def test_two_files_pass(self): """Test set function set_from_tracks with two ibtracs.""" tc_track = TCTracks() tc_track.read_processed_ibtracs_csv( [TEST_TRACK_SHORT, TEST_TRACK_SHORT]) tc_haz = TCRain() tc_haz.set_from_tracks(tc_track, CENTR_TEST_BRB) tc_haz.remove_duplicates() tc_haz.check() self.assertEqual(tc_haz.tag.haz_type, 'TR') self.assertEqual(tc_haz.tag.description, '') self.assertEqual(tc_haz.tag.file_name, ['IBTrACS: 1951239N12334', 'IBTrACS: 1951239N12334']) self.assertEqual(tc_haz.units, 'mm') self.assertEqual(tc_haz.centroids.size, 296) self.assertEqual(tc_haz.event_id.size, 1) self.assertEqual(tc_haz.event_id[0], 1) self.assertEqual(tc_haz.event_name, ['1951239N12334']) self.assertTrue(np.array_equal(tc_haz.frequency, np.array([1]))) self.assertTrue(np.array_equal(tc_haz.orig, np.array([True]))) self.assertTrue(isinstance(tc_haz.intensity, sparse.csr.csr_matrix)) self.assertTrue(isinstance(tc_haz.fraction, sparse.csr.csr_matrix)) self.assertEqual(tc_haz.intensity.shape, (1, 296)) self.assertEqual(tc_haz.fraction.shape, (1, 296)) self.assertEqual(tc_haz.fraction.nonzero()[0].size, 0) self.assertEqual(tc_haz.intensity.nonzero()[0].size, 0)
def test_set_one_pass(self): """Test _set_from_track function.""" tc_track = TCTracks() tc_track.read_processed_ibtracs_csv(TEST_TRACK) tc_track.equal_timestep() tc_haz = TCRain._set_from_track(tc_track.data[0], CENTR_TEST_BRB) self.assertEqual(tc_haz.tag.haz_type, 'TR') self.assertEqual(tc_haz.tag.description, '') self.assertEqual(tc_haz.tag.file_name, 'IBTrACS: 1951239N12334') self.assertEqual(tc_haz.units, 'mm') self.assertEqual(tc_haz.centroids.size, 296) self.assertEqual(tc_haz.event_id.size, 1) self.assertEqual(tc_haz.date.size, 1) self.assertEqual(dt.datetime.fromordinal(tc_haz.date[0]).year, 1951) self.assertEqual(dt.datetime.fromordinal(tc_haz.date[0]).month, 8) self.assertEqual(dt.datetime.fromordinal(tc_haz.date[0]).day, 27) self.assertEqual(tc_haz.event_id[0], 1) self.assertEqual(tc_haz.event_name, ['1951239N12334']) self.assertTrue(np.array_equal(tc_haz.frequency, np.array([1]))) self.assertTrue(isinstance(tc_haz.intensity, sparse.csr.csr_matrix)) self.assertTrue(isinstance(tc_haz.fraction, sparse.csr.csr_matrix)) self.assertEqual(tc_haz.intensity.shape, (1, 296)) self.assertEqual(tc_haz.fraction.shape, (1, 296)) self.assertAlmostEqual(tc_haz.intensity[0, 100], 99.7160586771286, 6) self.assertAlmostEqual(tc_haz.intensity[0, 260], 33.2087621869295) self.assertEqual(tc_haz.fraction[0, 100], 1) self.assertEqual(tc_haz.fraction[0, 260], 1) self.assertEqual(tc_haz.fraction.nonzero()[0].size, 296) self.assertEqual(tc_haz.intensity.nonzero()[0].size, 296)
def test_set_one_file_pass(self): """Test set function set_from_tracks with one input.""" tc_track = TCTracks() tc_track.read_processed_ibtracs_csv(TEST_TRACK_SHORT) tc_haz = TCRain() tc_haz.set_from_tracks(tc_track, CENTR_TEST_BRB) tc_haz.check() self.assertEqual(tc_haz.tag.haz_type, 'TR') self.assertEqual(tc_haz.tag.description, '') self.assertEqual(tc_haz.tag.file_name, 'IBTrACS: 1951239N12334') self.assertEqual(tc_haz.units, 'mm') self.assertEqual(tc_haz.centroids.size, 296) self.assertEqual(tc_haz.event_id.size, 1) self.assertEqual(tc_haz.event_id[0], 1) self.assertEqual(tc_haz.event_name, ['1951239N12334']) self.assertEqual(tc_haz.category, tc_track.data[0].category) self.assertEqual(tc_haz.basin[0], "NA") self.assertIsInstance(tc_haz.basin, list) self.assertIsInstance(tc_haz.category, np.ndarray) self.assertTrue(np.array_equal(tc_haz.frequency, np.array([1]))) self.assertTrue(isinstance(tc_haz.intensity, sparse.csr.csr_matrix)) self.assertTrue(isinstance(tc_haz.fraction, sparse.csr.csr_matrix)) self.assertEqual(tc_haz.intensity.shape, (1, 296)) self.assertEqual(tc_haz.fraction.shape, (1, 296)) self.assertEqual(tc_haz.fraction.nonzero()[0].size, 0) self.assertEqual(tc_haz.intensity.nonzero()[0].size, 0)
def test_rainfield_diff_time_steps(self): tc_track = TCTracks() tc_track.read_processed_ibtracs_csv(TEST_TRACK) train_org = TCRain() train_org.set_from_tracks(tc_track) tc_track.equal_timestep(time_step_h=1) train_1h = TCRain() train_1h.set_from_tracks(tc_track) tc_track.equal_timestep(time_step_h=0.5) train_05h = TCRain() train_05h.set_from_tracks(tc_track) np.testing.assert_allclose(train_org.intensity.sum(), train_1h.intensity.sum(), rtol=1e-1) np.testing.assert_allclose(train_org.intensity.sum(), train_05h.intensity.sum(), rtol=1e-1) np.testing.assert_allclose(train_05h.intensity.sum(), train_1h.intensity.sum(), rtol=1e-1)