def test_lcth_algorithm_real(self): # Compute cloud mask cloudfilter = CloudFilter(self.input['ir108'], **self.input) cloudfilter.apply() snowfilter = SnowFilter(cloudfilter.result, **self.input) snowfilter.apply() icefilter = IceCloudFilter(snowfilter.result, **self.input) icefilter.apply() cirrusfilter = CirrusCloudFilter(icefilter.result, **self.input) cirrusfilter.apply() waterfilter = WaterCloudFilter(cirrusfilter.result, cloudmask=cloudfilter.mask, **self.input) ret, mask = waterfilter.apply() self.ccl = cloudfilter.ccl self.input['ccl'] = self.ccl self.input['cloudmask'] = ret.mask lcthalgo = LowCloudHeightAlgorithm(**self.input) ret, mask = lcthalgo.run() self.assertEqual(lcthalgo.ir108.shape, (141, 298)) self.assertEqual(ret.shape, (141, 298)) self.assertEqual(lcthalgo.shape, (141, 298)) self.assertEqual(np.ma.is_mask(lcthalgo.mask), True) self.assertLessEqual(round(np.nanmax(lcthalgo.dz), 2), 1524.43)
def test_lcth_algorithm_artificial_next(self): lcthalgo = LowCloudHeightAlgorithm(**self.testnextinput) ret, mask = lcthalgo.run() self.assertEqual(lcthalgo.ir108.shape, (3, 3)) self.assertEqual(ret.shape, (3, 3)) self.assertEqual(lcthalgo.shape, (3, 3)) self.assertEqual(np.ma.is_mask(lcthalgo.mask), True) self.assertEqual(np.nanmax(lcthalgo.dz), 12.) self.assertEqual(np.around(lcthalgo.cth[1, 1], 2), 444.23)
def test_lcth_algorithm_artificial_complement(self): lcthalgo = LowCloudHeightAlgorithm(**self.testinput2) ret, mask = lcthalgo.run() self.assertEqual(lcthalgo.ir108.shape, (3, 3)) self.assertEqual(ret.shape, (3, 3)) self.assertEqual(lcthalgo.shape, (3, 3)) self.assertEqual(np.ma.is_mask(lcthalgo.mask), True) self.assertEqual(np.nanmax(lcthalgo.dz), 1300.) self.assertEqual(np.nanmax(np.around(lcthalgo.cth, 2)), 6168.06)
def test_lcth_algorithm_artificial(self): lcthalgo = LowCloudHeightAlgorithm(**self.testinput) ret, mask = lcthalgo.run() self.assertEqual(lcthalgo.ir108.shape, (3, 3)) self.assertEqual(ret.shape, (3, 3)) self.assertEqual(lcthalgo.shape, (3, 3)) self.assertEqual(np.ma.is_mask(lcthalgo.mask), True) self.assertEqual(np.nanmax(lcthalgo.dz), 800.) self.assertEqual(np.nanmax(lcthalgo.cth), 800.)
def test_lcth_algorithm_interpolate(self): lcthalgo = LowCloudHeightAlgorithm(**self.testinput) cth = np.random.random_integers(0, 10, (5, 5)).astype(float) cth[cth > 7] = np.nan mask = np.random.random_integers(0, 1, (5, 5)).astype(bool) result = lcthalgo.interpol_cth(cth, mask) self.assertEqual(result.shape, (5, 5)) self.assertTrue(np.all(np.isnan(result[mask]))) self.assertGreaterEqual(np.sum(np.isnan(result)), np.sum(mask))
def test_lcth_algorithm_linreg(self): lcthalgo = LowCloudHeightAlgorithm(**self.testinput) cth = np.random.randint(0, 10, (5, 5)).astype(float) ctt = np.random.randint(260, 290, (5, 5)).astype(float) cth[cth > 7] = np.nan mask = np.random.randint(0, 2, (5, 5)).astype(bool) result = lcthalgo.linreg_cth(cth, mask, ctt) self.assertEqual(result.shape, (5, 5)) self.assertTrue(np.all(np.isnan(result[mask]))) self.assertEqual(np.sum(np.isnan(result)), np.sum(mask))
def test_lcth_algorithm_nan_neighbor(self): lcthalgo = LowCloudHeightAlgorithm(**self.testinput) elev = np.empty((3, 3)) elev[:] = np.nan lcthalgo.elev = elev ret, mask = lcthalgo.run() self.assertEqual(lcthalgo.ir108.shape, (3, 3)) self.assertEqual(ret.shape, (3, 3)) self.assertEqual(lcthalgo.shape, (3, 3)) self.assertEqual(np.ma.is_mask(lcthalgo.mask), True) self.assertEqual(np.isnan(np.nanmax(lcthalgo.dz)), True) self.assertEqual(np.isnan(np.nanmax(lcthalgo.cth)), True)
def lcth_ok(): alg = LowCloudHeightAlgorithm() alg.elev = np.zeros((5, 5)) alg.ir108 = np.arange(260, 265, 0.2).reshape(5, 5) alg.ccl = np.ones((5, 5)) alg.clusters = np.array([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 1, 1, 0, 0], [0, 1, 1, 1, 0], [1, 1, 0, 0, 0]], dtype="i4") alg.dz = np.zeros((5, 5)) alg.cth = np.zeros((5, 5)) alg.nlapse = 0 return alg
def test_lcth_lapse_rate(self): lcthalgo = LowCloudHeightAlgorithm(**self.testinput) test_z = lcthalgo.apply_lapse_rate(265, 270, 1000) test_z2 = lcthalgo.apply_lapse_rate(260, 290, 800) test_z3 = lcthalgo.apply_lapse_rate(260, 290, 1000) test_z4 = lcthalgo.apply_lapse_rate(290, np.array([290, 260, 300]), np.array([1000, 1500, 900])) test_z5 = lcthalgo.apply_lapse_rate(290, 260, 1000) self.assertEqual(round(test_z, 2), 1925.93) self.assertEqual(round(test_z2, 2), 6355.56) self.assertEqual(round(test_z3, 2), 6555.56) self.assertEqual(test_z4[0], 1000.) self.assertTrue(np.isnan(test_z4[1])) self.assertEqual(round(test_z4[2], 2), 2751.85) self.assertTrue(np.isnan(test_z5))
def test_lcth_algorithm_interpolate(self): lcthalgo = LowCloudHeightAlgorithm(**self.testinput) # originally obtained with np.random.random_integers cth = np.array([[6., 3., 10., 7., 4.], [6., 9., 2., 6., 10.], [10., 7., 4., 3., 7.], [7., 2., 5., 4., 1.], [7., 5., 1., 4., 0.]]) cth[cth > 7] = np.nan mask = np.array([[True, True, True, False, True], [False, False, False, False, False], [True, True, True, True, True], [False, True, True, False, True], [False, True, False, True, True]]) result = lcthalgo.interpol_cth(cth, mask) self.assertEqual(result.shape, (5, 5)) self.assertTrue(np.all(np.isnan(result[mask]))) self.assertGreaterEqual(np.sum(np.isnan(result)), np.sum(mask))
def test_lcth_algorithm_linreg_cluster(self): """Test single cloud cluster linear regression interpolation""" # Get cloud parameters from fogpy.filters import CloudFilter cloudfilter = CloudFilter(self.ir108, **self.input) ret, mask = cloudfilter.apply() input = {'ir108': self.ir108, 'elev': self.elev, 'ccl': cloudfilter.ccl, 'cloudmask': cloudfilter.mask, 'interpolate': False, 'single': True} # Run LCTH algorithm lcthalgo = LowCloudHeightAlgorithm(**input) ret, mask = lcthalgo.run() # lcthalgo.plot_result() self.assertEqual(ret.shape, (141, 298)) self.assertEqual(lcthalgo.shape, (141, 298)) self.assertEqual(np.ma.is_mask(lcthalgo.mask), True) self.assertLessEqual(round(np.nanmax(lcthalgo.dz), 2), 1900)
def test_lcth_algorithm_linreg(self): lcthalgo = LowCloudHeightAlgorithm(**self.testinput) # originally obtained with np.random.randint cth = np.array([[6., 3., 7., 4., 6.], [9., 2., 6., 7., 4.], [3., 7., 7., 2., 5.], [4., 1., 7., 5., 1.], [4., 0., 9., 5., 8.]]) ctt = np.array([[276., 286., 286., 269., 287.], [287., 275., 274., 289., 289.], [274., 289., 278., 271., 282.], [279., 284., 262., 264., 278.], [266., 280., 268., 266., 277.]]) cth[cth > 7] = np.nan mask = np.array([[True, False, True, True, True], [True, False, True, False, True], [True, True, False, True, False], [True, False, True, False, False], [True, False, True, True, True]]) result = lcthalgo.linreg_cth(cth, mask, ctt) self.assertEqual(result.shape, (5, 5)) self.assertTrue(np.all(np.isnan(result[mask]))) self.assertEqual(np.sum(np.isnan(result)), np.sum(mask))
def test_lcth_cell_neighbors(self): lcthalgo = LowCloudHeightAlgorithm(**self.testinput) elev = self.testinput2['elev'] center, neigh, ids = lcthalgo.cell_neighbors(elev, 1, 1) compare = np.array([800., 900., 1000., 700., 600., 400., 300., 200.]) self.assertTrue(np.alltrue(compare == neigh)) # Test upper left corner center, neigh, ids = lcthalgo.cell_neighbors(elev, 0, 0) compare = np.array([900., 700., 1500.]) self.assertTrue(np.alltrue(compare == neigh)) # Test lower left corner center, neigh, ids = lcthalgo.cell_neighbors(elev, 2, 0) compare = np.array([700., 1500., 300.]) self.assertTrue(np.alltrue(compare == neigh)) # Test upper right corner center, neigh, ids = lcthalgo.cell_neighbors(elev, 0, 2) compare = np.array([900., 1500., 600.]) self.assertTrue(np.alltrue(compare == neigh)) # Test lower right corner center, neigh, ids = lcthalgo.cell_neighbors(elev, 2, 2) compare = np.array([1500., 600., 300.]) self.assertTrue(np.alltrue(compare == neigh)) # Test middle right cell center, neigh, ids = lcthalgo.cell_neighbors(elev, 1, 2) compare = np.array([900., 1000., 1500., 300., 200.]) self.assertTrue(np.alltrue(compare == neigh)) # Test middle left cell center, neigh, ids = lcthalgo.cell_neighbors(elev, 1, 0) compare = np.array([800., 900., 1500., 400., 300.]) self.assertTrue(np.alltrue(compare == neigh)) # Test upper middle cell center, neigh, ids = lcthalgo.cell_neighbors(elev, 0, 1) compare = np.array([800., 1000., 700., 1500., 600.]) self.assertTrue(np.alltrue(compare == neigh)) # Test lower middle cell center, neigh, ids = lcthalgo.cell_neighbors(elev, 2, 1) compare = np.array([700., 1500., 600., 400., 200.]) self.assertTrue(np.alltrue(compare == neigh))