How to detect & store lunar eclipse events?

Hi all, I am quite new, this is my first question on here so hope I have provided enough detail!

I am writing a script for detecting lunar eclipses across a spacecraft, using various Astrodynamics julia packages (AstroTime.jl, SPICE.jl etc.). I created a custom struct Eclipse to store my individual eclipse events.

struct Eclipse
    "Start time (UTC)" 
    Ti::UTCEpoch 
    "Finish time (UTC)" 
    Tf::UTCEpoch 
    "Duration - seconds" 
    dur::AstroTime.Period 
    "Type - penumbral or umbral" 
    type::Symbol
    "Event number"
    num::Int64
end 

In the main I loop through the dates and at each time step detect the type of eclipse (or lack of eclipse). Now I want to store each eclipse as an instance of my struct Eclipse and save them to an array with the start and stop times. However, I can’t figure out how to do this in a general way (e.g. one that doesn’t rely on knowing a priori the order of eclipse types).

A MWE:

eclipses = []

for i in eachindex(dates)
        # Check whether the spacecraft is in eclipse or not. Returns :none, :pen, or :umb. 
        eclipse_type =  detect_eclipse(spacecraft_position[i], dates[i])
        

        ## DO some check conditions and identify the start and stop time of a single event (e.g. a series of uninterrupted :pen eclipse_types equates to one eclipse event). 

        # Once a full eclipse has been found, push this eclipse struct to the array. 
        push!(eclipses, Eclipse(t_i, t_f, t_f-t_i, eclipse_type, event_number))

end 
        

One idea i had was to push to another array at each time step so I have something like this

Array{N, 1}[:none, :none, :pen, :pen, :pen, :umb, :umb, :umb, :none, :none, … ] where N = length(dates)

then check at which indices the value changes as this indicates the start/stop times of an eclipse. However, I am unsure how to implement this and it seems very inefficient. Any other ideas for distinguishing events would be very appreciated, thanks!

How do you want to access the information, do you want to ask for the next event of some kind (or either kind) or do you want to have a daily state of affairs be shown to you or would you like to order the events by their duration or some combination of the above or something else entirely?

Ultimately I would like to read a spacecraft trajectory file and output a complete chronological list of all eclipses across a given date range that I can write to a file or plot etc.

E.g write a file that is similar to this:
row 1 = Ecclipse 1, start time, stoptime, eclipse type, duration, event number,
row 2 = Ecclipse 2, start time, stoptime, eclipse type, duration, event number,

row N = Ecclipse 3, start time, stoptime, eclipse type, duration, event number,

So the spacecraft trajectory file gives you the span of dates of interest for that craft+path. You have a date interval and you want all events that happen to occur within that interval returned to you in date order. Is that correct?

Yep!

There are two data management tools that are explicitly designed for time-sequenced information TimeSeries.jl and Temporal.jl in addtion, https://github.com/JuliaComputing/IndexedTables.jl is a very flexible data rearrainger and subset culler that would work well for this. At this time, all are light on the sorts of graduated examples that make learning fun. I suggest that read the docs that the first two offer and look through the examples and tests for all of them. If one feels more comfortable, use that. If none seems appropriate or speaks to you clearly, then you should see what DataFrames.jl can do for you (everything you need … and there is much more support and community familiarity with that package).

Thanks for pointing me to these packages JeffreySarnoff. Although I ended up figuring out a way to do it without creating extra tables, the TimeSeries docs led me to a conceptual method that solved the problem!