./0040777000151400000240000000000007330355741010177 5ustar phallgames./doc/0040777000151400000240000000000007215457706010752 5ustar phallgames./doc/trim.hlp0100644000151400000240000001174106417124276012423 0ustar phallgames.help trim Feb95 phiirs .ih NAME trim -- create constant-rms image with a certain minimum exposure time .ih USAGE trim image mask stats .ih PARAMETERS .ls image Image (or image list) to trim .le .ls mask Exposure map or list (default=image//em) .le .ls stats File to contain trimmed image RMS values .le .sp .ls out="trim" Prefix for trimmed images .le .ls mingoodexp=0.36 Minimum acceptable exptime (fraction of maximum) .le .ih DESCRIPTION trim allows you to trim an image so that only areas with a certain minimum exposure time are included in the output image. The default minimum exposure time is 0.36 of the maximum, which corresponds to a limiting magnitude 0.55 mags (=2.5*log10(sqrt(0.36))) shallower than the deeper part of the image. Similarly, 0.83 corresponds to 0.1 mag, and 0.91 to 0.05 mag. These shallower areas (typically around the edges of the mosaic) are perfectly good, just complicated to calibrate. The output image also includes a 5-pixel-wide border around the minimum exposure time area so that FOCAS will not toss out images lying within the minimum exptime area. .sp Along with the output image, a companion exposure map is created, as well as a mask image which blocks out all areas with less than the minimum exposure time. The RMS of the image(s) is calculated using maskstat with this mask and output to the specified file. .sp The output image is normalized by its exposure map so that the RMS is constant across the image. Thus the image can be directly input to object detection programs such as FOCAS. The detection significance of objects is constant across the output image (ie a 3sig detection is correct regardless of location on the image) **BUT THE MAGNITUDE SCALE IS NOT CONSTANT!** (The edges of the image have been divided by some factor <~2 to bring the RMS down, so the magnitudes of objects near the edges will be erroneously faint.) .sp If you set mingoodexp >= 0.83, the edge magnitudes will be accurate to <=10%. But if mingoodexp = 0.36 (the default and minimum recommended), you should do the following to correct the magnitudes of objects detected in the trimmed image. (With mingoodexp=0.36, the shallowest 3-sigma limiting magnitude in the resulting image will be equal to the deepest 5-sigma limiting magnitude, approximately. This allows you to uniformly detect objects down to the deepest 5-sigma limiting magnitude if you require only a 3-sigma detection.) .sp First, produce a list of the objects' INTEGER x,y coordinates and their total COUNTS. (If necessary, convert from magnitudes back to counts.) For example, in FOCAS: .sp .nf filter H < outimage.cat > outimage.cat catlist x y Ltotal < outimage.cat >> untrim.image .fi .sp Then run the following IRAF script (available as untrim.cl). It's slow, but it works; hopefully someday "imedit" will be able to do the job faster. It requires insertion of the photometric zeropoint and a value for the counts corresponding to whatever limit you're interested in (ie. 1 sigma/arcsec limit, or, more likely, the counts corresponding to an object at the 3sigma limiting magnitude in the deepest part of the image. The optional steps can be used to limit the effects of bad pixels on the exposure map in the central region of the image. Bad pixels are really a separate effect but were incorporated with the exposure map anyway since they do increase the RMS noise; however, they don't affect the true exposure time for that pixel. Thus for accuracy in this step one should add to the exposure map the sigma in the central exposure time produced by the bad pixels. .sp .nf imar outimage * (insert_desired_limit_counts_here) untrim.imagetmp.imh list="untrim.image" while (fscan (list, i, j, z) !=EOF) { imdel ("tmp.imh", ver-, >& "dev$null") imar("outmaskmask["//i//":"//i//","//j//":"//j//"]", "*", z, "tmp.imh") imcopy ("tmp.imh", "untrim.imagetmp.imh["//i//":"//i//","//j//":"//j//"]") imdel ("tmp.imh", ver-, >& "dev$null") } imcopy outmask outmasktmp #optional imar outmasktmp + 0.03 outmasktmp #optional imreplace outmasktmp 1. lower=1. upper=INDEF imcalc untrim.imagetmp.imh,outmasktmp untrim.image.imh "(insert_zeropoint_here)-2.5*log10(im1/(sqrt(im2)))" imdel outmasktmp ver- imdel untrim.imagetmp.imh ver- list="untrim.image" while (fscan (list, i, j, z) !=EOF) { imstat("untrim.image.imh["//i//":"//i//","//j//":"//j//"]", fields="mean", format-, >> "untrim.image.truemags") } .fi .sp The file "untrim.image.truemags" contains the corrected magnitudes of each object. The image "untrim.image.imh" can be used to compute the area surveyed as a function of magnitude; directly so if the 3sigma limiting object magnitude was used as the limiting counts value in the "untrim.cl" script. .sp .sp Output: .sp out//img trimmed image .sp out//mask NORMALIZED exposure map for trimmed image .sp out//mask//"mask" exposed/unexposed area mask for trimmed image .sp stats file of trimmed image RMS values (from maskstat) .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS .ih SEE ALSO addring, fileroot, maskstat, sigmanorm, untrim .endhelp ./doc/irshift2.hlp0100644000151400000240000000406706551206201013171 0ustar phallgames.help irshift2 Mar96 phiirs .ih NAME irshift2 -- measure object positions in two frames & make geomap input file .ih USAGE irshift2 refimage inimage prefix suffix .ih PARAMETERS .le .ls refimage Name of reference image .le .ls inimage Name of input image .le .ls prefix Prefix string for output files .le .ls suffix Suffix string for output files .le .sp .ls radius Imexamine aperture photometry radius .le .ls buffer Imexamine sky buffer .le .ls width Imexamine sky annulus width .le .ih DESCRIPTION This task calls the following other tasks: filecalc. .sp This task allows you to measure the positions of objects in two images of the same field. The measured positions are then formatted for input to the geomap task, which will calculate the offsets, rotation, and scaling between them. .sp The task displays the reference and input images and brings up "imexam". Get the coordinates (type 'a'), in the reference image, of an object that also appears in the input image. Repeat this as many times as desired. THE OBJECT COORDINATES **MUST** ALTERNATE REF/IN, REF/IN, etc. .sp When you are done, type 'q' to quit. The imexam logfile will be displayed for editing, in case mistakes were made. Then the coordinates are formatted for input to geomap. The following "prefix.*.suffix" files are created: .sp *.geomapin.* geomap input file listing reference & input image object coords .sp *.georefin.* (imexam logfile) objects' coordinates in both images .sp The *.geomapin.* file can be used as input to "images.geomap" or (preferably) "immatch.geomap". The latter is preferable because it allows explicitly for different fitting geometries, such as shifts + rotation, shifts + rescaling + rotation, etc. The task syntax should be .sp geomap *.geomapin.* *.geomapout.* INDEF INDEF INDEF INDEF fitgeo=rscale .sp Other parameters can be left with their default values. Parameters extracted from the *.geomapout.* file can then be used as input to "irrotate". .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS .ih SEE ALSO irrotate, immatch.geomap, images.geomap .endhelp ./doc/piscesfirst.hlp0100644000151400000240000000611406671256112014001 0ustar phallgames.help piscesfirst Jan99 phiirs .ih NAME piscesfirst -- subtract dark & add header params to Steward Observatory images .ih USAGE piscesfirst imagelist darksub badmask .ih PARAMETERS .ls imagelist List of images to process (do not use an `@') .le .ls darksub Boolean: subtract off dark frame? .le .ls badmask Name of bad pixel mask to add to image header .le .ls dark Name of dark frame to subtract .le .ls darkstring String to be appended to dark-subtracted images .le .ls coords Boolean: add RA, DEC, and EPOCH to image header? .le .ls airmass Boolean: Insert the airmass into the header of the image? .le .ls airauto Boolean: find the airmass of the image automatically? If airauto=no, you will be asked to enter the airmass or each image as the parameter `airval'. .le .ls airval Value of the airmass, if not finding it automatically. .le .ls epoch Epoch of the coordinates. .le .ls ra Right Ascension (surround the string with quotes to ensure proper formatting). .le .ls dec Declination (surround the string with quotes to ensure proper formatting). .le .ls observatory Observatory where observations were made (e.g. kpno, ctio, mtbigelow, mmto). .le .ls ut Boolean: is `TIME-OBS' in header ut or not? Needed for proper formatting of UT header keyword, which is needed for proper calculation of the airmass. .le .ls ddmmyy Boolean: is `DATE-OBS' in header in day/month/year format or not? Needed for proper formatting of `OBS-DATE', which is needed for proper calculation of the airmass. OBS-DATE should ALWAYS have format DD/MM/YY. .le .ih DESCRIPTION This routine adds various parameters to the IRAF image headers of images from the Steward Observatory PISCES 1024^2 array, and optionally subtracts the specified dark frame from them. Thus the dark-subtracted images also contain the header parameters added to the raw images. They also contain the additional header card "DARKSUB" which lists the image used in the dark-subtraction. .sp Note that North is RIGHT and East is UP on raw PISCES images. .sp The automatically added header params are: .sp 1. BPM and BPMASK: bad pixel mask. .sp 2. GAIN and RDNOISE: 8. and 25. respectively for PISCES. .sp 3. time-obs: copy of 'time' (usually, but not alwasys, UT time of observation) .sp 4. obs-date: date of observation, in DD/MM/YY format. .sp 5. ut: universal time, sometimes = time-obs in original header, and sometimes equals time-obs + 7h. .sp The following parameters are optionally entered: .sp 6. epoch, ra, dec: entered as parameters .sp 7. st: Sidereal Time. This is calculated from the ut, obs-date, and observatory using the task astutil.asttimes and entered into the header if the airmass is being automatically entered. .sp 8. airmass: calculated from epoch, ra, dec, st, and obs-date if not entered manually. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS They're everywhere! They're crawling all over me!! .sp Also, the airmass+ airauto+ option assumes you're observing from the MST time zone. This hasn't been fixed simply because most image headers already have the airmass parameter in them. .ih SEE ALSO cfhtfirst, first, irimfirst, irtffirst, onisfirst .endhelp ./doc/irtfcoadd.hlp0100644000151400000240000003107306502623426013403 0ustar phallgames.help ircoadd Mar96 phiirs .ih NAME ircoadd -- produce coadded image and exposure map .ih USAGE ircoadd comblist outimage expmap shiftlist scaling zeroing weighting magfac stack logfile .ih PARAMETERS .ls comblist List of images to combine .le .ls outimage Name of output coadded image .le .ls expmap Name of output exposure map image, which gives the weighted number of seconds of exposure that went into each pixel in the coadded image. .le .ls shiftlist File with image shifts. These should be INTEGERS (for best results, take the exact shifts and round them off (file `prefix.roundoff.suffix' from irshift) rather than truncate them) UNLESS parameter magfac>1, in which case they should be the exact image shifts (file `prefix.shiftexact.suffix' from irshift). .le .ls scaling Imcombine scaling factors (none|@file|!|etc.). If scaling=@filename AND "filename" does not exist, default scalings will be calculated that correct for extinction relative to a specified airmass. These scaling factors will then be combined with additional scaling factors (that correct for nonphotometric conditions, etc.) if desired. The final scaling factors can then optionally be inserted into the image headers and multiplied into the images prior to imcombining. .le .ls zeroing Imcombine zero-level offsets (@file|none|mode|!|etc.). If zeroing=@filename and "filename" does not exist, the iterative median of all images will be found, the average found, and "filename" created and filled with zero offsets for each image calculated as "average - iterative median". Note that the offsets found this way cannot be used within imcombine with weighted coadding, as some of the offsets will be negative. Set prescale=yes to get around this problem. .le .ls weighting Imcombine weights (none|@file|!|mode|etc.). If weighting=@filename and "filename" does not exist, the iterative variances of all images will be found (after pre-scaling) and combined with the exposure times (from the header keyword given by `expname') to produce the optimum weights=exptime/variance, which will then be listed in the newly created file "filename". .le .ls magfac Magnification factor for subpixel shifting (min=1, max=10). NOTE that this parameter should be set to the appropriate value even if the block-replication has been done with `irrotate' prior to starting this task. This ensures that e.g. the zero-level offsets will be properly recalculated if need be. .le .ls stack Boolean: Combine images by stacking & projecting? .le .ls logfile Name of log file .le .sp .ls newmask=no Boolean: override bad pixel masks listed in image headers? .le .ls badmask Bad pixel mask to use instead .le .ls spshift=no Boolean: Do image shifts account for subpixel shifting? .le .ls prescale=no Boolean: Scale images before, not during, imcombine? .le .ls unscale=yes Boolean: Undo scaling factors when done? .le .ls extcoeff Extinction coefficient for default scalings .le .ls airzero Airmass to scale images to? (INDEF=minimum airmass of all images in comblist) .le .ls scalecombine=no Boolean: Combine default & additional scalings? Note that these will only be used if the default scalings file does not yet exist and is created during the task. .le .ls morescalename @filename or !keyword for additional scalings .le .ls putscale Boolean: Insert scaling factors into image headers? .le .ls wordscale="SCALEFAC" Scaling factor header keyword .le .ls defscale=no Boolean: Do scales include default airmass scaling? .le .ls prezero=no Boolean: Do zero offseting before, not during, imcombine? .le .ls unzero=yes Boolean: Undo zero offsets when done? .le .ls putzero=no Boolean: Insert zero offsets into image headers? .le .ls wordzero="ZEROVAL" Zero offset header keyword .le .ls putweight=no Boolean: Insert weights into image headers? .le .ls wordweight="WEIGHT" Weighting factor header keyword .le .ls stackimage Name of stacked image .le .ls unstack Boolean: delete stacked image when done? .le .ls spscale=no Boolean: Do zero offsets account for subpixel shifting? .le .ls expname="EXPTIME" Header keyword for exposure time .le .ls maskedstat=no Boolean: Use `maskstat' with iterstat option, instead of just `iterstat', when finding default zero offsets and weights? The difference between the two is almost always insignificant, and maskstat is slower. .le .ls statfile="" File to for image statistics from iterstat or maskstat. This file will be created if it doesn't exist, to save time in later iterations of task. If it already exists, the statistics will be read in from it rather than recalculated. .le .ls stdpars=yes Boolean: Use standard imcombine parameters for coadd? These parameters are combine=average, rej=sigclip, zeros given by `zeroing' (default = iterative median), scales given by `scaling' (default = none), weight given by `weighting' (default = none), expname=expname, lsig=hsig=5., nkeep=1, mclip+. NOTE that the GAIN and READNOISE parameters are still taken from imcoaddpars if stdpars=yes, as are the SIGSCALE, MASKTYPE, and MASKVAL parameters. .le .ls makeavg=no Boolean: Make pure coadd (comb=average,rej=none)? Note that otherwise the parameters are the same as when stdpars=yes. .le .ls flip=no Boolean: Flip image L-R after coadd? .le .ls cleanup=yes Boolean: Clean up blkrep'd images after use? .le .ls tpl=no Boolean: Account for throughput correction in normalization map? .le .ls imcoaddpars Parameter set for imcombine operation used in coadding. GAIN and READNOISE parameters are located here. See help page for imcombine for description. The files "phiirs$ircoadd256.par", "phiirs$ircoaddirim.par", and "phiirs$ircoaddirtf.par" contain default params for the SO 256^2 array, the KPNO IRIM array, and the IRTF NSFCAM array, respectively. .le .ih DESCRIPTION This task is exactly the same as ircoadd.cl, but has been reworked to use perl scripts instead of the CTIO package (unavailable at IRTF). You will need to edit the source code to include the correct path names of the perl scripts. .sp This task coadds the input images using the specified integer-pixel offsets, producing a coadded image, an exposure map, and an *.imshifts file listing images & offsets used by the photcheck and masklet tasks. The parameters for imcombine can be specified directly in the "imcoaddpars" parameter set, or default parameters "stdpars" or "makeavg" can be used. NOTE that even in those cases, the GAIN, READNOISE, SIGSCALE, MASKTYPE, and MASKVAL parameters are still taken from imcoaddpars. .sp The following steps are performed, in this order: .sp .nf 1. Scale images by number of internal coadds, if necessary. 2. Calculate default (multiplicative) scaling factors that correct for extinction relative to a specified airmass if desired, combine these scaling factors with additional scaling factors (that correct for nonphotometric conditions, etc.) if desired, insert scaling factors into image headers if desired, and multiply the images by the scaling factors before imcombine, if desired. 3. Calculate default (additive) zero level offsets using iterative (and masked, if desired) medians and insert into image headers if desired. 4. Determine default weights (=exptime/variance, where the variance is the square of the iterative (and optionally masked) rms of the image) and put into file if desired, and/or insert weights into image headers if desired. 5. Block replicate images and calculate subpixel shifts if desired, adjusting zero offsets as necessary. 6. Implement (additive) zero level offsets before imcombine if desired. 7. Coadd as requested, stacking if necessary. Will not overwrite an output image. 8. Set output image airmass to average of input image airmasses if default airmass scaling was not used, otherwise set it to the specified airmass to which all images were normalized. 9. Normalize image to the maximum total exposure time that went into it. 10. Flip image left-right if desired. 11. Undo pre-imcombine zero offsets if desired. 12. Undo pre-imcombine scalings if desired. 13. Create exposure maps & coadd them into a coadded-image exposure map, if the latter doesn't already exist. 14. Create the *.imshifts file, listing images & offsets, used by tasks "photcheck" to check the photometric stability of the data and "masklet" to produce individual image object masks from the coadded-image object mask. .fi .sp The default imcombine parameters were chosen after considerable experimentation. Don't mess with them unless you have time to kill. Seriously, I've found them to work quite well in all cases so far. However, if you do experiment with different imcombine parameters, the task `photcomp' is a useful task for quickly and easily comparing the photometric differences between two images on the same coordinate system (i.e. the same set of images coadded two different ways). .sp .sp EXPOSURE MAPS .sp Coadded-image exposure maps (the weighted exposure time at each pixel) are generated using the following procedure. We imcombine the individual exposure map images (divided by the throughput correction, if desired) in the same way as the actual images, except with scale=zero=none, to get the (weighted) average exposure time (in seconds) at each pixel. We multiply this by the plfile produced in that imcombine modified to give the number of images used at each pixel. Then we multiply this by the overall unweighted exposure time and divide by the overall weighted exposure time. If no weighting was used, that last factor is just unity. If weighting was used, this factor can be seen to be correct as follows: .sp .nf exposure map = number_of_images map * weighted_average_exptime map * overall unweighted exptime / overall weighted exptime = number_of_images map * overall unweighted exptime * weighted_average_exptime map / overall weighted exptime = number_of_images map * overall unweighted exptime * fractional_weighted_average_exptime map = maximum integration time possible at that pixel * weighted fraction of that time used in imcombine .fi .sp It is suggested that if weighting is used, the weights be calculated outside of imcombine, and inserted into a file. This allows for an accurate weighted exposure map to be generated in all cases, and for the weighted exposure time to be correctly calculated if stacking is done. .sp This task calls tasks addcomment, iterstat, fileroot, filecalc, and stsdas.toolbox.imgtools.imcalc. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS 1. There is a known bug (IRAF buglog #244) in imcombine (all versions prior to V2.11) possibly applicable to the default parameters for this task: .sp When combine=average, reject=(sigclip, avsigclip, ccdclip, or pclip), and mclip=yes (the value of mclip does not matter for pclip) the average will be incorrect if the number of low pixels rejected is greater than the number of unrejected pixels. For example if 3 low pixels are rejected and only 2 pixels remain then the final average will be incorrect for that pixel. There is no workaround other than to avoid this combination of parameters. .sp The default parameter set has combine=average, reject=ccdclip, and mclip=yes. However, in coadding IR images, one typically deals with more than a dozen images, and so it is very unlikely that more low pixels will be rejected than the number of unrejected pixels. Thus the default parameters have not been changed to ensure avoiding this bug, as it is unlikely to arise in practice. .sp .sp 2. Only one bad pixel mask is allowed when stack=yes (this is a shortcoming of imcombine). If the first image in the list has an individual bad pixel mask (e.g. due to holes in the sky-subtracted image), that bad pixel mask will be used for the stacked image. This can be avoided by using newmask=yes, but the individual bad pixel masks can only be implemented in this case by multiplying the images by their individual bad pixel masks before running the task. .sp Note that this will not give correct results if you are coadding images which have been artificially set to the same image size but which have different sized areas of good data. In that case, you should set bad pixels not to zero but to some large negative number (e.g. -99999) and then set i_lthresh in imcoaddpars to a slightly less negative number (e.g. -10000). Thus those pixels will be excluded from consideration when making the coadded image. .sp .sp 3. Weighted coadding cannot be used with the default zero level offsets, since some of those are negative. Workaround is to set prezero=yes. .ih SEE ALSO irshift, irrotate, masklet, mkobjmask, photcomp, photcheck .endhelp ./doc/tpl.hlp0100644000151400000240000000722405754237324012252 0ustar phallgames.help tpl Feb95 phiirs .ih NAME tpl -- create throughput correction image .ih USAGE tpl rootname imagelist outname .ih PARAMETERS .ls rootname Rootname for output log files, etc. .le .ls imagelist List of images to use to create throughput image .le .ls outname Name of throughput image to create .le .ls ncols=256. Number of columns in output image .le .ls nlines=256. Number of columns in output image .le .ls radius=10. Aperture photometry radius for imexamine .le .ls buffer=5. Aperture photometry sky buffer for imexamine .le .ls width=10. Aperture photometry sky annulus width for imexamine .le .ls fit Boolean: Adjust parameters and refit image? .le .ls z Number of image to save? .le .ls tplpars Utilities.Surfit parameter set .le .ih DESCRIPTION tpl allows you to create a throughput correction image from a set (preferably a large grid taken at one time) of standard star images. .sp The throughput or "tpl" (thousand points of light) correction corrects fluxes for the differing optical paths that lead to differentt areas of the array. The IR secondary being undersized is the root of the problem. If the secondary was big enough, all parts of the chip could follow their optical path back through the scope and end up at the secondary, and this correction would not be needed. But since the secondary is undersized, different parts of the chip have different fractions of the secondary contributing to the image; i.e. at the edges of the chip some of the rays from the secondary are occulted, reducing the flux of the star and as a side effect allowing light from a bit of sky to reach the chip directly. .sp The way to correct for this is to take an 11x11 grid of exposures on a standard stars, take the fluxes of the object in all 121 grid positions, and fit a 2-D surface to the chip (typical residuals 3%), assuming that the transparancy & airmass were approximately constant during all 121 observations. You should see that the throughput is higher at the center of the array. This "flat" can be divided into all your images after the flatfielding and sky-subtraction steps, and before coadding. .sp tpl works as follows: .sp First, the input images are displayed in sequence and imexam is brought up for each of them. You should find the standard star flux by hitting 'a' in each image. When done, or if the image is bad, hit 'n' to go to the next image. After the last image, or to skip this stage if you've already done it, hit 'q'. .sp The following parameters from the imexam output from each image are output to a file: x y flux npix sky. A rough error is calculated as "sqrt(flux+npix*sky)/flux" and the x y flux err values are used by the utilities.surfit task to create an image representing the throughput at each point on the array. .sp The fitting procedure can be repeated with different parameters to try and improve the fit. When you reply "yes" to "Adjust parameters and refit image?", you are first allowed to edit the x y flux err input file, and then adjust the surfit fitting parameters. When you have obtained a satisfactory fit, type in the number of the image you wish to save-- the temporary fitting images have a "_#" suffix appended to them, where # is an integer. Only one image can be saved. .sp When the fitting loop is exited, the image is normalized to a maximum of unity, and it and the input file used to create it are saved. .sp Output: .sp outname output tpl image .sp log.rootname.tplcount file used to create outname .sp log.rootname.tplimex raw imexam output .sp log.rootname.tplsurf utilities.surfit log file .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS .ih SEE ALSO .endhelp ./doc/cfhtfirst.hlp0100644000151400000240000000367206671256066013455 0ustar phallgames.help cfhtfirst Dec98 phiirs .ih NAME cfhtfirst -- add header params to raw CFHT KIR images & maybe subtract darks .ih USAGE cfhtfirst imagelist darksub badmask .ih PARAMETERS .ls imagelist List of images to process (do not use an `@') .le .ls darksub Boolean: subtract off dark frame? .le .ls badmask Name of bad pixel mask to add to image header .le .ls dark Name of dark frame to subtract .le .ls darkstring String to be appended to dark-subtracted images .le .ls observatory = cfht Observatory where observations were made (e.g. kpno, ctio, mtbigelow, mmto). .le .ls ddmmyy = yes Boolean: is `DATE-OBS' in header in day/month/year format or not? Needed for proper formatting of `OBS-DATE', which is needed for proper calculation of the airmass. OBS-DATE should ALWAYS have format DD/MM/YY. .le .ls echog = yes Boolean: beep when task is done? .le .ih DESCRIPTION This routine adds various parameters to the IRAF image headers of IR images, and then subtracts the specified dark frame from them. Thus the dark-subtracted images also contain the header parameters added to the raw images. They also contain the additional header card "DARKSUB" which lists the image used in the dark-subtraction. .sp The automatically added header params are: .sp 1. BPM and BPMASK: bad pixel mask. .sp 2. UT and ST: Universal & Sidereal time (copied from UTIME & SIDTIME) .sp 3. coadds: number of internal coadds. This is taken from the RDTMODE header card; it is different from 1 only if RDTMODE=COADD* .sp 4. exptime: total exposure time. This is equal to the exposure time per coadd (given by INTTIME) times the number of coadds. .sp 5. obs-date: date of observation, in DD/MM/YY format. .sp 6. date-obs: date of observation in new millenium format YYYY-MM-DD (old DATE-OBS is saved as DATEORIG header card). .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS They're everywhere! They're crawling all over me!! .ih SEE ALSO first, irimfirst, irtffirst, onisfirst, piscesfirst .endhelp ./doc/ircoadd.hlp0100644000151400000240000003056206665432175013064 0ustar phallgames.help ircoadd Mar96 phiirs .ih NAME ircoadd -- produce coadded image and exposure map .ih USAGE ircoadd comblist outimage expmap shiftlist scaling zeroing weighting magfac stack logfile .ih PARAMETERS .ls comblist List of images to combine .le .ls outimage Name of output coadded image .le .ls expmap Name of output exposure map image, which gives the weighted number of seconds of exposure that went into each pixel in the coadded image. .le .ls shiftlist File with image shifts. These should be INTEGERS (for best results, take the exact shifts and round them off (file `prefix.roundoff.suffix' from irshift) rather than truncate them) UNLESS parameter magfac>1, in which case they should be the exact image shifts (file `prefix.shiftexact.suffix' from irshift). .le .ls scaling Imcombine scaling factors (none|@file|!|etc.). If scaling=@filename AND "filename" does not exist, default scalings will be calculated that correct for extinction relative to a specified airmass. These scaling factors will then be combined with additional scaling factors (that correct for nonphotometric conditions, etc.) if desired. The final scaling factors can then optionally be inserted into the image headers and multiplied into the images prior to imcombining. .le .ls zeroing Imcombine zero-level offsets (@file|none|mode|!|etc.). If zeroing=@filename and "filename" does not exist, the iterative median of all images will be found, the average found, and "filename" created and filled with zero offsets for each image calculated as "average - iterative median". Note that the offsets found this way cannot be used within imcombine with weighted coadding, as some of the offsets will be negative. Set prezero=yes (and prescale=yes if necessary) to get around this problem. .le .ls weighting Imcombine weights (none|@file|!|mode|etc.). If weighting=@filename and "filename" does not exist, the iterative variances of all images will be found (after pre-scaling) and combined with the exposure times (from the header keyword given by `expname') to produce the optimum weights=exptime/variance, which will then be listed in the newly created file "filename". .le .ls magfac Magnification factor for subpixel shifting (min=1, max=10). NOTE that this parameter should be set to the appropriate value even if the block-replication has been done with `irrotate' prior to starting this task. This ensures that e.g. the zero-level offsets will be properly recalculated if need be. .le .ls stack Boolean: Combine images by stacking & projecting? .le .ls logfile Name of log file .le .sp .ls newmask=no Boolean: override bad pixel masks listed in image headers? .le .ls badmask Bad pixel mask to use instead .le .ls spshift=no Boolean: Do image shifts account for subpixel shifting? .le .ls prescale=no Boolean: Scale images before, not during, imcombine? .le .ls unscale=yes Boolean: Undo scaling factors when done? .le .ls extcoeff Extinction coefficient for default scalings .le .ls airzero Airmass to scale images to? (INDEF=minimum airmass of all images in comblist) .le .ls scalecombine=no Boolean: Combine default & additional scalings? Note that these will only be used if the default scalings file does not yet exist and is created during the task. .le .ls morescalename @filename or !keyword for additional scalings .le .ls putscale Boolean: Insert scaling factors into image headers? .le .ls wordscale="SCALEFAC" Scaling factor header keyword .le .ls defscale=no Boolean: Do scales include default airmass scaling? .le .ls prezero=no Boolean: Do zero offseting before, not during, imcombine? .le .ls unzero=yes Boolean: Undo zero offsets when done? .le .ls putzero=no Boolean: Insert zero offsets into image headers? .le .ls wordzero="ZEROVAL" Zero offset header keyword .le .ls putweight=no Boolean: Insert weights into image headers? .le .ls wordweight="WEIGHT" Weighting factor header keyword .le .ls stackimage Name of stacked image .le .ls unstack Boolean: delete stacked image when done? .le .ls spscale=no Boolean: Do zero offsets account for subpixel shifting? .le .ls expname="EXPTIME" Header keyword for exposure time .le .ls maskedstat=no Boolean: Use `maskstat' with iterstat option, instead of just `iterstat', when finding default zero offsets and weights? The difference between the two is almost always insignificant, and maskstat is slower. .le .ls statfile="" File to use for image statistics from iterstat or maskstat. This file will be created if it doesn't exist, to save time in later iterations of task. If it already exists, the statistics will be read in from it rather than recalculated. .le .ls stdpars=yes Boolean: Use standard imcombine parameters for coadd? These parameters are combine=average, rej=sigclip, zeros given by `zeroing' (default = iterative median), scales given by `scaling' (default = none), weight given by `weighting' (default = none), expname=expname, lsig=hsig=5., nkeep=1, mclip+. NOTE that the GAIN and READNOISE parameters are still taken from imcoaddpars if stdpars=yes, as are the SIGSCALE, MASKTYPE, and MASKVAL parameters. .le .ls makeavg=no Boolean: Make pure coadd (comb=average,rej=none)? Note that otherwise the parameters are the same as when stdpars=yes. .le .ls flip=no Boolean: Flip image L-R after coadd? .le .ls cleanup=yes Boolean: Clean up blkrep'd images after use? .le .ls tpl=no Boolean: Account for throughput correction in normalization map? .le .ls imcoaddpars Parameter set for imcombine operation used in coadding. GAIN and READNOISE parameters are located here. See help page for imcombine for description. The files "phiirs$ircoadd256.par", "phiirs$ircoaddirim.par", and "phiirs$ircoaddirtf.par" contain default params for the SO 256^2 array, the KPNO IRIM array, and the IRTF NSFCAM array, respectively. .le .ih DESCRIPTION This task coadds the input images using the specified integer-pixel offsets, producing a coadded image, an exposure map, and an *.imshifts file listing images & offsets used by the photcheck and masklet tasks. The parameters for imcombine can be specified directly in the "imcoaddpars" parameter set, or default parameters "stdpars" or "makeavg" can be used. NOTE that even in those cases, the GAIN, READNOISE, SIGSCALE, MASKTYPE, and MASKVAL parameters are still taken from imcoaddpars. .sp The following steps are performed, in this order: .sp .nf 1. Scale images by number of internal coadds, if necessary. 2. Calculate default (multiplicative) scaling factors that correct for extinction relative to a specified airmass if desired, combine these scaling factors with additional scaling factors (that correct for nonphotometric conditions, etc.) if desired, insert scaling factors into image headers if desired, and multiply the images by the scaling factors before imcombine, if desired. 3. Calculate default (additive) zero level offsets using iterative (and masked, if desired) medians and insert into image headers if desired. 4. Determine default weights (=exptime/variance, where the variance is the square of the iterative (and optionally masked) rms of the image) and put into file if desired, and/or insert weights into image headers if desired. 5. Block replicate images and calculate subpixel shifts if desired, adjusting zero offsets as necessary. 6. Implement (additive) zero level offsets before imcombine if desired. 7. Coadd as requested, stacking if necessary. Will not overwrite an output image. 8. Set output image airmass to average of input image airmasses if default airmass scaling was not used, otherwise set it to the specified airmass to which all images were normalized. 9. Normalize image to the maximum total exposure time that went into it. 10. Flip image left-right if desired. 11. Undo pre-imcombine zero offsets if desired. 12. Undo pre-imcombine scalings if desired. 13. Create exposure maps & coadd them into a coadded-image exposure map, if the latter doesn't already exist. 14. Create the *.imshifts file, listing images & offsets, used by tasks "photcheck" to check the photometric stability of the data and "masklet" to produce individual image object masks from the coadded-image object mask. .fi .sp The default imcombine parameters were chosen after considerable experimentation. Don't mess with them unless you have time to kill. Seriously, I've found them to work quite well in all cases so far. However, if you do experiment with different imcombine parameters, the task `photcomp' is a useful task for quickly and easily comparing the photometric differences between two images on the same coordinate system (i.e. the same set of images coadded two different ways). .sp .sp EXPOSURE MAPS .sp Coadded-image exposure maps (the weighted exposure time at each pixel) are generated using the following procedure. We imcombine the individual exposure map images (divided by the throughput correction, if desired) in the same way as the actual images, except with scale=zero=none, to get the (weighted) average exposure time (in seconds) at each pixel. We multiply this by the plfile produced in that imcombine modified to give the number of images used at each pixel. Then we multiply this by the overall unweighted exposure time and divide by the overall weighted exposure time. If no weighting was used, that last factor is just unity. If weighting was used, this factor can be seen to be correct as follows: .sp .nf exposure map = number_of_images map * weighted_average_exptime map * overall unweighted exptime / overall weighted exptime = number_of_images map * overall unweighted exptime * weighted_average_exptime map / overall weighted exptime = number_of_images map * overall unweighted exptime * fractional_weighted_average_exptime map = maximum integration time possible at that pixel * weighted fraction of that time used in imcombine .fi .sp It is suggested that if weighting is used, the weights be calculated outside of imcombine, and inserted into a file. This allows for an accurate weighted exposure map to be generated in all cases, and for the weighted exposure time to be correctly calculated if stacking is done. .sp This task calls tasks addcomment, iterstat, fileroot, filecalc, and stsdas.toolbox.imgtools.imcalc. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS 1. There is a known bug (IRAF buglog #244) in imcombine (all versions prior to V2.11) possibly applicable to the default parameters for this task: .sp When combine=average, reject=(sigclip, avsigclip, ccdclip, or pclip), and mclip=yes (the value of mclip does not matter for pclip) the average will be incorrect if the number of low pixels rejected is greater than the number of unrejected pixels. For example if 3 low pixels are rejected and only 2 pixels remain then the final average will be incorrect for that pixel. There is no workaround other than to avoid this combination of parameters. .sp The default parameter set has combine=average, reject=ccdclip, and mclip=yes. However, in coadding IR images, one typically deals with more than a dozen images, and so it is very unlikely that more low pixels will be rejected than the number of unrejected pixels. Thus the default parameters have not been changed to ensure avoiding this bug, as it is unlikely to arise in practice. .sp .sp 2. Only one bad pixel mask is allowed when stack=yes (this is a shortcoming of imcombine). If the first image in the list has an individual bad pixel mask (e.g. due to holes in the sky-subtracted image), that bad pixel mask will be used for the stacked image. This can be avoided by using newmask=yes, but the individual bad pixel masks can only be implemented in this case by multiplying the images by their individual bad pixel masks before running the task. .sp Note that this will not give correct results if you are coadding images which have been artificially set to the same image size but which have different sized areas of good data. In that case, you should set bad pixels not to zero but to some large negative number (e.g. -99999) and then set i_lthresh in imcoaddpars to a slightly less negative number (e.g. -10000). Thus those pixels will be excluded from consideration when making the coadded image. .sp .sp 3. Weighted coadding cannot be used with the default zero level offsets, since some of those are negative. Workaround is to set prezero=yes. .ih SEE ALSO irshift, irrotate, masklet, mkobjmask, photcomp, photcheck .endhelp ./doc/irflat.hlp0100644000151400000240000001166606674326132012737 0ustar phallgames.help irflat May95 phiirs .ih NAME irflat -- make a running flatfield & apply it to IR images .ih USAGE irflat imagelist flatstring number objmask .ih PARAMETERS .ls imagelist Name of file containing list of images to process (do not use an `@'). .le .ls flatstring String to be appended to output flattened images. An input image "image1.imh" will have corresponding flattened image "image1flat.imh" if flatstring="flat". .le .ls number TOTAL number of images used in creating each flat. 8 or 10 suggested. EVEN numbers only are accepted, as (number/2) images on either side of the image being flattened are used to make the running flat, which is titled "image1flatfield.imh" for input image "image1.imh", etc. .le .ls objmask Boolean: Use object masking when constructing flats? .sp .le .ls logfile Name of log file. If null ("") then a file named rootname//".log" will be created. The log file will append to any existing file with the same name. .le .ls stdpars (boolean) Use standard imcombine parameters to create the flats? NOTE that the GAIN and READNOISE are still taken from imflatpars if stdpars=yes. The standard parameters are combine=median, rej=ccdclip, lsig=hsig=3, scale=!FLATVAL, zero=weight=none, mclip+, nkeep=1. The SIGMA, PLFILE, and MASKVALUE (if objmask-) parameters are also still taken from imflatpars. .le .ls flatsave (hidden) (boolean) Save all the individual flatfield images? .le .ls same (boolean) Do object masks all have same suffix? .le .ls suffix Suffix of object mask .le .ls tpl (hidden) (boolean) Throughput-correct images after flatfielding? .le .ls tplname FULL Name of throughput correction image to use, if tpl=yes. .le .ls v210 (hidden) (boolean) Use "combine" instead of "imcombine" to avoid v2.10 imcombine bug? .le .ls echog (boolean) Beep when task is done? .le .ls imflatpars (hidden) Parameter set for imcombine operation used to create the flat. GAIN and READNOISE are located here. See help page for imcombine for description. The files "phiirs$irflat256.par", "phiirs$irflatirim.par", and "phiirs$irflatirtf.par" contain default params for the SO 256^2 array, the KPNO IRIM array, and the IRTF NSFCAM array, respectively. .le .ih DESCRIPTION This task makes a flatfield for each image in an input list of IR array images and applies it to that image. The input images are unchanged; but the following images/files are created: .sp * flattened (& optionally bad pixel zeroed) frames: *flatstring.imh .sp * a file (list.flatstring//rootname) with the names of those images .sp * the logfile .sp * (optionally) the flatfield images (rootname//"flatfield.imh") .sp The steps of the routine are as follows: .sp 1) Make the list of images that go into each flatfield: (number/2) images on either side of each image, excluding the image itself. Images near the beginning(end) of the list use the first(last) "number" images excluding themselves; ie for number=8 #1 uses #2-#9, #2 uses #1,#3-9; etc. .sp 2) Do iterstat to find each image's "true" median, for use in scaling, and insert it into the image headers as the keyword "FLATVAL". .sp 3) Create flat field and normalize by dividing by iterative mean. .sp 4) Zero out the bad pixels on the flat, if desired .sp 5) Flatten each image by dividing by the appropriate normalized flat. .sp 6) Divide by throughput correction image, if desired .sp A few notes: .sp * Since this task is not speedy, and since each image is used in 8 flatfields, it is HIGHLY RECOMMENDED that you excise any bad images from the input list before starting. "Bad" meaning images where the sky changed abruptly for any reason, where the chip is saturated, where the sigma of the image is anomalously high, etc. Also, the images in the input list should be temporally contiguous (oo, big words): if there was more than 5 minutes delay between two sets of images you should probably have them in separate input lists. .sp * You should also inspect the output images before moving on to the next task. I suggest doing iterstat on all the output images and looking for images with outlying or rapidly changing means or sigmas, as well as displaying all the images to look for more insidious flaws. .sp * Combine an EVEN NUMBER OF IMAGES, because when you use median combining with an odd number of images, you get a spike in the flattened image histograms from pixels taken from that image and put into the flat. I don't know how badly (if at all) this effect skews the statistics, but it seems best to avoid it. .sp * for the SO 256x256, rdnoise=73 and gain=15.3 .sp * for the KPNO 4m + IRIM, rdnoise=35 and gain=10.46 .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS 1. Repeated accessing of pixel mask files can cause segmentation faults and memory errors. When running irflat and/or irsky in intensive batch mode, I have found the best way to avoid trouble is to erase bad pixel masks between each running of the program and replace them with backup copies from a backup directory. .ih SEE ALSO domeflat, qkflat .endhelp ./doc/masklet.hlp0100644000151400000240000000163706131316737013111 0ustar phallgames.help masklet Feb95 phiirs .ih NAME masklet -- break coadded-image object mask into individual-image masklets .ih USAGE masklet image objmask suffix .ih PARAMETERS .ls image Name of image mosaic produced by ircoadd .le .ls objmask Name of object mask for image mosaic .le .ls suffix="objmask" Suffix for output object masks .le .ls shiftfile="" Image+Shifts file (default=image//.imshifts) .le .ls flip Boolean: Flip object mask L-R before creating masklets? .le .ls update=yes Boolean: Update image headers with object mask name? .le .ih DESCRIPTION masklet takes a coadded image object mask and deregisters it back into object masks for the images which were used to create the coadded image. The `flip' parameter can be used to counteract the action of the `flip' parameter in the ircoadd task. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS .ih SEE ALSO makeobjmask, mkobjmask .endhelp ./doc/irrotate.hlp0100644000151400000240000000721506331733123013272 0ustar phallgames.help irrotate Mar96 phiirs .ih NAME irrotate -- rotate and resample list of images and recalculate shifts for them .ih USAGE irrotate rotlist suffix angle scale magfac shiftexactlist logfile .ih PARAMETERS .ls rotlist List of images to rotate .le .ls suffix UNIQUE suffix to append to rotated images. The suffix needs to be unique because the bad pixel images for each given rotation need to be distinguished from each other. This is especially important when you have multiple datasets using the same bad pixel mask. Also, this way multiple attempts at rotation can be done for each image list if necessary. .le .ls angle Rotation angle .le .ls scale Input image scale compared to reference image .le .ls magfac Output image magnification factor (for subpixel shifting) .le .ls shiftexactlist File with EXACT image shifts .le .ls logfile Name of log file .le .sp .ls i_interp = linear IMLINTRAN: Interpolation type .le .ls i_boundary = constant IMLINTRAN: Boundary extension type .le .ls i_constant = 0. IMLINTRAN: Value for constant boundary .le .ls bpzero = no Zero images by bad pixel masks before rotating? .le .ls newmask = no Boolean: Override bad pixel masks listed in image headers? .le .ls badmask Bad pixel mask to use instead .le .ls invert = no Boolean: Invert bad pixel masks so bad pixels=0? Bad pixels must equal zero in the bad pixel masks listed in the headers of the images input to this task. If invert=yes, the masks will be inverted within the task, and inverted again after rotation to output masks in the same format as they were input. .le .ls bpfrac = 0.75 Threshold bad pixel value in the rotated bp mask. When the bad pixel masks are rotated, interpolated values appear. This parameter is the threshold value, relative to the maximum value in the rotated bp mask, above which a pixel in that mask is considered to be a bad pixel. .le .ls norot = no Boolean: Skip image rotation and calculate shifts only? .le .ih DESCRIPTION This task takes a list of images and image shifts, rotates and magnifies as specified the images and the bad pixel masks and throughput correction images listed in each image's header keywords "BPM" and "TPLIMG" respectively, and recalculates the image shifts appropriately. A header keyword "ROTATED" = angle//"x"//magfac is added, and the task will not run on any image which already has this keyword in its image header. .sp If you are magnifying while rotating and plan to coadd the rotated images with other unrotated images, you should nonetheless use "irrotate" on those unrotated images, with angle=0., scale and magfac just as used for the rotated images, i_interp=nearest, and i_boundary=nearest. This mimics a "blkrep magfac magfac" command but in addition properly calculates the shifts for the new expanded but unrotated images. .sp If you are planning to eventually do "photcheck" and "photscale" on the coadded image to check the photometric properties of the dataset, then it is advisable to shorten the image names as much as possible before running this task, and to keep the suffix used in this task as short as possible. This is because txdump, which is used as a part of photcheck, outputs the proper format only for image names of 21 characters or less. .sp The output of the task is: .nf "*br"//mag//ssuffix//".imh" output rotated, replicated images inputlist//"br"//mag//ssuffix list of above images shiftexactlist//"br"//mag//suffix list of shifts for above images inputlist//"br"//mag//ssuffix//"pl" list of new bad pixel images created .fi where "mag" is the output image magnification factor and "br"="blkrep". .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS .ih SEE ALSO irshift2, immatch.geomap, ircoadd .endhelp ./doc/irshift.hlp0100644000151400000240000000663706724342261013125 0ustar phallgames.help irshift Feb95 phiirs .ih NAME irshift -- find offsets & optionally do fractional shifting for list of images .ih USAGE irshift flatlist refimage prefix suffix .ih PARAMETERS .le .ls flatlist List of images for which to find offsets (do not use an "@") .le .ls refimage Name of (flattened) reference image .le .ls prefix Prefix string for output files .le .ls suffix Suffix string for output files .le .ls fracshift Boolean: Create fractional-pixel-offset images? .le .ls interp Interpolation type for fractional-pixel shifting .le .ls boundary Boundary type for fractional-pixel shifting .le .ls badmask Name of the bad pixel mask to use (good pixels=1), if zeroout=yes. .le .ls useimages Boolean: Estimate shifts from images interactively? .le .ls inputlist File with coordinate info (for noninteractive image shift determination) .le .ls combdata Boolean: Combine shifts with earlier dataset? .le .ls xshiftold Reference image x shift in earlier dataset .le .ls yshiftold Reference image y shift in earlier dataset .le .ls radius Imexamine aperture photometry radius .le .ls buffer Imexamine sky buffer .le .ls width Imexamine sky annulus width .le .ls bs Centering box size for final shift calculation .le .ih DESCRIPTION This task calls the following other tasks: fileroot, filecalc. .sp This task allows you to measure the offsets of a list of (presumably dithered) images from a specified reference image. Optionally, the task will also fractionally shift the images using the computed fractional shifts and specified interpolation and boundary types. .sp I recommend setting rimexam.fittype=gaussian and rimexam.iterat=1 before starting the task to speed up the imexam portion of the task and to make it more robust to the occasional floating point error. .sp The task begins by displaying the reference image and bringing up "imexam". Get the coordinates, in the reference image, of all objects you wish to use for registration, starting with the `best' reference object-- one which appears in all images. .sp Then the images for which you are finding shifts are displayed one by one, and imexam is brought up for each. Choose one object that appears in all images, and find the position (type 'a') of this best registration object in each frame (hit 'n' to go on to the next frame, and 'q' when done). The file containing these positions will be displayed for editing when done, in case mistakes were made. .sp This information is used to automatically calculate the offsets of all the images from the reference image. The following "prefix.*.suffix" files are created: .nf *.refcoords.* registration objects' reference image coords *.allcoords.* registration objects' coordinates in all images *.offsets.* final shifts logfile, + coarse and final shifts *.imshifts.* image names and rounded integer shifts on same line *.shiftfrac.* fractional part of final shifts *.shiftint.* integer part of final shifts *.shiftexact.* final shifts (exact) *.roundoff.* final shifts rounded off to integer shifts .fi If you want to add some new images to an old set, first make sure you're using the same reference image as that old set. Then, take a look at the *.offsets.* file from that set and find the fractional offsets made on the reference image. You will be asked to enter them when you run the task. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS None, but lots of features. .ih SEE ALSO .endhelp ./doc/irsky.hlp0100644000151400000240000001100006330465740012573 0ustar phallgames.help irsky May95 phiirs .ih NAME irsky -- sky-subtract IR images using running median sky .ih USAGE irsky imagelist skystring number objmask .ih PARAMETERS .ls imagelist List of images to process. .le .ls skystring Suffix for sky subtracted output images .le .ls number TOTAL Number of images to use to create sky. EVEN NUMBERS ONLY. .le .ls objmask Boolean: Use object masking when constructing skies? .le .ls logfile Name of log file. If null ("") then a file named rootname//".log" will be created. The log file will overwrite any existing file with the same name. .le .ls stdpars Use standard imcombine parameters to create the skies? NOTE that the GAIN and READNOISE are still taken from imskypars if stdpars=yes. The standard parameters are combine=average, rej=ccdclip, lsig=hsig=3, scale=!SKYMED, zero=weight=none, mclip+, nkeep=1. The SIGMA, PLFILE, EXPNAME, and (if objmask=no) MASKVALUE parameters are also still taken from imskypars if stdpars=yes. .le .ls sky_del Delete sky images? .le .ls same Boolean: Use same suffix for all object masks? .le .ls suffix Suffix of object mask .le .ls tpl Boolean: Make throughput correction image after skysub? .le .ls tplname Name of throughput correction image .le .ls forcescale Force recalculation of image medians? The medians are used to scale the images relative to each other when creating the sky image. .le .ls premask Mask when scaling before creating sky? If objmask=yes, the object and bad pixel masks are multiplied together and used for the masking; if objmask=no, only the bad pixel mask is used. Premasking only needs to be done when you have large flatfield residuals or a large fraction (>5% maybe?) of the image masked by the bad pixel image. .le .ls csky_del Delete csky images? These .pl images count the # of images excluded from the final average by either pixel masking or rejection. They are later used to create the "holes" image of regions where no images contributed to the final sky. .le .ls myway I want *all* imcombine parameters my way! .le .ls imskypars Parameter set for imcombine operation used to create sky images. GAIN and READNOISE are located here. See help page for imcombine for description. The files "phiirs$irsky256.par", "phiirs$irskyirim.par", and "phiirs$irskyirtf.par" contain default params for the SO 256^2 array, the KPNO IRIM array, and the IRTF NSFCAM array, respectively. .le .ih DESCRIPTION This task makes a sky image for each image in the input list from a number of images before and after the image, and subtracts the sky from that image. The input images are unchanged; new sky-subtracted images are created, along with other files as follows: .sp * sky-subtracted images: rootname//suffix//".imh" .sp * a file (list.rootname.suffix) listing the names of those images .sp * the logfile .sp * (optionally) the sky images (rootname//".skyimage.imh") .sp * (possibly) "holes" masks (rootname//".holes.pl") which indicate where there were no unrejected pixels to include in the sky image. .sp * (possibly) individual bad pixel masks (rootname//badmask) which are the holes masks times the original bad pixel masks. .sp .sp This task optionally divides by a throughput image after the sky-subtraction. This option has not been tested extensively. .sp It is HIGHLY RECOMMENDED that you inspect the flatfielded input images in some way before running the task. One bad input image will screw up several output images. I suggest doing iterstat on the input images and looking for images with outlying or rapidly changing means or sigmas, and to be completely safe (and save time in the long run) displaying every input image to look for more insidious flaws in the flat fielding. .sp The output images can be inspected with irshift, the next task. You can do iterstat on the output images to note possible problem ones. It is ALSO HIGHLY RECOMMENDED that if you are on the second pass through irsky, with objmask=yes, that you inspect the skysubtracted output images instead of just running them blindly through irshift. This is the voice of experience here: it *will* save you time in the long run. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS 1. Comprise 90\% of all known species of life on Earth. .sp 2. Repeated accessing of pixel mask files can cause segmentation faults and memory errors. When running irflat and/or irsky in intensive batch mode, I have found the best way to avoid trouble is to erase bad pixel masks between each running of the program and replace them with backup copies from a backup directory. .ih SEE ALSO qksky .endhelp ./doc/look.hlp0100644000151400000240000000116106126542467012412 0ustar phallgames.help look Feb95 phiirs .ih NAME look -- difference two successive images for quick look at field .ih USAGE look rootname .ih PARAMETERS .ls rootname Root name of images to difference .le .ls stats Boolean: Display image statistics? .le .ls int Frame in which to display image .le .ih DESCRIPTION look is a simple script to convert two SO IR images from PC format into IRAF format, display their statistics, difference them and display the difference image (and its statistics, if desired). look4m does the same thing for KPNO IR images. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS .ih SEE ALSO look4m .endhelp ./doc/nshift.hlp0100644000151400000240000001253206721051661012735 0ustar phallgames.help nshift Apr99 phiirs .ih NAME nshift -- find offsets for N images or image sets overlapping a central image .ih USAGE nshift filelist flatlist refimage prefix suffix .ih PARAMETERS .le .ls filelist = "" File of image lists to find offsets for (no "@") .le .ls flatlist Overall list of images to find offsets for (no "@") .le .ls refimage Name of (flattened) reference image .le .ls prefix Prefix string for output files .le .ls suffix Suffix string for output files .le .sp .ls fracshift = no Boolean: Create fractional-pixel-offset images? .le .ls interp = poly5 Interpolation type for fractional-pixel shifting .le .ls boundary = nearest Boundary type for fractional-pixel shifting .le .ls badmask = "" Name of the bad pixel mask to use (good pixels=1), if zeroout=yes. .le .ls redo = no Erase files and redo shift-finding if already done? .le .ls useimages = yes Boolean: Estimate shifts from images interactively? .le .ls displayim = yes Boolean: Display images for imexam? .le .ls ptv = no Boolean: Use phat.ptv instead of display in imexam? .le .ls imsection = "" Image section to display in imexam? .le .ls editfiles = yes Boolean: Display coords files for editing? .le .ls xcor Use image cross-correlation to find shifts? .le .ls xsize = 0 X-axis image size (0 for autosense) for cross-correlation .le .ls ysize = 0 Y-axis image size (0 for autosense) for cross-correlation .le .ls inputlist File with coordinate info (for noninteractive image shift determination) .le .ls combdata = no Boolean: Combine shifts with earlier dataset? (NOT TESTED) .le .ls xshiftold Reference image x shift in earlier dataset .le .ls yshiftold Reference image y shift in earlier dataset .le .ls radius = 5. Imexamine aperture photometry radius .le .ls buffer = 10. Imexamine sky buffer .le .ls width = 10. Imexamine sky annulus width .le .ls bs = 9. Centering box size for final shift calculation .le .ls echog = yes Beep when task is done? .le .ih DESCRIPTION This task calls the following other tasks: fileroot, filecalc. .sp This task allows you to measure the offsets for N images or image lists which all overlap a central reference image. Optionally, the task will also fractionally shift the images using the computed fractional shifts and specified interpolation and boundary types. .sp I recommend setting rimexam.fittype=gaussian and rimexam.iterat=1 before starting the task to speed up the imexam portion of the task and to make it more robust to the occasional floating point error. .sp If there are N image sets for which to find offsets (e.g. several sets of dithered images which overlap a central image), then filelist should contain all the lists of these image sets. If there are just N images for which to find offsets from a central image, then set filelist="". .sp The "useimages=no" option has not been well tested. If "useimages=yes", the interactive image display and examination described below can be skipped by setting "displayim=no". Only an image section will be displayed, if specified by "imsection". The task "phat.ptv" will be used instead of "display" if "ptv=yes". The imexam log files will be displayed for editing when done if "editfiles=yes", in case mistakes were made. .sp For each image list in filelist (or image in flatlist if filelist=""), the task displays the first image in the list (or the current image from flatlist) and then brings up the reference image within "imexam". Get the coordinates, in the reference image, of ONE object visible in all images, for coarse registration. Then the image(s) for which you are finding shifts are displayed one by one, and imexam is brought up for each. Get the coordinates (hit 'a') of this same reference object in each image (hit 'n' to go on to the next frame, and 'q' when done). The task finds the coarse offsets, and then moves to the next image or image list. Finally, if xcor=no, the reference image is displayed again, and you should get the coordinates of all objects to use for registration, in no particular order. If xcor=yes, the shifts are computed automatically using the immatch.xregister task. .sp This information is used to automatically calculate the offsets of all the images from the reference image. The following "prefix.*.suffix" files are created: .sp *.refcoords.*_N registration object reference image coords for image/set N .sp *.allcoords.*_N registration object coordinates in all images in image/set N .sp *.coarse.*_N rough shifts for image/set N .sp *.refcoords.* registration objects' reference image coords .sp *.allcoords.* registration objects' coordinates in all images .sp *.offsets.* final shifts logfile, + coarse and final shifts .sp *.shiftfrac.* fractional part of final shifts .sp *.shiftint.* integer part of final shifts .sp *.roundoff.* final shifts rounded off to optimum integer shifts .sp *.xregout.* output of immatch.xregister (if used) .sp The "combdata=yes" option has not been tested, but if you want to add some new images to an old set, first make sure you're using the same reference image as that old set. Then, take a look at the *.offsets.* file from that set and find the fractional offsets made on the reference image. You will be asked to enter them when you run the task. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS None, but lots of features. .ih SEE ALSO irshift, phat.ptv .endhelp ./doc/look4m.hlp0100644000151400000240000000146605777437775012703 0ustar phallgames.help look4m Feb95 phiirs .ih NAME look4m -- difference two images for quick look at field .ih USAGE look rootname num1 num2 suffix .ih PARAMETERS .ls rootname EXACT Root name of images to difference .le .ls num1 Running number of first image .le .ls num2 Running number of second image .le .ls suffix Suffix of output image .le .ls disp Boolean: Display image? .le .ls int Frame in which to display image .le .ls stats Boolean: Display image statistics? .le .ih DESCRIPTION look4m is a simple script to take two KPNO IR images, display their statistics, difference them, and display the difference image (and its statistics, if desired). look does the same thing for SO IR images, including conversion from PC format. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS .ih SEE ALSO look .endhelp ./doc/makeobjmask.hlp0100644000151400000240000000443605754237323013740 0ustar phallgames.help makeobjmask Feb95 phiirs .ih NAME makeobjmask -- create object mask for input image(s) .ih USAGE makeobjmask inlist .ih PARAMETERS .le .ls inlist Image(s) to mask .le .ls suffix="objmask" Suffix for mask files. .le .ls headlist Image(s) to which to add BPM cards .le .ls subsample=1 Block averaging factor before median filtering .le .ls filtsize=15 Median filter size for local sky evaluation. If 0, no filtering is done. .le .ls nsmooth=3 Scale for boxcar smothing before thresholding. If 0, no smoothing is done. .le .ls threshtype="nsigma" Thresholding type: nsigma or constant .le .ls nsigthresh=2 Threshold for masking in sky sigma .le .ls constthresh=0 Constant threshold above sky for masking .le .ls ngrow=0 Width of rings to grow around masked objects .le .ls statsec Image region to use for computing sky statistics .le .ls checklimits Boolean: "Check min and max pix values before filtering? .le .ls zmin=-32767. Minimum data value for fmedian .le .ls zmax=32767. Minimum data value for fmedian .le .ls verbose Boolean: "Verbose output? .le .ih DESCRIPTION makeobjmask calls the scripts iterstat. .sp makeobjmask takes the input image(s) and create object mask(s) for them. The image(s) should have uniform pixel-to-pixel rms; if this is not the case, consider using the script "mkobjmask". .sp First, the image is (optionally) median filtered and the filtered image is subtracted. Optionally, the image can be subsampled before the filtering in order to speed things up. Next, the image is (optionally) boxcar smoothed. .sp The threshold for identifying objects can be set either as a constant or as a specific number of sky sigma above the median sky level as measured using iterative sigma rejection. The resulting thresholded image is turned into a mask with "sky" set to 0 and "objects" set to 1. The user may "grow" additional rings of pixels around masked regions to increase their area. .sp Finally, the resulting mask may optionally be recorded in the input image header using the keyword BPM. The user may in fact create a mask from one input image and add it into the header of another by specifying different lists for inlist and headlist. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS .ih SEE ALSO mkobjmask, iterstat .endhelp ./doc/maskstat.hlp0100644000151400000240000000302106334435640013265 0ustar phallgames.help maskstat Feb95 phiirs .ih NAME maskstat -- calculates image statistics from unmasked regions only .ih USAGE maskstat image mask goodvalue .ih PARAMETERS .le .ls image Input image(s) or list .le .ls mask Input mask(s), list, or ! .le .ls goodvalue Good pixel value in mask .le .ls lower Initial lower limit for data range .le .ls upper Initial upper limit for data range .le .ls verbose Verbose output? .le .ls iterstat Use iterstat instead of imstat for statistics calculation? .le .ls addheader Add iterstat output to image headers? .le .ls printit Print iterstat output? .le .ih DESCRIPTION maskstat takes the input image(s) and sets the bad pixels as given by the input mask(s) to a flag value which is subsequently ignored. The statistics of the remaining pixels in the image(s) are calculated normally using either imstat or iterstat. .sp If a list of images and only one mask is given, that mask is used for all images. If the masks are to be taken from the image headers, they are first output to a temporary list. Then, and in the case where lists of both images and masks are given, the numbers of each are checked to make sure they are identical, and if so, the images and masks are paired up and the statistics calculated. It would be kind of neat if only one image and a list of masks gave you the statistics of the image computed using all the different masks, but the task simply exits if that is the case. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS .ih SEE ALSO iterstat .endhelp ./doc/mkbpm.hlp0100644000151400000240000000125306645226075012556 0ustar phallgames.help mkbpm Dec98 phiirs .ih NAME mkbpm -- make bad pixel mask (BPM) image .ih USAGE cl < mkbpm.cl .ih PARAMETERS .ls none .le .ih DESCRIPTION mkbpm.cl is a non-interactive sample IRAF script for creating a bad pixel mask image. In the example, two flats (high and low lamps) are taken in each of three filters (J, H, and K). The two flats in each filter are ratioed and the iterative statistics calculate, and pixels greater than 5-sigma from the mean are flagged as bad pixels. Finally, two masks are generated: one where the bad pixels are required to be present in all three filters, and one where they are only required to be present in one filter. .ih SEE ALSO .endhelp ./doc/mkdark.hlp0100644000151400000240000000116405754237323012720 0ustar phallgames.help mkdark Jan95 phiirs .ih NAME mkdark -- make dark image .ih USAGE mkdark rootname outname titlestring .ih PARAMETERS .ls rootname Root name of dark images to coadd .le .ls outname Name of coadded dark image .le .ls titlestring Title to insert into coadded dark image header .le .ih DESCRIPTION mkdark.cl creates a dark image using comb=average, rej=minmax, nlo=nhi=1, scale=zero=weight="none"; and gives it a title. .ih EXAMPLES 1) Combine all images dk01ut01*imh to create dk01ut01.avg.imh. mkdark dk01ut01 dk01ut01.avg "1 sec dark, UT Day 1" .ih TIME REQUIREMENTS .ih BUGS .ih SEE ALSO .endhelp ./doc/mkobjmask.hlp0100644000151400000240000000320406253600624013413 0ustar phallgames.help mkobjmask Feb95 phiirs .ih NAME mkobjmask -- create object mask from coadded image and exposure map .ih USAGE mkobjmask image expname .ih PARAMETERS .ls image Name of image for making mask .le .ls expname Name of exposure map for normalization .le .ls suffix="objmask" Suffix of output object mask .le .ls prefix="norm" Prefix for temporary normalized image .le .ls nsmooth=3 Size of filter for boxcar smoothing. .le .ls subsample=1 Block averaging factor before median filtering .le .ls filtsize=15 Median filter size for local sky evaluation .le .ls ngrow=1 Width of rings to grow around masked objects .le .ls interact=yes Boolean: Interactively examine normalized image? .le .ls inv=yes Boolean: Invert mask so objects are zero? .le .ls threshold Cutoff point for replacement .ih DESCRIPTION mkobjmask calls the scripts makeobjmask, sigmanorm, and iterstat. .sp mkobjmask takes a coadded image and its corresponding exposure map and creates an object mask. First, the image is normalized to uniform pixel-to-pixel rms using the square root of the exposure map. The recommended threshold for identifying objects is (4.5/boxcar_smoothing_size) * rms of unsmoothed image. This threshold is applied to a boxcar smoothed version of the image, using the task makeobjmask, to produce the output object mask image. .sp The default parameters are for original-scale images. For images block replicated by a factor of two, I typically use nsmooth=5, subsample=2, filtsize=15, and ngrow=2 (or larger). .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS .ih SEE ALSO makeobjmask, sigmanorm, iterstat .endhelp ./doc/myget.hlp0100644000151400000240000000132605754237324012575 0ustar phallgames.help myget Feb95 phiirs .ih NAME myget -- convert PC format images to IRAF using wildcard specifications .ih USAGE myget filename .ih PARAMETERS .ls filename Files to process .le .ls stats Boolean: Display image statistics? .le .ls logfile File for imstatistics output .le .ls display Boolean: Display each image? .le .ls int Frame in which to display image .ih DESCRIPTION myget is a simple script to convert SO IR images from PC format into IRAF format and to display them and their statistics if desired. IRAF wildcard specifications can be used to convert multiple images with one call to the program. .sp Calls program "get_ir2". .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS .ih SEE ALSO .endhelp ./doc/nl_findcor.hlp0100644000151400000240000003310606125570476013567 0ustar phallgames.help nl_findcor Jul95 phiirs .ih NAME nl_findcor -- add header params, do nonlinearity correction, & subtract dark .ih USAGE cl < nl_findcor.cl .ih PARAMETERS None. .ih DESCRIPTION This non-interactive script determines a nonlinearity correction using a sequence of domeflat images. The task is located in the PHIIRS directory, and can be viewed with "help nl_findcor opt=source". .sp The output of this task is the `slope' (inverse slope, really) of the relation between the ratio of observed & input counts to the observed counts: .sp observed/input = 1 - observed / slope .sp This slope is used in the equation (derived below) actually employed by the task `irimfirst' to make the nonlinearity correction: .sp new_value = old_value / (1 - old_value * intfactor/slope) .sp where intfactor = 1 + 2*delaytime/intime, where delaytime is the time between biasing and the first (non-destructive) read of the bias, and intime is the integration time listed in the image header. .sp For IRIM, .sp delaytime = 1.0 if intime >= 1.381 .sp delaytime = intime - 0.381 if intime < 1.381 .sp .sp NONLINEARITY CORRECTION THEORY (mostly from the SQIID manual) .sp The output from IR arrays is a not strictly a linear function of the input signal: the pixels are biased to establish a potential well where charge can accumulate; this potential well gradually weakens as charge accumulates on the node capacitance, effectively changing (decreasing) the gain of that pixel. Since the total capacitance (which determines system gain) is the sum of the distributed (non-varying) capacitance of the system and the (variable) capacitance at each detector node, the degree of non-linearity is a function of the ratio of nodal to total capacitance. As a direct consequence, pixel response departs from linearity in a predictable fashion for accummulated signals above a device-specific level. Since key pixel parameters such as quantum efficiency are very uniform, the linearity appears to be a global property of the array rather than pixel specific. .sp The data fit were always within the regime where this correction for unseen charge was small. This is not the case, for example, when doing 5 sec integrations on standards! .sp The linearity correction is used to recontruct the input value during an integration time t on the basis of the difference between the observed values at times d and t+d (d=delay time): .sp obs_t = obs(t+d) - obs(d) .sp where each observation is itself subject to a linearity correction: .sp input_t = input(t+d) - input(d) .sp Keep in mind that obs_t, t, d, and the `slope' of the linearity correction are the only variables we know; everything else is determined from then. .sp Thus: .sp obs(t+d) = obs_t * ((t+d)/t) .sp obs(d) = obs_t * (d/t) .sp The known relation between observed and input counts is: .sp observed/input = 1 - observed / slope .sp or .sp input = observed / (1 - observed/slope) .sp Thus input_t = input(t+d) - input(d) becomes .sp input_t = [obs_t*(t+d)/t]/[1-obs_t*(t+d)/(t*slope)] - [obs_t*d/t]/[1-obs_t*d/(t*slope)] .sp We can approximate this using (1-x)^{-1} ~ 1+x as follows: .sp input_t = obs_t*[1 + d/t + obs_t*(t+d)/(t*slope) + obs_t*(t+d)*d/(slope*t^2) - d/t - obs_t*d^2/(slope*t^2)] .sp = obs_t*[1+obs_t*(t+2d)/(t*slope)] .sp = obs_t/[1-obs_t*(t+2d)/(t*slope)] .sp using the same approximation (1-x)^{-1} ~ 1+x again in the last step. This approximation should be good for x<~0.1, beyond which the array is extremely nonlinear anyway (above the knee in the curve). .sp Thus we can write, finally: .sp input_t = obs_t / (1 - obs_t * intfactor/slope) .sp where intfactor = (t+2d)/t and d is the delay time between biasing and the first (non-destructive) read of the bias. For IRIM, .sp d = 1.0 if t >= 1.381 .sp d = t - 0.381 if t < 1.381 .ih SOURCE CODE #UT 950709 version #-1 load stsdas.toolbox.imgtools, ctio, & phiirs before running #0 make lists #1 irimfirst on all #2 compare start & end refs & darks #3 imcombine all images #4 iterstat interspersed refs #5 iterstat observations #6 convert short-exposure images to actual flux and exposure time #7 convert long-exposure images to actual flux and exposure time #8 find average lamp values #9 correct images for lamp variability #10 turn (exptime,flux) file into (flux,%) file and graph .sp #0 make lists... ideally want to replace by directing specific files to # specific lists. files nldark_start*imh >> list.nl1_dark_start files nldark_end*imh >> list.nl1_dark_end copy list.nl1 list.nl1_refs copy list.nl1 list.nl1_ref_start copy list.nl1 list.nl1_ref_end copy list.nl1 list.nl1_005s copy list.nl1 list.nl1_0075s copy list.nl1 list.nl1_01s copy list.nl1 list.nl1_02s copy list.nl1 list.nl1_04s copy list.nl1 list.nl1_06s copy list.nl1 list.nl1_10s copy list.nl1 list.nl1_14s copy list.nl1 list.nl1_18s copy list.nl1 list.nl1_22s copy list.nl1 list.nl1_26s copy list.nl1 list.nl1_30s copy list.nl1 list.nl1_34s copy list.nl1 list.nl1_38s copy list.nl1 list.nl1_42s copy list.nl1 list.nl1_46s copy list.nl1 list.nl1_50s vi list.nl1_* count list.nl1_* >> list.nl1_counts vi list.nl1_counts .sp #1 irimfirst on all irimfirst list.nl1 no no badmask=bpk.pl irimfirst list.nl1_dark_start no no badmask=bpk.pl irimfirst list.nl1_dark_end no no badmask=bpk.pl .sp #2 imcombine start & end refs & darks imcombine @list.nl1_ref_start nl1_ref_start comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=none expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 .sp imcombine @list.nl1_ref_end nl1_ref_end comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=none expname=exptime logfile=log.nl1 weight=nonescale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 .sp imcombine @list.nl1_dark_start nl1_dark_start comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=none expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 .sp imcombine @list.nl1_dark_end nl1_dark_end comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=none expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 .sp print("#start & end dark stats", >> "log.nl1") iterstat nl1_dark_start.imh,nl1_dark_end.imh >> log.nl1 .sp #3 imcombine all images imcombine @list.nl1_005s nl1_005s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 .sp imcombine @list.nl1_0075s nl1_0075s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 .sp imcombine @list.nl1_01s nl1_01s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 .sp imcombine @list.nl1_02s nl1_02s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 .sp imcombine @list.nl1_04s nl1_04s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 .sp imcombine @list.nl1_06s nl1_06s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 .sp imcombine @list.nl1_10s nl1_10s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 .sp imcombine @list.nl1_14s nl1_14s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 .sp imcombine @list.nl1_18s nl1_18s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 .sp imcombine @list.nl1_22s nl1_22s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 .sp imcombine @list.nl1_26s nl1_26s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 .sp imcombine @list.nl1_30s nl1_30s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 .sp imcombine @list.nl1_34s nl1_34s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 .sp imcombine @list.nl1_38s nl1_38s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 .sp imcombine @list.nl1_42s nl1_42s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 .sp imcombine @list.nl1_46s nl1_46s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 .sp imcombine @list.nl1_50s nl1_50s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 .sp #4 iterstat interspersed refs print("#interspersed ref stats", >> "log.nl1") iterstat nl1_ref_start.imh,@list.nl1_refs,nl1_ref_end.imh >> stats.nl1_refs_1 type stats.nl1_refs_1 >> log.nl1 .sp #5 iterstat observations del _tmpdagnabit ver- >& dev$null iterstat nl1*s.imh[25:225,25:225] >> stats.nl1_1 hsel nl1*s.imh int_s yes >> imhe.nl1_1 fields stats.nl1_1 2 >> _tmpdagnabit join imhe.nl1_1,_tmpdagnabit out=stats.nl1_2 del _tmpdagnabit ver- .sp #6 convert short-exposure images to actual flux and exposure time print(" ", >> "stats.nl1_2") print("#the first time this is edited, comment out lines of images with ", >> "stats.nl1_2") print("#int_time >1.381 seconds.", >> "stats.nl1_2") vi stats.nl1_2 filecalc stats.nl1_2 "$1+$1-0.381;($1+$1-0.381)*($2/$1)" >> stats.nl1_3 #old (wrong) #filecalc stats.nl1_2 "$1+$1;($1+$1)*($2/$1)" >> stats.nl1_3 .sp #7 convert long-exposure images to actual flux and exposure time print(" ", >> "stats.nl1_2") print("#the second time this is edited, comment out lines of images with ", >> "stats.nl1_2") print("#int_time <=1.381 seconds.", >> "stats.nl1_2") vi stats.nl1_2 filecalc stats.nl1_2 "$1+1.0;($1+1.0)*($2/$1)" >> stats.nl1_3 .sp #8 find average lamp values print(" ", >> "stats.nl1_refs_1") count stats.nl1_3 | scan(z) print("#when this is edited, average each two adjacent values together", >> "stats.nl1_refs_1") print("#so that you end up with "//z//" values total, matching the number ", >> stats.nl1_refs_1") print("#of sets of nonlinearity exposures, which will be scaled by these averages.", >> "stats.nl1_refs_1") print("#Put the average values in file 'stats.nl1_refs_2'.", >> "stats.nl1_refs_1") print("#This can be done with the IRAF commands:", >> "stats.nl1_refs_1") print("# x=0.5* (AVG1 + AVG2); print(x, >> \"stats.nl1_refs_2\"", >> "stats.nl1_refs_1") .sp vi stats.nl1_refs_1 print("#Are there "//z//" lines of data in this file? if so, continue...", >> "stats.nl1_refs_2") vi stats.nl1_refs_2 sort stats.nl1_refs_2 col=1 num+ rev+ | head nlines=1 | scan(z) .sp print("Do the following IRAF commands after this task stops: ") print("filecalc stats.nl1_refs_2 \"$1/"//z//"\" >> stats.nl1_refs_3") .sp #9 correct images for lamp variability print("filecalc stats.nl1_3,stats.nl1_refs_3 \"$1;$2/($1@2)\" >> stats.nl1_4") .sp #10 turn (exptime,flux) file into (flux,%) file and graph print("fields stats.nl1_4 1 | head nlines=1 | scan(x)") print("fields stats.nl1_4 2 | head nlines=1 | scan(y)") print("=x") print("=y") print("-----insert x and y from above into the line below-----") print("filecalc stats.nl1_4 \"$2;$2/(y*$1/x)\" >> stats.nl1_5") print("graph stats.nl1_5 point-") print("graph stats.nl1_5 point+ append+ overplot+") print(" ") print("The file stats.nl1_5 contains the final data points. `vi stats.nl1_5'") print("and insert a zero at the end of each column, then run:") print(" stsdas.statistics.emmethod stats.nl1_5[3,2,1]") print("to get the slope coefficient from the least-squares solution.") .sp beep .ih SEE ALSO irimfirst .endhelp ./doc/photcheck.hlp0100644000151400000240000000654406136014574013422 0ustar phallgames.help photcheck Mar96 phiirs .ih NAME photcheck -- monitor photometric stability of a data set .ih USAGE photcheck image expmap starcoords output .ih PARAMETERS .ls image Mosaic image .le .ls expmap Exposure map image .le .ls starcoords File for reference star coordinates .le .ls output File for formatted output photometry .le .sp .ls imageshifts="" `imshifts' file (default = image//.imshifts) .le .ls interact=yes Boolean: Identify reference stars interactively? .le .ls dephot=yes Boolean: Use default values for critical PHOT params? .le .ls badcheck=yes Boolean: Check for bad pixels and return INDEF values? .le .ls verbose=yes Boolean: Verbose output? .le .ls cleanup=yes Boolean: Erase individual photometry files when done? .le .ls expname PHOT: exposure time header keyword (default="EXPTIME") .le .ls gain PHOT: gain of array (in electrons/ADU) .le .ls rn PHOT: readnoise of array (in electrons) .le .ls ann PHOT: inner radius of sky annulus .le .ls width PHOT: width of sky annulus .le .ls ap PHOT: radius of photometry aperture .le .ls zp=0. PHOT: zeropoint. Leaving this set to zero is usually fine, but if you have extremely bright (but still unsaturated) sources in the field you should set to set it to 10.0 or so, to avoid AWK formatting errors. .le .ih DESCRIPTION The user first identifies several suitable objects in a mosaiced image, using imexam if interact=yes, and/or using or appending to the file given by the `starcoords' parameter if that file already exists. These objects should be located on a portion of the mosaic with nearly maximum exposure time, so that they will appear in most or all of the individual input frames. .sp Photcheck then takes the list of star positions, transforms them back to the coordinate systems of the individual sky subtracted images which were summed to make the mosaic (the images are listed in the imshifts file, which is displayed for editing to ensure the correct images are listed), and uses digiphot.apphot.phot to compute accurate positions and measure magnitudes for the reference objects in each sky subtracted input frame. The critical parameters for phot are taken from the parameters listed in photcheck if dephot=yes; otherwise they are taken from phot directly. .sp If the user sets badcheck=yes, then each image's bad pixel mask is consulted, and if any bad pixels are within the photometric aperture, phot will return an INDEF value for the magnitude. Finally, the output files from phot are compiled using awk into a format suitable for input to "photscale", which allows interactive calculation of photometric scalings for the data set. If cleanup=no, then the output phot files (imagename//".mag.X") are not erased. .sp The default output uses the mosaic image as the reference photometric image. If another image is desired as a reference, that can be done in `photscale'. .sp The task requires the `photcheck.awk' awk script to reside in the phiirs directory, and exits with an error if this is not the case. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS Image names as listed in the imshifts file can be no more than 21 characters long; this is a limitation imposed by the output format of `txdump'. The task will stop with a warning if image names are too long. .ih SEE ALSO photscale .endhelp ./doc/onis3ew.hlp0100644000151400000240000001431106720605332013025 0ustar phallgames.help onis3ew Apr99 phiirs .ih NAME onis3ew -- shift & coadd ONIS CNOC 3-field east-west dither pattern .ih USAGE onis3ew inlist imageroot niter .ih PARAMETERS .le .ls inlist List of input images .le .ls imageroot Root name for output files .le .ls niter=1 Number to append to output files .le .ls pairing=all (MLK|FGJ|EHI|ON|BA|CD|TSP|URQ|VWX|all) Image pairings to process (or all) .le .ls inspect=yes Inspect image lists before proceeding? .le .ls shiftlongaxes=yes Find shifts for image pairings w/overlapping long axes? .le .ls coaddlongaxes=yes Coadd image pairings w/overlapping long axes? .le .ls nshiftall=yes Find shifts between all image pairings? .le .ls prereview Display all image for pre-nshift check? .le .ls p_tv Use ptv instead of display for pre-nshift check? .le .ls use_images=yes Measure shifts from images (not file) in nshift? .le .ls display_im=yes Display images for imexam in nshift? .le .ls edit_files=yes Edit coords files after creation in nshift? .le .ls exclude Exclude any image pairings from first-pass nshift? .le .ls exstring (MLK|FGJ|EHI|ON|BA|CD|TSP|URQ|VWX) Enter code(s) for excluded pairing(s) separated by commas .le .ls redo=no Redo shift-finding if already done? .le .ls coaddallimages=yes Coadd all images? .le .ls secondpassxcor=yes Cross-correlate all images with coadded image? .le .ls coaddsecondpass=yes Coadd images after second-pass cross-correlation? .le .ls domkobjmask=yes Make coadded-image object mask (INTERACTIVE)? .le .ls domasklet=yes Make individual-image object masks? .le .ls imextn=fits Image extension .le .ls xsize=512 X-axis individual image size (0 for autosense) .le .ls ysize=1024 Y-axis individual image size (0 for autosense) .le .ls echog = yes Beep when task is done? .le .ih DESCRIPTION This task requires the stsdas.imgtools package. .sp This task is an example of how to build a large mosaic from individual offset images which overlap at the edges, but not with one single image. This task assumes the use of the ONIS array (512x1024) with long axis vertical as seen by IRAF. This task assumes the following 24-point dither pattern; individual pointings are assumed to consist of several individual dithered images and are denoted by either their number in the sequence or the corresponding letter: .nf T20 U21 V22 S19 R18 W23 TSP URQ VWX P16 Q17 X24 20/19/16 21/18/17 22/23/24 O15 B2 C3 ON BA CD N14 A1 D4 15/14 2/1 4/5 M13 F6 E5 MLK FGJ EHI L12 G7 H8 13/12/11 6/7/10 5/8/9 K11 J10 I9 .fi On the right is shown the layout of the nine interim coadds. For example, images T and P overlap with image S, and so they are shifted (using nshift) and coadded into the TSP image, which is then shifted (using nshift) with all the other interim coadds relative to the central BA image. If not all the interim coadds overlap with the central BA image, a first-pass final coadd is done with images from those that do overlap, the remaining are shifted relative to the first-pass coadd, and the final coadd is produced at last. .sp The task takes the list of ALL input images and separates them using the image titles into lists of images for the various pointing pairings (inlist//"_BA", inlist//"_MLK", etc.), allowing inspection of the created lists if desired. .sp Individual image pairings can now be analyzed via the "pairing" parameter, or it can be set to "all" to analyze all pairings sequentially. Note that an "image pairing" here means e.g. "V, W, and X pointings", so it actually consists of many individual dithered images. If shiftlongaxes=yes, irshift or nshift is used to find the offsets of image pairings along their long axes. If coaddlongaxes=yes, the individual images for the pairing(s) are coadded to form the interim coadded images. .sp For the remaining steps, "pairing=all" is required. If nshiftall=yes, shifts for the interim coadded images are found using nshift. If prereview=yes, the central interim coadd (BA) will be displayed in frame 1, and the other interim coadds one at a time in frame 2; any that do not overlap the central interim coadd should be noted. You will then be asked if any image pairings should be excluded from the first-pass nshift and coadded. If you answer yes, you must enter the letter codes for the pairings to be excluded, chosen from among the following: (MLK|FGJ|EHI|ON|BA|CD|TSP|URQ|VWX), and separated by commas if necessary. If coaddallimages=yes, all the images are coadded into the final image, prefaced by an intermediate "most-image" coadd and "rest-image" nshift step if necessary. If secondpassxcor=yes, all the images are cross-correlated with the final image to find improved offsets. If coaddsecondpass=yes, the images are coadded after this second-pass cross-correlation. If domkobjmask=yes, a coadded-image object mask is INTERACTIVELY created from the second-pass coadded image. If domasklet=yes, individual-image object masks are created from the coadded-image object mask. .sp This task is not the most elegant in phiirs, and is probably buggy at some level (particularly if the task is interrupted part way through), but is included in the hopes it is useful as a demonstration task. .sp The following is a (probably incomplete) list of files created & used by this task during execution. .nf full overlap: 1 coadd partial overlap: 2 coadds --------------------- ------------------------- # lists of long-axis images: in_list//_coadd_//n_iter (in_list//_coadd_//n_iter) in_list//_coaddmost_//n_iter in_list//_coaddrest_//n_iter # long-axis image shifts: image_root//.*.shall//n_iter image_root//.*.shmost//n_iter image_root//.*.shrest//n_iter # all-image lists: in_list//_all in_list//_most in_list//_rest in_list//_all # all-image coadds: image_root//all//n_iter//_1stpass image_root//most//n_iter//_1stpass image_root//all//n_iter//_1stpass .fi .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS Are a critical part of the earth's biosphere. .ih SEE ALSO onis6pt, nshift .endhelp ./doc/xlist.hlp0100644000151400000240000000135506130055333012600 0ustar phallgames.help xlist Jan95 phiirs .ih NAME xlist -- generate list of files surrounding a given file in input list .ih USAGE xlist inlist outlist start finish xfile .ih PARAMETERS .ls inlist Input list of file names IN SEQUENCE .le .ls outlist Output file list .le .ls start Number of first file to use in list .le .ls finish Number of last file to use in list .le .ls xfile Number of file to exclude from lsit .le .ls prefix Prefix to append to filenames in output list .le .ih DESCRIPTION If input list has files 1 through N, xlist generates a new output list with files 'start' to 'finish', excluding file 'xfile'. sp Originally created 7/22/93 Mark Dickinson. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS .ih SEE ALSO .endhelp ./doc/fileroot.hlp0100644000151400000240000000163505754237321013273 0ustar phallgames.help fileroot Jan95 phiirs .ih NAME fileroot -- parses filename into root and final extension .ih USAGE fileroot filename .ih PARAMETERS .ih filename Single file name to parse .ih validim Parse only if extension represents valid IRAF image datatype? .ih root Returned filename root .ih extension Returned filename extension .ih DESCRIPTION fileroot parses an input filename into root and final extension, where the final extension is the portion of the filename which follows the last period in the filename. For example, 'test.001.imh' would be parsed into 'test.001' and 'imh'. The validim parameter allows a check to see if the final extension is a valid IRAF image datatype; i.e. 'test.001' would not be parsed if validim=yes, since '001' is not a valid image datatype. .sp Originally created by Mark Dickinson in the dim and distant past. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS .ih SEE ALSO .endhelp ./doc/iterstat.hlp0100644000151400000240000000361206704671441013305 0ustar phallgames.help iterstat Jan95 phiirs .ih NAME iterstat -- iterative image statistics intended to exclude deviant pixels .ih USAGE iterstat image .ih PARAMETERS .ls image Input image(s) .le .ls nsigrej Number of sigmas beyond which to discard pixels .le .ls maxiter Maximum number of iterations .le .ls print Print final results? .le .ls verbose Show results of all iterations? .le .ls addheader Put returned values into image header keywords? .le .ls lower Initial lower limit for data range .le .ls upper Initial upper limit for data range .le .ls mean Returned value of mean .le .ls sigma Returned value of sigma .le .ls median Returned value of median .le .ls valmode Returned value of mode .le .ls oneparam = "all" (all|mean|stddev|npix|midpt|mode|rms|median) Find iterative value of this one parameter only .le .ih DESCRIPTION iterstat.cl is a script for imstat which sets upper and lower limits to a given number of sigma from the mean and recalculates the image statistics repeatedly until all pixels fall within the given range of sigma or maxiter is reached. If addheader=yes, the output values of the mean, sigma, median, and mode are stored in the image as header keywords ITERMEAN, ITERSIG, ITERMED, and ITERMODE respectively; and header keyword VARIANCE (equal to sigma**2) is also created. .sp If the iterative value of only one parameter is desired, the "oneparam" parameter can be reset from "all". This speeds things up slightly, but note that iterative values of "mean", "stddev", and "npix" must be calculated anyway, so that the speed-up is marginal if oneparam="midpt" or "mode". Output values which might be inaccurate are set to "INDEF" if oneparam!="all". Note that "rms" is the same as "stddev" and "median" is the same as "midpt". .sp Originally created 4 August 1992 by John Ward. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS .ih SEE ALSO maskstat .endhelp ./doc/minv.hlp0100644000151400000240000000062505754237323012421 0ustar phallgames.help minv Feb95 phiirs .ih NAME minv -- invert a mask of ones and zeros .ih USAGE minv infile outfile .ih PARAMETERS .ls infile Input mask image .le .ls outfile Output inverted mask image .le .ih DESCRIPTION This task takes a mask composed solely of 0's and 1's and inverts it; i.e. all the 0's are set to 1 and all the 1's to 0. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS .ih SEE ALSO .endhelp ./doc/photscale.hlp0100644000151400000240000000772106502623373013432 0ustar phallgames.help photscale Mar96 phiirs .ih NAME photscale -- calculate photometric scalings of a data set .ih USAGE photscale photfile output .ih PARAMETERS .ls photfile Photometry data file from photcheck .le .ls output Root name for output file(s). If this file already exists, the magnitude differences in it will be plotted in the standard photscale format, but no changes can be made to it. .le .sp .ls apcor=no Use aperture corrections? Such corrections must have been previously calculated with e.g. photcal.mkapfile. .le .ls apfile File of aperture corrections (coadded image first), one value per image listed in column 1, no extraneous lines or columns please. .le .ls display=yes Boolean: Automatically display lightcurve (requires STSDAS)? .le .ls results=no Boolean: Output computed scales and weights? .le .ls newref=no Boolean: Select new reference image? .le .ls refimagenum Number of new reference image .le .ls replace=no Boolean: Replace a point with average of others? .le .ls newpoint Image number of point to replace .le .ls avgpoints Points to average for replacement (enter as `1,2') .le .ls reenter Re-enter points (enter as `1,2') .le .ls normal=no Boolean: Normalize scales to a certain image? .le .ls normimagenum Number of normalization image .le .ih DESCRIPTION This task takes the formatted output photometry from photcheck, determines the magnitude differences and scalings of all images relative to the reference image listed on the first line of the photcheck output file, and displays the magnitude differences graphically. The graphics cursor is activated in case a printout is desired; once the cursor has been deactivated by hitting any key, three optional steps can be performed: .sp .nf 1. Specify a new reference image 2. Replace a point with the average of two other points 3. Normalize magnitude differences and scales to those of a given image .fi .sp If any step is performed, the new magnitude differences are displayed, and the graphics cursor reactivated. These options should really be performed only in the listed order; i.e. you should decide on the reference image before replacing points, and normalize the magnitude differences and scales only as the last step. If none of the three steps is desired, the task ends and outputs: .sp .nf -- output//".photscales" main output file -- (results=yes) output//".scales" list of imcombine input scales -- (results=yes) output//".weights" list of imcombine input weights -- (newref=yes) output//".photfile" copy of input file w/new ref. image -- (normal=yes) output//".photold" pre-norm. scales & mag differences .fi .sp The main output file lists image name, airmass, magnitude difference and error, photometric scaling and error, number of stars used, and individual star magnitude differences. .sp The task requires the `photscale.awk' awk script to reside in the phiirs directory, and exits with an error if this is not the case. .sp NEW REFERENCE IMAGE .sp If this step is performed, the magnitude differences and photometric scalings are recalculated relative to the photometry for the specified image. .sp POINT REPLACEMENT .sp If this step is performed, the specified point's delta_m and scale values are replaced with the average values of two other specified points. The errors of the two points' values are added in quadrature to determine the errors of the new values for the replaced point. .sp NORMALIZATION .sp If this step is performed, the magnitude differences and photometric scalings are normalized such that the specified image has delta_m=0 and scale=1, i.e.: .sp .nf delta_m_new = delta_m_old - delta_m_normimage scale_new = scale_old / scale_normimage scale_err_new = scale_err_old / scale_normimage .fi .sp The errors in the value of delta_m_normimage and scale_normimage are not factored in to the new values because the magnitude differences and scalings are all relative. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS .ih SEE ALSO photcheck .endhelp ./doc/precoadd.hlp0100644000151400000240000000447506334210366013231 0ustar phallgames.help precoadd Apr97 phiirs .ih NAME precoadd -- prepare images w/same pixel scales but dif't sizes for coadding .ih USAGE precoadd listsmall imgbig .ih PARAMETERS .ls listsmall List of smaller-size images .le .ls imgbig Sample larger-size image .le .sp .ls badzero Do pixels in masks have value of 0? .le .ls delorig Delete original images? .le .ih DESCRIPTION Sometimes you want to combine images taken on different telescopes with different pixel scales. Even if you resample to the same pixel scale, one set of images will be larger in size than the other. If you have more than about 120 images and thus need to stack them before combining, this is obviously a problem. This task solves the problem by copying the smaller images of size X,Y into the subregions [1:X,1:Y] of images equal in size to the larger images. .sp This task takes the list of smaller size images, and the name of any one of the larger images, and performs the following steps: .sp .nf 0. Divide images by throughput correction image, if needed. 1. Scale images by number of coadds, if needed. 2. Create a blank larger-image template by subtracting bigimg from itself. 3. Copy each of the smaller images into a different copy of the blank larger-image template. Also create large bad pixel images for each different bad pixel image listed in the headers of the smaller images. 4. Rename or delete the original images. 5. Multiply each larger images' bad pixel mask by 99999. and subtract it from the corresponding larger image. Such pixels will be ignored in the eventual coadd. Thus the original image names are now larger versions of the original images, with bad pixels set to -99999. 6. Fix bad pixel masks so bad pixels are zero instead of one. 7. Get statistics of output images using lower=-10000. to ignore bp's. .fi .sp This task can also be used with a list of images identical in size to bigimg. In that case the original image names end up the same size but with bad pixels set to -99999. This is useful for example when you have images with different bad pixel masks which are going to be stacked and would otherwise lose those individual bad pixel masks. .sp This task calls tasks fileroot, minv, and stsdas.toolbox.imgtools.imcalc. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS .ih SEE ALSO ircoadd, irrotate, irshift, irshift2, minv .endhelp ./doc/sctv.hlp0100644000151400000240000000147706305452675012437 0ustar phallgames.help sctv Feb95 phiirs .ih NAME sctv -- display image with display scaled to full range of image values .ih USAGE sctv image frame .ih PARAMETERS .ls image Input mask image to be displayed .le .ls frame Frame buffer for image display .le .ls fill Boolean: "Scale image to fit display window? .le .ls xcenter Display window horizontal center .le .ls ycenter Display window vertical center .le .ls xsize Display window horizontal size .le .ls ysize Display window horizontal size .le .ls xmag Display window horizontal magnification .le .ls ymag Display window horizontal magnification .ih DESCRIPTION This task displays an image with the display range forced to the minimum and maximum values in the image. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS .ih SEE ALSO .endhelp ./doc/onis6pt.hlp0100644000151400000240000000734506720603121013043 0ustar phallgames.help onis6pt Apr99 phiirs .ih NAME onis6pt -- shift & coadd ONIS CNOC 6-point roundabout dither pattern .ih USAGE onis6pt inlist imageroot niter .ih PARAMETERS .le .ls inlist List of input images .le .ls imageroot Root name for output files .le .ls niter=1 Number to append to output files .le .ls pair=all (BC|AD|FE|all) Pair of images to process (or all) .le .ls inspect=yes Inspect image lists before proceeding? .le .ls shiftlongaxes=yes Find shifts for image pairs w/overlapping long axes? .le .ls coaddlongaxes=yes Coadd image pairs w/overlapping long axes? .le .ls shortaxesmethod="both" (xreg|irshift|both|none) Shift-finding method for overlapping short axes .le .ls use_images=yes Measure shifts from images (not file) in nshift? .le .ls display_im=yes Display images for imexam in nshift? .le .ls redo=no Redo shift-finding if already done? .le .ls coaddallimages=yes Coadd all images? .le .ls secondpassxcor=yes Cross-correlate all images with coadded image? .le .ls coaddsecondpass=yes Coadd images after second-pass cross-correlation? .le .ls domkobjmask=yes Make coadded-image object mask (INTERACTIVE)? .le .ls domasklet=yes Make individual-image object masks? .le .ls echog = yes Beep when task is done? .le .ih DESCRIPTION This task requires the stsdas.imgtools package. .sp This task is an example of how to build a large mosaic from individual offset images which overlap at the edges, but not with one single image. This task assumes a 6-point roundabout dither pattern. The six pointings, each of which may consist of many individual dithered images, are denoted A through F and are arranged like this: .nf CDE BAF .fi The task assumes use of the ONIS array (512x1024) with long axis vertical as seen by IRAF (though this task can be used for non-ONIS data). Thus B&C, A&D, and E&F overlap along their long axes, and B&A, A&F, C&D, and D&E overlap along their short axes. The task first shifts & coadds B&C, A&D, and E&F, then shifts & coadds the BC, AD, and EF images into a final mosaic. .sp The task takes the list of ALL input images and separates them using the image titles into lists of images for the pointing (or image) pairs AD, BC, and FE (inlist//"_AB", etc.), allowing inspection of the created lists if desired. .sp Individual image pairs can now be analyzed via the "pair" parameter, or it can be set to "all" to analyze all pairs sequentially. Note that an "image pair" here means e.g. "A and B pointings", so it may consist of many individual dithered images. If shiftlongaxes=yes, irshift is used to find the offsets of image pairs along their long axes. If coaddlongaxes=yes, the images are then coadded to form the BC, AD, and/or EF coadded images. .sp For the remaining steps, "pair=all" is required. If shortaxesmethod!=none, shifts for all images are found using either immatch.xregister, irshift, or both on the BC, AD, and EF images. If coaddallimages=yes, all the images are coadded into the final image. If secondpassxcor=yes, all the images are cross-correlated with the final image to find improved offsets. If coaddsecondpass=yes, the images are coadded after this second-pass cross-correlation. If domkobjmask=yes, a coadded-image object mask is INTERACTIVELY created from the second-pass coadded image. If domasklet=yes, individual-image object masks are created from the coadded-image object mask. .sp This task is not the most elegant in phiirs, and is probably buggy at some level (particularly if the task is interrupted part way through), but is included in the hopes it is useful as a demonstration task. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS Are an underappreciated source of protein. .ih SEE ALSO onis3ew .endhelp ./doc/subpattern.hlp0100644000151400000240000000572406726075755013655 0ustar phallgames.help subpattern Mar99 phiirs .ih NAME subpattern -- subtract pattern noise .ih USAGE subpattern imagelist subsuffix .ih PARAMETERS .ls imagelist Image or @Imagelist to process .le .ls subsuffix Suffix to add to output images .le .sp .ls premask = yes Mask before processing? .le .ls maskword = OBJMASK Header keyword for mask to use .le .ls startline = 1 First line of pattern noise region (default 1 for ONIS) .le .ls finishline = 512 Last line of pattern noise region (default 512 for ONIS) .le .ls numsigrej = 2 Sigma rejection limits in iterstat .le .ls useimgs = yes Boolean: Use any pattern noise images listed in headers? .le .ls saveimgs = no Boolean: Save pattern noise images? .le .ls verbose = no Boolean: Print iterstat output? .le .ls sinewave = no Use sinewave instead of constant fit to pattern .le .ls interact = no Interactive sine wave fit? .le .ls blankname="blank_pattern.fits" Blank template image name .le .ls echog = yes Boolean: Beep when task is done? .le .ih DESCRIPTION This task was written to subtract pattern noise in the ONIS array, which shows up with slightly different values on each image line in one quadrant. In fact, the noise pattern is a sine wave which runs from (1,1) to (512,512) with period almost exactly 6*512 pixels. .sp The noise can be fit as a sine wave (assuming a period of exactly 6*512 pixels) but that option is even slower than the recommended line-average option. Still, for completeness: the sine wave fit option first slices the image up into rows, stacks them into six sequences of every 6th row, gets the iterative statistics for the 6*512=3072 sample points and interactively fits a sine wave to them, and finally uses imcalc to subtract the fitted pattern from the input image. .sp The (recommended) line-averaged pattern noise subtract option is as follows. For each image in "imagelist", this routine takes the iterative average of each line between "startline" and "finishline" (discarding >nsigrej-sigma outliers over <=10 iterations) and copies it to the appropriate line in "blankname". The task subtracts the pattern noise image from the original image, overwriting if subsuffix="". Header cards PTTRNIMG with the name of the pattern noise image and PTTRNSUB with value "Pattern noise subtracted" are added to the noise- subtracted image header. The pattern noise images are saved if "saveimgs=yes"; along with a list of those images if imagelist was a list (and a list of the subtracted images, if subsuffix!=""). .sp If the image already has a PTTRNIMG but not a PTTRNSUB card in its header, that image will be used if "useimgs=yes". If both cards are present, the subtraction won't be done again. If subsuffix!="" and the output image list already exists, the task won't run. .ih BUGS The task does not check to see if the output images already exist, just if the output image list does. If the PTTRNIMG card does not include the image suffix (e.g. ".imh" or ".fits"), the task will create a new pattern noise image. .ih SEE ALSO .endhelp ./doc/domeflat.hlp0100644000151400000240000000422306674324704013243 0ustar phallgames.help domeflat Mar96 phiirs .ih NAME domeflat -- flatten IR array images with previously created flatfield image .ih USAGE domeflat imagelist Flatstring darksub dark flatfield zeroout badmask logfile .ih PARAMETERS .ls imagelist Name of file containing list of images to process (do not use an `@'). .le .ls Flatstring String to be appended to output flattened images. An input image "image1.imh" will have corresponding flattened image "image1flat.imh" if flatstring="flat". .le .ls darksub Subtract Dark frame? (boolean: yes or no). .le .ls dark Name of the Dark frame to use, if darksub=yes. .le .ls flatfield Name of the Flatfield image to use. .le .ls zeroout Zero out bad pixels on the images? (boolean: yes or no). Note that if the flatfield already has bad pixels zeroed out on it, then the final flattened images will as well, no matter what this parameter is set to. .le .ls badmask Name of the bad pixel mask to use (good pixels=1), if zeroout=yes. .le .ls logfile Name of the log file. .le .ls tpl Throughput-correct images after flatfielding? (boolean: yes or no). .le .ls tplname FULL Name of throughput correction image to use, if tpl=yes. .le .ih DESCRIPTION This task applies a previously created flatfield to an input list of IR array images. The input images are unchanged; new flattened images are created, along with other files as follows: .sp * dark corrected, flattened, bad pixel zeroed frames called "*Flatstring.imh" .sp * a file (imagelist//flatstring) with the names of those images. .sp The steps of the routine are as follows: .sp 1) Enter the bad pixel mask name into the image header BPM and BPMASK parameters. .sp 2) Subtract off the Dark current from each image, if desired. Enter the name of the dark image used into the image header DARKSUB parameter. .sp 3) Flatten each image by dividing by the flat. Enter the name of the flat used into the image header FLATIMG parameter. .sp 4) Zero out the bad pixels on the final images, if desired. .sp 5) Divide the final images by the throughput correction image, if desired. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS .ih SEE ALSO irflat, mkflat, qkflat .endhelp ./doc/mkflat.hlp0100644000151400000240000000167406671266506012737 0ustar phallgames.help mkflat May95 phiirs .ih NAME mkflat -- make domeflat image from lamp-on and lamp-off images .ih USAGE mkflat onlist offlist outname titlestring .ih PARAMETERS .ls onlist List of lamp-on flats .le .ls offlist List of lamp-off flats .le .ls outname Name of coadded dark image .le .ls titlestring Title to insert into coadded dark image header .le .ls logfile Name of log file .le .ls badmask Bad pixel mask to use with maskstat .le .ls maskval Value for good pixels in bad pixel mask .le .ls gain Gain of array .le .ls noise Read noise of array .le .ih DESCRIPTION mkflat creates an output domeflat image by combining a list of IR domeflats taken with lamps on, and a list of domeflats with lamps off, and then subtracting the two images, normalizing by the output using "maskstat". .sp mkflat calls tasks fileroot, maskstat. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS .ih SEE ALSO domeflat .endhelp ./doc/photcomp.hlp0100644000151400000240000000321106130530703013256 0ustar phallgames.help photcomp Apr96 phiirs .ih NAME photcomp -- compare photometric properties of two images on same coord system .ih USAGE photcomp refimage compimage suffix .ih PARAMETERS .le .ls refimage Name of reference image .le .ls compimage Name of comparison image .le .ls suffix Suffix string for output files .le .sp .ls reflog="" Reference image imexam log to use (default=create new one) .le .ls center=yes Imexamine: center object in aperture? .le .ls background=yes Imexamine: fit and subtract background? .le .ls radius=5. Imexamine aperture photometry radius .le .ls buffer=10. Imexamine sky buffer .le .ls width=10. Imexamine sky annulus width .le .ls another Boolean: Do another comparison image? .le .ih DESCRIPTION This task calls the following other tasks: filecalc, fileroot. .sp This task allows you to do photometry on objects in two or more images on the same coordinate system. The positions and fluxes measured from the reference image or taken from the specified previously created reference image imexam log file, are used to do photometry on the comparison image and to compare the fluxes from both images. The individual percentage differences are plotted, the average percentage difference calculated and appended to the output "pcomp" file, the file is displayed for editing in case outliers should be removed, and then the average percentage difference is recalculated and displayed. .sp .sp The following files are created: .sp refimage//.pcomp//suffix output photometry for all image pairs .sp refimage//.plog//suffix imexam log for refimage .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS .ih SEE ALSO ircoadd .endhelp ./doc/sigmanorm.hlp0100644000151400000240000000126506164021107013430 0ustar phallgames.help sigmanorm Feb95 phiirs .ih NAME sigmanorm -- normalize image by the square root of its exposure map .ih USAGE sigmanorm image .ih PARAMETERS .ls image Name of image to renormalize .le .ls normimage="" Normalization image (exposure map) -- assumed to be exp//image if left as null .le .ls prefix="norm" Prefix for renormalized image .le .ih DESCRIPTION sigmanorm takes the exposure map for the input image, normalizes it to unit exposure time, takes its square root, and multiplies it into the input image to produce an image which should have uniform rms pixel-to-pixel noise across the entire exposed area. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS .ih SEE ALSO .endhelp ./doc/crzap2.hlp0100644000151400000240000000244006357236766012660 0ustar phallgames.help crzap2 Feb97 phiirs .ih NAME crzap2 -- remove stubborn cosmic rays using imexam & fixpix .ih USAGE crzap2 .ih PARAMETERS .ls inlist Input image(s) for cosmic ray cleaning .le .ls outlist Output image(s) .le .ls cleanup Delete CR mask & logfile after execution? .le .ih DESCRIPTION crzap2 was adapted from dimsum.xzap, courtesy Mark Dickinson. It is intended for use after crzap to remove stubborn cosmic rays. First, the image is displayed using imexam. Rectangular areas to be interpolated over should be identified by typing `b' in two opposite corner pixels of the regions. The logfile from imexam can be edited for mistakes, and then it is used by nmisc.test2mask to create a cosmic ray mask _crmask_img, which is in turn used by nmisc.fixpix to interpolate over the marked regions. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS There is an IRAF display bug that has existed since the dawn of time, involving a one-pixel mismatch between the displayed cursor x value and the true x value in the image. If you find that the regions you mark for interpolation are systematically off by one pixel in x, you can adjust for this by marking a region one pixel higher in x than you actually want. And don't blame me for this stupid bug, I'm just as much a victim as you are. .ih SEE ALSO crzap .endhelp ./doc/addring.hlp0100644000151400000240000000103706130047741013046 0ustar phallgames.help addring Feb95 phiirs .ih NAME addring -- add rings around all objects in a mask image .ih USAGE addring inmask outmask .ih PARAMETERS .ih inmask Name of input mask image .ih outmask Name of output mask image .ih ngrow Number of pixel rings to grow around mask .ih badval Value for bad pixels .ih DESCRIPTION This task takes an IRAF .pl mask image and grows the specified number of pixel rings around the bad pixels in it. Calls on task "minv". .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS .ih SEE ALSO minv .endhelp ./doc/qkflat.hlp0100644000151400000240000000743506704671443012741 0ustar phallgames.help qkflat Jan95 phiirs .ih NAME qkflat -- make flatfield & apply it to IR images .ih USAGE qkflat rootname imagelist flatstring fextension logfile darksub dark badmask zeroout badpix .ih PARAMETERS .ls rootname Root name for flattened image file. .le .ls imagelist Name of file containing list of images to process (do not use an `@'). .le .ls flatstring = "fq" String to be appended to output flattened images. An input image "image1.imh" will have corresponding flattened image "image1flat.imh" if flatstring="flat". .le .ls fextension= "fq" Extension to be added to the flatfield image. .le .ls logfile Name of log file. If null ("") then a file named rootname//".log" will be created. The log file will append to any existing file with the same name. .le .ls darksub=no (boolean) Subtract dark frame? .le .ls dark="" Name of the dark frame to use. .le .ls badmask="" Name of the bad pixel mask to use. .le .ls zeroout=no (boolean) Zero out bad pixels on both flat & images? Choose "no" if you plan to eventually do fractional-pixel shifting. .le .ls badpix=no (boolean) Add bad pixel mask name to image header? .le .sp .ls mkflat=no (hidden) Make flatfield image even if it already exists? .le .ls iterstat=yes (hidden) Use iterative means when constructing flats? .le .ls doflat=yes (hidden) Use the flatfield to create flattened images? .le .ls tpl=no (hidden) (boolean) Throughput-correct images after flatfielding? .le .ls tplname (hidden) FULL Name of throughput correction image to use, if tpl=yes. .le .ls v210=no (hidden) (boolean) Use "combine" instead of "imcombine" to avoid v2.10 imcombine bug? .le .ls imflatpars (hidden) Parameter set for imcombine operation used to create the flat. See help page for imcombine for description. .le .ls echog=yes (hidden) (boolean) Beep when task is done? .le .ih DESCRIPTION This task makes a single flatfield from an input list of IR array images and applies it to the images in that list. The input images are unchanged, but the following images/files are created: .sp * flattened (& optionally bad pixel zeroed) frames: *flatstring.imh .sp * a file (list.flatstring//rootname) with the names of those images .sp * the logfile .sp * the flatfield image (rootname//"."//ffextension//".imh") .sp The steps of the routine are as follows: .sp 1) Subtract off dark current, if desired. .sp 2) Normalize images by their bad-pixel-corrected means. .sp 3) Create flat field and normalize by its bad-pixel-corrected mean. If "iterstat=yes", a slightly better flat is produced, but it takes longer to make. .sp 4) Zero out bad pixels on flat (and thus on images), if desired .sp 5) Flatten each image. .sp A few notes: .sp * You should inspect the output images before moving on to the next task. I suggest doing imstat on all the output images and looking for images with outlying or rapidly changing means, as well as displaying maybe every 8th image to look for more insidious flaws. .sp * combine an EVEN NUMBER OF IMAGES, because when you use median combining with an odd number of images, you get a spike in the flattened image histograms from pixels taken from that image and put into the flat. I don't know how badly (if at all) this effect skews the statistics, but it seems best to avoid it. .sp * for the SO 256x256, rdnoise=73 and gain=15.3 .sp * if you intend to eventually shift by fractional pixels when stacking the images into a final coadded image, do not zero out bad pixels yet. (You will eventually be interpolating to do the fractional shift, and a zero-valued pixel causes problems in the interpolation.) .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS This task does NOT by itself allow for object masking, but it can be done with object masking if run in DOPHIIRS instead. .ih SEE ALSO domeflat, dophiirs, irflat, dophiirs .endhelp ./doc/first.hlp0100644000151400000240000000602206671256073012576 0ustar phallgames.help first Feb95 phiirs .ih NAME first -- add header params to raw images & subtract dark from them .ih USAGE first imagelist darksub badmask .ih PARAMETERS .ls imagelist List of images to process (do not use an `@') .le .ls darksub Boolean: subtract off dark frame? .le .ls badmask Name of bad pixel mask to add to image header .le .ls dark Name of dark frame to subtract .le .ls darkstring String to be appended to dark-subtracted images .le .ls coords Boolean: add RA, DEC, and EPOCH to image header? .le .ls airmass Boolean: Insert the airmass into the header of the image? .le .ls airauto Boolean: find the airmass of the image automatically? If airauto=no, you will be asked to enter the airmass or each image as the parameter `airval'. .le .ls airval Value of the airmass, if not finding it automatically. .le .ls epoch Epoch of the coordinates. .le .ls ra Right Ascension (surround the string with quotes to ensure proper formatting). .le .ls dec Declination (surround the string with quotes to ensure proper formatting). .le .ls observatory Observatory where observations were made (e.g. kpno, ctio, mtbigelow, mmto). .le .ls ut Boolean: is `TIME-OBS' in header ut or not? Needed for proper formatting of UT header keyword, which is needed for proper calculation of the airmass. .le .ls ddmmyy Boolean: is `DATE-OBS' in header in day/month/year format or not? Needed for proper formatting of `OBS-DATE', which is needed for proper calculation of the airmass. OBS-DATE should ALWAYS have format DD/MM/YY. .le .ih DESCRIPTION This routine adds various parameters to the IRAF image headers of IR images, and then subtracts the specified dark frame from them. Thus the dark-subtracted images also contain the header parameters added to the raw images. They also contain the additional header card "DARKSUB" which lists the image used in the dark-subtraction. .sp The automatically added header params are: .sp 1. BPM and BPMASK: bad pixel mask. .sp 2. coadds: number of internal coadds. This is taken either from the "ncoadds" or "comment" header card. .sp 3. exptime: total exposure time. This is equal to the exposure time per coadd times the number of coadds. .sp 4. obs-date: date of observation, in DD/MM/YY format. .sp 5. ut: universal time, sometimes = time-obs in original header, and sometimes equals time-obs + 7h. .sp The following parameters are optionally entered: .sp 6. epoch, ra, dec: entered as parameters .sp 7. st: Sidereal Time. This is calculated from the ut, obs-date, and observatory using the task astutil.asttimes and entered into the header if the airmass is being automatically entered. .sp 8. airmass: calculated from epoch, ra, dec, st, and obs-date if not entered manually. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS They're everywhere! They're crawling all over me!! .sp Also, the airmass+ airauto+ option assumes you're observing from the MST time zone. This hasn't been fixed simply because most image headers already have the airmass parameter in them. .ih SEE ALSO cfhtfirst, irimfirst, irtffirst, onisfirst, piscesfirst .endhelp ./doc/crzap.hlp0100644000151400000240000000524006320557414012561 0ustar phallgames.help crzap Feb97 phiirs .ih NAME crzap -- remove cosmic rays using median smoothing .ih USAGE crzap .ih PARAMETERS .ls inlist Input image(s) for cosmic ray cleaning .le .ls outlist Output image(s) .le .ls zboxsz Box size for zapping .le .ls nsigma Number of sky sigma for zapping threshold .le .ls nnegsigma Number of sky sigma for negative zapping .le .ls nrings Number of pixels to flag as buffer around CRs .le .ls nobjsigma Number of sky sigma for object identification .le .ls skyfiltsize Median filter size for local sky evaluation .le .ls skysubsample Block averaging factor before median filtering .le .ls ngrowobj Number of pixels to flag as buffer around objects .le .ls statsec Image section to use for computing sky sigma .le .ls deletemask Delete CR mask after execution? .le .ls cleanpl Delete other working .pl masks after execution? .le .ls cleanimh Delete working .imh images after execution? .le .ls verbose Verbose output? .le .ls unzap Unzap using objects from OBJmask files? .le .ls checklimits Check min and max pix values before filtering? .le .ls zmin Minimum data value for fmedian .le .ls zmax Maximum data value for fmedian .ih DESCRIPTION crzap was adapted from dimsum.xzap, courtesy Mark Dickinson. First, images.fmedian is used to produce a median filtered image where each pixel has been replaced by the median of pixel values from a box zboxsz pixels on a side. The median filtered image will have no cosmic rays except in cases where a cosmic ray covers enough pixels to distort the median in the given box size... try a bigger box size if not all cr's are removed at first. The task also allows a different median filtering box size for creating the object mask (see below); it sometimes helps to keep this box size small when increasing the filtering box size for cosmic ray detection. In the end, however, if you want complete removal of all cosmic rays you will probably have to edit a few stubborn ones by hand. Anyway, back to our story... The median filtered image is then subtracted from the original image to produce an "unsharp masked" image emphasizing cosmic rays. Pixels nsigma*skysig above the mean are flagged as possible cosmic rays. An object mask is then made from the median filtered image if parameter nobjsigma!=0, and pixels falling in such areas are removed from the cosmic ray image. Additionally, pixels falling in regions identified as objects in the object mask listed in the original image header will be excluded if unzap=yes. Finally, cosmic rays are replaced with the local median and the cosmic ray mask name is stored as CRMASK in the image header. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS .ih SEE ALSO fmedian, crzap2 .endhelp ./doc/destripe.hlp0100644000151400000240000000275406305455620013267 0ustar phallgames.help destripe Jun96 phiirs .ih NAME destripe -- interactively remove striping from a coadded image .ih USAGE destripe fiximage outname objmask .ih PARAMETERS .ls fiximage Name of image to be corrected .le .ls normimage="" Name of image to create .le .ls objmask Object mask to use (default=!OBJMASK header keyword) .le .ls ngrow Number of rings to grow around bad pixels .le .ls boxmin MKSKYCOR: Minimum smoothing box size at edges .le .ls boxmax MKSKYCOR: Maximum smoothing box size .le .ls ok Continue to next step (yes) or redo (no) .le .ls rot Redo using rotated image? .le .ls z Number of image to save (zero to delete all) .le .ih DESCRIPTION This is an interactive task to remove the striping sometimes seen on deep IRIM images. destripe takes the input image and object mask and interpolates over the objects using nmisc.fixpix, displaying the result. The user has the option of adding rings around the bad pixels and/or redoing the masking until it is satisfactory. Next, the image is smoothed using ccdred.mkskycor and the stripe and stripe-subtracted images are displayed. Again, the process can be repeated and the user chooses the minimum and maximum box smoothing sizes (we recommend they be set equal to each other). The option also exists to redo the smoothing and subtraction after rotating the image by 90 degrees: since much of IRAF works line-by-line, the final results can depend on the orientation of the striping. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS .ih SEE ALSO .endhelp ./doc/irimfirst.hlp0100644000151400000240000001251406671256077013466 0ustar phallgames.help irimfirst Jul95 phiirs .ih NAME irimfirst -- add header params, do nonlinearity correction, & subtract dark .ih USAGE irimfirst inlist nonlin darksub .ih PARAMETERS .ls imagelist List of images to process (do not use an `@') .le .ls nonlin Boolean: do nonlinearity correction? .le .ls darksub Boolean: subtract off dark frame? .le .ls suffix String to be appended to output images .le .ls slope Slope coefficient of nonlinearity correction .le .ls iintname Name of integration time header keyword .le .ls replace Replace `saturated' pixels? .le .ls maxval Maximum good raw data value .le .ls dark Name of dark frame to subtract .le .ls badmask Name of bad pixel mask to add to image header .le .ih DESCRIPTION This routine first optionally applies a nonlinearity correction to the images, a correction which has been previously determined e.g. with "nl_findcor.cl". See the discussion below. It then optionally subtracts a specified dark frame from them, and lastly adds various parameters to the IRAF image headers. If dark subtraction is done, the raw images will not also contain the header parameters added to the dark-subtracted images. The dark-subtracted images also contain the additional header card "DARKSUB" which lists the image used in the dark-subtraction. .sp The automatically added header params are: .sp 1. BPM: bad pixel mask. .sp 2. coadds: number of internal coadds. This is taken either from the "ncoadds" or "comment" header card. .sp 3. exptime: total exposure time. This is equal to the exposure time per coadd times the number of coadds. .sp 4. obs-date: date of observation, in DD/MM/YY format. .sp NONLINEARITY CORRECTION .sp This can be computed using the task "nl_findcor.cl". The output of that task is the `slope' (inverse slope, really) of the relation between the ratio of observed & input counts to the observed counts: .sp observed/input = 1 - observed / slope .sp This slope is used in the equation (derived below) actually employed to make the nonlinearity correction: .sp new_value = old_value / (1 - old_value * intfactor/slope) .sp where intfactor = 1 + 2*delaytime/intime, where delaytime is the time between biasing and the first (non-destructive) read of the bias, and intime is the integration time listed in the image header. .sp For IRIM, .sp delaytime = 1.0 if intime >= 1.381 .sp delaytime = intime - 0.381 if intime < 1.381 .sp .sp NONLINEARITY CORRECTION THEORY (mostly from the SQIID manual) .sp The output from IR arrays is a not strictly a linear function of the input signal: the pixels are biased to establish a potential well where charge can accumulate; this potential well gradually weakens as charge accumulates on the node capacitance, effectively changing (decreasing) the gain of that pixel. Since the total capacitance (which determines system gain) is the sum of the distributed (non-varying) capacitance of the system and the (variable) capacitance at each detector node, the degree of non-linearity is a function of the ratio of nodal to total capacitance. As a direct consequence, pixel response departs from linearity in a predictable fashion for accummulated signals above a device-specific level. Since key pixel parameters such as quantum efficiency are very uniform, the linearity appears to be a global property of the array rather than pixel specific. .sp The data fit were always within the regime where this correction for unseen charge was small. This is not the case, for example, when doing 5 sec integrations on standards! .sp The linearity correction is used to recontruct the input value during an integration time t on the basis of the difference between the observed values at times d and t+d (d=delay time): .sp obs_t = obs(t+d) - obs(d) .sp where each observation is itself subject to a linearity correction: .sp input_t = input(t+d) - input(d) .sp Keep in mind that obs_t, t, d, and the `slope' of the linearity correction are the only variables we know; everything else is determined from them. .sp Thus: .sp obs(t+d) = obs_t * ((t+d)/t) .sp obs(d) = obs_t * (d/t) .sp The known relation between observed and input counts is: .sp observed/input = 1 - observed / slope .sp or .sp input = observed / (1 - observed/slope) .sp Thus input_t = input(t+d) - input(d) becomes .sp input_t = [obs_t*(t+d)/t]/[1-obs_t*(t+d)/(t*slope)] - [obs_t*d/t]/[1-obs_t*d/(t*slope)] .sp We can approximate this using (1-x)^{-1} ~ 1+x as follows: .sp input_t = obs_t*[1 + d/t + obs_t*(t+d)/(t*slope) + obs_t*(t+d)*d/(slope*t^2) - d/t - obs_t*d^2/(slope*t^2)] .sp = obs_t*[1+obs_t*(t+2d)/(t*slope)] .sp = obs_t/[1-obs_t*(t+2d)/(t*slope)] .sp using the same approximation (1-x)^{-1} ~ 1+x again in the last step. This approximation should be good for x<~0.1, beyond which the array is extremely nonlinear anyway (above the knee in the curve). .sp Thus we can write, finally: .sp input_t = obs_t / (1 - obs_t * intfactor/slope) .sp where intfactor = (t+2d)/t and d is the delay time between biasing and the first (non-destructive) read of the bias. For IRIM, .sp d = 1.0 if t >= 1.381 .sp d = t - 0.381 if t < 1.381 .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS They're everywhere! They're crawling all over me!! .ih SEE ALSO cfhtfirst, first, irtffirst, onisfirst, piscesfirst .endhelp ./doc/irtffirst.hlp0100644000151400000240000001423106671256102013455 0ustar phallgames.help irtffirst Mar97 phiirs .ih NAME irtffirst -- add header params, do nonlinearity correction, & subtract dark .ih USAGE irtffirst inlist nonlin darksub .ih PARAMETERS .ls imagelist List of images to process (do not use an `@') .le .ls nonlin Boolean: do nonlinearity correction? .le .ls darksub Boolean: subtract off dark frame? .le .ls suffix String to be appended to output images .le .ls slope Slope coefficient of nonlinearity correction .le .ls iintname Name of integration time header keyword .le .ls replace Replace `saturated' pixels? .le .ls maxval Maximum good raw data value .le .ls dark Name of dark frame to subtract .le .ls badmask Name of bad pixel mask to add to image header .le .ih DESCRIPTION This routine first optionally applies a nonlinearity correction to the images, a correction which has been previously determined e.g. with "nl_findcor.cl". See the discussion below. It then optionally subtracts a specified dark frame from them, and adds various parameters to the IRAF image headers. One IRTF/NSFCAM-specific thing is the division of the images by the value of the header keyword DIVISOR (=# of coadds). Most arrays give you the counts and integration time of a single coadd. (i.e. all coadds have been averaged internally.) IRTF NSFCAM gives you the TOTAL counts of all coadds but the integration time of a SINGLE coadd. Thus the need to divide by DIVISOR as well as insert EXPTIME as usual. If dark subtraction is done, the raw images will not also contain the header parameters added to the dark-subtracted images. The dark-subtracted images also contain the additional header card "DARKSUB" which lists the image used in the dark-subtraction. .sp The automatically added header params are: .sp 1. BPM and BPMASK: bad pixel mask. .sp 2. date-obs: UT date of observation, from date_obs (DD/MM/YY) .sp 3. time-obs and ut: UT time of observation, from time_obs (UT time) .sp 4. coadds: number of internal coadds, from co_adds .sp 5. DIVIDED: added after image is divided by header keyword DIVISOR .sp 6. exptime: total exposure time. This is equal to the exposure time per coadd times the number of coadds. .sp 7. obs-date: date of observation, in DD/MM/YY format, from date-obs. (UT date) Assumes that date_obs and date-obs are in DD/MM/YY format. .sp NONLINEARITY CORRECTION .sp This can be computed using the task "nl_findcor.cl". The output of that task is the `slope' (inverse slope, really) of the relation between the ratio of observed & input counts to the observed counts: .sp observed/input = 1 - observed / slope .sp This slope is used in the equation (derived below) actually employed to make the nonlinearity correction: .sp new_value = old_value / (1 - old_value * intfactor/slope) .sp where intfactor = 1 + 2*delaytime/intime, where delaytime is the time between biasing and the first (non-destructive) read of the bias, and intime is the integration time listed in the image header. .sp For IRIM, .sp delaytime = 1.0 if intime >= 1.381 .sp delaytime = intime - 0.381 if intime < 1.381 .sp .sp NONLINEARITY CORRECTION THEORY (mostly from the SQIID manual) .sp **NOTE** that the delaytime values (see above) in this task are set (in the code) to those of IRIM. If an IRTF nonlinearity correction is ever needed, these values will need to be changed. .sp The output from IR arrays is a not strictly a linear function of the input signal: the pixels are biased to establish a potential well where charge can accumulate; this potential well gradually weakens as charge accumulates on the node capacitance, effectively changing (decreasing) the gain of that pixel. Since the total capacitance (which determines system gain) is the sum of the distributed (non-varying) capacitance of the system and the (variable) capacitance at each detector node, the degree of non-linearity is a function of the ratio of nodal to total capacitance. As a direct consequence, pixel response departs from linearity in a predictable fashion for accummulated signals above a device-specific level. Since key pixel parameters such as quantum efficiency are very uniform, the linearity appears to be a global property of the array rather than pixel specific. .sp The data fit were always within the regime where this correction for unseen charge was small. This is not the case, for example, when doing 5 sec integrations on standards! .sp The linearity correction is used to recontruct the input value during an integration time t on the basis of the difference between the observed values at times d and t+d (d=delay time): .sp obs_t = obs(t+d) - obs(d) .sp where each observation is itself subject to a linearity correction: .sp input_t = input(t+d) - input(d) .sp Keep in mind that obs_t, t, d, and the `slope' of the linearity correction are the only variables we know; everything else is determined from them. .sp Thus: .sp obs(t+d) = obs_t * ((t+d)/t) .sp obs(d) = obs_t * (d/t) .sp The known relation between observed and input counts is: .sp observed/input = 1 - observed / slope .sp or .sp input = observed / (1 - observed/slope) .sp Thus input_t = input(t+d) - input(d) becomes .sp input_t = [obs_t*(t+d)/t]/[1-obs_t*(t+d)/(t*slope)] - [obs_t*d/t]/[1-obs_t*d/(t*slope)] .sp We can approximate this using (1-x)^{-1} ~ 1+x as follows: .sp input_t = obs_t*[1 + d/t + obs_t*(t+d)/(t*slope) + obs_t*(t+d)*d/(slope*t^2) - d/t - obs_t*d^2/(slope*t^2)] .sp = obs_t*[1+obs_t*(t+2d)/(t*slope)] .sp = obs_t/[1-obs_t*(t+2d)/(t*slope)] .sp using the same approximation (1-x)^{-1} ~ 1+x again in the last step. This approximation should be good for x<~0.1, beyond which the array is extremely nonlinear anyway (above the knee in the curve). .sp Thus we can write, finally: .sp input_t = obs_t / (1 - obs_t * intfactor/slope) .sp where intfactor = (t+2d)/t and d is the delay time between biasing and the first (non-destructive) read of the bias. For IRIM, .sp d = 1.0 if t >= 1.381 .sp d = t - 0.381 if t < 1.381 .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS They're everywhere! They're crawling all over me!! .ih SEE ALSO cfhtfirst, first, irimfirst, onisfirst, piscesfirst .endhelp ./doc/qksky.hlp0100644000151400000240000000514206704671443012612 0ustar phallgames.help qksky Jan95 phiirs .ih NAME qksky -- sky-subtract IR images .ih USAGE qksky rootname imagelist logfile substring sextension stdpars stdstar zeroout maskname tpl tplname .ih PARAMETERS .ls rootname Root name for sky-subtracted image file. .le .ls imagelist List of images to process. .le .ls logfile Name of log file. If null ("") then a file named rootname//".log" will be created. The log file will overwrite any existing file with the same name. .le .ls substring Suffix for sky subtracted output images .le .ls sextension Extension to be added to the sky image .le .ls stdpars Use the standard parameters for imcombine? They are: combine=average, rej=minmax, scale=!SKYMED, zero=none, weight=none, nlow=1, nhigh=1 .le .ls stdstar Are these standard star images? .le .ls zeroout Zero out bad pixels on both flat & images? .le .ls maskname Name of mask image to use .le .ls tpl Divide by throughput correction after sky-subtraction? .le .ls tplname Name of throughput correction image to use .le .sp .ls subpattern = no Subtract pattern noise (before tpl)? .le .ls mksky = no Make sky image even if it already exists? .le .ls iterstat = yes Use iterative means when constructing sky? YOU'RE STRONGLY ADVISED TO KEEP THIS SET TO YES! THIS TASK IS NOT GUARANTEED TO WORK IF ITERSTAT=NO! .le .ls dosky = yes Subtract sky from images once it's created? .le .ls addsky = no Add constant median sky level after subtraction? .le .ls forcescale = no Force recalculation of image medians? .le .ls premask = no Mask when scaling before creating sky? .le .ls imskypars Parameter set for imcombine parameters .le .ls echog = yes Beep when task is done? .le .ih DESCRIPTION This task creates a sky image from the images in the input list and subtracts the sky image from each image in the input list. The input images are unchanged; new sky-subtracted images are created, along with other files as follows: .sp * sky-subtracted, optionally bad pixel zeroed frames: *substring.imh .sp * a file (list.rootname.substring) listing those images .sp * the logfile .sp * the sky image (rootname//"."//sextension//".imh") .sp It is HIGHLY RECOMMENDED that you inspect the flatfielded input images in some way before running the task. I suggest doing "imstat" on the input images and looking for images with outlying or rapidly changing means, as well as displaying some or all of the images to look for more insidious flaws in the flat fielding. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS Comprise 90\% of all known species of life on Earth. .sp THIS TASK IS NOT GUARANTEED TO WORK IF ITERSTAT=NO!! .ih SEE ALSO dophiirs, irsky .endhelp ./doc/irtfphotscale.hlp0100644000151400000240000001031306502623442014303 0ustar phallgames.help irtfphotscale Mar96 phiirs .ih NAME irtfphotscale -- calculate photometric scalings of a data set .ih USAGE irtfphotscale photfile output .ih PARAMETERS .ls photfile Photometry data file from photcheck .le .ls output Root name for output file(s). If this file already exists, the magnitude differences in it will be plotted in the standard photscale format, but no changes can be made to it. .le .sp .ls apcor=no Use aperture corrections? Such corrections must have been previously calculated with e.g. photcal.mkapfile. .le .ls apfile File of aperture corrections (coadded image first), one value per image listed in column 1, no extraneous lines or columns please. .le .ls display=yes Boolean: Automatically display lightcurve (requires STSDAS)? .le .ls results=no Boolean: Output computed scales and weights? .le .ls newref=no Boolean: Select new reference image? .le .ls refimagenum Number of new reference image .le .ls replace=no Boolean: Replace a point with average of others? .le .ls newpoint Image number of point to replace .le .ls avgpoints Points to average for replacement (enter as `1,2') .le .ls reenter Re-enter points (enter as `1,2') .le .ls normal=no Boolean: Normalize scales to a certain image? .le .ls normimagenum Number of normalization image .le .ih DESCRIPTION This task is exactly the same as photscale.cl, but has been reworked to use perl scripts instead of the CTIO package (unavailable at IRTF). You will need to edit the source code to include the correct path names of the perl scripts. .sp This task takes the formatted output photometry from photcheck, determines the magnitude differences and scalings of all images relative to the reference image listed on the first line of the photcheck output file, and displays the magnitude differences graphically. The graphics cursor is activated in case a printout is desired; once the cursor has been deactivated by hitting any key, three optional steps can be performed: .sp .nf 1. Specify a new reference image 2. Replace a point with the average of two other points 3. Normalize magnitude differences and scales to those of a given image .fi .sp If any step is performed, the new magnitude differences are displayed, and the graphics cursor reactivated. These options should really be performed only in the listed order; i.e. you should decide on the reference image before replacing points, and normalize the magnitude differences and scales only as the last step. If none of the three steps is desired, the task ends and outputs: .sp .nf -- output//".photscales" main output file -- (results=yes) output//".scales" list of imcombine input scales -- (results=yes) output//".weights" list of imcombine input weights -- (newref=yes) output//".photfile" copy of input file w/new ref. image -- (normal=yes) output//".photold" pre-norm. scales & mag differences .fi .sp The main output file lists image name, airmass, magnitude difference and error, photometric scaling and error, number of stars used, and individual star magnitude differences. .sp The task requires the `photscale.awk' awk script to reside in the phiirs directory, and exits with an error if this is not the case. .sp NEW REFERENCE IMAGE .sp If this step is performed, the magnitude differences and photometric scalings are recalculated relative to the photometry for the specified image. .sp POINT REPLACEMENT .sp If this step is performed, the specified point's delta_m and scale values are replaced with the average values of two other specified points. The errors of the two points' values are added in quadrature to determine the errors of the new values for the replaced point. .sp NORMALIZATION .sp If this step is performed, the magnitude differences and photometric scalings are normalized such that the specified image has delta_m=0 and scale=1, i.e.: .sp .nf delta_m_new = delta_m_old - delta_m_normimage scale_new = scale_old / scale_normimage scale_err_new = scale_err_old / scale_normimage .fi .sp The errors in the value of delta_m_normimage and scale_normimage are not factored in to the new values because the magnitude differences and scalings are all relative. .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS .ih SEE ALSO photcheck .endhelp ./doc/dophiirs.hlp0100644000151400000240000003476106704671440013277 0ustar phallgames.help dophiirs Feb99 phiirs .ih NAME dophiirs -- run PHIIRS in batch mode .ih USAGE dophiirs ilist rootname badpixmask instrument .ih COMMAND-LINE PARAMETERS .ls ilist List of original images .le .ls rootname Rootname to use for files .le .ls badpixmask Bad pixel mask (if none, set masktyp=none) .le .ls instrument = generic Generic or specific instrument? Choices are currently: (generic|irim|kir|nsfcam|onis|pisces|so256) .le .ih WHICH TASKS TO DO? PARAMETERS .ls dofirst=no Add header parameters to raw images? .le .ls redo=no Redo a step even if it's already been done? .le .ls subdark="" Dark to subtract (dofirst+/domeflat/qkflat) .le .ls doflat="none" Which task to use for flattening? Choices are currently: (none|domeflat|irflat|qkflat) .le .ls dosky="none" Which task to use for flattening? Choices are currently: (none|irsky|qksky) .le .ls objmask=no Use object masks to make flat & sky? .le .ls getstats=no Get statistics for images to be coadded? .le .ls doshift=no Measure image shifts (poss. INTERACTIVE)? .le .ls docoadd=no Do coadding? .le .ls domkobjmask=no Make coadded-image objmask (poss. INTERACTIVE)? .le .ls domasklet=no Make individual-image objmasks (poss. INTERACTIVE)? .le .ls dotrim=no Create constant-rms image w/minimum exptime? .le .ls makenoise=yes Beep when tasks are done? .le .ih GENERAL PARAMETERS .ls darkstring="d" String to append to dark-subtracted images .le .ls flatstring="f" String to append to flat-fielded images .le .ls skystring="s" String to append to sky-subtracted images .le .ls logfile="" Name of log file (default="log_"//ilist) .le .ls imflatpars="" Generic IRFLAT/QKFLAT imcombine params filename .le .ls imskypars="" Generic IRSKY/QKSKY imcombine params filename .le .ls imcoaddpars="" Generic IRCOADD imcombine params filename .le .ls masktyp="badval" Mask type (badval|goodval|none) .le .ls maskval=0. Mask value for mask type (goodval|badval) pixels .le .ls im_extn="fits" Image type extension to use .le .ih DOFIRST+ PARAMETERS .ls coords=no Add RA, DEC, and EPOCH to image header? .le .ls airmass=no Enter airmass into image header? .le .ls airauto=no Find airmass of image automatically? .le .ls epoch="" Epoch of coordinates .le .ls ra="" Right Ascension (surround with quotes) .le .ls dec="" Declination (surround w/quotes; use - but not +) .le .ls observatory="" Observatory where observations were made .le .ls ut=yes Is 'time-obs' in header ut or not? .le .ls ddmmyy=no Is 'date-obs' in day/month/year format .le .ih FLATFIELDING & SKY-SUBTRACTION PARAMETERS .ls zeroout=no Zero out bad pixels (domeflat/qkflat/qksky)? .le .ls flatfield="" Name of flatfield image to use (domeflat) .le .ls flat_num=INDEF Total even # of imgs for running flat (irflat) .le .ls flatsave=no Save individual flatfield images? .le .ls objmsuffix="om" Suffix of object masks .le .ls remake=no Remake existing flat or sky (qkflat/qksky)? .le .ls iterstat=yes Use iterative means for quick flats & skys? .le .ls apply=yes Apply quick flats & skys to images once created? .le .ls sky_num=INDEF Total even # of images for running sky (irsky) .le .ls skysave=no Save individual sky images? .le .ls patternsub="never" Subtract pattern noise (during|after) skysub, or (never). Subtraction is done in IRSKY or QKSKY if patternsub="during", or directly with SUBPATTERN if patternsub="after". .le .ls whentpl="never" Throughput-correct images after (flat|sky|never)? .le .ls tplname="" FULL name of throughput correction image .le .ls addsky=no Add constant median sky level after subtraction? .le .ls forcescale=no Force recalculation of image medians? .le .ls premask=no Mask when scaling before creating sky? .le .ls shortcut=yes Use quick way to scale sky for subtraction? .le .ih IRSHIFT PARAMETERS (DOSHIFT+) .ls refimage="" Name of reference image for irshift .le .ls prefix="" irshift files prefix string (default=rootname) .le .ls suffix="" irshift files suffix string (default=shN; N=1,2..) .le .ls useimages=yes Measure shifts from images instead of a file? .le .ls displayim=yes Display images for imexam? .le .ls ptv=no Use phat.ptv instead of display in imexam? .le .ls imsection="" Image section to display in imexam? .le .ls editfiles=yes Display coords files for editing? .le .ih IRCOADD PARAMETERS (DOCOADD+) .ls coaddimage="" Coadded image name (default=rootname//_coaddN, N=1,2...) .le .ls expmap="" Exposure map image (default=coaddimage//em) .le .ls scaling="none" Scaling for coadd (none|@file|!keyword|etc.) .le .ls zeroing="mode" Zero offsets for coadd (none|@file|mode|etc.) .le .ls weighting="none" Weighting for coadd (none|@file|!keyword|etc.) .le .ls magfac=1 (min = 1, max = 10) Subpixel shifting magnification factor .le .ls prescale=no Scale images before, not during, imcombine? .le .ls prezero=no Do zero offseting before, not during, imcombine? .le .ls stack=no Combine images by stacking & projecting? .le .ls unstack=no Delete stacked image & expmap when done? .le .ls unzero=no Undo zero offsets when done? .le .ls unscale=no Undo scaling factors when done? .le .ls putscale=no Insert scaling factors into image headers? .le .ls wordscale="SCALEFAC" Scaling factor header keyword .le .ls putzero=no Insert zero offsets into image headers? .le .ls wordzero="ZEROVAL" Zero offset header keyword .le .ls putweight=no Insert weights into image headers? .le .ls wordweight="WEIGHT" Weighting factor header keyword .le .ls extcoeff=0.05 Extinction coefficient for default scalings .le .ls airzero=1. Airmass to scale to? (INDEF=min. observed) .le .ls maskedstat=no Use maskstat to find default zeros & weights? .le .ls statfile="" File for image statistics .le .ls makeavg=no Make pure coadd (comb=average,rej=none)? .le .ls flip=no Flip image L-R after coadd? .le .ih MKOBJMASK/MASKLET PARAMETERS (DOMKOBJMASK+/DOMASKLET+) .ls areamask="" Exposed area mask (default: image//mask.pl) .le .ls subtract=no Subtract average beforehand (ALSO DOTRIM+)? .le .ls substring="sub" Suffix string for subtracted image, if made .le .ls nsmooth = 3 (min = 0) Boxcar smoothing filter size (ODD values only) .le .ls subsample = 1 (min = 1) Subsampling factor before median filtering .le .ls filtsize = 15 (min = 1) Filter size for local median sky evaluation .le .ls ngrow = 1 (min = 0) Width of rings to grow around masked objects .le .ls interact=yes Interactively examine normalized image? .le .ls editimshift=yes Edit Image+Shifts file in masklet? .le .ih TRIM PARAMETERS (DOTRIM+; ALSO subtract UNDER MKOBJMASK ABOVE) .ls stats="" File to contain trimmed image RMS values .le .ls mingoodexp=0.36 Minimum acceptable exptime (fraction of maximum) .le .ih DESCRIPTION This task is intended for use when you want to run PHIIRS in batch mode on a set of images with a minimum of intervention. By setting the "instrument" parameter away from its default of "generic", it will automatically use the default parameters for that array. The task is designed to run smoothly using these defaults, but I still recommend doing "epar dophiirs" and looking over all the parameters before running the task, Parameters to watch out for include "masktyp", "maskval", "im_extn", "flatfield", and "remake". DOPHIIRS can be made completely non-interactive by setting "editfiles=no" (for irshift), "interact=yes" (for mkobjmask), and "editimshift=yes" (for masklet), although in practice you will rarely want to make it non-interactive. .sp The individual tasks are run via the "WHICH TASKS TO DO?" parameters. You should first do "dophiirs dofirst+", then proceed to the other tasks. DOPHIIRS subtracts a dark image if requested, creating new images with "darkstring" appended. Flatfielding is done on dark-subtracted images if they exist, or raw images otherwise, creating new images with "flatstring" appended. Sky-subtraction is done on flat-fielded images if they exist, or raw images otherwise, creating new images with "skystring" appended. "doshift" and/or "docoadd" is done on sky-subtracted images if they exist, or flat-fielded images otherwise. A first-pass run might do everything up through "domasklet+"; a second-pass run would redo sky-subtraction and maybe flat-fielding using "objmask=yes", then do "docoadd+" with "zeroing=@zeros" and "weighting=@weights". After checking for photometric stability using PHOTCHECK and PHOTSCALE and possibly rotating/resampling with IRROTATE (all outside of DOPHIIRS), a final run would do "docoadd+" (possibly with "scaling=@scales") & "dotrim+". .sp If you choose a specific instrument (instrument!="generic"), the values for some parameters are ignored in favor of the default values for that instrument; see below for a list of parameters reset for each instrument. .sp Most importantly, if you choose a specific instrument you can leave the "imflatpars", "imskypars", and "imcoaddpars" strings set to "". (Found under GENERAL PARAMETERS, these govern flattening, sky-subtraction, & coadding.) DOPHIIRS will then use the instrument-specific parameter set found in the phiirs$ directory (i.e. phiirs$irflatkir.par, phiirs$irskykir.par, and phiirs$ircoaddkir.par for the KIR instrument; see IRFLAT/QKFLAT, IRSKY/QKSKY, and IRCOADD for details on the individual im*pars parameter sets). Of course, you can reset the im*pars string values away from "" to override the defaults for each instrument, or if you're using "instrument=generic". If "instrument=generic" and imflatpars="" and/or imskypars="", then the flattening and/or sky-subtraction is done with "stdpars=yes". Coadding also uses "stdpars=yes" if imcoaddpars="", with the one exception that "makeavg=yes" forces the use of "combine=average" and "rejection=none" in imcombine regardless of what imcoaddpars is set to. Also, for DOCOADD+, don't forget to set the "scaling", "zeroing" and "weighting" parameters as desired, as they are NOT set via "imcoaddpars". .sp .ih MISCELLENIA: .sp Keeping "redo=no" means you don't have to keep track of what's been done; i.e. you can type "dophiirs doflat=irflat dosky=irsky doshift+" and then "dophiirs doflat=irflat dosky=irsky doshift+ docoadd+" and DOPHIIRS will just do the coadding the second time around (same as "dophiirs docoadd+"). NOTE THAT "redo=no" DOES NOT WORK WHEN "dofirst=yes", and that "redo=yes" doesn't make any difference for "domkobjmask+", "domasklet+", & "dotrim+"; and that "redo=yes" only works for "doshift+" if suffix="". .sp If "redo=yes" and a list of images DOPHIIRS wants to create already exists, it will change the suffix being used so that a new list (and presumably new images) can be safely created. The suffix used will just be the old suffix concatenated with itself as many times as needed. .sp For "doflat=irflat" and "dosky=irsky", if the number of images to use is set to "INDEF", DOPHIIRS will use the largest EVEN number of images less than the total number of input images. .sp For "doflat=qkflat" and "dosky=qksky", if "remake=no" and the flat or sky image DOPHIIRS wants to create already exists but the list of images to be created doesn't, DOPHIIRS won't recreate the flat or sky but instead use the pre-existing one. .sp For "doshift+", if "prefix" or "refimage" are set to "", DOPHIIRS will set "prefix=rootname" and "refimage" to the first image listed. If "suffix" is set to "", DOPHIIRS will choose the first available string of the form "shN", where N=1,2,3.... .sp For "docoadd+", don't forget to set the "scaling", "zeroing" and "weighting" parameters as desired, as they are NOT set via "imcoaddpars". If "coaddimage" is set to "", DOPHIIRS will choose the first available string of the form rootname//"_coaddN", where N=1,2,.... If "prefix" is set to "", DOPHIIRS will set "prefix=rootname". If "suffix" is set to "", DOPHIIRS will choose a string of the form "shN", where N is the highest number correspoding to a file that actually exists. If "statfile" is set to "", DOPHIIRS will set it to s_list//".stats", where "s_list" is the list of images being coadded. .sp For "domkobjmask+", "domasklet+" and/or "dotrim+", if coaddimage="", DOPHIIRS will look for the image rootname//"_coaddN" with the highest N. .sp Most individual-task parameters are read into DOPHIIRS as "d_*"; e.g. you enter "flip=yes", but DOPHIIRS reads it in as "d_flip=yes". .sp Not all options can be done within DOPHIIRS. If you want to do a nonlinearity correction, you will have to run IRIMFIRST or IRTFFIRST outside of DOPHIIRS. If you have trouble running a particular parameter combination for the first time, try running it repeatedly until it works or has a consistent error. Then try running it outside of DOPHIIRS once, or even just setting up its parameters directly, and then running it in DOPHIIRS. Also try re-typing in the first three entries of any parameter sets being used; who knows why that helps, but it does. .sp Even if you properly set "im_extn=fits" (or whatever the correct image extension is that you're using), it's a good habit to also include that extension on all image names you specify, just in case. .sp .ih PARAMETERS FOR INSTRUMENT != GENERIC .nf instrument=irim: observatory="kpno", imflatpars="phiirs$irflatirim.par", imskypars="phiirs$irskyirim.par", imcoaddpars="phiirs$ircoaddirim.par" .fi .nf instrument=kir: observatory="cfht", premask=yes, maskedstat=yes, imflatpars="phiirs$irflatkir.par", imskypars="phiirs$irskykir.par", imcoaddpars="phiirs$ircoaddkir.par", nsmooth=9, subsample=7, filtsize=15, ngrow=15 .fi .nf instrument=nsfcam: observatory="cfht", imflatpars="phiirs$irflatirtf.par", imskypars="phiirs$irskyirtf.par", imcoaddpars="phiirs$ircoaddirtf.par" .fi .nf instrument=onis: observatory="kpno", premask=yes, maskedstat=yes, imflatpars="phiirs$irflatonis.par", imskypars="phiirs$irskyonis.par", imcoaddpars="phiirs$ircoaddonis.par" .fi .nf instrument=pisces: observatory="kpno", premask=yes, maskedstat=yes, imflatpars="phiirs$irflatpisces.par", imskypars="phiirs$irskypisces.par", imcoaddpars="phiirs$ircoaddpisces.par" .fi .nf instrument=so256: imflatpars="phiirs$irflat256.par", imskypars="phiirs$irsky256.par", imcoaddpars="phiirs$ircoadd256.par" .fi .ih BUGS .sp Note that this task apparently has close to the maximum number of parameters allowed by IRAF. I think you could have four more, but that's it. .sp **fix imgs messed up from onisfirst runaway itime - exptime feedback **synch chooyu & chomsky pkgs **onisfirst.hlp on chomsky **README (on JAC computers): iterstat bit, irshift sections .endhelp ./doc/addcomment.hlp0100644000151400000240000000113006130054633013541 0ustar phallgames.help addcomment Jan95 phiirs .ih NAME addcomment -- append 'COMMENT' cards to image headers .ih USAGE addcomment image comment .ih PARAMETERS image Image(s) to which to append comment card .ih comment Text of comment .ih verify Verify header? .ih answer Update header? .ih DESCRIPTION All existing 'COMMENT' cards are collated and moved to the end of the header, and the new card is added afterward, using `hfix' not `hedit'. .ls Originally created by Mark Dickinson, 30 July 1993. .le .ih EXAMPLES .ih TIME REQUIREMENTS .ih BUGS .ih SEE ALSO images.hedit proto.hfix noao.artdata.mkheader .endhelp ./ircoaddirtf.par0100644000151400000240000000270706542514732013175 0ustar phallgamesi_sigma,s,h,"",,,"IMCOMBINE: Sigma image (optional)" i_plfile,s,h,"",,,"IMCOMBINE: Rejected pixel list image (optional)" i_combine,s,h,"average",average|median,,"IMCOMBINE: Type of combine operation (median|average)" i_reject,s,h,"sigclip",none|minmax|ccdclip|crreject|sigclip|avsigclip|pclip,,"IMCOMBINE: Type of rejection" i_masktyp,s,h,"badvalue",none|goodvalue|badvalue|goodbits|badbits,,"IMCOMBINE: Mask type" i_maskval,r,h,0.,,,"IMCOMBINE: Mask value" i_blank,r,h,0.,,,"IMCOMBINE: Value if there are no pixels" i_statsec,s,h,"",,,"IMCOMBINE: Image section for computing statistics" i_expname,s,h,"exptime",,,"IMCOMBINE: Image header exposure time keyword" i_lthresh,r,h,-10000.,,,"IMCOMBINE: Lower threshold" i_hthresh,r,h,INDEF,,,"IMCOMBINE: Upper threshold" i_nlow,r,h,1.,0.,,"IMCOMBINE: minmax: Number of low pixels to reject" i_nhigh,r,h,1.,0.,,"IMCOMBINE: minmax: Number of high pixels to reject" i_nkeep,r,h,1.,,,"IMCOMBINE: Minimum to keep (+) or maximum to reject(-)" i_lsigma,r,h,5.,0.,,"IMCOMBINE: Lower sigma clipping factor" i_hsigma,r,h,5.,0.,,"IMCOMBINE: Upper sigma clipping factor" i_rdnoise,s,h,"rn",,,"IMCOMBINE: ccdclip: CCD readout noise (electrons)" i_gain,s,h,"gain",,,"IMCOMBINE: ccdclip: CCD gain (electrons/ADU)" i_sigscale,r,h,0.1,0.,,"IMCOMBINE: Tolerance for sig-clip scaling corrections" i_pclip,r,h,-0.5,,,"IMCOMBINE: pclip: Percentile clipping parameter" i_grow,r,h,0.,,,"IMCOMBINE: Radius (pixels) for 1D neighbor rejection" mode,s,h,"q",,, ./README0100644000151400000240000001076207330355574011062 0ustar phallgames PHIIRS -- Pat Hall's Infrared Imaging Reduction Software Spawned from original tasks by Doug Williams & Anne Turner and including many cannibalized parts from DIMSUM (Dickinson et al). v.0 950714 Spawned from original tasks by Doug Williams & Anne Turner and including many cannibalized parts from the DIMSUM package (Dickinson et al.). Read "phiirs.hlp" for an introduction. v.1 960226 Minor revisions. Read "phiirs.hlp" for an introduction. v.2 960711 Major revisions and additions; tasks are now available for complete reduction from raw data to images suitable for input to FOCAS or such. Read "phiirs.hlp" for an introduction. The entire package is available as a compressed tarfile from "http://www.astro.utoronto.ca/~hall/phiirsold.tar.gz". Replace "iterstat.cl" with "iterstatold.cl" if problems occur. v.2.10 980314 Final release for IRAF Version 2.10. Read "phiirs.hlp" for an introduction and overview. NOTE that several perl scripts (included with the package) are used for image coaddition if the CTIO package is unavailable. Several awk scripts are also used for photometric scaling tasks. Entire package available as a compressed tarfile from "http://www.astro.utoronto.ca/~hall/phiirs.tar.gz". To install, enter the proper pathnames in "phiirs.cl" and "phiirs.hd", load the softools IRAF package, and type "mkhelpdb root.hd helpdb.mip", deleting the old helpdb.mip if necessary. See "sample.loginuser.cl" for how to include the package in your default IRAF startup. For this & subsequent versions PHIIRS can now handle the DATE-OBS keyword in both "old" format "dd/mm/yy" and the new millenium format "yyyy-mm-dd" (affects first.cl, irimfirst.cl, and irtffirst.cl only). Currently I believe the IRAF astutil.setairmass task only accepts old format, but presumably any update to it will be backwards compatible. v.2.11 980805 IRAF V2.11 + FITS kernel release. Read "phiirs.hlp" for an introduction and overview. Default image extension is now assumed to be "fits" instead of "imh". I don't guarantee that all tasks are 100% compatible with V2.11, but all problems I've encountered in 5+ months of use have been fixed. NOTE that several perl scripts (included with the package) are used for image coaddition if the CTIO package is unavailable. Several awk scripts are also used for photometric scaling tasks. Entire package available as a compressed tarfile from "http://www.astro.utoronto.ca/~hall/phiirs211.tar.gz". To install, enter the proper pathnames in "phiirs.cl" and "phiirs.hd", load the softools IRAF package, and type "mkhelpdb root.hd helpdb.mip", deleting the old helpdb.mip if necessary. See "sample.loginuser.cl" for how to include the package in your default IRAF startup. v.2.11.1 990415/990519 New V2.11 release including "dophiirs.cl" script task. Read "phiirs.hlp" and "doc/dophiirs.hlp" for an introduction and overview. Other changes from v.2.11 (besides inevitable bug fixes): renamed task "irflat2.cl" to "domeflat.cl"; added tasks "cfhtfirst.cl", "onisfirst.cl", & "piscesfirst.cl" for use with particular telescope/ instrument combinations; better "irshift.cl", "qkflat.cl" & "qksky.cl"; "nshift.cl" task added for finding offsets for N images or image sets overlapping a central image, and "onis6ew.cl" & "onis3ew.cl" included as examples of how to build a large mosaic from individual image sets; and streamlined tasks for faster reduction of large IR arrays (e.g. iterstat can be run for single parameters only; irshift includes an imsection parameter to avoid displaying every image; & minv is faster). NOTE that several perl scripts (included with the package) are used for image coaddition if the CTIO package is unavailable. Several awk scripts are also used for photometric scaling tasks. Entire package available as a compressed tarfile from http://www.astro.puc.cl/~phall/phiirs211.1.tar.gz along with tasks with minor bugfixes (replacing those in the tar file) at http://www.astro.puc.cl/~phall/PHIIRS/ To install, enter the proper pathname in "phiirs.cl", load the IRAF softools package, and type "mkhelpdb root.hd helpdb.mip", deleting the old "helpdb.mip" if necessary. See "sample.loginuser.cl" for how to include the package in your default IRAF startup. v.2.11.2 010108 Update release including numerous (minor) bug fixes. ./cfhtfirst.cl0100644000151400000240000001630506720572775012523 0ustar phallgames# cfhtfirst.cl -- CFHT/KIR specific version of first # # 1. hedit image headers, adding: # 1. BPM,BPMASK = bad pixel mask name # 2. ut,st = Universal & Sidereal time (copied from UTIME & SIDTIME) # 3. coadds = number of internal coadds (from RDTMODE) # 4. exptime = (inttime: exposure time per coadd) * (# of coadds) # 5. obs-date = old date-obs but in dd/mm/yy format # 6. date-obs = new millenium format (old date-obs saved as dateorig) # 2. subtract dark # # 940902: fixed problem with ut>24 # 950122: adjusted so that header params are added first, to raw image, and # dark is then subtracted, so that both sets of images have header params. # Also added `DARKSUB' header card to darksubbed images, indicating what # dark image was subtracted from them. # Also fixed problem with BPM not getting added into image header. # 950203: added adding of "coadds" header card # 950214: check for "ncoadds" header card & ok date-obs (laird's fits256.e data) # 950215: use "obs-date" to find day, month, year since it has standard format; # also streamlined input parameters. # 950216: made adding of airmass optional # 970321: yyear calculated correctly for observations from 1981-2080 only # 980414: added compatibility to incoming date-obs in new-millenium format and # output of date-obs in same format (valid for data from 1990 to 2089); # original date-obs is output as dateorig # 981228: adapted to CFHT + KIR: removed airmass & coords options; # now adds UT directly from UTIME and ST from SIDTIME; # 981229: added optional step to convert from default 3-D format to 2-D # 990427: DARKSUB keyword added to darksubbed images, not original ones # # **should add ability to do nonlinearity correction if desired # **assumes that INTTIME is exposure time per coadd, which should be correct procedure cfhtfirst(imagelist,darksub,badmask,project) string imagelist {prompt="List of images to process (do not use an `@')"} bool darksub {prompt="Subtract off dark frame?"} string badmask {prompt="Name of bad pixel mask to add to image header"} bool project=yes {prompt="Convert default 3-D image format to 2-D?"} string dark {prompt="Name of the dark frame to subtract", mode="q"} string darkstring {prompt="String to append to dark-subtracted images",mode="q"} string observatory="cfht" {prompt="Observatory where observations were made"} bool ddmmyy=yes {prompt="Is 'date-obs' in day/month/year format?"} bool echog=yes {prompt="Beep when task is done?"} struct *list begin string ddark, ddarkstring, bbadmask, check, base, iimagelist, ext string darklist, flat, flatbase, meanfile, currentflat, tempflat, name string editlist, current, obsdate, oobservatory, minsec, tmplist, tmplist2 string obstime, timeobs, dateobs, century, val_imgets real intime, ttime, mean, meanbad, x int ncoadd, ddy, hhr, hhour, mmonth, yyear, dday, last2digits bool ddarksub, pproject iimagelist = imagelist list = iimagelist editlist = iimagelist ddarksub = darksub if (ddarksub) { ddark = dark ddarkstring = darkstring darklist = iimagelist//ddarkstring } bbadmask = badmask pproject = project if (pproject) { tmplist = iimagelist//"_tMp" tmplist2 = iimagelist//"_tMp2" del (tmplist, ver-, >& "dev$null") del (tmplist2, ver-, >& "dev$null") } oobservatory = observatory # Add BPM and other goodies to the image headers, just like in the hadd.cl task print("===> Adding various parameters to the image headers...") list = iimagelist while (fscan (list, current) !=EOF) { hedit(current,"BPM",bbadmask,add+,ver-,show+,update+) hedit(current,"BPMASK",bbadmask,add+,ver-,show+,update+) hedit(current,"ut",("(@'utime')"),add+,ver-,show+,update+) hedit(current,"st",("(@'sidtime')"),add+,ver-,show+,update+) # Set exptime=itime * (# of coadds) imgets(current,"rdtmode", >& "dev$null") val_imgets=str(imgets.value) if(substr(val_imgets,1,5)!="COADD"){ ncoadd=1. } else { ncoadd=real(substr(val_imgets,6,strlen(val_imgets))) } hedit(current,"coadds",(ncoadd),add+,ver-,show+,update+) imgets(current,"inttime") intime=real(imgets.value) hedit(current,"exptime",(ncoadd*intime),add+,ver-,show+,update+) # # The 'date-obs' keyword comes in either the old format "dd/mm/yy", # the erroneous format "mm/dd/yy", or the new format "yyyy-mm-dd". # Create new 'date-obs' keyword in the new format "yyyy-mm-dd". imgets(current,"dateorig",>&"dev$null") if (imgets.value!="0") { print ("DATEORIG keyword already exists -- cfhtfirst already run on image?") } else { imgets(current,"date-obs") # Copy 'date-obs' keyword to 'dateorig' in original format. hedit(current,"dateorig",imgets.value,add+,ver-,show+,update+) # Create header keyword 'obs-date', always in "dd/mm/yy" format. if(!ddmmyy){ # mm/dd/yy format: if(substr(imgets.value,3,3)=="/") { obsdate=substr(imgets.value,4,6)//substr(imgets.value,1,3)//substr(imgets.value,7,8) } else { # yyyy-mm-dd format: # 1234567890 obsdate=substr(imgets.value,9,10)//"/"//substr(imgets.value,6,7)//"/"//substr(imgets.value,3,4) } # create obs-date if date-obs in mm/dd/yy or yyyy-mm-dd format: hedit(current,"obs-date",obsdate,add+,ver-,show+,update+) } else { # create obs-date if date-obs in dd/mm/yy format: hedit(current,"obs-date",imgets.value,add+,ver-,show+,update+) } # Create new 'date-obs' in new format "yyyy-mm-dd" from 'obs-date' "dd/mm/yy" # 12345678 imgets(current,"obs-date") if ((substr(imgets.value,7,7))=="9") { century=19 } else { century=20 } dateobs=century//substr(imgets.value,7,8)//"-"//substr(imgets.value,4,5)//"-"//substr(imgets.value,1,2) hedit(current,"date-obs",dateobs,add+,ver-,show+,update+) } } # Project from 3-D to 2-D image if (pproject) { list = iimagelist print("===> Projecting 3-D images down to 2-D...") while (fscan (list, name) !=EOF) { fileroot(name,validim+) base=fileroot.root ext=fileroot.extension if(ext!="")ext="."//ext print(base//ext//"[*,*,1]", >> tmplist) print(base//"_tMp2"//ext, >> tmplist2) } imcopy("@"//tmplist,"@"//tmplist2,ver-) imdel("@"//iimagelist,ver-) imren("@"//tmplist2,"@"//iimagelist,ver-) del(tmplist,ver-) del(tmplist2,ver-) } # Subtract off Dark Current if (ddarksub) { list = iimagelist # if darklist doesn't exist, assume dsub imgs don't either; create it & dsubs if(!access(darklist)) { print("===> Subtracting off Dark Current...") while (fscan (list, name) !=EOF) { fileroot(name,validim+) base=fileroot.root ext=fileroot.extension if(ext!="")ext="."//ext print(base//ddarkstring//ext, >> darklist) imgets(name,"DARKSUB") if (imgets.value=="0") { imarith(name, "-", ddark, base//ddarkstring//ext, verbose-) hedit(base//ddarkstring//ext,"DARKSUB",ddark,add+,ver-,show+,update+) } else { print("DARKSUB keyword exists; cfhtfirst already run? "//name//" just copied") imcopy(name, base//ddarkstring//ext, verbose-) } } } else { print("Darksubbed image list "//darklist//" already exists; images assumed to exist too.") } #imarith("@"//iimagelist, "-", ddark, "@"//darklist, verbose-) #hedit("@"//darklist,"DARKSUB",ddark,add+,ver-,show+,update+) print(" ") print("===> Dark-subtracted images are listed in the file "//darklist//".") } if(echog)beep end ./crzap.cl0100644000151400000240000002461407226415322011632 0ustar phallgamesprocedure crzap(inlist,outlist) # Cosmic ray cleaning routine using median filtering. # # 970227: created from dimsum.xzap (original courtesy Mark Dickinson) # 980622: iterstat calculation not done if iterstat header keywords extant # 980709: hadd parameter: ensure iterstat params not wrongly added to header # 990516: use imcalc instead of imreplace where appropriate # 990520: fix inadvertent imcalc bug # 990530: add CRMASK to output image header only # # Calls scripts fileroot.cl, iterstat.cl; possibly makeobjmask.cl, minv.cl string inlist {prompt="Image(s) for cosmic ray cleaning"} string outlist {prompt="Output image(s)"} int zboxsz {7,min=3,prompt="Box size for zapping"} int oboxsz {7,min=3,prompt="Box size for smoothing before object flagging"} real nsigma {5.,min=0.,prompt="Number of sky sigma for zapping threshold"} real nnegsigma {0.,min=0.,prompt="Number of sky sigma for negative zapping"} int nrings {1,min=0,prompt="Number of pixels to flag as buffer around CRs"} real nobjsigma {2.,min=0.,prompt="Number of sky sigma for object masking"} int skyfiltsize {15,min=0,prompt="Median filter size for sky in object masking"} int skysubsample {1,min=0,prompt="Block averaging factor for object masking"} int ngrowobj {2,min=0,prompt="Number of buffer pixels to grow around objects"} string statsec {"",prompt="Image section to use for computing sky sigma"} bool deletemask {yes, prompt="Delete CR mask after execution?"} bool cleanpl {yes,prompt="Delete other working masks after execution?"} bool cleanimh {yes,prompt="Delete working images after execution?"} bool verbose {yes,prompt="Verbose output?"} bool unzap {no,prompt="Unzap using objects from objmask files?"} bool checklimits {yes,prompt="Check min and max pix values before filtering?"} bool hadd {no,prompt="Add iterstat results to header if missing?"} real zmin {-99999.,prompt="Minimum data value for fmedian"} real zmax {99999.,prompt="Minimum data value for fmedian"} bool echog {no,prompt="Beep when task is done?"} struct *inimglist struct *outimglist struct *statlist begin real skysig,skymode,cr_thresh,objthresh,negthresh,dmin,dmax int nbox,nbox2,nin string infile, outfile, img, outimg, statfile, objmask string itmean, itsig, origimg bool maskobj, maskneg # Check input parameters. if (nnegsigma > 0.) maskneg = yes else maskneg = no if (nobjsigma == 0.) { print ("No object masking will be used during zapping.") maskobj = no } else { maskobj = yes } # Expand file lists into temporary files. infile = mktemp("tmp$zap") outfile = mktemp("tmp$zap") sections (inlist,option="fullname",>infile) nin = sections.nimages sections (outlist,option="fullname",>outfile) if (nin != sections.nimages) { print ("ERROR: Numbers of input and output images do not match.") return } inimglist = infile outimglist = outfile # Loop through input files: while (fscan(inimglist,origimg) != EOF) { # Strip extension off input file name. fileroot (origimg,validim+) img = fileroot.root # Read name of output file. if (fscan(outimglist,outimg) == EOF) { print ("ERROR: Problem scanning output file name in crzap.") return } fileroot (outimg,validim+) outimg = fileroot.root print ("Working on ",img," ---ZAP!--> ",outimg) # Calulate sky mean and RMS noise using iterative sigma rejection. if (verbose) print (" Computing statistics.") imgets(img, "itermean", >& "dev$null") itmean=str(imgets.value) if(itmean!="0") { skymode = real(imgets.value) imgets(img, "itersig", >& "dev$null") skysig = real(imgets.value) } else { iterstat (img//statsec,nsigrej=5.,maxiter=10, verbose=verbose,print=verbose,addh=hadd) skymode = iterstat.mean skysig = iterstat.sigma } # Median filter image to produce file _fmed_//img if (verbose) print (" Median filtering.") # First, check limits of data range. Wildly large (positive or negative) data # values will screw up fmedian calculation unless checklimits = yes and zmin # and zmax are set to appropriate values, e.g. zmin=-32768, zmax=32767. # Note that the old fmedian bug which occurred if zmin=hmin and zmax=hmax has # been fixed in IRAF version 2.10.1. The pipe to dev$null, however, is # included because V2.10.1 and .2 have debugging print statements accidentally # left in the fmedian code. if (checklimits) { minmax (img,force+,update+,ve-) if (verbose) print("Data minimum = ",minmax.minval, " maximum = ",minmax.maxval) } if (checklimits && (minmax.minval < zmin || minmax.maxval > zmax)) { if (minmax.minval < zmin) { dmin = zmin } else { dmin = minmax.minval } if (minmax.maxval > zmax) { dmax = zmax } else { dmax = minmax.maxval } if (verbose) print (" Truncating data range ",dmin," to ",dmax) if(!access("_fmed_"//origimg)) { fmedian (img,"_fmed_"//img,xw=zboxsz,yw=zboxsz, boundary="reflect",hmin=-32768,hmax=32767, zmin=dmin,zmax=dmax,>&"dev$null") } } else { if(!access("_fmed_"//origimg)) { fmedian (img,"_fmed_"//img,xw=zboxsz,yw=zboxsz,boundary="reflect", hmin=-32768,hmax=32767,zmin=INDEF,zmax=INDEF,>&"dev$null") } } # Take difference to produce "unsharp masked" image _cr_//img if(!access("_cr_"//origimg)) { imarith (img,"-","_fmed_"//img,"_cr_"//img) } # Threshold _cr_//img at nsigma*skysig to make CR mask _peaks_//img. # Potential CRs --> 1 # "Blank sky" --> 0 # Note that cr_thresh will be positive by definition. if (verbose) print (" Masking potential CR events.") if (!access("_peaks_"//img//".pl")) { imcopy ("_cr_"//img,"_peaks_"//img,ve-) cr_thresh = nsigma*skysig #imreplace ("_peaks_"//img,0.,upper=cr_thresh,lower=INDEF) #imreplace ("_peaks_"//img,1.,lower=cr_thresh,upper=INDEF) imcalc ("_peaks_"//img, "_peaks_"//img, "if im1 .le. "//cr_thresh//" then 0 else 1", ver-) # Make PL format version of _peaks_//img and delete old format version. imcopy ("_peaks_"//img,"_tmpeaks_"//img//".pl",ve-) imdelete ("_peaks_"//img,ve-) imren ("_tmpeaks_"//img//".pl","_peaks_"//img//".pl") } # Object masking: create mask identifying where objects might be, # inverting mask after creation to make objects --> 0 and "sky" --> 1. if (maskobj) { if (verbose) print (" Creating object mask.") objthresh = nobjsigma*skysig # If smoothing scale for object detection is different, create another image if (!access("_obj_fmed_"//img//".pl")) { if (oboxsz==zboxsz) { makeobjmask ("_fmed_"//img,suffix="_obj",headlist="",subs=skysubsample,filts=skyfiltsize,nsmoo=0,threshty="constant",constth=objthresh,ngrow=ngrowobj,statsec=statsec,checklimits=checklimits,verbose=verbose,inv+) imren ("_fmed_"//img//"_obj.pl", "_obj_fmed_"//img//".pl",ver-) } else { fmedian (img,"_omed_"//img,xw=oboxsz,yw=oboxsz,boundary="reflect",hmin=-32768,hmax=32767,zmin=INDEF,zmax=INDEF,>&"dev$null") makeobjmask ("_omed_"//img,suffix="_obj",headlist="",subs=skysubsample,filts=skyfiltsize,nsmoo=0,threshty="constant",constth=objthresh,ngrow=ngrowobj,statsec=statsec,checklimits=checklimits,verbose=verbose,inv+) imren ("_omed_"//img//"_obj.pl", "_obj_fmed_"//img//".pl",ver-) } } } # If not masking objects, final CR mask is just _peaks_//img. If we are # masking objects, take product of object and CR masks to make _crmask_//img if (maskobj) { imarith ("_peaks_"//img//".pl","*","_obj_fmed_"//img//".pl", "_crmask_"//img//".pl") } else { imcopy ("_peaks_"//img//".pl","_crmask_"//img//".pl",ve-) } # Grow additional buffer region around identified CRs. if (nrings > 0) { if (verbose) print (" Growing mask rings around CR hits.") nbox = 2 * nrings + 1 nbox2 = nbox * nbox imarith ("_crmask_"//img//".pl","*",nbox2,"_crmask_"//img//".pl") boxcar ("_crmask_"//img//".pl","_crmask_"//img//".pl", xw=nbox,yw=nbox) imreplace ("_crmask_"//img//".pl",1,lower=1,upper=INDEF) } # Identify negative pixels if desired. No "rings" are grown around them. if (maskneg) { if (verbose) print (" Masking deviant negative pixels.") imcopy ("_cr_"//img,"_neg_"//img,ve-) negthresh = -1.*nnegsigma*skysig #imreplace ("_neg_"//img,0.,lower=negthresh,upper=INDEF) #imreplace ("_neg_"//img,1.,upper=negthresh,lower=INDEF) imcalc ("_neg_"//img, "_neg_"//img, "if im1 .ge. "//negthresh//" then 0 else 1", ver-) imcopy ("_neg_"//img,"_neg_"//img//".pl",ve-) imdelete ("_neg_"//img,ve-) imarith ("_crmask_"//img//".pl","+","_neg_"//img//".pl", "_crmask_"//img//".pl") imreplace ("_crmask_"//img//".pl",1,lower=1,upper=INDEF) } # unzap pixels which are where objects are as defined by objmask files if (unzap) { imgets(img, "objmask", >& "dev$null") objmask=str(imgets.value) if(objmask!="0") { imarith(objmask,"*","_crmask_"//img//".pl", "_crmask_"//img//".pl",ver-) } else { print ("No object mask defined in image header-- cosmic rays left as is.") } } if (verbose) print (" Replacing CR hits with local median.") # Multiply CR mask by _crmask_//img to make "comic rays only" image _cronly_//img imarith ("_cr_"//img,"*","_crmask_"//img//".pl", "_cronly_"//img) # Subtract _cronly_//img from data to produce clean image "outimg". # Note that this effectively replaces the masked regions with the local # median, since _cronly_//img = img - _fmed_//img. imarith (img,"-","_cronly_"//img,outimg) ## Record CR mask name in headers of input and output images # hedit (img//","//outimg,"CRMASK","_crmask_"//img//".pl", # Record CR mask name in header of output image hedit (outimg,"CRMASK","_crmask_"//img//".pl", add+,ver-,show+,update+,>&"dev$null") # Clean up. if (deletemask) delete ("_crmask_"//img//".pl",ve-) if (cleanpl) { delete ("_peaks_"//img//".pl",ve-) if (maskobj) delete ("_obj_fmed_"//img//".pl",ve-) if (maskneg) delete ("_neg_"//img//".pl",ve-) } if (cleanimh) { imdelete ("_fmed_"//img,ver-,>&"dev$null") imdelete ("_omed_"//img,ver-,>&"dev$null") imdelete ("_cr_"//img,ver-,>&"dev$null") imdelete ("_cronly_"//img,ver-,>&"dev$null") } if (verbose) print (" "//outimg//" created.") } inimglist = ""; delete (infile, verify-) outimglist = ""; delete (outfile, verify-) statlist = "" if(echog)beep end ./destripe.cl0100644000151400000240000001503206720572776012343 0ustar phallgames# destripe -- interactively remove striping from a coadded image # # 960405: created by Pat Hall from phip$checkfringe.cl # 960805: fixed error of default objmask value not being !OBJMASK as claimed # # **edit image list & display option? # **want a mkskycor that is not line-by-line... **images/mfilters package? test procedure destripe(fiximage,outname,objmask) string fiximage {prompt="Name of image to be corrected"} string outname {prompt="Name of image to create"} string objmask {prompt="Object mask to use (default=!OBJMASK)"} int ngrow {1,min=0,max=10,prompt="Number of rings to grow around bad pixels",mode="q"} int boxmin {5,prompt="MKSKYCOR: Minimum smoothing box size at edges",mode="q"} int boxmax {5,prompt="MKSKYCOR: Maximum smoothing box size",mode="q"} bool ok=no {prompt="Continue to next step (yes) or redo (no)?",mode="q"} bool rot=no {prompt="Redo using rotated image?",mode="q"} int z {0,prompt="Number of image to save (0 to delete all)?",mode="q"} bool echog {yes,prompt="Beep when task is done?"} begin string logimex, logsurf, countfile, rrootname, iimagelist, ooutname, ffunc string wweighting, fiximg, ffringe, titlestring, fixin, oobjmask, objminv string fixroot, outroot, extn real max, nncols, nnlines, sscale, rorig int x, y, zz, xxord, yyord, xx, nngrow, bboxmin, bboxmax, r, s bool go, ffit, xxterms, ook, first, rrot extn=".fits" fixin=fiximage fiximg="_z."//fixin fileroot(fixin,validim+) fixroot="_z."//fileroot.root if(fileroot.extension!="")extn="."//fileroot.extension ooutname=outname fileroot(ooutname,validim+) outroot=fileroot.root oobjmask=objmask fileroot(oobjmask,validim+) if(fileroot.root==""){ imgets(fixin,"OBJMASK") fileroot(imgets.value,validim+) oobjmask=fileroot.root } objminv=fileroot.root//"inv_z.pl" if(access(objminv))objminv=mktemp("objminv") print("Enter initial values of adjustable parameters:") nngrow=ngrow bboxmin=boxmin bboxmax=boxmax zz=0 # check for necessary stuff; if not defined abort task. go=yes if(!deftask("addring")) {go=no} if(!deftask("fileroot")) {go=no} if(!deftask("minv")) {go=no} if(!defpac("nmisc")) {go=no} if(!defpac("ccdred")) {go=no} if(go) { print("Beginning...") imdel(fiximg,ver-,>&"dev$null") imdel("_.tmp"//fiximg,ver-,>&"dev$null") imdel("_.tmp"//objminv,ver-,>&"dev$null") # ** make optional # if (!access(fiximg) # iterstat to get mode iterstat(fixin,nsigrej=5.,maxiter=10.,print-,verbose-) # imar to subtract mode imar(fixin,"-",iterstat.valmode,fiximg,divzero=0.,ver-,noact-) # OBJECT MASKING STEP ook=no first=yes while(!ook){ print("Masking objects on coadded image...") # if not first time through, get params if(!first){ nngrow=ngrow imdel("_.tmp"//fiximg,ver-) imdel(objminv,ver-) } # addring and/or minv if(nngrow!=0){ addring(oobjmask,"_.tmp"//objminv,ngrow=nngrow,badval=0) minv("_.tmp"//objminv,objminv) imdel("_.tmp"//objminv,ver-,>&"dev$null") } else { minv(oobjmask,objminv) } # nmisc$fixpix imcopy(fiximg,"_.tmp"//fiximg,ver-) fixpix("_.tmp"//fiximg,objminv,ninterp="1") # acceptable? if(first)display(fixin, 1) display("_.tmp"//fiximg, 2) beep ook=ok first=no } imdel(objminv,ver-) imdel(fiximg,ver-) imcopy("_.tmp"//fiximg,fiximg,ver-) # SKY SMOOTHING & SUBTRACTION STEP ccdproc.fixpix=no ccdproc.overscan=no ccdproc.trim=no ccdproc.zerocor=no ccdproc.darkcor=no ccdproc.flatcor=no ccdproc.illumcor=no ccdproc.fringecor=no ccdproc.readcor=no ccdproc.scancor=no x=1 y=2 r=0 ook=no rrot=no # loop as long as desired while(!ook) { print("Making stripe image and subtracting from original image...") # get new params if redoing things if(x!=1){ bboxmin=boxmin bboxmax=boxmax # If rotating, copy original image to temporary image, rotate by 90 degrees # r number of times, transposing first if rotating 360 degrees or more, # and not doing anything if more than 720 degrees of rotation are requested. if(rot){ rrot=yes s=1 r=r+1 rorig=r imdel(fiximg,ver-) imcopy("_.tmp"//fiximg,fiximg,ver-) if(r>=8){ print("WARNING! All possible permutations of rotation and transposition") print("have been done, so pick one as the best and stick with it.") } else { if(r>=4){ print("Transposing image...") imtranspose(fiximg,fiximg) r=r-4 } while(s<=r){ print("Rotating image by "//r*90//" degrees...") imtranspose(fiximg//"[*,-*]",fiximg) s+=1 } } } } # make the stripe correction image if(access(fixroot//"_"//str(x)//".imh"))imdel(fixroot//"_"//str(x),ver-) if(access(fixroot//"_"//str(x)//".hhh"))imdel(fixroot//"_"//str(x),ver-) mkskycor(fiximg,fixroot//"_"//str(x),ccdtype="",xboxmin=bboxmin,yboxmin=bboxmin,xboxmax=bboxmax,yboxmax=bboxmax,clip+,lowsig=2.5,highsig=2.5,>&"dev$null") # if rotating if(rrot){ s=1 if(rorig<8){ print("Setting images back to original orientation...") if(rorig>=4){ imtranspose(fixroot//"_"//str(x),fixroot//"_"//str(x)) imtranspose(fiximg,fiximg) rorig=rorig-4 } while(s<=rorig){ imtranspose(fixroot//"_"//str(x)//"[-*,*]",fixroot//"_"//str(x)) imtranspose(fiximg//"[-*,*]",fiximg) s+=1 } } } # imar orig - mkskycor if(access(outroot//"_"//str(x)//".imh"))imdel(outroot//"_"//str(x),ver-) if(access(outroot//"_"//str(x)//".hhh"))imdel(outroot//"_"//str(x),ver-) imar(fixin,"-",fixroot//"_"//str(x),outroot//"_"//str(x),divzero=0.,ver-,noact-) # inspect the subtracted image print ("===> Displaying striped and de-striped images #"//str(x)//"...") display(fixroot//"_"//str(x), 3) display(outroot//"_"//str(x), 4) # abort loop? beep ook=ok rrot=no x+=1 } # CLEAN UP zz=z if(zz!=0){ imcopy(fixroot//"_"//str(zz),outroot//"stripe",ver-) imcopy(outroot//"_"//str(zz),ooutname,ver-) print("Image "//ooutname//" created using stripe model "//outroot//"stripe") hedit(ooutname,"STRIPEIM",outroot//"stripe",add+,ver-,show-,update+) hedit(outroot//"stripe","title","Stripe image used to create "//ooutname,add+,ver-,update+,show-) } else{ print("No images saved.") } y=0 zz=0 while(y& "dev$null") imdel(ooutname//"_"//str(y),ver-, >& "dev$null") y+=1 } imdel("_.tmp"//fiximg,ver-,>&"dev$null") imdel(fiximg,ver-) } else{ print("Tasks/packages `nmisc', `ccdred', `minv', `addring', or `fileroot' aren't loaded") print("and this task needs them to run. Please load them (nmisc last) and start again.") } if(echog)beep end ./domeflat.cl0100644000151400000240000001451106720572776012320 0ustar phallgames# domeflat.cl -- flatfield IR images with a previously created flatfield image # # Calls script addcomment, fileroot. # # The products of this routine are: # --flattened images (optionally dark subtracted and bad pixel zeroed): # *//Flatstring # --a file (imagelist//Flatstring) which contains the names of those images # --the logfile # # CHANGES: # 940815: made sure task copied images so it could work when darksub=no # 960228: added DARKSUB and FLATIMG header cards, other minor changes # 960301: fixed BPM header card error, added logfile & header cards # and streamlined the task to more closely match irflat.cl # 990127: removed scan of output of "time" task due to problem w/linux # 990306: don't subtract dark if already done # 990317: added tpl option # 990320: fixed bug in darksub option # 990506: added ZEROOUT keyword creation procedure domeflat(imagelist,Flatstring,darksub,dark,flatfield,zeroout,badmask,logfile) string imagelist {prompt="List of images to process"} string Flatstring {prompt="String to be appended to flattened images"} bool darksub {prompt="Subtract Dark frame?"} string dark {prompt="Name of the Dark frame to use"} string flatfield {prompt="Name of the flatfield frame to use"} bool zeroout=yes {prompt="Zero out bad pixels on flattened images?"} string badmask {prompt="Name of the bad pixel mask (good pixels=1)"} string logfile {prompt="Name of the log file"} bool tpl=no {prompt="Throughput-correct images after flatfielding?"} string tplname {prompt="FULL Name of throughput correction image"} bool echog {yes,prompt="Beep when task is done?"} struct *list begin string rrootname, ddark, llogfile, bbadmask, eextension, ffextension int sstartno, eendno, i, j, numpix string flatlist, flat, flatbase, meanfile, currentflat, fflatfield, ttplname string iimagelist, FlatImageList, fflatstr, base, check, flatjoinlist string datefile, thedate, ickinfo, name, ext, predsimage, postdsimage real mean, meanbad bool ddarksub, zzeroout, go, ttpl struct datelist iimagelist = imagelist list = iimagelist fflatstr = Flatstring ddarksub = darksub ddark = dark fflatfield = flatfield if (fflatfield=="") { go=no print ("WARNING! Flatfield image must be defined... task aborted.") } zzeroout = zeroout bbadmask = badmask llogfile = logfile ttpl = tpl if (ttpl) ttplname=tplname # The "go" parameter won't let the task run if you haven't loaded needed tasks. go=yes if(!deftask("addcomment")) {go=no} if(go) { #set up FlatImageList FlatImageList = iimagelist//fflatstr # @file for flattened images flatjoinlist = "listjoin."//iimagelist//fflatstr # @file for making the flat if(access(FlatImageList)) delete(FlatImageList,ver-) while (fscan (list, name) !=EOF) { fileroot(name,validim+) base=fileroot.root ext=fileroot.extension if(ext!="")ext="."//ext print(base//fflatstr//ext, >> FlatImageList) } #Set up log file, appending if it already exists print(" ") print("Let the games begin...") if(llogfile == "") llogfile="log."//iimagelist print("", >> llogfile) print("===> PHIIRS.DOMEFLAT:", >> llogfile) print("===> Input images from "//iimagelist//" flattened with "//fflatfield, >> llogfile) print("===> with darksub="/ddarksub//" using dark image="//ddark, >> llogfile) print("===> and zeroout="/zzeroout//" using bad pixel mask="//bbadmask, >> llogfile) print("", >> llogfile) # Add the BPM to the image header hedit("@"//iimagelist,"BPM",bbadmask,add+,ver-,show+,update+) hedit("@"//iimagelist,"BPMASK",bbadmask,add+,ver-,show+,update+) # Subtract off Dark Current if (ddarksub) { print("===> Subtract off Dark Current") print("===> Subtract off Dark Current", >> llogfile) join (iimagelist, FlatImageList, out=flatjoinlist) list = flatjoinlist while (fscan (list, predsimage, postdsimage) !=EOF) { imgets(predsimage,"darksub",>&"dev$null") if(imgets.value=="0"){ imarith (predsimage,"-",ddark,postdsimage,ver-,noact-) hedit(postdsimage,"DARKSUB",ddark,add+,ver-,sho+,updat+) print(predsimage//" - "//ddark//" "//postdsimage, >> llogfile) } else { imcopy (predsimage, postdsimage, ver-) print (predsimage//" already darksubtracted; just copied to "//postdsimage, >> llogfile) print (predsimage//" already darksubtracted; just copied to "//postdsimage) } } del(flatjoinlist,ver-) } else { print("===> Preparing...") imcopy("@"//iimagelist, "@"//FlatImageList, verbose-) } # Divide All Images by the Flat Field print("===> Correct All Images for Flat Field") imarith("@"//FlatImageList, "/", fflatfield, "@"//FlatImageList, verbose-) hedit("@"//FlatImageList,"FLATIMG",fflatfield,add+,ver-,show+,update+) # Zero out Bad Pixels if desired if (zzeroout) { print("===> Zero out bad pixels") imarith("@"//FlatImageList, "*", bbadmask, "@"//FlatImageList, verbose-) hedit("@"//FlatImageList,"ZEROOUT",bbadmask,del-,add+,ver-,sho-,upd+) } # Do throughput correction if desired. if (ttpl) { print("===> Divide by Throughput Correction") print("===> Divide by Throughput Correction", >> llogfile) list = FlatImageList while (fscan (list, name) !=EOF) { imgets(name,"tplimg",>&"dev$null") if(imgets.value=="0"){ imar(name, "/", ttplname, name, ver-) hedit(name,fields="TPL",value="TPL correction made using image"//ttplname,add+,ver-,up+,sho-) hedit(name,fields="TPLIMG",value=ttplname,add+,ver-,up+,sho-) print(name//" / "//ttplname//" "//name, >> llogfile) } else { print(name//" already throughput-corrected using "//imgets.value, >> llogfile) print(name//" already throughput-corrected using "//imgets.value) } } } # Add comment cards to header of flattened image #time | scan (datelist) del ("_gooDaTe", ver-, >& "dev$null") !date > _gooDaTe type ("_gooDaTe") | scan (datelist) del ("_gooDaTe", ver-, >& "dev$null") addcomment ("@"//FlatImageList,"phiirs.domeflat: "//datelist,ver-) addcomment ("@"//FlatImageList,"Flattened w/"//fflatfield//", darksub="/ddarksub//", zeroout="//zzeroout,ver-) # Update log file print("", >> llogfile) print("===> Flatfielded images listed in "//FlatImageList, >> llogfile) print("===> PHIIRS.DOMEFLAT finished at "//datelist, >> llogfile) print("...it is accomplished. Flatfielded images listed in "//FlatImageList//". ") print("Next task to run is `irsky'.") } else { print("WARNING: the `addcomment' task is not loaded!") print("Please load it and restart this task.") } if(echog)beep end ./addring.cl0100644000151400000240000000263506551162105012120 0ustar phallgames# addring.cl -- add rings around all objects in a mask image # # Calls task "minv" if bad pixels are zero-valued, since this task needs "bad" # pixels (the ones around which rings are added) to have values of 1 to work. # # 920711: created by John S. Ward # 930519: Mod. by MD to make it compatable with .pl masks, to add mask # as query parameter, to make number of added rings a variable. # 950220: modified for different input, output names and bad pixel values # 950725: fixed bug of too many minv's if outmask=inmask # 970801: changed so that it copies to an intermediate image, thus avoiding # problem of minv messing up original input files # 980708: optimized coding a bit, cutting down on number of imcopies etc. procedure addring(inmask,outmask) string inmask {prompt="Name of input mask image"} string outmask {prompt="Name of output mask image"} int ngrow {1,min=0,prompt="Number of pixel rings to grow around mask"} int badval {0,min=0,max=1,prompt="Value for `bad' pixels around which to grow rings"} begin string inmi # equals inmask string outmi # equals outmask int nbox int nbox2 inmi = inmask outmi = outmask nbox = 2 * ngrow + 1 nbox2 = nbox * nbox if (badval==0) { minv(inmi,outmi) imarith (outmi,"*",nbox2,outmi,ver-) } else { imarith (inmi,"*",nbox2,outmi,ver-) } boxcar (outmi,outmi,nbox,nbox) imreplace (outmi,1.,lower=1.,upper=INDEF) if(badval==0)minv(outmi,outmi) end ./imflatpars.par0100644000151400000240000000317206664345000013035 0ustar phallgames#pset imcomflatpars {prompt="Imcombine parameters"} i_plfile,s,h,"",,,"IMCOMBINE: List of pixel list files (optional)" i_sigma,s,h,"",,,"IMCOMBINE: List of sigma images (optional)" i_combine,s,h,"median",,,"IMCOMBINE: Combine operation (median|average)" i_reject,s,h,"ccdclip",,,"IMCOMBINE: Type of rejection" i_offsets,s,h,"none",,,"IMCOMBINE: Input image offsets" i_masktyp,s,h,"badvalue",,,"IMCOMBINE: Mask type" i_maskval,r,h,0.,,,"IMCOMBINE: Mask value" i_blank,r,h,1.,,,"IMCOMBINE: Value if there are no pixels" i_scale,s,h,"none",,,"IMCOMBINE: Image scaling" i_zero,s,h,"none",,,"IMCOMBINE: Image zero point offset" i_weight,s,h,"none",,,"IMCOMBINE: Image weights" i_statsec,s,h,"",,,"IMCOMBINE: Image section for computing statistics" i_expname,s,h,"",,,"IMCOMBINE: Image header exposure time keyword" i_lthresh,r,h,INDEF,,,"IMCOMBINE: Lower threshold" i_hthresh,r,h,INDEF,,,"IMCOMBINE: Upper threshold" i_nlow,r,h,1.,,,"IMCOMBINE: minmax: Number of low pixels to reject" i_nhigh,r,h,1.,,,"IMCOMBINE: minmax: Number of high pixels to reject" i_nkeep,r,h,6.,,,"IMCOMBINE: Minimum to keep (+) or maximum to reject(-)" i_lsigma,r,h,3.,,,"IMCOMBINE: Lower sigma clipping factor" i_hsigma,r,h,3.,,,"IMCOMBINE: Upper sigma clipping factor" i_rdnoise,r,h,73,,,"IMCOMBINE: ccdclip: CCD readout noise (e-'s)" i_gain,r,h,15.3,,,"IMCOMBINE: ccdclip: CCD gain (e-'s/ADU)" i_snoise,s,h,"0.",,,"IMCOMBINE: ccdclip: Sensitivity noise (fraction)" i_sigscale,r,h,0.1,0.,,"IMCOMBINE: Tolerance for sigma-clip scale corrections" i_pclip,r,h,-0.5,,,"IMCOMBINE: pclip: Percentile clipping parameter" i_grow,r,h,0.,,,"IMCOMBINE: Radius (pixels) for 1D neighbor rejection" ./dophiirs.cl0100644000151400000240000007732007124505077012342 0ustar phallgamesprocedure dophiirs(ilist,rootname,badpixmask,instrument) # dophiirs.cl -- batch job for phiirs reductions # # 990205: begin creation # 990309: merged with dophpars.par & removed irrotate bits # 990318: flat_tpl and sky_tpl options # 990320: added patternsub option; modified flat_tpl and sky_tpl options # 990324: added editimshift option # 990420: irflat: added premask, forcescale, & comment about using objmasks # 990506: changed name of subdark parameter to imgdark # 990523: objmask+: check for image list existence before doing hedit on it # # **possible improvements: # **edit for SQIID # **does irflat assume goodval=1 & require minv/imcalc? # # **bug: docoadd+ redo- doesn't work... new coadd made # **bug if domkobjmask+ redo- and existing objmask (problem just w/imextn?) # # --ideally want it to know how to do std defaults without being told # (e.g. if flatfield but no skysub, sub=yes on mkobjmask, trim) # --output batch file equivalent # --crzap, photcheck, photscale: see dophiirs_990217noon.cl # --not included: mkbpm, mkdark, mkflat, irshift2, immatch.geomap, precoadd # COMMAND-LINE PARAMETERS string ilist {prompt="List of original images"} string rootname {prompt="Rootname to use for files"} string badpixmask {prompt="Bad pixel mask (if none, set masktyp=none)"} string instrument {"generic",enum="generic|irim|kir|nsfcam|onis|pisces|so256",prompt="Generic or specific instrument?"} # WHICH TASKS TO DO? PARAMETERS bool dofirst=no {prompt="Add header parameters to raw images?"} bool redo=no {prompt="Redo a step even if it's already been done?"} string imgdark="" {prompt="Dark to subtract (dofirst+/domeflat/qkflat)"} string doflat="none" {enum="none|domeflat|irflat|qkflat",prompt="Which task to use for flattening?"} string dosky="none" {enum="none|irsky|qksky",prompt="Which task to use for sky-subtraction?"} bool objmask=no {prompt="Use object masks to make flat & sky?"} bool getstats=no {prompt="Get statistics for images to be coadded?"} bool doshift=no {prompt="Measure image shifts (poss. INTERACTIVE)?"} bool docoadd=no {prompt="Do coadding?"} bool domkobjmask=no {prompt="Make coadded-image objmask (poss. INTERACTIVE)?"} bool domasklet=no {prompt="Make individual-image objmasks (poss. INTERACTIVE)?"} bool dotrim=no {prompt="Create constant-rms image w/minimum exptime?"} bool makenoise=yes {prompt="Beep when tasks are done?\n--GENERAL PARAMETERS----------------------------"} # GENERAL PARAMETERS string darkstring="d" {prompt="String to append to dark-subtracted images"} string flatstring="f" {prompt="String to append to flat-fielded images"} string skystring="s" {prompt="String to append to sky-subtracted images"} string logfile="" {prompt="Name of log file"} string imflatpars="" {prompt="Generic IRFLAT/QKFLAT imcombine params filename"} string imskypars="" {prompt="Generic IRSKY/QKSKY imcombine params filename"} string imcoaddpars="" {prompt="Generic IRCOADD imcombine params filename"} string masktyp="badval" {prompt="Mask type (badval|goodval|none)"} real maskval=0. {prompt="Mask value for mask type (goodval|badval) pixels"} string im_extn="fits" {prompt="Image type extension to use\n--DOFIRST+ PARAMETERS---------------------------"} # DOFIRST+ PARAMETERS bool coords=no {prompt="Add RA, DEC, and EPOCH to image header?"} bool airmass=no {prompt="Enter airmass into image header?"} bool airauto=no {prompt="Find airmass of image automatically?"} string epoch="" {prompt="Epoch of coordinates"} string ra="" {prompt="Right Ascension (surround with quotes)"} string dec="" {prompt="Declination (surround w/quotes; use - but not +)"} string observatory="" {prompt="Observatory where observations were made"} bool ut=yes {prompt="Is 'time-obs' in header ut or not?"} bool ddmmyy=no {prompt="Is 'date-obs' in day/month/year format?\n--FLATFIELDING & SKY-SUBTRACTION PARAMETERS-----"} # FLATFIELDING & SKY-SUBTRACTION PARAMETERS bool zeroout=no {prompt="Zero out bad pixels (domeflat/qkflat/qksky)?"} string flatfield="" {prompt="Name of flatfield image to use (domeflat)"} real flat_num=INDEF {prompt="Total even # of imgs for running flat (irflat)"} bool flatsave=no {prompt="Save individual flatfield images?"} string objmsuffix="om" {prompt="Suffix of object masks"} bool remake=no {prompt="Remake existing flat or sky (qkflat/qksky)?"} bool iterstat=yes {prompt="Use iterative means for quick flats & skys?"} bool premask=no {prompt="Mask bad pixels before creating flats/skys?"} bool apply=yes {prompt="Apply quick flats & skys to images once created?"} real sky_num=INDEF {prompt="Total even # of images for running sky (irsky)"} bool skysave=no {prompt="Save individual sky images?"} string patternsub="never" {enum="during|after|never",prompt="Subtract pattern noise (during|after) skysub, or (never)?"} string whentpl="never" {enum="flat|sky|never",prompt="Throughput-correct images after (flat|sky|never)"} string tplname="" {prompt="FULL name of throughput correction image"} bool addsky=no {prompt="Add median sky level after subtraction?"} bool forcescale=no {prompt="Force recalculation of image medians?"} bool shortcut=yes {prompt="Use quick way to scale sky for subtraction?\n--IRSHIFT PARAMETERS (DOSHIFT+)-----------------"} # IRSHIFT PARAMETERS (DOSHIFT+) string refimage="" {prompt="Name of reference image for irshift"} string prefix="" {prompt="irshift files prefix string (default=rootname)"} string suffix="" {prompt="irshift files suffix string (default=shN; N=1,2..)"} bool useimages=yes {prompt="Measure shifts from images instead of a file?"} bool displayim=yes {prompt="Display images for imexam?"} bool ptv=no {prompt="Use phat.ptv instead of display in imexam?"} string imsection="" {prompt="Image section to display in imexam?"} bool editfiles=yes {prompt="Display coords files for editing?\n--IRCOADD PARAMETERS (DOCOADD+)-----------------"} # IRCOADD PARAMETERS (DOCOADD+) string coaddimage="" {prompt="Coadded image name (default=rootname//_coaddN, N=1,2...)"} string expmap="" {prompt="Exposure map image (default=coaddimage//em)"} string scaling="none" {prompt="Scaling for coadd (none|@file|!keyword|etc.)"} string zeroing="mode" {prompt="Zero offsets for coadd (none|@file|mode|etc.)"} string weighting="none" {prompt="Weighting for coadd (none|@file|!keyword|etc.)"} int magfac {1,min=1,max=10,prompt="Subpixel shifting magnification factor"} bool prescale=no {prompt="Scale images before, not during, imcombine?"} bool prezero=no {prompt="Do zero offseting before, not during, imcombine?"} bool stack=no {prompt="Combine images by stacking & projecting?"} bool unstack=no {prompt="Delete stacked image & expmap when done?"} bool unzero=no {prompt="Undo zero offsets when done?"} bool unscale=no {prompt="Undo scaling factors when done?"} bool putscale=no {prompt="Insert scaling factors into image headers?"} string wordscale="SCALEFAC" {prompt="Scaling factor header keyword"} bool putzero=no {prompt="Insert zero offsets into image headers?"} string wordzero="ZEROVAL" {prompt="Zero offset header keyword"} bool putweight=no {prompt="Insert weights into image headers?"} string wordweight="WEIGHT" {prompt="Weighting factor header keyword"} real extcoeff=0.05 {prompt="Extinction coefficient for default scalings"} real airzero=1. {prompt="Airmass to scale to? (INDEF=min. observed)"} bool maskedstat=no {prompt="Use maskstat to find default zeros & weights?"} string statfile="" {prompt="File for image statistics"} bool makeavg=no {prompt="Make pure coadd (comb=average,rej=none)?"} bool flip=no {prompt="Flip image L-R after coadd?\n--MKOBJMASK/MASKLET PARAMETERS (DOMKOBJMASK+/DOMASKLET+)--"} # MKOBJMASK/MASKLET PARAMETERS (DOMKOBJMASK+/DOMASKLET+) string areamask="" {prompt="Exposed area mask (default: image//mask.pl)"} bool subtract=no {prompt="Subtract average beforehand (ALSO DOTRIM+)?"} string substring="sub" {prompt="Suffix string for subtracted image, if made"} int nsmooth {3,min=0,prompt="Boxcar smoothing filter size (ODD values only)"} int subsample {1,min=1,prompt="Subsampling factor before median filtering"} int filtsize {15,min=1,prompt="Filter size for local median sky evaluation"} int ngrow {1,min=0,prompt="Width of rings to grow around masked objects"} bool interact=yes {prompt="Interactively examine normalized image?"} bool editimshift=yes {prompt="Edit Image+Shifts file in masklet?\n--TRIM PARAMETERS (DOTRIM+; ALSO subtract)------"} # TRIM PARAMETERS (DOTRIM+; ALSO subtract UNDER MKOBJMASK ABOVE) string stats="" {prompt="File to contain trimmed image RMS values"} real mingoodexp=0.36 {prompt="Minimum acceptable exptime (fraction of maximum)"} begin string i_list, root_name, log_file, instru_ment, BP_mask, stat_list, do_flat string x_tmpstring, y_tmpstring, d_statfile, x_oldstring, d_rotsuffix, do_sky string d_dark, d_darkstring, d_flatstring, d_skystring, d_coaddimage, d_expmap string d_masktyp, d_flatfield, d_objmasksuffix, d_tplname, d_refimage, d_prefix string d_suffix, d_scaling, d_zeroing, d_weighting, d_observatory, d_im_extn string d_list, f_list, s_list, d_imflatpars, d_imskypars, d_imcoaddpars, d_stats string d_substring, d_areamask, d_epoch, d_ra, d_dec, d_wordscale, d_wordzero string d_wordweight, d_imsection, old_string, old_list, d_whentpl, d_patternsub string subpat_list real d_maskval, d_extcoeff, d_airzero, temp2_num, d_mingoodexp, d_angle, d_scale real d_bpfrac int d_flat_num, d_sky_num, temP_num, d_magfac, d_rotmagfac int d_nsmooth, d_subsample, d_filtsize, d_ngrow, good_value bool do_first, sub_dark, quick_look, do_dflat, do_sflat, do_skysub, d_interact bool obj_mask, do_shift, do_coadd, do_mkobjmask, do_masklet, do_crzap, echo_g bool do_rotate, do_photcheck, do_photscale, do_trim, do_qkflat, do_qksky, d_ut bool d_ddmmyy, d_zeroout, d_flatsave, d_skysave, d_tpl, d_forcescale, d_coords bool d_premask, d_useimages, d_displayim, d_prescale, d_prezero, d_stack, go bool d_unstack, d_unzero, d_unscale, d_maskedstat, d_sky_del, d_flip, d_addsky bool d_bpzero, d_invert, d_norot, get_stats, d_iterstat, d_shortcut, d_remake bool flat_stdpars, sky_stdpars, coadd_stdpars, d_makeavg, d_ptv, d_apply, re_do bool d_subtract, d_airmass, d_airauto, d_putscale, d_putzero, d_putweight bool d_editfiles, d_sky_tpl, d_flat_tpl, after_subpat, during_subpat bool d_editimshift struct datelist # COMMAND LINE PARAMETERS i_list = ilist root_name = rootname BP_mask = badpixmask instru_ment = instrument # WHICH TASKS TO DO? PARAMETERS do_first = dofirst re_do = redo d_dark = imgdark sub_dark=no if (d_dark != "") sub_dark=yes do_flat = doflat do_dflat = no; do_qkflat = no; do_sflat = no if (doflat=="domeflat") do_dflat = yes if (doflat=="qkflat") do_qkflat = yes if (doflat=="irflat") do_sflat = yes do_sky = dosky do_qksky = no; do_skysub = no if (dosky=="qksky") do_qksky = yes if (dosky=="irsky") do_skysub = yes obj_mask = objmask do_shift = doshift get_stats = getstats do_coadd = docoadd do_mkobjmask = domkobjmask do_masklet = domasklet do_trim = dotrim echo_g = makenoise # GENERAL PARAMETERS d_darkstring = darkstring d_flatstring = flatstring d_skystring = skystring log_file = logfile d_imflatpars = imflatpars d_imskypars = imskypars d_imcoaddpars = imcoaddpars d_im_extn = im_extn # DOFIRST+ PARAMETERS d_coords = coords d_airmass = airmass d_airauto = airauto d_epoch = epoch d_ra = ra d_dec = dec d_observatory = observatory d_ut = ut d_ddmmyy = ddmmyy # FLATFIELDING AND SKY-SUBTRACTION PARAMETERS d_zeroout = zeroout d_flatfield = flatfield d_flat_num = flat_num d_flatsave = flatsave d_objmasksuffix = objmsuffix d_remake = remake d_iterstat = iterstat d_premask = premask d_apply = apply d_sky_num = sky_num d_skysave = skysave d_whentpl = whentpl d_tpl = no; d_flat_tpl = no; d_sky_tpl = no if (d_whentpl=="flat") d_flat_tpl = yes if (d_whentpl=="sky") d_sky_tpl = yes if (d_flat_tpl || d_sky_tpl) d_tpl=yes d_tplname = tplname d_addsky = addsky d_patternsub = patternsub during_subpat = no; after_subpat = no if (d_patternsub=="during") during_subpat=yes if (d_patternsub=="after") after_subpat=yes d_forcescale = forcescale d_shortcut = shortcut # IRSHIFT PARAMETERS (DOSHIFT+) d_refimage = refimage d_prefix = prefix d_suffix = suffix d_useimages = useimages d_displayim = displayim d_ptv = ptv d_imsection = imsection d_editfiles = editfiles # GETSTATS+ PARAMETERS d_masktyp = masktyp d_maskval = maskval # IRCOADD PARAMETERS (DOCOADD+) d_coaddimage = coaddimage fileroot (d_coaddimage,validim+); d_coaddimage = fileroot.root d_expmap = expmap fileroot (d_expmap,validim+); d_expmap = fileroot.root d_scaling = scaling d_zeroing = zeroing d_weighting = weighting d_magfac = magfac d_prescale = prescale d_prezero = prezero d_stack = stack d_unstack = unstack d_unzero = unzero d_unscale = unscale d_putscale = putscale d_wordscale = wordscale d_putzero = putzero d_wordzero = wordzero d_putweight = putweight d_wordweight = wordweight d_extcoeff = extcoeff d_airzero = airzero d_maskedstat = maskedstat d_statfile = statfile d_makeavg = makeavg d_flip = flip # MKOBJMASK/MASKLET PARAMETERS (DOMKOBJMASK+/DOMASKLET+) d_areamask = areamask d_subtract = subtract d_substring = substring d_nsmooth = nsmooth d_subsample = subsample d_filtsize = filtsize d_ngrow = ngrow d_interact = interact d_editimshift = editimshift # TRIM PARAMETERS (DOTRIM+) d_stats = stats d_mingoodexp = mingoodexp # Constructed parameters d_list = i_list // d_darkstring # If you don't plan to subtract the dark within dofirst+, # and the dark-subtracted image list doesn't already exist, # use the original list to do flatfielding etc. on: if (!(sub_dark && do_first) && !access(d_list)) d_list = i_list #f_list = d_list // d_flatstring #s_list = f_list // d_skystring d_sky_del = yes flat_stdpars = no sky_stdpars = no coadd_stdpars = no # The "go" parameter won't let the task run if certain tasks aren't loaded. go=yes if(do_shift || do_coadd){ if(!deftask("filecalc")) {go=no} } if(do_coadd){ if(!defpac("imgtools")) {go=no} } if(go) { print("---------- Running DOPHIIRS. --------------------------") # Set up log file, appending if it already exists if (log_file == "") log_file="log_"//i_list print("", >> log_file) print("---------- Running DOPHIIRS. --------------------------", >> log_file) # If darksubbed image list already exists, reset darksubbed image suffix if (do_first && sub_dark) { x_tmpstring = d_darkstring; y_tmpstring = d_darkstring//d_darkstring old_string = d_darkstring; old_list = d_list if (d_darkstring!="") { while (access(d_list)) { old_string = d_darkstring; old_list = d_list d_list = d_list // x_tmpstring d_darkstring = d_darkstring // x_tmpstring } } if (!re_do) { d_list = old_list d_darkstring = old_string } } # Set up instrument-dependent parameters and prep images, w/poss. darksub if (instru_ment == "generic") { if (d_imflatpars=="") flat_stdpars=yes if (d_imskypars=="") sky_stdpars=yes if (d_imcoaddpars=="") coadd_stdpars=yes if (do_first) { print("---------- Setting up images using first. -------------") first (imagelist=i_list, darksub=sub_dark, badmask=BP_mask, dark=d_dark, darkstring=d_darkstring, coords=d_coords, airmass=d_airmass, airauto=d_airauto, epoch=d_epoch, ra=d_ra, dec=d_dec, observatory=d_observatory, ut=d_ut, ddmmyy=d_ddmmyy, echog=echo_g) } } else if (instru_ment == "irim") { d_observatory="kpno" if (d_imflatpars=="") d_imflatpars="phiirs$irflatirim.par" if (d_imskypars=="") d_imskypars="phiirs$irskyirim.par" if (d_imcoaddpars=="") d_imcoaddpars="phiirs$ircoaddirim.par" if (do_first) { print("---------- Setting up images using irimfirst. ---------") irimfirst (i_list, no, sub_dark, suffix=d_darkstring, dark=d_dark, badmask=BP_mask, echog=echo_g) } } else if (instru_ment == "kir") { d_observatory="cfht" d_premask=yes d_maskedstat=yes if (d_imflatpars=="") d_imflatpars="phiirs$irflatkir.par" if (d_imskypars=="") d_imskypars="phiirs$irskykir.par" if (d_imcoaddpars=="") d_imcoaddpars="phiirs$ircoaddkir.par" d_nsmooth = 9 d_subsample = 7 d_filtsize = 15 d_ngrow = 15 if (do_first) { print("---------- Setting up images using cfhtfirst. ---------") cfhtfirst (imagelist=i_list, darksub=sub_dark, badmask=BP_mask, project+, dark=d_dark, darkstring=d_darkstring, observatory=d_observatory, ddmmyy+, echog=echo_g) } } else if (instru_ment == "nsfcam") { d_observatory="cfht" if (d_imflatpars=="") d_imflatpars="phiirs$irflatirtf.par" if (d_imskypars=="") d_imskypars="phiirs$irskyirtf.par" if (d_imcoaddpars=="") d_imcoaddpars="phiirs$ircoaddirtf.par" if (do_first) { print("---------- Setting up images using irtffirst. ---------") irtffirst (i_list, no, sub_dark, suffix=d_darkstring, dark=d_dark, badmask=BP_mask, echog=echo_g) } } else if (instru_ment == "onis") { d_observatory="kpno" d_premask=yes d_maskedstat=yes if (d_imflatpars=="") d_imflatpars="phiirs$irflatonis.par" if (d_imskypars=="") d_imskypars="phiirs$irskyonis.par" if (d_imcoaddpars=="") d_imcoaddpars="phiirs$ircoaddonis.par" d_nsmooth = 3 d_subsample = 3 d_filtsize = 15 d_ngrow = 1 if (do_first) { print("---------- Setting up images using onisfirst. ---------") onisfirst (i_list, sub_dark, BP_mask, dark=d_dark, darkstring=d_darkstring, coords=d_coords, airmass=d_airmass, airauto=d_airauto, epoch=d_epoch, ra=d_ra, dec=d_dec, observatory=d_observatory, ut+, ddmmyy+, echog=echo_g) } } else if (instru_ment == "pisces") { d_observatory="kpno" # d_zeroout=yes d_premask=yes d_maskedstat=yes if (d_imflatpars=="") d_imflatpars="phiirs$irflatpisces.par" if (d_imskypars=="") d_imskypars="phiirs$irskypisces.par" if (d_imcoaddpars=="") d_imcoaddpars="phiirs$ircoaddpisces.par" if (do_first) { print("---------- Setting up images using piscesfirst. -------") piscesfirst (i_list, sub_dark, BP_mask, dark=d_dark, darkstring=d_darkstring, coords=d_coords, airmass=d_airmass, airauto=d_airauto, epoch=d_epoch, ra=d_ra, dec=d_dec, observatory=d_observatory, ut+, ddmmyy+, echog=echo_g) } } else if (instru_ment == "so256") { if (d_imflatpars=="") d_imflatpars="phiirs$irflat256.par" if (d_imskypars=="") d_imskypars="phiirs$irsky256.par" if (d_imcoaddpars=="") d_imcoaddpars="phiirs$ircoadd256.par" if (do_first) { print("---------- Setting up SO 256^2 images using first. ----") first (imagelist=i_list, darksub=sub_dark, badmask=BP_mask, dark=d_dark, darkstring=d_darkstring, coords=d_coords, airmass=d_airmass, airauto=d_airauto, epoch=d_epoch, ra=d_ra, dec=d_dec, observatory=d_observatory, ut=d_ut, ddmmyy=d_ddmmyy, echog=echo_g) } } print("", >> log_file) # If flatfielded image list already exists, reset flatfielded image suffix #if (do_dflat || do_qkflat || do_sflat) { f_list = d_list // d_flatstring x_tmpstring = d_flatstring; y_tmpstring = d_flatstring//d_flatstring old_string = d_flatstring; old_list = f_list if (d_flatstring!="") { while (access(f_list)) { old_string = d_flatstring; old_list = f_list f_list = f_list // x_tmpstring d_flatstring = d_flatstring // x_tmpstring } } if (!re_do || (re_do && !do_dflat && !do_qkflat && !do_sflat)) { f_list = old_list d_flatstring = old_string if (access(f_list)) { do_dflat=no; do_qkflat=no; do_sflat=no } } #} # Flatten using domeflat... if (do_dflat) { print("---------- Flat-fielding using domeflat. --------------") print("---------- Flat-fielding using domeflat.", >> log_file) domeflat (imagelist=d_list, Flatstring=d_flatstring, darksub=sub_dark, dark=d_dark, flatfield=d_flatfield, zeroout=d_zeroout, badmask=BP_mask, logfile=log_file, tpl=d_flat_tpl, tplname=d_tplname, echog=echo_g) print("", >> log_file) # ...or quick-look flattening... } else if (do_qkflat) { print("---------- Flat-fielding using qkflat. ----------------") print("---------- Flat-fielding using qkflat.", >> log_file) if (obj_mask) { print("---------- Also using objmasks. -----------------------") hedit ("@"//d_list,"BPM",("(@'OBJMASK')"),add+,ver-,sho-,upd+) } qkflat (root_name, d_list, d_flatstring, d_flatstring//"."//d_im_extn, log_file, sub_dark, d_dark, BP_mask, d_zeroout, no, mkflat=d_remake, iterstat=d_iterstat, doflat=d_apply, tpl=d_flat_tpl, tplname=d_tplname, imflatpars=d_imflatpars, v210-, echog=echo_g) if(obj_mask)hedit("@"//d_list,"BPM",("(@'BPMASK')"),add+,ver-,sho-,upd+) if(obj_mask)hedit("@"//f_list,"BPM",("(@'BPMASK')"),add+,ver-,sho-,upd+) print("", >> log_file) # ...or self-flattening. } else if (do_sflat) { print("---------- Flat-fielding using irflat. ----------------") print("---------- Flat-fielding using irflat.", >> log_file) if (obj_mask) print("---------- Also using objmasks. -----------------------") # If number of images to use is INDEF, set to highest possible EVEN number if(d_flat_num==INDEF){ count (i_list) | scan (temP_num) temP_num=temP_num-1 temp2_num=temP_num/2. if((temp2_num-int(temp2_num))!=0.) temP_num=temP_num-1 d_flat_num=temP_num } irflat (d_list, d_flatstring, d_flat_num, obj_mask, log_file, premask=d_premask, forcescale=d_forcescale, stdpars=flat_stdpars, flatsave=d_flatsave, same+, suffix=d_objmasksuffix, tpl=d_flat_tpl, tplname=d_tplname, v210-, echog=echo_g, imflatpars=d_imflatpars) print("", >> log_file) } # If skysubbed image list already exists, reset skysubbed image suffix #if (do_skysub || do_qksky) { s_list = f_list // d_skystring x_tmpstring = d_skystring; y_tmpstring = d_skystring//d_skystring old_string = d_skystring; old_list = s_list if (d_skystring!="") { while (access(s_list)) { old_string = d_skystring; old_list = s_list s_list = s_list // x_tmpstring d_skystring = d_skystring // x_tmpstring } } if (!re_do || (re_do && !do_skysub && !do_qksky)) { s_list = old_list d_skystring = old_string if (access(s_list)) { do_skysub=no; do_qksky=no } } #} # Sky-subtract using running sky... if (do_skysub) { print("---------- Sky-subtracting using irsky. ---------------") print("---------- Sky-subtracting using irsky.", >> log_file) # If list of sky-subtracted images doesn't exist, use list of flatfielded ones if (!access(f_list)) f_list = d_list # If number of images to use is INDEF, set to highest possible EVEN number if(d_sky_num==INDEF){ count (i_list) | scan (temP_num) temP_num=temP_num-1 temp2_num=temP_num/2. if((temp2_num-int(temp2_num))!=0.) temP_num=temP_num-1 d_sky_num=temP_num } if(d_skysave)d_sky_del=no irsky (f_list, d_skystring, d_sky_num, obj_mask, log_file, stdpars=sky_stdpars, sky_del=d_sky_del, same+, suffix=d_objmasksuffix, subpattern=during_subpat, tpl=d_sky_tpl, tplname=d_tplname, addsky=d_addsky, forcescale=d_forcescale, premask=d_premask, csky_del+, myway-, shortcut=d_shortcut, imskypars=d_imskypars, echog=echo_g) print("", >> log_file) # ...or quick-look sky-subtraction. } else if (do_qksky) { print("---------- Sky-subtracting using qksky. ---------------") print("---------- Sky-subtracting using qksky.", >> log_file) # If list of sky-subtracted images doesn't exist, use list of flatfielded ones if (!access(f_list)) f_list = d_list if (obj_mask) { print("---------- Also using objmasks. -----------------------") hedit ("@"//f_list,"BPM",("(@'OBJMASK')"),add+,ver-,sho-,upd+) } qksky (root_name, f_list, log_file, d_skystring, d_flatstring//d_skystring//"."//d_im_extn, stdpars=sky_stdpars, stdstar-, zeroout=d_zeroout, maskname=BP_mask, subpattern=during_subpat, tpl=d_sky_tpl, tplname=d_tplname, mksky=d_remake, iterstat=d_iterstat, dosky=d_apply, addsky=d_addsky, forcescale=d_forcescale, premask=d_premask, imskypars=d_imskypars, echog=echo_g) if(obj_mask && access(f_list))hedit("@"//f_list,"BPM",("(@'BPMASK')"),add+,ver-,sho-,upd+) if(obj_mask && access(s_list))hedit("@"//s_list,"BPM",("(@'BPMASK')"),add+,ver-,sho-,upd+) print("", >> log_file) } # Subtract pattern noise if (after_subpat) { subpat_list = s_list if (!access(s_list)) subpat_list = f_list subpattern(subpat_list, "", startline=1, finishline=512, blankname="blank_pattern.fits", ver-, useimgs+, saveimgs+, echog=echo_g) } # Get iterative statistics of images to be coadded if (get_stats) { stat_list = s_list if (!access(s_list)) stat_list = f_list if (access(stat_list//".stats")) { if (!re_do) { print (stat_list//".stats exists... not recreated.") print (stat_list//".stats exists... not recreated.", >>log_file) } else { # if (!access(stat_list)) stat_list = d_list # if (!access(stat_list)) stat_list = i_list del (stat_list//".stats_old", ver-, >& "dev$null") rename (stat_list//".stats", stat_list//".stats_old") print ("Recreating "//stat_list//".stats; old version renamed "//stat_list//".stats_old") print ("Recreating "//stat_list//".stats; old version renamed "//stat_list//".stats_old", >> log_file) } } if (!access(stat_list//".stats")) { if (d_masktyp=="none") { print ("masktyp set to none... using iterstat instead of maskstat.") d_premask=no } if (d_premask) { print("---------- Outputting maskstat results to "//stat_list//".stats") print("---------- Outputting maskstat results to "//stat_list//".stats", >> log_file) if (d_masktyp=="goodval") { good_value=int(d_maskval) } else if (d_masktyp=="badval") { good_value=int(1.-d_maskval) } maskstat ("@"//stat_list, "!BPM", goodvalue=good_value, iterstat+, addh+, printit+, >> stat_list//".stats") } else { print("---------- Outputting iterstat results to "//stat_list//".stats") print("---------- Outputting iterstat results to "//stat_list//".stats", >> log_file) iterstat ("@"//stat_list, print+, addh+, >> stat_list//".stats") } } type (stat_list//".stats") } # Measure image shifts if (do_shift) { print("---------- Calculating image shifts using irshift. ----") print("---------- Calculating image shifts using irshift.", >> log_file) # If list of sky-subtracted images doesn't exist, use list of flatfielded ones if (!access(s_list)) s_list = f_list # If refimage, prefix or suffix are not set, use defaults if (d_refimage=="") fields (s_list, 1, lines="1-1") | scan (d_refimage) if (d_prefix=="") d_prefix=root_name if (d_suffix=="") { x_tmpstring = "sh1" y_tmpstring=d_prefix//".roundoff."//x_tmpstring old_string = x_tmpstring; old_list = y_tmpstring while (access(y_tmpstring)) { old_string = x_tmpstring; old_list = y_tmpstring x_tmpstring = x_tmpstring + 1 y_tmpstring=d_prefix//".roundoff."//x_tmpstring } if (!re_do) { y_tmpstring = old_list x_tmpstring = old_string } d_suffix=x_tmpstring } if(re_do || (!re_do && !access(y_tmpstring))) { irshift (s_list, d_refimage, d_prefix, d_suffix, fracshift-, useimages=d_useimages, displayim=d_displayim, ptv=d_ptv, imsection=d_imsection, editfiles=d_editfiles, combdata-, echog=echo_g) } print("", >> log_file) } # Coadd images if (do_coadd) { print("---------- Coadding images using ircoadd. -------------") print("---------- Coadding images using ircoadd.", >> log_file) # If shift-file prefix or suffix not set, use highest-numbered image shifts file if (d_prefix=="") d_prefix=root_name if (d_suffix=="") { x_tmpstring = "sh1" x_oldstring = x_tmpstring y_tmpstring=d_prefix//".roundoff."//x_tmpstring while (access(y_tmpstring)) { x_oldstring = x_tmpstring x_tmpstring = x_tmpstring + 1 y_tmpstring=d_prefix//".roundoff."//x_tmpstring } x_tmpstring = x_oldstring d_suffix=x_tmpstring } # If list of sky-subtracted images doesn't exist, use list of flatfielded ones if (!access(s_list)) s_list = f_list # If name of statfile not set, use the same default as the ircoadd task if (d_statfile=="") d_statfile=s_list//".stats" # If name of coadded image not set, use the first available "_coaddN" suffix if (d_coaddimage=="") { y_tmpstring = "" x_tmpstring = "_coadd1" y_tmpstring=root_name//x_tmpstring//"."//d_im_extn while (access(y_tmpstring)) { x_tmpstring = x_tmpstring + 1 y_tmpstring=root_name//x_tmpstring//"."//d_im_extn } d_coaddimage=root_name//x_tmpstring//"."//d_im_extn } if(re_do || (!re_do && !access(y_tmpstring))) { ircoadd (s_list, d_coaddimage, d_expmap, d_prefix//".roundoff."//d_suffix, d_scaling, d_zeroing, d_weighting, d_magfac, d_stack, log_file, prescale=d_prescale, unscale=d_unscale, putscale=d_putscale, wordscale=d_wordscale, extcoeff=d_extcoeff, airzero=d_airzero, prezero=d_prezero, unzero=d_unzero, putzero=d_putzero, wordzero=d_wordzero, putweight=d_putweight, wordweight=d_wordweight, unstack=d_unstack, maskedstat=d_maskedstat, statfile=d_statfile, stdpars=coadd_stdpars, makeavg=d_makeavg, flip=d_flip, tpl=d_tpl, echog=echo_g, imcoaddpars=d_imcoaddpars) } else { print(d_coaddimage//" already exists ... not recreating.") print(d_coaddimage//" already exists ... not recreating.", >>log_file) } print("", >> log_file) } # Make object mask for coadded image if (do_mkobjmask) { print("---------- Making object mask using mkobjmask. ---------") print("---------- Making object mask using mkobjmask.", >> log_file) # If name of coadded image not set, use highest-numbered "_coaddN" suffix if (d_coaddimage=="") { x_tmpstring = "_coadd1" x_oldstring = x_tmpstring y_tmpstring=root_name//x_tmpstring//"."//d_im_extn while (access(y_tmpstring)) { x_oldstring = x_tmpstring x_tmpstring = x_tmpstring + 1 y_tmpstring=root_name//x_tmpstring//"."//d_im_extn } x_tmpstring = x_oldstring d_coaddimage=root_name//x_tmpstring//"."//d_im_extn } mkobjmask (d_coaddimage, d_expmap, suffix="objmask", prefix="norm", areamask=d_areamask, subtract=d_subtract, substring=d_substring, nsmooth=d_nsmooth, subsample=d_subsample, filtsize=d_filtsize, ngrow=d_ngrow, interact=d_interact, echog=echo_g) print("", >> log_file) } # Make object masks for individual images if (do_masklet) { print("---------- Making individual object masks with masklet. ") print("---------- Making individual object masks with masklet.", >> log_file) # If name of coadded image not set, use highest-numbered "_coaddN" suffix if (d_coaddimage=="") { x_tmpstring = "_coadd1" x_oldstring = x_tmpstring y_tmpstring=root_name//x_tmpstring//"."//d_im_extn while (access(y_tmpstring)) { x_oldstring = x_tmpstring x_tmpstring = x_tmpstring + 1 y_tmpstring=root_name//x_tmpstring//"."//d_im_extn } x_tmpstring = x_oldstring d_coaddimage=root_name//x_tmpstring//"."//d_im_extn } masklet (d_coaddimage, "", d_objmasksuffix, shiftfile="", editfile=d_editimshift, flip=d_flip, update+, echog=echo_g) print("", >> log_file) } # Created constant-rms image with a minimum exposure time if (do_trim) { print("---------- Creating constant-rms image. ----------------") print("---------- Creating constant-rms image.", >> log_file) # If name of coadded image not set, use highest-numbered "_coaddN" suffix if (d_coaddimage=="") { x_tmpstring = "_coadd1" x_oldstring = x_tmpstring y_tmpstring=root_name//x_tmpstring//"."//d_im_extn while (access(y_tmpstring)) { x_oldstring = x_tmpstring x_tmpstring = x_tmpstring + 1 y_tmpstring=root_name//x_tmpstring//"."//d_im_extn } x_tmpstring = x_oldstring d_coaddimage=root_name//x_tmpstring//"."//d_im_extn } # If name of trimmed-image stat file not set, use "*_coaddN.trimstats" if (d_stats=="") { fileroot (d_coaddimage, validim+) d_stats=fileroot.root//".trimstats" } trim (d_coaddimage, d_expmap, d_stats, out="trim", subtract=d_subtract, mingoodexp=d_mingoodexp, echog=echo_g) print("", >> log_file) } del ("_gooDaTe", ver-, >& "dev$null") !date > _gooDaTe type ("_gooDaTe") | scan (datelist) del ("_gooDaTe", ver-, >& "dev$null") print("---------- DOPHIIRS complete at "//datelist, >> log_file) print("", >> log_file); print("") print("DOPHIIRS complete at "//datelist//"; detailed log in "//log_file) } else { print("WARNING: either ctio.filecalc task is not loaded (if doshift+ or docoadd+)") print("or stsdas.toolbox.imgtools package isn't loaded (if docoadd+).") print("Please load them and restart this task.") } if (echo_g) beep end ./first.cl0100644000151400000240000002347407254743514011655 0ustar phallgames# first.cl -- task to subtract dark & add header params to brand new raw images # # 1. subtract dark # 2. hedit image headers, adding: (basically this task is hadd.cl plus #0) # 1. BPM,BPMASK = bad pixel mask name # 2. coadds = number of internal coadds # 3. exptime = (itime: exposure time per coadd) * (# of coadds) # 4. obs-date = date-obs but in dd/mm/yy format # 5. ut = time-obs (or time-obs + 7) # 6. date-obs = yyyy-mm-dd format (old date-obs saved as dateorig) # (following are optional) # 7. epoch, ra, dec = entered as parameters, if desired # 8. st = sidereal time, calculated from ut & date using astutil.asttimes # & the observatory parameter (kpno, mtbigelow, mmto, ctio) # 9. airmass = calculated from epoch, ra, dec, st, and obs-date # # 940902: fixed problem with ut>24 # 950122: adjusted so that header params are added first, to raw image, and # dark is then subtracted, so that both sets of images have header params. # Also added `DARKSUB' header card to darksubbed images, indicating what # dark image was subtracted from them. # Also fixed problem with BPM not getting added into image header. # 950203: added adding of "coadds" header card # 950214: check for "ncoadds" header card & ok date-obs (laird's fits256.e data) # 950215: use "obs-date" to find day, month, year since it has standard format; # also streamlined input parameters. # 950216: made adding of airmass optional # 970321: yyear calculated correctly for observations from 1981-2080 only # 980414: added compatibility to incoming date-obs in new-millenium format and # output of date-obs in same format (valid for data from 1990 to 2089); # original date-obs is output as dateorig # 981228: added check for dateorig -- if it exists, date-obs etc. not redone # 990427: DARKSUB keyword added to darksubbed images, not original ones # # **bug: airmass+ airauto+ option assumes you're observing from MST time zone! # ...but that's only for the "asttimes" task, which may be irrelevant # **should be more options for computing ut than just time-obs or time-obs+7h procedure first(imagelist,darksub,badmask) string imagelist {prompt="List of images to process (do not use an `@')"} bool darksub {prompt="Subtract off dark frame?"} string badmask {prompt="Name of bad pixel mask to add to image header"} string dark {prompt="Name of the dark frame to subtract", mode="q"} string darkstring {prompt="String to append to dark-subtracted images",mode="q"} bool coords=no {prompt="Add RA, DEC, and EPOCH to image header?"} bool airmass=no {prompt="Enter airmass into image header?"} bool airauto=yes {prompt="Find airmass of image automatically?"} real airval {prompt="Airmass of image", mode="q"} string epoch {prompt="Epoch of coordinates"} string ra {prompt="Right Ascension (surround with quotes)"} string dec {prompt="Declination (surround w/quotes; use - but not +"} string observatory {prompt="Observatory where observations were made"} bool ut=yes {prompt="Is 'time-obs' in header ut or not?"} bool ddmmyy=no {prompt="Is 'date-obs' in day/month/year format?"} bool echog=yes {prompt="Beep when task is done?"} struct *list begin string ddark, ddarkstring, bbadmask, check, base, iimagelist, ext string darklist, flat, flatbase, meanfile, currentflat, tempflat, name string editlist, current, obsdate, rra, ddec, eepoch, oobservatory, minsec string obstime, timeobs, dateobs, century real intime, aairval, ttime, mean, meanbad, x int ncoadd, ddy, hhr, hhour, mmonth, yyear, dday, uttime, last2digits bool ddarksub, ccoords, aairauto, uut, aairmass iimagelist = imagelist list = iimagelist editlist = iimagelist ddarksub = darksub if (ddarksub) { ddark = dark ddarkstring = darkstring darklist = iimagelist//ddarkstring } bbadmask = badmask ccoords = coords aairmass = airmass if (aairmass) { aairauto = airauto # if(!aairauto)aairval = airval if(!defpac("astutil")) { beep print ("WARNING!! Package ''astutil'' is not loaded; cannot set airmass in images.") print ("Load the package and rerun the task.") return } } eepoch = epoch rra = ra ddec = dec oobservatory = observatory uut = ut # Add BPM and other goodies to the image headers, just like in the hadd.cl task print("===> Adding various parameters to the image headers...") list = iimagelist while (fscan (list, current) !=EOF) { hedit(current,"BPM",bbadmask,add+,ver-,show+,update+) hedit(current,"BPMASK",bbadmask,add+,ver-,show+,update+) # Set exptime=itime * (# of coadds) imgets(current,"comment", >& "dev$null") if(imgets.value!="0"){ ncoadd=int(substr(imgets.value,strlen(imgets.value),strlen(imgets.value))) } else { imgets(current,"ncoadds", >& "dev$null") ncoadd=real(imgets.value) } hedit(current,"coadds",(ncoadd),add+,ver-,show+,update+) imgets(current,"itime") intime=real(imgets.value) hedit(current,"exptime",(ncoadd*intime),add+,ver-,show+,update+) # # The 'date-obs' keyword comes in either the old format "dd/mm/yy", # the erroneous format "mm/dd/yy", or the new format "yyyy-mm-dd". # Create new 'date-obs' keyword in the new format "yyyy-mm-dd". imgets(current,"dateorig") if (imgets.value!="0") { print ("DATEORIG keyword already exists -- first already run on image?") } else { imgets(current,"date-obs") # Copy 'date-obs' keyword to 'dateorig' in original format. hedit(current,"dateorig",imgets.value,add+,ver-,show+,update+) # Create header keyword 'obs-date', always in "dd/mm/yy" format. if(!ddmmyy){ # mm/dd/yy format: if(substr(imgets.value,3,3)=="/") { obsdate=substr(imgets.value,4,6)//substr(imgets.value,1,3)//substr(imgets.value,7,8) } else { # yyyy-mm-dd format: # 1234567890 obsdate=substr(imgets.value,9,10)//"/"//substr(imgets.value,6,7)//"/"//substr(imgets.value,3,4) } # create obs-date if date-obs in mm/dd/yy or yyyy-mm-dd format: hedit(current,"obs-date",obsdate,add+,ver-,show+,update+) } else { # create obs-date if date-obs in dd/mm/yy format: hedit(current,"obs-date",imgets.value,add+,ver-,show+,update+) } # Create new 'date-obs' in new format "yyyy-mm-dd" from 'obs-date' "dd/mm/yy" # 12345678 imgets(current,"obs-date") if ((substr(imgets.value,7,7))=="9") { century=19 } else { century=20 } dateobs=century//substr(imgets.value,7,8)//"-"//substr(imgets.value,4,5)//"-"//substr(imgets.value,1,2) hedit(current,"date-obs",dateobs,add+,ver-,show+,update+) # # Sometimes the time in the image header is ut, sometimes not. # so this option lets you choose either ut or mst if(uut){hedit(current,"ut",("(@'time-obs')"),add+,ver-,show+,update+)} else{ imgets(current,"time-obs") obstime=substr(imgets.value,1,2) uttime=int(obstime)+7 if(uttime>=24){uttime=uttime-24} if(uttime<=9){timeobs="0"//str(uttime)//substr(imgets.value,3,8)} if(uttime>=10){timeobs=str(uttime)//substr(imgets.value,3,8)} #need to hedit ut twice cause is not in hh:mm:ss format 1st time around hedit(current,"ut",timeobs,add+,ver-,show+,update+) hedit(current,"ut",timeobs,add+,ver-,show+,update+) } } } if(ccoords){ list = iimagelist while (fscan (list, current) !=EOF) { hedit(current,"epoch",eepoch,add+,ver-,show+,update+) hedit(current,"ra",rra,add+,ver-,show-,update+) hedit(current,"ra",rra,add+,ver-,show+,update+) hedit(current,"dec",ddec,add+,ver-,show-,update+) hedit(current,"dec",ddec,add+,ver-,show+,update+) #hedit test ra "(str('21:51:59.0'))" add+ ver- show- } } if(aairmass){ if(aairauto){ list = iimagelist while (fscan (list, current) !=EOF) { imgets(current,"obs-date") dday=int(substr(imgets.value,1,2)) mmonth=int(substr(imgets.value,4,5)) # yyear=int("19"//substr(imgets.value,7,8)) last2digits=int(substr(imgets.value,7,8)) if(last2digits <= 80) { yyear=int("20"//substr(imgets.value,7,8)) } else { yyear=int("19"//substr(imgets.value,7,8)) } imgets(current,"ut") hhr=int(substr(imgets.value,1,2)) minsec=substr(imgets.value,3,8) hhour=hhr-7 if(hhour<0){ dday=dday-1 hhour=hhour+24. } if(dday<=0){ mmonth=mmonth-1 # this will not always be totally accurate, and may fail for feb., but hey. dday=30 } # observing on new year's eve will require a new correction! ttime=real(str(int(hhour))//minsec) asttimes(observatory=oobservatory, year=yyear, month=mmonth, day=dday, time=ttime) hedit(current,"st",asttimes.lmst,add+,ver-,show-,update+) hedit(current,"st",asttimes.lmst,add+,ver-,show+,update+) setairmass(current, observatory=oobservatory, intype="middle", outtype="effective", date="obs-date",exposure="exptime", utmiddle="utmiddle", show+, update+, override+) } } else { list = iimagelist while (fscan (list, current) !=EOF) { print("Setting airmass for image "//current) hedit(current,"airmass",airval,add+,ver-,show+,update+) } } } # Subtract off Dark Current if (ddarksub) { list = iimagelist # if darklist doesn't exist, assume dsub imgs don't either; create it & dsubs if(!access(darklist)) { print("===> Subtracting off Dark Current...") while (fscan (list, name) !=EOF) { fileroot(name,validim+) base=fileroot.root ext=fileroot.extension if(ext!="")ext="."//ext print(base//ddarkstring//ext, >> darklist) imgets(name,"DARKSUB") if (imgets.value=="0") { imarith(name, "-", ddark, base//ddarkstring//ext, verbose-) hedit(base//ddarkstring//ext,"DARKSUB",ddark,add+,ver-,show+,update+) } else { print("DARKSUB keyword exists; first already run? "//name//" just copied") imcopy(name, base//ddarkstring//ext, verbose-) } } } else { print("Darksubbed image list "//darklist//" already exists; images assumed to exist too.") } #imarith("@"//iimagelist, "-", ddark, "@"//darklist, verbose-) #hedit("@"//darklist,"DARKSUB",ddark,add+,ver-,show+,update+) print(" ") print("===> Dark-subtracted images are listed in the file "//darklist//".") } if(echog)beep end ./minv.cl0100644000151400000240000000372507112212463011457 0ustar phallgamesprocedure minv(infile,outfile) # Routine to invert masks so that <=0 --> 1 and >0 --> 0 # # 960416: added check for 0-1 range, and more careful with image extension # 970430: changed so that all values >=1 now set to 0, with warning # 970730: changed so that values <=0 --> 1 and values >0 --> 0 # 970930: intermediate step: copy to .fits format & real pixtype # to avoid .pl limitations # 971101: modified so a fixed temporary image name is not created # 980709: does chpixtype instead of imarith to generate pixtype=real tmp image # 990218: changed default working image type from ".imh" to ".fits" # 990513: vastly simplified through logical use of imcalc # 000521: now tells you it's abandoning the task if imcalc isn't loaded string infile {prompt = "Input mask image (best include extension)"} string outfile {prompt = "Output (inverted) mask image (ditto)"} begin string inf,outf,inex,outex,biteme # Get query parameters: fileroot(infile) inf = fileroot.root inex = "."//fileroot.extension if(inex==".")inex="" fileroot(outfile,validim+) outf = fileroot.root outex = "."//fileroot.extension if(outex==".")outex="" if (!defpac("imgtools")) { beep print("WARNING! stsdas.imgtools package not loaded! Bailing out of minv...") return } minmax (inf, force+, ver-) if ((minmax.minval < 0.) || (minmax.maxval > 1.)) { beep print("WARNING! Pixels in image range beyond 0-1.") } imcalc(inf//inex,outf//outex, "if im1 .le. 0 then 1 else 0", ver-) # biteme = mktemp("_biteme") # imcopy(inf//inex,biteme//".fits",ver-) ## imar(biteme//".fits","+",0.,biteme//".fits",ver-,noact-,pixt="real") # chpixtype(biteme//".fits",biteme//".fits",newpi="real",oldpi="all",ver-) # imreplace (biteme//".fits",1.,lower=0.01,upper=INDEF) # imreplace (biteme//".fits",2.,lower=INDEF,upper=0.02) # imarith (biteme//".fits","-",1.,biteme//".fits") # if(inf//inex==outf//outex)imdel(inf//inex, ver-) # imcopy(biteme//".fits",outf//outex,ver-) # imdel(biteme//".fits",ver-) end ./helpdb.mip0100644000151400000240000001401407217760206012135 0ustar phallgamesD'qá: wˆ*uBHB5=rootdefdir=piscis!/astr16/users/phall/IRAF/phiirs/_phiirs_phiirs.hdÉBi B8?J_U?_phiirsdefdir=piscis!/astr16/users/phall/IRAF/phiirs/phiirsphiirs.menphiirs.hlpphiirs.hdphiirs.cl=zÂ55z7GRes{‹– ²¿ÅÓÜãòü"+<HQbnwˆ”š¨±¹ÉÔÛêôþ&7CK[fo€Œ’ ©³ÅÒÜîû 09JV[hpw†œ°¿Ç×âëü "(6?FU_fu‰›¨®¼åðÅÌÛ:CT`k~Œ–¨µ½ÍØàð-û$->JTfs“¢«¼ÈÏÞèîü );HSftx„‹¥«¹phiirsdefdir=piscis!/astr16/users/phall/IRAF/phiirs/doc=phiirs$doc/addcommentdoc$addcomment.hlpaddcomment.claddringdoc$addring.hlpaddring.clcfhtfirstdoc$cfhtfirst.hlpcfhtfirst.clcrzapdoc$crzap.hlpcrzap.clcrzap2doc$crzap2.hlpcrzap2.cldestripedoc$destripe.hlpdestripe.cldomeflatdoc$domeflat.hlpdomeflat.cldophiirsdoc$dophiirs.hlpdophiirs.clfilerootdoc$fileroot.hlpfileroot.clfirstdoc$first.hlpfirst.clircoadddoc$ircoadd.hlpircoadd.clirflatdoc$irflat.hlpirflat.clirimfirstdoc$irimfirst.hlpirimfirst.clirrotatedoc$irrotate.hlpirrotate.clirshiftdoc$irshift.hlpirshift.clirshift2doc$irshift2.hlpirshift2.clirskydoc$irsky.hlpirsky.clirtfcoadddoc$irtfcoadd.hlpirtfcoadd.clirtffirstdoc$irtffirst.hlpirtffirst.clirtfphotscaledoc$irtfphotscale.hlpirtfphotscale.cliterstatdoc$iterstat.hlpiterstat.cllookdoc$look.hlplook.cllook4mdoc$look4m.hlplook4m.clmakeobjmaskdoc$makeobjmask.hlpmakeobjmask.clmaskletdoc$masklet.hlpmasklet.clmaskstatdoc$maskstat.hlpmaskstat.clminvdoc$minv.hlpminv.clmkbpmdoc$mkbpm.hlpmkbpm.clmkdarkdoc$mkdark.hlpmkdark.clmkflatdoc$mkflat.hlpmkflat.clmkobjmaskdoc$mkobjmask.hlpmkobjmask.clmygetdoc$myget.hlpmyget.clnshiftdoc$nshift.hlpnshift.clnl_findcordoc$nl_findcor.hlpnl_findcor.clonisfirstdoc$onisfirst.hlponisfirst.clonis0302doc$onis0302.hlponis0302.clonis1358cndoc$onis1358cn.hlponis1358cn.clonis1358sdoc$onis1358s.hlponis1358s.clonis3ewdoc$onis3ew.hlponis3ew.clonis6ptdoc$onis6pt.hlponis6pt.clphotcheckdoc$photcheck.hlpphotcheck.clphotcompdoc$photcomp.hlpphotcomp.clphotscaledoc$photscale.hlpphotscale.clpiscesfirstdoc$piscesfirst.hlppiscesfirst.clprecoadddoc$precoadd.hlpprecoadd.clqkflatdoc$qkflat.hlpqkflat.clqkskydoc$qksky.hlpqksky.clsctvdoc$sctv.hlpsctv.clsigmanormdoc$sigmanorm.hlpsigmanorm.clsubpatterndoc$subpattern.hlpsubpattern.cltpldoc$tpl.hlptpl.cltrimdoc$trim.hlptrim.clxlistdoc$xlist.hlpxlist.clY­NHNIP‚´å _rootroot.hd_phiirspiscis!/astr16/users/phall/IRAF/phiirs/_phiirs.hdphiirspiscis!/astr16/users/phall/IRAF/phiirs/phiirs.menpiscis!/astr16/users/phall/IRAF/phiirs/phiirs.hlppiscis!/astr16/users/phall/IRAF/phiirs/phiirs.clpiscis!/astr16/users/phall/IRAF/phiirs/phiirs.hdpiscis!/astr16/users/phall/IRAF/phiirs/phiirs.men_index8'qápiscis!/astr16/users/phall/IRAF/phiirs/_phiirs.hdf#ÆZpiscis!/astr16/users/phall/IRAF/phiirs/phiirs.hdÝ'Fˆ root.hd" or @filename.") mmorescalename=morescalename checkmore=substr(mmorescalename,1,1) } } } pputscale=putscale if(pputscale)wwordscale=wordscale } if(!ddefscale)ddefscale=defscale if(ddefscale && aairzero==100.)aairzero=airzero # if airzero=INDEF and airzero is needed later in the task, airzero=min(airmass) if(aairzero==INDEF && (ddefscale || (pprescale && checkscale=="@" && access(sscalename)))){ print("...one moment please...") file_of_air=mktemp("foa") hsel("@"//ccomblist1,"AIRMASS",yes, >> file_of_air) list=file_of_air aairzero=100. while (fscan (list,air) != EOF) { aairzero=min(air,aairzero) } del(file_of_air,ver-,>&"dev$null") list="" } } zzeroing = zeroing if(zzeroing=="")zzeroing="none" pprezero=no uunzero=no checkzero=substr(zzeroing,1,1) if(checkzero=="!" || checkzero=="@"){ wwordzero = substr(zzeroing,2,strlen(zzeroing)) pprezero=prezero if(pprezero)uunzero=unzero if(checkzero=="@"){ zzeroname = substr(zzeroing,2,strlen(zzeroing)) pputzero=putzero if(pputzero)wwordzero=wordzero } } wweighting = weighting if(wweighting=="")wweighting="none" checkweight=substr(wweighting,1,1) if(checkweight=="!")wwordweight=substr(wweighting,2,strlen(wweighting)) if(checkweight=="@"){ wweightname = substr(wweighting,2,strlen(wweighting)) pputweight=putweight if(pputweight)wwordweight=wordweight } mag = magfac mag2=mag*mag blk = "br"//mag ccomblist2 = ccomblist//blk bprotlist = ccomblist//blk//"pl" sspscale=no sspshift=no if(mag!=1){ if(zzeroing!="none")sspscale=spscale sspshift=spshift } sstack=stack sstackimage="fake_image_oog" if(sstack) { fileroot(stackimage,validim+) sstackimage = fileroot.root uunstack=unstack } llogfile = logfile nnewmask = newmask if(nnewmask)bbadmask = badmask eexpname = expname sstatfile = statfile # if(sstatfile=="")sstatfile=sshiftexactlist//".stats" if(sstatfile=="")sstatfile=ccomblist//".stats" ttpl = tpl ccleanup = cleanup # Check for bad parameter combinations and exit if necessary if(!pprescale && sstack && checkscale=="!"){ print("WARNING! You can't scale during imcombine from a header keyword") print("when stack=yes! (There is only one header for a stacked image.)") print("Use `@file' or prescale=yes instead.") return } if(!pprezero && sstack && checkzero=="!"){ print("WARNING! You can't take the zero offsets from a header keyword") print("when stack=yes! (There is only one header for a stacked image.)") print("Use `@filename' or prezero=yes instead.") return } if(checkweight!="@" && wweighting!="none" && sstack){ print("WARNING! Output image exposure time would have been incorrect.") print("If you want to use weights and stacking, put the weights in a file") print("before running the task; that way the output image exposure time") print("will be correctly calculated.") return } wt_avg_exptime=-1. unwt_avg_exptime=-1. s_sigma = i_sigma # imcombine parameters s_plfile = i_plfile s_combine = i_combine s_reject = i_reject s_masktyp = i_masktyp s_maskval = i_maskval s_blank = i_blank s_statsec = i_statsec s_expname = i_expname s_lthresh = i_lthresh s_hthresh = i_hthresh s_nlow = i_nlow s_nhigh = i_nhigh s_nkeep = i_nkeep s_lsigma = i_lsigma s_hsigma = i_hsigma s_rdnoise = i_rdnoise s_gain = i_gain s_sigscale = i_sigscale s_pclip = i_pclip s_grow = i_grow # Certain tasks/packages must be loaded for task to run. go=yes if(!defpac("imgtools")) {go=no} if(!deftask("addcomment")) {go=no} if(!deftask("fileroot")) {go=no} if(!deftask("filecalc")) {go=no} if(!deftask("iterstat")) {go=no} if(go) { # Set up log file, appending if it already exists. if(llogfile == "") llogfile="log."//ooutimage print("", >> llogfile) print("===> PHIIRS.IRCOADD:", >> llogfile) if(mag!=1){ print("===> Input images from "//ccomblist1//" replicated by factor "//mag//" in each direction.", >> llogfile) print("===> Replicated images in "//ccomblist2//" coadded w/offsets from "//sshiftexactlist//blk, >> llogfile) } else { print("===> Images in "//ccomblist1//" coadded w/offsets from "//sshiftexactlist//",", >> llogfile) } print("===> weights="/wweighting//", stdpars="/stdpars//", makeavg="/makeavg//",", >> llogfile) print("===> scales="/sscaling//", zero offsets="/zzeroing//",", >> llogfile) print("===> readnoise="/s_rdnoise//", gain="//s_gain //",", >> llogfile) print("===> pre-scaling="/pprescale//", un-scaling="/uunscale//", pre-zeroing="/pprezero//", un-zeroing="/uunzero//",", >> llogfile) print("===> defscale="/ddefscale//", subpixscale="/sspscale//", subpixshift="/sspshift//",", >> llogfile) print("===> to make image "//ooutimage//" and exposure map "//eexpmap, >> llogfile) # Scale images by NUMBER OF INTERNAL COADDS # If stacking, and image already exists, do not bother if(sstack && (access(sstackimage//".fits") || access (sstackimage//".fit") || access(sstackimage//".imh") || access(sstackimage//".hhh"))){ print("Not bothering to scale by # of internal coadds; stacked image already exists.") } else { list=ccomblist1 print(" ") print("===) Scaling by the number of internal coadds if necessary...") while (fscan (list, img) !=EOF) { # Check: has this scaling already been done? Look for INTCOSCA header card imgets(img, "intcosca", >& "dev$null") intcosca=str(imgets.value) # If so, nothing is done. # If not, look for the "coadds" header card (from 4m & later first.cl versions) if(intcosca=="0") { imgets(img, "coadds", >& "dev$null") ncoadds=int(imgets.value) # If no "coadds" header card, search for the "ncoadds" header card. It is # usually only found in 'fits256.e' images (ie laird-type), but does not run # the risk of being confused with any other comment cards in the image header, # so it is looked for first. if(ncoadds==0) { imgets(img,"ncoadds", >& "dev$null") ncoadds=int(imgets.value) # If no "ncoadds" header card, get ncoadds from the comment card if(ncoadds==0) { imgets(img,"comment", >& "dev$null") ncoadds=int(substr(imgets.value,strlen(imgets.value),strlen(imgets.value))) } } # Unless ncoadds=1 or 0, multiply through if(ncoadds!=1 && ncoadds!=0) imar(img,"*",ncoadds,img) # Add INTCOSCA header card hedit(img,"INTCOSCA","Internal coadd scaling by factor "//ncoadds//" DONE",add+,ver-,show-,update+) } } } list="" # PRE-SCALING AND DEFAULT SCALING FACTORS FILE CREATION if(pprescale){ # Prevent imcombine from scaling twice sscaling="none" # **DO NOT UNCOMMENT FOLLOWING LINES! unstacking requires that the # list_of_scales file already exists... it must thus be created here. # If stacking, and image already exists, do not bother # if(sstack && (access(sstackimage//".imh") || access(sstackimage//".hhh"))){ # print("Not bothering to pre-scale... stacked image already exists.") # list_of_scales=mktemp("los") # } else { print("===> Multiplying by additional scaling factors...") # In case of scalings taken from header keyword, make file_of_scales if(checkscale=="!"){ file_of_scales=mktemp("fos") hsel("@"//ccomblist1,wwordscale,yes, >> file_of_scales) } # In case of scalings taken from file... if(checkscale=="@"){ # # ...create file of DEFAULT SCALING FACTORS if it doesn't exist... # if(!access(sscalename)){ file_of_air=mktemp("foa") # get airmasses hsel("@"//ccomblist1,"AIRMASS",yes, >> file_of_air) # turn airmasses into scales list=file_of_air while (fscan (list,air) != EOF) { sf=10**(0.4*eextcoeff*(air-aairzero)) print(sf, >> sscalename) } del(file_of_air,ver-) # If combining default scales with other pre-existing scales... if(sscalecombine){ file_of_more=mktemp("fom") if(checkmore=="@"){ copy(substr(mmorescalename,2,strlen(mmorescalename)),file_of_more,ver-) } if(checkmore=="!"){ hsel("@"//ccomblist1,substr(mmorescalename,2,strlen(mmorescalename)),yes, >> file_of_more) } # join files of default and additional scales del("tmp_."//sscalename,ver-,>&"dev$null") join(sscalename,file_of_more,output="tmp_."//sscalename) del(sscalename,ver-,>&"dev$null") del(file_of_more,ver-,>&"dev$null") list="" list="tmp_."//sscalename # create new scales & put into scale file while(fscan (list,air,sf) != EOF) { print(air*sf, >> sscalename) } del("tmp_."//sscalename,ver-,>&"dev$null") } # Finished with creation of default scalings file } list="" file_of_scales=sscalename # End of taking scales from list subroutine } list="" # Allow imcombine to do sigscaling as requested even when pre-scaling if(s_sigscale!=0.){ del ("_avg.file.tmp", ver-, >& "dev$null") type (file_of_scales | average opt="new_sample", >> "_avg.file.tmp") sfavg=average.mean sfmin=1.E20 sfmax=-1.E20 list=file_of_scales while (fscan (list,sf) != EOF) { sfmin=min(sfmin,sf) sfmax=max(sfmax,sf) } if((sfavg-sfmin/sfavg)>=s_sigscale || (sfmax-sfavg/sfavg)>=s_sigscale)s_sigscale=0. del ("_avg.file.tmp", ver-, >& "dev$null") list="" } # Do multiplicative scaling unless it has already been done list_of_scales=mktemp("los") join(ccomblist1,file_of_scales,output=list_of_scales) if(checkscale=="!")del(file_of_scales,ver-) list=list_of_scales while (fscan (list,img,sf) != EOF) { imgets(img,"PRESCALE",>&"dev$null") if(imgets.value=="0"){ imar(img,"*",sf,img,pixt="real",calct="real",ver-) hedit(img,"PRESCALE",sf,add+,ver-,show-,update+,>&"dev$null") if(ddefscale){ imgets(img,"AIRMASS",>&"dev$null") hedit(img,"AIRMOLD",imgets.value,add+,ver-,show-,update+,>&"dev$null") hedit(img,"AIRMASS",aairzero,add+,ver-,show-,update+,>&"dev$null") } } else { print("No action -- image "//img//" already pre-scaled by factor "//imgets.value) } } # } } list="" # put scale factors into image headers if desired if(checkscale=="@"){ if(pputscale){ del("_tmp.sscaling",ver-,>&"dev$null") join(ccomblist1,sscalename,out="_tmp.sscaling") list="_tmp.sscaling" while(fscan (list, img, sf) != EOF) { hedit(img,wwordscale,sf,add+,ver-,show-,update+,>&"dev$null") } del("_tmp.sscaling",ver-,>&"dev$null") } } list="" # DETERMINE ZERO-LEVEL OFFSETS IF NEEDED AND INSERT INTO HEADERS IF DESIRED if(checkzero=="@"){ if(!access(zzeroname)){ print("===) Finding iterative median zero offsets for the images...") del ("_zero.file.tmp?", ver-, >& "dev$null") del ("_avg.file.tmp", ver-, >& "dev$null") # first find iterative median of each image if(!access(sstatfile)){ if(maskedstat){ iterstat.nsigrej=5. iterstat.maxiter=10 maskstat("@"//ccomblist1,"!BPM",1,lower=INDEF,upper=INDEF,iterstat+,ver-,printit+, >> "_zero.file.tmp1") copy("_zero.file.tmp1", sstatfile, ver-) } else { iterstat("@"//ccomblist1,nsigrej=5.,maxiter=10,lower=INDEF,upper=INDEF,print+,ver-, >> "_zero.file.tmp1") copy("_zero.file.tmp1", sstatfile, ver-) } } else { print("Using statistics from "//sstatfile) copy(sstatfile, "_zero.file.tmp1", ver-) } # next find the overall average of the means fields ("_zero.file.tmp1", 5, >> "_zero.file.tmp2") type ("_zero.file.tmp2" | average opt="new_sample", >> "_avg.file.tmp") # now compute the offset of each image from the overall average mean list="_avg.file.tmp" while (fscan (list, avg, sig, num) !=EOF) { lintran("_zero.file.tmp2",min=2,x2=avg,yfield=1,angle=180, >> zzeroname) } del ("_zero.file.tmp?", ver-) del ("_avg.file.tmp", ver-) } # now insert into image headers if desired if(pputzero) { if(access("_tmp.zzeroing"))del("_tmp.zzeroing",ver-) join(ccomblist1,zzeroname,out="_tmp.zzeroing") list="" list="_tmp.zzeroing" while (fscan (list, img, zf) !=EOF) { hedit(img,wwordzero,zf,add+,ver-,show-,update+) } del("_tmp.zzeroing",ver-,>&"dev$null") } } list="" # DETERMINE WEIGHTS IF NEEDED AND ADD TO IMAGE HEADERS IF DESIRED if(checkweight=="@"){ if(!access(wweightname)){ print("===) Creating file of optimal exptime/rms**2 weights for the images...") del ("_weight.file.tmp?", ver-, >& "dev$null") del ("_avg.file.tmp", ver-, >& "dev$null") # first find iterative rms of each image #hsel("@"//ccomblist1,"PRESCALE",yes, >> "_weight.file.tmp9") #count("_weight.file.tmp9") | scan (i,j,k) #if(j!=0){ #beep #print("WARNING! At least one image in "//ccomblist//" was pre-scaled;") #print("thus, the image weights being calculated will be erroneous.") #} if(!access(sstatfile)){ if(maskedstat){ iterstat.nsigrej=5. iterstat.maxiter=10 if(!access("_weight.file.tmp1"))maskstat("@"//ccomblist1,"!BPM",1,lower=INDEF,upper=INDEF,iterstat+,ver-,printit+, >> "_weight.file.tmp1") copy("_weight.file.tmp1", sstatfile, ver-) } else { if(!access("_weight.file.tmp1"))iterstat("@"//ccomblist1,nsigrej=5.,maxiter=10,lower=INDEF,upper=INDEF,print+,ver-, >> "_weight.file.tmp1") copy("_weight.file.tmp1", sstatfile, ver-) } } else { copy (sstatfile, "_weight.file.tmp1", ver-) } fields ("_weight.file.tmp1", 3, >> "_weight.file.tmp2") # get the exptimes for the images hsel("@"//ccomblist1,eexpname,yes, >> "_weight.file.tmp0") join("_weight.file.tmp2","_weight.file.tmp0",out="_weight.file.tmp3") # compute the weights = exptime./(rms**2.) filecalc ("_weight.file.tmp3", "$2/($1*$1)", calctype="real", >> "_weight.file.tmp4") # find the sum of the weights type ("_weight.file.tmp4" | average opt="new_sample",>> "_avg.file.tmp") # normalize by the sum of the weights filecalc ("_weight.file.tmp4", "$1/"//average.sum, calctype="real", >> wweightname) del ("_weight.file.tmp?", ver-) del ("_avg.file.tmp", ver-) } if(pputweight){ if(access("_tmp.wweighting"))del("_tmp.wweighting",ver-) join(ccomblist1,wweightname,out="_tmp.wweighting") list="_tmp.wweighting" while (fscan (list, img, wt) !=EOF) { hedit(img,wwordweight,wt,add+,ver-,show-,update+) } del("_tmp.wweighting",ver-) } } list="" # SUBPIXEL SHIFTING noappend=no # First expand images if subpixel shifting is desired if (mag!=1){ if(!sspshift)sshiftintlist=sshiftexactlist//blk # If output image list already exists, do not append to it if (access(ccomblist2)){ noappend=yes print("WARNING! Output image list "//ccomblist2//" already exists.") print("Any images listed therein will be created if they do not exist,") print("but no image names will be appended to this preexisting file.") } print("===) Expanding images by factor "//mag//" in both directions...") list=ccomblist1 # Go through image list while (fscan (list, img) !=EOF) { fileroot(img,validim+) image=fileroot.root # Do the magnification as long as the image does not already exist or has not # already been rotated/magnified if(!access(image//blk//"."//fileroot.extension)){ imgets(image,"ROTATED",>&"dev$null") if(imgets.value=="0"){ # Divide by mag squared to conserve total number of counts in input image. imar(image,"/",mag2,"_"//blk//image,pixt="real",calc="real",ver-) blkrep("_"//blk//image,image//blk,mag,mag) imdel("_"//blk//image,ver-) if(!noappend)print (image//blk, >> ccomblist2) # Now replicate the bad pixel mask, if not already done. imgets(image//blk,"BPMASK",>&"dev$null") if(imgets.value=="0")imgets(image//blk,"BPM",>&"dev$null") oldbp=imgets.value newbp=blk//oldbp if(!access(newbp)){ blkrep(oldbp,newbp,mag,mag) print(newbp//".pl", >> bprotlist) } # Insert the replicated bad pixel mask in the image header hedit(image//blk,"BPMASK",newbp,add+,ver-,show-,update+) hedit(image//blk,"BPM",newbp,add+,ver-,show-,update+) } else { # If input image already rotated, only print a warning. print("WARNING! "//image//" already rotated; not rotated again") } } else { # If output image already exists, only print a warning. print("WARNING! "//image//blk//" already exists; not overwritten") } # Next image } # # If output subpixel shifts file doesn't exist, create it if(!access(sshiftintlist)) { print("===> Calculating shifts for expanded images...") if (access("tmp"//sshiftintlist))del("tmp"//sshiftintlist,ver-) list="" list=sshiftexactlist # Convert old shifts to new while (fscan (list,xold,yold) != EOF) { xnew=mag*xold ynew=mag*yold print (xnew, ynew, >> "tmp"//sshiftintlist) } # Round off to integer shifts (in units of new pixels, natch). filecalc("tmp"//sshiftintlist,"$1;$2",format="%4.0f %4.0f", >> sshiftintlist) del("tmp"//sshiftintlist,ver-) # If output subpixel shifts file does exist, just print warning } else { if(sshiftintlist==sshiftexactlist//blk)print("WARNING! "//sshiftintlist//" already exists; not overwritten") } # Correction of zero offsets for lower flux/pixel in blkrep'd images, if needed if(!sspscale) { # Zero offsets from list if(checkzero=="@") { if(!access(zzeroname//blk)) { filecalc(zzeroname,"$1/"//mag2,format="%9.7f", >> zzeroname//blk) newzzeroname=zzeroname//blk zzeroname=newzzeroname zzeroing="@"//newzzeroname } } # Zero offsets from header keyword if(checkzero=="!"){ oldzs=mktemp("oz") newzs=mktemp("nz") hsel("@"//ccomblist1,wwordzero,yes, >> oldzs) filecalc(oldzs,"$1/"//mag2,format="%9.7f", >> newzs) join(ccomblist2,oldzs,output=newzs) list="" list=newzs while (fscan (list,img,levelzero) != EOF) { hedit(img,wwordzero,levelzero,add+,ver-,show-,update+) } del(oldzs,ver-) del(newzs,ver-) } } # End of subpixel shift option } list="" # INSERT NEW ZERO OFFSETS INTO REPLICATED IMAGE HEADERS IF DESIRED. if(access(ccomblist2) && checkzero=="@"){ if(pputzero) { if(!sspscale && access(zzeroname//blk))zzeroname=zzeroname//blk del("_tmp.zzeroing",ver-,>&"dev$null") join(ccomblist2,zzeroname,out="_tmp.zzeroing") list="_tmp.zzeroing" while (fscan (list, img, zf) !=EOF) { hedit(img,wwordzero,zf,add+,ver-,show-,update+) } del("_tmp.zzeroing",ver-,>&"dev$null") } } list="" # PRE-ZEROING: INCORPORATE ZERO OFFSETS BEFORE IMCOMBINE IF DESIRED if(pprezero){ print("===> Doing zero offsetting prior to imcombine...") # Prevent imcombine from zeroing twice zzeroing="none" # If list of images to coadd doesn't exist, create it! if (!access(ccomblist2))copy(ccomblist1,ccomblist2,ver-) # In case of zero offsets taken from header keyword, make file_of_zeros if(checkzero=="!"){ file_of_zeros=mktemp("foz") hsel("@"//ccomblist2,wwordzero,yes, >> file_of_zeros) } if(checkzero=="@")file_of_zeros=zzeroname list_of_zeros=mktemp("loz") join(ccomblist2,file_of_zeros,output=list_of_zeros) if(checkzero=="!")del(file_of_zeros,ver-) # If stacking, and image already exists, do not bother if(sstack && (access(sstackimage//".imh") || access(sstackimage//".fits") || access (sstackimage//".fit") || access(sstackimage//".hhh"))){ print("Not bothering to pre-zero... stacked image already exists.") } else { # Do zero offsetting unless it has already been done list=list_of_zeros while (fscan (list,img,levelzero) != EOF) { imgets(img,"PREZERO",>&"dev$null") if(imgets.value=="0"){ imar(img,"+",levelzero,img,pixt="real",calc="real",ver-) hedit(img,"PREZERO",levelzero,add+,ve-,sho-,updat+,>&"dev$null") } else { print("No action -- image "//img//" already zero-offset by "//imgets.value) } } } } list="" # COADD images # If output coadded image doesn't exist, create it! if (!access(ooutimage//"."//oextimage)){ # If list of images to coadd doesn't exist, create it! if (!access(ccomblist2))copy(ccomblist1,ccomblist2,ver-) if (sstack){ # If output stacked image doesn't exist, create it! if (!access(sstackimage//"."//oextimage)){ print("===) Stacking the images...") imstack("@"//ccomblist2,sstackimage,title="Stacked images listed in "//ccomblist2) } if(nnewmask) { hedit(sstackimage,"BPM",bbadmask,add+,ver-,show-,update+) hedit(sstackimage,"BPMASK",bbadmask,add+,ver-,show-,update+) } print("===) Combining the images...") if (makeavg){ imcombine(sstackimage, ooutimage, sigma=s_sigma, plfile=s_plfile, combine="average", reject="none", project+, offsets=sshiftintlist, masktype=s_masktyp, maskvalue=s_maskval, blank=s_blank, scale=sscaling, zero=zzeroing, weight=wweighting, statsec=s_statsec, expname=s_expname, lthresh=s_lthresh, hthresh=s_hthresh, nlow=s_nlow, nhigh=s_nhigh, nkeep=s_nkeep, mclip+, lsigma=s_lsigma, hsigma=s_hsigma, rdnoise=s_rdnoise, gain=s_gain, sigscale=s_sigscale, pclip=s_pclip, grow=s_grow, logfile='STDOUT', >> llogfile) } else{ if (stdpars) { imcombine(sstackimage, ooutimage, sigma="", plfile="", combine="average", reject="sigclip", project+, offsets=sshiftintlist, masktype=s_masktyp, maskvalue=s_maskval, blank=0., scale=sscaling, zero=zzeroing, weight=wweighting, statsec="", expname=eexpname, lthresh=-100000., hthresh=100000, nlow=1., nhigh=1., nkeep=1., mclip+, lsigma=5., hsigma=5., rdnoise=s_rdnoise, gain=s_gain, sigscale=s_sigscale, pclip=-0.5, grow=0., logfile='STDOUT', >> llogfile) } else { imcombine(sstackimage, ooutimage, sigma=s_sigma, plfile=s_plfile, combine=s_combine, reject=s_reject, project+, offsets=sshiftintlist, masktype=s_masktyp, maskvalue=s_maskval, blank=s_blank, scale=sscaling, zero=zzeroing, weight=wweighting, statsec=s_statsec, expname=s_expname, lthresh=s_lthresh, hthresh=s_hthresh, nlow=s_nlow, nhigh=s_nhigh, nkeep=s_nkeep, mclip+, lsigma=s_lsigma, hsigma=s_hsigma, rdnoise=s_rdnoise, gain=s_gain, sigscale=s_sigscale, pclip=s_pclip, grow=s_grow, logfile='STDOUT', >> llogfile) } } # Stacked images only: compute correct UNWEIGHTED average exposure time del("tmp_"//ccomblist2,ver-,>&"dev$null") hsel ("@"//ccomblist2,eexpname,yes, >> "tmp_"//ccomblist2) type ("tmp_"//ccomblist2) | average (opt="new_sample") | scan (eexptime,p,b) hedit(ooutimage,eexpname,eexptime,add+,ver-,show-,update+) del("tmp_"//ccomblist2,ver-,>&"dev$null") # if(uunstack)imdel(sstackimage,ver-) } else{ if(nnewmask) { list=ccomblist2 while (fscan (list, img) !=EOF) { imgets(img,"BPMASK",>&"dev$null") if(imgets.value=="0") { imgets(img,"BPM",>&"dev$null") hedit(img,"BPMASK",imgets.value,add+,ver-,show-,update+) hedit(img,"BPM",bbadmask,add+,ver-,show-,update+) } else { hedit(img,"BPM",bbadmask,add+,ver-,show-,update+) } } } print("===) Combining the images...") if (makeavg){ imcombine("@"//ccomblist2, ooutimage, sigma=s_sigma, plfile=s_plfile, combine="average", reject="none", project-, offsets=sshiftintlist, masktype=s_masktyp, maskvalue=s_maskval, blank=s_blank, scale=sscaling, zero=zzeroing, weight=wweighting, statsec=s_statsec, expname=s_expname, lthresh=s_lthresh, hthresh=s_hthresh, nlow=s_nlow, nhigh=s_nhigh, nkeep=s_nkeep, mclip+, lsigma=s_lsigma, hsigma=s_hsigma, rdnoise=s_rdnoise, gain=s_gain, sigscale=s_sigscale, pclip=s_pclip, grow=s_grow, logfile='STDOUT', >> llogfile) } else{ if (stdpars) { imcombine("@"//ccomblist2, ooutimage, sigma="", plfile="", combine="average", reject="sigclip", project-, offsets=sshiftintlist, masktype=s_masktyp, maskvalue=s_maskval, blank=0., scale=sscaling, zero=zzeroing, weight=wweighting, statsec="", expname=eexpname, lthresh=-100000., hthresh=100000, nlow=1., nhigh=1., nkeep=1., mclip+, lsigma=5., hsigma=5., rdnoise=s_rdnoise, gain=s_gain, sigscale=0.1, pclip=-0.5, grow=0., logfile='STDOUT', >> llogfile) } else { imcombine("@"//ccomblist2, ooutimage, sigma=s_sigma, plfile=s_plfile, combine=s_combine, reject=s_reject, project-, offsets=sshiftintlist, masktype=s_masktyp, maskvalue=s_maskval, blank=s_blank, scale=sscaling, zero=zzeroing, weight=wweighting, statsec=s_statsec, expname=s_expname, lthresh=s_lthresh, hthresh=s_hthresh, nlow=s_nlow, nhigh=s_nhigh, nkeep=s_nkeep, mclip+, lsigma=s_lsigma, hsigma=s_hsigma, rdnoise=s_rdnoise, gain=s_gain, sigscale=s_sigscale, pclip=s_pclip, grow=s_grow, logfile='STDOUT', >> llogfile) } } } list="" # Put original BPM back if necessary if(nnewmask) { list=ccomblist2 while (fscan (list, img) !=EOF) { imgets(img,"BPMASK",>&"dev$null") hedit(img,"BPM",imgets.value,add+,ver-,show-,update+) } } list="" # Header parameters for the coadded image hedit(ooutimage,"title","Coadded image from "//ccomblist2//" and "//sshiftintlist,ver-,show-,update+) #time | scan (theadline) del ("_5oogDaTe", ver-, >& "dev$null") !date > _5oogDaTe type ("_5oogDaTe") | scan (theadline) del ("_5oogDaTe", ver-, >& "dev$null") addcomment (ooutimage,"phiirs.ircoadd: "//theadline,ver-) addcomment(ooutimage,"Coadded from "//ccomblist2//" and "//sshiftintlist,ver-) addcomment(ooutimage,"makeavg="/makeavg//", stpars="/stdpars//", zero="//zzeroing,ver-) addcomment(ooutimage,"scale="/sscaling//", and weight="//wweighting,ver-) # AIRMASS # Set airmass of coadded image to effective airmass if default scaling !used if(!ddefscale){ imgets(ooutimage,"airmass",>&"dev$null") if ((imgets.value)!="0") { del("_airmass.tmp?",ver-,>&"dev$null") hsel("@"//ccomblist2, "airmass", yes, >> "_airmass.tmp1") type("_airmass.tmp1" | average opt="new_sample", >> "_airmass.tmp2") effairmass=real(average.mean) hedit(ooutimage,"airmass",(effairmass),add+,ver-,show-,update+) del("_airmass.tmp?",ver-,>&"dev$null") } # Set airmass of coadded image to reference airmass if default scaling was used } else { hedit(ooutimage,"airmass",(aairzero),add+,ver-,show-,update+) } # EXPOSURE NORMALIZATION -- normalize coadded image to total exposure time. # If weighting was done w/a stacked image, first find correct WEIGHTED exptime del ("_exptime.tmp?", ver-, >& "dev$null") if(sstack && wweighting!="none"){ # First get individual image exposure times del ("_exptime.tmp?", ver-, >& "dev$null") hsel("@"//ccomblist2,eexpname,yes, >> "_exptime.tmp1") # Join individual image exptimes with weights join("_exptime.tmp1", wweightname, output="_exptime.tmp3") # Calculate individual image weighted exposure times filecalc ("_exptime.tmp3", "$1*$2", calctype="real", >> "_exptime.tmp4") # Calculate correct weighted exposure time type ("_exptime.tmp4" | average opt="new_sample",>> "_exptime.tmp5") # Insert correct weighted exposure time into image header hedit(ooutimage,eexpname,average.sum,add+,ver-,show-,update+) } # First find total exposure time of input images hsel("@"//ccomblist2,eexpname,yes, >> "_exptime.tmp6") type("_exptime.tmp6" | average opt="new_sample", >> "_exptime.tmp7") del ("_exptime.tmp?", ver-, >& "dev$null") unwt_avg_exptime=real(average.mean) eexptime=real(average.sum) # Get output exposure time of coadded image imgets(ooutimage,eexpname) wt_avg_exptime=real(imgets.value) # Insert total exposure time into coadded image header hedit(ooutimage,eexpname,eexptime,add+,ver-,show-,update+) # Multiply coadded image by (total_exposure_time/output_exposure_time) imar(ooutimage, "*", eexptime/wt_avg_exptime, ooutimage) print("", >> llogfile) print("Coadded image multiplied by "//eexptime/wt_avg_exptime//" to bring its flux", >> llogfile) print("in line with the total exposure time of "//eexptime//" s.", >> llogfile) hedit(ooutimage,"bpm","",add-,del+,ver-,show-,update+) hedit(ooutimage,"bpmask","",add-,del+,ver-,show-,update+) hedit(ooutimage,"objmask","",add-,del+,ver-,show-,update+) # FLIP image over to correct orientation if necessary (N is up, E is left) if(flip){ imcopy(ooutimage//"[-*,*]", ooutimage, ver-) addcomment(ooutimage,"Image has been flipped L-R from orig. orientation",ver-) print("WARNING! Image has been flipped L-R! (i.e. imcopy orig[-*,*] new)") } } else { print("Output coadded image already exists-- coadding not done.") print("Output coadded image already exists-- coadding not done.", >> llogfile) } # UNDO PRE-ZEROING: if zeroing was done before imcombine, undo it if desired if(pprezero && uunzero){ # If block-replication was done, skip step if those images are to be deleted if(mag!=1 && ccleanup && !noappend){ print("", >> llogfile) } else { print("===> Undoing zero offsetting...") list=list_of_zeros while (fscan (list,img,levelzero) != EOF) { imgets(img,"PREZERO",>&"dev$null") if(imgets.value!="0"){ tmpzero=real(imgets.value) imar(img,"-",tmpzero,img,pixt="real",calc="real",ver-) hedit(img,"PREZERO","",add-,del+,ver-,show-,updat+,>&"dev$null") } else { print("No action -- "//img//" not pre-zeroed in the first place!") } } } } if(pprezero){ if(sstack && access(sstackimage//"."//oextimage)){print("", >> llogfile)} else{del(list_of_zeros,ver-,>&"dev$null")} } list="" # UNDO PRE-SCALING: if scaling was done before imcombine, undo it if desired if(pprescale && uunscale){ # If block-replication was done, skip step if those images are to be deleted if(mag!=1 && ccleanup && !noappend){ print("", >> llogfile) } else { print("===> Undoing scaling factors...") list=list_of_scales while (fscan (list,img,sf) != EOF) { imgets(img,"PREZERO",>&"dev$null") if(imgets.value!="0"){ print("WARNING! "//img//" still pre-scaled: pre-zeroing not undone first") } else { imgets(img,"PRESCALE",>&"dev$null") if(imgets.value!="0"){ imar(img,"/",sf,img,pixt="real",calct="real",ver-) hedit(img,"PRESCALE","",add-,del+,ver-,sho-,updat+,>&"dev$null") if(ddefscale){ imgets(img,"AIRMOLD",>&"dev$null") hedit(img,"AIRMASS",imgets.value,add+,del-,ver-,sho-,updat+,>&"dev$null") hedit(img,"AIRMOLD","",add-,del+,ver-,sho-,updat+,>&"dev$null") } } else { print("No action -- "//img//" not pre-scaled in the first place!") } } } } } if(pprescale)del(list_of_scales,ver-,>&"dev$null") list="" # EXPOSURE MAPS # Create exposure maps if the output coadded-image exposure map does not exist. # Routine allows for images of different exposure times, sizes, and BPMs, while # creating as few images as possible consistent with meeting those criteria. explist="" if(!access(eexpmap//"."//oextimage)){ # Don't recreate exposure maps to be stacked if stacked expmap image exists if (!access(ccomblist2))copy(ccomblist1,ccomblist2,ver-) if(!sstack || (sstack && !access("exp"//sstackimage//"."//oextimage))) { print("===) Creating exposure maps...") subimgold="_oops" testold=0. test1old=0 test2old=0 expmaskold="" tplimgold="" # If list of images to coadd doesn't exist, create it! # if (!access(ccomblist2))copy(ccomblist1,ccomblist2,ver-) list=ccomblist2 explist=ccomblist2//"exp" if(access(explist))del(explist,ver-,>&"dev$null") while (fscan (list, img) !=EOF) { # get image parameters: xsize, ysize, exptime, badpixelmask fileroot(img,validim+) imgets(img,"i_naxis1") test1=int(imgets.value) imgets(img,"i_naxis2") test2=int(imgets.value) imgets(img,eexpname) exposure=real(imgets.value) imgets(img,"BPMASK") expmask=str(imgets.value) imgets(img,"TPLIMG",>&"dev$null") tplimg=str(imgets.value) # if any of those parameters differ from the previous image, need to create a # new exposure map for eventual coadding. if(test1!=test1old || test2!=test2old || exposure!=testold || expmask!=expmaskold || tplimg!=tplimgold) { subimg = mktemp(fileroot.root) print (subimg, >> explist) # tpl if(ttpl && access(tplimg)) { tpltmp=mktemp("tpltmp") imgets(tplimg,"i_naxis1") tpl1=int(imgets.value) imgets(tplimg,"i_naxis2") tpl2=int(imgets.value) # if tpl image is not same size as actual image, assume the image has been # copied to subsection of bigger image starting at (1,1), and that the rest of # the image is -99999 (thus no imar(img,"-",img,subimg) needed. (ie 61"+90") if(tpl1!=test1 || tpl2!=test2) { imcopy(img,subimg,ver-) imcalc(tplimg, tpltmp, str(exposure)//"/im1**2.", ver-) imcopy(tpltmp, subimg//"[1:"//str(tpl1)//",1:"//str(tpl2)//"]", ver-) imdel(tpltmp, ver-) } else { imcalc(img//","//tplimg,subimg,"(im1-im1)+"//str(exposure)//"/im2**2.",ver-) } # no tpl } else { imcopy(img,subimg,ver-) imreplace(subimg,exposure,lower=-10000.,upper=INDEF) } if(nnewmask)hedit(subimg,"BPM",bbadmask,add+,ver-,show-,update+) test1old=test1 test2old=test2 tplimgold=tplimg testold=exposure expmaskold=expmask subimgold=subimg } else { print (subimgold, >> explist) } } } # Create coadded-image exposure map print("===> Creating coadded-image exposure map...") if(sstack) { if(!access("exp"//sstackimage//"."//oextimage)) { print("===> Stacking exposure maps...") imstack("@"//explist,"exp"//sstackimage,title="Stacked exposure maps listed in "//explist) } else { print("Stacked exposure map image already exists-- not overwritten.") } if(nnewmask) { hedit("exp"//sstackimage,"BPM",bbadmask,add+,ver-,show-,update+) } imcombine("exp"//sstackimage, "junk"//eexpmap, sigma="", plfile=eexpmap//"pl", combine="average", reject="none", project+, offsets=sshiftintlist, masktype=s_masktyp, maskvalue=s_maskval, blank=s_blank, scale="none", zero="none", weight=wweighting, statsec=s_statsec, expname=s_expname, lthresh=s_lthresh, hthresh=s_hthresh, nlow=s_nlow, nhigh=s_nhigh, nkeep=s_nkeep, mclip+, lsigma=s_lsigma, hsigma=s_hsigma, rdnoise=s_rdnoise, gain=s_gain, sigscale=s_sigscale, pclip=s_pclip, grow=s_grow, logfile='STDOUT', >> llogfile) if(uunstack)imdel("exp"//sstackimage,ver-) } else { imcombine("@"//explist, "junk"//eexpmap, sigma="", plfile=eexpmap//"pl", combine="average", reject="none", project-, offsets=sshiftintlist, masktype=s_masktyp, maskvalue=s_maskval, blank=s_blank, scale=sscaling, zero="none", weight=wweighting, statsec=s_statsec, expname=s_expname, lthresh=s_lthresh, hthresh=s_hthresh, nlow=s_nlow, nhigh=s_nhigh, nkeep=s_nkeep, mclip+, lsigma=s_lsigma, hsigma=s_hsigma, rdnoise=s_rdnoise, gain=s_gain, sigscale=s_sigscale, pclip=s_pclip, grow=s_grow, logfile='STDOUT', >> llogfile) } imgets("junk"//eexpmap,"ncombine") nncombine=int(imgets.value) if(explist!=""){ imdel("@"//explist, ver-, >& "dev$null") del(explist, ver-, >& "dev$null") } # Find some numbers needed for accurate exposure map calculation # If unweighted average exposure time has not been calculated, calculate it del ("_exptime.tmp?", ver-, >& "dev$null") if(unwt_avg_exptime==-1.){ hsel("@"//ccomblist2,eexpname,yes, >> "_exptime.tmp6") type("_exptime.tmp6" | average opt="new_sample", >> "_exptime.tmp7") unwt_avg_exptime=real(average.mean) } # If weighting was used... if(wweighting!="none"){ # ...and the weighted avg. exposure time was not found earlier... if(wt_avg_exptime==-1.){ # ...then find it. First get individual image exposure times. del ("_exptime.tmp?", ver-, >& "dev$null") hsel("@"//ccomblist2,eexpname,yes, >> "_exptime.tmp1") # Take weights from header keyword... if(checkweight=="!"){ hsel("@"//ccomblist2,wwordweight,yes, >> "_exptime.tmp2") } # ...or specified file... if(checkweight=="@"){ copy(wweightname, "_exptime.tmp2", ver-) } # ...or use default=exptime with a warning... if(checkweight!="@" && checkweight!="!"){ beep print("WARNING! Using default weights = exptime for exposure map.") print("For accuracy with weighting="/wweighting//", you will need") print("to create the exposure map at the same time as the coadded image.") hsel("@"//ccomblist2,eexpname,yes, >> "_exptime.tmp2") } # Join individual image exptimes with weights join("_exptime.tmp1", "_exptime.tmp2", output="_exptime.tmp3") # Calculate individual image weighted exposure times filecalc ("_exptime.tmp3", "$1*$2", calctype="real", >> "_exptime.tmp4") # Calculate correct weighted exposure time type ("_exptime.tmp4" | average opt="new_sample",>> "_exptime.tmp5") wt_avg_exptime=average.sum } # If weighting was not used, weighted avg. exptime is same as avg. exptime } else { wt_avg_exptime=unwt_avg_exptime } del ("_exptime.tmp?", ver-, >& "dev$null") # Following should yield accurate exposure map. To get the actual exposure # time at each pixel, we must multiply the image from the above imcombining, # which gives the average exposure time (in seconds) at each pixel, by the # plfile, which gives the number of images used at each pixel, and by the # overall unweighted exptime divided by the overall weighted exptime. # # Step 1: just to be safe, get rid of any possible negative values imreplace(eexpmap//"pl",0.,lower=INDEF,upper=0.) # Step 2: Since the plfile lists # images *not* used, we subtract total # images if(access(eexpmap//"number."//oextimage))imdel(eexpmap//"number."//oextimage,ver-) imar(eexpmap//"pl","-",nncombine,eexpmap//"number."//oextimage) # Step 3: Then multiplying by -1 gives # of images used (positive quantity) imar(eexpmap//"number."//oextimage,"*",-1.,eexpmap//"number."//oextimage) # Step 4: Then multiplying by the (weighted) average number of seconds at each # pixel, times the overall **unweighted** average number of seconds, # divided by the overall **weighted** average number of seconds, gives # the desired total number of seconds at each pixel. imar(eexpmap//"number."//oextimage,"*","junk"//eexpmap,eexpmap) imar(eexpmap//"."//oextimage,"*",unwt_avg_exptime/wt_avg_exptime,eexpmap//"."//oextimage,pixt="real",calct="real") imdel(eexpmap//"pl.pl",ver-) imdel("junk"//eexpmap, ver-, >& "dev$null") imdel(eexpmap//"number."//oextimage, ver-, >& "dev$null") hedit(eexpmap,"title","Exposure map image for coadded image "//ooutimage,ver-,show-,update+) hedit(eexpmap,"bpm","",add-,del+,ver-,show-,update+) hedit(eexpmap,"bpmask","",add-,del+,ver-,show-,update+) hedit(eexpmap,"objmask","",add-,del+,ver-,show-,update+) if(flip){ imcopy(eexpmap//"[-*,*]", eexpmap, ver-) addcomment(eexpmap,"Image has been flipped L-R from orig. orientation",ver-) } } else{ print("Output exposure map already exists-- new one not created.") print("Output exposure map already exists-- new one not created.", >> llogfile) } # IMSHIFTS FILE # Create *.imshifts file, listing images & offsets used by masklet & photcheck if (!access(ooutimage//".imshifts")) { print("===> Creating output imshifts file...") if (!access(ccomblist2))copy(ccomblist1,ccomblist2,ver-) join(ccomblist2,sshiftintlist,output=ooutimage//".imshifts_tmp") # Find minimum x and y shift values and subtract them from output offsets listimshift=ooutimage//".imshifts_tmp" list="" list=listimshift xmin=100000 ymin=100000 while (fscan (list,img,newx,newy) != EOF) { if (newx < xmin) { xmin = newx } if (newy < ymin) { ymin = newy } } newx=0 newy=0 list="" list=listimshift while (fscan (list,img,oldx,oldy) != EOF) { newx = oldx - xmin newy = oldy - ymin print(img, " ", newx, newy, >> ooutimage//".imshifts") } del(ooutimage//".imshifts_tmp",ver-) } else { print("Output imshifts file already exists-- not overwritten.") print(" ") } # Clean up. if(mag!=1){ if(ccleanup && !noappend){ if(access(bprotlist)){ imdel("@"//bprotlist,ver-,>&"dev$null") del(bprotlist,ver-,>&"dev$null") } if(access(ccomblist2))imdel("@"//ccomblist2,ver-,>&"dev$null") del(ccomblist2,ver-,>&"dev$null") del(sshiftexactlist//blk,ver-,>&"dev$null") del(zzeroname//blk,ver-,>&"dev$null") } } else { del(ccomblist2,ver-,>&"dev$null") } print(ooutimage//", exposure map, and imshifts file have been created.") print("Next task is `mkobjmask' or `photcheck'.") } else { print("WARNING: tasks stsdas.toolbox.imgtools.imcalc, addcomment,") print("filecalc, fileroot, and/or iterstat are not loaded!") print("Please load the appropriate package(s) and restart this task.") } list="" print(" ") if(echog)beep end ./_phiirs.hd0100644000151400000240000000020606645225112012134 0ustar phallgames# Help definitions for the PHIIRS package phiirs men = phiirs.men, hlp = .., sys = phiirs.hlp, pkg = phiirs.hd, src = phiirs.cl ./addcomment.cl0100644000151400000240000000246105754224734012633 0ustar phallgamesprocedure addcomment (image,comment) # Script to append 'COMMENT' cards to the image header. # All existing 'COMMENT' cards are collated and moved to the end of # the header, and the new card is added afterward. # # 930730: created by Mark Dickinson string image {prompt="Image(s) to which to append comment card"} string comment {prompt="Comment"} bool verify {no,prompt="Verify header?"} bool answer {yes,prompt="Update header?",mode="q"} struct *imglist begin string im,com,inlist,headfile,img,check bool setheader if (!verify) setheader = yes im = image com = comment inlist = mktemp("tmp$addc") sections (im,option="fullname",>inlist) imglist = inlist while (fscan(imglist,img) != EOF) { headfile = mktemp("_headerjj") hfix (img,command="!grep -v 'COMMENT =' $fname > "//headfile,update-) hfix (img,command="!grep 'COMMENT =' $fname >> "//headfile,update-) print("COMMENT = '",com,"'",>>headfile) if (verify) { print ("Comment cards currently read:") match ("COMMENT =",headfile,stop-,print+) if (answer) { setheader = yes } else { setheader = no print ("Header will be left unchanged.") } } if (setheader) hfix (img,command="delete $fname ver- ; copy "//headfile//" $fname",update+) delete (headfile,ve-) } delete (inlist,ver-) imglist = "" end ./sigmanorm.cl0100644000151400000240000000367107124507774012521 0ustar phallgames# sigmanorm.cl -- normalize image by the square root of its exposure map # # Renormalizes mosaic image produced by DIMSUM by the square root of # the exposure map to produce an image which should have uniform rms # pixel-to-pixel noise across the entire exposed area. # # 930726: created by Mark Dickinson # 940106: Modified to allow user to specify name of normalization image. # 960328: added addition of header comments to output image # 960405: changed default normimage suffix from "exp" to "em" # **BUG**: will not work if IRAF parameter imtype = "*,inherit" (imcalc bug) procedure sigmanorm(image) string image {prompt="Name of image to renormalize"} string normimage {"",prompt="Normalization image (default is root//em)"} string prefix {"norm", prompt="Prefix for renormalized image"} # bool undo {no,prompt="Undo (invert) normalization step?"} begin string img # equals image string ext # equals extension string nimg # normalization image real maxexp # peak exposure time # Get query parameter. img = image # Strip off filename extension. fileroot (img,validim+) img = fileroot.root ext = fileroot.extension if(ext!="")ext="."//ext # Check to see if normimage is null; if so, exposure map is assumed to be # imageroot//"em"//ext if (normimage == "") { nimg = img//"em"//ext } else { nimg = normimage } # Calculate sqrt of exposure map and multiply into image with normalization # such that the maximum exposure time in the normalization image is 1. minmax(nimg,force+,update-,ver-) maxexp = minmax.maxval imarith(nimg,"/",maxexp,prefix//img//ext,ver-) imfunc(prefix//img,prefix//img,"sqrt",ver-) # if(undo){imarith(img,"/",prefix//img,prefix//img,pix="real",calc="real",ver-,noact-) # }else{ imarith(img,"*",prefix//img,prefix//img,pix="real",calc="real",ver-) if(deftask("addcomment")){ addcomment(prefix//img,"phiirs.sigmanorm:",ver-) addcomment(prefix//img,img//" normalized by "//normimage,ver-) } end ./ircoaddpisces.par0100644000151400000240000000271406720572776013527 0ustar phallgamesi_sigma,s,h,"",,,"IMCOMBINE: Sigma image (optional)" i_plfile,s,h,"",,,"IMCOMBINE: Rejected pixel list image (optional)" i_combine,s,h,"average",average|median,,"IMCOMBINE: Type of combine operation (median|average)" i_reject,s,h,"ccdclip",none|minmax|ccdclip|crreject|sigclip|avsigclip|pclip,,"IMCOMBINE: Type of rejection" i_masktyp,s,h,"badvalue",none|goodvalue|badvalue|goodbits|badbits,,"IMCOMBINE: Mask type" i_maskval,r,h,0.,,,"IMCOMBINE: Mask value" i_blank,r,h,0.,,,"IMCOMBINE: Value if there are no pixels" i_statsec,s,h,"",,,"IMCOMBINE: Image section for computing statistics" i_expname,s,h,"exptime",,,"IMCOMBINE: Image header exposure time keyword" i_lthresh,r,h,-10000.,,,"IMCOMBINE: Lower threshold" i_hthresh,r,h,INDEF,,,"IMCOMBINE: Upper threshold" i_nlow,r,h,1.,0.,,"IMCOMBINE: minmax: Number of low pixels to reject" i_nhigh,r,h,1.,0.,,"IMCOMBINE: minmax: Number of high pixels to reject" i_nkeep,r,h,1.,,,"IMCOMBINE: Minimum to keep (+) or maximum to reject(-)" i_lsigma,r,h,5.,0.,,"IMCOMBINE: Lower sigma clipping factor" i_hsigma,r,h,5.,0.,,"IMCOMBINE: Upper sigma clipping factor" i_rdnoise,s,h,"RDNOISE",,,"IMCOMBINE: ccdclip: CCD readout noise (electrons)" i_gain,s,h,"GAIN",,,"IMCOMBINE: ccdclip: CCD gain (electrons/ADU)" i_sigscale,r,h,0.1,0.,,"IMCOMBINE: Tolerance for sig-clip scaling corrections" i_pclip,r,h,-0.5,,,"IMCOMBINE: pclip: Percentile clipping parameter" i_grow,r,h,0.,,,"IMCOMBINE: Radius (pixels) for 1D neighbor rejection" mode,s,h,"q",,, ./look4m.cl0100644000151400000240000000203305777437337011732 0ustar phallgames#Take a quick look at a field thru difference of 2 offset images #941217: Modified for 4-m use procedure look(rootname,num1,num2,suffix) string rootname {prompt = "EXACT root name of images to difference"} string num1 {prompt = "Running number of first image"} string num2 {prompt = "Running number of second image"} string suffix {prompt = "Suffix of output image (root//suffix)"} bool disp=yes {prompt = "Display image? (yes|no)"} int frame=1 {prompt = "Frame in which to display image"} bool stats=yes {prompt = "Display image statistics? (yes|no)"} begin string root string suff bool sstats root = rootname suff = suffix sstats = stats print ("Creating image "//root//suff//"...") imar (root//num1//".imh","-",root//num2//".imh",root//suff) if(sstats){ print ("Image statistics:") imstat (root//num1//".imh,"//root//num2//".imh,"//root//suff//".imh") #imstat (root//suff//".imh") } if(disp){ print ("Displaying "//root//suff//" ("//num1//" minus "//num2//") in frame "//frame//".") displ (root//suff, frame) } end ./irflat.cl0100644000151400000240000003660007124505047011773 0ustar phallgames# irflat.cl -- flatfield IR images with a running flat # # Calls scripts addcomment, fileroot, iterstat. # # The products of this routine are: # --flatfielded images: *//flatstring # --a file (imagelist//flatstring) which contains the names of those images # --the logfile # --optionally: flatfield images called *//"flatfield"//flatstring.imh # # CHANGES: # 950117: created from irskynew.cl # 950121: added "flatsave" parameter and use of iterstat to determine scaling # 950122: FINAL VERSION REPLACES OLD IRFLAT.CL # -- MAKE ONLY COSMETIC CHANGES HEREAFTER! # 950208: begin adding object-masking ability # 950209: finalized object-masking ability & added header & logfile comments # 950223: fixed problem with objmask/bpmask confusion # 960226: explicit request for logfile name # 971026: changed to allow gain & rdnoise taken from image headers # 990113: now prints range of images used in flattening to the screen # 990114: removed scan of output of "time" task due to problem w/linux # 990317: added tpl option # 990420: added premask and forcescale options # 990513: fixed premask / forcescale bug & streamlined masking procedure # 990521: fixed bug of using "img" where "name" was required, # and of not always deleting "maskmask" # 000528: really fixed bug of not always deleting "maskmask" this time, I think # # **does irflat assume goodval=1 & require minv/imcalc? procedure irflat(imagelist,flatstring,number,objmask,logfile) string imagelist {prompt="List of images to process (do not use an `@')"} string flatstring {"ff",prompt="String to be appended to flattened images"} int number {8,min=2,prompt="TOTAL # of images for each flat (EVEN #s only)"} bool objmask {no,prompt="Use object masking when constructing flats?"} string logfile="" {prompt="Name of log file"} bool premask=yes {prompt="Mask when finding scaling for creating flats?"} bool forcescale=no {prompt="Force recalculation of image scalings?"} bool stdpars=yes {prompt="Use std. imcombine params to create flats?"} bool flatsave=no {prompt="Save individual flatfield images?"} bool same=yes {prompt="Do object masks all have same suffix?",mode="q"} string suffix {prompt="Suffix of object mask",mode="q"} bool tpl=no {prompt="Throughput-correct images after flatfielding?"} string tplname {prompt="FULL Name of throughput correction image"} bool v210=no {prompt="Older version of IRAF w/imcombine bug?"} bool echog {yes,prompt="Beep when task is done?"} pset imflatpars {prompt="Imcombine parameters"} struct *list struct *list2 begin string rrootname, ddark, llogfile, bbadmask, eextension, img, ssuffix, oosuffix string flatlist, flat, flatbase, meanfile, currentflat, base, omask string iimagelist, FlatImageList, fflatstr, check, ttplname, templist, flatdiv string datefile, thedate, ickinfo, name, tempstring, otherstring, tempfile string s_sigma, s_plfile, s_combine, s_reject, s_offsets, s_masktyp, bpmask string s_scale, s_weight, s_statsec, s_expname, s_zero, s_snoise, ext string s_rdnoise, s_gain, maskmask real s_maskval, s_blank, s_lthresh, s_hthresh, s_nlow, s_nhigh, s_nkeep real s_lsigma, s_hsigma, s_pclip, s_grow, s_sigscale real mean, meanbad, nnumber, flatnorm, valmed int sstartno, eendno, i, j, numpix, x, y, z, nnnumber, nf bool zzeroout, ttpl, sstdpars, go, fflatsave, oobjmask, ssame, mmasksave bool force_scale, pre_mask struct datelist iimagelist = imagelist fflatstr = flatstring nnnumber = number nnumber = nnnumber / 2 oobjmask = objmask llogfile = logfile pre_mask = premask force_scale = forcescale sstdpars = stdpars fflatsave = flatsave ttpl = tpl if (ttpl) ttplname=tplname # Imcombine parameters s_plfile = i_plfile s_sigma = i_sigma s_combine = i_combine s_reject = i_reject s_masktyp = i_masktyp s_maskval = i_maskval s_blank = i_blank s_scale = i_scale s_zero = i_zero s_weight = i_weight s_statsec = i_statsec s_expname = i_expname s_lthresh = i_lthresh s_hthresh = i_hthresh s_nlow = i_nlow s_nhigh = i_nhigh s_nkeep = i_nkeep s_lsigma = i_lsigma s_hsigma = i_hsigma s_rdnoise = i_rdnoise s_gain = i_gain s_snoise = i_snoise s_sigscale = i_sigscale s_pclip = i_pclip s_grow = i_grow # The "go" parameter won't let the task run if you haven't loaded the needed # tasks or if you're using IRAF v2.10 and haven't loaded the ccdred package. go=yes if(!deftask("addcomment")) {go=no} if(!deftask("fileroot")) {go=no} if(!deftask("iterstat")) {go=no} if(!defpac("ccdred") && v210) {go=no} if(go) { # Miscellaneous FlatImageList = iimagelist//fflatstr # @file for flat-divided images if(access(FlatImageList))delete(FlatImageList,ver-) count(iimagelist) | scan (nf) if(nnnumber>=nf){ nnnumber=nf - 1 nnumber=nnnumber / 2 print("Number of frames to use for flat is too big! Resetting to "//nnnumber//".") } #Set up log file, appending if it already exists print(" "); print("Let the games begin...") if(llogfile == "") llogfile="log."//iimagelist print("", >> llogfile); print("===> PHIIRS.IRFLAT:", >> llogfile) print("===> Input images from "//iimagelist//" flattened with "//nnnumber//" images total", >> llogfile) print("===> with stdpars="/sstdpars//" and object masking="//oobjmask, >> llogfile) print("", >> llogfile) # Calculate scalings for all frames. If we are using object masking, first # get the name of the object mask from the image header keyword OBJMASK. # If no OBJMASK keyword, find the object mask name and create OBJMASK keyword. # Insert OBJMASK into BPM keyword temporarily, for later use in imcombine. print("===> Calculating scalings and checking for object masks if desired...") list=iimagelist x=0 while (fscan(list,name) !=EOF) { # If (and only if) BPMASK keyword not already in header, put it there imgets(name,"BPMASK",>&"dev$null") if(imgets.value=="0"){ imgets(name,"BPM",>&"dev$null") bpmask=imgets.value hedit(name,"BPMASK",bpmask,add+,del-,ver-,show-,upd+) } else { bpmask=imgets.value } # If doing object masking, get mask name and insert in image header if needed. if(oobjmask){ fileroot(name,validim+) name=fileroot.root # Check if image has object mask already listed in image header imgets(name,"OBJMASK",>&"dev$null") omask=imgets.value # If not, check to see if same suffix is to be used for all images' objmasks. if(omask=="0" && x==0){ print("No object mask listed in header of image "//name//".") ssame=same if(ssame)ssuffix=suffix if(ssame)print("===> Inserting object mask names into image headers...") x+=1 } # Insert the object mask name in the header if necessary if(omask=="0"){ if(ssame){ omask=name//ssuffix//".pl" hedit(name,"OBJMASK",omask,add+,del-,ver-,show-,update+) } else { print("No object mask listed in header of image "//name//".") omask=name//suffix//".pl" hedit(name,"OBJMASK",omask,add+,del-,ver-,show-,update+) } } # Create mask to use in premasking maskmask=mktemp("maskmask") imarith(omask,"*",bpmask,maskmask,divzero=0.,pixtype="real",calctype="real",ver-,noact-) # Put name of mask to use in premasking in header hedit (name,"BPM",maskmask,add+,del-,ver-,show-,update+) hedit (name,"MASKMASK",maskmask,add+,del-,ver-,show-,update+) } else { maskmask=mktemp("maskmask") imcopy(bpmask,maskmask,ver-) hedit (name,"MASKMASK",maskmask,add+,del-,ver-,show-,update+) } # Calculate median of image. if (!forcescale) { imgets (name,"FLATVAL",>&"dev$null") if (imgets.value == "0") force_scale = yes } if (force_scale) { if(pre_mask) { iterstat.nsigrej=5. iterstat.maxiter=10 maskstat(name,maskmask,1.,lower=INDEF,upper=INDEF,iterstat+,ver-,printit-) } else { iterstat(name,nsigrej=5.,maxiter=10,lower=INDEF,upper=INDEF,print-,ver-) } valmed = 1./iterstat.median hedit (name,"FLATVAL",valmed,add+,del-,ver-,show-,update+) } } # Cycle through list of images, making flat for each list = iimagelist while (fscan (list, name) !=EOF) { # Create names for flat image and flat-divided image fileroot(name, validim+) base=fileroot.root ext=fileroot.extension if(ext!="")ext="."//ext flat=base//"flatfield"//fflatstr//ext flatdiv=base//fflatstr//ext # Extract images needed to make flat for each individual image # This next bit is better done as a call to "xlist", but it works so hey. templist = mktemp("templist") grep ("-n", name, iimagelist, >> templist) list2 = templist while (fscan (list2, tempstring) !=EOF) { otherstring=":" x=stridx(otherstring, tempstring) - 1 otherstring=substr(tempstring,1,x) } del(templist, ver-) print(otherstring, >> templist) type(templist) | average >& "dev$null" del(templist, ver-) y=average.sum count(iimagelist, >> templist) list2=templist while (fscan (list2, x, z, tempstring, otherstring) !=EOF) { #if(y>=x-3)y=x-3 if(y>=x-nnumber)y=x-nnumber } del(templist, ver-) if(y<=nnumber+1)y=nnumber+1 x=y-nnumber z=y+nnumber-1 grep ("-v", name, iimagelist, >> templist) tempfile = mktemp("tempfile") fields (templist, 1, lines=x//"-"//z, >> tempfile) del(templist,ver-) # Use this list of images to make the flat print("Flatfielding image "//name//" --> "//flatdiv//" w/other images from "//x//"-"//z+1) if(sstdpars){ if(v210){ combine("@"//tempfile, flat, sigma=s_sigma, delete-, clobber-, plfile=s_plfile, combine="median", reject="ccdclip", outtype="real", project-, offsets="none", masktype="none", maskvalue=s_maskval, blank=0., scale="!FLATVAL", zero="none", weight="none", statsec="", lthresh=-100000, hthresh=100000, nlow=1, nhigh=1, nkeep=1, mclip+, lsigma=3., hsigma=3., rdnoise=s_rdnoise, gain=s_gain, snoise="0.", sigscale=0.1, pclip=-0.5, grow=0.) } else { if(oobjmask){ imcombine("@"//tempfile, flat, sigma=s_sigma, plfile=s_plfile, combine="median", reject="ccdclip", project-, offsets="none", masktype="badvalue", maskvalue=0., blank=0., scale="!FLATVAL", zero="none", weight="none", statsec="", expname=s_expname, lthresh=-100000, hthresh=100000, nlow=1, nhigh=1, nkeep=1, mclip+, lsigma=3, hsigma=3, rdnoise=s_rdnoise, gain=s_gain, snoise="0.", sigscale=0.1, pclip=-0.5, grow=0., logfile='STDOUT', >> llogfile) } else { imcombine("@"//tempfile, flat, sigma=s_sigma, plfile=s_plfile, combine="median", reject="ccdclip", project-, offsets="none", masktype="none", maskvalue=s_maskval, blank=0., scale="!FLATVAL", zero="none", weight="none", statsec="", expname=s_expname, lthresh=-100000, hthresh=100000, nlow=1, nhigh=1, nkeep=1, mclip+, lsigma=3, hsigma=3, rdnoise=s_rdnoise, gain=s_gain, snoise="0.", sigscale=0.1, pclip=-0.5, grow=0., logfile='STDOUT', >> llogfile) } } } else { if(v210){ combine("@"//tempfile, flat, sigma=s_sigma, delete-, clobber-, plfile=s_plfile, combine=s_combine, reject=s_reject, outtype="real", project-, offsets="none", masktype="none", maskvalue=s_maskval, blank=s_blank, scale=s_scale, zero=s_zero, weight=s_weight, statsec=s_statsec, lthresh=s_lthresh, hthresh=s_hthresh, nlow=s_nlow, nhigh=s_nhigh, nkeep=s_nkeep, mclip+, lsigma=s_lsigma, hsigma=s_hsigma, rdnoise=s_rdnoise, gain=s_gain, snoise=s_snoise, sigscale=s_sigscale, pclip=s_pclip, grow=s_grow) } else { if(oobjmask){ imcombine("@"//tempfile, flat, sigma=s_sigma, plfile=s_plfile, combine=s_combine, reject=s_reject, project-, offsets="none", masktype="badvalue", maskvalue=0., blank=s_blank, scale=s_scale, zero=s_zero, weight=s_weight, statsec=s_statsec, expname=s_expname, lthresh=s_lthresh, hthresh=s_hthresh, nlow=s_nlow, nhigh=s_nhigh, nkeep=s_nkeep, mclip+, lsigma=s_lsigma, hsigma=s_hsigma, rdnoise=s_rdnoise, gain=s_gain, snoise=s_snoise, sigscale=s_sigscale, pclip=s_pclip, grow=s_grow, logfile='STDOUT', >> llogfile) } else { imcombine("@"//tempfile, flat, sigma=s_sigma, plfile=s_plfile, combine=s_combine, reject=s_reject, project-, offsets="none", masktype=s_masktyp, maskvalue=s_maskval, blank=s_blank, scale=s_scale, zero=s_zero, weight=s_weight, statsec=s_statsec, expname=s_expname, lthresh=s_lthresh, hthresh=s_hthresh, nlow=s_nlow, nhigh=s_nhigh, nkeep=s_nkeep, mclip+, lsigma=s_lsigma, hsigma=s_hsigma, rdnoise=s_rdnoise, gain=s_gain, snoise=s_snoise, sigscale=s_sigscale, pclip=s_pclip, grow=s_grow, logfile='STDOUT', >> llogfile) } } } del(tempfile,ver-) # Normalize the flat by its iterative mean if(pre_mask){ iterstat.nsigrej=5. iterstat.maxiter=10 maskstat(flat,bpmask,1.,lower=INDEF,upper=INDEF,iterstat+,ver-,printit-) } else { iterstat(flat,nsigrej=5.,maxiter=10,lower=0.001,upper=INDEF,print-,ver-) } flatnorm = iterstat.mean imar(flat, "/", flatnorm, flat, verbose-) # Divide the input image by the Flat imarith(name, "/", flat, flatdiv, verbose-) # Add comment cards to header of flattened image del ("_1oogDaTe", ver-, >& "dev$null") !date > _1oogDaTe type ("_1oogDaTe") | scan (datelist) del ("_1oogDaTe", ver-, >& "dev$null") addcomment (flatdiv,"phiirs.irflat: "//datelist,ver-) addcomment (flatdiv,"Flattened w/"//nnnumber//" images, stdpars="/sstdpars//", objmask="//oobjmask,ver-) # Added flattened image name to output image list and delete flat if desired. print(flatdiv, >> FlatImageList) if(fflatsave) { # Insert title into flat image header hedit (flat, "title", "Flatfield for image "//name//" normalized by "//flatnorm, add+,del-,ver-,show-,update+) print(flat, >> iimagelist//"flatfield"//fflatstr) } else { imdel(flat, ver-) } } # Replace BPM keyword with bad pixel mask if object masking was done, # and delete maskmask in any case list=iimagelist while (fscan (list, name) !=EOF) { fileroot(name, validim+) imgets(name,"MASKMASK",>&"dev$null") maskmask=imgets.value imdel(maskmask,ver-,>&"dev$null") hedit(name,"MASKMASK","",del+,add-,ver-,show-,update+) if(oobjmask){ flatdiv=fileroot.root//fflatstr//ext imgets(name,"BPMASK",>&"dev$null") bpmask=imgets.value hedit(name,"BPM",bpmask,add+,del-,ver-,show-,update+) hedit(flatdiv,"BPM",bpmask,add+,del-,ver-,show-,update+) } } # Do throughput correction if desired. if (ttpl) { print("===> Divide by Throughput Correction") print("===> Divide by Throughput Correction", >> llogfile) list = FlatImageList while (fscan (list, name) !=EOF) { imgets(name,"tplimg",>&"dev$null") if(imgets.value=="0"){ imar(name, "/", ttplname, name, ver-) hedit(name,fields="TPL",value="TPL correction made using image"//ttplname,add+,del-,ver-,up+,sho-) hedit(name,fields="TPLIMG",value=ttplname,add+,del-,ver-,up+,sho-) print(name//" / "//ttplname//" "//name, >> llogfile) } else { print(name//" already throughput-corrected using "//imgets.value, >> llogfile) print(name//" already throughput-corrected using "//imgets.value) } } } print("", >> llogfile) print("===> Flatfielded images listed in "//FlatImageList, >> llogfile) if(fflatsave)print("===> Flatfield images listed in "//iimagelist//"flatfield"//fflatstr, >> llogfile) del ("_2oogDaTe", ver-, >& "dev$null") !date > _2oogDaTe type ("_2oogDaTe") | scan (datelist) del ("_2oogDaTe", ver-, >& "dev$null") print("===> PHIIRS.IRFLAT finished at "//datelist, >> llogfile) print("It is accomplished. Flatfielded images listed in "//FlatImageList//".") if(fflatsave)print("Flatfield images listed in "//iimagelist//"flatfield"//fflatstr//".") print("Next task to run is `irsky'.") } else { print("WARNING: package noao.imred.ccdred and/or other necessary") print("tasks are not loaded! Please load them and restart this task.") } if(echog)beep end ./photscale.awk0100644000151400000240000000563106670306227012664 0ustar phallgames# awk script used by the PHIIRS routine photscale to measure photometric # variations from frame to frame over an observing sequence. This routine # uses the formatted output from PHIIRS routine photcheck + awk script # photcheck.awk as its input. # # The format of that file is one line for each image, with image name and # airmass in cols 1 & 2, and mag,err pairs for each reference star # in odd and even numbered columns thereafter. # # The first line of that input file is considered to be the photometry for the # "reference frame." Magnitudes of stars in each subsequent line are compared # to it, and the average and rms of the magnitude differences is output in both # magnitude and flux form, along with the individual stellar magnitude # differences. Magnitude and error records that are INDEF are ignored. # # originally created 3 August 1993 by Mark Dickinson # modified March 1996 by Pat Hall # { # # Record magnitudes from first line as reference values. # if (NR==1) { ii=0 nn=0 for (i=3;i<=NF;i+=2) { ii+=1 if ($i == "INDEF") { m[ii] = -99.99 v[ii] = -99.99 } else { nn+=1 m[ii] = $i v[ii] = $(i+1)*$(i+1) } } printf ("%26s %7s %7s %6s %7s %6s %2g ",$1,"airmass","delta_m"," err_m","scaling"," err_s",nn) ii=0 for (i=3;i<=NF;i+=2) { ii+=1 if ($i == "INDEF") { printf (" %6s", " INDEF") } else { printf (" %6.3f", m[ii]) } } printf ("\n") # # For all other lines, calculate differences between the star magnitudes and # the reference values, print these out, and calculate the mean and rms of # those differences, then print those out at the end of the line. Stars with # magnitude values = INDEF or with (mag, err) = (0.000, 0.000) caused by too- # bright stars (true mag <= -10.000) are excluded from the mean and rms # calculations. # } else { printf ("%26s %7.4f ",$1,$2) dsum = 0. wsum = 0. nn = 0 ii=0 for (i=3;i<=NF;i+=2) { ii+=1 if (($i != "INDEF" && m[ii] != -99.99) && ($i != "0.000" && m[ii] != 0.000)) { d[ii] = m[ii] - $i vd[ii] = $(i+1)*$(i+1) + v[ii] dsum += d[ii]/vd[ii] wsum += 1./vd[ii] nn += 1 } else { d[ii] = -99.99 } } if (nn > 0) { dmean = dsum / wsum derr = sqrt(1./wsum) # # New mean & error in flux, not magnitude, units # # nmean = exp(log(10.0)*dmean/2.5) # nmean = exp(log(10.0)*dmean/-2.5) nerr = 0.4*log(10.0)*nmean*derr printf ("%7.3f %6.3f %7.3f %6.3f %2g ", dmean, derr, nmean, nerr, nn) } else { printf ("%7s %6s %7s %6s %2g "," INDEF"," INDEF"," INDEF"," INDEF", 0) } ii=0 for (i=3;i<=NF;i+=2) { ii+=1 if ($i != "INDEF" && m[ii] != -99.99) { printf (" %6.3f", d[ii]) } else { printf (" %6s"," INDEF") } } printf ("\n") } } # i column # ii star counter # nn good star counter # m[ii] magref # v[ii] varref # d[ii] magref - mag # vd[ii] varref + var # dsum sum of d[] # wsum sum of vd[] ./makeobjmask.cl0100644000151400000240000002353306414275617013007 0ustar phallgames# makeobjmask.cl -- Create object masks for input images. # # Image is sky subtracted, either using a constant value, or optionally by # median filtering the image on a specified spatial scale and subtracting # filtered image. If the desired filtering scale is large, the user may want # to first subsample the image to a smaller size before filtering in order to # speed up the calculation -- the resulting sky frame is then block replicated # back up to the original image size before subtracting. # # After sky subtraction, a threshold is applied to the image after optional # boxcar smoothing. The threshold may be specified in terms of a number of sky # sigma above the median sky level as measured using iterative sigma rejection, # or as a specified constant number of ADU above the sky level. The resulting # thresholded image is turned into a mask with "sky" set to 0 and "objects" set # to 1. The user may "grow" additional rings of pixels around masked regions # to increase their area. # # Finally, the resulting mask may optionally be recorded in the input image # header keywords BPM and OBJMASK. The user may in fact create a mask from one # input image and add it into the header of another by specifying different # lists for inlist and headlist. # # Calls tasks "fileroot" and "addcomment" # # 950208: renamed makeobjmask. Switched output prefix to suffix. # 950314: adjusted use of "sections" task # 950324: added "invert" option here instead of in mkobjmask.cl # 960226: use `hedit' to give mask a proper title... # 960301: ...but make sure you do it correctly. procedure makeobjmask(inlist) string inlist {prompt="Image(s) to mask"} string suffix {"objmask",prompt="Suffix for mask files."} string headlist="!default" {prompt="Image(s) to which to add BPM cards"} int subsample {1,min=0,prompt="Block averaging factor before median filtering"} int filtsize {15,min=0,prompt="Median filter size for local sky evaluation"} int nsmooth {3,min=0,prompt="Scale for boxcar smothing before thresholding"} string threshtype {"nsigma",enum="nsigma|constant",prompt="Thresholding type: nsigma or constant"} real nsigthresh {2.,prompt="Threshold for masking in sky sigma"} real constthresh {0.,prompt="Constant threshold above sky for masking"} int ngrow {0,min=0,prompt="Width of rings to grow around masked objects"} string statsec {"",prompt="Image region to use for computing sky statistics"} bool checklimits {yes,prompt="Check min and max pix values before filtering?"} real zmin {-32767.,prompt="Minimum data value for fmedian"} real zmax {32767.,prompt="Minimum data value for fmedian"} bool inv {yes,prompt="Invert output mask so objects are zero?"} bool verbose {yes,prompt="Verbose output?"} struct *imglist struct *imglist2 begin string inl,check,inh int nbox,narea int ix,iy real thresh, dmin, dmax, realsize string infile, img, workimg, ext string infile2, img2 string cutsec # Get query parameter. inl = inlist inh = headlist # Check validity of boxcar smoothing scale. if (nsmooth > 0) { if (2*int(nsmooth/2) == nsmooth) { # i.e. if nsmooth is even... print ("ERROR: parameter nsmooth should be set to an odd value.") return } } # Notify user of effective median filter scale. if (subsample > 1 && filtsize > 0) { realsize = subsample * filtsize print ("After subsampling image, effective median filter scale will be ", realsize) } # Size for boxcar smoothing in growing stage. nbox = (2*ngrow + 1) narea = nbox * nbox # Expand input file list. infile = inl check = substr(infile,1,1) if(check=="@") { infile=substr(inl,2,strlen(inl)) } else { infile = mktemp("tmp$makeobjmask") print(inl,>>infile) } imglist = infile # infile = mktemp("tmp$makeobjmask") # sections (inl,option="fullname",>infile) # imglist = infile # If parameter headlist != "", update image headers with bad pixel list. if (headlist != "") { infile2 = headlist check = substr(infile2,1,1) if(check=="@") { infile2=substr(inh,2,strlen(inh)) } else { if(check=="!") { infile2=infile } else { infile2 = mktemp("tmp$makeobjmask") print(inh,>>infile2) } } imglist2 = infile2 # infile2 = mktemp("tmp$makeobjmask") # sections (headlist,option="fullname",>infile2) # imglist2 = infile2 } # Loop through input files. while (fscan(imglist,img) != EOF) { # Strip ".imh" extension off filename if present. fileroot (img,validim+) img = fileroot.root ext = fileroot.extension if (ext!="") ext = "."//ext if (verbose) print (" Working on image ",img,"-------------------------------") if (verbose) print (" Subtracting local sky.") # If filtsize > 0, median filter image to produce local sky, then subtract # that from the image. if (filtsize > 0) { # If subsample > 1, block average input image to smaller size. if (subsample > 1) { if (verbose) print (" Block averaging.") blkavg (img,"_blk_"//img,subsample,subsample,option="average") workimg = "_blk_"//img } else { workimg = img } # First, check limits of data range. Wildly large (positive or negative) data # values will screw up fmedian calculation unless checklimits = yes and zmin # and zmax are set to appropriate values, e.g. zmin=-32768, zmax=32767. # Note that the old fmedian bug which occurred if zmin=hmin and zmax=hmax # has been fixed in IRAF version 2.10.1. if (verbose) print (" Median filtering sky.") if (checklimits) { minmax (workimg,force+,update+,ve-) if (verbose) print(" Data minimum = ",minmax.minval, " maximum = ",minmax.maxval) } if (checklimits && (minmax.minval < zmin || minmax.maxval > zmax)) { if (minmax.minval < zmin) { dmin = zmin } else { dmin = minmax.minval } if (minmax.maxval > zmax) { dmax = zmax } else { dmax = minmax.maxval } if (verbose) print (" Truncating data range ",dmin," to ",dmax) fmedian (workimg,"_fmed_"//workimg,xw=filtsize,yw=filtsize, boundary="nearest",hmin=-32768,hmax=32767, zmin=dmin,zmax=dmax,>&"dev$null") } else { fmedian (workimg,"_fmed_"//workimg,xw=filtsize,yw=filtsize,boundary="nearest", hmin=-32768,hmax=32767,zmin=INDEF,zmax=INDEF,>&"dev$null") } # If we have block averaged, block replicate median filtered image back to original size. if (subsample > 1) { if (verbose) print (" Block reproducing.") blkrep ("_fmed_"//workimg,"_fmed_"//img,subsample,subsample) imgets(img,"i_naxis1") ix = int(imgets.value) imgets(img,"i_naxis2") iy = int(imgets.value) cutsec = "[1:"//ix//",1:"//iy//"]" imcopy ("_fmed_"//img//cutsec,"_fmed_"//img,ver-) } imarith (img,"-","_fmed_"//img,"_mask_"//img) } else { # ...or, just copy the image to a working mask frame. imcopy (img,"_mask_"//img) } # Calculate image statistics to determine median sky level and RMS noise. if (verbose) print (" Computing sky statistics.") iterstat ("_mask_"//img//statsec,verbose=verbose,print=verbose) if (nsmooth > 0) { if (verbose) print (" Smoothing image before thresholding.") boxcar ("_mask_"//img,"_mask_"//img,nsmooth,nsmooth) } # Calculate threshold. if (threshtype == "constant") { thresh = iterstat.median + constthresh } else { thresh = iterstat.median + nsigthresh * iterstat.sigma } if (verbose) print (" Thresholding image at level ",thresh) # Apply threshold to image, setting "objects" to 1 and "sky" to 0. # The order of the imreplace statments must be different if threshold is # greater than or less than 1. if (thresh >= 0.) { imreplace ("_mask_"//img//ext,0.,upper=thresh,lower=INDEF) imreplace ("_mask_"//img//ext,1.,lower=thresh,upper=INDEF) } else if (thresh < 0.) { imreplace ("_mask_"//img//ext,1.,lower=thresh,upper=INDEF) imreplace ("_mask_"//img//ext,0.,upper=thresh,lower=INDEF) } # Copy mask to .pl file. if (verbose) print (" Saving mask as ",img//suffix//".pl") imcopy ("_mask_"//img,img//suffix//".pl",ve-) # If desired, grow rings around masked objects. if (ngrow > 0) { if (verbose) print (" Growing rings around masked objects.") imarith (img//suffix//".pl","*",narea,img//suffix//".pl") boxcar (img//suffix//".pl",img//suffix//".pl",nbox,nbox) imreplace (img//suffix//".pl",1,lower=1,upper=INDEF) } # Invert mask if desired. if(inv){ if (verbose) print (" Inverting mask so objects=zero.") minv(img//suffix//".pl",img//suffix//".pl") } # add title and comment cards to mask hedit(img//suffix//".pl","title","Object Mask for "//img,add+,ver-,show-,updat+) if(deftask("addcomment")){ addcomment(img//suffix//".pl","phiirs.makeobjmask: mask made w/subsample="//subsample,ver-) addcomment(img//suffix//".pl","filtsize="/filtsize//", nsmooth="//nsmooth,ver-) if(threshtype=="nsigma"){ addcomment(img//suffix//".pl","threshtype=nsigma, nsigthresh="//nsigthresh,ver-) } else { addcomment(img//suffix//".pl","threshtype=constant, constthresh="//constthresh,ver-) } addcomment(img//suffix//".pl","ngrow="/ngrow//", statsec="/statsec//", checklimits="//checklimits,ver-) addcomment(img//suffix//".pl","zmin="/zmin//", zmax="/zmax//", inverse="//inv,ver-) } # Record mask name into BPM keyword in image header of files specified # by inlist2. if (headlist != "") { if (fscan(imglist2,img2) != EOF) { if(verbose)print(" Recording pixel mask into header of image ",img2) hedit(img2,"BPM",img//suffix//".pl",add+,ver-,update+,show-) hedit(img2,"OBJMASK",img//suffix//".pl",add+,ver-,update+,show-) } } # Clean up. if (filtsize > 0) { imdelete ("_fmed_"//img//ext,ve-) if (subsample > 1 ) { imdelete ("_blk_"//img//ext,ve-) imdelete ("_fmed_"//workimg//ext,ve-) } } imdelete ("_mask_"//img//ext,ve-) } # delete (infile,ver-) if (headlist != "" && check != "!") delete (infile2,ver-) imglist = "" imglist2 = "" end ./irflat256.par0100644000151400000240000000313506720572777012430 0ustar phallgamesi_plfile,s,h,"",,,"IMCOMBINE: List of pixel list files (optional)" i_sigma,s,h,"",,,"IMCOMBINE: List of sigma images (optional)" i_combine,s,h,"median",,,"IMCOMBINE: Combine operation (median|average)" i_reject,s,h,"ccdclip",,,"IMCOMBINE: Type of rejection" i_offsets,s,h,"none",,,"IMCOMBINE: Input image offsets" i_masktyp,s,h,"badvalue",,,"IMCOMBINE: Mask type" i_maskval,r,h,0.,,,"IMCOMBINE: Mask value" i_blank,r,h,1.,,,"IMCOMBINE: Value if there are no pixels" i_scale,s,h,"!FLATVAL",,,"IMCOMBINE: Image scaling" i_zero,s,h,"none",,,"IMCOMBINE: Image zero point offset" i_weight,s,h,"none",,,"IMCOMBINE: Image weights" i_statsec,s,h,"",,,"IMCOMBINE: Image section for computing statistics" i_expname,s,h,"",,,"IMCOMBINE: Image header exposure time keyword" i_lthresh,r,h,INDEF,,,"IMCOMBINE: Lower threshold" i_hthresh,r,h,INDEF,,,"IMCOMBINE: Upper threshold" i_nlow,r,h,1.,,,"IMCOMBINE: minmax: Number of low pixels to reject" i_nhigh,r,h,1.,,,"IMCOMBINE: minmax: Number of high pixels to reject" i_nkeep,r,h,6.,,,"IMCOMBINE: Minimum to keep (+) or maximum to reject(-)" i_lsigma,r,h,3.,,,"IMCOMBINE: Lower sigma clipping factor" i_hsigma,r,h,3.,,,"IMCOMBINE: Upper sigma clipping factor" i_rdnoise,s,h,73.,,,"IMCOMBINE: ccdclip: CCD readout noise (e-\'s)" i_gain,s,h,15.3,,,"IMCOMBINE: ccdclip: CCD gain (e-\'s/ADU)" i_snoise,s,h,"0.",,,"IMCOMBINE: ccdclip: Sensitivity noise (fraction)" i_sigscale,r,h,0.1,0.,,"IMCOMBINE: Tolerance for sigma-clip scale corrections" i_pclip,r,h,-0.5,,,"IMCOMBINE: pclip: Percentile clipping parameter" i_grow,r,h,0.,,,"IMCOMBINE: Radius (pixels) for 1D neighbor rejection" mode,s,h,"q",,, ./irflatirim.par0100644000151400000240000000313606720572777013055 0ustar phallgamesi_plfile,s,h,"",,,"IMCOMBINE: List of pixel list files (optional)" i_sigma,s,h,"",,,"IMCOMBINE: List of sigma images (optional)" i_combine,s,h,"median",,,"IMCOMBINE: Combine operation (median|average)" i_reject,s,h,"ccdclip",,,"IMCOMBINE: Type of rejection" i_offsets,s,h,"none",,,"IMCOMBINE: Input image offsets" i_masktyp,s,h,"badvalue",,,"IMCOMBINE: Mask type" i_maskval,r,h,0.,,,"IMCOMBINE: Mask value" i_blank,r,h,1.,,,"IMCOMBINE: Value if there are no pixels" i_scale,s,h,"!FLATVAL",,,"IMCOMBINE: Image scaling" i_zero,s,h,"none",,,"IMCOMBINE: Image zero point offset" i_weight,s,h,"none",,,"IMCOMBINE: Image weights" i_statsec,s,h,"",,,"IMCOMBINE: Image section for computing statistics" i_expname,s,h,"",,,"IMCOMBINE: Image header exposure time keyword" i_lthresh,r,h,INDEF,,,"IMCOMBINE: Lower threshold" i_hthresh,r,h,INDEF,,,"IMCOMBINE: Upper threshold" i_nlow,r,h,1.,,,"IMCOMBINE: minmax: Number of low pixels to reject" i_nhigh,r,h,1.,,,"IMCOMBINE: minmax: Number of high pixels to reject" i_nkeep,r,h,6.,,,"IMCOMBINE: Minimum to keep (+) or maximum to reject(-)" i_lsigma,r,h,3.,,,"IMCOMBINE: Lower sigma clipping factor" i_hsigma,r,h,3.,,,"IMCOMBINE: Upper sigma clipping factor" i_rdnoise,s,h,35.,,,"IMCOMBINE: ccdclip: CCD readout noise (e-\'s)" i_gain,s,h,10.46,,,"IMCOMBINE: ccdclip: CCD gain (e-\'s/ADU)" i_snoise,s,h,"0.",,,"IMCOMBINE: ccdclip: Sensitivity noise (fraction)" i_sigscale,r,h,0.1,0.,,"IMCOMBINE: Tolerance for sigma-clip scale corrections" i_pclip,r,h,-0.5,,,"IMCOMBINE: pclip: Percentile clipping parameter" i_grow,r,h,0.,,,"IMCOMBINE: Radius (pixels) for 1D neighbor rejection" mode,s,h,"q",,, ./mkdark.cl0100644000151400000240000000205207114542562011757 0ustar phallgames# mkdark.cl -- make dark image # # 950329: added option for input list # 990202: should now work with any image extension and/or naming convention # 990219: added logfile option # 000521: changed "rej" param in imcombine to "reject" procedure mkdark(rootname,outname,titlestring) string rootname {prompt = "Root name of images to coadd (or @list)"} string outname {prompt = "Name of coadded dark image"} string titlestring {prompt = "Title for coadded dark image"} string logfile="" {prompt = "Logfile for imcombine output"} begin string root, oout, tstring, log_file root = rootname oout = outname tstring = titlestring log_file = logfile if(substr(root,1,1)=="@"){ imcombine (rootname, oout, logfile=log_file, combine="average", reject="minmax", masktyp="none", nlow=1, nhigh=1, scale="none", zero="none", weight="none") } else{ imcombine(root//"*", oout, logfile=log_file, combine="average", reject="minmax", masktyp="none", nlow=1, nhigh=1, scale="none", zero="none", weight="none") } hedit (oout, "title", tstring, add+, ver-, show-, update+) end ./mkflat.cl0100644000151400000240000000635507114542671011777 0ustar phallgames# mkflat.cl -- make domeflats # # calls tasks fileroot, maskstat # # 950329: created # 971026: minor bug re: "ext" fixed # 990611: checks for preexisting images & doesn't recreate them # 000521: changed "rej" param in imcombine to "reject" procedure mkflat(onlist,offlist,outname,titlestring) string onlist {prompt="List of lamp-on flats (do not use an `@')"} string offlist {prompt="List of lamp-off flats (do not use an `@')"} string outname {prompt="Name of output flat image (best include extension)"} string titlestring {prompt = "Title for output flat image"} string logfile {prompt = "Name of log file"} string badmask {prompt = "Bad pixel mask to use with `maskstat'"} real maskval {prompt = "Value for good pixels in bad pixel mask"} real gain {prompt = "Gain of array"} real noise {prompt = "Readnoise of array"} bool echog {yes,prompt="Beep when task is done?"} struct *list begin string ddark, ssuffix, check, base, oonlist, oofflist, llogfile string oout, tstring, off, on, bbadmask, ooutname, ext real ggain, readnoise # array parameters real normval # flatfield normalization value int mmaskval # = maskval bool go # just do it struct theadline # temporary struct for header information oonlist = onlist oofflist = offlist ooutname = outname # ooutname is output image name tstring = titlestring llogfile = logfile bbadmask = badmask mmaskval = maskval ggain = gain readnoise = noise # The "go" parameter won't let the task run if the needed tasks aren't loaded. go=yes if(!deftask("fileroot")) {go=no} if(!deftask("maskstat")) {go=no} if(go) { fileroot(ooutname,validim+) oout = fileroot.root # oout is root of output image name ext = fileroot.extension # ext is extension of output image name if(ext!="")ext="."//ext off=oout//"off"//ext on=oout//"on"//ext if (!imaccess(on)) { print("===> Creating lamp-on image "//on//"...") imcombine ("@"//oonlist, on, combine="average", reject="ccdclip", masktyp="none", lsig=3., hsig=3., scale="mode", zero="none", weight="none", gain=ggain, rdnoise=readnoise, mclip+, logfile="STDOUT", >> llogfile) } else { print("===> lamp-on image "//on//" already exists!") } if (!imaccess(off)) { print("===> Creating lamp-off image "//off//"...") imcombine ("@"//oofflist, off, combine="average", reject="ccdclip", masktyp="none", lsig=3., hsig=3., scale="mode", zero="none", weight="none", gain=ggain, rdnoise=readnoise, mclip+, logfile="STDOUT", >> llogfile) } else { print("===> lamp-off image "//off//" already exists!") } print("===> Subtracting to create image "//ooutname//"...") imar (on, "-", off, ooutname) iterstat.nsigrej=5. iterstat.maxiter=10 maskstat(ooutname,bbadmask,mmaskval,iterstat+,ver-,printit+, >>llogfile) normval=iterstat.mean imar (ooutname, "/", normval, ooutname) hedit (ooutname, "NORMVAL", normval, add+, ver-, show-, update+) hedit (ooutname, "title", tstring, add+, ver-, show-, update+) print(" ") print("===> Domeflat "//ooutname//" created as "//on//"-"//off//",") print("===> then normalized by "//normval//".") } else { print("WARNING: fileroot and/or maskstat tasks are not loaded!") print("Please load them and restart this task.") } if(echog)beep end ./mkobjmask.cl0100644000151400000240000001646607124506242012476 0ustar phallgames# mkobjmask.cl -- script to interactively create object mask # # originally created 11 July 1992 by John S. Ward # 930228: Now excludes zero exposure regions from computation of pixel sigma. # 930726: Modified by MD to call sigmanorm and use makeobjmask.cl. # 950208: Renamed mkobjmask. Various minor adjustments. # 950209: inv parameter: prefer to have masks with objects=0 not 1. # 960301: display object-masked image in interactive mode # 960405: removed "inv" param and added interactive iteration mode # 990224: added areamask bits, changed iterstat to maskstat # 990225: added subtract option and moved things around a bit # 990306: fixed bug of display of normalized image even if interact=no # 990307: prints parameter values during initial makeobjmask step # # Calls scripts makeobjmask, sigmanorm, iterstat, sctv procedure mkobjmask(image,expname) string image {prompt="Image for making mask (best include extension)"} string expname {prompt="Exposure map (default=image//em)"} string suffix="objmask" {prompt="Suffix of output object mask"} string areamask="" {prompt="Exposed area mask (default: create image//mask)"} bool subtract=no {prompt="Subtract average from image before making mask?"} string substring="sub" {prompt="String to append to subtracted image, if made"} string prefix="norm" {prompt="Prefix for temporary normalized image"} int nsmooth {3,min=0,prompt="Boxcar smoothing filter size (ODD values only)"} int subsample {1,min=1,prompt="Subsampling factor before median filtering"} int filtsize {15,min=1,prompt="Filter size for local median sky evaluation"} int ngrow {1,min=0,prompt="Width of rings to grow around masked objects"} bool interact {yes,prompt="Interactively examine normalized image?"} real threshold {prompt="Cutoff point for replacement",mode="q"} bool redo {no,prompt="Redo with different parameters?",mode="q"} int z {0,prompt="Number of image to save (zero to delete all)?",mode="q"} int i_nsmooth {3,min=0,prompt="Boxcar smoothing filter size (ODD values only)",mode="q"} int i_subsample {1,min=1,prompt="Subsampling factor before median filtering",mode="q"} int i_filtsize {15,min=1,prompt="Filter size for local median sky evaluation",mode="q"} int i_ngrow {1,min=0,prompt="Width of rings to grow around masked objects",mode="q"} bool echog {yes,prompt="Beep when task is done?"} begin string img # equals image string ext # equals image extension string eexpname # equals expname string ssuffix # equals suffix string objmask # name of output mask string area_mask # equals areamask string sub_string # equals substring string pprefix # equals prefix real th # equals threshold real recthresh # recommended thresholding value real minval # minimum value in mask image real maxexp # peak exposure time real flagval # flag value bool rredo # iterate mask determination? bool sub_tract # equals subtract int x # number to append to tmp. images; increased by 1 each time int y # dummy number; looped through to delete leftover images at end int zz # dummy variable for `z' bool ook # dummy variable set equal to `ok' to keep loop going or not int nnsmooth, ssubsample, ffiltsize, nngrow # dummy variables # Get query parameters fileroot (image,validim+) img = fileroot.root ext = fileroot.extension if(ext!="")ext="."//ext eexpname = expname if(eexpname=="")eexpname=img//"em" ssuffix = suffix objmask = img//ssuffix area_mask = areamask if(area_mask=="")area_mask=img//"mask.pl" sub_tract = subtract sub_string = substring if (sub_tract && access(img//sub_string)) { print (img//sub_string//" already exists! Using it...") img=img//sub_string sub_tract=no } pprefix = prefix nnsmooth=nsmooth ssubsample=subsample ffiltsize=filtsize nngrow=ngrow # Create area mask if it doesn't already exist if (!access(area_mask)) { print("Creating "//area_mask//"...") imcopy(eexpname,area_mask,ver-) imreplace(area_mask,0.,lower=INDEF,upper=0.01) imreplace(area_mask,1.,lower=0.01,upper=INDEF) } # Subtract masked iterative mean if desired if (sub_tract) { print("Creating "//img//sub_string//"...") imdel (img//sub_string, ver-, >& "dev$null") maskstat(img,area_mask,1.,nsigrej=5.,maxiter=5.,lower=INDEF,upper=INDEF,ver-,iterstat+,print-,addh+) imar(img,"-",iterstat.mean,img//sub_string,calctype="real",ver-,noact-) img=img//sub_string } # Display initial image if (interact) { print ("Displaying image "//img//"...") display(img,1) } # Normalize image to uniform pixel-to-pixel rms using sq.root of exposure map. print ("Normalizing image "//img//" to uniform RMS...") if(!access(pprefix//img//ext))sigmanorm(img,normimage=eexpname,prefix=pprefix) # Find thresholding level print ("Finding thresholding level using maskstat...") maskstat(pprefix//img,area_mask,1.,nsigrej=5.,maxiter=10.,lower=INDEF,upper=INDEF,ver-,iterstat+,print-,addh+) recthresh = 4.5 / nsmooth * iterstat.sigma print ("Recommended thresholding level for mask is ",recthresh) # Allow user to interactively examine (unsmoothed) normalized image to set # threshold for masking. #if (interact) imexamine(pprefix//img,display="display(image='$1',frame=2,zs+)") if (interact) display(pprefix//img,frame=2,zs+) # If interactive, query for final threshold to adopt. # If not interactive, use the default recommended threshold. if (interact) { beep threshold = recthresh th = threshold } else { th = recthresh } # Apply thresholding to image using makeobjmask. print ("Creating mask with nsmooth="/nsmooth//", subsample="/subsample//", filtsize="/filtsize//", ngrow="//ngrow) makeobjmask (pprefix//img,suffix=ssuffix,headlist="",subsample=subsample,filtsize=filtsize,nsmooth=nsmooth,threshtype="constant",constthresh=th,ngrow=ngrow,statsec="",checklimits+,inv+,ver-) imrename (pprefix//img//ssuffix//".pl",objmask//".pl",ver-) # Display original image and mask if interact=yes. if (interact) { sctv(objmask//".pl",3) imarith(img,"*",objmask//".pl","del_"//img) display("del_"//img,4) imdel("del_"//img,ver-) # Allow iteration if desired. x=2 beep rredo=redo while(rredo){ if(x==2){ imren(objmask//".pl",pprefix//img//ssuffix//"_1.pl",ver-) if (!access(objmask//"orig.pl")) imcopy (pprefix//img//ssuffix//"_1.pl",objmask//"orig.pl",ver-, >& "dev$null") } print("Recommended thresholding level for mask is ",recthresh) th = threshold nnsmooth=i_nsmooth ssubsample=i_subsample ffiltsize=i_filtsize nngrow=i_ngrow makeobjmask (pprefix//img,suffix=ssuffix//"_"//str(x),headlist="",subsample=ssubsample,filtsize=ffiltsize,nsmooth=nnsmooth,threshtype="constant",constthresh=th,ngrow=nngrow,statsec="",checklimits+,inv+,ver-) sctv(pprefix//img//ssuffix//"_"//str(x)//".pl",3) imar(img,"*",pprefix//img//ssuffix//"_"//str(x)//".pl","del_"//img) display("del_"//img,4) imdel("del_"//img,ver-) # Another iteration? beep rredo=redo x+=1 } } # CLEAN UP zz=1 if(interact)zz=z if(zz!=0){ imren(pprefix//img//ssuffix//"_"//str(zz)//".pl",objmask//".pl",ver-, >& "dev$null") if(access(objmask//"orig.pl")){ print("Object masks "//objmask//".pl & "//objmask//"orig.pl created.") } else { print("Object mask "//objmask//".pl created.") } } else{ print("No images saved.") } y=0 zz=0 if(interact){ while(y& "dev$null") y+=1 } } print("Next task to run is `masklet'.") imdelete (pprefix//img,ver-) if(echog)beep end ./photcomp.cl0100644000151400000240000001626706722257536012364 0ustar phallgames# photcomp -- compare photometry between two images on the same coord system # # Task calls following other tasks: filecalc, fileroot. # # Output: # # refimage//.pcomp//suffix Individual-star & avg. photometry for all images # refimage//.plog//suffix Imexam log for refimage # # 960402: created from irshift2.cl # 990317: fixed to work with V2.11 imexam format # 990524: sort output in x procedure photcomp(refimage,compimage,suffix) string refimage {prompt="Reference image"} string compimage {prompt="Comparison image"} string suffix="1" {prompt="Suffix string for output files"} string reflog="" {prompt="Ref. image imexam log (default=create new one)"} bool center=yes {prompt="Imexamine: center object in aperture?"} bool background=yes {prompt="Imexamine: fit and subtract background?"} real radius=5. {prompt="Imexamine aperture photometry radius"} real buffer=10. {prompt="Imexamine sky buffer"} real width=10. {prompt="Imexamine sky annulus width"} bool another {prompt="Do another comparison image?",mode="q"} bool echog {yes,prompt="Beep when task is done?"} struct *list begin string rrefimage, fflatlist, rrefcoords, bbadmask, rroundname string sshiftlist, coarsefile, ooffname, ssuffix, iintname, ffracname string pprefix, logoffname, sl, sx, img, iinterp, bboundary string ccompimage, stringline1, stringline2, stringline1old, stringline2old string stringline1tmp, stringline2tmp, georefin, geomapin real p, pixscale, stcoordx, stcoordy, nrows, ncols, delx, dely, adelx, adely real xold, yold, xxshiftold, yyshiftold, xshiftnew, yshiftnew, astcoordx real astcoordy, nl, nx, x, y int xref, yref, number, xtmp, ytmp, z bool go, aanother #The "go" parameter won't let the task run if you haven't loaded the ctio pkg. go=yes if(!deftask("filecalc") || (!deftask("fileroot"))) {go=no} if(go) { fileroot (refimage,validim+) rrefimage = fileroot.root fileroot (compimage,validim+) ccompimage = fileroot.root ssuffix = suffix rimexam.center=center rimexam.background=background rimexam.radius=radius rimexam.buffer=buffer rimexam.width=width del("_??g."//rrefimage,ver-,>&"dev$null") del("_??g."//ccompimage,ver-,>&"dev$null") del("_*refcomp",ver-,>&"dev$null") display(ccompimage,2) display(rrefimage,1) if(reflog==""){ print(" ") print("===) Choose an object that appears in both images, find its coordinates") print("===) (type 'a') in frame 1 (the reference image), and repeat with as many") print("===) objects as desired. The imexam output log will be displayed for") print("===> editing when done, in case mistakes were made.") print(" ") imexam(logfile="_log."//rrefimage, keep+) print(" ") print("===> In case mistakes were made, the imexam logfile can now be edited.") vi("_log."//rrefimage) } else { copy(reflog,"_log."//rrefimage,ver-) } print("===> Finding comparison image object fluxes...") del("_pxy",ver-,>&"dev$null") filecalc ("_log."//rrefimage, "$1;$2;2", lines="1-9999", format="%8.2f %8.2f %1d", calctype="real", >> "_pxy") imexam (ccompimage, defkey="a", imagecur="_pxy", keeplog+, logfile="_log."//ccompimage) print("===> Finding percentage differences (reference-comparison)/reference...") filecalc ("_log."//rrefimage, "$7", lines="1-9999", calctype="real", >> "_mag."//rrefimage) filecalc ("_log."//ccompimage, "$7", lines="1-9999", calctype="real", >> "_mag."//ccompimage) join("_mag."//rrefimage//",_mag."//ccompimage//",_pxy", out="_mag.refcomp") print("#", >> "_temp.refcomp") print("# Col. 1. X position", >> "_temp.refcomp") print("# Col. 2. Y position", >> "_temp.refcomp") print("# Col. 3. "//rrefimage//" flux", >> "_temp.refcomp") print("# Col. 4. "//ccompimage//" flux", >> "_temp.refcomp") print("# Col. 5. % difference ("//rrefimage//"-"//ccompimage//")/"//rrefimage, >> "_temp.refcomp") # filecalc ("_mag.refcomp", "$3;$4;$1;$2;($1-$2)/$1", lines="1-9999", format="%8.2f %8.2f %10.4f %10.4f %10.6f", calctype="real", >> "_temp.refcomp") filecalc ("_mag.refcomp", "$3;$4;$1;$2;($1-$2)/$1", lines="1-9999", format="%8.2f %8.2f %10.4f %10.4f %10.6f", calctype="real") | sort (col=1, num+, rev-, >> "_temp.refcomp") print("# Output of `average' task: avg rms #_of_pts",>> "_temp.refcomp") fields("_temp.refcomp","5") | average (opt="new_sample", >> "_temp.refcomp") fields("_temp.refcomp","5") | graph (point+,mark="cross",szm=0.005,logx-,logy-) vi ("_temp.refcomp") fields("_temp.refcomp", "5") | average (opt="new_sample") | scan (x,y,z) print("# Output of `average' task: avg rms #_of_pts",>> "_temp.refcomp") fields("_temp.refcomp","5") | average (opt="new_sample", >> "_temp.refcomp") print("Avg. (ref-comp)/ref = "//x//" +- "//y) # Clean up rename("_temp.refcomp", rrefimage//".pcomp"//ssuffix) rename("_log."//rrefimage, rrefimage//".plog"//ssuffix) del("_??g."//ccompimage,ver-,>&"dev$null") del("_*refcomp",ver-,>&"dev$null") #ANOTHER IMAGE? aanother=another while(aanother){ fileroot(compimage) ccompimage=fileroot.root del("_??g."//ccompimage,ver-,>&"dev$null") display(ccompimage,2) print("===> Finding comparison image object fluxes...") imexam (ccompimage, defkey="a", imagecur=coords, keeplog+, logfile="_log."//ccompimage) print("===> Finding percentage differences (reference-comparison)/reference...") filecalc ("_log."//ccompimage, "$4", lines="1-9999", calctype="real", >> "_mag."//ccompimage) join("_mag."//rrefimage//",_mag."//ccompimage//",_pxy", out="_mag.refcomp") print("#", >> "_temp.refcomp") print("# Col. 1. X position", >> "_temp.refcomp") print("# Col. 2. Y position", >> "_temp.refcomp") print("# Col. 3. "//rrefimage//" flux", >> "_temp.refcomp") print("# Col. 4. "//ccompimage//" flux", >> "_temp.refcomp") print("# Col. 5. % difference ("//rrefimage//"-"//ccompimage//")/"//rrefimage, >> "_temp.refcomp") # filecalc ("_mag.refcomp", "$3;$4;$1;$2;($1-$2)/$1", lines="1-9999", format="%8.2f %8.2f %10.4f %10.4f %10.6f", calctype="real", >> "_temp.refcomp") filecalc ("_mag.refcomp", "$3;$4;$1;$2;($1-$2)/$1", lines="1-9999", format="%8.2f %8.2f %10.4f %10.4f %10.6f", calctype="real") | sort (col=1, num+, rev-, >> "_temp.refcomp") print("# Output of `average' task: avg rms #_of_pts", >> "_temp.refcomp") fields("_temp.refcomp","5") | average (opt="new_sample", >> "_temp.refcomp") fields("_temp.refcomp","5") | graph (point+,mark="cross",szm=0.005,logx-,logy-) vi ("_temp.refcomp") fields("_temp.refcomp", "5") | average (opt="new_sample") | scan (x,y,z) print("# Output of `average' task: avg rms #_of_pts",>> "_temp.refcomp") fields("_temp.refcomp","5") | average (opt="new_sample", >> "_temp.refcomp") print("Avg. (ref-comp)/ref = "//x//" +- "//y) # Clean up del("_mag."//ccompimage,ver-,>&"dev$null") del("_??g."//ccompimage,ver-,>&"dev$null") type("_temp.refcomp", >> rrefimage//".pcomp"//ssuffix) del("_*refcomp",ver-,>&"dev$null") # Next comparison image, if desired aanother=another } # Clean up del("_mag."//rrefimage,ver-,>&"dev$null") del("_pxy",ver-,>&"dev$null") print("Files "//rrefimage//".pcomp"//ssuffix//" and "//rrefimage//".plog"//ssuffix//" have been created.") } else { print("WARNING: tasks `ctio.filecalc' and/or `phiirs.fileroot' not loaded!") print("Please load them and restart this task.") } if(echog)beep end ./photscale.cl0100644000151400000240000003356106670313641012501 0ustar phallgames# photscale -- calculate photometric scalings of a data set. # # Originally created by Mark Dickinson. Modified by Pat Hall. # # 960323: created from photdiff.cl # 960325: added normalization option # 960326: truncate output to 161 characters so IRAF can handle it # 960327: fixed bugs relating to 161-char IRAF limit by using awk not IRAF # 960411: added option to just replot old results w/o changing or redoing them # 960716: added option to use aperture corrections if desired # 980429: fixed minor semi-bug: xevaluate r*1. instead of xevaluate r # 980511: fixed minor bug: lines 1 256 instead of lines 1 1000 # 990306: converted to V2.11 1023-character IRAF limit, and added grep stage # to "awk -f photcheck*.awk" to avoid including extraneous junk on chooyu procedure photscale (photfile,prefix,suffix) string photfile {prompt="Photometry data file from photcheck"} string prefix {prompt="Prefix for output file(s)"} string suffix {prompt="Suffix for output file(s)"} bool apcor {no, prompt="Use aperture corrections?"} string apfile {no, prompt="Aperture correction file (coadded image first)"} bool display {yes, prompt="Automatically display lightcurve (needs STSDAS)?"} bool results {no, prompt="Output computed scales and weights?", mode="q"} bool newref {no, prompt="Select new reference image?", mode="q"} int refimagenum {min=1,prompt="Number of new reference image", mode="q"} bool replace {no, prompt="Replace a point with average of others?", mode="q"} int newpoint {min=1,prompt="Image number of point to replace", mode="q"} string avgpoints {prompt="Points to avg. for replacement (enter as `1,2')", mode="q"} string reenter {prompt="Re-enter points (enter as `1,2')", mode="q"} bool normal {no, prompt="Normalize scales to a certain image?", mode="q"} int normimagenum {min=1,prompt="Number of normalization image", mode="q"} bool echog {yes,prompt="Beep when task is done?"} struct *outdat begin string phfile,outp # tmp. working versions of input/output files string phiirsdir # directory containing PHIIRS scripts string igicommands, filename, tmpout, tmpfile, ssuffix, s1, s2, s3 string aavgpoints, tmpstart, tmpmid, tmpend, pphotfile, s4, s5, tmpawk string aapfile real ut, scale, serr, delta, derr, value1, error1, value2, error2 real xmin, xmax, ymin, ymax, valuemag, errormag, error0, value0 real xplotmin, xplotmax, yplotmin, yplotmax real normvalue, normserr, normdelta, normderr int x, y, z, rrefimagenum, nnewpoint, nnormimagenum, point1, point2 bool rresults, nnewref, rreplace, iterate, nnormal, normed, refereed bool justplot, aapcor # Get query parameters. pphotfile = photfile phfile = mktemp(pphotfile) copy(pphotfile,phfile) tmpout = prefix outp = mktemp(tmpout) ssuffix = suffix aapcor = apcor if(aapcor)aapfile=apfile # Check for presence of output files justplot=no if(access(tmpout//".photscales"//ssuffix)){ beep print("Output file "//tmpout//".photscales"//ssuffix//" already exists.") print ("No new files will be created; only plotting will be done.") justplot=yes } # Check for presence of filecalc task (in CTIO package) if(!deftask("filecalc")){ print ("Task `filecalc' is not loaded. Please load and restart task.") return } # Check for presence of the photscale.awk & photscale2.awk scripts in PHIIRS # source code directory. If either are not present, return error message. phiirsdir = osfn("phiirs$") if ((!access(phiirsdir//"photscale.awk")) || (!access(phiirsdir//"photscale2.awk"))) { print ("ERROR: Cannot access "//phiirsdir//"$photscale.awk or photscale2.awk!") return } # MAIN LOOP # Set up loop to allow repeated iterations using different reference images print ("Beginning...") iterate=yes nnewref=no rreplace=no nnormal=no normed=no refereed=no while(iterate){ # NEW REFERENCE IMAGE if(nnewref){ # If new reference image, what image number? refereed=yes rrefimagenum=refimagenum # Get that reference image's data and insert it as the first line w/awk tmpawk=mktemp("tmpawk") tmpfile=mktemp("tmpfile") print ("NR == "//rrefimagenum+1//", NR == "//rrefimagenum+1//" {print $0}", >> tmpawk) awk ("-f",tmpawk,phfile,>> tmpfile) del(tmpawk,ver-) tmpawk=mktemp("tmpawk") print ("NR != 1, NR != 1 {print $0}", >> tmpawk) awk ("-f",tmpawk,phfile,>> tmpfile) del(tmpawk,ver-) # Use awk script to calculate photometric scalings between frames. if(!aapcor){ awk ("-f",phiirsdir//"photscale.awk",tmpfile,>"_tmp."//outp) # If aperture corrections... } else { join(aapfile, tmpfile, maxch=9999, ver-, >> tmpfile//"2") awk ("-f",phiirsdir//"photscale2.awk",tmpfile//"2",>"_tmp."//outp) del(tmpfile//"2", ver-) } # Truncate output to 1021 characters so IRAF can handle it. Lines are formatted # such that no mag,err pair should be cut off in the middle via this truncation tmpawk=mktemp("tmpawk") print ("{print (substr($0,1,1021))}", >> tmpawk) awk ("-f",tmpawk,"_tmp."//outp,> outp) del("_tmp."//outp,ver-) del(tmpawk,ver-) del(phfile,ver-) rename(tmpfile,phfile) } else { # If first time through, calculate photometric scalings between frames. if(!rreplace && !nnormal){ del(outp,ver-,>&"dev$null") if(!aapcor){ # Added grep stage to avoid inclusion of extraneous junk on chooyu # awk ("-f",phiirsdir//"photscale.awk",phfile,>"_tmp."//outp) awk ("-f",phiirsdir//"photscale.awk",phfile) | grep ("-v","\%",>"_tmp."//outp) # If aperture corrections... } else { join(aapfile, phfile, maxch=9999, ver-, >> phfile//"2") # Added grep stage to avoid inclusion of extraneous junk on chooyu # awk ("-f",phiirsdir//"photscale2.awk",phfile//"2",>"_tmp."//outp) awk ("-f",phiirsdir//"photscale2.awk",phfile//"2") | grep ("-v","\%",>"_tmp."//outp) del(phfile//"2", ver-) } # Truncate output to 1021 characters so IRAF can handle it. Lines are formatted # such that no mag,err pair should be cut off in the middle via this truncation tmpawk=mktemp("tmpawk") print ("{print (substr($0,1,1021))}", >> tmpawk) awk ("-f",tmpawk,"_tmp."//outp,> outp) del("_tmp."//outp,ver-) del(tmpawk,ver-) } } # If display==yes, check to see if stsdas.graphics.stplot is loaded, and if # not, load it, then call stsdas.graphics.stplot.igi to display light curve. if (display) { if (!defpac("stsdas")) stsdas if (!defpac("graphics")) graphics if (!defpac("stplot")) stplot xplotmin = 0. xplotmax = 1. ymin = 1.E20 ymax = -1.E20 outdat = outp del("_plot."//outp, ver-, >& "dev$null") # First, scan data values to determine plot limits. Skip first line. if (fscan(outdat,filename) == EOF) error (0,"No lines in file ",outdat) while (fscan(outdat,filename,ut,delta,derr,scale,serr) != EOF) { xplotmax = xplotmax + 1. if(delta!=INDEF && derr!=INDEF){ ymin = min(ymin,delta-derr) ymax = max(ymax,delta+derr) } else { if(delta!=INDEF) { derr=99.999 } else { delta=0. derr=99.999 } } print(filename//" ",ut,delta,derr,scale,serr, >> "_plot."//outp) } yplotmin = ymin - 0.2 * (ymax-ymin) yplotmax = ymax + 0.2 * (ymax-ymin) # Now open temporary file and create igi command macro. igicommands = mktemp("plotdiff") print ("limits ",xplotmin,xplotmax,yplotmin,yplotmax, >igicommands) print ("box", >>igicommands) print ("xlabel image number", >>igicommands) print ("ylabel \gDm: reference - image", >>igicommands) print ("title Relative magnitude differences: ", tmpout//".photscales"//ssuffix, >>igicommands) print ("ltype 1", >>igicommands) print ("relocate ",xplotmin," 0.0 ", >>igicommands) print ("draw ",xplotmax," 0.0 ", >>igicommands) print ("ltype 0", >>igicommands) print ("data _plot."//outp, >>igicommands) # print ("data ",outp, >>igicommands) # print ("lines 2 256 ", >>igicommands) # print ("lines 1 256 ", >>igicommands) print ("xcolumn 2", >>igicommands) print ("xevaluate r*1.", >>igicommands) print ("ycolumn 3", >>igicommands) print ("ecol 4", >>igicommands) print ("ptype 4 0", >>igicommands) print ("points", >>igicommands) print ("error 2", >>igicommands) print ("error 4", >>igicommands) # Execute igi with command macro, exit, then bring up graphics cursor to # allow user to snapshot if desired. igi (initcmd="input "//igicommands//" ; end", >"dev$null") # igi (< igicommands) =gcur delete (igicommands,ver-) delete ("_plot."//outp,ver-,>&"dev$null") } # default: do not iterate, choose new reference image, or replace point(s) iterate=no nnewref=no nnormal=no rreplace=no # New reference image? if(!justplot)nnewref=newref if(nnewref){ iterate=yes } else { # # POINT REPLACEMENT # Replace a point? if(!justplot)rreplace=replace if(rreplace){ iterate=yes # Which point? nnewpoint=newpoint # Replace with average of what two points? (enter as 1,2) aavgpoints=avgpoints #if no , "re-enter (enter as 1,2):" while(stridx(",",aavgpoints)==0){ aavgpoints=reenter } point1=int(substr(aavgpoints,1,stridx(",",aavgpoints)-1)) point2=int(substr(aavgpoints,stridx(",",aavgpoints)+1,strlen(aavgpoints))) # Extract the value of point1 w/awk tmpawk=mktemp("tmpawk") tmpfile=mktemp("tmpfile") print("NR == "//point1+1//", NR == "//point1+1//" {print $0}",>> tmpawk) awk ("-f",tmpawk,outp,>> tmpfile) del(tmpawk,ver-) outdat=tmpfile while(fscan(outdat,filename,ut,delta,derr,scale,serr) != EOF) { value1=scale error1=serr } del(tmpfile,ver-,>&"dev$null") # Extract the value of point2 w/awk tmpawk=mktemp("tmpawk") tmpfile=mktemp("tmpfile") print("NR == "//point2+1//", NR == "//point2+1//" {print $0}",>> tmpawk) awk ("-f",tmpawk,outp,>> tmpfile) del(tmpawk,ver-) outdat=tmpfile while(fscan(outdat,filename,ut,delta,derr,scale,serr) != EOF) { value2=scale error2=serr } del(tmpfile,ver-,>&"dev$null") # Calculate the new point value0=0.5*(value1+value2) error0=sqrt(error1*error1+error2*error2) valuemag=-2.5*log10(value0) errormag=(2.5*error0)/(log(10.0)*value0) # Put in file w/awk, leaving out individ. star dm values to denote replacement tmpawk=mktemp("tmpawk") tmpstart=mktemp("tmpstart") tmpmid=mktemp("tmpmid") tmpend=mktemp("tmpend") tmpfile=mktemp("tmpfile") print("NR == 1, NR == "//nnewpoint//" {print $0}",>> tmpawk) awk ("-f",tmpawk,outp,>> tmpstart) del(tmpawk,ver-) tmpawk=mktemp("tmpawk") print("NR >= "//nnewpoint+2//" {print $0}",>> tmpawk) awk ("-f",tmpawk,outp,>> tmpend) del(tmpawk,ver-) tmpawk=mktemp("tmpawk") print("NR == "//nnewpoint+1//" {print $0}",>> tmpawk) awk ("-f",tmpawk,outp,>> tmpfile) del(tmpawk,ver-) outdat=tmpfile while(fscan(outdat,filename,ut,delta,derr,scale,serr) != EOF) { print(filename//" "//ut//" "//valuemag//" "//errormag//" "//value0//" "//error0, >> tmpmid) } del(outp, ver-) concat(tmpstart//","//tmpmid//","//tmpend, outp) del(tmpfile,ver-,>&"dev$null") del(tmpstart,ver-,>&"dev$null") del(tmpmid,ver-,>&"dev$null") del(tmpend,ver-,>&"dev$null") # End of loop for point replacement } else { # NORMALIZATION # Normalize scales? if(!justplot)nnormal=normal if(nnormal){ normed=yes iterate=yes # Normalize with what image? nnormimagenum=normimagenum # Extract the scaling value of nnormimagenum tmpawk=mktemp("tmpawk") tmpfile=mktemp("tmpfile") print("NR == "//nnormimagenum+1//", NR == "//nnormimagenum+1//" {print $0}",>> tmpawk) awk ("-f",tmpawk,outp,>> tmpfile) del(tmpawk,ver-) outdat=tmpfile while(fscan(outdat,filename,ut,delta,derr,scale,serr) != EOF) { normvalue=scale normdelta=delta } del(tmpfile,ver-,>&"dev$null") # Normalize all scales and errors by scaling value of nnormimagenum if(access(tmpout//".photold"//ssuffix))del(tmpout//".photold"//ssuffix,ver-) rename (outp,tmpout//".photold"//ssuffix) outdat=tmpout//".photold"//ssuffix while(fscan(outdat,s2,s3,delta,derr,scale,serr) != EOF) { # If delta, scale, and error are all defined, print normalized values of all if(delta!=INDEF && scale!=INDEF && serr!=INDEF){ # s1="one" # print(s1,delta,derr,scale,serr) print(s2//" "//s3//" "//delta-normdelta//" "//derr//" "//scale/normvalue//" "//serr/normvalue, >> outp) } else { # s1="two" # print(s1,delta,derr,scale,serr) # Set up strings containing values of delta and derr if(delta==INDEF){s4="INDEF"} else{s4=str(delta-normdelta)} if(derr==INDEF){s5="INDEF"} else{s5=str(derr)} # If only scale error is undefined, print INDEF value for it if(scale!=INDEF){ print(s2//" "//s3//" "//s4//" "//s5//" "//scale/normvalue//" INDEF", >> outp) # If both scale and scale error are undefined, print INDEF value for both } else { print(s2//" "//s3//" "//s4//" "//s5//" INDEF INDEF", >> outp) } } } # End of loop for normalization } # End of loop for no point replacement } # End of loop for no new reference image } # End of loop for a given reference image outdat="" } # Output scales and weights? if(!justplot){ rename(outp,tmpout//".photscales"//ssuffix) if(refereed){rename(phfile,tmpout//".photfile"//ssuffix)} else{del(phfile,ver-)} rresults=results if(rresults){ fields(tmpout//".photscales"//ssuffix, 5, lines="2-10000", >> tmpout//".scales"//ssuffix) filecalc(tmpout//".photscales"//ssuffix, "1/($6*$6)", lines="2-10000", >> tmpout//".weights"//ssuffix) } print("File "//tmpout//".photscales"//ssuffix//" was created") if(rresults){ print("along with "//tmpout//".scales"//ssuffix//" and "//tmpout//".weights"//ssuffix) print("(either or both of which can be used to re-ircoadd the images)") } if(refereed){ print("along with "//tmpout//".photfile"//ssuffix//" (which is a copy of") print(pphotfile//" except with a new reference image)") } if(normed){ print("along with "//tmpout//".photold"//ssuffix//" (which contains pre-normalization") print("scales and individual star magnitude differences)") } } else { del(outp,ver-,>&"dev$null") del(phfile,ver-,>&"dev$null") } if(echog)beep end ./ircoadd256.par0100644000151400000240000000270406542514712012540 0ustar phallgamesi_sigma,s,h,"",,,"IMCOMBINE: Sigma image (optional)" i_plfile,s,h,"",,,"IMCOMBINE: Rejected pixel list image (optional)" i_combine,s,h,"average",average|median,,"IMCOMBINE: Type of combine operation (median|average)" i_reject,s,h,"sigclip",none|minmax|ccdclip|crreject|sigclip|avsigclip|pclip,,"IMCOMBINE: Type of rejection" i_masktyp,s,h,"badvalue",none|goodvalue|badvalue|goodbits|badbits,,"IMCOMBINE: Mask type" i_maskval,r,h,0.,,,"IMCOMBINE: Mask value" i_blank,r,h,0.,,,"IMCOMBINE: Value if there are no pixels" i_statsec,s,h,"",,,"IMCOMBINE: Image section for computing statistics" i_expname,s,h,"exptime",,,"IMCOMBINE: Image header exposure time keyword" i_lthresh,r,h,-10000.,,,"IMCOMBINE: Lower threshold" i_hthresh,r,h,INDEF,,,"IMCOMBINE: Upper threshold" i_nlow,r,h,1.,0.,,"IMCOMBINE: minmax: Number of low pixels to reject" i_nhigh,r,h,1.,0.,,"IMCOMBINE: minmax: Number of high pixels to reject" i_nkeep,r,h,1.,,,"IMCOMBINE: Minimum to keep (+) or maximum to reject(-)" i_lsigma,r,h,5.,0.,,"IMCOMBINE: Lower sigma clipping factor" i_hsigma,r,h,5.,0.,,"IMCOMBINE: Upper sigma clipping factor" i_rdnoise,s,h,73.,,,"IMCOMBINE: ccdclip: CCD readout noise (electrons)" i_gain,s,h,15.3,,,"IMCOMBINE: ccdclip: CCD gain (electrons/ADU)" i_sigscale,r,h,0.1,0.,,"IMCOMBINE: Tolerance for sig-clip scaling corrections" i_pclip,r,h,-0.5,,,"IMCOMBINE: pclip: Percentile clipping parameter" i_grow,r,h,0.,,,"IMCOMBINE: Radius (pixels) for 1D neighbor rejection" mode,s,h,"q",,, ./sctv.cl0100644000151400000240000000233606333714360011471 0ustar phallgamesprocedure sctv(image, frame) # Display an image with display range scaled to full range of image values # # 931123: modified to include more optional display parameters. -- MD # 950216: switch from min,max=0,1 to =min,max in image # 970506: modified to avoid IRAFV2.10 bug with some *.pl and minmax string image {prompt="Mask image to be displayed"} int frame {min=1,max=4,prompt="Frame buffer for image display"} bool fill {no,prompt="Scale image to fit display window?"} real xcenter {0.5,prompt="display window horizontal center"} real ycenter {0.5,prompt="display window vertical center"} real xsize {1.,prompt="display window horizontal size"} real ysize {1.,prompt="display window horizontal size"} real xmag {1.,prompt="display window horizontal magnification"} real ymag {1.,prompt="display window horizontal magnification"} begin real maxv, minv # replaced next line due to bug for *.pl files with large pos or neg values #minmax (image,force+,update-,ver-); maxv=real(minmax.maxval); minv=real(minmax.minval) imstat (image,fields="min,max",format-) | scan (minv,maxv) display (image,frame,zsc-,zra-,z1=minv,z2=maxv,fill=fill,xcenter=xcenter,ycenter=ycenter,xsize=xsize,ysize=ysize,xmag=xmag,ymag=ymag,ztrans="linear",order=0) end ./irflatirtf.par0100644000151400000240000000314506720572777013061 0ustar phallgamesi_plfile,s,h,"",,,"IMCOMBINE: List of pixel list files (optional)" i_sigma,s,h,"",,,"IMCOMBINE: List of sigma images (optional)" i_combine,s,h,"median",,,"IMCOMBINE: Combine operation (median|average)" i_reject,s,h,"ccdclip",,,"IMCOMBINE: Type of rejection" i_offsets,s,h,"none",,,"IMCOMBINE: Input image offsets" i_masktyp,s,h,"badvalue",,,"IMCOMBINE: Mask type" i_maskval,r,h,0.,,,"IMCOMBINE: Mask value" i_blank,r,h,1.,,,"IMCOMBINE: Value if there are no pixels" i_scale,s,h,"!FLATVAL",,,"IMCOMBINE: Image scaling" i_zero,s,h,"none",,,"IMCOMBINE: Image zero point offset" i_weight,s,h,"none",,,"IMCOMBINE: Image weights" i_statsec,s,h,"",,,"IMCOMBINE: Image section for computing statistics" i_expname,s,h,"",,,"IMCOMBINE: Image header exposure time keyword" i_lthresh,r,h,-100000.,,,"IMCOMBINE: Lower threshold" i_hthresh,r,h,100000.,,,"IMCOMBINE: Upper threshold" i_nlow,r,h,1.,,,"IMCOMBINE: minmax: Number of low pixels to reject" i_nhigh,r,h,1.,,,"IMCOMBINE: minmax: Number of high pixels to reject" i_nkeep,r,h,6.,,,"IMCOMBINE: Minimum to keep (+) or maximum to reject(-)" i_lsigma,r,h,3.,,,"IMCOMBINE: Lower sigma clipping factor" i_hsigma,r,h,3.,,,"IMCOMBINE: Upper sigma clipping factor" i_rdnoise,s,h,"rn",,,"IMCOMBINE: ccdclip: CCD readout noise (e-\'s)" i_gain,s,h,"gain",,,"IMCOMBINE: ccdclip: CCD gain (e-\'s/ADU)" i_snoise,s,h,"0.",,,"IMCOMBINE: ccdclip: Sensitivity noise (fraction)" i_sigscale,r,h,0.1,0.,,"IMCOMBINE: Tolerance for sigma-clip scale corrections" i_pclip,r,h,-0.5,,,"IMCOMBINE: pclip: Percentile clipping parameter" i_grow,r,h,0.,,,"IMCOMBINE: Radius (pixels) for 1D neighbor rejection" mode,s,h,"q",,, ./crzap2.cl0100644000151400000240000000620106561402307011704 0ustar phallgamesprocedure crzap2(inlist,outlist) # Cosmic ray cleaning routine using imexam and fixpix # # 970227: created from dimsum.xzap (original courtesy Mark Dickinson) # 980428: rewrote to call fixpix and text2mask from proto or nmisc, # altho nmisc.fixpix is a bit more versatile & would be preferred # # Calls scripts fileroot.cl, text2mask and fixpix string inlist {prompt="Image(s) for cosmic ray cleaning"} string outlist {prompt="Output image(s)"} bool cleanup {yes, prompt="Delete CR mask & logfile after execution?"} bool overwrite {no, prompt="Overwrite input image with output image?"} bool echog {yes, prompt="Beep when task is done?"} struct *inimglist struct *outimglist begin real skysig,skymode,crthresh,objthresh,negthresh,dmin,dmax int nbox,nbox2,nin,x,y string infile, outfile, img, outimg, statfile, objmask bool maskobj, maskneg, go go=yes #if(!defpac("nmisc")) {go=no} if(!deftask("fixpix")) {go=no} if(!deftask("text2mask")) {go=no} if(go) { # Expand file lists into temporary files. infile = mktemp("tmp$zap") outfile = mktemp("tmp$zap") sections (inlist,option="fullname",>infile) nin = sections.nimages sections (outlist,option="fullname",>outfile) if (nin != sections.nimages) { print ("ERROR: Numbers of input and output images do not match.") return } inimglist = infile outimglist = outfile # Loop through input files: while (fscan(inimglist,img) != EOF) { # Strip extension off input file name. fileroot (img,validim+) img = fileroot.root # Read name of output file. if (fscan(outimglist,outimg) == EOF) { print ("ERROR: Problem scanning output file name in crzap.") return } fileroot (outimg,validim+) outimg = fileroot.root # Imexam print ("Identify rectangular cosmic ray regions by typing `b' at the corners.") imexam (img, frame=1, logfile="_crlog."//img, keeplog+) vi("_crlog."//img) imgets (img, "i_naxis1") x=int(imgets.value) imgets (img, "i_naxis2") y=int(imgets.value) # Create mask print("text2mask _crlog."//img, "_crmask2_"//img//".pl", "ncols="//x, "nlines="//y, "linterp=1, cinterp=2, square=2, pixel=2", >> "dev$null") text2mask ("_crlog."//img, "_crmask2_"//img//".pl", ncols=x, nlines=y, linterp=1, cinterp=2, square=2, pixel=2) # following for nmisc.fixpix only # text2mask ("_crlog."//img, "_crmask2_"//img//".pl", ncols=x, nlines=y, linterp=1, cinterp=2, square=3, pixel=3) # Fix image if(outimg!=img) { imcopy (img, outimg, ver-) } else { if(!overwrite) { imcopy (img,"_orig."//img,ver-) print("Original image "//img//" will be saved as _orig."//img) } } fixpix (outimg, "_crmask2_"//img//".pl", linterp=1, cinterp=2) # following for nmisc.fixpix only #fixpix (outimg, "_crmask2_"//img//".pl", linterp=1, cinterp=2, ninterp=3) # Next input file } # Clean up. if (cleanup) delete ("_crmask2_"//img//".pl",ve-) if (cleanup) delete ("_crlog."//img,ve-) inimglist = ""; delete (infile, verify-) outimglist = ""; delete (outfile, verify-) } else { print ("WARNING! Tasks 'fixpix' and text2mask not loaded -- crzap2 can't run!") print ("To access tasks load 'nmisc' for V2.10 'proto' for V2.11.") } if(echog)beep end ./tplpars.par0100644000151400000240000000062206173013761012356 0ustar phallgames#pset tplpars {prompt="Utitilites.Surfit parameters"} func,s,h,"polynomial",chebyshev|legendre|polynomial,,"SURFIT: Function to use in output fit" xord,i,h,4,1,,"SURFIT: Order of output fit in x-direction" yord,i,h,4,1,,"SURFIT: Order of output fit in x-direction" xterms,b,h,yes,,,"SURFIT: Include cross-terms?" weighting,s,h,"uniform",uniform|user|statistical|instrumental",,"SURFIT: Weighting type" ./irflatkir.par0100644000151400000240000000315206720572777012700 0ustar phallgamesi_plfile,s,h,"",,,"IMCOMBINE: List of pixel list files (optional)" i_sigma,s,h,"",,,"IMCOMBINE: List of sigma images (optional)" i_combine,s,h,"median",,,"IMCOMBINE: Combine operation (median|average)" i_reject,s,h,"ccdclip",,,"IMCOMBINE: Type of rejection" i_offsets,s,h,"none",,,"IMCOMBINE: Input image offsets" i_masktyp,s,h,"badvalue",,,"IMCOMBINE: Mask type" i_maskval,r,h,0.,,,"IMCOMBINE: Mask value" i_blank,r,h,1.,,,"IMCOMBINE: Value if there are no pixels" i_scale,s,h,"!FLATVAL",,,"IMCOMBINE: Image scaling" i_zero,s,h,"none",,,"IMCOMBINE: Image zero point offset" i_weight,s,h,"none",,,"IMCOMBINE: Image weights" i_statsec,s,h,"",,,"IMCOMBINE: Image section for computing statistics" i_expname,s,h,"",,,"IMCOMBINE: Image header exposure time keyword" i_lthresh,r,h,-100000.,,,"IMCOMBINE: Lower threshold" i_hthresh,r,h,100000.,,,"IMCOMBINE: Upper threshold" i_nlow,r,h,1.,,,"IMCOMBINE: minmax: Number of low pixels to reject" i_nhigh,r,h,1.,,,"IMCOMBINE: minmax: Number of high pixels to reject" i_nkeep,r,h,6.,,,"IMCOMBINE: Minimum to keep (+) or maximum to reject(-)" i_lsigma,r,h,3.,,,"IMCOMBINE: Lower sigma clipping factor" i_hsigma,r,h,3.,,,"IMCOMBINE: Upper sigma clipping factor" i_rdnoise,s,h,"rdnoise",,,"IMCOMBINE: ccdclip: CCD readout noise (e-\'s)" i_gain,s,h,"gain",,,"IMCOMBINE: ccdclip: CCD gain (e-\'s/ADU)" i_snoise,s,h,"0.",,,"IMCOMBINE: ccdclip: Sensitivity noise (fraction)" i_sigscale,r,h,0.1,0.,,"IMCOMBINE: Tolerance for sigma-clip scale corrections" i_pclip,r,h,-0.5,,,"IMCOMBINE: pclip: Percentile clipping parameter" i_grow,r,h,0.,,,"IMCOMBINE: Radius (pixels) for 1D neighbor rejection" mode,s,h,"q",,, ./irflatonis.par0100644000151400000240000000314606722102463013045 0ustar phallgamesi_plfile,s,h,"",,,"IMCOMBINE: List of pixel list files (optional)" i_sigma,s,h,"",,,"IMCOMBINE: List of sigma images (optional)" i_combine,s,h,"median",,,"IMCOMBINE: Combine operation (median|average)" i_reject,s,h,"ccdclip",,,"IMCOMBINE: Type of rejection" i_offsets,s,h,"none",,,"IMCOMBINE: Input image offsets" i_masktyp,s,h,"badvalue",,,"IMCOMBINE: Mask type" i_maskval,r,h,0.,,,"IMCOMBINE: Mask value" i_blank,r,h,1.,,,"IMCOMBINE: Value if there are no pixels" i_scale,s,h,"!FLATVAL",,,"IMCOMBINE: Image scaling" i_zero,s,h,"none",,,"IMCOMBINE: Image zero point offset" i_weight,s,h,"none",,,"IMCOMBINE: Image weights" i_statsec,s,h,"",,,"IMCOMBINE: Image section for computing statistics" i_expname,s,h,"",,,"IMCOMBINE: Image header exposure time keyword" i_lthresh,r,h,-100000.,,,"IMCOMBINE: Lower threshold" i_hthresh,r,h,100000.,,,"IMCOMBINE: Upper threshold" i_nlow,r,h,1.,,,"IMCOMBINE: minmax: Number of low pixels to reject" i_nhigh,r,h,1.,,,"IMCOMBINE: minmax: Number of high pixels to reject" i_nkeep,r,h,6.,,,"IMCOMBINE: Minimum to keep (+) or maximum to reject(-)" i_lsigma,r,h,3.,,,"IMCOMBINE: Lower sigma clipping factor" i_hsigma,r,h,3.,,,"IMCOMBINE: Upper sigma clipping factor" i_rdnoise,s,h,"35.0",,,"IMCOMBINE: ccdclip: CCD readout noise (e-\'s)" i_gain,s,h,"4.0",,,"IMCOMBINE: ccdclip: CCD gain (e-\'s/ADU)" i_snoise,s,h,"0.",,,"IMCOMBINE: ccdclip: Sensitivity noise (fraction)" i_sigscale,r,h,0.1,0.,,"IMCOMBINE: Tolerance for sigma-clip scale corrections" i_pclip,r,h,-0.5,,,"IMCOMBINE: pclip: Percentile clipping parameter" i_grow,r,h,0.,,,"IMCOMBINE: Radius (pixels) for 1D neighbor rejection" mode,s,h,"q",,, ./ircoaddirim.par0100644000151400000240000000270106542514717013166 0ustar phallgamesi_sigma,s,h,"",,,"IMCOMBINE: Sigma image (optional)" i_plfile,s,h,"",,,"IMCOMBINE: Rejected pixel list image (optional)" i_combine,s,h,"average",average|median,,"IMCOMBINE: Type of combine operation (median|average)" i_reject,s,h,"sigclip",none|minmax|ccdclip|crreject|sigclip|avsigclip|pclip,,"IMCOMBINE: Type of rejection" i_masktyp,s,h,"badvalue",none|goodvalue|badvalue|goodbits|badbits,,"IMCOMBINE: Mask type" i_maskval,r,h,0.,,,"IMCOMBINE: Mask value" i_blank,r,h,0.,,,"IMCOMBINE: Value if there are no pixels" i_statsec,s,h,"",,,"IMCOMBINE: Image section for computing statistics" i_expname,s,h,"exptime",,,"IMCOMBINE: Image header exposure time keyword" i_lthresh,r,h,INDEF,,,"IMCOMBINE: Lower threshold" i_hthresh,r,h,INDEF,,,"IMCOMBINE: Upper threshold" i_nlow,r,h,1.,0.,,"IMCOMBINE: minmax: Number of low pixels to reject" i_nhigh,r,h,1.,0.,,"IMCOMBINE: minmax: Number of high pixels to reject" i_nkeep,r,h,1.,,,"IMCOMBINE: Minimum to keep (+) or maximum to reject(-)" i_lsigma,r,h,5.,0.,,"IMCOMBINE: Lower sigma clipping factor" i_hsigma,r,h,5.,0.,,"IMCOMBINE: Upper sigma clipping factor" i_rdnoise,s,h,7.7,,,"IMCOMBINE: ccdclip: CCD readout noise (electrons)" i_gain,s,h,2.2,,,"IMCOMBINE: ccdclip: CCD gain (electrons/ADU)" i_sigscale,r,h,0.1,0.,,"IMCOMBINE: Tolerance for sig-clip scaling corrections" i_pclip,r,h,-0.5,,,"IMCOMBINE: pclip: Percentile clipping parameter" i_grow,r,h,0.,,,"IMCOMBINE: Radius (pixels) for 1D neighbor rejection" mode,s,h,"q",,, ./irflatpisces.par0100644000151400000240000000316106720572777013401 0ustar phallgamesi_plfile,s,h,"",,,"IMCOMBINE: List of pixel list files (optional)" i_sigma,s,h,"",,,"IMCOMBINE: List of sigma images (optional)" i_combine,s,h,"median",,,"IMCOMBINE: Combine operation (median|average)" i_reject,s,h,"ccdclip",,,"IMCOMBINE: Type of rejection" i_offsets,s,h,"none",,,"IMCOMBINE: Input image offsets" i_masktyp,s,h,"badvalue",,,"IMCOMBINE: Mask type" i_maskval,r,h,0.,,,"IMCOMBINE: Mask value" i_blank,r,h,1.,,,"IMCOMBINE: Value if there are no pixels" i_scale,s,h,"!FLATVAL",,,"IMCOMBINE: Image scaling" i_zero,s,h,"none",,,"IMCOMBINE: Image zero point offset" i_weight,s,h,"none",,,"IMCOMBINE: Image weights" i_statsec,s,h,"",,,"IMCOMBINE: Image section for computing statistics" i_expname,s,h,"exptime",,,"IMCOMBINE: Image header exposure time keyword" i_lthresh,r,h,-100000.,,,"IMCOMBINE: Lower threshold" i_hthresh,r,h,100000.,,,"IMCOMBINE: Upper threshold" i_nlow,r,h,1.,,,"IMCOMBINE: minmax: Number of low pixels to reject" i_nhigh,r,h,1.,,,"IMCOMBINE: minmax: Number of high pixels to reject" i_nkeep,r,h,6.,,,"IMCOMBINE: Minimum to keep (+) or maximum to reject(-)" i_lsigma,r,h,3.,,,"IMCOMBINE: Lower sigma clipping factor" i_hsigma,r,h,3.,,,"IMCOMBINE: Upper sigma clipping factor" i_rdnoise,s,h,"RDNOISE",,,"IMCOMBINE: ccdclip: CCD readout noise (e-\'s)" i_gain,s,h,"GAIN",,,"IMCOMBINE: ccdclip: CCD gain (e-\'s/ADU)" i_snoise,s,h,"0.",,,"IMCOMBINE: ccdclip: Sensitivity noise (fraction)" i_sigscale,r,h,0.1,0.,,"IMCOMBINE: Tolerance for sigma-clip scale corrections" i_pclip,r,h,-0.5,,,"IMCOMBINE: pclip: Percentile clipping parameter" i_grow,r,h,0.,,,"IMCOMBINE: Radius (pixels) for 1D neighbor rejection" mode,s,h,"q",,, ./irimfirst.cl0100644000151400000240000002241707254743520012527 0ustar phallgames# irimfirst.cl -- add header params to raw IRIM (4-m) images and optionally do # nonlinearity correction, saturated pixel replacement, & dark subtraction # # 1. do nonlinearity correction & add NLCOR (& poss. SATVAL) header card(s) # 2. subtract dark & add DARKSUB header card # 3. hedit image headers, adding: (basically this is task 'hadd.cl', except #0) # 0. BPM,BPMASK = bad pixel mask name # 1. exptime = (itime: exposure time per coadd) * (# of coadds) # 2. obs-date = date-obs (obs-date should have dd/mm/yy format) # # 941217: adapted for 4-m from first.cl # 950328: added DARKSUB header card insertion and nonlinearity option # 950403: changed correction to account for nonlinearity before first read # 960203: changed to allow suffix="" # 970321: changed to yield obs-date in dd/mm/yy format # 980414: added compatibility to incoming date-obs in new-millenium format and # output of date-obs in same format (valid for data from 1990 to 2089); # original date-obs is output as dateorig # 990320: fixed bug where exptime & itime were feedbacking on each other # 990427: DARKSUB keyword added to darksubbed images, not original ones # # **cannot replace saturated pixels except at same time as nonlin. correction # **does not check to see if DARKSUB header card already exists in images procedure irimfirst(inlist,nonlin,darksub) string inlist {prompt="List of images to process (do not use an `@')"} bool nonlin {prompt="Do nonlinearity correction?"} bool darksub {prompt="Subtract off dark frame?"} string suffix {prompt="String to be appended to output images",mode="q"} real slope {min=1.,prompt="Slope coefficient of nonlinearity correction",mode="q"} string intname {prompt="Name of integration time header keyword",mode="q"} bool replace {prompt="Replace `saturated' pixels?",mode="q"} real maxval {40000.,min=30000.,prompt="Maximum good raw data value",mode="q"} string dark {prompt="Name of the dark frame to subtract",mode="q"} string badmask {prompt="Name of bad pixel mask to add to image header"} bool echog {yes,prompt="Beep when task is done?"} struct *list begin string ddark, ssuffix, bbadmask, check, base, ilist string olist, flat, flatbase, meanfile, currentflat, tempflat, name string editlist, current, obsdate, rra, ddec, eepoch, oobservatory, minsec string obstime, timeobs, dateobs, century real aairval, ttime, mean, meanbad, x int ncoadd, ddy, hhr, hhour, mmonth, dday, uttime bool ddarksub, ccoords, uut, nnonlin string iintname # equals intname string instring # temporary string real sslope # equals slope of nonlinearity correction real mmaxval # equals maxval real valmax # equals maxval string img # fscanned name of individual input image string oimg # fscanned name of individual output image real intime # equals int_time real delaytime # delay time between reset & first read real intfactor # factor for use in nonlinearity correction bool rreplace # equals replace bool go # just do it bool goon # just do it struct theadline # temporary struct for header information ilist = inlist editlist = ilist # editlist lists images currently being worked on olist = ilist # olist lists output images nnonlin = nonlin ddarksub = darksub ssuffix = suffix if(nnonlin){ # If suffix=="", insert temporary suffix to avoid overwriting if(ssuffix==""){ ssuffix="filthpig" beep print("WARNING! Input files will be overwritten!") } olist = ilist//ssuffix # olist lists output images sslope = slope iintname = intname rreplace = replace if(rreplace){ mmaxval = maxval valmax = mmaxval } } if(ddarksub){ if(!nnonlin){ ssuffix = suffix olist = ilist//ssuffix # olist lists output images } ddark = dark } bbadmask = badmask # The "go" parameter won't let the task run if the needed tasks aren't loaded. go=yes if(!deftask("fileroot")) {go=no} if(!deftask("imcalc")) {go=no} if(go) { # Do nonlinearity correction goon=no if(nnonlin){ print("===> Running nonlinearity correction procedure...") list = ilist editlist = olist while (fscan(list,img) != EOF) { fileroot(img,validim+) oimg=fileroot.root//ssuffix//"."//fileroot.extension # add output image name to output image list unless suffix="" # if(ssuffix!="filthpig")print(oimg, >> olist) print(oimg, >> olist) # do the correction only if input image has not already been corrected imgets(img,"NLCOR",>&"dev$null") if(imgets.value=="0")goon=yes # if output image exists... if(access(oimg)){ imgets(oimg,"NLCOR",>&"dev$null") # ...and has not been nlcorrected, delete it if(imgets.value=="0"){ imdel(oimg,ver-) } # ...if it has been nlcorrected, print error message & do not do the correction else{ goon=no print("Nonlinearity correction already done on "//oimg//"-- not redone.") } } if(goon){ imgets(img,iintname) intime=real(imgets.value) # Find delay time... if(intime>=1.381){ delaytime=1. # intfactor=1.+(1./intime) } else{ delaytime=intime-0.381 # intfactor=2.-(0.381/intime) } intfactor=1.+((2.*delaytime)/intime) # Do nonlinearity correction. The correction is approximate, but should be # good for pixels requiring <=10% correction, above which they saturate anyway. imcalc(img,oimg,"(im1)/(1.-im1*("//intfactor//"/"//sslope//"))", pixtype="real",nullval=0.,ver-) # imcalc(img,oimg,"("//sslope//"*im1)/("//sslope//"-im1*"//intfactor//")",pixtype="real",nullval=0.,ver-) hedit(oimg,"NLCOR",sslope,add+,ver-,show+,update+) # Replace "saturated" pixels if desired if(rreplace){ mmaxval=(sslope*valmax)/(sslope-valmax*intfactor) imreplace(oimg,mmaxval,lower=mmaxval,upper=INDEF) hedit(oimg,"SATVAL",mmaxval,add+,ver-,show+,update+) } } # If correction already done on input image, do not redo, just copy to output else{ print("Nonlinearity correction already done on "//img//"-- not redone.") if(!access(oimg))imcopy(img,oimg,ver-) } } } # Subtract off Dark Current if (ddarksub) { print("===> Subtracting off Dark Current...") # If final output list is not same as current list, need to create output list if(olist!=editlist){ # if olist doesn't exist, assume darksub'd imgs don't either; create it & dsubs if(!access(olist)) { print("===> Subtracting off Dark Current...") list=editlist while (fscan(list,img) != EOF) { fileroot(img,validim+) oimg=fileroot.root//ssuffix if(fileroot.extension!="")oimg=oimg//"."//fileroot.extension print(oimg, >> olist) imgets(img,"DARKSUB") if (imgets.value=="0") { imarith(img, "-", ddark, oimg, verbose-) hedit(oimg,"DARKSUB",ddark,add+,ver-,show+,upd+) } else { print("DARKSUB keyword exists; irimfirst already run? "//name//" just copied") imcopy(img, oimg, verbose-) } } } else { print("Darksubbed image list "//olist//" already exists; images assumed to exist too.") } print(" ") print("===> Dark-subtracted images are listed in the file "//olist//".") # imarith("@"//editlist, "-", ddark, "@"//olist, verbose-) # hedit("@"//olist,"DARKSUB",ddark,add+,ver-,show+,update+) editlist=olist } # Add the BPM to the image headers print("===> Adding various parameters to the image headers...") hedit("@"//editlist,"BPM",bbadmask,add+,ver-,show-,update+) hedit("@"//editlist,"BPMASK",bbadmask,add+,ver-,show-,update+) # Add other goodies to the image headers, just like in the hadd.cl task list = editlist while (fscan (list, current) !=EOF) { imgets(current,"int_s") intime=real(imgets.value) imgets(current,"coadds") ncoadd=real(imgets.value) hedit(current,"exptime",(ncoadd*intime),add+,ver-,show+,update+) imgets(current,"date-obs") hedit(current,"dateorig",(imgets.value),add+,ver-,show+,update+) # date-obs is either in dd/mm/yy format or yyyy-mm-dd format if(substr(imgets.value,3,3)=="/") { # if input date-obs is in dd/mm/yy format, rework to get output date-obs if ((substr(imgets.value,7,7))=="9") { century=19 } else { century=20 } dateobs=century//substr(imgets.value,7,8)//"-"//substr(imgets.value,4,5)//"-"//substr(imgets.value,1,2) hedit(current,"date-obs",dateobs,add+,ver-,show+,update+) # if input date-obs is in dd/mm/yy format, obs-date is a direct copy of it hedit(current,"obs-date",(imgets.value),add+,ver-,show+,update+) } else { # if input date-obs is in yyyy-mm-dd format, rework to get obs-date obsdate=substr(imgets.value,9,10)//"/"//substr(imgets.value,6,7)//"/"//substr(imgets.value,3,4) hedit(current,"obs-date",obsdate,add+,ver-,show+,update+) } } # If suffix=="", if(ssuffix=="filthpig"){ imdel("@"//ilist,ver-) imren("@"//olist,"@"//ilist,ver-) del(olist,ver-) olist=ilist } print(" ") print("===> Processed images are listed in the file "//olist//".") if(ddarksub || nnonlin){ print("===> You should rerun the task with nonlin=no and/or darksub=no to properly") print("===> update the original image headers, if you plan to use those images.") } } else { print("WARNING: tasks fileroot and/or stsdas.toolbox.imgtools.imcalc") print("are not loaded! Please load them and restart this task.") } if(echog)beep end ./untrim.cl0100644000151400000240000000256606561403212012027 0ustar phallgames# untrim.cl -- script to produce true output magnitudes for objects detected # on a variable-exposure-time mosaic. # # Following two lines produce a list of the objects' INTEGER x,y # coordinates and their total COUNTS from FOCAS catalogs. # #filter H < image.cat > imagetmp.cat #catlist x y Li < imagetmp.cat >> untrim.image #catlist x y Ltotal < imagetmp.cat >> untrim.image # # Insert 1sig/arsec rms cts or 3sig limit cts in next line # imdel untrim.image*.imh ver- imar imagemask * 999 untrim.imagetmp.imh # list="untrim.image" while (fscan (list, i, j, z) !=EOF) { imdel ("tmp.imh", ver-, >& "dev$null") imar("imagemask["//i//":"//i//","//j//":"//j//"]", "*", z, "tmp.imh") imcopy ("tmp.imh", "untrim.imagetmp.imh["//i//":"//i//","//j//":"//j//"]") imdel ("tmp.imh", ver-, >& "dev$null") } minmax imagenorm force+ imar("imagenorm", "/", minmax.maxval, "imagenormtmp", ver+, noact-) # # Following two lines are optional. # #imar imagenormtmp + 0.03 imagenormtmp #imreplace imagenormtmp 1. lower=1. upper=INDEF # # Insert zeropoint for image in next line # imcalc untrim.imagetmp.imh,imagenormtmp untrim.image.imh "999-2.5*log10(im1 / (sqrt(im2)))" imdel imagenormtmp ver- imdel untrim.imagetmp.imh ver- # list="untrim.image" while (fscan (list, i, j, z) !=EOF) { imstat("untrim.image.imh["//i//":"//i//","//j//":"//j//"]", fields="mean", format-, >> "untrim.image.truemags") } beep ./fileroot.cl0100644000151400000240000000523606646717312012346 0ustar phallgamesprocedure fileroot(filename) # Routine to parse a file name into its root and extension. # The extension is assumed to be the portion of the file name # which follows the last period in the input string supplied # by the user; the root is everything which preceeds that period. # # 930816: Included parameter 'validim' to force a check to see if the extension # represents a valid IRAF image datatype, and if not, to negate the parsing. # This would be a common usage; often the user only wants to strip off the # portion of the filename after the last period if that substring represents a # valid IRAF image type such as .imh or .pl. Without the 'validim' parameter, # if the file included another period somewhere in its name, then the portion # of the filename after that period would be erroneously returned as an image # extension. At present, the routine only checks for a few datatypes; # this should be expanded in the future. # 980622: updated valid ID headers to include FITS (fts and fits) for V2.11 # 990112: updated valid ID headers to include FITS (fit) for V2.11 string filename {prompt="File name"} bool validim {yes,prompt="Parse only if extension represents valid image datatype?"} string root {"",prompt="Returned filename root"} string extension {"",prompt="Returned filename extension"} begin string fname # Equals filename string revname # Reversed version of input string int ilen,ipos,ic # String position markers int ii # Counter string imtype = "imh", "fits", "fts", "fit", "hhh", "pl", "qpoe", "qp", "" # Must use null string to terminate! # Get query parameter. fname = filename # Reverse filename string character by character --> revname. ilen = strlen(fname) revname = "" for (ic=ilen; ic>=1; ic-=1) { revname = revname // substr(fname,ic,ic) } # Look for the first period in the reversed name. ipos = stridx(".",revname) # If period exists, break filename into root and extension. Otherwise, # return null values for the extension, and the whole file name for the root. if (ipos != 0) { root = substr(fname,1,ilen-ipos) extension = substr(fname,ilen-ipos+2,ilen) } else { root = fname extension = "" } # If validim = yes and extension != "", check to see if the parsed extension # is a string indicating a valid image data type, e.g. "imh", "pl", etc. # If not, then undo the parsing, replacing the root with the complete input # string 'filename' and setting the extension to null. if (validim && extension != "") { ii = 1 while (imtype[ii] != "") { if (extension == imtype[ii]) break ii += 1 } if (imtype[ii] == "") { root = fname extension = "" } } end ./tpl.cl0100644000151400000240000001147506674031435011320 0ustar phallgames# tpl.cl -- create throughput correction image # 950123: created # 950201: fixed so it would work and normalize correctly. # 950214: fitting loop, tplpars # 950224: added plot of object flux as f(time) # 950523: fixed various minor bugs # 990317: fixed to work with V2.11 imexam format procedure tplnew(rootname,imagelist,outname) string rootname {prompt="Rootname for output log files, etc."} string imagelist {prompt="List of images to use to create throughput image"} string outname {prompt="Name of throughput image to create"} real ncols {256.,prompt="Number of columns in output image"} real nlines {256.,prompt="Number of columns in output image"} real radius=10. {prompt="Aperture photometry radius for imexamine"} real buffer=5. {prompt="Aperture photometry sky buffer for imexamine"} real width=10. {prompt="Aperture photometry sky annulus width for imexamine"} bool fit {prompt="Adjust parameters and refit image?", mode="q"} int z {prompt="Number of image to save?", mode="q"} bool echog {yes,prompt="Beep when task is done?"} pset tplpars {prompt="Utilities.Surfit parameters"} begin string logimex, logsurf, countfile, rrootname, iimagelist, ooutname, ffunc string wweighting real max, nncols, nnlines int x, y, zz, xxord, yyord bool go, ffit, xxterms rrootname=rootname iimagelist=imagelist ooutname=outname nncols=ncols nnlines=nlines ffunc=tplpars.func xxord=tplpars.xord yyord=tplpars.yord xxterms=tplpars.xterms wweighting=tplpars.weighting logimex="log."//rrootname//".tplimex" logsurf="log."//rrootname//".tplsurf" countfile="log."//rrootname//".tplcount" # check for addcomment and utilities.surfit; if not defined abort task. go=yes if(!deftask("addcomment")) {go=no} if(!deftask("surfit")) {go=no} if(go) { # examine tpl images and find std. star flux in each print (" ") print ("===> Find std star flux with 'a' in each image.") print ("===> When done, or if image is bad, hit 'n' to go to next image.") print ("===> After last image, or if you've already done this stage, hit 'q'.") rimexam.radius=radius rimexam.buffer=buffer rimexam.width=width rimexam.center=yes rimexam.background=yes rimexam.xorder=1 rimexam.yorder=1 print("#TPL photometry: radius="/radius//", buffer="/buffer//", width="//width, >> logimex) imexam ("@"//iimagelist, keeplog+, logfile=logimex) del("_tmp.countfile",ver-, >& "dev$null") print("#1:x 2:y 3:flux 4:err", >> countfile) #--OLD IMEXAM FORMAT (x,y,flux,sky,npix) #fields (logimex, "1,2,4,5,6", >> "_tmp.countfile") #filecalc ("_tmp.countfile","$1;$2;$3;((sqrt($3+$4*$5))/$3)",format="%7.2f%7.2f%9.1f%9.5f", >> countfile) #--NEW IMEXAM FORMAT (x,y,flux,sky,radius) fields (logimex, "1,2,7,8,6", >> "_tmp.countfile") filecalc ("_tmp.countfile","$1;$2;$3;((sqrt($3+$4*3.14159*$5**2.))/$3)",format="%7.2f%7.2f%9.1f%9.5f", >> countfile) del("_tmp.countfile",ver-) x=1 y=0 ffit=yes # Fitting loop while(ffit) { if(x!=1){ copy(countfile//"_"//str(x-1),countfile//"_"//str(x)) vi(countfile//"_"//str(x)) tplpars ffunc=tplpars.func xxord=tplpars.xord yyord=tplpars.yord xxterms=tplpars.xterms wweighting=tplpars.weighting } else { copy(countfile,countfile//"_"//str(x)) } # fit this output (x,y,counts) file using utilities.surfit: print (" ") print ("===> Fitting surface to data points...") surfit (countfile//"_"//str(x),image=ooutname//"_"//str(x),ncols=nncols,nlines=nnlines,xord=xxord,yord=yyord,xterms=xxterms,weight=wweighting,func=ffunc, >> logsurf) imstat (ooutname//"_"//str(x), fields="max", format-) | scan (max) imar (ooutname//"_"//str(x), "/", max, ooutname//"_"//str(x), ver-) # inspect the fitted images & decide on best order/funct. print (" ") print ("===> Displaying surface-fit image and plotting flux time series...") y=y+1 if(y>4)y=1 displ (ooutname//"_"//str(x), y) fields (countfile//"_"//str(x), "3") | graph (point-) # clean up del(logimex//"sort",ver-, >& "dev$null") # abort loop? ffit=fit x+=1 } # clean up zz=z if(zz==0){ del(countfile,ver-, >& "dev$null") print("No throughput image saved.") } else { imcopy(ooutname//"_"//str(zz),ooutname,ver-) del(countfile,ver-, >& "dev$null") rename(countfile//"_"//str(zz),countfile, >& "dev$null") hedit(ooutname,"title","Throughput correction image from "//iimagelist//" and "//countfile,add+,ver-,update+,show-) addcomment(ooutname,"Image created from "//iimagelist//" and "//countfile,ver-) addcomment(ooutname,"using func="/ffunc//", xord="/xxord//", yord="/yyord//",",ver-) addcomment(ooutname,"xterms="/xxterms//", and weighting="//wweighting,ver-) } y=0 while(y& "dev$null") del(countfile//"_"//str(y),ver-, >& "dev$null") y+=1 } } else{ print("The tasks `utilities.surfit' and/or `addcomment' are not loaded,") print("and this task needs them to run. Please load it and start again.") } if(echog)beep end ./irrotate.cl0100644000151400000240000003312006720573000012330 0ustar phallgames# irrotate -- rotate and resample images and recalculate shifts for them # # Calls scripts fileroot, filecalc, addcomment. # # Output: # "*br"//mag//ssuffix//".imh" output rotated, resampled images # inputlist//"br"//mag//ssuffix list of above images # shiftexactlist//"br"//mag//suffix list of shifts for above images # inputlist//"br"//mag//ssuffix//"pl" list of new bad pixel images created # # 960307: created from ircoadd2.cl # 960402: add header keyword ROTATED = angle//"x"//magfac # 960817: allowed for non-creation of shifts file if desired # 970426: added rotation of TPLIMG images # 970505: fixed bug -- need boundary=nearest for rotation of TPLIMG images # 970513: fixed bug which made offsets -0.5 < offsets < 0.5 round to 1. not 0 # 970630: fixed minv bugs, nothing major # 990516: use imcalc instead of imreplace # # **should include optional tpl division, before bp zeroing procedure irrotate(rotlist,suffix,angle,scale,magfac,shiftexactlist,logfile) string rotlist {prompt="List of images to rotate"} string suffix {prompt="UNIQUE suffix to append to rotated images"} real angle {prompt="Rotation angle in degrees"} real scale {prompt="Input image scale compared to reference image"} int magfac {2,min=1,max=10,prompt="Output image magnification factor (subpix shifts)"} string shiftexactlist="" {prompt="File with EXACT image shifts"} string logfile {prompt="Name of log file"} string i_interp {"linear",enum="nearest|linear|poly3|poly5|spline3",prompt="IMLINTRAN: Interpolation type"} string i_boundary {"constant",enum="nearest|constant|reflect|wrap",prompt="IMLINTRAN: Boundary extension type"} real i_constant {0.,prompt="IMLINTRAN: Value for constant boundary"} bool bpzero=no {prompt="Zero images by bad pixel masks before rotating?"} bool newmask=no {prompt="Override bad pixel masks listed in image headers?"} string badmask {prompt="Bad pixel mask to use instead",mode="q"} bool invert=no {prompt="Invert output bad pixel masks so bad pixels=0?"} real bpfrac {0.75,min=0.,max=0.99,prompt="Threshold bad pixel value in the rotated bp mask"} bool norot=no {prompt="Skip image rotation and calculate shifts only?"} bool echog {yes,prompt="Beep when task is done?"} struct *list begin string sshiftfraclist, iinterp, ssuffix, sshiftlist, subimg, explist, bpmimg string rrotlist, bbadmask, sshiftoutlist, ooutimage, zzerofile, sstackimage string llogfile, check, zzeroname, sscalefile, sscalename, img, eexpname, blk string listimshift, mmoreword, wwordzero, mmorename, subimgold, expmaskold, ext string rrotlist1, rrotlist2, sshiftexactlist, newzzeroname, image, newbp, sect string oldbp, holesmask, tmpstring, s1, s2, s3, bprotlist, o_interp, o_boundary string oldtpl, newtpl real avg, x, sig, invmag, valmax, bbpfrac, outfactor, invfactor, aangle real effairmass, wtavg, nncombine, exp, exposure, sf, zf, testold, eexptime real xold, yold, xnew, ynew, angrad, x_shift, y_shift, sscale, tmpreal, y, z real o_constant int mag, mag2, xlength, ylength, j, k, n_cols, n_lines int xmin, ymin, newx, newy, oldx, oldy, test1, test1old, test2, test2old int sstartno, eendno, i, numpix, num, xdim, ydim, newxsize, newysize, ncoadds bool mmakescalefile, sstack, mmakestack, mmorescale, go, mmorehow, pputzero bool nnewmask, sstackdel, sstdstar, ssubpixscale, noappend, iinvert, bbpzero struct theadline rrotlist = rotlist rrotlist1 = rrotlist ssuffix=suffix if(ssuffix==""){ date | scan(s1,s2,i,x,s3,k) y=int(100*x) ssuffix="rot"//i//s2//y//"_" print("Auto-generated image suffix is "//ssuffix) } aangle=angle angrad=aangle*3.1415926535/180. sscale = scale mag = magfac invmag=1./mag invfactor=sscale*invmag mag2=mag*mag blk = "br"//mag rrotlist2 = rrotlist//blk//ssuffix bprotlist = rrotlist//blk//ssuffix//"pl" sshiftexactlist = shiftexactlist sshiftoutlist=sshiftexactlist//blk//ssuffix #sshiftoutlist = sshiftexactlist//blk llogfile = logfile o_interp = i_interp o_boundary = i_boundary o_constant=0. if(o_boundary=="constant")o_constant=i_constant bbpzero = bpzero nnewmask = newmask if(nnewmask)bbadmask=badmask iinvert = invert bbpfrac = bpfrac # Certain tasks/packages must be loaded for task to run. go=yes if(!deftask("fileroot")) {go=no} if(!deftask("filecalc")) {go=no} if(!defpac("imgtools")) {go=no} if(go) { # Set up log file, overwriting if it already exists. if(llogfile == "") llogfile="log."//ooutimage print("", >> llogfile) print("===> PHIIRS.IRROTATE:", >> llogfile) print("===> Input images from "//rrotlist1//" rotated by angle "//aangle, >> llogfile) if(bbpzero)print("===> (after having all bad pixels zeroed), then", >> llogfile) print("===> rescaled by factor "//sscale//" to match reference image,", >> llogfile) print("===> and resampled by factor "//mag//" in each direction.", >> llogfile) print("===> New x-y shifts for the output images listed in "//rrotlist2, >> llogfile) print("===> can be found in "//sshiftoutlist, >> llogfile) # BP ZEROING IF DESIRED if (bbpzero) { print("Zeroing images in "//rrotlist1//" by their bad pixel masks.") list=rrotlist1 while (fscan (list, img) !=EOF) { fileroot(img,validim+) image=fileroot.root imgets(image,"BPM",>&"dev$null") bpmimg=str(imgets.value) imar(img,"*",bpmimg,img,pixtype="real",calctype="real",noact-,ver-) } } # ROTATION # If output image list already exists, do not append to it. if (!norot) { noappend=no if (access(rrotlist2)) { noappend=yes beep print("WARNING! Output image list "//rrotlist2//" already exists.") print("Any images listed therein will be created if they do not exist,") print("but no image names will be appended to this preexisting file.") } print("===) Rotating images and expanding by factor "//mag//" in both directions...") list=rrotlist1 while (fscan (list, img) !=EOF) { fileroot(img,validim+) image=fileroot.root ext=fileroot.extension if(ext==""){ ext=".imh" } else { ext="."//ext } imgets(image,"ROTATED",>&"dev$null") if(imgets.value=="0"){ if(!noappend)print(image//blk//ssuffix, >> rrotlist2) imgets(image,"i_naxis1") xlength=int(imgets.value) imgets(image,"i_naxis2") ylength=int(imgets.value) n_cols=int(xlength/invfactor) n_lines=int(ylength/invfactor) # Increasing output sizes by 1 does preserve all info, but makes coadding with # nonrotated images painful. # n_cols=int(xlength/invfactor)+1 # n_lines=int(ylength/invfactor)+1 # If output rotated & resampled image does not exist, create it if(!access(image//blk//ssuffix//ext)){ imlintran(image, image//blk//ssuffix, xrotation=aangle, yrotation=aangle, xmag=invfactor, ymag=invfactor, xin=INDEF, yin=INDEF, xout=INDEF, yout=INDEF, ncols=n_cols, nlines=n_lines, interpolant=o_interp, boundary=o_boundary, constant=o_constant, fluxconserve+, nxblock=512, nyblock=512) # imlintran(image, image//blk//ssuffix, xrotation=aangle, #yrotation=aangle, xmag=invfactor, ymag=invfactor, xin=INDEF, yin=INDEF, #xout=INDEF, yout=INDEF, ncols=n_cols, nlines=n_lines, interpolant="linear", #boundary="constant", constant=0., fluxconserve+, nxblock=512, nyblock=512) imgets(image//blk//ssuffix,"TPLIMG",>&"dev$null") if(imgets.value!="0")hedit(image//blk//ssuffix,"TPORIG",imgets.value,add+,ver-,show-,update+) imgets(image//blk//ssuffix,"BPMASK",>&"dev$null") if(imgets.value=="0")imgets(image//blk//ssuffix,"BPM",>&"dev$null") hedit(image//blk//ssuffix,"BPORIG",imgets.value,add+,ver-,show-,update+) } else { # If output image already exists, only print a warning. print("WARNING! "//image//blk//ssuffix//" already exists; not overwritten") } # imlintran the TPL image, if not already done. imgets(image//blk//ssuffix,"TPORIG",>&"dev$null") if(imgets.value=="0"){ print("Image "//image//blk//ssuffix//" is missing TPORIG keyword!") } else { fileroot(imgets.value,validim+) oldtpl=fileroot.root newtpl=oldtpl//blk//ssuffix if(!access(oldtpl//blk//ssuffix//ext)){ imlintran(oldtpl, oldtpl//blk//ssuffix//ext, xrotation=aangle, yrotation=aangle, xmag=invfactor, ymag=invfactor, xin=INDEF, yin=INDEF, xout=INDEF, yout=INDEF, ncols=n_cols, nlines=n_lines, interpolant=o_interp, boundary="nearest", constant=o_constant, fluxconserve-, nxblock=512, nyblock=512) } hedit(image//blk//ssuffix,"TPLIMG",oldtpl//blk//ssuffix//ext,add+,ver-,show-,update+) } # imlintran the bad pixel mask, if not already done. Include "edge effects". imgets(image//blk//ssuffix,"BPORIG",>&"dev$null") if(imgets.value=="0"){ beep print("Image "//image//blk//ssuffix//" is missing BPORIG keyword!") } else { fileroot(imgets.value,validim+) oldbp=fileroot.root newbp=oldbp//blk//ssuffix if(!access(oldbp//blk//ssuffix//".pl")){ if(!iinvert){ imcopy(oldbp,oldbp//"tmp"//ext,ver-) } else { minv(oldbp,oldbp//"tmp"//ext) } imar(oldbp//"tmp"//ext,"/",oldbp//"tmp"//ext,oldbp//"tmpe"//ext, divzero=0., pixtype="real", calctype="real",ver-) imlintran(oldbp//"tmp"//ext//","//oldbp//"tmpe"//ext, newbp//"tmp"//ext//","//newbp//"tmpe"//ext, xrotation=aangle, yrotation=aangle, xmag=invfactor, ymag=invfactor, xin=INDEF, yin=INDEF, xout=INDEF, yout=INDEF, ncols=n_cols, nlines=n_lines, interpolant=o_interp, boundary=o_boundary, constant=o_constant, fluxconserve+, nxblock=512, nyblock=512) # imlintran(oldbp//"tmp"//ext//","//oldbp//"tmpe"//ext, #newbp//"tmp"//ext//","//newbp//"tmpe"//ext, xrotation=aangle, yrotation=aangle, #xmag=invfactor, ymag=invfactor, xin=INDEF, yin=INDEF, xout=INDEF, yout=INDEF, #ncols=n_cols, nlines=n_lines, interpolant="linear", boundary=" #constant", constant=0., fluxconserve+, nxblock=512, nyblock=512) # Replace edge pixels in the edge mask minmax(newbp//"tmpe"//ext,force+,ver-) valmax=minmax.maxval #imreplace(newbp//"tmpe"//ext,0.,lower=INDEF,upper=0.99*valmax) #imreplace(newbp//"tmpe"//ext,1.,lower=0.98*valmax,upper=INDEF) imcalc(newbp//"tmpe"//ext,newbp//"tmpe"//ext,"if im1 .lt. "//valmax//" then 0 else 1",ver-) # Replace only slightly bad pixels in the bad pixel mask with 1. minmax(newbp//"tmp"//ext,force+,ver-) valmax=minmax.maxval #imreplace(newbp//"tmp",0.,lower=INDEF,upper=bbpfrac*valmax) #imreplace(newbp//"tmp",1.,lower=0.9*bbpfrac*valmax,upper=INDEF) imcalc(newbp//"tmp"//ext,newbp//"tmp"//ext,"if im1 .le. "//bbpfrac*valmax//" then 0 else 1",ver-) # Multiply bad pixel mask by edge mask and convert to .pl format imar(newbp//"tmp","*",newbp//"tmpe",newbp//"tmp",pixt="real",calct="real",ver-) if(!iinvert){ imcopy(newbp//"tmp"//ext,newbp//".pl",ver-) } else { minv(newbp//"tmp"//ext,newbp//".pl") } # Clean up imdel(oldbp//"tmp*"//ext,ver-) imdel(newbp//"tmp*"//ext,ver-) print(newbp//".pl", >> bprotlist) } # Insert the rotated & resampled bad pixel mask in the image header hedit(image//blk//ssuffix,"BPM",newbp//".pl",add+,ver-,show-,update+) hedit(image//blk//ssuffix,"BPMASK",newbp//".pl",add+,ver-,show-,update+) } # # addcomment ROTATED w/angle, magfac hedit(image//blk//ssuffix,"ROTATED",str(aangle)//"x"//str(mag),add+,ver-,show-,update+) # # If image has already been rotated, do not rotate. } else { print("WARNING! Image "//image//" already rotated; not rotated again.") } # Rotate/resample next image... } } else { print("===> Image rotation not done.") } # CALCULATE SUBPIXEL SHIFTS # Create subpixel shift file if desired and if not already in existence if (sshiftexactlist!="" && !access(sshiftoutlist)){ print("===> Calculating shifts for rotated, resampled images...") if (access("tmp"//sshiftoutlist))del("tmp"//sshiftoutlist,ver-) list=sshiftexactlist while (fscan (list,xold,yold) != EOF) { xnew=(mag/sscale)*(xold*cos(angrad) - yold*sin(angrad)) ynew=(mag/sscale)*(yold*cos(angrad) + xold*sin(angrad)) print (xnew, ynew, >> "tmp"//sshiftoutlist) } # Round off to integer shifts (in units of new pixels, natch). # Extensive code needed to make sure offsets -0.5 < offsets < 0.5 round to 0. list="tmp"//sshiftoutlist while(fscan(list,x,y) !=EOF) { if(((abs(x))>=0.5) && ((abs(y))>=0.5)) { print(x,y, >> "temp."//sshiftoutlist) filecalc("temp."//sshiftoutlist,"$1;$2",format="%4.0f %4.0f", >> sshiftoutlist) del ("temp."//sshiftoutlist, ver-, >& "dev$null") } else { if((abs(x))<=0.5) { x=0. } if((abs(y))<=0.5) { y=0. } print(x,y, >> "temp."//sshiftoutlist) filecalc("temp."//sshiftoutlist,"$1;$2",format="%4.0f %4.0f", >> sshiftoutlist) del ("temp."//sshiftoutlist, ver-, >& "dev$null") } } del("tmp"//sshiftoutlist,ver-,>&"dev$null") del("temp"//sshiftoutlist,ver-,>&"dev$null") } else { beep print("WARNING! "//sshiftoutlist//" not created (may already exist).") } ## Temporary fix -- correction of zero offsets #if(!ssubpixscale && !access(zzeroname//blk)) { # filecalc(zzeroname,"$1/"//mag2,format="%16.12f", >> zzeroname//blk) # newzzeroname=zzeroname//blk # zzeroname=newzzeroname #} # Clean up. (IRCOADD2 ONLY!) # imdel("@"//rrotlist2, ver-) # del(rrotlist2, ver-) # imdel("@"//bprotlist, ver-) # del(bprotlist, ver-) # del(sshiftoutlist, ver-) if(!norot)print("Images in "//rrotlist//" were rotated to make "//rrotlist2) if(sshiftexactlist!="")print("Next run `ircoadd' w/shifts from "//sshiftoutlist) } else { print("WARNING: stsdas.imgtools package, filecalc, or fileroot not loaded!") print("Please load the appropriate package or task and restart this task.") } print(" ") if(echog)beep end ./irshift.cl0100644000151400000240000003431707124504731012164 0ustar phallgames#irshift.cl--script to find offsets for a set of images. # # Task calls following other tasks: fileroot, filecalc. # # Output: # prefix.refcoords.suffix registration objects' reference image coords # prefix.allcoords.suffix registration objects' coordinates in all images # prefix.offsets.suffix final shifts logfile, + coarse and final shifts # prefix.imshifts.suffix image names and rounded int. shifts on same line # prefix.shiftfrac.suffix fractional part of final shifts # prefix.shiftint.suffix integer part of final shifts # prefix.roundoff.suffix final shifts rounded off to integer shifts # (optional): # @flatlist//suffix.imh fractionally-shifted images # flatlist//suffix list of fractionally-shifted images # # CHANGES: # 940815: changed bad pixel replacement to be done ifr fractional shifting done # 940816: output filenames no longer std names to facilitate rerunning of task # 940826: added rounded-off integer shift computation # 940909: irshift2 (?) # 950201: eliminated need for typing in xref and yref in interactive mode # 950214: eliminated need for manual editing of intermediate files # 960307: added output "shiftexact" file # 961212: added output "imshifts" file # 970513: fixed bug which made offsets -0.5 < offsets < 0.5 round to 1. not 0 # 980320: added displayim param & started updating to V2.11 # 990222: added ptv option # 990306: added option to display only image section during allcoords creation # 990309: added editfiles parameter # 990407: use new optimum method to calculate rounded-off integer shifts # 990413: added "flpr; flpr; flpr" after "filecalc" to avoid erratic errors # 990419: use "temp."//rroundname not temp_rroundname to avoid other errors # # **edit for sqiid to cut interactive time by 3 # **xref,yref are integers... ok to switch to real. # --should interpolate over bad pixels before shifting # --might use iteravg to automatically reject extended objects in refcoords procedure irshift(flatlist,refimage,prefix,suffix) string flatlist {prompt="List of images for which to find offsets (no @)"} string refimage {prompt="Name of (flattened) reference image"} string prefix {prompt="Prefix string for output files"} string suffix {prompt="Suffix string for output files"} bool fracshift=no {prompt="Create fractional-pixel-offset images?"} string interp {"poly5",enum="nearest|linear|poly3|poly5|spline3",prompt="Interpolation type"} string boundary {"nearest",enum="constant|nearest|reflect|wrap",prompt="Boundary type"} string badmask="" {prompt="Bad pixel mask for shifted images (blank=old mask)",mode="q"} bool useimages=yes {prompt="Measure shifts from images instead of a file?"} bool displayim=yes {prompt="Display images for imexam?"} bool ptv=no {prompt="Use phat.ptv instead of display in imexam?"} string imsection="" {prompt="Image section to display in imexam?"} bool editfiles=yes {prompt="Display coords files for editing?"} string inputlist {prompt="File with coordinate info", mode="q"} bool combdata=no {prompt="Combine shifts with earlier dataset?"} real xshiftold {prompt="Reference image x shift in earlier dataset"} real yshiftold {prompt="Reference image y shift in earlier dataset"} real radius=5. {prompt="Imexamine aperture photometry radius"} real buffer=10. {prompt="Imexamine sky buffer"} real width=10. {prompt="Imexamine sky annulus width"} real bs=9. {prompt="Centering box size for final shift calculation"} bool echog {yes,prompt="Beep when task is done?"} struct *iinputlist struct *list begin string rrefimage, fflatlist, rrefcoords, aallcoords, bbadmask, rroundname, ext string sshiftlist, coarsefile, ooffname, ssuffix, iintname, ffracname, ooptname string pprefix, logoffname, sl, sx, img, iinterp, bboundary, im_section real p, pixscale, stcoordx, stcoordy, nrows, ncols, delx, dely, adelx, adely real xold, yold, bbs, xxshiftold, yyshiftold, xshiftnew, yshiftnew, astcoordx real astcoordy, nl, nx, x, y, xoff, yoff real new_x, new_y, old_x, old_y, exact_x, exact_y, step, step_x, step_y int xref, yref, int_x, int_y bool uuseimages, ffracshift, ccombdata, go, ddisplayim, edit_files # The "go" parameter won't let the task run if you haven't loaded the ctio pkg. go=yes if(!deftask("filecalc")) {go=no} if(!deftask("fileroot")) {go=no} if(ptv && !deftask("ptv")) {go=no} if(go) { fflatlist = flatlist rrefimage = refimage pprefix = prefix ssuffix = suffix ffracshift = fracshift if(ffracshift)bbadmask=badmask uuseimages = useimages ddisplayim = displayim im_section = imsection edit_files = editfiles ccombdata = combdata bbs = bs ooffname = pprefix//".shiftexact."//ssuffix logoffname = pprefix//".offsets."//ssuffix rrefcoords = pprefix//".refcoords."//ssuffix aallcoords = pprefix//".allcoords."//ssuffix coarsefile = pprefix//".coarse."//ssuffix iintname = pprefix//".shiftint."//ssuffix ffracname = pprefix//".shiftfrac."//ssuffix rroundname = pprefix//".roundoff."//ssuffix if(ccombdata){ print(" ") print("===> So you wanna add some new images to an old coadd, eh? Well, first make") print("===> sure you're using the same reference image as that old set. Then, take") print("===> a look at the *.offsets.* file from that set, find the fractional") print("===> offsets made on the reference image, and enter them here:") xxshiftold=xshiftold yyshiftold=yshiftold } if(ddisplayim){ print(" ") print("===> Get the coordinates (type 'a'), in the reference image, of all objects") print(" you wish to use for registration, starting with the `best' reference") print(" object-- one which appears in all images. Type 'q' when done.") print(" ") rimexam.radius=radius rimexam.buffer=buffer rimexam.width=width if (ptv) { imexam(rrefimage, frame=1, logfile=rrefcoords, keep+, display="ptv(image='$1',frame=$2)") } else { imexam(rrefimage, frame=1, logfile=rrefcoords, keep+) } } # First method: ID objects from images if(uuseimages){ # ... interactively ... if(ddisplayim){ print(" ") print("===> Choose one object that appears in all images, & find the position") print("===> (type 'a') of this best registration object in each frame (hit 'n' to go on") print("===> to the next frame, and 'q' when done). The file containing these positions") print("===> will be displayed for editing when done, in case of mistakes.") print(" ") print("===> If this is the first run of irshift for these images, it is a good idea") print("===> to note which images have bad seeing, tracking, etc. for future reference.") print(" ") if (ptv) { imexam("@"//fflatlist, frame=1, logfile=aallcoords, keep+, display="ptv(image='$1"//im_section//"',frame=$2)") } else { imexam("@"//fflatlist, frame=1, logfile=aallcoords, keep+, display="display(image='$1"//im_section//"',frame=$2)") } } else { # ... or non-interactively ... print("===> Images not displayed.") } if(edit_files){ print(" ") print("===> In case of mistakes, both coordinate files can now be edited.") vi(rrefcoords) vi(aallcoords) } print(" ") print("===> Finding the coarse offsets...") fields (rrefcoords, "1-2") | scan (xref, yref) lintran(aallcoords,x1=0.001,y1=0.001,x2=xref,y2=yref,angle=180, >coarsefile) } # Second method: estimate shifts from telescope offsets if(!uuseimages){ iinputlist=inputlist print("Generating initial shift file from file "//inputlist//".") while (fscan (iinputlist, pixscale, astcoordx, astcoordy, nrows, ncols, adelx, adely) !=EOF) { stcoordx=astcoordx/pixscale stcoordy=astcoordy/pixscale delx=adelx/pixscale dely=adely/pixscale x=stcoordx xold=stcoordx y=stcoordy yold=stcoordy #procedure:i=1 (0,-dely); i=2 (-delx,+dely); i=3 (-delx,-dely); i=4(-delx,+dely) for (i=1; i<=nrows; i+=1) { for (j=1; j<=ncols; j+=1) { y=yold+dely*(-1)**(i+1) print(x, y, >> aallcoords) yold=y } x=xold+delx xold=x y=yold+dely*(-1)**(i+1) yold=y } } print("===> Edit the file with :wq twice.") vi("-c ':g/0\.\ /s//0.00 /g'", aallcoords) vi("-c ':g/0\.$/s//0.00/g'", aallcoords) print(" ") print("===> Type in the reference image offsets (printed 2 lines below) when") print("===> requested, to zero the coordinate system on the reference image.") del("tempsortlist", ver-, >& "dev$null") join(fflatlist, aallcoords, out="tempsortlist") grep(rrefimage,"tempsortlist") del("tempsortlist",ver-) print("===> Finding the coarse offsets...") lintran(aallcoords, x2=xref, y2=yref, angle=180, > coarsefile) } # Common ending for both approaches. print(" ") print("===> Finding the final offsets...") del(logoffname, ver-, >& "dev$null") imcentroid("@"//fflatlist, rrefimage, rrefcoords, shift=coarsefile, boxsize=bbs, > logoffname) del("temp.joinfile", ver-, >& "dev$null") del("temp.joinfile?", ver-, >& "dev$null") # read in length of temp.joinfile0 and cut out last two lines copy(logoffname,"temp.joinfile0") count("temp.joinfile0") | scan (nl) nx=nl-2 head("temp.joinfile0", nlines=nx, >> "temp.joinfile1") # find line on which the string "X-s" appears and cut out that line & all before !grep -n X-s temp.joinfile1 > temp.joinfile2 type("temp.joinfile2") | scan (sl) x=stridx(":",sl) sx=substr(sl,1,x) x=nx-real(sx) tail("temp.joinfile1", nlines=x, >> "temp.joinfile") # Cut down on number of output files print(" ", >> logoffname) print("#Coarse offsets:", >> logoffname) print(" ", >> logoffname) type(coarsefile, >> logoffname) del(coarsefile, ver-) # Create exact shifts list if(ccombdata){ # Extract the new reference image shifts from the offsets file del("temp.joinfile?",ver-, >& "dev$null") grep(rrefimage,"temp.joinfile") | fields ("junk", "2", >> "temp.joinfile3") type("temp.joinfile3") | average >> "temp.joinfile4" xshiftnew=real(average.sum) del("temp.joinfile?",ver-) grep(rrefimage,"temp.joinfile") | fields ("junk", "4", >> "temp.joinfile3") type("temp.joinfile3") | average >> "temp.joinfile4" yshiftnew=real(average.sum) del("temp.joinfile?",ver-) # Want to take the calculated shift ($2 for x), cancel out the newly calculated # reference image shift ($2 - xshiftnew = -xnew+$2 = -1*xnew+$2) and add in # the old reference image shift (xold+(-1*xnew+$2) filecalc("temp.joinfile",xxshiftold//"+(-1*"//xshiftnew//"+$2);"//yyshiftold//"+(-1*"//yshiftnew//"+$4)",format="%8.2f%8.2f ", >> ooffname) flpr; flpr; flpr } else { fields("temp.joinfile", "2,4", >> ooffname) } del("temp.joinfile*", ver-) # Create integer shifts list list=ooffname while(fscan(list,x,y) !=EOF) { print(int(x),int(y), >> iintname) } # Create fractional shifts list join(iintname,ooffname,out="temp.joinfile") filecalc("temp.joinfile","$3-$1;$4-$2",forma="%6.2f%6.2f", >> ffracname) flpr; flpr; flpr # Create optimum rounded-off integer offsets print(" ") print("===> Finding optimum rounded-off integer offsets...") old_x = 999.; old_y = 999. # for each 0.01 pixel step... for (i=-50; i<50; i+=1) { step = i / 100. # print (i) # ...recalculate integer offsets... list=ooffname del (rroundname, ver-, >& "dev$null") del ("temp."//rroundname, ver-, >& "dev$null") while(fscan(list,xoff,yoff) !=EOF) { xoff=xoff+step yoff=yoff+step if(((abs(xoff))>=0.5) && ((abs(yoff))>=0.5)) { print(xoff,yoff, >> "temp."//rroundname) } else { if((abs(xoff))<=0.5) { xoff=0. } if((abs(yoff))<=0.5) { yoff=0. } print(xoff,yoff, >> "temp."//rroundname) } filecalc("temp."//rroundname, "$1;$2", format="%4.0f %4.0f", >> rroundname) flpr; flpr; flpr del ("temp."//rroundname, ver-, >& "dev$null") } del ("temp."//rroundname, ver-, >& "dev$null") # calculate sum of squares of residuals of exact offsets - new integer offsets filecalc (ooffname//","//rroundname, "$1@1-$1@2+"//step) | average (option = "new_sample", >& "dev$null") flpr; flpr; flpr new_x=average.sumsqrs filecalc (ooffname//","//rroundname, "$2@1-$2@2+"//step) | average (option = "new_sample", >& "dev$null") flpr; flpr; flpr new_y=average.sumsqrs if (new_x < old_x) { old_x = new_x step_x = step } if (new_y < old_y) { old_y = new_y step_y = step } } # recalculate final integer offsets list=ooffname del(rroundname,ver-) del ("temp."//rroundname, ver-, >& "dev$null") while(fscan(list,xoff,yoff) !=EOF) { xoff=xoff+step_x yoff=yoff+step_y if(((abs(xoff))>=0.5) && ((abs(yoff))>=0.5)) { print(xoff,yoff, >> "temp."//rroundname) } else { if((abs(xoff))<=0.5) { xoff=0. } if((abs(yoff))<=0.5) { yoff=0. } print(xoff,yoff, >> "temp."//rroundname) } filecalc("temp."//rroundname,"$1;$2",format="%4.0f %4.0f", >>rroundname) flpr; flpr; flpr del ("temp."//rroundname, ver-, >& "dev$null") } del ("temp."//rroundname, ver-, >& "dev$null") print(" ", >> logoffname) print("#Final offsets:", >> logoffname) print(" ", >> logoffname) type(ooffname, >> logoffname) del("temp.joinfile", ver-) join(fflatlist,rroundname,out=pprefix//".imshifts."//ssuffix) # Produce photometric time series from *allcoords* file fields(aallcoords, "7") | graph (title="Flux of centering object as f(image number)", point-) # Create fractional-pixel-shifted images if(ffracshift){ sshiftlist=fflatlist//ssuffix print(" ") print("===> Creating fractional-pixel-shifted images listed in "//sshiftlist//".") list=fflatlist while(fscan(list,img) !=EOF) { fileroot(img,validim+) img=fileroot.root ext=fileroot.extension if(ext!="")ext="."//ext print(img//ssuffix//ext, >> sshiftlist) } iinterp=interp bboundary=boundary imshift("@"//fflatlist, "@"//sshiftlist, shifts=ffracname, interp=iinterp, bound=bboundary) if(bbadmask!="") { hedit("@"//sshiftlist,"BPM",bbadmask,add+,ver-,show-,update+) hedit("@"//sshiftlist,"BPMASK",bbadmask,add+,ver-,show-,update+) } } print("...it is accomplished. Next you should run `ircoadd' using") if(ffracshift)print(sshiftlist//" and "//iintname//" or") print(fflatlist//" and "//rroundname//".") } else { print("WARNING: tasks `filecalc', `fileroot', or package `phat' (if ptv=yes)" print("are not loaded! Please load them and restart this task.") } if(echog)beep end ./irsky.cl0100644000151400000240000005345706722113775011672 0ustar phallgames# irsky.cl -- sky-subtract images using running median sky # # Calls scripts addcomment, fileroot, iterstat, xlist. # Also calls minv and maskstat if object masking is used. # # The products of this routine are: # --skysubbed images: *//skystring # --a file (imagelist//skystring) which contains the names of those images # --the logfile # --optionally: sky images called *//"skyimage"//skystring.imh # # CHANGES: # 900924: dimsum.xslm originally created by Peter Eisenhardt # 921207: Added Boolean parameter premask-- determines if scaling of images # by their medians excludes masked regions. For cases where variation due to # objects exceeds the residual flatfield variation in the input images, this # parameter should be yes. For dim objects and noticeable residual flatfield # problems it should be no. Even with premask-, imcombine will mask out pixels. # 950121: created from dimsum.xslm, replaces old irsky.cl # 950123: adjusted default imcombine parameters away from dimsum default # 950209: begin adjusting object-masking capability # 950522: adjusted tpl subroutine slightly # 960226: explicit request for logfile name # 960313: incorporate holes masks into individual-image bad pixel masks # 960404: fixed minor bugs of bpm for input images being altered # and wrong output names for bp+holes masks # 960413: changed masking to mask w/objmask+bpmask or bpmask, depending, # and premask to work even if objmask=no # 970426: added addition of TPLIMG header card if tpl=yes # 971026: changed to allow gain & rdnoise taken from image headers # 990114: removed scan of UNIX 'time' task due to problem w/LINUX # 990217: added shortcut option for scaling & subtracting sky image # 990307: added addsky option # 990320: added subpattern option # 990406: changed ITERMEAN to ITERMED in scaling of sky image before subtraction # 990419: iter/maskstat addheader+ explicitly if shortcut=yes # 990513: speeded up holesimg creation through logical use of imcalc # 990523: fixed bug of not always deleting "maskmask" procedure irsky(imagelist,skystring,number,objmask,logfile) string imagelist {prompt="List of images to sky subtract"} string skystring {"ss",prompt="Suffix for sky subtracted output images"} int number {8,min=2,prompt="EVEN Number of images to use in sky frame"} bool objmask {no,prompt="Use object masking when constructing skies?"} string logfile="" {prompt="Name of log file"} bool stdpars=yes {prompt="Use standard imcombine params to create sky?"} bool sky_del {yes,prompt="Delete sky images?"} bool same=yes {prompt="Use same suffix for all object masks?",mode="q"} string suffix {prompt="Suffix of object mask",mode="q"} bool subpattern=no {prompt="Subtract pattern noise (before tpl)?"} bool tpl=no {prompt="Do throughput correction on image after skysub?"} string tplname {prompt="FULL Name of throughput correction image"} bool addsky {no, prompt="Add constant median sky level after subtraction?"} bool forcescale {no, prompt="Force recalculation of image medians?"} bool premask {no, prompt="Mask when scaling before creating sky?"} bool csky_del {yes, prompt="Delete csky images?"} bool myway {no, prompt="I want *all* imcombine parameters my way!"} bool shortcut {yes, prompt="Use quick way to scale sky for subtraction?"} pset imskypars {prompt="Imcombine parameters"} bool echog {yes, prompt="Beep when task is done?"} struct *list struct *imglist begin string imlist # equals imagelist int nnumber # equals number int nnnumber # equals number bool oobjmask # equals objmask bool sstdpars # equals stdpars string img # fscanned name of individual input image string ext # extension of individual input image string subimg # sky subtracted output image string skyimg # sky image for image "img" string holesimg # mask identifying "holes" in output image int nsmin # equals nskymin most of the time int nf # number frames in imagelist int ip # number of current image to sky subtract int start, finish # first & last image #'s in list to use for sky real valmed # median value int maxcsky # minimum pixels used int nskyframes # number of sky frames used int nholes # number of pixels found to be in "holes" struct theadline # temporary struct for header information string templist # temporary image list file string sskystring # suffix to append to sky-subtracted images string ssuffix # suffix of object mask images string maskmask, maskfile, filemask # various temporary masks bool scalecalc # calculate image scalings bool ttpl # do throughput correction? bool go # necessary tasks loaded? string ttplname # throughput correction image name string omask # object mask string bpmask # bad pixel mask string bp_mask # bad pixel mask string s_sigma, s_plfile, s_combine, s_reject, s_offsets, s_masktyp string s_scale, s_weight, s_statsec, s_expname, s_zero, llogfile, rrootname string s_rdnoise, s_gain, subpat_list real s_maskval, s_blank, s_lthresh, s_hthresh, s_nlow, s_nhigh, s_nkeep real s_lsigma, s_hsigma, s_pclip, s_grow, s_sigscale real x, valsky bool ssame, short_cut, add_sky, sub_pattern # Get query parameters and initialize # rrootname = rootname imlist = imagelist sskystring = skystring nnnumber = number nnumber = nnnumber / 2 oobjmask = objmask llogfile = logfile sstdpars = stdpars sub_pattern = subpattern ttpl = tpl if (ttpl) ttplname=tplname add_sky = addsky short_cut = shortcut # Imcombine parameters s_sigma = i_sigma s_plfile = i_plfile s_combine = i_combine s_reject = i_reject s_masktyp = i_masktyp s_maskval = i_maskval s_blank = i_blank s_scale = i_scale s_zero = i_zero s_weight = i_weight s_statsec = i_statsec s_expname = i_expname s_lthresh = i_lthresh s_hthresh = i_hthresh s_nlow = i_nlow s_nhigh = i_nhigh s_nkeep = i_nkeep s_lsigma = i_lsigma s_hsigma = i_hsigma s_rdnoise = i_rdnoise s_gain = i_gain s_sigscale = i_sigscale s_pclip = i_pclip s_grow = i_grow # The "go" parameter won't let the task run if the needed tasks aren't loaded. go=yes if(!deftask("addcomment")) {go=no} if(!deftask("fileroot")) {go=no} if(!deftask("iterstat")) {go=no} if(!deftask("xlist")) {go=no} if(!defpac("imgtools")) {go=no} #if(short_cut && !defpac("imgtools")) {go=no} if(oobjmask && !deftask("minv")) {go=no} if(oobjmask && !deftask("maskstat")) {go=no} if(go) { # Miscellaneous del(imlist//sskystring, ver-, >& "dev$null") count(imlist) | scan (nf) if (nnnumber >= nf) { nnnumber = nf - 1 nnumber = nnnumber / 2 print("Number of images to use for sky is too big! Resetting to "//nnnumber//".") } # Set up log file, appending if it already exists if(llogfile == "")llogfile="log."//imlist print("", >> llogfile) print("===> PHIIRS.IRSKY:", >> llogfile) print("===> Input images from "//imlist//" skysubbed with "//nnnumber//" images total", >> llogfile) print("===> with stdpars="/sstdpars//", object masking="/oobjmask//", addsky="//add_sky, >> llogfile) print("", >> llogfile) # Calculate scalings for all frames. If we are using object masking, first # get the name of the object mask from the image header keyword OBJMASK. # If no OBJMASK keyword, insert object mask name into both it and BPM # keywords for later use in imcombine. print("===> Calculating scalings and checking for object masks if desired...") imglist = imlist x=0 while (fscan (imglist, img) !=EOF) { imgets(img,"BPM",>&"dev$null") bpmask=imgets.value if(oobjmask){ fileroot(img,validim+) img=fileroot.root # Check if image has object mask already listed in image header imgets(img,"OBJMASK",>&"dev$null") omask=imgets.value # If not, check to see if same suffix is to be used for all images' objmasks. if(omask=="0" && x==0){ print("No object mask listed in header of image `"//img//"'.") ssame=same if(ssame)ssuffix=suffix if(ssame)print("===> Inserting object mask names into image headers...") x+=1 } # Insert the object mask name in the header if(omask=="0"){ if(ssame){ omask=img//ssuffix//".pl" hedit(img,"OBJMASK",omask,add+,ver-,show-,update+) } else { print("No object mask listed in header of image "//img//".") omask=img//suffix//".pl" hedit(img,"OBJMASK",omask,add+,ver-,show-,update+) } } hedit (img,"BPM",omask,add+,ver-,show-,update+) # If (and only if) BPMASK keyword not already in header, put it there imgets(img,"BPMASK",>&"dev$null") if(imgets.value=="0")hedit(img,"BPMASK",bpmask,add+,ver-,show-,updat+) # Create file to use in premasking maskmask=mktemp("maskmask") imarith(omask,"*",bpmask,maskmask,divzero=0.,pixtype="real",calctype="real",ver-,noact-) } else { maskmask=mktemp("maskmask") imcopy(bpmask,maskmask,ver-) } flpr; flpr; flpr # Calculate the median of the image. If premask=yes, use only unmasked pixels. # Record the median value into the image header with the card SKYMED. # If SKYMED card already exists in the header, do not recalculate unless # the parameter forcescale=yes. scalecalc = forcescale if (!forcescale) { imgets (img,"SKYMED",>&"dev$null") if (imgets.value == "0") scalecalc = yes } if (scalecalc) { if(premask) { iterstat.nsigrej=5. iterstat.maxiter=10 maskstat(img,maskmask,1.,lower=INDEF,upper=INDEF,iterstat+,ver-,printit-) # imdel (maskmask,ver-) } else { iterstat(img,nsigrej=5.,maxiter=10,lower=INDEF,upper=INDEF,print-,ver-) # imdel (maskmask,ver-) } valmed = 1./iterstat.median hedit (img,"SKYMED",valmed,add+,ver-,show-,update+) } imdel (maskmask,ver-) } flpr; flpr; flpr # Begin main loop imglist = imlist ip=0 while (fscan(imglist,img) != EOF) { ip+=1 if (ip-nnumber < 1) { start = 1 finish = 1+nnnumber } else if (ip+nnumber > nf) { start = nf-nnnumber finish = nf } else { start = ip - nnumber finish = ip + nnumber } # Construct lists of input images and masks for this sky image nskyframes = finish - start templist = mktemp("tmp$slm") xlist (imlist,templist,start,finish,ip,prefix="") # Construct sky. If we are using object masking, the parameter imcombine.plfile # is used to create a .pl file called csky_//prefix//img//.pl which, for each # pixel in the sky frame, counts the number of images excluded from the final # average by either pixel masking or rejection. This will later be used to # create the "holes" image. If there are any "holes" (i.e. regions where no # images contributed to the final sky), they are set to the value of the # parameter "imcombine.blank" (0 for stdpars) in the final image. flpr; flpr; flpr # set up sky-subtracted image name and output list fileroot (img,validim+) ext = fileroot.extension if(ext!="")ext="."//ext subimg = fileroot.root//sskystring skyimg = fileroot.root//"skyimage"//sskystring//ext print(subimg//ext, >> imlist//sskystring) print ("Sky subtracting ",fileroot.root," --> ",subimg,": frame ",ip,"w/sky frames "//start//"-"//finish) if (myway) { print("WARNING! Unless certain parameters are set correctly in imskypars,") print("doing things `your way' could cause problems later on with PHIIRS.") imcombine("@"//templist, skyimg, sigma=s_sigma, plfile=s_plfile, combine=s_combine,reject=s_reject, project-, offsets="none", masktype=s_masktyp, maskvalue=s_maskval, blank=s_blank, scale=s_scale, zero=s_zero, weight=s_weight, statsec=s_statsec, expname=s_expname, lthresh=s_lthresh, hthresh=s_hthresh, nlow=s_nlow, nhigh=s_nhigh, nkeep=s_nkeep, mclip+, lsigma=s_lsigma, hsigma=s_hsigma, rdnoise=s_rdnoise, gain=s_gain, sigscale=s_sigscale, pclip=s_pclip, grow=s_grow, logfile='STDOUT', >> llogfile) } else { if (oobjmask) { if(sstdpars){ imcombine("@"//templist,skyimg,sigma="",plfile="csky_"//subimg//".pl",combine="average",reject="ccdclip",project-,offsets="none",masktype="badvalue",maskvalue=0.,blank=0.,scale="!SKYMED",zero="none",weight="none",statsec=s_statsec,expname=s_expname,lthresh=INDEF,hthresh=INDEF,nlow=1,nhigh=1,nkeep=1,mclip+,lsigma=3,hsigma=3,rdnoise=s_rdnoise,gain=s_gain,sigscale=s_sigscale,pclip=s_pclip,grow=s_grow,logfile='STDOUT', >> llogfile) } else { imcombine("@"//templist,skyimg,sigma=s_sigma,plfile="csky_"//subimg//".pl",combine=s_combine,reject=s_reject,project-,offsets="none",masktype="badvalue",maskvalue=0.,blank=s_blank,scale=s_scale,zero=s_zero,weight=s_weight,statsec=s_statsec,expname=s_expname,lthresh=s_lthresh,hthresh=s_hthresh,nlow=s_nlow,nhigh=s_nhigh,nkeep=s_nkeep,mclip+,lsigma=s_lsigma,hsigma=s_hsigma,rdnoise=s_rdnoise,gain=s_gain,sigscale=s_sigscale,pclip=s_pclip,grow=s_grow,logfile='STDOUT', >> llogfile) } } else { if(sstdpars){ imcombine("@"//templist,skyimg,sigma="",plfile="",combine="average",reject="ccdclip",project-,offsets="none",masktype="none",maskvalue=s_maskval,blank=0.,scale="!SKYMED",zero="none",weight="none",statsec=s_statsec,expname=s_expname,lthresh=INDEF,hthresh=INDEF,nlow=1,nhigh=1,nkeep=1,mclip+,lsigma=3,hsigma=3,rdnoise=s_rdnoise,gain=s_gain,sigscale=s_sigscale,pclip=s_pclip,grow=s_grow,logfile='STDOUT', >> llogfile) } else { imcombine("@"//templist,skyimg,sigma=s_sigma,plfile=s_plfile,combine=s_combine,reject=s_reject,project-,offsets="none",masktype=s_masktyp,maskvalue=s_maskval,blank=s_blank,scale=s_scale,zero=s_zero,weight=s_weight,statsec=s_statsec,expname=s_expname,lthresh=s_lthresh,hthresh=s_hthresh,nlow=s_nlow,nhigh=s_nhigh,nkeep=s_nkeep,mclip+,lsigma=s_lsigma,hsigma=s_hsigma,rdnoise=s_rdnoise,gain=s_gain,sigscale=s_sigscale,pclip=s_pclip,grow=s_grow,logfile='STDOUT', >> llogfile) } } } flpr; flpr; flpr # Divide image by sky frame to produce temporary ratio image _sclmsk//img. imdelete ("_sclmsk"//img,ver-,>&"dev$null") imarith(img,"/",skyimg,"_sclmsk"//img,divzero=0., pixtype="real",calctype="real",ver-,noact-) flpr; flpr; flpr # Original slower way of scaling and subtracting sky image if (!short_cut) { # Calculate median of unmasked (sky) pixels in _sclmsk and save in variable # 'valmed'. Delete _sclmsk image afterward. if (oobjmask) { imgets (img,"OBJMASK") maskfile = imgets.value imgets (img,"BPMASK") filemask = imgets.value maskmask=mktemp("maskmask") imarith(filemask,"*",maskfile,maskmask,divzero=0.,pixtype="real",calctype="real",ver-,noact-) iterstat.nsigrej=5 iterstat.maxiter=10 maskstat("_sclmsk"//img,maskmask,1.,lower=0.,upper=INDEF,iterstat+,ver-,printit-,>>llogfile) imdel(maskmask,ver-) } else { iterstat.nsigrej=5 iterstat.maxiter=10 #iterstat("_sclmsk"//img,nsigrej=5.,maxit=10,lower=INDEF,upper=INDEF,pri-,ver-) maskstat("_sclmsk"//img,"!BPMASK",1.,lower=INDEF,upper=INDEF,iterstat+,ver-,print-) } valmed = iterstat.median imdelete ("_sclmsk"//img,ver-) flpr; flpr; flpr # Rescale sky to object frame median imar(skyimg,"*",valmed,skyimg,pix="real",calc="real",ve-) # Subtract pattern noise, and add sky back in if desired if (sub_pattern) { imar(img,"-",skyimg,subimg,pixt="real",calct="real",ver-) subpat_list = mktemp("subpat") print (subimg, >> subpat_list) if (add_sky) { imdel ("addsky_pattern.fits",ver-,>& "dev$null") if (!access("blank_pattern.fits")) imar (subimg, "-", subimg, "blank_pattern.fits", pix="real", calc="real", ver-) imar ("blank_pattern.fits", "-", valmed, "addsky_pattern.fits", pix="real", calc="real", ver-) subpattern (subpat_list, "", startline=1, finishline=512, blankname="addsky_pattern.fits", ver-, useimgs+, saveimgs-) imdel ("addsky_pattern.fits",ver-,>& "dev$null") } else { subpattern (subpat_list, "", startline=1, finishline=512, blankname="blank_pattern.fits", ver-, useimgs+, saveimgs-) } del (subpat_list, ver-) } else { # Don't subtract pattern noise, but subtract sky & poss. add sky level back in. if (add_sky) { imar(skyimg,"-",valmed,skyimg,pix="real",calc="real",ve-) } flpr; flpr; flpr imar(img,"-",skyimg,subimg,pixt="real",calct="real",ve-) flpr; flpr; flpr } # New, speedier shortcut method to scale & subtract sky image } else { imdelete ("_sclmsk"//img,ver-) if (premask) { maskstat(skyimg,"!BPMASK",1.,nsigrej=5.,maxiter=10,lower=INDEF,upper=INDEF,iterstat+,addh+,ver-,print+, >> llogfile) valsky = iterstat.median } else { iterstat(skyimg,nsigrej=5.,maxiter=10,lower=INDEF,upper=INDEF,print+,addh+,ver-, >> llogfile) valsky = iterstat.median } # Get sky image scaling imgets (img,"ITERMED",>&"dev$null") valmed=real(imgets.value)/valsky # Scale & subtract sky image & pattern noise, & add back in sky level if desired if (sub_pattern) { imcalc(img//","//skyimg,subimg,"im1-im2*"//valmed,pi="real",ve-) subpat_list = mktemp("subpat") print (subimg, >> subpat_list) if (add_sky) { imdel ("addsky_pattern.fits",ver-,>& "dev$null") if (!access("blank_pattern.fits")) imar (subimg, "-", subimg, "blank_pattern.fits", pix="real", calc="real", ver-) imar ("blank_pattern.fits", "-", valmed, "addsky_pattern.fits", pix="real", calc="real", ver-) subpattern (subpat_list, "", startline=1, finishline=512, blankname="addsky_pattern.fits", ver-, useimgs+, saveimgs-) imdel ("addsky_pattern.fits",ver-,>& "dev$null") } else { subpattern (subpat_list, "", startline=1, finishline=512, blankname="blank_pattern.fits", ver-, useimgs+, saveimgs-) } del (subpat_list, ver-) } else { # Don't subtract pattern noise, but subtract sky & poss. add sky level back in. if (add_sky) { imcalc(img//","//skyimg,subimg,"im1-im2*"//valmed//"+"//valmed,pi="real",ve-) } else { imcalc(img//","//skyimg,subimg,"im1-im2*"//valmed,pi="real",ve-) } } } # If we are using object masking, find "holes" in the sky subtracted frame # wherever the sky frame had no unrejected pixels entering into the coaverage. if (oobjmask) { holesimg = subimg//".holes.pl" if (access(holesimg)) delete (holesimg,ve-) imstat("csky_"//subimg//".pl",fo-,fields="max") | scan (maxcsky) if (maxcsky == nskyframes) { imstat ("csky_"//subimg,for-,fields="npix",lower=nskyframes,upper=nskyframes) | scan(nholes) print("There are ",nholes," holes in output image ",subimg) print("There are ",nholes," holes in output image ",subimg, >> llogfile) # 0 to nskyframes-1 are OK --> 1 # nskyframes to INDEF are holes --> 0 imcalc("csky_"//subimg//".pl",holesimg,"if im1 .ge. "//nskyframes//" then 0 else 1",ver-) # imcopy("csky_"//subimg//".pl",holesimg,ve-) # imreplace (holesimg,0,lower=0,upper=nskyframes-1) # imreplace (holesimg,1,lower=nskyframes,upper=INDEF) # minv (holesimg,holesimg) imarith (subimg,"*",holesimg,subimg,ver-) # Multiply holes mask into bad pixel mask for that image imgets(subimg,"BPMASK",>&"dev$null") bpmask=imgets.value fileroot (img,validim+) if (access(fileroot.root//skystring//bpmask)) imdelete (fileroot.root//skystring//bpmask,ver-) imarith(bpmask,"*",holesimg,fileroot.root//skystring//bpmask,ver-) # Used to save holes mask & header keyword; now just delete since it's in bpmask hedit(fileroot.root//skystring//bpmask,fields="title",value="Bad Pixel and Sky Holes Mask for "//subimg,add+,ver-,up+,sho-) imdel(holesimg,ver-) hedit(subimg,fields="BPMASK",value=fileroot.root//skystring//bpmask,ad+,ve-,up+,sho-) } if (csky_del) delete ("csky_"//subimg//".pl",ve-) # End if (oobjmask) } # Do throughput correction if desired. if (ttpl) { imar(subimg,"/",ttplname,subimg,ver-) hedit(subimg,fields="TPL",value="TPL correction made using image "//ttplname,add+,ver-,up+,sho-) hedit(subimg,fields="TPLIMG",value=ttplname,add+,ver-,up+,sho-) } # Add comment cards to header of sky subtracted image. del ("_3oogDaTe", ver-, >& "dev$null") !date > _3oogDaTe type ("_3oogDaTe") | scan (theadline) del ("_3oogDaTe", ver-, >& "dev$null") addcomment (subimg,"phiirs.irsky: "//theadline,ver-) addcomment (subimg,"Skysubbed w/"//nnnumber//" images, stdpars="/sstdpars//", objmask="//oobjmask,ver-) # Clean up. if(sky_del){ imdelete(skyimg,ver-) } else { hedit(skyimg,"title","Sky for "//img//" from frames "//start//"-"//finish//" in "//imlist//" normalized by "//valmed,add+,ver-,show-,update+) print(skyimg, >> imlist//"skyimage"//sskystring) } delete(templist,ver-) # End main loop } # Replace BPM keyword with bad pixel mask if(oobjmask){ imglist=imlist while (fscan (imglist, img) !=EOF) { fileroot(img, validim+) ext=fileroot.extension if(ext!="")ext="."//ext subimg=fileroot.root//sskystring//ext imgets(subimg,"BPMASK",>&"dev$null") bpmask=imgets.value hedit(subimg,"BPM",bpmask,add+,ver-,show-,update+) imgets(img,"MASKMASK",>&"dev$null") imdel(maskmask,ver-,>&"dev$null") hedit(img,"MASKMASK","",del+,add-,ver-,show-,update+) } } print("===> Sky-subtracted images listed in "//imlist//sskystring, >> llogfile) if(!sky_del)print("===> Sky-subtracted images listed in "//imlist//"skyimage"//sskystring, >> llogfile) #time | scan (theadline) del ("_4oogDaTe", ver-, >& "dev$null") !date > _4oogDaTe type ("_4oogDaTe") | scan (theadline) del ("_4oogDaTe", ver-, >& "dev$null") print("===> PHIIRS.IRSKY finished at "//theadline, >> llogfile) print("...all done. Sky-subtracted images listed in "//imlist//sskystring//".") if(!sky_del)print("Sky images listed in "//imlist//"skyimage"//sskystring//".") print("Next task to run is `irshift' (or `irshift2' if necessary).") # End if(go) } else { print("WARNING: some/all of the necessary tasks are not loaded!") print("Please load them and restart this task.") } imglist = "" if(echog)beep end ./irsky256.par0100644000151400000240000000312406720573000012262 0ustar phallgamesi_sigma,s,h,"",,,"IMCOMBINE: Sigma image (optional)" i_plfile,s,h,"",,,"IMCOMBINE: Rejected pixel list image (optional)" i_combine,s,h,"median",average|median,,"IMCOMBINE: Type of combine operation (median|average)" i_reject,s,h,"ccdclip",none|minmax|ccdclip|crreject|sigclip|avsigclip|pclip,,"IMCOMBINE: Type of rejection" i_masktyp,s,h,"badvalue",none|goodvalue|badvalue|goodbits|badbits,,"IMCOMBINE: Mask type" i_maskval,r,h,0.,,,"IMCOMBINE: Mask value" i_blank,r,h,1.,,,"IMCOMBINE: Value if there are no pixels" i_scale,s,h,"!SKYMED",,,"IMCOMBINE: Image scaling" i_zero,s,h,"none",,,"IMCOMBINE: Image scaling" i_weight,s,h,"none",,,"IMCOMBINE: Image weights" i_statsec,s,h,"",,,"IMCOMBINE: Image section for computing statistics" i_expname,s,h,"exptime",,,"IMCOMBINE: Image header exposure time keyword" i_lthresh,r,h,INDEF,,,"IMCOMBINE: Lower threshold" i_hthresh,r,h,INDEF,,,"IMCOMBINE: Upper threshold" i_nlow,r,h,1.,0.,,"IMCOMBINE: minmax: Number of low pixels to reject" i_nhigh,r,h,1.,0.,,"IMCOMBINE: minmax: Number of high pixels to reject" i_nkeep,r,h,1.,,,"IMCOMBINE: Minimum to keep (+) or maximum to reject(-)" i_lsigma,r,h,5.,0.,,"IMCOMBINE: Lower sigma clipping factor" i_hsigma,r,h,5.,0.,,"IMCOMBINE: Upper sigma clipping factor" i_rdnoise,s,h,73.,,,"IMCOMBINE: ccdclip: CCD readout noise (electrons)" i_gain,s,h,15.3,,,"IMCOMBINE: ccdclip: CCD gain (electrons/ADU)" i_sigscale,r,h,0.1,0.,,"IMCOMBINE: Tolerance for sig-clip scaling corrections" i_pclip,r,h,-0.5,,,"IMCOMBINE: pclip: Percentile clipping parameter" i_grow,r,h,0.,,,"IMCOMBINE: Radius (pixels) for 1D neighbor rejection" mode,s,h,"q",,, ./imcoaddpars.par0100644000151400000240000000270406671273120013162 0ustar phallgamesi_sigma,s,h,"",,,"IMCOMBINE: Sigma image (optional)" i_plfile,s,h,"",,,"IMCOMBINE: Rejected pixel list image (optional)" i_combine,s,h,"average",average|median,,"IMCOMBINE: Type of combine operation (median|average)" i_reject,s,h,"sigclip",none|minmax|ccdclip|crreject|sigclip|avsigclip|pclip,,"IMCOMBINE: Type of rejection" i_masktyp,s,h,"badvalue",none|goodvalue|badvalue|goodbits|badbits,,"IMCOMBINE: Mask type" i_maskval,r,h,0.,,,"IMCOMBINE: Mask value" i_blank,r,h,0.,,,"IMCOMBINE: Value if there are no pixels" i_statsec,s,h,"",,,"IMCOMBINE: Image section for computing statistics" i_expname,s,h,"exptime",,,"IMCOMBINE: Image header exposure time keyword" i_lthresh,r,h,INDEF,,,"IMCOMBINE: Lower threshold" i_hthresh,r,h,INDEF,,,"IMCOMBINE: Upper threshold" i_nlow,r,h,1.,0.,,"IMCOMBINE: minmax: Number of low pixels to reject" i_nhigh,r,h,1.,0.,,"IMCOMBINE: minmax: Number of high pixels to reject" i_nkeep,r,h,1.,,,"IMCOMBINE: Minimum to keep (+) or maximum to reject(-)" i_lsigma,r,h,5.,0.,,"IMCOMBINE: Lower sigma clipping factor" i_hsigma,r,h,5.,0.,,"IMCOMBINE: Upper sigma clipping factor" i_rdnoise,s,h,"25.",,,"IMCOMBINE: ccdclip: CCD readout noise (electrons)" i_gain,s,h,"8.",,,"IMCOMBINE: ccdclip: CCD gain (electrons/ADU)" i_sigscale,r,h,0.1,0.,,"IMCOMBINE: Tolerance for sig-clip scaling corrections" i_pclip,r,h,-0.5,,,"IMCOMBINE: pclip: Percentile clipping parameter" i_grow,r,h,0.,,,"IMCOMBINE: Radius (pixels) for 1D neighbor rejection" mode,s,h,"q",,, ./irskyirim.par0100644000151400000240000000312506720573000012707 0ustar phallgamesi_sigma,s,h,"",,,"IMCOMBINE: Sigma image (optional)" i_plfile,s,h,"",,,"IMCOMBINE: Rejected pixel list image (optional)" i_combine,s,h,"median",average|median,,"IMCOMBINE: Type of combine operation (median|average)" i_reject,s,h,"ccdclip",none|minmax|ccdclip|crreject|sigclip|avsigclip|pclip,,"IMCOMBINE: Type of rejection" i_masktyp,s,h,"badvalue",none|goodvalue|badvalue|goodbits|badbits,,"IMCOMBINE: Mask type" i_maskval,r,h,0.,,,"IMCOMBINE: Mask value" i_blank,r,h,1.,,,"IMCOMBINE: Value if there are no pixels" i_scale,s,h,"!SKYMED",,,"IMCOMBINE: Image scaling" i_zero,s,h,"none",,,"IMCOMBINE: Image scaling" i_weight,s,h,"none",,,"IMCOMBINE: Image weights" i_statsec,s,h,"",,,"IMCOMBINE: Image section for computing statistics" i_expname,s,h,"exptime",,,"IMCOMBINE: Image header exposure time keyword" i_lthresh,r,h,INDEF,,,"IMCOMBINE: Lower threshold" i_hthresh,r,h,INDEF,,,"IMCOMBINE: Upper threshold" i_nlow,r,h,1.,0.,,"IMCOMBINE: minmax: Number of low pixels to reject" i_nhigh,r,h,1.,0.,,"IMCOMBINE: minmax: Number of high pixels to reject" i_nkeep,r,h,1.,,,"IMCOMBINE: Minimum to keep (+) or maximum to reject(-)" i_lsigma,r,h,5.,0.,,"IMCOMBINE: Lower sigma clipping factor" i_hsigma,r,h,5.,0.,,"IMCOMBINE: Upper sigma clipping factor" i_rdnoise,s,h,35.,,,"IMCOMBINE: ccdclip: CCD readout noise (electrons)" i_gain,s,h,10.46,,,"IMCOMBINE: ccdclip: CCD gain (electrons/ADU)" i_sigscale,r,h,0.1,0.,,"IMCOMBINE: Tolerance for sig-clip scaling corrections" i_pclip,r,h,-0.5,,,"IMCOMBINE: pclip: Percentile clipping parameter" i_grow,r,h,0.,,,"IMCOMBINE: Radius (pixels) for 1D neighbor rejection" mode,s,h,"q",,, ./irskyirtf.par0100644000151400000240000000313406720573000012713 0ustar phallgamesi_sigma,s,h,"",,,"IMCOMBINE: Sigma image (optional)" i_plfile,s,h,"",,,"IMCOMBINE: Rejected pixel list image (optional)" i_combine,s,h,"median",average|median,,"IMCOMBINE: Type of combine operation (median|average)" i_reject,s,h,"ccdclip",none|minmax|ccdclip|crreject|sigclip|avsigclip|pclip,,"IMCOMBINE: Type of rejection" i_masktyp,s,h,"badvalue",none|goodvalue|badvalue|goodbits|badbits,,"IMCOMBINE: Mask type" i_maskval,r,h,0.,,,"IMCOMBINE: Mask value" i_blank,r,h,1.,,,"IMCOMBINE: Value if there are no pixels" i_scale,s,h,"!SKYMED",,,"IMCOMBINE: Image scaling" i_zero,s,h,"none",,,"IMCOMBINE: Image scaling" i_weight,s,h,"none",,,"IMCOMBINE: Image weights" i_statsec,s,h,"",,,"IMCOMBINE: Image section for computing statistics" i_expname,s,h,"exptime",,,"IMCOMBINE: Image header exposure time keyword" i_lthresh,r,h,-100000.,,,"IMCOMBINE: Lower threshold" i_hthresh,r,h,100000.,,,"IMCOMBINE: Upper threshold" i_nlow,r,h,1.,0.,,"IMCOMBINE: minmax: Number of low pixels to reject" i_nhigh,r,h,1.,0.,,"IMCOMBINE: minmax: Number of high pixels to reject" i_nkeep,r,h,1.,,,"IMCOMBINE: Minimum to keep (+) or maximum to reject(-)" i_lsigma,r,h,5.,0.,,"IMCOMBINE: Lower sigma clipping factor" i_hsigma,r,h,5.,0.,,"IMCOMBINE: Upper sigma clipping factor" i_rdnoise,s,h,"rn",,,"IMCOMBINE: ccdclip: CCD readout noise (electrons)" i_gain,s,h,"gain",,,"IMCOMBINE: ccdclip: CCD gain (electrons/ADU)" i_sigscale,r,h,0.1,0.,,"IMCOMBINE: Tolerance for sig-clip scaling corrections" i_pclip,r,h,-0.5,,,"IMCOMBINE: pclip: Percentile clipping parameter" i_grow,r,h,0.,,,"IMCOMBINE: Radius (pixels) for 1D neighbor rejection" mode,s,h,"q",,, ./irskykir.par0100644000151400000240000000314106720573000012532 0ustar phallgamesi_sigma,s,h,"",,,"IMCOMBINE: Sigma image (optional)" i_plfile,s,h,"",,,"IMCOMBINE: Rejected pixel list image (optional)" i_combine,s,h,"median",average|median,,"IMCOMBINE: Type of combine operation (median|average)" i_reject,s,h,"ccdclip",none|minmax|ccdclip|crreject|sigclip|avsigclip|pclip,,"IMCOMBINE: Type of rejection" i_masktyp,s,h,"badvalue",none|goodvalue|badvalue|goodbits|badbits,,"IMCOMBINE: Mask type" i_maskval,r,h,0.,,,"IMCOMBINE: Mask value" i_blank,r,h,1.,,,"IMCOMBINE: Value if there are no pixels" i_scale,s,h,"!SKYMED",,,"IMCOMBINE: Image scaling" i_zero,s,h,"none",,,"IMCOMBINE: Image scaling" i_weight,s,h,"none",,,"IMCOMBINE: Image weights" i_statsec,s,h,"",,,"IMCOMBINE: Image section for computing statistics" i_expname,s,h,"exptime",,,"IMCOMBINE: Image header exposure time keyword" i_lthresh,r,h,-100000.,,,"IMCOMBINE: Lower threshold" i_hthresh,r,h,100000.,,,"IMCOMBINE: Upper threshold" i_nlow,r,h,1.,0.,,"IMCOMBINE: minmax: Number of low pixels to reject" i_nhigh,r,h,1.,0.,,"IMCOMBINE: minmax: Number of high pixels to reject" i_nkeep,r,h,1.,,,"IMCOMBINE: Minimum to keep (+) or maximum to reject(-)" i_lsigma,r,h,5.,0.,,"IMCOMBINE: Lower sigma clipping factor" i_hsigma,r,h,5.,0.,,"IMCOMBINE: Upper sigma clipping factor" i_rdnoise,s,h,"rdnoise",,,"IMCOMBINE: ccdclip: CCD readout noise (electrons)" i_gain,s,h,"gain",,,"IMCOMBINE: ccdclip: CCD gain (electrons/ADU)" i_sigscale,r,h,0.1,0.,,"IMCOMBINE: Tolerance for sig-clip scaling corrections" i_pclip,r,h,-0.5,,,"IMCOMBINE: pclip: Percentile clipping parameter" i_grow,r,h,0.,,,"IMCOMBINE: Radius (pixels) for 1D neighbor rejection" mode,s,h,"q",,, ./irskyonis.par0100644000151400000240000000313506720573000012720 0ustar phallgamesi_sigma,s,h,"",,,"IMCOMBINE: Sigma image (optional)" i_plfile,s,h,"",,,"IMCOMBINE: Rejected pixel list image (optional)" i_combine,s,h,"median",average|median,,"IMCOMBINE: Type of combine operation (median|average)" i_reject,s,h,"ccdclip",none|minmax|ccdclip|crreject|sigclip|avsigclip|pclip,,"IMCOMBINE: Type of rejection" i_masktyp,s,h,"badvalue",none|goodvalue|badvalue|goodbits|badbits,,"IMCOMBINE: Mask type" i_maskval,r,h,0.,,,"IMCOMBINE: Mask value" i_blank,r,h,1.,,,"IMCOMBINE: Value if there are no pixels" i_scale,s,h,"!SKYMED",,,"IMCOMBINE: Image scaling" i_zero,s,h,"none",,,"IMCOMBINE: Image scaling" i_weight,s,h,"none",,,"IMCOMBINE: Image weights" i_statsec,s,h,"",,,"IMCOMBINE: Image section for computing statistics" i_expname,s,h,"exptime",,,"IMCOMBINE: Image header exposure time keyword" i_lthresh,r,h,-100000.,,,"IMCOMBINE: Lower threshold" i_hthresh,r,h,100000.,,,"IMCOMBINE: Upper threshold" i_nlow,r,h,1.,0.,,"IMCOMBINE: minmax: Number of low pixels to reject" i_nhigh,r,h,1.,0.,,"IMCOMBINE: minmax: Number of high pixels to reject" i_nkeep,r,h,1.,,,"IMCOMBINE: Minimum to keep (+) or maximum to reject(-)" i_lsigma,r,h,5.,0.,,"IMCOMBINE: Lower sigma clipping factor" i_hsigma,r,h,5.,0.,,"IMCOMBINE: Upper sigma clipping factor" i_rdnoise,s,h,"35.0",,,"IMCOMBINE: ccdclip: CCD readout noise (electrons)" i_gain,s,h,"4.0",,,"IMCOMBINE: ccdclip: CCD gain (electrons/ADU)" i_sigscale,r,h,0.1,0.,,"IMCOMBINE: Tolerance for sig-clip scaling corrections" i_pclip,r,h,-0.5,,,"IMCOMBINE: pclip: Percentile clipping parameter" i_grow,r,h,0.,,,"IMCOMBINE: Radius (pixels) for 1D neighbor rejection" mode,s,h,"q",,, ./myget.cl0100644000151400000240000000160206561402072011627 0ustar phallgames# myget--script to "get_ir2" lots of files at once using wildcard specifications procedure myget(filename) string filename {prompt = "Files to process"} bool stats=yes {prompt = "Display image statistics?"} string logfile="STDOUT" {prompt = "Name of logfile for imstat output"} bool display=no {prompt = "Display image?"} int frame="1" {prompt = "Frame in which to display image"} struct *namelist begin string ffilename,namefile,f,llogfile ffilename = filename llogfile = logfile namefile = mktemp("tmp$name") namelist = namefile files(ffilename,sort+,>namefile) while (fscan(namelist,f) != EOF) { print(f) get_ir2(osfn(f)) imrename(f,f//".tmp",ver-) imcopy(f//".tmp",f,ver-) imdel(f//".tmp",ver-) if (display) { display(f, frame) } # imstat(f, >> llogfile) } if (stats) { imstat("@"//namefile, >> llogfile) } namelist = "" delete(namefile,ver-) end ./photscale2.awk0100644000151400000240000000543106173000133012725 0ustar phallgames# awk script used by the PHIIRS routine photscale to measure photometric # variations from frame to frame over an observing sequence. This routine # uses the formatted output from PHIIRS routine photcheck + awk script # photcheck.awk as its input. # # This version deals with aperture corrections in col 1, image name and # airmass in cols 2 & 3, and mag,err pairs for each reference star # in even and odd numbered columns thereafter. # # The first line of the input file is considered to be the photometry for the # "reference frame." Magnitudes of stars in each subsequent line are compared # to it, and the average and rms of the magnitude differences is output in both # magnitude and flux form, along with the individual stellar magnitude # differences. Magnitude and error records that are INDEF are ignored. # # originally created 3 August 1993 by Mark Dickinson # modified March 1996 by Pat Hall # { # # Record magnitudes from first line as reference values. # if (NR==1) { ii=0 nn=0 for (i=4;i<=NF;i+=2) { ii+=1 if ($i == "INDEF") { m[ii] = -99.99 v[ii] = -99.99 } else { nn+=1 m[ii] = $i + $1 v[ii] = $(i+1)*$(i+1) } } printf ("%26s %7s %7s %6s %7s %6s %2g ",$2,"airmass","delta_m"," err_m","scaling"," err_s",nn) ii=0 for (i=4;i<=NF;i+=2) { ii+=1 if ($i == "INDEF") { printf (" %6s", " INDEF") } else { printf (" %6.3f", m[ii]) } } printf ("\n") # # For all other lines, calculate differences between the star magnitudes and # the reference values, print these out, and calculate the mean and rms of # those differences, then print those out at the end of the line. Stars with # magnitude values = INDEF are excluded from the mean and rms calculation. # } else { printf ("%26s %7.4f ",$2,$3) dsum = 0. wsum = 0. nn = 0 ii=0 for (i=4;i<=NF;i+=2) { ii+=1 if ($i != "INDEF" && m[ii] != -99.99) { d[ii] = m[ii] - $i - $1 vd[ii] = $(i+1)*$(i+1) + v[ii] dsum += d[ii]/vd[ii] wsum += 1./vd[ii] nn += 1 } else { d[ii] = -99.99 } } if (nn > 0) { dmean = dsum / wsum derr = sqrt(1./wsum) # # New mean & error in flux, not magnitude, units # # nmean = exp(log(10.0)*dmean/2.5) # nmean = exp(log(10.0)*dmean/-2.5) nerr = 0.4*log(10.0)*nmean*derr printf ("%7.3f %6.3f %7.3f %6.3f %2g ", dmean, derr, nmean, nerr, nn) } else { printf ("%7s %6s %7s %6s %2g "," INDEF"," INDEF"," INDEF"," INDEF", 0) } ii=0 for (i=4;i<=NF;i+=2) { ii+=1 if ($i != "INDEF" && m[ii] != -99.99) { printf (" %6.3f", d[ii]) } else { printf (" %6s"," INDEF") } } printf ("\n") } } # i column # ii star counter # nn good star counter # m[ii] magref # v[ii] varref # d[ii] magref - mag # vd[ii] varref + var # dsum sum of d[] # wsum sum of vd[] ./photscalenew.awk0100644000151400000240000000667006670310733013377 0ustar phallgames# awk script used by the PHIIRS routine photscale to measure photometric # variations from frame to frame over an observing sequence. This routine # uses the formatted output from PHIIRS routine photcheck + awk script # photcheck.awk as its input. # # The format of that file is one line for each image, with image name and # airmass in cols 1 & 2, and mag,err pairs for each reference star # in odd and even numbered columns thereafter. # # The first line of that input file is considered to be the photometry for the # "reference frame." Magnitudes of stars in each subsequent line are compared # to it, and the average and rms of the magnitude differences is output in both # magnitude and flux form, along with the individual stellar magnitude # differences. Magnitude and error records that are INDEF are ignored. # # originally created 3 August 1993 by Mark Dickinson # modified March 1996 by Pat Hall # { # # Record magnitudes from first line as reference values. # if (NR==1) { ii=0 nn=0 for (i=3;i<=NF;i+=2) { ii+=1 if ($i == "INDEF") { m[ii] = -99.99 v[ii] = -99.99 } else { nn+=1 m[ii] = $i v[ii] = $(i+1)*$(i+1) } } printf ("%26s %7s %7s %6s %7s %6s %2g ",$1,"airmass","delta_m"," err_m","scaling"," err_s",nn) ii=0 for (i=3;i<=NF;i+=2) { ii+=1 if ($i == "INDEF") { printf (" %6s", " INDEF") } else { printf (" %6.3f", m[ii]) } } printf ("\n") # # For all other lines, calculate differences between the star magnitudes and # the reference values, print these out, and calculate the mean and rms of # those differences, then print those out at the end of the line. Stars with # magnitude values = INDEF or with (mag, err) = (0.000, 0.000) caused by too- # bright stars (true mag <= -10.000) are excluded from the mean and rms # calculations. # } else { printf ("%26s %7.4f ",$1,$2) dsum = 0. wsum = 0. nn = 0 ii=0 for (i=3;i<=NF;i+=2) { ii+=1 if (($i != "INDEF" && m[ii] != -99.99) && ($i != "0.000" && m[ii] != 0.000)) { d[ii] = m[ii] - $i vd[ii] = $(i+1)*$(i+1) + v[ii] dsum += d[ii]/vd[ii] wsum += 1./vd[ii] nn += 1 } else { d[ii] = -99.99 } } if (nn > 0) { dmean = dsum / wsum derr = sqrt(1./wsum) # # Redo using 5 sigma rejection of too-bright magnitudes # dsum = 0. wsum = 0. nn = 0 ii=0 for (i=3;i<=NF;i+=2) { ii+=1 if (($i != "INDEF" && m[ii] != -99.99) && ($i != "0.000" && m[ii] != 0.000)) { d[ii] = m[ii] - $i vd[ii] = $(i+1)*$(i+1) + v[ii] if (d[ii] > dmean-5*derr) { dsum += d[ii]/vd[ii] wsum += 1./vd[ii] nn += 1 } else { d[ii] = -99.99 } } else { d[ii] = -99.99 } } if (nn > 0) { dmean = dsum / wsum derr = sqrt(1./wsum) # # New mean & error in flux, not magnitude, units # # nmean = exp(log(10.0)*dmean/2.5) # nmean = exp(log(10.0)*dmean/-2.5) nerr = 0.4*log(10.0)*nmean*derr printf ("%7.3f %6.3f %7.3f %6.3f %2g ", dmean, derr, nmean, nerr, nn) } else { printf ("%7s %6s %7s %6s %2g "," INDEF"," INDEF"," INDEF"," INDEF", 0) } ii=0 for (i=3;i<=NF;i+=2) { ii+=1 if ($i != "INDEF" && m[ii] != -99.99) { printf (" %6.3f", d[ii]) } else { printf (" %6s"," INDEF") } } printf ("\n") } } # i column # ii star counter # nn good star counter # m[ii] magref # v[ii] varref # d[ii] magref - mag # vd[ii] varref + var # dsum sum of d[] # wsum sum of vd[] ./precoadd.cl0100644000151400000240000001660606561402202012270 0ustar phallgames# precoadd -- prepare images w/same pixel scales but dif't sizes for coadding # # Calls fileroot (old version also called minv, imcalc) # # 970402: created # 970430: added TPL division option # 970507: added iterstat lower=-10000. # # **ASSUMES that bad pixel masks originally have bad pixels = zero procedure precoadd(listsmall,imgbig) string listsmall {prompt="List of smaller-size images"} string imgbig {prompt="Sample larger-size image"} bool tpl=no {prompt="Divide by throughput correction image first?"} string tplimg {prompt="Name of throughput correction image"} #bool badzero=yes {prompt="Do bad pixels in masks have value of 0?"} bool delorig=no {prompt="Delete original images?"} bool echog {yes,prompt="Beep when task is done?"} begin string img, llistsmall, bigimg, tmpzero, bpimage, bpimg, origlist, plistsmall string bplist, origimg, image, intcosca, ttplimg real s_maskval int smallx, smally, ncoadds, bigx, bigy bool ddelorig,go,ttpl #bool bbadzero struct theadline # Set up parameters llistsmall = listsmall plistsmall = "p_"//llistsmall del(plistsmall,ver-,>&"dev$null") bplist = "bp_"//llistsmall del(bplist,ver-,>&"dev$null") bigimg = imgbig ttpl=tpl if(ttpl)ttplimg=tplimg #bbadzero=badzero ddelorig=delorig # Certain tasks/packages must be loaded for task to run. go=yes #if(!defpac("imgtools")) {go=no} if(!deftask("fileroot")) {go=no} #if(!deftask("minv")) {go=no} if(go) { # Scale images by NUMBER OF INTERNAL COADDS list=llistsmall print("Scaling by the number of internal coadds if necessary...") while (fscan (list, img) !=EOF) { # Check: has this scaling already been done? Look for INTCOSCA header card imgets(img, "intcosca", >& "dev$null") intcosca=str(imgets.value) # If so, nothing is done. # If not, look for the "coadds" header card (from 4m & later first.cl versions) if(intcosca=="0") { imgets(img, "coadds", >& "dev$null") ncoadds=int(imgets.value) # If no "coadds" header card, search for the "ncoadds" header card. It is # usually only found in 'fits256.e' images (ie laird-type), but does not run # the risk of being confused with any other comment cards in the image header, # so it is looked for first. if(ncoadds==0) { imgets(img,"ncoadds", >& "dev$null") ncoadds=int(imgets.value) # If no "ncoadds" header card, get ncoadds from the comment card if(ncoadds==0) { imgets(img,"comment", >& "dev$null") ncoadds=int(substr(imgets.value,strlen(imgets.value),strlen(imgets.value))) } } # Unless ncoadds=1 or 0, multiply through if(ncoadds!=1 && ncoadds!=0) imar(img,"*",ncoadds,img) # Add INTCOSCA header card hedit(img,"INTCOSCA","Internal coadd scaling by factor "//ncoadds//" DONE",add+,ver-,show-,update+) } } list="" tmpzero=mktemp("zero") imgets(bigimg,"i_naxis1"); bigx=int(imgets.value) imgets(bigimg,"i_naxis2"); bigy=int(imgets.value) imar (bigimg, "-", bigimg, tmpzero, ver-, noact-) print ("Copying into larger-size blank images and creating bad pixel images...") list=llistsmall while (fscan (list,img) != EOF) { # Divide by tpl image if desired if(ttpl){ imgets(img,"TPLIMG") if(imgets.value=="0"){ imar (img, "/", ttplimg, img, divzero=0., ver-, noact-) hedit (img,"TPLIMG",ttplimg,add+,ver-,update+,show-) } else { print ("TPL division not done -- image already has TPLIMG header keyword") } } # Copy smaller-size image into subregions of larger-size images imgets(img,"i_naxis1"); smallx=int(imgets.value) imgets(img,"i_naxis2"); smally=int(imgets.value) if ((smallx==bigx) && (smally==bigy)) { imcopy (img, "p_"//img, ver-) print ("p_"//img, >> plistsmall) } else { imcopy (tmpzero, "p_"//img, ver-) print ("p_"//img, >> plistsmall) imcopy (img, "p_"//img//"[1:"//smallx//",1:"//smally//"]", ver-) imgets(img,"airmass") hedit("p_"//img,"airmass",imgets.value,add+,ver-,show-,update+) imgets(img,"objmask") hedit("p_"//img,"objmask",imgets.value,add+,ver-,show-,update+) imgets(img,"bpmask") hedit("p_"//img,"bpmask",imgets.value,add+,ver-,show-,update+) imgets(img,"bpm") hedit("p_"//img,"bpm",imgets.value,add+,ver-,show-,update+) imgets(img,"intcosca") hedit("p_"//img,"intcosca",imgets.value,add+,ver-,show-,update+) imgets(img,"exptime") hedit("p_"//img,"exptime",imgets.value,add+,ver-,show-,update+) imgets(img,"itime") hedit("p_"//img,"itime",imgets.value,add+,ver-,show-,update+) } imgets (img,"BPMASK"); bpimg=str(imgets.value) fileroot(bpimg,validim+); bpimage=fileroot.root # If larger-size bad pixel mask doesn't already exist... if(!access("bp_"//bpimage//".pl")) { # ...copy smaller-size bad pixel mask into subregions of larger-size mask imdel ("t_"//bpimage//".pl", ver-, >& "dev$null") imcopy (tmpzero, "t_"//bpimage//".pl", ver-) imcopy (bpimage, "t_"//bpimage//".pl[1:"//smallx//",1:"//smally//"]", ver-) # ...invert so that bad pixels are equal to one (temporarily) if not already so # if(bbadzero){ # minv("t_"//bpimage//".pl", "bp_"//bpimage//".pl") # imdel ("t_"//bpimage//".pl", ver-) # } else { imren ("t_"//bpimage//".pl", "bp_"//bpimage//".pl", ver-) # } # Invert existing larger-size bad pixel mask if necessary # } else { # if(bbadzero){ # imdel ("t_"//bpimage//".pl", ver-, >& "dev$null") # minv ("bp_"//bpimage//".pl", "t_"//bpimage//".pl") # imdel ("bp_"//bpimage//".pl", ver-) # imren ("t_"//bpimage//".pl", "bp_"//bpimage//".pl", ve-) # } } if(!access(bplist)) { print ("bp_"//bpimage//".pl", >> bplist) } hedit ("p_"//img,"BPMASK","bp_"//bpimage//".pl",add+,ver-,show-,update+) hedit ("p_"//img,"BPM","bp_"//bpimage//".pl",add+,ver-,show-,update+) hedit ("p_"//img,"ORIGIMG",img,add+,ver-,show-,update+) } if(ddelorig){ print ("Deleting original images...") imdel("@"//llistsmall, ver-) } else { print ("Renaming original images...") list=llistsmall origlist=llistsmall//"orig" del(origlist,ver-,>&"dev$null") while (fscan (list,img) != EOF) { imren (img, "orig"//img, ver-) print ("orig"//img, >> origlist) } } print ("Creating final larger-size images with bad pixels set to -99999.") list=plistsmall # Create final larger-size images with bad pixels set to -99999. while (fscan (list,img) != EOF) { imgets (img,"BPMASK") bpimg=str(imgets.value) imgets (img,"ORIGIMG") origimg=str(imgets.value) imar (img, "/", bpimg, origimg, divz=-99999., ver-) # imcalc (img//","//bpimg, origimg, "im1-im2*99999", ver-) } #if(bbadzero){ # print ("Fixing bad pixel masks so bad pixels = 0...") # list=bplist # while (fscan (list,img) != EOF) { # fileroot(img,validim+) # image=fileroot.root # minv (image, "t_"//image//".pl") # imdel (image//".pl", ver-) # imren ("t_"//image//".pl", image//".pl", ver-) # } #} print ("Deleting temporary images...") imdel (tmpzero, ver-) imdel ("@"//plistsmall, ver-) del (plistsmall, ver-) print ("Getting robust statistics...") iterstat ("@"//llistsmall, lower=-10000., upper=INDEF, nsig=5., maxiter=10, print+, ver-, >> "stats_"//llistsmall) print("Images in "//llistsmall//" now same size as "//bigimg) print("and have statistics listed in headers and stats_"//llistsmall) print("and have new badpix masks listed in headers and "//bplist) if(!ddelorig)print("Original images renamed to files listed in "//origlist) } else { # print("WARNING: tasks stsdas.toolbox.imgtools.imcalc,") # print("fileroot, and/or minv are not loaded!") print("WARNING: fileroot task is not loaded!") print("Please load the appropriate package(s) and restart this task.") } list="" if(echog)beep end ./irskypisces.par0100644000151400000240000000314106720573000013233 0ustar phallgamesi_sigma,s,h,"",,,"IMCOMBINE: Sigma image (optional)" i_plfile,s,h,"",,,"IMCOMBINE: Rejected pixel list image (optional)" i_combine,s,h,"median",average|median,,"IMCOMBINE: Type of combine operation (median|average)" i_reject,s,h,"ccdclip",none|minmax|ccdclip|crreject|sigclip|avsigclip|pclip,,"IMCOMBINE: Type of rejection" i_masktyp,s,h,"badvalue",none|goodvalue|badvalue|goodbits|badbits,,"IMCOMBINE: Mask type" i_maskval,r,h,0.,,,"IMCOMBINE: Mask value" i_blank,r,h,1.,,,"IMCOMBINE: Value if there are no pixels" i_scale,s,h,"!SKYMED",,,"IMCOMBINE: Image scaling" i_zero,s,h,"none",,,"IMCOMBINE: Image scaling" i_weight,s,h,"none",,,"IMCOMBINE: Image weights" i_statsec,s,h,"",,,"IMCOMBINE: Image section for computing statistics" i_expname,s,h,"exptime",,,"IMCOMBINE: Image header exposure time keyword" i_lthresh,r,h,-100000.,,,"IMCOMBINE: Lower threshold" i_hthresh,r,h,100000.,,,"IMCOMBINE: Upper threshold" i_nlow,r,h,1.,0.,,"IMCOMBINE: minmax: Number of low pixels to reject" i_nhigh,r,h,1.,0.,,"IMCOMBINE: minmax: Number of high pixels to reject" i_nkeep,r,h,1.,,,"IMCOMBINE: Minimum to keep (+) or maximum to reject(-)" i_lsigma,r,h,5.,0.,,"IMCOMBINE: Lower sigma clipping factor" i_hsigma,r,h,5.,0.,,"IMCOMBINE: Upper sigma clipping factor" i_rdnoise,s,h,"RDNOISE",,,"IMCOMBINE: ccdclip: CCD readout noise (electrons)" i_gain,s,h,"GAIN",,,"IMCOMBINE: ccdclip: CCD gain (electrons/ADU)" i_sigscale,r,h,0.1,0.,,"IMCOMBINE: Tolerance for sig-clip scaling corrections" i_pclip,r,h,-0.5,,,"IMCOMBINE: pclip: Percentile clipping parameter" i_grow,r,h,0.,,,"IMCOMBINE: Radius (pixels) for 1D neighbor rejection" mode,s,h,"q",,, ./irtffirst.cl0100644000151400000240000002544707254743522012543 0ustar phallgames# irtffirst.cl -- add header params to raw IRTF NSFCAM images and optionally do # nonlinearity correction, saturated pixel replacement, & dark subtraction # # 1. do nonlinearity correction & add NLCOR (& poss. SATVAL) header card(s) # 2. subtract dark & add DARKSUB header card # 3. hedit image headers, adding: (basically this is task 'hadd.cl', except #0) # 1. BPM,BPMASK = bad pixel mask name # 2. date-obs = date_obs # 3. ut,time-obs = time_obs (UT) # 4. coadds from co_adds # ** 5. divide by DIVISOR if not already done; add header keyword DIVIDED # ** 6. exptime = (itime: exposure time per coadd) * (# of coadds) # 7. obs-date = date-obs but in dd/mm/yy format # **: Most arrays give you the counts and integration time of a single coadd. # (i.e. all coadds have been averaged internally) IRTF NSFCAM gives you # the TOTAL counts of all coadds but the integration time of a SINGLE coadd. # Thus the need to divide by DIVISOR as well as insert EXPTIME as usual. # # 970321: adapted for IRTF from irimfirst.cl # 971025: removed lin. corr. option -- stsdas not available at IRTF # 971026: added insertion of gain and rn keywords, latter accounting for NDR's # 980414: added compatibility to incoming date-obs in new-millenium format and # output of date-obs in same format (valid for data from 1990 to 2089); # original date-obs is output as dateorig # 990320: fixed bug where exptime & itime were feedbacking on each other # 990427: DARKSUB keyword added to darksubbed images, not original ones # # **cannot replace saturated pixels except at same time as nonlin. correction # **does not check to see if DARKSUB header card already exists in images procedure irtffirst(inlist,nonlin,darksub) string inlist {prompt="List of images to process (do not use an `@')"} bool nonlin=no {prompt="Do nonlinearity correction?"} bool darksub=no {prompt="Subtract off dark frame?"} string suffix {prompt="String to be appended to output images",mode="q"} real slope {min=1.,prompt="Slope coefficient of nonlinearity correction",mode="q"} string intname {prompt="Name of integration time header keyword",mode="q"} bool replace=no {prompt="Replace `saturated' pixels?",mode="q"} real maxval {40000.,min=30000.,prompt="Maximum good raw data value",mode="q"} string dark {prompt="Name of the dark frame to subtract",mode="q"} string badmask {prompt="Name of bad pixel mask to add to image header"} bool echog {yes,prompt="Beep when task is done?"} struct *list begin string ddark, ssuffix, bbadmask, check, base, ilist string olist, flat, flatbase, meanfile, currentflat, tempflat, name string editlist, current, obsdate, rra, ddec, eepoch, oobservatory, minsec string obstime, timeobs, dateobs, century real aairval, ttime, mean, meanbad, x int ncoadd, ddy, hhr, hhour, mmonth, dday, uttime bool ddarksub, ccoords, uut, nnonlin string iintname # equals intname string instring # temporary string real sslope # equals slope of nonlinearity correction real mmaxval # equals maxval real valmax # equals maxval string img # fscanned name of individual input image string oimg # fscanned name of individual output image real intime # equals int_time real delaytime # delay time between reset & first read real intfactor # factor for use in nonlinearity correction bool rreplace # equals replace bool go # just do it bool goon # just do it struct theadline # temporary struct for header information ilist = inlist editlist = ilist # editlist lists images currently being worked on olist = ilist # olist lists output images nnonlin = nonlin ddarksub = darksub ssuffix = suffix if(nnonlin){ # If suffix=="", insert temporary suffix to avoid overwriting if(ssuffix==""){ ssuffix="filthpig" beep print("WARNING! Input files will be overwritten!") } olist = ilist//ssuffix # olist lists output images sslope = slope iintname = intname rreplace = replace if(rreplace){ mmaxval = maxval valmax = mmaxval } } if(ddarksub){ if(!nnonlin){ ssuffix = suffix olist = ilist//ssuffix # olist lists output images } ddark = dark } bbadmask = badmask # The "go" parameter won't let the task run if the needed tasks aren't loaded. go=yes if(!deftask("fileroot")) {go=no} #if(!deftask("imcalc")) {go=no} if(go) { # Do nonlinearity correction if desired goon=no if(nnonlin){ print("===> Running nonlinearity correction procedure...") list = ilist editlist = olist while (fscan(list,img) != EOF) { fileroot(img,validim+) oimg=fileroot.root//ssuffix//"."//fileroot.extension # add output image name to output image list unless suffix="" # if(ssuffix!="filthpig")print(oimg, >> olist) print(oimg, >> olist) # do the correction only if input image has not already been corrected imgets(img,"NLCOR",>&"dev$null") if(imgets.value=="0")goon=yes # if output image exists... if(access(oimg)){ imgets(oimg,"NLCOR",>&"dev$null") # ...and has not been nlcorrected, delete it if(imgets.value=="0"){ imdel(oimg,ver-) } # ...if it has been nlcorrected, print error message & do not do the correction else{ goon=no print("Nonlinearity correction already done on "//oimg//"-- not redone.") } } if(goon){ imgets(img,iintname) intime=real(imgets.value) # Find delay time... if(intime>=1.381){ delaytime=1. # intfactor=1.+(1./intime) } else{ delaytime=intime-0.381 # intfactor=2.-(0.381/intime) } intfactor=1.+((2.*delaytime)/intime) # Do nonlinearity correction. The correction is approximate, but should be # good for pixels requiring <=10% correction, above which they saturate anyway. imcalc(img,oimg,"(im1)/(1.-im1*("//intfactor//"/"//sslope//"))", pixtype="real",nullval=0.,ver-) # imcalc(img,oimg,"("//sslope//"*im1)/("//sslope//"-im1*"//intfactor//")",pixtype="real",nullval=0.,ver-) hedit(oimg,"NLCOR",sslope,add+,ver-,show+,update+) # Replace "saturated" pixels if desired if(rreplace){ mmaxval=(sslope*valmax)/(sslope-valmax*intfactor) imreplace(oimg,mmaxval,lower=mmaxval,upper=INDEF) hedit(oimg,"SATVAL",mmaxval,add+,ver-,show+,update+) } } # If correction already done on input image, do not redo, just copy to output else{ print("Nonlinearity correction already done on "//img//"-- not redone.") if(!access(oimg))imcopy(img,oimg,ver-) } } } # Subtract off Dark Current if (ddarksub) { print("===> Subtracting off Dark Current...") # If final output list is not same as current list, need to create output list if(olist!=editlist){ # if olist doesn't exist, assume darksub'd imgs don't either; create it & dsubs if(!access(olist)) { print("===> Subtracting off Dark Current...") list=editlist while (fscan(list,img) != EOF) { fileroot(img,validim+) oimg=fileroot.root//ssuffix if(fileroot.extension!="")oimg=oimg//"."//fileroot.extension print(oimg, >> olist) imgets(img,"DARKSUB") if (imgets.value=="0") { imarith(img, "-", ddark, oimg, verbose-) hedit(oimg,"DARKSUB",ddark,add+,ver-,show+,upd+) } else { print("DARKSUB keyword exists; irtffirst already run? "//name//" just copied") imcopy(img, oimg, verbose-) } } } else { print("Darksubbed image list "//olist//" already exists; images assumed to exist too.") } print(" ") print("===> Dark-subtracted images are listed in the file "//olist//".") # imarith("@"//editlist, "-", ddark, "@"//olist, verbose-) # hedit("@"//olist,"DARKSUB",ddark,add+,ver-,show+,update+) editlist=olist } # Add the BPM to the image headers print("===> Adding various parameters to the image headers...") hedit("@"//editlist,"BPM",bbadmask,add+,ver-,show-,update+) hedit("@"//editlist,"BPMASK",bbadmask,add+,ver-,show-,update+) # Add the GAIN and RN to the image headers hedit("@"//editlist,"GAIN",10.,add+,ver-,show-,update+) hedit("@"//editlist,"RN","(55./sqrt(NDR))",add+,ver-,show-,update+) # Add other goodies to the image headers, just like in the hadd.cl task list = editlist while (fscan (list, current) !=EOF) { # copy date_obs to dateorig imgets(current,"date_obs") hedit(current,"dateorig",(imgets.value),add+,ver-,show+,update+) # date_obs is either in dd/mm/yy format or yyyy-mm-dd format if(substr(imgets.value,3,3)=="/") { # if date_obs is in dd/mm/yy format, rework to get date-obs if ((substr(imgets.value,7,7))=="9") { century=19 } else { century=20 } dateobs=century//substr(imgets.value,7,8)//"-"//substr(imgets.value,4,5)//"-"//substr(imgets.value,1,2) hedit(current,"date-obs",dateobs,add+,ver-,show+,update+) # if date_obs is in dd/mm/yy format, obs-date is a direct copy of it hedit(current,"obs-date",(imgets.value),add+,ver-,show+,update+) } else { # if date_obs is in yyyy-mm-dd format, date-obs is a direct copy of it hedit(current,"date-obs",(imgets.value),add+,ver-,show+,update+) # if date_obs is in yyyy-mm-dd format, rework to get obs-date obsdate=substr(imgets.value,9,10)//"/"//substr(imgets.value,6,7)//"/"//substr(imgets.value,3,4) hedit(current,"obs-date",obsdate,add+,ver-,show+,update+) } # ut and time-obs from time_obs imgets(current,"time_obs") hedit(current,"time-obs",(imgets.value),add+,ver-,show+,update+) hedit(current,"ut",(imgets.value),add+,ver-,show+,update+) # coadds from co_adds imgets(current,"co_adds") hedit(current,"coadds",(imgets.value),add+,ver-,show+,update+) # divide by DIVISOR imgets(current,"divided",>&"dev$null") if(imgets.value=="0"){ imgets(current,"divisor") if(imgets.value!="1"){ imar(current,"/",real(imgets.value),current,noact-,ver-) hedit(current,"divided","yes",add+,ver-,show+,update+) } else { hedit(current,"divided","yes",add+,ver-,show+,update+) } print("Image "//current//" divided by factor "//imgets.value//" given in DIVISOR.") } else { print("WARNING! Image "//current//" already divided by DIVISOR!") } # exptime = itime * ncoadds imgets(current,"itime") intime=real(imgets.value) imgets(current,"coadds") ncoadd=real(imgets.value) hedit(current,"exptime",(ncoadd*intime),add+,ver-,show+,update+) } # If suffix=="", if(ssuffix=="filthpig"){ imdel("@"//ilist,ver-) imren("@"//olist,"@"//ilist,ver-) del(olist,ver-) olist=ilist } print(" ") print("===> Processed images are listed in the file "//olist//".") if(ddarksub || nnonlin){ print("===> You should rerun the task with nonlin=no and/or darksub=no to properly") print("===> update the original image headers, if you plan to use those images.") } } else { print("WARNING: tasks fileroot and/or stsdas.toolbox.imgtools.imcalc") print("are not loaded! Please load them and restart this task.") } if(echog)beep end ./trim.cl0100644000151400000240000001057206720573004011464 0ustar phallgames# trim -- create constant-rms image with a certain minimum exposure time # # This task takes an input image and exposure map and creates: # # "trim"//img trimmed image # "trim"//mask exposure map for trimmed image # "trim"//mask//"mask" exposed/unexposed area mask for trimmed image # stats files of trimmed image RMS values (from maskstat) # # 960710: created from batch routine dofocasprep.cl # 990307: added subtract option # 990515: when appropriate, use imcalc not imarith procedure trim(image,mask,stats) string image {prompt="Image (or image list) to trim"} string mask {prompt="Exposure map or list (default=image//em)"} string stats {prompt="File to contain trimmed image RMS values"} string out="trim" {prompt="Prefix for trimmed images"} bool subtract=no {prompt="Subtract average from image before making mask?"} real mingoodexp=0.36 {prompt="Minimum acceptable exptime (fraction of maximum)"} bool echog {yes,prompt="Beep when task is done?"} struct *list begin string img, exp, newexp, pprefix, trimlist, imglist, trimmask, explist string sstats, joinlist, checki, checke, ext, tmpsub real mmingoodexp bool doren, sub_tract img = image checki=substr(img,1,1) if(checki=="@"){ imglist=substr(img,2,strlen(img)) trimlist=imglist//"trim" } else { imglist=mktemp("imglist") trimlist=imglist//"trim" print (img, >> imglist) } exp = mask checke=substr(exp,1,1) if(checke=="@"){ explist=substr(exp,2,strlen(exp)) } else { explist=mktemp("explist") if(checke=="") { fileroot (img, validim+) print (fileroot.root//"em", >> explist) } else { print (exp, >> explist) } } sstats=stats pprefix=out if(pprefix=="")pprefix="trim" sub_tract=subtract mmingoodexp=mingoodexp # join image and mask lists joinlist=mktemp("joinlist") join (imglist, explist, >> joinlist) list=joinlist while (fscan (list,img,exp) != EOF) { fileroot(img, validim+) img = fileroot.root fileroot(exp, validim+) exp = fileroot.root ext = fileroot.extension if(ext!="") ext="."//ext newexp = pprefix//fileroot.root # the core if (!access(newexp//ext)) { print ("Preparing exposure map...") minmax (exp, force+, update+, ver-) imar (exp, "/", minmax.maxval, newexp, pixt="real", ver-, noac-) #imreplace (newexp, 0., lower=INDEF, upper=mmingoodexp) #imreplace (newexp, 1., lower=mmingoodexp-0.01, upper=INDEF) imcalc (newexp, newexp, "if im1 .le. "//mmingoodexp//" then 0 else 1", ver-) addring (newexp, newexp, ngrow=5, badval=1) imar (newexp, "*", exp, newexp, ver-, pixt="real", noact-) } if (!access(pprefix//img//"mask.pl")) { print ("Creating trimmed area mask...") #imcopy (newexp, pprefix//img//"mask.pl", ver-) #imreplace (pprefix//img//"mask.pl",1.,lower=0.01,upper=INDEF) imcalc (newexp, pprefix//img//"mask.pl", "if im1 .eq. 0 then 0 else 1", ver-) } # subtraction phase if (sub_tract) { print ("Subtracting mean from image...") tmpsub=mktemp("tmpsub") maskstat(img,pprefix//img//"mask.pl",1.,nsigrej=5.,maxiter=5.,lower=INDEF,upper=INDEF,ver-,iterstat+,print-,addh-) imar(img,"-",iterstat.mean,tmpsub,calctype="real",ver-,noact-) print ("Normalizing image...") sigmanorm (tmpsub, normim=newexp, prefix=pprefix) imren (pprefix//tmpsub, pprefix//img, ver-) imdel (pprefix//tmpsub, ver-, >& "dev$null") imdel (tmpsub, ver-, >& "dev$null") } else { print ("Normalizing image...") sigmanorm (img, normim=newexp, prefix=pprefix) } print (pprefix//img, >> trimlist) print ("Getting statistics...") maskstat (pprefix//img, pprefix//img//"mask.pl", goodv=1, iterstat+, ver-, >> sstats) } del (joinlist, ver-) if (checke!="@") del (explist, ver-) if (checki!="@") { del (imglist, ver-) del (trimlist, ver-) } else { print("Output trimmed images are listed in "//trimlist) } print("Output trimmed image statistics are listed in "//sstats) #imar cf1.coadd3em / 3879.999267578125 cf1.coadd3em2 #imreplace cf1.coadd3em2 0. lower=INDEF upper=0.4 #imreplace cf1.coadd3em2 1. lower=0.39 upper=INDEF #addring cf1.coadd3em2 cf1.coadd3em2 ngrow=5 badval=1 #imar cf1.coadd3em * cf1.coadd3em2 cf1.coadd3em2 #imar cf1.coadd3em2 / 3879.999267578125 cf1.coadd3em2 #sigmanorm cf1.coadd3 normim=cf1.coadd3em2 #imcopy cf1.coadd3em2.imh cf1.coadd3em3.imh #imreplace cf1.coadd3em3.imh 1. lower=0.10 upper=INDEF #imren normcf1.coadd3.imh cf1 #maskstat cf1.imh cf1.coadd3em3.imh goodv=1 iterstat+ ver- >> stats if(echog)beep end ./irshift2.cl0100600000151400000240000001253007146311727012234 0ustar phallgames# irshift2 -- measure scale and rotation between two images' coord systems # # Task calls following other tasks: filecalc. # # Output: # prefix.georefin.suffix object coordinates in ref and input images # prefix.geomapin.suffix input file for geomap task # # CHANGES: # 960307: created from irshift.cl # 980429: rewritten to work without "nlocal.linenum" task # 980809: now suggests xmin xmax ymin ymax for immatch.geomap # 000815: fixed splitting of combined log file for very large files procedure irshift2(refimage,inimage,prefix,suffix) string refimage {prompt="Reference image"} string inimage {prompt="Input image"} string prefix {prompt="Prefix string for output files"} string suffix {prompt="Suffix string for output files"} real radius=5. {prompt="Imexamine aperture photometry radius"} real buffer=10. {prompt="Imexamine sky buffer"} real width=10. {prompt="Imexamine sky annulus width"} bool echog {yes,prompt="Beep when task is done?"} struct *list begin string rrefimage, fflatlist, rrefcoords, bbadmask, rroundname string sshiftlist, coarsefile, ooffname, ssuffix, iintname, ffracname string pprefix, logoffname, sl, sx, img, iinterp, bboundary string iinimage, stringline1, stringline2, stringline1old, stringline2old string stringline1tmp, stringline2tmp, georefin, geomapin, string1, string2 real p, pixscale, stcoordx, stcoordy, nrows, ncols, delx, dely, adelx, adely real xold, yold, xxshiftold, yyshiftold, xshiftnew, yshiftnew, astcoordx real astcoordy, nl, nx, x, y int xref # Reference object x coordinate (nearest integer) int yref # Reference object y coordinate (nearest integer) int number, xtmp, ytmp, z, linenum, imax, imay bool go #The "go" parameter won't let the task run if you haven't loaded the ctio pkg. go=yes if(!deftask("filecalc")) {go=no} if(go) { rrefimage = refimage iinimage = inimage pprefix = prefix ssuffix = suffix rimexam.radius=radius rimexam.buffer=buffer rimexam.width=width georefin = pprefix//".georefin."//ssuffix geomapin = pprefix//".geomapin."//ssuffix print(" ") print("===) Choose an object that appears in both images, find its coordinates") print("===) (type 'a') first in frame 1 and then in frame 2, and repeat with as many") print("===) objects as desired. The separation of coordinates from the different") print("===> images will be done later, but **THE SEPARATION WILL FAIL** if the") print("===> frame1/frame2 cycle is deviated from even slightly! The imexam output") print("===> log will be displayed for editing when done, in case mistakes were made.") print(" ") display(iinimage,2) display(rrefimage,1) imexam(logfile=georefin, keep+) print(" ") print("===> In case mistakes were made, the coordinate file can now be edited.") vi(georefin) print("===> Constructing geomap input file...") del("temp.joinfile*", ver-) # copy the imexam output to a working file copy(georefin,"temp.joinfile",ver-) # remove all comment lines !grep -v '^#' temp.joinfile > temp.joinfile1 # make sure there is an even number of lines remaining count("temp.joinfile1") | scan (nl) if((frac(nl/2.))!=0.){ beep print ("ERROR! Odd number of coordinates in this file! Fix it!", >> "temp.joinfile1") vi("-c ':$'", "temp.joinfile1") } ## number the lines in the input file ## linenum("temp.joinfile1","temp.joinfile0",first_line=1,increment=1) # linenum=1 # list="temp.joinfile1" # while(fscan(list, string1) !=EOF) { # print(linenum, >> "temp.joinfile0") # linenum=linenum+1 # } ## extract the first 3 columns in appropriate format ## filecalc("temp.joinfile0","$1;$2;$3",lines="1-99999",format="%5.0f%9.2f%9.2f", >> "temp.joinfile2") # filecalc("temp.joinfile0,temp.joinfile1","$1@1;$1@2;$2@2",lines="1-99999",format="%5.0f%9.2f%9.2f", >> "temp.joinfile2") ## initialize loop # list="temp.joinfile2" # stringline1="" # stringline2="" # stringline1old="" # stringline2old="" # stringline1tmp="" # stringline2tmp="" ## create one string of odd line numbers "1,3,5,..." and one of even. ## both of which will eventually be used as parameters for filecalc # while(fscan(list, number, xtmp, ytmp) !=EOF) { # if((frac(number/2.))!=0.){ # stringline1tmp=stringline1old//number//"," # } else { # stringline2tmp=stringline2old//number//"," # } # stringline1old=stringline1tmp # stringline2old=stringline2tmp # } ## cut off trailing comma # z=strlen(stringline1tmp)-1 # stringline1=substr(stringline1tmp,1,z) # z=strlen(stringline2tmp)-1 # stringline2=substr(stringline2tmp,1,z) # extract coords from image 1 # filecalc("temp.joinfile1","$1;$2",lines=stringline1,format="%9.2f%9.2f", >> "temp.joinfile1a") filecalc("temp.joinfile1","$1;$2",lines="1-99999x2",format="%9.2f%9.2f", >> "temp.joinfile1a") # extract coords from image 2 # filecalc("temp.joinfile1","$1;$2",lines=stringline2,format="%9.2f%9.2f", >> "temp.joinfile1b") filecalc("temp.joinfile1","$1;$2",lines="2-99999x2",format="%9.2f%9.2f", >> "temp.joinfile1b") # join coords from images 1 and 2 join("temp.joinfile1a","temp.joinfile1b",out=geomapin) # del("temp.joinfile*", ver-) hsel (refimage, "i_naxis1", "yes") | scan (imax) hsel (refimage, "i_naxis2", "yes") | scan (imay) print("Next:") print("immatch.geomap "//geomapin//" "//pprefix//".geomapout."//ssuffix//" 1 "//imax//" 1 "//imay) } else { print("WARNING: task `ctio.filecalc' is not loaded!") print("Please load it and restart this task.") } if(echog)beep end ./onis1358cn.cl0100644000151400000240000010572606721637465012346 0ustar phallgames# onis1348cn -- shift & coadd ONIS CNOC MS1358+62 Center-North dither pattern # 990520 -- created from onis6pt.cl / onis3ew.cl # 990521 -- skip shiftlongaxes step if redo- & *.roundoff.* exists # ** could do xcor in a chain: after coaddlongaxes, # displ AB #1 CD #2 & measure 1-star offset, then # EHI #3 FGI #4 MLK #1 ON #2 TSP #3 URQ #4 VWX #1 # ** would allow all shifts to be done at once # ** in pre-review: display xm=0.5 ym=0.5 with estimated offsets? # -- ideally would include multimasklet.cl instead of masklet.cl, # to identify & exclude spurious objects from bright star residuals. # layout of MS1358+62 Center-North pattern & image pairings (long axis vertical): # # L12 C3/I9 D4/H8 E5 KL BJCI AGDH FE # K11 B2/J10 A1/G7 F6 # # G7 = N A1 # H8 = N B2 # I9 = N C3 # J10 = N D4 # K11 = N E5 # L12 = N F6 # layout of MS1358+62 South pattern & image pairings (long axis vertical): # # B2 C3 F6 AB DC EF # A1 D4 E5 procedure onis1348cn(inlist,imageroot,niter) string inlist {prompt="List of input images"} string imageroot {prompt="Root name for output files"} int niter=1 {prompt="Number to append to output files"} string pairing="all" {enum="AGDH|BJCI|FE|KL|all",prompt="Images pairings to process (or all)"} bool inspect=yes {prompt="Inspect image lists before proceeding?"} bool shiftlongaxes=yes {prompt="Find shifts for image pairings w/overlapping long axes?"} bool coaddlongaxes=yes {prompt="Coadd image pairings w/overlapping long axes?"} bool nshiftall=yes {prompt="Find shifts between all image pairings?"} bool prereview=yes {prompt="Display all image for pre-nshift check?"} bool p_tv=yes {prompt="Use ptv instead of display for pre-nshift check?"} bool use_images=yes {prompt="Measure shifts from images (not file) in nshift?"} bool display_im=yes {prompt="Display images for imexam in nshift?"} bool edit_files=yes {prompt="Edit coords files after creation in nshift?"} bool exclude {prompt="Exclude any image pairings from first-pass nshift?"} string exstring {prompt="Enter code(s) for excluded pairing(s) separated by commas (AGDH|BJCI|FE|KL|all)"} bool redo=no {prompt="Redo shift-finding if already done?"} bool coaddallimages=yes {prompt="Coadd all images?"} bool secondpassxcor=yes {prompt="Cross-correlate all images with coadded image?"} bool coaddsecondpass=yes {prompt="Coadd images after second-pass cross-correlation?"} bool domkobjmask=yes {prompt="Make coadded-image object mask (INTERACTIVE)?"} bool domasklet=yes {prompt="Make individual-image object masks?"} string imextn="fits" {prompt="Image extension"} int xsize=512 {prompt="X-axis individual image size (0 for autosense)"} int ysize=1024 {prompt="Y-axis individual image size (0 for autosense)"} bool echog=yes {prompt="Beep when task is done?"} struct *list begin string in_list, image_root, p_air, ref_image, tmpheaders, sigprefix, rroundname string theory, method_shortaxes, tempfile2, msect, image_name, tempx, tempy string rvw_image, ex_string, current_string, future_string, in_string, im_extn string zero_out int xmin, ymin, xint, yint, old_xint, old_yint, xmax_bcad, xmin_fead, ix, iy int xmin_tspurq, xmax_tspurq, xtspurq, ytspurq, tspn1 int xmin_vwxurq, xmax_vwxurq, xvwxurq, yvwxurq, vwxn1 int xmin_mlkfgj, xmax_mlkfgj, xmlkfgj, ymlkfgj, mlkn1 int xmin_ehifgj, xmax_ehifgj, xehifgj, yehifgj, ehin1 int n_iter, xbcad, ybcad, xfead, yfead, bcn1, fen1, x_shift, y_shift, xe, ye int xref, yref, int_x, int_y, junkint, ilen, ipos int oxdim, oydim # dimensions of mask image int ixdim, iydim # dimensions of individual input frames int xbamost, ybamost, xbaba, ybaba, xcdba, ycdba, xehiba, yehiba, xfgjba, yfgjba int xmlkba, ymlkba, xonba, yonba, xtspba, ytspba, xurqba, yurqba, xvwxba, yvwxba real baba_xshiftexact, baba_yshiftexact, bamost_xshiftexact, bamost_yshiftexact real cdba_xshiftexact, cdba_yshiftexact, ehiba_xshiftexact, ehiba_yshiftexact real fgjba_xshiftexact, fgjba_yshiftexact, mlkba_xshiftexact, mlkba_yshiftexact real onba_xshiftexact, onba_yshiftexact, tspba_xshiftexact, tspba_yshiftexact real urqba_xshiftexact, urqba_yshiftexact, vwxba_xshiftexact, vwxba_yshiftexact real xbcad2, ybcad2, xfead2, yfead2, bcad_x, bcad_y, fead_x, fead_y real xtspurq2, ytspurq2, tspurq_xlag, tspurq_ylag real xvwxurq2, yvwxurq2, vwxurq_xlag, vwxurq_ylag real xurq, yurq, xtsp, ytsp, xvwx, yvwx real xmlkfgj2, ymlkfgj2, mlkfgj_xlag, mlkfgj_ylag real xehifgj2, yehifgj2, ehifgj_xlag, ehifgj_ylag real xfgj, yfgj, xmlk, ymlk, xehi, yehi real xad, yad, xbc, ybc, xfe, yfe, bcad_xlag, bcad_ylag, fead_xlag, fead_ylag real bcad_xfirstpass, bcad_yfirstpass, fead_xfirstpass, fead_yfirstpass real tspurq_xfirstpass, tspurq_yfirstpass, vwxurq_xfirstpass, vwxurq_yfirstpass real mlkfgj_xfirstpass, mlkfgj_yfirstpass, ehifgj_xfirstpass, ehifgj_yfirstpass real xoff, yoff, step, new_x, new_y, old_x, old_y, step_x, step_y, xsig, ysig bool in_spect, shift_longaxes, echo_g, coadd_longaxes, abort, go, do_masklet bool coadd_allimages, xcor_secondpass, coadd_secondpass, do_mkobjmask, re_do bool im_display, images_use, shift_shortaxes, coadd_shortaxes, xreg_secondpass bool nshift_all, files_edit, ex_clude, pt_v, pre_review in_list=inlist image_root=imageroot n_iter=niter p_air=pairing in_spect=inspect shift_longaxes=shiftlongaxes images_use=use_images im_display=display_im files_edit=edit_files ex_string="" re_do=redo coadd_longaxes=coaddlongaxes nshift_all=nshiftall pre_review=prereview pt_v=p_tv coadd_allimages=coaddallimages xcor_secondpass=secondpassxcor coadd_secondpass=coaddsecondpass do_mkobjmask=domkobjmask do_masklet=domasklet im_extn=imextn echo_g=echog rroundname=image_root//".xregshifts.shall"//n_iter sigprefix=sigmanorm.prefix baba_xshiftexact = 0; baba_yshiftexact = 0; cdba_xshiftexact = 0 cdba_xshiftexact = 0; ehiba_xshiftexact = 0; ehiba_yshiftexact = 0 fgjba_xshiftexact = 0; fgjba_yshiftexact = 0; mlkba_xshiftexact = 0 mlkba_yshiftexact = 0; onba_xshiftexact = 0; onba_yshiftexact = 0 tspba_xshiftexact = 0; tspba_yshiftexact = 0; urqba_xshiftexact = 0 urqba_yshiftexact = 0; vwxba_xshiftexact = 0; vwxba_yshiftexact = 0 go=yes if(!defpac("imgtools")) {go=no} if(go) { # Separate input list into lists of images overlapping along long axes print ("\n===> Checking image pairing lists...") tmpheaders=mktemp("tmpheaders") hsel ("@"//in_list, "$I,i_title", yes, >> tmpheaders) if (!access(in_list//"_AGDH")) { grep ('Position\ \ 1\ of\ \ 6', tmpheaders) | grep ("-v", 'N') | grep ("-v", 'S') | fields ("junk", "1", lines="1-9999", >> in_list//"_AGDH") grep ('Position\ \ 1\ of\ \ 6', tmpheaders) | grep ('N') | fields ("junk", "1", lines="1-9999", >> in_list//"_AGDH") grep ('Position\ \ 4\ of\ \ 6', tmpheaders) | grep ("-v", 'N') | grep ("-v", 'S') | fields ("junk", "1", lines="1-9999", >> in_list//"_AGDH") grep ('Position\ \ 2\ of\ \ 6', tmpheaders) | grep ('N') | fields ("junk", "1", lines="1-9999", >> in_list//"_AGDH") } else { print (in_list//"_AGDH already exists; not created.") } if (!access(in_list//"_BJCI")) { grep ('Position\ \ 2\ of\ \ 6', tmpheaders) | grep ("-v", 'N') | grep ("-v", 'S') | fields ("junk", "1", lines="1-9999", >> in_list//"_BJCI") grep ('Position\ \ 4\ of\ \ 6', tmpheaders) | grep ('N') | fields ("junk", "1", lines="1-9999", >> in_list//"_BJCI") grep ('Position\ \ 3\ of\ \ 6', tmpheaders) | grep ("-v", 'N') | grep ("-v", 'S') | fields ("junk", "1", lines="1-9999", >> in_list//"_BJCI") grep ('Position\ \ 3\ of\ \ 6', tmpheaders) | grep ('N') | fields ("junk", "1", lines="1-9999", >> in_list//"_BJCI") } else { print (in_list//"_BJCI already exists; not created.") } if (!access(in_list//"_FE")) { grep ('Position\ \ 6\ of\ \ 6', tmpheaders) | grep ("-v", 'N') | grep ("-v", 'S') | fields ("junk", "1", lines="1-9999", >> in_list//"_FE") grep ('Position\ \ 5\ of\ \ 6', tmpheaders) | grep ("-v", 'N') | grep ("-v", 'S') | fields ("junk", "1", lines="1-9999", >> in_list//"_FE") } else { print (in_list//"_FE already exists; not created.") } if (!access(in_list//"_KL")) { grep ('Position\ \ 5\ of\ \ 6', tmpheaders) | grep ('N') | fields ("junk", "1", lines="1-9999", >> in_list//"_KL") grep ('Position\ \ 6\ of\ \ 6', tmpheaders) | grep ('N') | fields ("junk", "1", lines="1-9999", >> in_list//"_KL") } else { print (in_list//"_KL already exists; not created.") } del(tmpheaders,ver-) if (in_spect) vi (in_list//"_?? "//in_list//"_????") # Do irshift on lists of images overlapping along long axes if (shift_longaxes) { print("\n===> Finding shifts for image pairings overlapping along long axes...") if (p_air=="AGDH" || p_air=="all") { fields (in_list//"_AGDH", 1, lines="2-2") | scan (ref_image) if (!access(image_root//".roundoff.shAGDH"//n_iter)) { print("\n----> Overlap region is UPPER part of the reference image; using irshift <----") irshift (in_list//"_AGDH", ref_image, image_root, "shAGDH"//n_iter, useimages=images_use, displayim=im_display) } } if (p_air=="BJCI" || p_air=="all") { fields (in_list//"_BJCI", 1, lines="2-2") | scan (ref_image) if (re_do || !access(image_root//".roundoff.shBJCI"//n_iter)) { print("\n----> Overlap region is UPPER part of the reference image; using irshift <----") irshift (in_list//"_BJCI", ref_image, image_root, "shBJCI"//n_iter, useimages=images_use, displayim=im_display) } } if (p_air=="FE" || p_air=="all") { fields (in_list//"_FE", 1, lines="2-2") | scan (ref_image) if (re_do || !access(image_root//".roundoff.shFE"//n_iter)) { print("\n----> Overlap region is UPPER part of the reference image; using irshift <----") irshift (in_list//"_FE", ref_image, image_root, "shFE"//n_iter, useimages=images_use, displayim=im_display) } } if (p_air=="KL" || p_air=="all") { fields (in_list//"_KL", 1, lines="2-2") | scan (ref_image) if (re_do || !access(image_root//".roundoff.shKL"//n_iter)) { print("\n----> Overlap region is UPPER part of the reference image; using irshift <----") irshift (in_list//"_KL", ref_image, image_root, "shKL"//n_iter, useimages=images_use, displayim=im_display) } } } # Coadd images overlapping along long axes if (coadd_longaxes) { print ("\n===> Coadding image pairings overlapping along long axes...") if (p_air=="AGDH" || p_air=="all") { imdel (image_root//"AGDH"//n_iter, ver-, >& "dev$null") imdel (image_root//"AGDH"//n_iter//"em", ver-, >& "dev$null") del (image_root//"AGDH"//n_iter//".imshifts", ver-, >& "dev$null") imdel (sigprefix//image_root//"AGDH"//n_iter, ver-, >& "dev$null") ircoadd (in_list//"_AGDH", image_root//"AGDH"//n_iter, "", image_root//".roundoff.shAGDH"//n_iter, "none", "mode", "none", 1, no, "log_"//image_root//"_allatonce", makeavg+, flip-) # sigmanorm (image_root//"AGDH"//n_iter) } if (p_air=="BJCI" || p_air=="all") { imdel (image_root//"BJCI"//n_iter, ver-, >& "dev$null") imdel (image_root//"BJCI"//n_iter//"em", ver-, >& "dev$null") del (image_root//"BJCI"//n_iter//".imshifts", ver-, >& "dev$null") imdel (sigprefix//image_root//"BJCI"//n_iter, ver-, >& "dev$null") ircoadd (in_list//"_BJCI", image_root//"BJCI"//n_iter, "", image_root//".roundoff.shBJCI"//n_iter, "none", "mode", "none", 1, no, "log_"//image_root//"_allatonce", makeavg+, flip-) # sigmanorm (image_root//"BJCI"//n_iter) } if (p_air=="FE" || p_air=="all") { imdel (image_root//"FE"//n_iter, ver-, >& "dev$null") imdel (image_root//"FE"//n_iter//"em", ver-, >& "dev$null") del (image_root//"FE"//n_iter//".imshifts", ver-, >& "dev$null") imdel (sigprefix//image_root//"FE"//n_iter, ver-, >& "dev$null") ircoadd (in_list//"_FE", image_root//"FE"//n_iter, "", image_root//".roundoff.shFE"//n_iter, "none", "mode", "none", 1, no, "log_"//image_root//"_allatonce", makeavg+, flip-) # sigmanorm (image_root//"FE"//n_iter) } if (p_air=="KL" || p_air=="all") { imdel (image_root//"KL"//n_iter, ver-, >& "dev$null") imdel (image_root//"KL"//n_iter//"em", ver-, >& "dev$null") del (image_root//"KL"//n_iter//".imshifts", ver-, >& "dev$null") imdel (sigprefix//image_root//"KL"//n_iter, ver-, >& "dev$null") ircoadd (in_list//"_KL", image_root//"KL"//n_iter, "", image_root//".roundoff.shKL"//n_iter, "none", "mode", "none", 1, no, "log_"//image_root//"_allatonce", makeavg+, flip-) # sigmanorm (image_root//"KL"//n_iter) } } # Find shifts between all image pairings if (p_air=="all" && nshift_all) { if (!access(image_root//".shiftexact.shall"//n_iter)) { # ** should test this out if (re_do) { del (image_root//".imshifts.shall*"//n_iter, ver-, >& "dev$null") del (image_root//".offsets.shall*"//n_iter, ver-, >& "dev$null") del (image_root//".roundoff.shall*"//n_iter, ver-, >& "dev$null") del (image_root//".shiftexact.shall*"//n_iter, ver-, >& "dev$null") del (image_root//".shiftfrac.shall*"//n_iter, ver-, >& "dev$null") del (image_root//".shiftint.shall*"//n_iter, ver-, >& "dev$null") del (image_root//".imshifts.shmost*"//n_iter, ver-, >& "dev$null") del (image_root//".offsets.shmost*"//n_iter, ver-, >& "dev$null") del (image_root//".roundoff.shmost*"//n_iter, ver-, >& "dev$null") del (image_root//".shiftexact.shmost*"//n_iter, ver-, >& "dev$null") del (image_root//".shiftfrac.shmost*"//n_iter, ver-, >& "dev$null") del (image_root//".shiftint.shmost*"//n_iter, ver-, >& "dev$null") print ("\n*allcoords*, *refcoords*, & *coarse* preserved; all else will be recreated.") } if (!access(in_list//"_coadd_"//n_iter)) { print (image_root//"AGDH"//n_iter, >> in_list//"_coadd_"//n_iter) print (image_root//"BJCI"//n_iter, >> in_list//"_coadd_"//n_iter) print (image_root//"FE"//n_iter, >> in_list//"_coadd_"//n_iter) print (image_root//"KL"//n_iter, >> in_list//"_coadd_"//n_iter) } # initial pre-review if (pre_review) { print ("Central image will be displayed in frame 1, and others in 2.") print ("Note any images that do not overlap the central image.") list=in_list//"_coadd_"//n_iter junkint = 1 while (fscan (list, rvw_image) !=EOF) { if (junkint==1) { if (pt_v) { ptv (rvw_image, frame=1) } else { display (rvw_image, frame=1) } } else { if (pt_v) { imexam (rvw_image, frame=2, keep-, display="ptv(image='$1',frame=2)") } else { display (rvw_image, junkint) imexam (rvw_image, frame=junkint, keep-, display="display(image='$1',frame=$2)") #imexam (rvw_image, frame=2, keep-, display="display(image='$1',frame=2)") } } junkint = junkint + 1 if (junkint==5) junkint = 2 } } # exclude any images from nshift at first? print ("") ex_clude=exclude # if excluding any images: if (ex_clude) { # **redo here too? not a global redo, since need to get paramaters below for use in coadding del ("_coaddTmp?_", ver-, >& "dev$null") # get code(s) of excluded image(s) ex_string=exstring # create file of codes of images excluded from most-images coadd # files (image_root//ex_string//n_iter, >> "_coaddTmp1_") files (ex_string, >> "_coaddTmp1_") # create file of images included in most-images coadd copy (in_list//"_coadd_"//n_iter, "_coaddTmp2_", ver-) !fgrep -v -f _coaddTmp1_ _coaddTmp2_ > _coaddTmp3_ # **redo/!redo instead of delete & recreate? del (in_list//"_coaddmost_"//n_iter, ver-, >& "dev$null") rename ("_coaddTmp3_", in_list//"_coaddmost_"//n_iter, field="all", >& "dev$null") # create file of images included in full coadd # **redo/!redo instead of delete & recreate? del (in_list//"_coaddrest_"//n_iter, ver-, >& "dev$null") print (image_root//"AGDH"//n_iter, > "_coaddTmp4_") !fgrep -f _coaddTmp1_ _coaddTmp2_ >> _coaddTmp4_ print (image_root//"most"//n_iter//"_1stpass", >> "_coaddTmp4_") type ("_coaddTmp4_", >> in_list//"_coaddrest_"//n_iter) # find shifts for most-images coadd # **redo here too? if(!access(image_root//".roundoff.shmost"//n_iter)) nshift("", in_list//"_coaddmost_"//n_iter, image_root//"AGDH"//n_iter, image_root, "shmost"//n_iter, redo=re_do, useimages=images_use, displayim=im_display, editfiles=files_edit) if (!access(image_root//".imshifts.shmost"//n_iter)) join (in_list//"_coaddmost_"//n_iter, image_root//".shiftexact.shmost"//n_iter, >> image_root//".imshifts.shmost"//n_iter) grep ("AGDH", image_root//".imshifts.shmost"//n_iter) | scan (theory, baba_xshiftexact, baba_yshiftexact) grep ("BJCI", image_root//".imshifts.shmost"//n_iter) | scan (theory, cdba_xshiftexact, cdba_yshiftexact) grep ("FE", image_root//".imshifts.shmost"//n_iter) | scan (theory, fgjba_xshiftexact, fgjba_yshiftexact) grep ("KL", image_root//".imshifts.shmost"//n_iter) | scan (theory, mlkba_xshiftexact, mlkba_yshiftexact) } else { # if not excluding any images: if (!access(image_root//".shiftexact.shall"//n_iter)) nshift ("", in_list//"_coadd_"//n_iter, image_root//"AGDH"//n_iter, image_root, "shall"//n_iter, redo=re_do, useimages=images_use, displayim=im_display, editfiles=files_edit) fields(image_root//".shiftexact.shall"//n_iter,"1-2",lines="1-1")|scan(baba_xshiftexact,baba_yshiftexact) fields(image_root//".shiftexact.shall"//n_iter,"1-2",lines="2-2")|scan(cdba_xshiftexact,cdba_yshiftexact) fields(image_root//".shiftexact.shall"//n_iter,"1-2",lines="3-3")|scan(ehiba_xshiftexact,ehiba_yshiftexact) fields(image_root//".shiftexact.shall"//n_iter,"1-2",lines="4-4")|scan(fgjba_xshiftexact,fgjba_yshiftexact) fields(image_root//".shiftexact.shall"//n_iter,"1-2",lines="5-5")|scan(mlkba_xshiftexact,mlkba_yshiftexact) fields(image_root//".shiftexact.shall"//n_iter,"1-2",lines="6-6")|scan(onba_xshiftexact,onba_yshiftexact) fields(image_root//".shiftexact.shall"//n_iter,"1-2",lines="7-7")|scan(tspba_xshiftexact,tspba_yshiftexact) fields(image_root//".shiftexact.shall"//n_iter,"1-2",lines="8-8")|scan(urqba_xshiftexact,urqba_yshiftexact) fields(image_root//".shiftexact.shall"//n_iter,"1-2",lines="9-9")|scan(vwxba_xshiftexact,vwxba_yshiftexact) } } if(baba_xshiftexact>=0)xbaba=int(0.5+baba_xshiftexact) if(baba_yshiftexact>=0)ybaba=int(0.5+baba_yshiftexact) if(baba_xshiftexact<0)xbaba=int(-0.5+baba_xshiftexact) if(baba_yshiftexact<0)ybaba=int(-0.5+baba_yshiftexact) if(cdba_xshiftexact>=0)xcdba=int(0.5+cdba_xshiftexact) if(cdba_yshiftexact>=0)ycdba=int(0.5+cdba_yshiftexact) if(cdba_xshiftexact<0)xcdba=int(-0.5+cdba_xshiftexact) if(cdba_yshiftexact<0)ycdba=int(-0.5+cdba_yshiftexact) if(ehiba_xshiftexact>=0)xehiba=int(0.5+ehiba_xshiftexact) if(ehiba_yshiftexact>=0)yehiba=int(0.5+ehiba_yshiftexact) if(ehiba_xshiftexact<0)xehiba=int(-0.5+ehiba_xshiftexact) if(ehiba_yshiftexact<0)yehiba=int(-0.5+ehiba_yshiftexact) if(fgjba_xshiftexact>=0)xfgjba=int(0.5+fgjba_xshiftexact) if(fgjba_yshiftexact>=0)yfgjba=int(0.5+fgjba_yshiftexact) if(fgjba_xshiftexact<0)xfgjba=int(-0.5+fgjba_xshiftexact) if(fgjba_yshiftexact<0)yfgjba=int(-0.5+fgjba_yshiftexact) if(mlkba_xshiftexact>=0)xmlkba=int(0.5+mlkba_xshiftexact) if(mlkba_yshiftexact>=0)ymlkba=int(0.5+mlkba_yshiftexact) if(mlkba_xshiftexact<0)xmlkba=int(-0.5+mlkba_xshiftexact) if(mlkba_yshiftexact<0)ymlkba=int(-0.5+mlkba_yshiftexact) if(onba_xshiftexact>=0)xonba=int(0.5+onba_xshiftexact) if(onba_yshiftexact>=0)yonba=int(0.5+onba_yshiftexact) if(onba_xshiftexact<0)xonba=int(-0.5+onba_xshiftexact) if(onba_yshiftexact<0)yonba=int(-0.5+onba_yshiftexact) if(tspba_xshiftexact>=0)xtspba=int(0.5+tspba_xshiftexact) if(tspba_yshiftexact>=0)ytspba=int(0.5+tspba_yshiftexact) if(tspba_xshiftexact<0)xtspba=int(-0.5+tspba_xshiftexact) if(tspba_yshiftexact<0)ytspba=int(-0.5+tspba_yshiftexact) if(urqba_xshiftexact>=0)xurqba=int(0.5+urqba_xshiftexact) if(urqba_yshiftexact>=0)yurqba=int(0.5+urqba_yshiftexact) if(urqba_xshiftexact<0)xurqba=int(-0.5+urqba_xshiftexact) if(urqba_yshiftexact<0)yurqba=int(-0.5+urqba_yshiftexact) if(vwxba_xshiftexact>=0)xvwxba=int(0.5+vwxba_xshiftexact) if(vwxba_yshiftexact>=0)yvwxba=int(0.5+vwxba_yshiftexact) if(vwxba_xshiftexact<0)xvwxba=int(-0.5+vwxba_xshiftexact) if(vwxba_yshiftexact<0)yvwxba=int(-0.5+vwxba_yshiftexact) } # coadd all images at once (w/intermediate most-image coadd if needed) if (p_air=="all" && coadd_allimages) { # first set minimum x,y offsets to be 0 & 0 (independently) if (!access(image_root//".roundoff.shAGDH"//n_iter//"min0")) { list=image_root//".roundoff.shAGDH"//n_iter xmin=9999; ymin=9999 while (fscan(list,xint,yint) !=EOF) { if (xint < xmin) xmin = xint if (yint < ymin) ymin = yint } filecalc(image_root//".roundoff.shAGDH"//n_iter, "$1-"//xmin//";$2-"//ymin, format="%4.0f %4.0f", >> image_root//".roundoff.shAGDH"//n_iter//"min0") } if (!access(image_root//".roundoff.shBJCI"//n_iter//"min0")) { list=image_root//".roundoff.shBJCI"//n_iter xmin=9999; ymin=9999 while (fscan(list,xint,yint) !=EOF) { if (xint < xmin) xmin = xint if (yint < ymin) ymin = yint } filecalc(image_root//".roundoff.shBJCI"//n_iter, "$1-"//xmin//";$2-"//ymin, format="%4.0f %4.0f", >> image_root//".roundoff.shBJCI"//n_iter//"min0") } if (!access(image_root//".roundoff.shFE"//n_iter//"min0")) { list=image_root//".roundoff.shFE"//n_iter xmin=9999; ymin=9999 while (fscan(list,xint,yint) !=EOF) { if (xint < xmin) xmin = xint if (yint < ymin) ymin = yint } filecalc(image_root//".roundoff.shFE"//n_iter, "$1-"//xmin//";$2-"//ymin, format="%4.0f %4.0f", >> image_root//".roundoff.shFE"//n_iter//"min0") } if (!access(image_root//".roundoff.shKL"//n_iter//"min0")) { list=image_root//".roundoff.shKL"//n_iter xmin=9999; ymin=9999 while (fscan(list,xint,yint) !=EOF) { if (xint < xmin) xmin = xint if (yint < ymin) ymin = yint } filecalc(image_root//".roundoff.shKL"//n_iter, "$1-"//xmin//";$2-"//ymin, format="%4.0f %4.0f", >> image_root//".roundoff.shKL"//n_iter//"min0") } # if not excluding any images: if (!exclude) { if(ex_string=="")ex_string=exstring # now offset by offsets to the central image (AGDH) if(!access(in_list//"_all")) concat (in_list//"_AGDH,"//in_list//"_BJCI,"//in_list//"_FE,"//in_list//"_KL", in_list//"_all") if(!access(image_root//".roundoff.shall"//n_iter)) { filecalc (image_root//".roundoff.shAGDH"//n_iter//"min0", "$1+"//xbaba//";$2+"//ybaba, format="%4.0f %4.0f", >> image_root//".roundoff.shall"//n_iter) filecalc (image_root//".roundoff.shBJCI"//n_iter//"min0", "$1+"//xcdba//";$2+"//ycdba, format="%4.0f %4.0f", >> image_root//".roundoff.shall"//n_iter) filecalc (image_root//".roundoff.shFE"//n_iter//"min0", "$1+"//xfgjba//";$2+"//yfgjba, format="%4.0f %4.0f", >> image_root//".roundoff.shall"//n_iter) filecalc (image_root//".roundoff.shKL"//n_iter//"min0", "$1+"//xmlkba//";$2+"//ymlkba, format="%4.0f %4.0f", >> image_root//".roundoff.shall"//n_iter) } # do the coadd print ("\n===> Coadding all images at once...") ircoadd (in_list//"_all", image_root//"all"//n_iter//"_1stpass", "", image_root//".roundoff.shall"//n_iter, "none", "mode", "none", 1, no, "log_"//in_list//"_all", stdpars-, makeavg+, flip-, imcoaddpars="phiirs$ircoaddonis.par") # if excluding any images: } else { if(!access(in_list//"_most")) { # create list of all image lists print (in_list//"_AGDH\n"//in_list//"_BJCI\n"//in_list//"_FE\n"//in_list//"_KL", > "_coaddTmp5_") # create list of all image lists to be included in coadd !fgrep -v -f _coaddTmp1_ _coaddTmp5_ > _coaddTmp6_ concat ("@_coaddTmp6_", in_list//"_most") } # offset the shift lists of all the images to be included in the coadd # by their offsets to the central image (AGDH) if(!access(image_root//".1stpass.shmost"//n_iter)) { # create list of codes of all image lists print ("AGDH\nBJCI\nFE\nKL", > "_coaddTmp7_") # create list of codes of all image lists to be included in coadd !fgrep -v -f _coaddTmp1_ _coaddTmp7_ > _coaddTmp8_ list = "_coaddTmp8_" while (fscan (list, in_string) !=EOF) { if (in_string=="AGDH") { filecalc (image_root//".roundoff.shAGDH"//n_iter//"min0", "$1+"//xbaba//";$2+"//ybaba, format="%4.0f %4.0f", >> image_root//".1stpass.shmost"//n_iter) } else if (in_string=="BJCI") { filecalc (image_root//".roundoff.shBJCI"//n_iter//"min0", "$1+"//xcdba//";$2+"//ycdba, format="%4.0f %4.0f", >> image_root//".1stpass.shmost"//n_iter) } else if (in_string=="FE") { filecalc (image_root//".roundoff.shFE"//n_iter//"min0", "$1+"//xfgjba//";$2+"//yfgjba, format="%4.0f %4.0f", >> image_root//".1stpass.shmost"//n_iter) } else if (in_string=="KL") { filecalc (image_root//".roundoff.shKL"//n_iter//"min0", "$1+"//xmlkba//";$2+"//ymlkba, format="%4.0f %4.0f", >> image_root//".1stpass.shmost"//n_iter) } } del ("_coaddTmp?_", ver-, >& "dev$null") } # do the most-images coadd if (!access(image_root//"most"//n_iter//"_1stpass."//im_extn)) { print ("\n===> Coadding most images at once...") ircoadd (in_list//"_most", image_root//"most"//n_iter//"_1stpass", "", image_root//".1stpass.shmost"//n_iter, "none", "mode", "none", 1, no, "log_"//in_list//"_all", stdpars-, makeavg+, flip-, imcoaddpars="phiirs$ircoaddonis.par") } # do nshift on most-images coadd if (!access(image_root//".roundoff.shrest"//n_iter)) nshift ("", in_list//"_coaddrest_"//n_iter, image_root//"most"//n_iter//"_1stpass", image_root, "shrest"//n_iter, redo=re_do, useimages=images_use, displayim=im_display, editfiles=files_edit) # get shifts for images excluded from most-images coadd if (!access(image_root//".imshifts.shrest"//n_iter)) join(in_list//"_coaddrest_"//n_iter,image_root//".shiftexact.shrest"//n_iter, >>image_root//".imshifts.shrest"//n_iter) grep("AGDH",image_root//".imshifts.shrest"//n_iter)|scan(theory, bamost_xshiftexact, bamost_yshiftexact) if(bamost_xshiftexact>=0)xbamost=int(0.5+bamost_xshiftexact) if(bamost_yshiftexact>=0)ybamost=int(0.5+bamost_yshiftexact) if(bamost_xshiftexact<0)xbamost=int(-0.5+bamost_xshiftexact) if(bamost_yshiftexact<0)ybamost=int(-0.5+bamost_yshiftexact) if (stridx(ex_string,"AGDH")!=0) { grep("AGDH",image_root//".imshifts.shrest"//n_iter)|scan(theory, baba_xshiftexact, baba_yshiftexact) if(baba_xshiftexact>=0)xbaba=int(0.5+baba_xshiftexact)-xbamost if(baba_yshiftexact>=0)ybaba=int(0.5+baba_yshiftexact)-ybamost if(baba_xshiftexact<0)xbaba=int(-0.5+baba_xshiftexact)-xbamost if(baba_yshiftexact<0)ybaba=int(-0.5+baba_yshiftexact)-ybamost } if (stridx(ex_string,"BJCI")!=0) { grep("BJCI",image_root//".imshifts.shrest"//n_iter)|scan(theory,cdba_xshiftexact,cdba_yshiftexact) if(cdba_xshiftexact>=0)xcdba=int(0.5+cdba_xshiftexact)-xbamost if(cdba_yshiftexact>=0)ycdba=int(0.5+cdba_yshiftexact)-ybamost if(cdba_xshiftexact<0)xcdba=int(-0.5+cdba_xshiftexact)-xbamost if(cdba_yshiftexact<0)ycdba=int(-0.5+cdba_yshiftexact)-ybamost } if (stridx(ex_string,"FE")!=0) { grep("FE",image_root//".imshifts.shrest"//n_iter)|scan(theory,fgjba_xshiftexact,fgjba_yshiftexact) if(fgjba_xshiftexact>=0)xfgjba=int(0.5+fgjba_xshiftexact)-xbamost if(fgjba_yshiftexact>=0)yfgjba=int(0.5+fgjba_yshiftexact)-ybamost if(fgjba_xshiftexact<0)xfgjba=int(-0.5+fgjba_xshiftexact)-xbamost if(fgjba_yshiftexact<0)yfgjba=int(-0.5+fgjba_yshiftexact)-ybamost } if (stridx(ex_string,"KL")!=0) { grep("KL",image_root//".imshifts.shrest"//n_iter)|scan(theory,mlkba_xshiftexact,mlkba_yshiftexact) if(mlkba_xshiftexact>=0)xmlkba=int(0.5+mlkba_xshiftexact)-xbamost if(mlkba_yshiftexact>=0)ymlkba=int(0.5+mlkba_yshiftexact)-ybamost if(mlkba_xshiftexact<0)xmlkba=int(-0.5+mlkba_xshiftexact)-xbamost if(mlkba_yshiftexact<0)ymlkba=int(-0.5+mlkba_yshiftexact)-ybamost } # now offset by offsets to the central image (AGDH) if(!access(in_list//"_all")) concat (in_list//"_AGDH,"//in_list//"_BJCI,"//in_list//"_FE,"//in_list//"_KL", in_list//"_all") if(!access(image_root//".1stpass.shall"//n_iter)) { filecalc (image_root//".roundoff.shAGDH"//n_iter//"min0", "$1+"//xbaba//";$2+"//ybaba, format="%4.0f %4.0f", >> image_root//".1stpass.shall"//n_iter) filecalc (image_root//".roundoff.shBJCI"//n_iter//"min0", "$1+"//xcdba//";$2+"//ycdba, format="%4.0f %4.0f", >> image_root//".1stpass.shall"//n_iter) filecalc (image_root//".roundoff.shFE"//n_iter//"min0", "$1+"//xfgjba//";$2+"//yfgjba, format="%4.0f %4.0f", >> image_root//".1stpass.shall"//n_iter) filecalc (image_root//".roundoff.shKL"//n_iter//"min0", "$1+"//xmlkba//";$2+"//ymlkba, format="%4.0f %4.0f", >> image_root//".1stpass.shall"//n_iter) } # do the full coadd print ("\n===> Coadding all images at once...") ircoadd (in_list//"_all", image_root//"all"//n_iter//"_1stpass", "", image_root//".1stpass.shall"//n_iter, "none", "mode", "none", 1, no, "log_"//in_list//"_all", stdpars-, makeavg+, flip-, imcoaddpars="phiirs$ircoaddonis.par") } } # cross-correlate individual images with coadded image if (p_air=="all" && xcor_secondpass) { ixdim=xsize; iydim=ysize if(!access(sigprefix//image_root//"all"//n_iter//"_1stpass."//im_extn)){ print ("\n===> Creating constant-RMS coadded image...") sigmanorm(image_root//"all"//n_iter//"_1stpass."//im_extn) } imgets(sigprefix//image_root//"all"//n_iter//"_1stpass","i_naxis1") oxdim=int(imgets.value) imgets(sigprefix//image_root//"all"//n_iter//"_1stpass","i_naxis2") oydim=int(imgets.value) list=image_root//"all"//n_iter//"_1stpass.imshifts" if (!access(image_root//"all"//n_iter//"_xregout")) { print("\n===> Cross-correlating individual images w/coadded image...") while (fscan(list,image_name,x_shift,y_shift) !=EOF) { # zero out bad pixels if not already done imgets(image_name,"ZEROOUT") zero_out=imgets.value if(zero_out=="0"){ imgets(image_name,"BPMASK") if(imgets.value!="0"){ imar(image_name,"*",imgets.value,image_name,pixt="real",calct="real",ver-,noac-) hedit(image_name,"ZEROOUT",imgets.value,add+,ver-,show-,update+) } else { print("Bad pixels not zeroed for "//image_name//", and no BP mask in header!") } } if(xsize==0){ imgets(image_name,"i_naxis1") ixdim=int(imgets.value) } if(ysize==0){ imgets(image_name,"i_naxis2") iydim=int(imgets.value) } ix=x_shift+1-14; if(ix<1)ix=1 iy=y_shift+1-14; if(iy<1)iy=1 xe=x_shift + ixdim + 14; if(xe>oxdim)xe=oxdim ye=y_shift + iydim + 14; if(ye>oydim)ye=oydim msect = "["//ix//":"//xe//","//iy//":"//ye//"]" print ("Rough shift from "//image_name//" to "//sigprefix//image_root//"all"//n_iter//"_1stpass is "//x_shift//" "//y_shift//" pixels") immatch.xreg (image_name, sigprefix//image_root//"all"//n_iter//"_1stpass", msect, image_root//"all"//n_iter//"_xregout", datab+, records="", xlag=-1*x_shift, ylag=-1*y_shift, xwindow=25, ywindow=25, append+) } } tempx = mktemp("tempx"); tempy = mktemp("tempy") grep ('xshift', image_root//"all"//n_iter//"_xregout") | fields ("junk", "2", >> tempx) grep ('yshift', image_root//"all"//n_iter//"_xregout") | fields ("junk", "2", >> tempy) if(!access(image_root//".xregexact.shall"//n_iter)) join (tempx, tempy, output=image_root//".xregexact.shall"//n_iter) del (tempx, ver-); del (tempy, ver-) # Create optimum rounded-off integer offsets if (!access(rroundname)) { print("\n===> Finding optimum second-pass rounded-off integer offsets...") old_x = 999.; old_y = 999. # for each 0.01 pixel step... for (i=-50; i<50; i+=1) { step = i / 100. # print (i) # ...recalculate integer offsets... list=image_root//".xregexact.shall"//n_iter del (rroundname, ver-, >& "dev$null") while(fscan(list,xoff,yoff) !=EOF) { xoff=xoff+step yoff=yoff+step if(((abs(xoff))>=0.5) && ((abs(yoff))>=0.5)) { print(xoff,yoff, >> "temp."//rroundname) } else { if((abs(xoff))<=0.5) { xoff=0. } if((abs(yoff))<=0.5) { yoff=0. } print(xoff,yoff, >> "temp."//rroundname) } filecalc("temp."//rroundname, "$1;$2", format="%4.0f %4.0f", >> rroundname) flpr; flpr; flpr del ("temp."//rroundname, ver-, >& "dev$null") } del ("temp."//rroundname, ver-, >& "dev$null") # calculate sum of squares of residuals of exact offsets - new integer offsets filecalc (image_root//".xregexact.shall"//n_iter//","//rroundname, "$1@1-$1@2+"//step) | average (option = "new_sample", >& "dev$null") flpr; flpr; flpr new_x=average.sumsqrs filecalc (image_root//".xregexact.shall"//n_iter//","//rroundname, "$2@1-$2@2+"//step) | average (option = "new_sample", >& "dev$null") flpr; flpr; flpr new_y=average.sumsqrs if (new_x < old_x) { old_x = new_x step_x = step } if (new_y < old_y) { old_y = new_y step_y = step } } # recalculate final integer offsets list=image_root//".xregexact.shall"//n_iter del(rroundname,ver-) del ("temp."//rroundname, ver-, >& "dev$null") while(fscan(list,xoff,yoff) !=EOF) { xoff=xoff+step_x yoff=yoff+step_y if(((abs(xoff))>=0.5) && ((abs(yoff))>=0.5)) { print(xoff,yoff, >> "temp."//rroundname) } else { if((abs(xoff))<=0.5) { xoff=0. } if((abs(yoff))<=0.5) { yoff=0. } print(xoff,yoff, >> "temp."//rroundname) } filecalc("temp."//rroundname,"$1;$2",format="%4.0f %4.0f",>>rroundname) flpr; flpr; flpr del ("temp."//rroundname, ver-, >& "dev$null") } del ("temp."//rroundname, ver-, >& "dev$null") } del ("temp."//rroundname, ver-, >& "dev$null") filecalc (rroundname//","//image_root//".1stpass.shall"//n_iter, "$1@1-$1@2", lines="1-") | average filecalc (rroundname//","//image_root//".1stpass.shall"//n_iter, "$1@1-$1@2-"//average.mean, lines="1-", >> "temp."//rroundname) filecalc (rroundname//","//image_root//".1stpass.shall"//n_iter, "$2@1-$2@2", lines="1-") | average filecalc (rroundname//","//image_root//".1stpass.shall"//n_iter, "$2@1-$2@2-"//average.mean, lines="1-", >> "temp."//rroundname) graph ("temp."//rroundname, point-, title="mean-subtracted 2ndpass - 1stpass x and y offsets") del ("temp."//rroundname, ver-, >& "dev$null") } # Coadd images after second-pass cross-correlation if (p_air=="all" && coadd_secondpass) { print ("\n===> Coadding after second-pass cross-correlation...") ircoadd(in_list//"_all", image_root//"all"//n_iter, "", rroundname, "none", "mode", "none", 1, no, "log_"//in_list//"_all", stdpars-, makeavg-, flip-, imcoaddpars="phiirs$ircoaddonis.par") # ircoadd(in_list//"_all", image_root//"all"//n_iter//"avg", "", rroundname, "none", "mode", "none", 1, no, "log_"//in_list//"_all", stdpars-, makeavg+, flip-, imcoaddpars="phiirs$ircoaddonis.par") } # Make coadded-image object mask if (p_air=="all" && do_mkobjmask) { print ("\n===> Making coadded-image object mask...") mkobjmask (image_root//"all"//n_iter//"."//im_extn, "", suffix="objmask", nsmooth=3, subsample=3, filtsize=15, ngrow=1, interact+) } # Make individual-image object masks if (p_air=="all" && do_masklet) { print ("\n===> Making individual-image object masks...") masklet (image_root//"all"//n_iter, "", "om", shiftfile="", editfile+, flip-, update+) } } else { print ("\nWARNING! Package stsdas.imgtools not loaded... task aborted.") } if (echo_g) beep end ./maskstat.cl0100644000151400000240000002206607124510034012332 0ustar phallgamesprocedure maskstat(image,mask,goodvalue) # Calculates images statistics from unmasked regions of an input frame. # * Mask file must have only values of 0 and 1! # * Parameter 'iterstat' gives the option of calling iterative statistics # routine iterstat instead of imstat. # * It is assumed that the user will have set the parameters for imstat # or iterstat in whatever manner is desired. This routine does not # set those parameters except using lower= to exclude the masked pixels. # * Checks to see if stsdas.tools is loaded. If so, it uses imcalc to do the # calculation; otherwise, it uses a slower combination of imarith statements. # Calls scripts minv and possibly iterstat. # **BUG**: will not work if IRAF parameter imtype = "*,inherit" (imcalc bug) # **BUG** premature end of mask list if one mask image specified for many files # **BUG** minmax step means that in an image with a high and nonzero mean, # 0-valued pixels will not be outside the initial iterstat range, which might # make itersig high enough that such pixels will (erroneously, presumably) # not be excluded in any of the iterations. # 930722: created by Mark Dickinson # 950216: got rid of imcalc option-- couldn't handle long input image names # 950314: adjusted use of `sections' task-- risk of collision w/other tasks # 960405: added option to take masks from a header keyword # 960413: added option to not print iterstat output # 960416: fixed bug for 1-entry list, and cleaned up code using `| scan' # 970429: added insertion of iterstat results into image header if iterstat+ # 970501: fixed bug that pixel masks can't have negative or non-integer values # 970508: insert iterstat results into image header if iterstat+ and addheader+ # 970620: allow for explicit temporary changing of iterstat params if desired # 970714: added MASKMASK header param (= mask used) if iterstat+ addheader+ # 970930: fixed bug relating to .pl image being mulitplied by too large a # # 990128: (hopefully) fixed bug of undeleted _minvfile (now .pl not .imh) # 990203: (hopefully) fixed minor bugs for various parameter combinations # 990224: added stsdas.toolbox.imgtools.imcalc option -- slightly faster # 990406: uses temp files so >1 copy of task can run simult. in same directory # 990513: removed need for inverting mask through smarter use of imcalc # 000521: added mask inversion step back in for non-imcalc situations string image {prompt="Input image(s) or list"} string mask {prompt="Input mask(s), list, or !"} int goodvalue {1,min=0,max=1,prompt="Good pixel value in mask"} real nsigrej {5.,min=0.,prompt="Number of sigmas for limits"} int maxiter {10,min=1,prompt="Maximum number of iterations"} real lower {INDEF,prompt="Initial lower limit for data range"} real upper {INDEF,prompt="Initial upper limit for data range"} bool verbose {no,prompt="Verbose output?"} bool iterstat {no,prompt="Use iterstat instead of imstat?"} bool addheader {yes,prompt="Add iterstat output to image header?"} bool printit {yes,prompt="Print iterstat output?"} struct *inimglist struct *mlist begin string check # `@filename' check string imglist # equals image string ext # equals image extension string msk # equals mask string mskfile # temporary mask file string keyword # mask header keyword string mfile # name of individual mask file string mf # name of individual mask file without .pl string minvfile # inverted mask file string minvstring # string for inverted mask file string infile # temporary list for files string j4 # temp string int goodv # equals goodvalue int nimgs,nmask # number of input images and masks int j1,j2,j3 # temp values real minval # lower limit for image statistics calculation real maxval # upper limit of image statistics real flagval # flag value bool indel # delete input list file? bool maskdel # delete mask list file? # Get query parameters & expand input lists imglist = image msk = mask if(msk=="")msk="!BPM" goodv = goodvalue maskdel = no indel = no # Expand file lists into temporary files. infile = imglist check = substr(imglist,1,1) if(check=="@"){ infile=substr(imglist,2,strlen(imglist)) count(infile) | scan(nimgs) #print("a") } else { infile = mktemp("tmp$maskstat") indel=yes sections(imglist,option="fullname",>infile) count(infile) | scan(nimgs) #print("b") } inimglist = infile #print("one") # Exact same spiel for list of masks, with extra step if only one mask. mskfile = msk check = substr(msk,1,1) if(check=="@" || check=="!"){ if(check=="!"){ maskdel=yes keyword=substr(msk,2,strlen(msk)) mskfile = mktemp("tmp$maskstat") hsel("@"//infile,(keyword),yes, >> mskfile) #print("c") } if(check=="@"){ mskfile=substr(msk,2,strlen(msk)) #print("d") } count (mskfile) | scan (nmask) } else { mskfile = mktemp("tmp$maskstat") maskdel=yes sections(msk,option="fullname",>mskfile) count (mskfile) | scan (nmask) #print("e") if (nmask == 1) { mfile = msk fileroot(mfile,validim+) if (!defpac("imgtools")) { minvstring = mktemp("_"//fileroot.root) minvfile = minvstring//".pl" if(access(minvfile))imdel(minvfile,ver-) minv (mfile,minvfile) } #print("f") } } mlist = mskfile if ((nmask != nimgs) && nmask != 1) { print ("ERROR: Numbers of image and mask files differ.") return } #print("two") # Loop through input files. while (fscan(inimglist,img) != EOF) { fileroot(img,validim+) ext=fileroot.extension if(ext!="")ext="."//ext #print("thr") # Get name of mask file # get from mlist if check=="@" or nmask != 1; if nmask==1 mfile already set if (check == "@" || check == "!" || nmask != 1) { #print("g") if (fscan(mlist,mfile) != EOF) { fileroot(mfile,validim+) if (!defpac("imgtools")) { minvstring = mktemp("_"//fileroot.root) minvfile = minvstring//".pl" if(access(minvfile))imdel(minvfile,ver-) minv (mfile,minvfile) } #print("h") } else { print ("ERROR: Premature end of mask list.") return } } #print("for") # Strip extension off mask name and save root as variable mf for later use. fileroot (mfile,validim+) mf = mktemp(fileroot.root) ext=fileroot.extension if(ext!="")ext="."//ext if(access("_x"//mf//ext))imdel("_x"//mf//ext,ver-) #print("fiv") if (verbose) print ("Calculating statistics for ",img," using mask ",mfile) minmax (img,force+,update-,ver-) minval = minmax.minval maxval = minmax.maxval if (lower == INDEF) { flagval = 2 * minval - maxval } else { minval = lower flagval = 2 * lower - maxval } flagval = -1 * abs(int(flagval)) #print("six") #print(img//" "//mfile//" "//minvfile) #print(img//" "//mfile//" "//mf//" "//ext) # Masking replaces bad pixels with "flagval" and leaves good pixels unchanged. imdel ("_"//img, ver-, >& "dev$null") if (goodv == 0) { if(defpac("imgtools")) { imcalc (img//","//mfile, "_"//img, "if im2 .eq. 1 then "//flagval//" else im1", pixty="real", ver-) # imcalc (img//","//minvfile//","//mfile, "_"//img, "im1*im2-im3*"//abs(int(flagval)), pixty="real",ver-) } else { imar (img,"*",minvfile,"_"//img,pixty="real",calcty="real",ver-) imar (mfile,"*",abs(int(flagval)),"_x"//mf,pixty="real",calcty="real",ver-) imar ("_"//img,"-","_x"//mf,"_"//img,pixty="real",calcty="real",ver-) } } else { if(defpac("imgtools")) { imcalc (img//","//mfile, "_"//img, "if im2 .eq. 0 then "//flagval//" else im1", pixty="real", ver-) # imcalc (img//","//mfile//","//minvfile, "_"//img, "im1*im2-im3*"//abs(int(flagval)), pixty="real",ver-) } else { imar (img,"*",mfile,"_"//img,pixty="real",calcty="real",ver-) imar (minvfile,"*",abs(int(flagval)),"_x"//mf,pixty="real",calcty="real",ver-) imar ("_"//img,"-","_x"//mf,"_"//img,pixty="real",calcty="real",ver-) } } #print("sev") if (iterstat) { if (printit) { iterstat ("_"//img,lower=minval,nsigrej=nsigrej,maxiter=maxiter,upper=upper,verbose=verbose,print+,addh-) } else { iterstat ("_"//img,lower=minval,nsigrej=nsigrej,maxiter=maxiter,upper=upper,verbose=verbose,print-,addh-) } if (addheader) { hedit (img, "MASKMASK", msk, add+, ver-,show-,update+) hedit (img, "ITERMEAN", iterstat.mean, add+, ver-,show-,update+) hedit (img, "ITERSIG", iterstat.sigma, add+, ver-,show-,update+) hedit (img, "VARIANCE", iterstat.variance,add+,ver-,sho-,updat+) hedit (img, "ITERMED", iterstat.median, add+,ver-,show-,update+) hedit (img, "ITERMODE", iterstat.valmode,add+,ver-,show-,updat+) } } else { imstat ("_"//img,lower=minval,upper=upper) if (addheader) { hedit(img,"MASKMASK",msk,add+,ver-,show-,updat+) } } imdelete ("_"//img,ver-,>&"dev$null") imdelete ("_x"//mf,ver-,>&"dev$null") if (nmask != 1 && !defpac("imgtools")) imdel (minvfile,ver-,>&"dev$null") } #print("ate") if (nmask == 1 && !defpac("imgtools")) imdel(minvfile,ver-,>&"dev$null") #print("nin") if(indel)delete(infile,ver-,>&"dev$null") if(maskdel)delete(mskfile,ver-,>&"dev$null") inimglist = "" mlist = "" end ./mkbpm.cl0100644000151400000240000000364006720573001011612 0ustar phallgames# #imcombine @l_hhion hhion #imcombine @l_khion khion #imcombine @l_jhion jhion #imcombine @l_jloon jloon #imcombine @l_hloon hloon #imcombine @l_kloon kloon # #imar khion / kloon khidivlo #imar hhion / hloon hhidivlo #imar jhion / jloon jhidivlo # #iterstat *hidivlo.fits ##IMAGE MEAN RMS NPIX MEDIAN MODE #hhidivlo.fits 1.962901 0.007448982 1041439 1.962677 1.96279 #jhidivlo.fits 1.960372 0.007922052 1041442 1.960526 1.96135 #khidivlo.fits 1.958461 0.006485879 1038781 1.957977 1.957864 # #= 1.962901 - 5 * 0.007448982 #= 1.962901 + 5 * 0.007448982 #= 1.960372 - 5 * 0.007922052 #= 1.960372 + 5 * 0.007922052 #= 1.958461 - 5 * 0.006485879 #= 1.958461 + 5 * 0.006485879 imcopy hhidivlo.fits hbpm1.fits imcopy jhidivlo.fits jbpm1.fits imcopy khidivlo.fits kbpm1.fits imreplace hbpm1 1.962901 lower=1.92565609 upper=2.00014591 imreplace hbpm1 0. lower=INDEF upper=1.92565609 imreplace hbpm1 0. lower=2.00014591 upper=INDEF imreplace jbpm1 1.960372 lower=1.92076174 upper=1.99998226 imreplace jbpm1 0. lower=INDEF upper=1.92076174 imreplace jbpm1 0. lower=1.99998226 upper=INDEF imreplace kbpm1 1.958461 lower=1.926031605 upper=1.990890395 imreplace kbpm1 0. lower=INDEF upper=1.926031605 imreplace kbpm1 0. lower=1.990890395 upper=INDEF imar hbpm1.fits / 1.962901 hbpm2.fits imar jbpm1.fits / 1.960372 jbpm2.fits imar kbpm1.fits / 1.958461 kbpm2.fits imreplace hbpm2.fits 1. lower=0.98 upper=INDEF imreplace jbpm2.fits 1. lower=0.98 upper=INDEF imreplace kbpm2.fits 1. lower=0.98 upper=INDEF imar hbpm2 * jbpm2 anybpm2 imar anybpm2 * kbpm2 anybpm2 # ?bpm2.fits have bp 0, goodpix 1 imcalc jbpm2,hbpm2,kbpm2 allbpm2.fits "if im1 .eq. 0 and im2 .eq. 0 and im3 .eq. 0 then 0 else 1" ##minv hbpm2.fits hbpm2inv.fits ##minv jbpm2.fits jbpm2inv.fits ##minv kbpm2.fits kbpm2inv.fits ##imar hbpm2inv.fits * jbpm2inv.fits allbpm2.fits ##imar allbpm2.fits * kbpm2inv.fits allbpm2.fits #imcopy allbpm2.fits bpmkir98ii.pl ./multimasklet.cl0100644000151400000240000001176506720573001013226 0ustar phallgames# multimasklet -- remove spurious objects from mask & masklet w/old or new mask # # 990512: created from masklet.cl # redefine multimasklet = phiirs$workdir/multimasklet.cl #display image #display rawmask #display longaxis images (exploded view) #imexam rawmask #after each bad pixel grouping, hit q and enter good-image letter, imexam again? # e.g. log_imexam --> log_imexam_A #take each good image letter and make a separate objmask for each # get x,y for a bad pixel w/in area of a spurious object in the mask # imreplace x,y to good # get coords (listpix) of all bad pixels in x-1:x+1,y-1:y+1 # if none, end # else imreplace to good & repeat with xmin-1:xmax+1,ymin-1:ymax+1 # where xmin:xmax,ymin:ymax spans the range of bad pixels #take list of images from each good letter, extract them from *.imshifts, # add the mask name to each line, and dump to *.imshiftsmasks procedure multimasklet (image,rawmask,cleanmask,suffix) string image {prompt="Coadded Image"} string rawmask {prompt="Object mask for Coadded Image (default=image//objmask)"} string cleanmask {prompt="Output cleaned object mask (default=rawmask//clean)"} string suffix="om" {prompt="Suffix for output individual-image object masks"} string shiftfile="" {prompt="Image+Shifts file (default=image//.imshifts)"} string shiftmaskfile="" {prompt="Output Image+Shifts+Mask file (default=shiftfile//masks)"} bool editfile=yes {prompt="Edit Image+Shifts+Mask file?"} bool flip=no {prompt="Flip object mask L-R before creating masklets?"} bool update=yes {prompt="Update image headers with object mask name?"} bool echog=yes {prompt="Beep when task is done?"} struct *imglist begin string oimg # equals image string maskimg # equals rawmask string clean_mask # equals cleanmask string ssuffix # equals suffix string img # fscanned name of individual input image string word # original object mask title string int ix,iy # start pixel coords for input image from .imshifts file int xe, ye # end pixel coordinages for input images string ushiftlist # equals shiftfile string ushiftmasklist # equals shiftmaskfile int oxdim,oydim # dimensions of mask image int ixdim,iydim # dimensions of individual input frames string msect # subsection of mask to extract for individual images bool edit_file # equals editfile # Get query parameters fileroot (image,validim+) oimg = fileroot.root maskimg = rawmask if(maskimg=="")maskimg=oimg//"rawmask" clean_mask = cleanmask if(cleanmask=="")cleanmask=maskimg//"clean" ssuffix = suffix # Verify that the oimg.imshifts file exists. if (shiftfile!="") {ushiftlist=shiftfile} else {ushiftlist = oimg//".imshifts"} if (!access(ushiftlist)) { beep print ("ERROR: file ",ushiftlist," does not exist.") return } if (shiftmaskfile!="") {ushiftmasklist=shiftmaskfile} else {ushiftmasklist = ushiftlist//"masks"} edit_file=editfile # ** start editing here # Allow editing of imshifts file if (edit_file) { print("Edit the imshifts file and replace the flatfielded,") print("skysubtracted image names with the image names that will be") print("the input to `irflat objmask+' or `irsky objmask+' so that the") print("object mask keyword is inserted into the correct image headers.") print("#Edit this imshifts file and replace the flatfielded,", >>ushiftlist) print("#skysubtracted image names with the image names that will be", >> ushiftlist) print("#the input to `irflat objmask+' or `irsky objmask+' so that the", >> ushiftlist) print("#object mask keyword is inserted into the correct image headers.", >> ushiftlist) vi(ushiftlist) } # Flip mask if desired if(flip){ imcopy(maskimg//"[-*,*]","_objmask",ver-) } else { imcopy(maskimg,"_objmask",ver-) } hedit("_objmask","title","Object mask for image ",add+,ver-,show-,update+) # Get dimensions of mask image from image mosaic produced by shiftfix. imgets("_objmask","i_naxis1") oxdim=int(imgets.value) imgets("_objmask","i_naxis2") oydim=int(imgets.value) # Rewind file list. imglist=ushiftlist # Make working mask images, one for each input image, by cutting out # appropriate subsection of the large input mask image. while (fscan(imglist,img,ix,iy) != EOF) { fileroot (img,validim+) img = fileroot.root print ("Making mask image "//img//ssuffix//".pl for ",img) imgets(img,"i_naxis1") ixdim=int(imgets.value) imgets(img,"i_naxis2") iydim=int(imgets.value) ix+=1 iy+=1 xe=ix + ixdim - 1 ye=iy + iydim - 1 msect = "["//ix//":"//xe//","//iy//":"//ye//"]" print(msect) imcopy("_objmask"//msect,img//ssuffix//".pl",ver-) imgets(img//ssuffix//".pl","title") word=imgets.value//" "//img hedit(img//ssuffix//".pl","title",word,add+,ver-,show-,update+) # If update=yes, insert mask name into input image headers with OBJMASK card. if (update) hedit(img,"OBJMASK",img//ssuffix//".pl",add+,ver-,up+,sho-) } # Clean up. print("All done. Next task to run is `irflat objmask+' or `irsky objmask+'.") imdel("_objmask",ver-) imglist = "" if(echog)beep end ./nshift.cl0100644000151400000240000005042106720577164012014 0ustar phallgames# nshift -- find offsets for N images or image sets overlapping a central image # # Task calls following other tasks: fileroot, filecalc. # # Output: # prefix.refcoords.suffix registration objects' reference image coords # prefix.allcoords.suffix registration objects' coordinates in all images # prefix.offsets.suffix final shifts logfile, + coarse and final shifts # prefix.imshifts.suffix image names and rounded int. shifts on same line # prefix.shiftfrac.suffix fractional part of final shifts # prefix.shiftint.suffix integer part of final shifts # prefix.roundoff.suffix final shifts rounded off to integer shifts # (optional): # @flatlist//suffix.imh fractionally-shifted images # flatlist//suffix list of fractionally-shifted images # # CHANGES: # 990422: created from irshift.cl # 990423: added xregister option (xcor) # 990519: added zero-out of bad pixels before xcor # # --should interpolate over bad pixels before shifting # --might use iteravg to automatically reject extended objects in refcoords procedure nshift(filelist,flatlist,refimage,prefix,suffix) string filelist="" {prompt="File of image lists to find offsets for (no @)"} string flatlist {prompt="Overall list of images to find offsets for (no @)"} string refimage {prompt="Name of (flattened) reference image"} string prefix {prompt="Prefix string for output files"} string suffix {prompt="Suffix string for output files"} bool fracshift=no {prompt="Create fractional-pixel-offset images?"} string interp {"poly5",enum="nearest|linear|poly3|poly5|spline3",prompt="Interpolation type"} string boundary {"nearest",enum="constant|nearest|reflect|wrap",prompt="Boundary type"} string badmask="" {prompt="Bad pixel mask for shifted images (blank=old mask)",mode="q"} bool redo=no {prompt="Erase files and redo shift-finding if already done?"} bool useimages=yes {prompt="Measure shifts from images instead of a file?"} bool displayim=yes {prompt="Display images for imexam?"} bool ptv=no {prompt="Use phat.ptv instead of display in imexam?"} string imsection="" {prompt="Image section to display in imexam?"} bool editfiles=yes {prompt="Display coords files for editing?"} bool xcor=yes {prompt="Use image cross-correlation to find shifts?"} int xsize=0 {prompt="X-axis image size (0 for autosense) for cross-correlation"} int ysize=0 {prompt="Y-axis image size (0 for autosense) for cross-correlation"} string inputlist {prompt="File with coordinate info", mode="q"} bool combdata=no {prompt="Combine shifts with earlier dataset? (NOT TESTED)"} real xshiftold {prompt="Reference image x shift in earlier dataset"} real yshiftold {prompt="Reference image y shift in earlier dataset"} real radius=5. {prompt="Imexamine aperture photometry radius"} real buffer=10. {prompt="Imexamine sky buffer"} real width=10. {prompt="Imexamine sky annulus width"} real bs=9. {prompt="Centering box size for final shift calculation"} bool echog {yes,prompt="Beep when task is done?"} struct *iinputlist struct *list begin string rrefimage, fflatlist, rrefcoords, aallcoords, bbadmask, rroundname, ext string sshiftlist, coarsefile, ooffname, ssuffix, iintname, ffracname, ooptname string pprefix, logoffname, sl, sx, img, iinterp, bboundary, im_section string file_list, nooffname, nlogoffname, naallcoords, nrrefcoords, ncoarsefile string niintname, nffracname, nrroundname, flat_list, flat_image, tmplist string tmpfile1, tmpfile2, image_name, msect, tempx, tempy, zero_out string fr_image_name, fr_rrefimage real p, pixscale, stcoordx, stcoordy, nrows, ncols, delx, dely, adelx, adely real xold, yold, bbs, xxshiftold, yyshiftold, xshiftnew, yshiftnew, astcoordx real astcoordy, nl, nx, x, y, xoff, yoff real new_x, new_y, old_x, old_y, exact_x, exact_y, step, step_x, step_y real nxxshiftold, nyyshiftold int xref, yref, int_x, int_y, n, x_shift, y_shift, xe, ye, ix, iy int oxdim, oydim, ixdim, iydim bool uuseimages, ffracshift, ccombdata, go, ddisplayim, edit_files, notalist bool do_xcor, re_do # The "go" parameter won't let the task run if you haven't loaded the ctio pkg. go=yes if(!deftask("filecalc")) {go=no} if(!deftask("fileroot")) {go=no} if(ptv && !deftask("ptv")) {go=no} if(go) { file_list = filelist notalist = no flat_list = flatlist if (file_list=="") { notalist = yes } rrefimage = refimage pprefix = prefix ssuffix = suffix ffracshift = fracshift if(ffracshift)bbadmask=badmask re_do = redo uuseimages = useimages ddisplayim = displayim im_section = imsection edit_files = editfiles do_xcor = xcor ccombdata = combdata bbs = bs ooffname = pprefix//".shiftexact."//ssuffix logoffname = pprefix//".offsets."//ssuffix rrefcoords = pprefix//".refcoords."//ssuffix aallcoords = pprefix//".allcoords."//ssuffix coarsefile = pprefix//".coarse."//ssuffix iintname = pprefix//".shiftint."//ssuffix ffracname = pprefix//".shiftfrac."//ssuffix rroundname = pprefix//".roundoff."//ssuffix # nshift: Find offsets for each individual list of images in file_list n = 0 if (notalist) { tmplist = flat_list } else { tmplist = file_list } list = tmplist while (fscan (list, fflatlist) !=EOF) { n = n + 1 nrrefcoords = rrefcoords//"_"//n naallcoords = aallcoords//"_"//n ncoarsefile = coarsefile//"_"//n print ("# "//fflatlist, >> nrrefcoords); print ("# ", >> nrrefcoords) print ("# "//fflatlist, >> naallcoords); print ("# ", >> naallcoords) if(ccombdata){ print(" ") print("===> So you wanna add some new images to an old coadd, eh? Well, first make") print("===> sure you're using the same reference image as that old set. Then, take") print("===> a look at the *.offsets.* file from that set, find the fractional") print("===> offsets made on the reference image, and enter them here:") nxxshiftold=xshiftold nyyshiftold=yshiftold } # nshift: get reference image coordinates of one object for coarse registration if(ddisplayim){ if (!notalist) { fields (fflatlist, "1", lines="1-1") | scan (flat_image) print(" ") print("===> Displaying "//flat_image//" in frame 2 for convenience,") } else { fields (flat_list, "1", lines=n//"-"//n) | scan (flat_image) print(" ") print("===> Displaying "//flat_image//" in frame 2,") } print("===> and reference image "//rrefimage//" in 1 for examination.") print(" ") print("===> Get the coords (hit 'a') in the reference image (frame 1) of ONE object") print("===> visible in all images, for coarse registration. Hit 'q' when done.") print(" ") rimexam.radius=radius rimexam.buffer=buffer rimexam.width=width if (ptv) { ptv (flat_image, frame=2) imexam(rrefimage, frame=1, logfile=nrrefcoords, keep+, display="ptv(image='$1',frame=$2)") } else { displ (flat_image, frame=2) imexam(rrefimage, frame=1, logfile=nrrefcoords, keep+) } } # First method: ID objects from images if(uuseimages){ # ... interactively ... if(ddisplayim){ if (ptv) { if (notalist) { print(" ") print("===> Get the coordinates (hit 'a') in this image of the object") print("===> just marked in the reference image. Hit 'q' when done.") print(" ") imexam(fflatlist, frame=1, logfile=naallcoords, keep+, display="ptv(image='$1"//im_section//"',frame=$2)") } else { print(" ") print("===> Choose one object that appears in all images, & find the position") print("===> (hit 'a') of this object in each frame (hit 'n' to go on to the") print("===> next frame, and 'q' when done). The file of these positions") print("===> will be displayed for editing when done, in case of mistakes.") print(" ") imexam("@"//fflatlist, frame=1, logfile=naallcoords, keep+, display="ptv(image='$1"//im_section//"',frame=$2)") } } else { if (notalist) { print(" ") print("===> Get the coordinates (hit 'a') in this image of the object") print("===> just marked in the reference image. Hit 'q' when done.") print(" ") imexam(fflatlist, frame=1, logfile=naallcoords, keep+, display="display(image='$1"//im_section//"',frame=$2)") } else { print(" ") print("===> Choose one object that appears in all images, & find the position") print("===> (hit 'a') of this object in each frame (hit 'n' to go on to the") print("===> next frame, and 'q' when done). The file of these positions") print("===> will be displayed for editing when done, in case of mistakes.") print(" ") imexam("@"//fflatlist, frame=1, logfile=naallcoords, keep+, display="display(image='$1"//im_section//"',frame=$2)") } } } else { # ... or non-interactively ... print("===> Images not displayed.") } if(edit_files){ print(" ") print("===> In case of mistakes, both coordinate files can now be edited.") vi(nrrefcoords) vi(naallcoords) } print(" ") print("===> Finding the coarse offsets...") fields (nrrefcoords, "1-2") | scan (xref, yref) if((!access(ncoarsefile)) || (re_do && access(ncoarsefile))) { del(ncoarsefile,ver-,>&"dev$null") lintran(naallcoords,x1=0.001,y1=0.001,x2=xref,y2=yref,angle=180, >ncoarsefile) } } # Second method: estimate shifts from telescope offsets if(!uuseimages){ iinputlist=inputlist print("Generating initial shift file from file "//inputlist//".") while (fscan (iinputlist, pixscale, astcoordx, astcoordy, nrows, ncols, adelx, adely) !=EOF) { stcoordx=astcoordx/pixscale stcoordy=astcoordy/pixscale delx=adelx/pixscale dely=adely/pixscale x=stcoordx xold=stcoordx y=stcoordy yold=stcoordy #procedure:i=1 (0,-dely); i=2 (-delx,+dely); i=3 (-delx,-dely); i=4(-delx,+dely) for (i=1; i<=nrows; i+=1) { for (j=1; j<=ncols; j+=1) { y=yold+dely*(-1)**(i+1) print(x, y, >> naallcoords) yold=y } x=xold+delx xold=x y=yold+dely*(-1)**(i+1) yold=y } } print("===> Edit the file with :wq twice.") vi("-c ':g/0\.\ /s//0.00 /g'", naallcoords) vi("-c ':g/0\.$/s//0.00/g'", naallcoords) print(" ") print("===> Type in the reference image offsets (printed 2 lines below) when") print("===> requested, to zero the coordinate system on the reference image.") del("tempsortlist", ver-, >& "dev$null") join(fflatlist, naallcoords, out="tempsortlist") grep(rrefimage,"tempsortlist") del("tempsortlist",ver-) print("===> Finding the coarse offsets...") if((!access(ncoarsefile)) || (re_do && access(ncoarsefile))) { del(ncoarsefile,ver-) lintran(naallcoords, x2=xref, y2=yref, angle=180, > ncoarsefile) } } # nshift: end of file of lists } # Common ending for both approaches. print(" ") print("===> Finding the final offsets...") # nshift: create coarsefile from all ncoarsefile print(" ") print("===> Finding exact offsets...") if ((!access(coarsefile)) || (re_do && access(coarsefile))) { del (coarsefile, ver-, >& "dev$null") concat (coarsefile//"_?", coarsefile, append-) } # nshift: Get reference image coords of all reference objects # nshift: new xregister method if (do_xcor) { print ("Cross-correlating individual images with central image...") ixdim=xsize; iydim=ysize #print (ixdim, iydim) imgets(rrefimage,"i_naxis1") oxdim=int(imgets.value) imgets(rrefimage,"i_naxis2") oydim=int(imgets.value) #print (oxdim, oydim) tmpfile1=mktemp("tmpfile1"); tmpfile2=mktemp("tmpfile2") fields (coarsefile, "1-2", >> tmpfile1) join (flat_list//","//tmpfile1, >> tmpfile2) list=tmpfile2 if ((!access(pprefix//".xregout."//ssuffix)) || (re_do && access(pprefix//".xregout."//ssuffix))) { while (fscan(list,image_name,x_shift,y_shift) !=EOF) { # zero out bad pixels if not already done imgets(image_name,"ZEROOUT") zero_out=imgets.value if(zero_out=="0"){ imgets(image_name,"BPMASK") if(imgets.value!="0"){ imar(image_name,"*",imgets.value,image_name,pixt="real",calct="real",ver-,noac-) hedit(image_name,"ZEROOUT",imgets.value,add+,ver-,show-,update+) } else { print("Bad pixels not zeroed for "//image_name//", and no BP mask in header!") } } if(xsize==0){ imgets(image_name,"i_naxis1") ixdim=int(imgets.value) } if(ysize==0){ imgets(image_name,"i_naxis2") iydim=int(imgets.value) } #print (x_shift, y_shift) #print (ixdim, iydim) ix=int(x_shift)+1-14; if(ix<1)ix=1 iy=int(y_shift)+1-14; if(iy<1)iy=1 xe=int(x_shift) + ixdim + 14; if(xe>oxdim)xe=oxdim ye=int(y_shift) + iydim + 14; if(ye>oydim)ye=oydim #print (ix, iy) #print (xe, ye) msect = "["//ix//":"//xe//","//iy//":"//ye//"]" print("Rough shift from "//image_name//" to "//rrefimage//" is "//x_shift//" "//y_shift) fileroot (image_name, validim+); fr_image_name = fileroot.root fileroot (rrefimage, validim+); fr_rrefimage= fileroot.root if (fr_image_name != fr_rrefimage) { immatch.xreg (image_name, rrefimage, msect, pprefix//".xregout."//ssuffix, datab+, records="", xlag=-1*x_shift, ylag=-1*y_shift, xwindow=25, ywindow=25, append+) } else { print("", >> pprefix//".xregout."//ssuffix) print("begin "//image_name, >> pprefix//".xregout."//ssuffix) print(" xshift 0.",>>pprefix//".xregout."//ssuffix) print(" yshift 0.",>>pprefix//".xregout."//ssuffix) } } } tempx = mktemp("tempx"); tempy = mktemp("tempy") grep ('xshift', pprefix//".xregout."//ssuffix) | fields ("junk", "2", >> tempx) grep ('yshift', pprefix//".xregout."//ssuffix) | fields ("junk", "2", >> tempy) join(tempx,tempy,output=ooffname) del (tempx, ver-); del (tempy, ver-) del (tmpfile1, ver-); del (tmpfile2, ver-) } else { # nshift: irshift-style method # nshift: Get reference image coords of all reference objects if(ddisplayim){ print(" ") print("===> Get the coordinates (type 'a') in the reference image of ALL objects you") print(" wish to use for registration, in no particular order. Hit 'q' when done.") print(" ") rimexam.radius=radius rimexam.buffer=buffer rimexam.width=width if (ptv) { imexam(rrefimage, frame=1, logfile=rrefcoords, keep+, display="ptv(image='$1',frame=$2)") } else { imexam(rrefimage, frame=1, logfile=rrefcoords, keep+) } } if(edit_files){ print(" ") print("===> In case of mistakes, the reference coords file can now be edited.") vi(rrefcoords) } # nshift: set fflatlist to flat_list (all images) fflatlist=flat_list del(logoffname, ver-, >& "dev$null") imcentroid("@"//fflatlist, rrefimage, rrefcoords, shift=coarsefile, boxsize=bbs, > logoffname) del("temp.joinfile", ver-, >& "dev$null") del("temp.joinfile?", ver-, >& "dev$null") # read in length of temp.joinfile0 and cut out last two lines copy(logoffname,"temp.joinfile0") count("temp.joinfile0") | scan (nl) nx=nl-2 head("temp.joinfile0", nlines=nx, >> "temp.joinfile1") # find line on which the string "X-s" appears and cut out that line & all before !grep -n X-s temp.joinfile1 > temp.joinfile2 type("temp.joinfile2") | scan (sl) x=stridx(":",sl) sx=substr(sl,1,x) x=nx-real(sx) tail("temp.joinfile1", nlines=x, >> "temp.joinfile") # Cut down on number of output files print(" ", >> logoffname) print("#Coarse offsets:", >> logoffname) print(" ", >> logoffname) type(coarsefile, >> logoffname) # del(coarsefile, ver-) # Create exact shifts list if(ccombdata){ # Extract the new reference image shifts from the offsets file del("temp.joinfile?",ver-, >& "dev$null") grep(rrefimage,"temp.joinfile") | fields ("junk", "2", >> "temp.joinfile3") type("temp.joinfile3") | average >> "temp.joinfile4" xshiftnew=real(average.sum) del("temp.joinfile?",ver-) grep(rrefimage,"temp.joinfile") | fields ("junk", "4", >> "temp.joinfile3") type("temp.joinfile3") | average >> "temp.joinfile4" yshiftnew=real(average.sum) del("temp.joinfile?",ver-) # Want to take the calculated shift ($2 for x), cancel out the newly calculated # reference image shift ($2 - xshiftnew = -xnew+$2 = -1*xnew+$2) and add in # the old reference image shift (xold+(-1*xnew+$2) filecalc("temp.joinfile",xxshiftold//"+(-1*"//xshiftnew//"+$2);"//yyshiftold//"+(-1*"//yshiftnew//"+$4)",format="%8.2f%8.2f ", >> ooffname) flpr; flpr; flpr } else { fields("temp.joinfile", "2,4", >> ooffname) } del("temp.joinfile*", ver-) # nshift: end of old irshift method } # Create integer shifts list if (!access(iintname) || (re_do && access(iintname))) { list=ooffname while(fscan(list,x,y) !=EOF) { print(int(x),int(y), >> iintname) } } # Create fractional shifts list if (!access(ffracname) || (re_do && access(ffracname))) { join(iintname,ooffname,out="temp.joinfile") filecalc("temp.joinfile","$3-$1;$4-$2",forma="%6.2f%6.2f", >> ffracname) flpr; flpr; flpr } # Create optimum rounded-off integer offsets if (!access(rroundname) || (re_do && access(rroundname))) { print(" ") print("===> Finding optimum rounded-off integer offsets...") old_x = 999.; old_y = 999. # for each 0.01 pixel step... for (i=-50; i<50; i+=1) { step = i / 100. # print (i) # ...recalculate integer offsets... list=ooffname del (rroundname, ver-, >& "dev$null") del ("temp."//rroundname, ver-, >& "dev$null") while(fscan(list,xoff,yoff) !=EOF) { xoff=xoff+step yoff=yoff+step if(((abs(xoff))>=0.5) && ((abs(yoff))>=0.5)) { print(xoff,yoff, >> "temp."//rroundname) } else { if((abs(xoff))<=0.5) { xoff=0. } if((abs(yoff))<=0.5) { yoff=0. } print(xoff,yoff, >> "temp."//rroundname) } filecalc("temp."//rroundname, "$1;$2", format="%4.0f %4.0f", >> rroundname) flpr; flpr; flpr del ("temp."//rroundname, ver-, >& "dev$null") } del ("temp."//rroundname, ver-, >& "dev$null") # calculate sum of squares of residuals of exact offsets - new integer offsets filecalc (ooffname//","//rroundname, "$1@1-$1@2+"//step) | average (option = "new_sample", >& "dev$null") flpr; flpr; flpr new_x=average.sumsqrs filecalc (ooffname//","//rroundname, "$2@1-$2@2+"//step) | average (option = "new_sample", >& "dev$null") flpr; flpr; flpr new_y=average.sumsqrs if (new_x < old_x) { old_x = new_x step_x = step } if (new_y < old_y) { old_y = new_y step_y = step } } # recalculate final integer offsets list=ooffname del (rroundname, ver-) del ("temp."//rroundname, ver-, >& "dev$null") while(fscan(list,xoff,yoff) !=EOF) { xoff=xoff+step_x yoff=yoff+step_y if(((abs(xoff))>=0.5) && ((abs(yoff))>=0.5)) { print(xoff,yoff, >> "temp."//rroundname) } else { if((abs(xoff))<=0.5) { xoff=0. } if((abs(yoff))<=0.5) { yoff=0. } print(xoff,yoff, >> "temp."//rroundname) } filecalc("temp."//rroundname,"$1;$2",format="%4.0f %4.0f", >>rroundname) flpr; flpr; flpr del ("temp."//rroundname, ver-, >& "dev$null") } del ("temp."//rroundname, ver-, >& "dev$null") } if (!access(pprefix//".imshifts."//ssuffix) || (re_do && access(pprefix//".imshifts."//ssuffix))) { print(" ", >> logoffname) print("#Final offsets:", >> logoffname) print(" ", >> logoffname) type(ooffname, >> logoffname) del("temp.joinfile", ver-) join(flat_list,rroundname,out=pprefix//".imshifts."//ssuffix) } # Produce photometric time series from *allcoords* file # fields(aallcoords, "7") | graph (title="Flux of centering object as f(image number)", point-) # Create fractional-pixel-shifted images if(ffracshift){ sshiftlist=fflatlist//ssuffix print(" ") print("===> Creating fractional-pixel-shifted images listed in "//sshiftlist//".") list=fflatlist while(fscan(list,img) !=EOF) { fileroot(img,validim+) img=fileroot.root ext=fileroot.extension if(ext!="")ext="."//ext print(img//ssuffix//ext, >> sshiftlist) } iinterp=interp bboundary=boundary imshift("@"//fflatlist, "@"//sshiftlist, shifts=ffracname, interp=iinterp, bound=bboundary) if(bbadmask!="") { hedit("@"//sshiftlist,"BPM",bbadmask,add+,ver-,show-,update+) hedit("@"//sshiftlist,"BPMASK",bbadmask,add+,ver-,show-,update+) } } print("...it is accomplished. Next you should run `ircoadd' using") if(ffracshift)print(sshiftlist//" and "//iintname//" or") print(fflatlist//" and "//rroundname//".") } else { print("WARNING: tasks `filecalc', `fileroot', or package `phat' (if ptv=yes)" print("are not loaded! Please load them and restart this task.") } if(echog)beep end ./onis3ew.cl0100644000151400000240000014746206721031433012105 0ustar phallgames# onis3ew -- shift & coadd ONIS CNOC 3-field east-west dither pattern # 990420 -- created from onis6pt.cl # 990422 -- nshiftall portion created # 990423 -- started adding ability to handle non-overlapping images in nshiftall # 990518 -- make sure indiv. images are multiplied by BPM before xcor # 990519 -- sigmanorm of long-axis coadds commented out (not used) # ** ideally should take offset file input to PROSPERO, and dither file too, # and figure out image pairs for itself # ** could do xcor in a chain: after coaddlongaxes, # displ AB #1 CD #2 & measure 1-star offset, then # EHI #3 FGI #4 MLK #1 ON #2 TSP #3 URQ #4 VWX #1 # ** would allow all shifts to be done at once # --ideally would include multimasklet.cl instead of masklet.cl, # to identify & exclude spurious objects from bright star residuals. # ** interactively ident star resids? when? (& make bpms) # ** ideally want to ID star resids as you go thru the images in order # could do this in chainshift # but how to apply marked x,y to final objmask image? # ** if you have objmask and objmasknospur, want to tell it which single-letter # images take which object mask. # ** better write masklet to handle this. But will it make a diff? #get x,y for a bad pixel w/in area of a spurious object in the mask #imreplace x,y to good #get coords (listpix) of all bad pixels in x-1:x+1,y-1:y+1 # if none, end # if some, imreplace to good and repeat with xmin-1:xmax+1,ymin-1:ymax+1 # where the xmin:xmax,ymin:ymax spans the range of bad pixels # ** in pre-review: display xm=0.5 ym=0.5 with estimated offsets? # layout of 3-field E-W dither pattern & image pairings (long axis vertical): # T20 U21 V22 # S19 R18 W23 TSP URQ VWX # P16 Q17 X24 20/19/16 21/18/17 22/23/24 # O15 B2 C3 ON BA CD # N14 A1 D4 15/14 2/1 4/5 # M13 F6 E5 MLK FGJ EHI # L12 G7 H8 13/12/11 6/7/10 5/8/9 # K11 J10 I9 procedure onis3ew(inlist,imageroot,niter) string inlist {prompt="List of input images"} string imageroot {prompt="Root name for output files"} int niter=1 {prompt="Number to append to output files"} string pairing="all" {enum="MLK|FGJ|EHI|ON|BA|CD|TSP|URQ|VWX|all",prompt="Images pairings to process (or all)"} bool inspect=yes {prompt="Inspect image lists before proceeding?"} bool shiftlongaxes=yes {prompt="Find shifts for image pairings w/overlapping long axes?"} bool coaddlongaxes=yes {prompt="Coadd image pairings w/overlapping long axes?"} bool nshiftall=yes {prompt="Find shifts between all image pairings?"} bool prereview=yes {prompt="Display all image for pre-nshift check?"} bool p_tv=yes {prompt="Use ptv instead of display for pre-nshift check?"} bool use_images=yes {prompt="Measure shifts from images (not file) in nshift?"} bool display_im=yes {prompt="Display images for imexam in nshift?"} bool edit_files=yes {prompt="Edit coords files after creation in nshift?"} bool exclude {prompt="Exclude any image pairings from first-pass nshift?"} string exstring {prompt="Enter code(s) for excluded pairing(s) separated by commas (MLK|FGJ|EHI|ON|BA|CD|TSP|URQ|VWX)"} bool redo=no {prompt="Redo shift-finding if already done?"} bool coaddallimages=yes {prompt="Coadd all images?"} bool secondpassxcor=yes {prompt="Cross-correlate all images with coadded image?"} bool coaddsecondpass=yes {prompt="Coadd images after second-pass cross-correlation?"} bool domkobjmask=yes {prompt="Make coadded-image object mask (INTERACTIVE)?"} bool domasklet=yes {prompt="Make individual-image object masks?"} string imextn="fits" {prompt="Image extension"} int xsize=512 {prompt="X-axis individual image size (0 for autosense)"} int ysize=1024 {prompt="Y-axis individual image size (0 for autosense)"} bool echog=yes {prompt="Beep when task is done?"} struct *list begin string in_list, image_root, p_air, ref_image, tmpheaders, sigprefix, rroundname string theory, method_shortaxes, tempfile2, msect, image_name, tempx, tempy string rvw_image, ex_string, current_string, future_string, in_string, im_extn string zero_out int xmin, ymin, xint, yint, old_xint, old_yint, xmax_bcad, xmin_fead, ix, iy int xmin_tspurq, xmax_tspurq, xtspurq, ytspurq, tspn1 int xmin_vwxurq, xmax_vwxurq, xvwxurq, yvwxurq, vwxn1 int xmin_mlkfgj, xmax_mlkfgj, xmlkfgj, ymlkfgj, mlkn1 int xmin_ehifgj, xmax_ehifgj, xehifgj, yehifgj, ehin1 int n_iter, xbcad, ybcad, xfead, yfead, bcn1, fen1, x_shift, y_shift, xe, ye int xref, yref, int_x, int_y, junkint, ilen, ipos int oxdim, oydim # dimensions of mask image int ixdim, iydim # dimensions of individual input frames int xbamost, ybamost, xbaba, ybaba, xcdba, ycdba, xehiba, yehiba, xfgjba, yfgjba int xmlkba, ymlkba, xonba, yonba, xtspba, ytspba, xurqba, yurqba, xvwxba, yvwxba real baba_xshiftexact, baba_yshiftexact, bamost_xshiftexact, bamost_yshiftexact real cdba_xshiftexact, cdba_yshiftexact, ehiba_xshiftexact, ehiba_yshiftexact real fgjba_xshiftexact, fgjba_yshiftexact, mlkba_xshiftexact, mlkba_yshiftexact real onba_xshiftexact, onba_yshiftexact, tspba_xshiftexact, tspba_yshiftexact real urqba_xshiftexact, urqba_yshiftexact, vwxba_xshiftexact, vwxba_yshiftexact real xbcad2, ybcad2, xfead2, yfead2, bcad_x, bcad_y, fead_x, fead_y real xtspurq2, ytspurq2, tspurq_xlag, tspurq_ylag real xvwxurq2, yvwxurq2, vwxurq_xlag, vwxurq_ylag real xurq, yurq, xtsp, ytsp, xvwx, yvwx real xmlkfgj2, ymlkfgj2, mlkfgj_xlag, mlkfgj_ylag real xehifgj2, yehifgj2, ehifgj_xlag, ehifgj_ylag real xfgj, yfgj, xmlk, ymlk, xehi, yehi real xad, yad, xbc, ybc, xfe, yfe, bcad_xlag, bcad_ylag, fead_xlag, fead_ylag real bcad_xfirstpass, bcad_yfirstpass, fead_xfirstpass, fead_yfirstpass real tspurq_xfirstpass, tspurq_yfirstpass, vwxurq_xfirstpass, vwxurq_yfirstpass real mlkfgj_xfirstpass, mlkfgj_yfirstpass, ehifgj_xfirstpass, ehifgj_yfirstpass real xoff, yoff, step, new_x, new_y, old_x, old_y, step_x, step_y, xsig, ysig bool in_spect, shift_longaxes, echo_g, coadd_longaxes, abort, go, do_masklet bool coadd_allimages, xcor_secondpass, coadd_secondpass, do_mkobjmask, re_do bool im_display, images_use, shift_shortaxes, coadd_shortaxes, xreg_secondpass bool nshift_all, files_edit, ex_clude, pt_v, pre_review in_list=inlist image_root=imageroot n_iter=niter p_air=pairing in_spect=inspect shift_longaxes=shiftlongaxes images_use=use_images im_display=display_im files_edit=edit_files ex_string="" re_do=redo coadd_longaxes=coaddlongaxes nshift_all=nshiftall pre_review=prereview pt_v=p_tv coadd_allimages=coaddallimages xcor_secondpass=secondpassxcor coadd_secondpass=coaddsecondpass do_mkobjmask=domkobjmask do_masklet=domasklet im_extn=imextn echo_g=echog rroundname=image_root//".xregshifts.shall"//n_iter sigprefix=sigmanorm.prefix baba_xshiftexact = 0; baba_yshiftexact = 0; cdba_xshiftexact = 0 cdba_xshiftexact = 0; ehiba_xshiftexact = 0; ehiba_yshiftexact = 0 fgjba_xshiftexact = 0; fgjba_yshiftexact = 0; mlkba_xshiftexact = 0 mlkba_yshiftexact = 0; onba_xshiftexact = 0; onba_yshiftexact = 0 tspba_xshiftexact = 0; tspba_yshiftexact = 0; urqba_xshiftexact = 0 urqba_yshiftexact = 0; vwxba_xshiftexact = 0; vwxba_yshiftexact = 0 go=yes if(!defpac("imgtools")) {go=no} if(go) { # Separate input list into lists of images overlapping along long axes print ("\n===> Checking image pairing lists...") tmpheaders=mktemp("tmpheaders") hsel ("@"//in_list, "$I,i_title", yes, >> tmpheaders) if (!access(in_list//"_BA")) { grep ('Position\ \ 2\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_BA") grep ('Position\ \ 1\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_BA") } else { print (in_list//"_BA already exists; not created.") } if (!access(in_list//"_ON")) { grep ('Position\ 15\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_ON") grep ('Position\ 14\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_ON") } else { print (in_list//"_ON already exists; not created.") } if (!access(in_list//"_CD")) { grep ('Position\ \ 3\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_CD") grep ('Position\ \ 4\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_CD") } else { print (in_list//"_CD already exists; not created.") } if (!access(in_list//"_MLK")) { grep ('Position\ 13\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_MLK") grep ('Position\ 12\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_MLK") grep ('Position\ 11\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_MLK") grep ('Position\ 13\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_ML") grep ('Position\ 12\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_ML") grep ('Position\ 11\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_K") print (in_list//"_ML", >> "l_"//in_list//"_MLK") print (in_list//"_K", >> "l_"//in_list//"_MLK") } else { print (in_list//"_MLK etc. already exist; not created.") } if (!access(in_list//"_FGJ")) { grep ('Position\ \ 6\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_FGJ") grep ('Position\ \ 7\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_FGJ") grep ('Position\ 10\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_FGJ") grep ('Position\ \ 6\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_FG") grep ('Position\ \ 7\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_FG") grep ('Position\ 10\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_J") print (in_list//"_FG", >> "l_"//in_list//"_FGJ") print (in_list//"_J", >> "l_"//in_list//"_FGJ") } else { print (in_list//"_FGJ etc. already exist; not created.") } if (!access(in_list//"_EHI")) { grep ('Position\ \ 5\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_EHI") grep ('Position\ \ 8\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_EHI") grep ('Position\ \ 9\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_EHI") grep ('Position\ \ 5\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_EH") grep ('Position\ \ 8\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_EH") grep ('Position\ \ 9\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_I") print (in_list//"_EH", >> "l_"//in_list//"_EHI") print (in_list//"_I", >> "l_"//in_list//"_EHI") } else { print (in_list//"_EHI etc. already exist; not created.") } if (!access(in_list//"_TSP")) { grep ('Position\ 20\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_TSP") grep ('Position\ 19\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_TSP") grep ('Position\ 16\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_TSP") grep ('Position\ 20\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_TS") grep ('Position\ 19\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_TS") grep ('Position\ 16\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_P") print (in_list//"_TS", >> "l_"//in_list//"_TSP") print (in_list//"_P", >> "l_"//in_list//"_TSP") } else { print (in_list//"_TSP etc. already exist; not created.") } if (!access(in_list//"_URQ")) { grep ('Position\ 21\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_URQ") grep ('Position\ 18\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_URQ") grep ('Position\ 17\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_URQ") grep ('Position\ 21\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_UR") grep ('Position\ 18\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_UR") grep ('Position\ 17\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_Q") print (in_list//"_UR", >> "l_"//in_list//"_URQ") print (in_list//"_Q", >> "l_"//in_list//"_URQ") } else { print (in_list//"_URQ etc. already exist; not created.") } if (!access(in_list//"_VWX")) { grep ('Position\ 22\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_VWX") grep ('Position\ 23\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_VWX") grep ('Position\ 24\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_VWX") grep ('Position\ 22\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_VW") grep ('Position\ 23\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_VW") grep ('Position\ 24\ of\ 24', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_X") print (in_list//"_VW", >> "l_"//in_list//"_VWX") print (in_list//"_X", >> "l_"//in_list//"_VWX") } else { print (in_list//"_VWX etc. already exist; not created.") } del(tmpheaders,ver-) if (in_spect) vi (in_list//"_?? "//in_list//"_???") # Do irshift on lists of images overlapping along long axes if (shift_longaxes) { print("\n===> Finding shifts for image pairings overlapping along long axes...") if (p_air=="BA" || p_air=="all") { fields (in_list//"_BA", 1, lines="2-2") | scan (ref_image) if (!access(image_root//".roundoff.shBA"//n_iter)) { print("\n----> Overlap region is LOWER part of the reference image; using irshift <----") irshift (in_list//"_BA", ref_image, image_root, "shBA"//n_iter, useimages=images_use, displayim=im_display) } } if (p_air=="ON" || p_air=="all") { fields (in_list//"_ON", 1, lines="2-2") | scan (ref_image) if (!access(image_root//".roundoff.shON"//n_iter)) { print("\n----> Overlap region is LOWER part of the reference image; using irshift <----") irshift (in_list//"_ON", ref_image, image_root, "shON"//n_iter, useimages=images_use, displayim=im_display) } } if (p_air=="CD" || p_air=="all") { fields (in_list//"_CD", 1, lines="2-2") | scan (ref_image) if (!access(image_root//".roundoff.shCD"//n_iter)) { print("\n----> Overlap region is LOWER part of the reference image; using irshift <----") irshift (in_list//"_CD", ref_image, image_root, "shCD"//n_iter, useimages=images_use, displayim=im_display) } } if (p_air=="MLK" || p_air=="all") { fields (in_list//"_MLK", 1, lines="6-6") | scan (ref_image) if (!access(image_root//".roundoff.shMLK"//n_iter)) { print("\n----> The overlap region is the ENTIRE reference image; using nshift <----") nshift ("l_"//in_list//"_MLK", in_list//"_MLK", ref_image, image_root, "shMLK"//n_iter, useimages=images_use, displayim=im_display, editfiles=files_edit) } } if (p_air=="FGJ" || p_air=="all") { fields (in_list//"_FGJ", 1, lines="6-6") | scan (ref_image) if (!access(image_root//".roundoff.shFGJ"//n_iter)) { print("\n----> The overlap region is the ENTIRE reference image; using nshift <----") nshift ("l_"//in_list//"_FGJ", in_list//"_FGJ", ref_image, image_root, "shFGJ"//n_iter, useimages=images_use, displayim=im_display, editfiles=files_edit) } } if (p_air=="EHI" || p_air=="all") { fields (in_list//"_EHI", 1, lines="6-6") | scan (ref_image) if (!access(image_root//".roundoff.shEHI"//n_iter)) { print("\n----> The overlap region is the ENTIRE reference image; using nshift <----") nshift ("l_"//in_list//"_EHI", in_list//"_EHI", ref_image, image_root, "shEHI"//n_iter, useimages=images_use, displayim=im_display, editfiles=files_edit) } } if (p_air=="TSP" || p_air=="all") { fields (in_list//"_TSP", 1, lines="6-6") | scan (ref_image) if (!access(image_root//".roundoff.shTSP"//n_iter)) { print("\n----> The overlap region is the ENTIRE reference image; using nshift <----") nshift ("l_"//in_list//"_TSP", in_list//"_TSP", ref_image, image_root, "shTSP"//n_iter, useimages=images_use, displayim=im_display, editfiles=files_edit) } } if (p_air=="URQ" || p_air=="all") { fields (in_list//"_URQ", 1, lines="6-6") | scan (ref_image) if (!access(image_root//".roundoff.shURQ"//n_iter)) { print("\n----> The overlap region is the ENTIRE reference image; using nshift <----") nshift ("l_"//in_list//"_URQ", in_list//"_URQ", ref_image, image_root, "shURQ"//n_iter, useimages=images_use, displayim=im_display, editfiles=files_edit) } } if (p_air=="VWX" || p_air=="all") { fields (in_list//"_VWX", 1, lines="6-6") | scan (ref_image) if (!access(image_root//".roundoff.shVWX"//n_iter)) { print("\n----> The overlap region is the ENTIRE reference image; using nshift <----") nshift ("l_"//in_list//"_VWX", in_list//"_VWX", ref_image, image_root, "shVWX"//n_iter, useimages=images_use, displayim=im_display, editfiles=files_edit) } } } # Coadd images overlapping along long axes if (coadd_longaxes) { print ("\n===> Coadding image pairings overlapping along long axes...") if (p_air=="BA" || p_air=="all") { imdel (image_root//"BA"//n_iter, ver-, >& "dev$null") imdel (image_root//"BA"//n_iter//"em", ver-, >& "dev$null") del (image_root//"BA"//n_iter//".imshifts", ver-, >& "dev$null") imdel (sigprefix//image_root//"BA"//n_iter, ver-, >& "dev$null") ircoadd (in_list//"_BA", image_root//"BA"//n_iter, "", image_root//".roundoff.shBA"//n_iter, "none", "mode", "none", 1, no, "log_"//image_root//"_allatonce", makeavg+, flip-) # sigmanorm (image_root//"BA"//n_iter) } if (p_air=="ON" || p_air=="all") { imdel (image_root//"ON"//n_iter, ver-, >& "dev$null") imdel (image_root//"ON"//n_iter//"em", ver-, >& "dev$null") del (image_root//"ON"//n_iter//".imshifts", ver-, >& "dev$null") imdel (sigprefix//image_root//"ON"//n_iter, ver-, >& "dev$null") ircoadd (in_list//"_ON", image_root//"ON"//n_iter, "", image_root//".roundoff.shON"//n_iter, "none", "mode", "none", 1, no, "log_"//image_root//"_allatonce", makeavg+, flip-) # sigmanorm (image_root//"ON"//n_iter) } if (p_air=="CD" || p_air=="all") { imdel (image_root//"CD"//n_iter, ver-, >& "dev$null") imdel (image_root//"CD"//n_iter//"em", ver-, >& "dev$null") del (image_root//"CD"//n_iter//".imshifts", ver-, >& "dev$null") imdel (sigprefix//image_root//"CD"//n_iter, ver-, >& "dev$null") ircoadd (in_list//"_CD", image_root//"CD"//n_iter, "", image_root//".roundoff.shCD"//n_iter, "none", "mode", "none", 1, no, "log_"//image_root//"_allatonce", makeavg+, flip-) # sigmanorm (image_root//"CD"//n_iter) } if (p_air=="MLK" || p_air=="all") { imdel (image_root//"MLK"//n_iter, ver-, >& "dev$null") imdel (image_root//"MLK"//n_iter//"em", ver-, >& "dev$null") del (image_root//"MLK"//n_iter//".imshifts", ver-, >& "dev$null") imdel (sigprefix//image_root//"MLK"//n_iter, ver-, >& "dev$null") ircoadd (in_list//"_MLK", image_root//"MLK"//n_iter, "", image_root//".roundoff.shMLK"//n_iter, "none", "mode", "none", 1, no, "log_"//image_root//"_allatonce", makeavg+, flip-) # sigmanorm (image_root//"MLK"//n_iter) } if (p_air=="FGJ" || p_air=="all") { imdel (image_root//"FGJ"//n_iter, ver-, >& "dev$null") imdel (image_root//"FGJ"//n_iter//"em", ver-, >& "dev$null") del (image_root//"FGJ"//n_iter//".imshifts", ver-, >& "dev$null") imdel (sigprefix//image_root//"FGJ"//n_iter, ver-, >& "dev$null") ircoadd (in_list//"_FGJ", image_root//"FGJ"//n_iter, "", image_root//".roundoff.shFGJ"//n_iter, "none", "mode", "none", 1, no, "log_"//image_root//"_allatonce", makeavg+, flip-) # sigmanorm (image_root//"FGJ"//n_iter) } if (p_air=="EHI" || p_air=="all") { imdel (image_root//"EHI"//n_iter, ver-, >& "dev$null") imdel (image_root//"EHI"//n_iter//"em", ver-, >& "dev$null") del (image_root//"EHI"//n_iter//".imshifts", ver-, >& "dev$null") imdel (sigprefix//image_root//"EHI"//n_iter, ver-, >& "dev$null") ircoadd (in_list//"_EHI", image_root//"EHI"//n_iter, "", image_root//".roundoff.shEHI"//n_iter, "none", "mode", "none", 1, no, "log_"//image_root//"_allatonce", makeavg+, flip-) # sigmanorm (image_root//"EHI"//n_iter) } if (p_air=="TSP" || p_air=="all") { imdel (image_root//"TSP"//n_iter, ver-, >& "dev$null") imdel (image_root//"TSP"//n_iter//"em", ver-, >& "dev$null") del (image_root//"TSP"//n_iter//".imshifts", ver-, >& "dev$null") imdel (sigprefix//image_root//"TSP"//n_iter, ver-, >& "dev$null") ircoadd (in_list//"_TSP", image_root//"TSP"//n_iter, "", image_root//".roundoff.shTSP"//n_iter, "none", "mode", "none", 1, no, "log_"//image_root//"_allatonce", makeavg+, flip-) # sigmanorm (image_root//"TSP"//n_iter) } if (p_air=="URQ" || p_air=="all") { imdel (image_root//"URQ"//n_iter, ver-, >& "dev$null") imdel (image_root//"URQ"//n_iter//"em", ver-, >& "dev$null") del (image_root//"URQ"//n_iter//".imshifts", ver-, >& "dev$null") imdel (sigprefix//image_root//"URQ"//n_iter, ver-, >& "dev$null") ircoadd (in_list//"_URQ", image_root//"URQ"//n_iter, "", image_root//".roundoff.shURQ"//n_iter, "none", "mode", "none", 1, no, "log_"//image_root//"_allatonce", makeavg+, flip-) # sigmanorm (image_root//"URQ"//n_iter) } if (p_air=="VWX" || p_air=="all") { imdel (image_root//"VWX"//n_iter, ver-, >& "dev$null") imdel (image_root//"VWX"//n_iter//"em", ver-, >& "dev$null") del (image_root//"VWX"//n_iter//".imshifts", ver-, >& "dev$null") imdel (sigprefix//image_root//"VWX"//n_iter, ver-, >& "dev$null") ircoadd (in_list//"_VWX", image_root//"VWX"//n_iter, "", image_root//".roundoff.shVWX"//n_iter, "none", "mode", "none", 1, no, "log_"//image_root//"_allatonce", makeavg+, flip-) # sigmanorm (image_root//"VWX"//n_iter) } } # Find shifts between all image pairings if (p_air=="all" && nshift_all) { if (!access(image_root//".shiftexact.shall"//n_iter)) { # ** should test this out if (re_do) { del (image_root//".imshifts.shall*"//n_iter, ver-, >& "dev$null") del (image_root//".offsets.shall*"//n_iter, ver-, >& "dev$null") del (image_root//".roundoff.shall*"//n_iter, ver-, >& "dev$null") del (image_root//".shiftexact.shall*"//n_iter, ver-, >& "dev$null") del (image_root//".shiftfrac.shall*"//n_iter, ver-, >& "dev$null") del (image_root//".shiftint.shall*"//n_iter, ver-, >& "dev$null") del (image_root//".imshifts.shmost*"//n_iter, ver-, >& "dev$null") del (image_root//".offsets.shmost*"//n_iter, ver-, >& "dev$null") del (image_root//".roundoff.shmost*"//n_iter, ver-, >& "dev$null") del (image_root//".shiftexact.shmost*"//n_iter, ver-, >& "dev$null") del (image_root//".shiftfrac.shmost*"//n_iter, ver-, >& "dev$null") del (image_root//".shiftint.shmost*"//n_iter, ver-, >& "dev$null") print ("\n*allcoords*, *refcoords*, & *coarse* preserved; all else will be recreated.") } if (!access(in_list//"_coadd_"//n_iter)) { print (image_root//"BA"//n_iter, >> in_list//"_coadd_"//n_iter) print (image_root//"CD"//n_iter, >> in_list//"_coadd_"//n_iter) print (image_root//"EHI"//n_iter, >> in_list//"_coadd_"//n_iter) print (image_root//"FGJ"//n_iter, >> in_list//"_coadd_"//n_iter) print (image_root//"MLK"//n_iter, >> in_list//"_coadd_"//n_iter) print (image_root//"ON"//n_iter, >> in_list//"_coadd_"//n_iter) print (image_root//"TSP"//n_iter, >> in_list//"_coadd_"//n_iter) print (image_root//"URQ"//n_iter, >> in_list//"_coadd_"//n_iter) print (image_root//"VWX"//n_iter, >> in_list//"_coadd_"//n_iter) } # initial pre-review if (pre_review) { print ("Central image will be displayed in frame 1, and others in 2.") print ("Note any images that do not overlap the central image.") list=in_list//"_coadd_"//n_iter junkint = 1 while (fscan (list, rvw_image) !=EOF) { if (junkint==1) { if (pt_v) { ptv (rvw_image, frame=1) } else { display (rvw_image, frame=1) } } else { if (pt_v) { imexam (rvw_image, frame=2, keep-, display="ptv(image='$1',frame=2)") } else { display (rvw_image, junkint) imexam (rvw_image, frame=junkint, keep-, display="display(image='$1',frame=$2)") #imexam (rvw_image, frame=2, keep-, display="display(image='$1',frame=2)") } } junkint = junkint + 1 if (junkint==5) junkint = 2 } } # exclude any images from nshift at first? print ("") ex_clude=exclude # if excluding any images: if (ex_clude) { # **redo here too? not a global redo, since need to get paramaters below for use in coadding del ("_coaddTmp?_", ver-, >& "dev$null") # get code(s) of excluded image(s) ex_string=exstring # create file of codes of images excluded from most-images coadd # files (image_root//ex_string//n_iter, >> "_coaddTmp1_") files (ex_string, >> "_coaddTmp1_") # create file of images included in most-images coadd copy (in_list//"_coadd_"//n_iter, "_coaddTmp2_", ver-) !fgrep -v -f _coaddTmp1_ _coaddTmp2_ > _coaddTmp3_ # **redo/!redo instead of delete & recreate? del (in_list//"_coaddmost_"//n_iter, ver-, >& "dev$null") rename ("_coaddTmp3_", in_list//"_coaddmost_"//n_iter, field="all", >& "dev$null") # create file of images included in full coadd # **redo/!redo instead of delete & recreate? del (in_list//"_coaddrest_"//n_iter, ver-, >& "dev$null") print (image_root//"BA"//n_iter, > "_coaddTmp4_") !fgrep -f _coaddTmp1_ _coaddTmp2_ >> _coaddTmp4_ print (image_root//"most"//n_iter//"_1stpass", >> "_coaddTmp4_") type ("_coaddTmp4_", >> in_list//"_coaddrest_"//n_iter) # find shifts for most-images coadd # **redo here too? if (!access(image_root//".roundoff.shmost"//n_iter)) nshift ("", in_list//"_coaddmost_"//n_iter, image_root//"BA"//n_iter, image_root, "shmost"//n_iter, redo=re_do, useimages=images_use, displayim=im_display, editfiles=files_edit) if (!access(image_root//".imshifts.shmost"//n_iter)) join (in_list//"_coaddmost_"//n_iter, image_root//".shiftexact.shmost"//n_iter, >> image_root//".imshifts.shmost"//n_iter) grep ("BA", image_root//".imshifts.shmost"//n_iter) | scan (theory, baba_xshiftexact, baba_yshiftexact) grep ("CD", image_root//".imshifts.shmost"//n_iter) | scan (theory, cdba_xshiftexact, cdba_yshiftexact) grep ("EHI", image_root//".imshifts.shmost"//n_iter) | scan (theory, ehiba_xshiftexact, ehiba_yshiftexact) grep ("FGJ", image_root//".imshifts.shmost"//n_iter) | scan (theory, fgjba_xshiftexact, fgjba_yshiftexact) grep ("MLK", image_root//".imshifts.shmost"//n_iter) | scan (theory, mlkba_xshiftexact, mlkba_yshiftexact) grep ("ON", image_root//".imshifts.shmost"//n_iter) | scan (theory, onba_xshiftexact, onba_yshiftexact) grep ("TSP", image_root//".imshifts.shmost"//n_iter) | scan (theory, tspba_xshiftexact, tspba_yshiftexact) grep ("URQ", image_root//".imshifts.shmost"//n_iter) | scan (theory, urqba_xshiftexact, urqba_yshiftexact) grep ("VWX", image_root//".imshifts.shmost"//n_iter) | scan (theory, vwxba_xshiftexact, vwxba_yshiftexact) } else { # if not excluding any images: if (!access(image_root//".shiftexact.shall"//n_iter)) nshift ("", in_list//"_coadd_"//n_iter, image_root//"BA"//n_iter, image_root, "shall"//n_iter, redo=re_do, useimages=images_use, displayim=im_display, editfiles=files_edit) fields(image_root//".shiftexact.shall"//n_iter,"1-2",lines="1-1")|scan(baba_xshiftexact,baba_yshiftexact) fields(image_root//".shiftexact.shall"//n_iter,"1-2",lines="2-2")|scan(cdba_xshiftexact,cdba_yshiftexact) fields(image_root//".shiftexact.shall"//n_iter,"1-2",lines="3-3")|scan(ehiba_xshiftexact,ehiba_yshiftexact) fields(image_root//".shiftexact.shall"//n_iter,"1-2",lines="4-4")|scan(fgjba_xshiftexact,fgjba_yshiftexact) fields(image_root//".shiftexact.shall"//n_iter,"1-2",lines="5-5")|scan(mlkba_xshiftexact,mlkba_yshiftexact) fields(image_root//".shiftexact.shall"//n_iter,"1-2",lines="6-6")|scan(onba_xshiftexact,onba_yshiftexact) fields(image_root//".shiftexact.shall"//n_iter,"1-2",lines="7-7")|scan(tspba_xshiftexact,tspba_yshiftexact) fields(image_root//".shiftexact.shall"//n_iter,"1-2",lines="8-8")|scan(urqba_xshiftexact,urqba_yshiftexact) fields(image_root//".shiftexact.shall"//n_iter,"1-2",lines="9-9")|scan(vwxba_xshiftexact,vwxba_yshiftexact) } } if(baba_xshiftexact>=0)xbaba=int(0.5+baba_xshiftexact) if(baba_yshiftexact>=0)ybaba=int(0.5+baba_yshiftexact) if(baba_xshiftexact<0)xbaba=int(-0.5+baba_xshiftexact) if(baba_yshiftexact<0)ybaba=int(-0.5+baba_yshiftexact) if(cdba_xshiftexact>=0)xcdba=int(0.5+cdba_xshiftexact) if(cdba_yshiftexact>=0)ycdba=int(0.5+cdba_yshiftexact) if(cdba_xshiftexact<0)xcdba=int(-0.5+cdba_xshiftexact) if(cdba_yshiftexact<0)ycdba=int(-0.5+cdba_yshiftexact) if(ehiba_xshiftexact>=0)xehiba=int(0.5+ehiba_xshiftexact) if(ehiba_yshiftexact>=0)yehiba=int(0.5+ehiba_yshiftexact) if(ehiba_xshiftexact<0)xehiba=int(-0.5+ehiba_xshiftexact) if(ehiba_yshiftexact<0)yehiba=int(-0.5+ehiba_yshiftexact) if(fgjba_xshiftexact>=0)xfgjba=int(0.5+fgjba_xshiftexact) if(fgjba_yshiftexact>=0)yfgjba=int(0.5+fgjba_yshiftexact) if(fgjba_xshiftexact<0)xfgjba=int(-0.5+fgjba_xshiftexact) if(fgjba_yshiftexact<0)yfgjba=int(-0.5+fgjba_yshiftexact) if(mlkba_xshiftexact>=0)xmlkba=int(0.5+mlkba_xshiftexact) if(mlkba_yshiftexact>=0)ymlkba=int(0.5+mlkba_yshiftexact) if(mlkba_xshiftexact<0)xmlkba=int(-0.5+mlkba_xshiftexact) if(mlkba_yshiftexact<0)ymlkba=int(-0.5+mlkba_yshiftexact) if(onba_xshiftexact>=0)xonba=int(0.5+onba_xshiftexact) if(onba_yshiftexact>=0)yonba=int(0.5+onba_yshiftexact) if(onba_xshiftexact<0)xonba=int(-0.5+onba_xshiftexact) if(onba_yshiftexact<0)yonba=int(-0.5+onba_yshiftexact) if(tspba_xshiftexact>=0)xtspba=int(0.5+tspba_xshiftexact) if(tspba_yshiftexact>=0)ytspba=int(0.5+tspba_yshiftexact) if(tspba_xshiftexact<0)xtspba=int(-0.5+tspba_xshiftexact) if(tspba_yshiftexact<0)ytspba=int(-0.5+tspba_yshiftexact) if(urqba_xshiftexact>=0)xurqba=int(0.5+urqba_xshiftexact) if(urqba_yshiftexact>=0)yurqba=int(0.5+urqba_yshiftexact) if(urqba_xshiftexact<0)xurqba=int(-0.5+urqba_xshiftexact) if(urqba_yshiftexact<0)yurqba=int(-0.5+urqba_yshiftexact) if(vwxba_xshiftexact>=0)xvwxba=int(0.5+vwxba_xshiftexact) if(vwxba_yshiftexact>=0)yvwxba=int(0.5+vwxba_yshiftexact) if(vwxba_xshiftexact<0)xvwxba=int(-0.5+vwxba_xshiftexact) if(vwxba_yshiftexact<0)yvwxba=int(-0.5+vwxba_yshiftexact) } # coadd all images at once (w/intermediate most-image coadd if needed) if (p_air=="all" && coadd_allimages) { # first set minimum x,y offsets to be 0 & 0 (independently) if (!access(image_root//".roundoff.shBA"//n_iter//"min0")) { list=image_root//".roundoff.shBA"//n_iter xmin=9999; ymin=9999 while (fscan(list,xint,yint) !=EOF) { if (xint < xmin) xmin = xint if (yint < ymin) ymin = yint } filecalc(image_root//".roundoff.shBA"//n_iter, "$1-"//xmin//";$2-"//ymin, format="%4.0f %4.0f", >> image_root//".roundoff.shBA"//n_iter//"min0") } if (!access(image_root//".roundoff.shON"//n_iter//"min0")) { list=image_root//".roundoff.shON"//n_iter xmin=9999; ymin=9999 while (fscan(list,xint,yint) !=EOF) { if (xint < xmin) xmin = xint if (yint < ymin) ymin = yint } filecalc(image_root//".roundoff.shON"//n_iter, "$1-"//xmin//";$2-"//ymin, format="%4.0f %4.0f", >> image_root//".roundoff.shON"//n_iter//"min0") } if (!access(image_root//".roundoff.shCD"//n_iter//"min0")) { list=image_root//".roundoff.shCD"//n_iter xmin=9999; ymin=9999 while (fscan(list,xint,yint) !=EOF) { if (xint < xmin) xmin = xint if (yint < ymin) ymin = yint } filecalc(image_root//".roundoff.shCD"//n_iter, "$1-"//xmin//";$2-"//ymin, format="%4.0f %4.0f", >> image_root//".roundoff.shCD"//n_iter//"min0") } if (!access(image_root//".roundoff.shEHI"//n_iter//"min0")) { list=image_root//".roundoff.shEHI"//n_iter xmin=9999; ymin=9999 while (fscan(list,xint,yint) !=EOF) { if (xint < xmin) xmin = xint if (yint < ymin) ymin = yint } filecalc(image_root//".roundoff.shEHI"//n_iter, "$1-"//xmin//";$2-"//ymin, format="%4.0f %4.0f", >> image_root//".roundoff.shEHI"//n_iter//"min0") } if (!access(image_root//".roundoff.shFGJ"//n_iter//"min0")) { list=image_root//".roundoff.shFGJ"//n_iter xmin=9999; ymin=9999 while (fscan(list,xint,yint) !=EOF) { if (xint < xmin) xmin = xint if (yint < ymin) ymin = yint } filecalc(image_root//".roundoff.shFGJ"//n_iter, "$1-"//xmin//";$2-"//ymin, format="%4.0f %4.0f", >> image_root//".roundoff.shFGJ"//n_iter//"min0") } if (!access(image_root//".roundoff.shMLK"//n_iter//"min0")) { list=image_root//".roundoff.shMLK"//n_iter xmin=9999; ymin=9999 while (fscan(list,xint,yint) !=EOF) { if (xint < xmin) xmin = xint if (yint < ymin) ymin = yint } filecalc(image_root//".roundoff.shMLK"//n_iter, "$1-"//xmin//";$2-"//ymin, format="%4.0f %4.0f", >> image_root//".roundoff.shMLK"//n_iter//"min0") } if (!access(image_root//".roundoff.shTSP"//n_iter//"min0")) { list=image_root//".roundoff.shTSP"//n_iter xmin=9999; ymin=9999 while (fscan(list,xint,yint) !=EOF) { if (xint < xmin) xmin = xint if (yint < ymin) ymin = yint } filecalc(image_root//".roundoff.shTSP"//n_iter, "$1-"//xmin//";$2-"//ymin, format="%4.0f %4.0f", >> image_root//".roundoff.shTSP"//n_iter//"min0") } if (!access(image_root//".roundoff.shURQ"//n_iter//"min0")) { list=image_root//".roundoff.shURQ"//n_iter xmin=9999; ymin=9999 while (fscan(list,xint,yint) !=EOF) { if (xint < xmin) xmin = xint if (yint < ymin) ymin = yint } filecalc(image_root//".roundoff.shURQ"//n_iter, "$1-"//xmin//";$2-"//ymin, format="%4.0f %4.0f", >> image_root//".roundoff.shURQ"//n_iter//"min0") } if (!access(image_root//".roundoff.shVWX"//n_iter//"min0")) { list=image_root//".roundoff.shVWX"//n_iter xmin=9999; ymin=9999 while (fscan(list,xint,yint) !=EOF) { if (xint < xmin) xmin = xint if (yint < ymin) ymin = yint } filecalc(image_root//".roundoff.shVWX"//n_iter, "$1-"//xmin//";$2-"//ymin, format="%4.0f %4.0f", >> image_root//".roundoff.shVWX"//n_iter//"min0") } # if not excluding any images: if (!exclude) { if(ex_string=="")ex_string=exstring # now offset by offsets to the central image (BA) if(!access(in_list//"_all")) concat (in_list//"_BA,"//in_list//"_CD,"//in_list//"_EHI,"//in_list//"_FGJ,"//in_list//"_MLK,"//in_list//"_ON,"//in_list//"_TSP,"//in_list//"_URQ,"//in_list//"_VWX", in_list//"_all") if(!access(image_root//".roundoff.shall"//n_iter)) { filecalc (image_root//".roundoff.shBA"//n_iter//"min0", "$1+"//xbaba//";$2+"//ybaba, format="%4.0f %4.0f", >> image_root//".roundoff.shall"//n_iter) filecalc (image_root//".roundoff.shCD"//n_iter//"min0", "$1+"//xcdba//";$2+"//ycdba, format="%4.0f %4.0f", >> image_root//".roundoff.shall"//n_iter) filecalc (image_root//".roundoff.shEHI"//n_iter//"min0", "$1+"//xehiba//";$2+"//yehiba, format="%4.0f %4.0f", >> image_root//".roundoff.shall"//n_iter) filecalc (image_root//".roundoff.shFGJ"//n_iter//"min0", "$1+"//xfgjba//";$2+"//yfgjba, format="%4.0f %4.0f", >> image_root//".roundoff.shall"//n_iter) filecalc (image_root//".roundoff.shMLK"//n_iter//"min0", "$1+"//xmlkba//";$2+"//ymlkba, format="%4.0f %4.0f", >> image_root//".roundoff.shall"//n_iter) filecalc (image_root//".roundoff.shON"//n_iter//"min0", "$1+"//xonba//";$2+"//yonba, format="%4.0f %4.0f", >> image_root//".roundoff.shall"//n_iter) filecalc (image_root//".roundoff.shTSP"//n_iter//"min0", "$1+"//xtspba//";$2+"//ytspba, format="%4.0f %4.0f", >> image_root//".roundoff.shall"//n_iter) filecalc (image_root//".roundoff.shURQ"//n_iter//"min0", "$1+"//xurqba//";$2+"//yurqba, format="%4.0f %4.0f", >> image_root//".roundoff.shall"//n_iter) filecalc (image_root//".roundoff.shVWX"//n_iter//"min0", "$1+"//xvwxba//";$2+"//yvwxba, format="%4.0f %4.0f", >> image_root//".roundoff.shall"//n_iter) } # do the coadd print ("\n===> Coadding all images at once...") ircoadd (in_list//"_all", image_root//"all"//n_iter//"_1stpass", "", image_root//".roundoff.shall"//n_iter, "none", "mode", "none", 1, no, "log_"//in_list//"_all", stdpars-, makeavg+, flip-, imcoaddpars="phiirs$ircoaddonis.par") # if excluding any images: } else { if(!access(in_list//"_most")) { # create list of all image lists print (in_list//"_BA\n"//in_list//"_CD\n"//in_list//"_EHI\n"//in_list//"_FGJ\n"//in_list//"_MLK\n"//in_list//"_ON\n"//in_list//"_TSP\n"//in_list//"_URQ\n"//in_list//"_VWX", > "_coaddTmp5_") # create list of all image lists to be included in coadd !fgrep -v -f _coaddTmp1_ _coaddTmp5_ > _coaddTmp6_ concat ("@_coaddTmp6_", in_list//"_most") } # offset the shift lists of all the images to be included in the coadd # by their offsets to the central image (BA) if(!access(image_root//".1stpass.shmost"//n_iter)) { # create list of codes of all image lists print ("BA\nCD\nEHI\nFGJ\nMLK\nON\nTSP\nURQ\nVWX", > "_coaddTmp7_") # create list of codes of all image lists to be included in coadd !fgrep -v -f _coaddTmp1_ _coaddTmp7_ > _coaddTmp8_ list = "_coaddTmp8_" while (fscan (list, in_string) !=EOF) { if (in_string=="BA") { filecalc (image_root//".roundoff.shBA"//n_iter//"min0", "$1+"//xbaba//";$2+"//ybaba, format="%4.0f %4.0f", >> image_root//".1stpass.shmost"//n_iter) } else if (in_string=="CD") { filecalc (image_root//".roundoff.shCD"//n_iter//"min0", "$1+"//xcdba//";$2+"//ycdba, format="%4.0f %4.0f", >> image_root//".1stpass.shmost"//n_iter) } else if (in_string=="EHI") { filecalc (image_root//".roundoff.shEHI"//n_iter//"min0", "$1+"//xehiba//";$2+"//yehiba, format="%4.0f %4.0f", >> image_root//".1stpass.shmost"//n_iter) } else if (in_string=="FGJ") { filecalc (image_root//".roundoff.shFGJ"//n_iter//"min0", "$1+"//xfgjba//";$2+"//yfgjba, format="%4.0f %4.0f", >> image_root//".1stpass.shmost"//n_iter) } else if (in_string=="MLK") { filecalc (image_root//".roundoff.shMLK"//n_iter//"min0", "$1+"//xmlkba//";$2+"//ymlkba, format="%4.0f %4.0f", >> image_root//".1stpass.shmost"//n_iter) } else if (in_string=="ON") { filecalc (image_root//".roundoff.shON"//n_iter//"min0", "$1+"//xonba//";$2+"//yonba, format="%4.0f %4.0f", >> image_root//".1stpass.shmost"//n_iter) } else if (in_string=="TSP") { filecalc (image_root//".roundoff.shTSP"//n_iter//"min0", "$1+"//xtspba//";$2+"//ytspba, format="%4.0f %4.0f", >> image_root//".1stpass.shmost"//n_iter) } else if (in_string=="URQ") { filecalc (image_root//".roundoff.shURQ"//n_iter//"min0", "$1+"//xurqba//";$2+"//yurqba, format="%4.0f %4.0f", >> image_root//".1stpass.shmost"//n_iter) } else if (in_string=="VWX") { filecalc (image_root//".roundoff.shVWX"//n_iter//"min0", "$1+"//xvwxba//";$2+"//yvwxba, format="%4.0f %4.0f", >> image_root//".1stpass.shmost"//n_iter) } } del ("_coaddTmp?_", ver-, >& "dev$null") } # do the most-images coadd if (!access(image_root//"most"//n_iter//"_1stpass."//im_extn)) { print ("\n===> Coadding most images at once...") ircoadd (in_list//"_most", image_root//"most"//n_iter//"_1stpass", "", image_root//".1stpass.shmost"//n_iter, "none", "mode", "none", 1, no, "log_"//in_list//"_all", stdpars-, makeavg+, flip-, imcoaddpars="phiirs$ircoaddonis.par") } # do nshift on most-images coadd if (!access(image_root//".roundoff.shrest"//n_iter)) nshift ("", in_list//"_coaddrest_"//n_iter, image_root//"most"//n_iter//"_1stpass", image_root, "shrest"//n_iter, redo=re_do, useimages=images_use, displayim=im_display, editfiles=files_edit) # get shifts for images excluded from most-images coadd if (!access(image_root//".imshifts.shrest"//n_iter)) join(in_list//"_coaddrest_"//n_iter,image_root//".shiftexact.shrest"//n_iter, >>image_root//".imshifts.shrest"//n_iter) grep("BA",image_root//".imshifts.shrest"//n_iter)|scan(theory, bamost_xshiftexact, bamost_yshiftexact) if(bamost_xshiftexact>=0)xbamost=int(0.5+bamost_xshiftexact) if(bamost_yshiftexact>=0)ybamost=int(0.5+bamost_yshiftexact) if(bamost_xshiftexact<0)xbamost=int(-0.5+bamost_xshiftexact) if(bamost_yshiftexact<0)ybamost=int(-0.5+bamost_yshiftexact) if (stridx(ex_string,"BA")!=0) { grep("BA",image_root//".imshifts.shrest"//n_iter)|scan(theory, baba_xshiftexact, baba_yshiftexact) if(baba_xshiftexact>=0)xbaba=int(0.5+baba_xshiftexact)-xbamost if(baba_yshiftexact>=0)ybaba=int(0.5+baba_yshiftexact)-ybamost if(baba_xshiftexact<0)xbaba=int(-0.5+baba_xshiftexact)-xbamost if(baba_yshiftexact<0)ybaba=int(-0.5+baba_yshiftexact)-ybamost } if (stridx(ex_string,"CD")!=0) { grep("CD",image_root//".imshifts.shrest"//n_iter)|scan(theory,cdba_xshiftexact,cdba_yshiftexact) if(cdba_xshiftexact>=0)xcdba=int(0.5+cdba_xshiftexact)-xbamost if(cdba_yshiftexact>=0)ycdba=int(0.5+cdba_yshiftexact)-ybamost if(cdba_xshiftexact<0)xcdba=int(-0.5+cdba_xshiftexact)-xbamost if(cdba_yshiftexact<0)ycdba=int(-0.5+cdba_yshiftexact)-ybamost } if (stridx(ex_string,"EHI")!=0) { grep("EHI",image_root//".imshifts.shrest"//n_iter)|scan(theory,ehiba_xshiftexact,ehiba_yshiftexact) if(ehiba_xshiftexact>=0)xehiba=int(0.5+ehiba_xshiftexact)-xbamost if(ehiba_yshiftexact>=0)yehiba=int(0.5+ehiba_yshiftexact)-ybamost if(ehiba_xshiftexact<0)xehiba=int(-0.5+ehiba_xshiftexact)-xbamost if(ehiba_yshiftexact<0)yehiba=int(-0.5+ehiba_yshiftexact)-ybamost } if (stridx(ex_string,"FGJ")!=0) { grep("FGJ",image_root//".imshifts.shrest"//n_iter)|scan(theory,fgjba_xshiftexact,fgjba_yshiftexact) if(fgjba_xshiftexact>=0)xfgjba=int(0.5+fgjba_xshiftexact)-xbamost if(fgjba_yshiftexact>=0)yfgjba=int(0.5+fgjba_yshiftexact)-ybamost if(fgjba_xshiftexact<0)xfgjba=int(-0.5+fgjba_xshiftexact)-xbamost if(fgjba_yshiftexact<0)yfgjba=int(-0.5+fgjba_yshiftexact)-ybamost } if (stridx(ex_string,"MLK")!=0) { grep("MLK",image_root//".imshifts.shrest"//n_iter)|scan(theory,mlkba_xshiftexact,mlkba_yshiftexact) if(mlkba_xshiftexact>=0)xmlkba=int(0.5+mlkba_xshiftexact)-xbamost if(mlkba_yshiftexact>=0)ymlkba=int(0.5+mlkba_yshiftexact)-ybamost if(mlkba_xshiftexact<0)xmlkba=int(-0.5+mlkba_xshiftexact)-xbamost if(mlkba_yshiftexact<0)ymlkba=int(-0.5+mlkba_yshiftexact)-ybamost } if (stridx(ex_string,"ON")!=0) { grep("ON",image_root//".imshifts.shrest"//n_iter)|scan(theory,onba_xshiftexact,onba_yshiftexact) if(onba_xshiftexact>=0)xonba=int(0.5+onba_xshiftexact)-xbamost if(onba_yshiftexact>=0)yonba=int(0.5+onba_yshiftexact)-ybamost if(onba_xshiftexact<0)xonba=int(-0.5+onba_xshiftexact)-xbamost if(onba_yshiftexact<0)yonba=int(-0.5+onba_yshiftexact)-ybamost } if (stridx(ex_string,"TSP")!=0) { grep("TSP",image_root//".imshifts.shrest"//n_iter)|scan(theory,tspba_xshiftexact,tspba_yshiftexact) if(tspba_xshiftexact>=0)xtspba=int(0.5+tspba_xshiftexact)-xbamost if(tspba_yshiftexact>=0)ytspba=int(0.5+tspba_yshiftexact)-ybamost if(tspba_xshiftexact<0)xtspba=int(-0.5+tspba_xshiftexact)-xbamost if(tspba_yshiftexact<0)ytspba=int(-0.5+tspba_yshiftexact)-ybamost } if (stridx(ex_string,"URQ")!=0) { grep("URQ",image_root//".imshifts.shrest"//n_iter)|scan(theory,urqba_xshiftexact,urqba_yshiftexact) if(urqba_xshiftexact>=0)xurqba=int(0.5+urqba_xshiftexact)-xbamost if(urqba_yshiftexact>=0)yurqba=int(0.5+urqba_yshiftexact)-ybamost if(urqba_xshiftexact<0)xurqba=int(-0.5+urqba_xshiftexact)-xbamost if(urqba_yshiftexact<0)yurqba=int(-0.5+urqba_yshiftexact)-ybamost } if (stridx(ex_string,"VWX")!=0) { grep("VWX",image_root//".imshifts.shrest"//n_iter)|scan(theory,vwxba_xshiftexact,vwxba_yshiftexact) if(vwxba_xshiftexact>=0)xvwxba=int(0.5+vwxba_xshiftexact)-xbamost if(vwxba_yshiftexact>=0)yvwxba=int(0.5+vwxba_yshiftexact)-ybamost if(vwxba_xshiftexact<0)xvwxba=int(-0.5+vwxba_xshiftexact)-xbamost if(vwxba_yshiftexact<0)yvwxba=int(-0.5+vwxba_yshiftexact)-ybamost } # now offset by offsets to the central image (BA) if(!access(in_list//"_all")) concat (in_list//"_BA,"//in_list//"_CD,"//in_list//"_EHI,"//in_list//"_FGJ,"//in_list//"_MLK,"//in_list//"_ON,"//in_list//"_TSP,"//in_list//"_URQ,"//in_list//"_VWX", in_list//"_all") if(!access(image_root//".1stpass.shall"//n_iter)) { filecalc (image_root//".roundoff.shBA"//n_iter//"min0", "$1+"//xbaba//";$2+"//ybaba, format="%4.0f %4.0f", >> image_root//".1stpass.shall"//n_iter) filecalc (image_root//".roundoff.shCD"//n_iter//"min0", "$1+"//xcdba//";$2+"//ycdba, format="%4.0f %4.0f", >> image_root//".1stpass.shall"//n_iter) filecalc (image_root//".roundoff.shEHI"//n_iter//"min0", "$1+"//xehiba//";$2+"//yehiba, format="%4.0f %4.0f", >> image_root//".1stpass.shall"//n_iter) filecalc (image_root//".roundoff.shFGJ"//n_iter//"min0", "$1+"//xfgjba//";$2+"//yfgjba, format="%4.0f %4.0f", >> image_root//".1stpass.shall"//n_iter) filecalc (image_root//".roundoff.shMLK"//n_iter//"min0", "$1+"//xmlkba//";$2+"//ymlkba, format="%4.0f %4.0f", >> image_root//".1stpass.shall"//n_iter) filecalc (image_root//".roundoff.shON"//n_iter//"min0", "$1+"//xonba//";$2+"//yonba, format="%4.0f %4.0f", >> image_root//".1stpass.shall"//n_iter) filecalc (image_root//".roundoff.shTSP"//n_iter//"min0", "$1+"//xtspba//";$2+"//ytspba, format="%4.0f %4.0f", >> image_root//".1stpass.shall"//n_iter) filecalc (image_root//".roundoff.shURQ"//n_iter//"min0", "$1+"//xurqba//";$2+"//yurqba, format="%4.0f %4.0f", >> image_root//".1stpass.shall"//n_iter) filecalc (image_root//".roundoff.shVWX"//n_iter//"min0", "$1+"//xvwxba//";$2+"//yvwxba, format="%4.0f %4.0f", >> image_root//".1stpass.shall"//n_iter) } # do the full coadd print ("\n===> Coadding all images at once...") ircoadd (in_list//"_all", image_root//"all"//n_iter//"_1stpass", "", image_root//".1stpass.shall"//n_iter, "none", "mode", "none", 1, no, "log_"//in_list//"_all", stdpars-, makeavg+, flip-, imcoaddpars="phiirs$ircoaddonis.par") } } # cross-correlate individual images with coadded image if (p_air=="all" && xcor_secondpass) { ixdim=xsize; iydim=ysize if(!access(sigprefix//image_root//"all"//n_iter//"_1stpass."//im_extn)){ print ("\n===> Creating constant-RMS coadded image...") sigmanorm(image_root//"all"//n_iter//"_1stpass."//im_extn) } imgets(sigprefix//image_root//"all"//n_iter//"_1stpass","i_naxis1") oxdim=int(imgets.value) imgets(sigprefix//image_root//"all"//n_iter//"_1stpass","i_naxis2") oydim=int(imgets.value) list=image_root//"all"//n_iter//"_1stpass.imshifts" if (!access(image_root//"all"//n_iter//"_xregout")) { print("\n===> Cross-correlating individual images w/coadded image...") while (fscan(list,image_name,x_shift,y_shift) !=EOF) { # zero out bad pixels if not already done imgets(image_name,"ZEROOUT") zero_out=imgets.value if(zero_out=="0"){ imgets(image_name,"BPMASK") if(imgets.value!="0"){ imar(image_name,"*",imgets.value,image_name,pixt="real",calct="real",ver-,noac-) hedit(image_name,"ZEROOUT",imgets.value,add+,ver-,show-,update+) } else { print("Bad pixels not zeroed for "//image_name//", and no BP mask in header!") } } if(xsize==0){ imgets(image_name,"i_naxis1") ixdim=int(imgets.value) } if(ysize==0){ imgets(image_name,"i_naxis2") iydim=int(imgets.value) } ix=x_shift+1-14; if(ix<1)ix=1 iy=y_shift+1-14; if(iy<1)iy=1 xe=x_shift + ixdim + 14; if(xe>oxdim)xe=oxdim ye=y_shift + iydim + 14; if(ye>oydim)ye=oydim msect = "["//ix//":"//xe//","//iy//":"//ye//"]" print ("Rough shift from "//image_name//" to "//sigprefix//image_root//"all"//n_iter//"_1stpass is "//x_shift//" "//y_shift//" pixels") immatch.xreg (image_name, sigprefix//image_root//"all"//n_iter//"_1stpass", msect, image_root//"all"//n_iter//"_xregout", datab+, records="", xlag=-1*x_shift, ylag=-1*y_shift, xwindow=25, ywindow=25, append+) } } tempx = mktemp("tempx"); tempy = mktemp("tempy") grep ('xshift', image_root//"all"//n_iter//"_xregout") | fields ("junk", "2", >> tempx) grep ('yshift', image_root//"all"//n_iter//"_xregout") | fields ("junk", "2", >> tempy) if(!access(image_root//".xregexact.shall"//n_iter)) join (tempx, tempy, output=image_root//".xregexact.shall"//n_iter) del (tempx, ver-); del (tempy, ver-) # Create optimum rounded-off integer offsets if (!access(rroundname)) { print("\n===> Finding optimum second-pass rounded-off integer offsets...") old_x = 999.; old_y = 999. # for each 0.01 pixel step... for (i=-50; i<50; i+=1) { step = i / 100. # print (i) # ...recalculate integer offsets... list=image_root//".xregexact.shall"//n_iter del (rroundname, ver-, >& "dev$null") while(fscan(list,xoff,yoff) !=EOF) { xoff=xoff+step yoff=yoff+step if(((abs(xoff))>=0.5) && ((abs(yoff))>=0.5)) { print(xoff,yoff, >> "temp."//rroundname) } else { if((abs(xoff))<=0.5) { xoff=0. } if((abs(yoff))<=0.5) { yoff=0. } print(xoff,yoff, >> "temp."//rroundname) } filecalc("temp."//rroundname, "$1;$2", format="%4.0f %4.0f", >> rroundname) flpr; flpr; flpr del ("temp."//rroundname, ver-, >& "dev$null") } del ("temp."//rroundname, ver-, >& "dev$null") # calculate sum of squares of residuals of exact offsets - new integer offsets filecalc (image_root//".xregexact.shall"//n_iter//","//rroundname, "$1@1-$1@2+"//step) | average (option = "new_sample", >& "dev$null") flpr; flpr; flpr new_x=average.sumsqrs filecalc (image_root//".xregexact.shall"//n_iter//","//rroundname, "$2@1-$2@2+"//step) | average (option = "new_sample", >& "dev$null") flpr; flpr; flpr new_y=average.sumsqrs if (new_x < old_x) { old_x = new_x step_x = step } if (new_y < old_y) { old_y = new_y step_y = step } } # recalculate final integer offsets list=image_root//".xregexact.shall"//n_iter del(rroundname,ver-) del ("temp."//rroundname, ver-, >& "dev$null") while(fscan(list,xoff,yoff) !=EOF) { xoff=xoff+step_x yoff=yoff+step_y if(((abs(xoff))>=0.5) && ((abs(yoff))>=0.5)) { print(xoff,yoff, >> "temp."//rroundname) } else { if((abs(xoff))<=0.5) { xoff=0. } if((abs(yoff))<=0.5) { yoff=0. } print(xoff,yoff, >> "temp."//rroundname) } filecalc("temp."//rroundname,"$1;$2",format="%4.0f %4.0f",>>rroundname) flpr; flpr; flpr del ("temp."//rroundname, ver-, >& "dev$null") } del ("temp."//rroundname, ver-, >& "dev$null") } del ("temp."//rroundname, ver-, >& "dev$null") filecalc (rroundname//","//image_root//".1stpass.shall"//n_iter, "$1@1-$1@2", lines="1-") | average filecalc (rroundname//","//image_root//".1stpass.shall"//n_iter, "$1@1-$1@2-"//average.mean, lines="1-", >> "temp."//rroundname) filecalc (rroundname//","//image_root//".1stpass.shall"//n_iter, "$2@1-$2@2", lines="1-") | average filecalc (rroundname//","//image_root//".1stpass.shall"//n_iter, "$2@1-$2@2-"//average.mean, lines="1-", >> "temp."//rroundname) graph ("temp."//rroundname, point-, title="mean-subtracted 2ndpass - 1stpass x and y offsets") del ("temp."//rroundname, ver-, >& "dev$null") } # Coadd images after second-pass cross-correlation if (p_air=="all" && coadd_secondpass) { print ("\n===> Coadding after second-pass cross-correlation...") ircoadd(in_list//"_all", image_root//"all"//n_iter, "", rroundname, "none", "mode", "none", 1, no, "log_"//in_list//"_all", stdpars-, makeavg-, flip-, imcoaddpars="phiirs$ircoaddonis.par") # ircoadd(in_list//"_all", image_root//"all"//n_iter//"avg", "", rroundname, "none", "mode", "none", 1, no, "log_"//in_list//"_all", stdpars-, makeavg+, flip-, imcoaddpars="phiirs$ircoaddonis.par") } # Make coadded-image object mask if (p_air=="all" && do_mkobjmask) { print ("\n===> Making coadded-image object mask...") mkobjmask (image_root//"all"//n_iter//"."//im_extn, "", suffix="objmask", nsmooth=3, subsample=3, filtsize=15, ngrow=1, interact+) } # Make individual-image object masks if (p_air=="all" && do_masklet) { print ("\n===> Making individual-image object masks...") masklet (image_root//"all"//n_iter, "", "om", shiftfile="", editfile+, flip-, update+) } } else { print ("\nWARNING! Package stsdas.imgtools not loaded... task aborted.") } if (echo_g) beep end ./onis6pt.cl0100644000151400000240000006026006721637630012121 0ustar phallgames# onis6pt -- shift & coadd ONIS CNOC 6-point roundabout dither pattern # 990413 -- created # 990419 -- major modifications # 990521 -- added some helpful screen output during shortaxes xreg step; # skip shiftlongaxes step if redo- & *.roundoff.* exists # layout of 6-point roundabout dither pattern (long axis vertical): # CDE # BAF procedure onis6pt(inlist,imageroot,niter) string inlist {prompt="List of input images"} string imageroot {prompt="Root name for output files"} int niter=1 {prompt="Number to append to output files"} string pair="all" {enum="BC|AD|FE|all",prompt="Pair of images to process (or all)"} bool inspect=yes {prompt="Inspect image lists before proceeding?"} bool shiftlongaxes=yes {prompt="Find shifts for image pairs w/overlapping long axes?"} bool coaddlongaxes=yes {prompt="Coadd image pairs w/overlapping long axes?"} string shortaxesmethod="both" {enum="xreg|irshift|both|none",prompt="Shift-finding method for overlapping short axes"} bool use_images=yes {prompt="Measure shifts from images (not file) in irshift?"} bool display_im=yes {prompt="Display images for imexam in irshift?"} bool redo=no {prompt="Redo shift-finding if already done?"} bool coaddallimages=yes {prompt="Coadd all images?"} bool secondpassxcor=yes {prompt="Cross-correlate all images with coadded image?"} bool coaddsecondpass=yes {prompt="Coadd images after second-pass cross-correlation?"} bool domkobjmask=yes {prompt="Make coadded-image object mask (INTERACTIVE)?"} bool domasklet=yes {prompt="Make individual-image object masks?"} bool echog=yes {prompt="Beep when task is done?"} struct *list begin string in_list, image_root, p_air, ref_image, tmpheaders, sigprefix, rroundname string theory, method_shortaxes, tempfile2, msect, image_name, tempx, tempy string zero_out int xmin, ymin, xint, yint, old_xint, old_yint, xmax_bcad, xmin_fead, ix, iy int n_iter, xbcad, ybcad, xfead, yfead, bcn1, fen1, xshift, yshift, xe, ye int xref, yref, int_x, int_y, junkint int oxdim,oydim # dimensions of mask image int ixdim,iydim # dimensions of individual input frames real xbcad2, ybcad2, xfead2, yfead2, bcad_x, bcad_y, fead_x, fead_y real xad, yad, xbc, ybc, xfe, yfe, bcad_xlag, bcad_ylag, fead_xlag, fead_ylag real bcad_xfirstpass, bcad_yfirstpass, bcad_xsecondpass, bcad_ysecondpass real fead_xfirstpass, fead_yfirstpass, fead_xsecondpass, fead_ysecondpass real xoff, yoff, step, new_x, new_y, old_x, old_y, step_x, step_y, xsig, ysig bool in_spect, shift_longaxes, echo_g, coadd_longaxes, abort, go, do_masklet bool coadd_allimages, xcor_secondpass, coadd_secondpass, do_mkobjmask, re_do bool im_display, images_use in_list=inlist image_root=imageroot n_iter=niter p_air=pair in_spect=inspect shift_longaxes=shiftlongaxes re_do=redo coadd_longaxes=coaddlongaxes method_shortaxes=shortaxesmethod images_use=use_images im_display=display_im coadd_allimages=coaddallimages xcor_secondpass=secondpassxcor coadd_secondpass=coaddsecondpass do_mkobjmask=domkobjmask do_masklet=domasklet echo_g=echog rroundname=image_root//".xregshifts.shBCADFE"//n_iter sigprefix=sigmanorm.prefix go=yes if(!defpac("imgtools")) {go=no} if(go) { # Separate input list into lists of images overlapping along long axes tmpheaders=mktemp("tmpheaders") hsel ("@"//in_list, "$I,i_title", yes, >> tmpheaders) if (!access(in_list//"_AD")) { grep ('Position\ \ 1\ of\ \ 6', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_AD") grep ('Position\ \ 4\ of\ \ 6', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_AD") } else { print (in_list//"_AD already exists; not created.") } if (!access(in_list//"_BC")) { grep ('Position\ \ 2\ of\ \ 6', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_BC") grep ('Position\ \ 3\ of\ \ 6', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_BC") } else { print (in_list//"_BC already exists; not created.") } if (!access(in_list//"_FE")) { grep ('Position\ \ 6\ of\ \ 6', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_FE") grep ('Position\ \ 5\ of\ \ 6', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_FE") } else { print (in_list//"_FE already exists; not created.") } del(tmpheaders,ver-) if (in_spect) vi (in_list//"_??") # Do irshift on lists of images overlapping along long axes if (shift_longaxes) { print ("Finding shifts for images overlapping along long axes...") if (p_air=="AD" || p_air=="all") { if (re_do || !access(image_root//".roundoff.shAD"//n_iter)) { fields (in_list//"_AD", 1, lines="2-2") | scan (ref_image) irshift (in_list//"_AD", ref_image, image_root, "shAD"//n_iter, useimages=images_use, displayim=im_display) } } if (p_air=="BC" || p_air=="all") { if (re_do || !access(image_root//".roundoff.shBC"//n_iter)) { fields (in_list//"_BC", 1, lines="2-2") | scan (ref_image) irshift (in_list//"_BC", ref_image, image_root, "shBC"//n_iter, useimages=images_use, displayim=im_display) } } if (p_air=="FE" || p_air=="all") { if (re_do || !access(image_root//".roundoff.shFE"//n_iter)) { fields (in_list//"_FE", 1, lines="2-2") | scan (ref_image) irshift (in_list//"_FE", ref_image, image_root, "shFE"//n_iter, useimages=images_use, displayim=im_display) } } } # Coadd images overlapping along long axes if (coadd_longaxes) { print ("Coadding images overlapping along long axes...") if (p_air=="AD" || p_air=="all") { imdel (image_root//"AD"//n_iter, ver-, >& "dev$null") imdel (image_root//"AD"//n_iter//"em", ver-, >& "dev$null") del (image_root//"AD"//n_iter//".imshifts", ver-, >& "dev$null") imdel (sigprefix//image_root//"AD"//n_iter, ver-, >& "dev$null") ircoadd (in_list//"_AD", image_root//"AD"//n_iter, "", image_root//".roundoff.shAD"//n_iter, "none", "mode", "none", 1, no, "log_"//image_root//"_ABCDEF", makeavg+, flip-) sigmanorm (image_root//"AD"//n_iter) } if (p_air=="BC" || p_air=="all") { imdel (image_root//"BC"//n_iter, ver-, >& "dev$null") imdel (image_root//"BC"//n_iter//"em", ver-, >& "dev$null") del (image_root//"BC"//n_iter//".imshifts", ver-, >& "dev$null") imdel (sigprefix//image_root//"BC"//n_iter, ver-, >& "dev$null") ircoadd (in_list//"_BC", image_root//"BC"//n_iter, "", image_root//".roundoff.shBC"//n_iter, "none", "mode", "none", 1, no, "log_"//image_root//"_ABCDEF", makeavg+, flip-) sigmanorm (image_root//"BC"//n_iter) } if (p_air=="FE" || p_air=="all") { imdel (image_root//"FE"//n_iter, ver-, >& "dev$null") imdel (image_root//"FE"//n_iter//"em", ver-, >& "dev$null") del (image_root//"FE"//n_iter//".imshifts", ver-, >& "dev$null") imdel (sigprefix//image_root//"FE"//n_iter, ver-, >& "dev$null") ircoadd (in_list//"_FE", image_root//"FE"//n_iter, "", image_root//".roundoff.shFE"//n_iter, "none", "mode", "none", 1, no, "log_"//image_root//"_ABCDEF", makeavg+, flip-) sigmanorm (image_root//"FE"//n_iter) } } # Determine offsets along short axes #--xreg method------------------------------------------------------------------ if (p_air=="all" && (method_shortaxes=="xreg" || method_shortaxes=="both")) { if (!access(image_root//"_shBCAD"//n_iter) || !access(image_root//"_shFEAD"//n_iter)) { if (re_do) { del (image_root//"_shBCAD"//n_iter//"_rough", ver-, >& "dev$null") del (image_root//"_shFEAD"//n_iter//"_rough", ver-, >& "dev$null") del (image_root//"_shBCAD"//n_iter//"_1stpass", ver-, >& "dev$null") del (image_root//"_shFEAD"//n_iter//"_1stpass", ver-, >& "dev$null") del (image_root//"_shBCAD"//n_iter, ver-, >& "dev$null") del (image_root//"_shFEAD"//n_iter, ver-, >& "dev$null") print ("") print ("The imexam log file has been preserved; all else will be recreated.") } print ("") print ("The xregister offset method must be given rough offsets:") print ("Find an object in both the BC and AD images. Get its coords") print ("(type 'a' or 'r') in the AD image, then in the BC image.") print ("Then find an object in both the FE and AD images, get its coords") print ("in the AD image, then in the FE image, and then type 'q'.") print ("The imexam log file will appear for editing in case it's needed.") displ (sigprefix//image_root//"BC"//n_iter, 1) displ (sigprefix//image_root//"FE"//n_iter, 3) displ (sigprefix//image_root//"AD"//n_iter, 2) tempfile2=mktemp("temp2") print ("#**PROPER FORMAT**: uncommented line 1: AD, 2: BC, 3: AD, 4: FE", >> "log_imexam_"//image_root) imexam (sigprefix//image_root//"AD"//n_iter, logfile="log_imexam_"//image_root) vi ("log_imexam_"//image_root) print ("") # get rough x,y lags from object pairs (lag=other-AD) fields ("log_imexam_"//image_root, "1-2", lines="1-", >> tempfile2) fields (tempfile2, "1-2", lines="1-1") | scan (xad,yad) fields (tempfile2, "1-2", lines="2-2") | scan (xbc,ybc) bcad_xlag=xbc-xad; bcad_ylag=ybc-yad print (-1*bcad_xlag,-1*bcad_ylag, >> image_root//"_shBCAD"//n_iter//"_rough") print ("Rough shift from "//sigprefix//image_root//"BC"//n_iter//" to "//sigprefix//image_root//"AD"//n_iter//" is "//-1*bcad_xlag//" "//-1*bcad_ylag//" pixels") fields (tempfile2, "1-2", lines="3-3") | scan (xad,yad) fields (tempfile2, "1-2", lines="4-4") | scan (xfe,yfe) fead_xlag=xfe-xad; fead_ylag=yfe-yad print (-1*fead_xlag,-1*fead_ylag, >> image_root//"_shFEAD"//n_iter//"_rough") print ("Rough shift from "//sigprefix//image_root//"FE"//n_iter//" to "//sigprefix//image_root//"AD"//n_iter//" is "//-1*fead_xlag//" "//-1*fead_ylag//" pixels") del (tempfile2, ver-) # figure out image section limits from rough offsets imgets (sigprefix//image_root//"BC"//n_iter, "i_naxis1"); bcn1=int(imgets.value) imgets (sigprefix//image_root//"FE"//n_iter, "i_naxis1"); fen1=int(imgets.value) xmax_bcad = bcn1 - int(bcad_xlag) xmin_fead = int(abs(fead_xlag)) # first-pass with rough lag print ("") print ("First pass: immatch.xreg using [1:"//xmax_bcad//",*] xlag="/bcad_xlag//" ylag="//bcad_ylag) immatch.xreg (sigprefix//image_root//"BC"//n_iter, sigprefix//image_root//"AD"//n_iter, "[1:"//xmax_bcad//",*]", image_root//"_shBCAD"//n_iter//"_1stpass", datab-, xlag=bcad_xlag, ylag=bcad_ylag, xwindow=25, ywindow=25) print ("First pass: immatch.xreg using ["//xmin_fead//":"//fen1//",*] xlag="/fead_xlag//" ylag="//fead_ylag) immatch.xreg (sigprefix//image_root//"FE"//n_iter, sigprefix//image_root//"AD"//n_iter, "["//xmin_fead//":"//fen1//",*]", image_root//"_shFEAD"//n_iter//"_1stpass", datab-, xlag=fead_xlag, ylag=fead_ylag, xwindow=25, ywindow=25) # second-pass with with result of first-pass type(image_root//"_shBCAD"//n_iter//"_1stpass") | scan(theory, bcad_xfirstpass, bcad_yfirstpass) print ("") print ("Second pass: immatch.xreg using [1:"//xmax_bcad//",*] xlag="//-1*bcad_xfirstpass//" ylag="//-1*bcad_yfirstpass) immatch.xreg (sigprefix//image_root//"BC"//n_iter, sigprefix//image_root//"AD"//n_iter, "[1:"//xmax_bcad//",*]", image_root//"_shBCAD"//n_iter, datab-, xlag=-1*bcad_xfirstpass, ylag=-1*bcad_yfirstpass, xwindow=25, ywindow=25) type(image_root//"_shFEAD"//n_iter//"_1stpass") | scan(theory, fead_xfirstpass, fead_yfirstpass) print ("Second pass: immatch.xreg using ["//xmin_fead//":"//fen1//",*] xlag="//-1*fead_xfirstpass//" ylag="//-1*fead_yfirstpass) immatch.xreg (sigprefix//image_root//"FE"//n_iter, sigprefix//image_root//"AD"//n_iter, "["//xmin_fead//":"//fen1//",*]", image_root//"_shFEAD"//n_iter, datab-, xlag=-1*fead_xfirstpass, ylag=-1*fead_yfirstpass, xwindow=25, ywindow=25) print ("") # abort if diverging, i.e. if abs(secondpass-firstpass)>0.5*abs(firstpass+rough) # "+" is because output of xreg is opposite sign of input lag abort=no type (image_root//"_shBCAD"//n_iter) | scan (theory, bcad_xsecondpass, bcad_ysecondpass) if ((abs(bcad_xsecondpass - bcad_xfirstpass)) > (abs(0.5*(bcad_xfirstpass + bcad_xlag)))) abort=yes if ((abs(bcad_ysecondpass - bcad_yfirstpass)) > (abs(0.5*(bcad_yfirstpass + bcad_ylag)))) abort=yes type (image_root//"_shFEAD"//n_iter) | scan (theory, fead_xsecondpass, fead_ysecondpass) if ((abs(fead_xsecondpass - fead_xfirstpass)) > (abs(0.5*(fead_xfirstpass + fead_xlag)))) abort=yes if ((abs(fead_ysecondpass - fead_yfirstpass)) > (abs(0.5*(fead_yfirstpass + fead_ylag)))) abort=yes if (abort) { beep print("WARNING! xregister did not converge for at least one offset.") print("Stopping task; finish xregister manually and then resume.") return } } type (image_root//"_shBCAD"//n_iter) | scan (theory, bcad_xsecondpass, bcad_ysecondpass) type (image_root//"_shFEAD"//n_iter) | scan (theory, fead_xsecondpass, fead_ysecondpass) if(bcad_xsecondpass>=0)xbcad=int(0.5+bcad_xsecondpass) if(bcad_ysecondpass>=0)ybcad=int(0.5+bcad_ysecondpass) if(fead_xsecondpass>=0)xfead=int(0.5+fead_xsecondpass) if(fead_xsecondpass>=0)yfead=int(0.5+fead_ysecondpass) if(bcad_xsecondpass<0)xbcad=int(-0.5+bcad_xsecondpass) if(bcad_ysecondpass<0)ybcad=int(-0.5+bcad_ysecondpass) if(fead_xsecondpass<0)xfead=int(-0.5+fead_xsecondpass) if(fead_xsecondpass<0)yfead=int(-0.5+fead_ysecondpass) } #--irshift method--------------------------------------------------------------- if (p_air=="all" && (method_shortaxes=="irshift" || method_shortaxes=="both")) { if(!access(image_root//".roundoff.shBCAD"//n_iter) || !access(image_root//".roundoff.shFEAD"//n_iter)) { if (re_do) { del(image_root//".imshifts.sh??"//n_iter, ver-, >& "dev$null") del(image_root//".offsets.sh??"//n_iter, ver-, >& "dev$null") del(image_root//".roundoff.sh??"//n_iter, ver-, >& "dev$null") del(image_root//".shiftexact.sh??"//n_iter, ver-, >& "dev$null") del(image_root//".shiftfrac.sh??"//n_iter, ver-, >& "dev$null") del(image_root//".shiftint.sh??"//n_iter, ver-, >& "dev$null") print ("The *allcoords* and *refcoords* files have been saved;") print ("all else will be recreated.") } if(!access(in_list//"_BCAD")) { print (sigprefix//image_root//"BC"//n_iter, >> in_list//"_BCAD") print (sigprefix//image_root//"AD"//n_iter, >> in_list//"_BCAD") } irshift (in_list//"_BCAD", sigprefix//image_root//"AD"//n_iter, image_root, "shBCAD"//n_iter, useimages=images_use, displayim=im_display) if(!access(in_list//"_FEAD")) { print (sigprefix//image_root//"FE"//n_iter, >> in_list//"_FEAD") print (sigprefix//image_root//"AD"//n_iter, >> in_list//"_FEAD") } irshift (in_list//"_FEAD", sigprefix//image_root//"AD"//n_iter, image_root, "shFEAD"//n_iter, useimages=images_use, displayim=im_display) } fields (image_root//".shiftexact.shBCAD"//n_iter, "1-2", lines="1-1") | scan (xbc, ybc) fields (image_root//".shiftexact.shBCAD"//n_iter, "1-2", lines="2-2") | scan (xad, yad) fields (image_root//".shiftexact.shFEAD"//n_iter, "1-2", lines="1-1") | scan (xfe, yfe) fields (image_root//".shiftexact.shFEAD"//n_iter, "1-2", lines="2-2") | scan (xad, yad) xbcad2=xbc-xad; ybcad2=ybc-yad; xfead2=xfe-xad; yfead2=yfe-yad # set xbcad ybcad xfead yfead if "both" if (method_shortaxes=="both") { print ("") print ("BC/AD xregister offsets: "//bcad_xsecondpass//" "//bcad_ysecondpass) print ("BC/AD irshift offsets: "//xbcad2//" "//ybcad2) tempx = mktemp("tempx"); tempy = mktemp("tempy") print (xbcad, >> tempx); print (xbcad2, >> tempx) print (ybcad, >> tempy); print (ybcad2, >> tempy) type (tempx) | average | scan (bcad_x, xsig, junkint) type (tempy) | average | scan (bcad_y, ysig, junkint) print ("BC/AD average offsets: "//bcad_x//"+-"//xsig//" "//bcad_y//"+-"//ysig) del (tempx, ver-); del (tempy, ver-) if(!access(image_root//"_shBCAD"//n_iter//"_irshift"))print(xbcad2, ybcad2, >> image_root//"_shBCAD"//n_iter//"_irshift") if(!access(image_root//"_shBCAD"//n_iter//"_xreg"))copy(image_root//"_shBCAD"//n_iter,image_root//"_shBCAD"//n_iter//"_xreg") print (bcad_x, bcad_y, xsig, ysig, >> image_root//"_shBCAD"//n_iter) print ("") print ("FE/AD xregister offsets: "//fead_xsecondpass//" "//fead_ysecondpass) print ("FE/AD irshift offsets: "//xfead2//" "//yfead2) tempx = mktemp("tempx"); tempy = mktemp("tempy") print (xfead, >> tempx); print (xfead2, >> tempx) print (yfead, >> tempy); print (yfead2, >> tempy) type (tempx) | average | scan (fead_x, xsig, junkint) type (tempy) | average | scan (fead_y, ysig, junkint) print ("FE/AD average offsets: "//fead_x//"+-"//xsig//" "//fead_x//"+-"//ysig) del (tempx, ver-); del (tempy, ver-) if(!access(image_root//"_shFEAD"//n_iter//"_irshift"))print(xfead2, yfead2, >> image_root//"_shFEAD"//n_iter//"_irshift") if(!access(image_root//"_shFEAD"//n_iter//"_xreg"))copy(image_root//"_shFEAD"//n_iter,image_root//"_shFEAD"//n_iter//"_xreg") print (fead_x, fead_y, xsig, ysig, >> image_root//"_shFEAD"//n_iter) print ("") xbcad=int(abs(0.5+bcad_x)); ybcad=int(abs(0.5+bcad_y)) xfead=int(abs(0.5+fead_x)); yfead=int(abs(0.5+fead_y)) } } # coadd all images at once if (p_air=="all" && coadd_allimages) { # set minimum x,y offsets to be 0 & 0 (independently) if (!access(image_root//".roundoff.shAD"//n_iter//"min0")) { list=image_root//".roundoff.shAD"//n_iter xmin=9999; ymin=9999 while (fscan(list,xint,yint) !=EOF) { if (xint < xmin) xmin = xint if (yint < ymin) ymin = yint } filecalc(image_root//".roundoff.shAD"//n_iter, "$1-"//xmin//";$2-"//ymin, format="%4.0f %4.0f", >> image_root//".roundoff.shAD"//n_iter//"min0") } if (!access(image_root//".roundoff.shBC"//n_iter//"min0")) { list=image_root//".roundoff.shBC"//n_iter xmin=9999; ymin=9999 while (fscan(list,xint,yint) !=EOF) { if (xint < xmin) xmin = xint if (yint < ymin) ymin = yint } filecalc(image_root//".roundoff.shBC"//n_iter, "$1-"//xmin//";$2-"//ymin, format="%4.0f %4.0f", >> image_root//".roundoff.shBC"//n_iter//"min0") } list=image_root//".roundoff.shFE"//n_iter if (!access(image_root//".roundoff.shFE"//n_iter//"min0")) { xmin=9999; ymin=9999 while (fscan(list,xint,yint) !=EOF) { if (xint < xmin) xmin = xint if (yint < ymin) ymin = yint } filecalc(image_root//".roundoff.shFE"//n_iter, "$1-"//xmin//";$2-"//ymin, format="%4.0f %4.0f", >> image_root//".roundoff.shFE"//n_iter//"min0") } # then offset by BC/AD or FE/AD offsets, as appropriate if(!access(image_root//".roundoff.shBCADFE"//n_iter)) { filecalc (image_root//".roundoff.shBC"//n_iter//"min0", "$1+"//xbcad//";$2+"//ybcad, format="%4.0f %4.0f", >> image_root//".roundoff.shBCADFE"//n_iter) type (image_root//".roundoff.shAD"//n_iter//"min0", >> image_root//".roundoff.shBCADFE"//n_iter) filecalc (image_root//".roundoff.shFE"//n_iter//"min0", "$1+"//xfead//";$2+"//yfead, format="%4.0f %4.0f", >> image_root//".roundoff.shBCADFE"//n_iter) } if(!access(in_list//"_BCADFE")) concat (in_list//"_BC,"//in_list//"_AD,"//in_list//"_FE", in_list//"_BCADFE") # do the coadd print ("Coadding all images at once...") ircoadd (in_list//"_BCADFE", image_root//"BCADFE"//n_iter//"_1stpass", "", image_root//".roundoff.shBCADFE"//n_iter, "none", "mode", "none", 1, no, "log_"//in_list//"_ABCDEF", stdpars-, makeavg+, flip-, imcoaddpars="phiirs$ircoaddonis.par") } # cross-correlate individual images with coadded image if (p_air=="all" && xcor_secondpass) { print ("Creating constant-RMS coadded image...") ixdim=512; iydim=1024 if (!access(sigprefix//image_root//"BCADFE"//n_iter//"_1stpass.fits")) sigmanorm (image_root//"BCADFE"//n_iter//"_1stpass.fits") print ("Cross-correlating individual images with coadded image...") imgets(sigprefix//image_root//"BCADFE"//n_iter//"_1stpass","i_naxis1") oxdim=int(imgets.value) imgets(sigprefix//image_root//"BCADFE"//n_iter//"_1stpass","i_naxis2") oydim=int(imgets.value) list=image_root//"BCADFE"//n_iter//"_1stpass.imshifts" while (fscan(list,image_name,xshift,yshift) !=EOF) { # zero out bad pixels if not already done imgets(image_name,"ZEROOUT") zero_out=imgets.value if(zero_out=="0"){ imgets(image_name,"BPMASK") if(imgets.value!="0"){ imar(image_name,"*",imgets.value,image_name,pixt="real",calct="real",ver-,noac-) hedit(image_name,"ZEROOUT",imgets.value,add+,ver-,show-,update+) } else { print("Bad pixels not zeroed for "//image_name//", and no BP mask in header!") } } ix=xshift+1-14; if(ix<1)ix=1 iy=yshift+1-14; if(iy<1)iy=1 xe=xshift + ixdim + 14; if(xe>oxdim)xe=oxdim ye=yshift + iydim + 14; if(ye>oydim)ye=oydim msect = "["//ix//":"//xe//","//iy//":"//ye//"]" print ("Rough shift from "//image_name//" to "//sigprefix//image_root//"BCADFE"//n_iter//"_1stpass is "//xshift//" "//yshift//" pixels") immatch.xreg (image_name, sigprefix//image_root//"BCADFE"//n_iter//"_1stpass", msect, image_root//"BCADFE"//n_iter//"_xregout", datab+, records="", xlag=-1*xshift, ylag=-1*yshift, xwindow=25, ywindow=25, append+) } tempx = mktemp("tempx"); tempy = mktemp("tempy") grep ('xshift', image_root//"BCADFE"//n_iter//"_xregout") | fields ("junk", "2", >> tempx) grep ('yshift', image_root//"BCADFE"//n_iter//"_xregout") | fields ("junk", "2", >> tempy) if(!access(image_root//".xregexact.shBCADFE"//n_iter)) join (tempx, tempy, output=image_root//".xregexact.shBCADFE"//n_iter) del (tempx, ver-); del (tempy, ver-) # Create optimum rounded-off integer offsets print(" ") print("===) Finding optimum second-pass rounded-off integer offsets...") old_x = 999.; old_y = 999. # for each 0.01 pixel step... for (i=-50; i<50; i+=1) { step = i / 100. # print (i) # ...recalculate integer offsets... list=image_root//".xregexact.shBCADFE"//n_iter del (rroundname, ver-, >& "dev$null") while(fscan(list,xoff,yoff) !=EOF) { xoff=xoff+step yoff=yoff+step if(((abs(xoff))>=0.5) && ((abs(yoff))>=0.5)) { print(xoff,yoff, >> "temp."//rroundname) } else { if((abs(xoff))<=0.5) { xoff=0. } if((abs(yoff))<=0.5) { yoff=0. } print(xoff,yoff, >> "temp."//rroundname) } filecalc("temp."//rroundname, "$1;$2", format="%4.0f %4.0f", >> rroundname) flpr; flpr; flpr del ("temp."//rroundname, ver-, >& "dev$null") } del ("temp."//rroundname, ver-, >& "dev$null") # calculate sum of squares of residuals of exact offsets - new integer offsets filecalc (image_root//".xregexact.shBCADFE"//n_iter//","//rroundname, "$1@1-$1@2+"//step) | average (option = "new_sample", >& "dev$null") flpr; flpr; flpr new_x=average.sumsqrs filecalc (image_root//".xregexact.shBCADFE"//n_iter//","//rroundname, "$2@1-$2@2+"//step) | average (option = "new_sample", >& "dev$null") flpr; flpr; flpr new_y=average.sumsqrs if (new_x < old_x) { old_x = new_x step_x = step } if (new_y < old_y) { old_y = new_y step_y = step } } # recalculate final integer offsets list=image_root//".xregexact.shBCADFE"//n_iter del(rroundname,ver-) del ("temp."//rroundname, ver-, >& "dev$null") while(fscan(list,xoff,yoff) !=EOF) { xoff=xoff+step_x yoff=yoff+step_y if(((abs(xoff))>=0.5) && ((abs(yoff))>=0.5)) { print(xoff,yoff, >> "temp."//rroundname) } else { if((abs(xoff))<=0.5) { xoff=0. } if((abs(yoff))<=0.5) { yoff=0. } print(xoff,yoff, >> "temp."//rroundname) } filecalc("temp."//rroundname,"$1;$2",format="%4.0f %4.0f", >>rroundname) flpr; flpr; flpr del ("temp."//rroundname, ver-, >& "dev$null") } del ("temp."//rroundname, ver-, >& "dev$null") } # ** next 3 can be done in dophiirs # Coadd images after second-pass cross-correlation if (p_air=="all" && coadd_secondpass) { print ("Coadding after second-pass cross-correlation...") ircoadd(in_list//"_BCADFE", image_root//"BCADFE"//n_iter, "", rroundname, "none", "mode", "none", 1, no, "log_"//in_list//"_ABCDEF", stdpars-, makeavg-, flip-, imcoaddpars="phiirs$ircoaddonis.par") } # Make coadded-image object mask if (p_air=="all" && do_mkobjmask) { print ("Make coadded-image object mask...") mkobjmask (image_root//"BCADFE"//n_iter//".fits", "", suffix="objmask", nsmooth=3, subsample=3, filtsize=15, ngrow=1, interact+) } # Make individual-image object masks if (p_air=="all" && do_masklet) { print ("Make individual-image object masks...") masklet (image_root//"BCADFE"//n_iter, "", "om", shiftfile="", editfile+, flip-, update+) } } else { print ("WARNING! Package stsdas.imgtools not loaded... task aborted.") } if (echo_g) beep end ./imskypars.par0100644000151400000240000000316006664345000012712 0ustar phallgames#pset imskypars {prompt="Imcombine parameters"} i_sigma,s,h,"",,,"IMCOMBINE: Sigma image (optional)" i_plfile,s,h,"",,,"IMCOMBINE: Rejected pixel list image (optional)" i_combine,s,h,"median",average|median,,"IMCOMBINE: Type of combine operation (median|average)" i_reject,s,h,"ccdclip",none|minmax|ccdclip|crreject|sigclip|avsigclip|pclip,,"IMCOMBINE: Type of rejection" i_masktyp,s,h,"badvalue",none|goodvalue|badvalue|goodbits|badbits,,"IMCOMBINE: Mask type" i_maskval,r,h,0.,,,"IMCOMBINE: Mask value" i_blank,r,h,1.,,,"IMCOMBINE: Value if there are no pixels" i_scale,s,h,"median",,,"IMCOMBINE: Image scaling" i_zero,s,h,"none",,,"IMCOMBINE: Image scaling" i_weight,s,h,"none",,,"IMCOMBINE: Image weights" i_statsec,s,h,"",,,"IMCOMBINE: Image section for computing statistics" i_expname,s,h,"exptime",,,"IMCOMBINE: Image header exposure time keyword" i_lthresh,r,h,INDEF,,,"IMCOMBINE: Lower threshold" i_hthresh,r,h,INDEF,,,"IMCOMBINE: Upper threshold" i_nlow,r,h,1.,0,,"IMCOMBINE: minmax: Number of low pixels to reject" i_nhigh,r,h,1.,0,,"IMCOMBINE: minmax: Number of high pixels to reject" i_nkeep,r,h,1.,,,"IMCOMBINE: Minimum to keep (+) or maximum to reject(-)" i_lsigma,r,h,5.,0.,,"IMCOMBINE: Lower sigma clipping factor" i_hsigma,r,h,5.,0.,,"IMCOMBINE: Upper sigma clipping factor" i_rdnoise,r,h,73,,,"IMCOMBINE: ccdclip: CCD readout noise (electrons)" i_gain,r,h,15.3,,,"IMCOMBINE: ccdclip: CCD gain (electrons/ADU)" i_sigscale,r,h,0.1,0.,,"IMCOMBINE: Tolerance for sig-clip scaling corrections" i_pclip,r,h,-0.5,,,"IMCOMBINE: pclip: Percentile clipping parameter" i_grow,r,h,0.,,,"IMCOMBINE: Radius (pixels) for 1D neighbor rejection" ./onisfirst.cl0100644000151400000240000002334707254743526012550 0ustar phallgames# onisfirst.cl -- task to subtract dark & add header params to ONIS images # # 1. subtract dark # 2. hedit image headers, adding: (basically this task is hadd.cl plus #0) # 1. BPM,BPMASK = bad pixel mask name # 2. GAIN,RDNOISE if not present (currently assumes 4.,35.) # 3. coadds = number of coadds (copy of ncoadds) # 4. itime,exptime = exposure time per coadd (old exptime) # and total exposure time (itime * coadds) # 5. obs-date = date-obs but in dd/mm/yy format # 6. ut = time-obs (or time-obs + 7) # 7. date-obs = yyyy-mm-dd format (old date-obs saved as dateorig) # (following are optional) # 8. epoch, ra, dec = entered as parameters, if desired # 9. st = sidereal time, calculated from ut & date using astutil.asttimes # & the observatory parameter (kpno, mtbigelow, mmto, ctio) # 10. airmass = calculated from epoch, ra, dec, st, and obs-date # # 990202: created ONIS version; original exptime stored as itime # 990320: fixed bug where exptime & itime were feedbacking on each other # 990420: now adds gain & rdnoise to image header if not already there # 990427: DARKSUB keyword added to darksubbed images, not original ones # 990523: '>& "dev$null"' search for DARKSUB keyword to suppress error msg # # **bug: airmass+ airauto+ option assumes you're observing from MST time zone! # ...but that's only for the "asttimes" task, which may be irrelevant # **should be more options for computing ut than just time-obs or time-obs+7h procedure onisfirst(imagelist,darksub,badmask) string imagelist {prompt="List of images to process (do not use an `@')"} bool darksub=yes {prompt="Subtract off dark frame?"} string badmask {prompt="Name of bad pixel mask to add to image header"} string dark {prompt="Name of the dark frame to subtract", mode="q"} string darkstring {prompt="String to append to dark-subtracted images",mode="q"} bool coords=no {prompt="Add RA, DEC, and EPOCH to image header?"} bool airmass=yes {prompt="Enter airmass into image header?"} bool airauto=yes {prompt="Find airmass of image automatically?"} real airval {prompt="Airmass of image", mode="q"} string epoch="1950.0" {prompt="Epoch of coordinates"} string ra="" {prompt="Right Ascension (surround with quotes)"} string dec="" {prompt="Declination (surround w/quotes; use - but not +"} string observatory="kpno" {prompt="Observatory where observations were made"} bool ut=yes {prompt="Is 'time-obs' in header ut or not?"} bool ddmmyy=yes {prompt="Is 'date-obs' in day/month/year format?"} bool echog {yes,prompt="Beep when task is done?"} struct *list begin string ddark, ddarkstring, bbadmask, check, base, iimagelist, ext string darklist, flat, flatbase, meanfile, currentflat, tempflat, name string editlist, current, obsdate, rra, ddec, eepoch, oobservatory, minsec string obstime, timeobs, dateobs, century real intime, aairval, ttime, mean, meanbad, x int ncoadd, ddy, hhr, hhour, mmonth, yyear, dday, uttime, last2digits bool ddarksub, ccoords, aairauto, uut, aairmass iimagelist = imagelist list = iimagelist editlist = iimagelist ddarksub = darksub if (ddarksub) { ddark = dark ddarkstring = darkstring darklist = iimagelist//ddarkstring } bbadmask = badmask ccoords = coords aairmass = airmass if (aairmass) { aairauto = airauto # if(!aairauto)aairval = airval if(!defpac("astutil")) { beep print ("WARNING!! Package ''astutil'' is not loaded; cannot set airmass in images.") print ("Load the package and rerun the task.") return } } eepoch = epoch rra = ra ddec = dec oobservatory = observatory uut = ut # Add BPM and other goodies to the image headers, just like in the hadd.cl task print("===> Adding various parameters to the image headers...") list = iimagelist while (fscan (list, current) !=EOF) { hedit(current,"BPM",bbadmask,add+,ver-,show+,update+) hedit(current,"BPMASK",bbadmask,add+,ver-,show+,update+) # Currently assumes gain=4, rdnoise=35 imgets(current,"GAIN", >& "dev$null") if (imgets.value=="0" || imgets.value=="") { hedit(current,"GAIN","4.",add+,ver-,show+,updat+) } imgets(current,"RDNOISE", >& "dev$null") if (imgets.value=="0" || imgets.value=="") { hedit(current,"RDNOISE","35.",add+,ver-,show+,updat+) } # Set coadds=(# of coadds) imgets(current,"ncoadds", >& "dev$null") ncoadd=real(imgets.value) hedit(current,"coadds",(ncoadd),add+,ver-,show+,update+) # Set itime=exposure time per coadd imgets(current,"itime", >& "dev$null") if (imgets.value!="0") { print ("ITIME keyword already exists -- onisfirst already run on image?") } else { imgets(current,"exptime", >& "dev$null") intime=real(imgets.value) hedit(current,"itime",(intime),add+,ver-,show+,update+) # Set exptime=itime * (# of coadds) hedit(current,"exptime",(ncoadd*intime),add+,ver-,show+,update+) } # # The 'date-obs' keyword comes in either the old format "dd/mm/yy", # the erroneous format "mm/dd/yy", or the new format "yyyy-mm-dd". # Create new 'date-obs' keyword in the new format "yyyy-mm-dd". imgets(current,"dateorig",>&"dev$null") if (imgets.value!="0") { print ("DATEORIG keyword already exists -- onisfirst already run on image?") } else { imgets(current,"date-obs") # Copy 'date-obs' keyword to 'dateorig' in original format. hedit(current,"dateorig",imgets.value,add+,ver-,show+,update+) # Create header keyword 'obs-date', always in "dd/mm/yy" format. if(!ddmmyy){ # mm/dd/yy format: if(substr(imgets.value,3,3)=="/") { obsdate=substr(imgets.value,4,6)//substr(imgets.value,1,3)//substr(imgets.value,7,8) } else { # yyyy-mm-dd format: # 1234567890 obsdate=substr(imgets.value,9,10)//"/"//substr(imgets.value,6,7)//"/"//substr(imgets.value,3,4) } # create obs-date if date-obs in mm/dd/yy or yyyy-mm-dd format: hedit(current,"obs-date",obsdate,add+,ver-,show+,update+) } else { # create obs-date if date-obs in dd/mm/yy format: hedit(current,"obs-date",imgets.value,add+,ver-,show+,update+) } # Create new 'date-obs' in new format "yyyy-mm-dd" from 'obs-date' "dd/mm/yy" # 12345678 imgets(current,"obs-date") if ((substr(imgets.value,7,7))=="9") { century=19 } else { century=20 } dateobs=century//substr(imgets.value,7,8)//"-"//substr(imgets.value,4,5)//"-"//substr(imgets.value,1,2) hedit(current,"date-obs",dateobs,add+,ver-,show+,update+) # # Sometimes the time in the image header is ut, sometimes not. # so this option lets you choose either ut or mst if(uut){hedit(current,"ut",("(@'time-obs')"),add+,ver-,show+,update+)} else{ imgets(current,"time-obs") obstime=substr(imgets.value,1,2) uttime=int(obstime)+7 if(uttime>=24){uttime=uttime-24} if(uttime<=9){timeobs="0"//str(uttime)//substr(imgets.value,3,8)} if(uttime>=10){timeobs=str(uttime)//substr(imgets.value,3,8)} #need to hedit ut twice cause is not in hh:mm:ss format 1st time around hedit(current,"ut",timeobs,add+,ver-,show+,update+) hedit(current,"ut",timeobs,add+,ver-,show+,update+) } } } if(ccoords){ list = iimagelist while (fscan (list, current) !=EOF) { hedit(current,"epoch",eepoch,add+,ver-,show+,update+) hedit(current,"ra",rra,add+,ver-,show-,update+) hedit(current,"ra",rra,add+,ver-,show+,update+) hedit(current,"dec",ddec,add+,ver-,show-,update+) hedit(current,"dec",ddec,add+,ver-,show+,update+) #hedit test ra "(str('21:51:59.0'))" add+ ver- show- } } if(aairmass){ if(aairauto){ list = iimagelist while (fscan (list, current) !=EOF) { imgets(current,"obs-date") dday=int(substr(imgets.value,1,2)) mmonth=int(substr(imgets.value,4,5)) # yyear=int("19"//substr(imgets.value,7,8)) last2digits=int(substr(imgets.value,7,8)) if(last2digits <= 80) { yyear=int("20"//substr(imgets.value,7,8)) } else { yyear=int("19"//substr(imgets.value,7,8)) } imgets(current,"ut") hhr=int(substr(imgets.value,1,2)) minsec=substr(imgets.value,3,8) hhour=hhr-7 if(hhour<0){ dday=dday-1 hhour=hhour+24. } if(dday<=0){ mmonth=mmonth-1 # this will not always be totally accurate, and may fail for feb., but hey. dday=30 } # observing on new year's eve will require a new correction! ttime=real(str(int(hhour))//minsec) asttimes(observatory=oobservatory, year=yyear, month=mmonth, day=dday, time=ttime) hedit(current,"st",asttimes.lmst,add+,ver-,show-,update+) hedit(current,"st",asttimes.lmst,add+,ver-,show+,update+) setairmass(current, observatory=oobservatory, intype="middle", outtype="effective", date="obs-date",exposure="exptime", utmiddle="utmiddle", show+, update+, override+) } } else { list = iimagelist while (fscan (list, current) !=EOF) { print("Setting airmass for image "//current) hedit(current,"airmass",airval,add+,ver-,show+,update+) } } } # Subtract off Dark Current if (ddarksub) { list = iimagelist # if darklist doesn't exist, assume dsub imgs don't either; create it & dsubs if(!access(darklist)) { print("===> Subtracting off Dark Current...") while (fscan (list, name) !=EOF) { fileroot(name,validim+) base=fileroot.root ext=fileroot.extension if(ext!="")ext="."//ext print(base//ddarkstring//ext, >> darklist) imgets(name,"DARKSUB",>&"dev$null") if (imgets.value=="0") { imarith(name, "-", ddark, base//ddarkstring//ext, verbose-) hedit(base//ddarkstring//ext,"DARKSUB",ddark,add+,ver-,show+,update+) } else { print("DARKSUB keyword exists; onisfirst already run? "//name//" just copied") imcopy(name, base//ddarkstring//ext, verbose-) } } } else { print("Darksubbed image list "//darklist//" already exists; images assumed to exist too.") } #imarith("@"//iimagelist, "-", ddark, "@"//darklist, verbose-) #hedit("@"//darklist,"DARKSUB",ddark,add+,ver-,show+,update+) print(" ") print("===> Dark-subtracted images are listed in the file "//darklist//".") } if(echog)beep end ./phiirs.cl0100644000151400000240000000544607254742065012023 0ustar phallgames# Package script task for the PHIIRS package # Enter the correct pathname for the package directory, # using the following format: set phiirs = /astr16/users/phall/IRAF/phiirs/ package phiirs reset helpdb = (envget ("helpdb") // ",phiirs$helpdb.mip") task addcomment = phiirs$addcomment.cl task addring = phiirs$addring.cl task c40ircfirst = phiirs$c40ircfirst.cl task cfhtfirst = phiirs$cfhtfirst.cl task crzap = phiirs$crzap.cl task crzap2 = phiirs$crzap2.cl task destripe = phiirs$destripe.cl task domeflat = phiirs$domeflat.cl task dophiirs = phiirs$dophiirs.cl task fileroot = phiirs$fileroot.cl task first = phiirs$first.cl task imcoaddpars = phiirs$imcoaddpars.par task imflatpars = phiirs$imflatpars.par task imskypars = phiirs$imskypars.par task ircoadd = phiirs$ircoadd.cl task irflat = phiirs$irflat.cl task irimfirst = phiirs$irimfirst.cl task irrotate = phiirs$irrotate.cl task irshift = phiirs$irshift.cl task irshift2 = phiirs$irshift2.cl task irsky = phiirs$irsky.cl task irtfcoadd = phiirs$irtfcoadd.cl task irtffirst = phiirs$irtffirst.cl task irtfphotscale = phiirs$irtfphotscale.cl task iterstat = phiirs$iterstat.cl task look = phiirs$look.cl task look4m = phiirs$look4m.cl task makeobjmask = phiirs$makeobjmask.cl task masklet = phiirs$masklet.cl task maskstat = phiirs$maskstat.cl task minv = phiirs$minv.cl task mkbpm = phiirs$mkbpm.cl task mkdark = phiirs$mkdark.cl task mkflat = phiirs$mkflat.cl task mkobjmask = phiirs$mkobjmask.cl task myget = phiirs$myget.cl task nshift = phiirs$nshift.cl task nl_findcor = phiirs$nl_findcor.cl task onisfirst = phiirs$onisfirst.cl task onis0302 = phiirs$onis0302.cl task onis0451 = phiirs$onis0451.cl task onis1358cn = phiirs$onis1358cn.cl task onis1358s = phiirs$onis1358s.cl task onis3ew = phiirs$onis3ew.cl task onis6pt = phiirs$onis6pt.cl task osirisfirst = phiirs$osirisfirst.cl task photcheck = phiirs$photcheck.cl task photcomp = phiirs$photcomp.cl task photscale = phiirs$photscale.cl task piscesfirst = phiirs$piscesfirst.cl task precoadd = phiirs$precoadd.cl task qkflat = phiirs$qkflat.cl task qksky = phiirs$qksky.cl task sctv = phiirs$sctv.cl task sigmanorm = phiirs$sigmanorm.cl task sqiidfirst = phiirs$sqiidfirst.cl task subpattern = phiirs$subpattern.cl task tplpars = phiirs$tplpars.par task tpl = phiirs$tpl.cl task trim = phiirs$trim.cl task $untrim = phiirs$untrim.cl task xlist = phiirs$xlist.cl clbye() ./phiirs.hd0100644000151400000240000000662007254742077012016 0ustar phallgames# Help directory for the PHIIRS package # Enter the proper pathname for the package's help files, # using the following format: $doc = "phiirs$doc/" addcomment hlp = doc$addcomment.hlp, src = addcomment.cl addring hlp = doc$addring.hlp, src = addring.cl c40ircfirst hlp = doc$c40ircfirst.hlp, src = c40ircfirst.cl cfhtfirst hlp = doc$cfhtfirst.hlp, src = cfhtfirst.cl crzap hlp = doc$crzap.hlp, src = crzap.cl crzap2 hlp = doc$crzap2.hlp, src = crzap2.cl destripe hlp = doc$destripe.hlp, src = destripe.cl domeflat hlp = doc$domeflat.hlp, src = domeflat.cl dophiirs hlp = doc$dophiirs.hlp, src = dophiirs.cl fileroot hlp = doc$fileroot.hlp, src = fileroot.cl first hlp = doc$first.hlp, src = first.cl ircoadd hlp = doc$ircoadd.hlp, src = ircoadd.cl irflat hlp = doc$irflat.hlp, src = irflat.cl irimfirst hlp = doc$irimfirst.hlp, src = irimfirst.cl irrotate hlp = doc$irrotate.hlp, src = irrotate.cl irshift hlp = doc$irshift.hlp, src = irshift.cl irshift2 hlp = doc$irshift2.hlp, src = irshift2.cl irsky hlp = doc$irsky.hlp, src = irsky.cl irtfcoadd hlp = doc$irtfcoadd.hlp, src = irtfcoadd.cl irtffirst hlp = doc$irtffirst.hlp, src = irtffirst.cl irtfphotscale hlp = doc$irtfphotscale.hlp, src = irtfphotscale.cl iterstat hlp = doc$iterstat.hlp, src = iterstat.cl look hlp = doc$look.hlp, src = look.cl look4m hlp = doc$look4m.hlp, src = look4m.cl makeobjmask hlp = doc$makeobjmask.hlp, src = makeobjmask.cl masklet hlp = doc$masklet.hlp, src = masklet.cl maskstat hlp = doc$maskstat.hlp, src = maskstat.cl minv hlp = doc$minv.hlp, src = minv.cl mkbpm hlp = doc$mkbpm.hlp, src = mkbpm.cl mkdark hlp = doc$mkdark.hlp, src = mkdark.cl mkflat hlp = doc$mkflat.hlp, src = mkflat.cl mkobjmask hlp = doc$mkobjmask.hlp, src = mkobjmask.cl myget hlp = doc$myget.hlp, src = myget.cl nshift hlp = doc$nshift.hlp, src = nshift.cl nl_findcor hlp = doc$nl_findcor.hlp, src = nl_findcor.cl onisfirst hlp = doc$onisfirst.hlp, src = onisfirst.cl onis0302 hlp = doc$onis0302.hlp, src = onis0302.cl onis1358cn hlp = doc$onis1358cn.hlp, src = onis1358cn.cl onis1358s hlp = doc$onis1358s.hlp, src = onis1358s.cl onis3ew hlp = doc$onis3ew.hlp, src = onis3ew.cl onis6pt hlp = doc$onis6pt.hlp, src = onis6pt.cl osirisfirst hlp = doc$osirisfirst.hlp, src = osirisfirst.cl photcheck hlp = doc$photcheck.hlp, src = photcheck.cl photcomp hlp = doc$photcomp.hlp, src = photcomp.cl photscale hlp = doc$photscale.hlp, src = photscale.cl piscesfirst hlp = doc$piscesfirst.hlp, src = piscesfirst.cl precoadd hlp = doc$precoadd.hlp, src = precoadd.cl qkflat hlp = doc$qkflat.hlp, src = qkflat.cl qksky hlp = doc$qksky.hlp, src = qksky.cl sctv hlp = doc$sctv.hlp, src = sctv.cl sigmanorm hlp = doc$sigmanorm.hlp, src = sigmanorm.cl subpattern hlp = doc$subpattern.hlp, src = subpattern.cl tpl hlp = doc$tpl.hlp, src = tpl.cl trim hlp = doc$trim.hlp, src = trim.cl xlist hlp = doc$xlist.hlp, src = xlist.cl ./phiirs.men0100644000151400000240000000674407254742114012201 0ustar phallgames PHIIRS --- Pat Hall's Infrared Imaging Reduction Software addcomment - appends COMMENT cards to the image header addring - add rings around all objects in a mask image c40ircfirst - LCO40"/C40IRC specific version of first cfhtfirst - CFHT/KIR specific version of first crzap - remove cosmic rays using median filtering crzap2 - remove stubborn cosmic rays using imexam & fixpix domeflat - flatfield with a preexisting flat dophiirs - run PHIIRS in batch mode destripe - interactively remove striping from a coadded image fileroot - parses a file name into root and extension first - subtracts dark and adds header parameters to images ircoadd - produce coadded image and exposure map irflat - do flatfielding with a running flat irimfirst - does nonlinearity correction and darksub on IRIM images irrotate - rotate and resample images and recalculate shifts for them irshift - find offsets for images and optionally fractionally-shift them irshift2 - measure scale and rotation between two images' coord systems irsky - do skysubtraction with a running sky irtfcoadd - IRTF specific version of ircoadd (doesn't use CTIO package) irtffirst - IRTF/NSFCAM specific version of first irtfphotscale - IRTF specific version of photscale (doesn't use CTIO package) iterstat - find image statistics excluding deviant pixels look - convert from PC to IRAF format, then difference, 2 offset images look4m - take a quick look at a field thru difference of 2 offset images makeobjmask - create object masks for input images masklet - break coadded-image object mask into individual-image masklets maskstat - calculate images statistics from unmasked regions of an image minv - invert a mask of zeros and ones mkbpm - make a bad pixel mask (BPM) image mkdark - make a dark image mkflat - make domeflats from lamp-on and lamp-off images mkobjmask - interactively create object mas myget - convert images from PC to IRAF format nshift - find offsets for N images / image sets overlaping a central image nl_findcor - find parameters of nonlinearity correction onisfirst - ONIS/TIFKAM/MOSAIC specific version of first onis0302 - shift & coadd ONIS CNOC MS0302 dither pattern onis1358cn - shift & coadd ONIS CNOC MS1358+62 Center-North dither pattern onis1358s - shift & coadd ONIS CNOC MS1358+62 South dither pattern onis3ew - shift & coadd ONIS CNOC 3-field east-west dither pattern onis6pt - shift & coadd ONIS CNOC 6-point dither pattern osirisfirst - OSIRIS specific version of first photcheck - monitor photometric stability of a data set photcomp - compare photometric properties of two images on same coord sys. photscale - calculate photometric scalings of a data set piscesfirst - Steward Observatory + PISCES 1024^2 specific version of first precoadd - prepare images w/same pixel scales but dif't sizes for coadding qkflat - quick IR flattening routine using all images in a list qksky - quick IR sky-subtraction routine using all images in a list sctv - display image with display scaled to full range of image values sigmanorm - normalize image by the square root of its exposure map subpattern - subtract line-averaged pattern noise tpl - create throughput correction image trim - create constant-rms image with a certain minimum exposure time xlist - generate sublists of files extracted from a main list ./irtfcoadd_1.p0100644000151400000240000000045006427031106012517 0ustar phallgames#!/usr/local/bin/perl -w # cycle thru contents of file(s) given on command line using <> while (<>) { # skip blank lines or lines with # as first non-whitespace character next if (/^\s+$/ or /^#/ or /^\s+#/); ($one, $two) = split " "; $out=$two/($one*$one); print "$out\n"; } ./irtfcoadd.cl0100644000151400000240000014025106663347403012456 0ustar phallgames# ircoadd -- coadd images with sub-pixel shift options and much, much more # # **IRTF version -- imcalc not allowed, so tpl cannot be done** # # Calls addcomment, iterstat, fileroot, filecalc, stsdas.toolbox.imgtools.imcalc # # 950129: created from an unholy union between old ircoadd & dimsum.shiftfix # 950209: added imshifts output # 950214: adjusted zero- & scale- file procedures # 950216: changed procedure for looking for & scaling by # of internal coadds # 950220: streamlined exposure map creation and zero-offset keyword insertion # 950224: removed badmask param so can have dift bpm's for dift input images # 960226: explicit request for logfile name # 960302: fixed bug of not deleting stacked image when requested # 960306: exposure mask now ok w/dift bpmasks, and outputs exact seconds/pixel # 960306: added subpixel shift option # 960314: shortened temporary airmass filenames to ensure IRAF deletion # 960321: added exposure time calculation for stacked image unweighted coadding # 960321: normalize image to actual total exposure time # 960323: added pre-imcombine scaling option # 960325: added pre-imcombine zero offsetting option # 960328: added weightfile option, with default weights=exptime/rms**2 # 960329: fixed exposure map and normalization to work in case of weights # 960330: added default airmass scaling option # 960405: added maskstat option # 960419: changed unzero to be taken from the PREZERO header keyword; added # statfile parameter; and cut out weights mask/iterstat run if done for zeros # 960716: fixed slight error for expmap generation with imcombine scaling # 960807: fixed minor bug of ccomblist2 not existing in expmap creation only # 961130: fixed 2 minor bugs re: intcosca & weighting when stacking # 970322: added listing of readnoise and gain to logfile # 970402: changed expmap -- now sets bad pixels to -99999. # 970425: added check for tpl image # 980812: fixed minor bug of "hedit del+" instead of "hedit del+ add-" # 990217: removed scan of output of "time" task due to problem w/linux # # **should have option of multiplying stacked (exp) image by weird bp images # **should change so it will (re)create magnified bad pixel masks even if # magnified images already exist procedure ircoadd(comblist,outimage,expmap,shiftlist,scaling,zeroing,weighting,magfac,stack,logfile) string comblist {prompt="List of images to combine"} string outimage {prompt="Output coadded image"} string expmap {prompt="Output exposure map image (default=outimage//em)"} string shiftlist {prompt="File with image shifts"} string scaling {prompt="Imcombine scaling (none|@file|!|etc.)"} string zeroing {prompt="Imcombine zero offsets (none|@file|mode|etc.)"} string weighting {prompt="Imcombine weighting (none|@file|!|etc.)"} int magfac {1,min=1,max=10,prompt="Magnification factor for subpixel shifting"} bool stack {prompt="Combine images by stacking & projecting?"} string logfile {prompt="Name of log file"} bool newmask=no {prompt="Override bad pixel masks listed in image headers?"} string badmask {prompt="Bad pixel mask to use instead",mode="q"} bool spshift=no {prompt="Do image shifts account for subpix shifting?",mode="q"} bool prescale=no {prompt="Scale images before, not during, imcombine?",mode="q"} bool unscale=yes {prompt="Undo scaling factors when done?",mode="q"} real extcoeff {prompt="Extinction coefficient for default scalings",mode="q"} real airzero {INDEF,min=0.,max=99.,prompt="Airmass to scale to? (INDEF=min. observed)",mode="q"} bool scalecombine=no {prompt="Combine default & additional scalings?",mode="q"} string morescalename {prompt="@filename or !keyword for additional scalings",mode="q"} bool putscale {prompt="Insert scaling factors into image headers?",mode="q"} string wordscale="SCALEFAC" {prompt="Scaling factor header keyword",mode="q"} bool defscale=no {prompt="Do scales include default airmass scaling?",mode="q"} bool prezero=no {prompt="Do zero offseting before, not during, imcombine?",mode="q"} bool unzero=yes {prompt="Undo zero offsets when done?",mode="q"} bool putzero=no {prompt="Insert zero offsets into image headers?",mode="q"} string wordzero="ZEROVAL" {prompt="Zero offset header keyword",mode="q"} bool putweight=no {prompt="Insert weights into image headers?",mode="q"} string wordweight="WEIGHT" {prompt="Weighting factor header keyword",mode="q"} string stackimage {prompt="Name of stacked image", mode="q"} bool unstack {prompt="Delete stacked image & expmap when done?",mode="q"} bool spscale=no {prompt="Do zero offsets account for subpix shifting?",mode="q"} string expname="EXPTIME" {prompt="Header keyword for exposure time"} bool maskedstat=no {prompt="Use maskstat to find default zeros & wts?"} string statfile="" {prompt="File for image statistics"} bool stdpars=yes {prompt="Use std imcombine parameters for coadd?"} bool makeavg=no {prompt="Make pure coadd (comb=average,rej=none)?"} bool flip=no {prompt="Flip image L-R after coadd?"} bool cleanup=yes {prompt="Clean up new created blkrep'd images after use?"} bool tpl=no {prompt="Account for throughput correction in norm. map?"} bool echog {yes,prompt="Beep when task is done?"} pset imcoaddpars {prompt="Imcombine parameters"} struct *list begin string sshiftfraclist, iinterp, sshiftlist, subimg, explist, sect string ccomblist, bbadmask, sshiftintlist, ooutimage, zzeroing, sstackimage string llogfile, check, zzeroname, sscalefile, sscalename, img, eexpname, blk string s_sigma, s_plfile, s_combine, s_reject, s_offsets, s_masktyp, eexpmap string s_scale, s_weight, s_statsec, s_expname, sscaling, intcosca, expmask string listimshift, wwordscale, wwordzero, subimgold, expmaskold, checkmore string ccomblist1, ccomblist2, sshiftexactlist, image, newbp, newzzeroname string oldbp, bprotlist, file_of_zeros, list_of_zeros, checkscale, checkweight string checkzero, newwweightname, oldzs, newzs, oldwts, newwts, wweightname string file_of_more, mmorescalename, file_of_air, wweighting, wwordweight string file_of_scales, list_of_scales, sstatfile, oextimage, tplimg, tpltmp string tplimgold, s_gain, s_rdnoise real s_maskval, s_blank, s_lthresh, s_hthresh, s_nlow, s_nhigh, s_nkeep, avg, x real s_lsigma, s_hsigma, s_pclip, s_grow, s_sigscale, sig real effairmass, wtavg, nncombine, exp, exposure, sf, zf, testold, eexptime real xold, yold, xnew, ynew, xshift, yshift, sscale, p, b, h, levelzero, wt real wt_avg_exptime, unwt_avg_exptime, eextcoeff, aairzero, air, sfavg, sfmin real sfmax, tmpzero int mag, mag2, j, k, tpl1, tpl2 int xmin, ymin, newx, newy, oldx, oldy, test1, test1old, test2, test2old int sstartno, eendno, i, numpix, num, xdim, ydim, newxsize, newysize, ncoadds bool mmakescalefile, mmakestack, go, mmorehow, pputzero, ddefscale, pputscale bool nnewmask, uunstack, pprescale, uunscale, pputweight, sstack, ttpl bool sspscale, ccleanup, noappend, pprezero, uunzero, sscalecombine, sspshift struct theadline #for zero/scale/weight=* # *ing how to do it # *name filename, if substr(*ing,1,1)==@ # word* header keyword, if substr(*ing,1,1)==! (or @ && pre*=yes) # pre* do zero/scale before imcombine # un* undo zero/scale after imcombine # Set up parameters ccomblist = comblist ccomblist1 = ccomblist fileroot (outimage,validim+) ooutimage = fileroot.root oextimage = fileroot.extension if(oextimage=="")oextimage="imh" fileroot (expmap,validim+) eexpmap = fileroot.root if(eexpmap=="")eexpmap=ooutimage//"em" sshiftexactlist = shiftlist sshiftintlist = sshiftexactlist sscaling = scaling if(sscaling=="")sscaling="none" ddefscale=no aairzero=100. pprescale=no uunscale=no sscalename="_.imag_in_ary_fileJ" checkscale=substr(sscaling,1,1) if(checkscale=="!" || checkscale=="@"){ wwordscale = substr(sscaling,2,strlen(sscaling)) pprescale=prescale if(pprescale)uunscale=unscale if(checkscale=="@"){ sscalename = substr(sscaling,2,strlen(sscaling)) if(!access(sscalename)){ ddefscale=yes eextcoeff=extcoeff aairzero=airzero sscalecombine=scalecombine if(sscalecombine){ mmorescalename=morescalename checkmore=substr(mmorescalename,1,1) while(checkmore!="@" && checkmore!="!"){ print("Additional scales must have format ! or @filename.") mmorescalename=morescalename checkmore=substr(mmorescalename,1,1) } } } pputscale=putscale if(pputscale)wwordscale=wordscale } if(!ddefscale)ddefscale=defscale if(ddefscale && aairzero==100.)aairzero=airzero # if airzero=INDEF and airzero is needed later in the task, airzero=min(airmass) if(aairzero==INDEF && (ddefscale || (pprescale && checkscale=="@" && access(sscalename)))){ print("...one moment please...") file_of_air=mktemp("foa") hsel("@"//ccomblist1,"AIRMASS",yes, >> file_of_air) list=file_of_air aairzero=100. while (fscan (list,air) != EOF) { aairzero=min(air,aairzero) } del(file_of_air,ver-,>&"dev$null") list="" } } zzeroing = zeroing if(zzeroing=="")zzeroing="none" pprezero=no uunzero=no checkzero=substr(zzeroing,1,1) if(checkzero=="!" || checkzero=="@"){ wwordzero = substr(zzeroing,2,strlen(zzeroing)) pprezero=prezero if(pprezero)uunzero=unzero if(checkzero=="@"){ zzeroname = substr(zzeroing,2,strlen(zzeroing)) pputzero=putzero if(pputzero)wwordzero=wordzero } } wweighting = weighting if(wweighting=="")wweighting="none" checkweight=substr(wweighting,1,1) if(checkweight=="!")wwordweight=substr(wweighting,2,strlen(wweighting)) if(checkweight=="@"){ wweightname = substr(wweighting,2,strlen(wweighting)) pputweight=putweight if(pputweight)wwordweight=wordweight } mag = magfac mag2=mag*mag blk = "br"//mag ccomblist2 = ccomblist//blk bprotlist = ccomblist//blk//"pl" sspscale=no sspshift=no if(mag!=1){ if(zzeroing!="none")sspscale=spscale sspshift=spshift } sstack=stack sstackimage="fake_image_oog" if(sstack) { fileroot(stackimage,validim+) sstackimage = fileroot.root uunstack=unstack } llogfile = logfile nnewmask = newmask if(nnewmask)bbadmask = badmask eexpname = expname sstatfile = statfile # if(sstatfile=="")sstatfile=sshiftexactlist//".stats" if(sstatfile=="")sstatfile=ccomblist//".stats" ttpl = tpl ccleanup = cleanup # Check for bad parameter combinations and exit if necessary if(!pprescale && sstack && checkscale=="!"){ print("WARNING! You can't scale during imcombine from a header keyword") print("when stack=yes! (There is only one header for a stacked image.)") print("Use `@file' or prescale=yes instead.") return } if(!pprezero && sstack && checkzero=="!"){ print("WARNING! You can't take the zero offsets from a header keyword") print("when stack=yes! (There is only one header for a stacked image.)") print("Use `@filename' or prezero=yes instead.") return } if(checkweight!="@" && wweighting!="none" && sstack){ print("WARNING! Output image exposure time would have been incorrect.") print("If you want to use weights and stacking, put the weights in a file") print("before running the task; that way the output image exposure time") print("will be correctly calculated.") return } wt_avg_exptime=-1. unwt_avg_exptime=-1. s_sigma = i_sigma # imcombine parameters s_plfile = i_plfile s_combine = i_combine s_reject = i_reject s_masktyp = i_masktyp s_maskval = i_maskval s_blank = i_blank s_statsec = i_statsec s_expname = i_expname s_lthresh = i_lthresh s_hthresh = i_hthresh s_nlow = i_nlow s_nhigh = i_nhigh s_nkeep = i_nkeep s_lsigma = i_lsigma s_hsigma = i_hsigma s_rdnoise = i_rdnoise s_gain = i_gain s_sigscale = i_sigscale s_pclip = i_pclip s_grow = i_grow # Certain tasks/packages must be loaded for task to run. go=yes #if(!defpac("imgtools")) {go=no} if(!deftask("addcomment")) {go=no} if(!deftask("fileroot")) {go=no} #if(!deftask("filecalc")) {go=no} if(!deftask("iterstat")) {go=no} if(go) { # Set up log file, appending if it already exists. if(llogfile == "") llogfile="log."//ooutimage print("", >> llogfile) print("===> PHIIRS.IRCOADD:", >> llogfile) if(mag!=1){ print("===> Input images from "//ccomblist1//" replicated by factor "//mag//" in each direction.", >> llogfile) print("===> Replicated images in "//ccomblist2//" coadded w/offsets from "//sshiftexactlist//blk, >> llogfile) } else { print("===> Images in "//ccomblist1//" coadded w/offsets from "//sshiftexactlist//",", >> llogfile) } print("===> weights="/wweighting//", stdpars="/stdpars//", makeavg="/makeavg//",", >> llogfile) print("===> scales="/sscaling//", zero offsets="/zzeroing//",", >> llogfile) print("===> readnoise="/s_rdnoise//", gain="//s_gain //",", >> llogfile) print("===> pre-scaling="/pprescale//", un-scaling="/uunscale//", pre-zeroing="/pprezero//", un-zeroing="/uunzero//",", >> llogfile) print("===> defscale="/ddefscale//", subpixscale="/sspscale//", subpixshift="/sspshift//",", >> llogfile) print("===> to make image "//ooutimage//" and exposure map "//eexpmap, >> llogfile) # Scale images by NUMBER OF INTERNAL COADDS # If stacking, and image already exists, do not bother if(sstack && (access(sstackimage//".imh") || access(sstackimage//".hhh"))){ print("Not bothering to scale by # of internal coadds; stacked image already exists.") } else { list=ccomblist1 print(" ") print("===) Scaling by the number of internal coadds if necessary...") while (fscan (list, img) !=EOF) { # Check: has this scaling already been done? Look for INTCOSCA header card imgets(img, "intcosca", >& "dev$null") intcosca=str(imgets.value) # If so, nothing is done. # If not, look for the "coadds" header card (from 4m & later first.cl versions) if(intcosca=="0") { imgets(img, "coadds", >& "dev$null") ncoadds=int(imgets.value) # If no "coadds" header card, search for the "ncoadds" header card. It is # usually only found in 'fits256.e' images (ie laird-type), but does not run # the risk of being confused with any other comment cards in the image header, # so it is looked for first. if(ncoadds==0) { imgets(img,"ncoadds", >& "dev$null") ncoadds=int(imgets.value) # If no "ncoadds" header card, get ncoadds from the comment card if(ncoadds==0) { imgets(img,"comment", >& "dev$null") ncoadds=int(substr(imgets.value,strlen(imgets.value),strlen(imgets.value))) } } # Unless ncoadds=1 or 0, multiply through if(ncoadds!=1 && ncoadds!=0) imar(img,"*",ncoadds,img) # Add INTCOSCA header card hedit(img,"INTCOSCA","Internal coadd scaling by factor "//ncoadds//" DONE",add+,ver-,show-,update+) } } } list="" # PRE-SCALING AND DEFAULT SCALING FACTORS FILE CREATION if(pprescale){ # Prevent imcombine from scaling twice sscaling="none" # **DO NOT UNCOMMENT FOLLOWING LINES! unstacking requires that the # list_of_scales file already exists... it must thus be created here. # If stacking, and image already exists, do not bother # if(sstack && (access(sstackimage//".imh") || access(sstackimage//".hhh"))){ # print("Not bothering to pre-scale... stacked image already exists.") # list_of_scales=mktemp("los") # } else { print("===> Multiplying by additional scaling factors...") # In case of scalings taken from header keyword, make file_of_scales if(checkscale=="!"){ file_of_scales=mktemp("fos") hsel("@"//ccomblist1,wwordscale,yes, >> file_of_scales) } # In case of scalings taken from file... if(checkscale=="@"){ # # ...create file of DEFAULT SCALING FACTORS if it doesn't exist... # if(!access(sscalename)){ file_of_air=mktemp("foa") # get airmasses hsel("@"//ccomblist1,"AIRMASS",yes, >> file_of_air) # turn airmasses into scales list=file_of_air while (fscan (list,air) != EOF) { sf=10**(0.4*eextcoeff*(air-aairzero)) print(sf, >> sscalename) } del(file_of_air,ver-) # If combining default scales with other pre-existing scales... if(sscalecombine){ file_of_more=mktemp("fom") if(checkmore=="@"){ copy(substr(mmorescalename,2,strlen(mmorescalename)),file_of_more,ver-) } if(checkmore=="!"){ hsel("@"//ccomblist1,substr(mmorescalename,2,strlen(mmorescalename)),yes, >> file_of_more) } # join files of default and additional scales del("tmp_."//sscalename,ver-,>&"dev$null") join(sscalename,file_of_more,output="tmp_."//sscalename) del(sscalename,ver-,>&"dev$null") del(file_of_more,ver-,>&"dev$null") list="" list="tmp_."//sscalename # create new scales & put into scale file while(fscan (list,air,sf) != EOF) { print(air*sf, >> sscalename) } del("tmp_."//sscalename,ver-,>&"dev$null") } # Finished with creation of default scalings file } list="" file_of_scales=sscalename # End of taking scales from list subroutine } list="" # Allow imcombine to do sigscaling as requested even when pre-scaling if(s_sigscale!=0.){ del ("_avg.file.tmp", ver-, >& "dev$null") type (file_of_scales | average opt="new_sample", >> "_avg.file.tmp") sfavg=average.mean sfmin=1.E20 sfmax=-1.E20 list=file_of_scales while (fscan (list,sf) != EOF) { sfmin=min(sfmin,sf) sfmax=max(sfmax,sf) } if((sfavg-sfmin/sfavg)>=s_sigscale || (sfmax-sfavg/sfavg)>=s_sigscale)s_sigscale=0. del ("_avg.file.tmp", ver-, >& "dev$null") list="" } # Do multiplicative scaling unless it has already been done list_of_scales=mktemp("los") join(ccomblist1,file_of_scales,output=list_of_scales) if(checkscale=="!")del(file_of_scales,ver-) list=list_of_scales while (fscan (list,img,sf) != EOF) { imgets(img,"PRESCALE",>&"dev$null") if(imgets.value=="0"){ imar(img,"*",sf,img,pixt="real",calct="real",ver-) hedit(img,"PRESCALE",sf,add+,ver-,show-,update+,>&"dev$null") if(ddefscale){ imgets(img,"AIRMASS",>&"dev$null") hedit(img,"AIRMOLD",imgets.value,add+,ver-,show-,update+,>&"dev$null") hedit(img,"AIRMASS",aairzero,add+,ver-,show-,update+,>&"dev$null") } } else { print("No action -- image "//img//" already pre-scaled by factor "//imgets.value) } } # } } list="" # put scale factors into image headers if desired if(checkscale=="@"){ if(pputscale){ del("_tmp.sscaling",ver-,>&"dev$null") join(ccomblist1,sscalename,out="_tmp.sscaling") list="_tmp.sscaling" while(fscan (list, img, sf) != EOF) { hedit(img,wwordscale,sf,add+,ver-,show-,update+,>&"dev$null") } del("_tmp.sscaling",ver-,>&"dev$null") } } list="" # DETERMINE ZERO-LEVEL OFFSETS IF NEEDED AND INSERT INTO HEADERS IF DESIRED if(checkzero=="@"){ if(!access(zzeroname)){ print("===) Finding iterative median zero offsets for the images...") del ("_zero.file.tmp?", ver-, >& "dev$null") del ("_avg.file.tmp", ver-, >& "dev$null") # first find iterative median of each image if(!access(sstatfile)){ if(maskedstat){ iterstat.nsigrej=5. iterstat.maxiter=10 maskstat("@"//ccomblist1,"!BPM",1,lower=INDEF,upper=INDEF,iterstat+,ver-,printit+, >> "_zero.file.tmp1") copy("_zero.file.tmp1", sstatfile, ver-) } else { iterstat("@"//ccomblist1,nsigrej=5.,maxiter=10,lower=INDEF,upper=INDEF,print+,ver-, >> "_zero.file.tmp1") copy("_zero.file.tmp1", sstatfile, ver-) } } else { print("Using statistics from "//sstatfile) copy(sstatfile, "_zero.file.tmp1", ver-) } # next find the overall average of the means fields ("_zero.file.tmp1", 5, >> "_zero.file.tmp2") type ("_zero.file.tmp2" | average opt="new_sample", >> "_avg.file.tmp") # now compute the offset of each image from the overall average mean list="_avg.file.tmp" while (fscan (list, avg, sig, num) !=EOF) { lintran("_zero.file.tmp2",min=2,x2=avg,yfield=1,angle=180, >> zzeroname) } del ("_zero.file.tmp?", ver-) del ("_avg.file.tmp", ver-) } # now insert into image headers if desired if(pputzero) { if(access("_tmp.zzeroing"))del("_tmp.zzeroing",ver-) join(ccomblist1,zzeroname,out="_tmp.zzeroing") list="" list="_tmp.zzeroing" while (fscan (list, img, zf) !=EOF) { hedit(img,wwordzero,zf,add+,ver-,show-,update+) } del("_tmp.zzeroing",ver-,>&"dev$null") } } list="" # DETERMINE WEIGHTS IF NEEDED AND ADD TO IMAGE HEADERS IF DESIRED if(checkweight=="@"){ if(!access(wweightname)){ print("===) Creating file of optimal exptime/rms**2 weights for the images...") del ("_weight.file.tmp?", ver-, >& "dev$null") del ("_avg.file.tmp", ver-, >& "dev$null") # first find iterative rms of each image #hsel("@"//ccomblist1,"PRESCALE",yes, >> "_weight.file.tmp9") #count("_weight.file.tmp9") | scan (i,j,k) #if(j!=0){ #beep #print("WARNING! At least one image in "//ccomblist//" was pre-scaled;") #print("thus, the image weights being calculated will be erroneous.") #} if(!access(sstatfile)){ if(maskedstat){ iterstat.nsigrej=5. iterstat.maxiter=10 if(!access("_weight.file.tmp1"))maskstat("@"//ccomblist1,"!BPM",1,lower=INDEF,upper=INDEF,iterstat+,ver-,printit+, >> "_weight.file.tmp1") copy("_weight.file.tmp1", sstatfile, ver-) } else { if(!access("_weight.file.tmp1"))iterstat("@"//ccomblist1,nsigrej=5.,maxiter=10,lower=INDEF,upper=INDEF,print+,ver-, >> "_weight.file.tmp1") copy("_weight.file.tmp1", sstatfile, ver-) } } else { copy (sstatfile, "_weight.file.tmp1", ver-) } fields ("_weight.file.tmp1", 3, >> "_weight.file.tmp2") # get the exptimes for the images hsel("@"//ccomblist1,eexpname,yes, >> "_weight.file.tmp0") join("_weight.file.tmp2","_weight.file.tmp0",out="_weight.file.tmp3") # compute the weights = exptime./(rms**2.) #filecalc ("_weight.file.tmp3", "$2/($1*$1)", calctype="real", >> "_weight.file.tmp4") !/scrs1/pathall/irtfcoadd_1.p _weight.file.tmp3 > _weight.file.tmp4 # find the sum of the weights type ("_weight.file.tmp4" | average opt="new_sample",>> "_avg.file.tmp") # normalize by the sum of the weights #filecalc ("_weight.file.tmp4", "$1/"//average.sum, calctype="real", >> wweightname) !/scrs1/pathall/irtfcoadd_2.p _avg.file.tmp _weight.file.tmp4 > _weight.file.tmp5 rename ("_weight.file.tmp5", wweightname) del ("_weight.file.tmp?", ver-) del ("_avg.file.tmp", ver-) } if(pputweight){ if(access("_tmp.wweighting"))del("_tmp.wweighting",ver-) join(ccomblist1,wweightname,out="_tmp.wweighting") list="_tmp.wweighting" while (fscan (list, img, wt) !=EOF) { hedit(img,wwordweight,wt,add+,ver-,show-,update+) } del("_tmp.wweighting",ver-) } } list="" # SUBPIXEL SHIFTING noappend=no # First expand images if subpixel shifting is desired if (mag!=1){ if(!sspshift)sshiftintlist=sshiftexactlist//blk # If output image list already exists, do not append to it if (access(ccomblist2)){ noappend=yes print("WARNING! Output image list "//ccomblist2//" already exists.") print("Any images listed therein will be created if they do not exist,") print("but no image names will be appended to this preexisting file.") } print("===) Expanding images by factor "//mag//" in both directions...") list=ccomblist1 # Go through image list while (fscan (list, img) !=EOF) { fileroot(img,validim+) image=fileroot.root # Do the magnification as long as the image does not already exist or has not # already been rotated/magnified if(!access(image//blk//"."//fileroot.extension)){ imgets(image,"ROTATED",>&"dev$null") if(imgets.value=="0"){ # Divide by mag squared to conserve total number of counts in input image. imar(image,"/",mag2,"_"//blk//image,pixt="real",calc="real",ver-) blkrep("_"//blk//image,image//blk,mag,mag) imdel("_"//blk//image,ver-) if(!noappend)print (image//blk, >> ccomblist2) # Now replicate the bad pixel mask, if not already done. imgets(image//blk,"BPMASK",>&"dev$null") if(imgets.value=="0")imgets(image//blk,"BPM",>&"dev$null") oldbp=imgets.value newbp=blk//oldbp if(!access(newbp)){ blkrep(oldbp,newbp,mag,mag) print(newbp//".pl", >> bprotlist) } # Insert the replicated bad pixel mask in the image header hedit(image//blk,"BPMASK",newbp,add+,ver-,show-,update+) hedit(image//blk,"BPM",newbp,add+,ver-,show-,update+) } else { # If input image already rotated, only print a warning. print("WARNING! "//image//" already rotated; not rotated again") } } else { # If output image already exists, only print a warning. print("WARNING! "//image//blk//" already exists; not overwritten") } # Next image } # # If output subpixel shifts file doesn't exist, create it if(!access(sshiftintlist)) { print("===> Calculating shifts for expanded images...") if (access("tmp"//sshiftintlist))del("tmp"//sshiftintlist,ver-) list="" list=sshiftexactlist # Convert old shifts to new while (fscan (list,xold,yold) != EOF) { xnew=mag*xold ynew=mag*yold print (xnew, ynew, >> "tmp"//sshiftintlist) } # Round off to integer shifts (in units of new pixels, natch). #filecalc("tmp"//sshiftintlist,"$1;$2",format="%4.0f %4.0f", >> sshiftintlist) del("tmp?.sshiftintlist",ver-) copy ("tmp"//sshiftintlist, "tmp1.sshiftintlist") !/scrs1/pathall/irtfcoadd_3.p tmp1.sshiftintlist > tmp2.sshiftintlist rename ("tmp2.sshiftintlist", sshiftintlist) del("tmp?.sshiftintlist",ver-) del("tmp"//sshiftintlist,ver-) # If output subpixel shifts file does exist, just print warning } else { if(sshiftintlist==sshiftexactlist//blk)print("WARNING! "//sshiftintlist//" already exists; not overwritten") } # Correction of zero offsets for lower flux/pixel in blkrep'd images, if needed if(!sspscale) { # Zero offsets from list if(checkzero=="@") { if(!access(zzeroname//blk)) { #filecalc(zzeroname,"$1/"//mag2,format="%9.7f", >> zzeroname//blk) del ("_tmpmag2", ver-, >& "dev$null") del ("_zzeroname*", ver-, >& "dev$null") print (mag2, >> "_tmpmag2") copy (zzeroname, "_zzeroname", ver-) !/scrs1/pathall/irtfcoadd_4.p _tmpmag2 _zzeroname > _zzeronameblk rename ("_zzeronameblk", zzeroname//blk) del ("_zzeroname*", ver-, >& "dev$null") del ("_tmpmag2", ver-, >& "dev$null") newzzeroname=zzeroname//blk zzeroname=newzzeroname zzeroing="@"//newzzeroname } } # Zero offsets from header keyword if(checkzero=="!"){ oldzs=mktemp("oz") newzs=mktemp("nz") hsel("@"//ccomblist1,wwordzero,yes, >> oldzs) #filecalc(oldzs,"$1/"//mag2,format="%9.7f", >> newzs) del ("_???zs", ver-, >& "dev$null") del ("_tmpmag2", ver-, >& "dev$null") print (mag2, >> "_tmpmag2") copy (oldzs, "_oldzs", ver-) !/scrs1/pathall/irtfcoadd_4.p _tmpmag2 _oldzs > _newzs rename ("_newzs", newzs, ver-) del ("_???zs", ver-, >& "dev$null") del ("_tmpmag2", ver-, >& "dev$null") join(ccomblist2,oldzs,output=newzs) list="" list=newzs while (fscan (list,img,levelzero) != EOF) { hedit(img,wwordzero,levelzero,add+,ver-,show-,update+) } del(oldzs,ver-) del(newzs,ver-) } } # End of subpixel shift option } list="" # INSERT NEW ZERO OFFSETS INTO REPLICATED IMAGE HEADERS IF DESIRED. if(access(ccomblist2) && checkzero=="@"){ if(pputzero) { if(!sspscale && access(zzeroname//blk))zzeroname=zzeroname//blk del("_tmp.zzeroing",ver-,>&"dev$null") join(ccomblist2,zzeroname,out="_tmp.zzeroing") list="_tmp.zzeroing" while (fscan (list, img, zf) !=EOF) { hedit(img,wwordzero,zf,add+,ver-,show-,update+) } del("_tmp.zzeroing",ver-,>&"dev$null") } } list="" # PRE-ZEROING: INCORPORATE ZERO OFFSETS BEFORE IMCOMBINE IF DESIRED if(pprezero){ print("===> Doing zero offsetting prior to imcombine...") # Prevent imcombine from zeroing twice zzeroing="none" # If list of images to coadd doesn't exist, create it! if (!access(ccomblist2))copy(ccomblist1,ccomblist2,ver-) # In case of zero offsets taken from header keyword, make file_of_zeros if(checkzero=="!"){ file_of_zeros=mktemp("foz") hsel("@"//ccomblist2,wwordzero,yes, >> file_of_zeros) } if(checkzero=="@")file_of_zeros=zzeroname list_of_zeros=mktemp("loz") join(ccomblist2,file_of_zeros,output=list_of_zeros) if(checkzero=="!")del(file_of_zeros,ver-) # If stacking, and image already exists, do not bother if(sstack && (access(sstackimage//".imh") || access(sstackimage//".hhh"))){ print("Not bothering to pre-zero... stacked image already exists.") } else { # Do zero offsetting unless it has already been done list=list_of_zeros while (fscan (list,img,levelzero) != EOF) { imgets(img,"PREZERO",>&"dev$null") if(imgets.value=="0"){ imar(img,"+",levelzero,img,pixt="real",calc="real",ver-) hedit(img,"PREZERO",levelzero,add+,ve-,sho-,updat+,>&"dev$null") } else { print("No action -- image "//img//" already zero-offset by "//imgets.value) } } } } list="" # COADD images # If output coadded image doesn't exist, create it! if (!access(ooutimage//"."//oextimage)){ # If list of images to coadd doesn't exist, create it! if (!access(ccomblist2))copy(ccomblist1,ccomblist2,ver-) if (sstack){ # If output stacked image doesn't exist, create it! if (!access(sstackimage//"."//oextimage)){ print("===) Stacking the images...") imstack("@"//ccomblist2,sstackimage,title="Stacked images listed in "//ccomblist2) } if(nnewmask) { hedit(sstackimage,"BPM",bbadmask,add+,ver-,show-,update+) hedit(sstackimage,"BPMASK",bbadmask,add+,ver-,show-,update+) } print("===) Combining the images...") if (makeavg){ imcombine(sstackimage, ooutimage, sigma=s_sigma, plfile=s_plfile, combine="average", reject="none", project+, offsets=sshiftintlist, masktype=s_masktyp, maskvalue=s_maskval, blank=s_blank, scale=sscaling, zero=zzeroing, weight=wweighting, statsec=s_statsec, expname=s_expname, lthresh=s_lthresh, hthresh=s_hthresh, nlow=s_nlow, nhigh=s_nhigh, nkeep=s_nkeep, mclip+, lsigma=s_lsigma, hsigma=s_hsigma, rdnoise=s_rdnoise, gain=s_gain, sigscale=s_sigscale, pclip=s_pclip, grow=s_grow, logfile='STDOUT', >> llogfile) } else{ if (stdpars) { imcombine(sstackimage, ooutimage, sigma="", plfile="", combine="average", reject="sigclip", project+, offsets=sshiftintlist, masktype=s_masktyp, maskvalue=s_maskval, blank=0., scale=sscaling, zero=zzeroing, weight=wweighting, statsec="", expname=eexpname, lthresh=-100000., hthresh=100000, nlow=1., nhigh=1., nkeep=1., mclip+, lsigma=5., hsigma=5., rdnoise=s_rdnoise, gain=s_gain, sigscale=s_sigscale, pclip=-0.5, grow=0., logfile='STDOUT', >> llogfile) } else { imcombine(sstackimage, ooutimage, sigma=s_sigma, plfile=s_plfile, combine=s_combine, reject=s_reject, project+, offsets=sshiftintlist, masktype=s_masktyp, maskvalue=s_maskval, blank=s_blank, scale=sscaling, zero=zzeroing, weight=wweighting, statsec=s_statsec, expname=s_expname, lthresh=s_lthresh, hthresh=s_hthresh, nlow=s_nlow, nhigh=s_nhigh, nkeep=s_nkeep, mclip+, lsigma=s_lsigma, hsigma=s_hsigma, rdnoise=s_rdnoise, gain=s_gain, sigscale=s_sigscale, pclip=s_pclip, grow=s_grow, logfile='STDOUT', >> llogfile) } } # Stacked images only: compute correct UNWEIGHTED average exposure time del("tmp_"//ccomblist2,ver-,>&"dev$null") hsel ("@"//ccomblist2,eexpname,yes, >> "tmp_"//ccomblist2) type ("tmp_"//ccomblist2) | average (opt="new_sample") | scan (eexptime,p,b) hedit(ooutimage,eexpname,eexptime,add+,ver-,show-,update+) del("tmp_"//ccomblist2,ver-,>&"dev$null") # if(uunstack)imdel(sstackimage,ver-) } else{ if(nnewmask) { list=ccomblist2 while (fscan (list, img) !=EOF) { imgets(img,"BPMASK",>&"dev$null") if(imgets.value=="0") { imgets(img,"BPM",>&"dev$null") hedit(img,"BPMASK",imgets.value,add+,ver-,show-,update+) hedit(img,"BPM",bbadmask,add+,ver-,show-,update+) } else { hedit(img,"BPM",bbadmask,add+,ver-,show-,update+) } } } print("===) Combining the images...") if (makeavg){ imcombine("@"//ccomblist2, ooutimage, sigma=s_sigma, plfile=s_plfile, combine="average", reject="none", project-, offsets=sshiftintlist, masktype=s_masktyp, maskvalue=s_maskval, blank=s_blank, scale=sscaling, zero=zzeroing, weight=wweighting, statsec=s_statsec, expname=s_expname, lthresh=s_lthresh, hthresh=s_hthresh, nlow=s_nlow, nhigh=s_nhigh, nkeep=s_nkeep, mclip+, lsigma=s_lsigma, hsigma=s_hsigma, rdnoise=s_rdnoise, gain=s_gain, sigscale=s_sigscale, pclip=s_pclip, grow=s_grow, logfile='STDOUT', >> llogfile) } else{ if (stdpars) { imcombine("@"//ccomblist2, ooutimage, sigma="", plfile="", combine="average", reject="sigclip", project-, offsets=sshiftintlist, masktype=s_masktyp, maskvalue=s_maskval, blank=0., scale=sscaling, zero=zzeroing, weight=wweighting, statsec="", expname=eexpname, lthresh=-100000., hthresh=100000, nlow=1., nhigh=1., nkeep=1., mclip+, lsigma=5., hsigma=5., rdnoise=s_rdnoise, gain=s_gain, sigscale=0.1, pclip=-0.5, grow=0., logfile='STDOUT', >> llogfile) } else { imcombine("@"//ccomblist2, ooutimage, sigma=s_sigma, plfile=s_plfile, combine=s_combine, reject=s_reject, project-, offsets=sshiftintlist, masktype=s_masktyp, maskvalue=s_maskval, blank=s_blank, scale=sscaling, zero=zzeroing, weight=wweighting, statsec=s_statsec, expname=s_expname, lthresh=s_lthresh, hthresh=s_hthresh, nlow=s_nlow, nhigh=s_nhigh, nkeep=s_nkeep, mclip+, lsigma=s_lsigma, hsigma=s_hsigma, rdnoise=s_rdnoise, gain=s_gain, sigscale=s_sigscale, pclip=s_pclip, grow=s_grow, logfile='STDOUT', >> llogfile) } } } list="" # Put original BPM back if necessary if(nnewmask) { list=ccomblist2 while (fscan (list, img) !=EOF) { imgets(img,"BPMASK",>&"dev$null") hedit(img,"BPM",imgets.value,add+,ver-,show-,update+) } } list="" # Header parameters for the coadded image hedit(ooutimage,"title","Coadded image from "//ccomblist2//" and "//sshiftintlist,ver-,show-,update+) #time | scan (theadline) del ("_6oogDaTe", ver-, >& "dev$null") !date > _6oogDaTe type ("_6oogDaTe") | scan (theadline) del ("_6oogDaTe", ver-, >& "dev$null") addcomment (ooutimage,"phiirs.ircoadd: "//theadline,ver-) addcomment(ooutimage,"Coadded from "//ccomblist2//" and "//sshiftintlist,ver-) addcomment(ooutimage,"makeavg="/makeavg//", stpars="/stdpars//", zero="//zzeroing,ver-) addcomment(ooutimage,"scale="/sscaling//", and weight="//wweighting,ver-) # AIRMASS # Set airmass of coadded image to effective airmass if default scaling !used if(!ddefscale){ del("_airmass.tmp?",ver-,>&"dev$null") hsel("@"//ccomblist2, "airmass", yes, >> "_airmass.tmp1") type("_airmass.tmp1" | average opt="new_sample", >> "_airmass.tmp2") effairmass=real(average.mean) hedit(ooutimage,"airmass",(effairmass),add+,ver-,show-,update+) del("_airmass.tmp?",ver-,>&"dev$null") # Set airmass of coadded image to reference airmass if default scaling was used } else { hedit(ooutimage,"airmass",(aairzero),add+,ver-,show-,update+) } # EXPOSURE NORMALIZATION -- normalize coadded image to total exposure time. # If weighting was done w/a stacked image, first find correct WEIGHTED exptime del ("_exptime.tmp?", ver-, >& "dev$null") if(sstack && wweighting!="none"){ # First get individual image exposure times del ("_exptime.tmp?", ver-, >& "dev$null") hsel("@"//ccomblist2,eexpname,yes, >> "_exptime.tmp1") # Join individual image exptimes with weights join("_exptime.tmp1", wweightname, output="_exptime.tmp3") # Calculate individual image weighted exposure times #filecalc ("_exptime.tmp3", "$1*$2", calctype="real", >> "_exptime.tmp4") !/scrs1/pathall/irtfcoadd_5.p _exptime.tmp3 > _exptime.tmp4 # Calculate correct weighted exposure time type ("_exptime.tmp4" | average opt="new_sample",>> "_exptime.tmp5") # Insert correct weighted exposure time into image header hedit(ooutimage,eexpname,average.sum,add+,ver-,show-,update+) } # First find total exposure time of input images hsel("@"//ccomblist2,eexpname,yes, >> "_exptime.tmp6") type("_exptime.tmp6" | average opt="new_sample", >> "_exptime.tmp7") del ("_exptime.tmp?", ver-, >& "dev$null") unwt_avg_exptime=real(average.mean) eexptime=real(average.sum) # Get output exposure time of coadded image imgets(ooutimage,eexpname) wt_avg_exptime=real(imgets.value) # Insert total exposure time into coadded image header hedit(ooutimage,eexpname,eexptime,add+,ver-,show-,update+) # Multiply coadded image by (total_exposure_time/output_exposure_time) imar(ooutimage, "*", eexptime/wt_avg_exptime, ooutimage) print("", >> llogfile) print("Coadded image multiplied by "//eexptime/wt_avg_exptime//" to bring its flux", >> llogfile) print("in line with the total exposure time of "//eexptime//" s.", >> llogfile) # FLIP image over to correct orientation if necessary (N is up, E is left) if(flip){ imcopy(ooutimage//"[-*,*]", ooutimage, ver-) addcomment(ooutimage,"Image has been flipped L-R from orig. orientation",ver-) print("WARNING! Image has been flipped L-R! (i.e. imcopy orig[-*,*] new)") } } else { print("Output coadded image already exists-- coadding not done.") print("Output coadded image already exists-- coadding not done.", >> llogfile) } # UNDO PRE-ZEROING: if zeroing was done before imcombine, undo it if desired if(pprezero && uunzero){ # If block-replication was done, skip step if those images are to be deleted if(mag!=1 && ccleanup && !noappend){ print("", >> llogfile) } else { print("===> Undoing zero offsetting...") list=list_of_zeros while (fscan (list,img,levelzero) != EOF) { imgets(img,"PREZERO",>&"dev$null") if(imgets.value!="0"){ tmpzero=real(imgets.value) imar(img,"-",tmpzero,img,pixt="real",calc="real",ver-) hedit(img,"PREZERO","",add-,del+,ver-,show-,updat+,>&"dev$null") } else { print("No action -- "//img//" not pre-zeroed in the first place!") } } } } if(pprezero){ if(sstack && access(sstackimage//"."//oextimage)){print("", >> llogfile)} else{del(list_of_zeros,ver-,>&"dev$null")} } list="" # UNDO PRE-SCALING: if scaling was done before imcombine, undo it if desired if(pprescale && uunscale){ # If block-replication was done, skip step if those images are to be deleted if(mag!=1 && ccleanup && !noappend){ print("", >> llogfile) } else { print("===> Undoing scaling factors...") list=list_of_scales while (fscan (list,img,sf) != EOF) { imgets(img,"PREZERO",>&"dev$null") if(imgets.value!="0"){ print("WARNING! "//img//" still pre-scaled: pre-zeroing not undone first") } else { imgets(img,"PRESCALE",>&"dev$null") if(imgets.value!="0"){ imar(img,"/",sf,img,pixt="real",calct="real",ver-) hedit(img,"PRESCALE","",add-,del+,ver-,sho-,updat+,>&"dev$null") if(ddefscale){ imgets(img,"AIRMOLD",>&"dev$null") hedit(img,"AIRMASS",imgets.value,add+,del-,ver-,sho-,updat+,>&"dev$null") hedit(img,"AIRMOLD","",add-,del+,ver-,sho-,updat+,>&"dev$null") } } else { print("No action -- "//img//" not pre-scaled in the first place!") } } } } } if(pprescale)del(list_of_scales,ver-,>&"dev$null") list="" # EXPOSURE MAPS # Create exposure maps if the output coadded-image exposure map does not exist. # Routine allows for images of different exposure times, sizes, and BPMs, while # creating as few images as possible consistent with meeting those criteria. explist="" if(!access(eexpmap//"."//oextimage)){ # Don't recreate exposure maps to be stacked if stacked expmap image exists if (!access(ccomblist2))copy(ccomblist1,ccomblist2,ver-) if(!sstack || (sstack && !access("exp"//sstackimage//"."//oextimage))) { print("===) Creating exposure maps...") subimgold="_oops" testold=0. test1old=0 test2old=0 expmaskold="" tplimgold="" # If list of images to coadd doesn't exist, create it! # if (!access(ccomblist2))copy(ccomblist1,ccomblist2,ver-) list=ccomblist2 explist=ccomblist2//"exp" if(access(explist))del(explist,ver-,>&"dev$null") while (fscan (list, img) !=EOF) { # get image parameters: xsize, ysize, exptime, badpixelmask fileroot(img,validim+) imgets(img,"i_naxis1") test1=int(imgets.value) imgets(img,"i_naxis2") test2=int(imgets.value) imgets(img,eexpname) exposure=real(imgets.value) imgets(img,"BPMASK") expmask=str(imgets.value) imgets(img,"TPLIMG",>&"dev$null") tplimg=str(imgets.value) # if any of those parameters differ from the previous image, need to create a # new exposure map for eventual coadding. if(test1!=test1old || test2!=test2old || exposure!=testold || expmask!=expmaskold || tplimg!=tplimgold) { subimg = mktemp(fileroot.root) print (subimg, >> explist) # tpl if(ttpl && access(tplimg)) { tpltmp=mktemp("tpltmp") imgets(tplimg,"i_naxis1") tpl1=int(imgets.value) imgets(tplimg,"i_naxis2") tpl2=int(imgets.value) # if tpl image is not same size as actual image, assume the image has been # copied to subsection of bigger image starting at (1,1), and that the rest of # the image is -99999 (thus no imar(img,"-",img,subimg) needed. (ie 61"+90") if(tpl1!=test1 || tpl2!=test2) { imcopy(img,subimg,ver-) imcalc(tplimg, tpltmp, str(exposure)//"/im1**2.", ver-) imcopy(tpltmp, subimg//"[1:"//str(tpl1)//",1:"//str(tpl2)//"]", ver-) imdel(tpltmp, ver-) } else { imcalc(img//","//tplimg,subimg,"(im1-im1)+"//str(exposure)//"/im2**2.",ver-) } # no tpl } else { imcopy(img,subimg,ver-) imreplace(subimg,exposure,lower=-10000.,upper=INDEF) } if(nnewmask)hedit(subimg,"BPM",bbadmask,add+,ver-,show-,update+) test1old=test1 test2old=test2 tplimgold=tplimg testold=exposure expmaskold=expmask subimgold=subimg } else { print (subimgold, >> explist) } } } # Create coadded-image exposure map print("===> Creating coadded-image exposure map...") if(sstack) { if(!access("exp"//sstackimage//"."//oextimage)) { print("===> Stacking exposure maps...") imstack("@"//explist,"exp"//sstackimage,title="Stacked exposure maps listed in "//explist) } else { print("Stacked exposure map image already exists-- not overwritten.") } if(nnewmask) { hedit("exp"//sstackimage,"BPM",bbadmask,add+,ver-,show-,update+) } imcombine("exp"//sstackimage, "junk"//eexpmap, sigma="", plfile=eexpmap//"pl", combine="average", reject="none", project+, offsets=sshiftintlist, masktype=s_masktyp, maskvalue=s_maskval, blank=s_blank, scale="none", zero="none", weight=wweighting, statsec=s_statsec, expname=s_expname, lthresh=s_lthresh, hthresh=s_hthresh, nlow=s_nlow, nhigh=s_nhigh, nkeep=s_nkeep, mclip+, lsigma=s_lsigma, hsigma=s_hsigma, rdnoise=s_rdnoise, gain=s_gain, sigscale=s_sigscale, pclip=s_pclip, grow=s_grow, logfile='STDOUT', >> llogfile) if(uunstack)imdel("exp"//sstackimage,ver-) } else { imcombine("@"//explist, "junk"//eexpmap, sigma="", plfile=eexpmap//"pl", combine="average", reject="none", project-, offsets=sshiftintlist, masktype=s_masktyp, maskvalue=s_maskval, blank=s_blank, scale=sscaling, zero="none", weight=wweighting, statsec=s_statsec, expname=s_expname, lthresh=s_lthresh, hthresh=s_hthresh, nlow=s_nlow, nhigh=s_nhigh, nkeep=s_nkeep, mclip+, lsigma=s_lsigma, hsigma=s_hsigma, rdnoise=s_rdnoise, gain=s_gain, sigscale=s_sigscale, pclip=s_pclip, grow=s_grow, logfile='STDOUT', >> llogfile) } imgets("junk"//eexpmap,"ncombine") nncombine=int(imgets.value) if(explist!=""){ imdel("@"//explist, ver-, >& "dev$null") del(explist, ver-, >& "dev$null") } # Find some numbers needed for accurate exposure map calculation # If unweighted average exposure time has not been calculated, calculate it del ("_exptime.tmp?", ver-, >& "dev$null") if(unwt_avg_exptime==-1.){ hsel("@"//ccomblist2,eexpname,yes, >> "_exptime.tmp6") type("_exptime.tmp6" | average opt="new_sample", >> "_exptime.tmp7") unwt_avg_exptime=real(average.mean) } # If weighting was used... if(wweighting!="none"){ # ...and the weighted avg. exposure time was not found earlier... if(wt_avg_exptime==-1.){ # ...then find it. First get individual image exposure times. del ("_exptime.tmp?", ver-, >& "dev$null") hsel("@"//ccomblist2,eexpname,yes, >> "_exptime.tmp1") # Take weights from header keyword... if(checkweight=="!"){ hsel("@"//ccomblist2,wwordweight,yes, >> "_exptime.tmp2") } # ...or specified file... if(checkweight=="@"){ copy(wweightname, "_exptime.tmp2", ver-) } # ...or use default=exptime with a warning... if(checkweight!="@" && checkweight!="!"){ beep print("WARNING! Using default weights = exptime for exposure map.") print("For accuracy with weighting="/wweighting//", you will need") print("to create the exposure map at the same time as the coadded image.") hsel("@"//ccomblist2,eexpname,yes, >> "_exptime.tmp2") } # Join individual image exptimes with weights join("_exptime.tmp1", "_exptime.tmp2", output="_exptime.tmp3") # Calculate individual image weighted exposure times #filecalc ("_exptime.tmp3", "$1*$2", calctype="real", >> "_exptime.tmp4") !/scrs1/pathall/irtfcoadd_5.p _exptime.tmp3 > _exptime.tmp4 # Calculate correct weighted exposure time type ("_exptime.tmp4" | average opt="new_sample",>> "_exptime.tmp5") wt_avg_exptime=average.sum } # If weighting was not used, weighted avg. exptime is same as avg. exptime } else { wt_avg_exptime=unwt_avg_exptime } del ("_exptime.tmp?", ver-, >& "dev$null") # Following should yield accurate exposure map. To get the actual exposure # time at each pixel, we must multiply the image from the above imcombining, # which gives the average exposure time (in seconds) at each pixel, by the # plfile, which gives the number of images used at each pixel, and by the # overall unweighted exptime divided by the overall weighted exptime. # # Step 1: just to be safe, get rid of any possible negative values imreplace(eexpmap//"pl",0.,lower=INDEF,upper=0.) # Step 2: Since the plfile lists # images *not* used, we subtract total # images if(access(eexpmap//"number."//oextimage))imdel(eexpmap//"number."//oextimage,ver-) imar(eexpmap//"pl","-",nncombine,eexpmap//"number."//oextimage) # Step 3: Then multiplying by -1 gives # of images used (positive quantity) imar(eexpmap//"number."//oextimage,"*",-1.,eexpmap//"number."//oextimage) # Step 4: Then multiplying by the (weighted) average number of seconds at each # pixel, times the overall **unweighted** average number of seconds, # divided by the overall **weighted** average number of seconds, gives # the desired total number of seconds at each pixel. imar(eexpmap//"number."//oextimage,"*","junk"//eexpmap,eexpmap) imar(eexpmap//"."//oextimage,"*",unwt_avg_exptime/wt_avg_exptime,eexpmap//"."//oextimage) imdel(eexpmap//"pl.pl",ver-) imdel("junk"//eexpmap, ver-, >& "dev$null") imdel(eexpmap//"number."//oextimage, ver-, >& "dev$null") hedit(eexpmap,"title","Exposure map image for coadded image "//ooutimage,ver-,show-,update+) if(flip){ imcopy(eexpmap//"[-*,*]", eexpmap, ver-) addcomment(eexpmap,"Image has been flipped L-R from orig. orientation",ver-) } } else{ print("Output exposure map already exists-- new one not created.") print("Output exposure map already exists-- new one not created.", >> llogfile) } # IMSHIFTS FILE # Create *.imshifts file, listing images & offsets used by masklet & photcheck if (!access(ooutimage//".imshifts")) { print("===> Creating output imshifts file...") if (!access(ccomblist2))copy(ccomblist1,ccomblist2,ver-) join(ccomblist2,sshiftintlist,output=ooutimage//".imshifts_tmp") # Find minimum x and y shift values and subtract them from output offsets listimshift=ooutimage//".imshifts_tmp" list="" list=listimshift xmin=100000 ymin=100000 while (fscan (list,img,newx,newy) != EOF) { if (newx < xmin) { xmin = newx } if (newy < ymin) { ymin = newy } } newx=0 newy=0 list="" list=listimshift while (fscan (list,img,oldx,oldy) != EOF) { newx = oldx - xmin newy = oldy - ymin print(img, " ", newx, newy, >> ooutimage//".imshifts") } del(ooutimage//".imshifts_tmp",ver-) } else { print("Output imshifts file already exists-- not overwritten.") print(" ") } # Clean up. if(mag!=1){ if(ccleanup && !noappend){ if(access(bprotlist)){ imdel("@"//bprotlist,ver-,>&"dev$null") del(bprotlist,ver-,>&"dev$null") } if(access(ccomblist2))imdel("@"//ccomblist2,ver-,>&"dev$null") del(ccomblist2,ver-,>&"dev$null") del(sshiftexactlist//blk,ver-,>&"dev$null") del(zzeroname//blk,ver-,>&"dev$null") } } else { del(ccomblist2,ver-,>&"dev$null") } print(ooutimage//", exposure map, and imshifts file have been created.") print("Next task is `mkobjmask' or `photcheck'.") } else { print("WARNING: tasks addcomment, fileroot, and/or iterstat aren't loaded!") print("Please load the appropriate package(s) and restart this task.") } list="" print(" ") if(echog)beep end ./root.hd0100644000151400000240000000011506502624075011464 0ustar phallgames# Root help directory for Pat Hall's IRAF package _phiirs pkg = _phiirs.hd ./photcheck.cl0100644000151400000240000002732106743170132012461 0ustar phallgames# photcheck -- monitor photometric stability of a data set. # # The user first identifies several suitable objects in a mosaiced image using # imexam. These objects should be located on a portion of the mosaic with # nearly maximum exposure time, so that they will appear in most or all of # the individual input frames. Photcheck then takes that input position list, # transforms it back to the coordinate systems of the individual sky subtracted # images which were summed to make the mosaic, and uses digiphot.apphot.phot to # compute accurate positions and measure magnitudes for the reference objects # in each sky subtracted input frame. # # If the user sets badcheck=yes, then each image's bad pixel mask is consulted, # and if any bad pixels are within the photometric aperture, phot will return # an INDEF value for the magnitude. Finally, the output files from phot are # compiled using awk into a format suitable for input to "photscale", which # allows interactive calculation of photometric scalings for the data set. # # The default output uses the mosaic image as the reference photometric image. # If another image is desired as a reference, that can be done in `photscale'. # # This routine requires: minv, fileroot, photcheck.awk; and that awk be # defined in the user package as a foreign task, i.e. task $awk = $foreign. # # 930803: originally created 2-3 Aug 1993 by Mark Dickinson # 960321: modified to include interactive identification of ref. stars, etc. # 960326: include editing of imshifts file, and check for overlong image names # 960409: changed _badpix.imh to unique filename, & removed duplicate creation # 960410: fixed bad pixel image bug # 960418: allowed for flipping of coadded image # 960420: removed dephot option in favor of editing PHOT parameter set # 960716: allow for multiple phot apertures by retrieving only mag[1] & merr[1] # 980511: fixed minor bug where "ext" could be called on w/o being defined # 990225: minor change to calling of "phot" # 990513: use imcalc now instead of imar # 990714: intermediate file for awk to work on more platforms procedure photcheck(image,expmap,photcoords,output) string image {prompt="Mosaic image"} string expmap {prompt="Exposure map image"} string photcoords {prompt="File for reference star coordinates"} string output {prompt="File for formatted output photometry"} string imageshifts="" {prompt="`imshifts' file (default = image//.imshifts)"} bool flipped {no, prompt="Was coadded image flipped during ircoadd?"} bool interact {yes, prompt="Identify reference stars interactively?"} bool ephot {yes, prompt="Edit PHOT parameter sets before beginning?"} bool badcheck {yes, prompt="Check for bad pixels and return INDEF values?"} bool verbose {yes, prompt="Verbose output?"} bool cleanup {yes, prompt="Erase individual photometry files when done?"} bool echog {yes,prompt="Beep when task is done?"} struct *imglist begin string mimg,photc,outp # Equal query parameters int oxdim,oydim # Dimensions of mosaic image int ix, iy # Coordinate offsets of input images string img # Fscanned name of image string ext # extension of image (imh, hhh, etc.) string starshift # File for translated star coordinates string workimage # Copy of image for use with phot. real xstar, ystar # Star coordinates real temp # swap variable string photlist # temporary dump file string phiirsdir # pathname of PHIIRS source code directory real flagval # large flag value -- set to 1.e9 string mexp, bpmold, bpmnew, imagelist, s1, imgroot, morig, tempbp string old_exposure, old_gain, old_ccdread, old_apertures, old_filter real old_epadu, old_readnoise, old_annulus, old_dannulus, old_zmag real old_scale int x, y, z bool iinteract, eephot, fflipped flagval = -1.e9 # Check to make sure digiphot.apphot is loaded. if (!defpac("apphot") || !defpac("imgtools")) { beep print ("Please load digiphot.apphot and/or stsdas.imgtools before using this routine.") return } # Check for presence of the photcheck.awk script in the PHIIRS source # code directory. If that file is not present, return error message. phiirsdir = osfn("phiirs$") if (!access(phiirsdir//"photcheck.awk")) { beep print ("ERROR: Cannot access "//phiirsdir//"$photcheck.awk") return } # Check for presence tasks needed to run script if (!deftask("minv") || !deftask("fileroot")) { beep print ("ERROR: tasks `minv' and/or `fileroot' are not loaded.") print ("Please load them and restart task.") return } # Get query parameters. fileroot(image,validim+) mimg = fileroot.root morig = mimg mexp = expmap if(mexp=="")mexp=mimg//"em" photc = photcoords if(photc=="")photc=mimg//".photcoords" outp = output if(outp=="")outp=mimg//".photcheck" if (access(outp)) { beep print ("ERROR: File "//outp//" already exists. Choose another output name.") return } imagelist = imageshifts if(imagelist=="")imagelist=mimg//".imshifts" fflipped = flipped if(fflipped){ if(access(mimg//"_F.imh"))imdel(mimg//"_F", ver-) if(access(mimg//"_F.hhh"))imdel(mimg//"_F", ver-) imcopy(mimg//"[-*,*]", mimg//"_F", ver-) mimg=mimg//"_F" if(strlen(mimg)>=22){ print("WARNING! Image name "//mimg//" is too long!") print("Image names can't be longer than 21 characters.") print("Please rename image(s) and restart the task.") return } } ext="" # Check to make sure no image names are more than 21 characters long imglist=imagelist while (fscan(imglist,img,ix,iy) != EOF) { if(strlen(img)>=22){ beep print("WARNING! Image name "//img//" is too long! Image names as listed in") print(imagelist//" can be no longer than 21 characters.") print("Please rename image(s) and restart the task.") return } } imglist="" iinteract = interact eephot = ephot if(!eephot)print("PHOT task parameter sets will not be edited.") # Display mosaic image for reference star identification, if desired if(iinteract){ print("===> The mosaic image and exposure map are being displayed. Identify") print("===> several objects suitable for photometry in the mosaic image,") print("===> preferably ones located on parts of the mosaic with nearly") print("===> maximum exposure time, and get their coords (type 'a').") print("") print("===> When done, the coordinate file can be edited in case mistakes were made.") print("===> When using preexisting coordinate file, this temporary file will be blank.") print("") print("===> Finally, the imshifts file will be displayed for editing. Be sure the") print("===> listed images were the actual ones coadded to produce the mosaic.") if(fflipped){display(mexp//"[-*,*]",2)} else{display(mexp,2)} display(mimg,1) imexam(logfile="tmp"//photc, keep+) vi("tmp"//photc) vi(imagelist) # Output reference star x and y values to desired file if(fflipped)print("# WARNING! Coordinates are for "//morig//"[-*,*]",>>photc) fields("tmp"//photc,"1-2",lines="1-99999",>>photc) del("tmp"//photc,ver-) } # Get dimensions of mosaic image. imgets(mimg,"i_naxis1") oxdim=int(imgets.value) imgets(mimg,"i_naxis2") oydim=int(imgets.value) # If bad pixel checking is turned on, delete temporary files if present. if (badcheck) { # datapars.datamin is set to trigger 'INDEF' results for any object which has # a bad pixel within the aperture. If badcheck=no, then leave datamin = INDEF. datapars.datamin = 0.95 * flagval } else { datapars.datamin = INDEF } # If desired, set up default values for important PHOT parameters if(eephot){ epar("datapars") epar("fitskypars") epar("photpars") } # Create temporary file for phot output filenames. photlist = mktemp ("photcheck") # First, do photometry on stars in the mosaic image to act as reference values. if (verbose) print ("Measuring reference magnitudes from ",morig) if(access(morig//".mag.X")){ #del(morig//".mag.X",ver-) print("WARNING! "//morig//".mag.X already exists! Not overwritten.") } else { phot (mimg,skyfile="",datapars="",centerpars="",fitskypars="",photpars="",coords=photc,output=morig//".mag.X",inter-,verify-,verbose-) } # Record photometry output file name in temporary file photlist. print (morig//".mag.X", >photlist) # Next, loop through the individual images. bpmold="" bpmnew="" imglist=imagelist while (fscan(imglist,img,ix,iy) != EOF) { fileroot(img,validim+) if (badcheck) { workimage = "_"//img imgroot="_"//fileroot.root } else { workimage = img imgroot=fileroot.root } # If photometry files already exist, do not re-create them if(access(imgroot//".mag.X")){ print("WARNING! "//imgroot//".mag.X already exists! Not overwritten.") } else { # If photometry files do not exist, create them. Used to rename bad pixel mask # to *.imh, thus giving it datatype=real to allow large flag values used later, # but now I just use 1.e9 as the large flag value, which works for *.pl images. if (verbose) print ("Working on image ",img) if (badcheck) { imgets (img,"BPMASK") bpmnew=imgets.value fileroot(bpmnew,validim+) tempbp=fileroot.root ext=fileroot.extension if(ext!="")ext="."//ext ## Only create new bad pixel mask if image BPM is different than previous image # if(tempbp!=bpmold){ # imdel ("_badp"//bpmold//ext,ver-,>&"dev$null") # imdel ("_newp"//bpmold//ext,ver-,>&"dev$null") # imdel ("_badp"//tempbp//ext,ver-,>&"dev$null") # imdel ("_newp"//tempbp//ext,ver-,>&"dev$null") # imcopy (tempbp,"_badp"//tempbp//ext,ver-) # minv("_badp"//tempbp//ext,"_newp"//tempbp//ext) # imar("_newp"//tempbp//ext,"*",flagval,"_newp"//tempbp//ext,ver-) # } ## Copy image and set bad pixels to a large, negative flag value. # imar(img,"*","_badp"//tempbp//ext,"_"//img,ver-,noact-) # imar("_"//img,"-","_newp"//tempbp//ext,"_"//img,ver-) # bpmold=tempbp # Set bad pixels to a large, negative flag value. imcalc(img//","//tempbp, "_"//img, "if im1 .eq. 0 then "//flagval//" else im1", nullval=flagval, ver-) } # Apply translation to star coordinate file. starshift = mktemp("photcheck") lintran (photc,xf=1,yf=2,x1=ix,y1=iy,x2=0.,y2=0.,xsc=1.,ysc=1.,angle=0,min_sig=4,radians=no,>>starshift) # Do photometry on star list. Output goes to file named imgroot//.mag.X phot (workimage,skyfile="",datapars="",centerpars="",fitskypars="",photpars="",coords=starshift,output=imgroot//".mag.X",inter-,verify-,verbose-) # End of photometry file creation loop. Clean up. delete (starshift,ver-) if (badcheck) { imdelete ("_"//img,ver-) } } # Record photometry output file name in temporary file photlist. print (imgroot//".mag.X",>>photlist) # Next image } imdelete ("_badp"//bpmnew//ext,ver-,>&"dev$null") imdelete ("_newp"//bpmnew//ext,ver-,>&"dev$null") # Dump photometric records to output photometry file & format using awk scripts #txdump ("@"//photlist,"image,xairmass,mag[1],merr[1]","yes",headers+,parameters-) | awk ("-f",phiirsdir//"photcheck.awk",> outp) del ("_tmpoutp", ver-, >& "dev$null") txdump ("@"//photlist,"image,xairmass,mag[1],merr[1]","yes",headers+,parameters-, >> "_tmpoutp") awk ("-f", phiirsdir//"photcheck.awk", "_tmpoutp", > outp) print ("", >> outp) if (verbose) { print ("") print ("Output data written to file "//outp//"; now, if desired,") print ("replace the first line in it with the desired reference") print ("photometry values, and then use it as input to task photscale") print ("to compute and plot photometric offsets between frames.") } # Clean up. if(fflipped) imdelete (mimg,ver-) imdelete ("_badp*"//ext,ver-,>&"dev$null") imdelete ("_newp*"//ext,ver-,>&"dev$null") if(cleanup){ delete ("@"//photlist,ver-) delete (photlist,ver-) delete ("_tmpoutp", ver-) } else { if(!access(morig//photlist)){ if(!access(morig//".photlist"))rename(photlist,morig//".photlist") print("Output photometry files are listed in "//morig//".photlist") } else { print("Output photometry files are listed in "//photlist) } } imglist = "" if(echog)beep end ./piscesfirst.cl0100644000151400000240000002402207254743534013054 0ustar phallgames# piscesfirst.cl -- subtract dark & add header params to PISCES images # # 1. subtract dark # 2. hedit image headers, adding: # 1. BPM,BPMASK = bad pixel mask name # 2. GAIN,RDNOISE if not present (currently assumes 8, 25.) # 3. time-obs = copy of 'time' (UT time of observation) # 4. obs-date = date-obs but in dd/mm/yy format # 5. ut = time-obs (or time-obs + 7) # 6. date-obs = yyyy-mm-dd format (old date-obs saved as dateorig) # (following are optional) # 7. epoch, ra, dec = entered as parameters, if desired # 8. st = sidereal time, calculated from ut & date using astutil.asttimes # & the observatory parameter (kpno, mtbigelow, mmto, ctio) # 9. airmass = calculated from epoch, ra, dec, st, and obs-date # # 980414: added compatibility to incoming date-obs in new-millenium format and # output of date-obs in same format (valid for data from 1990 to 2089); # original date-obs is output as dateorig # 981228: added check for dateorig -- if it exists, date-obs etc. not redone # 990112: created from first.cl and modified for Don McCarthy's array # 990219: edited setairmass.intype and inserted "datetmp" header card # 990223: added addition of "coadds" header parameter (always assumed = 1) # 990309: checks for blank OBJECT keyword and replaces it with "blank" # 990320: fixed bug where exptime & itime were feedbacking on each other # 990419: existing gain & rdnoise not overwritten, + minor bug fixed # 990426: epoch,ra,dec made optional again; copy SECZ keyword to AIRMASS # 990427: DARKSUB keyword added to darksubbed images, not original ones # # **bug: airmass+ airauto+ option assumes you're observing from MST time zone! # ...but that's only for the "asttimes" task, which may be irrelevant # **should be more options for computing ut than just time-obs or time-obs+7h procedure piscesfirst(imagelist,darksub,badmask) string imagelist {prompt="List of images to process (do not use an `@')"} bool darksub=no {prompt="Subtract off dark frame?"} string badmask {prompt="Name of bad pixel mask to add to image header"} string dark {prompt="Name of the dark frame to subtract", mode="q"} string darkstring {prompt="String to append to dark-subtracted images",mode="q"} bool coords=yes {prompt="Add RA, DEC, and EPOCH to image header?"} bool airmass=yes {prompt="Enter airmass into image header?"} bool airauto=yes {prompt="Find airmass of image automatically?"} real airval {prompt="Airmass of image", mode="q"} string epoch {prompt="Epoch of coordinates"} string ra {prompt="Right Ascension (surround with quotes)"} string dec {prompt="Declination (surround w/quotes; use - but not +"} string observatory {"kpno",prompt="Observatory where observations were made"} bool ut=yes {prompt="Is 'time' in header ut or not?"} bool ddmmyy=yes {prompt="Is 'date' in day/month/year format?"} bool echog=yes {prompt="Beep when task is done?"} struct *list begin string ddark, ddarkstring, bbadmask, check, base, iimagelist, ext string darklist, flat, flatbase, meanfile, currentflat, tempflat, name string editlist, current, obsdate, rra, ddec, eepoch, oobservatory, minsec string obstime, timeobs, dateobs, century real intime, aairval, ttime, mean, meanbad, x int ncoadd, ddy, hhr, hhour, mmonth, yyear, dday, uttime, last2digits bool ddarksub, ccoords, aairauto, uut, aairmass iimagelist = imagelist list = iimagelist editlist = iimagelist ddarksub = darksub if (ddarksub) { ddark = dark ddarkstring = darkstring darklist = iimagelist//ddarkstring } bbadmask = badmask ccoords = coords aairmass = airmass if (aairmass) { aairauto = airauto # if(!aairauto)aairval = airval if(!defpac("astutil")) { beep print ("WARNING!! Package ''astutil'' is not loaded; cannot set airmass in images.") print ("Load the package and rerun the task.") return } } if (coords) { eepoch = epoch rra = ra ddec = dec } oobservatory = observatory uut = ut # Add BPM and other goodies to the image headers, just like in the hadd.cl task print("===> Adding various parameters to the image headers...") list = iimagelist while (fscan (list, current) !=EOF) { hedit(current,"datetmp",("(@'date')"),add+,ver-,show-,updat+) hedit(current,"BPM",bbadmask,add+,ver-,show+,updat+) hedit(current,"BPMASK",bbadmask,add+,ver-,show+,updat+) imgets(current,"SECZ", >& "dev$null") if (imgets.value!="0" || imgets.value!="") { hedit(current,"AIRMASS",real(imgets.value),add+,ver-,show+,updat+) # hedit(current,"AIRMASS",("(@'SECZ')"),add+,ver-,show+,updat+) } imgets(current,"OBJECT", >& "dev$null") if (imgets.value=="0" || imgets.value=="") { hedit(current,"OBJECT","blank",add+,ver-,show+,updat+) } # Currently assumes gain=8, rdnoise=25, and only 1 coadd per image imgets(current,"GAIN", >& "dev$null") if (imgets.value=="0" || imgets.value=="") { hedit(current,"GAIN","8.",add+,ver-,show+,updat+) } imgets(current,"RDNOISE", >& "dev$null") if (imgets.value=="0" || imgets.value=="") { hedit(current,"RDNOISE","25.",add+,ver-,show+,updat+) } hedit(current,"coadds",1.,add+,ver-,show+,updat+) # No 'date-obs' keyword, only 'date', in format "dd/mm/yy". # Create new 'date-obs' keyword in the new format "yyyy-mm-dd". imgets(current,"dateorig", >& "dev$null") if (imgets.value!="0") { print ("DATEORIG keyword already exists -- *first already run on image?") } else { hedit(current,"time-obs",("(@'time')"),add+,ver-,show+,updat+) imgets(current,"datetmp") # Copy original 'date' keyword to 'dateorig' in original format. hedit(current,"dateorig",imgets.value,add+,ver-,show+,updat+) hedit(current,"datetmp","",add-,del+,ver-,show-,updat+) # Create header keyword 'obs-date', always in "dd/mm/yy" format. if(!ddmmyy){ # mm/dd/yy format: if(substr(imgets.value,3,3)=="/") { obsdate=substr(imgets.value,4,6)//substr(imgets.value,1,3)//substr(imgets.value,7,8) } else { # yyyy-mm-dd format: # 1234567890 obsdate=substr(imgets.value,9,10)//"/"//substr(imgets.value,6,7)//"/"//substr(imgets.value,3,4) } # create obs-date if date-obs in mm/dd/yy or yyyy-mm-dd format: hedit(current,"obs-date",obsdate,add+,ver-,show+,updat+) } else { # create obs-date if date-obs in dd/mm/yy format: hedit(current,"obs-date",imgets.value,add+,ver-,show+,updat+) } # Create new 'date-obs' in new format "yyyy-mm-dd" from 'obs-date' "dd/mm/yy" # 12345678 imgets(current,"obs-date") if ((substr(imgets.value,7,7))=="9") { century=19 } else { century=20 } dateobs=century//substr(imgets.value,7,8)//"-"//substr(imgets.value,4,5)//"-"//substr(imgets.value,1,2) hedit(current,"date-obs",dateobs,add+,ver-,show+,updat+) # # Sometimes the time in the image header is ut, sometimes not. # so this option lets you choose either ut or mst if(uut){hedit(current,"ut",("(@'time-obs')"),add+,ver-,show+,updat+)} else{ imgets(current,"time-obs") obstime=substr(imgets.value,1,2) uttime=int(obstime)+7 if(uttime>=24){uttime=uttime-24} if(uttime<=9){timeobs="0"//str(uttime)//substr(imgets.value,3,8)} if(uttime>=10){timeobs=str(uttime)//substr(imgets.value,3,8)} #need to hedit ut twice cause is not in hh:mm:ss format 1st time around hedit(current,"ut",timeobs,add+,ver-,show+,updat+) hedit(current,"ut",timeobs,add+,ver-,show+,updat+) } } } if(ccoords){ list = iimagelist while (fscan (list, current) !=EOF) { hedit(current,"epoch",eepoch,add+,ver-,show+,updat+) hedit(current,"ra",rra,add+,ver-,show-,updat+) hedit(current,"ra",rra,add+,ver-,show+,updat+) hedit(current,"dec",ddec,add+,ver-,show-,updat+) hedit(current,"dec",ddec,add+,ver-,show+,updat+) #hedit test ra "(str('21:51:59.0'))" add+ ver- show- } } if(aairmass){ if(aairauto){ list = iimagelist while (fscan (list, current) !=EOF) { imgets(current,"obs-date") dday=int(substr(imgets.value,1,2)) mmonth=int(substr(imgets.value,4,5)) # yyear=int("19"//substr(imgets.value,7,8)) last2digits=int(substr(imgets.value,7,8)) if(last2digits <= 80) { yyear=int("20"//substr(imgets.value,7,8)) } else { yyear=int("19"//substr(imgets.value,7,8)) } imgets(current,"ut") hhr=int(substr(imgets.value,1,2)) minsec=substr(imgets.value,3,8) hhour=hhr-7 if(hhour<0){ dday=dday-1 hhour=hhour+24. } if(dday<=0){ mmonth=mmonth-1 # this will not always be totally accurate, and may fail for feb., but hey. dday=30 } # observing on new year's eve will require a new correction! ttime=real(str(int(hhour))//minsec) asttimes(observatory=oobservatory, year=yyear, month=mmonth, day=dday, time=ttime) hedit(current,"st",asttimes.lmst,add+,ver-,show-,updat+) hedit(current,"st",asttimes.lmst,add+,ver-,show+,updat+) setairmass(current, observatory=oobservatory, intype="end", outtype="effective", date="obs-date",exposure="exptime", utmiddle="utmiddle", show+, updat+, override+) } } else { list = iimagelist while (fscan (list, current) !=EOF) { print("Setting airmass for image "//current) hedit(current,"airmass",airval,add+,ver-,show+,updat+) } } } # Subtract off Dark Current if (ddarksub) { list = iimagelist # if darklist doesn't exist, assume dsub imgs don't either; create it & dsubs if(!access(darklist)) { print("===> Subtracting off Dark Current...") while (fscan (list, name) !=EOF) { fileroot(name,validim+) base=fileroot.root ext=fileroot.extension if(ext!="")ext="."//ext print(base//ddarkstring//ext, >> darklist) imgets(name,"DARKSUB",>&"dev$null") if (imgets.value=="0") { imarith(name, "-", ddark, base//ddarkstring//ext, verbose-) hedit(base//ddarkstring//ext,"DARKSUB",ddark,add+,ver-,show+,update+) } else { print("DARKSUB keyword exists; piscesfirst already run? "//name//" just copied") imcopy(name, base//ddarkstring//ext, verbose-) } } } else { print("Darksubbed image list "//darklist//" already exists; images assumed to exist too.") } #imarith("@"//iimagelist, "-", ddark, "@"//darklist, verbose-) #hedit("@"//darklist,"DARKSUB",ddark,add+,ver-,show+,update+) print(" ") print("===> Dark-subtracted images are listed in the file "//darklist//".") } if(echog)beep end ./qkflat.cl0100644000151400000240000004102607254220105011763 0ustar phallgames# qkflat.cl -- quick IR flattening routine using all images in a list # # This task creates a flat from all images in the input list and flattens # the images in the list with it. # # The task should be run in the directory which contains the raw images *.### # listed in imagelist. This script does not change the original images. # Previously a bad pixel image (mask) should have been produced. # # darksub=no: # imagelist: input # flatlist: imagelist or imagelist * bpmask if zeroout+ # flatmakelist: imagelist / avg(flatlist) # imcom @flatmakelist flat # flatimagelist: imagelist / flat # darksub=yes: # imagelist: input # flatimagelist: imagelist - dark # flatlist: flatimagelist or flatimagelist * bpmask if zeroout+ # flatmakelist: flatimagelist / avg(flatlist) # imcom @flatmakelist flat # flatimagelist: flatimagelist / flat # # CHANGES: # 940729: images used in creating the flat are normalized to their # average sky level before the flat is made... seems like this should # have been a bug in earlier flats... problem w/older imcombine? # 940912: speeded things up # 940917: added compatibility with iraf version 2.10, in which ccdclip in # imcombine doesn't work; and added stacking capability for making flat. # 981230: fixed minor bug which showed up when image extension was "fits" # 990115: added option to just make the flat and not apply it to the images # 990217: added option to use iterstat; this slows things down if used but # produces a slightly better flat # 990218: added mkflat option, fixing prob of nondeletion of flatbase to boot # 990225: fixed darksub+ bug; moved zeroout+ from all output images to just flat # (+ divzero=0. during flat division); don't subtract dark if already done # and do iterstat such that results propagate through to the final images # 990306: add DARKSUB header card after dark subtraction # 990317: added tpl option # 990419: minor bug in flat normalization fixed ... no big effect # 990506: added ZEROOUT keyword creation # 990523: set scale="none" during (im)combine step # 010315: changed "access" to "imaccess" in mkflat check procedure qkflat(rootname,imagelist,flatstring,fextension,logfile,darksub,dark,badmask,zeroout,badpix) string rootname {prompt="Rootname for flatfield image"} string imagelist {prompt="List of images to process (do not use an `@')"} string flatstring {"fq",prompt="String to be appended to flattened images"} string fextension {"fq",prompt="Extension to be added to the flatfield image"} string logfile {prompt="Name of log file"} bool darksub=no {prompt="Subtract Dark frame? (yes|no)"} string dark="" {prompt="Name of the Dark frame to use"} string badmask="" {prompt="Name of the Bad Pixel Mask to use"} bool zeroout=no {prompt="Zero out bad pixels on final images? (yes|no)"} bool badpix=no {prompt="Add bad pixel mask name to image header? (yes|no)"} bool mkflat=no {prompt="Make flatfield image even if it already exists?"} bool iterstat=yes {prompt="Use iterative means when constructing flats?"} bool doflat=yes {prompt="Use the flatfield to create flattened images?"} bool tpl=no {prompt="Throughput-correct images after flatfielding?"} string tplname {prompt="FULL Name of throughput correction image"} bool v210=no {prompt="Older version of IRAF w/imcombine bug? (yes|no)"} pset imflatpars {prompt="Imcombine parameters"} bool echog=yes {prompt="Beep when task is done?"} struct *list struct *list2 struct *datelist struct *meanlist begin string s_sigma, s_combine, s_reject, s_offsets, s_masktyp, s_gain, s_rdnoise string s_scale, s_zero, s_weight, s_statsec, s_expname, templist, postdsimage string rrootname, ddark, llogfile, bbadmask, eextension, ffextension, predsimage string flatlist, flat, flatbase, meanfile, currentflat, tempflat, origimage string iimagelist, flatimagelist, fflatstr, flatmakelist, flatjoinlist, newflat string datefile, thedate, ickinfo, name, base, check, tempstring, otherstring string ttplname real mean, meaner, meanest, meanbad, x, y, z real s_maskval, s_blank, s_lthresh, s_hthresh, s_nlow, s_nhigh, s_nkeep real s_lsigma, s_hsigma, s_pclip, s_grow int sstartno, eendno, i, j, numpix bool ddarksub, zzeroout, bbadpix, go, ddoflat, iter_stat, mmkflat, ttpl rrootname = rootname iimagelist = imagelist list = iimagelist fflatstr = flatstring ffextension = fextension llogfile = logfile ddarksub = darksub ddark = dark bbadmask = badmask zzeroout = zeroout bbadpix = badpix mmkflat = mkflat iter_stat = iterstat ddoflat = doflat ttpl = tpl if (ttpl) ttplname=tplname s_sigma = i_sigma s_combine = i_combine s_reject = i_reject s_offsets = i_offsets s_masktyp = i_masktyp s_maskval = i_maskval s_blank = i_blank s_scale = i_scale s_zero = i_zero s_weight = i_weight s_statsec = i_statsec s_expname = i_expname s_lthresh = i_lthresh s_hthresh = i_hthresh s_nlow = i_nlow s_nhigh = i_nhigh s_nkeep = i_nkeep s_lsigma = i_lsigma s_hsigma = i_hsigma s_rdnoise = i_rdnoise s_gain = i_gain s_pclip = i_pclip s_grow = i_grow # Set up log file, printing warning if it already exists # The "go" parameter won't let the task run if you're using "combine" # instead of "imcombine" and haven't loaded the ccdred package. go=yes if(!defpac("ccdred") && v210) {go=no} if(go) { print("Let the games begin...") if(llogfile == "") llogfile=rrootname//".log" if(access(llogfile)) print("Log file `"//llogfile//"' already exists... will append to it.") print(" ",>>llogfile);print("PHIIRS.QKFLAT-------------------------",>>llogfile) # Set up files flat = rrootname//"."//ffextension # the final flat field image flatimagelist = iimagelist//fflatstr # @file for flattened images flatmakelist = "listmake."//rrootname//fflatstr # @file for making the flat flatjoinlist = "listjoin."//rrootname//fflatstr # @file for making the flat flatlist = mktemp("flatlist") # @file for temp flat files flatbase = mktemp("flat") # temp flat files base name if(access(flatimagelist)) delete(flatimagelist,ver-) if(access(flatmakelist)) delete(flatmakelist,ver-) while (fscan (list, name) !=EOF) { fileroot(name,validim+) check=fileroot.extension if(check!="")check="."//check base=fileroot.root print(base//fflatstr//check, >> flatimagelist) print(base//fflatstr//check, >> flatmakelist) print(flatbase//base//fflatstr//check, >> flatlist) } # Make flat, if desired if (mmkflat || !imaccess(flat)) { print ("===> Making flat...") if (imaccess(flat)) imdel (flat, ver-) print("File "//flatlist//" contains the following filenames:", >> llogfile) type(flatlist, >> llogfile); print(" ", >> llogfile) print("File "//flatimagelist//" contains the following filenames:", >> llogfile) type(flatimagelist, >> llogfile); print(" ", >> llogfile) # Add the BPM to the image header if(bbadpix){ hedit("@"//iimagelist,"BPM",bbadmask,add+,ver-,show-,update+) } # If desired, subtract off Dark Current in both flatlist and flatimagelist if (ddarksub) { print("===> Subtract off Dark Current") print("===> Subtract off Dark Current", >> llogfile) join (iimagelist, flatimagelist, out=flatjoinlist) list = flatjoinlist while (fscan (list, predsimage, postdsimage) !=EOF) { imgets(predsimage,"darksub",>&"dev$null") if(imgets.value=="0"){ imarith (predsimage,"-",ddark,postdsimage,ver-,noact-) hedit(postdsimage,"DARKSUB",ddark,add+,ver-,sho+,updat+) print(predsimage//" - "//ddark//" "//postdsimage, >> llogfile) } else { imcopy (predsimage, postdsimage, ver-) print (predsimage//" already darksubtracted; just copied to "//postdsimage, >> llogfile) print (predsimage//" already darksubtracted; just copied to "//postdsimage) } } delete(flatjoinlist,ver-) print(" ", >> llogfile) # Zero out the Bad Pixels in flatlist if (zzeroout) { print("===> Zero out the Bad Pixels before making the flat") print("===> Zero out the Bad Pixels before making flat", >> llogfile) imarith("@"//flatimagelist,"*",bbadmask,"@"//flatlist,verbose-) hedit("@"//flatlist,"ZEROOUT",bbadmask,del-,add+,ver-,sho-,upd+) print("IMARITH: @"//flatimagelist//" * "//bbadmask//" @"//flatlist, >> llogfile) print(" ", >> llogfile) } else { imcopy("@"//flatimagelist, "@"//flatlist, verbose-) print("IMCOPY: @"//flatimagelist//" @"//flatlist, >> llogfile) } # No dark subtraction } else { if (zzeroout) { print("===> Zero out the Bad Pixels before making the flat") print("===> Zero out the Bad Pixels before making flat", >> llogfile) imarith("@"//iimagelist, "*", bbadmask, "@"//flatlist, verbose-) hedit("@"//flatlist,"ZEROOUT",bbadmask,del-,ad+,ve-,sho-,upd+) print("IMARITH: @"//iimagelist//" * "//bbadmask//" @"//flatlist, >> llogfile) print(" ", >> llogfile) } else { print("===> Copying to temporary images") imcopy("@"//iimagelist, "@"//flatlist, verbose-) print("IMCOPY: @"//iimagelist//" @"//flatlist, >> llogfile) } } # Normalize each image in flatimagelist/flatmakelist by the bad-pixel-corrected # (and possibly iterative) mean of its corresponding image in flatlist, and to # the average bad-pixel-corrected (and possibly iterative) mean of all images # in flatlist. (Images in flatimagelist are original or dark-subtracted; # images in flatlist are original or dark-subtracted and/or bad-pixel-zeroed.) meanlist="" print(" ", >> llogfile); print("===> Normalize each image by its mean (accounting for bad pixels)", >> llogfile) print("===> Normalize each image by its mean (accounting for bad pixels)") if(iter_stat){ if (ddarksub) { join (flatimagelist, flatlist, out=flatjoinlist) } else { join (iimagelist, flatlist, out=flatjoinlist) } list = flatjoinlist while (fscan (list, origimage, currentflat) !=EOF) { imgets(currentflat,"itermean",>&"dev$null") if(imgets.value=="0"){ iterstat(currentflat, nsigrej=5., maxiter=10., print+, ver-, addh+, lower=0.0000001, upper=INDEF, >> llogfile) hedit(currentflat,"itermean",iterstat.mean,add+,ver-,sho-,upd+) } } delete(flatjoinlist,ver-) hsel("@"//flatlist, "itermean", yes) | average >> "tempffile" } else { imstat("@"//flatlist, lower=0.0000001, >> llogfile) imstat("@"//flatlist, fields="mean", lower=0.0000001, format=no) | average >> "tempffile" } meaner = average.mean del ("tempffile", ver-); print(" ", >> llogfile) if (ddarksub) { join (flatimagelist, flatmakelist, out=flatjoinlist) } else { join (iimagelist, flatmakelist, out=flatjoinlist) } list = flatjoinlist while (fscan (list, tempflat, currentflat) !=EOF) { meanfile = mktemp("mean") meanlist = meanfile if(iter_stat){ hsel(flatbase//currentflat, "itermean", yes, >> meanfile) } else { imstat(flatbase//currentflat, fields="mean", format=no, lower=0.0000001, >> meanfile) } j=fscan(meanlist, mean) meanest = mean / meaner imarith(tempflat, "/", meanest, currentflat, verbose-) print("IMARITH: "//currentflat//" / "//meanest//" "//currentflat,>>llogfile) meanlist = "" delete(meanfile,ver-) } delete(flatjoinlist,ver-) imdel("@"//flatlist, ver-) # Combine all images to make the flat print(" ", >> llogfile) print("===> Combine all images to make the flat") print("===> Combine all images to make the flat", >> llogfile) # If there are 100 or more images to combine, stack the images first. count(flatmakelist, >> "temp.count.thang") templist="temp.count.thang" list2=templist while (fscan (list2, y, z, tempstring, otherstring) !=EOF) { if(y>=100) { if(v210) { imstack("@"//flatmakelist, "stack."//flat) combine("stack."//flat, flat, project+, sigma=s_sigma, delete-, clobber-, combine=s_combine, reject=s_reject, outtype="real", offsets=s_offsets, masktype=s_masktyp, maskvalue=s_maskval, blank=s_blank, scale="none", zero=s_zero, weight=s_weight, statsec=s_statsec, lthresh=s_lthresh, hthresh=s_hthresh, nlow=s_nlow, nhigh=s_nhigh, nkeep=s_nkeep, mclip+, lsigma=s_lsigma, hsigma=s_hsigma, rdnoise=s_rdnoise, gain=s_gain, pclip=s_pclip, grow=s_grow) imdel("stack."//flat, ver-) } else { imstack("@"//flatmakelist, "stack."//flat) imcombine("stack."//flat, flat, project+, sigma=s_sigma, combine=s_combine, reject=s_reject, offsets=s_offsets, masktype=s_masktyp, maskvalue=s_maskval, blank=s_blank, scale="none", zero=s_zero, weight=s_weight, statsec=s_statsec, expname=s_expname, lthresh=s_lthresh, hthresh=s_hthresh, nlow=s_nlow, nhigh=s_nhigh, nkeep=s_nkeep, mclip+, lsigma=s_lsigma, hsigma=s_hsigma, rdnoise=s_rdnoise, gain=s_gain, pclip=s_pclip, grow=s_grow, logfile='STDOUT', >> llogfile) imdel("stack."//flat, ver-) } } else { if(v210) { combine("@"//flatmakelist, flat, sigma=s_sigma, delete-, clobber-, combine=s_combine, reject=s_reject, outtype="real", offsets=s_offsets, masktype=s_masktyp, maskvalue=s_maskval, blank=s_blank, scale="none", zero=s_zero, weight=s_weight, statsec=s_statsec, lthresh=s_lthresh, hthresh=s_hthresh, nlow=s_nlow, nhigh=s_nhigh, nkeep=s_nkeep, mclip+, lsigma=s_lsigma, hsigma=s_hsigma, rdnoise=s_rdnoise, gain=s_gain, pclip=s_pclip, grow=s_grow) } else { imcombine("@"//flatmakelist, flat, sigma=s_sigma, combine=s_combine, reject=s_reject, offsets=s_offsets, masktype=s_masktyp, maskvalue=s_maskval, blank=s_blank, scale="none", zero=s_zero, weight=s_weight, statsec=s_statsec, expname=s_expname, lthresh=s_lthresh, hthresh=s_hthresh, nlow=s_nlow, nhigh=s_nhigh, nkeep=s_nkeep, mclip+, lsigma=s_lsigma, hsigma=s_hsigma, rdnoise=s_rdnoise, gain=s_gain, pclip=s_pclip, grow=s_grow, logfile='STDOUT',>> llogfile) } } } del("temp.count.thang", ver-) hedit(flat, "title", "Flatfield created from "//iimagelist, ver-, show-, update+) if (!ddarksub) imdel("@"//flatmakelist, ver-) # Divide flat by its mean value, accounting for bad pixels meanfile = mktemp("mean") meanlist = meanfile tempflat = flat//"cameldung" imarith(flat, "*", bbadmask, tempflat, verbose-) if(iter_stat){ iterstat(tempflat, nsigrej=5, maxiter=10, print+, ver-, addh+, lower=0.0000001, upper=INDEF, >> llogfile) hsel(tempflat, "itermean", yes, >> meanfile) } else { print(" ",>>llogfile);imstat(tempflat,>>llogfile);print(" ",>>llogfile) imstat(tempflat, fields="mean", format=no, lower=0.0000001, >> meanfile) } j=fscan(meanlist, mean) imarith(flat, "/", mean, flat, verbose-) print("IMARITH: "//flat//" / "//mean//" "//flat, >> llogfile) print(" ", >>llogfile) meanlist = "" delete(meanfile, ver-) imdelete(tempflat, ver-) # Zero out Bad Pixels if desired if (zzeroout) { print("===> Zero out bad pixels on flat") print("===> Zero out bad pixels on flat", >> llogfile) imar(flat,"*",bbadmask,flat,ver-) print("IMARITH: "//flat//" * "//bbadmask//" "//flat, >> llogfile) hedit(flat,"ZEROOUT",bbadmask,del-,ad+,ve-,sho-,upd+) print(" ", >> llogfile) } else { print("===> Bad pixel zeroing not done", >> llogfile) } # End of mkflat+ portion } else { print("===> "//flat//" already exists -- not recreated -- continuing...") print(flat//" already exists -- not recreated",>>llogfile);print(" ",>>llogfile) } # Divide All Images by the Flat Field if(ddoflat){ print("===> Correct All Images for Flat Field") print("===> Correct All Images for Flat Field", >> llogfile) if (ddarksub) { imar("@"//flatimagelist,"/",flat,"@"//flatimagelist,ver-,noact-,divzero=0.) print("IMARITH: @"//flatimagelist//" / "//flat//" @"//flatimagelist,>>llogfile) } else { imar("@"//iimagelist,"/",flat,"@"//flatimagelist,ver-,noact-,divzero=0.) print("IMARITH: @"//iimagelist//" / "//flat//" @"//flatimagelist,>>llogfile) } print(" ", >> llogfile) # Do throughput correction if desired. if (ttpl) { print("===> Divide by Throughput Correction") print("===> Divide by Throughput Correction", >> llogfile) list = flatimagelist while (fscan (list, name) !=EOF) { imgets(name,"tplimg",>&"dev$null") if(imgets.value=="0"){ imar(name, "/", ttplname, name, ver-) hedit(name,fields="TPL",value="TPL correction made using image"//ttplname,add+,ver-,up+,sho-) hedit(name,fields="TPLIMG",value=ttplname,add+,ver-,up+,sho-) print(name//" / "//ttplname//" "//name, >> llogfile) } else { print(name//" already throughput-corrected using "//imgets.value, >> llogfile) print(name//" already throughput-corrected using "//imgets.value) } } } # Force updating of pixel values, just to be safe print("===> Update pixel values") minmax("@"//flatimagelist, force+, update+, verbose-) } else { print("===> Flat fielding of images not done", >> llogfile) } print("===> Mopping Up...") del(flatlist, ver-, >& "dev$null"); del(flatmakelist, ver-, >& "dev$null") del(flatbase, ver-, >& "dev$null") datefile = mktemp("date") date(>>datefile) datelist = datefile print("finished at "//datelist, >> llogfile) datelist = "" del(datefile, ver-) print("...it is accomplished.") } else { beep print("WARNING: package noao.imred.ccdred is not loaded!") print("Please load that package and restart this task.") } if(echog)beep end ./qksky.cl0100644000151400000240000003220207026340602011641 0ustar phallgames# qksky.cl -- quick IR sky-subtraction routine using all images in a list # # This task creates a sky image from a list of flattened images # and subtracts it from them. # # This task should be run in the directory which contains the flattened images # listed in imagelist. This script does not change those input images. # Previously a bad pixel image (mask) should have been produced. # The products of this routine are: # --dark corrected, sky-subtracted, bad pixel zeroed frames: *.###substring.imh # --a file (list.substring//rootname) which contains the names of those images # --a sky image called rootname.sextension.imh # --and the logfile. # # CHANGES: # 940907: added parameter set for imcombine used to make the sky, as well as # option to use standard parameters for both object and std.star images # 990217: added option to use iterstat; this slows things down if used but # produces a much better subtraction (note stdpars+ means iterstat-) # 990218: added mksky & dosky options # 990307: added addsky options # 990320: added subpattern option # 990406: fixed bugs of attempted double subtraction, and incorrect scaling, # plus changed ITERMEAN to ITERMED in scaling of sky image before subtraction # 990506: added ZEROOUT keyword creation # 991216: added check for ITERMED keyword and creation if absent procedure qksky(rootname,imagelist,logfile,substring,sextension,stdpars,stdstar,zeroout,maskname,tpl,tplname) string rootname {prompt="Rootname for sky image"} string imagelist {prompt="List of images to process (do not use an `@')"} string logfile {prompt="Name of log file"} string substring {"sq",prompt="String to be appended to sky-subtracted images"} string sextension {"sq",prompt="Extension to be added to the sky image"} bool stdpars {prompt="Use standard imcombine parameters to create sky?"} bool stdstar {prompt="Are these standard star images?"} bool zeroout {prompt="Zero out bad pixels on both sky & images?"} string maskname {prompt="Name of mask image to use"} bool tpl {prompt="Divide by throughput correction after sky-subtraction?"} string tplname {prompt="Name of throughput correction image to use"} bool subpattern=no {prompt="Subtract pattern noise (before tpl)?"} bool mksky {no,prompt="Make sky image even if it already exists?"} bool iterstat {yes,prompt="Use iterative means when constructing sky?"} bool dosky {yes,prompt="Subtract sky from images once it's created?"} bool addsky {no,prompt="Add constant median sky level after subtraction?"} bool forcescale {no,prompt="Force recalculation of image medians?"} bool premask {no,prompt="Mask when scaling before creating sky?"} pset imskypars {prompt="Imcombine parameters"} bool echog {yes,prompt="Beep when task is done?"} struct *list struct *datelist begin string rrootname, ddark, llogfile, bbadmask, eextension, ssextension string skylist, sky, skybase, meanfile, currentsky, base, mmaskname string iimagelist, SkyImageList, ssubstr, check, ttplname, subpat_list string datefile, thedate, ickinfo, name, img, img2, joinlist string s_sigma, s_plfile, s_combine, s_reject, s_offsets, s_masktyp string s_scale, s_weight, s_statsec, s_expname, s_zero, s_rdnoise, s_gain real s_maskval, s_blank, s_lthresh, s_hthresh, s_nlow, s_nhigh, s_nkeep real s_lsigma, s_hsigma, s_pclip, s_grow, s_sigscale real mean, meanbad, x, valmed, valsky int sstartno, eendno, i, j, numpix bool zzeroout, ttpl, sstdpars, sstdstar, iter_stat, scalecalc, force_scale, go bool pre_mask, mk_sky, do_sky, add_sky, sub_pattern, headadd rrootname = rootname iimagelist = imagelist list = iimagelist llogfile = logfile ssubstr = substring ssextension = sextension sstdpars = stdpars sstdstar = stdstar zzeroout = zeroout mmaskname = maskname ttpl = tpl ttplname = tplname sub_pattern = subpattern mk_sky = mksky iter_stat = iterstat do_sky = dosky add_sky = addsky force_scale = forcescale pre_mask = premask s_sigma = i_sigma s_plfile = i_plfile s_combine = i_combine s_reject = i_reject s_masktyp = i_masktyp s_maskval = i_maskval s_blank = i_blank s_scale = i_scale s_zero = i_zero s_weight = i_weight s_statsec = i_statsec s_expname = i_expname s_lthresh = i_lthresh s_hthresh = i_hthresh s_nlow = i_nlow s_nhigh = i_nhigh s_nkeep = i_nkeep s_lsigma = i_lsigma s_hsigma = i_hsigma s_rdnoise = i_rdnoise s_gain = i_gain s_sigscale = i_sigscale s_pclip = i_pclip s_grow = i_grow # The "go" parameter won't let the task run if the needed tasks aren't loaded. go=yes if(iter_stat && !defpac("imgtools")) {go=no} if(!iter_stat && add_sky) {go=no} if(!iter_stat && sub_pattern) {go=no} if(go) { # Set up log file, appending if it already exists print("Let the games begin...") if(access(llogfile)) print("Log file `"//llogfile//"' already exists... will append to it.") print(" ",>>llogfile);print("PHIIRS.QKSKY--------------------------",>>llogfile) # Set up files sky = rrootname//"."//ssextension # the final sky image SkyImageList = iimagelist//ssubstr # @file for sky-subtracted images if(access(SkyImageList)) delete(SkyImageList,ver-) while (fscan (list, name) !=EOF) { fileroot(name,validim+) check=fileroot.extension if(check!="")check="."//check base=fileroot.root print(base//ssubstr//check, >> SkyImageList) } # Make sky, if desired if (mk_sky || !access(sky)) { print("===> Making sky...") if (access(sky)) imdel (sky, ver-) print("File "//SkyImageList//" contains the following filenames:", >> llogfile) type(SkyImageList, >> llogfile) print(" ", >> llogfile) # Calculate scalings for all frames, if necessary if (iter_stat) { print("===> Calculating scalings using iterstat (or maskstat)...") list = iimagelist # Calculate the median of the image. If premask=yes, use only unmasked pixels. # Record the median value into the image header with the card SKYMED. # If SKYMED card already exists in the header, do not recalculate # unless the parameter forcescale=yes. while (fscan (list, img) !=EOF) { scalecalc = force_scale headadd = no imgets (img,"ITERMED",>&"dev$null") if (imgets.value == "0") headadd = yes if (!force_scale) { imgets (img,"SKYMED",>&"dev$null") if (imgets.value == "0") scalecalc = yes imgets (img,"ITERMED",>&"dev$null") if (imgets.value == "0") scalecalc = yes } if (scalecalc) { if(pre_mask) { maskstat(img,maskname,1.,nsigrej=5.,maxiter=10,lower=INDEF,upper=INDEF,iterstat+,addhead=headadd,ver-,print-) } else { iterstat(img,nsigrej=5.,maxiter=10,lower=INDEF,upper=INDEF,print-,ver-,addhead=headadd) } valmed = 1./iterstat.median hedit (img,"SKYMED",valmed,add+,ver-,show-,update+) } } } # Combine all images to make the sky print(" ", >> llogfile) print("===> Combine all images to make the sky") print("===> Combine all images to make the sky", >> llogfile) if(sstdpars){ if(sstdstar){ imcombine("@"//iimagelist, sky, sigma=s_sigma, plfile=s_plfile, combine="median", reject="ccdclip", project-, offsets="none", masktype="none", maskvalue=s_maskval, blank=s_blank, scale="none", zero="none", weight="none", statsec=s_statsec, expname=s_expname, lthresh=s_lthresh, hthresh=s_hthresh, nlow=s_nlow, nhigh=s_nhigh, nkeep=1, mclip+, lsigma=3, hsigma=3, rdnoise=s_rdnoise, gain=s_gain, sigscale=s_sigscale, pclip=s_pclip, grow=s_grow, logfile='STDOUT', >> llogfile) } else { imcombine("@"//iimagelist, sky, sigma=s_sigma, plfile=s_plfile, combine="median", reject="ccdclip", project-, offsets="none", masktype="none", maskvalue=s_maskval, blank=s_blank, scale="median", zero="none", weight="none", statsec=s_statsec, expname=s_expname, lthresh=s_lthresh, hthresh=s_hthresh, nlow=s_nlow, nhigh=s_nhigh, nkeep=1, mclip+, lsigma=3, hsigma=3, rdnoise=s_rdnoise, gain=s_gain, sigscale=s_sigscale, pclip=s_pclip, grow=s_grow, logfile='STDOUT', >> llogfile) } } else { if (iter_stat) { imcombine("@"//iimagelist, sky, sigma=s_sigma, plfile=s_plfile, combine=s_combine, reject=s_reject, project-, offsets="none", masktype=s_masktyp, maskvalue=s_maskval, blank=s_blank, scale="!SKYMED", zero=s_zero, weight=s_weight, statsec=s_statsec, expname=s_expname, lthresh=s_lthresh, hthresh=s_hthresh, nlow=s_nlow, nhigh=s_nhigh, nkeep=s_nkeep, mclip+, lsigma=s_lsigma, hsigma=s_hsigma, rdnoise=s_rdnoise, gain=s_gain, sigscale=s_sigscale, pclip=s_pclip, grow=s_grow, logfile='STDOUT', >> llogfile) } else { imcombine("@"//iimagelist, sky, sigma=s_sigma, plfile=s_plfile, combine=s_combine, reject=s_reject, project-, offsets="none", masktype=s_masktyp, maskvalue=s_maskval, blank=s_blank, scale=s_scale, zero=s_zero, weight=s_weight, statsec=s_statsec, expname=s_expname, lthresh=s_lthresh, hthresh=s_hthresh, nlow=s_nlow, nhigh=s_nhigh, nkeep=s_nkeep, mclip+, lsigma=s_lsigma, hsigma=s_hsigma, rdnoise=s_rdnoise, gain=s_gain, sigscale=s_sigscale, pclip=s_pclip, grow=s_grow, logfile='STDOUT', >> llogfile) } } # Make sure ITERMED header card isn't carried over from the first input image hedit(sky, "ITERMED", del+, add-, ver-, show-, update+) if(zzeroout){ imar(sky, "*", mmaskname, sky, verbose-) hedit(sky,"ZEROOUT",mmaskname,del-,add+,ver-,sho-,upd+) print("===> Zeroed out bad pixels on the sky image", >> llogfile) } else { print("===> Bad pixel zeroing not done on the sky image", >> llogfile) } print(" ", >> llogfile) # End of mksky+ portion } else { print("===> "//sky//" already exists -- not recreated -- continuing...") print(sky//" already exists -- not recreated",>>llogfile);print(" ",>>llogfile) } if (iter_stat) { imgets (sky,"ITERMED",>&"dev$null") valsky = real(imgets.value) if(pre_mask) { if (imgets.value=="0" || force_scale) { maskstat(sky,maskname,1.,nsigrej=5.,maxiter=10,lower=INDEF,upper=INDEF,iterstat+,ver-,print+, >> llogfile) valsky = iterstat.median } } else { if (imgets.value=="0" || force_scale) { iterstat(sky,nsigrej=5.,maxiter=10,lower=INDEF,upper=INDEF,print+,ver-, >> llogfile) valsky = iterstat.median } } } else { imstat(sky, >> llogfile) } if (do_sky) { # Subtract the Sky from all Images print("===> Subtract the Sky from all Images ") print("",>> llogfile);print("===> Subtract the Sky from all Images", >>llogfile) if (add_sky) { print("===> Then Add Back In Median Sky Level (addsky+)") print("===> Then Add Back In Median Sky Level (addsky+)", >>llogfile) } if (iter_stat) { joinlist=mktemp("join") join (iimagelist, SkyImageList, >> joinlist) list = joinlist while (fscan (list, img, img2) !=EOF) { # Scale sky image imgets (img,"ITERMED",>&"dev$null") valmed=real(imgets.value)/valsky # Subtract sky image & pattern noise, & add back in sky level if desired. if (sub_pattern) { print("===> Subtracting pattern noise from all images ") print("===> Subtracting pattern noise from all images ", >> llogfile) subpat_list = mktemp("subpat") print (img2, >> subpat_list) if (add_sky) { imdel ("addsky_pattern.fits",ver-,>& "dev$null") if (!access("blank_pattern.fits")) imar (subimg, "-", subimg, "blank_pattern.fits", pix="real", calc="real", ver-) imar ("blank_pattern.fits", "-", valmed, "addsky_pattern.fits", pix="real", calc="real", ver-) subpattern (subpat_list, "", startline=1, finishline=512, blankname="addsky_pattern.fits", ver-, useimgs+, saveimgs-) imdel ("addsky_pattern.fits",ver-,>& "dev$null") } else { subpattern (subpat_list, "", startline=1, finishline=512, blankname="blank_pattern.fits", ver-, useimgs+, saveimgs-) } del (subpat_list, ver-) print(" ", >> llogfile) } else { # Don't subtract pattern noise, but subtract sky & poss. add sky level back in. if (add_sky) { imcalc(img//","//sky,img2,"im1-im2*"//valmed//"+"//valmed,ver-) } else { imcalc(img//","//sky,img2,"im1-im2*"//valmed,ver-) } } } del(joinlist,ver-,>&"dev$null") } else { imarith("@"//iimagelist, "-", sky, "@"//SkyImageList, verbose-) print("IMARITH: @"//iimagelist//" - "//sky//" @"//SkyImageList,>>llogfile) print(" ", >> llogfile) } # Make throughput correction, if desired if(ttpl){ print("===> Make throughput correction on all images ") print("===> Make throughput correction on all images ", >> llogfile) imarith("@"//SkyImageList, "/", ttplname, "@"//SkyImageList, verbose-) print("IMARITH: @"//SkyImageList//" / "//ttplname//" @"//SkyImageList, >> llogfile) print(" ", >> llogfile) } # Force updating of pixel values, just to be safe print("===> Updating pixel values... ") minmax("@"//SkyImageList, force+, update+, verbose-) if (!iter_stat) imstat("@"//SkyImageList, >> llogfile) # End of do_sky=yes option } else { print("===> Sky made but NOT subtracted from images... ") } print("===> Wrapping up... ") datefile = mktemp("date") date(>>datefile) datelist = datefile print(" ", >> llogfile); print("finished at "//datelist, >> llogfile) datelist = "" del(datefile, ver-) print("...it is accomplished.") } else { if(!iter_stat && add_sky) { print("WARNING: iterstat=no & addsky=yes are incompatible options!") } else if (!iter_stat && sub_pattern) { print("WARNING: iterstat=no & sub_pattern=yes are incompatible options!") } else { print("WARNING: stsdas.toolbox.imgtools not loaded (for imcalc)!") } } if(echog)beep end ./subpattern.cl0100644000151400000240000002416607124503004012674 0ustar phallgames# subpattern -- subtract line-averaged pattern noise # # 990320: created # 990322: use imreplace (quicker) # 990322: allow @list or individual images (latter can be saved but not to list) # 990513: added premask option # 990518: added numsigrej option # 990604: added sinewave fit option procedure subpattern(imagelist,subsuffix) string imagelist {prompt="Image or @Imagelist to process"} string subsuffix {prompt="Suffix to add to output images"} bool premask=yes {prompt="Mask before processing?"} string maskword="OBJMASK" {prompt="Header keyword for mask to use"} int startline=1 {prompt="First line of pattern noise region"} int finishline=512 {prompt="Last line of pattern noise region"} real numsigrej=2 {prompt="Sigma rejection limits in iterstat"} bool useimgs {yes,prompt="Use any pattern noise images listed in headers?"} bool saveimgs {no,prompt="Save pattern noise images?"} bool verbose {no,prompt="Print iterstat output?"} bool sinewave {no,prompt="Use sinewave instead of constant fit to pattern?"} bool interact {no,prompt="Interactive sinewave fit"} string blankname {"blank_pattern.fits",prompt="Blank template image name"} bool echog {yes,prompt="Beep when task is done?"} struct *list begin string image_list, sub_list, sub_suffix, image_name, sub_name, tmp_name, check string blank_name, pattern_name, pattern_list, infile, mask_word, msk, old_name string tmp_img, tempslice, tempstack, tempslicelist, tempstacklist, junk1, junk2 real noise_value, n_sigrej, ampli_tude, ph_ase, off_set int start_line, finish_line, i, j, k bool go, wordy, save_imgs, create_pattern, use_imgs, pre_mask, sine_wave, inter_act go=yes create_pattern=no image_list = imagelist infile = image_list check = substr(image_list,1,1) # List of images if(check=="@") { infile = substr(image_list,2,strlen(image_list)) # Single image or image template } else { infile = mktemp("tmp$image_list") sections (image_list,option="fullname",>infile) } image_list = infile sub_suffix = subsuffix if (sub_suffix!="") { sub_list = image_list//sub_suffix pattern_list = image_list//"_"//sub_suffix if (access(sub_list)) go=no } else { sub_list = image_list pattern_list = image_list//"_pattern" } pre_mask=premask mask_word=maskword start_line=startline finish_line=finishline n_sigrej=numsigrej use_imgs=useimgs save_imgs=saveimgs wordy=verbose sine_wave=sinewave inter_act=interact blank_name=blankname if(blank_name=="")blank_name="blank_pattern.fits" if(!defpac("imgtools")) {go=no} if(sine_wave && !defpac("fitting")) {go=no} if(go) { # check for blank image & make if necessary head (image_list, nlines=1) | scan (tmp_name) if(!access(blank_name)) imar(tmp_name,"*","0.",blank_name,ver-,noact-) list = image_list tmp_name = mktemp("tmp_name") while (fscan (list, image_name) !=EOF) { tmp_img="" ; old_name="" # get new image & pattern name if (sub_suffix!="") { fileroot (image_name, validim+) pattern_name=sub_suffix//"_"//fileroot.root sub_name=fileroot.root//sub_suffix if(fileroot.extension!="")sub_name=sub_name//"."//fileroot.extension } else { sub_name = image_name pattern_name = "pattern_"//sub_name } # make pattern noise image if not done, PTTRNIMG doesn't exist, or useimgs=no... imgets (image_name, "PTTRNIMG", >& "dev$null") if(imgets.value=="0"||!access(imgets.value)||!use_imgs)create_pattern=yes if (create_pattern) { print("Creating pattern noise image ",pattern_name," ...takes a while!") imdel(pattern_name,ver-,>&"dev$null") if(!sine_wave)imcopy(blank_name,pattern_name,ver-) # create masked image if desired if (pre_mask) { imgets (image_name, mask_word, >& "dev$null") if (imgets.value=="0") { print ("WARNING! ",mask_word," header keyword not found; using unmasked image.") } else { tmp_img = mktemp(image_name) #imar (image_name,"*",imgets.value,tmp_img,ver-,noact-) imcalc (image_name//","//imgets.value,tmp_img,"if im2 .eq. 0 then -99999. else im1",ver-,nullval=-99999.) # set image name to masked image for pattern-finding step old_name = image_name image_name = tmp_img } } # NEW sinewave method if (sine_wave) { # new sinewave fit: slice image into single-line strips print ("Slicing & stacking image for sinewave fit...") tempslice=mktemp("slice") imslice(image_name//"[*,"//start_line//":"//finish_line//"]",tempslice,2,ver-) # new sinewave fit: imstack the single-line strips into six stacks tempslicelist=mktemp("slicelist") tempstacklist=mktemp("stacklist") tempstack=mktemp("stack") for (j=1; j<=6; j+=1) { for (i=start_line+j-1; i<=finish_line; i+=6) { print (i, >> tempslicelist) } filecal(tempslicelist,"$1",format=tempslice//"%03d",>>tempstacklist) imstack ("@"//tempstacklist, tempstack//j) del (tempslicelist, ver-) del (tempstacklist, ver-) } imdel (tempslice//"*", ver-) # new sinewave fit: get statistics for each pixel in each stack print ("Getting statistics for sinewave fit...") for (j=1; j<=6; j+=1) { for (i=1; i<=512; i+=1) { iterstat(tempstack//j//"["//i//",*]",nsigrej=n_sigrej,maxit=10,print=wordy,ver-,addh-) k=i+512*(j-1) print(k, iterstat.mean, iterstat.sigma, >> tempstack) } } imdel (tempstack//j, ver-) # new sinewave fit: set up parameters for nfit1d userpars.function = "c1 * sin(c2 * (x + c3)) +c4" userpars.c1 = 1. userpars.c2 = 0.0020453077 userpars.c3 = 0. userpars.c4 = 0. userpars.c5 = INDEF userpars.c6 = INDEF userpars.c7 = INDEF userpars.c8 = INDEF userpars.c9 = INDEF userpars.c10 = INDEF userpars.v1 = yes userpars.v2 = no userpars.v3 = yes userpars.v4 = yes userpars.v5 = no userpars.v6 = no userpars.v7 = no userpars.v8 = no userpars.v9 = no userpars.v10 = no errorpars.errcol = "" errorpars.errtype = "bars" # STSDAS 2.0 # errorpars.errors = no # STSDAS 2.0.1 # errorpars.resample = no samplepars.low_rej= 3. samplepars.high_rej= 3. samplepars.grow= 0. # new sinewave fit: run nfit1d & get fit parameters print("Running nfit1d interactively; type `:resample y' for error estimates;") print("when finished, type `:show' to display fit parameters, then 'q' to end.") nfit1d (tempstack, tempstack//"fit.tab", xunits="*", func="user", rt-, interac=inter_act, ver-) prfit (tempstack//"fit.tab") | grep ("c1") | scan (junk1, junk2, ampli_tude) prfit (tempstack//"fit.tab") | grep ("c3") | scan (junk1, junk2, ph_ase) prfit (tempstack//"fit.tab") | grep ("c4") | scan (junk1, junk2, off_set) print("Subtracting pattern from image...") imcalc (image_name, pattern_name, "im1-"//ampli_tude//"*sin(0.002045308*(x+512*(y-1)+"//ph_ase//"))-"//off_set) imcopy (image_name, sub_name) imcopy (pattern_name//"[*,"//start_line//":"//finish_line//"]", sub_name//"[*,"//start_line//":"//finish_line//"]") if (sub_suffix!="") print (sub_name, >> sub_list) # create the pattern image if desired, and save its name to list if desired if (save_imgs==yes) { imar (image_name, "-", sub_name, pattern_name, ver-) if (check=="@") print (pattern_name, >> pattern_list) } # OLD line average method } else { # go line by line for (i=start_line; i<=finish_line; i+=1) { # get line average iterstat(image_name//"[*,"//i//"]",nsigrej=n_sigrej,maxi=10,print=wordy,ver-,addh-,lower=-90000.,upper=INDEF) noise_value = iterstat.median if (noise_value==INDEF) noise_value=0. # clear out temporary image imdel (tmp_name, ver-, >& "dev$null") # add the line average to the appropriate line in the pattern image # imarith (blank_name//"[*,"//i//"]", "+", noise_value, tmp_name, ver-, noact-) imreplace (pattern_name//"[*,"//i//"]", noise_value, imaginary=0., lower=INDEF, upper=INDEF, radius=0.) } # reset image name away from masked image and delete masked image, if necessary if (tmp_img != "" && old_name != "") { image_name = old_name imdel (tmp_img, ver-) } # subtract the pattern image from the original image print ("Subtracting pattern noise to create "//sub_name) imar (image_name, "-", pattern_name, sub_name, ver-, noact-) hedit (sub_name,"PTTRNIMG",pattern_name,ad+,ve-,sh-,upd+) hedit(sub_name,"PTTRNSUB","Pattern noise subtracted",ad+,ve-,sh-,up+) if (sub_suffix!="") print (sub_name, >> sub_list) # add the pattern image name to the list, or delete it if (save_imgs==yes && check=="@") { print (pattern_name, >> pattern_list) } else if (save_imgs==no) { imdel (pattern_name, ver-) } # end of NEW sinewave method / OLD line average method tree } # ...but don't recreate the pattern noise image if it already exists } else { # test if subtraction of pattern noise image has been done pattern_name=imgets.value imgets (image_name, "PTTRNSUB", >& "dev$null") if (imgets.value=="0") { # ... or subtract existing pattern noise image if not already done ... print("Subtracting pattern noise image "//pattern_name//" to create "//sub_name) imar (image_name, "-", pattern_name, sub_name, ver-, noact-) hedit(sub_name,"PTTRNSUB","Pattern noise subtracted",ad+,ve-,sh-,up+) if(save_imgs==yes&&check=="@")print(pattern_name,>>pattern_list) } else { # ... or just copy image if pattern noise subtraction already done. print(image_name//" already pattern-noise subtracted... just copied.") imcopy (image_name, sub_name, ver-) } } } imdel (tmp_name, ver-, >& "dev$null") if (check!="@") { del(infile, ver-, >& "dev$null") del(sub_list, ver-, >& "dev$null") } if (save_imgs==yes) { if (check=="@") { print ("Pattern noise images listed in "//pattern_list) if(sub_suffix!="")print("Noise-subtracted images listed in "//sub_list) } else { print ("Pattern noise image(s) not deleted") } } } else { print("WARNING! Output image list already exists, or stsdas.toolbox.imgtools") print("package (w/imcalc task) not loaded, or stsdas.analysis.fitting package") print("not loaded (if sinewave=yes); noise subtraction not done.") } if(echog)beep end ./onis1358s.cl0100644000151400000240000005734106721637613012202 0ustar phallgames# onis1358s -- shift & coadd ONIS CNOC MS1358+62 South dither pattern # 990520 -- created from onis6pt # skip shiftlongaxes step if redo- & *.roundoff.* exists # layout of MS1358+62 South dither pattern (long axis vertical): # BCF # ADE procedure onis1358s(inlist,imageroot,niter) string inlist {prompt="List of input images"} string imageroot {prompt="Root name for output files"} int niter=1 {prompt="Number to append to output files"} string pair="all" {enum="AB|DC|EF|all",prompt="Pair of images to process (or all)"} bool inspect=yes {prompt="Inspect image lists before proceeding?"} bool shiftlongaxes=yes {prompt="Find shifts for image pairs w/overlapping long axes?"} bool coaddlongaxes=yes {prompt="Coadd image pairs w/overlapping long axes?"} string shortaxesmethod="both" {enum="xreg|irshift|both|none",prompt="Shift-finding method for overlapping short axes"} bool use_images=yes {prompt="Measure shifts from images (not file) in irshift?"} bool display_im=yes {prompt="Display images for imexam in irshift?"} bool redo=no {prompt="Redo shift-finding if already done?"} bool coaddallimages=yes {prompt="Coadd all images?"} bool secondpassxcor=yes {prompt="Cross-correlate all images with coadded image?"} bool coaddsecondpass=yes {prompt="Coadd images after second-pass cross-correlation?"} bool domkobjmask=yes {prompt="Make coadded-image object mask (INTERACTIVE)?"} bool domasklet=yes {prompt="Make individual-image object masks?"} bool echog=yes {prompt="Beep when task is done?"} struct *list begin string in_list, image_root, p_air, ref_image, tmpheaders, sigprefix, rroundname string theory, method_shortaxes, tempfile2, msect, image_name, tempx, tempy string zero_out int xmin, ymin, xint, yint, old_xint, old_yint, xmax_bcad, xmin_fead, ix, iy int n_iter, xbcad, ybcad, xfead, yfead, bcn1, fen1, xshift, yshift, xe, ye int xref, yref, int_x, int_y, junkint, xdiff, ydiff int oxdim,oydim # dimensions of mask image int ixdim,iydim # dimensions of individual input frames real xbcad2, ybcad2, xfead2, yfead2, bcad_x, bcad_y, fead_x, fead_y real xad, yad, xbc, ybc, xfe, yfe, bcad_xlag, bcad_ylag, fead_xlag, fead_ylag real bcad_xfirstpass, bcad_yfirstpass, bcad_xsecondpass, bcad_ysecondpass real fead_xfirstpass, fead_yfirstpass, fead_xsecondpass, fead_ysecondpass real xoff, yoff, step, new_x, new_y, old_x, old_y, step_x, step_y, xsig, ysig bool in_spect, shift_longaxes, echo_g, coadd_longaxes, abort, go, do_masklet bool coadd_allimages, xcor_secondpass, coadd_secondpass, do_mkobjmask, re_do bool im_display, images_use in_list=inlist image_root=imageroot n_iter=niter p_air=pair in_spect=inspect shift_longaxes=shiftlongaxes re_do=redo coadd_longaxes=coaddlongaxes method_shortaxes=shortaxesmethod images_use=use_images im_display=display_im coadd_allimages=coaddallimages xcor_secondpass=secondpassxcor coadd_secondpass=coaddsecondpass do_mkobjmask=domkobjmask do_masklet=domasklet echo_g=echog rroundname=image_root//".xregshifts.shABDCEF"//n_iter sigprefix=sigmanorm.prefix go=yes if(!defpac("imgtools")) {go=no} if(go) { # Separate input list into lists of images overlapping along long axes tmpheaders=mktemp("tmpheaders") hsel ("@"//in_list, "$I,i_title", yes, >> tmpheaders) if (!access(in_list//"_DC")) { grep ('Position\ \ 4\ of\ \ 6', tmpheaders) | grep ('S') | fields ("junk", "1", lines="1-9999", >> in_list//"_DC") grep ('Position\ \ 3\ of\ \ 6', tmpheaders) | grep ('S') | fields ("junk", "1", lines="1-9999", >> in_list//"_DC") } else { print (in_list//"_DC already exists; not created.") } if (!access(in_list//"_AB")) { grep ('Position\ \ 1\ of\ \ 6', tmpheaders) | grep ('S') | fields ("junk", "1", lines="1-9999", >> in_list//"_AB") grep ('Position\ \ 2\ of\ \ 6', tmpheaders) | grep ('S') | fields ("junk", "1", lines="1-9999", >> in_list//"_AB") } else { print (in_list//"_AB already exists; not created.") } if (!access(in_list//"_EF")) { grep ('Position\ \ 5\ of\ \ 6', tmpheaders) | grep ('S') | fields ("junk", "1", lines="1-9999", >> in_list//"_EF") grep ('Position\ \ 6\ of\ \ 6', tmpheaders) | grep ('S') | fields ("junk", "1", lines="1-9999", >> in_list//"_EF") } else { print (in_list//"_EF already exists; not created.") } del(tmpheaders,ver-) if (in_spect) vi (in_list//"_??") # Do irshift on lists of images overlapping along long axes if (shift_longaxes) { print ("Finding shifts for images overlapping along long axes...") if (p_air=="DC" || p_air=="all") { if (re_do || !access(image_root//".roundoff.shDC"//n_iter)) { fields (in_list//"_DC", 1, lines="2-2") | scan (ref_image) irshift (in_list//"_DC", ref_image, image_root, "shDC"//n_iter, useimages=images_use, displayim=im_display) } } if (p_air=="AB" || p_air=="all") { if (re_do || !access(image_root//".roundoff.shAB"//n_iter)) { fields (in_list//"_AB", 1, lines="2-2") | scan (ref_image) irshift (in_list//"_AB", ref_image, image_root, "shAB"//n_iter, useimages=images_use, displayim=im_display) } } if (p_air=="EF" || p_air=="all") { if (re_do || !access(image_root//".roundoff.shEF"//n_iter)) { fields (in_list//"_EF", 1, lines="2-2") | scan (ref_image) irshift (in_list//"_EF", ref_image, image_root, "shEF"//n_iter, useimages=images_use, displayim=im_display) } } } # Coadd images overlapping along long axes if (coadd_longaxes) { print ("Coadding images overlapping along long axes...") if (p_air=="DC" || p_air=="all") { imdel (image_root//"DC"//n_iter, ver-, >& "dev$null") imdel (image_root//"DC"//n_iter//"em", ver-, >& "dev$null") del (image_root//"DC"//n_iter//".imshifts", ver-, >& "dev$null") imdel (sigprefix//image_root//"DC"//n_iter, ver-, >& "dev$null") ircoadd (in_list//"_DC", image_root//"DC"//n_iter, "", image_root//".roundoff.shDC"//n_iter, "none", "mode", "none", 1, no, "log_"//image_root//"_all", makeavg+, flip-) sigmanorm (image_root//"DC"//n_iter) } if (p_air=="AB" || p_air=="all") { imdel (image_root//"AB"//n_iter, ver-, >& "dev$null") imdel (image_root//"AB"//n_iter//"em", ver-, >& "dev$null") del (image_root//"AB"//n_iter//".imshifts", ver-, >& "dev$null") imdel (sigprefix//image_root//"AB"//n_iter, ver-, >& "dev$null") ircoadd (in_list//"_AB", image_root//"AB"//n_iter, "", image_root//".roundoff.shAB"//n_iter, "none", "mode", "none", 1, no, "log_"//image_root//"_all", makeavg+, flip-) sigmanorm (image_root//"AB"//n_iter) } if (p_air=="EF" || p_air=="all") { imdel (image_root//"EF"//n_iter, ver-, >& "dev$null") imdel (image_root//"EF"//n_iter//"em", ver-, >& "dev$null") del (image_root//"EF"//n_iter//".imshifts", ver-, >& "dev$null") imdel (sigprefix//image_root//"EF"//n_iter, ver-, >& "dev$null") ircoadd (in_list//"_EF", image_root//"EF"//n_iter, "", image_root//".roundoff.shEF"//n_iter, "none", "mode", "none", 1, no, "log_"//image_root//"_all", makeavg+, flip-) sigmanorm (image_root//"EF"//n_iter) } } # Determine offsets along short axes #--xreg method------------------------------------------------------------------ if (p_air=="all" && (method_shortaxes=="xreg" || method_shortaxes=="both")) { if (!access(image_root//"_shABDC"//n_iter) || !access(image_root//"_shEFDC"//n_iter)) { if (re_do) { del (image_root//"_shABDC"//n_iter//"_rough", ver-, >& "dev$null") del (image_root//"_shEFDC"//n_iter//"_rough", ver-, >& "dev$null") del (image_root//"_shABDC"//n_iter//"_1stpass", ver-, >& "dev$null") del (image_root//"_shEFDC"//n_iter//"_1stpass", ver-, >& "dev$null") del (image_root//"_shABDC"//n_iter, ver-, >& "dev$null") del (image_root//"_shEFDC"//n_iter, ver-, >& "dev$null") print ("") print ("The imexam log file has been preserved; all else will be recreated.") } print ("") print ("The xregister offset method must be given rough offsets:") print ("Find an object in both the AB and DC images. Get its coords") print ("(type 'a' or 'r') in the DC image, then in the AB image.") print ("Then find an object in both the EF and DC images, get its coords") print ("in the DC image, then in the EF image, and then type 'q'.") print ("The imexam log file will appear for editing in case it's needed.") displ (sigprefix//image_root//"AB"//n_iter, 1) displ (sigprefix//image_root//"EF"//n_iter, 3) displ (sigprefix//image_root//"DC"//n_iter, 2) tempfile2=mktemp("temp2") print ("#**PROPER FORMAT**: uncommented line 1: DC, 2: AB, 3: DC, 4: EF", >> "log_imexam_"//image_root) imexam (sigprefix//image_root//"DC"//n_iter, logfile="log_imexam_"//image_root) vi ("log_imexam_"//image_root) # get rough x,y lags from object pairs (lag=other-DC) fields ("log_imexam_"//image_root, "1-2", lines="1-", >> tempfile2) fields (tempfile2, "1-2", lines="1-1") | scan (xad,yad) fields (tempfile2, "1-2", lines="2-2") | scan (xbc,ybc) bcad_xlag=xbc-xad; bcad_ylag=ybc-yad print (-1*bcad_xlag,-1*bcad_ylag, >> image_root//"_shABDC"//n_iter//"_rough") print ("Rough shift from "//sigprefix//image_root//"AB"//n_iter//" to "//sigprefix//image_root//"DC"//n_iter//" is "//-1*bcad_xlag//" "//-1*bcad_ylag//" pixels") fields (tempfile2, "1-2", lines="3-3") | scan (xad,yad) fields (tempfile2, "1-2", lines="4-4") | scan (xfe,yfe) fead_xlag=xfe-xad; fead_ylag=yfe-yad print (-1*fead_xlag,-1*fead_ylag, >> image_root//"_shEFDC"//n_iter//"_rough") print ("Rough shift from "//sigprefix//image_root//"EF"//n_iter//" to "//sigprefix//image_root//"DC"//n_iter//" is "//-1*fead_xlag//" "//-1*fead_ylag//" pixels") del (tempfile2, ver-) # figure out image section limits from rough offsets imgets (sigprefix//image_root//"AB"//n_iter, "i_naxis1"); bcn1=int(imgets.value) imgets (sigprefix//image_root//"EF"//n_iter, "i_naxis1"); fen1=int(imgets.value) xmax_bcad = bcn1 - int(bcad_xlag) xmin_fead = int(abs(fead_xlag)) # first-pass with rough lag print ("First pass xregister...") immatch.xreg (sigprefix//image_root//"AB"//n_iter, sigprefix//image_root//"DC"//n_iter, "[1:"//xmax_bcad//",*]", image_root//"_shABDC"//n_iter//"_1stpass", datab-, xlag=bcad_xlag, ylag=bcad_ylag, xwindow=25, ywindow=25) immatch.xreg (sigprefix//image_root//"EF"//n_iter, sigprefix//image_root//"DC"//n_iter, "["//xmin_fead//":"//fen1//",*]", image_root//"_shEFDC"//n_iter//"_1stpass", datab-, xlag=fead_xlag, ylag=fead_ylag, xwindow=25, ywindow=25) # second-pass with with result of first-pass print ("Second pass xregister...") type(image_root//"_shABDC"//n_iter//"_1stpass") | scan(theory, bcad_xfirstpass, bcad_yfirstpass) immatch.xreg (sigprefix//image_root//"AB"//n_iter, sigprefix//image_root//"DC"//n_iter, "[1:"//xmax_bcad//",*]", image_root//"_shABDC"//n_iter, datab-, xlag=-1*bcad_xfirstpass, ylag=-1*bcad_yfirstpass, xwindow=25, ywindow=25) type(image_root//"_shEFDC"//n_iter//"_1stpass") | scan(theory, fead_xfirstpass, fead_yfirstpass) immatch.xreg (sigprefix//image_root//"EF"//n_iter, sigprefix//image_root//"DC"//n_iter, "["//xmin_fead//":"//fen1//",*]", image_root//"_shEFDC"//n_iter, datab-, xlag=-1*fead_xfirstpass, ylag=-1*fead_yfirstpass, xwindow=25, ywindow=25) # abort if diverging, i.e. if abs(secondpass-firstpass)>0.5*abs(firstpass+rough) # "+" is because output of xreg is opposite sign of input lag abort=no type (image_root//"_shABDC"//n_iter) | scan (theory, bcad_xsecondpass, bcad_ysecondpass) if ((abs(bcad_xsecondpass - bcad_xfirstpass)) > (abs(0.5*(bcad_xfirstpass + bcad_xlag)))) abort=yes if ((abs(bcad_ysecondpass - bcad_yfirstpass)) > (abs(0.5*(bcad_yfirstpass + bcad_ylag)))) abort=yes type (image_root//"_shEFDC"//n_iter) | scan (theory, fead_xsecondpass, fead_ysecondpass) if ((abs(fead_xsecondpass - fead_xfirstpass)) > (abs(0.5*(fead_xfirstpass + fead_xlag)))) abort=yes if ((abs(fead_ysecondpass - fead_yfirstpass)) > (abs(0.5*(fead_yfirstpass + fead_ylag)))) abort=yes if (abort) { beep print("WARNING! xregister did not converge for at least one offset.") print("Stopping task; finish xregister manually and then resume.") return } } type (image_root//"_shABDC"//n_iter) | scan (theory, bcad_xsecondpass, bcad_ysecondpass) type (image_root//"_shEFDC"//n_iter) | scan (theory, fead_xsecondpass, fead_ysecondpass) if(bcad_xsecondpass>=0)xbcad=int(0.5+bcad_xsecondpass) if(bcad_ysecondpass>=0)ybcad=int(0.5+bcad_ysecondpass) if(fead_xsecondpass>=0)xfead=int(0.5+fead_xsecondpass) if(fead_xsecondpass>=0)yfead=int(0.5+fead_ysecondpass) if(bcad_xsecondpass<0)xbcad=int(-0.5+bcad_xsecondpass) if(bcad_ysecondpass<0)ybcad=int(-0.5+bcad_ysecondpass) if(fead_xsecondpass<0)xfead=int(-0.5+fead_xsecondpass) if(fead_xsecondpass<0)yfead=int(-0.5+fead_ysecondpass) } #--irshift method--------------------------------------------------------------- if (p_air=="all" && (method_shortaxes=="irshift" || method_shortaxes=="both")) { if(!access(image_root//".roundoff.shABDC"//n_iter) || !access(image_root//".roundoff.shEFDC"//n_iter)) { if (re_do) { del(image_root//".imshifts.sh??"//n_iter, ver-, >& "dev$null") del(image_root//".offsets.sh??"//n_iter, ver-, >& "dev$null") del(image_root//".roundoff.sh??"//n_iter, ver-, >& "dev$null") del(image_root//".shiftexact.sh??"//n_iter, ver-, >& "dev$null") del(image_root//".shiftfrac.sh??"//n_iter, ver-, >& "dev$null") del(image_root//".shiftint.sh??"//n_iter, ver-, >& "dev$null") print ("The *allcoords* and *refcoords* files have been saved;") print ("all else will be recreated.") } if(!access(in_list//"_ABDC")) { print (sigprefix//image_root//"AB"//n_iter, >> in_list//"_ABDC") print (sigprefix//image_root//"DC"//n_iter, >> in_list//"_ABDC") } irshift (in_list//"_ABDC", sigprefix//image_root//"DC"//n_iter, image_root, "shABDC"//n_iter, useimages=images_use, displayim=im_display) if(!access(in_list//"_EFDC")) { print (sigprefix//image_root//"EF"//n_iter, >> in_list//"_EFDC") print (sigprefix//image_root//"DC"//n_iter, >> in_list//"_EFDC") } irshift (in_list//"_EFDC", sigprefix//image_root//"DC"//n_iter, image_root, "shEFDC"//n_iter, useimages=images_use, displayim=im_display) } fields (image_root//".shiftexact.shABDC"//n_iter, "1-2", lines="1-1") | scan (xbc, ybc) fields (image_root//".shiftexact.shABDC"//n_iter, "1-2", lines="2-2") | scan (xad, yad) fields (image_root//".shiftexact.shEFDC"//n_iter, "1-2", lines="1-1") | scan (xfe, yfe) fields (image_root//".shiftexact.shEFDC"//n_iter, "1-2", lines="2-2") | scan (xad, yad) xbcad2=xbc-xad; ybcad2=ybc-yad; xfead2=xfe-xad; yfead2=yfe-yad # set xbcad ybcad xfead yfead if "both" if (method_shortaxes=="both") { print ("") print ("AB/DC xregister offsets: "//bcad_xsecondpass//" "//bcad_ysecondpass) print ("AB/DC irshift offsets: "//xbcad2//" "//ybcad2) tempx = mktemp("tempx"); tempy = mktemp("tempy") print (xbcad, >> tempx); print (xbcad2, >> tempx) print (ybcad, >> tempy); print (ybcad2, >> tempy) type (tempx) | average | scan (bcad_x, xsig, junkint) type (tempy) | average | scan (bcad_y, ysig, junkint) print ("AB/DC average offsets: "//bcad_x//"+-"//xsig//" "//bcad_y//"+-"//ysig) del (tempx, ver-); del (tempy, ver-) if(!access(image_root//"_shABDC"//n_iter//"_irshift"))print(xbcad2, ybcad2, >> image_root//"_shABDC"//n_iter//"_irshift") if(!access(image_root//"_shABDC"//n_iter//"_xreg"))copy(image_root//"_shABDC"//n_iter,image_root//"_shABDC"//n_iter//"_xreg") print (bcad_x, bcad_y, xsig, ysig, >> image_root//"_shABDC"//n_iter) print ("") print ("EF/DC xregister offsets: "//fead_xsecondpass//" "//fead_ysecondpass) print ("EF/DC irshift offsets: "//xfead2//" "//yfead2) tempx = mktemp("tempx"); tempy = mktemp("tempy") print (xfead, >> tempx); print (xfead2, >> tempx) print (yfead, >> tempy); print (yfead2, >> tempy) type (tempx) | average | scan (fead_x, xsig, junkint) type (tempy) | average | scan (fead_y, ysig, junkint) print ("EF/DC average offsets: "//fead_x//"+-"//xsig//" "//fead_x//"+-"//ysig) del (tempx, ver-); del (tempy, ver-) if(!access(image_root//"_shEFDC"//n_iter//"_irshift"))print(xfead2, yfead2, >> image_root//"_shEFDC"//n_iter//"_irshift") if(!access(image_root//"_shEFDC"//n_iter//"_xreg"))copy(image_root//"_shEFDC"//n_iter,image_root//"_shEFDC"//n_iter//"_xreg") print (fead_x, fead_y, xsig, ysig, >> image_root//"_shEFDC"//n_iter) print ("") xbcad=int(abs(0.5+bcad_x)); ybcad=int(abs(0.5+bcad_y)) xfead=int(abs(0.5+fead_x)); yfead=int(abs(0.5+fead_y)) } } # coadd all images at once if (p_air=="all" && coadd_allimages) { # set minimum x,y offsets to be 0 & 0 (independently) if (!access(image_root//".roundoff.shDC"//n_iter//"min0")) { list=image_root//".roundoff.shDC"//n_iter xmin=9999; ymin=9999 while (fscan(list,xint,yint) !=EOF) { if (xint < xmin) xmin = xint if (yint < ymin) ymin = yint } filecalc(image_root//".roundoff.shDC"//n_iter, "$1-"//xmin//";$2-"//ymin, format="%4.0f %4.0f", >> image_root//".roundoff.shDC"//n_iter//"min0") } if (!access(image_root//".roundoff.shAB"//n_iter//"min0")) { list=image_root//".roundoff.shAB"//n_iter xmin=9999; ymin=9999 while (fscan(list,xint,yint) !=EOF) { if (xint < xmin) xmin = xint if (yint < ymin) ymin = yint } filecalc(image_root//".roundoff.shAB"//n_iter, "$1-"//xmin//";$2-"//ymin, format="%4.0f %4.0f", >> image_root//".roundoff.shAB"//n_iter//"min0") } list=image_root//".roundoff.shEF"//n_iter if (!access(image_root//".roundoff.shEF"//n_iter//"min0")) { xmin=9999; ymin=9999 while (fscan(list,xint,yint) !=EOF) { if (xint < xmin) xmin = xint if (yint < ymin) ymin = yint } filecalc(image_root//".roundoff.shEF"//n_iter, "$1-"//xmin//";$2-"//ymin, format="%4.0f %4.0f", >> image_root//".roundoff.shEF"//n_iter//"min0") } # then offset by AB/DC or EF/DC offsets, as appropriate if(!access(image_root//".roundoff.shABDCEF"//n_iter)) { filecalc (image_root//".roundoff.shAB"//n_iter//"min0", "$1+"//xbcad//";$2+"//ybcad, format="%4.0f %4.0f", >> image_root//".roundoff.shABDCEF"//n_iter) type (image_root//".roundoff.shDC"//n_iter//"min0", >> image_root//".roundoff.shABDCEF"//n_iter) filecalc (image_root//".roundoff.shEF"//n_iter//"min0", "$1+"//xfead//";$2+"//yfead, format="%4.0f %4.0f", >> image_root//".roundoff.shABDCEF"//n_iter) } if(!access(in_list//"_ABDCEF")) concat (in_list//"_AB,"//in_list//"_DC,"//in_list//"_EF", in_list//"_ABDCEF") # do the coadd print ("Coadding all images at once...") ircoadd (in_list//"_ABDCEF", image_root//"ABDCEF"//n_iter//"_1stpass", "", image_root//".roundoff.shABDCEF"//n_iter, "none", "mode", "none", 1, no, "log_"//in_list//"_all", stdpars-, makeavg+, flip-, imcoaddpars="phiirs$ircoaddonis.par") } # cross-correlate individual images with coadded image if (p_air=="all" && xcor_secondpass) { print ("Creating constant-RMS coadded image...") ixdim=512; iydim=1024 if (!access(sigprefix//image_root//"ABDCEF"//n_iter//"_1stpass.fits")) sigmanorm (image_root//"ABDCEF"//n_iter//"_1stpass.fits") print ("Cross-correlating individual images with coadded image...") imgets(sigprefix//image_root//"ABDCEF"//n_iter//"_1stpass","i_naxis1") oxdim=int(imgets.value) imgets(sigprefix//image_root//"ABDCEF"//n_iter//"_1stpass","i_naxis2") oydim=int(imgets.value) list=image_root//"ABDCEF"//n_iter//"_1stpass.imshifts" while (fscan(list,image_name,xshift,yshift) !=EOF) { # zero out bad pixels if not already done imgets(image_name,"ZEROOUT") zero_out=imgets.value if(zero_out=="0"){ imgets(image_name,"BPMASK") if(imgets.value!="0"){ imar(image_name,"*",imgets.value,image_name,pixt="real",calct="real",ver-,noac-) hedit(image_name,"ZEROOUT",imgets.value,add+,ver-,show-,update+) } else { print("Bad pixels not zeroed for "//image_name//", and no BP mask in header!") } } ix=xshift+1-14 iy=yshift+1-14 xe=xshift + ixdim + 14 ye=yshift + iydim + 14 msect = "["//ix//":"//xe//","//iy//":"//ye//"]" print ("\nReference image region used for registration: "//msect) print ("Rough shift from "//image_name//" to "//sigprefix//image_root//"ABDCEF"//n_iter//"_1stpass is "//xshift//" "//yshift//" pixels") immatch.xreg (image_name, sigprefix//image_root//"ABDCEF"//n_iter//"_1stpass", msect, image_root//"ABDCEF"//n_iter//"_xregout", datab+, records="", xlag=-1*xshift, ylag=-1*yshift, xwindow=25, ywindow=25, append+) } tempx = mktemp("tempx"); tempy = mktemp("tempy") grep ('xshift', image_root//"ABDCEF"//n_iter//"_xregout") | fields ("junk", "2", >> tempx) grep ('yshift', image_root//"ABDCEF"//n_iter//"_xregout") | fields ("junk", "2", >> tempy) if(!access(image_root//".xregexact.shABDCEF"//n_iter)) join (tempx, tempy, output=image_root//".xregexact.shABDCEF"//n_iter) del (tempx, ver-); del (tempy, ver-) # Create optimum rounded-off integer offsets print(" ") print("===) Finding optimum second-pass rounded-off integer offsets...") old_x = 999.; old_y = 999. # for each 0.01 pixel step... for (i=-50; i<50; i+=1) { step = i / 100. # print (i) # ...recalculate integer offsets... list=image_root//".xregexact.shABDCEF"//n_iter del (rroundname, ver-, >& "dev$null") while(fscan(list,xoff,yoff) !=EOF) { xoff=xoff+step yoff=yoff+step if(((abs(xoff))>=0.5) && ((abs(yoff))>=0.5)) { print(xoff,yoff, >> "temp."//rroundname) } else { if((abs(xoff))<=0.5) { xoff=0. } if((abs(yoff))<=0.5) { yoff=0. } print(xoff,yoff, >> "temp."//rroundname) } filecalc("temp."//rroundname, "$1;$2", format="%4.0f %4.0f", >> rroundname) flpr; flpr; flpr del ("temp."//rroundname, ver-, >& "dev$null") } del ("temp."//rroundname, ver-, >& "dev$null") # calculate sum of squares of residuals of exact offsets - new integer offsets filecalc (image_root//".xregexact.shABDCEF"//n_iter//","//rroundname, "$1@1-$1@2+"//step) | average (option = "new_sample", >& "dev$null") flpr; flpr; flpr new_x=average.sumsqrs filecalc (image_root//".xregexact.shABDCEF"//n_iter//","//rroundname, "$2@1-$2@2+"//step) | average (option = "new_sample", >& "dev$null") flpr; flpr; flpr new_y=average.sumsqrs if (new_x < old_x) { old_x = new_x step_x = step } if (new_y < old_y) { old_y = new_y step_y = step } } # recalculate final integer offsets list=image_root//".xregexact.shABDCEF"//n_iter del(rroundname,ver-) del ("temp."//rroundname, ver-, >& "dev$null") while(fscan(list,xoff,yoff) !=EOF) { xoff=xoff+step_x yoff=yoff+step_y if(((abs(xoff))>=0.5) && ((abs(yoff))>=0.5)) { print(xoff,yoff, >> "temp."//rroundname) } else { if((abs(xoff))<=0.5) { xoff=0. } if((abs(yoff))<=0.5) { yoff=0. } print(xoff,yoff, >> "temp."//rroundname) } filecalc("temp."//rroundname,"$1;$2",format="%4.0f %4.0f", >>rroundname) flpr; flpr; flpr del ("temp."//rroundname, ver-, >& "dev$null") } del ("temp."//rroundname, ver-, >& "dev$null") } # ** next 3 can be done in dophiirs # Coadd images after second-pass cross-correlation if (p_air=="all" && coadd_secondpass) { print ("Coadding after second-pass cross-correlation...") ircoadd(in_list//"_ABDCEF", image_root//"ABDCEF"//n_iter, "", rroundname, "none", "mode", "none", 1, no, "log_"//in_list//"_all", stdpars-, makeavg-, flip-, imcoaddpars="phiirs$ircoaddonis.par") } # Make coadded-image object mask if (p_air=="all" && do_mkobjmask) { print ("Make coadded-image object mask...") mkobjmask (image_root//"ABDCEF"//n_iter//".fits", "", suffix="objmask", nsmooth=3, subsample=3, filtsize=15, ngrow=1, interact+) } # Make individual-image object masks if (p_air=="all" && do_masklet) { print ("Make individual-image object masks...") masklet (image_root//"ABDCEF"//n_iter, "", "om", shiftfile="", editfile+, flip-, update+) } } else { print ("WARNING! Package stsdas.imgtools not loaded... task aborted.") } if (echo_g) beep end ./irtfcoadd_2.p0100644000151400000240000000057006427031106012523 0ustar phallgames#!/usr/local/bin/perl # cycle thru contents of file(s) given on command line using <> $iter=0; while (<>) { # skip blank lines or lines with # as first non-whitespace character next if (/^\s+$/ or /^#/ or /^\s+#/); if($iter==0) { ($avg, $rms, $num) = split " "; } else { ($one) = split " "; $out=$one/$avg; print "$out\n"; } $iter=1; } ./xlist.cl0100644000151400000240000000215506561403220011645 0ustar phallgames# xlist.cl -- tool for generating sublists of files extracted from a main list. # If input list (inlist) has files 1 through N, xlist generates a new output # list (outlist) with files 'start' to 'finish', excluding file 'xfile'. # # originally created 7/22/93 Mark Dickinson procedure xlist(inlist,outlist,start,finish,xfile) string inlist {prompt="Input list of file names in sequence"} string outlist {prompt="Output file list"} int start {min=1,prompt="Number of first file to use in list"} int finish {min=1,prompt="Number of last file to use in list"} int xfile {min=1,prompt="Number of file to be excluded from list"} string prefix {"",prompt="Prefix to append to filenames in output list"} string *inlst begin string fname,outlst int ilist,istart,ifinish,ixfile # Get query parameters inlst = inlist outlst = outlist istart = start ifinish = finish ixfile = xfile # Now construct the list ilist=1 while (fscan(inlst,fname) != EOF) { if (ilist > ifinish) bye if (ilist > (istart-1)) { if (ilist != ixfile) { files(prefix//fname, >> outlst) } } ilist+=1 } inlst = "" end ./sample.loginuser.cl0100644000151400000240000000523207330353645014002 0ustar phallgames# sample inclusion of PHIIRS in default IRAF login # put any special commands after this line & before 'keep' # phiirs set phiirs = "/...insert_path_here.../phiirs/" task $phiirs = phiirs$phiirs.cl # following lines are sometimes needed to get help pages running; # if you have trouble, try uncommenting them as instructed below. # if "helpdb" has not previously been defined, uncomment the following line: #set helpdb = ("phiirs$helpdb.mip") # otherwise, you may need to uncomment the following line only: #reset helpdb = (envget ("helpdb") // ",phiirs$helpdb.mip") task addcomment = phiirs$addcomment.cl task addring = phiirs$addring.cl task cfhtfirst = phiirs$cfhtfirst.cl task crzap = phiirs$crzap.cl task crzap2 = phiirs$crzap2.cl task destripe = phiirs$destripe.cl task domeflat = phiirs$domeflat.cl task dophiirs = phiirs$dophiirs.cl task fileroot = phiirs$fileroot.cl task first = phiirs$first.cl task imcoaddpars = phiirs$imcoaddpars.par task imflatpars = phiirs$imflatpars.par task imskypars = phiirs$imskypars.par task ircoadd = phiirs$ircoadd.cl task irflat = phiirs$irflat.cl task irimfirst = phiirs$irimfirst.cl task irrotate = phiirs$irrotate.cl task irshift = phiirs$irshift.cl task irshift2 = phiirs$irshift2.cl task irsky = phiirs$irsky.cl task irtfcoadd = phiirs$irtfcoadd.cl task irtffirst = phiirs$irtffirst.cl task irtfphotscale = phiirs$irtfphotscale.cl task iterstat = phiirs$iterstat.cl task look = phiirs$look.cl task look4m = phiirs$look4m.cl task makeobjmask = phiirs$makeobjmask.cl task masklet = phiirs$masklet.cl task maskstat = phiirs$maskstat.cl task minv = phiirs$minv.cl task mkbpm = phiirs$mkbpm.cl task mkdark = phiirs$mkdark.cl task mkflat = phiirs$mkflat.cl task mkobjmask = phiirs$mkobjmask.cl task myget = phiirs$myget.cl task nl_findcor = phiirs$nl_findcor.cl task onisfirst = phiirs$onisfirst.cl task photcheck = phiirs$photcheck.cl task photcomp = phiirs$photcomp.cl task photscale = phiirs$photscale.cl task piscesfirst = phiirs$piscesfirst.cl task precoadd = phiirs$precoadd.cl task qkflat = phiirs$qkflat.cl task qksky = phiirs$qksky.cl task sctv = phiirs$sctv.cl task sigmanorm = phiirs$sigmanorm.cl task subpattern = phiirs$subpattern.cl task tplpars = phiirs$tplpars.par task tpl = phiirs$tpl.cl task trim = phiirs$trim.cl task $untrim = phiirs$untrim.cl task xlist = phiirs$xlist.cl keep ./ircoaddonis.par0100644000151400000240000000271006654115471013174 0ustar phallgamesi_sigma,s,h,"",,,"IMCOMBINE: Sigma image (optional)" i_plfile,s,h,"",,,"IMCOMBINE: Rejected pixel list image (optional)" i_combine,s,h,"average",average|median,,"IMCOMBINE: Type of combine operation (median|average)" i_reject,s,h,"sigclip",none|minmax|ccdclip|crreject|sigclip|avsigclip|pclip,,"IMCOMBINE: Type of rejection" i_masktyp,s,h,"badvalue",none|goodvalue|badvalue|goodbits|badbits,,"IMCOMBINE: Mask type" i_maskval,r,h,0.,,,"IMCOMBINE: Mask value" i_blank,r,h,0.,,,"IMCOMBINE: Value if there are no pixels" i_statsec,s,h,"",,,"IMCOMBINE: Image section for computing statistics" i_expname,s,h,"exptime",,,"IMCOMBINE: Image header exposure time keyword" i_lthresh,r,h,-10000.,,,"IMCOMBINE: Lower threshold" i_hthresh,r,h,INDEF,,,"IMCOMBINE: Upper threshold" i_nlow,r,h,1.,0.,,"IMCOMBINE: minmax: Number of low pixels to reject" i_nhigh,r,h,1.,0.,,"IMCOMBINE: minmax: Number of high pixels to reject" i_nkeep,r,h,1.,,,"IMCOMBINE: Minimum to keep (+) or maximum to reject(-)" i_lsigma,r,h,5.,0.,,"IMCOMBINE: Lower sigma clipping factor" i_hsigma,r,h,5.,0.,,"IMCOMBINE: Upper sigma clipping factor" i_rdnoise,s,h,"35.0",,,"IMCOMBINE: ccdclip: CCD readout noise (electrons)" i_gain,s,h,"4.0",,,"IMCOMBINE: ccdclip: CCD gain (electrons/ADU)" i_sigscale,r,h,0.1,0.,,"IMCOMBINE: Tolerance for sig-clip scaling corrections" i_pclip,r,h,-0.5,,,"IMCOMBINE: pclip: Percentile clipping parameter" i_grow,r,h,0.,,,"IMCOMBINE: Radius (pixels) for 1D neighbor rejection" mode,s,h,"q",,, ./onis0302.cl0100644000151400000240000006105006721353457011774 0ustar phallgames# onis0302 -- shift & coadd ONIS CNOC 6-point dither pattern for MS0302 # 990520 -- created from onis6pt; different criteria used to make image lists # layout of 6-point roundabout dither pattern (long axis vertical): # CDE # BAF procedure onis0302(inlist,imageroot,niter) string inlist {prompt="List of input images"} string imageroot {prompt="Root name for output files"} int niter=1 {prompt="Number to append to output files"} string pair="all" {enum="BC|AD|FE|all",prompt="Pair of images to process (or all)"} bool inspect=yes {prompt="Inspect image lists before proceeding?"} bool shiftlongaxes=yes {prompt="Find shifts for image pairs w/overlapping long axes?"} bool coaddlongaxes=yes {prompt="Coadd image pairs w/overlapping long axes?"} string shortaxesmethod="both" {enum="xreg|irshift|both|none",prompt="Shift-finding method for overlapping short axes"} bool use_images=yes {prompt="Measure shifts from images (not file) in irshift?"} bool display_im=yes {prompt="Display images for imexam in irshift?"} bool redo=no {prompt="Redo shift-finding if already done?"} bool coaddallimages=yes {prompt="Coadd all images?"} bool secondpassxcor=yes {prompt="Cross-correlate all images with coadded image?"} bool coaddsecondpass=yes {prompt="Coadd images after second-pass cross-correlation?"} bool domkobjmask=yes {prompt="Make coadded-image object mask (INTERACTIVE)?"} bool domasklet=yes {prompt="Make individual-image object masks?"} bool echog=yes {prompt="Beep when task is done?"} struct *list begin string in_list, image_root, p_air, ref_image, tmpheaders, sigprefix, rroundname string theory, method_shortaxes, tempfile2, msect, image_name, tempx, tempy string zero_out, tmp2headers int xmin, ymin, xint, yint, old_xint, old_yint, xmax_bcad, xmin_fead, ix, iy int n_iter, xbcad, ybcad, xfead, yfead, bcn1, fen1, xshift, yshift, xe, ye int xref, yref, int_x, int_y, junkint int oxdim,oydim # dimensions of mask image int ixdim,iydim # dimensions of individual input frames real xbcad2, ybcad2, xfead2, yfead2, bcad_x, bcad_y, fead_x, fead_y real xad, yad, xbc, ybc, xfe, yfe, bcad_xlag, bcad_ylag, fead_xlag, fead_ylag real bcad_xfirstpass, bcad_yfirstpass, bcad_xsecondpass, bcad_ysecondpass real fead_xfirstpass, fead_yfirstpass, fead_xsecondpass, fead_ysecondpass real xoff, yoff, step, new_x, new_y, old_x, old_y, step_x, step_y, xsig, ysig bool in_spect, shift_longaxes, echo_g, coadd_longaxes, abort, go, do_masklet bool coadd_allimages, xcor_secondpass, coadd_secondpass, do_mkobjmask, re_do bool im_display, images_use in_list=inlist image_root=imageroot n_iter=niter p_air=pair in_spect=inspect shift_longaxes=shiftlongaxes re_do=redo coadd_longaxes=coaddlongaxes method_shortaxes=shortaxesmethod images_use=use_images im_display=display_im coadd_allimages=coaddallimages xcor_secondpass=secondpassxcor coadd_secondpass=coaddsecondpass do_mkobjmask=domkobjmask do_masklet=domasklet echo_g=echog rroundname=image_root//".xregshifts.shBCADFE"//n_iter sigprefix=sigmanorm.prefix go=yes if(!defpac("imgtools")) {go=no} if(go) { # Separate input list into lists of images overlapping along long axes tmpheaders=mktemp("tmpheaders") tmp2headers=mktemp("tmp2headers") hsel ("@"//in_list, "$I,i_title", yes, >> tmpheaders) if (!access(in_list//"_AD")) { grep ('Position\ \ 1\ of\ \ 7', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_AD") grep ('Position\ \ 7\ of\ \ 7', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_AD") grep ('Position\ \ 1\ of\ \ 6', tmpheaders) | fields ("junk", "1", lines="1-9999", >> tmp2headers) grep ("-v", '990202.085', tmp2headers, >> in_list//"_AD") del (tmp2headers, ver-) grep ('Position\ \ 6\ of\ \ 6', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_AD") grep ('Position\ \ 4\ of\ \ 7', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_AD") grep ('Position\ \ 3\ of\ \ 6', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_AD") grep ('Position\ \ 1\ of\ \ 1', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_AD") } else { print (in_list//"_AD already exists; not created.") } if (!access(in_list//"_BC")) { grep ('Position\ \ 2\ of\ \ 7', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_BC") grep ('Position\ \ 1\ of\ \ 6', tmpheaders) | fields ("junk", "1", lines="1-9999", >> tmp2headers) grep ('990202.085', tmp2headers, >> in_list//"_BC") del (tmp2headers, ver-) grep ('Position\ \ 3\ of\ \ 7', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_BC") grep ('Position\ \ 2\ of\ \ 6', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_BC") } else { print (in_list//"_BC already exists; not created.") } if (!access(in_list//"_FE")) { grep ('Position\ \ 6\ of\ \ 7', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_FE") grep ('Position\ \ 5\ of\ \ 6', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_FE") grep ('Position\ \ 5\ of\ \ 7', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_FE") grep ('Position\ \ 4\ of\ \ 6', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_FE") } else { print (in_list//"_FE already exists; not created.") } del(tmpheaders,ver-) if (in_spect) vi (in_list//"_??") # Do irshift on lists of images overlapping along long axes if (shift_longaxes) { print ("Finding shifts for images overlapping along long axes...") if (p_air=="AD" || p_air=="all") { fields (in_list//"_AD", 1, lines="2-2") | scan (ref_image) irshift (in_list//"_AD", ref_image, image_root, "shAD"//n_iter, useimages=images_use, displayim=im_display) } if (p_air=="BC" || p_air=="all") { fields (in_list//"_BC", 1, lines="2-2") | scan (ref_image) irshift (in_list//"_BC", ref_image, image_root, "shBC"//n_iter, useimages=images_use, displayim=im_display) } if (p_air=="FE" || p_air=="all") { fields (in_list//"_FE", 1, lines="2-2") | scan (ref_image) irshift (in_list//"_FE", ref_image, image_root, "shFE"//n_iter, useimages=images_use, displayim=im_display) } } # Coadd images overlapping along long axes if (coadd_longaxes) { print ("Coadding images overlapping along long axes...") if (p_air=="AD" || p_air=="all") { imdel (image_root//"AD"//n_iter, ver-, >& "dev$null") imdel (image_root//"AD"//n_iter//"em", ver-, >& "dev$null") del (image_root//"AD"//n_iter//".imshifts", ver-, >& "dev$null") imdel (sigprefix//image_root//"AD"//n_iter, ver-, >& "dev$null") ircoadd (in_list//"_AD", image_root//"AD"//n_iter, "", image_root//".roundoff.shAD"//n_iter, "none", "mode", "none", 1, no, "log_"//image_root//"_ABCDEF", makeavg+, flip-) sigmanorm (image_root//"AD"//n_iter) } if (p_air=="BC" || p_air=="all") { imdel (image_root//"BC"//n_iter, ver-, >& "dev$null") imdel (image_root//"BC"//n_iter//"em", ver-, >& "dev$null") del (image_root//"BC"//n_iter//".imshifts", ver-, >& "dev$null") imdel (sigprefix//image_root//"BC"//n_iter, ver-, >& "dev$null") ircoadd (in_list//"_BC", image_root//"BC"//n_iter, "", image_root//".roundoff.shBC"//n_iter, "none", "mode", "none", 1, no, "log_"//image_root//"_ABCDEF", makeavg+, flip-) sigmanorm (image_root//"BC"//n_iter) } if (p_air=="FE" || p_air=="all") { imdel (image_root//"FE"//n_iter, ver-, >& "dev$null") imdel (image_root//"FE"//n_iter//"em", ver-, >& "dev$null") del (image_root//"FE"//n_iter//".imshifts", ver-, >& "dev$null") imdel (sigprefix//image_root//"FE"//n_iter, ver-, >& "dev$null") ircoadd (in_list//"_FE", image_root//"FE"//n_iter, "", image_root//".roundoff.shFE"//n_iter, "none", "mode", "none", 1, no, "log_"//image_root//"_ABCDEF", makeavg+, flip-) sigmanorm (image_root//"FE"//n_iter) } } # Determine offsets along short axes #--xreg method------------------------------------------------------------------ if (p_air=="all" && (method_shortaxes=="xreg" || method_shortaxes=="both")) { if (!access(image_root//"_shBCAD"//n_iter) || !access(image_root//"_shFEAD"//n_iter)) { if (re_do) { del (image_root//"_shBCAD"//n_iter//"_rough", ver-, >& "dev$null") del (image_root//"_shFEAD"//n_iter//"_rough", ver-, >& "dev$null") del (image_root//"_shBCAD"//n_iter//"_1stpass", ver-, >& "dev$null") del (image_root//"_shFEAD"//n_iter//"_1stpass", ver-, >& "dev$null") del (image_root//"_shBCAD"//n_iter, ver-, >& "dev$null") del (image_root//"_shFEAD"//n_iter, ver-, >& "dev$null") print ("") print ("The imexam log file has been preserved; all else will be recreated.") } print ("") print ("The xregister offset method must be given rough offsets:") print ("Find an object in both the BC and AD images. Get its coords") print ("(type 'a' or 'r') in the AD image, then in the BC image.") print ("Then find an object in both the FE and AD images, get its coords") print ("in the AD image, then in the FE image, and then type 'q'.") print ("The imexam log file will appear for editing in case it's needed.") displ (sigprefix//image_root//"BC"//n_iter, 1) displ (sigprefix//image_root//"FE"//n_iter, 3) displ (sigprefix//image_root//"AD"//n_iter, 2) tempfile2=mktemp("temp2") print ("#**PROPER FORMAT**: uncommented line 1: AD, 2: BC, 3: AD, 4: FE", >> "log_imexam_"//image_root) imexam (sigprefix//image_root//"AD"//n_iter, logfile="log_imexam_"//image_root) vi ("log_imexam_"//image_root) # get rough x,y lags from object pairs (lag=other-AD) fields ("log_imexam_"//image_root, "1-2", lines="1-", >> tempfile2) fields (tempfile2, "1-2", lines="1-1") | scan (xad,yad) fields (tempfile2, "1-2", lines="2-2") | scan (xbc,ybc) bcad_xlag=xbc-xad; bcad_ylag=ybc-yad print (-1*bcad_xlag,-1*bcad_ylag, >> image_root//"_shBCAD"//n_iter//"_rough") print ("Rough shift from "//sigprefix//image_root//"BC"//n_iter//" to "//sigprefix//image_root//"AD"//n_iter//" is "//-1*bcad_xlag//" "//-1*bcad_ylag//" pixels") fields (tempfile2, "1-2", lines="3-3") | scan (xad,yad) fields (tempfile2, "1-2", lines="4-4") | scan (xfe,yfe) fead_xlag=xfe-xad; fead_ylag=yfe-yad print (-1*fead_xlag,-1*fead_ylag, >> image_root//"_shFEAD"//n_iter//"_rough") print ("Rough shift from "//sigprefix//image_root//"FE"//n_iter//" to "//sigprefix//image_root//"AD"//n_iter//" is "//-1*fead_xlag//" "//-1*fead_ylag//" pixels") del (tempfile2, ver-) # figure out image section limits from rough offsets imgets (sigprefix//image_root//"BC"//n_iter, "i_naxis1"); bcn1=int(imgets.value) imgets (sigprefix//image_root//"FE"//n_iter, "i_naxis1"); fen1=int(imgets.value) xmax_bcad = bcn1 - int(bcad_xlag) xmin_fead = int(abs(fead_xlag)) # first-pass with rough lag print ("First pass xregister...") immatch.xreg (sigprefix//image_root//"BC"//n_iter, sigprefix//image_root//"AD"//n_iter, "[1:"//xmax_bcad//",*]", image_root//"_shBCAD"//n_iter//"_1stpass", datab-, xlag=bcad_xlag, ylag=bcad_ylag, xwindow=25, ywindow=25) immatch.xreg (sigprefix//image_root//"FE"//n_iter, sigprefix//image_root//"AD"//n_iter, "["//xmin_fead//":"//fen1//",*]", image_root//"_shFEAD"//n_iter//"_1stpass", datab-, xlag=fead_xlag, ylag=fead_ylag, xwindow=25, ywindow=25) # second-pass with with result of first-pass print ("Second pass xregister...") type(image_root//"_shBCAD"//n_iter//"_1stpass") | scan(theory, bcad_xfirstpass, bcad_yfirstpass) immatch.xreg (sigprefix//image_root//"BC"//n_iter, sigprefix//image_root//"AD"//n_iter, "[1:"//xmax_bcad//",*]", image_root//"_shBCAD"//n_iter, datab-, xlag=-1*bcad_xfirstpass, ylag=-1*bcad_yfirstpass, xwindow=25, ywindow=25) type(image_root//"_shFEAD"//n_iter//"_1stpass") | scan(theory, fead_xfirstpass, fead_yfirstpass) immatch.xreg (sigprefix//image_root//"FE"//n_iter, sigprefix//image_root//"AD"//n_iter, "["//xmin_fead//":"//fen1//",*]", image_root//"_shFEAD"//n_iter, datab-, xlag=-1*fead_xfirstpass, ylag=-1*fead_yfirstpass, xwindow=25, ywindow=25) # abort if diverging, i.e. if abs(secondpass-firstpass)>0.5*abs(firstpass+rough) # "+" is because output of xreg is opposite sign of input lag abort=no type (image_root//"_shBCAD"//n_iter) | scan (theory, bcad_xsecondpass, bcad_ysecondpass) if ((abs(bcad_xsecondpass - bcad_xfirstpass)) > (abs(0.5*(bcad_xfirstpass + bcad_xlag)))) abort=yes if ((abs(bcad_ysecondpass - bcad_yfirstpass)) > (abs(0.5*(bcad_yfirstpass + bcad_ylag)))) abort=yes type (image_root//"_shFEAD"//n_iter) | scan (theory, fead_xsecondpass, fead_ysecondpass) if ((abs(fead_xsecondpass - fead_xfirstpass)) > (abs(0.5*(fead_xfirstpass + fead_xlag)))) abort=yes if ((abs(fead_ysecondpass - fead_yfirstpass)) > (abs(0.5*(fead_yfirstpass + fead_ylag)))) abort=yes if (abort) { beep print("WARNING! xregister did not converge for at least one offset.") print("Stopping task; finish xregister manually and then resume.") return } } type (image_root//"_shBCAD"//n_iter) | scan (theory, bcad_xsecondpass, bcad_ysecondpass) type (image_root//"_shFEAD"//n_iter) | scan (theory, fead_xsecondpass, fead_ysecondpass) if(bcad_xsecondpass>=0)xbcad=int(0.5+bcad_xsecondpass) if(bcad_ysecondpass>=0)ybcad=int(0.5+bcad_ysecondpass) if(fead_xsecondpass>=0)xfead=int(0.5+fead_xsecondpass) if(fead_xsecondpass>=0)yfead=int(0.5+fead_ysecondpass) if(bcad_xsecondpass<0)xbcad=int(-0.5+bcad_xsecondpass) if(bcad_ysecondpass<0)ybcad=int(-0.5+bcad_ysecondpass) if(fead_xsecondpass<0)xfead=int(-0.5+fead_xsecondpass) if(fead_xsecondpass<0)yfead=int(-0.5+fead_ysecondpass) } #--irshift method--------------------------------------------------------------- if (p_air=="all" && (method_shortaxes=="irshift" || method_shortaxes=="both")) { if(!access(image_root//".roundoff.shBCAD"//n_iter) || !access(image_root//".roundoff.shFEAD"//n_iter)) { if (re_do) { del(image_root//".imshifts.sh??"//n_iter, ver-, >& "dev$null") del(image_root//".offsets.sh??"//n_iter, ver-, >& "dev$null") del(image_root//".roundoff.sh??"//n_iter, ver-, >& "dev$null") del(image_root//".shiftexact.sh??"//n_iter, ver-, >& "dev$null") del(image_root//".shiftfrac.sh??"//n_iter, ver-, >& "dev$null") del(image_root//".shiftint.sh??"//n_iter, ver-, >& "dev$null") print ("The *allcoords* and *refcoords* files have been saved;") print ("all else will be recreated.") } if(!access(in_list//"_BCAD")) { print (sigprefix//image_root//"BC"//n_iter, >> in_list//"_BCAD") print (sigprefix//image_root//"AD"//n_iter, >> in_list//"_BCAD") } irshift (in_list//"_BCAD", sigprefix//image_root//"AD"//n_iter, image_root, "shBCAD"//n_iter, useimages=images_use, displayim=im_display) if(!access(in_list//"_FEAD")) { print (sigprefix//image_root//"FE"//n_iter, >> in_list//"_FEAD") print (sigprefix//image_root//"AD"//n_iter, >> in_list//"_FEAD") } irshift (in_list//"_FEAD", sigprefix//image_root//"AD"//n_iter, image_root, "shFEAD"//n_iter, useimages=images_use, displayim=im_display) } fields (image_root//".shiftexact.shBCAD"//n_iter, "1-2", lines="1-1") | scan (xbc, ybc) fields (image_root//".shiftexact.shBCAD"//n_iter, "1-2", lines="2-2") | scan (xad, yad) fields (image_root//".shiftexact.shFEAD"//n_iter, "1-2", lines="1-1") | scan (xfe, yfe) fields (image_root//".shiftexact.shFEAD"//n_iter, "1-2", lines="2-2") | scan (xad, yad) xbcad2=xbc-xad; ybcad2=ybc-yad; xfead2=xfe-xad; yfead2=yfe-yad # set xbcad ybcad xfead yfead if "both" if (method_shortaxes=="both") { print ("") print ("BC/AD xregister offsets: "//bcad_xsecondpass//" "//bcad_ysecondpass) print ("BC/AD irshift offsets: "//xbcad2//" "//ybcad2) tempx = mktemp("tempx"); tempy = mktemp("tempy") print (xbcad, >> tempx); print (xbcad2, >> tempx) print (ybcad, >> tempy); print (ybcad2, >> tempy) type (tempx) | average | scan (bcad_x, xsig, junkint) type (tempy) | average | scan (bcad_y, ysig, junkint) print ("BC/AD average offsets: "//bcad_x//"+-"//xsig//" "//bcad_y//"+-"//ysig) del (tempx, ver-); del (tempy, ver-) if(!access(image_root//"_shBCAD"//n_iter//"_irshift"))print(xbcad2, ybcad2, >> image_root//"_shBCAD"//n_iter//"_irshift") if(!access(image_root//"_shBCAD"//n_iter//"_xreg"))copy(image_root//"_shBCAD"//n_iter,image_root//"_shBCAD"//n_iter//"_xreg") print (bcad_x, bcad_y, xsig, ysig, >> image_root//"_shBCAD"//n_iter) print ("") print ("FE/AD xregister offsets: "//fead_xsecondpass//" "//fead_ysecondpass) print ("FE/AD irshift offsets: "//xfead2//" "//yfead2) tempx = mktemp("tempx"); tempy = mktemp("tempy") print (xfead, >> tempx); print (xfead2, >> tempx) print (yfead, >> tempy); print (yfead2, >> tempy) type (tempx) | average | scan (fead_x, xsig, junkint) type (tempy) | average | scan (fead_y, ysig, junkint) print ("FE/AD average offsets: "//fead_x//"+-"//xsig//" "//fead_x//"+-"//ysig) del (tempx, ver-); del (tempy, ver-) if(!access(image_root//"_shFEAD"//n_iter//"_irshift"))print(xfead2, yfead2, >> image_root//"_shFEAD"//n_iter//"_irshift") if(!access(image_root//"_shFEAD"//n_iter//"_xreg"))copy(image_root//"_shFEAD"//n_iter,image_root//"_shFEAD"//n_iter//"_xreg") print (fead_x, fead_y, xsig, ysig, >> image_root//"_shFEAD"//n_iter) print ("") xbcad=int(abs(0.5+bcad_x)); ybcad=int(abs(0.5+bcad_y)) xfead=int(abs(0.5+fead_x)); yfead=int(abs(0.5+fead_y)) } } # coadd all images at once if (p_air=="all" && coadd_allimages) { # set minimum x,y offsets to be 0 & 0 (independently) if (!access(image_root//".roundoff.shAD"//n_iter//"min0")) { list=image_root//".roundoff.shAD"//n_iter xmin=9999; ymin=9999 while (fscan(list,xint,yint) !=EOF) { if (xint < xmin) xmin = xint if (yint < ymin) ymin = yint } filecalc(image_root//".roundoff.shAD"//n_iter, "$1-"//xmin//";$2-"//ymin, format="%4.0f %4.0f", >> image_root//".roundoff.shAD"//n_iter//"min0") } if (!access(image_root//".roundoff.shBC"//n_iter//"min0")) { list=image_root//".roundoff.shBC"//n_iter xmin=9999; ymin=9999 while (fscan(list,xint,yint) !=EOF) { if (xint < xmin) xmin = xint if (yint < ymin) ymin = yint } filecalc(image_root//".roundoff.shBC"//n_iter, "$1-"//xmin//";$2-"//ymin, format="%4.0f %4.0f", >> image_root//".roundoff.shBC"//n_iter//"min0") } list=image_root//".roundoff.shFE"//n_iter if (!access(image_root//".roundoff.shFE"//n_iter//"min0")) { xmin=9999; ymin=9999 while (fscan(list,xint,yint) !=EOF) { if (xint < xmin) xmin = xint if (yint < ymin) ymin = yint } filecalc(image_root//".roundoff.shFE"//n_iter, "$1-"//xmin//";$2-"//ymin, format="%4.0f %4.0f", >> image_root//".roundoff.shFE"//n_iter//"min0") } # then offset by BC/AD or FE/AD offsets, as appropriate if(!access(image_root//".roundoff.shBCADFE"//n_iter)) { filecalc (image_root//".roundoff.shBC"//n_iter//"min0", "$1+"//xbcad//";$2+"//ybcad, format="%4.0f %4.0f", >> image_root//".roundoff.shBCADFE"//n_iter) type (image_root//".roundoff.shAD"//n_iter//"min0", >> image_root//".roundoff.shBCADFE"//n_iter) filecalc (image_root//".roundoff.shFE"//n_iter//"min0", "$1+"//xfead//";$2+"//yfead, format="%4.0f %4.0f", >> image_root//".roundoff.shBCADFE"//n_iter) } if(!access(in_list//"_BCADFE")) concat (in_list//"_BC,"//in_list//"_AD,"//in_list//"_FE", in_list//"_BCADFE") # do the coadd print ("Coadding all images at once...") ircoadd (in_list//"_BCADFE", image_root//"BCADFE"//n_iter//"_1stpass", "", image_root//".roundoff.shBCADFE"//n_iter, "none", "mode", "none", 1, no, "log_"//in_list//"_ABCDEF", stdpars-, makeavg+, flip-, imcoaddpars="phiirs$ircoaddonis.par") } # cross-correlate individual images with coadded image if (p_air=="all" && xcor_secondpass) { print ("Creating constant-RMS coadded image...") ixdim=512; iydim=1024 if (!access(sigprefix//image_root//"BCADFE"//n_iter//"_1stpass.fits")) sigmanorm (image_root//"BCADFE"//n_iter//"_1stpass.fits") print ("Cross-correlating individual images with coadded image...") imgets(sigprefix//image_root//"BCADFE"//n_iter//"_1stpass","i_naxis1") oxdim=int(imgets.value) imgets(sigprefix//image_root//"BCADFE"//n_iter//"_1stpass","i_naxis2") oydim=int(imgets.value) list=image_root//"BCADFE"//n_iter//"_1stpass.imshifts" while (fscan(list,image_name,xshift,yshift) !=EOF) { # zero out bad pixels if not already done imgets(image_name,"ZEROOUT") zero_out=imgets.value if(zero_out=="0"){ imgets(image_name,"BPMASK") if(imgets.value!="0"){ imar(image_name,"*",imgets.value,image_name,pixt="real",calct="real",ver-,noac-) hedit(image_name,"ZEROOUT",imgets.value,add+,ver-,show-,update+) } else { print("Bad pixels not zeroed for "//image_name//", and no BP mask in header!") } } ix=xshift+1-14; if(ix<1)ix=1 iy=yshift+1-14; if(iy<1)iy=1 xe=xshift + ixdim + 14; if(xe>oxdim)xe=oxdim ye=yshift + iydim + 14; if(ye>oydim)ye=oydim msect = "["//ix//":"//xe//","//iy//":"//ye//"]" print ("Rough shift from "//image_name//" to "//sigprefix//image_root//"BCADFE"//n_iter//"_1stpass is "//xshift//" "//yshift//" pixels") immatch.xreg (image_name, sigprefix//image_root//"BCADFE"//n_iter//"_1stpass", msect, image_root//"BCADFE"//n_iter//"_xregout", datab+, records="", xlag=-1*xshift, ylag=-1*yshift, xwindow=25, ywindow=25, append+) } tempx = mktemp("tempx"); tempy = mktemp("tempy") grep ('xshift', image_root//"BCADFE"//n_iter//"_xregout") | fields ("junk", "2", >> tempx) grep ('yshift', image_root//"BCADFE"//n_iter//"_xregout") | fields ("junk", "2", >> tempy) if(!access(image_root//".xregexact.shBCADFE"//n_iter)) join (tempx, tempy, output=image_root//".xregexact.shBCADFE"//n_iter) del (tempx, ver-); del (tempy, ver-) # Create optimum rounded-off integer offsets print(" ") print("===) Finding optimum second-pass rounded-off integer offsets...") old_x = 999.; old_y = 999. # for each 0.01 pixel step... for (i=-50; i<50; i+=1) { step = i / 100. # print (i) # ...recalculate integer offsets... list=image_root//".xregexact.shBCADFE"//n_iter del (rroundname, ver-, >& "dev$null") while(fscan(list,xoff,yoff) !=EOF) { xoff=xoff+step yoff=yoff+step if(((abs(xoff))>=0.5) && ((abs(yoff))>=0.5)) { print(xoff,yoff, >> "temp."//rroundname) } else { if((abs(xoff))<=0.5) { xoff=0. } if((abs(yoff))<=0.5) { yoff=0. } print(xoff,yoff, >> "temp."//rroundname) } filecalc("temp."//rroundname, "$1;$2", format="%4.0f %4.0f", >> rroundname) flpr; flpr; flpr del ("temp."//rroundname, ver-, >& "dev$null") } del ("temp."//rroundname, ver-, >& "dev$null") # calculate sum of squares of residuals of exact offsets - new integer offsets filecalc (image_root//".xregexact.shBCADFE"//n_iter//","//rroundname, "$1@1-$1@2+"//step) | average (option = "new_sample", >& "dev$null") flpr; flpr; flpr new_x=average.sumsqrs filecalc (image_root//".xregexact.shBCADFE"//n_iter//","//rroundname, "$2@1-$2@2+"//step) | average (option = "new_sample", >& "dev$null") flpr; flpr; flpr new_y=average.sumsqrs if (new_x < old_x) { old_x = new_x step_x = step } if (new_y < old_y) { old_y = new_y step_y = step } } # recalculate final integer offsets list=image_root//".xregexact.shBCADFE"//n_iter del(rroundname,ver-) del ("temp."//rroundname, ver-, >& "dev$null") while(fscan(list,xoff,yoff) !=EOF) { xoff=xoff+step_x yoff=yoff+step_y if(((abs(xoff))>=0.5) && ((abs(yoff))>=0.5)) { print(xoff,yoff, >> "temp."//rroundname) } else { if((abs(xoff))<=0.5) { xoff=0. } if((abs(yoff))<=0.5) { yoff=0. } print(xoff,yoff, >> "temp."//rroundname) } filecalc("temp."//rroundname,"$1;$2",format="%4.0f %4.0f", >>rroundname) flpr; flpr; flpr del ("temp."//rroundname, ver-, >& "dev$null") } del ("temp."//rroundname, ver-, >& "dev$null") } # ** next 3 can be done in dophiirs # Coadd images after second-pass cross-correlation if (p_air=="all" && coadd_secondpass) { print ("Coadding after second-pass cross-correlation...") ircoadd(in_list//"_BCADFE", image_root//"BCADFE"//n_iter, "", rroundname, "none", "mode", "none", 1, no, "log_"//in_list//"_ABCDEF", stdpars-, makeavg-, flip-, imcoaddpars="phiirs$ircoaddonis.par") } # Make coadded-image object mask if (p_air=="all" && do_mkobjmask) { print ("Make coadded-image object mask...") mkobjmask (image_root//"BCADFE"//n_iter//".fits", "", suffix="objmask", nsmooth=3, subsample=3, filtsize=15, ngrow=1, interact+) } # Make individual-image object masks if (p_air=="all" && do_masklet) { print ("Make individual-image object masks...") masklet (image_root//"BCADFE"//n_iter, "", "om", shiftfile="", editfile+, flip-, update+) } } else { print ("WARNING! Package stsdas.imgtools not loaded... task aborted.") } if (echo_g) beep end ./onis0451.cl0100644000151400000240000012561006721656266012010 0ustar phallgames# onis0451 -- shift & coadd ONIS data on MS0451+02 # 990518 -- created from onis3ew.cl # 990519 -- sigmanorm of long-axis coadds commented out (not used) # ** could do xcor in a chain: after coaddlongaxes, # displ AB #1 CD #2 & measure 1-star offset, then # EHI #3 FGI #4 MLK #1 ON #2 TSP #3 URQ #4 VWX #1 # ** would allow all shifts to be done at once # --ideally would include multimasklet.cl instead of masklet.cl, # to identify & exclude spurious objects from bright star residuals. # ** interactively ident star resids? when? (& make bpms) # ** ideally want to ID star resids as you go thru the images in order # could do this in chainshift # but how to apply marked x,y to final objmask image? # ** if you have objmask and objmasknospur, want to tell it which single-letter # images take which object mask. # ** better write masklet to handle this. But will it make a diff? #get x,y for a bad pixel w/in area of a spurious object in the mask #imreplace x,y to good #get coords (listpix) of all bad pixels in x-1:x+1,y-1:y+1 # if none, end # if some, imreplace to good and repeat with xmin-1:xmax+1,ymin-1:ymax+1 # where the xmin:xmax,ymin:ymax spans the range of bad pixels # ** in pre-review: display xm=0.5 ym=0.5 with estimated offsets? # layout of MS0451 dither pattern & image pairings (long axis vertical): # BA EHI FGJ MLK URQ TSP (CD ON VWX) #A1 L12 K11 J10 ABC LEMDN KFG JIH OPQ RST #B2 E5/M13 F6 I9 #C3 D4/N14 G7 H8 # O15 # P16 # Q17 # R18 # S19 # T20 procedure onis0451(inlist,imageroot,niter) string inlist {prompt="List of input images"} string imageroot {prompt="Root name for output files"} int niter=1 {prompt="Number to append to output files"} string pairing="all" {enum="ABC|LEMDN|KFG|JIH|OPQ|RST|all",prompt="Pair of images to process (or all)"} bool inspect=yes {prompt="Inspect image lists before proceeding?"} bool shiftlongaxes=yes {prompt="Find shifts for image pairings w/overlapping long axes?"} bool coaddlongaxes=yes {prompt="Coadd image pairings w/overlapping long axes?"} bool nshiftall=yes {prompt="Find shifts between all image pairings?"} bool prereview {prompt="Display all image for pre-nshift check?"} bool p_tv {prompt="Use ptv instead of display for pre-nshift check?"} bool use_images=yes {prompt="Measure shifts from images (not file) in nshift?"} bool display_im=yes {prompt="Display images for imexam in nshift?"} bool edit_files=yes {prompt="Edit coords files after creation in nshift?"} bool exclude {prompt="Exclude any image pairings from first-pass nshift?"} string exstring {prompt="Enter code(s) for excluded pairing(s) separated by commas (ABC|LEMDN|KFG|JIH|OPQ|RST)"} bool redo=no {prompt="Redo shift-finding if already done?"} bool coaddallimages=yes {prompt="Coadd all images?"} bool secondpassxcor=yes {prompt="Cross-correlate all images with coadded image?"} bool coaddsecondpass=yes {prompt="Coadd images after second-pass cross-correlation?"} bool domkobjmask=yes {prompt="Make coadded-image object mask (INTERACTIVE)?"} bool domasklet=yes {prompt="Make individual-image object masks?"} string imextn="fits" {prompt="Image extension"} int xsize=512 {prompt="X-axis individual image size (0 for autosense)"} int ysize=1024 {prompt="Y-axis individual image size (0 for autosense)"} bool echog=yes {prompt="Beep when task is done?"} struct *list begin string in_list, image_root, p_air, ref_image, tmpheaders, sigprefix, rroundname string theory, method_shortaxes, tempfile2, msect, image_name, tempx, tempy string rvw_image, ex_string, current_string, future_string, in_string, im_extn string zero_out int xmin, ymin, xint, yint, old_xint, old_yint, xmax_bcad, xmin_fead, ix, iy int xmin_rstopq, xmax_rstopq, xrstopq, yrstopq, rstn1 int xmin_vwxopq, xmax_vwxopq, xvwxopq, yvwxopq, vwxn1 int xmin_jihkfg, xmax_jihkfg, xjihkfg, yjihkfg, jihn1 int xmin_ehikfg, xmax_ehikfg, xehikfg, yehikfg, ehin1 int n_iter, xbcad, ybcad, xfead, yfead, bcn1, fen1, x_shift, y_shift, xe, ye int xref, yref, int_x, int_y, junkint, ilen, ipos int oxdim, oydim # dimensions of mask image int ixdim, iydim # dimensions of individual input frames int xlemdnmost, ylemdnmost, xabcba, yabcba, xcdba, ycdba, xlemdnba, ylemdnba, xkfgba, ykfgba int xjihba, yjihba, xonba, yonba, xrstba, yrstba, xopqba, yopqba, xvwxba, yvwxba real abcba_xshiftexact, abcba_yshiftexact, lemdnmost_xshiftexact, lemdnmost_yshiftexact real cdba_xshiftexact, cdba_yshiftexact, lemdnba_xshiftexact, lemdnba_yshiftexact real kfgba_xshiftexact, kfgba_yshiftexact, jihba_xshiftexact, jihba_yshiftexact real onba_xshiftexact, onba_yshiftexact, rstba_xshiftexact, rstba_yshiftexact real opqba_xshiftexact, opqba_yshiftexact, vwxba_xshiftexact, vwxba_yshiftexact real xbcad2, ybcad2, xfead2, yfead2, bcad_x, bcad_y, fead_x, fead_y real xrstopq2, yrstopq2, rstopq_xlag, rstopq_ylag real xvwxopq2, yvwxopq2, vwxopq_xlag, vwxopq_ylag real xopq, yopq, xrst, yrst, xvwx, yvwx real xjihkfg2, yjihkfg2, jihkfg_xlag, jihkfg_ylag real xehikfg2, yehikfg2, ehikfg_xlag, ehikfg_ylag real xkfg, ykfg, xjih, yjih, xehi, yehi real xad, yad, xbc, ybc, xfe, yfe, bcad_xlag, bcad_ylag, fead_xlag, fead_ylag real bcad_xfirstpass, bcad_yfirstpass, fead_xfirstpass, fead_yfirstpass real rstopq_xfirstpass, rstopq_yfirstpass, vwxopq_xfirstpass, vwxopq_yfirstpass real jihkfg_xfirstpass, jihkfg_yfirstpass, ehikfg_xfirstpass, ehikfg_yfirstpass real xoff, yoff, step, new_x, new_y, old_x, old_y, step_x, step_y, xsig, ysig bool in_spect, shift_longaxes, echo_g, coadd_longaxes, abort, go, do_masklet bool coadd_allimages, xcor_secondpass, coadd_secondpass, do_mkobjmask, re_do bool im_display, images_use, shift_shortaxes, coadd_shortaxes, xreg_secondpass bool nshift_all, files_edit, ex_clude, pt_v, pre_review in_list=inlist image_root=imageroot n_iter=niter p_air=pairing in_spect=inspect shift_longaxes=shiftlongaxes images_use=use_images im_display=display_im files_edit=edit_files ex_string="" re_do=redo coadd_longaxes=coaddlongaxes nshift_all=nshiftall pre_review=prereview pt_v=p_tv coadd_allimages=coaddallimages xcor_secondpass=secondpassxcor coadd_secondpass=coaddsecondpass do_mkobjmask=domkobjmask do_masklet=domasklet im_extn=imextn echo_g=echog rroundname=image_root//".xregshifts.shall"//n_iter sigprefix=sigmanorm.prefix abcba_xshiftexact = 0; abcba_yshiftexact = 0; cdba_xshiftexact = 0 cdba_xshiftexact = 0; lemdnba_xshiftexact = 0; lemdnba_yshiftexact = 0 kfgba_xshiftexact = 0; kfgba_yshiftexact = 0; jihba_xshiftexact = 0 jihba_yshiftexact = 0; onba_xshiftexact = 0; onba_yshiftexact = 0 rstba_xshiftexact = 0; rstba_yshiftexact = 0; opqba_xshiftexact = 0 opqba_yshiftexact = 0; vwxba_xshiftexact = 0; vwxba_yshiftexact = 0 go=yes if(!defpac("imgtools")) {go=no} if(go) { # Separate input list into lists of images overlapping along long axes print ("\n===> Checking image pairing lists...") tmpheaders=mktemp("tmpheaders") hsel ("@"//in_list, "$I,i_title", yes, >> tmpheaders) if (!access(in_list//"_ABC")) { grep ('Position\ \ 1\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_ABC") grep ('Position\ \ 2\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_ABC") grep ('Position\ \ 3\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_ABC") grep ('Position\ \ 1\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_AB") grep ('Position\ \ 2\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_AB") grep ('Position\ \ 3\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_C") print (in_list//"_AB", >> "l_"//in_list//"_ABC") print (in_list//"_C", >> "l_"//in_list//"_ABC") } else { print (in_list//"_ABC already exists; not created.") } if (!access(in_list//"_JIH")) { grep ('Position\ 10\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_JIH") grep ('Position\ \ 9\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_JIH") grep ('Position\ \ 8\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_JIH") grep ('Position\ 10\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_JI") grep ('Position\ \ 9\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_JI") grep ('Position\ \ 8\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_H") print (in_list//"_JI", >> "l_"//in_list//"_JIH") print (in_list//"_H", >> "l_"//in_list//"_JIH") } else { print (in_list//"_JIH etc. already exist; not created.") } if (!access(in_list//"_KFG")) { grep ('Position\ 11\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_KFG") grep ('Position\ \ 6\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_KFG") grep ('Position\ \ 7\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_KFG") grep ('Position\ 11\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_KF") grep ('Position\ \ 6\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_KF") grep ('Position\ \ 7\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_G") print (in_list//"_KF", >> "l_"//in_list//"_KFG") print (in_list//"_G", >> "l_"//in_list//"_KFG") } else { print (in_list//"_KFG etc. already exist; not created.") } if (!access(in_list//"_LEMDN")) { grep ('Position\ 12\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_LEMDN") grep ('Position\ \ 5\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_LEMDN") grep ('Position\ 13\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_LEMDN") grep ('Position\ \ 4\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_LEMDN") grep ('Position\ 14\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_LEMDN") grep ('Position\ 12\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_LEM") grep ('Position\ \ 5\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_LEM") grep ('Position\ 13\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_LEM") grep ('Position\ \ 4\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_DN") grep ('Position\ 14\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_DN") print (in_list//"_LEM", >> "l_"//in_list//"_LEMDN") print (in_list//"_DN", >> "l_"//in_list//"_LEMDN") } else { print (in_list//"_LEMDN etc. already exist; not created.") } if (!access(in_list//"_RST")) { grep ('Position\ 18\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_RST") grep ('Position\ 19\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_RST") grep ('Position\ 20\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_RST") grep ('Position\ 18\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_RS") grep ('Position\ 19\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_RS") grep ('Position\ 20\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_T") print (in_list//"_RS", >> "l_"//in_list//"_RST") print (in_list//"_T", >> "l_"//in_list//"_RST") } else { print (in_list//"_RST etc. already exist; not created.") } if (!access(in_list//"_OPQ")) { grep ('Position\ 15\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_OPQ") grep ('Position\ 16\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_OPQ") grep ('Position\ 17\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_OPQ") grep ('Position\ 15\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_OP") grep ('Position\ 16\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_OP") grep ('Position\ 17\ of\ 20', tmpheaders) | fields ("junk", "1", lines="1-9999", >> in_list//"_Q") print (in_list//"_OP", >> "l_"//in_list//"_OPQ") print (in_list//"_Q", >> "l_"//in_list//"_OPQ") } else { print (in_list//"_OPQ etc. already exist; not created.") } del(tmpheaders,ver-) if (in_spect) vi (in_list//"_?? "//in_list//"_??? "//in_list//"_LEMDN") # Do irshift on lists of images overlapping along long axes if (shift_longaxes) { print("\n===> Finding shifts for image pairings overlapping along long axes...") if (p_air=="ABC" || p_air=="all") { fields (in_list//"_ABC", 1, lines="6-6") | scan (ref_image) if (!access(image_root//".roundoff.shABC"//n_iter)) { print("\n----> ABC: overlap region is the ENTIRE reference image; using nshift <----") nshift ("l_"//in_list//"_ABC", in_list//"_ABC", ref_image, image_root, "shABC"//n_iter, useimages=images_use, displayim=im_display, editfiles=files_edit) } } if (p_air=="LEMDN" || p_air=="all") { fields (in_list//"_LEMDN", 1, lines="6-6") | scan (ref_image) if (!access(image_root//".roundoff.shLEMDN"//n_iter)) { print("\n----> LEMDN: overlap region is the ENTIRE reference image; using nshift <----") nshift ("l_"//in_list//"_LEMDN", in_list//"_LEMDN", ref_image, image_root, "shLEMDN"//n_iter, useimages=images_use, displayim=im_display, editfiles=files_edit) } } if (p_air=="KFG" || p_air=="all") { fields (in_list//"_KFG", 1, lines="6-6") | scan (ref_image) if (!access(image_root//".roundoff.shKFG"//n_iter)) { print("\n----> KFG: overlap region is the ENTIRE reference image; using nshift <----") nshift ("l_"//in_list//"_KFG", in_list//"_KFG", ref_image, image_root, "shKFG"//n_iter, useimages=images_use, displayim=im_display, editfiles=files_edit) } } if (p_air=="JIH" || p_air=="all") { fields (in_list//"_JIH", 1, lines="6-6") | scan (ref_image) if (!access(image_root//".roundoff.shJIH"//n_iter)) { print("\n----> JIH: overlap region is the ENTIRE reference image; using nshift <----") nshift ("l_"//in_list//"_JIH", in_list//"_JIH", ref_image, image_root, "shJIH"//n_iter, useimages=images_use, displayim=im_display, editfiles=files_edit) } } if (p_air=="OPQ" || p_air=="all") { fields (in_list//"_OPQ", 1, lines="6-6") | scan (ref_image) if (!access(image_root//".roundoff.shOPQ"//n_iter)) { print("\n----> OPQ: overlap region is the ENTIRE reference image; using nshift <----") nshift ("l_"//in_list//"_OPQ", in_list//"_OPQ", ref_image, image_root, "shOPQ"//n_iter, useimages=images_use, displayim=im_display, editfiles=files_edit) } } if (p_air=="RST" || p_air=="all") { fields (in_list//"_RST", 1, lines="6-6") | scan (ref_image) if (!access(image_root//".roundoff.shRST"//n_iter)) { print("\n----> RST: overlap region is the ENTIRE reference image; using nshift <----") nshift ("l_"//in_list//"_RST", in_list//"_RST", ref_image, image_root, "shRST"//n_iter, useimages=images_use, displayim=im_display, editfiles=files_edit) } } } # Coadd images overlapping along long axes if (coadd_longaxes) { print ("\n===> Coadding image pairings overlapping along long axes...") if (p_air=="ABC" || p_air=="all") { imdel (image_root//"ABC"//n_iter, ver-, >& "dev$null") imdel (image_root//"ABC"//n_iter//"em", ver-, >& "dev$null") del (image_root//"ABC"//n_iter//".imshifts", ver-, >& "dev$null") imdel (sigprefix//image_root//"ABC"//n_iter, ver-, >& "dev$null") ircoadd (in_list//"_ABC", image_root//"ABC"//n_iter, "", image_root//".roundoff.shABC"//n_iter, "none", "mode", "none", 1, no, "log_"//image_root//"_allatonce", makeavg+, flip-) # sigmanorm (image_root//"ABC"//n_iter) } if (p_air=="LEMDN" || p_air=="all") { imdel (image_root//"LEMDN"//n_iter, ver-, >& "dev$null") imdel (image_root//"LEMDN"//n_iter//"em", ver-, >& "dev$null") del(image_root//"LEMDN"//n_iter//".imshifts", ver-, >& "dev$null") imdel(sigprefix//image_root//"LEMDN"//n_iter, ver-, >& "dev$null") ircoadd (in_list//"_LEMDN", image_root//"LEMDN"//n_iter, "", image_root//".roundoff.shLEMDN"//n_iter, "none", "mode", "none", 1, no, "log_"//image_root//"_allatonce", makeavg+, flip-) # sigmanorm (image_root//"LEMDN"//n_iter) } if (p_air=="KFG" || p_air=="all") { imdel (image_root//"KFG"//n_iter, ver-, >& "dev$null") imdel (image_root//"KFG"//n_iter//"em", ver-, >& "dev$null") del (image_root//"KFG"//n_iter//".imshifts", ver-, >& "dev$null") imdel (sigprefix//image_root//"KFG"//n_iter, ver-, >& "dev$null") ircoadd (in_list//"_KFG", image_root//"KFG"//n_iter, "", image_root//".roundoff.shKFG"//n_iter, "none", "mode", "none", 1, no, "log_"//image_root//"_allatonce", makeavg+, flip-) # sigmanorm (image_root//"KFG"//n_iter) } if (p_air=="JIH" || p_air=="all") { imdel (image_root//"JIH"//n_iter, ver-, >& "dev$null") imdel (image_root//"JIH"//n_iter//"em", ver-, >& "dev$null") del (image_root//"JIH"//n_iter//".imshifts", ver-, >& "dev$null") imdel (sigprefix//image_root//"JIH"//n_iter, ver-, >& "dev$null") ircoadd (in_list//"_JIH", image_root//"JIH"//n_iter, "", image_root//".roundoff.shJIH"//n_iter, "none", "mode", "none", 1, no, "log_"//image_root//"_allatonce", makeavg+, flip-) # sigmanorm (image_root//"JIH"//n_iter) } if (p_air=="OPQ" || p_air=="all") { imdel (image_root//"OPQ"//n_iter, ver-, >& "dev$null") imdel (image_root//"OPQ"//n_iter//"em", ver-, >& "dev$null") del (image_root//"OPQ"//n_iter//".imshifts", ver-, >& "dev$null") imdel (sigprefix//image_root//"OPQ"//n_iter, ver-, >& "dev$null") ircoadd (in_list//"_OPQ", image_root//"OPQ"//n_iter, "", image_root//".roundoff.shOPQ"//n_iter, "none", "mode", "none", 1, no, "log_"//image_root//"_allatonce", makeavg+, flip-) # sigmanorm (image_root//"OPQ"//n_iter) } if (p_air=="RST" || p_air=="all") { imdel (image_root//"RST"//n_iter, ver-, >& "dev$null") imdel (image_root//"RST"//n_iter//"em", ver-, >& "dev$null") del (image_root//"RST"//n_iter//".imshifts", ver-, >& "dev$null") imdel (sigprefix//image_root//"RST"//n_iter, ver-, >& "dev$null") ircoadd (in_list//"_RST", image_root//"RST"//n_iter, "", image_root//".roundoff.shRST"//n_iter, "none", "mode", "none", 1, no, "log_"//image_root//"_allatonce", makeavg+, flip-) # sigmanorm (image_root//"RST"//n_iter) } } # Find shifts between all image pairings if (p_air=="all" && nshift_all) { if (!access(image_root//".shiftexact.shall"//n_iter)) { # ** should test this out if (re_do) { del (image_root//".imshifts.shall*"//n_iter, ver-, >& "dev$null") del (image_root//".offsets.shall*"//n_iter, ver-, >& "dev$null") del (image_root//".roundoff.shall*"//n_iter, ver-, >& "dev$null") del (image_root//".shiftexact.shall*"//n_iter, ver-, >& "dev$null") del (image_root//".shiftfrac.shall*"//n_iter, ver-, >& "dev$null") del (image_root//".shiftint.shall*"//n_iter, ver-, >& "dev$null") del (image_root//".imshifts.shmost*"//n_iter, ver-, >& "dev$null") del (image_root//".offsets.shmost*"//n_iter, ver-, >& "dev$null") del (image_root//".roundoff.shmost*"//n_iter, ver-, >& "dev$null") del (image_root//".shiftexact.shmost*"//n_iter, ver-, >& "dev$null") del (image_root//".shiftfrac.shmost*"//n_iter, ver-, >& "dev$null") del (image_root//".shiftint.shmost*"//n_iter, ver-, >& "dev$null") print ("\n*allcoords*, *refcoords*, & *coarse* preserved; all else will be recreated.") } if (!access(in_list//"_coadd_"//n_iter)) { print (image_root//"ABC"//n_iter, >> in_list//"_coadd_"//n_iter) print (image_root//"LEMDN"//n_iter, >> in_list//"_coadd_"//n_iter) print (image_root//"KFG"//n_iter, >> in_list//"_coadd_"//n_iter) print (image_root//"JIH"//n_iter, >> in_list//"_coadd_"//n_iter) print (image_root//"OPQ"//n_iter, >> in_list//"_coadd_"//n_iter) print (image_root//"RST"//n_iter, >> in_list//"_coadd_"//n_iter) } # initial pre-review if (pre_review) { print ("Central image will be displayed in frame 1, and others in 2.") print ("Note any images that do not overlap the central image.") list=in_list//"_coadd_"//n_iter junkint = 1 while (fscan (list, rvw_image) !=EOF) { if (junkint==1) { if (pt_v) { ptv (rvw_image, frame=1) } else { display (rvw_image, frame=1) } } else { if (pt_v) { imexam (rvw_image, frame=2, keep-, display="ptv(image='$1',frame=2)") } else { display (rvw_image, junkint) imexam (rvw_image, frame=junkint, keep-, display="display(image='$1',frame=$2)") } } junkint = junkint + 1 if (junkint==5) junkint = 2 } } # exclude any images from nshift at first? print ("") ex_clude=exclude # if excluding any images: if (ex_clude) { # **redo here too? not a global redo, since need to get paramaters below for use in coadding del ("_coaddTmp?_", ver-, >& "dev$null") # get code(s) of excluded image(s) ex_string=exstring # create file of codes of images excluded from most-images coadd files (ex_string, >> "_coaddTmp1_") # create file of images included in most-images coadd copy (in_list//"_coadd_"//n_iter, "_coaddTmp2_", ver-) !fgrep -v -f _coaddTmp1_ _coaddTmp2_ > _coaddTmp3_ # **redo/!redo instead of delete & recreate? del (in_list//"_coaddmost_"//n_iter, ver-, >& "dev$null") rename ("_coaddTmp3_", in_list//"_coaddmost_"//n_iter, field="all", >& "dev$null") # create file of images included in full coadd # **redo/!redo instead of delete & recreate? del (in_list//"_coaddrest_"//n_iter, ver-, >& "dev$null") print (image_root//"LEMDN"//n_iter, > "_coaddTmp4_") !fgrep -f _coaddTmp1_ _coaddTmp2_ >> _coaddTmp4_ print (image_root//"most"//n_iter//"_1stpass", >> "_coaddTmp4_") type ("_coaddTmp4_", >> in_list//"_coaddrest_"//n_iter) # find shifts for most-images coadd # **redo here too? if (!access(image_root//".roundoff.shmost"//n_iter)) nshift ("", in_list//"_coaddmost_"//n_iter, image_root//"LEMDN"//n_iter, image_root, "shmost"//n_iter, redo=re_do, useimages=images_use, displayim=im_display, editfiles=files_edit) if (!access(image_root//".imshifts.shmost"//n_iter)) join (in_list//"_coaddmost_"//n_iter, image_root//".shiftexact.shmost"//n_iter, >> image_root//".imshifts.shmost"//n_iter) grep ("ABC", image_root//".imshifts.shmost"//n_iter) | scan (theory, abcba_xshiftexact, abcba_yshiftexact) grep ("LEMDN", image_root//".imshifts.shmost"//n_iter) | scan (theory, lemdnba_xshiftexact, lemdnba_yshiftexact) grep ("KFG", image_root//".imshifts.shmost"//n_iter) | scan (theory, kfgba_xshiftexact, kfgba_yshiftexact) grep ("JIH", image_root//".imshifts.shmost"//n_iter) | scan (theory, jihba_xshiftexact, jihba_yshiftexact) grep ("OPQ", image_root//".imshifts.shmost"//n_iter) | scan (theory, opqba_xshiftexact, opqba_yshiftexact) grep ("RST", image_root//".imshifts.shmost"//n_iter) | scan (theory, rstba_xshiftexact, rstba_yshiftexact) } else { # if not excluding any images: if (!access(image_root//".shiftexact.shall"//n_iter)) nshift ("", in_list//"_coadd_"//n_iter, image_root//"LEMDN"//n_iter, image_root, "shall"//n_iter, redo=re_do, useimages=images_use, displayim=im_display, editfiles=files_edit) fields(image_root//".shiftexact.shall"//n_iter,"1-2",lines="1-1")|scan(abcba_xshiftexact,abcba_yshiftexact) fields(image_root//".shiftexact.shall"//n_iter,"1-2",lines="2-2")|scan(lemdnba_xshiftexact,lemdnba_yshiftexact) fields(image_root//".shiftexact.shall"//n_iter,"1-2",lines="3-3")|scan(kfgba_xshiftexact,kfgba_yshiftexact) fields(image_root//".shiftexact.shall"//n_iter,"1-2",lines="4-4")|scan(jihba_xshiftexact,jihba_yshiftexact) fields(image_root//".shiftexact.shall"//n_iter,"1-2",lines="5-5")|scan(opqba_xshiftexact,opqba_yshiftexact) fields(image_root//".shiftexact.shall"//n_iter,"1-2",lines="6-6")|scan(rstba_xshiftexact,rstba_yshiftexact) } } if(abcba_xshiftexact>=0)xabcba=int(0.5+abcba_xshiftexact) if(abcba_yshiftexact>=0)yabcba=int(0.5+abcba_yshiftexact) if(abcba_xshiftexact<0)xabcba=int(-0.5+abcba_xshiftexact) if(abcba_yshiftexact<0)yabcba=int(-0.5+abcba_yshiftexact) if(lemdnba_xshiftexact>=0)xlemdnba=int(0.5+lemdnba_xshiftexact) if(lemdnba_yshiftexact>=0)ylemdnba=int(0.5+lemdnba_yshiftexact) if(lemdnba_xshiftexact<0)xlemdnba=int(-0.5+lemdnba_xshiftexact) if(lemdnba_yshiftexact<0)ylemdnba=int(-0.5+lemdnba_yshiftexact) if(kfgba_xshiftexact>=0)xkfgba=int(0.5+kfgba_xshiftexact) if(kfgba_yshiftexact>=0)ykfgba=int(0.5+kfgba_yshiftexact) if(kfgba_xshiftexact<0)xkfgba=int(-0.5+kfgba_xshiftexact) if(kfgba_yshiftexact<0)ykfgba=int(-0.5+kfgba_yshiftexact) if(jihba_xshiftexact>=0)xjihba=int(0.5+jihba_xshiftexact) if(jihba_yshiftexact>=0)yjihba=int(0.5+jihba_yshiftexact) if(jihba_xshiftexact<0)xjihba=int(-0.5+jihba_xshiftexact) if(jihba_yshiftexact<0)yjihba=int(-0.5+jihba_yshiftexact) if(rstba_xshiftexact>=0)xrstba=int(0.5+rstba_xshiftexact) if(rstba_yshiftexact>=0)yrstba=int(0.5+rstba_yshiftexact) if(rstba_xshiftexact<0)xrstba=int(-0.5+rstba_xshiftexact) if(rstba_yshiftexact<0)yrstba=int(-0.5+rstba_yshiftexact) if(opqba_xshiftexact>=0)xopqba=int(0.5+opqba_xshiftexact) if(opqba_yshiftexact>=0)yopqba=int(0.5+opqba_yshiftexact) if(opqba_xshiftexact<0)xopqba=int(-0.5+opqba_xshiftexact) if(opqba_yshiftexact<0)yopqba=int(-0.5+opqba_yshiftexact) } # coadd all images at once (w/intermediate most-image coadd if needed) if (p_air=="all" && coadd_allimages) { # first set minimum x,y offsets to be 0 & 0 (independently) if (!access(image_root//".roundoff.shABC"//n_iter//"min0")) { list=image_root//".roundoff.shABC"//n_iter xmin=9999; ymin=9999 while (fscan(list,xint,yint) !=EOF) { if (xint < xmin) xmin = xint if (yint < ymin) ymin = yint } filecalc(image_root//".roundoff.shABC"//n_iter, "$1-"//xmin//";$2-"//ymin, format="%4.0f %4.0f", >> image_root//".roundoff.shABC"//n_iter//"min0") } if (!access(image_root//".roundoff.shLEMDN"//n_iter//"min0")) { list=image_root//".roundoff.shLEMDN"//n_iter xmin=9999; ymin=9999 while (fscan(list,xint,yint) !=EOF) { if (xint < xmin) xmin = xint if (yint < ymin) ymin = yint } filecalc(image_root//".roundoff.shLEMDN"//n_iter, "$1-"//xmin//";$2-"//ymin, format="%4.0f %4.0f", >> image_root//".roundoff.shLEMDN"//n_iter//"min0") } if (!access(image_root//".roundoff.shKFG"//n_iter//"min0")) { list=image_root//".roundoff.shKFG"//n_iter xmin=9999; ymin=9999 while (fscan(list,xint,yint) !=EOF) { if (xint < xmin) xmin = xint if (yint < ymin) ymin = yint } filecalc(image_root//".roundoff.shKFG"//n_iter, "$1-"//xmin//";$2-"//ymin, format="%4.0f %4.0f", >> image_root//".roundoff.shKFG"//n_iter//"min0") } if (!access(image_root//".roundoff.shJIH"//n_iter//"min0")) { list=image_root//".roundoff.shJIH"//n_iter xmin=9999; ymin=9999 while (fscan(list,xint,yint) !=EOF) { if (xint < xmin) xmin = xint if (yint < ymin) ymin = yint } filecalc(image_root//".roundoff.shJIH"//n_iter, "$1-"//xmin//";$2-"//ymin, format="%4.0f %4.0f", >> image_root//".roundoff.shJIH"//n_iter//"min0") } if (!access(image_root//".roundoff.shOPQ"//n_iter//"min0")) { list=image_root//".roundoff.shOPQ"//n_iter xmin=9999; ymin=9999 while (fscan(list,xint,yint) !=EOF) { if (xint < xmin) xmin = xint if (yint < ymin) ymin = yint } filecalc(image_root//".roundoff.shOPQ"//n_iter, "$1-"//xmin//";$2-"//ymin, format="%4.0f %4.0f", >> image_root//".roundoff.shOPQ"//n_iter//"min0") } if (!access(image_root//".roundoff.shRST"//n_iter//"min0")) { list=image_root//".roundoff.shRST"//n_iter xmin=9999; ymin=9999 while (fscan(list,xint,yint) !=EOF) { if (xint < xmin) xmin = xint if (yint < ymin) ymin = yint } filecalc(image_root//".roundoff.shRST"//n_iter, "$1-"//xmin//";$2-"//ymin, format="%4.0f %4.0f", >> image_root//".roundoff.shRST"//n_iter//"min0") } # if not excluding any images: if (!exclude) { if(ex_string=="")ex_string=exstring # now offset by offsets to the central image (LEMDN) if(!access(in_list//"_all")) concat (in_list//"_ABC,"//in_list//"_LEMDN,"//in_list//"_KFG,"//in_list//"_JIH,"//in_list//"_OPQ,"//in_list//"_RST", in_list//"_all") if(!access(image_root//".roundoff.shall"//n_iter)) { filecalc(image_root//".roundoff.shABC"//n_iter//"min0","$1+"//xabcba//";$2+"//yabcba,format="%4.0f %4.0f", >> image_root//".roundoff.shall"//n_iter) filecalc(image_root//".roundoff.shLEMDN"//n_iter//"min0","$1+"//xlemdnba//";$2+"//ylemdnba,format="%4.0f %4.0f",>>image_root//".roundoff.shall"//n_iter) filecalc(image_root//".roundoff.shKFG"//n_iter//"min0","$1+"//xkfgba//";$2+"//ykfgba,format="%4.0f %4.0f", >> image_root//".roundoff.shall"//n_iter) filecalc(image_root//".roundoff.shJIH"//n_iter//"min0","$1+"//xjihba//";$2+"//yjihba,format="%4.0f %4.0f", >> image_root//".roundoff.shall"//n_iter) filecalc(image_root//".roundoff.shOPQ"//n_iter//"min0","$1+"//xopqba//";$2+"//yopqba,format="%4.0f %4.0f", >> image_root//".roundoff.shall"//n_iter) filecalc(image_root//".roundoff.shRST"//n_iter//"min0","$1+"//xrstba//";$2+"//yrstba,format="%4.0f %4.0f", >> image_root//".roundoff.shall"//n_iter) } # do the coadd print ("\n===> Coadding all images at once...") ircoadd (in_list//"_all", image_root//"all"//n_iter//"_1stpass", "", image_root//".roundoff.shall"//n_iter, "none", "mode", "none", 1, no, "log_"//in_list//"_all", stdpars-, makeavg+, flip-, imcoaddpars="phiirs$ircoaddonis.par") # if excluding any images: } else { if(!access(in_list//"_most")) { # create list of all image lists print (in_list//"_ABC\n"//in_list//"_LEMDN\n"//in_list//"_KFG\n"//in_list//"_JIH\n"//in_list//"_OPQ\n"//in_list//"_RST", > "_coaddTmp5_") # create list of all image lists to be included in coadd !fgrep -v -f _coaddTmp1_ _coaddTmp5_ > _coaddTmp6_ concat ("@_coaddTmp6_", in_list//"_most") } # offset the shift lists of all the images to be included in the coadd # by their offsets to the central image (LEMDN) if(!access(image_root//".1stpass.shmost"//n_iter)) { # create list of codes of all image lists print ("ABC\nLEMDN\nKFG\nJIH\nOPQ\nRST", > "_coaddTmp7_") # create list of codes of all image lists to be included in coadd !fgrep -v -f _coaddTmp1_ _coaddTmp7_ > _coaddTmp8_ list = "_coaddTmp8_" while (fscan (list, in_string) !=EOF) { if (in_string=="ABC") { filecalc (image_root//".roundoff.shABC"//n_iter//"min0", "$1+"//xabcba//";$2+"//yabcba, format="%4.0f %4.0f", >> image_root//".1stpass.shmost"//n_iter) } else if (in_string=="LEMDN") { filecalc (image_root//".roundoff.shLEMDN"//n_iter//"min0", "$1+"//xlemdnba//";$2+"//ylemdnba, format="%4.0f %4.0f", >> image_root//".1stpass.shmost"//n_iter) } else if (in_string=="KFG") { filecalc (image_root//".roundoff.shKFG"//n_iter//"min0", "$1+"//xkfgba//";$2+"//ykfgba, format="%4.0f %4.0f", >> image_root//".1stpass.shmost"//n_iter) } else if (in_string=="JIH") { filecalc (image_root//".roundoff.shJIH"//n_iter//"min0", "$1+"//xjihba//";$2+"//yjihba, format="%4.0f %4.0f", >> image_root//".1stpass.shmost"//n_iter) } else if (in_string=="OPQ") { filecalc (image_root//".roundoff.shOPQ"//n_iter//"min0", "$1+"//xopqba//";$2+"//yopqba, format="%4.0f %4.0f", >> image_root//".1stpass.shmost"//n_iter) } else if (in_string=="RST") { filecalc (image_root//".roundoff.shRST"//n_iter//"min0", "$1+"//xrstba//";$2+"//yrstba, format="%4.0f %4.0f", >> image_root//".1stpass.shmost"//n_iter) } } del ("_coaddTmp?_", ver-, >& "dev$null") } # do the most-images coadd if (!access(image_root//"most"//n_iter//"_1stpass."//im_extn)) { print ("\n===> Coadding most images at once...") ircoadd (in_list//"_most", image_root//"most"//n_iter//"_1stpass", "", image_root//".1stpass.shmost"//n_iter, "none", "mode", "none", 1, no, "log_"//in_list//"_all", stdpars-, makeavg+, flip-, imcoaddpars="phiirs$ircoaddonis.par") } # do nshift on most-images coadd if (!access(image_root//".roundoff.shrest"//n_iter)) nshift ("", in_list//"_coaddrest_"//n_iter, image_root//"most"//n_iter//"_1stpass", image_root, "shrest"//n_iter, redo=re_do, useimages=images_use, displayim=im_display, editfiles=files_edit) # get shifts for images excluded from most-images coadd if (!access(image_root//".imshifts.shrest"//n_iter)) join(in_list//"_coaddrest_"//n_iter,image_root//".shiftexact.shrest"//n_iter, >>image_root//".imshifts.shrest"//n_iter) grep("LEMDN",image_root//".imshifts.shrest"//n_iter)|scan(theory, lemdnmost_xshiftexact, lemdnmost_yshiftexact) if(lemdnmost_xshiftexact>=0)xlemdnmost=int(0.5+lemdnmost_xshiftexact) if(lemdnmost_yshiftexact>=0)ylemdnmost=int(0.5+lemdnmost_yshiftexact) if(lemdnmost_xshiftexact<0)xlemdnmost=int(-0.5+lemdnmost_xshiftexact) if(lemdnmost_yshiftexact<0)ylemdnmost=int(-0.5+lemdnmost_yshiftexact) if (stridx(ex_string,"ABC")!=0) { grep("ABC",image_root//".imshifts.shrest"//n_iter)|scan(theory, abcba_xshiftexact, abcba_yshiftexact) if(abcba_xshiftexact>=0)xabcba=int(0.5+abcba_xshiftexact)-xlemdnmost if(abcba_yshiftexact>=0)yabcba=int(0.5+abcba_yshiftexact)-ylemdnmost if(abcba_xshiftexact<0)xabcba=int(-0.5+abcba_xshiftexact)-xlemdnmost if(abcba_yshiftexact<0)yabcba=int(-0.5+abcba_yshiftexact)-ylemdnmost } if (stridx(ex_string,"LEMDN")!=0) { grep("LEMDN",image_root//".imshifts.shrest"//n_iter)|scan(theory,lemdnba_xshiftexact,lemdnba_yshiftexact) if(lemdnba_xshiftexact>=0)xlemdnba=int(0.5+lemdnba_xshiftexact)-xlemdnmost if(lemdnba_yshiftexact>=0)ylemdnba=int(0.5+lemdnba_yshiftexact)-ylemdnmost if(lemdnba_xshiftexact<0)xlemdnba=int(-0.5+lemdnba_xshiftexact)-xlemdnmost if(lemdnba_yshiftexact<0)ylemdnba=int(-0.5+lemdnba_yshiftexact)-ylemdnmost } if (stridx(ex_string,"KFG")!=0) { grep("KFG",image_root//".imshifts.shrest"//n_iter)|scan(theory,kfgba_xshiftexact,kfgba_yshiftexact) if(kfgba_xshiftexact>=0)xkfgba=int(0.5+kfgba_xshiftexact)-xlemdnmost if(kfgba_yshiftexact>=0)ykfgba=int(0.5+kfgba_yshiftexact)-ylemdnmost if(kfgba_xshiftexact<0)xkfgba=int(-0.5+kfgba_xshiftexact)-xlemdnmost if(kfgba_yshiftexact<0)ykfgba=int(-0.5+kfgba_yshiftexact)-ylemdnmost } if (stridx(ex_string,"JIH")!=0) { grep("JIH",image_root//".imshifts.shrest"//n_iter)|scan(theory,jihba_xshiftexact,jihba_yshiftexact) if(jihba_xshiftexact>=0)xjihba=int(0.5+jihba_xshiftexact)-xlemdnmost if(jihba_yshiftexact>=0)yjihba=int(0.5+jihba_yshiftexact)-ylemdnmost if(jihba_xshiftexact<0)xjihba=int(-0.5+jihba_xshiftexact)-xlemdnmost if(jihba_yshiftexact<0)yjihba=int(-0.5+jihba_yshiftexact)-ylemdnmost } if (stridx(ex_string,"OPQ")!=0) { grep("OPQ",image_root//".imshifts.shrest"//n_iter)|scan(theory,opqba_xshiftexact,opqba_yshiftexact) if(opqba_xshiftexact>=0)xopqba=int(0.5+opqba_xshiftexact)-xlemdnmost if(opqba_yshiftexact>=0)yopqba=int(0.5+opqba_yshiftexact)-ylemdnmost if(opqba_xshiftexact<0)xopqba=int(-0.5+opqba_xshiftexact)-xlemdnmost if(opqba_yshiftexact<0)yopqba=int(-0.5+opqba_yshiftexact)-ylemdnmost } if (stridx(ex_string,"RST")!=0) { grep("RST",image_root//".imshifts.shrest"//n_iter)|scan(theory,rstba_xshiftexact,rstba_yshiftexact) if(rstba_xshiftexact>=0)xrstba=int(0.5+rstba_xshiftexact)-xlemdnmost if(rstba_yshiftexact>=0)yrstba=int(0.5+rstba_yshiftexact)-ylemdnmost if(rstba_xshiftexact<0)xrstba=int(-0.5+rstba_xshiftexact)-xlemdnmost if(rstba_yshiftexact<0)yrstba=int(-0.5+rstba_yshiftexact)-ylemdnmost } # now offset by offsets to the central image (LEMDN) if(!access(in_list//"_all")) concat (in_list//"_ABC,"//in_list//"_LEMDN,"//in_list//"_KFG,"//in_list//"_JIH,"//in_list//"_OPQ,"//in_list//"_RST", in_list//"_all") if(!access(image_root//".1stpass.shall"//n_iter)) { filecalc (image_root//".roundoff.shABC"//n_iter//"min0", "$1+"//xabcba//";$2+"//yabcba, format="%4.0f %4.0f", >> image_root//".1stpass.shall"//n_iter) filecalc (image_root//".roundoff.shLEMDN"//n_iter//"min0", "$1+"//xlemdnba//";$2+"//ylemdnba, format="%4.0f %4.0f", >> image_root//".1stpass.shall"//n_iter) filecalc (image_root//".roundoff.shKFG"//n_iter//"min0", "$1+"//xkfgba//";$2+"//ykfgba, format="%4.0f %4.0f", >> image_root//".1stpass.shall"//n_iter) filecalc (image_root//".roundoff.shJIH"//n_iter//"min0", "$1+"//xjihba//";$2+"//yjihba, format="%4.0f %4.0f", >> image_root//".1stpass.shall"//n_iter) filecalc (image_root//".roundoff.shOPQ"//n_iter//"min0", "$1+"//xopqba//";$2+"//yopqba, format="%4.0f %4.0f", >> image_root//".1stpass.shall"//n_iter) filecalc (image_root//".roundoff.shRST"//n_iter//"min0", "$1+"//xrstba//";$2+"//yrstba, format="%4.0f %4.0f", >> image_root//".1stpass.shall"//n_iter) } # do the full coadd print ("\n===> Coadding all images at once...") ircoadd (in_list//"_all", image_root//"all"//n_iter//"_1stpass", "", image_root//".1stpass.shall"//n_iter, "none", "mode", "none", 1, no, "log_"//in_list//"_all", stdpars-, makeavg+, flip-, imcoaddpars="phiirs$ircoaddonis.par") } } # cross-correlate individual images with coadded image if (p_air=="all" && xcor_secondpass) { ixdim=xsize; iydim=ysize if(!access(sigprefix//image_root//"all"//n_iter//"_1stpass."//im_extn)){ print ("\n===> Creating constant-RMS coadded image...") sigmanorm(image_root//"all"//n_iter//"_1stpass."//im_extn) } imgets(sigprefix//image_root//"all"//n_iter//"_1stpass","i_naxis1") oxdim=int(imgets.value) imgets(sigprefix//image_root//"all"//n_iter//"_1stpass","i_naxis2") oydim=int(imgets.value) list=image_root//"all"//n_iter//"_1stpass.imshifts" if (!access(image_root//"all"//n_iter//"_xregout")) { print("\n===> Cross-correlating individual images w/coadded image...") while (fscan(list,image_name,x_shift,y_shift) !=EOF) { # zero out bad pixels if not already done imgets(image_name,"ZEROOUT") zero_out=imgets.value if(zero_out=="0"){ imgets(image_name,"BPMASK") if(imgets.value!="0"){ imar(image_name,"*",imgets.value,image_name,pixt="real",calct="real",ver-,noac-) hedit(image_name,"ZEROOUT",imgets.value,add+,ver-,show-,update+) } else { print("Bad pixels not zeroed for "//image_name//", and no BP mask in header!") } } if(xsize==0){ imgets(image_name,"i_naxis1") ixdim=int(imgets.value) } if(ysize==0){ imgets(image_name,"i_naxis2") iydim=int(imgets.value) } ix=x_shift+1-14; if(ix<1)ix=1 iy=y_shift+1-14; if(iy<1)iy=1 xe=x_shift + ixdim + 14; if(xe>oxdim)xe=oxdim ye=y_shift + iydim + 14; if(ye>oydim)ye=oydim msect = "["//ix//":"//xe//","//iy//":"//ye//"]" print ("Rough shift from "//image_name//" to "//sigprefix//image_root//"all"//n_iter//"_1stpass is "//x_shift//" "//y_shift//" pixels") immatch.xreg (image_name, sigprefix//image_root//"all"//n_iter//"_1stpass", msect, image_root//"all"//n_iter//"_xregout", datab+, records="", xlag=-1*x_shift, ylag=-1*y_shift, xwindow=25, ywindow=25, append+) } } tempx = mktemp("tempx"); tempy = mktemp("tempy") grep ('xshift', image_root//"all"//n_iter//"_xregout") | fields ("junk", "2", >> tempx) grep ('yshift', image_root//"all"//n_iter//"_xregout") | fields ("junk", "2", >> tempy) if(!access(image_root//".xregexact.shall"//n_iter)) join (tempx, tempy, output=image_root//".xregexact.shall"//n_iter) del (tempx, ver-); del (tempy, ver-) # Create optimum rounded-off integer offsets if (!access(rroundname)) { print("\n===> Finding optimum second-pass rounded-off integer offsets...") old_x = 999.; old_y = 999. # for each 0.01 pixel step... for (i=-50; i<50; i+=1) { step = i / 100. # print (i) # ...recalculate integer offsets... list=image_root//".xregexact.shall"//n_iter del (rroundname, ver-, >& "dev$null") while(fscan(list,xoff,yoff) !=EOF) { xoff=xoff+step yoff=yoff+step if(((abs(xoff))>=0.5) && ((abs(yoff))>=0.5)) { print(xoff,yoff, >> "temp."//rroundname) } else { if((abs(xoff))<=0.5) { xoff=0. } if((abs(yoff))<=0.5) { yoff=0. } print(xoff,yoff, >> "temp."//rroundname) } filecalc("temp."//rroundname, "$1;$2", format="%4.0f %4.0f", >> rroundname) flpr; flpr; flpr del ("temp."//rroundname, ver-, >& "dev$null") } del ("temp."//rroundname, ver-, >& "dev$null") # calculate sum of squares of residuals of exact offsets - new integer offsets filecalc (image_root//".xregexact.shall"//n_iter//","//rroundname, "$1@1-$1@2+"//step) | average (option = "new_sample", >& "dev$null") flpr; flpr; flpr new_x=average.sumsqrs filecalc (image_root//".xregexact.shall"//n_iter//","//rroundname, "$2@1-$2@2+"//step) | average (option = "new_sample", >& "dev$null") flpr; flpr; flpr new_y=average.sumsqrs if (new_x < old_x) { old_x = new_x step_x = step } if (new_y < old_y) { old_y = new_y step_y = step } } # recalculate final integer offsets list=image_root//".xregexact.shall"//n_iter del(rroundname,ver-) del ("temp."//rroundname, ver-, >& "dev$null") while(fscan(list,xoff,yoff) !=EOF) { xoff=xoff+step_x yoff=yoff+step_y if(((abs(xoff))>=0.5) && ((abs(yoff))>=0.5)) { print(xoff,yoff, >> "temp."//rroundname) } else { if((abs(xoff))<=0.5) { xoff=0. } if((abs(yoff))<=0.5) { yoff=0. } print(xoff,yoff, >> "temp."//rroundname) } filecalc("temp."//rroundname,"$1;$2",format="%4.0f %4.0f",>>rroundname) flpr; flpr; flpr del ("temp."//rroundname, ver-, >& "dev$null") } del ("temp."//rroundname, ver-, >& "dev$null") } del ("temp."//rroundname, ver-, >& "dev$null") filecalc (rroundname//","//image_root//".1stpass.shall"//n_iter, "$1@1-$1@2", lines="1-") | average filecalc (rroundname//","//image_root//".1stpass.shall"//n_iter, "$1@1-$1@2-"//average.mean, lines="1-", >> "temp."//rroundname) filecalc (rroundname//","//image_root//".1stpass.shall"//n_iter, "$2@1-$2@2", lines="1-") | average filecalc (rroundname//","//image_root//".1stpass.shall"//n_iter, "$2@1-$2@2-"//average.mean, lines="1-", >> "temp."//rroundname) graph ("temp."//rroundname, point-, title="mean-subtracted 2ndpass - 1stpass x and y offsets") del ("temp."//rroundname, ver-, >& "dev$null") } # Coadd images after second-pass cross-correlation if (p_air=="all" && coadd_secondpass) { print ("\n===> Coadding after second-pass cross-correlation...") ircoadd(in_list//"_all", image_root//"all"//n_iter, "", rroundname, "none", "mode", "none", 1, no, "log_"//in_list//"_all", stdpars-, makeavg-, flip-, imcoaddpars="phiirs$ircoaddonis.par") # ircoadd(in_list//"_all", image_root//"all"//n_iter//"avg", "", rroundname, "none", "mode", "none", 1, no, "log_"//in_list//"_all", stdpars-, makeavg+, flip-, imcoaddpars="phiirs$ircoaddonis.par") } # Make coadded-image object mask if (p_air=="all" && do_mkobjmask) { print ("\n===> Making coadded-image object mask...") mkobjmask (image_root//"all"//n_iter//"."//im_extn, "", suffix="objmask", nsmooth=3, subsample=3, filtsize=15, ngrow=1, interact+) } # Make individual-image object masks if (p_air=="all" && do_masklet) { print ("\n===> Making individual-image object masks...") masklet (image_root//"all"//n_iter, "", "om", shiftfile="", editfile+, flip-, update+) } } else { print ("\nWARNING! Package stsdas.imgtools not loaded... task aborted.") } if (echo_g) beep end ./irtfcoadd_3.p0100644000151400000240000000044306427031106012523 0ustar phallgames#!/usr/local/bin/perl -w # cycle thru contents of file(s) given on command line using <> while (<>) { # skip blank lines or lines with # as first non-whitespace character next if (/^\s+$/ or /^#/ or /^\s+#/); ($one, $two) = split " "; printf "%4.0f%4.0f\n", $one, $two; } ./sqiidfirst.cl0100644000151400000240000003265007254743537012710 0ustar phallgames# sqiidfirst.cl -- task to subtract dark & add header params to SQIID images # # 1. hedit image headers, adding: (basically this task is hadd.cl plus #0) # 1. BPM,BPMASK = bad pixel mask name # 2. GAIN,RDNOISE if not present (currently assumes 10.,40.) # 3. coadds = number of coadds (copy of ncoadds) # 4. itime,exptime = exposure time per coadd (old exptime) # and total exposure time (itime * coadds) # 5. obs-date = date-obs but in dd/mm/yy format # 6. date-obs = yyyy-mm-dd format (old date-obs saved as dateorig) # 2. optionally subtract dark # 3. optionally reorient so N up and E left # # 000521: created SQIID version # 000528: added REORIENT & changed so DARKSUB can be done for all filters at once # # **add undo-REORIENT step # **refuse to mix images w/ & w/o REORIENT header keyword procedure sqiidfirst(imagelist,darksub,bpmj,bpmh,bpmk,bpml) string imagelist {prompt="List of images to process (do not use an `@')"} bool darksub=no {prompt="Subtract off dark frame?"} string bpmj {prompt="Name of bad pixel mask to add to J image headers"} string bpmh {prompt="Name of bad pixel mask to add to H image headers"} string bpmk {prompt="Name of bad pixel mask to add to K image headers"} string bpml {prompt="Name of bad pixel mask to add to L image headers"} string darkj {prompt="Name of the J dark frame to subtract", mode="q"} string darkh {prompt="Name of the H dark frame to subtract", mode="q"} string darkk {prompt="Name of the K dark frame to subtract", mode="q"} string darkl {prompt="Name of the L dark frame to subtract", mode="q"} string darkstring {prompt="String to append to dark-subtracted images",mode="q"} string observatory="kpno" {prompt="Observatory where observations were made"} bool ddmmyy=yes {prompt="Is 'date-obs' in day/month/year format?"} bool orient=yes {prompt="Reorient so N is up and E is at left"} bool echog {yes,prompt="Beep when task is done?"} struct *list begin string ddark, ddarkstring, bbadmask, check, base, iimagelist, ext string jdark, hdark, kdark, ldark, jbadmask, hbadmask, kbadmask, lbadmask string darklist, flat, flatbase, meanfile, currentflat, tempflat, name string editlist, current, obsdate, rra, ddec, eepoch, oobservatory, minsec string obstime, timeobs, dateobs, century, channel real intime, aairval, ttime, mean, meanbad, x int ncoadd, ddy, hhr, hhour, mmonth, yyear, dday, uttime, last2digits bool ddarksub, ccoords, aairauto, uut, aairmass, oorient iimagelist = imagelist list = iimagelist editlist = iimagelist ddarksub = darksub jbadmask = bpmj hbadmask = bpmh kbadmask = bpmk lbadmask = bpml if (ddarksub) { jdark = darkj hdark = darkh kdark = darkk ldark = darkl ddarkstring = darkstring darklist = iimagelist//ddarkstring } oobservatory = observatory oorient=orient # Add BPM and other goodies to the image headers, just like in the hadd.cl task print("===> Adding various parameters to the image headers...") list = iimagelist while (fscan (list, current) !=EOF) { # Currently assumes gain=10, rdnoise=40 imgets(current,"GAIN", >& "dev$null") if (imgets.value=="0" || imgets.value=="") { hedit(current,"GAIN","10.",add+,ver-,show+,updat+) } imgets(current,"RDNOISE", >& "dev$null") if (imgets.value=="0" || imgets.value=="") { hedit(current,"RDNOISE","40.",add+,ver-,show+,updat+) } # Get channel (j or h or k or l) imgets(current,"channel", >& "dev$null") channel=imgets.value # J ---------------------------------------------------------------------------- if (channel=="j") { hedit(current,"BPM",jbadmask,add+,ver-,show+,update+) hedit(current,"BPMASK",jbadmask,add+,ver-,show+,update+) # Set coadds=(# of coadds) imgets(current,"coaddsj", >& "dev$null") ncoadd=real(imgets.value) hedit(current,"coadds",(ncoadd),add+,ver-,show+,update+) # Set itime=exposure time per coadd imgets(current,"itime", >& "dev$null") if (imgets.value!="0") { print ("ITIME keyword already exists -- sqiidfirst already run on image?") } else { imgets(current,"int_sj", >& "dev$null") intime=real(imgets.value) hedit(current,"itime",(intime),add+,ver-,show+,update+) # Set exptime=itime * (# of coadds) hedit(current,"exptime",(ncoadd*intime),add+,ver-,show+,update+) } # H ---------------------------------------------------------------------------- } else if (channel=="h") { hedit(current,"BPM",hbadmask,add+,ver-,show+,update+) hedit(current,"BPMASK",hbadmask,add+,ver-,show+,update+) # Set coadds=(# of coadds) imgets(current,"coaddsh", >& "dev$null") ncoadd=real(imgets.value) hedit(current,"coadds",(ncoadd),add+,ver-,show+,update+) # Set itime=exposure time per coadd imgets(current,"itime", >& "dev$null") if (imgets.value!="0") { print ("ITIME keyword already exists -- sqiidfirst already run on image?") } else { imgets(current,"int_sh", >& "dev$null") intime=real(imgets.value) hedit(current,"itime",(intime),add+,ver-,show+,update+) # Set exptime=itime * (# of coadds) hedit(current,"exptime",(ncoadd*intime),add+,ver-,show+,update+) } # K ---------------------------------------------------------------------------- } else if (channel=="k") { hedit(current,"BPM",kbadmask,add+,ver-,show+,update+) hedit(current,"BPMASK",kbadmask,add+,ver-,show+,update+) # Set coadds=(# of coadds) imgets(current,"coaddsk", >& "dev$null") ncoadd=real(imgets.value) hedit(current,"coadds",(ncoadd),add+,ver-,show+,update+) # Set itime=exposure time per coadd imgets(current,"itime", >& "dev$null") if (imgets.value!="0") { print ("ITIME keyword already exists -- sqiidfirst already run on image?") } else { imgets(current,"int_sk", >& "dev$null") intime=real(imgets.value) hedit(current,"itime",(intime),add+,ver-,show+,update+) # Set exptime=itime * (# of coadds) hedit(current,"exptime",(ncoadd*intime),add+,ver-,show+,update+) } # L ---------------------------------------------------------------------------- } else if (channel=="l") { hedit(current,"BPM",lbadmask,add+,ver-,show+,update+) hedit(current,"BPMASK",lbadmask,add+,ver-,show+,update+) # Set coadds=(# of coadds) imgets(current,"coaddsl", >& "dev$null") ncoadd=real(imgets.value) hedit(current,"coadds",(ncoadd),add+,ver-,show+,update+) # Set itime=exposure time per coadd imgets(current,"itime", >& "dev$null") if (imgets.value!="0") { print ("ITIME keyword already exists -- sqiidfirst already run on image?") } else { imgets(current,"int_sl", >& "dev$null") intime=real(imgets.value) hedit(current,"itime",(intime),add+,ver-,show+,update+) # Set exptime=itime * (# of coadds) hedit(current,"exptime",(ncoadd*intime),add+,ver-,show+,update+) } } # # The 'date-obs' keyword comes in either the old format "dd/mm/yy", # the erroneous format "mm/dd/yy", or the new format "yyyy-mm-dd". # Create new 'date-obs' keyword in the new format "yyyy-mm-dd". imgets(current,"dateorig") if (imgets.value!="0") { print ("DATEORIG keyword already exists -- sqiidfirst already run on image?") } else { imgets(current,"date-obs") # Copy 'date-obs' keyword to 'dateorig' in original format. hedit(current,"dateorig",imgets.value,add+,ver-,show+,update+) # Create header keyword 'obs-date', always in "dd/mm/yy" format. if(!ddmmyy){ # mm/dd/yy format: if(substr(imgets.value,3,3)=="/") { obsdate=substr(imgets.value,4,6)//substr(imgets.value,1,3)//substr(imgets.value,7,8) } else { # yyyy-mm-dd format: # 1234567890 obsdate=substr(imgets.value,9,10)//"/"//substr(imgets.value,6,7)//"/"//substr(imgets.value,3,4) } # create obs-date if date-obs in mm/dd/yy or yyyy-mm-dd format: hedit(current,"obs-date",obsdate,add+,ver-,show+,update+) } else { # create obs-date if date-obs in dd/mm/yy format: hedit(current,"obs-date",imgets.value,add+,ver-,show+,update+) } # Create new 'date-obs' in new format "yyyy-mm-dd" from 'obs-date' "dd/mm/yy" # 12345678 imgets(current,"obs-date") if ((substr(imgets.value,7,7))=="9") { century=19 } else { century=20 } dateobs=century//substr(imgets.value,7,8)//"-"//substr(imgets.value,4,5)//"-"//substr(imgets.value,1,2) hedit(current,"date-obs",dateobs,add+,ver-,show+,update+) # } } # Subtract off Dark Current (and reorient dark-subtracted images, if desired) if (ddarksub) { list = iimagelist # if darklist doesn't exist, assume dsub imgs don't either; create it & dsubs if(!access(darklist)) { print("===> Subtracting off Dark Current...") while (fscan (list, name) !=EOF) { fileroot(name,validim+) base=fileroot.root ext=fileroot.extension if(ext!="")ext="."//ext print(base//ddarkstring//ext, >> darklist) # Get channel (j or h or k or l) imgets(name,"channel", >& "dev$null") channel=imgets.value imgets(name,"DARKSUB", >& "dev$null") if (imgets.value=="0") { # J ---------------------------------------------------------------------------- if (channel=="j") { imarith(name,"-",jdark,base//ddarkstring//ext,verbose-) hedit(base//ddarkstring//ext,"DARKSUB",jdark,add+,ver-,show+,update+) if (oorient) { imgets(name,"REORIENT", >& "dev$null") if (imgets.value=="0") { imtranspose(base//ddarkstring//ext,base//ddarkstring//ext) hedit(base//ddarkstring//ext,"REORIENT","yes",add+,ver-,show+,update+) } else { print("REORIENT keyword exists; sqiidfirst already run?") } } # H ---------------------------------------------------------------------------- } else if (channel=="h") { imarith(name,"-",hdark,base//ddarkstring//ext,verbose-) hedit(base//ddarkstring//ext,"DARKSUB",hdark,add+,ver-,show+,update+) if (oorient) { imgets(name,"REORIENT", >& "dev$null") if (imgets.value=="0") { imcopy(base//ddarkstring//ext//"[-*,*]",base//ddarkstring//ext,ver-) hedit(base//ddarkstring//ext,"REORIENT","yes",add+,ver-,show+,update+) } else { print("REORIENT keyword exists; sqiidfirst already run?") } } # K ---------------------------------------------------------------------------- } else if (channel=="k") { imarith(name,"-",kdark,base//ddarkstring//ext,verbose-) hedit(base//ddarkstring//ext,"DARKSUB",kdark,add+,ver-,show+,update+) if (oorient) { imgets(name,"REORIENT", >& "dev$null") if (imgets.value=="0") { imcopy(base//ddarkstring//ext//"[*,-*]",base//ddarkstring//ext,ver-) hedit(base//ddarkstring//ext,"REORIENT","yes",add+,ver-,show+,update+) } else { print("REORIENT keyword exists; sqiidfirst already run?") } } # L ---------------------------------------------------------------------------- } else if (channel=="l") { imarith(name,"-",ldark,base//ddarkstring//ext,verbose-) hedit(base//ddarkstring//ext,"DARKSUB",ldark,add+,ver-,show+,update+) if (oorient) { imgets(name,"REORIENT", >& "dev$null") if (imgets.value=="0") { print ("WARNING! raw orientation of L unknown.") # hedit(name,"REORIENT","yes",add+,ver-,show+,update+) } else { print("REORIENT keyword exists; sqiidfirst already run?") } } } } else { print("DARKSUB keyword exists; sqiidfirst already run? "//name//" just copied") imcopy(name, base//ddarkstring//ext, verbose-) } } } else { print("Darksubbed image list "//darklist//" already exists; images assumed to exist too.") } print(" ") print("===> Dark-subtracted images are listed in the file "//darklist//".") } # Reorient original images if (oorient) { list = iimagelist while (fscan (list, name) !=EOF) { # Get channel (j or h or k or l) imgets(name,"channel", >& "dev$null") channel=imgets.value # J ---------------------------------------------------------------------------- if (channel=="j") { imgets(name,"REORIENT", >& "dev$null") if (imgets.value=="0") { imtranspose (name, name) hedit(name,"REORIENT","yes",add+,ver-,show+,update+) } else { print("REORIENT keyword exists; sqiidfirst already run?") } # H ---------------------------------------------------------------------------- } else if (channel=="h") { imgets(name,"REORIENT", >& "dev$null") if (imgets.value=="0") { imcopy (name//"[-*,*]", name, ver-) hedit(name,"REORIENT","yes",add+,ver-,show+,update+) } else { print("REORIENT keyword exists; sqiidfirst already run?") } # K ---------------------------------------------------------------------------- } else if (channel=="k") { imgets(name,"REORIENT", >& "dev$null") if (imgets.value=="0") { imcopy (name//"[*,-*]", name, ver-) hedit(name,"REORIENT","yes",add+,ver-,show+,update+) } else { print("REORIENT keyword exists; sqiidfirst already run?") } # L ---------------------------------------------------------------------------- } else if (channel=="l") { imgets(name,"REORIENT", >& "dev$null") if (imgets.value=="0") { print ("WARNING! raw orientation of L unknown.") # hedit(name,"REORIENT","yes",add+,ver-,show+,update+) } else { print("REORIENT keyword exists; sqiidfirst already run?") } } } } if(echog)beep end ./irflatsqiid.par0100644000151400000240000000313007114546731013205 0ustar phallgamesi_plfile,s,h,"",,,"IMCOMBINE: List of pixel list files (optional)" i_sigma,s,h,"",,,"IMCOMBINE: List of sigma images (optional)" i_combine,s,h,"median",,,"IMCOMBINE: Combine operation (median|average)" i_reject,s,h,"ccdclip",,,"IMCOMBINE: Type of rejection" i_offsets,s,h,"none",,,"IMCOMBINE: Input image offsets" i_masktyp,s,h,"badvalue",,,"IMCOMBINE: Mask type" i_maskval,r,h,0.,,,"IMCOMBINE: Mask value" i_blank,r,h,1.,,,"IMCOMBINE: Value if there are no pixels" i_scale,s,h,"none",,,"IMCOMBINE: Image scaling" i_zero,s,h,"none",,,"IMCOMBINE: Image zero point offset" i_weight,s,h,"none",,,"IMCOMBINE: Image weights" i_statsec,s,h,"",,,"IMCOMBINE: Image section for computing statistics" i_expname,s,h,"",,,"IMCOMBINE: Image header exposure time keyword" i_lthresh,r,h,INDEF,,,"IMCOMBINE: Lower threshold" i_hthresh,r,h,INDEF,,,"IMCOMBINE: Upper threshold" i_nlow,r,h,1.,,,"IMCOMBINE: minmax: Number of low pixels to reject" i_nhigh,r,h,1.,,,"IMCOMBINE: minmax: Number of high pixels to reject" i_nkeep,r,h,6.,,,"IMCOMBINE: Minimum to keep (+) or maximum to reject(-)" i_lsigma,r,h,3.,,,"IMCOMBINE: Lower sigma clipping factor" i_hsigma,r,h,3.,,,"IMCOMBINE: Upper sigma clipping factor" i_rdnoise,r,h,40.,,,"IMCOMBINE: ccdclip: CCD readout noise (e-\'s)" i_gain,r,h,10.,,,"IMCOMBINE: ccdclip: CCD gain (e-\'s/ADU)" i_snoise,s,h,"0.",,,"IMCOMBINE: ccdclip: Sensitivity noise (fraction)" i_sigscale,r,h,0.1,0.,,"IMCOMBINE: Tolerance for sigma-clip scale corrections" i_pclip,r,h,-0.5,,,"IMCOMBINE: pclip: Percentile clipping parameter" i_grow,r,h,0.,,,"IMCOMBINE: Radius (pixels) for 1D neighbor rejection" mode,s,h,"q",,, ./look.cl0100644000151400000240000000135706310077575011465 0ustar phallgames#Take a quick look at a field thru difference of 2 offset images procedure look(rootname) string rootname {prompt = "Root name of images to difference"} bool stats=yes {prompt = "Display image statistics?"} int frame=1 {prompt = "Frame in which to display image"} begin string root bool sstats root = rootname sstats = stats myget (root//".001", stats=sstats, logfile="STDOUT", display=no) myget (root//".002", stats=sstats, logfile="STDOUT", display=no) print ("Creating image "//root//"diff...") imar (root//".001.imh","-",root//".002.imh",root//"diff") if(sstats){ print ("Image statistics:") imstat (root//"diff.imh") } print ("Displaying "//root//"diff (1 minus 2) in frame "//frame//"...") displ (root//"diff[*,-*]", frame) end ./ircoaddkir.par0100644000151400000240000000271506670321100013000 0ustar phallgamesi_sigma,s,h,"",,,"IMCOMBINE: Sigma image (optional)" i_plfile,s,h,"",,,"IMCOMBINE: Rejected pixel list image (optional)" i_combine,s,h,"average",average|median,,"IMCOMBINE: Type of combine operation (median|average)" i_reject,s,h,"sigclip",none|minmax|ccdclip|crreject|sigclip|avsigclip|pclip,,"IMCOMBINE: Type of rejection" i_masktyp,s,h,"badvalue",none|goodvalue|badvalue|goodbits|badbits,,"IMCOMBINE: Mask type" i_maskval,r,h,0.,,,"IMCOMBINE: Mask value" i_blank,r,h,0.,,,"IMCOMBINE: Value if there are no pixels" i_statsec,s,h,"",,,"IMCOMBINE: Image section for computing statistics" i_expname,s,h,"exptime",,,"IMCOMBINE: Image header exposure time keyword" i_lthresh,r,h,-10000.,,,"IMCOMBINE: Lower threshold" i_hthresh,r,h,INDEF,,,"IMCOMBINE: Upper threshold" i_nlow,r,h,1.,0.,,"IMCOMBINE: minmax: Number of low pixels to reject" i_nhigh,r,h,1.,0.,,"IMCOMBINE: minmax: Number of high pixels to reject" i_nkeep,r,h,-2.,,,"IMCOMBINE: Minimum to keep (+) or maximum to reject(-)" i_lsigma,r,h,5.,0.,,"IMCOMBINE: Lower sigma clipping factor" i_hsigma,r,h,5.,0.,,"IMCOMBINE: Upper sigma clipping factor" i_rdnoise,s,h,"rdnoise",,,"IMCOMBINE: ccdclip: CCD readout noise (electrons)" i_gain,s,h,"gain",,,"IMCOMBINE: ccdclip: CCD gain (electrons/ADU)" i_sigscale,r,h,0.1,0.,,"IMCOMBINE: Tolerance for sig-clip scaling corrections" i_pclip,r,h,-0.5,,,"IMCOMBINE: pclip: Percentile clipping parameter" i_grow,r,h,0.,,,"IMCOMBINE: Radius (pixels) for 1D neighbor rejection" mode,s,h,"q",,, ./irtfcoadd_4.p0100644000151400000240000000056606427031106012532 0ustar phallgames#!/usr/local/bin/perl # cycle thru contents of file(s) given on command line using <> $iter=0; while (<>) { # skip blank lines or lines with # as first non-whitespace character next if (/^\s+$/ or /^#/ or /^\s+#/); if($iter==0) { ($mag2) = split " "; } else { ($one) = split " "; $out=$one/$mag2; printf "%9.7f\n", $out; } $iter=1; } ./irtfcoadd_5.p0100644000151400000240000000044106427031106012523 0ustar phallgames#!/usr/local/bin/perl -w # cycle thru contents of file(s) given on command line using <> while (<>) { # skip blank lines or lines with # as first non-whitespace character next if (/^\s+$/ or /^#/ or /^\s+#/); ($one, $two) = split " "; $out=$two*$one; print "$out\n"; } ./irtfphotscale.cl0100644000151400000240000003315506561403006013357 0ustar phallgames# photscale -- calculate photometric scalings of a data set. # # Originally created by Mark Dickinson. Modified by Pat Hall. # # **requires stsdas (for igi) # # 960323: created from photdiff.cl # 960325: added normalization option # 960326: truncate output to 159 characters so IRAF can handle it # 960327: fixed bugs relating to 159-char IRAF limit by using awk not IRAF # 960411: added option to just replot old results w/o changing or redoing them # 960716: added option to use aperture corrections if desired procedure photscale (photfile,prefix,suffix) string photfile {prompt="Photometry data file from photcheck"} string prefix {prompt="Prefix for output file(s)"} string suffix {prompt="Suffix for output file(s)"} bool apcor {no, prompt="Use aperture corrections?"} string apfile {no, prompt="Aperture correction file (coadded image first)"} bool display {yes, prompt="Automatically display lightcurve (needs STSDAS)?"} bool results {no, prompt="Output computed scales and weights?", mode="q"} bool newref {no, prompt="Select new reference image?", mode="q"} int refimagenum {min=1,prompt="Number of new reference image", mode="q"} bool replace {no, prompt="Replace a point with average of others?", mode="q"} int newpoint {min=1,prompt="Image number of point to replace", mode="q"} string avgpoints {prompt="Points to avg. for replacement (enter as `1,2')", mode="q"} string reenter {prompt="Re-enter points (enter as `1,2')", mode="q"} bool normal {no, prompt="Normalize scales to a certain image?", mode="q"} int normimagenum {min=1,prompt="Number of normalization image", mode="q"} bool echog {yes,prompt="Beep when task is done?"} struct *outdat begin string phfile,outp # tmp. working versions of input/output files string phiirsdir # directory containing PHIIRS scripts string igicommands, filename, tmpout, tmpfile, ssuffix, s1, s2, s3 string aavgpoints, tmpstart, tmpmid, tmpend, pphotfile, s4, s5, tmpawk string aapfile real ut, scale, serr, delta, derr, value1, error1, value2, error2 real xmin, xmax, ymin, ymax, valuemag, errormag, error0, value0 real xplotmin, xplotmax, yplotmin, yplotmax real normvalue, normserr, normdelta, normderr int x, y, z, rrefimagenum, nnewpoint, nnormimagenum, point1, point2 bool rresults, nnewref, rreplace, iterate, nnormal, normed, refereed bool justplot, aapcor # Get query parameters. pphotfile = photfile phfile = mktemp(pphotfile) copy(pphotfile,phfile) tmpout = prefix outp = mktemp(tmpout) ssuffix = suffix aapcor = apcor if(aapcor)aapfile=apfile # Check for presence of output files justplot=no if(access(tmpout//".photscales"//ssuffix)){ beep print("Output file "//tmpout//".photscales"//ssuffix//" already exists.") print ("No new files will be created; only plotting will be done.") justplot=yes } ## Check for presence of filecalc task (in CTIO package) #if(!deftask("filecalc")){ #print ("Task `filecalc' is not loaded. Please load and restart task.") # return #} # Check for presence of the photscale.awk & photscale2.awk scripts in PHIIRS # source code directory. If either are not present, return error message. phiirsdir = osfn("phiirs$") if ((!access(phiirsdir//"photscale.awk")) || (!access(phiirsdir//"photscale2.awk"))) { print ("ERROR: Cannot access "//phiirsdir//"$photscale.awk or photscale2.awk!") return } # MAIN LOOP # Set up loop to allow repeated iterations using different reference images print ("Beginning...") iterate=yes nnewref=no rreplace=no nnormal=no normed=no refereed=no while(iterate){ # NEW REFERENCE IMAGE if(nnewref){ # If new reference image, what image number? refereed=yes rrefimagenum=refimagenum # Get that reference image's data and insert it as the first line w/awk tmpawk=mktemp("tmpawk") tmpfile=mktemp("tmpfile") print ("NR == "//rrefimagenum+1//", NR == "//rrefimagenum+1//" {print $0}", >> tmpawk) awk ("-f",tmpawk,phfile,>> tmpfile) del(tmpawk,ver-) tmpawk=mktemp("tmpawk") print ("NR != 1, NR != 1 {print $0}", >> tmpawk) awk ("-f",tmpawk,phfile,>> tmpfile) del(tmpawk,ver-) # Use awk script to calculate photometric scalings between frames. if(!aapcor){ awk ("-f",phiirsdir//"photscale.awk",tmpfile,>"_tmp."//outp) # If aperture corrections... } else { join(aapfile, tmpfile, maxch=9999, ver-, >> tmpfile//"2") awk ("-f",phiirsdir//"photscale2.awk",tmpfile//"2",>"_tmp."//outp) del(tmpfile//"2", ver-) } # Truncate output to 159 characters so IRAF can handle it. Lines are formatted # such that no mag,err pair should be cut off in the middle via this truncation tmpawk=mktemp("tmpawk") print ("{print (substr($0,1,159))}", >> tmpawk) awk ("-f",tmpawk,"_tmp."//outp,> outp) del("_tmp."//outp,ver-) del(tmpawk,ver-) del(phfile,ver-) rename(tmpfile,phfile) } else { # If first time through, calculate photometric scalings between frames. if(!rreplace && !nnormal){ del(outp,ver-,>&"dev$null") if(!aapcor){ awk ("-f",phiirsdir//"photscale.awk",phfile,>"_tmp."//outp) # If aperture corrections... } else { join(aapfile, phfile, maxch=9999, ver-, >> phfile//"2") awk ("-f",phiirsdir//"photscale2.awk",phfile//"2",>"_tmp."//outp) del(phfile//"2", ver-) } # Truncate output to 159 characters so IRAF can handle it. Lines are formatted # such that no mag,err pair should be cut off in the middle via this truncation tmpawk=mktemp("tmpawk") print ("{print (substr($0,1,159))}", >> tmpawk) awk ("-f",tmpawk,"_tmp."//outp,> outp) del("_tmp."//outp,ver-) del(tmpawk,ver-) } } # If display==yes, check to see if stsdas.graphics.stplot is loaded, and if # not, load it, then call stsdas.graphics.stplot.igi to display light curve. if (display) { if (!defpac("stsdas")) stsdas if (!defpac("graphics")) graphics if (!defpac("stplot")) stplot xplotmin = 0. xplotmax = 1. ymin = 1.E20 ymax = -1.E20 outdat = outp del("_plot."//outp, ver-, >& "dev$null") # First, scan data values to determine plot limits. Skip first line. if (fscan(outdat,filename) == EOF) error (0,"No lines in file ",outdat) while (fscan(outdat,filename,ut,delta,derr,scale,serr) != EOF) { xplotmax = xplotmax + 1. if(delta!=INDEF && derr!=INDEF){ ymin = min(ymin,delta-derr) ymax = max(ymax,delta+derr) } else { if(delta!=INDEF) { derr=99.999 } else { delta=0. derr=99.999 } } print(filename//" ",ut,delta,derr,scale,serr, >> "_plot."//outp) } yplotmin = ymin - 0.2 * (ymax-ymin) yplotmax = ymax + 0.2 * (ymax-ymin) # Now open temporary file and create igi command macro. igicommands = mktemp("plotdiff") print ("limits ",xplotmin,xplotmax,yplotmin,yplotmax, >igicommands) print ("box", >>igicommands) print ("xlabel image number", >>igicommands) print ("ylabel \gDm: reference - image", >>igicommands) print ("title Relative magnitude differences: ", tmpout//".photscales"//ssuffix, >>igicommands) print ("ltype 1", >>igicommands) print ("relocate ",xplotmin," 0.0 ", >>igicommands) print ("draw ",xplotmax," 0.0 ", >>igicommands) print ("ltype 0", >>igicommands) print ("data _plot."//outp, >>igicommands) # print ("data ",outp, >>igicommands) # print ("lines 2 256 ", >>igicommands) print ("lines 1 256 ", >>igicommands) print ("xcolumn 2", >>igicommands) print ("xevaluate r", >>igicommands) print ("ycolumn 3", >>igicommands) print ("ecol 4", >>igicommands) print ("ptype 4 0", >>igicommands) print ("points", >>igicommands) print ("error 2", >>igicommands) print ("error 4", >>igicommands) # Execute igi with command macro, exit, then bring up graphics cursor to # allow user to snapshot if desired. igi (initcmd="input "//igicommands//" ; end", >"dev$null") =gcur delete (igicommands,ver-) delete ("_plot."//outp,ver-,>&"dev$null") } # default: do not iterate, choose new reference image, or replace point(s) iterate=no nnewref=no nnormal=no rreplace=no # New reference image? if(!justplot)nnewref=newref if(nnewref){ iterate=yes } else { # # POINT REPLACEMENT # Replace a point? if(!justplot)rreplace=replace if(rreplace){ iterate=yes # Which point? nnewpoint=newpoint # Replace with average of what two points? (enter as 1,2) aavgpoints=avgpoints #if no , "re-enter (enter as 1,2):" while(stridx(",",aavgpoints)==0){ aavgpoints=reenter } point1=int(substr(aavgpoints,1,stridx(",",aavgpoints)-1)) point2=int(substr(aavgpoints,stridx(",",aavgpoints)+1,strlen(aavgpoints))) # Extract the value of point1 w/awk tmpawk=mktemp("tmpawk") tmpfile=mktemp("tmpfile") print("NR == "//point1+1//", NR == "//point1+1//" {print $0}",>> tmpawk) awk ("-f",tmpawk,outp,>> tmpfile) del(tmpawk,ver-) outdat=tmpfile while(fscan(outdat,filename,ut,delta,derr,scale,serr) != EOF) { value1=scale error1=serr } del(tmpfile,ver-,>&"dev$null") # Extract the value of point2 w/awk tmpawk=mktemp("tmpawk") tmpfile=mktemp("tmpfile") print("NR == "//point2+1//", NR == "//point2+1//" {print $0}",>> tmpawk) awk ("-f",tmpawk,outp,>> tmpfile) del(tmpawk,ver-) outdat=tmpfile while(fscan(outdat,filename,ut,delta,derr,scale,serr) != EOF) { value2=scale error2=serr } del(tmpfile,ver-,>&"dev$null") # Calculate the new point value0=0.5*(value1+value2) error0=sqrt(error1*error1+error2*error2) valuemag=-2.5*log10(value0) errormag=(2.5*error0)/(log(10.0)*value0) # Put in file w/awk, leaving out individ. star dm values to denote replacement tmpawk=mktemp("tmpawk") tmpstart=mktemp("tmpstart") tmpmid=mktemp("tmpmid") tmpend=mktemp("tmpend") tmpfile=mktemp("tmpfile") print("NR == 1, NR == "//nnewpoint//" {print $0}",>> tmpawk) awk ("-f",tmpawk,outp,>> tmpstart) del(tmpawk,ver-) tmpawk=mktemp("tmpawk") print("NR >= "//nnewpoint+2//" {print $0}",>> tmpawk) awk ("-f",tmpawk,outp,>> tmpend) del(tmpawk,ver-) tmpawk=mktemp("tmpawk") print("NR == "//nnewpoint+1//" {print $0}",>> tmpawk) awk ("-f",tmpawk,outp,>> tmpfile) del(tmpawk,ver-) outdat=tmpfile while(fscan(outdat,filename,ut,delta,derr,scale,serr) != EOF) { print(filename//" "//ut//" "//valuemag//" "//errormag//" "//value0//" "//error0, >> tmpmid) } del(outp, ver-) concat(tmpstart//","//tmpmid//","//tmpend, outp) del(tmpfile,ver-,>&"dev$null") del(tmpstart,ver-,>&"dev$null") del(tmpmid,ver-,>&"dev$null") del(tmpend,ver-,>&"dev$null") # End of loop for point replacement } else { # NORMALIZATION # Normalize scales? if(!justplot)nnormal=normal if(nnormal){ normed=yes iterate=yes # Normalize with what image? nnormimagenum=normimagenum # Extract the scaling value of nnormimagenum tmpawk=mktemp("tmpawk") tmpfile=mktemp("tmpfile") print("NR == "//nnormimagenum+1//", NR == "//nnormimagenum+1//" {print $0}",>> tmpawk) awk ("-f",tmpawk,outp,>> tmpfile) del(tmpawk,ver-) outdat=tmpfile while(fscan(outdat,filename,ut,delta,derr,scale,serr) != EOF) { normvalue=scale normdelta=delta } del(tmpfile,ver-,>&"dev$null") # Normalize all scales and errors by scaling value of nnormimagenum if(access(tmpout//".photold"//ssuffix))del(tmpout//".photold"//ssuffix,ver-) rename (outp,tmpout//".photold"//ssuffix) outdat=tmpout//".photold"//ssuffix while(fscan(outdat,s2,s3,delta,derr,scale,serr) != EOF) { # If delta, scale, and error are all defined, print normalized values of all if(delta!=INDEF && scale!=INDEF && serr!=INDEF){ # s1="one" # print(s1,delta,derr,scale,serr) print(s2//" "//s3//" "//delta-normdelta//" "//derr//" "//scale/normvalue//" "//serr/normvalue, >> outp) } else { # s1="two" # print(s1,delta,derr,scale,serr) # Set up strings containing values of delta and derr if(delta==INDEF){s4="INDEF"} else{s4=str(delta-normdelta)} if(derr==INDEF){s5="INDEF"} else{s5=str(derr)} # If only scale error is undefined, print INDEF value for it if(scale!=INDEF){ print(s2//" "//s3//" "//s4//" "//s5//" "//scale/normvalue//" INDEF", >> outp) # If both scale and scale error are undefined, print INDEF value for both } else { print(s2//" "//s3//" "//s4//" "//s5//" INDEF INDEF", >> outp) } } } # End of loop for normalization } # End of loop for no point replacement } # End of loop for no new reference image } # End of loop for a given reference image outdat="" } # Output scales and weights? if(!justplot){ rename(outp,tmpout//".photscales"//ssuffix) if(refereed){rename(phfile,tmpout//".photfile"//ssuffix)} else{del(phfile,ver-)} rresults=results if(rresults){ fields(tmpout//".photscales"//ssuffix, 5, lines="2-10000", >> tmpout//".scales"//ssuffix) #filecalc(tmpout//".photscales"//ssuffix, "1/($6*$6)", lines="2-10000", >> tmpout//".weights"//ssuffix) del ("tmpout.*s.ssuffix", ver-, >& "dev$null") copy (tmpout//".photscales"//ssuffix, "tmpout.photscales.ssuffix", ver-) !/scrs1/pathall/irtfphotscale.p tmpout.photscales.ssuffix > tmpout.weights.ssuffix copy ("tmpout.weights.ssuffix", tmpout//".weights"//ssuffix, ver-) del ("tmpout.*s.ssuffix", ver-, >& "dev$null") } print("File "//tmpout//".photscales"//ssuffix//" was created") if(rresults){ print("along with "//tmpout//".scales"//ssuffix//" and "//tmpout//".weights"//ssuffix) print("(either or both of which can be used to re-ircoadd the images)") } if(refereed){ print("along with "//tmpout//".photfile"//ssuffix//" (which is a copy of") print(pphotfile//" except with a new reference image)") } if(normed){ print("along with "//tmpout//".photold"//ssuffix//" (which contains pre-normalization") print("scales and individual star magnitude differences)") } } else { del(outp,ver-,>&"dev$null") del(phfile,ver-,>&"dev$null") } if(echog)beep end ./irtfphotscale.p0100644000151400000240000000066506427136230013223 0ustar phallgames#!/usr/local/bin/perl # cycle thru contents of file(s) given on command line using <> $iter=0; while (<>) { # skip blank lines or lines with # as first non-whitespace character next if (/^\s+$/ or /^#/ or /^\s+#/); if($iter==0) { ($one, $two, $three, $four, $five, $six) = split " "; } else { ($one, $two, $three, $four, $five, $six) = split " "; $out=1./($six*$six); print "$out\n"; } $iter=1; } ./masklet.cl0100644000151400000240000001010407116237025012140 0ustar phallgames# masklet -- break coadded-image object mask into individual-image masklets # # 950208: created from dimsum.maskdereg # 950216: fixed bug in output mask naming # 960326: allow editing of imshifts file # 960405: removed angle parameter and added flip option # 990217: added editfile option # 000603: added pre-deletion of _objmask procedure masklet(image,objmask,suffix) string image {prompt="Image mosaic produced by ircoadd"} string objmask {prompt="Object mask for image mosaic (default=image//objmask)"} string suffix="om" {prompt="Suffix for output object masks"} string shiftfile="" {prompt="Image+Shifts file (default=image//.imshifts)"} bool editfile=yes {prompt="Edit Image+Shifts file?"} bool flip=no {prompt="Flip object mask L-R before creating masklets?"} bool update=yes {prompt="Update image headers with object mask name?"} bool echog=yes {prompt="Beep when task is done?"} struct *imglist begin string oimg # equals image string maskimg # equals objmask string ssuffix # equals suffix string img # fscanned name of individual input image string word # original object mask title string int ix,iy # start pixel coords for input image from .imshifts file int xe, ye # end pixel coordinages for input images string ushiftlist # File outimg//.imshifts produced by shiftfix int oxdim,oydim # dimensions of mask image int ixdim,iydim # dimensions of individual input frames string msect # subsection of mask to extract for individual images bool edit_file # equals editfile # Get query parameters fileroot (image,validim+) oimg = fileroot.root maskimg = objmask if(maskimg=="")maskimg=oimg//"objmask" ssuffix = suffix # Verify that the oimg.imshifts file exists. if (shiftfile!="") {ushiftlist=shiftfile} else {ushiftlist = oimg//".imshifts"} if (!access(ushiftlist)) { beep print ("ERROR: ircoadd output file ",ushiftlist," does not exist.") return } edit_file=editfile # Allow editing of imshifts file if (edit_file) { print("Edit the imshifts file and replace the flatfielded,") print("skysubtracted image names with the image names that will be") print("the input to `irflat objmask+' or `irsky objmask+' so that the") print("object mask keyword is inserted into the correct image headers.") print("#Edit this imshifts file and replace the flatfielded,", >>ushiftlist) print("#skysubtracted image names with the image names that will be", >> ushiftlist) print("#the input to `irflat objmask+' or `irsky objmask+' so that the", >> ushiftlist) print("#object mask keyword is inserted into the correct image headers.", >> ushiftlist) vi(ushiftlist) } # Flip mask if desired imdel("_objmask",ver-,>&"dev$null") if(flip){ imcopy(maskimg//"[-*,*]","_objmask",ver-) } else { imcopy(maskimg,"_objmask",ver-) } hedit("_objmask","title","Object mask for image ",add+,ver-,show-,update+) # Get dimensions of mask image from image mosaic produced by shiftfix. imgets("_objmask","i_naxis1") oxdim=int(imgets.value) imgets("_objmask","i_naxis2") oydim=int(imgets.value) # Rewind file list. imglist=ushiftlist # Make working mask images, one for each input image, by cutting out # appropriate subsection of the large input mask image. while (fscan(imglist,img,ix,iy) != EOF) { fileroot (img,validim+) img = fileroot.root print ("Making mask image "//img//ssuffix//".pl for ",img) imgets(img,"i_naxis1") ixdim=int(imgets.value) imgets(img,"i_naxis2") iydim=int(imgets.value) ix+=1 iy+=1 xe=ix + ixdim - 1 ye=iy + iydim - 1 msect = "["//ix//":"//xe//","//iy//":"//ye//"]" print(msect) imcopy("_objmask"//msect,img//ssuffix//".pl",ver-) imgets(img//ssuffix//".pl","title") word=imgets.value//" "//img hedit(img//ssuffix//".pl","title",word,add+,ver-,show-,update+) # If update=yes, insert mask name into input image headers with OBJMASK card. if (update) hedit(img,"OBJMASK",img//ssuffix//".pl",add+,ver-,up+,sho-) } # Clean up. print("All done. Next task to run is `irflat objmask+' or `irsky objmask+'.") imdel("_objmask",ver-) imglist = "" if(echog)beep end ./nl_findcor.cl0100644000151400000240000002313306561403066012626 0ustar phallgames#UT 950709 version # #-1 load stsdas.toolbox.imgtools, ctio, & phiirs before running #0 make lists #1 irimfirst on all #2 compare start & end refs & darks #3 imcombine all images #4 iterstat interspersed refs #5 iterstat observations #6 convert short-exposure images to actual flux and exposure time #7 convert long-exposure images to actual flux and exposure time #8 find average lamp values #9 correct images for lamp variability #10 turn (exptime,flux) file into (flux,%) file and graph #0 make lists... ideally want to replace by directing specific files to # specific lists. files nldark_start*imh >> list.nl1_dark_start files nldark_end*imh >> list.nl1_dark_end copy list.nl1 list.nl1_refs copy list.nl1 list.nl1_ref_start copy list.nl1 list.nl1_ref_end copy list.nl1 list.nl1_005s copy list.nl1 list.nl1_0075s copy list.nl1 list.nl1_01s copy list.nl1 list.nl1_02s copy list.nl1 list.nl1_04s copy list.nl1 list.nl1_06s copy list.nl1 list.nl1_10s copy list.nl1 list.nl1_14s copy list.nl1 list.nl1_18s copy list.nl1 list.nl1_22s copy list.nl1 list.nl1_26s copy list.nl1 list.nl1_30s copy list.nl1 list.nl1_34s copy list.nl1 list.nl1_38s copy list.nl1 list.nl1_42s copy list.nl1 list.nl1_46s copy list.nl1 list.nl1_50s vi list.nl1_* count list.nl1_* >> list.nl1_counts vi list.nl1_counts #1 irimfirst on all irimfirst list.nl1 no no badmask=bpk.pl irimfirst list.nl1_dark_start no no badmask=bpk.pl irimfirst list.nl1_dark_end no no badmask=bpk.pl #2 imcombine start & end refs & darks imcombine @list.nl1_ref_start nl1_ref_start comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=none expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 imcombine @list.nl1_ref_end nl1_ref_end comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=none expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 imcombine @list.nl1_dark_start nl1_dark_start comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=none expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 imcombine @list.nl1_dark_end nl1_dark_end comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=none expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 print("#start & end dark stats", >> "log.nl1") iterstat nl1_dark_start.imh,nl1_dark_end.imh >> log.nl1 #3 imcombine all images imcombine @list.nl1_005s nl1_005s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 imcombine @list.nl1_0075s nl1_0075s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 imcombine @list.nl1_01s nl1_01s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 imcombine @list.nl1_02s nl1_02s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 imcombine @list.nl1_04s nl1_04s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 imcombine @list.nl1_06s nl1_06s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 imcombine @list.nl1_10s nl1_10s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 imcombine @list.nl1_14s nl1_14s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 imcombine @list.nl1_18s nl1_18s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 imcombine @list.nl1_22s nl1_22s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 imcombine @list.nl1_26s nl1_26s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 imcombine @list.nl1_30s nl1_30s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 imcombine @list.nl1_34s nl1_34s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 imcombine @list.nl1_38s nl1_38s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 imcombine @list.nl1_42s nl1_42s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 imcombine @list.nl1_46s nl1_46s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 imcombine @list.nl1_50s nl1_50s comb=average rej=ccdclip lsig=3. hsig=3. gain=10.46 rdnoise=35. masktyp=badval expname=exptime logfile=log.nl1 weight=none scale=none zero=none statsec="" project=no plfile="" sigma="" offsets=none snoise=0 grow=0 #4 iterstat interspersed refs print("#interspersed ref stats", >> "log.nl1") iterstat nl1_ref_start.imh,@list.nl1_refs,nl1_ref_end.imh >> stats.nl1_refs_1 type stats.nl1_refs_1 >> log.nl1 #5 iterstat observations del _tmpdagnabit ver- >& dev$null iterstat nl1*s.imh[25:225,25:225] >> stats.nl1_1 hsel nl1*s.imh int_s yes >> imhe.nl1_1 fields stats.nl1_1 2 >> _tmpdagnabit join imhe.nl1_1,_tmpdagnabit out=stats.nl1_2 del _tmpdagnabit ver- #6 convert short-exposure images to actual flux and exposure time print(" ", >> "stats.nl1_2") print("#the first time this is edited, comment out lines of images with ", >> "stats.nl1_2") print("#int_time >1.381 seconds.", >> "stats.nl1_2") vi stats.nl1_2 filecalc stats.nl1_2 "$1+$1-0.381;($1+$1-0.381)*($2/$1)" >> stats.nl1_3 #old (wrong) #filecalc stats.nl1_2 "$1+$1;($1+$1)*($2/$1)" >> stats.nl1_3 #7 convert long-exposure images to actual flux and exposure time print(" ", >> "stats.nl1_2") print("#the second time this is edited, comment out lines of images with ", >> "stats.nl1_2") print("#int_time <=1.381 seconds.", >> "stats.nl1_2") vi stats.nl1_2 filecalc stats.nl1_2 "$1+1.0;($1+1.0)*($2/$1)" >> stats.nl1_3 #8 find average lamp values print(" ", >> "stats.nl1_refs_1") count stats.nl1_3 | scan(z) print("#when this is edited, average each two adjacent values together", >> "stats.nl1_refs_1") print("#so that you end up with "//z//" values total, matching the number ", >> "stats.nl1_refs_1") print("#of sets of nonlinearity exposures, which will be scaled by these averages.", >> "stats.nl1_refs_1") print("#Put the average values in file 'stats.nl1_refs_2'.", >> "stats.nl1_refs_1") print("#This can be done with the IRAF commands:", >> "stats.nl1_refs_1") print("# x=0.5* (AVG1 + AVG2); print(x, >> \"stats.nl1_refs_2\"", >> "stats.nl1_refs_1") vi stats.nl1_refs_1 print("#Are there "//z//" lines of data in this file? if so, continue...", >> "stats.nl1_refs_2") vi stats.nl1_refs_2 sort stats.nl1_refs_2 col=1 num+ rev+ | head nlines=1 | scan(z) print("Do the following IRAF commands after this task stops: ") print("filecalc stats.nl1_refs_2 \"$1/"//z//"\" >> stats.nl1_refs_3") #9 correct images for lamp variability print("filecalc stats.nl1_3,stats.nl1_refs_3 \"$1;$2/($1@2)\" >> stats.nl1_4") #10 turn (exptime,flux) file into (flux,%) file and graph print("fields stats.nl1_4 1 | head nlines=1 | scan(x)") print("fields stats.nl1_4 2 | head nlines=1 | scan(y)") print("=x") print("=y") print("-----insert x and y from above into the line below-----") print("filecalc stats.nl1_4 \"$2;$2/(y*$1/x)\" >> stats.nl1_5") print("graph stats.nl1_5 point-") print("graph stats.nl1_5 point+ append+ overplot+") print(" ") print("The file stats.nl1_5 contains the final data points. `vi stats.nl1_5'") print("and insert a zero at the end of each column, then run:") print(" stsdas.statistics.emmethod stats.nl1_5[3,2,1]") print("to get the slope coefficient from the least-squares solution.") beep ./photcheck.awk0100644000151400000240000000331606126306434012644 0ustar phallgames# awk script used by the PHIIRS routine photcheck for formatting output data # files. The input data is taken from txdump, and consists of a series of # N lines for each apphot.phot photometry file, where column 1 of each line has # the name of the image from which the photometry was measured, column 2 # records the airmass of observation, column 3 contains the magnitude measured # for the star, and column 4 contains the error estimate in that magnitude. # There will a number of comment lines beginning with "#" between each set # of N input data lines, indicating a break before the next photometry file. # # originally created by Mark Dickinson, 3 Aug 1993, revised 2 March 1994 # modified March 1996 by Pat Hall # # Set new file switch. # BEGIN {newfile = 1} # { # # If input line is a lone #, set newfile=1 and print carriage return # except at the start of the file, thus avoiding a leading blank line. # if (substr($0,1,1)=="#") { if (substr($0,2,2)=="") { if(newfile) { newfile = 1 } else { newfile = 1 printf ("\n") } } # # Otherwise, if new file, print image name in column 1, airmass in column 2, # and set newfile=0. # } else { if (newfile) { printf ("%26s %6.4f ",$1,$2) newfile = 0 } # # If magnitude record = INDEF, print "INDEF" on end of current output record. # if ($3=="INDEF") { printf (" %6s"," INDEF") # # Otherwise, print magnitude on end of current output record. # } else { printf (" %6.3f",$3) } # # If error record = INDEF, print "INDEF" on end of current output record. # if ($4=="INDEF") { printf (" %6s"," INDEF") # # Otherwise, print error on end of current output record. # } else { printf (" %6.3f",$4) } } } ./irskysqiid.par0100644000151400000240000000312207114546731013066 0ustar phallgamesi_sigma,s,h,"",,,"IMCOMBINE: Sigma image (optional)" i_plfile,s,h,"",,,"IMCOMBINE: Rejected pixel list image (optional)" i_combine,s,h,"median",average|median,,"IMCOMBINE: Type of combine operation (median|average)" i_reject,s,h,"ccdclip",none|minmax|ccdclip|crreject|sigclip|avsigclip|pclip,,"IMCOMBINE: Type of rejection" i_masktyp,s,h,"badvalue",none|goodvalue|badvalue|goodbits|badbits,,"IMCOMBINE: Mask type" i_maskval,r,h,0.,,,"IMCOMBINE: Mask value" i_blank,r,h,1.,,,"IMCOMBINE: Value if there are no pixels" i_scale,s,h,"median",,,"IMCOMBINE: Image scaling" i_zero,s,h,"none",,,"IMCOMBINE: Image scaling" i_weight,s,h,"none",,,"IMCOMBINE: Image weights" i_statsec,s,h,"",,,"IMCOMBINE: Image section for computing statistics" i_expname,s,h,"exptime",,,"IMCOMBINE: Image header exposure time keyword" i_lthresh,r,h,INDEF,,,"IMCOMBINE: Lower threshold" i_hthresh,r,h,INDEF,,,"IMCOMBINE: Upper threshold" i_nlow,r,h,1.,0.,,"IMCOMBINE: minmax: Number of low pixels to reject" i_nhigh,r,h,1.,0.,,"IMCOMBINE: minmax: Number of high pixels to reject" i_nkeep,r,h,1.,,,"IMCOMBINE: Minimum to keep (+) or maximum to reject(-)" i_lsigma,r,h,5.,0.,,"IMCOMBINE: Lower sigma clipping factor" i_hsigma,r,h,5.,0.,,"IMCOMBINE: Upper sigma clipping factor" i_rdnoise,r,h,40.,,,"IMCOMBINE: ccdclip: CCD readout noise (electrons)" i_gain,r,h,10.,,,"IMCOMBINE: ccdclip: CCD gain (electrons/ADU)" i_sigscale,r,h,0.1,0.,,"IMCOMBINE: Tolerance for sig-clip scaling corrections" i_pclip,r,h,-0.5,,,"IMCOMBINE: pclip: Percentile clipping parameter" i_grow,r,h,0.,,,"IMCOMBINE: Radius (pixels) for 1D neighbor rejection" mode,s,h,"q",,, ./c40ircfirst.cl0100644000151400015140000001723307265436232012665 0ustar phallphall# first.cl -- task to subtract dark & add header params to brand new raw images # # 1. subtract dark # 2. hedit image headers, adding: (basically this task is hadd.cl plus #0) # 1. BPM,BPMASK = bad pixel mask name # 2. coadds = number of internal coadds # 3. exptime = (itime: exposure time per coadd) * (# of coadds) # 4. obs-date = date-obs but in dd/mm/yy format # 5. ut = time-obs (or time-obs + 7) # 6. date-obs = yyyy-mm-dd format (old date-obs saved as dateorig) # (following are optional) # 7. epoch, ra, dec = entered as parameters, if desired # 8. st = sidereal time, calculated from ut & date using astutil.asttimes # & the observatory parameter (kpno, mtbigelow, mmto, ctio) # 9. airmass = calculated from epoch, ra, dec, st, and obs-date # # 010315: created by PBH # 010410: cleaned up "header keyword not found" errors # # **bug: airmass+ airauto+ option assumes you're observing from MST time zone! # ...but that's only for the "asttimes" task, which may be irrelevant # **should be more options for computing ut than just time-obs or time-obs+7h procedure c40ircfirst(imagelist,darksub,badmask) string imagelist {prompt="List of images to process (do not use an `@')"} bool darksub {prompt="Subtract off dark frame?"} string badmask {prompt="Name of bad pixel mask to add to image header"} string dark {prompt="Name of the dark frame to subtract", mode="q"} string darkstring {prompt="String to append to dark-subtracted images",mode="q"} bool coords=yes {prompt="Add RA, DEC, and EPOCH to image header?"} bool airmass=yes {prompt="Enter airmass into image header?"} bool airauto=yes {prompt="Find airmass of image automatically?"} real airval {prompt="Airmass of image", mode="q"} string epoch {prompt="Epoch of coordinates"} string ra {prompt="Right Ascension (surround with quotes)"} string dec {prompt="Declination (surround w/quotes; use - but not +"} string observatory="lco" {prompt="Observatory where observations were made"} bool ut=yes {prompt="Is 'time-obs' in header ut or not?"} bool ddmmyy=no {prompt="Is 'date-obs' in day/month/year format?"} bool echog=yes {prompt="Beep when task is done?"} struct *list begin string ddark, ddarkstring, bbadmask, check, base, iimagelist, ext string darklist, flat, flatbase, meanfile, currentflat, tempflat, name string editlist, current, obsdate, rra, ddec, eepoch, oobservatory, minsec string obstime, timeobs, dateobs, century, utdate real intime, aairval, ttime, mean, meanbad, x int ncoadd, ddy, hhr, hhour, mmonth, yyear, dday, uttime, last2digits bool ddarksub, ccoords, aairauto, uut, aairmass iimagelist = imagelist list = iimagelist editlist = iimagelist ddarksub = darksub if (ddarksub) { ddark = dark ddarkstring = darkstring darklist = iimagelist//ddarkstring } bbadmask = badmask ccoords = coords aairmass = airmass if (aairmass) { aairauto = airauto # if(!aairauto)aairval = airval if(!defpac("astutil")) { beep print ("WARNING!! Package ''astutil'' is not loaded; cannot set airmass in images.") print ("Load the package and rerun the task.") return } } eepoch = epoch rra = ra ddec = dec oobservatory = observatory uut = ut # Add BPM and other goodies to the image headers, just like in the hadd.cl task print("===> Adding various parameters to the image headers...") list = iimagelist while (fscan (list, current) !=EOF) { hedit(current,"BPM",bbadmask,add+,ver-,show+,update+) hedit(current,"BPMASK",bbadmask,add+,ver-,show+,update+) # Set exptime=itime * (# of coadds) ncoadd=1 hedit(current,"coadds",(ncoadd),add+,ver-,show+,update+) # # Add colons to UT date in header imgets(current,"ut",>&"dev$null") utdate=substr(imgets.value,1,2)//":"//substr(imgets.value,4,5)//":"//substr(imgets.value,7,8) hedit(current,"ut",utdate,add+,ver-,show+,update+) # # The 'date-obs' keyword comes in either the old format "dd/mm/yy", # the erroneous format "mm/dd/yy", or the new format "yyyy-mm-dd". # Create new 'date-obs' keyword in the new format "yyyy-mm-dd". imgets(current,"dateorig",>&"dev$null") if (imgets.value!="0") { print ("DATEORIG keyword already exists -- first already run on image?") } else { imgets(current,"date-obs",>&"dev$null") # Copy 'date-obs' keyword to 'dateorig' in original format. hedit(current,"dateorig",imgets.value,add+,ver-,show+,update+) # Get yyyy-mm-dd from "date" keyword imgets(current,"date",>&"dev$null") # Create header keyword 'obs-date', always in "dd/mm/yy" format. # yyyy-mm-dd format: # 1234567890 obsdate=substr(imgets.value,9,10)//"/"//substr(imgets.value,6,7)//"/"//substr(imgets.value,3,4) hedit(current,"obs-date",obsdate,add+,ver-,show+,update+) # Create new 'date-obs' in new format "yyyy-mm-dd" from 'obs-date' "dd/mm/yy" # 12345678 dateobs=substr(imgets.value,1,10) hedit(current,"date-obs",dateobs,add+,ver-,show+,update+) # } } if(ccoords){ list = iimagelist while (fscan (list, current) !=EOF) { hedit(current,"epoch",eepoch,add+,ver-,show+,update+) hedit(current,"ra",rra,add+,ver-,show-,update+) hedit(current,"ra",rra,add+,ver-,show+,update+) hedit(current,"dec",ddec,add+,ver-,show-,update+) hedit(current,"dec",ddec,add+,ver-,show+,update+) #hedit test ra "(str('21:51:59.0'))" add+ ver- show- } } if(aairmass){ if(aairauto){ list = iimagelist while (fscan (list, current) !=EOF) { imgets(current,"obs-date",>&"dev$null") dday=int(substr(imgets.value,1,2)) mmonth=int(substr(imgets.value,4,5)) # yyear=int("19"//substr(imgets.value,7,8)) last2digits=int(substr(imgets.value,7,8)) if(last2digits <= 80) { yyear=int("20"//substr(imgets.value,7,8)) } else { yyear=int("19"//substr(imgets.value,7,8)) } imgets(current,"ut",>&"dev$null") hhr=int(substr(imgets.value,1,2)) minsec=substr(imgets.value,3,8) hhour=hhr-7 if(hhour<0){ dday=dday-1 hhour=hhour+24. } if(dday<=0){ mmonth=mmonth-1 # this will not always be totally accurate, and may fail for feb., but hey. dday=30 } # observing on new year's eve will require a new correction! ttime=real(str(int(hhour))//minsec) asttimes(observatory=oobservatory, year=yyear, month=mmonth, day=dday, time=ttime) hedit(current,"st",asttimes.lmst,add+,ver-,show-,update+) hedit(current,"st",asttimes.lmst,add+,ver-,show+,update+) setairmass(current, observatory=oobservatory, intype="middle", outtype="effective", date="obs-date",exposure="exptime", utmiddle="utmiddle", show+, update+, override+) } } else { list = iimagelist while (fscan (list, current) !=EOF) { print("Setting airmass for image "//current) hedit(current,"airmass",airval,add+,ver-,show+,update+) } } } # Subtract off Dark Current if (ddarksub) { list = iimagelist # if darklist doesn't exist, assume dsub imgs don't either; create it & dsubs if(!access(darklist)) { print("===> Subtracting off Dark Current...") while (fscan (list, name) !=EOF) { fileroot(name,validim+) base=fileroot.root ext=fileroot.extension if(ext!="")ext="."//ext print(base//ddarkstring//ext, >> darklist) imgets(name,"DARKSUB",>&"dev$null") if (imgets.value=="0") { imarith(name, "-", ddark, base//ddarkstring//ext, verbose-) hedit(base//ddarkstring//ext,"DARKSUB",ddark,add+,ver-,show+,update+) } else { print("DARKSUB keyword exists; first already run? "//name//" just copied") imcopy(name, base//ddarkstring//ext, verbose-) } } } else { print("Darksubbed image list "//darklist//" already exists; images assumed to exist too.") } #imarith("@"//iimagelist, "-", ddark, "@"//darklist, verbose-) #hedit("@"//darklist,"DARKSUB",ddark,add+,ver-,show+,update+) print(" ") print("===> Dark-subtracted images are listed in the file "//darklist//".") } if(echog)beep end ./ircoaddsqiid.par0100644000151400000240000000270607114546731013341 0ustar phallgamesi_sigma,s,h,"",,,"IMCOMBINE: Sigma image (optional)" i_plfile,s,h,"",,,"IMCOMBINE: Rejected pixel list image (optional)" i_combine,s,h,"average",average|median,,"IMCOMBINE: Type of combine operation (median|average)" i_reject,s,h,"crreject",none|minmax|ccdclip|crreject|sigclip|avsigclip|pclip,,"IMCOMBINE: Type of rejection" i_masktyp,s,h,"badvalue",none|goodvalue|badvalue|goodbits|badbits,,"IMCOMBINE: Mask type" i_maskval,r,h,0.,,,"IMCOMBINE: Mask value" i_blank,r,h,0.,,,"IMCOMBINE: Value if there are no pixels" i_statsec,s,h,"",,,"IMCOMBINE: Image section for computing statistics" i_expname,s,h,"exptime",,,"IMCOMBINE: Image header exposure time keyword" i_lthresh,r,h,INDEF,,,"IMCOMBINE: Lower threshold" i_hthresh,r,h,INDEF,,,"IMCOMBINE: Upper threshold" i_nlow,r,h,1.,0.,,"IMCOMBINE: minmax: Number of low pixels to reject" i_nhigh,r,h,1.,0.,,"IMCOMBINE: minmax: Number of high pixels to reject" i_nkeep,r,h,1.,,,"IMCOMBINE: Minimum to keep (+) or maximum to reject(-)" i_lsigma,r,h,5.,0.,,"IMCOMBINE: Lower sigma clipping factor" i_hsigma,r,h,5.,0.,,"IMCOMBINE: Upper sigma clipping factor" i_rdnoise,s,h,"40.",,,"IMCOMBINE: ccdclip: CCD readout noise (electrons)" i_gain,s,h,"10.",,,"IMCOMBINE: ccdclip: CCD gain (electrons/ADU)" i_sigscale,r,h,0.1,0.,,"IMCOMBINE: Tolerance for sig-clip scaling corrections" i_pclip,r,h,-0.5,,,"IMCOMBINE: pclip: Percentile clipping parameter" i_grow,r,h,0.,,,"IMCOMBINE: Radius (pixels) for 1D neighbor rejection" mode,s,h,"q",,, ./osirisfirst.cl0100600000151400015140000002203007265436266013077 0ustar phallphall# first.cl -- task to subtract dark & add header params to brand new raw images # # 1. subtract dark # 2. hedit image headers, adding: (basically this task is hadd.cl plus #0) # 1. BPM,BPMASK = bad pixel mask name # 2. coadds = number of internal coadds # 3. exptime = (itime: exposure time per coadd) * (# of coadds) # 4. obs-date = date-obs but in dd/mm/yy format # 5. ut = time-obs (or time-obs + 7) # 6. date-obs = yyyy-mm-dd format (old date-obs saved as dateorig) # (following are optional) # 7. epoch, ra, dec = entered as parameters, if desired # 8. st = sidereal time, calculated from ut & date using astutil.asttimes # & the observatory parameter (kpno, mtbigelow, mmto, ctio) # 9. airmass = calculated from epoch, ra, dec, st, and obs-date # # 010315: created by PBH # 010410: cleaned up "header keyword not found" errors # # **bug: airmass+ airauto+ option assumes you're observing from MST time zone! # ...but that's only for the "asttimes" task, which may be irrelevant # **should be more options for computing ut than just time-obs or time-obs+7h procedure osirisfirst(imagelist,darksub,badmask) string imagelist {prompt="List of images to process (do not use an `@')"} bool darksub {prompt="Subtract off dark frame?"} string badmask {prompt="Name of bad pixel mask to add to image header"} string dark {prompt="Name of the dark frame to subtract", mode="q"} string darkstring {prompt="String to append to dark-subtracted images",mode="q"} bool coords=no {prompt="Add RA, DEC, and EPOCH to image header?"} bool airmass=no {prompt="Enter airmass into image header?"} bool airauto=yes {prompt="Find airmass of image automatically?"} real airval {prompt="Airmass of image", mode="q"} string epoch {prompt="Epoch of coordinates"} string ra {prompt="Right Ascension (surround with quotes)"} string dec {prompt="Declination (surround w/quotes; use - but not +"} string observatory {prompt="Observatory where observations were made"} bool ut=yes {prompt="Is 'time-obs' in header ut or not?"} bool ddmmyy=no {prompt="Is 'date-obs' in day/month/year format?"} bool echog=yes {prompt="Beep when task is done?"} struct *list begin string ddark, ddarkstring, bbadmask, check, base, iimagelist, ext string darklist, flat, flatbase, meanfile, currentflat, tempflat, name string editlist, current, obsdate, rra, ddec, eepoch, oobservatory, minsec string obstime, timeobs, dateobs, century real intime, aairval, ttime, mean, meanbad, x int ncoadd, ddy, hhr, hhour, mmonth, yyear, dday, uttime, last2digits bool ddarksub, ccoords, aairauto, uut, aairmass iimagelist = imagelist list = iimagelist editlist = iimagelist ddarksub = darksub if (ddarksub) { ddark = dark ddarkstring = darkstring darklist = iimagelist//ddarkstring } bbadmask = badmask ccoords = coords aairmass = airmass if (aairmass) { aairauto = airauto # if(!aairauto)aairval = airval if(!defpac("astutil")) { beep print ("WARNING!! Package ''astutil'' is not loaded; cannot set airmass in images.") print ("Load the package and rerun the task.") return } } eepoch = epoch rra = ra ddec = dec oobservatory = observatory uut = ut # Add BPM and other goodies to the image headers, just like in the hadd.cl task print("===> Adding various parameters to the image headers...") list = iimagelist while (fscan (list, current) !=EOF) { hedit(current,"BPM",bbadmask,add+,ver-,show+,update+) hedit(current,"BPMASK",bbadmask,add+,ver-,show+,update+) # Set exptime=itime * (# of coadds) #imgets(current,"comment", >& "dev$null") #if(imgets.value!="0"){ #ncoadd=int(substr(imgets.value,strlen(imgets.value),strlen(imgets.value))) #} #else { imgets(current,"ncoadds", >& "dev$null") ncoadd=real(imgets.value) #} hedit(current,"coadds",(ncoadd),add+,ver-,show+,update+) imgets(current,"exptime",>&"dev$null") intime=real(imgets.value) # next line new hedit(current,"itime",(intime),add+,ver-,show+,update+) hedit(current,"exptime",(ncoadd*intime),add+,ver-,show+,update+) # # The 'date-obs' keyword comes in either the old format "dd/mm/yy", # the erroneous format "mm/dd/yy", or the new format "yyyy-mm-dd". # Create new 'date-obs' keyword in the new format "yyyy-mm-dd". imgets(current,"dateorig",>&"dev$null") if (imgets.value!="0") { print ("DATEORIG keyword already exists -- first already run on image?") } else { imgets(current,"date-obs",>&"dev$null") # Copy 'date-obs' keyword to 'dateorig' in original format. hedit(current,"dateorig",imgets.value,add+,ver-,show+,update+) # Create header keyword 'obs-date', always in "dd/mm/yy" format. if(!ddmmyy){ # mm/dd/yy format: if(substr(imgets.value,3,3)=="/") { obsdate=substr(imgets.value,4,6)//substr(imgets.value,1,3)//substr(imgets.value,7,8) } else { # yyyy-mm-dd format: # 1234567890 obsdate=substr(imgets.value,9,10)//"/"//substr(imgets.value,6,7)//"/"//substr(imgets.value,3,4) } # create obs-date if date-obs in mm/dd/yy or yyyy-mm-dd format: hedit(current,"obs-date",obsdate,add+,ver-,show+,update+) } else { # create obs-date if date-obs in dd/mm/yy format: hedit(current,"obs-date",imgets.value,add+,ver-,show+,update+) } # Create new 'date-obs' in new format "yyyy-mm-dd" from 'obs-date' "dd/mm/yy" # 12345678 imgets(current,"obs-date",>&"dev$null") if ((substr(imgets.value,7,7))=="9") { century=19 } else { century=20 } dateobs=century//substr(imgets.value,7,8)//"-"//substr(imgets.value,4,5)//"-"//substr(imgets.value,1,2) hedit(current,"date-obs",dateobs,add+,ver-,show+,update+) # # Sometimes the time in the image header is ut, sometimes not. # so this option lets you choose either ut or mst if(uut){hedit(current,"ut",("(@'time-obs')"),add+,ver-,show+,update+)} else{ imgets(current,"time-obs",>&"dev$null") obstime=substr(imgets.value,1,2) uttime=int(obstime)+7 if(uttime>=24){uttime=uttime-24} if(uttime<=9){timeobs="0"//str(uttime)//substr(imgets.value,3,8)} if(uttime>=10){timeobs=str(uttime)//substr(imgets.value,3,8)} #need to hedit ut twice cause is not in hh:mm:ss format 1st time around hedit(current,"ut",timeobs,add+,ver-,show+,update+) hedit(current,"ut",timeobs,add+,ver-,show+,update+) } } } if(ccoords){ list = iimagelist while (fscan (list, current) !=EOF) { hedit(current,"epoch",eepoch,add+,ver-,show+,update+) hedit(current,"ra",rra,add+,ver-,show-,update+) hedit(current,"ra",rra,add+,ver-,show+,update+) hedit(current,"dec",ddec,add+,ver-,show-,update+) hedit(current,"dec",ddec,add+,ver-,show+,update+) #hedit test ra "(str('21:51:59.0'))" add+ ver- show- } } if(aairmass){ if(aairauto){ list = iimagelist while (fscan (list, current) !=EOF) { imgets(current,"obs-date",>&"dev$null") dday=int(substr(imgets.value,1,2)) mmonth=int(substr(imgets.value,4,5)) # yyear=int("19"//substr(imgets.value,7,8)) last2digits=int(substr(imgets.value,7,8)) if(last2digits <= 80) { yyear=int("20"//substr(imgets.value,7,8)) } else { yyear=int("19"//substr(imgets.value,7,8)) } imgets(current,"ut",>&"dev$null") hhr=int(substr(imgets.value,1,2)) minsec=substr(imgets.value,3,8) hhour=hhr-7 if(hhour<0){ dday=dday-1 hhour=hhour+24. } if(dday<=0){ mmonth=mmonth-1 # this will not always be totally accurate, and may fail for feb., but hey. dday=30 } # observing on new year's eve will require a new correction! ttime=real(str(int(hhour))//minsec) asttimes(observatory=oobservatory, year=yyear, month=mmonth, day=dday, time=ttime) hedit(current,"st",asttimes.lmst,add+,ver-,show-,update+) hedit(current,"st",asttimes.lmst,add+,ver-,show+,update+) setairmass(current, observatory=oobservatory, intype="middle", outtype="effective", date="obs-date",exposure="exptime", utmiddle="utmiddle", show+, update+, override+) } } else { list = iimagelist while (fscan (list, current) !=EOF) { print("Setting airmass for image "//current) hedit(current,"airmass",airval,add+,ver-,show+,update+) } } } # Subtract off Dark Current if (ddarksub) { list = iimagelist # if darklist doesn't exist, assume dsub imgs don't either; create it & dsubs if(!access(darklist)) { print("===> Subtracting off Dark Current...") while (fscan (list, name) !=EOF) { fileroot(name,validim+) base=fileroot.root ext=fileroot.extension if(ext!="")ext="."//ext print(base//ddarkstring//ext, >> darklist) imgets(name,"DARKSUB",>&"dev$null") if (imgets.value=="0") { imarith(name, "-", ddark, base//ddarkstring//ext, verbose-) hedit(base//ddarkstring//ext,"DARKSUB",ddark,add+,ver-,show+,update+) } else { print("DARKSUB keyword exists; first already run? "//name//" just copied") imcopy(name, base//ddarkstring//ext, verbose-) } } } else { print("Darksubbed image list "//darklist//" already exists; images assumed to exist too.") } #imarith("@"//iimagelist, "-", ddark, "@"//darklist, verbose-) #hedit("@"//darklist,"DARKSUB",ddark,add+,ver-,show+,update+) print(" ") print("===> Dark-subtracted images are listed in the file "//darklist//".") } if(echog)beep end ./iterstat.cl0100644000151400000240000001624506704671441012361 0ustar phallgamesprocedure iterstat(image) # Script to find image statistics excluding deviant pixels # originally created 4 August 1992 by John Ward # 930818: revisions by MD # 950201: changed output formatting-- still prob. w/short values/image names. # 950209: simple string check for INDEF, for IRAF 2.10.4? patch # 950314: adjusted use of "sections" task # 970227: optionally add header keywords ITERMEAN, ITERSIG, ITERMED, ITERMODE # 970401: optionally add header keyword VARIANCE = ITERSIG**2. # 990322: added oneparam option; prints INDEF for possibly inaccurate parameters string image {prompt="Input image(s)"} real nsigrej {5.,min=0.,prompt="Number of sigmas for limits"} int maxiter {10,min=1,prompt="Maximum number of iterations"} bool print {yes,prompt="Print final results?"} bool verbose {no,prompt="Show results of all iterations?"} bool addheader {yes,prompt="Put returned values into image header keywords?"} real lower {INDEF,prompt="Initial lower limit for data range"} real upper {INDEF,prompt="Initial upper limit for data range"} real mean {prompt="Returned value of mean"} real sigma {prompt="Returned value of sigma"} real variance {prompt="Returned value of variance (sigma**2)"} real median {prompt="Returned value of median"} real valmode {prompt="Returned value of mode"} #Above must be "valmode" to avoid conflict w/ omnipresent task parameter "mode" string oneparam {"all",enum="all|mean|stddev|npix|midpt|mode|rms|median", prompt="Find iterative value of this one parameter only"} struct *inimglist begin string im # equals image string imglist # equals image string infile # temporary list for files string img # image name from fscan string check # string for `@filename' checking string blankstring # long blank string string headstring # strings for output formatting string mnstring # string sigstring # string npxstring # string medstring # string one_param # real mn # mean from imstat real sig # stddev from imstat real med # midpt from imstat real mod # mode from imstat real ll # lower limit for imstat real ul # upper limit for imstat int nx, npx # number of pixels used int m # dummy for countdown int i # length of image string int j # dummy integer int x # dummy integer # Expand file lists into temporary files. imglist = image infile = imglist check = substr(imglist,1,1) if(check=="@") { infile=substr(imglist,2,strlen(imglist)) } else { infile = mktemp("tmp$iterstat") sections (imglist,option="fullname",>infile) } inimglist = infile one_param = oneparam if (one_param=="rms") one_param="stddev" if (one_param=="median") one_param="midpt" j=0; med=0.; mod=0. # Loop through images while (fscan(inimglist,img) != EOF) { # Calculate stats using initial lower & upper limits # imstat(img,fields="mean,stddev,npix,midpt,mode",lower=lower,upper=upper,for-) | scan(mn,sig,npx,med,mod) if (one_param=="all") { imstat(img,fields="mean,stddev,npix,midpt,mode",lower=lower,upper=upper,for-) | scan(mn,sig,npx,med,mod) } if (one_param=="mean" || one_param=="stddev" || one_param=="npix") imstat(img,fields="mean,stddev,npix",lower=lower,upper=upper,for-) | scan(mn,sig,npx) if (one_param=="midpt") imstat(img,fields="mean,stddev,npix,midpt",lower=lower,upper=upper,for-) | scan(mn,sig,npx,med) if (one_param=="mode") imstat(img,fields="mean,stddev,npix,mode",lower=lower,upper=upper,for-) | scan(mn,sig,npx,mod) # If verbose+, print output header if(verbose){ blankstring=" " i=strlen(str(img)) if (i<=6) i=7 headstring=substr(blankstring,1,i-6) i=strlen(str(mn)) if (i<=4) i=5 mnstring=substr(blankstring,1,i-4) i=strlen(str(sig)) if (i<=3) i=4 sigstring=substr(blankstring,1,i-3) i=strlen(str(npx)) if (i<=4) i=5 npxstring=substr(blankstring,1,i-4) i=strlen(str(med)) if (i<=6) i=7 medstring=substr(blankstring,1,i-6) print("#IMAGE"//headstring//" MEAN"//mnstring//" RMS"//sigstring//" NPIX"//npxstring//" MEDIAN"//medstring//" MODE") } m = 1 while (m <= maxiter) { if (verbose) print(img," ",mn,sig,npx,med,mod) # Calculate new lower & upper limits by tossing out values nsigrej from the mean ll = mn - (nsigrej*sig) ul = mn + (nsigrej*sig) if (lower != INDEF && ll < lower) ll = lower if (upper != INDEF && ul > upper) ul = upper # imstat(img,fields="mean,stddev,npix,midpt,mode",lower=ll,upper=ul,for-) | scan(mn,sig,nx,med,mod) if (one_param=="all") { imstat(img,fields="mean,stddev,npix,midpt,mode",lower=ll,upper=ul,for-) | scan(mn,sig,nx,med,mod) } if (one_param=="mean"||one_param=="stddev"||one_param=="npix") imstat(img,fields="mean,stddev,npix",lower=ll,upper=ul,for-) | scan(mn,sig,nx) if (one_param=="midpt") imstat(img,fields="mean,stddev,npix,midpt",lower=ll,upper=ul,for-) | scan(mn,sig,nx,med) if (one_param=="mode") imstat(img,fields="mean,stddev,npix,mode",lower=ll,upper=ul,for-) | scan(mn,sig,nx,mod) # If mean is INDEF, set it to zero if(mn==INDEF) { mn=0. print("#WARNING: mean of "//img//" is INDEF! Setting mean equal to zero.") } # If stddev is INDEF, set it to 32767 if(sig==INDEF) { sig=32767. print("#WARNING: stddev of "//img//" is INDEF! Setting stddev equal to 32767.") } # If midpt (median) is INDEF, set it to the mean if(med==INDEF && (one_param=="all" || one_param=="midpt")) { med=mn print("#WARNING: median of "//img//" is INDEF! Setting median equal to mean.") } # If mode is INDEF, set it to the mean if(mod==INDEF && (one_param=="all" || one_param=="mode")) { mod=mn print("#WARNING: mode of "//img//" is INDEF! Setting mode equal to mean.") } # If after this recalculation the same number of pixels are accepted, end loop if (nx == npx) break npx = nx m = m + 1 } # If median (midpt) or mode output was not requested, set to INDEF if (med!=INDEF && (one_param!="all" && one_param!="midpt")) med=INDEF if (mod!=INDEF && (one_param!="all" && one_param!="mode")) mod=INDEF # If first image, print output header j+=1 if(j==1 && !verbose){ blankstring=" " i=strlen(str(img)) if (i<=6) i=7 headstring=substr(blankstring,1,i-6) i=strlen(str(mn)) if (i<=4) i=5 mnstring=substr(blankstring,1,i-4) i=strlen(str(sig)) if (i<=3) i=4 sigstring=substr(blankstring,1,i-3) i=strlen(str(npx)) if (i<=4) i=5 npxstring=substr(blankstring,1,i-4) i=strlen(str(med)) if (i<=6) i=7 medstring=substr(blankstring,1,i-6) if (print && !verbose) print("#IMAGE"//headstring//" MEAN"//mnstring//" RMS"//sigstring//" NPIX"//npxstring//" MEDIAN"//medstring//" MODE") } # Print statistics if (print && !verbose) print(img," ",mn,sig,npx,med,mod) mean = mn sigma = sig variance = sig**2. median = med valmode = mod if(addheader) { hedit (img, "ITERMEAN", mean, add+, ver-, show-, update+) hedit (img, "ITERSIG", sigma, add+, ver-, show-, update+) hedit (img, "VARIANCE", variance, add+, ver-, show-, update+) hedit (img, "ITERMED", median, add+, ver-, show-, update+) hedit (img, "ITERMODE", valmode, add+, ver-, show-, update+) } } if(check!="@") delete (infile,ver-, >& "dev$null") inimglist = "" #!time end ./phiirs.hlp0100644000151400000240000001755506704671442012213 0ustar phallgames.help phiirs May95 phiirs .ih NAME phiirs -- Pat Hall's Infrared Imaging Reduction Software .ih DESCRIPTION PHIIRS is an IRAF package for the reduction of IR array images. The basic reduction technique is to darksubtract, flatfield using a running flat or domeflats, skysubtract using a running sky, shift and coadd the images, use the coadded image to make object masks for the individual images, and then redo the flattening (unless domeflats were used), skysubtraction, and coadding. .sp More advanced tasks and options allow for rotated and resampled images, and scaling of nonphotometric images using photometric images. .sp .sp OUTLINE .sp Sequence of tasks (parentheses indicate optional/advanced tasks): (The DOPHIIRS task allows you to run steps 2-10,19,21 in batch mode; see the DOPHIIRS help page for more details.) .sp .nf 0. nl_findcor : find nonlinearity correction if needed (e.g. IRIM data) 1. mkbpm & mkdark : make dark and bad pixel mask images 2. (cfht/irim/irtf/onis/pisces)first : nonlinearity correction &/or darksub 3. irflat (or qkflat, or mkflat + domeflat) : flatten images 4. irsky (or qksky) : sky-subtract images (also subpattern for ONIS data) 5. irshift : find image shifts 6. ircoadd : coadd ALL the images, with magfac=1 7. mkobjmask : make object mask for the coadded image 8. masklet : make object masks for the individual images 9. (irflat objmask+ : redo flattening using object masks) 10. irsky objmask+ : redo skysubtraction using object masks 11. (irshift2 : get data needed to measure scale and rotation between two images' coordinate systems) 12. (immatch.geomap : calculate scale and rotation from irshift2 data) 13. (crzap : remove cosmic rays if desired, before rotation smears them) 14. (irrotate : rotate and resample images and recalculate shifts for them) 15. ircoadd : coadd the good second-pass (and possibly rotated) images (w/ magfac>1 if desired or necessary) 16. (photcheck : measure photometric stability of the individual images) 17. (photscale : calculate photometric scalings from photcheck output) 18. (precoadd : prepare to coadd images w/different pixel scales & FOVs) 19. (ircoadd : final coadd of the second-pass (and possibly rotated) images using photometric scalings and magfac>1 if desired) 20. (destripe : remove striping from coadded image if necessary) 21. (trim : create constant-rms image w/a certain minimum exposure time) .fi .sp .sp DETAILS .sp 0. nl_findcor : find nonlinearity correction if needed (e.g. IRIM data) .sp 1. mkbpm & mkdark : make bad pixel mask and dark images .sp 2. (cfht/irim/irtf/onis/pisces)first : nonlinearity correction &/or darksub .sp 3. irflat (or qkflat, or mkflat + domeflat) : flatten images .sp 4. irsky (or qksky) : sky-subtract images .sp 5. irshift : find image shifts Inspect images at the same time. Don't toss out ones with scattered light from bright stars just off the image, or with satellite/airplane/asteroid trails... those things can be masked out later quite easily if the images are retained. .sp 6. ircoadd : coadd ALL the images, with magfac=1 .sp 7. mkobjmask : make object mask for the coadded image .sp 8. masklet : make object masks for the individual images Now is the best time to mask out areas of scattered light, satellite trails, etc, adding them in to the object masks as well as the bad pixel masks. When redoing irflat and/or irsky with objmask+, should you redo it on the list of all images, even if they were bad enough to be excluded from the ircoadd and thus have no object mask? If so, you'll need to create fake object mask header keywords (OBJMASK) for those images (setting OBJMASK = BPMASK is good). But experience shows that most of the time it's okay to use just the `good' images to make the running flats and/or skies, unless you have a really long stretch of `bad' images (and even then you could just split the list in two). .sp 9. (irflat objmask+ : redo flattening using object masks) .sp 10. irsky objmask+ : redo skysubtraction using object masks .sp 11. (irshift2 : get data needed to measure scale and rotation between two images' coordinate systems) .sp 12. (immatch.geomap : calculate scale and rotation from irshift2 data) .sp 13. (crzap : remove cosmic rays before rotation smears them) .sp 14. (irrotate : rotate and resample images and recalculate shifts for them) .sp 15. ircoadd : coadd the good second-pass (and possibly rotated) images with magfac>1 if desired or necessary See notes about normalization map under the next (optional) ircoadd step if this is instead the last ircoadd step you'll be doing. .sp 16. (photcheck : measure photometric stability of the individual images) .sp 17. (photscale : calculate photometric scalings from photcheck output) .sp 18. (precoadd : prepare to coadd images w/different pixel scales & FOVs) .sp 19. (ircoadd : final coadd of the second-pass (and possibly rotated) images using photometric scalings and magfac>1 if desired). At this point you'll want to be sure to generate an exact normalization map. If you're coadding throughput-corrected images, put the FULL name of the throughput correction image (including .imh or whatever extension) in the header card "TPLIMG" of each such image, if not already done by irsky. This enables ircoadd (and optcoadd) to account for the varying RMS across throughput-corrected images. If the normalization map generated by ircoadd is not good enough, use task "phat.optcoadd". .sp 20. (destripe : remove striping from IRIM data coadded image if necessary) .sp 21. (trim : trim image to area w/a certain minimum exposure time if desired) See untrim.cl for an example of how to produce true output magnitudes for objects detected on a variable-exposure-time mosaic. .sp .ih HOW TO COADD IMAGES WITH DIFFERENT FIELDS OF VIEW .sp Sometimes you want to combine images taken on different telescopes with different pixel scales. Even after you resample to the same pixel scale, one set of images will be larger in size than the other. If you have more than about 120 images and thus need to stack them before combining, this is obviously a problem. .sp Here's a detailed guide to dealing with such a situation. "Big" and "small" refer to the size of the FOV after resampling to identical pixel scales. This example assumes 256x256 original images, and that to reach identical pixel scales you're resampling by a factor of 2 for the small field of view, and a factor of (2/mag) for the big field of view. .sp .nf 0) USE THE SAME REFERENCE OBJECT THRUOUT! 1) irshift2 coadd.small coadd.big 2) immatch.geomap ... 3) irrotate list.small suffix -angle 1. 2 shiftexactlist logfile bpzero+ irrotate list.big suffix 0. mag 2 shiftexactlist logfile bpzero+ where angle and mag are rotation angle and magnification from irshift2. Be sure that the rotated TPL image, if any, is created sucessfully too. 4) immatch.geoxytran all/refcoords.small all/refcoords.smallnew "" xrot=-angle yrot=-angle xmag=2 ymag=2 xref=128 yref=128 xout=256 yout=256 5) immatch.geoxytran all/refcoords.big all/refcoords.bignew "" xrot=0 yrot=0 xmag=2./mag ymag=2./mag 6) Pick one image (big or small) to be the reference image. Copy that refcoords file to refcoords.all and then concat allcoords.small,allcoords.big >> all.allcoords.sh1 concat list.small,list.big >> list.all 7) irshift list.all refimage all sh1 bs=17 8) precoadd list.small img.big (see help page for precoadd for more info) 9) precoadd list.big img.big 10) ircoadd (see help page for ircoadd for more info) .fi .sp .ih PHIIRS arose from original tasks by Doug Williams and Anne Turner and includes many cannibalized parts from the DIMSUM package of Mark Dickinson et al. See the PHIIRS homepage: http://www.astro.utoronto.ca/~hall/astro.html#software .ih BUGS 1. Older versions of IRAF might need to replace "iterstat.cl" with "iterstatold.cl" if problems occur (they should be rare). .sp 2. The "tpl" option of irsky has not been well tested. .ih SEE ALSO .endhelp