コード例 #1
0
 def test_360_day_calendar_nd_CalendarDateTime(self):
     # Test the case where the input is an nd-array.
     calendar = '360_day'
     unit = 'days since 2000-01-01'
     val = np.array(
         [[CalendarDateTime(cftime.datetime(2014, 8, 12), calendar)],
          [CalendarDateTime(cftime.datetime(2014, 8, 13), calendar)]])
     result = NetCDFTimeConverter().default_units(val, None)
     self.assertEqual(result, (calendar, unit, CalendarDateTime))
コード例 #2
0
 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)
コード例 #3
0
ファイル: util.py プロジェクト: JulianDekker/DOVAL
 def convert(cls, value, unit, axis):
     if not nc_axis_available:
         raise ValueError('In order to display cftime types with '
                          'matplotlib install the nc_time_axis '
                          'library using pip or from conda-forge '
                          'using:\n\tconda install -c conda-forge '
                          'nc_time_axis')
     if isinstance(value, cftime_types):
         value = CalendarDateTime(value.datetime, value.calendar)
     elif isinstance(value, np.ndarray):
         value = np.array([CalendarDateTime(v.datetime, v.calendar) for v in value])
     return super(CFTimeConverter, cls).convert(value, unit, axis)
コード例 #4
0
 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])
コード例 #5
0
ファイル: test_netcdftime.py プロジェクト: etraiger/iris
 def test_360_day_calendar(self):
     n = 360
     calendar = '360_day'
     time_unit = Unit('days since 1970-01-01 00:00', calendar=calendar)
     time_coord = AuxCoord(np.arange(n), 'time', units=time_unit)
     expected_ydata = np.array([
         CalendarDateTime(time_unit.num2date(point), calendar)
         for point in time_coord.points
     ])
     line1, = iplt.plot(time_coord)
     result_ydata = line1.get_ydata()
     self.assertArrayEqual(expected_ydata, result_ydata)
コード例 #6
0
ファイル: test_netcdftime.py プロジェクト: xigrug/iris
 def test_360_day_calendar(self):
     n = 360
     calendar = '360_day'
     time_unit = Unit('days since 1970-01-01 00:00', calendar=calendar)
     time_coord = AuxCoord(np.arange(n), 'time', units=time_unit)
     times = [time_unit.num2date(point) for point in time_coord.points]
     times = [netcdftime.datetime(atime.year, atime.month, atime.day,
                                  atime.hour, atime.minute, atime.second)
              for atime in times]
     expected_ydata = np.array([CalendarDateTime(time, calendar)
                                for time in times])
     line1, = iplt.plot(time_coord)
     result_ydata = line1.get_ydata()
     self.assertArrayEqual(expected_ydata, result_ydata)
コード例 #7
0
 def test_diff_datetime(self):
     other_cdt = CalendarDateTime(cftime.datetime(1992, 11, 23, 3, 6),
                                  '360_day')
     self.assertTrue(self.cdt != other_cdt)
コード例 #8
0
 def test_diff_cal(self):
     other_cdt = CalendarDateTime(cftime.datetime(1967, 7, 22, 3, 6),
                                  '365_day')
     self.assertTrue(self.cdt != other_cdt)
コード例 #9
0
 def setUp(self):
     self.cdt = CalendarDateTime(cftime.datetime(1967, 7, 22, 3, 6),
                                 '360_day')
コード例 #10
0
 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)
コード例 #11
0
 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.]))
コード例 #12
0
 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.)
コード例 #13
0
 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))
コード例 #14
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))
コード例 #15
0
 def test_diff_datetime(self):
     other_cdt = CalendarDateTime(netcdftime.datetime(1992, 11, 23, 3, 6),
                                  '360_day')
     self.assertFalse(self.cdt == other_cdt)
コード例 #16
0
 def test_diff_cal(self):
     other_cdt = CalendarDateTime(netcdftime.datetime(1967, 7, 22, 3, 6),
                                  '365_day')
     self.assertFalse(self.cdt == other_cdt)