API Reference
This contains a reference document to the PyCSEP API.
Loading catalogs and forecasts
|
General function to load stochastic event sets |
|
General function to load single catalog |
|
Access Comcat catalog through web service |
|
Access BSI catalog through web service |
|
Loads grid based forecast from hard-disk. |
|
General function to handle loading catalog forecasts. |
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 |
|
|
Plot catalog according to plate-carree projection |
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 mag_bins |
Return counts of events in space-magnitude region. |
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 gridded forecast according to plate-carree projection |
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 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. |
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. |
Testing regions:
|
Returns class representing California testing region. |
|
Returns class representing Italian testing 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 |
|
Returns class representing California testing region. |
Plotting
General plotting:
|
Plots histogram of single statistic for stochastic event sets and observations. |
|
Plots empirical cumulative distribution function. |
|
Wrapper function for multiple cartopy base plots, including access to standard raster webservices |
|
Plot spatial dataset such as data from a gridded forecast |
|
Adds publication labels too the outside of a figure. |
Plotting from catalogs:
|
Plots magnitude versus linear time for an earthquake data. |
|
Plot catalog in a region |
Plotting stochastic event sets and evaluations:
|
Same as below but performs the statistics on numpy arrays without using pandas data frames. |
|
Generates a magnitude histogram from a catalog-based forecast |
|
Takes result from evaluation and generates a specific histogram plot to show the results of the statistical evaluation for the n-test. |
|
Takes result from evaluation and generates a specific histogram plot to show the results of the statistical evaluation for the M-test. |
|
Takes result from evaluation and generates a specific histogram plot to show the results of the statistical evaluation for the M-test. |
|
Takes result from evaluation and generates a specific histogram plot to show the results of the statistical evaluation for the L-test. |
|
Plot spatial test result from catalog based forecast |
|
Plotting gridded forecasts and evaluations:
|
Plot spatial dataset such as data from a gridded forecast |
|
Plots list of T-Test (and W-Test) Results |
|
Plots results from CSEP1 tests following the CSEP1 convention. |
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. This search function is a wrapper around the ComCat Web API described here: https://earthquake.usgs.gov/fdsnws/event/1/ Some of the search parameters described there are NOT implemented here, usually because they do not apply to GeoJSON search results, which we are getting here and parsing into Python data structures. This function returns a list of SummaryEvent objects, described elsewhere in this package. Usage: TODO: Show usage information. :param starttime: Python datetime - Limit to events on or after the specified start time. :type starttime: datetime :param endtime: Python datetime - Limit to events on or before the specified end time. :type endtime: datetime :param updatedafter: Python datetime - Limit to events updated after the specified time. :type updatedafter: datetime :param minlatitude: Limit to events with a latitude larger than the specified minimum. :type minlatitude: float :param maxlatitude: Limit to events with a latitude smaller than the specified maximum. :type maxlatitude: float :param minlongitude: Limit to events with a longitude larger than the specified minimum. :type minlongitude: float :param maxlongitude: Limit to events with a longitude smaller than the specified maximum. :type maxlongitude: float :param latitude: Specify the latitude to be used for a radius search. :type latitude: float :param longitude: Specify the longitude to be used for a radius search. :type longitude: float :param maxradiuskm: Limit to events within the specified maximum number of kilometers from the geographic point defined by the latitude and longitude parameters. :type maxradiuskm: float :param maxradius: Limit to events within the specified maximum number of degrees from the geographic point defined by the latitude and longitude parameters. :type maxradius: float :param catalog: Limit to events from a specified catalog. :type catalog: str :param contributor: Limit to events contributed by a specified contributor. :type contributor: str :param limit: Limit the results to the specified number of events. NOTE, this will be throttled by this Python API to the supported Web API limit of 20,000. :type limit: int :param maxdepth: Limit to events with depth less than the specified maximum. :type maxdepth: float :param maxmagnitude: Limit to events with a magnitude smaller than the specified maximum. :type maxmagnitude: float :param mindepth: Limit to events with depth more than the specified minimum. :type mindepth: float :param minmagnitude: Limit to events with a magnitude larger than the specified minimum. :type minmagnitude: float :param offset: Return results starting at the event count specified, starting at 1. :type offset: int :param orderby: Order the results. The allowed values are: - time order by origin descending time - time-asc order by origin ascending time - magnitude order by descending magnitude - magnitude-asc order by ascending magnitude :type orderby: str :param alertlevel: Limit to events with a specific PAGER alert level. The allowed values are: - green Limit to events with PAGER alert level "green". - yellow Limit to events with PAGER alert level "yellow". - orange Limit to events with PAGER alert level "orange". - red Limit to events with PAGER alert level "red". :type alertlevel: str :param eventtype: Limit to events of a specific type. NOTE: "earthquake" will filter non-earthquake events. :type eventtype: str :param maxcdi: Maximum value for Maximum Community Determined Intensity reported by DYFI. :type maxcdi: float :param maxgap: Limit to events with no more than this azimuthal gap. :type maxgap: float :param maxmmi: Maximum value for Maximum Modified Mercalli Intensity reported by ShakeMap. :type maxmmi: float :param maxsig: Limit to events with no more than this significance. :type maxsig: float :param mincdi: Minimum value for Maximum Community Determined Intensity reported by DYFI. :type mincdi: float :param minfelt: Limit to events with this many DYFI responses. :type minfelt: int :param mingap: Limit to events with no less than this azimuthal gap. :type mingap: float :param minsig: Limit to events with no less than this significance. :type minsig: float :param producttype: Limit to events that have this type of product associated. Example producttypes: - moment-tensor - focal-mechanism - shakemap - losspager - dyfi :type producttype: str :param productcode: Return the event that is associated with the productcode. The event will be returned even if the productcode is not the preferred code for the event. Example productcodes: - nn00458749 - at00ndf1fr :type productcode: str :param reviewstatus: Limit to events with a specific review status. The different review statuses are: - automatic Limit to events with review status "automatic". - reviewed Limit to events with review status "reviewed". :type reviewstatus: str :param host: Replace default ComCat host (earthquake.usgs.gov) with a custom host. :type host: str :param enable_limit: Enable 20,000 event search limit. Will turn off searching in segments, which is meant to safely avoid that limit. Use only when you are certain your search will be small. :type enable_limit: bool. |
|
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. |