Beispiel #1
0
    def test_geotiff_generation_discrete_colorscale_custom_bins(self):
        """Check RGB geotiff generation with colorscale for GMF. Use
        discrete colorscale based on IML values, with custom IML."""
        path = test.do_test_output_file(
            GEOTIFF_FILENAME_DISCRETE_CUSTOMBIN_COLORSCALE)
        asymmetric_region = shapes.Region.from_coordinates(
            TEST_REGION_LARGE_ASYMMETRIC)

        iml_list = [
            0.005, 0.007, 0.0098, 0.0137, 0.0192, 0.0269, 0.0376, 0.0527,
            0.0738, 0.103, 0.145, 0.203, 0.284, 0.397, 0.556, 0.778, 1.09,
            1.52, 2.13
        ]

        gwriter = geotiff.GMFGeoTiffFile(path,
                                         asymmetric_region.grid,
                                         iml_list=iml_list,
                                         discrete=True,
                                         colormap='matlab-polar')

        reference_raster = numpy.zeros(
            (asymmetric_region.grid.rows, asymmetric_region.grid.columns),
            dtype=numpy.float)
        self._fill_rasters(asymmetric_region, gwriter, reference_raster,
                           self._colorscale_cuts_fill)
        gwriter.close()
Beispiel #2
0
    def test_geotiff_generation_colorscale(self):
        """Check RGB geotiff generation with colorscale for GMF."""
        path = test.do_test_output_file(GEOTIFF_FILENAME_COLORSCALE)
        asymmetric_region = shapes.Region.from_coordinates(
            TEST_REGION_LARGE_ASYMMETRIC)
        gwriter = geotiff.GMFGeoTiffFile(path,
                                         asymmetric_region.grid,
                                         discrete=False)

        reference_raster = numpy.zeros(
            (asymmetric_region.grid.rows, asymmetric_region.grid.columns),
            dtype=numpy.float)
        self._fill_rasters(asymmetric_region, gwriter, reference_raster,
                           self._colorscale_fill)
        gwriter.close()
Beispiel #3
0
    def write_gmf_files(self, ses):
        """Generate a GeoTiff file and a NRML file for each GMF."""
        image_grid = self.region.grid
        iml_list = [
            float(param)
            for param in self.params['INTENSITY_MEASURE_LEVELS'].split(",")
        ]

        LOG.debug("Generating GMF image, grid is %s col by %s rows" %
                  (image_grid.columns, image_grid.rows))
        LOG.debug("IML: %s" % (iml_list))
        files = []
        for event_set in ses:
            for rupture in ses[event_set]:

                # NOTE(fab): we have to explicitly convert the JSON-decoded
                # tokens from Unicode to string, otherwise the path will not
                # be accepted by the GeoTiffFile constructor
                common_path = os.path.join(
                    self.base_path, self['OUTPUT_DIR'],
                    "gmf-%s-%s" % (str(event_set.replace(
                        "!", "_")), str(rupture.replace("!", "_"))))
                tiff_path = "%s.tiff" % common_path
                nrml_path = "%s.xml" % common_path
                gwriter = geotiff.GMFGeoTiffFile(tiff_path,
                                                 image_grid,
                                                 init_value=0.0,
                                                 normalize=True,
                                                 iml_list=iml_list,
                                                 discrete=True)
                xmlwriter = hazard_output.GMFXMLWriter(nrml_path)
                gmf_data = {}
                for site_key in ses[event_set][rupture]:
                    site = ses[event_set][rupture][site_key]
                    site_obj = shapes.Site(site['lon'], site['lat'])
                    point = image_grid.point_at(site_obj)
                    gwriter.write((point.row, point.column),
                                  math.exp(float(site['mag'])))
                    gmf_data[site_obj] = \
                        {'groundMotion': math.exp(float(site['mag']))}

                gwriter.close()
                xmlwriter.serialize(gmf_data)
                files.append(tiff_path)
                files.append(gwriter.html_path)
                files.append(nrml_path)
        return files
