Skip to content

Commit

Permalink
Ref #163
Browse files Browse the repository at this point in the history
Address header and coordinate issues.
  • Loading branch information
EdwardSafford-NOAA committed Nov 27, 2023
1 parent a1e87fd commit af41b61
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/eva/data/csv_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,41 @@ def execute(self, dataset_config, data_collections, timing):

for group in groups:
group_name = get(group, self.logger, 'name')
header_info = get(group, self.logger, 'header', None, False)
group_vars = get(group, self.logger, 'variables', None, False)

selected_fields = get(group, self.logger, 'selected_fields', 'all')
date_config = get(group, self.logger, 'date', None, False)
coord = None

coord_config = get(group, self.logger, 'coordinate', None, False)
coord = None if not coord_config else coord_config.get('name')

# skip header if present
if header_info is not None:
nrows = int(header_info.get('rows'))
file_data.pop(nrows-1)

# load datetime if available
if date_config is not None:
coord = 'Cycle'
var_name = group_name + "::datetime"
dt_arr = self.get_datetime_array(file_data, date_config)
ds = xr.Dataset({var_name: (coord, dt_arr),
coord: range(0, len(dt_arr))})
coord: range(0, len(dt_arr))})

ds_list.append(ds)

# load requested data
# load requested data
if group_vars is not None:
for key, var in group_vars.items():
if coord is None: coord = 'Unit'
if coord is None:
coord = 'Unit'
var_name = group_name + "::" + key
st_var_arr = [row[var] for row in file_data]
var_arr = np.array(st_var_arr, dtype=np.float32)

ds = xr.Dataset({var_name: (coord, var_arr),
coord: range(0, len(var_arr))})
coord: range(0, len(var_arr))})
ds_list.append(ds)

# Concatenate datasets from ds_list into a single dataset
Expand Down Expand Up @@ -127,7 +136,7 @@ def get_datetime_array(self, file_data, date_config):
date_config (dict): date configuration information
Returns:
np.array: datetime array
np.array: datetime array
"""

datetime_key = 'datetime'
Expand All @@ -141,13 +150,13 @@ def get_datetime_array(self, file_data, date_config):
mon = [row[date_config.get('month')] for row in file_data]
day = [row[date_config.get('day')] for row in file_data]
hr = [row[date_config.get('hour')] for row in file_data]
date_str_list = [y + m + d + h for y,m,d,h in zip(yr,mon,day,hr)]
date_str_list = [y + m + d + h for y, m, d, h in zip(yr, mon, day, hr)]

else:
self.logger.abort("The date configuration in yaml file does not contain required date " +
"information. A \'date\': entry must specify either " +
self.logger.abort("The date configuration in yaml file does not contain required " +
"date information. A \'date\': entry must specify either " +
"\'datetime\': (int) file field position or entries specifying " +
" \'year\': int, \'month\': int, \'day\': int, and \'hour\': int. " +
f" Date information found was {date_config}")
" \'year\': int, \'month\': int, \'day\': int, and \'hour\': int. " +
f" Date information found was {date_config}")

return np.array([np.datetime64(datetime.strptime(ds, '%Y%m%d%H')) for ds in date_str_list])

0 comments on commit af41b61

Please sign in to comment.