xarray.Dataset.traj.transform#
- Dataset.traj.transform(to_crs)#
Transform this datasets to to_crs coordinate system. If the target projection is not a geographic coordinate system the variables will be named x and y, otherwise lon and lat.
- Parameters:
to_crs (
pyproj.crs.CRS
)- Returns:
ds (array-like) – Dataset in to_crs coordinate system.
Example
Transform dataset to UTM coordinates:
>>> 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 >>> >>> ds_merc = ds.traj.transform(crs) >>> print(ds_merc) <xarray.Dataset> Size: 110kB Dimensions: (trajectory: 2, obs: 2287) Dimensions without coordinates: trajectory, obs Data variables: time (trajectory, obs) datetime64[ns] 37kB ... drifter_names (trajectory) <U16 128B ... x (trajectory, obs) float64 37kB 3.323e+06 ... 2.354e+06 y (trajectory, obs) float64 37kB 1.401e+07 ... 1.276e+07 proj1 float64 8B nan 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
See also