Beispiel #4
0
    def test_geotiff_generation_nondefault_colorscale(self):
        """Check RGB geotiff generation with colorscale for GMF. Use
        alternative colorscale."""
        path = test.do_test_output_file(GEOTIFF_FILENAME_NONDEFAULT_COLORSCALE)
        asymmetric_region = shapes.Region.from_coordinates(
            TEST_REGION_LARGE_ASYMMETRIC)

        gwriter = geotiff.GMFGeoTiffFile(path,
                                         asymmetric_region.grid,
                                         iml_list=None,
                                         discrete=False,
                                         colormap='gmt-green-red')

        reference_raster = numpy.zeros(
            (asymmetric_region.grid.rows, asymmetric_region.grid.columns),
            dtype=numpy.float)
        self._fill_rasters(asymmetric_region, gwriter, reference_raster,
                           self._colorscale_cuts_fill)
        gwriter.close()
Beispiel #5
0
    def test_geotiff_generation_discrete_colorscale(self):
        """Check RGB geotiff generation with colorscale for GMF. Use
        discrete colorscale based on IML values, with default IML."""
        path = test.do_test_output_file(GEOTIFF_FILENAME_DISCRETE_COLORSCALE)
        asymmetric_region = shapes.Region.from_coordinates(
            TEST_REGION_LARGE_ASYMMETRIC)

        gwriter = geotiff.GMFGeoTiffFile(path,
                                         asymmetric_region.grid,
                                         iml_list=None,
                                         discrete=True,
                                         colormap='gmt-seis')

        reference_raster = numpy.zeros(
            (asymmetric_region.grid.rows, asymmetric_region.grid.columns),
            dtype=numpy.float)
        self._fill_rasters(asymmetric_region, gwriter, reference_raster,
                           self._colorscale_cuts_fill)
        gwriter.close()
Beispiel #6
0
    def test_geotiff_generation_multisegment_colorscale(self):
        """Check RGB geotiff generation with colorscale for GMF. Use
        multisegment colorscale."""
        path = helpers.get_output_path(
            GEOTIFF_FILENAME_MULTISEGMENT_COLORSCALE)
        asymmetric_region = shapes.Region.from_coordinates(
            TEST_REGION_LARGE_ASYMMETRIC)

        gwriter = geotiff.GMFGeoTiffFile(
            path,
            asymmetric_region.grid,
            iml_list=None,
            discrete=False,
            colormap=geotiff.COLORMAPS['gmt-seis'])

        reference_raster = numpy.zeros(
            (asymmetric_region.grid.rows, asymmetric_region.grid.columns),
            dtype=numpy.float)
        self._fill_rasters(asymmetric_region, gwriter, reference_raster,
                           self._colorscale_cuts_fill)
        gwriter.close()
Beispiel #7
0
    def test_geotiff_generation_explicit_colorscale_bins(self):
        """Check RGB geotiff generation with colorscale for GMF. Limits
        and bins of colorscale are explicitly given."""
        path = test.do_test_output_file(
            GEOTIFF_FILENAME_EXPLICIT_COLORSCALE_BINS)
        asymmetric_region = shapes.Region.from_coordinates(
            TEST_REGION_LARGE_ASYMMETRIC)

        for test_number, test_list in enumerate(([0.9, 0.95, 1.0,
                                                  1.05], None)):

            curr_path = "%s.%s.tiff" % (path[0:-5], test_number)
            gwriter = geotiff.GMFGeoTiffFile(curr_path,
                                             asymmetric_region.grid,
                                             iml_list=test_list,
                                             discrete=False)

            reference_raster = numpy.zeros(
                (asymmetric_region.grid.rows, asymmetric_region.grid.columns),
                dtype=numpy.float)
            self._fill_rasters(asymmetric_region, gwriter, reference_raster,
                               self._colorscale_cuts_fill)
            gwriter.close()
Beispiel #8
0
    def test_geotiff_generation_discrete_colorscale_custom_bins(self):
        """Check RGB geotiff generation with colorscale for GMF. Use
        discrete colorscale based on IML values, with custom IML."""
        path = helpers.get_output_path(
            GEOTIFF_FILENAME_DISCRETE_CUSTOMBIN_COLORSCALE)
        asymmetric_region = shapes.Region.from_coordinates(
            TEST_REGION_LARGE_ASYMMETRIC)

        iml_list = TEST_IML_LIST

        gwriter = geotiff.GMFGeoTiffFile(
            path,
            asymmetric_region.grid,
            iml_list=iml_list,
            discrete=True,
            colormap=geotiff.COLORMAPS['matlab-polar'])

        reference_raster = numpy.zeros(
            (asymmetric_region.grid.rows, asymmetric_region.grid.columns),
            dtype=numpy.float)
        self._fill_rasters(asymmetric_region, gwriter, reference_raster,
                           self._colorscale_cuts_fill)
        gwriter.close()