From ceee1f8934a2a6c2f358bb91b593a471716cef70 Mon Sep 17 00:00:00 2001 From: Nick Guy Date: Mon, 11 Jan 2016 14:00:43 -0700 Subject: [PATCH 1/5] Time-height displays. Updated datetime_utils to convert to Epoch time if desired. Updated RadarDisplay.plot_vpt to accept a flag to use time along x-axis. Added time formatting for x-axis for time-height plots. --- pyart/core/radar.py | 1 + pyart/graph/radardisplay.py | 77 ++++++++++++++++++++++++++++++++++-- pyart/util/datetime_utils.py | 54 +++++++++++++++++++------ 3 files changed, 117 insertions(+), 15 deletions(-) diff --git a/pyart/core/radar.py b/pyart/core/radar.py index 91ebb3db93..d2d39ee58e 100644 --- a/pyart/core/radar.py +++ b/pyart/core/radar.py @@ -1019,6 +1019,7 @@ def join_radar(radar1, radar2): # to combine times we need to reference them to a standard # for this we'll use epoch time + ### NG THIS should use new updated datetime_utils if accepted estring = "seconds since 1970-01-01T00:00:00Z" r1dt = num2date(radar1.time['data'], radar1.time['units']) r2dt = num2date(radar2.time['data'], radar2.time['units']) diff --git a/pyart/graph/radardisplay.py b/pyart/graph/radardisplay.py index 9a76a15ad4..2b2054f1c2 100644 --- a/pyart/graph/radardisplay.py +++ b/pyart/graph/radardisplay.py @@ -17,11 +17,15 @@ import matplotlib.pyplot as plt import numpy as np import netCDF4 +from matplotlib.dates import ( + DateFormatter, SecondLocator, MinuteLocator, + HourLocator, DayLocator) from . import common from ..core.transforms import antenna_to_cartesian from ..core.transforms import antenna_vectors_to_cartesian from ..core.transforms import corner_to_point +from ..util.datetime_utils import datetimes_from_radar class RadarDisplay(object): @@ -112,6 +116,7 @@ def __init__(self, radar, shift=(0.0, 0.0)): units = radar.time['units'] calendar = radar.time['calendar'] self.time_begin = netCDF4.num2date(times, units, calendar) + self.times = datetimes_from_radar(radar) # sweep start and end indices self.starts = radar.sweep_start_ray_index['data'] @@ -486,7 +491,10 @@ def plot_vpt(self, field, mask_tuple=None, vmin=None, vmax=None, axislabels=(None, None), axislabels_flag=True, colorbar_flag=True, colorbar_label=None, colorbar_orient='vertical', edges=True, - filter_transitions=True, ax=None, fig=None): + filter_transitions=True, + time_axis_flag=False, + dForm=None, tz=None, date_MinTicker=None, + ax=None, fig=None): """ Plot a VPT scan. @@ -542,6 +550,15 @@ def plot_vpt(self, field, mask_tuple=None, vmin=None, vmax=None, sweeps from the plot. False will include these rays in the plot. No rays are filtered when the antenna_transition attribute of the underlying radar is not present. + time_axis_flag : bool + True to plot the x-axis as time. False uses the default of index number. + dForm : str + Format of the time string for x-axis labels. + tz : str + Time zone info to use when creating axis labels (see datetime). + date_MinTicker : str + Sting to set minor ticks of date axis, + 'second','minute','hour','day' supported. ax : Axis Axis to plot on. None will use the current axis. fig : Figure @@ -567,6 +584,12 @@ def plot_vpt(self, field, mask_tuple=None, vmin=None, vmax=None, x = np.arange(data.shape[1]) y = self.ranges / 1000. + # set up the time axis + if time_axis_flag: + self._set_vpt_time_axis(ax, dForm=dForm, tz=tz, + date_MinTicker=date_MinTicker) + x = self.times + # mask the data where outside the limits if mask_outside: data = np.ma.masked_invalid(data) @@ -579,7 +602,7 @@ def plot_vpt(self, field, mask_tuple=None, vmin=None, vmax=None, self._set_vpt_title(field, title, ax) if axislabels_flag: - self._label_axes_vpt(axislabels, ax) + self._label_axes_vpt(axislabels, time_axis_flag, ax) # add plot and field to lists self.plots.append(pm) @@ -933,6 +956,11 @@ def label_xaxis_rays(self, ax=None): ax = common.parse_ax(ax) ax.set_xlabel('Ray number (unitless)') + def label_xaxis_time(self, ax=None): + """ Label the yaxis with the default label for rays. """ + ax = common.parse_ax(ax) + ax.set_xlabel('Time (HH:MM)') + def label_yaxis_field(self, field, ax=None): """ Label the yaxis with the default label for a field units. """ ax = common.parse_ax(ax) @@ -1007,11 +1035,14 @@ def _label_axes_ray(self, axis_labels, field, ax): else: ax.set_ylabel(y_label) - def _label_axes_vpt(self, axis_labels, ax): + def _label_axes_vpt(self, axis_labels, time_axis_flag, ax): """ Set the x and y axis labels for a PPI plot. """ x_label, y_label = axis_labels if x_label is None: - self.label_xaxis_rays(ax) + if time_axis_flag: + self.label_xaxis_time(ax) + else: + self.label_xaxis_rays(ax) else: ax.set_xlabel(x_label) if y_label is None: @@ -1019,6 +1050,44 @@ def _label_axes_vpt(self, axis_labels, ax): else: ax.set_ylabel(y_label) + def _set_vpt_time_axis(self, ax, dForm=None, tz=None, + date_MinTicker=None): + """ Set the x axis as a time formatted axis. + + Parameters + ---------- + ax : Matplotlib axis instance + Axis to plot. None will use the current axis. + dForm : str + Format of the time string for x-axis labels. + tz : str + Time zone info to use when creating axis labels (see datetime). + date_MinTicker : str + Sting to set minor ticks of date axis, + 'second','minute','hour','day' supported. + """ + if dForm is None: + dForm = '%H:%M' + if date_MinTicker is None: + date_MinTicker = 'minute' + + # Set the date format + date_Fmt = DateFormatter(dForm, tz=tz) + + # Set x-axis and tick parameters + ax.xaxis.set_major_formatter(date_Fmt) + if date_MinTicker == 'second': + ax.xaxis.set_minor_locator(SecondLocator()) + elif date_MinTicker == 'minute': + ax.xaxis.set_minor_locator(MinuteLocator()) + elif date_MinTicker == 'hour': + ax.xaxis.set_minor_locator(HourLocator()) + elif date_MinTicker == 'day': + ax.xaxis.set_minor_locator(DayLocator()) + + # Turn the tick marks outward + ax.tick_params(which='both', direction='out') + ########################## # name generator methods # ########################## diff --git a/pyart/util/datetime_utils.py b/pyart/util/datetime_utils.py index 0329cb6fdc..f4468ddec5 100644 --- a/pyart/util/datetime_utils.py +++ b/pyart/util/datetime_utils.py @@ -1,30 +1,62 @@ """ Functions for converting date and time between various forms """ -from netCDF4 import num2date +from netCDF4 import num2date, date2num -def datetime_from_radar(radar): +def datetime_from_radar(radar, epoch=False): """ Return a datetime for the first ray in a Radar. """ - return num2date(radar.time['data'][0], radar.time['units']) + if epoch: + dtrad = num2date(radar.time['data'][0], radar.time['units']) + epnum = date2num(dtrad, epoch_units()) + return num2date(epnum, epoch_units()) + else: + return num2date(radar.time['data'][0], radar.time['units']) -def datetimes_from_radar(radar): +def datetimes_from_radar(radar, epoch=False): """ Return an array of datetimes for the rays in a Radar. """ - return num2date(radar.time['data'][:], radar.time['units']) + if epoch: + dtrad = num2date(radar.time['data'][:], radar.time['units']) + epnum = date2num(dtrad, epoch_units()) + return num2date(epnum, epoch_units()) + else: + return num2date(radar.time['data'][:], radar.time['units']) -def datetime_from_dataset(dataset): +def datetime_from_dataset(dataset, epoch=False): """ Return a datetime for the first time in a netCDF Dataset. """ - return num2date(dataset.variables['time'][0], + if epoch: + dtdata = num2date(dataset.variables['time'][0], + dataset.variables['time'].units) + epnum = date2num(dtdata, epoch_units()) + return num2date(epnum, epoch_units()) + else: + return num2date(dataset.variables['time'][0], dataset.variables['time'].units) -def datetimes_from_dataset(dataset): +def datetimes_from_dataset(dataset, epoch=False): """ Return an array of datetimes for the times in a netCDF Dataset. """ - return num2date(dataset.variables['time'][:], + if epoch: + dtdata = num2date(dataset.variables['time'][:], + dataset.variables['time'].units) + epnum = date2num(dtdata, epoch_units()) + return num2date(epnum, epoch_units()) + else: + return num2date(dataset.variables['time'][:], dataset.variables['time'].units) -def datetime_from_grid(grid): +def datetime_from_grid(grid, epoch=False): """ Return a datetime for the volume start in a Grid. """ - return num2date(grid.time['data'][0], grid.time['units']) + if epoch: + dtrad = num2date(grid.time['data'][0], grid.time['units']) + epnum = date2num(dtrad, epoch_units()) + return num2date(epnum, epoch_units()) + else: + return num2date(grid.time['data'][0], grid.time['units']) + +def epoch_units(): + """ Return the units used in converting to datetime in the + standard Epoch units. """ + return "seconds since 1970-01-01T00:00:00Z" From 020e1460df6ba81315ea208b9c9617a357770846 Mon Sep 17 00:00:00 2001 From: Nick Guy Date: Mon, 18 Jan 2016 15:32:54 -0700 Subject: [PATCH 2/5] Removed minor tick label formatting. Updated doc strings in radardisplay.py Updated test script. --- pyart/core/radar.py | 2 +- pyart/graph/radardisplay.py | 36 +++++++------------------ pyart/graph/tests/test_radar_display.py | 2 +- 3 files changed, 12 insertions(+), 28 deletions(-) diff --git a/pyart/core/radar.py b/pyart/core/radar.py index d2d39ee58e..5871dab3c0 100644 --- a/pyart/core/radar.py +++ b/pyart/core/radar.py @@ -1019,7 +1019,7 @@ def join_radar(radar1, radar2): # to combine times we need to reference them to a standard # for this we'll use epoch time - ### NG THIS should use new updated datetime_utils if accepted + ### TODO Use new updated datetime_utils if accepted estring = "seconds since 1970-01-01T00:00:00Z" r1dt = num2date(radar1.time['data'], radar1.time['units']) r2dt = num2date(radar2.time['data'], radar2.time['units']) diff --git a/pyart/graph/radardisplay.py b/pyart/graph/radardisplay.py index 2b2054f1c2..999cdd4090 100644 --- a/pyart/graph/radardisplay.py +++ b/pyart/graph/radardisplay.py @@ -493,7 +493,7 @@ def plot_vpt(self, field, mask_tuple=None, vmin=None, vmax=None, colorbar_orient='vertical', edges=True, filter_transitions=True, time_axis_flag=False, - dForm=None, tz=None, date_MinTicker=None, + dForm=None, tz=None, ax=None, fig=None): """ Plot a VPT scan. @@ -551,14 +551,14 @@ def plot_vpt(self, field, mask_tuple=None, vmin=None, vmax=None, No rays are filtered when the antenna_transition attribute of the underlying radar is not present. time_axis_flag : bool - True to plot the x-axis as time. False uses the default of index number. - dForm : str - Format of the time string for x-axis labels. - tz : str + True to plot the x-axis as time. False uses the index number. + Default is False - index-based. + dForm : str, optional + Format of the time string for x-axis labels. Parameter is + ignored if time_axis_flag is set to False. + tz : str, optional Time zone info to use when creating axis labels (see datetime). - date_MinTicker : str - Sting to set minor ticks of date axis, - 'second','minute','hour','day' supported. + Parameter is ignored if time_axis_flag is set to False. ax : Axis Axis to plot on. None will use the current axis. fig : Figure @@ -586,8 +586,7 @@ def plot_vpt(self, field, mask_tuple=None, vmin=None, vmax=None, # set up the time axis if time_axis_flag: - self._set_vpt_time_axis(ax, dForm=dForm, tz=tz, - date_MinTicker=date_MinTicker) + self._set_vpt_time_axis(ax, dForm=dForm, tz=tz) x = self.times # mask the data where outside the limits @@ -1050,8 +1049,7 @@ def _label_axes_vpt(self, axis_labels, time_axis_flag, ax): else: ax.set_ylabel(y_label) - def _set_vpt_time_axis(self, ax, dForm=None, tz=None, - date_MinTicker=None): + def _set_vpt_time_axis(self, ax, dForm=None, tz=None): """ Set the x axis as a time formatted axis. Parameters @@ -1062,9 +1060,6 @@ def _set_vpt_time_axis(self, ax, dForm=None, tz=None, Format of the time string for x-axis labels. tz : str Time zone info to use when creating axis labels (see datetime). - date_MinTicker : str - Sting to set minor ticks of date axis, - 'second','minute','hour','day' supported. """ if dForm is None: dForm = '%H:%M' @@ -1074,17 +1069,6 @@ def _set_vpt_time_axis(self, ax, dForm=None, tz=None, # Set the date format date_Fmt = DateFormatter(dForm, tz=tz) - # Set x-axis and tick parameters - ax.xaxis.set_major_formatter(date_Fmt) - if date_MinTicker == 'second': - ax.xaxis.set_minor_locator(SecondLocator()) - elif date_MinTicker == 'minute': - ax.xaxis.set_minor_locator(MinuteLocator()) - elif date_MinTicker == 'hour': - ax.xaxis.set_minor_locator(HourLocator()) - elif date_MinTicker == 'day': - ax.xaxis.set_minor_locator(DayLocator()) - # Turn the tick marks outward ax.tick_params(which='both', direction='out') diff --git a/pyart/graph/tests/test_radar_display.py b/pyart/graph/tests/test_radar_display.py index 8defb9eede..6b1947e3bb 100644 --- a/pyart/graph/tests/test_radar_display.py +++ b/pyart/graph/tests/test_radar_display.py @@ -137,7 +137,7 @@ def test_radardisplay_user_specified_labels(): assert ax.get_xlabel() == 'baz' assert ax.get_ylabel() == 'qux' - display._label_axes_vpt(('nick', 'nock'), ax) + display._label_axes_vpt(('nick', 'nock'), False, ax) assert ax.get_xlabel() == 'nick' assert ax.get_ylabel() == 'nock' plt.close() From bd25ba4a2c75bc8a201105901859d1947c13d5e0 Mon Sep 17 00:00:00 2001 From: Nick Guy Date: Mon, 18 Jan 2016 15:59:14 -0700 Subject: [PATCH 3/5] Updated keyword names to standardize with rest of Py-ART package. Moved epoch units to a variable in datetime_utils, but maintained a get method to pull the units out if needed. Code in radar.join_radars is added, but still commented out for the time being. --- pyart/core/radar.py | 6 +++++- pyart/graph/radardisplay.py | 16 ++++++++-------- pyart/util/datetime_utils.py | 28 ++++++++++++++-------------- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/pyart/core/radar.py b/pyart/core/radar.py index 5871dab3c0..26cee2d21d 100644 --- a/pyart/core/radar.py +++ b/pyart/core/radar.py @@ -35,6 +35,7 @@ from ..config import get_metadata from ..lazydict import LazyLoadDict from .transforms import antenna_vectors_to_cartesian, cartesian_to_geographic +from ..util import datetime_utils class Radar(object): @@ -1019,7 +1020,6 @@ def join_radar(radar1, radar2): # to combine times we need to reference them to a standard # for this we'll use epoch time - ### TODO Use new updated datetime_utils if accepted estring = "seconds since 1970-01-01T00:00:00Z" r1dt = num2date(radar1.time['data'], radar1.time['units']) r2dt = num2date(radar2.time['data'], radar2.time['units']) @@ -1027,6 +1027,10 @@ def join_radar(radar1, radar2): r2num = date2num(r2dt, estring) new_radar.time['data'] = np.append(r1num, r2num) new_radar.time['units'] = estring + ### TODO Use new updated datetime_utils if accepted + # r1num = datetime_utils.datetimes_from_radar(radar1, epoch=True) + # r2num = datetime_utils.datetimes_from_radar(radar2, epoch=True) + # new_radar.time['units'] = datetime_utils.get_epoch_units() for var in new_radar.fields.keys(): sh1 = radar1.fields[var]['data'].shape diff --git a/pyart/graph/radardisplay.py b/pyart/graph/radardisplay.py index 999cdd4090..0871747b5f 100644 --- a/pyart/graph/radardisplay.py +++ b/pyart/graph/radardisplay.py @@ -493,7 +493,7 @@ def plot_vpt(self, field, mask_tuple=None, vmin=None, vmax=None, colorbar_orient='vertical', edges=True, filter_transitions=True, time_axis_flag=False, - dForm=None, tz=None, + date_time_form=None, tz=None, ax=None, fig=None): """ Plot a VPT scan. @@ -553,7 +553,7 @@ def plot_vpt(self, field, mask_tuple=None, vmin=None, vmax=None, time_axis_flag : bool True to plot the x-axis as time. False uses the index number. Default is False - index-based. - dForm : str, optional + date_time_form : str, optional Format of the time string for x-axis labels. Parameter is ignored if time_axis_flag is set to False. tz : str, optional @@ -586,7 +586,7 @@ def plot_vpt(self, field, mask_tuple=None, vmin=None, vmax=None, # set up the time axis if time_axis_flag: - self._set_vpt_time_axis(ax, dForm=dForm, tz=tz) + self._set_vpt_time_axis(ax, date_time_form=date_time_form, tz=tz) x = self.times # mask the data where outside the limits @@ -1049,25 +1049,25 @@ def _label_axes_vpt(self, axis_labels, time_axis_flag, ax): else: ax.set_ylabel(y_label) - def _set_vpt_time_axis(self, ax, dForm=None, tz=None): + def _set_vpt_time_axis(self, ax, date_time_form=None, tz=None): """ Set the x axis as a time formatted axis. Parameters ---------- ax : Matplotlib axis instance Axis to plot. None will use the current axis. - dForm : str + date_time_form : str Format of the time string for x-axis labels. tz : str Time zone info to use when creating axis labels (see datetime). """ - if dForm is None: - dForm = '%H:%M' + if date_time_form is None: + date_time_form = '%H:%M' if date_MinTicker is None: date_MinTicker = 'minute' # Set the date format - date_Fmt = DateFormatter(dForm, tz=tz) + date_Fmt = DateFormatter(date_time_form, tz=tz) # Turn the tick marks outward ax.tick_params(which='both', direction='out') diff --git a/pyart/util/datetime_utils.py b/pyart/util/datetime_utils.py index f4468ddec5..0a52f5865e 100644 --- a/pyart/util/datetime_utils.py +++ b/pyart/util/datetime_utils.py @@ -2,13 +2,14 @@ from netCDF4 import num2date, date2num +EPOCH_UNITS = "seconds since 1970-01-01T00:00:00Z" def datetime_from_radar(radar, epoch=False): """ Return a datetime for the first ray in a Radar. """ if epoch: dtrad = num2date(radar.time['data'][0], radar.time['units']) - epnum = date2num(dtrad, epoch_units()) - return num2date(epnum, epoch_units()) + epnum = date2num(dtrad, EPOCH_UNITS) + return num2date(epnum, EPOCH_UNITS) else: return num2date(radar.time['data'][0], radar.time['units']) @@ -17,8 +18,8 @@ def datetimes_from_radar(radar, epoch=False): """ Return an array of datetimes for the rays in a Radar. """ if epoch: dtrad = num2date(radar.time['data'][:], radar.time['units']) - epnum = date2num(dtrad, epoch_units()) - return num2date(epnum, epoch_units()) + epnum = date2num(dtrad, EPOCH_UNITS) + return num2date(epnum, EPOCH_UNITS) else: return num2date(radar.time['data'][:], radar.time['units']) @@ -28,8 +29,8 @@ def datetime_from_dataset(dataset, epoch=False): if epoch: dtdata = num2date(dataset.variables['time'][0], dataset.variables['time'].units) - epnum = date2num(dtdata, epoch_units()) - return num2date(epnum, epoch_units()) + epnum = date2num(dtdata, EPOCH_UNITS) + return num2date(epnum, EPOCH_UNITS) else: return num2date(dataset.variables['time'][0], dataset.variables['time'].units) @@ -40,8 +41,8 @@ def datetimes_from_dataset(dataset, epoch=False): if epoch: dtdata = num2date(dataset.variables['time'][:], dataset.variables['time'].units) - epnum = date2num(dtdata, epoch_units()) - return num2date(epnum, epoch_units()) + epnum = date2num(dtdata, EPOCH_UNITS) + return num2date(epnum, EPOCH_UNITS) else: return num2date(dataset.variables['time'][:], dataset.variables['time'].units) @@ -51,12 +52,11 @@ def datetime_from_grid(grid, epoch=False): """ Return a datetime for the volume start in a Grid. """ if epoch: dtrad = num2date(grid.time['data'][0], grid.time['units']) - epnum = date2num(dtrad, epoch_units()) - return num2date(epnum, epoch_units()) + epnum = date2num(dtrad, EPOCH_UNITS) + return num2date(epnum, EPOCH_UNITS) else: return num2date(grid.time['data'][0], grid.time['units']) -def epoch_units(): - """ Return the units used in converting to datetime in the - standard Epoch units. """ - return "seconds since 1970-01-01T00:00:00Z" +def get_epoch_units(): + """ Return the units of the standard Unix epoch time. """ + return EPOCH_UNITS From 493e51a66b7c36aac9cdd8ff1d85028894c2bbc6 Mon Sep 17 00:00:00 2001 From: Nick Guy Date: Tue, 19 Jan 2016 09:33:54 -0700 Subject: [PATCH 4/5] PEP8 on spacing of code. Removed commented out code from pyart.core.radar. Bug fix in radardisplay having to do with unused keyword. Additionally, removed datetime calculation of time variable as an attribute of RadarDisplay. --- pyart/core/radar.py | 4 ---- pyart/graph/radardisplay.py | 5 +---- pyart/util/datetime_utils.py | 9 +++++---- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/pyart/core/radar.py b/pyart/core/radar.py index 26cee2d21d..cb79e450c6 100644 --- a/pyart/core/radar.py +++ b/pyart/core/radar.py @@ -35,7 +35,6 @@ from ..config import get_metadata from ..lazydict import LazyLoadDict from .transforms import antenna_vectors_to_cartesian, cartesian_to_geographic -from ..util import datetime_utils class Radar(object): @@ -1028,9 +1027,6 @@ def join_radar(radar1, radar2): new_radar.time['data'] = np.append(r1num, r2num) new_radar.time['units'] = estring ### TODO Use new updated datetime_utils if accepted - # r1num = datetime_utils.datetimes_from_radar(radar1, epoch=True) - # r2num = datetime_utils.datetimes_from_radar(radar2, epoch=True) - # new_radar.time['units'] = datetime_utils.get_epoch_units() for var in new_radar.fields.keys(): sh1 = radar1.fields[var]['data'].shape diff --git a/pyart/graph/radardisplay.py b/pyart/graph/radardisplay.py index 0871747b5f..d41d64d5d5 100644 --- a/pyart/graph/radardisplay.py +++ b/pyart/graph/radardisplay.py @@ -116,7 +116,6 @@ def __init__(self, radar, shift=(0.0, 0.0)): units = radar.time['units'] calendar = radar.time['calendar'] self.time_begin = netCDF4.num2date(times, units, calendar) - self.times = datetimes_from_radar(radar) # sweep start and end indices self.starts = radar.sweep_start_ray_index['data'] @@ -587,7 +586,7 @@ def plot_vpt(self, field, mask_tuple=None, vmin=None, vmax=None, # set up the time axis if time_axis_flag: self._set_vpt_time_axis(ax, date_time_form=date_time_form, tz=tz) - x = self.times + x = datetimes_from_radar(radar) # mask the data where outside the limits if mask_outside: @@ -1063,8 +1062,6 @@ def _set_vpt_time_axis(self, ax, date_time_form=None, tz=None): """ if date_time_form is None: date_time_form = '%H:%M' - if date_MinTicker is None: - date_MinTicker = 'minute' # Set the date format date_Fmt = DateFormatter(date_time_form, tz=tz) diff --git a/pyart/util/datetime_utils.py b/pyart/util/datetime_utils.py index 0a52f5865e..7ebeda63fe 100644 --- a/pyart/util/datetime_utils.py +++ b/pyart/util/datetime_utils.py @@ -4,6 +4,7 @@ EPOCH_UNITS = "seconds since 1970-01-01T00:00:00Z" + def datetime_from_radar(radar, epoch=False): """ Return a datetime for the first ray in a Radar. """ if epoch: @@ -28,24 +29,24 @@ def datetime_from_dataset(dataset, epoch=False): """ Return a datetime for the first time in a netCDF Dataset. """ if epoch: dtdata = num2date(dataset.variables['time'][0], - dataset.variables['time'].units) + dataset.variables['time'].units) epnum = date2num(dtdata, EPOCH_UNITS) return num2date(epnum, EPOCH_UNITS) else: return num2date(dataset.variables['time'][0], - dataset.variables['time'].units) + dataset.variables['time'].units) def datetimes_from_dataset(dataset, epoch=False): """ Return an array of datetimes for the times in a netCDF Dataset. """ if epoch: dtdata = num2date(dataset.variables['time'][:], - dataset.variables['time'].units) + dataset.variables['time'].units) epnum = date2num(dtdata, EPOCH_UNITS) return num2date(epnum, EPOCH_UNITS) else: return num2date(dataset.variables['time'][:], - dataset.variables['time'].units) + dataset.variables['time'].units) def datetime_from_grid(grid, epoch=False): From 74c667df27d1cc900c844c214fd9779ecc6366e5 Mon Sep 17 00:00:00 2001 From: Nick Guy Date: Tue, 19 Jan 2016 09:50:54 -0700 Subject: [PATCH 5/5] Remove unneeded function in datetime_utils --- pyart/util/datetime_utils.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pyart/util/datetime_utils.py b/pyart/util/datetime_utils.py index 7ebeda63fe..444f2b6aad 100644 --- a/pyart/util/datetime_utils.py +++ b/pyart/util/datetime_utils.py @@ -57,7 +57,3 @@ def datetime_from_grid(grid, epoch=False): return num2date(epnum, EPOCH_UNITS) else: return num2date(grid.time['data'][0], grid.time['units']) - -def get_epoch_units(): - """ Return the units of the standard Unix epoch time. """ - return EPOCH_UNITS