mtpy.gis package

Submodules

mtpy.gis.raster_tools module

Created on Sun May 11 12:15:37 2014

@author: jrpeacock

mtpy.gis.raster_tools.array2raster(raster_fn: str, array: ndarray, lower_left: MTLocation, cell_size_north: float, cell_size_east: float, crs: str | int, rotation_angle: float = 0) None[source]

Write a numpy array to a GeoTIFF raster file using rasterio.

Parameters:
  • raster_fn (str) – Output raster filename (GeoTIFF format)

  • array (np.ndarray) – 2D numpy array containing the raster data to write

  • lower_left (MTLocation) – MTLocation object specifying the lower-left corner coordinates of the raster in the target coordinate system

  • cell_size_north (float) – Cell size in the north (vertical) direction

  • cell_size_east (float) – Cell size in the east (horizontal) direction

  • crs (str | int) – Coordinate reference system (CRS) specification. Can be an EPSG code (e.g., ‘EPSG:4326’) or other CRS string

  • rotation_angle (float, optional) – Rotation angle in degrees for the raster grid, by default 0

Raises:
  • TypeError – If lower_left is not an MTLocation object

  • TypeError – If array is not a numpy ndarray

Notes

The function uses an affine transformation to properly georeference the output raster. The transformation combines translation, scaling, and rotation operations.

Examples

>>> import numpy as np
>>> from mtpy.core.mt_location import MTLocation
>>> data = np.random.rand(100, 100)
>>> ll_corner = MTLocation(latitude=40.0, longitude=-120.0, datum='WGS84')
>>> array2raster(
...     'output.tif',
...     data,
...     ll_corner,
...     cell_size_north=0.01,
...     cell_size_east=0.01,
...     crs='EPSG:4326'
... )

mtpy.gis.shapefile_creator module

Description:

Create shape files for Phase Tensor Ellipses, Tipper Real/Imag. export the phase tensor map and tippers into jpeg/png images

CreationDate: 2017-03-06 Developer: fei.zhang@ga.gov.au

Revision History:

LastUpdate: 10/11/2017 FZ fix bugs after the big merge LastUpdate: 20/11/2017 change from freq to period filenames, allow to specify a period LastUpdate: 30/10/2018 combine ellipses and tippers together, refactorings

brenainn.moushall@ga.gov.au 27-03-2020 17:33:23 AEDT:

Fix outfile/directory issue (see commit messages)

update to v2 jpeacock 2024-04-15

class mtpy.gis.shapefile_creator.ShapefileCreator(mt_dataframe: MTDataFrame, output_crs: str | int | CRS, save_dir: str | Path | None = None, **kwargs)[source]

Bases: object

Create phase tensor and tipper shape files using geopandas and shapely tools.

mt_dataframe

MTDataFrame object containing MT station data

Type:

MTDataFrame

save_dir

Directory where shapefiles will be saved

Type:

Path

output_crs

Output coordinate reference system

Type:

CRS

ellipse_size

Size scaling factor for phase tensor ellipses

Type:

float

ellipse_resolution

Number of points to use when drawing ellipses

Type:

int

arrow_size

Size scaling factor for tipper arrows

Type:

float

utm

Whether to use UTM coordinates instead of lat/lon

Type:

bool

estimate_arrow_size(quantile: float = 0.03) float[source]

Estimate arrow size from station distances.

Parameters:

quantile (float, optional) – Quantile of station distances to use for size estimation, by default 0.03

Returns:

Estimated arrow size based on station spacing

Return type:

float

estimate_ellipse_size(quantile: float = 0.015) float[source]

Estimate ellipse size from station distances.

Parameters:

quantile (float, optional) – Quantile of station distances to use for size estimation, by default 0.015

Returns:

Estimated ellipse size based on station spacing

Return type:

float

make_shp_files(pt: bool = True, tipper: bool = True, periods: list[float] | ndarray | None = None, period_tol: float | None = None) dict[str, list[Path]][source]

Create shapefiles for phase tensors and/or tippers at specified periods.

Parameters:
  • pt (bool, optional) – Whether to create phase tensor shapefiles, by default True

  • tipper (bool, optional) – Whether to create tipper shapefiles (real and imaginary), by default True

  • periods (list[float] | np.ndarray | None, optional) – List of periods in seconds to create shapefiles for. If None, uses all periods in the MTDataFrame, by default None

  • period_tol (float | None, optional) – Tolerance for period matching, by default None

Returns:

Dictionary with keys ‘pt’, ‘tipper_real’, ‘tipper_imag’ containing lists of paths to created shapefiles

Return type:

dict[str, list[Path]]

Notes

If you want all stations on the same period map, you need to interpolate before converting to an MTDataFrame.

Examples

>>> md.interpolate(new_periods)
>>> mt_df = MTDataFrame(md)
>>> creator = ShapefileCreator(mt_df, output_crs='EPSG:4326')
>>> shp_files = creator.make_shp_files()
property mt_dataframe

MTDataFrame object.

property output_crs

Output crs.

property save_dir

Save dir.

property x_key

X key.

property y_key

Y key.

Module contents