Skip to content

Instantly share code, notes, and snippets.

@dpshelio
Created November 7, 2012 18:19
Show Gist options
  • Save dpshelio/4033372 to your computer and use it in GitHub Desktop.
Save dpshelio/4033372 to your computer and use it in GitHub Desktop.
Chain code contours from Lambert to disk projection
function cc_lamb2disk,eit_map,s_ch
;+
; CC_LAMB2DISK
; It converts the chain code of ch structures produced by CHARM from Lambert maps to disk
; INPUTS: eit_map -> the map used for the detection (normally EIT or AIA)
; s_ch -> the structure saved from CHARM
; OUTPUT: new_s_ch -> the same structure than s_ch with the CC updated for all the CHs
; EXAMPLE: CHARM_DETECTION
; updated_s_ch = cc_lamb2disk(euv_map,s_ch)
; ; if I want to plot the new ones
; sizeimage = size(euv_map.data)
; plot_image, euv_map.data
; for i=0, n_elements(s_ch)-1 do begin
; bound=egso_sfc_chain2ind(strsplit(updated_s_ch[i].cc_pix_xy,',',/extract)+0,$
; updated_s_ch[i].chain_code,sizeimage[1],sizeimage[2])
; plots,bound
; endfor
;
;-
; First, get the solar_X and solar_Y coordinates for all the map
XX = get_map_xp(eit_map)
YY = get_mpa_yp(eit_map)
; Convert the solar cooridnates to lambert projection
XX_plane=lambert_project(XX,[eit_map.xc,eit_map.yc],eit_map.dx,date=eit_map.time)
YY_plane=lambert_project(YY,[eit_map.xc,eit_map.yc],eit_map.dx,date=eit_map.time)
; Extract the size of each images, the disk(map) and the Lambert(plane)
sizem = size(XX)
sizep = size(XX_plane)
; Copy the structure of the detections as a new one
new_s_ch = s_ch
; extract for each detection the chain code and build the new one for the disk projection.
for i=0,n_elements(s_ch)-1 do begin
bound=egso_sfc_chain2ind(strsplit(s_ch[i].cc_pix_xy,',',/extract)+0,s_ch[i].chain_code,sizep[1],sizep[2])
XX1=XX_PLANE[bound]
YY1=YY_PLANE[bound]
for j=0,n_elements(xx1)-1 do begin
kk=min(abs(xx[*,0]-xx1[j]),ll)
mm=(j eq 0)?kk:[mm,kk]
indx=(j eq 0)?ll:[indx,ll]
kk=min(abs(yy[0,*]-yy1[j]),ll)
nn=(j eq 0)?kk:[nn,kk]
indy=(j eq 0)?ll:[indy,ll]
endfor
path_xy=transpose([[indx],[indy]])
npath=contour_nogap(path_xy)
npath_ind=coord2ind(npath,[sizem[1],sizem[2]])
npath_cc=egso_sfc_chain_code(npath_ind,sizem[1],sizem[2])
out_cc=string(npath_cc,format='('+strtrim(n_elements(npath_cc),2)+'I1)')
new_s_ch[i].CHAIN_CODE=out_cc
chain_length=n_elements(npath_cc)
new_s_ch[i].CCODE_LENGTH = chain_length
out_xy=string(npath[*,0],format='(I4.3,",",I4.3)')
new_s_ch[i].CC_PIX_XY = out_xy
new_s_ch[i].CC_ARC_X = xx[indx[0],0]
new_s_ch[i].CC_ARC_Y = yy[0,indy[0]]
endfor
return, new_s_ch
end
;=====================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment