Skip to content

Commit

Permalink
Merge pull request #52 from JGCRI/gexp-fix
Browse files Browse the repository at this point in the history
Grand Experiment fixes
  • Loading branch information
calebbraun authored Feb 26, 2019
2 parents 7d87ae2 + b80b4d9 commit 2dfd103
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
17 changes: 11 additions & 6 deletions cassandra/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,8 @@ class XanthosComponent(ComponentBase):
the grids in the precipitation and temperature lists match one another.
params:
config_file - Path to Xanthos config file
config_file - Path to Xanthos config file
OutputNameStr - Name for the directory to create for Xanthos outputs
Capability dependencies (all optional):
gridded_pr - List of gridded monthly precipitation by grid cell
Expand Down Expand Up @@ -679,6 +680,9 @@ def run_component(self):

# Run Xanthos for each pair of precipitation and temperature grids
args = {}
if self.params.get('OutputNameStr') is not None:
args['OutputNameStr'] = self.params['OutputNameStr']

for pr, tas in zip(pr_grids, tas_grids):
args['PrecipitationFile'] = self.prep_for_xanthos(pr, pr_coord)
args['trn_tas'] = self.prep_for_xanthos(tas, tas_coord) - 273.15 # K to C
Expand Down Expand Up @@ -817,10 +821,11 @@ def run_component(self):
numpy2ri.activate() # enable automatic conversion of numpy objects to R equivalents.

if self.params['loadpkgs']:
import os
pkgdir = self.params["pkgdir"]

an2month = os.path.join(workdir, "an2month")
fldgen = os.path.join(workdir, "fldgen")
an2month = os.path.join(pkgdir, "an2month")
fldgen = os.path.join(pkgdir, "fldgen")

devtools = importr("devtools")
devtools.load_all(an2month)
Expand All @@ -841,8 +846,8 @@ def run_component(self):
# Data is already at monthly resolution; however, we do still
# need to transpose it so that months are in columns.
fullgrids_monthly = {}
fullgrids_monthly['pr'] = [np.transpose(np.asarray(x)) for x in fullgrids_annual['pr']]
fullgrids_monthly['tas'] = [np.transpose(np.asarray(x)) for x in fullgrids_annual['tas']]
fullgrids_monthly['pr'] = [np.transpose(np.asarray(x, dtype=np.float32)) for x in fullgrids_annual['pr']]
fullgrids_monthly['tas'] = [np.transpose(np.asarray(x, dtype=np.float32)) for x in fullgrids_annual['tas']]
else:
fullgrids_monthly = self.run_monthlyds(fullgrids_annual, coords)

Expand Down Expand Up @@ -965,7 +970,7 @@ def run_monthlyds(self, annual_flds, coords):
# If this is precipitation, convert units.
monthly = [an2month.pr_conversion(x) for x in monthly]

rslt[var] = [np.transpose(np.asarray(x)) for x in monthly]
rslt[var] = [np.transpose(np.asarray(x, dtype=np.float32)) for x in monthly]
logging.debug(f'Result for {var}: len = {len(rslt[var])}. Shape = {rslt[var][0].shape}')

return rslt
Expand Down
3 changes: 2 additions & 1 deletion cassandra/mp.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ def distribute_assignments_supervisor(args):
except ValueError as e:
raise RuntimeError("Config file must have a '[Global]' section") from e

section_weights = [config[s].get('mp.weight', 1.0) for s in section_names]
section_weights = [float(config[s].get('mp.weight', 1.0)) for s in section_names]
logging.debug(f'section_weights: {section_weights}')
name_weight = zip(section_names, section_weights)
section_names = [s[0] for s in sorted(name_weight, key=lambda x:x[1], reverse=True)]

Expand Down

0 comments on commit 2dfd103

Please sign in to comment.