Skip to content

Commit

Permalink
Add the option to use verifying_time in time_dims
Browse files Browse the repository at this point in the history
  • Loading branch information
alexamici committed Nov 21, 2019
1 parent 3da85de commit b1b8319
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 9 additions & 0 deletions cfgrib/cfmessage.py
Expand Up @@ -104,6 +104,14 @@ def to_grib_step(message, step_ns, step_unit=1, step_key='endStep', step_unit_ke
message[step_unit_key] = step_unit


def from_grib_month(message, verifying_month_key='verifyingMonth', epoch=DEFAULT_EPOCH):
date = message[verifying_month_key]
year = date // 100
month = date % 100
data_datetime = datetime.datetime(year, month, 1, 0, 0)
return int((data_datetime - epoch).total_seconds())


def build_valid_time(time, step):
# type: (np.ndarray, np.ndarray) -> T.Tuple[T.Tuple[str, ...], np.ndarray]
"""
Expand Down Expand Up @@ -136,6 +144,7 @@ def build_valid_time(time, step):
functools.partial(from_grib_date_time, date_key='validityDate', time_key='validityTime'),
functools.partial(to_grib_date_time, date_key='validityDate', time_key='validityTime'),
),
'verifying_time': (from_grib_month, None),
}


Expand Down
8 changes: 7 additions & 1 deletion cfgrib/dataset.py
Expand Up @@ -147,7 +147,7 @@
ENSEMBLE_KEYS = ['number']
VERTICAL_KEYS = ['level']
DATA_TIME_KEYS = ['dataDate', 'dataTime', 'endStep']
ALL_REF_TIME_KEYS = ['time', 'step', 'valid_time']
ALL_REF_TIME_KEYS = ['time', 'step', 'valid_time', 'verifying_time']
SPECTRA_KEYS = ['directionNumber', 'frequencyNumber']

ALL_HEADER_DIMS = ENSEMBLE_KEYS + VERTICAL_KEYS + DATA_TIME_KEYS + ALL_REF_TIME_KEYS + SPECTRA_KEYS
Expand Down Expand Up @@ -227,6 +227,12 @@
'standard_name': 'time',
'long_name': 'time',
},
'verifying_time': {
'units': 'seconds since 1970-01-01T00:00:00',
'calendar': 'proleptic_gregorian',
'standard_name': 'time',
'long_name': 'time',
},
}


Expand Down

0 comments on commit b1b8319

Please sign in to comment.