Skip to content

Commit

Permalink
Modify 1-d read to handle both fortran and perl binary files. (JCSDA-…
Browse files Browse the repository at this point in the history
…internal#174)

Modify 1-d read to handle both fortran and perl binary files.
  • Loading branch information
EdwardSafford-NOAA authored Jan 12, 2024
1 parent b14e19d commit 2dec89f
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/eva/data/mon_data_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def execute(self, dataset_config, data_collections, timing):
else:
# read data file
darr, cycle_tm = self.read_ieee(filename, coords, dims, ndims_used,
dims_arr, nvars, vars)
dims_arr, nvars, vars, gsistat=attribs['gsistat'])

# add cycle as a variable to data array
cyc_darr = self.var_to_np_array(dims, ndims_used, dims_arr, cycle_tm)
Expand Down Expand Up @@ -317,7 +317,7 @@ def get_ctl_dict(self, control_file):
coord_list = []
dims = {'xdef': 0, 'ydef': 0, 'zdef': 0}
dim_list = []
attribs = {'sensor': None, 'sat': None, 'datatype': None}
attribs = {'sensor': None, 'sat': None, 'datatype': None, 'gsistat': False}
vars = []
nvars = 0
chans_dict = None
Expand Down Expand Up @@ -396,6 +396,9 @@ def get_ctl_dict(self, control_file):
if line.find('datatype station') != -1 or line.find('DTYPE station') != -1:
attribs['datatype'] = 'station'

if line.find('gsistat') != -1:
attribs['gsistat'] = True

if line.find('subtype') != -1:
strs = line.split()
datatype.append(strs[self.type_con] + strs[self.datatype_con] + '_' +
Expand Down Expand Up @@ -514,7 +517,7 @@ def get_stn_ctl_dict(self, control_file):
coords = {'xdef': 'Level', 'ydef': 'Nobs', 'zdef': None}
dims = {'xdef': 0, 'ydef': 0, 'zdef': 0}
dim_list = []
attribs = {'sensor': None, 'sat': None, 'datatype': 'station'}
attribs = {'sensor': None, 'sat': None, 'datatype': 'station', 'gsistat': False}
vars = []
nvars = 0
chans_dict = None
Expand Down Expand Up @@ -605,7 +608,8 @@ def get_stn_ctl_dict(self, control_file):

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

def read_ieee(self, file_name, coords, dims, ndims_used, dims_arr, nvars, vars, file_path=None):
def read_ieee(self, file_name, coords, dims, ndims_used, dims_arr, nvars, vars,
file_path=None, gsistat=False):

"""
Read data from an IEEE file and arrange it into a numpy array.
Expand Down Expand Up @@ -643,8 +647,8 @@ def read_ieee(self, file_name, coords, dims, ndims_used, dims_arr, nvars, vars,
self.logger.info(f"WARNING: file {filename} is missing")
load_data = False

if ndims_used == 1: # MinMon
rtn_array = np.empty((0, dims[dims_arr[0]]), datatype=float)
if ndims_used == 1: # MinMon, regional RadMon time,bcoef,bcor
rtn_array = np.empty((0, dims[dims_arr[0]]), dtype=float)
if not load_data:
zarray = np.zeros((dims[dims_arr[0]]), float)
dimensions = [dims[dims_arr[0]]]
Expand Down Expand Up @@ -688,11 +692,14 @@ def read_ieee(self, file_name, coords, dims, ndims_used, dims_arr, nvars, vars,
for x in range(nvars):
if load_data:
if ndims_used == 1:
with open(filename, 'rb') as infile:
binary_data = infile.read()
if gsistat:
with open(filename, 'rb') as infile:
binary_data = infile.read()
arr = array.array('f')
arr.frombytes(binary_data)
else:
arr = f.read_reals(dtype=np.dtype('>f4'))

arr = array.array('f')
arr.frombytes(binary_data)
else:
arr = np.transpose(f.read_reals(dtype=np.dtype('>f4')).reshape(dimensions))
else:
Expand Down

0 comments on commit 2dec89f

Please sign in to comment.