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

Fix mirror kernel loading #62

Open
planetarymike opened this issue Mar 7, 2024 · 2 comments
Open

Fix mirror kernel loading #62

planetarymike opened this issue Mar 7, 2024 · 2 comments
Assignees

Comments

@planetarymike
Copy link
Collaborator

Current CK loader in spice.py is not capable of loading mirror kernels for all IUVS observations. Needs to be updated to match implementation in IDL pipeline.

@planetarymike planetarymike self-assigned this Mar 7, 2024
@planetarymike
Copy link
Collaborator Author

Here is the relevant part of the spice.py code to update:

# Load only mirror kernels after the last combined mirror kernel in the meta kernel !ANC+"spice/mvn/mvn.tm"

Combined mirror kernels aren't made anymore: instead, the IDL pipeline was modified to load all mirror kernels within a specified date range.

@planetarymike
Copy link
Collaborator Author

planetarymike commented Mar 8, 2024

Here is the new load_ck routine in the IDL pipeline iuvs-itf-sw/code/idl_lib/spice/load_sc_ck.pro :

pro load_sc_ck_type,type,pred=pred, all=all
  ;Load the long kernels first
  f=file_search(string(!mvn_kpath,format='(%"%sck/mvn_'+type+'_rel_*.bc")'),count=count)
  if count gt 0 then long=find_latest_kernel(f,4,last=lastlong) ;use the second date in the week

  ;Now the daily kernels
  f=file_search(string(!mvn_kpath,format='(%"%sck/mvn_'+type+'_red_*.bc")'),count=count)
  if count gt 0 then day=find_latest_kernel(f,3,after=lastlong,last=lastday)

  ;Finally the "normal" kernels
  f=file_search(string(!mvn_kpath,format='(%"%sck/mvn_'+type+'_rec_*.bc")'),count=count)
  if count gt 0 then norm=find_latest_kernel(f,3,after=lastday)

  if keyword_set(pred) then begin
    ;When we load predictions, they will go here
    f=file_search(string(!mvn_kpath,format='(%"%sck/mvn_'+type+'_pred_*.bc")'),count=count)
    if count gt 0 then pred_list=find_latest_kernel(f,4,after=lastday) ;use the last day, because normal kernels are irregular.
    ;Use the second date, so if the prediction overlaps the last day, it gets loaded
  end
  
  ; unless the /all keyword is set, only load the last 53 long-term kernels
  ; 53 reconstructed kernels will cover about the last year (one per week)
  if ~keyword_set(all) then begin
    num_to_furnish = 53
    if n_elements(long) gt num_to_furnish then long = long[-num_to_furnish:-1]
  endif
  
  ;Furnish things in the following order so that they are in proper priority - weekly has highest, then daily, then normal (then predictions, if any) so load [pred,]norm,day,week
  ;furnsh_array,pred
  furnsh_array,norm
  furnsh_array,day
  furnsh_array,long
  if keyword_set(pred) then furnsh_array,pred_list
end  

;+
; :Description:
;    Load the CK kernels.
;
; :Keywords:
;    date_range  : List of YYYYMMDD formatted date strings. If not specified, load the last 90 days.
;    cruise      : Boolean, indicating if we are loading cruise phase kernels. 
;    all         : Boolean, indicating if we are loading all kernels.
;-
pro load_sc_ck, date_range=dates, cruise=cruise, all=all

  ; TODO: Determine if we nee /all here.
  load_sc_ck_type,'app', all=all
  load_sc_ck_type,'sc', all=all

  ;Load the latest of each days' IUVS mirror kernel
  ;Since the instrument was not active during September 2014 before MOI, we can consider
  ;any kernel taken before September 1 2014 to be cruise, and any after to be in-orbit.
  f=[]
  count=0
  if keyword_set(cruise) then begin
    this_f=file_search(string(!mvn_kpath,format='(%"%sck/mvn_iuv_all_l0_2013????_v*.bc")'),count=this_count) ;all the 2013 kernels
    count+=this_count
    if this_count gt 0 then f=[f,this_f]
    this_f=file_search(string(!mvn_kpath,format='(%"%sck/mvn_iuv_all_l0_20140[1-8]??_v*.bc")'),count=this_count) ;all the 2014 cruise kernels
    count+=this_count
    if this_count gt 0 then f=[f,this_f]
  end

  ;----------- load mirror CK files --------------
  if keyword_set(dates) then begin
    ; Pad the date range by one day on either end, to cover any midnight boundary problems.
    start_dates = list()
    end_dates = list()
    foreach date, dates do begin
      padded_date_range = pad_date_range(date)
      start_dates.add, padded_date_range[0]
      end_dates.add, padded_date_range[1]
    endforeach
  endif else begin
    ; Load the last 90 days
    start_dates = [yyyymmdd_n_days_ago(90)]
    end_dates = [yyyymmdd_n_days_ago(0)]
  endelse
  
  foreach start_date, start_dates, idate do begin
    end_date = end_dates[idate]
    
    ; Find daily kernels that correspond to the date range
    first_daily = !anc+'spice/mvn/ck/mvn_iuv_all_l0_' + start_date + '_v000.bc'
    last_daily = !anc+'spice/mvn/ck/mvn_iuv_all_l0_' + end_date + '_v999.bc'

    ; find all daily mirror kernels
    this_f = file_search(string(!mvn_kpath, format='(%"%sck/mvn_iuv_all_l0_????????_v*.bc")'), count=all_daily_count)
    if all_daily_count gt 0 then begin
      this_f = find_latest_kernel(this_f, 4)

      ; Get kernels for the date range
      w = where(logical_and(this_f gt first_daily, this_f lt last_daily), recent_daily_count)
      if recent_daily_count gt 0 then begin
        this_f = this_f[w]
        count += recent_daily_count
        f = [f, this_f]
      endif
    endif
  endforeach

  
  
  if count gt 0 then begin
    ; Make sure we don't have any duplicates
    f = f.uniq()
    furnsh_array, f
  endif else begin
    iuvs_log,"Didn't load any kernels!"
  endelse
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant