예제 #1
0
    def _parse_nrml_file(self):
        """Parse hazard curve data from NRML file into a dictionary."""

        nrml_element = hazard_parser.NrmlFile(self.nrml_input_path)

        # we collect hazard curves for one site into one plot
        # one plot contains hazard curves for several end branches
        # of the logic tree
        # each end branch can have its own abscissa value set
        for (nrml_point,
             nrml_attr) in nrml_element.filter(region_constraint=None):

            site_hash = nrml_point.hash()
            ebl = nrml_attr['endBranchLabel']

            if site_hash not in self.data:
                self.data[site_hash] = {
                    # capture SVG filename for each site
                    'path': self._generate_filename(site_hash),
                    'curves': {}
                }

            if ebl not in self.data[site_hash]['curves']:
                self.data[site_hash]['curves'][ebl] = {}

            self.data[site_hash]['curves'][ebl] = {
                'abscissa': nrml_attr['IMLValues'],
                'abscissa_property': nrml_attr['IMT'],
                'ordinate': nrml_attr['Values'],
                'ordinate_property': 'Probability of Exceedance',
                'Site': nrml_point,
                'curve_title': self.curve_title
            }
예제 #2
0
    def _read_curves(self, upper_left_cor, lower_right_cor, test_file):
        constraint = shapes.RegionConstraint.from_simple(
            upper_left_cor, lower_right_cor)

        reader = hazard_parser.NrmlFile(test.do_test_output_file(test_file))

        return reader.filter(constraint)
예제 #3
0
    def test_end_to_end_from_kvs_to_nrml(self):
        # storing in kvs from java side
        self.java_client.set("KEY", ONE_CURVE_MODEL)

        time.sleep(0.3)

        # reading in python side
        nrmls = self.reader.for_nrml("KEY")

        LOG.debug("Nrmls are %s", nrmls)

        # writing result
        writer = hazard_output.HazardCurveXMLWriter(
                os.path.join(helpers.DATA_DIR, TEST_FILE))

        writer.serialize(nrmls)

        # reading and checking
        constraint = shapes.RegionConstraint.from_simple(
                (1.5, 1.5), (2.5, 0.5))

        reader = hazard_parser.NrmlFile(
                os.path.join(helpers.DATA_DIR, TEST_FILE))

        number_of_curves = 0

        data = {shapes.Site(2.0, 1.0): {
            "IMT": "PGA",
            "IDmodel": "FIXED",
            "timeSpanDuration": 50.0,
            "endBranchLabel": "label",
            "IMLValues": [1.0, 2.0, 3.0],
            "Values": [0.1,0.2,0.3]}}

        for nrml_point, nrml_values in reader.filter(constraint):
            number_of_curves += 1

            self.assertTrue(nrml_point in data.keys())
            for key, val in nrml_values.items():
                self.assertEqual(val, data.values()[0][key])

        self.assertEqual(1, number_of_curves)
예제 #4
0
    def test_nrml_files_known_to_fail(self):
        for testfile in FILES_KNOWN_TO_FAIL:
            nrml_element = hazard_parser.NrmlFile(
                os.path.join(FAIL_EXAMPLE_DIR, testfile))

            self.assertRaises(ValueError, map, None, nrml_element)
예제 #5
0
 def setUp(self):
     self.nrml_element = hazard_parser.NrmlFile(TEST_FILE)
    def test_nrml_files_hazardmap_not_implemented(self):
        nrml_element = hazard_parser.NrmlFile(os.path.join(EXAMPLE_DIR,
            FILE_FLAVOUR_NOT_IMPLEMENTED))

        self.assertRaises(NotImplementedError, map, None, nrml_element)