Пример #1
0
    def test_serialize(self):
        expected_file = helpers.get_data_path(
            "expected-dmg-dist-total.xml")

        expected_text = open(expected_file, "r").readlines()

        self.make_dist()

        self.make_data("no_damage", 1.0, 1.6)
        self.make_data("slight", 34.8, 18.3)
        self.make_data("moderate", 64.2, 19.8)
        self.make_data("extensive", 64.3, 19.7)
        self.make_data("complete", 64.3, 19.7)

        try:
            _, result_xml = tempfile.mkstemp()

            writer = DmgDistTotalXMLWriter(result_xml,
                    "ebl1", self.damage_states)

            writer.serialize(self.data)
            actual_text = open(result_xml, "r").readlines()

            self.assertEqual(expected_text, actual_text)

            self.assertTrue(xml.validates_against_xml_schema(
                    result_xml))
        finally:
            os.unlink(result_xml)
    def test_writes_a_single_result(self):
        data = [(shapes.Site(-122.5000, 37.5000),
                {"IDmodel": "MMI_3_1",
                "investigationTimeSpan": 50.0,
                "endBranchLabel": "3_1",
                "IMLValues": [5.0000e-03, 7.0000e-03, 1.3700e-02,
                1.9200e-02, 2.6900e-02, 3.7600e-02, 5.2700e-02,
                7.3800e-02, 9.8000e-02, 1.0300e-01, 1.4500e-01,
                2.0300e-01, 2.8400e-01, 3.9700e-01, 5.5600e-01,
                7.7800e-01, 1.0900e+00, 1.5200e+00, 2.1300e+00],
                "saPeriod": 0.1,
                "saDamping": 1.0,
                "IMT": "PGA",
                "PoEValues": [9.8728e-01, 9.8266e-01, 9.4957e-01,
                9.0326e-01, 8.1956e-01, 6.9192e-01, 5.2866e-01,
                3.6143e-01, 2.4231e-01, 2.2452e-01, 1.2831e-01,
                7.0352e-02, 3.6060e-02, 1.6579e-02, 6.4213e-03,
                2.0244e-03, 4.8605e-04, 8.1752e-05, 7.3425e-06]})]

        path = helpers.get_output_path(TEST_FILE_SINGLE_RESULT)

        self._initialize_writer(path)
        self.writer.serialize(data)

        self.assertTrue(xml.validates_against_xml_schema(path))
        self.assertTrue(XML_METADATA in self._result_as_string(path))

        self.read_curves = self._read_curves(
                (-123.0, 38.0), (-122.0, 35.0),
                TEST_FILE_SINGLE_RESULT)

        self._assert_number_of_curves_is(1)
        self._assert_curves_are(data)
Пример #3
0
        def verify_quantile_haz_maps_stored_to_nrml(the_job, calculator):
            """Tests that quantile hazard map NRML files have been written,
            and that these file validate against the NRML schema.
            Does NOT test if results in NRML files are correct.
            """

            quantiles = calculator.quantile_levels

            if (the_job.params[hazard_general.POES_PARAM_NAME] != ''
                    and len(quantiles) > 0):

                for poe in calculator.poes_hazard_maps:
                    for quantile in quantiles:
                        nrml_path = os.path.join(
                            "demos/classical_psha_simple/computed_output",
                            calculator.quantile_hazard_map_filename(
                                quantile, poe))

                        LOG.debug("validating NRML file for quantile hazard "\
                            "map: %s" % nrml_path)

                        self.assertTrue(xml.validates_against_xml_schema(
                            nrml_path, NRML_SCHEMA_PATH),
                            "NRML instance file %s does not validate against "\
                            "schema" % nrml_path)
Пример #4
0
        def verify_quantile_haz_maps_stored_to_nrml(the_job, calculator):
            """Tests that quantile hazard map NRML files have been written,
            and that these file validate against the NRML schema.
            Does NOT test if results in NRML files are correct.
            """

            quantiles = calculator.quantile_levels

            if (the_job.params[hazard_general.POES_PARAM_NAME] != '' and
                len(quantiles) > 0):

                for poe in calculator.poes_hazard_maps:
                    for quantile in quantiles:
                        nrml_path = os.path.join(
                            "demos/classical_psha_simple/computed_output",
                            calculator.quantile_hazard_map_filename(quantile,
                                                                   poe))

                        LOG.debug("validating NRML file for quantile hazard "\
                            "map: %s" % nrml_path)

                        self.assertTrue(xml.validates_against_xml_schema(
                            nrml_path, NRML_SCHEMA_PATH),
                            "NRML instance file %s does not validate against "\
                            "schema" % nrml_path)
Пример #5
0
        def verify_quantile_haz_maps_stored_to_nrml(hazengine):
            """Tests that quantile hazard map NRML files have been written,
            and that these file validate against the NRML schema.
            Does NOT test if results in NRML files are correct.
            """

            quantiles = classical_psha._extract_values_from_config(hazengine,
                classical_psha.QUANTILE_PARAM_NAME)

            if (hazengine.params[classical_psha.POES_PARAM_NAME] != '' and
                len(quantiles) > 0):

                poes = classical_psha._extract_values_from_config(hazengine,
                    classical_psha.POES_PARAM_NAME)

                for quantile in quantiles:
                    for poe in poes:
                        nrml_path = os.path.join(
                            "smoketests/classical_psha_simple/computed_output",
                            opensha.quantile_hm_filename(quantile, poe))

                        LOG.debug("validating NRML file for quantile hazard "\
                            "map: %s" % nrml_path)

                        self.assertTrue(xml.validates_against_xml_schema(
                            nrml_path, NRML_SCHEMA_PATH),
                            "NRML instance file %s does not validate against "\
                            "schema" % nrml_path)
