Commit 905b12bc authored by Eva Börgens's avatar Eva Börgens
Browse files

update docstrings

parent e6ff1511
......@@ -7,20 +7,23 @@ from typing import Dict
import scipy.special as sp
import numpy as np
import numpy.typing as npt
rho = np.pi/180
R = 6367.4447
def get_grid_area(lon: npt.ArrayLike, lat: npt.ArrayLike) -> np.ndarray:
def get_grid_area(lon : np.ndarray, lat : np.ndarray) -> np.ndarray:
""""
Function getting the area weights of a coordinate list
Arg:
lon, array of longitudes: np.ndarray
lat, array of latitudes: np.ndarray
Parameters:
lon : np.ndarray
array of longitudes
lat : np.ndarray
array of latitudes
Returns:
area per grid point
np.ndarray
area per grid point
"""
area = np.zeros(len(lat))
delta_lon = np.abs(np.unique(lon)[1]-np.unique(lon)[0])
......@@ -34,13 +37,20 @@ def get_grid_area(lon: npt.ArrayLike, lat: npt.ArrayLike) -> np.ndarray:
def get_area(lon_ll: float, lat_ll: float, lon_ur: float,lat_ur: float) -> float:
""""
returns area of rectangular on sphere, defined by corner points lower left ll and upper right ur
Arg:
lon_ll, lon of lower left corner: float
lat_ll, lat of lower left corner: float
lon_ur, lon of upper right corner: float
lat_ur, lat of upper right corner: float
Parameters:
lon_ll: float
lon of lower left corner
lat_ll: float
lat of lower left corner
lon_ur: float
lon of upper right corner
lat_ur: float
lat of upper right corner
Returns:
area per grid point
float
area of grid point
"""
area = np.abs((lon_ll-lon_ur)*rho)*np.abs((np.sin(lat_ll*rho)-np.sin(lat_ur*rho)))*R**2
return area
......@@ -56,19 +66,31 @@ def cov_function_lat(lat1: float, lat2: float,
""""
Function to compute covariance function between two points according to
publication Boergens et al. 2020
Arg:
lat1, lat2, Latitude of the two points: float
d, distance between points: float
theta, azimuth angle between points: float
ny, order of Bessle function: float
a0, anisotropy parameter: float
ka0_2, ka0_4, ka0_6, ka0_8, Legende polynome parameters for a0: float
a1, isotropy shape parameter: float
ka1_2, ka1_4, ka1_6, ka1_8, Legende polynome parameters for a1: float
c0, amplitude parameter: float
k2,k4, k6, k8, Legende polynome parameters for c0: float
Parameters:
lat1, lat2: float
Latitude of the two points
d: float
distance between points
theta: float
azimuth angle between points
ny: float
order of Bessle function
a0: float
anisotropy parameter
ka0_2, ka0_4, ka0_6, ka0_8: float
Legende polynome parameters for a0
a1: float
isotropy shape parameter
ka1_2, ka1_4, ka1_6, ka1_8: float
Legende polynome parameters for a1
c0: float
amplitude parameter
k2,k4, k6, k8: float
Legende polynome parameters for c0
Returns:
Covariance: float
float
Covariance
"""
k = [1, 0, k_2, 0, k_4, 0, k_6, 0, k_8]
......@@ -93,25 +115,36 @@ def cov_function_lat(lat1: float, lat2: float,
return Cov
def legendre_polynome(n: int, lat: float) -> float:
'''
"""
Computes Legendre Polynome of degree n at given latitude lat
:param n: int
:param lat: float
:return: float
'''
Parameters:
n: int
lat: float
Returns:
float
"""
sin_lat = np.sin(lat)
P_n = sp.legendre(n)
P_n_x = P_n(sin_lat)
return P_n_x
def sum_legendre(n_max: int, leg_weights: npt.ArrayLike, lat:float) -> float:
'''
def sum_legendre(n_max: int, leg_weights: np.ndarray, lat:float) -> float:
"""
Computes weighted sum of Legendre Polynomes
:param n_max: maximum degree of Legendre Polynomes: int
:param leg_weights: arrays of the weights for the sum: np.ndarray
:param lat: latitude where the Legendre Polynomes are summed: float
:return:
'''
Parameters:
n_max: int
maximum degree of Legendre Polynomes
leg_weights: np.ndarray
arrays of the weights for the sum
lat: float
latitude where the Legendre Polynomes are summed
Returns:
float
"""
if n_max!=len(leg_weights)-1:
raise('N_max coefficients are needed ')
p_sum = 0
......@@ -125,31 +158,49 @@ def yaglom(dist: float,
a_1: float,
c_0: float,
ny: float) -> float:
'''
"""
Function to compute the adapted Yaglom function
:param dist: spherical distance: float
:param theta: azimut angel: float
:param a_0: anisotropic width parameter: float
:param a_1: isotropic width parameter: float
:param c_0: global scaling factor: float
:param ny: Order of Bessel function: int
:return: float
'''
Parameters:
dist: float
spherical distance
theta: float
azimut angel
a_0: float
anisotropic width parameter
a_1: float
isotropic width parameter
c_0: float
global scaling factor
ny: int
Order of Bessel function
Returns:
float
"""
alpha = a_0 * np.sin(theta) + a_1
cov = c_0 / (alpha * dist) ** ny * sp.jv(ny, alpha * dist)
return cov
def distance(lon_0: float, lat_0: float, lon_1: float, lat_1: float):
'''
"""
convert geograpic coordinates to spherical distances
:param lon_0[degree]: float
:param lat_0[degree]: float
:param lon_1[degree]: float
:param lat_1[degree]: float
:return: float
'''
Parameters:
lon_0: float
[degree]
lat_0: float
[degree]
lon_1: float
[degree]
lat_1: float
[degree]
Returns:
float
"""
lon_1_rad = lon_1 * rho
lat_1_rad = lat_1 * rho
......@@ -171,14 +222,22 @@ def distance(lon_0: float, lat_0: float, lon_1: float, lat_1: float):
return d_i
def azimut_angle(lon_0: float, lat_0: float, lon_1: float, lat_1: float):
'''
"""
get azimut angle between geograpic coordinates
:param lon_0[degree]: float
:param lat_0[degree]: float
:param lon_1[degree]: float
:param lat_1[degree]: float
:return: float
'''
Parameters:
lon_0: float
[degree]
lat_0: float
[degree]
lon_1: float
[degree]
lat_1: float
[degree]
Returns:
float
"""
lat_1_rad = lat_1 * rho
lat_0_rad = lat_0 * rho
......@@ -199,17 +258,25 @@ def azimut_angle(lon_0: float, lat_0: float, lon_1: float, lat_1: float):
alpha = np.pi
return alpha
def compute_covariance(region_coords: npt.ArrayLike,
gridstd: npt.ArrayLike,
def compute_covariance(region_coords: np.ndarray,
gridstd: np.ndarray,
flag_uncertainty: bool, flag_matrix: bool) -> Dict[str, np.ndarray]:
'''
"""
Function to compute the covariances for a region
:param region_coords: coordinates of region: np.ndarray[n,2]
:param gridstd: standard deviation for each grid point: np.ndarray[n]
:param flag_uncertainty: return uncertainty of mean tws of region: bool
:param flag_matrix: return covariance matrix of region: bool
:return: Dict[str, np.ndarray]
'''
Parameters:
region_coords: np.ndarray
coordinates of region, size [n,2]
gridstd: np.ndarray
standard deviation for each grid point, size[n]
flag_uncertainty: bool
flag, return uncertainty of mean tws of region
flag_matrix: bool
flag, return covariance matrix of region
Returns:
Dict[str, np.ndarray]
"""
lon = np.array([r[0] for r in region_coords])
lat = np.array([r[1] for r in region_coords])
......@@ -277,14 +344,23 @@ def compute_covariance(region_coords: npt.ArrayLike,
def get_timeseries(grid, lon_grid, lat_grid, region_coords):
'''
"""
Returns mean tws time series of region
:param grid: tws grid: np.ndarray[t,n,m]
:param lon_grid: longitude of grid: np.ndarray[m]
:param lat_grid: latitude of grid: np.ndarray[n]
:param region_coords: coordinates of region of interest: np.ndarray[l,2]
:return: np.ndarray[t]
'''
Parameters:
grid: np.ndarray
tws grid, size [t,n,m]
lon_grid: np.ndarray
longitude of grid, size [m]
lat_grid: np.ndarray
latitude of grid, size [n]
region_coords: np.ndarray
coordinates of region of interest, size [l,2]
Returns:
np.ndarray
size [t]
"""
lon_region = np.array([r[0] for r in region_coords])
lat_region = np.array([r[1] for r in region_coords])
......
......@@ -6,10 +6,10 @@ from argparse import ArgumentParser, FileType, RawTextHelpFormatter
from io import test_coordiantes
def arg_parser():
'''
"""
Argument parser of input line
:return: ArgumentParser.arguments
'''
"""
parser = ArgumentParser(
prog="tws_covariances.sh",
......
......@@ -13,11 +13,13 @@ import numpy.typing as npt
def read_netcdf(filename: str) -> Dict[str, np.ndarray]:
""""
Reads a TWS netcdf file as provided from GraVIS
Arg:
Reads a TWS netcdf file as provided from GravIS
Parameters:
filename: string
Returns:
dict with string as keys and numpy arrays as arguments
Dict[str, np.ndarray]
"""
try:
with netCDF4.Dataset(filename, 'r') as data:
......@@ -37,10 +39,12 @@ def read_netcdf(filename: str) -> Dict[str, np.ndarray]:
def read_ascii(filename: str) -> np.ndarray:
""""
Reads an Ascii file with coordinates
Arg:
Parameters:
filename: string
Returns:
numpy array
np.array
"""
try:
with open(filename) as fid:
......@@ -59,9 +63,9 @@ def read_ascii(filename: str) -> np.ndarray:
def test_coordiantes(filename: str):
""""
Tests if more than 2 coordinates are given in the file
Arg:
filename: string
Parameters:
filename: string
"""
coords = read_ascii(filename)
......@@ -82,7 +86,8 @@ def test_coordiantes(filename: str):
def same_dist_elems(arr: npt.ArrayLike) -> bool:
""""
Tests if coordinates are evenly spaced
Arg:
Parameters:
arr: numpy array
"""
diff = arr[1] - arr[0]
......@@ -101,7 +106,8 @@ def save_results(outname: str,
flag_timeseries: bool):
""""
Saving the results of the regional tws uncerty tools to a NetCDF file
Arg:
Parameters:
outname: str
inname: str
results: Dict[str, np.ndarray]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment