예제 #1
0
 def test_err(self):
     # missing ruptureId
     fname = os.path.join(DATADIR,  'gmfdata_err.xml')
     with self.assertRaises(readinput.InvalidFile) as ctx:
         readinput.get_scenario_from_nrml(self.oqparam, fname)
     self.assertIn("Found a missing etag '0000000001'",
                   str(ctx.exception))
예제 #2
0
 def test_err(self):
     # missing ruptureId
     fname = os.path.join(DATADIR,  'gmfdata_err.xml')
     with self.assertRaises(readinput.InvalidFile) as ctx:
         readinput.get_scenario_from_nrml(self.oqparam, fname)
     self.assertIn("Found a missing etag 'scenario-0000000001'",
                   str(ctx.exception))
예제 #3
0
    def test_two_nodes_on_the_same_point(self):
        # after rounding of the coordinates two points can collide
        fname = general.writetmp('''\
<?xml version="1.0" encoding="utf-8"?>
<nrml xmlns="http://openquake.org/xmlns/nrml/0.4"
      xmlns:gml="http://www.opengis.net/gml">
<gmfCollection gsimTreePath="" sourceModelTreePath="">
  <gmfSet stochasticEventSetId="1">
    <gmf IMT="PGA" ruptureId="0">
      <node gmv="0.0126515007046" lon="12.12477995" lat="43.5812"/>
      <node gmv="0.0124056290492" lon="12.12478193" lat="43.5812"/>
    </gmf>
  </gmfSet>
</gmfCollection>
</nrml>''')
        self.oqparam.imtls = {'PGA': None}
        with self.assertRaises(readinput.InvalidFile) as ctx:
            readinput.get_scenario_from_nrml(self.oqparam, fname)
        self.assertIn("Expected 1 sites, got 2 nodes in", str(ctx.exception))
예제 #4
0
    def test_ok(self):
        fname = os.path.join(DATADIR,  'gmfdata.xml')
        eids, gmfa = readinput.get_scenario_from_nrml(self.oqparam, fname)
        assert_allclose(eids, range(5))
        self.assertEqual(
            writers.write_csv(BytesIO(), gmfa), b'''\
PGA:float32,PGV:float32
6.824957E-01 3.656627E-01 8.700833E-01 3.279292E-01 6.968687E-01,6.824957E-01 3.656627E-01 8.700833E-01 3.279292E-01 6.968687E-01
1.270898E-01 2.561812E-01 2.106384E-01 2.357551E-01 2.581405E-01,1.270898E-01 2.561812E-01 2.106384E-01 2.357551E-01 2.581405E-01
1.603097E-01 1.106853E-01 2.232175E-01 1.781143E-01 1.351649E-01,1.603097E-01 1.106853E-01 2.232175E-01 1.781143E-01 1.351649E-01''')
예제 #5
0
    def test_two_nodes_on_the_same_point(self):
        # after rounding of the coordinates two points can collide
        fname = general.writetmp('''\
<?xml version="1.0" encoding="utf-8"?>
<nrml xmlns="http://openquake.org/xmlns/nrml/0.4"
      xmlns:gml="http://www.opengis.net/gml">
<gmfCollection gsimTreePath="" sourceModelTreePath="">
  <gmfSet stochasticEventSetId="1">
    <gmf IMT="PGA" ruptureId="scenario-0">
      <node gmv="0.0126515007046" lon="12.12477995" lat="43.5812"/>
      <node gmv="0.0124056290492" lon="12.12478193" lat="43.5812"/>
    </gmf>
  </gmfSet>
</gmfCollection>
</nrml>''')
        self.oqparam.imtls = {'PGA': None}
        with self.assertRaises(readinput.InvalidFile) as ctx:
            readinput.get_scenario_from_nrml(self.oqparam, fname)
        self.assertIn("Expected 1 sites, got 2 nodes in", str(ctx.exception))
