Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ALE Position in J2000 #539

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions ale/base/data_isis.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ def rotate_state(table, rotation):
else:
raise ValueError('No positions are available in the input table.')

rotated_pos = rotation.apply_at(positions, ephemeris_times)
if velocities is not None:
rotated_vel = rotation.rotate_velocity_at(positions, velocities, ephemeris_times)
else:
rotated_vel = None
return rotated_pos, rotated_vel, ephemeris_times
# rotated_pos = rotation.apply_at(positions, ephemeris_times)
# if velocities is not None:
# rotated_vel = rotation.rotate_velocity_at(positions, velocities, ephemeris_times)
# else:
# rotated_vel = None
return positions, velocities, ephemeris_times

class IsisSpice():
"""Mixin class for reading from an ISIS cube that has been spiceinit'd
Expand Down
19 changes: 9 additions & 10 deletions ale/base/data_naif.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,7 @@ def reference_frame(self):
String name of the target reference frame
"""
if not hasattr(self, "_reference_frame"):
try:
self._reference_frame = spice.cidfrm(spice.bodn2c(self.target_name))[1]
except:
self._reference_frame = 'IAU_{}'.format(self.target_name)
self._reference_frame = "J2000"
return self._reference_frame

@property
Expand All @@ -328,7 +325,9 @@ def sun_position(self):
: (sun_positions, sun_velocities)
a tuple containing a list of sun positions, a list of sun velocities
"""
times = [self.center_ephemeris_time]
times = self.ephemeris_time
if len(times) > 1:
times = [times[0], times[-1]]
positions = []
velocities = []

Expand Down Expand Up @@ -433,13 +432,13 @@ def frame_chain(self):
if nadir:
# Logic for nadir calculation was taken from ISIS3
# SpiceRotation::setEphemerisTimeNadir
rotation = self._frame_chain.compute_rotation(self.target_frame_id, 1)
# rotation = self._frame_chain.compute_rotation(self.target_frame_id, 1)
p_vec, v_vec, times = self.sensor_position
rotated_positions = rotation.apply_at(p_vec, times)
rotated_velocities = rotation.rotate_velocity_at(p_vec, v_vec, times)
# rotated_positions = rotation.apply_at(p_vec, times)
# rotated_velocities = rotation.rotate_velocity_at(p_vec, v_vec, times)

p_vec = rotated_positions
v_vec = rotated_velocities
# p_vec = rotated_positions
# v_vec = rotated_velocities

velocity_axis = 2
# Get the default line translation with no potential flipping
Expand Down
12 changes: 4 additions & 8 deletions ale/formatters/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,8 @@ def to_isd(driver):
instrument_position['spk_table_original_size'] = len(times)
instrument_position['ephemeris_times'] = times
# Rotate positions and velocities into J2000 then scale into kilometers
velocities = j2000_rotation.rotate_velocity_at(positions, velocities, times)/1000
positions = j2000_rotation.apply_at(positions, times)/1000
instrument_position['positions'] = positions
instrument_position['velocities'] = velocities
instrument_position['positions'] = np.array(positions)/1000
instrument_position['velocities'] = np.array(velocities)/1000
instrument_position["reference_frame"] = j2000_rotation.dest

meta_data['instrument_position'] = instrument_position
Expand All @@ -188,10 +186,8 @@ def to_isd(driver):
sun_position['spk_table_original_size'] = len(times)
sun_position['ephemeris_times'] = times
# Rotate positions and velocities into J2000 then scale into kilometers
velocities = j2000_rotation.rotate_velocity_at(positions, velocities, times)/1000
positions = j2000_rotation.apply_at(positions, times)/1000
sun_position['positions'] = positions
sun_position['velocities'] = velocities
sun_position['positions'] = np.array(positions)/1000
sun_position['velocities'] = np.array(velocities)/1000
sun_position["reference_frame"] = j2000_rotation.dest

meta_data['sun_position'] = sun_position
Expand Down
31 changes: 21 additions & 10 deletions tests/pytests/data/isds/chandrayaan_mrffr_isd.json
Original file line number Diff line number Diff line change
Expand Up @@ -58667,24 +58667,35 @@
"reference_frame": 1
},
"sun_position": {
"spk_table_start_time": 284618274.5028643,
"spk_table_end_time": 284618274.5028643,
"spk_table_original_size": 1,
"spk_table_start_time": 284618195.65060276,
"spk_table_end_time": 284618353.35512584,
"spk_table_original_size": 2,
"ephemeris_times": [
284618274.5028643
284618195.65060276,
284618353.35512584
],
"positions": [
[
43780497.0799206,
-129064945.41639775,
-55987592.45489679
43778143.55392006,
-129065559.6861403,
-55987861.91428987
],
[
43782850.604594715,
-129064331.09970973,
-55987322.97221424
]
],
"velocities": [
[
29.84809594419459,
7.7898174083485205,
3.41947441993111
29.847298686635785,
7.789832883807146,
3.417134417900032
],
[
29.84725641918019,
7.791031989531442,
3.4176990497686637
]
],
"reference_frame": 1
Expand Down
31 changes: 21 additions & 10 deletions tests/pytests/data/isds/chandrayannM3_isd.json
Original file line number Diff line number Diff line change
Expand Up @@ -390,24 +390,35 @@
"reference_frame": 1
},
"sun_position": {
"spk_table_start_time": 299622941.73534995,
"spk_table_end_time": 299622941.73534995,
"spk_table_original_size": 1,
"spk_table_start_time": 299622941.60814995,
"spk_table_end_time": 299622941.86254996,
"spk_table_original_size": 2,
"ephemeris_times": [
299622941.73534995
299622941.60814995,
299622941.86254996
],
"positions": [
[
-22279396.272817865,
138086310.683749,
59901633.861951254
-22279392.552556925,
138086311.0772047,
59901634.029351056
],
[
-22279399.993010454,
138086310.29030323,
59901633.69455383
]
],
"velocities": [
[
-29.247063986944152,
-3.0931661850381134,
-1.3160268288136903
-29.247063783209654,
-3.0931654356540093,
-1.3160264669418211
],
[
-29.24706420755107,
-3.0931669393224728,
-1.3160271856310302
]
],
"reference_frame": 1
Expand Down
Loading