pro coregister_L1B2_L2AS_event,event ; handler for widget events WIDGET_CONTROL,event.id,GET_UVALUE=uvalue case uvalue of "b2draw": begin WIDGET_CONTROL,event.top,GET_UVALUE=info if (event.type eq 2) then begin WIDGET_CONTROL,info.xtext,SET_VALUE=strtrim(string(event.x),2) WIDGET_CONTROL,info.ytext,SET_VALUE=strtrim(string(event.y),2) endif end "exit" : begin WIDGET_CONTROL,event.top,/DESTROY end else: begin end endcase return end pro coregister_L1B2_L2AS ; This routine will determine the row and column in an AirMISR Level 1B2 ; file where the L2AS upper left pixel lies. ; Images created from the L1B2 Terrain Red parameter and the L2AS ; LandDHR Red parameter are displayed and the L2AS footprint is outlined ; on the L1B2 image. ; ; The upper left and lower right corner coordinates for both data areas ; are converted from the Universal Transverse Mercator projection meter ; values stored in the file to latitude/longitude values. This information ; and the L1B2 row and column that correspond to the L2AS upper left corner ; are displayed in a text window. ; ; The entire application is exited when the EXIT button is pressed ; on the application's main splash screen window. Individual windows may ; be closed by using the standard close mechanism in the window's top frame. if LMGR(/VM) then begin info = ROUTINE_INFO('coregister_L1B2_L2AS',/source) vmdir = FILE_DIRNAME(info.path) cd,vmdir endif mainbase = WIDGET_BASE(/COL,TITLE="Coregister AirMISR",UNAME="mainbase") mainlabel = WIDGET_BUTTON(mainbase,VALUE="coregister_airmisr.bmp",/BITMAP,UNAME="logo") mainexit = WIDGET_BUTTON(mainbase,VALUE="EXIT",UVALUE="exit",UNAME="exit_button") WIDGET_CONTROL,mainbase,/REALIZE msg_txt = '' fid = -1 gid = -1 text = strarr(50) textidx = -1 ; choose a L1B2 data file and the corresponding L2AS file ; NOTE: The L2AS file needs to be the one derived from ; the same AirMISR run as the L1B2 file chosen ; modify the PATH keyword value in the DIALOG_PICKFILE function ; calls below to specify the location of the directory ; containing the AirMISR data files on your system b2file = DIALOG_PICKFILE(PATH='',FILTER='*GP*.hdf',$ TITLE="Select an AirMISR Level 1B2 file",GET_PATH=path) asfile = DIALOG_PICKFILE(PATH=path,FILTER='*AS*.hdf',$ TITLE="Select an AirMISR Level 2AS file") ; open the data files and attach the appropriate grid b2fid = EOS_GD_OPEN(b2file,/READ) if (b2fid lt 0) then begin msg_text = "Problem opening AirMISR L1B2 file " + b2file goto, error endif asfid = EOS_GD_OPEN(asfile,/READ) if (asfid lt 0) then begin msg_text = "Problem opening AirMISR L2AS file " + asfile goto, error endif num_grid = EOS_GD_INQGRID(b2file,gridlist) if (num_grid ne 1) then begin msg_text = "Expecting only one grid, found " + strtrim(string(num_grid),2) +$ " in L1B2 file" goto, error endif gridname = gridlist b2gid = EOS_GD_ATTACH(b2fid,gridname) if (b2gid lt 0) then begin msg_text = "Problem attaching L1B2 grid " + gridname goto, error endif num_grid = EOS_GD_INQGRID(asfile,gridlist) if (num_grid ne 1) then begin msg_text = "Expecting only one grid, found " + strtrim(string(num_grid),2) +$ " in L2AS file" goto, error endif gridname = gridlist asgid = EOS_GD_ATTACH(asfid,gridname) if (asgid lt 0) then begin msg_text = "Problem attaching L2AS grid " + gridname goto, error endif ; get the grid map projection and other grid information and convert from ; UTM coordinates to lat/lon status = EOS_GD_PROJINFO(b2gid, b2projcode, b2zonecode, b2spherecode, b2projparm) if (status lt 0) then begin msg_text = "Problem getting L1B2 projection info " goto, error endif status = EOS_GD_GRIDINFO(b2gid, b2xdimsize, b2ydimsize, b2upleft, b2lowright) text[++textidx] = "L1B2 dimensions: "+string(b2xdimsize)+string(b2ydimsize) text[++textidx] = "" if (status lt 0) then begin msg_text = "Problem getting L1B2 grid info" goto, error endif b2map_struc = MAP_PROJ_INIT(101, DATUM=8, /GCTP, ZONE=b2zonecode) b2ul= MAP_PROJ_INVERSE ([b2upleft[0]],[b2upleft[1]], MAP_STRUCTURE=b2map_struc) b2lr= MAP_PROJ_INVERSE ([b2lowright[0]],[b2lowright[1]], MAP_STRUCTURE=b2map_struc) text[++textidx] = "L1B2 geolocation: " text[++textidx] = "Upper left" text[++textidx] = " UTM coordinates (meters): "+ strtrim(string(b2upleft[0]),2) + $ " " + strtrim(string(b2upleft[1]),2) text[++textidx] = " lon/lat: " + strtrim(string(b2ul[0]),2) + " " + strtrim(string(b2ul[1]),2) text[++textidx] = "Lower right" text[++textidx] = " UTM coordinates (meters) " + strtrim(string(b2lowright[0]),2) + $ " " + strtrim(string(b2lowright[1]),2) text[++textidx] = " lon/lat: " + strtrim(string(b2lr[0]),2) + " " + strtrim(string(b2lr[1]),2) text[++textidx] = "" status = EOS_GD_PROJINFO(asgid, asprojcode, aszonecode, asspherecode, asprojparm) if (status lt 0) then begin msg_text = "Problem getting L2AS projection info " goto, error endif status = EOS_GD_GRIDINFO(asgid, asxdimsize, asydimsize, asupleft, aslowright) text[++textidx] = "L2AS dimensions: "+string(asxdimsize)+string(asydimsize) text[++textidx] = "" if (status lt 0) then begin msg_text = "Problem getting L2AS grid info" goto, error endif asmap_struc = MAP_PROJ_INIT(101, DATUM=8, /GCTP, ZONE=aszonecode) asul= MAP_PROJ_INVERSE ([asupleft[0]],[asupleft[1]], MAP_STRUCTURE=asmap_struc) aslr= MAP_PROJ_INVERSE ([aslowright[0]],[aslowright[1]], MAP_STRUCTURE=asmap_struc) text[++textidx] = "L2AS geolocation: " text[++textidx] = "Upper left" text[++textidx] = " UTM coordinates (meters): " + strtrim(string(asupleft[0]),2) + $ " " + strtrim(string(asupleft[1]),2) text[++textidx] = " lon/lat: " + strtrim(string(asul[0]),2) + " " + strtrim(string(asul[1]),2) text[++textidx] = "Lower right" text[++textidx] = " UTM coordinates (meters) " + strtrim(string(aslowright[0]),2) + $ " " + strtrim(string(aslowright[1]),2) text[++textidx] = " lon/lat: " + strtrim(string(aslr[0]),2) + " " + strtrim(string(aslr[1]),2) ; use the UTM corner meter values and the pixel size to ; find the L1B2 pixel that corresponds to upper left L2AS pixel xpix = round((asupleft[0] - b2upleft[0])/27.5) ypix = round((b2upleft[1] - asupleft[1])/27.5) text[++textidx] = "" text[++textidx] = "L1B2 pixel corresponding to L2AS upper left" text[++textidx] = "Column: " + strtrim(string(xpix+1),2) text[++textidx] = "Row: " + strtrim(string(ypix+1),2) ; read a data field in each file and display as an image status = EOS_GD_READFIELD(b2gid,"Terrain Red",b2reddata) if (status lt 0) then begin msg_txt = "Problem reading L1B2 data" goto, error endif status = EOS_GD_READFIELD(asgid,"LandDHR Red",asreddata) if (status lt 0) then begin msg_txt = "Problem reading L2AS data" goto, error endif b2tlb = WIDGET_BASE(/COLUMN,XSIZE=850,YSIZE=850,XOFFSET=350,$ TITLE=FILE_BASENAME(b2file),GROUP_LEADER=mainbase,UNAME="B2base") b2drawarea = WIDGET_DRAW(b2tlb,XSIZE=b2xdimsize,YSIZE=b2ydimsize,/SCROLL,$ X_SCROLL_SIZE=800,Y_SCROLL_SIZE=800,UVALUE='b2draw',/MOTION_EVENTS,UNAME="B2draw") coordbase = WIDGET_BASE(b2tlb,/ROW,UNAME="B2coordbase") xtext = WIDGET_TEXT(coordbase,VALUE="",UVALUE="xtext",UNAME="xtext") ytext = WIDGET_TEXT(coordbase,VALUE="",UVALUE="ytext",UNAME="ytext") info = {xtext:xtext,ytext:ytext} WIDGET_CONTROL,b2tlb,SET_UVALUE=info WIDGET_CONTROL,b2tlb,/REALIZE WIDGET_CONTROL,b2drawarea,GET_VALUE=b2dwin wset,b2dwin fill = where(b2reddata gt 65530, b2count) if (b2count gt 0) then b2reddata[fill] = 0 TV,HIST_EQUAL(b2reddata),/ORDER ; draw the L2AS footprint on the L1B2 image l2areax = [xpix,xpix+asxdimsize-1,xpix+asxdimsize-1,xpix,xpix] l2areay = 1713 - [ypix,ypix,ypix+asydimsize-1,ypix+asydimsize-1,ypix] PLOT,findgen(b2xdimsize),findgen(b2ydimsize),/NODATA,/NOERASE,$ XSTYLE=1+4,YSTYLE=1+4,XMARGIN=0,YMARGIN=0 OPLOT,l2areax,l2areay,COLOR=255 astlb = WIDGET_BASE(/COLUMN,XSIZE=asxdimsize+25,YSIZE=asydimsize+25,$ TITLE=FILE_BASENAME(asfile),XOFFSET=250,GROUP_LEADER=mainbase,UNAME="ASbase") asdrawarea = WIDGET_DRAW(astlb,XSIZE=asxdimsize,YSIZE=asydimsize,UVALUE="asdraw",UNAME="ASdraw") WIDGET_CONTROL,astlb,/REALIZE WIDGET_CONTROL,asdrawarea,GET_VALUE=asdwin wset,asdwin neg = where(asreddata lt 0, ascount) if (ascount gt 0) then asreddata[neg] = 0 tv,hist_equal(asreddata),/ORDER ; create the window for the text output information texttlb = WIDGET_BASE(/COLUMN,XSIZE=450,YSIZE=300,$ YOFFSET=200,GROUP_LEADER=mainbase,UNAME="textbase") text = text[0:textidx] textwin = WIDGET_TEXT(texttlb,/SCROLL,VALUE=text,UVALUE="textwin",XSIZE=60,YSIZE=20) WIDGET_CONTROL,texttlb,/REALIZE XMANAGER,'coregister_L1B2_L2AS',b2tlb,/JUST_REG XMANAGER,'coregister_L1B2_L2AS',mainbase error: if (msg_txt ne '') then begin response = DIALOG_MESSAGE(msg_text,/WARN) endif if (b2gid ge 0) then begin status = EOS_GD_DETACH(b2gid) endif if (b2fid ge 0) then begin status = EOS_GD_CLOSE(b2fid) endif if (asgid ge 0) then begin status = EOS_GD_DETACH(asgid) endif if (asfid ge 0) then begin status = EOS_GD_CLOSE(asfid) endif end