Skip to content

Commit 9fe54d8

Browse files
committed
remove dpt with .json data not available
1 parent cd275ba commit 9fe54d8

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/aclimate_cpt/01_prediccion.py

+23-6
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ def cpt_merge_x_files(file_paths):
10991099

11001100
merged_out_path = re.sub("[a-zA-Z]+.tsv", "merged.tsv", file_path_1 )
11011101

1102-
tmp_file = re.sub("[a-zA-Z]+.tsv", "batch.bat", file_path_1 )
1102+
tmp_file = re.sub("[a-zA-Z]+.tsv", "batch.bat", file_path_1 )
11031103

11041104
# argumentos para el batch
11051105
if platform.system() == "Windows":
@@ -1142,7 +1142,7 @@ def cpt_merge_x_files(file_paths):
11421142

11431143

11441144
# verificacion de que se creó el archivo tempora;l
1145-
if not os.path.exists(tmp_file):
1145+
if not os.path.exists(merged_out_path):
11461146
status = "Failed: Error en la creación del archivo temporal"
11471147
else:
11481148
# copia del archivo a merged out path
@@ -1158,6 +1158,7 @@ def cpt_merge_x_files(file_paths):
11581158
status = "Failed: Error al ejecutar CPT_batch for merging"
11591159

11601160

1161+
11611162
return status
11621163

11631164

@@ -1174,7 +1175,7 @@ def cpt_merge_x_files(file_paths):
11741175
#########################################################
11751176
print(os.path.join("D:/", "andres"))
11761177
#define some global variables (some paths should be already defined in runMain so may not be necesary here)
1177-
root_dir = os.path.join("D:"+os.sep, "documents_andres", "pr_r", "Colombia","inputs")
1178+
root_dir = os.path.join("D:"+os.sep, "documents_andres", "pr_descarga", "Colombia","inputs")
11781179
main_dir = os.path.join(root_dir, "prediccionClimatica")
11791180
path_dpto = os.path.join(main_dir, 'estacionesMensuales')#dir_response
11801181
dir_save = os.path.join(main_dir, "descarga") #paste0(dirPrediccionInputs, "descarga", sep = "", collapse = NULL)
@@ -1203,22 +1204,38 @@ def cpt_merge_x_files(file_paths):
12031204

12041205

12051206
dir_names = os.listdir(path_dpto)
1207+
path_stations = glob.glob(f"{path_dpto}\\**\\stations.csv", recursive = True)
12061208
path_json = glob.glob(f"{path_dpto}\\**\\cpt_areas.json", recursive = True)
12071209
init_params = {k: load_json(pth) for k,pth in zip(dir_names, path_json)}
12081210

1211+
#sacar del analisis departamentos donde el cpt_areas.json no tenga nada
1212+
items_lgth = {k: sum([len(x["areas"]) for x in val]) for k,val in init_params.items()}
1213+
empty_dpt = [k for k,v in items_lgth.items() if v == 0]
1214+
lgth_list = [v for k,v in items_lgth.items()]
1215+
if len(empty_dpt) >0:
1216+
for idx in range(len(items_lgth)):
1217+
if lgth_list[idx] == 0:
1218+
dir_names.pop(idx)
1219+
path_json.pop(idx)
1220+
path_stations.pop(idx)
1221+
for nm in empty_dpt:
1222+
init_params.pop(nm)
1223+
1224+
1225+
1226+
12091227
month = int(date.today().strftime("%m"))
12101228
year = int(date.today().strftime("%Y"))
12111229
season = {k: [x["season"] for x in val if len(x['areas'] )!= 0] for k,val in init_params.items()}
12121230
month_season = {k: [get_season_months(x["season"], month_abb = month_abb) for x in val if len(x['areas'] )!= 0] for k,val in init_params.items()}
12131231
predictands = {k: [x["predictand"] for x in val if len(x['areas'] )!= 0] for k,val in init_params.items()}
12141232
predictors = {k: [ len(np.unique(pd.DataFrame(x["areas"])["predictor"].to_numpy().tolist())) for x in val if len(x['areas'] )!= 0] for k,val in init_params.items()}
12151233

1234+
#list_elements = [len(x) for x in predictands.values()]
12161235

12171236

12181237
start_date = date.today()+ timedelta(days = 30)
12191238
years = {k: get_season_years(season_type = value[0]["type"], month = month, year = year) for k,value in init_params.items()}
1220-
{k: value[0]['type'] for k,value in init_params.items()}
1221-
12221239

12231240
path_months_l = {x: os.path.join(main_dir, "run_CPT", x) for x in dir_names}
12241241
for ky,pth in path_months_l.items():
@@ -1275,7 +1292,7 @@ def cpt_merge_x_files(file_paths):
12751292

12761293
print("\n Archivos de entrada cargados")
12771294

1278-
path_stations = glob.glob(f"{path_dpto}\\**\\stations.csv", recursive = True)
1295+
12791296
data_y = {k: pd.read_csv(fl) for k,fl in zip(dir_names, path_stations)}
12801297
part_id = {k: files_y(df, k, main_dir = main_dir) for k,df in data_y.items()}
12811298

0 commit comments

Comments
 (0)