-
Notifications
You must be signed in to change notification settings - Fork 32
/
analyzer_W1.py
95 lines (70 loc) · 3.81 KB
/
analyzer_W1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import os
import datetime
import pandas as pd
import numpy as np
import sys
import re
import random
from idmtools.entities import IAnalyzer
from idmtools.entities.simulation import Simulation
import manifest
## For plotting
import matplotlib.pyplot as plt
import matplotlib as mpl
import matplotlib.dates as mdates
class SimpleInsetChartAnalyzer(IAnalyzer):
@classmethod
def monthparser(self, x):
if x == 0:
return 12
else:
return datetime.datetime.strptime(str(x), '%j').month
def __init__(self, expt_name, working_dir=".", start_year=0):
super(SimpleInsetChartAnalyzer, self).__init__(working_dir=working_dir, filenames=["output/InsetChart.json"])
self.expt_name = expt_name
self.start_year = start_year
self.inset_channels = ["30-day Avg Infection Duration", "Adult Vectors", "Air Temperature", "Avg Num Infections",
"Births", "Blood Smear Gametocyte Prevalence", "Blood Smear Parasite Prevalence", "Campaign Cost",
"Daily Bites per Human", "Daily EIR", "Disease Deaths", "Fever Prevalence", "Human Infectious Reservoir",
"Infected", "Infectious Vectors", "Log Prevalence", "Mean Parasitemia", "New Clinical Cases",
"New Infections", "New Severe Cases", "Newly Symptomatic", "PCR Gametocyte Prevalence",
"PCR Parasite Prevalence", "PfHRP2 Prevalence", "Rainfall", "Relative Humidity", "Statistical Population",
"Symptomatic Population", "True Prevalence", "Variant Fraction-PfEMP1 Major"]
def map(self, data, simulation: Simulation):
simdata = pd.DataFrame({x: data[self.filenames[0]]['Channels'][x]['Data'] for x in self.inset_channels})
simdata['Time'] = simdata.index
simdata['Day'] = simdata['Time'] % 365
simdata['Year'] = simdata['Time'].apply(lambda x: int(x / 365) + self.start_year)
simdata['date'] = simdata.apply(
lambda x: datetime.date(int(x['Year']), 1, 1) + datetime.timedelta(int(x['Day']) - 1), axis=1)
return simdata
def reduce(self, all_data):
selected = [data for sim, data in all_data.items()]
if len(selected) == 0:
print("No data have been returned... Exiting...")
return
if not os.path.exists(os.path.join(self.working_dir, self.expt_name)):
os.mkdir(os.path.join(self.working_dir, self.expt_name))
adf = pd.concat(selected).reset_index(drop=True)
adf.to_csv(os.path.join(self.working_dir, self.expt_name, 'All_Age_InsetChart.csv'), index=False)
if __name__ == "__main__":
from idmtools.analysis.analyze_manager import AnalyzeManager
from idmtools.core import ItemType
from idmtools.core.platform_factory import Platform
expts = {
'example_basic' : 'd6992a9f-bc38-4162-9e27-177adfc906c5' ba4ac1da-332a-4c5f-b902-11520709d795
}
jdir = manifest.job_directory
wdir = os.path.join(jdir, 'my_outputs')
if not os.path.exists(wdir):
os.mkdir(wdir)
with Platform('SLURM_LOCAL',job_directory=jdir) as platform:
for expt_name, exp_id in expts.items():
analyzer = [SimpleInsetChartAnalyzer(expt_name=expt_name,
start_year = 2023,
working_dir=wdir)]
# Create AnalyzerManager with required parameters
manager = AnalyzeManager(configuration={}, ids=[(exp_id, ItemType.EXPERIMENT)],
analyzers=analyzer, partial_analyze_ok=True)
# Run analyze
manager.analyze()