GRRateGrid.add_time_index#

GRRateGrid.add_time_index(endtime=True) GRRateGrid#

Create MultiIndex using starttime and endtime, both taken from the object attributes, and a cell number for each spatial block.

Parameters:

endtime – If True, create MultiIndex with starttime and endtime. Otherwise, create MultiIndex with only starttime.

Returns:

rategrid – A new RateGrid with the MultiIndex set.

Examples

Create a GRRateGrid, then add a time index to it.

>>> import pandas as pd
>>> from seismostats import GRRateGrid
>>> data = {'longitude_min': [9.0, 10.0, 11.0],
...         'longitude_max': [10.0, 11.0, 12.0],
...         'latitude_min': [45.0, 46.0, 47.0],
...         'latitude_max': [46.0, 47.0, 48.0],
...         'depth_min': [1, 2, 3], 'depth_max': [2, 3, 4],
...         'a': [0, 1, 2], 'b': [0, 1, 2], 'mc': [0, 1, 2]}
>>> rategrid = GRRateGrid(
...     data,
...     starttime=pd.Timestamp("2023-01-01"),
...     endtime=pd.Timestamp("2023-01-02"))
>>> rategrid = rategrid.add_time_index()
>>> rategrid

                               longitude_min  ...  a  b  mc
starttime  endtime    cell_id
2023-01-01 2023-01-02 0                  9.0  ...  0  0   0
                      1                 10.0  ...  1  1   1
                      2                 11.0  ...  2  2   2