Skip to content

Commit

Permalink
Fix level bugs, part 2 in mon_data_space Ref #180 (#181)
Browse files Browse the repository at this point in the history
This PR fixes (fingers crossed) the level bug in `mon_data_space.py`.
These recent bugs all stem from the inconsistent logic in the legacy
control files (which describe the structure of the binary station and
data files). Initially I had (naïvely) assumed that if any of the three
defined dimensions (xdef, ydef, zdef) were 1 then it could be ignored.
That is not true, since we want to iterate on Level, and that can
legitimately be dimension 1 (surface pressure, most ozone time series).
This release corrects that and adds more in-line notes so I'll have a
better/faster handle on this if/when I need to revisit it.

Testing has been done with the oznTime plots (from which I encountered
the problem, as well as conventional, radiance, and minmon plots to try
to test all cases.

Resolves #180 .
  • Loading branch information
EdwardSafford-NOAA authored Mar 8, 2024
1 parent 66dfd09 commit 455c377
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/eva/data/mon_data_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ def execute(self, dataset_config, data_collections, timing):

# Read station data file. Note that the variable dimensions
# will NOT be the same for different station data files.
# y_range is set here because it's the number of obs which is not in the control
# file and is only known once the ieee file is read.
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 @@ -469,11 +470,10 @@ def get_ctl_dict(self, control_file):
# Ignore any coordinates in the control file that have a value of 1.
used = 0
mydef = ["xdef", "ydef", "zdef"]
for x in range(len(dim_list)):
if dim_list[x] > 2:
coords[mydef[used]] = coord_list[x]
dims[mydef[used]] = dim_list[x]
used += 1
for x in range(len(coord_list)):
coords[mydef[used]] = coord_list[x]
dims[mydef[used]] = dim_list[x]
used += 1

# If Scan is in the coords calculate the scan positions.
# scan_info[0] = num steps, [1] = start position, [2] = step size
Expand Down Expand Up @@ -861,20 +861,26 @@ def get_dim_ranges(self, coords, dims, channo, datatypes):
y_range = None
z_range = None

# - Return None for a coordinate that has value 0 or 1.
# - "Channel" can be either the x or y coordinate and can be
# - Return None for a dims['xdef'] or dims['ydef'] coordinate that has value 0.
# - Return None for a dims['zdef'] coordinate that has a value < 2. Some
# control files specify a non-existant zdef dimension which is interpreted
# by the control file parser as having a value of 1. That's the reasoning
# behind setting dims['zdef'] only if it's > 1.
#
# Additional special cases:
# - "Channel" can be either the x or y coordinate and can be
# numbered non-consecutively, which has been captured in channo.
# - The z coordinate is never used for channel.
# - DataType number has been captured in datatypes.

if dims['xdef'] > 1:
if dims['xdef'] > 0:
if coords['xdef'] == 'Channel':
x_range = channo
elif coords['xdef'] == 'DataType':
x_range = datatypes
else:
x_range = np.arange(1, dims['xdef']+1)

if dims['ydef'] > 1:
if dims['ydef'] > 0:
y_range = channo if coords['ydef'] == 'Channel' else np.arange(1, dims['ydef']+1)

if dims['zdef'] > 1:
Expand All @@ -899,14 +905,10 @@ def get_ndims_used(self, dims):

# Some ieee files (ozn) can be 1 or 2 dimensions depending on the
# number of levels used. Levels is the xdef, Regions is the ydef.
# All Ozn files use ydef, but many have xdef = 1. The dims_arr[]
# will return the name(s) of the dimensions actually used.

# Ignore dims with values of 0 or 1
ndims = len(dims)
dims_arr = []
for x in range(ndims):
if list(dims.values())[x] <= 1:
if list(dims.values())[x] <= 0:
ndims -= 1
else:
dims_arr.append(list(dims)[x])
Expand Down

0 comments on commit 455c377

Please sign in to comment.