Esempio n. 1
0
    def test_serialize_optional_metadata_geojson(self):
        expected = {
            'oqtype': 'LossMap',
            'oqnrmlversion': '0.4',
            'oqmetadata': {
                'investigationTime': '10.0',
                'poE': '0.8',
                'statistics': 'quantile',
                'quantileValue': '0.5',
                'unit': 'USD',
                'lossCategory': 'economic',
            },
            'type': 'FeatureCollection',
            'features': [
                {'geometry': {'coordinates': [1.0, 1.5], 'type': 'Point'},
                 'properties': {'losses': [
                    {'assetRef': 'asset_1', 'mean': '15.23', 'stdDev': '2'},
                 ]},
                 'type': 'Feature'},
            ],
        }

        writer = writers.LossMapGeoJSONWriter(
            self.filename,
            investigation_time=10.0, poe=0.80, statistics="quantile",
            quantile_value=0.50, unit="USD", loss_category="economic"
        )

        data = [LOSS_NODE(
                asset_ref="asset_1", location=Point(1.0, 1.5), value=15.23,
                std_dev=2)]

        writer.serialize(data)
        actual = json.load(open(self.filename))
        self.assertEqual(expected, actual)
Esempio n. 2
0
    def test_serialize_using_hazard_realization_geojson(self):
        expected = {
            'oqtype': 'LossMap',
            'oqnrmlversion': '0.4',
            'oqmetadata': {
                'investigationTime': '10.0',
                'poE': '0.8',
                'sourceModelTreePath': 'b1|b2',
                'gsimTreePath': 'b3|b4',
                'unit': 'USD',
                'lossCategory': 'economic',
            },
            'type': 'FeatureCollection',
            'features': [
                {'geometry': {'coordinates': [1.0, 1.5], 'type': 'Point'},
                 'properties': {'losses': [
                    {'assetRef': 'asset_1', 'mean': '15.23', 'stdDev': '2'},
                 ]},
                 'type': 'Feature'},
            ],
        }

        writer = writers.LossMapGeoJSONWriter(
            self.filename,
            investigation_time=10.0, poe=0.80, source_model_tree_path="b1|b2",
            gsim_tree_path="b3|b4", unit="USD", loss_category="economic"
        )

        data = [LOSS_NODE(
                asset_ref="asset_1", location=Point(1.0, 1.5), value=15.23,
                std_dev=2)]

        writer.serialize(data)
        actual = json.load(open(self.filename))
        self.assertEqual(expected, actual)
Esempio n. 3
0
    def test_serialize_a_model_geojson(self):
        expected = {
            'oqtype': 'LossMap',
            'oqnrmlversion': '0.4',
            'oqmetadata': {
                'investigationTime': '10.0',
                'poE': '0.8',
                'statistics': 'mean',
            },
            'type': 'FeatureCollection',
            'features': [
                {'geometry': {'coordinates': [1.0, 1.5], 'type': 'Point'},
                 'properties': {'losses': [
                    {'assetRef': 'asset_1', 'value': '15.23'},
                    {'assetRef': 'asset_2', 'value': '16.23'},
                 ]},
                 'type': 'Feature'},
                {'geometry': {'coordinates': [2.0, 2.5], 'type': 'Point'},
                 'properties': {'losses': [
                    {'assetRef': 'asset_3', 'value': '17.23'},
                 ]},
                 'type': 'Feature'},
            ],
        }
        writer = writers.LossMapGeoJSONWriter(
            self.filename, investigation_time=10.0, poe=0.8,
            statistics="mean"
        )

        writer.serialize(self.data)

        actual = json.load(open(self.filename))
        self.assertEqual(expected, actual)
Esempio n. 4
0
    def test_empty_model_not_supported_geojson(self):
        writer = writers.LossMapGeoJSONWriter(
            self.filename, investigation_time=10.0, poe=0.5,
            statistics="mean"
        )

        self.assertRaises(ValueError, writer.serialize, [])
        self.assertRaises(ValueError, writer.serialize, None)
