pylag.processing.coordinate module

The version of coordinate.py provided here is taken directly from the PyFVCOM library, which can be accessed via GitHub. It is copied here in order to minimise PyLag dependencies. The DOI for PyFVCOM is DOI: https://doi.org/10.5281/zenodo.1422462.

Utilities to convert from cartesian UTM coordinates to spherical latitude and longitudes.

This function uses functions lifted from the utm library. For those that are interested, the reason we don’t just use the utm utility is because it refuses to do coordinate conversions outside a single zone.

pylag.processing.coordinate.british_national_grid_to_lonlat(eastings, northings)[source]

Converts British National Grid coordinates to latitude and longitude on the WGS84 spheroid.

Parameters:
  • eastings (ndarray) – Array of eastings (in metres)

  • northings (ndarray) – Array of northings (in metres)

Returns:

  • lon (ndarray) – Array of converted longitudes (decimal degrees)

  • lat (ndarray) – Array of converted latitudes (decimal degrees)

pylag.processing.coordinate.check_valid_zone(zone_number, zone_letter=None)[source]

Check zone is valid

Implementation copied from the utm package. See https://github.com/Turbo87/utm.

Parameters:
  • zone_number (int) – The UTM zone number.

  • zone_letter (str, optional) – The UTM zone letter. If provided, this should be a single character in length and between C and X.

pylag.processing.coordinate.get_epsg_code(lon: float, lat: float, datum: str | None = 'WGS 84') str[source]

Calculate EPSG code from longitude and latitude values

Parameters:
  • lon (float) – Longitude and latitudes

  • lat (float) – Longitude and latitudes

  • datum (str, optional) – The datum to use. Optional, default “WGS 84”.

Returns:

epsg_code – The EPSG code.

Return type:

str

pylag.processing.coordinate.get_zone_letter(latitude)[source]

Calculate the UTM zone letter from the given latitude. Shamelessly lifted from the utm.latitude_to_zone_letter function.

Parameters:

latitude (float) – Latitude

Returns:

zone_letter – Zone letter

Return type:

str

Raises:

PyLagOutOfBoundsError - For a latitude that is < -80 or > 84

pylag.processing.coordinate.get_zone_number(longitude, latitude)[source]

Calculate the UTM zone number from the given coordinate. Shamelessly lifted from the utm.lonlat_to_zone_number function.

Parameters:
  • longitude (float) – Longitude in degrees East.

  • latitude (float) – Latitude in degrees North.

Returns:

zone_number – Zone number

Return type:

int

pylag.processing.coordinate.lonlat_decimal_from_degminsec(lon_degminsec, lat_degminsec)[source]

Converts from lon lat in degrees minutes and seconds to decimal degrees

Parameters:
  • lon_degminsec (Mx3 np.ndarray) – Array of longitude degrees, minutes and seconds in 3 separate columns (for M positions). East and West is determined by the sign of the leading non-zero number (e.g. [-4, 20, 16] or [0, -3, 10])

  • lat_degminsec (Mx3 np.ndarray) – Array of latitude degrees, minutes and seconds in 3 seperate columns (for M positions). North and South are determined by the sign of the leading number.

Returns:

  • lon (np.ndarray) – Array of converted decimal longitudes.

  • lat (np.ndarray) – Array of converted decimal latitudes.

pylag.processing.coordinate.lonlat_decimal_from_degminsec_wco(lon_degminsec, lat_degminsec)[source]

Converts from lon lat in degrees minutes and seconds to decimal degrees for the Western Channel Observatory format (DDD.MMSSS) rather than actual degrees, minutes seconds.

Parameters:
  • lon_degminsec (Mx3 np.ndarray) – Array of longitude degrees, minutes and seconds in 3 separate columns (for M positions). East and West is determined by the sign of the leading non-zero number (e.g. [-4, 20, 16] or [0, -3, 10])

  • lat_degminsec (Mx3 np.ndarray) – Array of latitude degrees, minutes and seconds in 3 seperate columns (for M positions). North and South are determined by the sign of the leading number.

Returns:

  • lon (np.ndarray) – Array of converted decimal longitudes.

  • lat (np.ndarray) – Array of converted decimal latitudes.

pylag.processing.coordinate.lonlat_from_utm(eastings, northings, epsg_code: str, zone=None)[source]

Converts UTM coordinates to lat/lon.

East Longitudes are positive, west longitudes are negative. North latitudes are positive, south latitudes are negative. Lat and Long are in decimal degrees.

Parameters:
  • eastings (object) – Eastings and northings. Can be single values or array like,

  • northings (object) – Eastings and northings. Can be single values or array like,

  • epsg_code (str) – The EPSG code for the utm transformation.

  • zone (str, optional) – DEPRECATED. Past means of specifying the UTM zone for the transformation that is no longer supported. If zone is passed in, a runtime error will be raised.

Returns:

lon, lat – Longitude and latitudes for the given eastings and northings.

Return type:

float, np.ndarray

pylag.processing.coordinate.to_ndarray(x)[source]

Try to convert x to a NumPy NDArray

Support for strings, ints, floats, tuples and lists is included.

Parameters:

x (object) – The object to convert.

Returns:

The processed object transformed to a ndarray.

Return type:

ndarray

Raises:

PyLagTypeError is the object is not supported.

pylag.processing.coordinate.utm_from_lonlat(longitude, latitude, epsg_code: str | None = None, zone=None)[source]

Converts lats and lons to UTM coordinates using pyproj

East Longitudes are positive, west longitudes are negative. North latitudes are positive, south latitudes are negative. Lats and lons are in decimal degrees.

The desired EPSG code can be found by searching websites such as epsg.io or spatialreference.org. If it is not provided, it will be calculated automatically from the first lon and lat values for the WGS 84 datum using the approach described here: https://tinyurl.com/aa83npwy.

Be careful when using this function for coordinates that span multiple zones as the transformation is specific to the specified EPSG reference system.

Parameters:
  • longitude (object) – Longitudes and latitudes. Can be a single value or array like.

  • latitude (object) – Longitudes and latitudes. Can be a single value or array like.

  • epsg_code (str, optional) – The EPSG code for the utm transformation.

  • zone (str, optional) – DEPRECATED. Past means of specifying the UTM zone for the transformation that is no longer supported.

Returns:

  • eastings, northings (numpy.ndarray) – Eastings and northings in the supplied reference system for the given longitudes and latitudes.

  • epsg_code (str) – The EPSG code for the utm transformation.