From 0e2773c8073a6d0c157efb948dfd4c913a62bb1a Mon Sep 17 00:00:00 2001 From: jaymurthy Date: Tue, 29 Aug 2017 23:15:43 +0530 Subject: [PATCH] Astrometry addons 1) Added a number of files to do astrometry (at the users risk). 2) Bug fixes. --- #Untitled-1# | 65 +++++++++++ jude_add_frames.pro | 5 +- jude_centroid.pro | 16 ++- jude_coadd.pro | 2 +- jude_driver_uv.pro | 8 +- jude_fuv_astrometry.pro | 65 ++++++----- jude_interactive.pro | 12 +- plot_simbad.pro | 236 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 371 insertions(+), 38 deletions(-) create mode 100644 #Untitled-1# create mode 100644 plot_simbad.pro diff --git a/#Untitled-1# b/#Untitled-1# new file mode 100644 index 0000000..8053288 --- /dev/null +++ b/#Untitled-1# @@ -0,0 +1,65 @@ +-rwxr-xr-x@ 1 jayanth staff 1529 Aug 22 00:48 jude_check_bod.pro +-rwxr-xr-x@ 1 jayanth staff 7880 Aug 22 00:48 jude_cnvt_att_xy.pro +-rwxr-xr-x@ 1 jayanth staff 5186 Aug 22 00:48 jude_coadd.pro +-rwxr-xr-x@ 1 jayanth staff 3112 Aug 22 00:48 jude_create_mask.pro +-rwxr-xr-x@ 1 jayanth staff 2608 Aug 22 00:48 jude_create_uvit_hdr.pro +-rwxr-xr-x@ 1 jayanth staff 19077 Aug 22 00:48 jude_driver_uv.pro +-rwxr-xr-x@ 1 jayanth staff 4278 Aug 22 00:48 jude_driver_vis.pro +-rwxr-xr-x@ 1 jayanth staff 1288 Aug 22 00:48 jude_err_process.pro +-rwxr-xr-x@ 1 jayanth staff 12377 Aug 22 00:48 jude_fuv_astrometry.pro +-rwxr-xr-x@ 1 jayanth staff 2591 Aug 22 00:48 jude_get_files.pro +-rwxr-xr-x@ 1 jayanth staff 8909 Aug 22 00:48 jude_get_xy.pro +-rwxr-xr-x@ 1 jayanth staff 21803 Aug 22 00:48 jude_interactive.pro +-rwxr-xr-x@ 1 jayanth staff 6023 Aug 22 00:48 jude_match_vis_offsets.pro +-rwxr-xr-x@ 1 jayanth staff 10536 Aug 22 00:48 jude_max_resolution.pro +-rwxr-xr-x@ 1 jayanth staff 6596 Aug 22 00:48 jude_merge_files.pro +-rwxr-xr-x@ 1 jayanth staff 9228 Aug 22 00:48 jude_mosaic.pro +-rwxr-xr-x@ 1 jayanth staff 3097 Aug 22 00:48 jude_obs_log.pro +-rwxr-xr-x@ 1 jayanth staff 2240 Aug 22 00:48 jude_params.pro +-rwxr-xr-x@ 1 jayanth staff 6443 Aug 22 00:48 jude_read_hk_files.pro +-rwxr-xr-x@ 1 jayanth staff 4014 Aug 22 00:48 jude_read_vis.pro +-rwxr-xr-x@ 1 jayanth staff 10772 Aug 22 00:48 jude_register_data.pro +-rwxr-xr-x@ 1 jayanth staff 9236 Aug 22 00:48 jude_set_dqi.pro +-rwxr-xr-x@ 1 jayanth staff 4044 Aug 22 00:48 jude_uv_cleanup.pro +-rwxr-xr-x@ 1 jayanth staff 6772 Aug 22 00:48 jude_vis_shifts.pro +-rwxr-xr-x@ 1 jayanth staff 3826 Aug 22 00:48 make_movie.pro +-rwxr-xr-x@ 1 jayanth staff 867 Aug 22 00:48 process_uvit.com +$ +rw-r--r--@ 1 jayanth staff 11358 Aug 29 20:18 LICENSE-2.0.txt +-rw-r--r--@ 1 jayanth staff 219 Aug 29 20:18 README.md +-rw-r--r--@ 1 jayanth staff 1385 Aug 29 20:18 interactive.com +-rw-r--r--@ 1 jayanth staff 9656 Aug 29 20:18 jude_add_frames.pro +-rw-r--r--@ 1 jayanth staff 4954 Aug 29 20:18 jude_add_vis.pro +-rw-r--r--@ 1 jayanth staff 5738 Aug 29 20:18 jude_apply_astrometry.pro +-rw-r--r--@ 1 jayanth staff 1789 Aug 29 20:18 jude_apply_cal.pro +-rw-r--r--@ 1 jayanth staff 4591 Aug 29 20:18 jude_apply_time.pro +-rw-r--r--@ 1 jayanth staff 3374 Aug 29 20:18 jude_call_astrometry.pro +-rw-r--r--@ 1 jayanth staff 15728 Aug 29 20:18 jude_centroid.pro +-rw-r--r--@ 1 jayanth staff 1529 Aug 29 20:18 jude_check_bod.pro +-rw-r--r--@ 1 jayanth staff 7880 Aug 29 20:18 jude_cnvt_att_xy.pro +-rw-r--r--@ 1 jayanth staff 5186 Aug 29 20:18 jude_coadd.pro +-rw-r--r--@ 1 jayanth staff 3112 Aug 29 20:18 jude_create_mask.pro +-rw-r--r--@ 1 jayanth staff 2608 Aug 29 20:18 jude_create_uvit_hdr.pro +-rw-r--r--@ 1 jayanth staff 19292 Aug 29 20:18 jude_driver_uv.pro +-rw-r--r--@ 1 jayanth staff 4278 Aug 29 20:18 jude_driver_vis.pro +-rw-r--r--@ 1 jayanth staff 1288 Aug 29 20:18 jude_err_process.pro +-rw-r--r--@ 1 jayanth staff 12815 Aug 29 20:18 jude_fuv_astrometry.pro +-rw-r--r--@ 1 jayanth staff 2591 Aug 29 20:18 jude_get_files.pro +-rw-r--r--@ 1 jayanth staff 8909 Aug 29 20:18 jude_get_xy.pro +-rw-r--r--@ 1 jayanth staff 21898 Aug 29 20:18 jude_interactive.pro +-rw-r--r--@ 1 jayanth staff 6023 Aug 29 20:18 jude_match_vis_offsets.pro +-rw-r--r--@ 1 jayanth staff 10536 Aug 29 20:18 jude_max_resolution.pro +-rw-r--r--@ 1 jayanth staff 6596 Aug 29 20:18 jude_merge_files.pro +-rw-r--r--@ 1 jayanth staff 9228 Aug 29 20:18 jude_mosaic.pro +-rw-r--r--@ 1 jayanth staff 3097 Aug 29 20:18 jude_obs_log.pro +-rw-r--r--@ 1 jayanth staff 2240 Aug 29 20:18 jude_params.pro +-rw-r--r--@ 1 jayanth staff 6443 Aug 29 20:18 jude_read_hk_files.pro +-rw-r--r--@ 1 jayanth staff 4014 Aug 29 20:18 jude_read_vis.pro +-rw-r--r--@ 1 jayanth staff 10772 Aug 29 20:18 jude_register_data.pro +-rw-r--r--@ 1 jayanth staff 9236 Aug 29 20:18 jude_set_dqi.pro +-rw-r--r--@ 1 jayanth staff 4044 Aug 29 20:18 jude_uv_cleanup.pro +-rw-r--r--@ 1 jayanth staff 6772 Aug 29 20:18 jude_vis_shifts.pro +-rw-r--r--@ 1 jayanth staff 3826 Aug 29 20:18 make_movie.pro +-rw-r--r--@ 1 jayanth staff 8128 Aug 29 20:18 plot_simbad.pro +-rw-r--r--@ 1 jayanth staff 867 Aug 29 20:18 process_uvit.com +$ \ No newline at end of file diff --git a/jude_add_frames.pro b/jude_add_frames.pro index da6881f..cc94419 100644 --- a/jude_add_frames.pro +++ b/jude_add_frames.pro @@ -61,6 +61,8 @@ ;JM: Jul 27, 2017: Corrected reference frame. ;JM: Aug. 12, 2017: Modified time addition to be faster (but still slow). ;JM: Aug. 18, 2017: Corrected crash if xoff or yoff are not passed through +;JM: Aug. 21, 2017: Made Dtime floating instead of double. +;JM: Aug. 27, 2017: Reset ref_frame if required ;Copyright 2016 Jayant Murthy ; ; Licensed under the Apache License, Version 2.0 (the "License"); @@ -118,6 +120,7 @@ if (min_frame eq 0)then min_frame = $ (abs(yoff) lt 1000))) if (n_elements(ref_frame) eq 0)then ref_frame = min_frame +if (ref_frame eq -1)then ref_frame = min_frame while (((abs(xoff[ref_frame]) gt 1000) or (abs(yoff[ref_frame]) gt 1000)) and $ (ref_frame lt (n_elements(data) - 2))) do ref_frame = ref_frame + 1 if (max_frame eq 0) then max_frame = n_elements(data)-1 @@ -239,7 +242,7 @@ endfor ;Put grid into units of either counts per pixel per frame or counts per pixel per s. if (keyword_set(notime))then pixel_time = fltarr(gxsize, gysize) + nframe -if (not(keyword_set(notime)))then pixel_time = pixel_time*dtime/nframe +if (not(keyword_set(notime)))then pixel_time = pixel_time*float(dtime)/nframe q = where(pixel_time gt 0, nq) if (nq gt 0)then grid(q) = grid(q)/pixel_time(q) return,nframe ;Return number of frames diff --git a/jude_centroid.pro b/jude_centroid.pro index 58ac36d..d75a49f 100644 --- a/jude_centroid.pro +++ b/jude_centroid.pro @@ -52,6 +52,7 @@ ;JM: Aug. 02, 2017: Explicitly print number of frames. ;JM: Aug. 03, 2017: Added option to quit. ;JM: Aug. 11, 2017: Nbin is redundant (params.fine_bin) so removed the option +;JM: Aug. 21, 2017: Fixed an inconsistency in passing offsets ;Copyright 2016 Jayant Murthy ; ; Licensed under the Apache License, Version 2.0 (the "License"); @@ -327,7 +328,7 @@ pro jude_centroid, events_file, grid2, params, xstar, ystar, $ if (nq gt 3)then begin quadterp,xindex[q],xcent[q]-xcent[q[0]],findgen(ndata_l2),xoff,missing=-1e6 quadterp,xindex[q],ycent[q]-ycent[q[0]],findgen(ndata_l2),yoff,missing=-1e6 - qmiss = where((xoff gt -1e6) and (yoff gt -1e6),nmiss) + qmiss = where((xoff gt -1e6) or (yoff gt -1e6),nmiss) if (nmiss gt 0) then begin xoff[qmiss] = -xoff[qmiss] @@ -359,10 +360,19 @@ pro jude_centroid, events_file, grid2, params, xstar, ystar, $ tv,bytscl(rebin(h1, siz[0]*4,siz[1]*4),0,max_im_value),512,0 print,"New width is ",a1[2],a1[3] +;Update offsets + qbad = where((xoff le -1e6) or (yoff le -1e6),nqbad) + xoff = xoff/params.resolution + yoff = yoff/params.resolution + if (nqbad gt 0)then begin + xoff[qbad] = -1e6 + yoff[qbad] = -1e6 + endif + data_l2.xoff = xoff + data_l2.yoff = yoff + if (not(keyword_set(nosave)))then begin ;Update original events file - data_l2.xoff = xoff/params.resolution - data_l2.yoff = yoff/params.resolution offsets=mrdfits(events_file,2,off_hdr) sxaddhist,"jude_centroid has been run",data_hdr0 sxaddpar,data_hdr0, "XCENT", xstar_first/params.resolution, "XPOS of centroid star" diff --git a/jude_coadd.pro b/jude_coadd.pro index e1571c4..6b26d37 100644 --- a/jude_coadd.pro +++ b/jude_coadd.pro @@ -10,7 +10,7 @@ ; out_file: FITS image file ; OPTIONAL INPUTS: ; ra_cent: Central RA in degrees -; dec_Cent: Central Dec in degrees +; dec_cent: Central Dec in degrees ; Fov: Field of view in degrees ; pixel_size: Size of each pixel in degrees ; OPTIONAL KEYWORDS: diff --git a/jude_driver_uv.pro b/jude_driver_uv.pro index 8c09677..71d0f1d 100644 --- a/jude_driver_uv.pro +++ b/jude_driver_uv.pro @@ -83,6 +83,9 @@ ; JM: Jul 27, 2017 : Add reference frame to files for astrometry ; JM: Aug. 14, 2017 : Added keyword to time frame. ; JM: Aug. 18, 2017 : No longer run jude_register by default. +; JM: Aug. 21, 2017 : Changed "Number of frames" to Nframes +; JM: Aug. 27, 2017 : Problem with ref_frame due to repeated calls. +; JM: Aug. 28, 2017 : Was writing header improperly for second extension ;Copyright 2016 Jayant Murthy ; ; Licensed under the Apache License, Version 2.0 (the "License"); @@ -375,6 +378,7 @@ endif xoff = data_l2.xoff yoff = data_l2.yoff par = params + ref_frame = -1 ;The notimes is much faster if (keyword_set(notime))then begin nframes = JUDE_ADD_FRAMES(data_l2, grid, pixel_time, par, $ @@ -434,9 +438,9 @@ endif ;Write out the image followed by the exposure times mwrfits,grid,image_name,out_hdr,/create - mkhdr, thdr, pixel_time + mkhdr, thdr, pixel_time,/image if (keyword_set(notime))then begin - sxaddpar,thdr,"BUNIT","Number of frames","Exposure map not applied" + sxaddpar,thdr,"BUNIT","Nframes","Exposure map not applied" endif else begin sxaddpar,thdr,"BUNIT","s","Exposure map" endelse diff --git a/jude_fuv_astrometry.pro b/jude_fuv_astrometry.pro index 7347384..387ef13 100644 --- a/jude_fuv_astrometry.pro +++ b/jude_fuv_astrometry.pro @@ -98,31 +98,32 @@ pro find_point_sources, new_im, x, y, f,new_max_value,xoff,yoff x = 0 & y = 0 & f = 0 thresh = .002 while ((n_elements(x) lt 6) or (n_elements(x) gt 20))do begin - tv,bytscl(rebin(new_im,512,512),0,new_max_value),xoff,yoff find,new_im,x,y,f,s,r,thresh,1.2,[-1.0,1.0],[.2,1.0] - if (n_elements(x) ge 2)then begin - srt = reverse(sort(f)) - x = x[srt] - y = y[srt] - f = f[srt] - for i = 0, n_elements(x) - 2 do begin - for j = i + 1, n_elements(x) - 1 do begin - d1 = sqrt((x[i] - x[j])^2 + (y[i] - y[j])^2) - if (d1 lt 100)then x[j] = -1 - endfor - endfor - endif - q = where(x gt 0, nq) - if (nq gt 0)then begin - x = x[q] - y = y[q] - f = f[q] - endif - plots,/dev,x/8+xoff,y/8+yoff,/psym,col=255,symsize=3 - print,n_elements(x)," stars found." + print,n_elements(x)," stars found with a threshold of ",thresh if (n_elements(x) gt 20) then thresh = thresh*1.5 if (n_elements(x) lt 6) then thresh = thresh/2 endwhile + + if (n_elements(x) ge 2)then begin + srt = reverse(sort(f)) + x = x[srt] + y = y[srt] + f = f[srt] + for i = 0, n_elements(x) - 2 do begin + for j = i + 1, n_elements(x) - 1 do begin + d1 = sqrt((x[i] - x[j])^2 + (y[i] - y[j])^2) + if (d1 lt 100)then x[j] = -1 + endfor + endfor + endif + q = where(x gt 0, nq) + if (nq gt 0)then begin + x = x[q] + y = y[q] + f = f[q] + endif + tv,bytscl(rebin(new_im,512,512),0,new_max_value),xoff,yoff + plots,/dev,x/8+xoff,y/8+yoff,/psym,col=255,symsize=3 end ;**********************END FIND_POINT_SOURCES ********************** @@ -159,11 +160,12 @@ function set_limits, grid2, xstar, ystar, boxsize, resolution,$ end ;*****************END DISPLAY PROGRAMS*************************** -pro jude_fuv_astrometry, new_file, ref_file, both_same = both_same, ref_stars = ref_stars +pro jude_fuv_astrometry, new_file, ref_file, both_same = both_same, $ + ref_stars = ref_stars, new_max_value = new_max_value, ref_max_value = ref_max_value ;Initialization - new_max_value = 0.0002 - ref_max_value = 0.0002 + if (n_elements(new_max_value) eq 0)then new_max_value = 0.0002 + if (n_elements(ref_max_value) eq 0)then ref_max_value = 0.0002 device,window_state = window_state if (window_state[0] eq 0)then $ window, 0, xs = 1024, ys = 512, xp = 10, yp = 500 @@ -190,14 +192,20 @@ pro jude_fuv_astrometry, new_file, ref_file, both_same = both_same, ref_stars = ans = get_kbrd(1) if (ans eq 'y')then read,"New scale factor: ",new_max_value endwhile - tv,bytscl(rebin(ref_im,512,512),0,ref_max_value),512,0 + ans='y' + while (ans eq 'y')do begin + tv,bytscl(rebin(ref_im,512,512), 0, ref_max_value),512,0 + print,"Change scale? " + ans = get_kbrd(1) + if (ans eq 'y')then read,"New scale factor: ",ref_max_value + endwhile ;Read stars from simbad using the file I've already created. The name ;of the file must be simbad.csv, just because it was easier. nstars = read_simbad_stars(names, ra, dec, stype, mag, xtest, ytest, ztest) ;If I've already figured out my useful stars, I don't need to find them again. if (n_elements(ref_stars) gt 0)then begin - refra = ref_stars[*,0] + refra = ref_stars[*,0] refdec = ref_stars[*,1] ad2xy, refra, refdec, ref_astr, refxp, refyp endif else begin @@ -332,6 +340,11 @@ pro jude_fuv_astrometry, new_file, ref_file, both_same = both_same, ref_stars = endif endfor +;Save stars for future. + openw,ref_lun,"ref_stars.txt",/get_lun + printf,ref_lun,newra + printf,ref_lun,newdec + free_lun,ref_lun ;Calculate astrometry using either solve astro or starast if (n_elements(newxp) gt 5)then begin astr = solve_astro(newra, newdec, newxp, newyp, distort = 'tnx') diff --git a/jude_interactive.pro b/jude_interactive.pro index 3e4a1b8..7336054 100644 --- a/jude_interactive.pro +++ b/jude_interactive.pro @@ -40,7 +40,9 @@ ; JM: Aug. 11, 2017 : If defaults = 2 then I don't run centroiding or write events file. ; JM: Aug. 14, 2017 : Added keywords to time header ; JM: Aug. 16, 2017 : Modified defaults as per table below -; JM: Aug. 22, 2017 : Minor typo +; JM: Aug. 21, 2017 : Minor typo +; JM: Aug. 21, 2017 : Problem in offsets if centroid was quit +; JM: Aug. 28, 2017 : Was writing header incorrectly for second extension. ;Copyright 2016 Jayant Murthy ; ; Licensed under the Apache License, Version 2.0 (the "License"); @@ -476,8 +478,8 @@ print,"Starting centroid" xoff = xoff_cent, yoff = yoff_cent,$ /nosave, defaults = defaults, /new_star,$ max_im_value = max_im_value, display = display - xoff_sc = xoff_cent/params.resolution - yoff_sc = yoff_cent/params.resolution + xoff_sc = xoff_cent + yoff_sc = yoff_cent endif ;Final image production @@ -571,9 +573,9 @@ print,"Starting centroid" t = data_dir + uv_base_dir + params.image_dir + imname + ".fits" print,"writing image file to ",t mwrfits,grid,t,out_hdr,/create - mkhdr, thdr, pixel_time + mkhdr, thdr, pixel_time, /image if (keyword_set(notime))then begin - sxaddpar,thdr,"BUNIT","Number of frames","Exposure map not applied" + sxaddpar,thdr,"BUNIT","Ns","Exposure map not applied" endif else begin sxaddpar,thdr,"BUNIT","s","Exposure map" endelse diff --git a/plot_simbad.pro b/plot_simbad.pro new file mode 100644 index 0000000..1be4454 --- /dev/null +++ b/plot_simbad.pro @@ -0,0 +1,236 @@ +;+ +; NAME: JUDE_FUV_ASTROMETRY +; PURPOSE: Apply astrometry to one image by comparison with another that is +; already corrected +; CALLING SEQUENCE: +; jude_new_astrometry, new_file, ref_file, both_same = both_same, ref_stars = ref_stars +; INPUTS: +; New_file : File to be corrected astrometrically. +; Ref_file : File with accurate astrometry +; OUTPUTS: +; None : New file is updated with correct astrometry +; OPTIONAL INPUT KEYWORDS: +; Both_same : If set, there is no rotation between files. Otherwise, +; the NUV data have to be rotated and reflected. +; Ref_stars : array with two rows: ra and dec +; NOTES: +; Data files are written out as per the original names +; MODIFICATION HISTORY: +; JM: Aug. 18, 2017 +;Copyright 2016 Jayant Murthy +; +; Licensed under the Apache License, Version 2.0 (the "License"); +; you may not use this file except in compliance with the License. +; You may obtain a copy of the License at +; +; http://www.apache.org/licenses/LICENSE-2.0 +; +; Unless required by applicable law or agreed to in writing, software +; distributed under the License is distributed on an "AS IS" BASIS, +; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +; See the License for the specific language governing permissions and +; limitations under the License. +; +;- + +;************************* READ_SIMBAD_STARS *********************** +;If I have a list of stars from Simbad, I use that. +function read_simbad_stars, names, ra, dec, stype, mag, xtest, ytest, ztest + +;If I enter this script into Simbad, I will get a list of stars around my +;specified position. The first few lines have to be deleted. +;****************************Sample Simbad Script ******************* +;format object form1 "%IDLIST(1) : %COO(d2;C) : %OTYPE(S) : %FLUXLIST(B;F) " +;set radius 20m +;query coo 198.315d -19.53d +;format displa +;********DELETE the first few lines until the start of the data +;********************************************************************** +;Read stars from the Simbad text file + spawn,"wc -l simbad.csv",str + wrds = strsplit(str, /extract) + nstars = long(wrds[0]) + stars = strarr(nstars) + openr,1,"simbad.csv" + readf,1,stars + close,1 + +;Variables for the Simbad stars + names = strarr(nstars) + ra = dblarr(nstars) + dec = dblarr(nstars) + stype = strarr(nstars) + mag = fltarr(nstars) + 9999 + +;Extract the ra, dec, mag + for i = 0, nstars - 1 do begin + if (strcompress(stars[i],/rem) ne '')then begin + wrds = strsplit(stars[i], /extract, ':') + names[i] = wrds[0] + w2 = strsplit(wrds[1],/extract) + ra[i] = double(w2[0]) + dec[i] = double(w2[1]) + stype[i] = wrds[2] + if (strcompress(wrds[3],/rem) ne '')then $ + mag[i] = float(wrds[3]) else $ + mag[i] = 9999 + endif + endfor + +;Order by magnitude remembering that the brightest have the least magnitude. + s = sort(mag) + ra = ra[s] + dec = dec[s] + stype = stype[s] + mag = mag[s] + names = names[s] + +;Convert to Cartesian coordinates. + xtest = cos(ra/180d*!dpi)*cos(dec/180d*!dpi) + ytest = sin(ra/180d*!dpi)*cos(dec/180d*!dpi) + ztest = sin(dec/180d*!dpi) + return, nstars +end +;********************** END READ_SIMBAD_STARS *********************** + +;********************* FIND_POINT_SOURCES ************************* +pro find_point_sources, new_im, x, y, f,new_max_value,xoff,yoff + x = 0 & y = 0 & f = 0 + thresh = .002 + while ((n_elements(x) lt 6) or (n_elements(x) gt 20))do begin + find,new_im,x,y,f,s,r,thresh,1.2,[-1.0,1.0],[.2,1.0] + print,n_elements(x)," stars found with a threshold of ",thresh + if (n_elements(x) gt 20) then thresh = thresh*1.5 + if (n_elements(x) lt 6) then thresh = thresh/2 + endwhile + + if (n_elements(x) ge 2)then begin + srt = reverse(sort(f)) + x = x[srt] + y = y[srt] + f = f[srt] + for i = 0, n_elements(x) - 2 do begin + for j = i + 1, n_elements(x) - 1 do begin + d1 = sqrt((x[i] - x[j])^2 + (y[i] - y[j])^2) + if (d1 lt 100)then x[j] = -1 + endfor + endfor + endif + q = where(x gt 0, nq) + if (nq gt 0)then begin + x = x[q] + y = y[q] + f = f[q] + endif + tv,bytscl(rebin(new_im,512,512),0,new_max_value),xoff,yoff + plots,/dev,x/8+xoff,y/8+yoff,/psym,col=255,symsize=3 + +end +;**********************END FIND_POINT_SOURCES ********************** + +;**********************DISPLAY PROGRAMS *********************** +pro display_image, im, max_value, x, y, xpos, ypos + tv,bytscl(rebin(im, 512, 512), 0, max_value),xpos, ypos + plots,/dev, x/8. + xpos, y/8. + ypos, psym=4, symsize=3, col=255 +end + +function set_limits, grid2, xstar, ystar, boxsize, resolution,$ + xmin = xmin, ymin = ymin, display = display + siz = size(grid2) + ndim = siz[1] + xmin = xstar - boxsize*resolution + xmax = xstar + boxsize*resolution + ymin = ystar - boxsize*resolution + ymax = ystar + boxsize*resolution + + xmin = 0 > xmin < (ndim - 1) + xmax = (xmin + 1) > xmax < (ndim - 1) + ymin = 0 > ymin < (ndim - 1) + ymax = (ymin + 1) > ymax < (ndim - 1) + + if (keyword_set(display))then begin + plots,/dev, [xmin, xmin, xmax, xmax, xmin]/resolution,$ + [ymin, ymax, ymax, ymin, ymin]/resolution,$ + col=255,thick=2 + endif + if (((xmax - xmin) lt 5) or ((ymax - ymin) lt 5)) then begin + h1 = fltarr(2*boxsize*resolution, 2*boxsize*resolution) + endif else h1 = grid2[xmin:xmax, ymin:ymax] + return,h1 +end +;*****************END DISPLAY PROGRAMS*************************** + +pro plot_simbad, ref_file, refra, refdec, refx, refy, ref_max_value = ref_max_value + +;Initialization + if (n_elements(ref_max_value) eq 0)then ref_max_value = 0.0002 + device,window_state = window_state + if (window_state[0] eq 0)then $ + window, 0, xs = 1024, ys = 512, xp = 10, yp = 500 + +;Read data from image files + ref_im = mrdfits(ref_file, 0, ref_hdr, /silent) + extast, ref_hdr, ref_astr + ref_time = mrdfits(ref_file, 1, ref_thdr, /silent) + ans='y' + while (ans eq 'y')do begin + tv,bytscl(rebin(ref_im,512,512), 0, ref_max_value),0,0 + print,"Change scale? " + ans = get_kbrd(1) + if (ans eq 'y')then read,"New scale factor: ",ref_max_value + endwhile +;Read stars from simbad using the file I've already created. The name +;of the file must be simbad.csv, just because it was easier. + nstars = read_simbad_stars(names, ra, dec, stype, mag, xtest, ytest, ztest) + +;If I've already figured out my useful stars, I don't need to find them again. + if (n_elements(ref_stars) gt 0)then begin + refra = ref_stars[*,0] + refdec = ref_stars[*,1] + ad2xy, refra, refdec, ref_astr, refxp, refyp + endif else begin + find_point_sources, ref_im, refxp, refyp, reffp, ref_max_value, 0, 0 + xy2ad, refxp, refyp, ref_astr, refra, refdec + endelse + nrefpoints = n_elements(refxp) + tv,bytscl(rebin(ref_im,512,512), 0, ref_max_value),512,0 + +;I now have a list of stars with good astrometry where I've identified the +;x and y with ra and dec. +;I calculate the ra and dec in Cartesian coordinates. + radeg = 180d/!dpi + refx = cos(refra/radeg)*cos(refdec/radeg) + refy = sin(refra/radeg)*cos(refdec/radeg) + refz = sin(refdec/radeg) + simb_stars = lonarr(nrefpoints) + for istar = 0, nrefpoints - 1 do begin + plots,/dev,refxp[istar]/8+512,refyp[istar]/8,psym=6,symsize=3 + dst = acos(refx[istar]*xtest + refy[istar]*ytest + refz[istar]*ztest)*radeg*3600d + simb_stars[istar] = where(dst eq min(dst)) + str = "Identified NUV " + string(istar) + " with " + str = str + " " + names[simb_stars[istar]] + " at " + string(min(dst)) + print,strcompress(str) + endfor + +ans='' +print,"continue?" +ans = get_kbrd(1) + +;Check each star +for istar = 0, nrefpoints - 1 do begin + tv,bytscl(rebin(ref_im,512,512), 0, ref_max_value),0,0 + plots,/dev,refxp[istar]/8.,refyp[istar]/8.,psym=6,symsize=3,thick=2,col=255 + h1 = set_limits(ref_im, refxp[istar], refyp[istar], 5, 8, xmin=xmin, ymin = ymin) + siz = size(h1, /dimens) + tv,bytscl(rebin(h1, siz(0)*5, siz(1)*5),0, ref_max_value),512,0 + r1 = mpfit2dpeak(h1, a1) + plots,(refxp[istar]-xmin)*5 + 512,(refyp[istar] - ymin)*5,/psym,/dev,symsize=3,thick=2,col=255 + plots,a1[4]*5 + 512, a1[5]*5,psym=6,/dev,symsize=3,thick=2,col=255 + dst = sqrt((a1[4] - (refxp[istar] - xmin))^2 + (a1[5] - (refyp[istar] - ymin))^2) + print,names[simb_stars[istar]]," ",dst + ans = get_kbrd(1) +endfor + + +noproc: + end