Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert excel files to csv files. Joe's modules #1508

Merged
merged 18 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions resources/ResourceFile_AntenatalCare.xlsx

This file was deleted.

3 changes: 3 additions & 0 deletions resources/ResourceFile_AntenatalCare/parameter_values.csv
Git LFS file not shown
3 changes: 0 additions & 3 deletions resources/ResourceFile_LabourSkilledBirthAttendance.xlsx

This file was deleted.

Git LFS file not shown
3 changes: 0 additions & 3 deletions resources/ResourceFile_NewbornOutcomes.xlsx

This file was deleted.

3 changes: 3 additions & 0 deletions resources/ResourceFile_NewbornOutcomes/parameter_values.csv
Git LFS file not shown
3 changes: 0 additions & 3 deletions resources/ResourceFile_PostnatalSupervisor.xlsx

This file was deleted.

Git LFS file not shown
3 changes: 0 additions & 3 deletions resources/ResourceFile_PregnancySupervisor.xlsx

This file was deleted.

Git LFS file not shown
3 changes: 0 additions & 3 deletions resources/contraception/ResourceFile_Contraception.xlsx

This file was deleted.

Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
2 changes: 1 addition & 1 deletion src/scripts/contraception/f_steril_use_2010vs2020.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
A helper script to see the numbers of women of reproductive age having female sterilisation per 5-years age categories +
total, and the number of all women in the population in 2010 and 2020, to help to calibrate the intervention multipliers
(saved in ResourceFile_Contraception.xlsx in the sheets Interventions_Pop & Interventions_PPFP).
(saved in ResourceFile_Contraception folder in the Interventions_Pop & Interventions_PPFP CSV files).
"""
from pathlib import Path

Expand Down
5 changes: 3 additions & 2 deletions src/tlo/methods/care_of_women_during_pregnancy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from tlo.methods.labour import LabourOnsetEvent
from tlo.methods.malaria import HSI_MalariaIPTp
from tlo.methods.tb import HSI_Tb_ScreeningAndRefer
from tlo.util import read_csv_files

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
Expand Down Expand Up @@ -176,8 +177,8 @@ def __init__(self, name=None, resourcefilepath=None):
}

def read_parameters(self, data_folder):
parameter_dataframe = pd.read_excel(Path(self.resourcefilepath) / 'ResourceFile_AntenatalCare.xlsx',
sheet_name='parameter_values')
parameter_dataframe = read_csv_files(Path(self.resourcefilepath) / 'ResourceFile_AntenatalCare',
files=['parameter_values'])
self.load_parameters_from_dataframe(parameter_dataframe)

def initialise_population(self, population):
Expand Down
10 changes: 5 additions & 5 deletions src/tlo/methods/contraception.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from tlo.analysis.utils import flatten_multi_index_series_into_dict_for_logging
from tlo.events import Event, IndividualScopeEventMixin, PopulationScopeEventMixin, RegularEvent
from tlo.methods.hsi_event import HSI_Event
from tlo.util import random_date, sample_outcome, transition_states
from tlo.util import random_date, read_csv_files, sample_outcome, transition_states

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
Expand Down Expand Up @@ -164,7 +164,7 @@ def read_parameters(self, data_folder):
"""Import the relevant sheets from the ResourceFile (excel workbook) and declare values for other parameters
(CSV ResourceFile).
"""
workbook = pd.read_excel(Path(self.resourcefilepath) / 'contraception' / 'ResourceFile_Contraception.xlsx', sheet_name=None)
workbook = read_csv_files(Path(self.resourcefilepath) / 'contraception' / 'ResourceFile_Contraception')

# Import selected sheets from the workbook as the parameters
sheet_names = [
Expand Down Expand Up @@ -1346,10 +1346,10 @@ def __init__(self, *args):
super().__init__(name='Labour')

def read_parameters(self, *args):
parameter_dataframe = pd.read_excel(self.sim.modules['Contraception'].resourcefilepath /
parameter_dataframe = read_csv_files(self.sim.modules['Contraception'].resourcefilepath /
'contraception' /
'ResourceFile_Contraception.xlsx',
sheet_name='simplified_labour_parameters')
'ResourceFile_Contraception',
files=['simplified_labour_parameters'])
self.load_parameters_from_dataframe(parameter_dataframe)

def initialise_population(self, population):
Expand Down
8 changes: 4 additions & 4 deletions src/tlo/methods/labour.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from tlo.methods.hsi_event import HSI_Event
from tlo.methods.hsi_generic_first_appts import GenericFirstAppointmentsMixin
from tlo.methods.postnatal_supervisor import PostnatalWeekOneMaternalEvent
from tlo.util import BitsetHandler
from tlo.util import BitsetHandler, read_csv_files

if TYPE_CHECKING:
from tlo.methods.hsi_generic_first_appts import HSIEventScheduler
Expand Down Expand Up @@ -620,9 +620,9 @@ def __init__(self, name=None, resourcefilepath=None):
}

def read_parameters(self, data_folder):
parameter_dataframe = pd.read_excel(Path(self.resourcefilepath) / 'ResourceFile_LabourSkilledBirth'
'Attendance.xlsx',
sheet_name='parameter_values')
parameter_dataframe = read_csv_files(Path(self.resourcefilepath) / 'ResourceFile_LabourSkilledBirth'
'Attendance',
files=['parameter_values'])
self.load_parameters_from_dataframe(parameter_dataframe)

def initialise_population(self, population):
Expand Down
6 changes: 3 additions & 3 deletions src/tlo/methods/newborn_outcomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from tlo.methods.causes import Cause
from tlo.methods.hsi_event import HSI_Event
from tlo.methods.postnatal_supervisor import PostnatalWeekOneNeonatalEvent
from tlo.util import BitsetHandler
from tlo.util import BitsetHandler, read_csv_files

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
Expand Down Expand Up @@ -311,8 +311,8 @@ def __init__(self, name=None, resourcefilepath=None):

def read_parameters(self, data_folder):

parameter_dataframe = pd.read_excel(Path(self.resourcefilepath) / 'ResourceFile_NewbornOutcomes.xlsx',
sheet_name='parameter_values')
parameter_dataframe = read_csv_files(Path(self.resourcefilepath) / 'ResourceFile_NewbornOutcomes',
files=['parameter_values'])
self.load_parameters_from_dataframe(parameter_dataframe)

# Here we map 'disability' parameters to associated DALY weights to be passed to the health burden module
Expand Down
5 changes: 3 additions & 2 deletions src/tlo/methods/postnatal_supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from tlo.methods import Metadata, postnatal_supervisor_lm, pregnancy_helper_functions
from tlo.methods.causes import Cause
from tlo.methods.hsi_event import HSI_Event
from tlo.util import read_csv_files

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
Expand Down Expand Up @@ -230,8 +231,8 @@ def __init__(self, name=None, resourcefilepath=None):
}

def read_parameters(self, data_folder):
parameter_dataframe = pd.read_excel(Path(self.resourcefilepath) / 'ResourceFile_PostnatalSupervisor.xlsx',
sheet_name='parameter_values')
parameter_dataframe = read_csv_files(Path(self.resourcefilepath) / 'ResourceFile_PostnatalSupervisor',
files=['parameter_values'])
self.load_parameters_from_dataframe(parameter_dataframe)

def initialise_population(self, population):
Expand Down
6 changes: 3 additions & 3 deletions src/tlo/methods/pregnancy_supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
)
from tlo.methods.causes import Cause
from tlo.methods.hsi_generic_first_appts import GenericFirstAppointmentsMixin
from tlo.util import BitsetHandler
from tlo.util import BitsetHandler, read_csv_files

if TYPE_CHECKING:
from tlo.methods.hsi_generic_first_appts import HSIEventScheduler
Expand Down Expand Up @@ -434,8 +434,8 @@ def __init__(self, name=None, resourcefilepath=None):

def read_parameters(self, data_folder):
# load parameters from the resource file
parameter_dataframe = pd.read_excel(Path(self.resourcefilepath) / 'ResourceFile_PregnancySupervisor.xlsx',
sheet_name='parameter_values')
parameter_dataframe = read_csv_files(Path(self.resourcefilepath) / 'ResourceFile_PregnancySupervisor',
files=['parameter_values'])
self.load_parameters_from_dataframe(parameter_dataframe)

# Here we map 'disability' parameters to associated DALY weights to be passed to the health burden module.
Expand Down
4 changes: 3 additions & 1 deletion src/tlo/methods/simplified_births.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from tlo import DateOffset, Module, Parameter, Property, Types, logging
from tlo.events import PopulationScopeEventMixin, RegularEvent
from tlo.methods.contraception import get_medium_variant_asfr_from_wpp_resourcefile
from tlo.util import read_csv_files

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
Expand Down Expand Up @@ -111,7 +112,8 @@ def read_parameters(self, data_folder):
self.parameters['months_between_pregnancy_and_delivery'] = 9

# Breastfeeding status for newborns (importing from the Newborn resourcefile)
rf = pd.read_excel(Path(self.resourcefilepath) / 'ResourceFile_NewbornOutcomes.xlsx')
# pylint: disable=E1101
rf = read_csv_files(Path(self.resourcefilepath) / 'ResourceFile_NewbornOutcomes')
param_as_string = rf.loc[rf.parameter_name == 'prob_breastfeeding_type']['value'].iloc[0]
parameter = json.loads(param_as_string)[0]
self.parameters['prob_breastfeeding_type'] = parameter
Expand Down
5 changes: 3 additions & 2 deletions tests/test_contraception.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from tlo.methods import contraception, demography, enhanced_lifestyle, healthsystem, symptommanager
from tlo.methods.contraception import HSI_Contraception_FamilyPlanningAppt
from tlo.methods.hiv import DummyHivModule
from tlo.util import read_csv_files


def run_sim(tmpdir,
Expand Down Expand Up @@ -918,8 +919,8 @@ def test_input_probs_sum():

# Import relevant sheets from the workbook
resourcefilepath = Path(os.path.dirname(__file__)) / '../resources'
workbook = pd.read_excel(Path(resourcefilepath) / 'contraception' / 'ResourceFile_Contraception.xlsx',
sheet_name=None)
workbook = read_csv_files(Path(resourcefilepath) / 'contraception' / 'ResourceFile_Contraception',
files=None)
sheet_names = [
'Initiation_ByMethod',
'Interventions_Pop',
Expand Down