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

SPICE - Spin phase query utils function - using spin start and spin rate data. #806

Closed
Tracked by #975
tech3371 opened this issue Sep 3, 2024 · 0 comments · Fixed by #824 or #852
Closed
Tracked by #975

SPICE - Spin phase query utils function - using spin start and spin rate data. #806

tech3371 opened this issue Sep 3, 2024 · 0 comments · Fixed by #824 or #852
Assignees
Labels
Level: L1 Level 1 processing Level: L2 Level 2 processing SPICE Related to SPICE

Comments

@tech3371
Copy link
Contributor

tech3371 commented Sep 3, 2024

For a given input time, this function will need to return spin phase angle of spacecraft.

Function signature

def get_spacecarft_spin_phase(query_times: Union[float, np.ndarray]) -> Union[float, np.ndarray]:
"""
Compute the floating point spin phase using spin table [0, 1] at the input times.
"""
spin_table = get_spin_table()  # Start with this function?
spin_phase = (query_time - (spin_start_seconds + spin_start_subseconds)) / spin_period_sec

Could also add a function to get instrument spin phase (Put this in a new ticket?)

def get_instrument_spin_phase(query_times: Union[float, np.ndarray], instrument_id: IntEnum) -> Union[float, np.ndarray]:
instrument_spin_phase = get_spacecraft_spin_phase + get_instrument_phase_offset()

fixture function signature

def gen_spin_table(start_time: datetime, end_time: datetime = None) -> Path:
"""
Generate a pointing table CSV covering one or more days.

Parameters
-----------
start_time : provides the starting day of year
end_time : optionally specify end day of year. If not provided default to one day

Returns
--------
Path to CSV file

Tim's prototype code:

# Spin table contains the following fields:
# (spin_number, spin_start_sec, spin_start_subsec, spin_period_sec, spin_period_valid, spin_phas_valid, spin_period_source, thruster_firing)
seconds_per_point = 24 * 60 * 60

# get the very first spin start sclk
_, start_sclk_sec, start_sclk_ticks = parse_sclk_str(spice.sce2s(SC_ID, cov[0]))
_, end_sclk_sec, end_sclk_ticks = parse_sclk_str(spice.sce2s(SC_ID, cov[-1]))

# fill the whole year worth of spin data with assuming ideal 15 seccond spins
spin_dict = dict()
spin_start_sec = np.arange(start_sclk_sec, end_sclk_sec, 15, dtype=np.uint64)
spin_dict["spin_number"] = np.arange(spin_start_sec.size, dtype=np.uint64)
spin_dict["spin_start_sec"] = spin_start_sec
spin_dict["spin_start_subsec"] = np.full(spin_dict["spin_start_sec"].size, start_sclk_ticks * TICKS_TO_MS, dtype=np.uint64)
spin_dict["spin_period_sec"] = np.full(spin_dict["spin_start_sec"].size, 15.0, dtype=np.float64)
spin_dict["spin_period_valid"] = np.ones(spin_dict["spin_start_sec"].size, dtype=np.uint8)
spin_dict["spin_period_phase"] = np.ones(spin_dict["spin_start_sec"].size, dtype=np.uint8)
spin_dict["spin_period_source"] = np.zeros(spin_dict["spin_start_sec"].size, dtype=np.uint8)
spin_dict["thruster_firing"] = np.zeros(spin_dict["spin_start_sec"].size, dtype=np.uint8)

spin_start_float = np.arange(cov[0], cov[-1], 15)

# Set thruster firing flag. Intervals here indicate time during repointing
for i_pointing, interval in enumerate(cov[1:-1].reshape((-1, 2))):
    # set values where spin end time is greater than repoint start and spin start time is < repoint end
    firing_mask = np.logical_and(
        spin_start_float + spin_dict["spin_period_sec"] >= interval[0],
        spin_start_float < interval[1]
    )
    spin_dict["thruster_firing"][firing_mask] = 1
    spin_dict["spin_period_valid"][firing_mask] = 0

spin_df = pd.DataFrame.from_dict(spin_dict)
spin_df.to_csv("imap_2025_106_2026_105_v00.spin.csv", index=False)
@tech3371 tech3371 added Level: L1 Level 1 processing Level: L2 Level 2 processing SPICE Related to SPICE labels Sep 3, 2024
@tech3371 tech3371 added this to the Sept 2024 milestone Sep 3, 2024
@tech3371 tech3371 added this to IMAP Sep 3, 2024
@tech3371 tech3371 changed the title Spin phase query utils function Spin phase query utils function - using spin start and spin rate data. Sep 4, 2024
@tech3371 tech3371 changed the title Spin phase query utils function - using spin start and spin rate data. SPICE - Spin phase query utils function - using spin start and spin rate data. Sep 4, 2024
@tech3371 tech3371 modified the milestones: Sept 2024, SPICE Tools Sep 4, 2024
@tech3371 tech3371 linked a pull request Sep 10, 2024 that will close this issue
@github-project-automation github-project-automation bot moved this to Done in IMAP Sep 18, 2024
@tech3371 tech3371 reopened this Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Level: L1 Level 1 processing Level: L2 Level 2 processing SPICE Related to SPICE
Projects
Status: Done
2 participants