예제 #1
0
 def test_anguilla_pass(self):
     country_name = ['Anguilla']
     ent = BlackMarble()
     ent.set_countries(country_name, 2013, res_km=0.2)
     self.assertEqual(ent.ref_year, 2013)
     self.assertIn("Anguilla 2013 GDP: 1.754e+08 income group: 3", ent.tag.description)
     self.assertAlmostEqual(ent.gdf.value.sum(), 1.754e+08 * (3 + 1))
     self.assertTrue(equal_crs(ent.crs, 'epsg:4326'))
예제 #2
0
    def test_spain_pass(self):
        country_name = ['Spain']
        ent = BlackMarble()
        with self.assertLogs('climada.util.finance', level='INFO') as cm:
            ent.set_countries(country_name, 2013, res_km=1)
        self.assertIn('GDP ESP 2013: 1.355e+12.', cm.output[0])
        self.assertIn('Income group ESP 2013: 4.', cm.output[1])

        with self.assertLogs('climada.entity.exposures.black_marble', level='INFO') as cm:
            ent.set_countries(country_name, 2013, res_km=1)
        self.assertIn("Nightlights from NOAA's earth observation group for year 2013.",
                      cm.output[0])
        self.assertIn("Processing country Spain.", cm.output[1])
        self.assertIn("Generating resolution of approx 1 km.", cm.output[2])
        self.assertTrue(np.isclose(ent.gdf.value.sum(), 1.355e+12 * (4 + 1), 0.001))
        self.assertTrue(equal_crs(ent.crs, 'epsg:4326'))
        self.assertEqual(ent.meta['width'], 2699)
        self.assertEqual(ent.meta['height'], 1938)
        self.assertTrue(equal_crs(ent.meta['crs'], 'epsg:4326'))
        self.assertAlmostEqual(ent.meta['transform'][0], 0.008333333333333333)
        self.assertAlmostEqual(ent.meta['transform'][1], 0)
        self.assertAlmostEqual(ent.meta['transform'][2], -18.1625000000000)
        self.assertAlmostEqual(ent.meta['transform'][3], 0)
        self.assertAlmostEqual(ent.meta['transform'][4], -0.008333333333333333)
        self.assertAlmostEqual(ent.meta['transform'][5], 43.79583333333333)
예제 #3
0
    def test_set_country_pass(self):
        """Test exposures attributes after black marble."""
        country_name = ['Switzerland', 'Germany']
        ent = BlackMarble()
        ent.set_countries(country_name, 2013, res_km=5.0)
        ent.check()

        self.assertEqual(np.unique(ent.gdf.region_id).size, 2)
        self.assertEqual(ent.ref_year, 2013)
        self.assertIn('Switzerland 2013 GDP: ', ent.tag.description)
        self.assertIn('Germany 2013 GDP: ', ent.tag.description)
        self.assertIn('income group: 4', ent.tag.description)
        self.assertIn('income group: 4', ent.tag.description)
        self.assertIn('F182013.v4c_web.stable_lights.avg_vis.p', ent.tag.file_name)
        self.assertIn('F182013.v4c_web.stable_lights.avg_vis.p', ent.tag.file_name)
예제 #4
0
    def test_switzerland_pass(self):
        country_name = ['Switzerland']
        ent = BlackMarble()
        with self.assertLogs('climada.util.finance', level='INFO') as cm:
            ent.set_countries(country_name, 1968, res_km=0.5)
        self.assertIn('GDP CHE 1968: 1.894e+10.', cm.output[0])
        self.assertIn('Income group CHE 1987: 4.', cm.output[1])

        with self.assertLogs('climada.entity.exposures.black_marble', level='INFO') as cm:
            ent.set_countries(country_name, 1968, res_km=0.5)
        self.assertIn("Nightlights from NOAA's earth observation group for year 1992.", cm.output[0])
        self.assertTrue("Processing country Switzerland." in cm.output[-2])
        self.assertTrue("Generating resolution of approx 0.5 km." in cm.output[-1])
        self.assertTrue(np.isclose(ent.value.sum(), 1.894e+10*(4+1), 4))
        self.assertEqual(ent.crs, {'init': 'epsg:4326'})
