Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fold_events keyword validation #837

Merged
merged 16 commits into from
Sep 19, 2024
22 changes: 14 additions & 8 deletions stingray/pulse/pulsar.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@

"""

ph0 = _default_value_if_no_key(opts, "ph0", 0)
to_1 = _default_value_if_no_key(opts, "to_1", True)
ph0 = dict.pop(opts, "ph0", 0)
to_1 = dict.pop(opts, "to_1", True)
ph = ph0

for i_f, f in enumerate(frequency_derivatives):
Expand Down Expand Up @@ -263,18 +263,24 @@
profile_err : array of floats
The uncertainties on the pulse profile
"""
mode = _default_value_if_no_key(opts, "mode", "ef")
nbin = _default_value_if_no_key(opts, "nbin", 16)
weights = _default_value_if_no_key(opts, "weights", 1)

mode = dict.pop(opts, "mode", "ef")
nbin = dict.pop(opts, "nbin", 16)
weights = dict.pop(opts, "weights", 1)
# If no key is passed, *or gti is None*, defaults to the
# initial and final event
gti = _default_value_if_no_key(opts, "gti", None)
gti = dict.pop(opts, "gti", None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, sorry, I think you can just use opts.pop("gti", None)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made the changes

if gti is None:
gti = [[times[0], times[-1]]]
# Be safe if gtis are a list
gti = np.asanyarray(gti)
ref_time = _default_value_if_no_key(opts, "ref_time", 0)
expocorr = _default_value_if_no_key(opts, "expocorr", False)
ref_time = dict.pop(opts, "ref_time", 0)
expocorr = dict.pop(opts, "expocorr", False)

if opts:
raise ValueError(

Check warning on line 281 in stingray/pulse/pulsar.py

View check run for this annotation

Codecov / codecov/patch

stingray/pulse/pulsar.py#L281

Added line #L281 was not covered by tests
f"Unidentified keys: {opts.keys()} \n Please refer to the description of the function for optional parameters."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unidentified keyword to fold_events: {opts.keys()} etc. would probably be more informative

)

if not isinstance(weights, Iterable):
weights *= np.ones(len(times))
Expand Down
Loading