diff --git a/Models/AVC/generate_avcdataset.py b/Models/AVC/generate_avcdataset.py index 7760f7b89153271044a28bb7d73a39f3c38b72f5..9ee3d4e9997ea846059b1a94474857f7a7fcd368 100644 --- a/Models/AVC/generate_avcdataset.py +++ b/Models/AVC/generate_avcdataset.py @@ -44,7 +44,7 @@ population.rename(columns={"index": "id"}, inplace=True) ###### Assign an AVC status -pAVC, pTA = pickle.load(open("AVCGenerator/ptavc.pkl", "rb")) +pAVC, pTA = pickle.load(open("Models/AVC/ptavc.pkl", "rb")) pAVC["sex"] = (pAVC["gender"] == "F").astype("int") + 1 # transform the age into intervals matching the ones of pTAVC @@ -59,7 +59,7 @@ population = pd.merge( )[["id", "age", "sex", "dpt", "code", "RR", "city_name", "p"]] -population["avc"] = population["p"] > np.random.rand(len(population["p"])) +population["avc"] = population["p"] > np.random.rand(len(population["p"])) population["type"] = np.random.choice( pTA["type"], p=pTA["p"], size=len(population["p"]) ) @@ -72,7 +72,7 @@ population.loc[population.avc == True, "date_avc"] = [ ] -mortality_laws = pickle.load(open("AVCGenerator/mortality_weibull_params.pkl", "rb")) +mortality_laws = pickle.load(open("Models/AVC/mortality_weibull_params.pkl", "rb")) # mortality_laws[['age','sex','type','k','lambda']] mortality_laws.set_index(["age", "sex", "type"], inplace=True) # ,'k','lambda']] @@ -139,10 +139,10 @@ simulator.run() # create a context with the default nomenclature DB # context = OpenDataFactoryContext("datarep/snds_nomenclature.db", datarep="../datarep") -#generate the patients +# generate the patients factory = PatientFactory(simulator.context, simulator.GPs) -attribute_map={'sex':'sex', 'age':'age', 'dc_date':"deathdate", 'dc_cause':'type'} -patients=factory.load(population, attribute_map) +attribute_map = {"sex": "sex", "age": "age", "dc_date": "deathdate", "dc_cause": "type"} +patients = factory.load(population, attribute_map) ########################################## @@ -218,7 +218,10 @@ def generate_drugs(x): loc_drugs["patient"] = np.random.choice(indices, size=len(loc_drugs)) # random dates - loc_drugs['date']=[np.datetime64("2022-01-01") + np.timedelta64(e, "D") for e in np.random.randint(size=len(loc_drugs), low=0, high=365)] + loc_drugs["date"] = [ + np.datetime64("2022-01-01") + np.timedelta64(e, "D") + for e in np.random.randint(size=len(loc_drugs), low=0, high=365) + ] return loc_drugs @@ -247,7 +250,10 @@ simu = { "data": hosps, "attributes": {"pid": "id", "cim": "type", "date": "date_avc"}, }, - "drugs": {"data": drugs, "attributes": {"pid": "patient", "cip": "CIP13", 'date':'date'}}, + "drugs": { + "data": drugs, + "attributes": {"pid": "patient", "cip": "CIP13", "date": "date"}, + }, } simulator.load(simu) @@ -275,5 +281,5 @@ for p in simulator.patients: injector.injection(p) dbgen = simDB() -dbgen.output_db_name = "AVCGenerator/snds_testgen.db" +dbgen.output_db_name = "Models/AVC/snds_testgen.db" dbgen.generate(simulator, rootschemas="schema-snds/schemas") diff --git a/Models/AVC/generate_eins.py b/Models/AVC/generate_eins.py index f0bb0f2e229519de24573448c3c5b6db8998a05b..6c0025c6f6db259981031184798edbf89d9ae06f 100644 --- a/Models/AVC/generate_eins.py +++ b/Models/AVC/generate_eins.py @@ -44,7 +44,7 @@ population.rename(columns={"index": "id"}, inplace=True) ###### Assign an AVC status -pAVC, pTA = pickle.load(open("AVCGenerator/ptavc.pkl", "rb")) +pAVC, pTA = pickle.load(open("Models/AVC/ptavc.pkl", "rb")) pAVC["sex"] = (pAVC["gender"] == "F").astype("int") + 1 # transform the age into intervals matching the ones of pTAVC @@ -59,7 +59,7 @@ population = pd.merge( )[["id", "age", "sex", "dpt", "code", "RR", "city_name", "p"]] -population["avc"] = population["p"] > np.random.rand(len(population["p"])) +population["avc"] = population["p"] > np.random.rand(len(population["p"])) population["type"] = np.random.choice( pTA["type"], p=pTA["p"], size=len(population["p"]) ) @@ -72,8 +72,8 @@ population.loc[population.avc == True, "date_avc"] = [ ] ######################## -#uniform generation of genepi population (with strokes) -population["genepi"] = np.random.rand(len(population))<(1000/taille_pop) +# uniform generation of genepi population (with strokes) +population["genepi"] = np.random.rand(len(population)) < (1000 / taille_pop) nbgenepi = len(population.loc[population.genepi == True]) population.loc[population.genepi == True, "date_genepi"] = [ np.datetime64("2022-01-01") + np.timedelta64(e, "D") @@ -82,7 +82,7 @@ population.loc[population.genepi == True, "date_genepi"] = [ ######################## -mortality_laws = pickle.load(open("AVCGenerator/mortality_weibull_params.pkl", "rb")) +mortality_laws = pickle.load(open("Models/AVC/mortality_weibull_params.pkl", "rb")) # mortality_laws[['age','sex','type','k','lambda']] mortality_laws.set_index(["age", "sex", "type"], inplace=True) # ,'k','lambda']] @@ -149,10 +149,10 @@ simulator.run() # create a context with the default nomenclature DB # context = OpenDataFactoryContext("datarep/snds_nomenclature.db", datarep="../datarep") -#generate the patients +# generate the patients factory = PatientFactory(simulator.context, simulator.GPs) -attribute_map={'sex':'sex', 'age':'age', 'dc_date':"deathdate", 'dc_cause':'type'} -patients=factory.load(population, attribute_map) +attribute_map = {"sex": "sex", "age": "age", "dc_date": "deathdate", "dc_cause": "type"} +patients = factory.load(population, attribute_map) ########################################## @@ -213,7 +213,10 @@ def generate_drugs(x): loc_drugs["patient"] = np.random.choice(indices, size=len(loc_drugs)) # random dates - loc_drugs['date']=[np.datetime64("2022-01-01") + np.timedelta64(e, "D") for e in np.random.randint(size=len(loc_drugs), low=0, high=365)] + loc_drugs["date"] = [ + np.datetime64("2022-01-01") + np.timedelta64(e, "D") + for e in np.random.randint(size=len(loc_drugs), low=0, high=365) + ] return loc_drugs @@ -223,10 +226,10 @@ drugs = pd.concat(res.to_list()) hosps = population[["id", "type", "date_avc"]].dropna() # Add hospitalisation for epileptic patients -hosps_genepi=population[["id", "date_genepi"]].dropna() -hosps_genepi['type']=np.random.choice(["G40", "G41"], size=len(hosps_genepi)) -hosps_genepi=hosps_genepi.rename( columns={'date_genepi': 'date_avc'} ) -hosps=pd.concat([hosps, hosps_genepi]) +hosps_genepi = population[["id", "date_genepi"]].dropna() +hosps_genepi["type"] = np.random.choice(["G40", "G41"], size=len(hosps_genepi)) +hosps_genepi = hosps_genepi.rename(columns={"date_genepi": "date_avc"}) +hosps = pd.concat([hosps, hosps_genepi]) ################################################################# ################################################################ @@ -247,7 +250,10 @@ simu = { "data": hosps, "attributes": {"pid": "id", "cim": "type", "date": "date_avc"}, }, - "drugs": {"data": drugs, "attributes": {"pid": "patient", "cip": "CIP13", 'date':'date'}}, + "drugs": { + "data": drugs, + "attributes": {"pid": "patient", "cip": "CIP13", "date": "date"}, + }, } simulator.load(simu) @@ -277,5 +283,5 @@ for p in simulator.patients: injector_genepi.injection(p) dbgen = simDB() -dbgen.output_db_name = "AVCGenerator/snds_testgen.db" +dbgen.output_db_name = "Models/AVC/snds_testgen.db" dbgen.generate(simulator, rootschemas="schema-snds/schemas") diff --git a/Models/VICAN/Simu_VICAN.py b/Models/VICAN/Simu_VICAN.py index 98542c6108f83fa145b475bd3b20f4c4dbc8f42e..8ad846dfe40dd179860daf786e510b0e13607f5c 100644 --- a/Models/VICAN/Simu_VICAN.py +++ b/Models/VICAN/Simu_VICAN.py @@ -155,5 +155,5 @@ for P in [P1, P2, P3, P4, P5, P6, P7, P8, P9, P10]: p.injection(patient) dbgen = simDB() -dbgen.output_db_name = "Marie/snds_testgen.db" +dbgen.output_db_name = "Models/VICAN/snds_testgen.db" dbgen.generate(simulator, rootschemas="schema-snds/schemas")