Skip to content

Commit

Permalink
Merge pull request #66 from USDA-ARS-NWRC/updates/smrf
Browse files Browse the repository at this point in the history
Update tests with SMRF basin lat and lon changes.
  • Loading branch information
jomey committed May 11, 2020
2 parents f9790e0 + 7fe92a2 commit ce1230c
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 317 deletions.
3 changes: 0 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ ENV VPYSNOBAL "0.2.0"

RUN apt-get update \
&& apt-get install -y --no-install-recommends curl \
&& apt-get install -y texlive-base \
&& apt-get install -y texlive-lang-english \
&& apt-get install -y texlive-latex-extra \
&& apt-get install -y gcc \
&& cd /code \
&& git clone --depth 1 https://github.com/USDA-ARS-NWRC/pysnobal.git \
Expand Down
1 change: 0 additions & 1 deletion awsm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@
from . import convertFiles
from . import interface
from . import knn
from . import reporting
from . import framework
5 changes: 1 addition & 4 deletions awsm/framework/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
import os
from .ascii_art import TITLE, MOUNTAIN
from . import framework

__author__ = """Micah Sandusky"""
__email__ = 'micah.sandusky@ars.usda.gov'
44 changes: 44 additions & 0 deletions awsm/framework/ascii_art.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
MOUNTAIN = \
" \n" \
r" _" + "\n" \
r" /#\ " + "\n" \
r" /###\ /\ " + "\n" \
r" / ###\ /##\ /\ " + "\n" \
r" / #\ /####\/##\ " + "\n" \
r" / / / # / ##\ _ /\ " + "\n" \
r" // // /\ / _/ / #\ _ /#\ _/##\ /\ " + "\n" \
r" // / / \ / / #\ \ _/###\_ / ##\__/ _\ " + "\n" \
r" / \ / .. \ / / _ { \ \ _/ / // / \\ " + "\n" \
r" /\ / /\ ... \_/ / / \ } \ | / /\ \ / _ / / \ /\ " + "\n" \
r" _ / \ /// / .\ ..%:. /... /\ . \ {: \\ /. \ / \ / ___ / \ " + "\n" \
r" /.\ .\.\// \/... \.::::..... _/..\ ..\:|:. . / .. \\ /.. \ /...\ / \ \ " + "\n" \
r"/...\.../..:.\. ..:::::::..:..... . ...\{:... / %... \\/..%. \ /./:..\__ \ " + "\n" \
r" .:..\:..:::....:::;;;;;;::::::::.:::::.\}.....::%.:. \ .:::. \/.%:::.:..\:::" + "\n" \
r"::::...:::;;:::::;;;;;;;;;;;;;;:::::;;::{:::::::;;;:.. .:;:... ::;;::::..:::" + "\n" \
r";;;;:::;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;];;;;;;;;;;::::::;;;;:.::;;;;;;;;:.." + "\n" \
r";;;;;;;;;;;;;;ii;;;;;;;;;;;;;;;;;;;;;;;;[;;;;;;;;;;;;;;;;;;;;;;:;;;;;;;;;;;;;" + "\n" \
r";;;;;;;;;;;;;;;;;;;iiiiiiii;;;;;;;;;;;;;;};;ii;;iiii;;;;i;;;;;;;;;;;;;;;ii;;;" + "\n" \
r"iiii;;;iiiiiiiiiiIIIIIIIIIIIiiiiiIiiiiii{iiIIiiiiiiiiiiiiiiii;;;;;iiiilliiiii" + "\n" \
r"IIIiiIIllllllIIlllIIIIlllIIIlIiiIIIIIIIIIIIIlIIIIIllIIIIIIIIiiiiiiiillIIIllII" + "\n" \
r"IIIiiilIIIIIIIllTIIIIllIIlIlIIITTTTlIlIlIIIlIITTTTTTTIIIIlIIllIlIlllIIIIIIITT" + "\n" \
r"IIIIilIIIIITTTTTTTIIIIIIIIIIIIITTTTTIIIIIIIIITTTTTTTTTTIIIIIIIIIlIIIIIIIITTTT" + "\n" \
r"IIIIIIIIITTTTTTTTTTTTTIIIIIIIITTTTTTTTIIIIIITTTTTTTTTTTTTTIIIIIIIIIIIIIITTTTT" + "\n"

TITLE = \
" \n \n" + \
' AAA WWWWWWWW WWWWWWWW SSSSSSSSSSSSSSS MMMMMMMM MMMMMMMM' + "\n" \
' A:::A W::::::W W::::::W SS:::::::::::::::SM:::::::M M:::::::M' + "\n" \
' A:::::A W::::::W W::::::WS:::::SSSSSS::::::SM::::::::M M::::::::M' + "\n" \
' A:::::::AW::::::W W::::::WS:::::S SSSSSSSM:::::::::M M:::::::::M' + "\n" \
' A:::::::::AW:::::W WWWWW W:::::W S:::::S M::::::::::M M::::::::::M' + "\n" \
' A:::::A:::::AW:::::W W:::::W W:::::W S:::::S M:::::::::::M M:::::::::::M' + "\n" \
' A:::::A A:::::AW:::::W W:::::::W W:::::W S::::SSSS M:::::::M::::M M::::M:::::::M' + "\n" \
' A:::::A A:::::AW:::::W W:::::::::W W:::::W SS::::::SSSSS M::::::M M::::M M::::M M::::::M' + "\n" \
' A:::::A A:::::AW:::::W W:::::W:::::W W:::::W SSS::::::::SS M::::::M M::::M::::M M::::::M' + "\n" \
' A:::::AAAAAAAAA:::::AW:::::W W:::::W W:::::W W:::::W SSSSSS::::S M::::::M M:::::::M M::::::M' + "\n" \
' A:::::::::::::::::::::AW:::::W:::::W W:::::W:::::W S:::::SM::::::M M:::::M M::::::M' + "\n" \
' A:::::AAAAAAAAAAAAA:::::AW:::::::::W W:::::::::W S:::::SM::::::M MMMMM M::::::M' + "\n" \
' A:::::A A:::::AW:::::::W W:::::::W SSSSSSS S:::::SM::::::M M::::::M' + "\n" \
' A:::::A A:::::AW:::::W W:::::W S::::::SSSSSS:::::SM::::::M M::::::M' + "\n" \
' A:::::A A:::::AW:::W W:::W S:::::::::::::::SS M::::::M M::::::M' + "\n" \
'AAAAAAA AAAAAAAWWW WWW SSSSSSSSSSSSSSS MMMMMMMM MMMMMMMM' + "\n"
157 changes: 25 additions & 132 deletions awsm/framework/framework.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,25 @@
import copy
import logging
import os
import sys
import coloredlogs
from datetime import datetime

import coloredlogs
import pandas as pd
import pytz
import copy
from inicheck.config import MasterConfig, UserConfig
from inicheck.tools import get_user_config, check_config
from inicheck.output import print_config_report, generate_config
from inicheck.tools import cast_all_variables
from inicheck.tools import get_user_config, check_config, cast_all_variables
from smrf.utils import utils
from spatialnc.topo import topo as mytopo

import smrf
# make input the same as raw input if python 2
try:
input = raw_input
except NameError:
pass

try:
import snowav
except:
print('snowav not installed')

from smrf import __core_config__ as __smrf_core_config__
from smrf import __recipes__ as __smrf_recipes__
from awsm import __core_config__ as __awsm_core_config__
from awsm import __config_titles__

from smrf.utils import utils, io
from awsm.convertFiles import convertFiles as cvf
from awsm.interface import interface as smin
from awsm.interface import smrf_ipysnobal as smrf_ipy
from awsm.interface import ingest_data
from awsm.utils import utilities as awsm_utils
from awsm.data.init_model import modelInit
import awsm.reporting.reportingtools as retools
from awsm.interface import interface as smin, smrf_ipysnobal as smrf_ipy, \
ingest_data
from awsm.utils import utilities as awsm_utils
from awsm.framework import ascii_art