Пример #6
0
    def test_serialize(self):
        expected_file = helpers.get_data_path(
            "expected-dmg-dist-total.xml")

        expected_text = open(expected_file, "r").readlines()

        self.make_dist()

        self.make_data("no_damage", 1.0, 1.6)
        self.make_data("slight", 34.8, 18.3)
        self.make_data("moderate", 64.2, 19.8)
        self.make_data("extensive", 64.3, 19.7)
        self.make_data("complete", 64.3, 19.7)

        try:
            _, result_xml = tempfile.mkstemp()

            writer = DmgDistTotalXMLWriter(result_xml,
                    "ebl1", self.damage_states)

            writer.serialize(self.data)
            actual_text = open(result_xml, "r").readlines()

            self.assertEqual(expected_text, actual_text)

            self.assertTrue(xml.validates_against_xml_schema(
                    result_xml))
        finally:
            os.unlink(result_xml)
Пример #7
0
    def test_writes_the_config_only_once(self):
        data = [(shapes.Site(-122.5000, 37.5000), {
            "IDmodel": "MMI_3_1",
            "investigationTimeSpan": 50.0,
            "endBranchLabel": "3_1",
            "IMLValues": [5.0, 6.0, 7.0],
            "saPeriod": 0.1,
            "saDamping": 1.0,
            "IMT": "PGA",
            "PoEValues": [0.1, 0.2, 0.3]
        }),
                (shapes.Site(-122.4000, 37.5000), {
                    "IDmodel": "MMI_3_1",
                    "investigationTimeSpan": 50.0,
                    "endBranchLabel": "3_2",
                    "IMLValues": [5.0, 6.0, 7.0],
                    "saPeriod": 0.1,
                    "saDamping": 1.0,
                    "IMT": "PGA",
                    "PoEValues": [0.4, 0.5, 0.6]
                })]

        path = helpers.get_output_path(TEST_FILE_CONFIG_ONCE)
        self._initialize_writer(path)

        self.writer.serialize(data)
        self.assertTrue(xml.validates_against_xml_schema(path))
    def test_write_multiple_result_nodes(self):
        result_data = [
            dict(groundMotionValue=0.25, path="filea"),
            dict(groundMotionValue=0.76, path="fileb"),
            dict(groundMotionValue=0.11, path="filec"),
        ]

        expected_result_attrib = [
            dict(groundMotionValue="0.25", path="filea"),
            dict(groundMotionValue="0.76", path="fileb"),
            dict(groundMotionValue="0.11", path="filec"),
        ]

        self.writer.open()
        self.writer.write(shapes.Site(1.0, 2.0), result_data[0])
        self.writer.write(shapes.Site(2.0, 3.0), result_data[1])
        self.writer.write(shapes.Site(3.0, 4.0), result_data[2])
        self.writer.close()

        site_nodes = self._xpath("//gml:pos")
        disagg_nodes = self._xpath("//nrml:disaggregationResultNode")
        results = self._xpath("//nrml:disaggregationResult")

        self.assertEquals(3, len(site_nodes))
        self.assertEquals(3, len(disagg_nodes))
        self.assertEquals(3, len(results))

        self.assertEquals("1.0 2.0", site_nodes[0].text)
        self.assertEquals("2.0 3.0", site_nodes[1].text)
        self.assertEquals("3.0 4.0", site_nodes[2].text)

        for i, res in enumerate(results):
            self.assertEquals(expected_result_attrib[i], res.attrib)

        self.assertTrue(xml.validates_against_xml_schema(self.FILENAME))
    def test_writes_the_config_only_once(self):
        data = [(shapes.Site(-122.5000, 37.5000),
                {"IDmodel": "MMI_3_1",
                "investigationTimeSpan": 50.0,
                "endBranchLabel": "3_1",
                "IMLValues": [5.0, 6.0, 7.0],
                "saPeriod": 0.1,
                "saDamping": 1.0,
                "IMT": "PGA",
                "PoEValues": [0.1, 0.2, 0.3]}),
                (shapes.Site(-122.4000, 37.5000),
                {"IDmodel": "MMI_3_1",
                "investigationTimeSpan": 50.0,
                "endBranchLabel": "3_2",
                "IMLValues": [5.0, 6.0, 7.0],
                "saPeriod": 0.1,
                "saDamping": 1.0,
                "IMT": "PGA",
                "PoEValues": [0.4, 0.5, 0.6]})]

        path = helpers.get_output_path(TEST_FILE_CONFIG_ONCE)
        self._initialize_writer(path)

        self.writer.serialize(data)
        self.assertTrue(xml.validates_against_xml_schema(path))
Пример #10
0
    def test_serialize(self):
        expected_file = helpers.get_data_path(
            "expected-collapse-map.xml")

        expected_text = open(expected_file, "r").readlines()

        asset_1, asset_2, asset_3, asset_4 = self.make_assets()
        self.make_map()

        self.make_data(asset_1, 1.6, 1.7)
        self.make_data(asset_2, 2.9, 3.1)
        self.make_data(asset_3, 4.9, 5.1)
        self.make_data(asset_4, 10.6, 11.7)

        try:
            _, result_xml = tempfile.mkstemp()

            writer = CollapseMapXMLWriter(result_xml, "ebl1")

            writer.serialize(self.data)
            actual_text = open(result_xml, "r").readlines()

            self.assertEqual(expected_text, actual_text)

            self.assertTrue(xml.validates_against_xml_schema(
                    result_xml))
        finally:
            os.unlink(result_xml)
Пример #11
0
        def verify_quantile_haz_maps_stored_to_nrml(hazengine):
            """Tests that quantile hazard map NRML files have been written,
            and that these file validate against the NRML schema.
            Does NOT test if results in NRML files are correct.
            """

            quantiles = classical_psha._extract_values_from_config(hazengine,
                classical_psha.QUANTILE_PARAM_NAME)

            if (hazengine.params[classical_psha.POES_PARAM_NAME] != '' and
                len(quantiles) > 0):

                poes = classical_psha._extract_values_from_config(hazengine,
                    classical_psha.POES_PARAM_NAME)

                for quantile in quantiles:
                    for poe in poes:
                        nrml_path = os.path.join(
                            "smoketests/classical_psha_simple/computed_output",
                            opensha.quantile_hm_filename(quantile, poe))

                        LOG.debug("validating NRML file for quantile hazard "\
                            "map: %s" % nrml_path)

                        self.assertTrue(xml.validates_against_xml_schema(
                            nrml_path, NRML_SCHEMA_PATH),
                            "NRML instance file %s does not validate against "\
                            "schema" % nrml_path)
