Skip to content
Snippets Groups Projects
Commit f2445e82 authored by tomrink's avatar tomrink
Browse files

new method

parent 42a9f2f9
No related branches found
No related tags found
No related merge requests found
......@@ -256,3 +256,33 @@ def get_grid_values_all(h5f, grid_name, scale_factor_name='scale_factor', add_of
grd_vals = np.where(grd_vals == fill_value, np.nan, grd_vals)
return grd_vals
# dt_str_0: start datetime string in format YYYY-MM-DD_HH:MM
# num_steps with increment of days, hours, minutes or seconds
# return num_steps+1 lists of datetime strings and timestamps for the times eries
def make_times(dt_str_0, num_steps, days=None, hours=None, minutes=None, seconds=None):
if days is not None:
inc = 86400*days
elif hours is not None:
inc = 3600*hours
elif minutes is not None:
inc = 60*minutes
else:
inc = seconds
dt_obj_s = []
ts_s = []
dto_0 = datetime.datetime.strptime(dt_str_0, '%Y-%m-%d_%H:%M').replace(tzinfo=timezone.utc)
ts_0 = dto_0.timestamp()
dt_obj_s.append(dto_0)
ts_s.append(ts_0)
dto_last = dto_0
for k in range(num_steps):
dt_obj = dto_last + datetime.timedelta(seconds=inc)
dt_obj_s.append(dt_obj)
ts_s.append(dt_obj.timestamp())
dto_last = dt_obj
return dt_obj_s, ts_s
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment