Skip to content

Commit 78ba748

Browse files
Merge pull request #168 from StingraySoftware/safe_intv_in_read_events
Introduce safe intervals in read_events
2 parents f75fb50 + c3a88ab commit 78ba748

File tree

8 files changed

+463
-300
lines changed

8 files changed

+463
-300
lines changed

.github/workflows/ci_test.yml

+2
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,5 @@ jobs:
165165
uses: codecov/codecov-action@v3
166166
with:
167167
file: ./coverage.xml
168+
env:
169+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

docs/conf.py

+22-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import os
2929
import sys
3030
from importlib import import_module
31+
import warnings
32+
import subprocess as sp
3133

3234
try:
3335
from sphinx_astropy.conf.v1 import * # noqa
@@ -41,13 +43,18 @@
4143
import tomli as tomllib
4244
from pathlib import Path
4345

46+
warnings.filterwarnings("ignore", message=".*recommended numba.*")
47+
warnings.filterwarnings("ignore", message=".*Using pickle.*")
48+
warnings.filterwarnings("ignore", message=".*PINT is not installed.*")
49+
4450
ON_RTD = os.environ.get("READTHEDOCS") == "True"
4551
ON_TRAVIS = os.environ.get("TRAVIS") == "true"
4652

4753
# Grab minversion from pyproject.toml
4854
with (Path(__file__).parents[1] / "pyproject.toml").open("rb") as f:
4955
pyproject = tomllib.load(f)
5056

57+
5158
# -- General configuration ----------------------------------------------------
5259

5360
# By default, highlight as Python 3.
@@ -203,8 +210,11 @@
203210
if not ON_RTD and not ON_TRAVIS:
204211
# scripts = dict(conf.items("options.entry_points"))["console_scripts"]
205212
scripts = pyproject["project"]["scripts"]
213+
pwarn = os.getenv("PYTHONWARNINGS")
206214

207-
import subprocess as sp
215+
os.environ["PYTHONWARNINGS"] = "ignore"
216+
cols = os.getenv("COLUMNS")
217+
os.environ["COLUMNS"] = "80"
208218

209219
cli_file = os.path.join(os.getcwd(), "scripts", "cli.rst")
210220
if os.path.exists(cli_file):
@@ -213,6 +223,7 @@
213223
print("""======================\n""", file=fobj)
214224

215225
for cl in sorted(scripts.keys()):
226+
print(f"Writing help for {cl}")
216227
if cl.startswith("MP"):
217228
continue
218229
print(cl, file=fobj)
@@ -227,3 +238,13 @@
227238
else:
228239
print(" " + l, file=fobj)
229240
print(file=fobj)
241+
242+
if cols is not None:
243+
os.environ["COLUMNS"] = cols
244+
else:
245+
del os.environ["COLUMNS"]
246+
247+
if pwarn is not None:
248+
os.environ["PYTHONWARNINGS"] = pwarn
249+
else:
250+
del os.environ["PYTHONWARNINGS"]

docs/index.rst

+10
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ satellite (for sure XMM-Newton and RXTE).
4343
What's new
4444
----------
4545

46+
HENDRICS 8.2 (under development)
47+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
48+
49+
+ Brings all bugfixes coming with `Stingray 2.2.4 <https://github.com/StingraySoftware/stingray/releases/tag/v2.2.4>`__
50+
+ New option for ``HENreadevents``: ``--safe-interval``, allowing to decrease GTI length by fixed amounts at the start and the end (useful, e.g., when observations show artifacts entering and exiting from occultation or SAA)
51+
52+
Internal changes:
53+
54+
+ Improvements with docs creation, in particular to the creation of the cli.rst file.
55+
4656
HENDRICS 8.1
4757
~~~~~~~~~~~~
4858

docs/scripts/cli.rst

+384-277
Large diffs are not rendered by default.

hendrics/efsearch.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -77,27 +77,27 @@
7777

7878

7979
__all__ = [
80+
"calculate_shifts",
8081
"check_phase_error_after_casting_to_double",
8182
"decide_binary_parameters",
82-
"folding_orbital_search",
83+
"dyn_folding_search",
8384
"fit",
84-
"calculate_shifts",
85-
"mod",
86-
"shift_and_sum",
87-
"z_n_fast",
88-
"transient_search",
89-
"plot_transient_search",
90-
"search_with_qffa_step",
91-
"search_with_qffa",
92-
"search_with_ffa",
85+
"folding_orbital_search",
9386
"folding_search",
94-
"dyn_folding_search",
87+
"h_test",
88+
"main_accelsearch",
9589
"main_efsearch",
90+
"main_z2vspf",
9691
"main_zsearch",
92+
"mod",
93+
"plot_transient_search",
94+
"search_with_ffa",
95+
"search_with_qffa",
96+
"search_with_qffa_step",
97+
"shift_and_sum",
98+
"transient_search",
9799
"z2_vs_pf",
98-
"main_z2vspf",
99-
"main_accelsearch",
100-
"h_test",
100+
"z_n_fast",
101101
]
102102

103103

hendrics/read_events.py

+24-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import os
55
import warnings
6+
from collections.abc import Iterable
67