Пример #12
0
    def test_write_multiple_result_nodes(self):
        result_data = [
            dict(groundMotionValue=0.25, path="filea"),
            dict(groundMotionValue=0.76, path="fileb"),
            dict(groundMotionValue=0.11, path="filec"),
        ]

        expected_result_attrib = [
            dict(groundMotionValue="0.25", path="filea"),
            dict(groundMotionValue="0.76", path="fileb"),
            dict(groundMotionValue="0.11", path="filec"),
        ]

        self.writer.open()
        self.writer.write(shapes.Site(1.0, 2.0), result_data[0])
        self.writer.write(shapes.Site(2.0, 3.0), result_data[1])
        self.writer.write(shapes.Site(3.0, 4.0), result_data[2])
        self.writer.close()

        site_nodes = self._xpath("//gml:pos")
        disagg_nodes = self._xpath("//nrml:disaggregationResultNode")
        results = self._xpath("//nrml:disaggregationResult")

        self.assertEquals(3, len(site_nodes))
        self.assertEquals(3, len(disagg_nodes))
        self.assertEquals(3, len(results))

        self.assertEquals("1.0 2.0", site_nodes[0].text)
        self.assertEquals("2.0 3.0", site_nodes[1].text)
        self.assertEquals("3.0 4.0", site_nodes[2].text)

        for i, res in enumerate(results):
            self.assertEquals(expected_result_attrib[i], res.attrib)

        self.assertTrue(xml.validates_against_xml_schema(self.FILENAME))
 def test_loss_map_output_writes_and_validates(self):
     xml_writer = \
         risk_output.LossMapXMLWriter(TEST_LOSS_MAP_XML_OUTPUT_PATH)
     xml_writer.serialize(SAMPLE_LOSS_MAP_DATA)
     self.assertTrue(
         xml.validates_against_xml_schema(TEST_LOSS_MAP_XML_OUTPUT_PATH,
         NRML_SCHEMA_PATH),
         "NRML instance file %s does not validate against schema" % \
         TEST_LOSS_MAP_XML_OUTPUT_PATH)
Пример #14
0
 def test_loss_map_output_writes_and_validates(self):
     xml_writer = \
         risk_output.LossMapXMLWriter(TEST_LOSS_MAP_XML_OUTPUT_PATH)
     xml_writer.serialize(SAMPLE_LOSS_MAP_DATA)
     self.assertTrue(
         xml.validates_against_xml_schema(TEST_LOSS_MAP_XML_OUTPUT_PATH,
         NRML_SCHEMA_PATH),
         "NRML instance file %s does not validate against schema" % \
         TEST_LOSS_MAP_XML_OUTPUT_PATH)
    def test_serialize(self):
        data = [(shapes.Site(1.0, 1.0),
                {"groundMotionValue": 0.25, "path": "filea"}),
                (shapes.Site(1.0, 2.0),
                {"groundMotionValue": 0.35, "path": "fileb"})]

        self.writer.serialize(data)

        self.assertTrue(xml.validates_against_xml_schema(self.FILENAME))
Пример #16
0
    def test_loss_is_serialized_to_file_and_validates(self):
        """Serialize loss curve to NRML and validate against schema."""
        xml_writer = risk_output.LossCurveXMLWriter(self.loss_curve_path)
        xml_writer.serialize(self.loss_curves)

        self.assertTrue(xml.validates_against_xml_schema(self.loss_curve_path,
            NRML_SCHEMA_PATH),
            "NRML instance file %s does not validate against schema" % \
            self.loss_curve_path)
Пример #17
0
    def test_loss_is_serialized_to_file_and_validates(self):
        """Serialize loss curve to NRML and validate against schema."""
        xml_writer = risk_output.LossCurveXMLWriter(self.loss_curve_path)
        xml_writer.serialize(self.loss_curves)

        self.assertTrue(xml.validates_against_xml_schema(self.loss_curve_path,
            NRML_SCHEMA_PATH),
            "NRML instance file %s does not validate against schema" % \
            self.loss_curve_path)
Пример #18
0
    def test_serialize(self):
        data = [(shapes.Site(1.0, 1.0), {
            "groundMotionValue": 0.25,
            "path": "filea"
        }),
                (shapes.Site(1.0, 2.0), {
                    "groundMotionValue": 0.35,
                    "path": "fileb"
                })]

        self.writer.serialize(data)

        self.assertTrue(xml.validates_against_xml_schema(self.FILENAME))
