Skip to content

Commit 494976d

Browse files
authored
Merge pull request #46 from CIAT-DAPA/develop
implemented changes on prediction_class.py
2 parents 0c82f17 + 2364cf0 commit 494976d

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/aclimate_cpt/prediction_class.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,31 @@ def run_master(self):
11781178
dir_names = os.listdir(self.path_inputs_monthly_stations)
11791179
#path_json = glob.glob(f"{self.path_inputs_monthly_stations}\\**\\cpt_areas.json", recursive = True)
11801180
path_json = glob.glob(os.path.join(self.path_inputs_monthly_stations, '**', 'cpt_areas.json'), recursive=True)
1181+
path_stations = glob.glob(os.path.join(self.path_inputs_monthly_stations, '**', 'stations.csv'), recursive=True)
11811182
init_params = {k: self.load_json(pth) for k,pth in zip(dir_names, path_json)}
1183+
#sacar del analisis departamentos donde el cpt_areas.json no tenga nada
1184+
items_lgth = {k: sum([len(x["areas"]) for x in val]) for k,val in init_params.items()}
1185+
empty_dpt = [k for k,v in items_lgth.items() if v == 0]
1186+
lgth_list = [v for k,v in items_lgth.items()]
1187+
bool_lgth = [x == 0 for x in lgth_list]
1188+
1189+
if len(empty_dpt) >0:
1190+
Warning("Empty areas.json file found")
1191+
for idx in range(len(items_lgth)):
1192+
if lgth_list[idx] == 0:
1193+
dir_names.pop(idx)
1194+
path_json.pop(idx)
1195+
path_stations.pop(idx)
1196+
for nm in empty_dpt:
1197+
init_params.pop(nm)
1198+
1199+
if all(bool_lgth):
1200+
raise ValueError("departments has ares.json file empty")
1201+
1202+
1203+
1204+
1205+
11821206
month_abb = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
11831207
ext_exe = ".bat"
11841208

@@ -1250,7 +1274,7 @@ def run_master(self):
12501274
print("\n Archivos de entrada cargados")
12511275

12521276
#path_stations = glob.glob(f"{self.path_inputs_monthly_stations}\\**\\stations.csv", recursive = True)
1253-
path_stations = glob.glob(os.path.join(self.path_inputs_monthly_stations, '**', 'stations.csv'), recursive=True)
1277+
12541278
data_y = {k: pd.read_csv(fl) for k,fl in zip(dir_names, path_stations)}
12551279
part_id = {k: self.files_y(df, k, main_dir = self.path_inputs_prediccion) for k,df in data_y.items()}
12561280

0 commit comments

Comments
 (0)