Esempio n. 5
0
    def test_serialize_a_model_geojson(self):
        expected = {
            u'features': [{
                u'geometry': {
                    u'coordinates': [1.0, 1.5],
                    u'type': u'Point'
                },
                u'properties': {
                    u'asset_ref': u'asset_1',
                    u'loss': 15.23
                },
                u'type': u'Feature'
            }, {
                u'geometry': {
                    u'coordinates': [1.0, 1.5],
                    u'type': u'Point'
                },
                u'properties': {
                    u'asset_ref': u'asset_2',
                    u'loss': 16.23
                },
                u'type': u'Feature'
            }, {
                u'geometry': {
                    u'coordinates': [2.0, 2.5],
                    u'type': u'Point'
                },
                u'properties': {
                    u'asset_ref': u'asset_3',
                    u'loss': 17.23
                },
                u'type': u'Feature'
            }],
            u'oqmetadata': {
                u'investigationTime': u'10.0',
                u'lossType': u'structural',
                u'poE': u'0.8',
                u'statistics': u'mean'
            },
            u'oqnrmlversion':
            u'0.4',
            u'oqtype':
            u'LossMap',
            u'type':
            u'FeatureCollection'
        }
        writer = writers.LossMapGeoJSONWriter(self.filename,
                                              investigation_time=10.0,
                                              poe=0.8,
                                              statistics="mean",
                                              loss_type="structural")

        writer.serialize(self.data)

        actual = json.load(open(self.filename))
        self.assertEqual(expected, actual)
Esempio n. 6
0
    def test_serialize_using_hazard_realization_geojson(self):
        expected = {
            u'features': [{
                u'geometry': {
                    u'coordinates': [1.0, 1.5],
                    u'type': u'Point'
                },
                u'properties': {
                    u'asset_ref': u'asset_1',
                    u'loss': 15.23,
                    u'std_dev': 2.0
                },
                u'type': u'Feature'
            }],
            u'oqmetadata': {
                u'gsimTreePath': u'b3|b4',
                u'investigationTime': u'10.0',
                u'lossCategory': u'economic',
                u'lossType': u'structural',
                u'poE': u'0.8',
                u'sourceModelTreePath': u'b1|b2',
                u'unit': u'USD'
            },
            u'oqnrmlversion':
            u'0.4',
            u'oqtype':
            u'LossMap',
            u'type':
            u'FeatureCollection'
        }

        writer = writers.LossMapGeoJSONWriter(self.filename,
                                              investigation_time=10.0,
                                              poe=0.80,
                                              source_model_tree_path="b1|b2",
                                              gsim_tree_path="b3|b4",
                                              unit="USD",
                                              loss_category="economic",
                                              loss_type="structural")

        data = [
            LOSS_NODE(asset_ref="asset_1",
                      location=Point(1.0, 1.5),
                      value=15.23,
                      std_dev=2)
        ]

        writer.serialize(data)
        actual = json.load(open(self.filename))
        self.assertEqual(expected, actual)
Esempio n. 7
0
    def test_serialize_optional_metadata_geojson(self):
        expected = {
            u'features': [{
                u'geometry': {
                    u'coordinates': [1.0, 1.5],
                    u'type': u'Point'
                },
                u'properties': {
                    u'asset_ref': u'asset_1',
                    u'loss': 15.23,
                    u'std_dev': 2.0
                },
                u'type': u'Feature'
            }],
            u'oqmetadata': {
                u'investigationTime': u'10.0',
                u'lossCategory': u'economic',
                u'lossType': u'structural',
                u'poE': u'0.8',
                u'quantileValue': u'0.5',
                u'statistics': u'quantile',
                u'unit': u'USD'
            },
            u'oqnrmlversion':
            u'0.4',
            u'oqtype':
            u'LossMap',
            u'type':
            u'FeatureCollection'
        }

        writer = writers.LossMapGeoJSONWriter(self.filename,
                                              investigation_time=10.0,
                                              poe=0.80,
                                              statistics="quantile",
                                              quantile_value=0.50,
                                              unit="USD",
                                              loss_category="economic",
                                              loss_type="structural")

        data = [
            LOSS_NODE(asset_ref="asset_1",
                      location=Point(1.0, 1.5),
                      value=15.23,
                      std_dev=2)
        ]

        writer.serialize(data)
        actual = json.load(open(self.filename))
        self.assertEqual(expected, actual)