diff --git a/modules/util/util.py b/modules/util/util.py index 6015b65ca39c182e227bf5dbfeda826135b8e5c7..30b6d0ce2b7ae6bf037cc740d79f91bb7a14e7c9 100644 --- a/modules/util/util.py +++ b/modules/util/util.py @@ -4,6 +4,7 @@ from datetime import timezone from metpy.units import units from metpy.calc import thickness_hydrostatic from collections import namedtuple +import os LatLonTuple = namedtuple('LatLonTuple', ['lat', 'lon']) @@ -18,6 +19,22 @@ def get_time_tuple_utc(timestamp): return dt_obj, dt_obj.timetuple() +def add_time_range_to_filename(pathname, tstart, tend): + dt_obj, _ = get_time_tuple_utc(tstart) + str_start = dt_obj.strftime('%Y%m%d%H') + + dt_obj, _ = get_time_tuple_utc(tend) + str_end = dt_obj.strftime('%Y%m%d%H') + + filename = os.path.split(pathname)[1] + w_o_ext, ext = os.path.splitext(filename) + filename = w_o_ext+'_'+str_start+'_'+str_end+ext + + path = os.path.split(pathname)[0] + path = path+'/'+filename + return path + + def haversine_np(lon1, lat1, lon2, lat2): """ Calculate the great circle distance between two points