Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 87560a5e authored by GUYET Thomas's avatar GUYET Thomas
Browse files

update scripts for DB generation with new repos (+ blacked)

parent 5fa4e4b4
Branches
No related tags found
No related merge requests found
......@@ -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")
......@@ -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")
......@@ -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")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment