ITRF/NAD83CSRS coordinate transforms in Python.
Install with pip:
pip install csrspy
CSRSPY provides coordinate transformation utilities to transform coordinates between various ITRF realization and NAD83 (CSRS). Furthermore, this library provides the ability to transform between reference epochs and between GRS80 ellipsoidal heights and orthometric heights in CGG2013, CGG2013a, and HT2_2010v70 vertical datums.
CSRSPY is tested for accuracy against official tools from Natural Resources Canada ( specifically, TRX and GPS-H).
If you're hoping to transform LAS/LAZ file coordinates using CSRSPY, check out LAS-TRX.
Here's a simple example of how to use CSRSPY to transform coordinates:
from csrspy import CSRSTransformer
from csrspy.enums import Reference, CoordType, VerticalDatum
transformer = CSRSTransformer(s_ref_frame=Reference.ITRF14,
t_ref_frame=Reference.NAD83CSRS,
s_coords=CoordType.GEOG, t_coords=CoordType.UTM10,
s_epoch=2023.58, t_epoch=2002.0,
s_vd=VerticalDatum.GRS80, t_vd=VerticalDatum.CGG2013A)
in_coords = [(-123.365646, 48.428421, 0)]
out_coords = list(transformer(in_coords))
print(out_coords) # Output: [(472952.4353700947, 5363983.41690525, 18.968777523406512)]
CSRSPY supports various coordinate types, reference frames, and vertical datums. Here's an example of a more complex transformation:
from csrspy import CSRSTransformer
from csrspy.enums import Reference, CoordType, VerticalDatum
transformer = CSRSTransformer(
s_ref_frame=Reference.ITRF14,
t_ref_frame=Reference.NAD83CSRS,
s_coords=CoordType.GEOG,
t_coords=CoordType.UTM10,
s_epoch=2002,
t_epoch=2010,
s_vd=VerticalDatum.GRS80,
t_vd=VerticalDatum.HT2_2010v70
)
in_coords = [(-123.365646, 48.428421, 0)]
out_coords = list(transformer(in_coords))
print(out_coords) # Output: [(472952.3385926245, 5363983.279823124, 18.81151352316209)]
The main class for performing coordinate transformations.
# CSRSTransformer(
# s_ref_frame: Reference | str,
# t_ref_frame: Reference | str,
# s_coords: CoordType | str,
# t_coords: CoordType | str,
# s_epoch: float,
# t_epoch: float,
# s_vd: VerticalDatum | str = VerticalDatum.GRS80,
# t_vd: VerticalDatum | str = VerticalDatum.GRS80,
# epoch_shift_grid: str = "ca_nrc_NAD83v70VG.tif"
# )
s_ref_frame
: Source reference framet_ref_frame
: Target reference frames_coords
: Source coordinate typet_coords
: Target coordinate types_epoch
: Source epoch in decimal year formatt_epoch
: Target epoch in decimal year formats_vd
: Source vertical datumt_vd
: Target vertical datumepoch_shift_grid
: Name of the proj grid file used for epoch transformations
Reference
: Enumeration of supported reference framesCoordType
: Enumeration of supported coordinate typesVerticalDatum
: Enumeration of supported vertical datums
CSRSPY provides some utility functions to assist with common tasks:
Converts a date object to a decimal year representation.
from datetime import date
from csrspy.utils import date_to_decimal_year
d = date(2023, 6, 15)
decimal_year = date_to_decimal_year(d)
print(decimal_year) # Output: 2023.4520547945206
Synchronizes missing PROJ grid files for the Canada area of use. This function should be
called to ensure all necessary grid files are downloaded before using the
CSRSTransformer
class.
from csrspy.utils import sync_missing_grid_files
sync_missing_grid_files()
This function will download any missing grid files required for transformations in the Canada area. It uses the pyproj library to manage the synchronization process.
-
Clone the repository:
git clone https://github.com/HakaiInstitute/csrspy.git cd csrspy
-
Install Poetry (if not already installed):
curl -sSL https://install.python-poetry.org | python3 -
-
Install dependencies:
poetry install
-
Activate the virtual environment:
poetry shell
To run the tests, use the following command:
poetry run pytest
To run tests across multiple Python versions, use tox:
poetry run tox
- Make your changes in the appropriate files.
- Update tests if necessary.
- Run the tests to ensure everything is working.
- Update the version number in
pyproject.toml
. - Commit your changes and push to the repository.
-
Ensure all tests pass and the version number is updated.
-
Create a new tag with the version number:
git tag v0.1.0 git push origin v0.1.0
-
The GitHub Action will automatically build and publish the package to PyPI when a new tag is pushed.
Contributions to CSRSPY are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Write tests for your changes.
- Make your changes and ensure all tests pass.
- Submit a pull request with a clear description of your changes.
CSRSPY is released under the MIT License.