Skip to content

Commit

Permalink
Codre reive and update HK timeseries in the same ways as QL
Browse files Browse the repository at this point in the history
  • Loading branch information
samaloney committed May 17, 2024
1 parent bb7d703 commit 60298dd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
22 changes: 12 additions & 10 deletions stixpy/timeseries/quicklook.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from astropy.io import fits
from astropy.io.fits import BinTableHDU, Header
from astropy.io.fits.connect import read_table_fits
from astropy.table import QTable, Table
from astropy.table import QTable
from astropy.time.core import Time, TimeDelta
from sunpy.timeseries.timeseriesbase import GenericTimeSeries

Expand Down Expand Up @@ -187,7 +187,7 @@ class QLBackground(GenericTimeSeries):
r"""
Quicklook X-ray time series from the background detector.
Background monitoring is done in such way that counts from background detector are summed in five specified energy
Nominally QL background files contain counts from the background detector summed over five specified energy
ranges. These QL data are double buffered into accumulators of 32bit depth. Maximum rate is approximately 30kHz and
one live time counter is available. Integration time is parameter with default value of 32s
Expand Down Expand Up @@ -335,7 +335,7 @@ def is_datasource_for(cls, **kwargs):
Determines if the file corresponds to a STIX QL LightCurve
`~sunpy.timeseries.TimeSeries`.
"""
# Check if source is explicitly assigned
# Check if a source is explicitly assigned
if "source" in kwargs.keys():
if kwargs.get("source", ""):
return kwargs.get("source", "").lower().startswith(cls._source)
Expand Down Expand Up @@ -496,7 +496,7 @@ def is_datasource_for(cls, **kwargs):
Determines if the file corresponds to a STIX QL LightCurve
`~sunpy.timeseries.TimeSeries`.
"""
# Check if source is explicitly assigned
# Check if a source is explicitly assigned
if "source" in kwargs.keys():
if kwargs.get("source", ""):
return kwargs.get("source", "").lower().startswith(cls._source)
Expand Down Expand Up @@ -596,28 +596,30 @@ def _parse_hdus(cls, hdulist):
The path to the file you want to parse.
"""
header = hdulist[0].header
control = Table(hdulist[1].data)
control = _hdu_to_qtable(hdulist[1])
header["control"] = control
data = Table(hdulist[2].data)
data = _hdu_to_qtable(hdulist[2])

try:
data["time"] = Time(header["date_obs"]) + TimeDelta(data["time"] * u.cs)
data["time"] = Time(header["date_obs"]) + TimeDelta(data["time"])
except KeyError:
data["time"] = Time(header["date-obs"]) + TimeDelta(data["time"] * u.cs)
data["time"] = Time(header["date-obs"]) + TimeDelta(data["time"])

units = OrderedDict((c.info.name, c.unit) for c in data.itercols() if c.info.name != 'time')

data_df = data.to_pandas()
data_df.index = data_df["time"]
data_df.drop(columns="time", inplace=True)

return data_df, header, None
return data_df, header, units

@classmethod
def is_datasource_for(cls, **kwargs):
"""
Determines if the file corresponds to a STIX QL LightCurve
`~sunpy.timeseries.TimeSeries`.
"""
# Check if source is explicitly assigned
# Check if a source is explicitly assigned
if "source" in kwargs.keys():
if kwargs.get("source", ""):
return kwargs.get("source", "").lower().startswith(cls._source)
Expand Down
31 changes: 23 additions & 8 deletions stixpy/timeseries/tests/test_quicklook.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def ql_lightcurve():
)
return ql_lc


@pytest.mark.remote_data
@pytest.fixture()
def ql_background():
Expand All @@ -21,6 +22,7 @@ def ql_background():
)
return ql_bkg


@pytest.mark.remote_data
@pytest.fixture()
def ql_variance():
Expand All @@ -29,11 +31,22 @@ def ql_variance():
)
return ql_var


@pytest.mark.remote_data
@pytest.fixture()
def hk_maxi():
hk_maxi = TimeSeries(
r"https://pub099.cs.technik.fhnw.ch/fits/L1/2020/05/06/HK/solo_L1_stix-hk-maxi_20200506_V02U.fits"
)
return hk_maxi


@pytest.mark.remote_data
def test_ql_lightcurve(ql_lightcurve):
assert isinstance(ql_lightcurve, QLLightCurve)
assert ql_lightcurve.quantity('4-10 keV').unit == u.ct/(u.s * u.keV)


@pytest.mark.remote_data
def test_ql_lightcurve_plot(ql_lightcurve):
ql_lightcurve.plot()
Expand All @@ -52,23 +65,25 @@ def test_ql_background_plot(ql_background):
ql_background.plot(columns=['4-10 keV'])



@pytest.mark.remote_data
def test_qlvariance(ql_variance):
def test_ql_variance(ql_variance):
assert isinstance(ql_variance, QLVariance)
assert ql_variance.quantity('4-20 keV').unit == u.ct / (u.s * u.keV)


@pytest.mark.remote_data
def test_qlvariance_plot(ql_variance):
def test_ql_variance_plot(ql_variance):
ql_variance.plot()
ql_variance.plot(columns=['4-20 keV'])



@pytest.mark.remote_data
def test_hk_maxi():
hk_maxi = TimeSeries(
"https://pub099.cs.technik.fhnw.ch/fits/L1/2020/05/06/HK/solo_L1_stix-hk-maxi_20200506_V02U.fits"
)
def test_hk_maxi(hk_maxi):
assert isinstance(hk_maxi, HKMaxi)
assert hk_maxi.quantity('hk_att_c').unit == u.mA


@pytest.mark.remote_data
def test_hk_maxi_plot(hk_maxi):
hk_maxi.plot()
hk_maxi.plot(columns=['hk_asp_photoa0_v'])

0 comments on commit 60298dd

Please sign in to comment.