Commit 3922fc05 authored by Carl Schaffer's avatar Carl Schaffer
Browse files

adding first version of IFU splitting

parent fdaf5d8a
pro split_ifu,filebase
gitrev = get_git_revision()
folder = file_dirname(file_dirname(filebase))
files = file_search(filebase+"*cc",count=file_count)
if file_count eq 0 then begin
print, "No IFU maps found for "+filebase
return
endif
header_dict = Dictionary()
primed = 0
series_headers = List()
foreach file_i, files do begin
print,"Processing "+file_i
fits_read,file_i,data,header,/header_only
foreach field, header do begin
key = repstr(strtrim(strmid(field,0,8)),"-","_")
if key eq "ISERIE" then begin
; print, "New map!"
if primed then begin
header_i = strarr(n_elements(header_dict))
i=0
foreach field_i, header_dict do begin
header_i[i] = field_i
i=i+1
endforeach
series_headers.add,header_i[sort(header_i)]
endif
primed = 1
endif
a = where(key eq ["", "END"],invalid_keyword)
if not(invalid_keyword) then begin
header_dict[key]=field
endif
endforeach
endforeach
; Add header to list of header blocks
header_i = strarr(n_elements(header_dict))
i=0
foreach field, header_dict do begin
header_i[i] = field
i=i+1
endforeach
series_headers.add,header_i[sort(header_i)]
; reshape all data to [lambda, x, y, pol, maps]
; (add degenerate dimensions of size 1 for maps and
; pol states if only one exists)
im = readifu(filebase)
im_size = size(im)
if sxpar(series_headers[0],"STATES") ne 4 then begin
im = reform(im,im_size[1],im_size[2],im_size[3],1)
endif
im_size = size(im)
if im_size[0] eq 4 then begin
im= reform(im,im_size[1],im_size[2],im_size[3],im_size[4],1)
endif
im_size = size(im)
im = transpose(im, [1,2,0,3,4])
n_maps = min([im_size[5],n_elements(series_headers)])
for i_map=0,n_maps-1 do begin
head_i = series_headers[i_map]
run_string = strmid(file_basename(file_i),8,3)
smap=string(sxpar(head_i,"ISERIE"),format='(I3.3)')
date_string = strtrim(repstr(sxpar(head_i,"DATE-OBS"),'-',''))
time_string = repstr(strmid(sxpar(head_i,"UTIME"),0,8),':',''); starting time of map
mode_string = "l1s"
if sxpar(head_i,"STATES") ne 4 then mode_string = "l1p"
fn_fields = ["gris-ifu",date_string,time_string,mode_string,run_string,smap]
filename = strjoin(fn_fields,"_")+".fits"
outdir=file_search(folder+'/level1_split',count=cntdir)
if(cntdir eq 0) then spawn,'mkdir '+folder+'/level1_split'
outdir=file_search(folder+'/level1_split',count=cntdir)
sxaddpar,head_i,'HISTORY','split_ifu run on: '+string(systime(0))
sxaddpar,head_i,'HISTORY','split_ifu git revision: '+gitrev[0]
sxaddpar,head_i,'HISTORY','split_ifu git repo: '+gitrev[2]
sxaddpar,head_i,'HISTORY','split_ifu git commit date: '+gitrev[1]
outpath = outdir+'/'+filename
print,outpath
fits_write, outpath, im[*,*,*,*,i_map], head_i
endfor
; CD,'/dat/sdc/gris_ifu/20190607'
; ; preview_frames,'23sep18.005'
; im = lee('level1/07jun19.000-02cc')
; help,im
end
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment