Beispiel #1
0
 def test_360_day_calendar(self):
     calendar = '360_day'
     unit = 'days since 2000-01-01'
     val = [netcdftime.datetime(2014, 8, 12)]
     val[0].calendar = calendar
     result = NetCDFTimeConverter().default_units(val, None)
     self.assertEqual(result, (calendar, unit))
Beispiel #2
0
 def test_360_day_calendar_nd_raw_date(self):
     # Test the case where the input is an nd-array.
     calendar = '360_day'
     unit = 'days since 2000-01-01'
     val = np.array([[cftime.Datetime360Day(2014, 8, 12)],
                     [cftime.Datetime360Day(2014, 8, 13)]])
     result = NetCDFTimeConverter().default_units(val, None)
     self.assertEqual(result, (calendar, unit, cftime.Datetime360Day))
 def test_nonequal_calendars(self):
     # Test that different supplied calendars causes an error.
     calendar_1 = '360_day'
     calendar_2 = '365_day'
     unit = 'days since 2000-01-01'
     val = [CalendarDateTime(netcdftime.datetime(2014, 8, 12), calendar_1),
            CalendarDateTime(netcdftime.datetime(2014, 8, 13), calendar_2)]
     with self.assertRaisesRegexp(ValueError, 'not all equal'):
         NetCDFTimeConverter().default_units(val, None)
 def test_axis_default_limits(self):
     cal = '360_day'
     unit = (cal, 'days since 2000-02-25 00:00:00')
     result = NetCDFTimeConverter().axisinfo(unit, None)
     expected_dt = [netcdftime.datetime(2000, 1, 1),
                    netcdftime.datetime(2010, 1, 1)]
     np.testing.assert_array_equal(
         result.default_limits,
         [CalendarDateTime(edt, cal) for edt in expected_dt])
 def test_360_day_calendar_nd(self):
     # Test the case where the input is an nd-array.
     calendar = '360_day'
     unit = 'days since 2000-01-01'
     val = np.array([[CalendarDateTime(netcdftime.datetime(2014, 8, 12),
                                       calendar)],
                    [CalendarDateTime(netcdftime.datetime(2014, 8, 13),
                                      calendar)]])
     result = NetCDFTimeConverter().default_units(val, None)
     self.assertEqual(result, (calendar, unit))
 def test_360_day_calendar_list(self):
     calendar = '360_day'
     unit = 'days since 2000-01-01'
     val = [CalendarDateTime(netcdftime.datetime(2014, 8, 12), calendar)]
     result = NetCDFTimeConverter().default_units(val, None)
     self.assertEqual(result, (calendar, unit))
Beispiel #7
0
 def test_cftime_np_array_raw_date(self):
     val = np.array([cftime.Datetime360Day(2012, 6, 4)], dtype=np.object)
     result = NetCDFTimeConverter().convert(val, None, None)
     self.assertEqual(result, np.array([4473.]))
 def test_netcdftime_np_array(self):
     val = np.array([CalendarDateTime(netcdftime.datetime(2012, 6, 4),
                                      '360_day')], dtype=np.object)
     result = NetCDFTimeConverter().convert(val, None, None)
     self.assertEqual(result, np.array([4473.]))
 def test_numeric_iterable(self):
     val = [12, 18]
     result = NetCDFTimeConverter().convert(val, None, None)
     np.testing.assert_array_equal(result, val)
Beispiel #10
0
 def test_no_calendar_attribute(self):
     val = [netcdftime.datetime(2014, 8, 12)]
     msg = 'Expecting netcdftimes with an extra "calendar" attribute.'
     with self.assertRaisesRegexp(ValueError, msg):
         result = NetCDFTimeConverter().default_units(val, None)
Beispiel #11
0
 def test_default_limits(self):
     unit = ('360_day', 'days since 2000-02-25 00:00:00')
     result = NetCDFTimeConverter().axisinfo(unit, None)
     np.testing.assert_array_equal(result.default_limits,
                                   [netcdftime.datetime(2000, 1, 1),
                                    netcdftime.datetime(2010, 1, 1)])
Beispiel #12
0
 def test_360_day_calendar_list_raw_date(self):
     calendar = '360_day'
     unit = 'days since 2000-01-01'
     val = [cftime.Datetime360Day(2014, 8, 12)]
     result = NetCDFTimeConverter().default_units(val, None)
     self.assertEqual(result, (calendar, unit, cftime.Datetime360Day))
Beispiel #13
0
 def test_360_day_calendar_point_CalendarDateTime(self):
     calendar = '360_day'
     unit = 'days since 2000-01-01'
     val = CalendarDateTime(cftime.datetime(2014, 8, 12), calendar)
     result = NetCDFTimeConverter().default_units(val, None)
     self.assertEqual(result, (calendar, unit, CalendarDateTime))
Beispiel #14
0
 def test_non_CalendarDateTime(self):
     val = 'test'
     msg = 'The values must be numbers or instances of ' \
           '"nc_time_axis.CalendarDateTime".'
     with assertRaisesRegex(self, ValueError, msg):
         result = NetCDFTimeConverter().convert(val, None, None)
 def test_numpy_array(self):
     val = np.array([7])
     result = NetCDFTimeConverter().convert(val, None, None)
     np.testing.assert_array_equal(result, val)
Beispiel #16
0
 def test_netcdftime_np_array(self):
     val = np.array([netcdftime.datetime(2012, 6, 4)], dtype=np.object)
     for date in val:
         date.calendar = '360_day'
     result = NetCDFTimeConverter().convert(val, None, None)
     self.assertEqual(result, np.array([4473.]))
 def test_numpy_nd_array(self):
     shape = (4, 2)
     val = np.arange(8).reshape(shape)
     result = NetCDFTimeConverter().convert(val, None, None)
     np.testing.assert_array_equal(result, val)
     self.assertEqual(result.shape, shape)
Beispiel #18
0
 def test_no_calendar_attribute(self):
     val = netcdftime.datetime(2014, 8, 12)
     msg = 'A "calendar" attribute must be attached'
     with self.assertRaisesRegexp(ValueError, msg):
         result = NetCDFTimeConverter().convert(val, None, None)
 def test_netcdftime(self):
     val = CalendarDateTime(netcdftime.datetime(2014, 8, 12), '365_day')
     result = NetCDFTimeConverter().convert(val, None, None)
     np.testing.assert_array_equal(result, 5333.)
 def test_non_CalendarDateTime(self):
     val = netcdftime.datetime(1988, 5, 6)
     msg = 'The values must be numbers or instances of ' \
           '"nc_time_axis.CalendarDateTime".'
     with self.assertRaisesRegexp(ValueError, msg):
         result = NetCDFTimeConverter().convert(val, None, None)
 def test_non_netcdftime_datetime(self):
     val = CalendarDateTime(4, '360_day')
     msg = 'The datetime attribute of the CalendarDateTime object must ' \
           'be of type `netcdftime.datetime`.'
     with self.assertRaisesRegexp(ValueError, msg):
         result = NetCDFTimeConverter().convert(val, None, None)
Beispiel #22
0
 def test_cftime_raw_date(self):
     val = cftime.DatetimeNoLeap(2014, 8, 12)
     result = NetCDFTimeConverter().convert(val, None, None)
     np.testing.assert_array_equal(result, 5333.)