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 setUp(self): # Load test data inputs = np.dsplit(testdata, 14) self.ir108 = inputs[0] self.ir039 = inputs[1] self.vis008 = inputs[2] self.nir016 = inputs[3] self.vis006 = inputs[4] self.ir087 = inputs[5] self.ir120 = inputs[6] self.elev = inputs[7] self.cot = inputs[8] self.reff = inputs[9] self.cwp = inputs[10] self.lat = inputs[11] self.lon = inputs[12] self.cth = inputs[13] self.time = datetime(2013, 11, 12, 8, 30, 00) # Create cloud mask testfilter = CloudFilter(self.ir108, ir108=self.ir108, ir039=self.ir039) ret, cloudmask = testfilter.apply() self.input = { 'ir108': self.ir108, 'vis006': self.vis006, 'nir016': self.nir016, 'ir039': self.ir039, 'cloudmask': cloudmask }
def test_cloud_filter(self): # Create cloud filter testfilter = CloudFilter(self.input['ir108'], **self.input) ret, mask = testfilter.apply() # Evaluate results self.assertAlmostEqual(self.ir108[0, 0], 244.044000086) self.assertAlmostEqual(self.ir039[20, 100], 269.573815979) self.assertAlmostEqual(testfilter.minpeak, -19.744686196671914) self.assertAlmostEqual(testfilter.maxpeak, 1.11645277953) self.assertAlmostEqual(testfilter.thres, -3.51935588185) self.assertEqual(np.sum(testfilter.mask), 20551)
def test_cloud_filter_plot(self): # Create cloud filter testfilter = CloudFilter(self.input['ir108'], **self.input) ret, mask = testfilter.apply() testfilter.plot_cloud_hist('/tmp/cloud_filter_hist_20131120830.png') testfilter.plot_filter(save=True) testfilter.plot_filter(save=True, area=area_def, type='tif') # Evaluate results self.assertAlmostEqual(self.ir108[0, 0], 244.044000086) self.assertAlmostEqual(self.ir039[20, 100], 269.573815979) self.assertAlmostEqual(testfilter.minpeak, -19.744686196671914) self.assertAlmostEqual(testfilter.maxpeak, 1.11645277953) self.assertAlmostEqual(testfilter.thres, -3.51935588185) self.assertEqual(np.sum(testfilter.mask), 20551)
def test_masked_cloud_filter(self): # Create cloud filter inarr = np.ma.masked_greater(self.input['ir108'], 275) testfilter = CloudFilter(inarr, **self.input) ret, mask = testfilter.apply() # Evaluate results np.testing.assert_almost_equal(self.ir108[0, 0], 244.044000086) np.testing.assert_almost_equal(self.ir039[20, 100], 269.573815979) np.testing.assert_almost_equal(testfilter.minpeak, -19.744686196671914) np.testing.assert_almost_equal(testfilter.maxpeak, 1.11645277953) np.testing.assert_almost_equal(testfilter.thres, -3.51935588185) self.assertEqual(np.sum(testfilter.mask), 20551) self.assertEqual(np.sum(testfilter.inmask), 4653) self.assertEqual(testfilter.new_masked, 15922)
def test_ccl_cloud_filter(self): # Create cloud filter testfilter = CloudFilter(self.input['ir108'], **self.input) ret, mask = testfilter.apply() # Evaluate results self.assertEqual(testfilter.ccl.squeeze().shape, (141, 298)) self.assertAlmostEqual(round(testfilter.ccl[95, 276], 3), 0.544) self.assertAlmostEqual(round(testfilter.ccl[29, 216], 3), 1) self.assertAlmostEqual(round(testfilter.ccl[78, 45], 3), 0.303) self.assertAlmostEqual(round(testfilter.ccl[61, 261], 3), 0) self.assertEqual(round(np.nanmax(testfilter.cm_diff), 2), 3.43) self.assertTrue( all(testfilter.ccl[testfilter.cm_diff < testfilter.thres] > 0.5)) self.assertTrue( all(testfilter.ccl[testfilter.cm_diff > testfilter.thres] < 0.5)) self.assertEqual(np.nanmax(testfilter.ccl), 1) self.assertEqual(np.nanmin(testfilter.ccl), 0)
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 setUp(self): # Load test data inputs = np.dsplit(testdata, 14) self.ir108 = inputs[0] self.ir039 = inputs[1] self.vis008 = inputs[2] self.nir016 = inputs[3] self.vis006 = inputs[4] self.ir087 = inputs[5] self.ir120 = inputs[6] self.elev = inputs[7] self.cot = inputs[8] self.reff = inputs[9] self.lwp = inputs[10] self.lat = inputs[11] self.lon = inputs[12] self.cth = inputs[13] self.time = datetime(2013, 11, 12, 8, 30, 00) self.input = { 'vis006': self.vis006, 'vis008': self.vis008, 'ir108': self.ir108, 'nir016': self.nir016, 'ir039': self.ir039, 'ir120': self.ir120, 'ir087': self.ir087, 'lat': self.lat, 'lon': self.lon, 'time': self.time, 'elev': self.elev, 'cot': self.cot, 'reff': self.reff, 'lwp': self.lwp, 'cth': self.cth, 'plot': True, 'save': True, 'dir': '/tmp/FLS', 'resize': '5' } # Create cloud top heights and clusters from fogpy.algorithms import DayFogLowStratusAlgorithm as FLS # Calculate cloud and snow masks cloudfilter = CloudFilter(self.ir108, **self.input) ret, self.cloudmask = cloudfilter.apply() snowfilter = SnowFilter(cloudfilter.result, **self.input) ret, snowmask = snowfilter.apply() # Get clusters fls = FLS(**self.input) self.clusters = FLS.get_cloud_cluster(self.cloudmask, False) self.clusters.mask[self.clusters != 120] = True self.input = { 'ir108': self.ir108, 'lwp': self.lwp, 'reff': self.reff, 'elev': self.elev, 'clusters': self.clusters, 'cth': self.cth } # Define small artificial test data dim = (2, 2, 1) test_ir = np.empty(dim) test_ir.fill(260) lwp_choice = np.array([0.01, 0.1, 1, 10, 100, 1000]) test_lwp_choice = np.random.choice(lwp_choice, dim) test_lwp_static = np.empty(dim) test_lwp_static.fill(94) test_reff = np.empty(dim) test_reff.fill(10e-6) test_cmask = np.empty(dim) test_cmask.fill(0) test_clusters = np.empty(dim) test_clusters.fill(1) test_clusters = np.ma.masked_array(test_clusters, test_cmask) test_elev = np.empty(dim) test_elev.fill(100) test_cth = np.empty(dim) test_cth.fill(200) # Testdata for ground cloud fog self.test_lwp1 = { 'ir108': test_ir, 'lwp': test_lwp_static, 'reff': test_reff, 'elev': test_elev, 'clusters': test_clusters, 'cth': test_cth } # Init with big droplet radius # Increase in droplet radius prevend declaration as ground fog test_reff = np.empty(dim) test_reff.fill(20e-5) self.test_lwp2 = { 'ir108': test_ir, 'lwp': test_lwp_static, 'reff': test_reff, 'elev': test_elev, 'clusters': test_clusters, 'cth': test_cth } # Randomly choose liquid water paths test_reff = np.empty(dim) test_reff.fill(10e-6) # Reset radius self.test_lwp3 = { 'ir108': test_ir, 'lwp': test_lwp_choice, 'reff': test_reff, 'elev': test_elev, 'clusters': test_clusters, 'cth': test_cth }