Skip to content

Commit

Permalink
fixed docstrings; replaced pkg_resourses with importlib.resourses
Browse files Browse the repository at this point in the history
  • Loading branch information
huangziwei committed Apr 24, 2023
1 parent 7a9d5d6 commit b41aab8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
17 changes: 6 additions & 11 deletions pycircstat2/descriptive.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def circ_r(
alpha: np.ndarray,
w: Union[np.ndarray, None] = None,
return_intermediates=False,
) -> tuple:
) -> Union[tuple, float]:
"""
Circular mean resultant vector length (r).
Expand All @@ -25,8 +25,6 @@ def circ_r(
Returns
-------
m: float or NaN
Circular mean
r: float
Resultant vector length
Cbar: float
Expand Down Expand Up @@ -59,7 +57,7 @@ def circ_mean(
alpha: np.ndarray,
w: Union[np.ndarray, None] = None,
return_r: bool = False,
) -> tuple:
) -> Union[tuple, float]:
"""
Circular mean (m) and resultant vector length (r).
Expand Down Expand Up @@ -172,7 +170,6 @@ def circ_dispersion(
alpha: np.ndarray,
w: Union[np.ndarray, None] = None,
mean=None,
centered=False,
) -> float:
r"""
Sample Circular Dispersion, defined by Fisher eq(2.28):
Expand Down Expand Up @@ -203,8 +200,8 @@ def circ_dispersion(
if w is None:
w = np.ones_like(alpha)

r1 = circ_moment(alpha=alpha, w=w, p=1, mean=mean, centered=centered)[1] # eq(2.26)
r2 = circ_moment(alpha=alpha, w=w, p=2, mean=mean, centered=centered)[1] # eq(2.27)
r1 = circ_moment(alpha=alpha, w=w, p=1, mean=mean, centered=False)[1] # eq(2.26)
r2 = circ_moment(alpha=alpha, w=w, p=2, mean=mean, centered=False)[1] # eq(2.27)

dispersion = (1 - r2) / (2 * r1**2) # eq(2.28)

Expand Down Expand Up @@ -239,8 +236,7 @@ def circ_skewness(alpha: np.ndarray, w: Union[np.ndarray, None] = None) -> float
if w is None:
w = np.ones_like(alpha)

u1, r1 = circ_mean(alpha=alpha, w=w, return_r=True)

u1, r1 = circ_moment(alpha=alpha, w=w, p=1, mean=None, centered=False)
u2, r2 = circ_moment(alpha=alpha, w=w, p=2, mean=None, centered=False) # eq(2.27)

skewness = (r2 * np.sin(u2 - 2 * u1)) / (1 - r1) ** 1.5
Expand Down Expand Up @@ -276,8 +272,7 @@ def circ_kurtosis(alpha: np.ndarray, w: Union[np.ndarray, None] = None) -> float
if w is None:
w = np.ones_like(alpha)

u1, r1 = circ_mean(alpha=alpha, w=w, return_r=True)

u1, r1 = circ_moment(alpha=alpha, w=w, p=1, mean=None, centered=False)
u2, r2 = circ_moment(alpha=alpha, w=w, p=2, mean=None, centered=False) # eq(2.27)

kurtosis = (r2 * np.cos(u2 - 2 * u1) - r1**4) / (1 - r1) ** 2
Expand Down
10 changes: 4 additions & 6 deletions pycircstat2/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import json
from importlib import resources as importlib_resources
from typing import Union

import numpy as np
import pandas as pd
import pkg_resources


def data2rad(
Expand Down Expand Up @@ -97,13 +97,11 @@ def load_data(
)

# load data
csv_path = pkg_resources.resource_filename(__name__, f"data/{source}/{name}.csv")
data_files = importlib_resources.files("pycircstat2")
csv_path = data_files / f"data/{source}/{name}.csv"
csv_data = pd.read_csv(csv_path, index_col=0)

# load meta data
json_path = pkg_resources.resource_filename(
__name__, f"data/{source}/{name}.csv-metadata.json"
)
json_path = data_files / f"data/{source}/{name}.csv-metadata.json"
with open(json_path) as f:
json_data = json.load(f)

Expand Down

0 comments on commit b41aab8

Please sign in to comment.