78
import numpy as np
89
from stingray.events import EventList
@@ -33,6 +34,7 @@ def treat_event_file(
3334
additional_columns=None,
3435
fill_small_gaps=None,
3536
bin_time_for_occultations=None,
37+
safe_interval=None,
3638
):
3739
"""Read data from an event file, with no external GTI information.
3840
@@ -63,6 +65,9 @@ def treat_event_file(
6365
Create a light curve with this bin time and infer occultations not
6466
recorded in GTIs. The rule is that the flux drops to zero and the average
6567
counts per bin are significantly above 25 ct/s.
68+
safe_interval : float or [float, float]
69+
A safe interval to exclude at both ends (if single float) or the start
70+
and the end (if pair of values) of GTIs.
6671
"""
6772
# gtistring = assign_value_if_none(gtistring, "GTI,GTI0,STDGTI")
6873
log.info(f"Opening {filename}")
@@ -85,9 +90,9 @@ def treat_event_file(
8590
if bin_time_for_occultations is not None and bin_time_for_occultations > 0:
8691
lc = events.to_lc(bin_time_for_occultations)
8792
meanrate = np.median(lc.counts)
88-
8993
if meanrate > 25:
90-
good_gti = create_gti_mask(lc.time, lc.gti)
94+
log.info("Filtering out occultations")
95+
good_gti = create_gti_mask(lc.time, lc.gti, safe_interval=safe_interval)
9196
good = lc.counts > 0
9297
new_bad = (~good) & good_gti
9398
if np.any(new_bad):
@@ -96,8 +101,13 @@ def treat_event_file(
96101
lc.time, (good_gti & good), safe_interval=bin_time_for_occultations
97102
)
98103
events.gti = gti
104+
elif safe_interval is not None:
105+
if not isinstance(safe_interval, Iterable):
106+
safe_interval = [safe_interval, safe_interval]
107+
gti[:, 0] += safe_interval[0]
108+
gti[:, 1] -= safe_interval[1]
99109

100-
lengths = np.array([g1 - g0 for (g0, g1) in gti])
110+
lengths = gti[:, 1] - gti[:, 0]
101111
gti = gti[lengths >= min_length]
102112
events.gti = gti
103113
detector_id = events.detector_id
@@ -150,9 +160,7 @@ def treat_event_file(
150160

151161
good_gti = cross_two_gtis([g], gti)
152162
if noclobber and os.path.exists(outfile_local):
153-
warnings.warn(
154-
f"{outfile_local} exists, " + "and noclobber option used. Skipping"
155-
)
163+
warnings.warn(f"{outfile_local} exists, and noclobber option used. Skipping")
156164
return
157165
good = np.logical_and(events.time >= g[0], events.time < g[1])
158166
all_good = good_det & good
@@ -453,7 +461,7 @@ def main_join(args=None):
453461
import argparse
454462

455463
description = (
456-
"Read a cleaned event files and saves the relevant " "information in a standard format"
464+
"Read a cleaned event files and saves the relevant information in a standard format"
457465
)
458466
parser = argparse.ArgumentParser(description=description)
459467
parser.add_argument("files", help="Files to join", type=str, nargs="+")
@@ -526,7 +534,7 @@ def main(args=None):
526534
from .base import _add_default_args, check_negative_numbers_in_args
527535

528536
description = (
529-
"Read a cleaned event files and saves the relevant " "information in a standard format"
537+
"Read a cleaned event files and saves the relevant information in a standard format"
530538
)
531539
parser = argparse.ArgumentParser(description=description)
532540
parser.add_argument("files", help="List of files", nargs="+")
@@ -586,6 +594,13 @@ def main(args=None):
586594
"XMM)",
587595
default=None,
588596
)
597+
parser.add_argument(
598+
"--safe-interval",
599+
nargs=2,
600+
type=float,
601+
default=0,
602+
help="Interval at start and stop of GTIs used" + " for filtering",
603+
)
589604
parser.add_argument(
590605
"--fill-small-gaps",
591606
type=float,
@@ -623,6 +638,7 @@ def main(args=None):
623638
"fill_small_gaps": args.fill_small_gaps,
624639
"split_by_detector": not args.ignore_detectors,
625640
"bin_time_for_occultations": args.bin_time_for_occultations,
641+
"safe_interval": args.safe_interval,
626642
}
627643

628644
arglist = [[f, argdict] for f in files]

hendrics/tests/test_read_events.py

+3
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,9 @@ def test_load_events_split(self):
371371
"monol_testB_nustar_fpmb_gti000_ev" + HEN_FILE_EXTENSION,
372372
)
373373
assert os.path.exists(new_filename)
374+
with pytest.warns(UserWarning, match=".*exists, and noclobber option"):
375+
read_events.main(command.split() + ["--noclobber"])
376+
374377
command = f"{new_filename}"
375378
lcurve.main(command.split())
376379
new_filename = os.path.join(

pyproject.toml

+4
Original file line numberDiff line numberDiff line change
@@ -481,3 +481,7 @@ ignore-words-list = """
481481
wrap-descriptions = 75
482482
black = true
483483
syntax = "numpy"
484+
485+
486+
[tool.black]
487+
line-length = 100

0 commit comments

Comments
 (0)