Skip to content

Commit c432bd2

Browse files
Merge pull request #929 from yashbhargava1992/add_laxpc_specific_codes
Add AstroSat-LAXPC specific codes
2 parents 60a4e4d + 36e8b96 commit c432bd2

File tree

7 files changed

+55
-1
lines changed

7 files changed

+55
-1
lines changed

docs/changes/929.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added functionality to read LAXPC observations.

stingray/events.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,3 +862,33 @@ def intensity(ev):
862862
starts, stops, (rate, rate_err) = self.analyze_segments(intensity, segment_size)
863863

864864
return starts, stops, rate, rate_err
865+
866+
def get_mask_for_filter_by_detector_id(self, value):
867+
"""Supplies a mask to filter the data for a particular detector(s) for a event file.
868+
For example can be used to filter the data for a single unit of LAXPC or a selected NICER detector ID
869+
870+
871+
Args:
872+
value: The value for which the mask returns 1
873+
"""
874+
if isinstance(value, int):
875+
col = self.detector_id
876+
return col == value
877+
elif isinstance(value, list) and all(isinstance(i, int) for i in value):
878+
col = self.detector_id
879+
full_mask = col == value[0]
880+
for i in range(1, len(value)):
881+
mask = col == value[i]
882+
full_mask = full_mask | mask
883+
return full_mask
884+
885+
def filter_detector_id(self, detector_id, inplace=False):
886+
"""Filters the data selecting only a selected detector or a list of detectors.
887+
888+
Args:
889+
detector_id (int, optional): The detector id on which the filtering needs to be applied. It can be a list.
890+
"""
891+
892+
mask = self.get_mask_for_filter_by_detector_id(detector_id)
893+
new_ev = self.apply_mask(mask, inplace=inplace)
894+
return new_ev

stingray/io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ def _transform_slice_into_events(self, data):
878878
if col == self.detector_key:
879879
continue
880880
if col in data.dtype.names:
881-
setattr(new_ts, col.lower(), data[col])
881+
setattr(new_ts, col.replace(".", "_").lower(), data[col])
882882

883883
for attr in self.meta_attrs():
884884
local_value = getattr(self, attr)

stingray/mission_support/missions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ def _patch_mission_info(info, mission=None):
8585
if mission.lower() == "xte" and "ecol" in info:
8686
info["ecol"] = "PHA"
8787
info["ccol"] = "PCUID"
88+
if mission.lower() == "astrosat": # Check if instrument is part of info dict.
89+
info["ecol"] = "Energy"
90+
info["ccol"] = "LAXPC_No."
91+
info["instkey"] = "INSTRUME"
8892
return info
8993

9094

39.4 KB
Binary file not shown.

stingray/tests/test_events.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,17 @@ def test_event_file_read(self, fname):
268268
fname = os.path.join(datadir, fname)
269269
EventList.read(fname, fmt="hea")
270270

271+
def test_event_file_read_laxpc(self):
272+
"""Test LAXPC file reading"""
273+
fname = os.path.join(datadir, "laxpc_file_read.fits")
274+
with pytest.warns(UserWarning, match="HDU EVENTS"):
275+
with pytest.warns(UserWarning, match="No valid GTI"):
276+
ev = EventList.read(fname, fmt="hea")
277+
assert ev.instr.lower() == "laxpc3"
278+
assert ev.mission.lower() == "astrosat"
279+
assert ((ev.filter_detector_id(detector_id=1)).main_array_length) == 453
280+
assert ((ev.filter_detector_id(detector_id=[1])).main_array_length) == 453
281+
271282
def test_fits_with_additional(self):
272283
"""Test that fits works with a standard event list
273284
file.

stingray/tests/test_io.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,14 @@ def test_event_file_read_chandra_noE(self):
140140
assert hasattr(data, "energy_list")
141141
assert data.energy_list.max() < 18
142142

143+
def test_event_file_read_laxpc(self):
144+
"""Test event file reading."""
145+
fname = os.path.join(datadir, "laxpc_file_read.fits")
146+
with pytest.warns(UserWarning, match="No valid GTI*"):
147+
data = load_events_and_gtis(fname, additional_columns=["Layer"], hduname="event file")
148+
assert data.mission.lower() == "astrosat"
149+
assert read_header_key(fname, "INSTRUME", hdu=0) == "LAXPC3"
150+
143151
def test_event_file_read_no_mission(self):
144152
"""Test event file reading."""
145153
fname = os.path.join(datadir, "nomission.evt")

0 commit comments

Comments
 (0)