def __init__( self, input_param_file: str = None, param_line_number: int = 1, output_file_dir: str = "./", input_households: Union[str, pd.DataFrame] = None, read_param_file=True, ): """[summary] Arguments: object {[type]} -- [description] Keyword Arguments: input_param_file {str} -- [Parameters file path] (default: {None}) param_line_number {int} -- [Which column of the input param file to read] (default: 1) output_file_dir {str} -- [Where to write output files to] (default: {"./"}) input_households {str} -- [Household demographics file (required)] (default: {None}) read_param_file {bool} -- [Read param file, all params can be set from python interface] (default: {True}) Raises: ParameterException: [Warnings if parameters are not correctly set] Sys.exit(0): [Underlaying C code will exist if params are not viable] """ self.c_params = covid19.parameters() if input_param_file: self.c_params.input_param_file = input_param_file elif not input_param_file and read_param_file: raise ParameterException( "Input param path is None and read param file set to true") else: LOGGER.info( "Have not passed input file for params, use set_param or set_param_dict" ) if param_line_number: self.c_params.param_line_number = int(param_line_number) self.c_params.output_file_dir = output_file_dir if isinstance(input_households, str): self.c_params.input_household_file = input_households self.household_df = None elif isinstance(input_households, pd.DataFrame): self.household_df = input_households elif not input_households: raise ParameterException( "Household data must be supplied as a csv") if read_param_file and input_param_file != None: self._read_and_check_from_file() if output_file_dir: self.c_params.sys_write_individual = 1 self.update_lock = False
def __init__( self, input_param_file: str = None, param_line_number: int = 1, output_file_dir: str = "./", input_households: Union[str, pd.DataFrame] = None, hospital_input_param_file: str = None, hospital_param_line_number: int = 1, read_param_file=True, read_hospital_param_file=False, ): """[summary] Arguments: object {[type]} -- [description] Keyword Arguments: input_param_file {str} -- [Parameters file path] (default: {None}) param_line_number {int} -- [Which column of the input param file to read] (default: 1) output_file_dir {str} -- [Where to write output files to] (default: {"./"}) input_households {str} -- [Household demographics file (required)] (default: {None}) read_param_file {bool} -- [Read param file, all params can be set from python interface] (default: {True}) Raises: ParameterException: [Warnings if parameters are not correctly set] Sys.exit(0): [Underlaying C code will exist if params are not viable] """ self.c_params = covid19.parameters() covid19.initialize_params( self.c_params ); # if no input_param_file is given use default if not input_param_file : input_param_file = pkg_resources.resource_filename('COVID19', 'default_params/baseline_parameters.csv') if read_param_file : self.c_params.input_param_file = input_param_file else: LOGGER.info( "Have not passed input file for params, use set_param or set_param_dict" ) if param_line_number: self.c_params.param_line_number = int(param_line_number) self.c_params.output_file_dir = output_file_dir if isinstance(input_households, pd.DataFrame): self.household_df = input_households else : if not input_households : input_households = pkg_resources.resource_filename('COVID19', 'default_params/baseline_household_demographics.csv') self.c_params.input_household_file = input_households self.household_df = None if hospital_param_line_number: self.c_params.hospital_param_line_number = int(hospital_param_line_number) # if no hospital_input_param_file is given use default if not hospital_input_param_file : hospital_input_param_file = pkg_resources.resource_filename('COVID19', 'default_params/hospital_baseline_parameters.csv') if read_hospital_param_file: self.c_params.hospital_input_param_file = hospital_input_param_file else: LOGGER.info("Have not passed hospital input file for params, use set_param or set_param_dict// crick todo look into this") if read_hospital_param_file and hospital_input_param_file != None: self._read_hospital_param_file() if read_param_file and input_param_file != None: self._read_and_check_from_file() if output_file_dir: self.c_params.sys_write_individual = 1 self.update_lock = False
def test_set_get_array_parameters(self): """ Test that an array parameter inside the C parameters structure can be changed """ params = covid19.parameters() # Define arrays get_age_types = covid19.doubleArray(covid19.N_AGE_TYPES) set_age_types = covid19.doubleArray(covid19.N_AGE_TYPES) for i in range(covid19.N_AGE_TYPES): set_age_types[i] = uniform(FLOAT_START, FLOAT_END) get_work_networks = covid19.doubleArray(covid19.N_DEFAULT_OCCUPATION_NETWORKS) set_work_networks = covid19.doubleArray(covid19.N_DEFAULT_OCCUPATION_NETWORKS) for i in range(covid19.N_DEFAULT_OCCUPATION_NETWORKS): set_work_networks[i] = uniform(FLOAT_START, FLOAT_END) get_interaction_types = covid19.doubleArray(covid19.N_INTERACTION_TYPES) set_interaction_types = covid19.doubleArray(covid19.N_INTERACTION_TYPES) for i in range(covid19.N_INTERACTION_TYPES): set_interaction_types[i] = uniform(FLOAT_START, FLOAT_END) get_age_groups = covid19.doubleArray(covid19.N_AGE_GROUPS) set_age_groups = covid19.doubleArray(covid19.N_AGE_GROUPS) for i in range(covid19.N_AGE_GROUPS): set_age_groups[i] = uniform(FLOAT_START, FLOAT_END) get_household_max = covid19.doubleArray(covid19.N_HOUSEHOLD_MAX) set_household_max = covid19.doubleArray(covid19.N_HOUSEHOLD_MAX) for i in range(covid19.N_HOUSEHOLD_MAX): set_household_max[i] = uniform(FLOAT_START, FLOAT_END) # Test set/get functions covid19.set_param_array_mean_random_interactions(params, set_age_types) covid19.get_param_array_mean_random_interactions(params, get_age_types) for i in range(covid19.N_AGE_TYPES): np.testing.assert_equal(set_age_types[i], get_age_types[i]) covid19.set_param_array_sd_random_interactions(params, set_age_types) covid19.get_param_array_sd_random_interactions(params, get_age_types) for i in range(covid19.N_AGE_TYPES): np.testing.assert_equal(set_age_types[i], get_age_types[i]) covid19.set_param_array_mean_work_interactions(params, set_work_networks) covid19.get_param_array_mean_work_interactions(params, get_work_networks) for i in range(covid19.N_DEFAULT_OCCUPATION_NETWORKS): np.testing.assert_equal(set_work_networks[i], get_work_networks[i]) covid19.set_param_array_relative_susceptibility(params, set_age_groups) covid19.get_param_array_relative_susceptibility(params, get_age_groups) for i in range(covid19.N_AGE_GROUPS): np.testing.assert_equal(set_age_groups[i], get_age_groups[i]) covid19.set_param_array_adjusted_susceptibility(params, set_age_groups) covid19.get_param_array_adjusted_susceptibility(params, get_age_groups) for i in range(covid19.N_AGE_GROUPS): np.testing.assert_equal(set_age_groups[i], get_age_groups[i]) covid19.set_param_array_relative_transmission(params, set_interaction_types) covid19.get_param_array_relative_transmission(params, get_interaction_types) for i in range(covid19.N_INTERACTION_TYPES): np.testing.assert_equal(set_interaction_types[i], get_interaction_types[i]) covid19.set_param_array_hospitalised_fraction(params, set_age_groups) covid19.get_param_array_hospitalised_fraction(params, get_age_groups) for i in range(covid19.N_AGE_GROUPS): np.testing.assert_equal(set_age_groups[i], get_age_groups[i]) covid19.set_param_array_critical_fraction(params, set_age_groups) covid19.get_param_array_critical_fraction(params, get_age_groups) for i in range(covid19.N_AGE_GROUPS): np.testing.assert_equal(set_age_groups[i], get_age_groups[i]) covid19.set_param_array_fatality_fraction(params, set_age_groups) covid19.get_param_array_fatality_fraction(params, get_age_groups) for i in range(covid19.N_AGE_GROUPS): np.testing.assert_equal(set_age_groups[i], get_age_groups[i]) covid19.set_param_array_household_size(params, set_household_max) covid19.get_param_array_household_size(params, get_household_max) for i in range(covid19.N_HOUSEHOLD_MAX): np.testing.assert_equal(set_household_max[i], get_household_max[i]) covid19.set_param_array_population(params, set_age_groups) covid19.get_param_array_population(params, get_age_groups) for i in range(covid19.N_AGE_GROUPS): np.testing.assert_equal(set_age_groups[i], get_age_groups[i]) covid19.set_param_array_fraction_asymptomatic(params, set_age_groups) covid19.get_param_array_fraction_asymptomatic(params, get_age_groups) for i in range(covid19.N_AGE_GROUPS): np.testing.assert_equal(set_age_groups[i], get_age_groups[i]) covid19.set_param_array_mild_fraction(params, set_age_groups) covid19.get_param_array_mild_fraction(params, get_age_groups) for i in range(covid19.N_AGE_GROUPS): np.testing.assert_equal(set_age_groups[i], get_age_groups[i]) covid19.set_param_array_location_death_icu(params, set_age_groups) covid19.get_param_array_location_death_icu(params, get_age_groups) for i in range(covid19.N_AGE_GROUPS): np.testing.assert_equal(set_age_groups[i], get_age_groups[i]) covid19.set_param_array_app_users_fraction(params, set_age_groups) covid19.get_param_array_app_users_fraction(params, get_age_groups) for i in range(covid19.N_AGE_GROUPS): np.testing.assert_equal(set_age_groups[i], get_age_groups[i])