Skip to content

Commit

Permalink
#37 Added real values of sun_angles and energies
Browse files Browse the repository at this point in the history
  • Loading branch information
rstrub committed Apr 22, 2024
1 parent 9ed9e09 commit ef4916e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 8 deletions.
37 changes: 30 additions & 7 deletions hermes_eea/SkymapFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from hermes_eea.io import EEA
from hermes_eea.util.time import ccsds_to_cdf_time
from hermes_eea import energies as voltages

from hermes_eea import deflections as elevation_angles
N_ENERGIES = 41
N_DEFLECTIONS = 4
N_AZIMUTH = 34
Expand Down Expand Up @@ -47,12 +47,13 @@ def SkymapFactory(l0_cdf, energies, deflections, myEEA):
+ stepper_table_packets[0]
)

epochs = ccsds_to_cdf_time.help_convert_eaa(l0_cdf)
step_values = manage_stepper_table_energies_and_angles(beginning_packets, energies, deflections, 0, len(epochs))
# This is done this way so that we can send this package to multiprocessor like:
# with Pool(n_pool) as p:
# b = p.starmap(do_EEA__packet, package)
package = []
# ccsds coarse+fine -> cdf-epoch times.
epochs = ccsds_to_cdf_time.help_convert_eaa(l0_cdf)
try:
for ptr in range(0, len(beginning_packets) + 1):
package.append(
Expand All @@ -71,8 +72,8 @@ def SkymapFactory(l0_cdf, energies, deflections, myEEA):
] # l0_cdf["COUNTER2"][47] = 12
],
epochs[beginning_packets[ptr] : beginning_packets[ptr + 1]],
energies, # from the stepper table
deflections, # from the stepper table
step_values['energy'], # from the stepper table
step_values['elevation_angle'], # from the stepper table
ptr,
)
)
Expand All @@ -87,7 +88,7 @@ def SkymapFactory(l0_cdf, energies, deflections, myEEA):
myEEA.populate(result)


def do_eea_packet(counts, cnt1, cnt2, epoch, energies, deflections, ith_FSmap):
def do_eea_packet(counts, cnt1, cnt2, epoch, energy_vals, deflection_vals, ith_FSmap):
"""
This function populates each sweep, or pass through
all of the energies and deflections designated by the stepper table
Expand All @@ -114,9 +115,31 @@ def do_eea_packet(counts, cnt1, cnt2, epoch, energies, deflections, ith_FSmap):
return_package["counts"] = counts
return_package["usec"] = epoch # we call this µsec, because it is the time of each step in the sweep within each packet.
return_package["Epoch"] = epoch[0] # here the "Epoch" is the traditional one: the start time of each packet
return_package["energies"] = voltages # a static thing for each stepper table
return_package["sun_angles"] = deflections # a static thing for each stepper table I think this is supposed to be angles, not 0,1,2,3 get from Skeberdis
return_package["energies"] = energy_vals # a static thing for each stepper table
return_package["sun_angles"] = deflection_vals # a static thing for each stepper table I think this is supposed to be angles, not 0,1,2,3 get from Skeberdis
return_package["counter1"] = cnt1 # number of counts in each packet
return_package["counter2"] = cnt2 # number of counts in each packet.

return return_package


def manage_stepper_table_energies_and_angles(beginning_packets, energies, deflections, packet, npackets):
"""
I'm doing it this way mostly to be able to handle the last,
incomplete sweep"""

stepvalues = {}
stepvalues['energy'] = []
stepvalues['elevation_angle'] = []
finish = npackets
try:
if beginning_packets[packet + 1]:
finish = beginning_packets[packet+1]
except TypeError:
pass # we are in last incomplete packet

for i in range(beginning_packets[packet], finish):

stepvalues['energy'].append(voltages[energies[i]])
stepvalues['elevation_angle'].append(elevation_angles[deflections[i]])
return stepvalues
6 changes: 6 additions & 0 deletions hermes_eea/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@

stepper_table = "flight_stepper.txt"

deflections = [
-16.875,
-5.625,
5.625,
16.875
]

energies = [
2.18000000e00,
Expand Down
9 changes: 9 additions & 0 deletions hermes_eea/calibration/build_spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ def _hermes_eea_spectra(self):
unit=astropy_units.eV,
),
),
(
"hermes_eea_deflection_angles",
NDCube(
data=np.array(self.EEA.SunAngles),
wcs=WCS(naxis=2),
meta={"CATDESC": "Deflection Angles"},
unit=astropy_units.deg,
),
),
(
"hermes_eea_accum",
NDCube(
Expand Down
8 changes: 7 additions & 1 deletion hermes_eea/tests/test_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,24 @@ def verify_l1a(output_l1a):
"""
assert os.path.getsize(output_l1a) > 275000
with pycdf.CDF(output_l1a) as cdf:

# overall structure
length_vars = len(cdf["Epoch"][:])
length_time = (cdf["Epoch"][-1] - cdf["Epoch"][0]).total_seconds()
nSteps = len(calib.energies)
assert len(cdf["Epoch"][:]) == 18
log.info("Length of CDF Variables: %d" % length_vars)
log.info("Time of CDF Variables: %d" % length_time)

assert abs(length_time - length_vars) < 2 # each sweep is about 1 sec

# review variables
variable_list = [item[0] for item in list(cdf.items())]
for var in variable_list:
log.info(var)
ndims = len(cdf[var].shape)

# look at the counts
# best guess at counter variable
if "count" in var:
counter = var
Expand All @@ -95,7 +101,7 @@ def verify_l1a(output_l1a):
total = np.sum(cdf[skymap][i])
cntsum = np.sum(cdf[counter][i])

# 40% seems like a lot...
# 40% seems like a lot... This is because this is not just for one packet but a whole sweep
# that's why I created my STATS variable.
# 1 is nominal but 40% is possible for small counts
diff = int(0.4 * total)
Expand Down

0 comments on commit ef4916e

Please sign in to comment.