예제 #5
0
    def test_spain_pass(self):
        country_name = ['Spain']
        ent = BlackMarble()
        with self.assertLogs('climada.util.finance', level='INFO') as cm:
            ent.set_countries(country_name, 2013, res_km=1)
        self.assertIn('GDP ESP 2013: 1.362e+12.', cm.output[0])
        self.assertIn('Income group ESP 2013: 4.', cm.output[1])

        with self.assertLogs('climada.entity.exposures.black_marble', level='INFO') as cm:
            ent.set_countries(country_name, 2013, res_km=1)
        self.assertIn("Nightlights from NOAA's earth observation group for year 2013.", cm.output[0])
        self.assertIn("Processing country Spain.", cm.output[1])
        self.assertIn("Generating resolution of approx 1 km.", cm.output[2])
        self.assertTrue(np.isclose(ent.value.sum(), 1.362e+12*(4+1), 4))
        self.assertEqual(ent.crs, {'init': 'epsg:4326'})
예제 #6
0
    def test_sint_maarten_pass(self):
        country_name = ['Sint Maarten']
        ent = BlackMarble()
        with self.assertLogs('climada.util.finance', level='INFO') as cm:
            ent.set_countries(country_name, 2013, res_km=0.2)
        self.assertIn('GDP SXM 2014: 3.658e+08.', cm.output[0])
        self.assertIn('Income group SXM 2013: 4.', cm.output[1])
        self.assertEqual(ent.crs, {'init': 'epsg:4326'})

        with self.assertLogs('climada.entity.exposures.black_marble', level='INFO') as cm:
            ent.set_countries(country_name, 2013, res_km=0.2)
        self.assertIn("Nightlights from NOAA's earth observation group for year 2013.", cm.output[0])
        self.assertIn("Processing country Sint Maarten.", cm.output[1])
        self.assertIn("Generating resolution of approx 0.2 km.", cm.output[2])
        self.assertAlmostEqual(ent.value.sum(), 3.658e+08*(4+1))
        self.assertEqual(ent.crs, {'init': 'epsg:4326'})
예제 #7
0
    def test_sint_maarten_pass(self):
        country_name = ['Sint Maarten']
        ent = BlackMarble()
        with self.assertLogs('climada.util.finance', level='INFO') as cm:
            ent.set_countries(country_name, 2013, res_km=0.2)
        self.assertIn('GDP SXM 2013: 1.023e+09.', cm.output[0])
        self.assertIn('Income group SXM 2013: 4.', cm.output[1])
        self.assertTrue(equal_crs(ent.crs, 'epsg:4326'))

        with self.assertLogs('climada.entity.exposures.black_marble', level='INFO') as cm:
            ent.set_countries(country_name, 2013, res_km=0.2)
        self.assertIn("Nightlights from NOAA's earth observation group for year 2013.",
                      cm.output[0])
        self.assertIn("Processing country Sint Maarten.", cm.output[1])
        self.assertIn("Generating resolution of approx 0.2 km.", cm.output[2])
        self.assertTrue(np.isclose(ent.gdf.value.sum(), 1.023e+09 * (4 + 1), 0.001))
        self.assertTrue(equal_crs(ent.crs, 'epsg:4326'))
예제 #8
0
    def test_from_hr_flag_pass(self):
        """Check from_hr flag in set_countries method."""
        country_name = ['Turkey']

        ent = BlackMarble()
        with self.assertLogs('climada.entity.exposures.black_marble', level='INFO') as cm:
            ent.set_countries(country_name, 2012, res_km=5.0)
        self.assertTrue('NOAA' in cm.output[-3])
        size1 = ent.gdf.value.size
        self.assertTrue(np.isclose(ent.gdf.value.sum(), 8.740e+11 * (3 + 1), 4))

        try:
            ent = BlackMarble()
            with self.assertLogs('climada.entity.exposures.black_marble', level='INFO') as cm:
                ent.set_countries(country_name, 2012, res_km=5.0, from_hr=True)
                self.assertTrue('NASA' in cm.output[-3])
                size2 = ent.gdf.value.size
                self.assertTrue(size1 < size2)
                self.assertTrue(np.isclose(ent.gdf.value.sum(), 8.740e+11 * (3 + 1), 4))
        except TypeError:
            print('MemoryError caught')
            pass

        ent = BlackMarble()
        with self.assertLogs('climada.entity.exposures.black_marble', level='INFO') as cm:
            ent.set_countries(country_name, 2012, res_km=5.0, from_hr=False)
        self.assertTrue('NOAA' in cm.output[-3])
        self.assertTrue(np.isclose(ent.gdf.value.sum(), 8.740e+11 * (3 + 1), 4))
        size3 = ent.gdf.value.size
        self.assertEqual(size1, size3)
        self.assertTrue(equal_crs(ent.crs, 'epsg:4326'))