cgeniepy.grid#
Classes#
A set of operations on grid/coordinate data |
|
A univeral ineteprolator for cgeniepy that |
Module Contents#
- class cgeniepy.grid.GridOperation#
A set of operations on grid/coordinate data
- get_genie_lon(N=36, edge=False, offset_start=-260)#
get GENIE longitude in 10 degree resolution, if edge is False, then return midpoint
- Parameters:
N – number of grid points
edge – if True, return edge points
offset_start – the par_grid_lon_offset option in main configuration file
- get_genie_lat(N=36, edge=False)#
return cGENIE latitude in log-sine normally degree resolution, if edge is False, then return midpoint
- get_genie_depth(N=16, edge=False, max_depth=5000)#
calculate cGENIE vertical depth :param N: number of grid points :param edge: if True, return edge points, otherwise return midpoints
- get_normal_lon(N=36, edge=False)#
Normal longitude in 10 degree resolution (default), if edge is False, then return midpoint
- lon_n2g(x, grid_lon_offset=-260)#
Convert normal longitude (-180, 180) to GENIE longitude (-270, 90)
- Parameters:
x – normal longitude
- Returns:
GENIE longitude
- lon_g2n(x)#
Convert GENIE longitude to normal longitude. This is independent on the grid_offset_start option
- Parameters:
x – GENIE longitude
- Returns:
normal longitude
- lon_e2n(x)#
Convert eastern longitude to normal longitude
- Parameters:
x – longitude in eastern degree
- Returns:
normal longitude
- lon_n2e(x)#
Convert normal longitude (-180, 180) to longitude east(0,360)
- Parameters:
x – normal longitude
- Returns:
longitude in eastern degree
- xr_n2g(data: xarray.Dataset, longitude='lon', *args, **kwargs) xarray.Dataset#
Apply longitude conversion method n2g for the input data (normal to GENIE)
- Parameters:
data – input data
longitude – longitude coordinate name
- Returns:
xr.Dataset
- xr_g2n(data: xarray.Dataset, longitude='lon', *args, **kwargs) xarray.Dataset#
Apply longitude conversion method g2n for the input data (GENIE to normal)
- Parameters:
data – input data
longitude – longitude coordinate name
- Returns:
xr.Dataset
- xr_e2n(data: xarray.Dataset, longitude='lon', *args, **kwargs) xarray.Dataset#
Apply longitude conversion method e2n for the input data (eastern to normal)
- Parameters:
data – input data
longitude – longitude coordinate name
- Returns:
xr.Dataset
- xr_n2e(data: xarray.Dataset, longitude='lon', *args, **kwargs) xarray.Dataset#
Apply longitude conversion method n2e for the input data (normal to eastern)
- Parameters:
data – input data
longitude – longitude coordinate name
- Returns:
xr.Dataset
- mask_Arctic_Med(array, policy='na')#
mask Arctic and Meditterean Sea in cGENIE modern continent configuration
- Parameters:
array – 36x36 GENIE array
- GENIE_grid_mask(base='worjh2', basin='ALL', subbasin='', invert=False)#
Get a modern GENIE 36x36 mask array from input data. The input array is flipped (left/right flip -> up/down flip) for easy recognition
- Continent:
worjh2, worlg4, worbe2, GIteiiaa, GIteiiaa, p0055c
- Basin:
Atlantic/Pacific/Indian/ALL/Tanzania
- Subbasin:
N/S/ALL, ALL means Southern Ocean section included
- Returns:
GENIE grid array where continent/ice cap is 0 and ocean is 1, default is ‘worjh2’
- geniebin_lat(x, *args, **kwargs)#
Categorize <latitude> into cGENIE grid bins
- geniebin_lon(x, *args, **kwargs)#
Categorize <longitude> into cGENIE grid bins
- geniebin_depth(x, *args, **kwargs)#
Categorize <depth> into cGENIE grid bins
- normbin_lon(x, *args, **kwargs)#
Categorize <longitude> into normal grid bins
- haversine_distance(lat1, lon1, lat2, lon2)#
Calculate the Haversine distance between corresponding pairs of points.
- Parameters:
lat1 – Array of latitudes for points 1
lon1 – Array of longitudes for points 1
lat2 – Array of latitudes for points 2
lon2 – Array of longitudes for points 2
- Returns:
Array of distances between corresponding pairs of points
- geo_dis3d(point1, points2)#
Calculate the 3D geographical distance between point1 and multiple points2.
- Parameters:
point1 – Tuple/list of coordinates (z, lat, lon) or (lat, lon)
points2 – Numpy Array of shape (n, 3) containing coordinates (z, lat, lon) of points
- Returns:
Array of distances between point1 and each point in points2
- geo_dis2d(point1, points2)#
Calculate the 2D geographical distance between point1 and multiple points2.
- Parameters:
point1 – Tuple/list of coordinates (z, lon, lat) or (lon, lat)
points2 – Array of shape (n, 3) containing coordinates (z, lon, lat) of points
- Returns:
Array of distances between point1 and each point in points2
- static check_dimension(input)#
check the presence of latitude, longitude, depth, and time in the input tuple
- Parameters:
input – tuple of dimension names
- Returns:
tuple of boolean values indicating the presence of latitude, longitude, depth, and time
Example#
>>> input = ('lat', 'lon', 'depth', 'time') >>> check_dimension(input) (True, True, True, True)
- dim_order(input)#
Determine the order of dimensions in the input data array
- Returns:
tuple of index in the input data
Example#
>>> input = ('lat', 'lon', 'depth') >>> dim_order(input) ## always follow time, depth, lat, lon (2, 0, 1)
- static set_coordinates(obj, index)#
Set the coordinates of the input object based on the input index
- Parameters:
obj – object to set coordinates
index – tuple of dimension names
- class cgeniepy.grid.Interpolator(dims, coordinates, values, grid_number=200, method='r-linear')#
A univeral ineteprolator for cgeniepy that can be used to interpolate data for both regular and irregular grid
- dims#
- coords#
- values#
- grid_number = 200#
- gridded_coord = []#
- meshgrid#
- interp_function#
- gridded_data#
- new_coordinate(n)#
create new coordinates for regridding
- Parameters:
n – the resolution of the new grid
- Returns:
a list of new coordinates
- new_meshgrid(*args, **kwargs)#
create meshgrid for regridding
- Returns:
numpy meshgrid
- interpolate_data(*args, **kwargs)#
Use the interpolation function to get regridded values
- Returns:
regridded data array
- to_xarray()#
Combine the regridded data with the new coordinates to create a xarray DataArray
- Returns:
xarray DataArray
- to_dataframe()#
Convert the regridded data to a pandas DataFrame
- Returns:
pandas DataFrame