예제 #6
0
    def test_ok(self):
        fname = os.path.join(DATADIR,  'gmfdata.xml')
        eids, gmfa = readinput.get_scenario_from_nrml(self.oqparam, fname)
        assert_allclose(eids, range(5))
        self.assertEqual(
            writers.write_csv(BytesIO(), gmfa), b'''\
PGA,PGV
6.824957E-01 3.656627E-01 8.700833E-01 3.279292E-01 6.968687E-01,6.824957E-01 3.656627E-01 8.700833E-01 3.279292E-01 6.968687E-01
1.270898E-01 2.561812E-01 2.106384E-01 2.357551E-01 2.581405E-01,1.270898E-01 2.561812E-01 2.106384E-01 2.357551E-01 2.581405E-01
1.603097E-01 1.106853E-01 2.232175E-01 1.781143E-01 1.351649E-01,1.603097E-01 1.106853E-01 2.232175E-01 1.781143E-01 1.351649E-01''')
예제 #7
0
    def test_ok(self):
        fname = os.path.join(DATADIR,  'gmfdata.xml')
        sitecol, etags, gmfa = readinput.get_scenario_from_nrml(
            self.oqparam, fname)
        coords = list(zip(sitecol.mesh.lons, sitecol.mesh.lats))
        self.assertEqual(writers.write_csv(StringIO(), coords), '''\
0.000000E+00,0.000000E+00
0.000000E+00,1.000000E-01
0.000000E+00,2.000000E-01''')
        assert_allclose(etags, range(5))
        self.assertEqual(
            writers.write_csv(StringIO(), gmfa), '''\
PGA:float32,PGV:float32
6.824957E-01 3.656627E-01 8.700833E-01 3.279292E-01 6.968687E-01,6.824957E-01 3.656627E-01 8.700833E-01 3.279292E-01 6.968687E-01
1.270898E-01 2.561812E-01 2.106384E-01 2.357551E-01 2.581405E-01,1.270898E-01 2.561812E-01 2.106384E-01 2.357551E-01 2.581405E-01
1.603097E-01 1.106853E-01 2.232175E-01 1.781143E-01 1.351649E-01,1.603097E-01 1.106853E-01 2.232175E-01 1.781143E-01 1.351649E-01''')
예제 #8
0
    def test_ok(self):
        fname = os.path.join(DATADIR,  'gmfdata.xml')
        sitecol, etags, gmfa = readinput.get_scenario_from_nrml(
            self.oqparam, fname)
        coords = list(zip(sitecol.mesh.lons, sitecol.mesh.lats))
        self.assertEqual(writers.write_csv(StringIO(), coords), '''\
0.000000E+00,0.000000E+00
0.000000E+00,1.000000E-01
0.000000E+00,2.000000E-01''')
        self.assertEqual(b'\n'.join(etags), b'''\
scenario-0000000000
scenario-0000000001
scenario-0000000002
scenario-0000000003
scenario-0000000004''')
        self.assertEqual(
            writers.write_csv(StringIO(), gmfa), '''\
PGA:float32,PGV:float32
6.824957E-01 3.656627E-01 8.700833E-01 3.279292E-01 6.968687E-01,6.824957E-01 3.656627E-01 8.700833E-01 3.279292E-01 6.968687E-01
1.270898E-01 2.561812E-01 2.106384E-01 2.357551E-01 2.581405E-01,1.270898E-01 2.561812E-01 2.106384E-01 2.357551E-01 2.581405E-01
1.603097E-01 1.106853E-01 2.232175E-01 1.781143E-01 1.351649E-01,1.603097E-01 1.106853E-01 2.232175E-01 1.781143E-01 1.351649E-01''')
예제 #9
0
    def test_tricky_ordering(self):
        # see https://github.com/gem/oq-risklib/issues/546
        fname = general.writetmp('''\
<?xml version="1.0" encoding="utf-8"?>
<nrml xmlns="http://openquake.org/xmlns/nrml/0.4"
      xmlns:gml="http://www.opengis.net/gml">
<gmfCollection gsimTreePath="" sourceModelTreePath="">
  <gmfSet stochasticEventSetId="1">
    <gmf IMT="PGA" ruptureId="0">
      <node gmv="0.0124783118478" lon="12.1244171" lat="43.58248037"/>
      <node gmv="0.0126515007046" lon="12.12477995" lat="43.58217888"/>
      <node gmv="0.0124056290492" lon="12.12478193" lat="43.58120146"/>
    </gmf>
  </gmfSet>
</gmfCollection>
</nrml>''')
        self.oqparam.imtls = {'PGA': None}
        sitecol, _, _ = readinput.get_scenario_from_nrml(self.oqparam, fname)
        self.assertEqual(list(zip(sitecol.lons, sitecol.lats)),
                         [(12.12442, 43.58248), (12.12478, 43.5812),
                          (12.12478, 43.58218)])