Пример #19
0
        def verify_mean_haz_curves_stored_to_nrml(the_job, calculator):
            """Tests that a mean hazard curve NRML file has been written,
            and that this file validates against the NRML schema.
            Does NOT test if results in NRML file are correct.
            """

            if the_job.params['COMPUTE_MEAN_HAZARD_CURVE'].lower() == 'true':
                nrml_path = psha.nrml_path(calculator.job_ctxt, "mean")

                LOG.debug("validating NRML file %s" % nrml_path)

                self.assertTrue(xml.validates_against_xml_schema(
                    nrml_path, NRML_SCHEMA_PATH),
                    "NRML instance file %s does not validate against schema"
                    % nrml_path)
    def test_writes_multiple_results_with_one_branch_level(self):
        data = [(shapes.Site(-122.5000, 37.5000),
                {"IDmodel": "MMI_3_1",
                "investigationTimeSpan": 50.0,
                "endBranchLabel": "3_1",
                "IMLValues": [5.0000e-03, 7.0000e-03, 1.3700e-02,
                1.9200e-02, 2.6900e-02, 3.7600e-02, 5.2700e-02,
                7.3800e-02, 9.8000e-02, 1.0300e-01, 1.4500e-01,
                2.0300e-01, 2.8400e-01, 3.9700e-01, 5.5600e-01,
                7.7800e-01, 1.0900e+00, 1.5200e+00, 2.1300e+00],
                "saPeriod": 0.1,
                "saDamping": 1.0,
                "IMT": "PGA",
                "PoEValues": [9.8728e-01, 9.8266e-01, 9.4957e-01,
                9.0326e-01, 8.1956e-01, 6.9192e-01, 5.2866e-01,
                3.6143e-01, 2.4231e-01, 2.2452e-01, 1.2831e-01,
                7.0352e-02, 3.6060e-02, 1.6579e-02, 6.4213e-03,
                2.0244e-03, 4.8605e-04, 8.1752e-05, 7.3425e-06]}),
                (shapes.Site(-122.4000, 37.5000),
                {"IDmodel": "MMI_3_1",
                "investigationTimeSpan": 50.0,
                "endBranchLabel": "3_1",
                "IMLValues": [5.0000e-03, 7.0000e-03, 1.3700e-02,
                1.9200e-02, 2.6900e-02, 3.7600e-02, 5.2700e-02,
                7.3800e-02, 9.8000e-02, 1.0300e-01, 1.4500e-01,
                2.0300e-01, 2.8400e-01, 3.9700e-01, 5.5600e-01,
                7.7800e-01, 1.0900e+00, 1.5200e+00, 2.1300e+00],
                "saPeriod": 0.1,
                "saDamping": 1.0,
                "IMT": "PGA",
                "PoEValues": [9.8784e-01, 9.8405e-01, 9.5719e-01,
                9.1955e-01, 8.5019e-01, 7.4038e-01, 5.9153e-01,
                4.2626e-01, 2.9755e-01, 2.7731e-01, 1.6218e-01,
                8.8035e-02, 4.3499e-02, 1.9065e-02, 7.0442e-03,
                2.1300e-03, 4.9498e-04, 8.1768e-05, 7.3425e-06]})]

        path = helpers.get_output_path(TEST_FILE_MULTIPLE_ONE_BRANCH)
        self._initialize_writer(path)
        self.writer.serialize(data)

        self.assertTrue(xml.validates_against_xml_schema(path))

        self.read_curves = self._read_curves(
                (-123.0, 38.0), (-120.0, 35.0),
                TEST_FILE_MULTIPLE_ONE_BRANCH)

        self._assert_number_of_curves_is(2)
        self._assert_curves_are(data)
Пример #21
0
        def verify_mean_haz_curves_stored_to_nrml(the_job, calculator):
            """Tests that a mean hazard curve NRML file has been written,
            and that this file validates against the NRML schema.
            Does NOT test if results in NRML file are correct.
            """

            if the_job.params['COMPUTE_MEAN_HAZARD_CURVE'].lower() == 'true':
                nrml_path = psha.nrml_path(calculator.job_ctxt, "mean")

                LOG.debug("validating NRML file %s" % nrml_path)

                self.assertTrue(
                    xml.validates_against_xml_schema(nrml_path,
                                                     NRML_SCHEMA_PATH),
                    "NRML instance file %s does not validate against schema" %
                    nrml_path)
Пример #22
0
    def test_write_single_result_node(self):
        result_data = dict(groundMotionValue=0.25, path="filea")
        expected_result_attrib = dict(groundMotionValue="0.25", path="filea")

        self.writer.write(shapes.Site(1.0, 2.0), result_data)
        self.writer.close()

        [site_node] = self._xpath("//gml:pos")
        disagg_nodes = self._xpath("//nrml:disaggregationResultNode")
        [result] = self._xpath("//nrml:disaggregationResult")

        self.assertEquals("1.0 2.0", site_node.text)
        self.assertEquals(1, len(disagg_nodes))
        self.assertEquals(expected_result_attrib, result.attrib)

        self.assertTrue(xml.validates_against_xml_schema(self.FILENAME))
Пример #23
0
        def verify_mean_haz_curves_stored_to_nrml(hazengine):
            """Tests that a mean hazard curve NRML file has been written,
            and that this file validates against the NRML schema.
            Does NOT test if results in NRML file are correct.
            """

            if hazengine.params['COMPUTE_MEAN_HAZARD_CURVE'].lower() == 'true':
                nrml_path = os.path.join(
                    "smoketests/classical_psha_simple/computed_output",
                    opensha.mean_hc_filename())

                LOG.debug("validating NRML file %s" % nrml_path)

                self.assertTrue(xml.validates_against_xml_schema(
                    nrml_path, NRML_SCHEMA_PATH),
                    "NRML instance file %s does not validate against schema" \
                    % nrml_path)
Пример #24
0
    def test_write_single_result_node(self):
        result_data = dict(groundMotionValue=0.25, path="filea")
        expected_result_attrib = dict(groundMotionValue="0.25", path="filea")

        self.writer.open()
        self.writer.write(shapes.Site(1.0, 2.0), result_data)
        self.writer.close()

        [site_node] = self._xpath("//gml:pos")
        disagg_nodes = self._xpath("//nrml:disaggregationResultNode")
        [result] = self._xpath("//nrml:disaggregationResult")

        self.assertEquals("1.0 2.0", site_node.text)
        self.assertEquals(1, len(disagg_nodes))
        self.assertEquals(expected_result_attrib, result.attrib)

        self.assertTrue(xml.validates_against_xml_schema(self.FILENAME))
