Skip to content

Commit

Permalink
Ref #178
Browse files Browse the repository at this point in the history
Complete bug fix.
  • Loading branch information
EdwardSafford-NOAA committed Mar 6, 2024
1 parent 7ef27ee commit cf1a817
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 cf1a817

Please sign in to comment.