Skip to content

Commit

Permalink
updated SkymapFactory with np.uint16
Browse files Browse the repository at this point in the history
starting to work with HermesData in
conda env add_eea
  • Loading branch information
rstrub committed Nov 28, 2023
1 parent b67744e commit 638e6fd
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 10 deletions.
14 changes: 7 additions & 7 deletions hermes_eea/SkymapFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def SkymapFactory(l0_cdf,energies,deflections,myEEA):
epochs = ccsds_to_cdf_time.helpConvertEEA(l0_cdf)
try:
#for ptr in range(0,len(beginning_packets)):
for ptr in range(0, 7000):
for ptr in range(0, 2000):
#skymap = np.zeros((beginning_packets[ptr+1]-beginning_packets[ptr],32))
package.append((
l0_cdf['STEP'][beginning_packets[ptr]:beginning_packets[ptr+1]],
Expand Down Expand Up @@ -64,13 +64,13 @@ def do_eea_packet( stepperTableCounter,
# skymap is already full of zeros, why do it again?
# skymap = np.zeros((beginning_packets[ptr+1]-beginning_packets[ptr],32))
skymaps = []
pulse_a = np.zeros((41,4))
pulse_b = np.zeros((41,4))
counter1 = np.zeros((41,4))
counter2 = np.zeros((41,4))
µepoch = np.zeros((41,4))
pulse_a = np.zeros((41,4), dtype=np.uint16)
pulse_b = np.zeros((41,4), dtype=np.uint16)
counter1 = np.zeros((41,4), dtype=np.uint16)
counter2 = np.zeros((41,4), dtype=np.uint16)
µepoch = np.zeros((41,4), dtype=np.uint16)

skymap = np.zeros((41, 4, 32))
skymap = np.zeros((41, 4, 32), dtype=np.uint16)

for row in stepperTableCounter:
dim0 = energies[row]
Expand Down
70 changes: 67 additions & 3 deletions hermes_eea/calibration/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
from hermes_eea.io.EEA import EEA
from hermes_eea.SkymapFactory import SkymapFactory
from hermes_eea.Global_Attrs_Cnts import Global_Attrs
from hermes_eea.util.time.iso_epoch import epoch_to_iso_obj, epoch_to_iso
from hermes_eea.util.time.iso_epoch import epoch_to_iso_obj, epoch_to_eea_iso, epoch_to_iso
import astropy.units as u
from astropy.timeseries import TimeSeries
from astropy.time import Time
from hermes_core.timedata import HermesData

__all__ = [
"process_file",
Expand Down Expand Up @@ -237,13 +241,73 @@ def l0_sci_data_to_cdf(data: dict, original_filename: Path) -> Path:
# This populates so doesn't have to return much
SkymapFactory(data, calib.energies, calib.deflections, myEEA)
example_start_times = epoch_to_iso_obj(myEEA.Epoch[0:10])
iso_times = Time(epoch_to_iso(myEEA.Epoch[:]), scale='utc')
range = [myEEA.Epoch[0], myEEA.Epoch[-1]]
range_of_packet = epoch_to_iso(range)
log.info("Range of file:" + range_of_packet[0] + " to " + range_of_packet[1])
n_packets = len(myEEA.Epoch)
#outputFile = eea_cdf.writeCDF(glblattr, myEEA, range, n_packets, srvy='normal')
#log.warning("Wrote CDF:" + outputFile)

#ts = TimeSeries(
# time=times,
# data={'diff_e_flux': u.Quantity(myEAA.stats,
# '1/(cm**2 * s * eV * steradian)',
# dtype=np.uint16)}
# )
ts = TimeSeries( time=iso_times )
ts2 = TimeSeries(time=iso_times,
data={'diff_e_flux':
u.Quantity(np.array(myEEA.stats), 'cm',
dtype=np.uint16)}
)
ts3 = TimeSeries(time=iso_times,
data={'diff_e_flux':
u.Quantity(np.array(myEEA.EnergyLabels), 'cm',
dtype=np.uint16)}
)
ts4 = TimeSeries(time=iso_times,
data={
'energy_labels': u.Quantity(np.array(myEEA.EnergyLabels), 'cm', dtype=np.uint16),
'step_counter_1': u.Quantity(np.array(np.array(myEEA.Counter1)), 'cm', dtype=np.uint16),
'step_counter_2': u.Quantity(np.array(np.array(myEEA.Counter2)), 'cm', dtype=np.uint16),
'accum': u.Quantity(np.array(np.array(myEEA.ACCUM)), 'cm', dtype=np.uint16)}
)
input_attrs = {
"DOI": "https://doi.org/<PREFIX>/<SUFFIX>",
"Data_level": "L1>Level 1", # NOT AN ISTP ATTR
"Data_version": "0.0.1",
"Descriptor": "EEA>Electron Electrostatic Analyzer",
"Data_product_descriptor": "odpd",
"HTTP_LINK": [
"https://spdf.gsfc.nasa.gov/istp_guide/istp_guide.html",
"https://spdf.gsfc.nasa.gov/istp_guide/gattributes.html",
"https://spdf.gsfc.nasa.gov/istp_guide/vattributes.html"
],
"Instrument_mode": "default", # NOT AN ISTP ATTR
"Instrument_type": "Electric Fields (space)",
"LINK_TEXT": [
"ISTP Guide",
"Global Attrs",
"Variable Attrs"
],
"LINK_TITLE": [
"ISTP Guide",
"Global Attrs",
"Variable Attrs"
],
"MODS": [
"v0.0.0 - Original version.",
"v1.0.0 - Include trajectory vectors and optics state.",
"v1.1.0 - Update metadata: counts -> flux.",
"v1.2.0 - Added flux error.",
"v1.3.0 - Trajectory vector errors are now deltas."
],
"PI_affiliation": "HERMES",
"PI_name": "HERMES SOC",
"TEXT": "Valid Test Case",
}


hermes_eea_data = HermesData(timeseries=ts4, meta=input_attrs)
return cdf_filename


Expand Down
21 changes: 21 additions & 0 deletions hermes_eea/tests/test_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,27 @@ def test_read_calibration_file():
assert len(calib.energies) == 164
assert len(calib.deflections) == 164

def test_HermesData1():
import numpy as np
import astropy.units as u
from astropy.timeseries import TimeSeries
from astropy.time import Time, TimeDelta
ts = TimeSeries(time_start='2016-03-22T12:30:31',
time_delta=3 * u.s,
data={'Bx': u.Quantity([1, 2, 3, 4],
'nanoTesla',
dtype=np.uint16)})
for item in ts.columns['time']:
print(item)
times = Time('2010-01-01 00:00:00', scale='utc') + TimeDelta(np.arange(100) * u.s)
ts = TimeSeries(
time=times,
data={'diff_e_flux': u.Quantity(np.arange(100) * 1e-3,
'1/(cm**2 * s * eV * steradian)',
dtype=np.float32)}
)


def test_calibrate_file(level0_file, level1_file):
"""Test that the output filenames are correct and that a file was actually created."""
output_file = calib.calibrate_file(level0_file)
Expand Down
14 changes: 14 additions & 0 deletions hermes_eea/util/time/iso_epoch.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ def epoch_to_iso(trange):
in_iso.append(c)
return in_iso

def epoch_to_eea_iso(trange):
"""
CDF EPOCH TO ISO:
cdflib.epochs.CDFepoch.encode_tt2000(378651727184000000)
:param trange:18 digit CDF epoch times
:return:a list,typically 2, of datetime strings in iso format
"""
in_iso = []
for t in trange:
c = cdflib.epochs.CDFepoch.encode_tt2000(int(t))
in_iso.append((c.replace("T"," ")[0:19]))
return in_iso

def epoch_to_iso_obj(trange):
"""
CDF EPOCH TO ISO:
Expand Down

0 comments on commit 638e6fd

Please sign in to comment.