Пример #25
0
        def verify_quantile_haz_curves_stored_to_nrml(the_job, calculator):
            """Tests that quantile hazard curve NRML files have been written,
            and that these file validate against the NRML schema.
            Does NOT test if results in NRML files are correct.
            """

            for quantile in calculator.quantile_levels:

                nrml_path = psha.nrml_path(calculator.job_ctxt, "quantile",
                                           quantile)
                LOG.debug("validating NRML file for quantile hazard curve: "
                    "%s" % nrml_path)

                self.assertTrue(xml.validates_against_xml_schema(
                    nrml_path, NRML_SCHEMA_PATH),
                    "NRML instance file %s does not validate against schema"
                    % nrml_path)
Пример #26
0
        def verify_mean_haz_curves_stored_to_nrml(hazengine):
            """Tests that a mean hazard curve NRML file has been written,
            and that this file validates against the NRML schema.
            Does NOT test if results in NRML file are correct.
            """

            if hazengine.params['COMPUTE_MEAN_HAZARD_CURVE'].lower() == 'true':
                nrml_path = os.path.join(
                    "smoketests/classical_psha_simple/computed_output",
                    opensha.mean_hc_filename())

                LOG.debug("validating NRML file %s" % nrml_path)

                self.assertTrue(xml.validates_against_xml_schema(
                    nrml_path, NRML_SCHEMA_PATH),
                    "NRML instance file %s does not validate against schema" \
                    % nrml_path)
Пример #27
0
    def test_writes_multiple_results_with_different_branch_levels(self):
        data = [(shapes.Site(-122.5000, 37.5000), {
            "IDmodel": "MMI_3_1",
            "investigationTimeSpan": 50.0,
            "endBranchLabel": "3_1",
            "IMLValues": [5.0, 6.0, 7.0],
            "saPeriod": 0.1,
            "saDamping": 1.0,
            "IMT": "PGA",
            "PoEValues": [0.1, 0.2, 0.3]
        }),
                (shapes.Site(-122.5000, 37.5000), {
                    "IDmodel": "MMI_3_1",
                    "investigationTimeSpan": 50.0,
                    "endBranchLabel": "3_2",
                    "IMLValues": [5.0, 6.0, 7.0],
                    "saPeriod": 0.1,
                    "saDamping": 1.0,
                    "IMT": "PGA",
                    "PoEValues": [0.1, 0.2, 0.3]
                }),
                (shapes.Site(-122.4000, 37.5000), {
                    "IDmodel": "MMI_3_1",
                    "investigationTimeSpan": 50.0,
                    "endBranchLabel": "3_2",
                    "IMLValues": [8.0, 9.0, 10.0],
                    "saPeriod": 0.1,
                    "saDamping": 1.0,
                    "IMT": "PGA",
                    "PoEValues": [0.1, 0.2, 0.3]
                })]

        path = helpers.get_output_path(TEST_FILE_MULTIPLE_DIFFERENT_BRANCHES)

        self._initialize_writer(path)
        self.writer.serialize(data)

        self.assertTrue(xml.validates_against_xml_schema(path))

        self.read_curves = self._read_curves(
            (-123.0, 38.0), (-120.0, 35.0),
            TEST_FILE_MULTIPLE_DIFFERENT_BRANCHES)

        self._assert_number_of_curves_is(3)
        self._assert_curves_are(data)
Пример #28
0
        def verify_realization_haz_curves_stored_to_nrml(the_job, calculator):
            """Tests that a NRML file has been written for each realization,
            and that this file validates against the NRML schema.
            Does NOT test if results in NRML file are correct.
            """
            realizations = int(the_job.params['NUMBER_OF_LOGIC_TREE_SAMPLES'])
            for realization in xrange(0, realizations):

                nrml_path = psha.nrml_path(calculator.job_ctxt, "curve",
                                           realization)

                LOG.debug("validating NRML file %s" % nrml_path)

                self.assertTrue(
                    xml.validates_against_xml_schema(nrml_path,
                                                     NRML_SCHEMA_PATH),
                    "NRML instance file %s does not validate against schema" %
                    nrml_path)
Пример #29
0
        def verify_quantile_haz_curves_stored_to_nrml(the_job, calculator):
            """Tests that quantile hazard curve NRML files have been written,
            and that these file validate against the NRML schema.
            Does NOT test if results in NRML files are correct.
            """

            for quantile in calculator.quantile_levels:

                nrml_path = psha.nrml_path(calculator.job_ctxt, "quantile",
                                           quantile)
                LOG.debug("validating NRML file for quantile hazard curve: "
                          "%s" % nrml_path)

                self.assertTrue(
                    xml.validates_against_xml_schema(nrml_path,
                                                     NRML_SCHEMA_PATH),
                    "NRML instance file %s does not validate against schema" %
                    nrml_path)
Пример #30
0
        def verify_realization_haz_curves_stored_to_nrml(the_job, calculator):
            """Tests that a NRML file has been written for each realization,
            and that this file validates against the NRML schema.
            Does NOT test if results in NRML file are correct.
            """
            realizations = int(the_job.params['NUMBER_OF_LOGIC_TREE_SAMPLES'])
            for realization in xrange(0, realizations):

                nrml_path = os.path.join(
                    "demos/classical_psha_simple/computed_output",
                    calculator.hazard_curve_filename(realization))

                LOG.debug("validating NRML file %s" % nrml_path)

                self.assertTrue(xml.validates_against_xml_schema(
                    nrml_path, NRML_SCHEMA_PATH),
                    "NRML instance file %s does not validate against schema" \
                    % nrml_path)
