Utilities
- kadlu.utils.DLDL_over_DXDY(lat, lat_deriv_order, lon_deriv_order)[source]
Compute factor for transforming partial derivates in lat-lon to partial derivates in x-y.
- Args:
- lat: float or array
Latitude of the positions(s) where the derivatives are to be evaluated
- lat_deriv_order: int
Order of latitude-derivative
- lon_deriv_order: int
Order of longitude-derivative
- Returns:
- ratio: float or array
Factor for transforming partial derivates in lat-lon to partial derivates in x-y
- kadlu.utils.LLtoXY(lat, lon, lat_ref=0, lon_ref=0, rot=0, grid=False, z=None, squeeze=True)[source]
Transform lat-lon coordinates to xy position coordinates.
By default, the origin of the xy coordinate system is set to 0 deg latitude and 0 deg longitude.
By default, the x-axis is aligned with the longitude axis (west to east) and the y-axis is aligned with the latitude axis (south to north).
- Args:
- lat: float or numpy array
latitude coordinate of a the location(s) of interest in degrees
- lon: float or numpy array
longitude coordinate of a the location(s) of interest in degrees
- lat_ref: float
latitude reference coordinate in degrees
- lon_ref: float
longitude reference coordinate in degrees
- rot: float
Rotation angle in degrees for the xy coordinate system (clockwise rotation).
- squeeze: bool
If output array has length 1, return float instead of array
- Returns:
- x: float or numpy array
x position coordinates in meters
- y: float or numpy array
y positions coordinates in meters
- kadlu.utils.XYtoLL(x, y, lat_ref=0, lon_ref=0, rot=0, grid=False, z=None, squeeze=True)[source]
Transform xy position coordinates to lat-lon coordinates.
By default, the origin of the xy coordinate system is set to 0 deg latitude and 0 deg longitude.
By default, the x-axis is aligned with the longitude axis (west to east) and the y-axis is aligned with the latitude axis (south to north).
- Args:
- x: float or numpy array
x coordinate of a the location(s) of interest in meters
- y: float or numpy array
y coordinate of a the location(s) of interest in meters
- lat_ref: float
latitude reference coordinate in degrees
- lon_ref: float
longitude reference coordinate in degrees
- rot: float
Rotation angle in degrees for the xy coordinate system (clockwise rotation).
- squeeze: bool
If output array has length 1, return float instead of array
- Returns:
- lat: float or numpy array
latitude coordinates in degrees
- lon: float or numpy array
longitude coordinates in degrees
- kadlu.utils.crop(lat, lon, south, north, west, east, grid=False)[source]
Select rectangular region bounded by the geographical coordinates latlon_SW to the south-west and latlon_NE to the north-east.
If grid is False, lat and lon must have the same length.
- Args:
- lat: 1d or 2d numpy array
Latitude values
- lon: 1d or 2d numpy array
Longitude values
- south: float
Southern boundary of the region of interest.
- north: float
Northern boundary of the region of interest.
- west: float
Western boundary of the region of interest.
- east: float
Eastern boundary of the region of interest.
- grid: bool
Specify how to combine elements of lat and lon.
- Returns:
- ind: numpy array
Selected indices. 1d if grid is False, 2d if grid is True.
- lat: numpy array
Latitude values
- lon: numpy array
Longitude values
- kadlu.utils.get_slices(distance, num_slices=1, bins=100, angle=0)[source]
Generate x,y coordinates for equally spaced radial slices originating from (0,0).
- Args:
- distance: float
Length of the radial slice.
- num_slices: int
Number of slices
- bins: int
Number of points per slice
- angle: float
Angle of the first slice relative to the x-axis.
- Returns:
- x,y: list of numpy arrays
x,y coordinate arrays for each slice
- kadlu.utils.interp_grid_1d(y, x=None, num_pts=inf, rel_err=None, method='linear')[source]
Determine the optimal interpolation grid for the function y(x).
The grid will in general not be uniform, as the grid points will be more densily clustered in regions where y(x) is changing more rapidly.
- Args:
- y: 1d numpy array
y values
- x: 1d numpy array
x values. If none are specified, they are assumed to be 0,1,2,…
- num_pts: int
Number of grid points. If rel_err is specified, num_pts becomes the maximum possible number of grid points.
- rel_err: float
Maximum deviation between the interpolation and y, relative to the range of values spanned by y.
- method: str
Interpolation method
- Returns:
- a: 1d numpy array
Indices of the grid points
- e: float
Maximum relative error
- kadlu.utils.load_data_from_file(path, val_name='bathy', lat_name='lat', lon_name='lon', lon_axis=1, south=-90, north=90, west=-180, east=180)[source]
Load geospatial data from a single file.
Currently supported formats are NetCDF (.nc) and MatLab (.mat).
The data can be cropped by speciyfing south/north/west/east boundaries.
- Args:
- path: str
File path
- val_name: str
Name of variable/field containing the data values
- lat_name: str
Name of variable/field containing the latitude values
- lon_name: str
Name of variable/field containing the longitude values
- lon_axis: int
Specify if the longitude dimension is the second (1, default) or first (0) axis.
- south: float
Southern boundary of the region of interest.
- north: float
Northern boundary of the region of interest.
- west: float
Western boundary of the region of interest.
- east: float
Eastern boundary of the region of interest.
- Returns:
- val: 1d or 2d numpy array
Data values
- lat: numpy array
Latitude values
- lon: numpy array
Longitude values
- kadlu.utils.torad(lat, lon)[source]
Convert latitute and longitude values from degrees to radians.
The method expects the latitude to be in the range (-90,90) and the longitude to be in the range (-180,180).
The output latitude is in the range (0,pi) and the output longitude is in the range (-pi,pi).
- Args:
- lat: float or array
latitude(s) in degrees from -90 to +90.
- lon: float or array
longitude(s) in degrees from -180 to +180.
- Returns:
- lat_rad: float or array
latitude(s) in radians from 0 to pi.
- lon_rad: float or array
longitude(s) in radians from -pi to pi.