Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify mon_data_space.py to differenciate between data file types #174

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading