Skip to content
This repository was archived by the owner on May 22, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nightshift/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ def get_version() -> str:

version: str = get_version()

from .main import coverage, period_match
from .main import coverage, period_match, coverage_multiple
21 changes: 21 additions & 0 deletions nightshift/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,24 @@ def period_match(t0s, periods, tolerance=0.001):
match = np.count_nonzero(np.abs(phase(t0s, t0s[0], periods)) < tolerance, 0)
best = periods[np.flatnonzero(match == np.max(match))[-1]]
return match, best


def coverage_multiple(t, p):
if p == 0:
print("period = 0")
return 1
else:
ph = ((t + 0.5*p)%p - (0.5*p))
sph_in = np.sort(ph)
sph_out = sph_in[::-1]

sph_in_diff = np.abs(np.diff(sph_in))
sph_out_diff = np.abs(np.diff(sph_out))


df = np.mean(np.diff(t))

spaces_in = np.sort(sph_in[np.hstack([*np.argwhere(sph_in_diff > 4*df).T, len(sph_in)-1])])
spaces_out = np.sort(sph_out[np.hstack([*np.argwhere(sph_out_diff > 4*df).T, len(sph_in)-1])])

return np.sum(spaces_in - spaces_out)/p