; ; PURPOSE: Produce cumulative (in time and BB/host) files ; ;goto, do_it nodata = -9999 ; Run to recognise ENVI routines: envi, /restore_base_save_files envi_batch_init ; --------------------------------------------------------------------------------------------- ; set up ; --------------------------------------------------------------------------------------------- method_str = ['MA_FHPR1-R4'] ;method_str = ['NKT_FHPR1-R4'] ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; define parameters of data set ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - num_x = 1886 num_y = 2216 beg_year = 1997 end_year = 2018 year_arr = makex(beg_year,end_year,1) num_years = n_elements(year_arr) dir_prefix = '/Users/jhicke/work/data/insects/ads/updated_ids_grids/ids_grids/updated_aerialsurvey_grids_for_public_distribution/' ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; get all filenames to determine host/BB combinations ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - all_filename_arr = file_search(dir_prefix+method_str+'/'+'us_????_'+method_str+'*capped.hdr') all_filename_arr = all_filename_arr.replace(dir_prefix+method_str+'/','') for i=0,n_elements(all_filename_arr)-1 do $ ; 'us_YYYY_' = 8 chars all_filename_arr[i] = strmid(strmid(all_filename_arr[i],0,strlen(all_filename_arr[i])-4),9+strlen(method_str),100) uniq_bbhost_str_arr = all_filename_arr[uniq(all_filename_arr,sort(all_filename_arr))] num_uniq_bbhost = n_elements(uniq_bbhost_str_arr) print print,'current num_uniq_bbhost = ',num_uniq_bbhost print pause ; ---------------------------------------------------------------------------------- ; mapping set up ; ---------------------------------------------------------------------------------- x_map_ul_ul = -2374500.0000d y_map_ul_ul = 3189500.0000d delta_xy = 1000.d ; m x_map_center_arr = (x_map_ul_ul - delta_xy/2.) + findgen(num_x)*delta_xy y_map_center_arr = reverse((y_map_ul_ul - delta_xy/2.) - findgen(num_y)*delta_xy) x_map_center_img = x_map_center_arr y_map_center_img = y_map_center_arr gengrid,x_map_center_img,y_map_center_img ; open for projection info (only) i = 20 j = 10 tmp_filename = file_search(dir_prefix+method_str+'/'+'us_'+string(year_arr[j],format='(i4.4)')+'_'+method_str+'_'+uniq_bbhost_str_arr[i],count=cnt) envi_open_file,tmp_filename,r_fid=fid,/no_interactive_query,/no_realize if (fid eq -1) then stop,'problems' envi_convert_projection_coordinates,x_map_center_img,y_map_center_img,envi_get_projection(fid=fid), $ lon_center_grid_albers,lat_center_grid_albers,envi_proj_create(/geographic,datum='WGS-84') limit = [lat_center_grid_albers[ 0,n_elements(lat_center_grid_albers[0,*])/2], $ lon_center_grid_albers[ 0,n_elements(lat_center_grid_albers[0,*])/2], $ lat_center_grid_albers[n_elements(lon_center_grid_albers[*,0])/2,n_elements(lat_center_grid_albers[0,*])-1], $ lon_center_grid_albers[n_elements(lon_center_grid_albers[*,0])/2,n_elements(lat_center_grid_albers[0,*])-1], $ lat_center_grid_albers[n_elements(lon_center_grid_albers[*,0])-1,n_elements(lat_center_grid_albers[0,*])/2], $ lon_center_grid_albers[n_elements(lon_center_grid_albers[*,0])-1,n_elements(lat_center_grid_albers[0,*])/2], $ lat_center_grid_albers[n_elements(lon_center_grid_albers[*,0])/2, 0], $ lon_center_grid_albers[n_elements(lon_center_grid_albers[*,0])/2, 0]] ; --------------------------------------------------------------------------------------------- ; read files to calculate time series of cumulative (across BB/host) maps, looping over each BB/host combo ; --------------------------------------------------------------------------------------------- cum_ma_imgyeararr = fltarr(num_x,num_y,num_years) tmp_bb_ma_img = fltarr(num_x,num_y ) for i=0,num_uniq_bbhost-1 do begin print,i,' of ',num_uniq_bbhost-1,' ',uniq_bbhost_str_arr[i] for j=0,num_years-1 do begin filename_arr = file_search(dir_prefix+method_str+'/'+'us_'+string(year_arr[j],format='(i4.4)')+'_'+method_str+'_'+uniq_bbhost_str_arr[i],count=cnt) if (cnt eq 1) then begin filename = filename_arr[0] openr,lun,filename,/get_lun readu,lun,tmp_bb_ma_img free_lun,lun ; note call to reverse() to flip upside down so southernmost row is at 0 ; ">0" converts nodata (-9999) to 0 for adding cum_ma_imgyeararr[*,*,j] += reverse(tmp_bb_ma_img,2)>0 endif endfor endfor ; --------------------------------------------------------------------------------------------- ; calculate cumulative across years ; --------------------------------------------------------------------------------------------- cum_ma_img = total(cum_ma_imgyeararr,3) ; --------------------------------------------------------------------------------------------- ; write out cumulative files ; --------------------------------------------------------------------------------------------- for j=0,num_years-1 do begin filename = dir_prefix+method_str+'/'+'us_'+string(year_arr[j],format='(i4.4)')+'_'+method_str+'_cumu' write_envi_bin,filename,cum_ma_imgyeararr[*,*,j] spawn,'cp '+tmp_filename+'.hdr '+filename+'.hdr',/sh endfor filename = dir_prefix+method_str+'/'+'us_'+method_str+'_cumu' write_envi_bin,filename,cum_ma_img ; add map, projection info to .hdr file by hand ; --------------------------------------------------------------------------------------------- ; produce figure ; --------------------------------------------------------------------------------------------- do_it: lj,51 if (method_str eq 'MA_FHPR1-R4' ) then ra = [0,50] if (method_str eq 'NKT_FHPR1-R4') then ra = [0,1e5] map_set,23.0,-96.0,/albers,standard_parallels=[29.5,45.5],limit=limit,noborder=1,/usa,/isotropic,xmargin=xmargin tvim,cum_ma_img < (max(ra)*.99),/sc,ra=ra,posi=boxpos(/get),/noframe map_set,23.0,-96.0,/albers,standard_parallels=[29.5,45.5],limit=limit,noborder=1,/cont,/noerase,/usa,/isotropic,xmargin=xmargin write_png_jah,'cumulative_'+method_str+'.png' end