예제 #10
0
    def test_ok(self):
        fname = os.path.join(DATADIR,  'gmfdata.xml')
        sitecol, tags, gmfa = readinput.get_scenario_from_nrml(
            self.oqparam, fname)
        coords = zip(sitecol.mesh.lons, sitecol.mesh.lats)
        self.assertEqual(writers.write_csv(StringIO(), coords), '''\
0.00000000E+00,0.00000000E+00
0.00000000E+00,1.00000000E-01
0.00000000E+00,2.00000000E-01''')
        self.assertEqual('\n'.join(tags), '''\
scenario-0000000000
scenario-0000000001
scenario-0000000002
scenario-0000000003
scenario-0000000004''')
        self.assertEqual(
            writers.write_csv(StringIO(), gmfa), '''\
PGV:float64:,PGA:float64:
6.82495715E-01 3.65662735E-01 8.70083359E-01 3.27929201E-01 6.96868642E-01,6.82495715E-01 3.65662735E-01 8.70083359E-01 3.27929201E-01 6.96868642E-01
1.27089832E-01 2.56181252E-01 2.10638411E-01 2.35755152E-01 2.58140526E-01,1.27089832E-01 2.56181252E-01 2.10638411E-01 2.35755152E-01 2.58140526E-01
1.60309678E-01 1.10685275E-01 2.23217460E-01 1.78114255E-01 1.35164914E-01,1.60309678E-01 1.10685275E-01 2.23217460E-01 1.78114255E-01 1.35164914E-01''')
예제 #11
0
    def test_tricky_ordering(self):
        # see https://github.com/gem/oq-risklib/issues/546
        fname = general.writetmp('''\
<?xml version="1.0" encoding="utf-8"?>
<nrml xmlns="http://openquake.org/xmlns/nrml/0.4"
      xmlns:gml="http://www.opengis.net/gml">
<gmfCollection gsimTreePath="" sourceModelTreePath="">
  <gmfSet stochasticEventSetId="1">
    <gmf IMT="PGA" ruptureId="scenario-0">
      <node gmv="0.0124783118478" lon="12.1244171" lat="43.58248037"/>
      <node gmv="0.0126515007046" lon="12.12477995" lat="43.58217888"/>
      <node gmv="0.0124056290492" lon="12.12478193" lat="43.58120146"/>
    </gmf>
  </gmfSet>
</gmfCollection>
</nrml>''')
        self.oqparam.imtls = {'PGA': None}
        sitecol, _, _ = readinput.get_scenario_from_nrml(self.oqparam, fname)
        self.assertEqual(list(zip(sitecol.lons, sitecol.lats)),
                         [(12.12442, 43.58248),
                          (12.12478, 43.5812),
                          (12.12478, 43.58218)])
예제 #12
0
 def test_err2(self):
     # wrong mesh
     fname = os.path.join(DATADIR,  'gmfdata_err2.xml')
     with self.assertRaises(readinput.InvalidFile) as ctx:
         readinput.get_scenario_from_nrml(self.oqparam, fname)
     self.assertIn("Expected 4 sites, got 3 nodes in", str(ctx.exception))
예제 #13
0
 def test_err2(self):
     # wrong mesh
     fname = os.path.join(DATADIR,  'gmfdata_err2.xml')
     with self.assertRaises(readinput.InvalidFile) as ctx:
         readinput.get_scenario_from_nrml(self.oqparam, fname)
     self.assertIn("Expected 4 sites, got 3 nodes in", str(ctx.exception))