def setup(self, builder): self.config = builder.configuration.metrics.mortality self.clock = builder.time.clock() self.step_size = builder.time.step_size() self.start_time = self.clock() self.initial_pop_entrance_time = self.start_time - self.step_size() self.age_bins = get_age_bins(builder) diseases = builder.components.get_components_by_type( (DiseaseState, RiskAttributableDisease)) self.causes = [c.state_id for c in diseases] + ['other_causes'] life_expectancy_data = builder.data.load( "population.theoretical_minimum_risk_life_expectancy") self.life_expectancy = builder.lookup.build_table( life_expectancy_data, key_columns=[], parameter_columns=['age']) columns_required = [ 'tracked', 'alive', 'entrance_time', 'exit_time', 'cause_of_death', 'years_of_life_lost', 'age' ] if self.config.by_sex: columns_required += ['sex'] self.population_view = builder.population.get_view(columns_required) builder.event.register_listener('time_step__prepare', self.on_time_step_prepare) builder.value.register_value_modifier('metrics', self.metrics)
def setup(self, builder: 'Builder'): self.config = builder.configuration['metrics'][ f'{self.disease}_observer'].to_dict() self.clock = builder.time.clock() self.age_bins = get_age_bins(builder) self.counts = Counter() self.person_time = Counter() self.states = project_globals.DISEASE_MODEL_MAP[self.disease]['states'] self.transitions = project_globals.DISEASE_MODEL_MAP[ self.disease]['transitions'] self.previous_state_column = f'previous_{self.disease}' builder.population.initializes_simulants( self.on_initialize_simulants, creates_columns=[self.previous_state_column]) columns_required = [ 'alive', f'{self.disease}', self.previous_state_column ] if self.config['by_age']: columns_required += ['age'] if self.config['by_sex']: columns_required += ['sex'] self.population_view = builder.population.get_view(columns_required) builder.value.register_value_modifier('metrics', self.metrics) # FIXME: The state table is modified before the clock advances. # In order to get an accurate representation of person time we need to look at # the state table before anything happens. builder.event.register_listener('time_step__prepare', self.on_time_step_prepare) builder.event.register_listener('collect_metrics', self.on_collect_metrics)
def setup(self, builder): self.clock = builder.time.clock() self.config = builder.configuration['metrics']['medication'] self.counts = Counter() self.never_treated = pd.DataFrame(columns=HYPERTENSION_DRUGS, dtype=bool) age_sex_filter, (self.ages, self.sexes) = get_age_sex_filter_and_iterables( self.config, get_age_bins(builder)) self.base_filter = age_sex_filter columns_required = ['alive', 'last_prescription_date' ] + DOSAGE_COLUMNS + SINGLE_PILL_COLUMNS if self.config.by_age: columns_required += ['age'] if self.config.by_sex: columns_required += ['sex'] self.population_view = builder.population.get_view(columns_required) builder.population.initializes_simulants( self.on_initialize_simulants, requires_columns=columns_required) builder.value.register_value_modifier('metrics', self.metrics) builder.event.register_listener('collect_metrics', self.on_collect_metrics)
def setup(self, builder): super().setup(builder) self.age_bins = get_age_bins(builder) self.anemia_counts = Counter() self.anemia_thresholds = builder.lookup.build_table( get_anemia_thresholds(), key_columns=[], parameter_columns=[('age', 'age_group_start', 'age_group_end')], value_columns=[ 'severe_threshold', 'moderate_threshold', 'mild_threshold' ]) self._disability_weight_data = builder.lookup.build_table( get_iron_deficiency_disability_weight(builder)) self.disability_weight = builder.value.register_value_producer( 'iron_deficiency.disability_weight', source=self.compute_disability_weight) builder.value.register_value_modifier('disability_weight', modifier=self.disability_weight) self.pop_view = builder.population.get_view(['alive', 'age', 'sex']) self.data = {} self.observer_config = builder.configuration['metrics'][ 'anemia_observer'] self.clock = builder.time.clock() builder.value.register_value_modifier('metrics', self.metrics) builder.event.register_listener('collect_metrics', self.on_collect_metrics)
def test_get_age_bins(builder, base_config, age_start, exit_age, result_age_end_values, result_age_start_values): base_config.update( {'population': { 'age_start': age_start, 'exit_age': exit_age }}, **metadata(__file__)) builder.configuration = base_config df = get_age_bins(builder) assert set(df.age_end) == result_age_end_values assert set(df.age_start) == result_age_start_values
def setup(self, builder): self.schedule = builder.configuration.shigellosis_vaccine.schedule self.config = builder.configuration['metrics'][self.name].to_dict() self.age_bins = get_age_bins(builder) self.counts = Counter() columns_required = ['alive', f'vaccine_dose', f'vaccine_event_time'] if self.config['by_age']: columns_required += ['age'] if self.config['by_sex']: columns_required += ['sex'] self.population_view = builder.population.get_view(columns_required) builder.value.register_value_modifier('metrics', self.metrics) builder.event.register_listener('collect_metrics', self.on_collect_metrics)
def setup(self, builder): self.clock = builder.time.clock() self.age_bins = get_age_bins(builder) required_columns = [ 'registry_evaluation_status', 'registry_evaluation_date', 'age', 'sex', 'alive', *data_values.RISKS ] self.population_view = builder.population.get_view(required_columns) builder.value.register_value_modifier('metrics', self.metrics) builder.event.register_listener('collect_metrics', self.on_collect_metrics) self.registry_entrances = Counter() self.registry_prevalence = Counter()
def setup(self, builder): self.data = {} self.config = builder.configuration[f'metrics'][ f'{self.risk.name}_observer'] self.clock = builder.time.clock() self.categories = self.config.categories self.age_bins = get_age_bins(builder) self.category_counts = Counter() self.population_view = builder.population.get_view( ['alive', 'age', 'sex'], query='alive == "alive"') self.exposure = builder.value.get_value(f'{self.risk.name}.exposure') builder.value.register_value_modifier('metrics', self.metrics) builder.event.register_listener('collect_metrics', self.on_collect_metrics)
def setup(self, builder): self.config = builder.configuration.metrics.supplemented_days self.step_size = builder.time.step_size() self.age_bins = get_age_bins(builder) self.lack_of_vitamin_a_supplementation = builder.value.get_value( "lack_of_vitamin_a_supplementation.exposure") self.supplemented_days = Counter() columns_required = ['tracked', 'alive'] if self.config.by_age: columns_required += ['age'] if self.config.by_sex: columns_required += ['sex'] self.population_view = builder.population.get_view(columns_required) builder.event.register_listener('collect_metrics', self.on_collect_metrics) builder.value.register_value_modifier('metrics', self.metrics)
def setup(self, builder): self.age_bins = get_age_bins(builder) treatment_cols = [ 'treatment_start_date', 'last_visit_date', 'last_visit_type', 'high_systolic_blood_pressure_measurement' ] disease_event_cols = [ f'{disease}_event_time' for disease in self.diseases ] death_cols = ['alive', 'exit_time', 'cause_of_death'] self.population_view = builder.population.get_view(treatment_cols + disease_event_cols + death_cols) builder.population.initializes_simulants(self.on_initialize_simulants) builder.value.register_value_modifier('metrics', self.metrics) builder.event.register_listener('collect_metrics', self.on_collect_metrics)
def setup(self, builder: 'Builder'): self.config = builder.configuration['metrics'][ 'anemia_observer'].to_dict() self.clock = builder.time.clock() self.age_bins = get_age_bins(builder) self.person_time = Counter() self.anemia_severity = builder.value.get_value('anemia_severity') self.states = project_globals.ANEMIA_SEVERITY_GROUPS columns_required = ['alive'] if self.config['by_age']: columns_required += ['age'] if self.config['by_sex']: columns_required += ['sex'] self.population_view = builder.population.get_view(columns_required) builder.value.register_value_modifier('metrics', self.metrics) # FIXME: The state table is modified before the clock advances. # In order to get an accurate representation of person time we need to look at # the state table before anything happens. builder.event.register_listener('time_step__prepare', self.on_time_step_prepare)
def setup(self, builder): self.config = builder.configuration['metrics'][ f'{self.disease}_observer'] self.clock = builder.time.clock() self.age_bins = get_age_bins(builder) self.counts = Counter() model = builder.components.get_component( f'disease_model.{self.disease}') self.disease_states = [s.name.split('.')[-1] for s in model.states] columns_required = ['alive'] + [ f'{state}_event_time' for state in self.disease_states ] if self.config.by_age: columns_required += ['age'] if self.config.by_sex: columns_required += ['sex'] self.population_view = builder.population.get_view(columns_required) builder.value.register_value_modifier('metrics', self.metrics) builder.event.register_listener('collect_metrics', self.on_collect_metrics)
def setup(self, builder: 'Builder'): self.config = builder.configuration.metrics.miscellaneous_observer.to_dict( ) self.age_bins = get_age_bins(builder) columns_required = [ project_globals.TREATMENT.name, 'age', 'sex', 'alive', 'initial_treatment_proportion_reduction' ] self.population_view = builder.population.get_view(columns_required) self.fpg = builder.value.get_value( f'{project_globals.FPG.name}.exposure') self.ldlc = builder.value.get_value( f'{project_globals.LDL_C.name}.exposure') self.sbp = builder.value.get_value( f'{project_globals.SBP.name}.exposure') self.is_adherent = builder.value.get_value('ldlc_treatment_adherence') self.cvd_risk_score = builder.value.get_value('cvd_risk_score') self.results = Counter() builder.value.register_value_modifier('metrics', self.metrics) builder.event.register_listener('collect_metrics', self.on_collect_metrics)
def _get_age_bins(self, builder: Builder) -> pd.DataFrame: return utilities.get_age_bins(builder)