PRO THM_ASI_CREATE_MOSAIC,time,$
cal_files=cal_files,$
gif_out=gif_out,$
verbose=verbose,$
pgm_file=pgm_file,$
thumb=thumb,$
exclude=exclude,$
top=top,$
special=special,$
show=show,$
scale=scale,$
central_lat=central_lat,$
central_lon=central_lon,$
color_continent=color_continent,$
color_background=color_background,$
position=position,$
xsize=xsize,$
ysize=ysize,$
noerase=noerase,$
zbuffer=zbuffer,$
cursor=cursor,$
projection=projection,$
maxval=maxval,$
minval=minval,$
window=window,$
rotation=rotation,$
full_minute=full_minute,$
minimum_elevation=minimum_elevation,$
merge=merge,$
gif_dir=gif_dir,$
force_map=force_map,$
no_grid=no_grid,$
no_midnight=no_midnight,$
add_plot=add_plot,$
mask=mask,$
xy_pos=xy_pos,$
location=location,$
no_color=no_color, $
xy_cursor=xy_cursor,$
track1=track1,$
track2=track2,$
ssize=ssize,$
sym_color=sym_color,$
keep_z=keep_z,$
stoptime=stoptime,$
timestep=timestep,$
color_annotation = color_annotation,$
insert=insert,$
no_label=no_label
if keyword_set(verbose) then verbose=systime(1)
if (strlen(time) ne 19) then begin
dprint, 'Wrong time input'
dprint, 'Correct value like 2006-01-01/05:00:00'
return
endif
if keyword_set(xy_pos) then begin
dd=size(xy_pos)
if (dd[2] ne 2) then begin
dprint, 'XY_pos input wrong!'
dprint, 'Needs to be given like [[x1,x2,x3,x4,x5,...],[y1,y2,y3,y4,y5,...]]'
return
endif
endif
if keyword_set(maxval) then begin
if not keyword_set(minval) then begin
dprint, 'minval has to be set with maxval'
return
endif
if not keyword_set(show) then begin
dprint, 'Show has to be set with maxval'
return
endif
if n_elements(show) ne n_elements(maxval) then begin
dprint, 'N_elements of show and maxval have to match'
return
endif
endif
res=time_struct(time)
year=res.year
month=res.month
day=res.date
hour=res.hour
minute=res.min
second=res.sec
thm_init
timespan,time,1,/hour
thm_asi_stations,site,loc
if keyword_set(zbuffer) then map_scale=2.6e7 else map_scale=4.e7
if keyword_set(scale) then map_scale=scale
if not keyword_set(central_lon) then central_lon=255.
if not keyword_set(central_lat) then central_lat=63.
if not keyword_set(xsize) then xsize=700
if not keyword_set(ysize) then ysize=410
if not keyword_set(top) then top=254
if keyword_set(zbuffer) then chars=1.15 else chars=1.5
if keyword_set(minimum_elevation) then minimum_elevation_to_plot=minimum_elevation else minimum_elevation_to_plot=8.
if (keyword_set(thumb) and not keyword_set(special)) then n1=1024l else n1=256l*256l
If(keyword_set(color_annotation)) Then Begin
xyouts_color = color_annotation[0]
Endif Else xyouts_color = 0
names=tnames('thg_as*')
if (names[0] ne '') then store_data,delete=names
if keyword_set(stoptime) then begin
if keyword_set(show) then thm_load_asi_cal,show,cal_files else $
thm_load_asi_cal,'atha chbg ekat fsmi fsim fykn gako gbay gill inuv kapu kian kuuj mcgr pgeo pina rank snkq tpas whit yknf nrsq snap talo',cal_files
endif
repeat_loop:
if not keyword_set(no_midnight) then begin
f=file_search('midnight.sav',count=midnight_count)
if (midnight_count eq 1) then begin
midlons=fltarr(40)+!values.f_nan
ut_hour=float(hour)+float(minute)/60.+float(second)/3600.
restore,f
for i=0,39 do begin
lon=interpol(findgen(141)+start_longitude,reform(midnight[i,*]),ut_hour)
midlons[i]=lon[0]
endfor
bad=where(midlons gt 360.,count)
if (count gt 0) then midlons[bad]=!values.f_nan
endif
endif else midnight_count=0
thm_mosaic_array,year,month,day,hour,minute,second,strlowcase(site),$
image,corners,elevation,pixel_illuminated,n_sites,verbose=verbose,$
cal_files=cal_files,pgm_file=pgm_file,thumb=thumb,special=special,$
show=show,exclude=exclude,full_minute=full_minute,merge=merge,$
mask=mask
if keyword_set(exclude) then begin
for i=0,n_elements(exclude)-1 do begin
not_site=where(strlowcase(site) eq strlowcase(exclude[i]),count)
if (count eq 0) then dprint, 'Not a valid site: ',exclude[i] else begin
corners[*,*,*,not_site]=!values.f_nan
image[*,not_site]=!values.f_nan
endelse
endfor
endif
bytval=fltarr(n_sites)+1.
bitval=fltarr(n_sites)
if keyword_set(maxval) then begin
for i=0,n_elements(maxval)-1 do begin
index=where(strlowcase(site) eq strlowcase(show[i]))
bytval[index]=maxval[i]
bitval[index]=minval[i]
endfor
for i=0,n_sites-1 do image[*,i]=bytscl(image[*,i],min=bitval[i],max=bytval[i])
endif else begin
if keyword_set(special) then for i=0,n_sites-1 do bytval[i]=(median(image[0:1023,i]) > 1) else begin
if keyword_set(full_minute) then begin
for i=0,n_sites-1 do bytval[i]=(median(image[*,i,*]) > 1)
for i=0,n_sites-1 do image[*,i,*]=((image[*,i,*]/bytval[i])*64.) < 254
endif else begin
for i=0,n_sites-1 do bytval[i]=(median(image[*,i]) > 1)
mm_dumm=where(merge ne -1,count_mm_dumm)
if (count_mm_dumm ne 0) then begin
for dki=0,count_mm_dumm-1 do bytval[mm_dumm[dki]]=(median(image[0:1023,mm_dumm[dki]]) > 1)
endif
for i=0,n_sites-1 do image[*,i]=((image[*,i]/bytval[i])*64.) < 254
endelse
endelse
endelse
if (max(bytval) eq 1.) then begin
dprint, 'No images for ',time
if not keyword_set(force_map) then begin
if keyword_set(gif_out) then gif_out=''
if double(!version.release) lt 8.0d then heap_gc
return
endif
endif
if keyword_set(exclude) then begin
for i=0,n_elements(exclude)-1 do begin
not_site=where(strlowcase(site) eq strlowcase(exclude[i]),count)
if (count eq 0) then dprint, 'Not a valid site: ',exclude[i] else begin
corners[*,*,*,not_site]=!values.f_nan
bytval[not_site]=!values.f_nan
endelse
endfor
endif
if keyword_set(full_minute) then begin
time_start=time
for ikk=0,19 do begin
if(keyword_set(zbuffer)) then set_plot, 'z'
thm_map_set,scale=map_scale,$
central_lat=central_lat,$
central_lon=central_lon,$
color_continent=color_continent,$
color_background=color_background,$
position=position,$
xsize=xsize,$
ysize=ysize,$
noerase=noerase,$
zbuffer=zbuffer,$
projection=projection,$
window=window,$
rotation=rotation,$
no_color=no_color
for pixel=0l,n1-1l do begin
for i_site=0,n_sites-1 do begin
if ((pixel_illuminated[pixel,i_site] eq 1) and $
(elevation[pixel,i_site] gt minimum_elevation_to_plot)) then $
polyfill,corners[pixel,[0,1,2,3,0],0,i_site],$
corners[pixel,[0,1,2,3,0],1,i_site],color=image[pixel,i_site, ikk] < top
if keyword_set(special) then if ((spec_illu[pixel*64 < (n1-1),i_site] eq 1) and $
(elevation[pixel*64 < (n1-1),i_site] gt minimum_elevation_to_plot)) then begin
for ijk=0,63 do polyfill,corners[pixel*64+ijk < (n1-1),[0,1,2,3,0],0,i_site],$
corners[pixel*64+ijk < (n1-1),[0,1,2,3,0],1,i_site],color=image[pixel*64+ijk < (n1-1),i_site] < top
endif
endfor
endfor
return_lons=1
return_lats=1
if not keyword_set(no_grid) then thm_map_add,invariant_lats=findgen(4)*10.+50.,invariant_color=210,$
invariant_linestyle=1,/invariant_lons,return_lons=return_lons,$
return_lats=return_lats
time=time_string(time_double(time_start)+ikk*3)
if not keyword_set(no_label) then begin
xyouts,0.005,0.018,time,color=xyouts_color,/normal,charsize=chars
xyouts,0.005,0.060,'THEMIS-GBO ASI',color=xyouts_color,/normal,charsize=chars
endif
if (not keyword_set(no_midnight) and midnight_count eq 1) then $
plots,smooth(midlons-360.,5),findgen(40)+40.,color=255,/data
if keyword_set(gif_out) then begin
If(keyword_set(gif_dir)) Then gdir = gif_dir Else gdir = './'
tvlct,r,g,b,/get
img=tvrd()
res=time_struct(time)
year=res.year
month=res.month
day=res.date
hour=res.hour
minute=res.min
second=res.sec
out_name='MOSA.'+year+'.'+month+'.'+day+'.'+hour+'.'+minute+'.'+second+'.gif'
write_gif,gdir+out_name,img,r,g,b
dprint, 'Output in ',out_name
gif_out=out_name
endif
if keyword_set(zbuffer) then zbuffer=tvrd()
if not keyword_set(keep_z) and keyword_set(zbuffer) then begin
device,/close
set_plot,'x'
endif
endfor
endif else begin
if(keyword_set(zbuffer)) then set_plot, 'z'
thm_map_set,scale=map_scale,$
central_lat=central_lat,$
central_lon=central_lon,$
color_continent=color_continent,$
color_background=color_background,$
position=position,$
xsize=xsize,$
ysize=ysize,$
noerase=noerase,$
zbuffer=zbuffer,$
projection=projection,$
window=window,$
rotation=rotation,$
no_color=no_color
if keyword_set(special) then begin
spec_illu=pixel_illuminated-2
for i=0,n_elements(special)-1 do begin
spec_stat=where(strlowcase(site) eq strlowcase(special[i]))
spec_illu[*,spec_stat]=pixel_illuminated[*,spec_stat]
endfor
endif
for pixel=0l,n1-1l do begin
for i_site=0,n_sites-1 do begin
if ((pixel_illuminated[pixel,i_site] eq 1) and $
(elevation[pixel,i_site] gt minimum_elevation_to_plot)) then $
polyfill,corners[pixel,[0,1,2,3,0],0,i_site],$
corners[pixel,[0,1,2,3,0],1,i_site],color=image[pixel,i_site] < top
if keyword_set(special) then if ((spec_illu[pixel*64 < (n1-1),i_site] eq 1) and $
(elevation[pixel*64 < (n1-1),i_site] gt minimum_elevation_to_plot)) then begin
for ijk=0,63 do polyfill,corners[pixel*64+ijk < (n1-1),[0,1,2,3,0],0,i_site],$
corners[pixel*64+ijk < (n1-1),[0,1,2,3,0],1,i_site],color=image[pixel*64+ijk < (n1-1),i_site] < top
endif
endfor
if (keyword_set(special) and pixel ge 1024) then break
endfor
return_lons=1
return_lats=1
thm_map_add,invariant_lats=findgen(4)*10.+50.,invariant_color=210,$
invariant_linestyle=1,/invariant_lons,return_lons=return_lons,$
return_lats=return_lats,no_grid=no_grid
if not keyword_set(no_label) then begin
xyouts,0.005,0.018,time,color=xyouts_color,/normal,charsize=chars
xyouts,0.005,0.060,'THEMIS-GBO ASI',color=xyouts_color,/normal,charsize=chars
endif
if keyword_set(verbose) then dprint, 'After map: ',systime(1)-verbose,$
' Seconds'
if (not keyword_set(no_midnight) and midnight_count eq 1) then $
plots,smooth(midlons-360.,5),findgen(40)+40.,color=255,/data
if keyword_set(add_plot) then stop
if keyword_set(track1) then begin
plots,track1[0,*],track1[1,*],psym=3
endif
if keyword_set(track2) then begin
plots,track2[0,*],track2[1,*],psym=4
endif
if keyword_set(location) then begin
if keyword_set(ssize) then ssize=ssize else ssize=1
if keyword_set(sym_color) then scolor=sym_color else scolor=255
plots,location[0,*],location[1,*],psym=2,symsize=ssize,color=scolor
endif
if keyword_set(cursor) then begin
ss=size(cursor)
xy_cursor=fltarr(cursor,4)
if (ss[1] ne 2) then cursor=1
for loop=1,cursor do begin
dprint, 'Point cursor on map!'
cursor,x,y,/data
wait,0.25
res=convert_coord(x,y,/data,/to_device)
dprint, 'Location: ',res,x,y
xy_cursor[loop-1L,*]=[res[0],res[1],x,y]
endfor
endif
if keyword_set(xy_pos) then begin
dd=size(xy_pos)
if (dd[0] eq 1) then begin
res=convert_coord(xy_pos[0],xy_pos[1],/to_data,/device)
dprint, 'Location: ',xy_pos,res[0:1],format='(a12,2i5,2f10.3)'
xy_pos_out=[xy_pos[0],xy_pos[1],res[0],res[1]]
endif else begin
xy_pos_out=fltarr(dd[1],4)
res=convert_coord(xy_pos[*,0],xy_pos[*,1],/to_data,/device)
for i1=0L,dd[1]-1L do begin
dprint, 'Location: ',xy_pos[i1,*],res[0:1,i1],format='(a12,2i5,2f10.3)'
xy_pos_out[i1,*]=[xy_pos[i1,0],xy_pos[i1,1],res[0,i1],res[1,i1]]
endfor
endelse
xy_pos=xy_pos_out
endif
if keyword_set(gif_out) then begin
If(keyword_set(gif_dir)) Then gdir = gif_dir Else gdir = './'
tvlct,r,g,b,/get
img=tvrd()
img[40:43,0]=[13,251,117,239]
img[0:6,0]=[year/100,year-(year/100)*100,month,day,hour,minute,second]
if keyword_set(thumb) then img[7,0]=1 else img[7,0]=0
if (central_lon lt 0.) then central_lon=central_lon+360.
img[8:12,0]=[fix(central_lon)/100,fix(central_lon)-(fix(central_lon)/100)*100,$
fix((central_lon-fix(central_lon))*100),$
fix(central_lat),fix((central_lat-fix(central_lat))*100)]
res=strsplit(string(map_scale*1.e10),'e',/extract)
img[13:15,0]=[fix(res[0]),fix((float(res[0])-fix(res[0]))*100),fix(res[1])-10]
img[16:19,0]=[xsize/100,xsize-(xsize/100)*100,ysize/100,ysize-(ysize/100)*100]
if keyword_set(rotation) then begin
if (rotation lt 0.) then rotation=rotation+360.
img[20:22,0]=[fix(rotation/100),fix(rotation-(fix(rotation)/100)*100),$
fix((rotation-fix(rotation))*100)]
endif else img[20:22]=[0,0,0]
img[23:24,0]=[fix(minimum_elevation_to_plot),$
fix((minimum_elevation_to_plot-fix(minimum_elevation_to_plot))*100)]
if keyword_set(zbuffer) then img[25,0]=1 else img[25,0]=0
img[49,0]=n_sites
for i1=0,n_sites-1 do begin
case 1 of
finite(bytval[i1]) eq 0: img[50+i1,0]=0
bytval[i1] eq 1.: img[50+i1,0]=1
bytval[i1] gt 1.: img[50+i1,0]=2
endcase
endfor
out_name='MOSA.'+string(year,'(i4.4)')+'.'+string(month,'(i2.2)')+'.'+$
string(day,'(i2.2)')+'.'+string(hour,'(i2.2)')+'.'+string(minute,'(i2.2)')+$
'.'+string(second,'(i2.2)')+'.gif'
write_gif,gdir+out_name,img,r,g,b
dprint, 'Output in ',out_name
gif_out=out_name
tv,img
endif
if keyword_set(zbuffer) then zbuffer=tvrd()
if not keyword_set(keep_z) and keyword_set(zbuffer) then begin
device,/close
set_plot,'x'
endif
endelse
if keyword_set(stoptime) then begin
if keyword_set(timestep) then new_time=time_double(time)+timestep else new_time=time_double(time)+3.d0
res=time_struct(new_time)
year=res.year
month=res.month
day=res.date
hour=res.hour
minute=res.min
second=res.sec
if (new_time le time_double(stoptime)) then begin
time=time_string(new_time)
goto,repeat_loop
endif
endif
if keyword_set(verbose) then dprint, 'Calculation took ',systime(1)-verbose,$
' Seconds'
if double(!version.release) lt 8.0d then heap_gc
if keyword_set(insert) then stop
end