Ejemplo n.º 1
0
    def test_catalog_binning_and_filtering_acceptance(self):
        # create space-magnitude region
        region = regions.create_space_magnitude_region(
            regions.california_relm_region(),
            regions.magnitude_bins(4.5, 10.05, 0.1)
        )

        # read catalog
        comcat = csep.load_catalog(comcat_path(), region=region).filter(f"magnitude >= 4.5")

        # create data set from data set
        d = forecasts.MarkedGriddedDataSet(
            data=comcat.spatial_magnitude_counts(),
            region=comcat.region,
            magnitudes=comcat.region.magnitudes
        )

        for idm, m_min in enumerate(d.magnitudes):
            # catalog filtered cumulative
            print(m_min)
            c = comcat.filter([f'magnitude >= {m_min}'], in_place=False)
            # catalog filtered incrementally
            c_int = comcat.filter([f'magnitude >= {m_min}', f'magnitude < {m_min + 0.1}'], in_place=False)
            # sum from overall data set
            gs = d.data[:, idm:].sum()
            # incremental counts
            gs_int = d.data[:, idm].sum()
            # event count from filtered catalog and events in binned data should be the same
            numpy.testing.assert_equal(gs, c.event_count)
            numpy.testing.assert_equal(gs_int, c_int.event_count)
Ejemplo n.º 2
0
def create_space_magnitude_region(name, min_mw, max_mw, dmw):
    # if we include this in the package we can expand
    mapper = {'california_relm_region': regions.california_relm_region}
    region = regions.create_space_magnitude_region(
        mapper[name](), regions.magnitude_bins(min_mw, max_mw, dmw))
    return region
####################################################################################################################################
# Define spatial and magnitude regions
# ------------------------------------
#
# Before we can compute the bin-wise rates we need to define a spatial region and a set of magnitude bin edges. The magnitude
# bin edges # are the lower bound (inclusive) except for the last bin, which is treated as extending to infinity. We can
# bind these # to the forecast object. This can also be done by passing them as keyword arguments
# into :func:`csep.load_catalog_forecast`.

# Magnitude bins properties
min_mw = 4.95
max_mw = 8.95
dmw = 0.1

# Create space and magnitude regions
magnitudes = regions.magnitude_bins(min_mw, max_mw, dmw)
region = regions.california_relm_region()

# Bind region information to the forecast (this will be used for binning of the catalogs)
forecast.region = regions.create_space_magnitude_region(region, magnitudes)

####################################################################################################################################
# Compute spatial event counts
# ----------------------------
#
# The :class:`csep.core.forecasts.CatalogForecast` provides a method to compute the expected number of events in spatial cells. This
# requires a region with magnitude information.

_ = forecast.get_expected_rates(verbose=True)

####################################################################################################################################