本文整理汇总了Python中tests._utils.validates_against_xml_schema函数的典型用法代码示例。如果您正苦于以下问题:Python validates_against_xml_schema函数的具体用法?Python validates_against_xml_schema怎么用?Python validates_against_xml_schema使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了validates_against_xml_schema函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_serialize_statistics_metadata
def test_serialize_statistics_metadata(self):
expected = StringIO.StringIO("""\
<?xml version='1.0' encoding='UTF-8'?>
<nrml
xmlns:gml="http://www.opengis.net/gml"
xmlns="http://openquake.org/xmlns/nrml/0.4">
<aggregateLossCurve
investigationTime="10.0"
statistics="quantile"
quantileValue="0.5">
<poEs>1.0 0.5 0.1</poEs>
<losses>10.0000 20.0000 30.0000</losses>
<averageLoss>2.0000e+00</averageLoss>
</aggregateLossCurve>
</nrml>
""")
writer = writers.AggregateLossCurveXMLWriter(
self.filename,
investigation_time=10.0, statistics="quantile",
quantile_value=0.50)
data = AGGREGATE_LOSS_CURVE(
poes=[1.0, 0.5, 0.1], losses=[10.0, 20.0, 30.0], average_loss=2.)
writer.serialize(data)
_utils.assert_xml_equal(expected, self.filename)
self.assertTrue(_utils.validates_against_xml_schema(self.filename))
示例2: test_serialize_a_model
def test_serialize_a_model(self):
expected = StringIO.StringIO("""\
<?xml version='1.0' encoding='UTF-8'?>
<nrml
xmlns:gml="http://www.opengis.net/gml"
xmlns="http://openquake.org/xmlns/nrml/0.4">
<aggregateLossCurve
investigationTime="10.0"
sourceModelTreePath="b1_b2_b3"
gsimTreePath="b1_b2"
unit="USD">
<poEs>1.0 0.5 0.1</poEs>
<losses>10.0000 20.0000 30.0000</losses>
<averageLoss>3.0000e+00</averageLoss>
</aggregateLossCurve>
</nrml>
""")
writer = writers.AggregateLossCurveXMLWriter(
self.filename,
investigation_time=10.0, source_model_tree_path="b1_b2_b3",
gsim_tree_path="b1_b2", unit="USD")
data = AGGREGATE_LOSS_CURVE(
poes=[1.0, 0.5, 0.1], losses=[10.0, 20.0, 30.0], average_loss=3.)
writer.serialize(data)
_utils.assert_xml_equal(expected, self.filename)
self.assertTrue(_utils.validates_against_xml_schema(self.filename))
示例3: test_serialize_optional_metadata_xml
def test_serialize_optional_metadata_xml(self):
expected = StringIO.StringIO("""\
<?xml version='1.0' encoding='UTF-8'?>
<nrml xmlns:gml="http://www.opengis.net/gml"
xmlns="http://openquake.org/xmlns/nrml/0.4">
<lossMap investigationTime="10.0" poE="0.8" statistics="quantile"
quantileValue="0.5" lossCategory="economic" unit="USD">
<node>
<gml:Point>
<gml:pos>1.0 1.5</gml:pos>
</gml:Point>
<loss assetRef="asset_1" mean="15.23" stdDev="2"/>
</node>
</lossMap>
</nrml>
""")
writer = writers.LossMapXMLWriter(
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)
_utils.assert_xml_equal(expected, self.filename)
self.assertTrue(_utils.validates_against_xml_schema(self.filename))
示例4: test_serialize_using_hazard_realization_xml
def test_serialize_using_hazard_realization_xml(self):
expected = StringIO.StringIO("""\
<?xml version='1.0' encoding='UTF-8'?>
<nrml xmlns:gml="http://www.opengis.net/gml"
xmlns="http://openquake.org/xmlns/nrml/0.4">
<lossMap investigationTime="10.0" poE="0.8"
sourceModelTreePath="b1|b2" gsimTreePath="b3|b4"
lossCategory="economic" unit="USD">
<node>
<gml:Point>
<gml:pos>1.0 1.5</gml:pos>
</gml:Point>
<loss assetRef="asset_1" value="15.23"/>
</node>
</lossMap>
</nrml>
""")
writer = writers.LossMapXMLWriter(
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=None)]
writer.serialize(data)
_utils.assert_xml_equal(expected, self.filename)
self.assertTrue(_utils.validates_against_xml_schema(self.filename))
示例5: test_serialize
def test_serialize(self):
expected = StringIO.StringIO('''<?xml version='1.0' encoding='UTF-8'?>
<nrml xmlns:gml="http://www.opengis.net/gml" xmlns="http://openquake.org/xmlns/nrml/0.4">
<totalDmgDist>
<damageStates>no_damage slight moderate extensive complete</damageStates>
<damage ds="no_damage" mean="1.0" stddev="1.6"/>
<damage ds="slight" mean="34.8" stddev="18.3"/>
<damage ds="moderate" mean="64.2" stddev="19.8"/>
<damage ds="extensive" mean="64.3" stddev="19.7"/>
<damage ds="complete" mean="64.3" stddev="19.7"/>
</totalDmgDist>
</nrml>''')
damage_states = 'no_damage slight moderate extensive complete'.split()
writer = writers.DmgDistTotalXMLWriter(self.filename, damage_states)
data = [
(NO_DAMAGE, 1.0, 1.6),
(SLIGHT, 34.8, 18.3),
(MODERATE, 64.2, 19.8),
(EXTENSIVE, 64.3, 19.7),
(COMPLETE, 64.3, 19.7),
]
writer.serialize(_starmap(DMG_DIST_TOTAL, data))
_utils.assert_xml_equal(expected, self.filename)
self.assertTrue(_utils.validates_against_xml_schema(self.filename))
示例6: test_serialize_a_model_xml
def test_serialize_a_model_xml(self):
expected = StringIO.StringIO("""\
<?xml version='1.0' encoding='UTF-8'?>
<nrml xmlns:gml="http://www.opengis.net/gml"
xmlns="http://openquake.org/xmlns/nrml/0.4">
<lossMap investigationTime="10.0" poE="0.8" statistics="mean">
<node>
<gml:Point>
<gml:pos>1.0 1.5</gml:pos>
</gml:Point>
<loss assetRef="asset_1" value="15.23"/>
<loss assetRef="asset_2" value="16.23"/>
</node>
<node>
<gml:Point>
<gml:pos>2.0 2.5</gml:pos>
</gml:Point>
<loss assetRef="asset_3" value="17.23"/>
</node>
</lossMap>
</nrml>
""")
writer = writers.LossMapXMLWriter(
self.filename, investigation_time=10.0, poe=0.8,
statistics="mean"
)
writer.serialize(self.data)
_utils.assert_xml_equal(expected, self.filename)
self.assertTrue(_utils.validates_against_xml_schema(self.filename))
示例7: test_serialize_using_hazard_realization
def test_serialize_using_hazard_realization(self):
expected = StringIO.StringIO("""\
<?xml version='1.0' encoding='UTF-8'?>
<nrml xmlns:gml="http://www.opengis.net/gml" xmlns="http://openquake.org/xmlns/nrml/0.4">
<bcrMap interestRate="10.0" assetLifeExpectancy="50.0" sourceModelTreePath="b1|b2" gsimTreePath="b1|b2" lossCategory="economic" unit="USD">
<node>
<gml:Point>
<gml:pos>1.0 1.5</gml:pos>
</gml:Point>
<bcr assetRef="asset_1" ratio="15.23" aalOrig="10.5" aalRetr="20.5"/>
</node>
</bcrMap>
</nrml>
""")
writer = writers.BCRMapXMLWriter(
self.filename,
interest_rate=10.0, asset_life_expectancy=50.0,
source_model_tree_path="b1|b2", gsim_tree_path="b1|b2",
unit="USD", loss_category="economic")
data = [BCR_NODE(
asset_ref="asset_1", location=Point(1.0, 1.5),
bcr=15.23, average_annual_loss_original=10.5,
average_annual_loss_retrofitted=20.5)]
writer.serialize(data)
_utils.assert_xml_equal(expected, self.filename)
self.assertTrue(_utils.validates_against_xml_schema(self.filename))
示例8: test_serialize_a_model
def test_serialize_a_model(self):
expected = StringIO.StringIO(
"""\
<?xml version='1.0' encoding='UTF-8'?>
<nrml xmlns:gml="http://www.opengis.net/gml" xmlns="http://openquake.org/xmlns/nrml/0.4">
<bcrMap interestRate="10.0" assetLifeExpectancy="50.0" statistics="mean">
<node>
<gml:Point>
<gml:pos>1.0 1.5</gml:pos>
</gml:Point>
<bcr assetRef="asset_1" ratio="15.23" aalOrig="10.5" aalRetr="20.5"/>
<bcr assetRef="asset_2" ratio="16.23" aalOrig="11.5" aalRetr="40.5"/>
</node>
<node>
<gml:Point>
<gml:pos>2.0 2.5</gml:pos>
</gml:Point>
<bcr assetRef="asset_3" ratio="17.23" aalOrig="12.5" aalRetr="10.5"/>
</node>
</bcrMap>
</nrml>
"""
)
writer = writers.BCRMapXMLWriter(
self.filename, interest_rate=10.0, asset_life_expectancy=50.0, statistics="mean"
)
data = [
BCR_NODE(
asset_ref="asset_1",
location=Point(1.0, 1.5),
bcr=15.23,
average_annual_loss_original=10.5,
average_annual_loss_retrofitted=20.5,
),
BCR_NODE(
asset_ref="asset_2",
location=Point(1.0, 1.5),
bcr=16.23,
average_annual_loss_original=11.5,
average_annual_loss_retrofitted=40.5,
),
BCR_NODE(
asset_ref="asset_3",
location=Point(2.0, 2.5),
bcr=17.23,
average_annual_loss_original=12.5,
average_annual_loss_retrofitted=10.5,
),
]
writer.serialize(data)
_utils.assert_xml_equal(expected, self.filename)
self.assertTrue(_utils.validates_against_xml_schema(self.filename))
示例9: test_serialize
def test_serialize(self):
locations = [Location(i * 0.1, i * 0.1) for i in xrange(12)]
gmf_nodes = [GmfNode(i * 0.2, locations[i])
for i in xrange(12)]
gmfs = [
Gmf('SA', 0.1, 5.0, gmf_nodes[:2]),
Gmf('SA', 0.2, 5.0, gmf_nodes[2:4]),
Gmf('SA', 0.3, 5.0, gmf_nodes[4:6]),
Gmf('PGA', None, None, gmf_nodes[6:8]),
Gmf('PGA', None, None, gmf_nodes[8:10]),
Gmf('PGA', None, None, gmf_nodes[10:]),
]
expected = StringIO.StringIO("""\
<?xml version='1.0' encoding='UTF-8'?>
<nrml xmlns:gml="http://www.opengis.net/gml" xmlns="http://openquake.org/xmlns/nrml/0.4">
<gmfSet>
<gmf IMT="SA" saPeriod="0.1" saDamping="5.0">
<node gmv="0.0" lon="0.0" lat="0.0"/>
<node gmv="0.2" lon="0.1" lat="0.1"/>
</gmf>
<gmf IMT="SA" saPeriod="0.2" saDamping="5.0">
<node gmv="0.4" lon="0.2" lat="0.2"/>
<node gmv="0.6" lon="0.3" lat="0.3"/>
</gmf>
<gmf IMT="SA" saPeriod="0.3" saDamping="5.0">
<node gmv="0.8" lon="0.4" lat="0.4"/>
<node gmv="1.0" lon="0.5" lat="0.5"/>
</gmf>
<gmf IMT="PGA">
<node gmv="1.2" lon="0.6" lat="0.6"/>
<node gmv="1.4" lon="0.7" lat="0.7"/>
</gmf>
<gmf IMT="PGA">
<node gmv="1.6" lon="0.8" lat="0.8"/>
<node gmv="1.8" lon="0.9" lat="0.9"/>
</gmf>
<gmf IMT="PGA">
<node gmv="2.0" lon="1.0" lat="1.0"/>
<node gmv="2.2" lon="1.1" lat="1.1"/>
</gmf>
</gmfSet>
</nrml>
""")
try:
# Make a temp file to save the results to:
_, path = tempfile.mkstemp()
writer = writers.ScenarioGMFXMLWriter(path)
writer.serialize(gmfs)
utils.assert_xml_equal(expected, path)
self.assertTrue(utils.validates_against_xml_schema(path))
finally:
os.unlink(path)
示例10: test_serialize_an_insured_loss_curve
def test_serialize_an_insured_loss_curve(self):
expected = StringIO.StringIO("""\
<?xml version='1.0' encoding='UTF-8'?>
<nrml xmlns:gml="http://www.opengis.net/gml"
xmlns="http://openquake.org/xmlns/nrml/0.4">
<lossCurves insured="True" investigationTime="10.0"
sourceModelTreePath="b1_b2_b3" gsimTreePath="b1_b2" unit="USD">
<lossCurve assetRef="asset_1">
<gml:Point>
<gml:pos>1.0 1.5</gml:pos>
</gml:Point>
<poEs>1.0 0.5 0.1</poEs>
<losses>10.0 20.0 30.0</losses>
<averageLoss>1.0000e+00</averageLoss>
<stdDevLoss>5.0000e-01</stdDevLoss>
</lossCurve>
<lossCurve assetRef="asset_2">
<gml:Point>
<gml:pos>2.0 2.5</gml:pos>
</gml:Point>
<poEs>1.0 0.3 0.2</poEs>
<losses>20.0 30.0 40.0</losses>
<averageLoss>2.0000e+00</averageLoss>
<stdDevLoss>1.0000e-01</stdDevLoss>
</lossCurve>
</lossCurves>
</nrml>
""")
writer = writers.LossCurveXMLWriter(
self.filename,
investigation_time=10.0, source_model_tree_path="b1_b2_b3",
gsim_tree_path="b1_b2", unit="USD", insured=True)
data = [
LOSS_CURVE(
asset_ref="asset_1", location=Point(1.0, 1.5),
poes=[1.0, 0.5, 0.1], losses=[10.0, 20.0, 30.0],
loss_ratios=None, average_loss=1., stddev_loss=0.5),
LOSS_CURVE(
asset_ref="asset_2", location=Point(2.0, 2.5),
poes=[1.0, 0.3, 0.2], losses=[20.0, 30.0, 40.0],
loss_ratios=None, average_loss=2., stddev_loss=0.1),
]
writer.serialize(data)
_utils.assert_xml_equal(expected, self.filename)
self.assertTrue(_utils.validates_against_xml_schema(self.filename))
示例11: test_serialize_optional_metadata
def test_serialize_optional_metadata(self):
expected = StringIO.StringIO(
"""\
<?xml version='1.0' encoding='UTF-8'?>
<nrml xmlns:gml="http://www.opengis.net/gml" xmlns="http://openquake.org/xmlns/nrml/0.4">
<bcrMap interestRate="10.0" assetLifeExpectancy="50.0" statistics="quantile" quantileValue="0.5" lossCategory="economic" unit="USD">
<node>
<gml:Point>
<gml:pos>1.0 1.5</gml:pos>
</gml:Point>
<bcr assetRef="asset_1" ratio="15.23" aalOrig="10.5" aalRetr="20.5"/>
</node>
</bcrMap>
</nrml>
"""
)
writer = writers.BCRMapXMLWriter(
self.filename,
interest_rate=10.0,
asset_life_expectancy=50.0,
statistics="quantile",
quantile_value=0.50,
unit="USD",
loss_category="economic",
)
data = [
BCR_NODE(
asset_ref="asset_1",
location=Point(1.0, 1.5),
bcr=15.23,
average_annual_loss_original=10.5,
average_annual_loss_retrofitted=20.5,
)
]
writer.serialize(data)
_utils.assert_xml_equal(expected, self.filename)
self.assertTrue(_utils.validates_against_xml_schema(self.filename))
示例12: test_serialize_quantile
def test_serialize_quantile(self):
# Test serialization of qunatile curves.
expected = StringIO.StringIO("""\
<?xml version='1.0' encoding='UTF-8'?>
<nrml xmlns:gml="http://www.opengis.net/gml" xmlns="http://openquake.org/xmlns/nrml/0.4">
<hazardCurves statistics="quantile" quantileValue="0.15" IMT="SA" investigationTime="50.0" saPeriod="0.025" saDamping="5.0">
<IMLs>0.005 0.007 0.0098</IMLs>
<hazardCurve>
<gml:Point>
<gml:pos>38.0 -20.1</gml:pos>
</gml:Point>
<poEs>0.1 0.2 0.3</poEs>
</hazardCurve>
<hazardCurve>
<gml:Point>
<gml:pos>38.1 -20.2</gml:pos>
</gml:Point>
<poEs>0.4 0.5 0.6</poEs>
</hazardCurve>
<hazardCurve>
<gml:Point>
<gml:pos>38.2 -20.3</gml:pos>
</gml:Point>
<poEs>0.7 0.8 0.8</poEs>
</hazardCurve>
</hazardCurves>
</nrml>
""")
metadata = dict(
investigation_time=self.TIME, imt='SA', imls=self.IMLS,
sa_period=0.025, sa_damping=5.0, statistics='quantile',
quantile_value=0.15
)
writer = writers.HazardCurveXMLWriter(self.path, **metadata)
writer.serialize(self.data)
utils.assert_xml_equal(expected, self.path)
self.assertTrue(utils.validates_against_xml_schema(self.path))
示例13: test_serialize_complete_lt_ses
def test_serialize_complete_lt_ses(self):
ruptures = [
SESRupture(1,
5.5, 1.0, 40.0, 10.0, 'Active Shallow Crust',
False, False,
top_left_corner=(1.1, 1.01, 10.0),
top_right_corner=(2.1, 2.01, 20.0),
bottom_right_corner=(3.1, 3.01, 30.0),
bottom_left_corner=(4.1, 4.01, 40.0)),
SESRupture(2,
6.5, 0.0, 41.0, 0.0, 'Active Shallow Crust',
True, False,
lons=[
[5.1, 6.1],
[7.1, 8.1],
],
lats=[
[5.01, 6.01],
[7.01, 8.01],
],
depths=[
[10.5, 10.6],
[10.7, 10.8],
]),
SESRupture(3,
5.4, 2.0, 42.0, 12.0, 'Stable Shallow Crust',
False, False,
top_left_corner=(1.1, 1.01, 10.0),
top_right_corner=(2.1, 2.01, 20.0),
bottom_right_corner=(3.1, 3.01, 30.0),
bottom_left_corner=(4.1, 4.01, 40.0)),
SESRupture(4,
6.4, 3.0, 43.0, 13.0, 'Stable Shallow Crust',
True, False,
lons=[
[5.2, 6.2],
[7.2, 8.2],
],
lats=[
[5.02, 6.02],
[7.02, 8.02],
],
depths=[
[10.1, 10.2],
[10.3, 10.4],
]),
]
complete_lt_ses = SES(1, 250.0, ruptures)
expected = StringIO.StringIO("""\
<?xml version='1.0' encoding='UTF-8'?>
<nrml xmlns:gml="http://www.opengis.net/gml" xmlns="http://openquake.org/xmlns/nrml/0.4">
<stochasticEventSet id="1" investigationTime="250.0">
<rupture id="1" magnitude="5.5" strike="1.0" dip="40.0" rake="10.0" tectonicRegion="Active Shallow Crust">
<planarSurface>
<topLeft lon="1.1" lat="1.01" depth="10.0"/>
<topRight lon="2.1" lat="2.01" depth="20.0"/>
<bottomLeft lon="4.1" lat="4.01" depth="40.0"/>
<bottomRight lon="3.1" lat="3.01" depth="30.0"/>
</planarSurface>
</rupture>
<rupture id="2" magnitude="6.5" strike="0.0" dip="41.0" rake="0.0" tectonicRegion="Active Shallow Crust">
<mesh rows="2" cols="2">
<node row="0" col="0" lon="5.1" lat="5.01" depth="10.5"/>
<node row="0" col="1" lon="6.1" lat="6.01" depth="10.6"/>
<node row="1" col="0" lon="7.1" lat="7.01" depth="10.7"/>
<node row="1" col="1" lon="8.1" lat="8.01" depth="10.8"/>
</mesh>
</rupture>
<rupture id="3" magnitude="5.4" strike="2.0" dip="42.0" rake="12.0" tectonicRegion="Stable Shallow Crust">
<planarSurface>
<topLeft lon="1.1" lat="1.01" depth="10.0"/>
<topRight lon="2.1" lat="2.01" depth="20.0"/>
<bottomLeft lon="4.1" lat="4.01" depth="40.0"/>
<bottomRight lon="3.1" lat="3.01" depth="30.0"/>
</planarSurface>
</rupture>
<rupture id="4" magnitude="6.4" strike="3.0" dip="43.0" rake="13.0" tectonicRegion="Stable Shallow Crust">
<mesh rows="2" cols="2">
<node row="0" col="0" lon="5.2" lat="5.02" depth="10.1"/>
<node row="0" col="1" lon="6.2" lat="6.02" depth="10.2"/>
<node row="1" col="0" lon="7.2" lat="7.02" depth="10.3"/>
<node row="1" col="1" lon="8.2" lat="8.02" depth="10.4"/>
</mesh>
</rupture>
</stochasticEventSet>
</nrml>
""")
try:
_, path = tempfile.mkstemp()
writer = writers.SESXMLWriter(path, None, None)
writer.serialize([complete_lt_ses])
utils.assert_xml_equal(expected, path)
self.assertTrue(utils.validates_against_xml_schema(path))
finally:
os.unlink(path)
示例14: test_serialize_complete_lt_gmf
def test_serialize_complete_lt_gmf(self):
# Test data is:
# - 1 gmf set
# for each set:
# - 2 ground motion fields
# for each ground motion field:
# - 2 nodes
# Total nodes: 12
locations = [Location(i * 0.1, i * 0.1) for i in xrange(12)]
gmf_nodes = [GmfNode(i * 0.2, locations[i]) for i in xrange(12)]
gmfs = [
Gmf('SA', 0.1, 5.0, gmf_nodes[:2], 1),
Gmf('SA', 0.2, 5.0, gmf_nodes[2:4], 2),
Gmf('SA', 0.3, 5.0, gmf_nodes[4:6], 3),
Gmf('PGA', None, None, gmf_nodes[6:8], 4),
Gmf('PGA', None, None, gmf_nodes[8:10], 5),
Gmf('PGA', None, None, gmf_nodes[10:], 6),
]
gmf_set = GmfSet(gmfs, 350.0, 1)
expected = StringIO.StringIO("""\
<?xml version='1.0' encoding='UTF-8'?>
<nrml xmlns:gml="http://www.opengis.net/gml" xmlns="http://openquake.org/xmlns/nrml/0.4">
<gmfSet investigationTime="350.0" stochasticEventSetId="1">
<gmf IMT="SA" saPeriod="0.1" saDamping="5.0" ruptureId="1">
<node gmv="0.0" lon="0.0" lat="0.0"/>
<node gmv="0.2" lon="0.1" lat="0.1"/>
</gmf>
<gmf IMT="SA" saPeriod="0.2" saDamping="5.0" ruptureId="2">
<node gmv="0.4" lon="0.2" lat="0.2"/>
<node gmv="0.6" lon="0.3" lat="0.3"/>
</gmf>
<gmf IMT="SA" saPeriod="0.3" saDamping="5.0" ruptureId="3">
<node gmv="0.8" lon="0.4" lat="0.4"/>
<node gmv="1.0" lon="0.5" lat="0.5"/>
</gmf>
<gmf IMT="PGA" ruptureId="4">
<node gmv="1.2" lon="0.6" lat="0.6"/>
<node gmv="1.4" lon="0.7" lat="0.7"/>
</gmf>
<gmf IMT="PGA" ruptureId="5">
<node gmv="1.6" lon="0.8" lat="0.8"/>
<node gmv="1.8" lon="0.9" lat="0.9"/>
</gmf>
<gmf IMT="PGA" ruptureId="6">
<node gmv="2.0" lon="1.0" lat="1.0"/>
<node gmv="2.2" lon="1.1" lat="1.1"/>
</gmf>
</gmfSet>
</nrml>
""")
try:
# Make a temp file to save the results to:
_, path = tempfile.mkstemp()
writer = writers.EventBasedGMFXMLWriter(
path, None, None)
writer.serialize([gmf_set])
utils.assert_xml_equal(expected, path)
self.assertTrue(utils.validates_against_xml_schema(path))
finally:
os.unlink(path)
示例15: test_serialize
def test_serialize(self):
# Test data is:
# - 1 gmf collection
# - 3 gmf sets
# for each set:
# - 2 ground motion fields
# for each ground motion field:
# - 2 nodes
# Total nodes: 12
locations = [Location(i * 0.1, i * 0.1) for i in xrange(12)]
gmf_nodes = [GmfNode(i * 0.2, locations[i]) for i in xrange(12)]
gmfs = [
Gmf('SA', 0.1, 5.0, gmf_nodes[:2]),
Gmf('SA', 0.2, 5.0, gmf_nodes[2:4]),
Gmf('SA', 0.3, 5.0, gmf_nodes[4:6]),
Gmf('PGA', None, None, gmf_nodes[6:8]),
Gmf('PGA', None, None, gmf_nodes[8:10]),
Gmf('PGA', None, None, gmf_nodes[10:]),
]
gmf_sets = [
GmfSet(gmfs[:2], 50.0),
GmfSet(gmfs[2:4], 40.0),
GmfSet(gmfs[4:], 30.0),
]
gmf_collection = GmfCollection(gmf_sets)
expected = StringIO.StringIO("""\
<?xml version='1.0' encoding='UTF-8'?>
<nrml xmlns:gml="http://www.opengis.net/gml" xmlns="http://openquake.org/xmlns/nrml/0.4">
<gmfCollection sourceModelTreePath="b1_b2_b3" gsimTreePath="b1_b7_b15">
<gmfSet investigationTime="50.0">
<gmf IMT="SA" saPeriod="0.1" saDamping="5.0">
<node iml="0.0" lon="0.0" lat="0.0"/>
<node iml="0.2" lon="0.1" lat="0.1"/>
</gmf>
<gmf IMT="SA" saPeriod="0.2" saDamping="5.0">
<node iml="0.4" lon="0.2" lat="0.2"/>
<node iml="0.6" lon="0.3" lat="0.3"/>
</gmf>
</gmfSet>
<gmfSet investigationTime="40.0">
<gmf IMT="SA" saPeriod="0.3" saDamping="5.0">
<node iml="0.8" lon="0.4" lat="0.4"/>
<node iml="1.0" lon="0.5" lat="0.5"/>
</gmf>
<gmf IMT="PGA">
<node iml="1.2" lon="0.6" lat="0.6"/>
<node iml="1.4" lon="0.7" lat="0.7"/>
</gmf>
</gmfSet>
<gmfSet investigationTime="30.0">
<gmf IMT="PGA">
<node iml="1.6" lon="0.8" lat="0.8"/>
<node iml="1.8" lon="0.9" lat="0.9"/>
</gmf>
<gmf IMT="PGA">
<node iml="2.0" lon="1.0" lat="1.0"/>
<node iml="2.2" lon="1.1" lat="1.1"/>
</gmf>
</gmfSet>
</gmfCollection>
</nrml>
""")
sm_lt_path = 'b1_b2_b3'
gsim_lt_path = 'b1_b7_b15'
try:
# Make a temp file to save the results to:
_, path = tempfile.mkstemp()
writer = writers.EventBasedGMFXMLWriter(
path, sm_lt_path, gsim_lt_path)
writer.serialize(gmf_collection)
utils.assert_xml_equal(expected, path)
self.assertTrue(utils.validates_against_xml_schema(path))
finally:
os.unlink(path)