function get_galex_hlsp_data, gl, gb, fov, out, data_dir = data_dir ;+ ; NAME: ; GET_GALEX_HLSP_DATA ; PURPOSE: ; Retrieve data from HLSP files for uv-bkgd public data ; EXPLANATION: ; Murthy (2014) ApJS 213, 32 has derived the diffuse flux from the GALEX surveys. ; These data are available from the HLSP archive at MAST at the ; URL: http://archive.stsci.edu/prepds/uv-bkgd/ and also at ; http://www.iiap.res.in/personnel/murthy/Jayant_Murthy/GALEX_Data.html ; This program will read those data within FOV of the given GL and GB ; into a structure with the following elements: ; 1. Name String Name of the GALEX pipeline file ; 2. Date String Observation date from GALEX pipeline file ; 3. Time String Observation time from GALEX pipeline file ; 4. Fuv_exp_time Long Total exposure time in the FUV band ; 5. Nuv_exp_time Long Total exposure time in the NUV Band ; 6. X Integer Binned pixel in X ; 7. Y Integer Binned pixel in Y ; 8. Glon Float Galactic longitude of pixel ; 9. Glat Float Galactic latitude of pixel ; 10. Ecl_lon Float Ecliptic longitude of pixel ; 11. Ecl_lat Float Ecliptic latitude of pixel ; 12. Sun_ecl_lon Float Ecliptic longitude of Sun ; 13. Sun_ecl_lat Float Ecliptic latitude of Sun ; 14. Fuv_orig Long Binned FUV flux ; 15. Nuv_orig Long Binned NUV flux ; 16. Fuv_ag Long FUV airglow contribution ; 17. Nuv_ag Long NUV airglow contribution ; 18. Nuv_zl Long NUV zodiacal light ; 19. Fuv_final Long Corrected diffuse astrophysical FUV ; 20. Nuv_final Long Corrected diffuse astrophysical NUV ; 21. Fuv_med Long Median FUV for this observation ; 22. Nuv_med Long Median NUV for this observation ; 23. Fuv_min Long Minimum FUV across all visits ; 24. Nuv_min Long Minimum NUV across all visits ; 25. Fuv_std Long Standard deviation across visits ; 26. Nuv_std Long Standard deviation across visits ; 27. Ir100 Float 100 micron emission ; 28. Ebv Float E(B-V) from Schlegel (magnitudes) ; ; Notes: All coordinates are in decimal degrees. The UV fluxes are in ; ph cm-2 s-1 sr-1 A-1. The 100 micron ; is from Schleget et al. (1998) in MJy sr-1. Missing values are ; -9999 and FUV_STD and NUV_STD are set to 50 if there is only one ; visit to a given location. ; ; This may not be the fastest implementation but is written to place no ; significant memory requirements on the user. ; ; CALLING SEQUENCE ; out_sum = get_galex_hlsp_data(gl, gb, fov, out, data_dir = data_dir) ; ; Inputs: ; GL - Galactic longitude of location in degrees ; GB - Galactic latitude of location in degrees ; FOV - Search radius in degrees ; ; Optional Input: ; data_dir - Location of data files. Default is in the running directory. ; ; Outputs: ; OUT - Structure (defined above) containing all rows ; near given location ; out_sum - Five element array with ; out_sum[0] total number of rows ; out_sum[1] weighted FUV ; out_sum[2] Total FUV exposure time ; out_sum[3] Weighted NUV ; out_sum[4] Total NUV exposure time ; ; NOTES: ; GALEX data outside the central 1 degree (radius 15 pixels) may have ; instrumental effects. Use ((data.x - 24)^2 + (data.y - 24)^2) < 225. ; PROCEDURES USED: ; None ; REVISION HISTORY ; Written by Jayant Murthy (jmurthy@yahoo.com): May 2, 2014 ; Named structure: May 9, 2014 ; Modified to return values for single pixels Jun 11, 2014 ; Undeclared variable corrected Jun 23, 2014 ; Changed integer to long Jun 30, 2014 ; Modified comment to exclude data Jul 10, 2014 ; Name changed Jul 24, 2014 ; COPYRIGHT ; Simplified BSD license copied from Wikipedia ; (https://en.wikipedia.org/wiki/BSD_licenses) ; Copyright (c) 2014, Jayant Murthy ; All rights reserved. ; Redistribution and use in source and binary forms, with or without ; modification, are permitted provided that the following conditions are met: ; ; 1. Redistributions of source code must retain the above copyright notice, this ; list of conditions and the following disclaimer. ; 2. Redistributions in binary form must reproduce the above copyright notice, ; this list of conditions and the following disclaimer in the documentation ; and/or other materials provided with the distribution. ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ; ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; ; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ; ; The views and conclusions contained in the software and documentation are those ; of the authors and should not be interpreted as representing official policies, ; either expressed or implied, of the FreeBSD Project. ;- ; Define data structure to hold variables ; Structure as defined by Murthy (2014) data = {galex, name:"", date: "", time: "", fuv_exp_time: 0L, nuv_exp_time: 0L, $ x: 0, y: 0, glon: 0., glat: 0., ecl_lon: 0., ecl_lat: 0., $ sun_ecl_lon: 0., sun_ecl_lat: 0., $ fuv_orig: 0L, nuv_orig: 0L, fuv_ag: 0L, nuv_ag: 0L, nuv_zl: 0L, $ fuv_final: 0L, nuv_final: 0L, fuv_med: 0L, nuv_med: 0L, $ fuv_min: 0L, nuv_min: 0L, fuv_std: 0L, nuv_std: 0L, ir100: 0., ebv: 0.} ;Define initial size as 100,000 units. Will be extended as needed out = replicate(data,100000) ;Location of data files if (not(keyword_set(data_dir))) then data_dir = "." ;Set up the file names as per the HLSP structure nfiles = 18 file_names = replicate({name:"", glat_min: 0., glat_max: 0.}, 18) for i=0,nfiles - 1 do begin file_names(i).glat_min = i*10 - 90 file_names(i).glat_max = i*10 - 80 file_names[i].name = data_dir + "/hlsp_uv-bkgd_galex_diffuse_glat" tmp = string(abs(file_names(i).glat_min),form="(i2)") if (tmp eq ' 0') then tmp = '00' file_names(i).name = file_names(i).name + tmp file_names(i).name = file_names(i).name + "-" tmp = string(abs(file_names(i).glat_max),form="(i2)") if (tmp eq ' 0') then tmp = '00' file_names(i).name = file_names(i).name + tmp if (file_names(i).glat_min lt 0)then $ file_names(i).name = file_names(i).name + "S" $ else file_names(i).name = file_names(i).name + "N" file_names(i).name = file_names(i).name + "_fuv-nuv_v1_table.txt" endfor ;End creating file names. ;Begin data read fuv_total = 0 nuv_total = 0 fuv_time = 0 nuv_time = 0 ;Minimum and maximum Galactic latitude. These are great circles so if the ;latitude difference must be less than the FOV min_gb = gb - fov max_gb = gb + fov ;Convert input coordinates to Cartesian. x = cos(gl/!radeg)*cos(gb/!radeg) y = sin(gl/!radeg)*cos(gb/!radeg) z = sin(gb/!radeg) ;To be used later in the cosine rule acmp = cos(fov/!radeg) index = 0L; Total number of lines in the data array nindex = 100000L; Initial guess at number of rows nlines = 0L ;Check each file to see if we should read it for ifile = 0, nfiles - 1 do begin if ((min_gb le file_names(ifile).glat_max) and $ (max_gb ge file_names(ifile).glat_min)) then begin print,"Reading from ",file_names(ifile).name openr,read_unit,file_names(ifile).name,/get ;Begin reading variables while (not(eof(read_unit))) do begin str="" readf, read_unit, str ;If the first character is '#' the line is a comment line ;Also skip if the line is comprised of spaces. if ((strmid(str,0,1) ne '#') and $ (strlen(strcompress(str,/remove)) gt 0)) then begin nlines = nlines + 1 ;The table is space delimited with 28 columns. ;Break up the input string into its constituent parts. wrds = strsplit(str, /extract) ;Stuff the data structure for i = 0, n_elements(wrds) - 1 do data.(i) = wrds(i) ;Convert the Galactic coordinates of the data points into Cartesian coordinates x1 = cos(data.glon/!radeg)*cos(data.glat/!radeg) y1 = sin(data.glon/!radeg)*cos(data.glat/!radeg) z1 = sin(data.glat/!radeg) ;Use the cosine rule to find those points near the requested location if ((x1*x + y1*y + z1*z) gt acmp)then begin out(index) = data index = index + 1 fuv_exp_time = data.fuv_exp_time fuv_data = data.fuv_final nuv_exp_time = data.nuv_exp_time nuv_data = data.nuv_final if ((fuv_exp_time gt 0) and (fuv_data ge 0))then begin fuv_total = fuv_total + fuv_data*fuv_exp_time fuv_time = fuv_time + fuv_exp_time endif if ((nuv_exp_time gt 0) and (nuv_data ge 0))then begin nuv_total = nuv_total+ nuv_data*nuv_exp_time nuv_time = nuv_time + nuv_exp_time endif ;If there are too many points, I extend the array. Nindex keeps track ;of the maximum size of the array. if (index ge nindex)then begin out = [out, replicate(data, 100000)] nindex = nindex + 100000 endif endif endif endwhile endif ;Check of filenames endfor ;Cut down the array size to the right number out =out(0:index-1) out_sum=fltarr(5) out_sum(0) = nlines out_sum(1) = -9999 out_sum(3) = -9999 if (fuv_time gt 0)then begin out_sum(0) = fuv_total/fuv_time out_sum(1) = fuv_time endif if (nuv_time gt 0) then begin out_sum(2) = nuv_total/nuv_time out_sum(3) = nuv_time endif return,out_sum end