Skip to content

Commit

Permalink
add import in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
AliciaRoh committed Feb 25, 2025
1 parent 5c3056e commit 9b7cf1e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 21 deletions.
27 changes: 15 additions & 12 deletions seismostats/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
# flake8: noqa
import functools
import math

import pandas as pd
from jinja2 import Environment, FileSystemLoader, select_autoescape

from seismostats.utils.binning import ( # noqa
bin_to_precision, # noqa
get_cum_fmd, # noqa
get_fmd, # noqa
from seismostats.utils.binning import (
bin_to_precision,
get_cum_fmd,
get_fmd,
)
from seismostats.utils.coordinates import CoordinateTransformer # noqa
from seismostats.utils.coordinates import ( # noqa
bounding_box_to_polygon, # noqa
polygon_to_bounding_box, # noqa
from seismostats.utils.coordinates import CoordinateTransformer
from seismostats.utils.coordinates import (
bounding_box_to_polygon,
polygon_to_bounding_box,
)
from seismostats.utils.filtering import cat_intersect_polygon # noqa
from seismostats.utils.simulate_distributions import ( # noqa
simulate_magnitudes, # noqa
simulate_magnitudes_binned, # noqa
from seismostats.utils.filtering import cat_intersect_polygon
from seismostats.utils.simulate_distributions import (
simulate_magnitudes,
simulate_magnitudes_binned,
)


Expand Down Expand Up @@ -86,6 +87,8 @@ def is_nan(value: float) -> bool:
check: True if the value is NaN, False otherwise.
Examples:
>>> from seismostats.utils import is_nan
>>> is_nan(float('nan'))
True
>>> is_nan(1.0)
Expand Down
4 changes: 4 additions & 0 deletions seismostats/utils/_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def set_option(key: str, value: Any):
KeyError: If the key is not in the available options.
Examples:
>>> from seismostats.utils._config import set_option
>>> # Disable warnings
>>> set_option('warnings', False)
Expand Down Expand Up @@ -50,6 +52,8 @@ def get_option(key: str) -> Any:
value: The value of the option.
Examples:
>>> from seismostats.utils._config import get_option
>>> # Get the value of the 'warnings' option
>>> warnings = get_option('warnings')
"""
Expand Down
8 changes: 8 additions & 0 deletions seismostats/utils/binning.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def normal_round_to_int(x: float) -> int:
x_round: Rounded value of the given number.
Examples:
>>> from seismostats.utils.binning import normal_round_to_int
>>> normal_round_to_int(2.5)
3
>>> normal_round_to_int(2.4)
Expand All @@ -39,6 +40,7 @@ def normal_round(x: float, n: int = 0) -> float:
x_round: Value rounded to the given number of decimals.
Examples:
>>> from seismostats.utils.binning import normal_round
>>> normal_round(2.123456, 2)
2.12
>>> normal_round(2.123456)
Expand All @@ -62,6 +64,7 @@ def bin_to_precision(x: np.ndarray | list, delta_x: float) -> np.ndarray:
x_round: Value rounded to the given precision.
Examples:
>>> from seismostats.utils import bin_to_precision
>>> bin_to_precision([1.234, 2.345, 3.456], 0.1)
array([1.2, 2.3, 3.5])
>>> bin_to_precision([1.234, 2.345, 3.456], 0.01)
Expand Down Expand Up @@ -123,6 +126,7 @@ def binning_test(
otherwise.
Examples:
>>> from seismostats.utils.binning import binning_test
>>> binning_test([0.2,0.4,0.6], 0.2)
True
>>> binning_test([0.2,0.4,0.6], 0.1)
Expand Down Expand Up @@ -194,6 +198,8 @@ def get_fmd(
mags: Array of magnitudes binned to ``delta_m``.
Examples:
>>> from seismostats.utils import get_fmd
>>> magnitudes = [0.9, 1.1, 1.2, 1.3, 2.1, 2.2, 2.3]
>>> delta_m = 1.0
>>> bin_position = "center"
Expand Down Expand Up @@ -254,6 +260,8 @@ def get_cum_fmd(
mags: Array of magnitudes binned to ``delta_m``.
Examples:
>>> from seismostats.utils import get_cum_fmd
>>> magnitudes = [0.9, 1.1, 1.2, 1.3, 2.1, 2.2, 2.3]
>>> delta_m = 1.0
>>> bin_position = "center"
Expand Down
10 changes: 5 additions & 5 deletions seismostats/utils/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def to_local_coords(
relative to reference.
Examples:
>>> from seismostats.utils.coordinates import CoordinateTransformer
>>> from seismostats.utils import CoordinateTransformer
>>> ref_easting = 2642690
>>> ref_northing = 1205590
Expand Down Expand Up @@ -130,7 +130,7 @@ def from_local_coords(
relative to reference.
Examples:
>>> from seismostats.utils.coordinates import CoordinateTransformer
>>> from seismostats.utils import CoordinateTransformer
>>> ref_easting = 2642690
>>> ref_northing = 1205590
Expand Down Expand Up @@ -171,7 +171,7 @@ def polygon_to_local_coords(self, polygon: Polygon) -> Polygon:
x: Shapely polygon in local coordinates.
Examples:
>>> from seismostats.utils.coordinates import CoordinateTransformer
>>> from seismostats.utils import CoordinateTransformer
>>> from shapely.geometry import Polygon
>>> ref_easting = 2642690
Expand Down Expand Up @@ -210,7 +210,7 @@ def polygon_from_local_coords(self, polygon: Polygon) -> Polygon:
x: Shapely polygon in geographic coordinates.
Examples:
>>> from seismostats.utils.coordinates import CoordinateTransformer
>>> from seismostats.utils import CoordinateTransformer
>>> from shapely.geometry import Polygon
>>> ref_easting = 2642690
Expand Down Expand Up @@ -253,7 +253,7 @@ def bounding_box_to_polygon(x_min, x_max, y_min, y_max, srid=None) -> Polygon:
x: Shapely polygon in geographic coordinates.
Examples:
>>> from seismostats.utils.coordinates import bounding_box_to_polygon
>>> from seismostats.utils import bounding_box_to_polygon
>>> polygon = bounding_box_to_polygon(0, 1, 0, 1)
>>> x,y = polygon.exterior.xy
>>> x
Expand Down
10 changes: 6 additions & 4 deletions seismostats/utils/simulate_distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ def simulate_magnitudes(
exponential distribution.
Examples:
>>> simulate_magnitudes(5, 1, 0, 5)
array([1.39701219, 0.09509761, 2.68367219, 0.73664695, 0.18811929])
>>> simulate_magnitudes(5, 1, 1)
array([1.3249975 , 1.63120196, 3.56443043, 1.15384524, 2.45147558])
>>> from seismostats.utils import simulate_magnitudes
>>> simulate_magnitudes(4, 1, 0, 5)
array([1.39701219, 0.09509761, 2.68367219, 0.73664695]) #random
>>> simulate_magnitudes(4, 1, 1)
array([1.3249975 , 1.63120196, 3.56443043, 1.15384524]) #random
See also:
:func:`~seismostats.utils.simulate_distributions.simulate_magnitudes_binned`
Expand Down Expand Up @@ -74,6 +75,7 @@ def simulate_magnitudes_binned(
mags: Array of magnitudes.
Examples:
>>> from seismostats.utils import simulate_magnitudes_binned
>>> simulate_magnitudes_binned(5, 1, 0, 1, 5)
array([1., 0., 1., 1., 0.])
>>> simulate_magnitudes_binned(5, 1, 1, 0.1)
Expand Down

0 comments on commit 9b7cf1e

Please sign in to comment.