Пример #31
0
        def verify_realization_haz_curves_stored_to_nrml(the_job, calculator):
            """Tests that a NRML file has been written for each realization,
            and that this file validates against the NRML schema.
            Does NOT test if results in NRML file are correct.
            """
            realizations = int(
                the_job.params['NUMBER_OF_LOGIC_TREE_SAMPLES'])
            for realization in xrange(0, realizations):

                nrml_path = psha.nrml_path(calculator.job_ctxt, "curve",
                                           realization)

                LOG.debug("validating NRML file %s" % nrml_path)

                self.assertTrue(xml.validates_against_xml_schema(
                    nrml_path, NRML_SCHEMA_PATH),
                    "NRML instance file %s does not validate against schema"
                    % nrml_path)
    def test_writes_multiple_results_with_different_branch_levels(self):
        data = [(shapes.Site(-122.5000, 37.5000),
                {"IDmodel": "MMI_3_1",
                "investigationTimeSpan": 50.0,
                "endBranchLabel": "3_1",
                "IMLValues": [5.0, 6.0, 7.0],
                "saPeriod": 0.1,
                "saDamping": 1.0,
                "IMT": "PGA",
                "PoEValues": [0.1, 0.2, 0.3]}),
                (shapes.Site(-122.5000, 37.5000),
                {"IDmodel": "MMI_3_1",
                "investigationTimeSpan": 50.0,
                "endBranchLabel": "3_2",
                "IMLValues": [5.0, 6.0, 7.0],
                "saPeriod": 0.1,
                "saDamping": 1.0,
                "IMT": "PGA",
                "PoEValues": [0.1, 0.2, 0.3]}),
                (shapes.Site(-122.4000, 37.5000),
                {"IDmodel": "MMI_3_1",
                "investigationTimeSpan": 50.0,
                "endBranchLabel": "3_2",
                "IMLValues": [8.0, 9.0, 10.0],
                "saPeriod": 0.1,
                "saDamping": 1.0,
                "IMT": "PGA",
                "PoEValues": [0.1, 0.2, 0.3]})]

        path = helpers.get_output_path(
                TEST_FILE_MULTIPLE_DIFFERENT_BRANCHES)

        self._initialize_writer(path)
        self.writer.serialize(data)

        self.assertTrue(xml.validates_against_xml_schema(path))

        self.read_curves = self._read_curves(
                (-123.0, 38.0), (-120.0, 35.0),
                TEST_FILE_MULTIPLE_DIFFERENT_BRANCHES)

        self._assert_number_of_curves_is(3)
        self._assert_curves_are(data)
Пример #33
0
        def verify_realization_haz_curves_stored_to_nrml(hazengine):
            """Tests that a NRML file has been written for each realization,
            and that this file validates against the NRML schema.
            Does NOT test if results in NRML file are correct.
            """
            realizations = int(
                hazengine.params['NUMBER_OF_LOGIC_TREE_SAMPLES'])
            for realization in xrange(0, realizations):

                nrml_path = os.path.join(
                    "smoketests/classical_psha_simple/computed_output",
                    opensha.realization_hc_filename(realization))

                LOG.debug("validating NRML file %s" % nrml_path)

                self.assertTrue(xml.validates_against_xml_schema(
                    nrml_path, NRML_SCHEMA_PATH),
                    "NRML instance file %s does not validate against schema" \
                    % nrml_path)
Пример #34
0
        def verify_quantile_haz_curves_stored_to_nrml(the_job, calculator):
            """Tests that quantile hazard curve NRML files have been written,
            and that these file validate against the NRML schema.
            Does NOT test if results in NRML files are correct.
            """

            for quantile in calculator.quantile_levels:

                nrml_path = os.path.join(
                    "demos/classical_psha_simple/computed_output",
                    calculator.quantile_hazard_curve_filename(quantile))

                LOG.debug("validating NRML file for quantile hazard curve: "\
                    "%s" % nrml_path)

                self.assertTrue(xml.validates_against_xml_schema(
                    nrml_path, NRML_SCHEMA_PATH),
                    "NRML instance file %s does not validate against schema" \
                    % nrml_path)
Пример #35
0
        def verify_quantile_haz_curves_stored_to_nrml(hazengine):
            """Tests that quantile hazard curve NRML files have been written,
            and that these file validate against the NRML schema.
            Does NOT test if results in NRML files are correct.
            """

            for quantile in hazengine.quantile_levels:

                nrml_path = os.path.join(
                    "smoketests/classical_psha_simple/computed_output",
                    hazengine.quantile_hazard_curve_filename(quantile))

                LOG.debug("validating NRML file for quantile hazard curve: "\
                    "%s" % nrml_path)

                self.assertTrue(xml.validates_against_xml_schema(
                    nrml_path, NRML_SCHEMA_PATH),
                    "NRML instance file %s does not validate against schema" \
                    % nrml_path)
Пример #36
0
    def test_result_field_attrs(self):
        """Test that the various disaggregationResultField attrs are written
        correctly (including all of the optional attributes)."""
        # write a single node just to create a valid document
        self.writer.write(shapes.Site(0.0, 0.0),
                          {"groundMotionValue": 0.25, "path": "filea"})
        self.writer.close()

        [disagg_field] = self._xpath(
            "/nrml:nrml/nrml:disaggregationResultField")

        attrib = disagg_field.attrib

        self.assertEquals(str(self.POE), attrib['poE'])
        self.assertEquals(self.IMT, attrib['IMT'])
        self.assertEquals(self.END_BRANCH_LABEL, attrib['endBranchLabel'])
        self.assertEquals(self.STATISTICS, attrib['statistics'])
        self.assertEquals(str(self.QUANTILE_VALUE), attrib['quantileValue'])

        self.assertTrue(xml.validates_against_xml_schema(self.FILENAME))
Пример #37
0
        def verify_mean_haz_maps_stored_to_nrml(the_job):
            """Tests that a mean hazard map NRML file has been written,
            and that this file validates against the NRML schema.
            Does NOT test if results in NRML file are correct.
            """
            if (the_job.params[hazard_general.POES_PARAM_NAME] != '' and
                the_job.params['COMPUTE_MEAN_HAZARD_CURVE'].lower() ==
                'true'):

                for poe in calculator.poes_hazard_maps:
                    _, nrml_path, _ = psha.hms_meta(
                        calculator.job_ctxt, "mean", (poe,))

                    LOG.debug("validating NRML file for mean hazard map %s"
                        % nrml_path)

                    self.assertTrue(xml.validates_against_xml_schema(
                        nrml_path, NRML_SCHEMA_PATH),
                        "NRML instance file %s does not validate against "
                        "schema" % nrml_path)
