From 22b5a5166c6d1c2212539329f4f8c6ccfb460102 Mon Sep 17 00:00:00 2001 From: Caleb Braun Date: Mon, 18 Feb 2019 13:23:11 -0800 Subject: [PATCH 1/2] Fix component weighting with floats --- cassandra/mp.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cassandra/mp.py b/cassandra/mp.py index 2b87ebf..e6bcff0 100644 --- a/cassandra/mp.py +++ b/cassandra/mp.py @@ -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)] From b80b4d926f829f95457b94560c90fcfad0f91b25 Mon Sep 17 00:00:00 2001 From: Caleb Braun Date: Mon, 18 Feb 2019 13:30:17 -0800 Subject: [PATCH 2/2] Package loading bugfix; reduce array size; param for Xanthos outdir --- cassandra/components.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/cassandra/components.py b/cassandra/components.py index db9c5eb..fe2e13e 100644 --- a/cassandra/components.py +++ b/cassandra/components.py @@ -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 @@ -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 @@ -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) @@ -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) @@ -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