Skip to content

Commit

Permalink
add gpm cleanup function to add timeMidScan variable when it is not t…
Browse files Browse the repository at this point in the history
…here
  • Loading branch information
nlensse1 committed Apr 30, 2024
1 parent 60170ed commit c249838
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions podaac/subsetter/gpm_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@
to nscan, nbin, nfreq by using the DimensionNames variable attribute
"""

import datetime
from netCDF4 import date2num

dim_dict = {}

def create_new_time_var(time_group, nc_dataset):
time_unit_out = "seconds since 1980-01-06 00:00:00"
new_time_list = [date2num(datetime.datetime(nc_dataset[time_group+'__Year'][:][i], nc_dataset[time_group+'__Month'][:][i], nc_dataset[time_group+'__DayOfMonth'][:][i],
hour=nc_dataset[time_group+'__Hour'][:][i], minute=nc_dataset[time_group+'__Minute'][:][i],
second=nc_dataset[time_group+'__Second'][:][i], microsecond=nc_dataset[time_group+'__Second'][:][i]*1000), time_unit_out)
for i in range(len(nc_dataset[time_group+'__Year'][:]))]

return new_time_list, time_unit_out

def change_var_dims(nc_dataset, variables=None):
"""
Expand Down Expand Up @@ -62,4 +73,15 @@ def change_var_dims(nc_dataset, variables=None):
# copy the data to the new variable with dimension names
new_mapped_var[var_name][:] = var[:]

if not any("timeMidScan" in var for var in var_list):
scan_time_groups = ["__".join(i.split('__')[:-1]) for i in var_list if 'ScanTime' in i]
for time_group in list(set(scan_time_groups)):
time_data, time_unit = create_new_time_var(time_group, nc_dataset)
new_time_var_name = time_group+'__timeMidScan'
var_dims = nc_dataset.variables[time_group+'__Year'].dimensions
comp_args = {"zlib": True, "complevel": 1}
nc_dataset.createVariable(new_time_var_name, 'f8', var_dims, **comp_args)
nc_dataset.variables[new_time_var_name].setncattr('unit', time_unit)
nc_dataset.variables[new_time_var_name][:] = time_data

return nc_dataset

0 comments on commit c249838

Please sign in to comment.