Пример #38
0
    def test_writes_a_single_result(self):
        data = [(shapes.Site(-122.5000, 37.5000), {
            "IDmodel":
            "MMI_3_1",
            "investigationTimeSpan":
            50.0,
            "endBranchLabel":
            "3_1",
            "IMLValues": [
                5.0000e-03, 7.0000e-03, 1.3700e-02, 1.9200e-02, 2.6900e-02,
                3.7600e-02, 5.2700e-02, 7.3800e-02, 9.8000e-02, 1.0300e-01,
                1.4500e-01, 2.0300e-01, 2.8400e-01, 3.9700e-01, 5.5600e-01,
                7.7800e-01, 1.0900e+00, 1.5200e+00, 2.1300e+00
            ],
            "saPeriod":
            0.1,
            "saDamping":
            1.0,
            "IMT":
            "PGA",
            "PoEValues": [
                9.8728e-01, 9.8266e-01, 9.4957e-01, 9.0326e-01, 8.1956e-01,
                6.9192e-01, 5.2866e-01, 3.6143e-01, 2.4231e-01, 2.2452e-01,
                1.2831e-01, 7.0352e-02, 3.6060e-02, 1.6579e-02, 6.4213e-03,
                2.0244e-03, 4.8605e-04, 8.1752e-05, 7.3425e-06
            ]
        })]

        path = helpers.get_output_path(TEST_FILE_SINGLE_RESULT)

        self._initialize_writer(path)
        self.writer.serialize(data)

        self.assertTrue(xml.validates_against_xml_schema(path))
        self.assertTrue(XML_METADATA in self._result_as_string(path))

        self.read_curves = self._read_curves((-123.0, 38.0), (-122.0, 35.0),
                                             TEST_FILE_SINGLE_RESULT)

        self._assert_number_of_curves_is(1)
        self._assert_curves_are(data)
Пример #39
0
        def verify_mean_haz_maps_stored_to_nrml(the_job):
            """Tests that a mean hazard map NRML file has been written,
            and that this file validates against the NRML schema.
            Does NOT test if results in NRML file are correct.
            """
            if (the_job.params[hazard_general.POES_PARAM_NAME] != ''
                    and the_job.params['COMPUTE_MEAN_HAZARD_CURVE'].lower()
                    == 'true'):

                for poe in calculator.poes_hazard_maps:
                    _, nrml_path, _ = psha.hms_meta(calculator.job_ctxt,
                                                    "mean", (poe, ))

                    LOG.debug("validating NRML file for mean hazard map %s" %
                              nrml_path)

                    self.assertTrue(
                        xml.validates_against_xml_schema(
                            nrml_path, NRML_SCHEMA_PATH),
                        "NRML instance file %s does not validate against "
                        "schema" % nrml_path)
Пример #40
0
        def verify_mean_haz_maps_stored_to_nrml(the_job):
            """Tests that a mean hazard map NRML file has been written,
            and that this file validates against the NRML schema.
            Does NOT test if results in NRML file are correct.
            """
            if (the_job.params[hazard_general.POES_PARAM_NAME] != '' and
                the_job.params['COMPUTE_MEAN_HAZARD_CURVE'].lower() == \
                'true'):

                for poe in calculator.poes_hazard_maps:
                    nrml_path = os.path.join(
                        "demos/classical_psha_simple/computed_output",
                        calculator.mean_hazard_map_filename(poe))

                    LOG.debug("validating NRML file for mean hazard map %s" \
                        % nrml_path)

                    self.assertTrue(xml.validates_against_xml_schema(
                        nrml_path, NRML_SCHEMA_PATH),
                        "NRML instance file %s does not validate against "\
                        "schema" % nrml_path)
Пример #41
0
        def verify_mean_haz_maps_stored_to_nrml(hazengine):
            """Tests that a mean hazard map NRML file has been written,
            and that this file validates against the NRML schema.
            Does NOT test if results in NRML file are correct.
            """
            if (hazengine.params[classical_psha.POES_PARAM_NAME] != '' and
                hazengine.params['COMPUTE_MEAN_HAZARD_CURVE'].lower() == \
                'true'):

                for poe in hazengine.poes_hazard_maps:
                    nrml_path = os.path.join(
                        "smoketests/classical_psha_simple/computed_output",
                        hazengine.mean_hazard_map_filename(poe))

                    LOG.debug("validating NRML file for mean hazard map %s" \
                        % nrml_path)

                    self.assertTrue(xml.validates_against_xml_schema(
                        nrml_path, NRML_SCHEMA_PATH),
                        "NRML instance file %s does not validate against "\
                        "schema" % nrml_path)
Пример #42
0
    def test_result_field_attrs(self):
        """Test that the various disaggregationResultField attrs are written
        correctly (including all of the optional attributes)."""
        # write a single node just to create a valid document
        self.writer.open()
        self.writer.write(shapes.Site(0.0, 0.0), {
            "groundMotionValue": 0.25,
            "path": "filea"
        })
        self.writer.close()

        [disagg_field
         ] = self._xpath("/nrml:nrml/nrml:disaggregationResultField")

        attrib = disagg_field.attrib

        self.assertEquals(str(self.POE), attrib['poE'])
        self.assertEquals(self.IMT, attrib['IMT'])
        self.assertEquals(self.END_BRANCH_LABEL, attrib['endBranchLabel'])
        self.assertEquals(self.STATISTICS, attrib['statistics'])
        self.assertEquals(str(self.QUANTILE_VALUE), attrib['quantileValue'])

        self.assertTrue(xml.validates_against_xml_schema(self.FILENAME))
Пример #43
0
        def verify_quantile_haz_maps_stored_to_nrml(the_job, calculator):
            """Tests that quantile hazard map NRML files have been written,
            and that these file validate against the NRML schema.
            Does NOT test if results in NRML files are correct.
            """

            quantiles = calculator.quantile_levels

            if (the_job.params[hazard_general.POES_PARAM_NAME] != '' and
                len(quantiles) > 0):

                for poe in calculator.poes_hazard_maps:
                    for quantile in quantiles:
                        _, nrml_path, _ = psha.hms_meta(
                            calculator.job_ctxt, "quantile", (poe, quantile))

                        LOG.debug("validating NRML file for quantile hazard "
                            "map: %s" % nrml_path)

                        self.assertTrue(xml.validates_against_xml_schema(
                            nrml_path, NRML_SCHEMA_PATH),
                            "NRML instance file %s does not validate against "
                            "schema" % nrml_path)
Пример #44
0
        def verify_quantile_haz_maps_stored_to_nrml(the_job, calculator):
            """Tests that quantile hazard map NRML files have been written,
            and that these file validate against the NRML schema.
            Does NOT test if results in NRML files are correct.
            """

            quantiles = calculator.quantile_levels

            if (the_job.params[hazard_general.POES_PARAM_NAME] != ''
                    and len(quantiles) > 0):

                for poe in calculator.poes_hazard_maps:
                    for quantile in quantiles:
                        _, nrml_path, _ = psha.hms_meta(
                            calculator.job_ctxt, "quantile", (poe, quantile))

                        LOG.debug("validating NRML file for quantile hazard "
                                  "map: %s" % nrml_path)

                        self.assertTrue(
                            xml.validates_against_xml_schema(
                                nrml_path, NRML_SCHEMA_PATH),
                            "NRML instance file %s does not validate against "
                            "schema" % nrml_path)
Пример #45
0
        def verify_mean_haz_maps_stored_to_nrml(hazengine):
            """Tests that a mean hazard map NRML file has been written,
            and that this file validates against the NRML schema.
            Does NOT test if results in NRML file are correct.
            """
            if (hazengine.params[classical_psha.POES_PARAM_NAME] != '' and
                hazengine.params['COMPUTE_MEAN_HAZARD_CURVE'].lower() == \
                'true'):

                poes = classical_psha._extract_values_from_config(hazengine,
                    classical_psha.POES_PARAM_NAME)

                for poe in poes:
                    nrml_path = os.path.join(
                        "smoketests/classical_psha_simple/computed_output",
                        opensha.mean_hm_filename(poe))

                    LOG.debug("validating NRML file for mean hazard map %s" \
                        % nrml_path)

                    self.assertTrue(xml.validates_against_xml_schema(
                        nrml_path, NRML_SCHEMA_PATH),
                        "NRML instance file %s does not validate against "\
                        "schema" % nrml_path)
Пример #46
0
    def test_writes_multiple_results_with_one_branch_level(self):
        data = [
            (shapes.Site(-122.5000, 37.5000), {
                "IDmodel":
                "MMI_3_1",
                "investigationTimeSpan":
                50.0,
                "endBranchLabel":
                "3_1",
                "IMLValues": [
                    5.0000e-03, 7.0000e-03, 1.3700e-02, 1.9200e-02, 2.6900e-02,
                    3.7600e-02, 5.2700e-02, 7.3800e-02, 9.8000e-02, 1.0300e-01,
                    1.4500e-01, 2.0300e-01, 2.8400e-01, 3.9700e-01, 5.5600e-01,
                    7.7800e-01, 1.0900e+00, 1.5200e+00, 2.1300e+00
                ],
                "saPeriod":
                0.1,
                "saDamping":
                1.0,
                "IMT":
                "PGA",
                "PoEValues": [
                    9.8728e-01, 9.8266e-01, 9.4957e-01, 9.0326e-01, 8.1956e-01,
                    6.9192e-01, 5.2866e-01, 3.6143e-01, 2.4231e-01, 2.2452e-01,
                    1.2831e-01, 7.0352e-02, 3.6060e-02, 1.6579e-02, 6.4213e-03,
                    2.0244e-03, 4.8605e-04, 8.1752e-05, 7.3425e-06
                ]
            }),
            (shapes.Site(-122.4000, 37.5000), {
                "IDmodel":
                "MMI_3_1",
                "investigationTimeSpan":
                50.0,
                "endBranchLabel":
                "3_1",
                "IMLValues": [
                    5.0000e-03, 7.0000e-03, 1.3700e-02, 1.9200e-02, 2.6900e-02,
                    3.7600e-02, 5.2700e-02, 7.3800e-02, 9.8000e-02, 1.0300e-01,
                    1.4500e-01, 2.0300e-01, 2.8400e-01, 3.9700e-01, 5.5600e-01,
                    7.7800e-01, 1.0900e+00, 1.5200e+00, 2.1300e+00
                ],
                "saPeriod":
                0.1,
                "saDamping":
                1.0,
                "IMT":
                "PGA",
                "PoEValues": [
                    9.8784e-01, 9.8405e-01, 9.5719e-01, 9.1955e-01, 8.5019e-01,
                    7.4038e-01, 5.9153e-01, 4.2626e-01, 2.9755e-01, 2.7731e-01,
                    1.6218e-01, 8.8035e-02, 4.3499e-02, 1.9065e-02, 7.0442e-03,
                    2.1300e-03, 4.9498e-04, 8.1768e-05, 7.3425e-06
                ]
            })
        ]

        path = helpers.get_output_path(TEST_FILE_MULTIPLE_ONE_BRANCH)
        self._initialize_writer(path)
        self.writer.serialize(data)

        self.assertTrue(xml.validates_against_xml_schema(path))

        self.read_curves = self._read_curves((-123.0, 38.0), (-120.0, 35.0),
                                             TEST_FILE_MULTIPLE_ONE_BRANCH)

        self._assert_number_of_curves_is(2)
        self._assert_curves_are(data)