xarray.Dataset.traj.transformer#
- Dataset.traj.transformer(from_crs)#
Create a transformer useful for transforming other coordinates to the CRS of this dataset.
- Parameters:
from_crs (
pyproj.crs.CRS
)- Returns:
transformer (
pyproj.Transformer
)
Example
Transform UTM coordinates to lat-lon
>>> import xarray as xr >>> import trajan as _ >>> import lzma >>> import pyproj >>> b = lzma.open('examples/barents.nc.xz') >>> ds = xr.open_dataset(b) >>> print(ds) <xarray.Dataset> Size: 110kB Dimensions: (trajectory: 2, obs: 2287) Dimensions without coordinates: trajectory, obs Data variables: lon (trajectory, obs) float64 37kB ... lat (trajectory, obs) float64 37kB ... time (trajectory, obs) datetime64[ns] 37kB ... drifter_names (trajectory) <U16 128B ... Attributes: (12/13) Conventions: CF-1.10 featureType: trajectory geospatial_lat_min: 74.5454462 geospatial_lat_max: 77.4774768 geospatial_lon_min: 17.2058074 geospatial_lon_max: 29.8523485 ... ... time_coverage_end: 2022-11-23T13:30:28 creator_email: gauteh@met.no, knutfd@met.no creator_name: Gaute Hope and Knut Frode Dagestad creator_url: https://github.com/OpenDrift/opendrift summary: Two drifters in the Barents Sea. One stranded at Ho... title: Barents Sea drifters
>>> crs = pyproj.CRS.from_epsg(3857) # mercator >>> >>> tlon, tlat = ds.traj.transformer(crs).transform(-10000, 3000) >>> print(tlon, tlat) -0.08983152841195213 0.026949457529889528