コード例 #1
0
 def test_get_hazard(self):
     client = Client()
     hazard = client.get_hazard(hazard_type='river_flood',
                                properties={
                                    'country_name': 'Austria',
                                    'year_range': '2010_2030',
                                    'climate_scenario': 'rcp26'
                                },
                                dump_dir=DATA_DIR)
     self.assertEqual(np.shape(hazard.intensity), (480, 5784))
     self.assertEqual(np.unique(hazard.centroids.region_id), 40)
     self.assertEqual(np.unique(hazard.date).size, 20)
     self.assertEqual(hazard.tag.haz_type, 'RF')
コード例 #2
0
    def test_get_hazard_fails(self):
        client = Client()
        with self.assertRaises(ValueError) as cm:
            client.get_hazard(hazard_type='litpop',
                              properties={
                                  'country_name': 'Austria',
                                  'year_range': '2010_2030',
                                  'climate_scenario': 'rcp26'
                              },
                              dump_dir=DATA_DIR)
        self.assertIn(
            'Valid hazard types are a subset of CLIMADA hazard types. Currently',
            str(cm.exception))

        with self.assertRaises(Client.AmbiguousResult) as cm:
            client.get_hazard(hazard_type='river_flood',
                              properties={
                                  'country_name': ['Switzerland', 'Austria'],
                                  'year_range': '2010_2030',
                                  'climate_scenario': ['rcp26', 'rcp85']
                              },
                              dump_dir=DATA_DIR)
        self.assertIn('there are several datasets meeting the requirements:',
                      str(cm.exception))