Skip to content

Commit 51e40e7

Browse files
author
Sarah Wagner
committed
stylistic improvements
1 parent 3cd9036 commit 51e40e7

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ extend-select = [
7878
"UP", # pyupgrade
7979
"YTT", # flake8-2020
8080
]
81+
extend-ignore = ["T201"] #make ruff ignore that there are print statements (bc notebooks use them)
8182
ignore = [
8283
"PLR09", # Too many <...>
8384
"PLR2004", # Magic value used in comparison

src/lightcurves/HopFinder.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ def clean(self, peaks, starts, ends, lc):
9090
if len(peaks) < 1:
9191
logging.info("not variable enough, no peak found")
9292
return (None, None, None)
93-
if self.lc_edges == "neglect":
94-
if len(starts) < 1 or len(ends) < 1:
93+
if self.lc_edges == "neglect" and (len(starts) < 1 or len(ends) < 1):
9594
logging.info("not variable enough, missing start or end")
9695
return (None, None, None)
9796
if self.lc_edges == "add":
@@ -177,7 +176,7 @@ def clean_multi_peaks(self, peaks, starts, ends, lc):
177176
>= lc.block_val[lc.bb_i(peaks[x + 1])]
178177
):
179178
peaks = np.delete(peaks, x + 1)
180-
logging.info("neglected double peak in HOP " + str(x))
179+
logging.info(f"neglected double peak in HOP {x}")
181180
break
182181
return peaks, starts, ends
183182

@@ -199,8 +198,7 @@ def find_peaks(self, lc):
199198
peaks = [] # time of all local peaks over baseline (in units of edges = units of time)
200199
for i in range(1, len(diff)):
201200
# if previous rising; this falling
202-
if diff[i - 1] > 0 and diff[i] < 0:
203-
if lc.block_val[i] > lc.baseline:
201+
if (diff[i - 1] > 0 and diff[i] < 0) and (lc.block_val[i] > lc.baseline):
204202
# peak_time = middle of peak block
205203
peaks.append(lc.edges[i] + (lc.edges[i + 1] - lc.edges[i]) / 2)
206204
return peaks

src/lightcurves/LC.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
import numpy as np
99
from matplotlib import pyplot as plt
1010
from matplotlib.axes import Axes # for type hints only
11+
from pathlib import Path
12+
1113

1214
# https://docs.astropy.org/en/stable/api/astropy.stats.bayesian_blocks.html
13-
from lightcurves.HopFinder import *
15+
import lightcurves.HopFinder as hf
1416

1517
logging.basicConfig(level=logging.ERROR)
1618
"""
@@ -23,29 +25,32 @@
2325
"""
2426

2527

26-
def load_lc(path: str) -> LightCurve:
28+
def load_lc(path: str | Path) -> LightCurve:
2729
"""
2830
Load a pickled LightCurve instance from a file created with `save_lc()`.
2931
3032
WARNING
3133
-------
3234
Uses pickle. Loaded instance reflects the class at save-time.
3335
"""
34-
with open(path, "rb") as f:
36+
path = Path(path)
37+
with path.open("rb") as f:
3538
return pickle.load(f)
3639

37-
38-
def load_lc_npy(path: str) -> LightCurve:
40+
'''
41+
this following is exactly like the previous one.. might not be necessary
42+
def load_lc_npy(path: str | Path) -> LightCurve:
3943
"""
4044
Load pickled LightCurve instance from numpy array created with `save_lc()`.
4145
4246
WARNING
4347
-------
4448
Uses pickle. Loaded instance reflects the class at save-time.
4549
"""
46-
with open(path, "rb") as f:
50+
path = Path(path)
51+
with path.open("rb") as f:
4752
return pickle.load(f)
48-
53+
'''
4954

5055
def load_lc_csv(path: str) -> LightCurve:
5156
"""
@@ -89,7 +94,7 @@ def flux_puffer(
8994
Associated uncertainties, modified analogously.
9095
"""
9196
flux_new = np.where(flux > threshold, flux, threshold)
92-
flux_error_new = np.where(flux > threshold, flux_error, th_error)
97+
flux_error_new = np.where(flux > threshold, flux_error, threshold_error)
9398
return (flux_new, flux_error_new)
9499

95100

@@ -979,13 +984,13 @@ def find_hop(
979984
self.baseline = np.mean(self.flux)
980985
else:
981986
self.baseline = baseline
982-
hopfinder = HopFinderBaseline(lc_edges)
987+
hopfinder = hf.HopFinderBaseline(lc_edges)
983988
if method == "half":
984-
hopfinder = HopFinderHalf(lc_edges)
989+
hopfinder = hf.HopFinderHalf(lc_edges)
985990
if method == "sharp":
986-
hopfinder = HopFinderSharp(lc_edges)
991+
hopfinder = hf.HopFinderSharp(lc_edges)
987992
if method == "flip":
988-
hopfinder = HopFinderFlip(lc_edges)
993+
hopfinder = hf.HopFinderFlip(lc_edges)
989994
self.hops = hopfinder.find(self)
990995
return self.hops
991996

0 commit comments

Comments
 (0)