Skip to content

Commit

Permalink
Fix levels bug in mon_data_space.py (JCSDA-internal#179)
Browse files Browse the repository at this point in the history
Levels implementation as dataset coordinate in `data/mon_data_space.py`
was not entirely complete. If the input yaml file requested only a
subset of the available levels, as opposed to requesting all levels
specified in the control file, the results were sub-optimal. The fix is
simple enough -- it now follows the same steps as for the Channel
coordinate.

Resolves JCSDA-internal#178 .
  • Loading branch information
EdwardSafford-NOAA authored Mar 6, 2024
1 parent 7ef27ee commit 66dfd09
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions src/eva/data/mon_data_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def execute(self, dataset_config, data_collections, timing):
# will NOT be the same for different station data files.
darr, cycle_tm, dims, lat, lon = self.read_stn_ieee(filename, coords, dims,
ndims_used, dims_arr, vars)
x_range = np.arange(1, dims['xdef']+1)
y_range = np.arange(1, dims['ydef']+1)

else:
Expand Down Expand Up @@ -168,8 +169,9 @@ def execute(self, dataset_config, data_collections, timing):
# --------------------------------------
for x in range(len(coord_dict)):
if drop_coord[x] and coord_dict[x][1] in list(ds.coords):
ds, chans_dict = \
self.subset_coordinate(ds, coord_dict[x][1], requested_coord[x], chans_dict)
ds, chans_dict, levs_dict = \
self.subset_coordinate(ds, coord_dict[x][1], requested_coord[x],
chans_dict, levs_dict)

# Conditionally add channel, level, scan, and iteration related variables
# -----------------------------------------------------------------------
Expand Down Expand Up @@ -227,7 +229,7 @@ def generate_default_config(self, filenames, collection_name, control_file):

# ----------------------------------------------------------------------------------------------

def subset_coordinate(self, ds, coordinate, requested_subset, chans_dict):
def subset_coordinate(self, ds, coordinate, requested_subset, chans_dict, levs_dict=None):

"""
Subset the input dataset along the specified coordinate dimension and update channel
Expand Down Expand Up @@ -284,11 +286,32 @@ def subset_coordinate(self, ds, coordinate, requested_subset, chans_dict):
chans_dict['chans_assim'] = new_chan_assim
chans_dict['chans_nassim'] = new_chan_nassim

# If Level coordinate has been reduced from "all" (by the yaml
# file) then reset level, level_yaxis_z, level_assim and level_nassim accordingly
if coordinate == 'Level':
new_levels_assim = []
new_levels_nassim = []

for x in requested_subset:
if x in levs_dict['levels_assim']:
new_levels_assim.append(x)
if x in levs_dict['levels_nassim']:
new_levels_nassim.append(x)

for x in range(len(new_levels_assim), len(requested_subset)):
new_levels_assim.append(0)
for x in range(len(new_levels_nassim), len(requested_subset)):
new_levels_nassim.append(0)

levs_dict['levels'] = requested_subset
levs_dict['levels_assim'] = new_levels_assim
levs_dict['levels_nassim'] = new_levels_nassim

else:
self.logger.info('Warning: requested coordinate, ' + str(coordinate) + ' is not in ' +
' dataset dimensions valid dimensions include ' + str(ds.dims))

return ds, chans_dict
return ds, chans_dict, levs_dict

# ----------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -773,8 +796,8 @@ def read_stn_ieee(self, file_name, coords, dims, ndims_used, dims_arr,
# dimensions are nvar, nlev, numobs
rtn_array = np.dstack(mylist)
dims['ydef'] = numobs
f.close()

f.close()
rtn_lat = np.asarray(lat).reshape(-1)
rtn_lon = np.asarray(lon).reshape(-1)

Expand Down

0 comments on commit 66dfd09

Please sign in to comment.