Commit 0d6208ef authored by Jean Matthieu Haussaire's avatar Jean Matthieu Haussaire
Browse files

Change print to verbose. Fix a tiny bug where a warning message was wrongfully...

Change print to verbose. Fix a tiny bug where a warning message was wrongfully printed due to some wrong index. Improve the reading of the stations in the rodenbeck file
parent d055a51d
......@@ -13,7 +13,7 @@ from netCDF4 import Dataset
from . import flexpart_header
from . import mod_flexpart
from pycif.utils.dates import j2d
from pycif.utils.check import verbose
def read_flexpart_dir(subdir, nested=True, **kwargs):
""" Reads all FLEXPART grid_time files from a directory
......@@ -118,9 +118,9 @@ def read_grid_nc(path_file, file_dates, fp_header):
#spec001 has dimension nageclass, numpoint, time, level, lat, lon
# Assume that there is 1 numpoint/station per file
shape = nc['spec001'].shape
if shape[0]>0 or shape[1]>0:
if shape[0]>1 or shape[1]>1:
verbose('WARNING: There are more than 1 station in the flexpart file.')
if shape[3]>0:
if shape[3]>1:
verbose('INFO: Select the bottom layer of the grid')
grid = nc['spec001'][0,0,:,0,:,:] # time, lat, lon
......
......@@ -34,7 +34,7 @@ def init_background_rodenbeck(obsvect, **kwargs):
# TODO: manage multiple background files at once
if obsvect.datef.strftime(path) != file_baseline:
print('ERROR: The time period spans multiple background files')
verbose('ERROR: The time period spans multiple background files')
raise ValueError
obs_cini = np.empty(len(obsvect.datastore)); obs_cini[:]=np.nan
......@@ -43,19 +43,24 @@ def init_background_rodenbeck(obsvect, **kwargs):
with Dataset(file_baseline) as bkg:
ids = [''.join([c.decode().lower() for c in name]) for name in bkg['identification'][:]]
ids = np.array(ids)
stations = dict()
for obs_i, row in enumerate(obsvect.datastore.itertuples()):
station = row.station
station_indices = np.where([station in name for name in ids])
if len(station_indices[0])==0:
print('ERROR: Station %s not found in the background file %s' % (station,file_baseline))
elif len(station_indices[0])>1:
print('WARNING: More than one station %s found in the background file %s' % (station,file_baseline))
print('\t ',*ids[station_indices[0]])
print('Picking the first one', ids[station_indices[0][0]])
station_index = station_indices[0][0]
try:
station_index = stations[station]
except KeyError:
station_indices = np.where([station in name for name in ids])
if len(station_indices[0])==0:
verbose('ERROR: Station %s not found in the background file %s' % (station,file_baseline))
elif len(station_indices[0])>1:
verbose('WARNING: More than one station %s found in the background file %s' % (station,file_baseline))
verbose('\t ' + ' '.join(ids[station_indices[0]]))
verbose('Picking the first one '+ids[station_indices[0][0]])
station_index = station_indices[0][0]
stations[station] = station_index
# find the time index in the baseline file
ts = np.array([pd.Timestamp(t[0],t[1],t[2],t[3],t[4]) for t in bkg['time1'][:]])
......@@ -64,7 +69,7 @@ def init_background_rodenbeck(obsvect, **kwargs):
obs_cini[obs_i] = bkg[varname][time_index,station_index]
except IndexError:
print('WARNING: time not found', row.Index)
verbose('WARNING: time not found ' + str(row.Index))
obsvect.background.cini_names = ['obs_cini_0']
obsvect.background.ncini = 1
......@@ -72,7 +77,7 @@ def init_background_rodenbeck(obsvect, **kwargs):
if background.optimize_cini:
print('ERROR: The Rödenbeck background can not be optimized ')
verbose('ERROR: The Rödenbeck background can not be optimized ')
raise ValueError
return obsvect
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment