hf_hydrodata.grid module

Functions to perform lat/lon to x,y conversions using hf_hydrodata grids.

The conversion functions in this class are verified against pyproj answers and is the same within .01 meters, but the conversion is much faster. It evaluates the lambert conformal projection formulas using projection constants.

hf_hydrodata.grid.from_latlon(grid: str, *args) List[float]

Convert grid lat,lon coordinates to x,y float values in grid resolution coordinates from the grid origin.

Parameters:
  • grid -- The name of a hf_hydrodata grid (e.g. conus1 or conus2).

  • args -- A list of (lat,lon) floating pairs of values.

Returns:

An array of x,y integer points converted from each of the (lat,lon) grid coordinates in args.

Raises:

ValueError -- If x,y point is outside the bounds of the grid.

Note, this may be used to convert a single point or a bounds of 2 points or a large array of points.

This conversion is fast. It is about 100K+ points/second.

Example:

import hf_hydrodata as hf

(x, y) = hf.from_latlon("conus1", 31.759219, -115.902573)
xy_bounds = hf.from_latlon("conus1", *[31.651836, -115.982367, 31.759219, -115.902573])
hf_hydrodata.grid.meters_to_ij(grid: str, *args) List[int]

Convert conic meter coordinates to (i, j) int values in grid resolution coordinates from grid origin.

Parameters:
  • grid -- The name of a hf_hydrodata grid (e.g. conus1 or conus2).

  • args -- A list of floating pairs returned from to_meters() function.

This is similar to the function to_ij(), but does not throw an error if the points are outside the grid.

Examples:

import hf_hydrodata as hf

meters = hf.to_meters("conus1", 31.759219, -115.902573)

(i, j) = hf.meters_to_ij("conus1", *meters)
assert i == 10
assert y == 10

(i, j) = hf.meters_to_ij("conus1", meters[0], meters[1])
assert i == 10
assert j == 10
hf_hydrodata.grid.meters_to_xy(grid: str, *args) List[float]

Convert conic meter coordinates to (x,y) float values in grid resolution coordinates from grid origin.

Parameters:
  • grid -- The name of a hf_hydrodata grid (e.g. conus1 or conus2).

  • args -- A list of floating pairs returned from to_meters() function.

This is similar to the function to_xy(), but does not throw an error if the points are outside the grid.

Examples:

import hf_hydrodata as hf

meters = hf.to_meters("conus1", 31.759219, -115.902573)

(x, y) = hf.meters_to_xy("conus1", *meters)
assert round(x) == 10
assert round(y) == 10

(x, y) = hf.meters_to_xy("conus1", meters[0], meters[1])
assert round(x) == 10
assert round(y) == 10
hf_hydrodata.grid.to_ij(grid: str, *args) List[int]

Convert grid lat,lon coordinates to i,j integers in grid resolution coordinates from grid origin.

Parameters:
  • grid -- The name of a hf_hydrodata grid (e.g. conus1 or conus2).

  • args -- A list of floating pairs of lat,lon values.

Raises:

ValueError -- If i,j point is outside the bounds of the grid.

Example:

import hf_hydrodata as hf

(i, j) = hf.to_ij("conus1", 31.759219, -115.902573)
ij_bounds = hf.to_ij("conus1", *[31.651836, -115.982367, 31.759219, -115.902573])
hf_hydrodata.grid.to_latlon(grid: str, *args) List[float]

Convert grid x,y coordinates to lat,lon.

Parameters:
  • grid -- The name of a hf_hydrodata grid (e.g. conus1 or conus2).

  • args -- A list of (x,y) numbers of that are coordinates in the grid (may be int or float).

Returns:

An array of lat,lon points converted from each of the (x,y) grid coordinates in args.

Note, this may be used to convert a single point or a bounds of 2 points or a large array of points.

This conversion is fast. It is about 100K+ points/second.

Example:

import hf_hydrodata as hf

(lat, lon) = hf.to_latlon("conus1", 10, 10)
latlon_bounds = hf.to_latlon("conus1", *[0, 0, 20, 20])
(lat, lon) = hf.to_latlon("conus1", 10.5, 10.5)
hf_hydrodata.grid.to_meters(grid: str, *args) List[float]

Convert grid lat,lon coordinates to x,y in meters from grid origin.

Parameters:
  • grid -- The name of a hf_hydrodata grid (e.g. conus1 or conus2).

  • args -- A list of floating pairs of lat,lon values.

Returns:

An array of (x,y) integer points converted from each of the (lat,lon) grid coordinates in args.

Note, this may be used to convert a single point or a bounds of 2 points or a large array of points.

This conversion is fast. It is about 100K+ points/second.

Example:

import hf_hydrodata as hf

(x, y) = hf.to_meters("conus1", 31.759219, -115.902573)
latlon_bounds = hf.to_meters("conus1", *[31.651836, -115.982367, 31.759219, -115.902573])
hf_hydrodata.grid.to_xy(grid: str, *args) List[float]

Convert grid lat,lon coordinates to (x,y) float values in grid resolution coordinates from grid origin.

Parameters:
  • grid -- The name of a hf_hydrodata grid (e.g. conus1 or conus2).

  • args -- A list of floating pairs of lat,lon values.

Raises:

ValueError -- If x,y point is outside the bounds of the grid.

Example:

import hf_hydrodata as hf

(x, y) = hf.to_xy("conus1", 31.759219, -115.902573)
xy_bounds = hf.to_xy("conus1", *[31.651836, -115.982367, 31.759219, -115.902573])