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=writers.Site(1.0, 1.5), value=15.23, std_dev=2)] writer.serialize(data) actual = json.load(open(self.filename)) self.assertEqual(expected, actual)
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)
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=writers.Site(1.0, 1.5), value=15.23, std_dev=2)] writer.serialize(data) actual = json.load(open(self.filename)) self.assertEqual(expected, actual)
def test_empty_model_not_supported_geojson(self): writer = writers.LossMapGeoJSONWriter( self.filename, investigation_time=10.0, poe=0.5, statistics="mean", loss_type="structural" ) self.assertRaises(ValueError, writer.serialize, []) self.assertRaises(ValueError, writer.serialize, None)