Skip to content

Commit 982a047

Browse files
committed
issues fixed
1 parent 870a640 commit 982a047

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

compliance_checker.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def files_and_subdirectories(path):
9393
directories = []
9494
for f in os.listdir(path):
9595
if os.path.isfile(os.path.join(path, f)):
96-
files.append(f)
96+
files.append(f)
9797
elif os.path.isdir(os.path.join(path, f)):
9898
directories.append(f)
9999
return directories, files
@@ -202,10 +202,15 @@ def strictly_increasing(L):
202202
temp_mandatory_var.remove(variable)
203203
#split the experiment directory name
204204
experiment_chain = xp.split('_')
205-
#get the experiment name (example: exp05)
206-
experiment_name = '_'.join(experiment_chain[:-1])
207-
#get the resolution as integer
208-
grid_resolution = int(experiment_chain[-1])
205+
if len(experiment_chain) == 2 :
206+
#get the experiment name (example: exp05)
207+
experiment_name = '_'.join(experiment_chain[:-1])
208+
#get the resolution as integer
209+
grid_resolution = int(experiment_chain[-1])
210+
else:
211+
experiment_name = xp
212+
grid_resolution = 0
213+
print('Error in the naming of the experiment ',xp,'. Should be similar to expXXX_RES')
209214

210215
if experiment_name in [dic['experiment'] for dic in experiments]:
211216
f.write('\n ')
@@ -325,7 +330,7 @@ def strictly_increasing(L):
325330
if False in ds[ivar].isnull():
326331
# check the min value
327332
if ds[ivar].min(skipna=True).item()>=ismip_meta[var_index[0]]['min_value_'+region.lower()]:
328-
f.write(' - The minimum value successfully verified.\n')
333+
f.write(' - The minimum value successfully verified.\n')
329334
else:
330335
f.write(' - ERROR: The minimum value (' + str(ds[ivar].min(skipna=True).values.item(0)) + ') is out of range. Min value accepted: ' + str(ismip_meta[var_index[0]]['min_value_'+region.lower()])+'\n')
331336
var_num_errors += 1
@@ -381,7 +386,7 @@ def strictly_increasing(L):
381386
iteration = len(ds.coords['time'])
382387
start_exp = min(ds['time']).values.astype("datetime64[D]")
383388
end_exp = max(ds['time']).values.astype("datetime64[D]")
384-
avgyear = 365.2425 # pedants definition of a year length with leap years
389+
avgyear = 365 # pedants definition of a year length with leap years
385390
duration_days = (end_exp - start_exp)
386391
duration_years = duration_days.astype('timedelta64[Y]')/np.timedelta64(1,'Y')
387392

@@ -423,10 +428,10 @@ def strictly_increasing(L):
423428
if experiments[index_exp]['endinf'] <= dateformat_end_exp <= experiments[index_exp]['endsup']:
424429
f.write(' - Experiment ends correctly on ' + end_exp.item().strftime('%Y-%m-%d') + '.\n')
425430
else:
426-
f.write(' - ERROR: the experiment ends on ' + end_exp.item() + '. The date should be comprised between ' + experiments[index_exp]['endinf'].strftime('%Y-%m-%d') + ' and ' + experiments[index_exp]['endsup'].strftime('%Y-%m-%d')+'\n')
431+
f.write(' - ERROR: the experiment ends on ' + end_exp.item().strftime('%Y-%m-%d') + '. The date should be comprised between ' + experiments[index_exp]['endinf'].strftime('%Y-%m-%d') + ' and ' + experiments[index_exp]['endsup'].strftime('%Y-%m-%d')+'\n')
427432
var_time_errors += 1
428433
else:
429-
end_date = start_exp + datetime.timedelta(days = experiments[index_exp]['duration']*avgyear)
434+
end_date = start_exp + np.timedelta64(experiments[2]['duration']*365,'D')
430435
f.write(' - ERROR: the experiment lasts ' + str(duration_years) + ' years. The duration should be ' + str(experiments[index_exp]['duration']) + ' years\n')
431436
f.write(' - As the experiment started on ' + start_exp.item().strftime('%Y-%m-%d') + ' , it should end on '+ end_date.item().strftime('%Y-%m-%d')+'\n')
432437
var_time_errors += 1
@@ -570,6 +575,6 @@ def strictly_increasing(L):
570575
with open(os.path.join(source_path,'compliance_checker_log.txt'), "w") as f:
571576
f.writelines(contents)
572577

573-
except TypeError:
574-
print('Something went wrong with your dataset. Please, check your file(s) carrefully.')
578+
except TypeError as err:
579+
print('Something went wrong with your dataset. Please, check your file(s) carrefully. Erreur :', err)
575580

0 commit comments

Comments
 (0)