GRRateGrid.concat#

classmethod GRRateGrid.concat(grids: list[GRRateGrid])#

Concatenate a list of GRRateGrid objects into a single GRRateGrid with a MultiIndex using starttime, optionally endtime and a unique cell number.

Requires that all GRRateGrid objects have the same columns and that at least the starttime attribute is set for all of them. :param grids: List of GRRateGrid objects to concatenate.

Returns:

rategrid – A new GRRateGrid object containing the concatenated data.

Examples

Create two GRRateGrid objects with different time ranges and then concatenate them into a single GRRateGrid with a MultiIndex based on starttime, endtime and cell_id.

>>> 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]}
>>> rategrid1 = GRRateGrid(
...     data,
...     starttime=pd.Timestamp("2023-01-01"),
...     endtime=pd.Timestamp("2023-01-02"))
>>> rategrid2 = GRRateGrid(
...     data,
...     starttime=pd.Timestamp("2023-01-02"),
...     endtime=pd.Timestamp("2023-01-03"))
>>> rategrid = GRRateGrid.concat([rategrid1, rategrid2])
>>> 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
2023-01-02 2023-01-03 0               9.0  ...  0  0   0
                      1              10.0  ...  1  1   1
                      2              11.0  ...  2  2   2