Skip to content

Comments

Bugfix/LBWSGRiskEffect#40

Merged
albrja merged 19 commits intomainfrom
bugfix/refactor-pregnancy
Mar 13, 2025
Merged

Bugfix/LBWSGRiskEffect#40
albrja merged 19 commits intomainfrom
bugfix/refactor-pregnancy

Conversation

@albrja
Copy link
Collaborator

@albrja albrja commented Mar 8, 2025

Bugfix/LBWSGRiskEffect

Fixes issues when subclassing LBWSG

Changes and notes

-refactors preganncy
-fixes bug when subclassing LBWSG
-fixes pipeline names

Verification and Testing

@property
def sub_components(self) -> List[str]:
return [self.lbwsg]
def columns_created(self) -> list[str]:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes in this file are for the refactor to the pregnancy component since the NewChildren component was more a class that stroed methods and it is now a proper subcomponent.

self.population_view.update(pop)


class ChildrenBirthExposure(Component):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This component also just moves where the gestational age and birthweight columns are being created.

GESTATIONAL_AGE = "gestational_age"


class LBWSGDistribution(LBWSGDistribution_):
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These components are so we use the correct columns to do lookup for birth exposure.

excluded_stratifications=self.config.exclude,
when="time_step__prepare",
)
# Add observer to get paf for preterm birth population
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adds an additional observer for a special preterm "PAF"

# Register csmr pipeline
self.csmr = builder.value.register_value_producer(
f"cause.{self.neonatal_cause}.cause_specific_mortality_rate",
f"{self.neonatal_cause}.cause_specific_mortality_rate",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THis is why relative risks were not being applied to the CSMR pipeline.

pop = self.population_view.get(index)
ga_greater_than_37 = pop[COLUMNS.GESTATIONAL_AGE] >= 37

normalized_csmr = super().get_normalized_csmr(index)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New math

Comment on lines 90 to 93
if self._sim_step_name() == SIMULATION_EVENT_NAMES.EARLY_NEONATAL_MORTALITY:
pop.loc[alive_children.index, COLUMNS.CHILD_AGE] = (7 / 2) / 365.0
else:
pop.loc[alive_children.index, COLUMNS.CHILD_AGE] = ((28 - 7) / 2) / 365.0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slightly more pythonic:

Suggested change
if self._sim_step_name() == SIMULATION_EVENT_NAMES.EARLY_NEONATAL_MORTALITY:
pop.loc[alive_children.index, COLUMNS.CHILD_AGE] = (7 / 2) / 365.0
else:
pop.loc[alive_children.index, COLUMNS.CHILD_AGE] = ((28 - 7) / 2) / 365.0
age_group_midpoints = {
SIMULATION_EVENT_NAMES.EARLY_NEONATAL_MORTALITY: (7 / 2) / 365.0,
SIMULATION_EVENT_NAMES.LATE_NEONATAL_MORTALITY: (7 + (28 - 7) / 2) / 365.0,
}
pop.loc[alive_children.index, COLUMNS.CHILD_AGE] = age_group_midpoints[self._sim_step_name()]

return [self.gestational_age, self.birth_weight]

def setup(self, builder: Builder) -> None:
# todo get the lbwsg value pipelines

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this todo be removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

@property
def columns_created(self) -> list[str]:
return [
COLUMNS.GESTATIONAL_AGE,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still have multiple columns for gestational age and birth weight?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. One is the birth exposure columns that come from the pipeline and then these that are just gestational age and birth weight. I'm not sure why the NO project initialized these columns separately but I assume it is so we can put some effect on simulants and see if that changes these values from the pipelien.

@albrja albrja merged commit 3a1f0f2 into main Mar 13, 2025
7 checks passed
@albrja albrja deleted the bugfix/refactor-pregnancy branch March 13, 2025 16:39
pletale pushed a commit that referenced this pull request Aug 5, 2025
Bugfix/LBWSGRiskEffect

Fixes issues when subclassing LBWSG
- *Category*: Bugfix
- *JIRA issue*: https://jira.ihme.washington.edu/browse/MIC-5894
- *Research reference*: <!--Link to research documentation for code -->

Changes and notes
-refactors preganncy
-fixes bug when subclassing LBWSG
-fixes pipeline names

### Verification and Testing
<!--
Details on how code was verified. Consider: plots, images, (small) csv files.
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants