コード例 #1
0
def time_equal(a, b):
    if (a is None) and (b is None):
        return True
    elif (a is None) or (b is None):
        return False
    else:
        return _to_datetime(a) == _to_datetime(b)
コード例 #2
0
 def valid_times(self, pattern, variable, initial_time):
     if self.variable_id != variable:
         self.variable_id = variable
         self._cube = None
     self._parse_pattern(pattern)
     cube = self.cube
     valid_times = [gridded_forecast._to_datetime(cell.point) for cell in
                    cube.coord('time').cells()]
     return valid_times
コード例 #3
0
def select_args(state):
    """Select args needed by :func:`SeriesView.render`

    .. note:: If all criteria are not present None is returned

    :returns: args tuple or None
    """
    if any(att not in state
           for att in ["variable", "initial_time", "position"]):
        return
    if "pressure" in state:
        optional = (state["pressure"], )
    else:
        optional = ()
    return (_to_datetime(state["initial_time"]), state["variable"],
            state["position"]["x"], state["position"]["y"]) + optional
コード例 #4
0
    def image(self, state):
        """
        Main image loading function. This function will actually realise the
        data,
        """
        if self.variable_id != state.variable:
            self.variable_id = state.variable
            self._cube = None

        valid_time = state.valid_time
        pressure = state.pressure

        selected_time = gridded_forecast._to_datetime(valid_time)

        # the guts of creating the bokeh object has been put into a separate
        # function so that it can be cached, so if image is called multiple
        # time the calculations are only done once (hopefully).
        cube = self.cube
        coord_names = [c1.name() for c1 in cube.coords()]
        if 'air_pressure' in coord_names and pressure is None:
            data = gridded_forecast.empty_image()
            return data

        data = _get_bokeh_image(cube, self.experiment_id,
                                self.variable_id,
                                self.institution_id, state.initial_time,
                                self.member_id, selected_time, pressure)

        data.update(gridded_forecast.coordinates(str(selected_time),
                                                 state.initial_time,
                                                 state.pressures,
                                                 pressure))
        data.update({
            'name': [self._label],
            'units': [str(cube.units)],
            'experiment': [self.experiment_id],
            'institution': [self.institution_id],
            'memberid': [self.member_id],
            'variableid': [self.variable_id]
        })

        return data
コード例 #5
0
 def initial_times(self, pattern, variable=None):
     self._parse_pattern(pattern)
     cube = self.cube
     for cell in cube.coord('time').cells():
         init_time = gridded_forecast._to_datetime(cell.point)
         return [init_time]
コード例 #6
0
 def time_comp(select_time, time_cell):  #
     data_time = gridded_forecast._to_datetime(time_cell.point)
     if abs((select_time - data_time).days) < 2:
         return True
     return False
コード例 #7
0
 def test_unsupported(self):
     with self.assertRaisesRegex(Exception, 'Unknown value'):
         gridded_forecast._to_datetime(12)
コード例 #8
0
 def test_datetime64(self):
     dt = np.datetime64('2019-10-10T11:22:33')
     result = gridded_forecast._to_datetime(dt)
     self.assertEqual(result, datetime(2019, 10, 10, 11, 22, 33))
コード例 #9
0
 def test_str_iso8601(self):
     result = gridded_forecast._to_datetime('2019-10-10T01:02:34')
     self.assertEqual(result, datetime(2019, 10, 10, 1, 2, 34))
コード例 #10
0
 def test_datetime(self):
     dt = datetime.now()
     result = gridded_forecast._to_datetime(dt)
     self.assertEqual(result, dt)