def test_csv_to_sys_param(self): output_sys_param_file = self.output_dir / 'test_sys_param.json' SystemParameters.csv_to_sys_param( model_type='time_series', scenario_dir=self.scenario_dir, feature_file=self.feature_file, sys_param_filename=output_sys_param_file) self.assertTrue(output_sys_param_file.exists())
def test_csv_to_sys_param_does_not_overwrite(self): with self.assertRaises(Exception) as context: output_sys_param_file = self.output_dir / 'test_overwriting_sys_param.json' SystemParameters.csv_to_sys_param( model_type='time_series', scenario_dir=self.scenario_dir, feature_file=self.feature_file, sys_param_filename=output_sys_param_file, overwrite=True) SystemParameters.csv_to_sys_param( model_type='time_series', scenario_dir=self.scenario_dir, feature_file=self.feature_file, sys_param_filename=output_sys_param_file, overwrite=False) self.assertIn("Output file already exists and overwrite is False:", str(context.exception))
def test_validate_sys_param_template(self): output_sys_param_file = self.output_dir / 'bogus_sys_param.json' with self.assertRaises(Exception) as context: SystemParameters.csv_to_sys_param( scenario_dir=self.scenario_dir, feature_file=self.feature_file, sys_param_filename=output_sys_param_file) self.assertIn( "csv_to_sys_param() missing 1 required positional argument: 'model_type'", str(context.exception)) with self.assertRaises(Exception) as context: bogus_template_type = 'openstudio' SystemParameters.csv_to_sys_param( model_type=bogus_template_type, scenario_dir=self.scenario_dir, feature_file=self.feature_file, sys_param_filename=output_sys_param_file) self.assertIn( f"No template found. {bogus_template_type} is not a valid template", str(context.exception))
def test_missing_files(self): with self.assertRaises(Exception) as context: output_sys_param_file = self.output_dir / 'going_to_fail_first.json' missing_scenario_dir = self.scenario_dir / 'foobar' SystemParameters.csv_to_sys_param( model_type='time_series', scenario_dir=missing_scenario_dir, feature_file=self.feature_file, sys_param_filename=output_sys_param_file) self.assertIn( f"Unable to find your scenario. The path you provided was: {missing_scenario_dir}", str(context.exception)) with self.assertRaises(Exception) as context: missing_feature_file = self.data_dir / 'sdk_output_skeleton' / 'foobar.json' SystemParameters.csv_to_sys_param( model_type='time_series', scenario_dir=self.scenario_dir, feature_file=missing_feature_file, sys_param_filename=output_sys_param_file) self.assertIn( f"Unable to find your feature file. The path you provided was: {missing_feature_file}", str(context.exception))
def build_sys_param(model_type: str, sys_param_filename: Path, scenario_file: Path, feature_file: Path, overwrite: bool): """ Create system parameters file using uo_sdk output SYS_PARAM_FILENAME: Path/name to sys-param file be created. Be sure to include the ".json" suffix. SCENARIO_FILE: Path to sdk scenario file. FEATURE_FILE: Path to sdk json feature file with data about the buildings. \b MODEL_TYPE: selection for which kind of simulation this sys-param file will support. Valid choices for MODEL_TYPE: "time_series" \f :param model_type: string, selection of which model type to use in the GMT :param sys_param_filename: Path, location & name of json output file to save :param scenario_file: Path, location of SDK scenario_file :param feature_file: Path, location of SDK feature_file :param overwrite: Boolean, flag to overwrite an existing file of the same name/location """ # Use scenario_file to be consistent with sdk scenario_name = Path(scenario_file).stem scenario_dir = Path(scenario_file).parent / 'run' / scenario_name SystemParameters.csv_to_sys_param( model_type=model_type, sys_param_filename=Path(sys_param_filename), scenario_dir=Path(scenario_dir), feature_file=Path(feature_file), overwrite=overwrite ) if Path(sys_param_filename).exists(): print(f"\nSystem parameters file {sys_param_filename} successfully created.") else: raise SystemExit(f"{sys_param_filename} failed. Please check your inputs and try again.")