Skip to content

Commit

Permalink
Merge pull request #46 from DavidChoi76/master
Browse files Browse the repository at this point in the history
add get_output method in Simulation.py
  • Loading branch information
lukeydchoi committed Oct 5, 2018
2 parents 5e78661 + 6588123 commit 366b0c3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
26 changes: 25 additions & 1 deletion pysumma/Simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def __init__(self, case_data, summa_code = None):
self.base_dir = case_data.split('/settings')[0]
# create self object from decision text file
self.decision_obj = Decisions(self.base_dir + '/settings/' + self.decision_path.value)
#

if summa_code == None:
self.modeloutput_obj = ModelOutput(self.base_dir + '/settings/' + self.OUTPUT_CONTROL.value, self.base_dir + '/settings/meta/var_lookup.f90')
Expand Down Expand Up @@ -176,6 +175,31 @@ def execute(self, run_option, run_suffix, specworker_img = None):

return xr.open_dataset(out_file_path), out_file_path

def get_output(self, version, output_prefix):
if version == "cuahsi_sopron":
out_file_path = self.base_dir + '/' + self.output_path.filepath.split('/')[1] + '/' + \
output_prefix + '_output_' + \
self.run_suffix + 'timestep.nc'
xr_output = xr.open_dataset(out_file_path)
elif version == "cuahsi_master":
out_file_path = self.base_dir + self.output_path.value.split('>')[1] + \
output_prefix + '_' + \
self.decision_obj.simulStart.value[0:4] + '-' + \
self.decision_obj.simulFinsh.value[0:4] + '_' + '1.nc'
xr_output = xr.open_dataset(out_file_path)
elif version == "docker_sopron":
if self.output_path.filepath.split('/')[0] == '<BASEDIR>':
out_file_path = self.output_path.filepath.split('<BASEDIR>')[1] + \
self.output_prefix.value + '_output_' + \
self.run_suffix + '_timestep.nc'
else:
out_file_path = self.output_path.filepath + \
self.output_prefix.value + '_output_' + \
self.run_suffix + '_timestep.nc'
xr_output = xr.open_dataset(out_file_path)
else:
raise ValueError('You need to write "cuahsi_sopron" or "cuahsi_master"or "docker_sorpon" for version')
return xr_output, out_file_path

class FileManagerOption(Option):

Expand Down
3 changes: 2 additions & 1 deletion pysumma/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from hs_restclient import HydroShare

class utils():

# download SUMMA TestCases from ucar web site, however this is old version of SUMMA TestCases
def install_test_cases_summa_web(save_filepath):
url = "https://ral.ucar.edu/sites/default/files/public/projects/structure-for-unifying-multiple-modeling-alternatives-summa/summatestcases-2.x.tar.gz"
Expand Down Expand Up @@ -76,4 +77,4 @@ def download_model_instance_pangeo(resource_id):
subprocess.run(cmd, shell=True, stderr=subprocess.STDOUT)
cmd = 'cd ' + Model_Instance_Name.split('.')[0] + '/; ./installTestCases_local.sh'
subprocess.run(cmd, shell=True, stderr=subprocess.STDOUT)
return Model_Instance_Name.split('.')[0]
return Model_Instance_Name.split('.')[0]

0 comments on commit 366b0c3

Please sign in to comment.