class AWSM():
"""
Expand Down Expand Up @@ -66,10 +49,6 @@ def __init__(self, config):
configFile = config

try:
# try:
# snowav_mcfg = MasterConfig(modules = 'snowav')
# combined_mcfg = MasterConfig(modules = ['smrf','awsm','snowav'])
# except:
combined_mcfg = MasterConfig(modules = ['smrf','awsm'])

# Read in the original users config
Expand Down Expand Up @@ -284,10 +263,6 @@ def __init__(self, config):
self.topo = mytopo(self.config['topo'], self.mask_isnobal,
self.model_type, self.csys, self.pathdd)

# parse reporting section and make reporting folder
# if self.do_report:
# self.parseReport()

# ################ Generate config backup ##################
# if self.config['output']['input_backup']:
# set location for backup and output backup of awsm sections
Expand All @@ -304,32 +279,6 @@ def __init__(self, config):
self.start_wyhr, self.pathro, self.pathrr,
self.pathinit, self.wy_start)

def parseReport(self):
"""
Parse the options related to reporting
"""
# get all relevant options
# snowav_mcfg = MasterConfig(modules = 'snowav')
# self.sec_snowav = snowav_mcfg.cfg.keys()
# self.path_report_o = os.path.join(self.path_wy, 'reports')
# self.path_report_i = os.path.join(self.path_report_o, 'report_{}'.format(self.folder_date_stamp))
# if not os.path.exists(self.path_report_i):
# os.makedirs(self.path_report_i)
#
# self.config['snowav system']['save_path'] = self.path_report_i
# self.config['snowav system']['wy'] = self.wy
# self.config['runs']['run_dirs'] = [self.pathrr]
# self.report_config = os.path.join(self.path_report_o, 'snowav_cfg.ini')
#
# # make copy and delete only awsm sections
# snowav_cfg = copy.deepcopy(self.ucfg)
# for key in self.ucfg.cfg.keys():
# if key in self.sec_awsm or key in self.sec_smrf:
# del snowav_cfg.cfg[key]
#
# self.tmp_log.append('Writing the config file for snowav')
# generate_config(snowav_cfg, self.report_config)

def createLog(self):
'''
Now that the directory structure is done, create log file and print out
Expand Down Expand Up @@ -406,12 +355,9 @@ def createLog(self):

self._logger = logging.getLogger(__name__)

# print title and mountains
title, mountain = self.title()
for line in mountain:
self._logger.info(line)
for line in title:
self._logger.info(line)
self._logger.info(ascii_art.MOUNTAIN)
self._logger.info(ascii_art.TITLE)

# dump saved logs
if len(self.tmp_log) > 0:
for l in self.tmp_log:
Expand Down Expand Up @@ -672,74 +618,26 @@ def make_rigid_directories(self, path_name):
else:
self.tmp_log.append('Directory --{}-- exists, not creating.\n')

def do_reporting(self):
"""
Outer most function for controlling what gets plotted to the dashboard
or written to the report
"""
retools.plot_dashboard(self)

def title(self):
"""
AWSM titles
Text generated from: http://patorjk.com/software/taag/#p=testall&f=Swamp%20Land&t=AWSM
Mountain ascii from: https://www.ascii-code.com/ascii-art/nature/mountains.php
"""
mountain = [r" _ ",
r" /#\ ",
r" /###\ /\ ",
r" / ###\ /##\ /\ ",
r" / #\ /####\/##\ ",
r" / / / # / ##\ _ /\ ",
r" // // /\ / _/ / #\ _ /#\ _/##\ /\ ",
r" // / / \ / / #\ \ _/###\_ / ##\__/ _\ ",
r" / \ / .. \ / / _ { \ \ _/ / // / \\ ",
r" /\ / /\ ... \_/ / / \ } \ | / /\ \ / _ / / \ /\ ",
r" _ / \ /// / .\ ..%:. /... /\ . \ {: \\ /. \ / \ / ___ / \ ",
r" /.\ .\.\// \/... \.::::..... _/..\ ..\:|:. . / .. \\ /.. \ /...\ / \ \ ",
r"/...\.../..:.\. ..:::::::..:..... . ...\{:... / %... \\/..%. \ /./:..\__ \ ",
r" .:..\:..:::....:::;;;;;;::::::::.:::::.\}.....::%.:. \ .:::. \/.%:::.:..\ ",
r"::::...:::;;:::::;;;;;;;;;;;;;;:::::;;::{:::::::;;;:.. .:;:... ::;;::::.. ",
r";;;;:::;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;];;;;;;;;;;::::::;;;;:.::;;;;;;;;:.. ",
r";;;;;;;;;;;;;;ii;;;;;;;;;;;;;;;;;;;;;;;;[;;;;;;;;;;;;;;;;;;;;;;:;;;;;;;;;;;;; ",
r";;;;;;;;;;;;;;;;;;;iiiiiiii;;;;;;;;;;;;;;};;ii;;iiii;;;;i;;;;;;;;;;;;;;;ii;;; ",
r"iiii;;;iiiiiiiiiiIIIIIIIIIIIiiiiiIiiiiii{iiIIiiiiiiiiiiiiiiii;;;;;iiiilliiiii ",
r"IIIiiIIllllllIIlllIIIIlllIIIlIiiIIIIIIIIIIIIlIIIIIllIIIIIIIIiiiiiiiillIIIllII ",
r"IIIiiilIIIIIIIllTIIIIllIIlIlIIITTTTlIlIlIIIlIITTTTTTTIIIIlIIllIlIlllIIIIIIITT ",
r"IIIIilIIIIITTTTTTTIIIIIIIIIIIIITTTTTIIIIIIIIITTTTTTTTTTIIIIIIIIIlIIIIIIIITTTT ",
r"IIIIIIIIITTTTTTTTTTTTTIIIIIIIITTTTTTTTIIIIIITTTTTTTTTTTTTTIIIIIIIIIIIIIITTTTT ",
"",
"",
""] # noqa
title = [
' AAA WWWWWWWW WWWWWWWW SSSSSSSSSSSSSSS MMMMMMMM MMMMMMMM',
' A:::A W::::::W W::::::W SS:::::::::::::::SM:::::::M M:::::::M',
' A:::::A W::::::W W::::::WS:::::SSSSSS::::::SM::::::::M M::::::::M',
' A:::::::AW::::::W W::::::WS:::::S SSSSSSSM:::::::::M M:::::::::M',
' A:::::::::AW:::::W WWWWW W:::::W S:::::S M::::::::::M M::::::::::M',
' A:::::A:::::AW:::::W W:::::W W:::::W S:::::S M:::::::::::M M:::::::::::M',
' A:::::A A:::::AW:::::W W:::::::W W:::::W S::::SSSS M:::::::M::::M M::::M:::::::M',
' A:::::A A:::::AW:::::W W:::::::::W W:::::W SS::::::SSSSS M::::::M M::::M M::::M M::::::M',
' A:::::A A:::::AW:::::W W:::::W:::::W W:::::W SSS::::::::SS M::::::M M::::M::::M M::::::M',
' A:::::AAAAAAAAA:::::AW:::::W W:::::W W:::::W W:::::W SSSSSS::::S M::::::M M:::::::M M::::::M',
' A:::::::::::::::::::::AW:::::W:::::W W:::::W:::::W S:::::SM::::::M M:::::M M::::::M',
' A:::::AAAAAAAAAAAAA:::::AW:::::::::W W:::::::::W S:::::SM::::::M MMMMM M::::::M',
' A:::::A A:::::AW:::::::W W:::::::W SSSSSSS S:::::SM::::::M M::::::M',
' A:::::A A:::::AW:::::W W:::::W S::::::SSSSSS:::::SM::::::M M::::::M',
' A:::::A A:::::AW:::W W:::W S:::::::::::::::SS M::::::M M::::::M',
'AAAAAAA AAAAAAAWWW WWW SSSSSSSSSSSSSSS MMMMMMMM MMMMMMMM'
]

return title, mountain
def run_report(self):
try:
import snowav
self._logger.info('AWSM finished run, starting report')
snowav.framework.framework.snowav(config_file=self.snowav_config)
except ModuleNotFoundError:
print('Library snowav not installed - skip reporting')

def __enter__(self):
self.start_time = datetime.now()
return self

def __exit__(self, exc_type, exc_value, traceback):
"""
Provide some logging info about when AWSM was closed
"""

self._logger.info(
'AWSM finished in: {}'.format(datetime.now() - self.start_time)
)
self._logger.info('AWSM closed --> %s' % datetime.now())


Expand Down Expand Up @@ -864,8 +762,6 @@ def run_awsm(config):
Args:
config: string path to the config file or inicheck UserConfig instance
"""
start = datetime.now()

with AWSM(config) as a:
if a.do_forecast:
runtype = 'forecast'
Expand Down Expand Up @@ -920,7 +816,4 @@ def run_awsm(config):

# create report
if a.snowav_config is not None:
a._logger.info('AWSM finished run, starting report')
a.do_reporting()

a._logger.info('AWSM finished in: {}'.format(datetime.now() - start))
a.run_report()
38 changes: 21 additions & 17 deletions awsm/interface/smrf_ipysnobal.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,14 @@ def run_smrf_ipysnobal_single(myawsm, s):
# 0.1 sun angle for time step
cosz, azimuth, rad_vec = radiation.sunang.sunang(
t.astimezone(pytz.utc),
s.topo.topoConfig['basin_lat'],
s.topo.topoConfig['basin_lon'],
s.topo.basin_lat,
s.topo.basin_long,
)

# 0.2 illumination angle
illum_ang = None
if cosz > 0:
illum_ang = radiation.shade(s.topo.slope,
illum_ang = radiation.shade(s.topo.sin_slope,
s.topo.aspect,
azimuth,
cosz)
Expand All @@ -262,22 +262,26 @@ def run_smrf_ipysnobal_single(myawsm, s):
t)

# 4. Precipitation
s.distribute['precip'].distribute(s.data.precip.loc[t],
s.distribute['vapor_pressure'].dew_point,
s.distribute['vapor_pressure'].precip_temp,
s.distribute['air_temp'].air_temp,
t,
s.data.wind_speed.loc[t],
s.data.air_temp.loc[t],
s.distribute['wind'].wind_direction,
s.distribute['wind'].dir_round_cell,
s.distribute['wind'].wind_speed,
s.distribute['wind'].cellmaxus)
s.distribute['precip'].distribute(
s.data.precip.loc[t],
s.distribute['vapor_pressure'].dew_point,
s.distribute['vapor_pressure'].precip_temp,
s.distribute['air_temp'].air_temp,
t,
s.data.wind_speed.loc[t],
s.data.air_temp.loc[t],
s.distribute['wind'].wind_direction,
s.distribute['wind'].wind_model.dir_round_cell,
s.distribute['wind'].wind_speed,
s.distribute['wind'].wind_model.cellmaxus
)

# 5. Albedo
s.distribute['albedo'].distribute(t,
illum_ang,
s.distribute['precip'].storm_days)
s.distribute['albedo'].distribute(
t,
illum_ang,
s.distribute['precip'].storm_days
)

# 6. cloud factor
s.distribute['cloud_factor'].distribute(s.data.cloud_factor.loc[t])
Expand Down
6 changes: 0 additions & 6 deletions awsm/reporting/__init__.py

This file was deleted.

0 comments on commit ce1230c

Please sign in to comment.