API Reference
This contains a reference document to the PyCSEP API.
Loading catalogs, forecasts and results
|
General function to load single catalog |
|
Access Comcat catalog through web service |
|
Access BSI catalog through web service |
|
Access GNS Science catalog through web service |
|
|
|
Loads grid based forecast from hard-disk. |
|
General function to handle loading catalog forecasts. |
|
General function to load stochastic event sets |
|
Load evaluation result stored as json file |
Catalogs
Catalog operations are defined using AbstractBaseCatalog class.
|
Abstract catalog base class for PyCSEP catalogs. |
|
Standard catalog class for PyCSEP catalog operations. |
|
Catalog written from UCERF3-ETAS binary format |
Catalog operations
Input and output operations for catalogs:
Serializes class to json dictionary. |
|
|
Creates a class from the dictionary representation of the class state. |
|
Returns pandas Dataframe describing the catalog. |
|
Creates catalog from dataframe. |
|
Writes catalog to json file |
|
Loads catalog from JSON file |
|
Loads catalog stored in CSEP1 ascii format |
|
Write catalog in csep2 ascii format. |
|
Loads multiple catalogs in csep-ascii format. |
Returns CSEP format for a catalog |
|
|
Plots the catalog epicenters. |
Accessing event information:
Number of events in catalog |
|
Returns magnitudes of all events in catalog |
|
Returns longitudes of all events in catalog |
|
Returns latitudes of all events in catalog |
|
Returns depths of all events in catalog |
|
Returns the datetime of the event as the UTC epoch time (aka unix timestamp) |
|
Returns datetime object from timestamp representation in catalog |
|
Returns the cumulative number of events in the catalog. |
Filtering and binning:
|
Filters the catalog based on statements. |
|
Removes events outside of the region. |
|
Applies time-dependent magnitude of completeness following a mainshock. |
Returns counts of events within discrete spatial region |
|
|
Computes the count of events within magnitude bins |
Return counts of events in space-magnitude bins. |
Other utilities:
Compute summary statistics of events in catalog |
|
Returns catalog length in seconds assuming that the catalog is sorted by time. |
|
|
Estimates the b-value of a catalog from Marzocchi and Sandri (2003). |
Forecasts
PyCSEP provides classes to interact with catalog and grid based Forecasts
|
Class to represent grid-based forecasts |
|
Catalog based forecast defined as a family of stochastic event sets. |
Gridded forecast methods:
Contains the spatio-magnitude forecast as 2d numpy.ndarray. |
|
Returns a sum of the forecast data |
|
Sums over all of the forecast data |
|
Returns the lowest magnitude bin edge |
|
Returns counts of events in magnitude bins |
|
|
Integrates over magnitudes to return the spatial version of the forecast. |
Returns the latitude of the lower left node of the spatial grid |
|
Returns the lognitude of the lower left node of the spatial grid |
|
Returns the left edge of the magnitude bins. |
|
|
Returns the index of lons, lats in spatial region |
|
Returns the indices into the magnitude bins of selected magnitudes |
|
Reads Forecast file from CSEP1 ascii format. |
|
Creates MarkedGriddedDataSet class from custom parsing function. |
|
Returns the rate associated with a longitude, latitude, and magnitude. |
|
Generates data set of target event rates given a target data. |
|
Scales forecast data by the fraction of the date. |
|
Plot the spatial rate of the forecast |
Catalog forecast methods:
Returns left bin-edges of magnitude bins |
|
Returns smallest magnitude bin edge of forecast |
|
|
Returns the expected spatial counts from forecast |
Returns expected magnitude counts from forecast |
|
|
Compute the expected rates in space-magnitude bins |
Return a single dataframe with all of the events from all of the catalogs. |
|
|
Writes data forecast to ASCII format |
|
Loads ASCII format for data forecast. |
Evaluations
PyCSEP provides implementations of evaluations for both catalog-based forecasts and grid-based forecasts.
Catalog-based forecast evaluations:
|
Performs the number test on a catalog-based forecast. |
|
Performs spatial test for catalog-based forecasts. |
|
Performs magnitude test for catalog-based forecasts |
|
Performs the resampled magnitude test for catalog-based forecasts (Serafini et al., 2024), which corrects the bias from the original M-test implementation to the total N of events. |
|
Implements the modified Multinomial log-likelihood ratio (MLL) magnitude test (Serafini et al., 2024). |
|
Performs the spatial pseudolikelihood test for catalog forecasts. |
|
Perform the calibration test by computing a Kilmogorov-Smirnov test of the observed quantiles against a uniform distribution. |
Grid-based forecast evaluations:
|
Computes "N-Test" on a gridded forecast. |
|
Performs the Magnitude Test on a Gridded Forecast using an observed catalog. |
|
Performs the Spatial Test on the Forecast using the Observed Catalogs. |
|
Performs the likelihood test on Gridded Forecast using an Observed Catalog. |
|
Performs the conditional likelihood test on Gridded Forecast using an Observed Catalog. |
|
Computes the t-test for gridded earthquake forecasts. |
|
Calculate the Single Sample Wilcoxon signed-rank test between two gridded forecasts. |
Evaluation result base class
|
Regions
PyCSEP includes commonly used CSEP testing regions and classes that facilitate working with gridded data sets. This module is early in development and help is welcome here!
Region class(es):
|
Represents a 2D cartesian gridded region. |
|
Creates instance of class from 2d numpy.array of lon/lat origins. |
|
Creates a region object from a dictionary |
Returns 2d ndrray representation of the data set, corresponding to the bounding box. |
|
Compute the area of each polygon in sq. |
|
|
Returns the index of lons, lats in self.polygons |
|
Respresents a 2D quadtree gridded region. |
|
Creates instance of class from 2d numpy.array of lon/lat of Catalog. |
Creates instance of class at single-resolution using provided zoom-level. |
|
|
Creates instance of class from available quadtree grid. |
Returns 2d ndrray representation of the data set, corresponding to the bounding box. |
Testing regions:
|
Returns class representing California testing region. |
Return collection region for California RELM testing region |
|
|
Returns class representing Italian testing region. |
|
Return collection region for Italy CSEP collection region |
|
Return collection region for the New Zealand CSEP testing region |
|
Return collection region for the New Zealand CSEP collection region |
|
Creates a global region used for evaluating gridded forecasts on the global scale. |
Region utilities:
|
Returns array holding magnitude bin edges. |
|
Simple wrapper to create space-magnitude region |
|
Reads CSEP XML template file and returns the lat/lon values for the forecast. |
|
Takes a set of origin points and returns a new set with higher grid resolution. |
|
Build a new region based off the coordinates in the polygon. |
|
Creates a spatial region around a given epicenter |
Plotting
PyCSEP offers multiple plot functionalities to visually explore forecasts, catalogs and results.
Exploratory plotting:
|
Scatter plot of the catalog magnitudes and origin times. |
|
Plots the cumulative number of forecasted events from a |
|
Generates a semi-log magnitude histogram comparing a catalog-based forecast with observed data. |
Spatial plotting:
|
Wrapper function for multiple Cartopy base plots, including access to standard raster web services and reading of filesystem geoTIFF. |
|
Spatial plot of catalog epicenters. |
|
Plot spatial gridded dataset such as data from a gridded forecast. |
Plotting grid-based evaluations:
|
Plots a list of T-Test (and optional W-Test) results on a single axis. |
|
Plots the results from one or multiple consistency tests. |
Plotting catalog-based evaluations:
|
Plots the histogram of a test statistic distribution calculated from stochastic event sets along with the observed statistic. |
|
Plots a calibration test (Quantile-Quantile plot) with confidence intervals. |
Plotting alarm-based evaluations:
|
Plots the ROC (Receiver Operating Characteristic) curve for a given forecast and observed catalog. |
|
Plots the Concentration ROC Diagram for a given forecast and observed catalog. |
|
Plot the Molchan Diagram based on forecast and test catalogs using the contingency table. |
Time Utilities
|
Accepts an epoch_time in milliseconds the UTC timezone and returns a python datetime object. |
Converts python datetime.datetime into epoch_time in milliseconds. |
|
|
Converts time in millis to days |
|
Converts days to millis |
|
Returns epoch time from formatted time string |
|
Returns python datetime.timedelta object based on the astronomical year in seconds. |
|
Converts time_string with format into time-zone aware datetime object in the UTC timezone. |
Returns current datetime |
|
Returns current epoch time |
|
|
Creates TZAware UTC datetime object from unaware object. |
|
Convert given test date to the decimal year representation. |
Comcat Access
We integrated the code developed by Mike Hearne and others at the USGS to reduce the dependencies of this package. We plan to move this to an external and optional dependency in the future.
|
Search the ComCat database for events matching input criteria. |
|
Search the ComCat database for an event matching the input event id. |
Calculation Utilities
|
Returns the index from array that is less than the value specified. |
|
Returns the value from array that is less than the value specified. |
|
Returns the value of a function based on interpolation. |
|
returns array with len(bin_edges) consisting of the discretized values from each bin. |
|
Efficient implementation of binning routine on 1D Cartesian Grid. |
Statistics Utilities
|
given two cumulative distribution functions, compute the supremum of the set of absolute distances. |
|
computes the ks statistic for two ecdfs that are not necessarily aligned on the same values. |
|
given two cumulative distribution functions, compute the cumulative sq. |
|
returns the statement P(X ≤ x) for val in vals. |
|
Compute the ecdf of vector x. |
|
Given val return P(x ≥ val). |
|
Given val return P(x ≤ val). |
|
Given an array x, returns the min value. |
|
Given an array x, returns the max value. |
|
Computes delta1 and delta2 quantile scores from empirical distribution and observation |
|
Wrapper around scipy to compute the Poisson log-likelihood |
Efficient calculation of joint log-likelihood of grid-based forecast. |
|
|
Wrapper around scipy inverse poisson cdf function |
Basic types
|
Allows us to work with data that need to be discretized and aggregated even though the the global min/max values are not known before hand. |