Skip to content

Commit

Permalink
Merge pull request #104 from metno/handle_month_interval
Browse files Browse the repository at this point in the history
montly interval
  • Loading branch information
TAlonglong authored Jan 13, 2025
2 parents a6af4b4 + 3be6548 commit ac1c055
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion mapgen/modules/generic_quicklook.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def generic_quicklook(netcdf_path: str,
if netcdf_path.endswith('ncml'):
netcdf_files = _read_netcdfs_from_ncml(netcdf_path)
for variable in variables:
if variable in ['longitude', 'latitude', 'forecast_reference_time', 'projection_lambert', 'p0', 'ap', 'b']:
if variable in ['longitude', 'latitude', 'forecast_reference_time', 'projection_lambert', 'p0', 'ap', 'b', 'time_bnds']:
logger.debug(f"Skipping variable or dimension: {variable}")
continue
layer = mapscript.layerObj()
Expand Down
11 changes: 9 additions & 2 deletions mapgen/modules/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,12 @@ def find_time_diff(ds, dim_name):
stamp = datetime.datetime(y, m, d, h, minute, s)
if prev:
diff = stamp - prev
if prev_diff and diff != prev_diff:
if prev_diff and diff >= datetime.timedelta(days=28) and diff <= datetime.timedelta(days=31) and prev + diff == stamp:
logger.debug(f"Possible monthly range: {prev} {stamp}")
diff = "P1M"
elif prev_diff and diff != prev_diff:
logger.debug(f"DIFF {diff} PREV_DIFF {prev_diff}")
logger.debug(f"Stamp {stamp} PREV {prev}")
# Diff between more than three stamps are different. Can not use range.
is_range = False
break
Expand All @@ -460,7 +465,9 @@ def find_time_diff(ds, dim_name):
return diff,diff_string,is_range

def _get_time_diff(diff):
if diff < datetime.timedelta(hours=1):
if diff == 'P1M':
diff_string = diff
elif diff < datetime.timedelta(hours=1):
h = int(diff.seconds/60)
diff_string = f"PT{h}M"
elif diff < datetime.timedelta(hours=24):
Expand Down

0 comments on commit ac1c055

Please sign in to comment.