def produce_comparison(ucfg, gold_dir, cfg_mods={}, results='output'): """ """ for s in cfg_mods.keys(): for i, v in cfg_mods[s].items(): print(s, i, v) ucfg.cfg[s][i] = v # Run smrf with the new config file from smrf.framework.model_framework import run_smrf run_smrf(ucfg) gf = glob(gold_dir + '/*.nc') cf = glob(ucfg.cfg['output']['out_location'] + '/*.nc') gc = GoldFilesCompare(gold_files=gf, compare_files=cf, file_type='netcdf', only_report_nonzero=True, output_dir=results) results = gc.compare() gc.plot_results(results, plot_original_data=False, include_hist=True, show_plots=False) shutil.rmtree(ucfg.cfg['output']['out_location'])
def test_variables_non_standard(self): new_variables = [ 'clear_ir_beam', 'veg_vis_diffuse', 'cloud_vis_beam', 'thermal_veg' ] config = self.change_variables(new_variables) run_smrf(config) self.check_outputs(new_variables)
def test_load_timestep(self): config = deepcopy(self.config) config.raw_cfg['gridded']['hrrr_load_method'] = 'timestep' config.apply_recipes() config = cast_all_variables(config, config.mcfg) run_smrf(config) self.compare_hrrr_gold()
def can_i_run_smrf(self, config): """ Test whether a config is possible to run """ try: run_smrf(config) return True except Exception as e: # print(e) return False
def test_load_timestep_threaded(self): config = deepcopy(self.config) config.raw_cfg['gridded']['hrrr_load_method'] = 'timestep' config.raw_cfg['system']['threading'] = True config.raw_cfg['system']['queue_max_values'] = 1 config.apply_recipes() config = cast_all_variables(config, config.mcfg) run_smrf(config) self.compare_hrrr_gold()
def test_grid_wrf(self): """ WRF NetCDF loading """ config = deepcopy(self.base_config) del config.raw_cfg['csv'] adj_config = { 'gridded': { 'data_type': 'wrf', 'wrf_file': './gridded/WRF_test.nc', }, 'system': { 'threading': 'False', 'log_file': './output/log.txt' }, 'precip': { 'station_adjust_for_undercatch': 'False' }, 'wind': { 'wind_model': 'interp' }, 'thermal': { 'correct_cloud': 'False', 'correct_veg': 'True' }, 'time': { 'start_date': '2015-03-03 00:00', 'end_date': '2015-03-03 04:00' } } config.raw_cfg.update(adj_config) # set the distribution to grid, thermal defaults will be fine for v in self.dist_variables: config.raw_cfg[v]['grid_mask'] = 'False' # fix the time to that of the WRF_test.nc config.apply_recipes() config = cast_all_variables(config, config.mcfg) # ensure that the recipes are used self.assertTrue( 'station_adjust_for_undercatch' not in config.cfg['precip'].keys()) self.assertFalse(config.cfg['thermal']['correct_cloud']) self.assertTrue(config.cfg['thermal']['correct_veg']) run_smrf(config)
def test_station_dates(self): """ Test the start date not in the data """ config = self.base_config # Use dates not in the dataset, expecting an error config.raw_cfg['time']['start_date'] = '1900-01-01 00:00' config.raw_cfg['time']['end_date'] = '1900-02-01 00:00' # apply the new recipes config.apply_recipes() config = cast_all_variables(config, config.mcfg) with self.assertRaises(Exception): run_smrf(config)
def setUpClass(self): """ Runs the short simulation over reynolds mountain east """ run_dir = abspath(join(dirname(smrf.__file__), '../tests', 'RME')) self.gold = abspath(join(run_dir, 'gold')) self.output = join(run_dir, 'output') # Remove any potential files to ensure fresh run if isdir(self.output): shutil.rmtree(self.output) config = join(run_dir, 'config.ini') run_smrf(config)
def test_grid_netcdf(self): config = deepcopy(self.base_config) del config.raw_cfg['csv'] generic_grid = { 'data_type': 'netcdf', 'netcdf_file': './gridded/netcdf_test.nc', 'air_temp': 'air_temp', 'vapor_pressure': 'vapor_pressure', 'precip': 'precip', 'wind_speed': 'wind_speed', 'wind_direction': 'wind_direction', 'cloud_factor': 'cloud_factor' } config.raw_cfg['gridded'] = generic_grid config.raw_cfg['system']['time_out'] = '25' config.raw_cfg['system']['queue_max_values'] = '2' # Doesn't work with true config.raw_cfg['system']['threading'] = 'False' # set the distribution to grid, thermal defaults will be fine for v in self.dist_variables: config.raw_cfg[v]['distribution'] = 'grid' config.raw_cfg[v]['grid_mask'] = 'False' config.raw_cfg['thermal']['correct_cloud'] = 'False' config.raw_cfg['thermal']['correct_veg'] = 'True' config.raw_cfg['wind']['wind_model'] = 'interp' # fix the time to that of the WRF_test.nc config.raw_cfg['time']['start_date'] = '2015-03-03 00:00' config.raw_cfg['time']['end_date'] = '2015-03-03 04:00' config.apply_recipes() config = cast_all_variables(config, config.mcfg) # ensure that the recipes are used self.assertTrue( 'station_adjust_for_undercatch' not in config.cfg['precip'].keys()) self.assertFalse(config.cfg['thermal']['correct_cloud']) self.assertTrue(config.cfg['thermal']['correct_veg']) run_smrf(config)
def test_all_stations(self): """ Test using all stations """ # test the end date config = self.base_config config.raw_cfg['csv']['stations'] = ['RMESP', 'RME_176'] # apply the new recipies config.apply_recipes() config = cast_all_variables(config, config.mcfg) self.assertIsInstance(run_smrf(config), SMRF)
def test_mysql_metadata_error(self): """ test no metadata found """ config = deepcopy(self.base_config) options = deepcopy(self.options) config.raw_cfg['mysql'] = options config.raw_cfg['mysql']['stations'] = ['NOT_STID', 'NOPE'] del config.raw_cfg['csv'] config.apply_recipes() config = cast_all_variables(config, config.mcfg) with self.assertRaises(Exception): result = run_smrf(config)
def test_mysql_data_error(self): """ test no data found """ config = deepcopy(self.base_config) options = deepcopy(self.options) config.raw_cfg['mysql'] = options config.raw_cfg['mysql']['stations'] = ['RMESP', 'RME_176'] del config.raw_cfg['csv'] # wrong time config.raw_cfg['time']['start_date'] = '1900-01-01 00:00' config.raw_cfg['time']['end_date'] = '1900-02-01 00:00' config.apply_recipes() config = cast_all_variables(config, config.mcfg) with self.assertRaises(Exception): result = run_smrf(config)
def setUpClass(cls): super().setUpClass() cls.smrf = run_smrf(cls.run_config)
def test_grid_hrrr_local(self): run_smrf(self.config) self.compare_hrrr_gold()
def run_smrf(self): """Run SMRF using the `run_smrf` from the SMRF API """ self._logger.info('Running SMRF') run_smrf(self.smrf_config, self._logger)
def setUpClass(cls): super().setUpClass() cls.gold_dir = cls.basin_dir.joinpath('gold') run_smrf(cls.run_config)
def test_variables_standard(self): new_variables = ['thermal', 'air_temp'] config = self.change_variables(new_variables) run_smrf(config) self.check_outputs(new_variables)