; docformat = 'rst' ; ; NAME: ; genoidHeaderBDD ; PURPOSE: ; Create a simple FITS header for ingestion in audela/BDD ; ;+ ; :Description: ; Create a simple FITS header for ingestion in audela/BDD ; ; :Categories: ; Disk I/O, Genoid ; ; :Return: Upon success, the header formated for audela/bdd in a ; string array. If fails, return codes are:: ; -1: Syntax error ; ; :Params: ; image: in, required, type=fltarr ; The image for which the header will be constructed ; header: in, required, type=strarr ; The header associated with the image ; target: in, optional, type=string ; The target identifier ; ; :Keywords: ; type: in, optional, type=string, default='IMG' ; The type of data IMG | CORONO1 | CORONO2 ; ; :Uses: ; mkHdr, extAst, sxPar, sxAddPar, sxDelPar ; ; :Author: ; B.Carry (OCA) ; ; :History: ; Change History:: ; Written in July 2017, B. Carry (OCA) ; 2017 Dec - B. Carry (OCA) - Correct bug on CDELT2 ; 2019 Jan - B. Carry (OCA) - Added Start time and saturation keywords ; 2019 Jan - B. Carry (OCA) - Focal length and pixel physical size added ; 2019 Jan - B. Carry (OCA) - Corrected CRPIX & CRVAL from windowing ; 2023 Feb - B. Carry (OCA) - Patched EQUINOX when missing ;- function genoidHeaderBDD, image, header, target, type=type COMPILE_OPT hidden, idl2 ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- I -- Initialization And Input Verification -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--I.1-- Syntax Validation -------------------------------------------------------------------; if N_params() LT 2 then begin message, 'syntax: header = genoidHeaderBDD( im, header )' return, -1 endif ;--I.2-- Retrieve Homogeneous Keywords from Header -------------------------------------------; ;--I.2.1-- Observatory and Instrument iau = getTelescopeCode(header) tel = getTelescopeId(header) cam = getCameraId(header) saturation = getCameraSaturation(header, tel, cam) ;--I.2.2-- Exposure Details filter = getCameraFilter(header, tel, cam) coords = getCameraCoords(header, tel, cam) pixel = getCameraPixel(header, tel, cam) dit = getCameraDIT(header, tel, cam) pa = getCameraPA(header, tel, cam) ;--I.2.3-- Correction of Coordinates tSplit=strSplit(target,'_',/Extract) targetEph = tSplit[1] eph = sspEphemCC( targetEph, dit.start, nbd=1 ) coords.ra = eph[0].ra.deg coords.dec = eph[0].dec.deg ;--I.3-- Default Parameters ------------------------------------------------------------------; if not keyword_set(type) then type='IMG' ;--I.4-- Useful Constants --------------------------------------------------------------------; MJDtoJD = 2400000.5d ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- II -- Basic Header Creation and Astrometry -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--II.1-- Create the Basic Header ------------------------------------------------------------; mkHdr, h, image ;--II.1.1-- Add comments on NAXISi Keywords sxAddPar, h, 'NAXIS1', sxPar(h,'NAXIS1'), ' Length of data axis 1' sxAddPar, h, 'NAXIS2', sxPar(h,'NAXIS2'), ' Length of data axis 2' ;--II.1.2-- ByteScale bScale = sxPar( header, 'BSCALE', count=nbKey) if nbKey eq 0 then bScale=1 sxAddPar, h, 'BSCALE', bScale, ' Default scaling factor', after='NAXIS2' ;--II.1.3-- ByteZero bZero = sxPar( header, 'BZERO', count=nbKey) if nbKey eq 0 then bZero=0 sxAddPar, h, 'BZERO', bZero, ' Offset data range to that of unsigned short', after='BSCALE' ;--II.2-- Astrometry Keywords are Available --------------------------------------------------; extAst, header, astrom ; extAst, h, astrom if total(size(astrom)) ne 0 then begin ;--II.2.1-- Set Basic Astrometry Keywords putAst, h, astrom ;--II.2.2-- Clean Basic Astrometry Keywords if sxPar(header,'EQUINOX') eq 0 then begin sxAddPar, h, 'EQUINOX', 2000, ' Equinox of Ref. Coord.' endif else begin sxAddPar, h, 'EQUINOX', sxPar(header,'EQUINOX'), ' Equinox of Ref. Coord.' endelse RADESYS = sxPar(h,'RADESYS') if not keyword_set(RADESYS) then RADESYS=sxPar(h,'RADECSYS') sxDelPar, h, 'RADESYS' sxAddPar, h, 'RADESYS', RADESYS, ' Reference frame', after='EQUINOX' sxDelPar, h, 'RADECSYS' sxAddPar, h, 'RADECSYS', RADESYS, ' Reference frame', before='RADESYS' ;--II.2.3-- Additional Astrometry Keywords: Coordinates sxAddPar, h, 'CRPIX1', round(sxPar(h,'NAXIS1')/2.), ' Reference Pixel in X' sxAddPar, h, 'CRPIX2', round(sxPar(h,'NAXIS2')/2.), ' Reference Pixel in Y' sxAddPar, h, 'CRVAL1', coords.ra, ' R.A. (degrees) of reference pixel' sxAddPar, h, 'CRVAL2', coords.dec, ' Declination of reference pixel' sxAddPar, h, 'RA', sxPar(h,'CRVAL1'), ' R.A. (degrees) of reference pixel', after='RADESYS' sxAddPar, h, 'DEC', sxPar(h,'CRVAL2'), ' Declination of reference pixel', after='RA' ;--II.3-- Ad Hoc Astrometry Keywords ---------------------------------------------------------; endif else begin ;--II.3.1-- Set Basic Astrometry Keywords sxAddPar, h, 'CTYPE1', 'RA---TAN', ' Coordinate Type' sxAddPar, h, 'CTYPE2', 'DEC--TAN', ' Coordinate Type' sxAddPar, h, 'EQUINOX', 2000.00000000, ' Equinox of Ref. Coord.' sxAddPar, h, 'RADESYS', 'FK5', ' Reference frame' ;--II.3.2-- Set Coordinate Astrometry Keywords sxAddPar, h, 'RA', coords.ra, ' R.A. (degrees) of reference pixel' sxAddPar, h, 'DEC', coords.dec, ' Declination of reference pixel' sxAddPar, h, 'CD1_1', cos(pa*!DTOR)*pixel.resol/3600., ' Degrees / Pixel' sxAddPar, h, 'CD1_2', -sin(pa*!DTOR)*pixel.resol/3600., ' Degrees / Pixel' sxAddPar, h, 'CD2_1', sin(pa*!DTOR)*pixel.resol/3600., ' Degrees / Pixel' sxAddPar, h, 'CD2_2', cos(pa*!DTOR)*pixel.resol/3600., ' Degrees / Pixel' sxAddPar, h, 'CRPIX1', round(sxPar(h,'NAXIS1')/2.), ' Reference Pixel in X' sxAddPar, h, 'CRPIX2', round(sxPar(h,'NAXIS2')/2.), ' Reference Pixel in Y' sxAddPar, h, 'CRVAL1', coords.ra, ' R.A. (degrees) of reference pixel' sxAddPar, h, 'CRVAL2', coords.dec, ' Declination of reference pixel' ;--II.3.3-- Set Time Keywords sxAddPar, h, 'DATE-OBS', dit.start, 'Start of exposure ISO 8601' MJD = date_conv(dit.start,'JULIAN')-MJDtoJD sxAddPar, h, 'MJD-OBS', MJD, ' Modified Julian day of observations', before='DATE-OBS' endelse ;--II.4-- Additional Astrometry Keywords -----------------------------------------------------; ;--II.4.1-- Additional Astrometry Keywords: Unit and Reference Frame sxAddPar, h, 'CUNIT1', 'deg', ' Unit of coordinate axe 1', after='CTYPE2' sxAddPar, h, 'CUNIT2', 'deg', ' Unit of coordinate axe 2', after='CUNIT1' sxAddPar, h, 'TIMESYS', 'UTC', ' Time Scale', after='DATE-OBS' sxAddPar, h, 'WCSAXES', 2, ' WCS dimensionality', after='RADESYS' ;--II.4.2-- Additional Astrometry Keywords: Binning sxAddPar, h, 'BIN1', 1, ' Binning along axe 1', after='NAXIS2' sxAddPar, h, 'BIN2', 1, ' Binning along axe 2', after='BIN1' ;--II.4.3-- Additional Astrometry Keywords: Pixel Size and Orientation sxAddPar, h, 'CDELT1', sxPar(h,'CD1_1'), ' X scale deg/pix', after='CRVAL2' sxAddPar, h, 'CDELT2', sxPar(h,'CD2_2'), ' Y scale deg/pix', after='CDELT1' sxAddPar, h, 'CROTA2', pa, ' Rotation deg', after='CDELT2' ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- III -- Target and Exposure Details -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--III.1-- Target, Airmass & Observer --------------------------------------------------------; ;--III.1.1-- Target Identifier if keyword_set(target) then sxAddPar, h, 'OBJECT', target, ' Target' $ else sxAddPar, h, 'OBJECT', '', ' Target' ;--III.1.2-- Airmass sxAddPar, h, 'AIRMASS', coords.airmass, ' Airmass of target at observing time' ;--III.1.3-- Observers observer = sxPar(header,'OBSERVER', count=nbKey) if nbKey eq 0 then observer='' sxAddPar, h, 'OBSERVER', observer, ' Observer names' ;--III.2-- Exposure --------------------------------------------------------------------------; tExp = dit.DIT * dit.NDIT sxAddPar, h, 'EXPOSURE', tExp, ' Total time of exposure s' ;--III.3-- Filter ----------------------------------------------------------------------------; ;--III.3.1-- Filter Identifier sxAddPar, h, 'FILTER', filter.id, ' Filter symbol' ;--III.3.2-- Filter Details sxAddPar, h, 'CENTRWV', filter.central, ' Filter central wavelength A' sxAddPar, h, 'BANDWID', filter.width, ' Filter band width A' sxAddPar, h, 'WAVEMAX', filter.max, ' Filter maximal wavelength A' sxAddPar, h, 'WAVEMIN', filter.min, ' Filter minimal wavelength A' ;--III.4-- Ambient Conditions ----------------------------------------------------------------; sxAddPar, h, 'FWHM', 0., ' Full Width at Half Maximum pixels' sxAddPar, h, 'CCD_TEMP', 0., ' Actual CCD temperature Celsius degrees ' ;--III.5-- Sky Background --------------------------------------------------------------------; sxAddPar, h, 'BGMEAN', 0., ' Mean value for background pixels adu' sxAddPar, h, 'BGSIGMA', 0., ' Std sigma value for background pixels adu' ;--III.6-- Saturation on Target --------------------------------------------------------------; pSatur = where( image ge saturation, nbSatur ) if nbSatur ge 100 then saturBool=1 else saturBool=0 sxAddPar, h, 'SATURED', saturBool,' Is the primary saturated? 1:yes/0:no', after='PRIM-dF' ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- IV -- Telescope and Instrument Details -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--IV.1-- Telescope Name and IAU Code --------------------------------------------------------; sxAddPar, h, 'ORIGIN', tel, ' Origin place of FITS image' sxAddPar, h, 'TELESCOP', tel, ' Telescope name' sxAddPar, h, 'IAU-CODE', iau, ' Observatory IAU code' ;--IV.2-- Telescope Topographic Location -----------------------------------------------------; sxAddPar, h, 'OBS-ELEV', 0., ' Elevation above sea of observatory m' sxAddPar, h, 'OBS-LAT' , 0., ' Geodetic observatory latitude deg' sxAddPar, h, 'OBS-LONG', 0., ' East-positive observatory longitude deg' ;--IV.3-- Instrument Identifier --------------------------------------------------------------; sxAddPar, h, 'CAMERA', CAM, ' Camera name' sxAddPar, h, 'INSTRUME', CAM, ' Instrument name' ;--IV.4-- Instrument Root Characteristics ----------------------------------------------------; ;--IV.4.1-- Focal Length sxAddPar, h, 'FOCLEN' , pixel.focLen, ' Equivalent focal length m' ;--IV.4.2-- Pixel Physical Size sxAddPar, h, 'XPIXSZ' , pixel.size, ' Pixel width micron' sxAddPar, h, 'YPIXSZ' , pixel.size, ' Pixel height micron' ;--IV.4.3-- Pixel Pseudo Physical Size After Binning sxAddPar, h, 'PIXSIZE1', 0., ' X Pixel size after binning micron' sxAddPar, h, 'PIXSIZE2', 0., ' Y Pixel size after binning micron' ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- V -- Date - ISO JD -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--V.1-- Retrieve Mid-Observing Time ---------------------------------------------------------; midObsTime = sxpar( header, 'DATE-OBS' ) expTime = sxPar( header, 'EXPTIME' ) startJD = date_conv(midObsTime,'JULIAN') - 0.5*expTime/86400. startISO= date_conv(startJD,'FITS') midJD = date_conv( midObsTime, 'JULIAN' ) midISO = date_conv( midObsTime, 'FITS' ) ;--V.2-- Set DATE-OBS and Mid-Observing Time -------------------------------------------------; sxAddPar, h, 'DATE-OBS', startISO, ' Exposure starting time (ISO)', after='EXPOSURE' sxAddPar, h, 'MJD-OBS', midJD-MJDtoJD, ' Exposure mid-time (MJD)', after='DATE-OBS' sxAddPar, h, 'MID-OBS', midISO,' Mid-observing time (JD)', after='MJD-OBS' ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--- TAG --- V -- Processing Information, Cleaning -----------------------; ;-----------------------------------------------------------------------------------------------; ;-----------------------------------------------------------------------------------------------; ;--VI.1-- Processing Information -------------------------------------------------------------; sxAddPar, h, 'SWCREATE', 'IDL redIM' , ' Acquisition software' sxAddPar, h, 'SWMODIFY', 'IDL binarIM', ' Processing software' sxAddPar, h, 'BIMTYPE', type, ' Level of image processing' ;--VI.2-- Keyword Cleaning -------------------------------------------------------------------; sxDelPar, h, 'DATE' sxDelPar, h, 'COMMENT' sxDelPar, h, 'HISTORY' ;--VI.3-- Return Header ----------------------------------------------------------------------; return, h end