Skip to content

gnomonic

fortran_vector_spherical_angle(e1, e2, e3)

The Fortran version Given x/y/z tuples, compute the spherical angle between them according to:

    p3
  /
 /
p_center ---> angle
 \
  \
   p2

This angle will always be less than Pi.

get_area(lon, lat, radius, np)

Given latitude and longitude on cell corners, return the area of each cell.

get_lonlat_vect(lonlat_grid, np)

Calculates the unit vectors pointing in the longitude/latitude directions for a set of longitude/latitude points.

get_rectangle_area(p1, p2, p3, p4, radius, np)

Given four point arrays whose last dimensions are x/y/z in clockwise or counterclockwise order, return an array of spherical rectangle areas.

NOTE: This is not the exact same order of operations as the Fortran code. This results in some errors in the last digit, but the spherical_angle is an exact match. The errors in the last digit multiplied out by the radius end up causing relative errors larger than 1e-14, but still within 1e-12.

get_triangle_area(p1, p2, p3, radius, np)

Given three point arrays whose last dimensions are x/y/z, return an array of spherical triangle areas.

get_unit_vector_direction(p1, p2, np)

Returns the unit vector pointing from a set of lonlat points p1 to lonlat points p2.

great_circle_distance_along_axis(lon, lat, radius, np, axis=0)

Returns the great-circle distance between points along the desired axis.

lon_lat_to_xyz(lon, lat, np)

This function maps (lon, lat) coordinates to (x, y, z) coordinates.

Parameters:

Name Type Description Default
lon

2d array of longitudes

required
lat

2d array of latitudes

required
np

numpy-like module for arrays

required

Returns:

Name Type Description
xyz

3d array whose last dimension is length 3 and indicates x/y/z value

set_c_grid_tile_border_area(xyz_dgrid, xyz_agrid, radius, area_cgrid, tile_partitioner, rank, np)

Using latitude and longitude without halo points, fix C-grid area at tile edges and corners.

Naively, the c-grid area is calculated as the area between the rectangle at the four corners of the grid cell. At tile edges however, this is not accurate, because the area makes a butterfly-like shape as it crosses the tile boundary. Instead we calculate the area on one side of that shape, and multiply it by two. At corners, the corner is composed of three rectangles from each tile bordering the corner. We calculate the area from one tile and multiply it by three.

Parameters:

Name Type Description Default
xyz_dgrid

d-grid cartesian coordinates as a 3-d array, last dimension of length 3 indicating x/y/z

required
xyz_agrid

a-grid cartesian coordinates as a 3-d array, last dimension of length 3 indicating x/y/z

required
area_cgrid

2d array of c-grid areas

required
radius

radius of Earth in metres

required
tile_partitioner

partitioner class to determine subtile position

required
rank

rank of current tile

required
np

numpy-like module to interact with arrays

required

set_corner_area_to_triangle_area(lon, lat, area, tile_partitioner, rank, radius, np)

Given latitude and longitude on cell corners, and an array of cell areas, set the four corner areas to the area of the inner triangle at those corners.

spherical_angle(p_center, p2, p3, np)

Given ndarrays whose last dimension is x/y/z, compute the spherical angle between them according to:

    p3
  /
 /
p_center ---> angle
 \
  \
   p2

This angle will always be less than Pi.

spherical_cos(p_center, p2, p3, np)

As Spherical angle, but returns cos(angle).

xyz_to_lon_lat(xyz, np)

This function maps (x, y, z) coordinates to (lon, lat) coordinates.

Parameters:

Name Type Description Default
xyz

3d array whose last dimension is length 3 and indicates x/y/z value

required
np

numpy-like module for arrays

required

Returns:

Name Type Description
lon

2d array of longitudes

lat

2d array of latitudes