Commit 5c88691c authored by Paulo Medeiros's avatar Paulo Medeiros
Browse files

Lint metrics.py docstrings.

parent 6ee96ff0
......@@ -41,7 +41,7 @@ def get_obs_norm_factors(obs_values):
(abs(obs_mean) > 1e-5 and abs(stdev / obs_mean) < 1e-5)
or abs(obs_mean) <= 1e-5
and stdev < 1e-7
):
): # pylint: disable=chained-comparison
rtn = 0.0
else:
rtn = 1.0 / stdev
......@@ -50,7 +50,20 @@ def get_obs_norm_factors(obs_values):
@njit("f4[:](f8[:, :], f8[:])", parallel=True, cache=True)
def calc_distance_matrix_numba(df, weights):
"""Calculate distance matrix using python+numba."""
"""Calculate distance matrix using python+numba.
Args:
df (numpy.ndarray): Multidimensional numpy array containing the data
entries, obtained from a pandas dataframe (numba doesn't work with
pandas datafames).
weights (numpy.array): Weights chosen for each observation parameter.
The weigts determine the relative importance of the observation
parameters w.r.t. each other.
Returns:
numpy.ndarray: Distance matrix.
"""
nrows, ncols = df.shape
# Get normalisation factors so that observations in different
......@@ -86,7 +99,7 @@ def calc_distance_matrix_numba(df, weights):
# Strangely, the results are correct without initialisation when using
# python 3.6 or when setting parallel=False.
i, j = np.zeros(2, dtype=np.int64)
for idist in prange(n_dists):
for idist in prange(n_dists): # pylint: disable=not-an-iterable
i, j = _data_index_to_matrix_index(nrows, idist, check_bounds=False)
rtn[idist] = weights_internal[0] * haversine_distance(
df[i], df[j]
......@@ -98,7 +111,24 @@ def calc_distance_matrix_numba(df, weights):
def calc_distance_matrix(df, weights, optimize_mode, num_threads=-1):
"""Calculate distance matrix between obs in dataframe df."""
"""Calculate distance matrix between obs in dataframe df.
Args:
df (pandas.Dataframe): Input data.
weights (numpy.array): Weights chosen for each observation parameter.
The weigts determine the relative importance of the observation
parameters w.r.t. each other.
optimize_mode: How the distance matrix is to be calculated and stored.
This is passed onto the constructor for the class
netatmoqc.hollow_symmetric_matrix.HollowSymmetricMatrix.
num_threads: Max number of threads used for the computation.
(Default value = -1)
Returns:
netatmoqc.hollow_symmetric_matrix.HollowSymmetricMatrix: The distance
matrix.
"""
logger.debug(" > Calculating distance matrix...")
tstart = time.time()
......
Supports Markdown
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