diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2015-07-08 20:46:52 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2015-07-08 20:46:52 -0400 |
commit | fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 (patch) | |
tree | bdda434976bc09c864f2e4fa6f16ba1952b1e555 /noao/digiphot/apphot | |
download | iraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz |
Initial commit
Diffstat (limited to 'noao/digiphot/apphot')
343 files changed, 56356 insertions, 0 deletions
diff --git a/noao/digiphot/apphot/README b/noao/digiphot/apphot/README new file mode 100644 index 00000000..8324e8d7 --- /dev/null +++ b/noao/digiphot/apphot/README @@ -0,0 +1,35 @@ + The Aperture Photometry Package + ---------------------------------- + +The apphot package contains routines which perform aperture +photometry in circular and polygonal apertures using fractional pixel +techniques. No point spread function fitting techniques are employed. +The photometry routines are most suitable for use on uncrowded +or moderately crowded fields. + +The apphot directory structure is listed below. The package organization +is by task, for example the center subdirectory contains routines +specific to the center task or by function, for example the nlfit +directory contains the non-linear least squares fitting routines. +The wphot task shares alot of code with the phot task. Similarly +the polymark task shares some code with the polyphot task. +The .h files are all in lib as many of them are shared by several tasks. + + |-aplib---------apphot routines used by several tasks + |-aputil--------miscellaneous useful routines + |-center--------routines specific to centering, the center task + |-daofind-------routines specific to the daofind task + |-doc-----------apphot documentation +|-apphot-----|-fitpsf--------routines specific to the fitpsf task + |-fitsky--------routines specific to sky fitting, the fitsky task + |-lib-----------apphot definitions or .h files + |-phot----------routines specific to the qphot/phot tasks + |-polyphot------routines specific to the polyphot/polymark tasks + |-radprof-------routines specific to the radprof task + |-wphot---------routines specific to the wphot task + |-test----------directory of test data + + +Lindsey Davis +NOAO IRAF GROUP +November 1991 diff --git a/noao/digiphot/apphot/Revisions b/noao/digiphot/apphot/Revisions new file mode 100644 index 00000000..99578517 --- /dev/null +++ b/noao/digiphot/apphot/Revisions @@ -0,0 +1,1582 @@ +.HELP revisions Jun88 noao.digiphot.apphot +.nf + + +apphot/wphot/apwmag.x + Minor typo where procedure closed with a ']' (8/19/09, MJF) + +apphot/wphot/t_wphot.x + A call to apstats() was being passed 'cl' instead of 'ap' (8/19/09, MJF) + +apphot/phot/apqradsetup.x +apphot/phot/apradsetup.x +apphot/wphot/apbwphot.x + The ap_wmag() was incorrectly being used as apwmag() (8/17/09, MJF) + +apphot/aputil/apvectors.x + Modified so the calculation is done in floating point (8/15/09, MJF) + +apphot/daofind/apfdcolon.x + A call to apsets() was mistakenly using a closed 'cl' pointer instead + of the 'ap' apphot struct pointer (8/15/09, MJF) + +apphot/radprof/apfrprof.x + The cvrject() subroutine was called w/ an extra argument (7/12/09, MJF) + +apphot/aputil/apnlfuncs.x + 1. Comments now say whether a parameter is a variance or a sigma. + 2. Check for zero variance or sigma were improved. The default value + is a sigma of 6 or a variance of 36. + 3. CGAUSS1D was setting the wrong variable (z instead of r2) when + a zero variance is found. + (3/18/09, Valdes: reported by Jason Quinn) + +aplib/apwparam1.x + The CLEAN parameter was being printed with UN_CSCALEUNIT units instead + of UN_CSWITCH (7/8/08, MJF) + +aplib/apwparam1.x + The format string had 'yyy' instead of 'yyyy'. + (5/27/08, Valdes) + +apphot/fitpsf/apsffit.x +apphot/phot/apmag.x +apphot/phot/apremag.x +apphot/wphot/apwmag.x +apphot/wphot/apwremag.x + Fixed some procedure calls being closed with a ']' instead of a ')' + (2/17/08, MJF) + +======= +V2.12.3 +======= + +apphot/aputil/apnlfuncs.x + Catch error when the input sigma is zero. (5/2/05, Valdes) + +======= +V2.12.2 +======= + +apphot/aputil/aptopt.x + Catch error when the input sigma is zero. (2/24/03, Valdes) + +apphot/center/t_center.x +apphot/fitpsf/t_fitpsf.x +apphot/fitsky/t_fitsky.x +apphot/phot/t_phot.x +apphot/phot/t_qphot.x +apphot/polyphot/t_polyphot.x +apphot/radprof/t_radprof.x +apphot/wphot/t_wphot.x + The handling of the "default" parameter value for coordinate lists + failed when the input list had more than one image. The way this + was done relied on a string not being modified but it was being + modified in a call to apfroot. (9/30/02, Valdes) + +======= +V2.12.1 +======= + +apphot/center/apcenter.x +apphot/fitpsf/apfitpsf.x +apphot/fitsky/apsky.x +apphot/phot/apphot.x +apphot/polyphot/apyhot.x +apphot/radprof/apradprof.x +apphot/wphot/apwphot.x + Fixed problems with the 'v' that can occur if the same star is measured + with different parameters without an intervening cursor move. + + Davis, June 20, 2002 + +apphot/fitsky/mkpkg + declaration. Added a missing <imhdr.h> file dependency to the apsky.x + declaration. + + Davis, December 13, 2001 + +apphot/daofind/mkpkg + Removed an unnecessary ../lib/display.h file dependency from the apbfdfind + declaration. Added a missing ../lib/display.h file dependency to the + apfdcolon.x declaration. + + Davis, December 13, 2001 + +apphot/aputil/appcache.x + Added a call setting IM_BUFFRAC to 0 to the memory caching code in the + apphot package tasks in order to force the imio buffer to be the size of + the input image. + + Davis, December 10, 2001 + +apphot/center/apcenter.x + Fixed a boolean / integer conversion problem in the interactive variable. + This bug should not be present in released code. + + Davis, September 19, 2001 + +apphot/polyphot/apymkinit.x + The call to ap_defsetup was missing the fwhmpsf argument. Since + this is never used in the code this bug may not cause a problem. + + Davis, September 19, 2001 + +apphot/aplib/apwres2.x + The pargr routine was being called with a double precision constant + 0.0d0 argument. + + Davis, September 19, 2001 + +apphot/fitsky/apcentroid.x + Fixed a real/double type mismatch in a call to alimr. + + Davis, September 19, 2001 + +apphot/ + Modified all the apphot tasks to accept input coordinates in logical, tv, + physical, or world coordinates and to write the output coordinates in + logical, tv, or physical coordinates. One consequence of this is that + the apphot tasks will now work correctly off image sections in interactive + mode. Another is that users can work on image sections while preserving + the coordinate system of the entire image. + + Davis, May 30, 2000 + +apphot/ + Modified all the apphot tasks to strip the directory information from + the input image and coordinate file names written to the output files, + to the terminal, and to the plot headers. The colon commands will still + read and write full image and coordinate file path names. This change + improves the likelyhood that the full root image name will be written + to the output. This root image name is used by the photometric calibration + code to construct images sets. + + Davis, April 19, 2000 + +apphot/*/mkpkg + Added some missing file dependencies and deleted some unecessary ones + from the mkpkg files. + + Davis, September 20, 1999 + +apphot/polyphot/apyfit.x +apphot/polyphot/appyerrors.x +apphot/aplib/apwres2.x + Improved the error reports for polyphot in the case where the effective + aperture is 0, which may occur if the polygon is off the image or due + to fractional pixel effects. + + Davis, August 10, 1999 + +apphot/polyphot/apyget.x +apphot/polyphot/apmkpylist.x +apphot/polyphot/ayphot.x +apphot/polyphot/apyradsetup.x + Modified the polygon drawing code (the g keystroke command) to flush + the graphics buffer after every polygon segement is drawn instead + of after the polygon is complete. + + Davis, July 9, 1999 + +apphot/aputil/apotime.x + Modified the code which reads the time of observation value from the image + header to extract the time field from the date-obs keyword if it is + present. + + Davis, May 11, 1999 + +apphot/aputil/apdate.x + Modified the date and time photometry file keyword encoding tasks to + write the date and time in the proper fits format and in units of GMT. + Note that GMT is deactivated in digiphotx because the necessary routine + is not yet in the system. + + Davis, May 11, 1999 + +apphot/aputil/apfnames.x + Modified the default input and output file nameing routines to handle + input images with kernel sections and cluster indices more gracefully. + + Davis, January 17, 1999 + +apphot/aplib/apwparam1.x +apphot/aputil/apdate.x + Modified the apphot output file writing routines to write the "DATE" + keyword in the new FITS standard format, eg. yyyy-mm-dd instead of + mm-dd-yy. + + Davis, December 29, 1998 + +apphot/daofind/t_daofind.x + Modified the default output file naming code to support names of the + form "directory/default" as well as "default" in interactive mode + as well as non-interactive mode. + + Davis, February 13, 1998 + +apphot/daofind/apfind.x + Modified the centering routines to protect against a rare floating + divide by 0 condition. + + Davis, June 24, 1997 + +apphot/aptest.cl + Modified the rfits calling sequence so that the test script will + run correctly with the new version of rfits. + + Davis, May 29, 1997 + +apphot/daofind/apfind.x + Modified the routine that computes the new roundness parameter to check + for <= 0.0 quantities in the denominator of the new roundness statistic. + Zero valued quantities can in rare cases cause a divide by zero or + floating operand error. + + Davis, July 21, 1996 + +apphot/lib/polyphotdef.h +apphot/aplib/apset1.x +apphot/aplib/apset2.x +apphot/aplib/apset.x +apphot/aplib/apstat1.x +apphot/aplib/apstat2.x +apphot/aplib/apstat.x +apphot/aplib/apwres2.x +apphot/aplib/aparrays.x +apphot/aplib/aprcursor1.x +apphot/aplib/mkpkg +apphot/phot/apmag.x +apphot/phot/apremag.x +apphot/phot/appinit.x +apphot/phot/appfree.x +apphot/phot/appplot.x +apphot/phot/apmeasure.x +apphot/phot/apcomags.x +apphot/phot/mkpkg +apphot/wphot/apwmag.x +apphot/wphot/apwremag.x +apphot/wphot/apgmeasure.x +apphot/wphot/aptmeasure.x +apphot/wphot/mkpkg +apphot/radprof/apfrprof.x +apphot/radprof/aprpindex.x +apphot/radprof/aprpplot.x +apphot/radprof/aprmmeasure.x +apphot/polyphot/apyfit.x +apphot/polyphot/mkpkg + Modified the aperture sum routines to work in double precision where + appropriate. This avoids rounding errors that become visible when + working on synthetic data or data with neglible sky noise. + + Davis, July 18, 1996 + +apphot/doc/qphot.hlp + Fixed some typos / omissions in the qphot help page. + + Davis, April 11, 1996 + +apphot/apphot.cl +apphot/apphot.men + Replaced the txdump task with the more general pdump task and added the + pcalc, pconvert, prenumber, pselect, and psort tasks to the apphot + package. + + Davis, March 15, 1996 + +apphot/aplib/apwres1.x +apphot/daofind/apfind.x + Fixed a serious bug in the daofind centering code which resulted + in incorrect fractional pixel corrections being computed. This error + can most easily be detected by plotting the histogram of the fractional + pixel corrections for an image with a large number of detected objects. + The histogram will be modulated with "peaks" around the .33 and .66 + fractional pixel values. + + This bug is also present in the standalone version of daophot ii. User + should obtain a new version of daophot ii from Peter Stetson. + + Added a new roundness statistic to daofind. This statistic is sensitive + to objects which are elongated in directions other than x and y. + + Davis, March 15, 1996 + +apphot/center/apcenter.x +apphot/fitpsf/apfitpsf.x +apphot/fitsky/apsky.x +apphot/phot/apphot.x +apphot/phot/apqphot.x +apphot/polyphot/apyphot.x +apphot/radprof/apradprof.x +apphot/wphot/apwphot.x + The new m keystroke command was doing exactly the same thing as the n + keystroke command due to a confusion of the key and colonkey variables. + + Davis, Feb 12, 1996 + +apphot/doc/centerpars.hlp +apphot/center/mkpkg +apphot/center/apfitcen.x +apphot/center/aprefitcen.x +apphot/center/apcplot.x +apphot/aputil/apgtools.x + Modified the centering algorithm code to recognize 3 separate cases: + 1) cthreshold = 0.0 invokes the default thresholding technique for + each algorithm, 2) cthreshold = +val sets the threshold to some + value above (below) the local data minimum (maximum), 3) cthreshold=INDEF + or undefined turns off all thresholding. This change does not + change the default behavior of the code. + + Changed the definition of local data minimum from the minimum pixel + in the centering box to the minimum median value for each row in the + centering box. This gives a value much closer to the background values + and protects against very low valued pixels in the centering box defining + the thresholding level. + + Davis, Sept 29, 1995 + +apphot/fitsky/apskybuf.x + Changed the misleading error return code from AP_SKY_OUTOFBOUNDS to + AP_NSKY_TOO_SMALL in the case when all the sky are out of the good + data range. + + Davis, June 22, 1995 + +apphot/daofind/apfind.x + Added a check to avoid a divide by zero error in the code which computes + the x and y positions of the detected objects. The divide by zero error + can occur when the datamin value is too high for the image and there + are not enough points to accurately compute the new x and y position. + + Davis, June 19, 1995 + +apphot/aplib/mkpkg +apphot/aplib/apwres1.x +apphot/aplib/apwres2.x +apphot/aplib/apwres3.x +apphot/aplib/apwres4.x +apphot/doc/phot.hlp +apphot/doc/polyphot.hlp +apphot/doc/qphot.hlp +apphot/doc/radprof.hlp +apphot/doc/wphot.hlp + Added a FLUX column to the output of the PHOT, POLYPHOT, QPHOT, RADPROF, + and WPHOT tasks and updated the appropriate help pages. + + Davis, Nov 14, 1994 + +apphot/daofind/apfdstars.x +apphot/daofind/apbfdfind.x + Added a missing check for an INDEF value of sigma that could cause + a floating point overflow in daofind when run from the APPHOT package + with the default parameters. + + Davis, Oct 20, 1994 + +apphot/aplib/apwres2.x + Added a check to make sure that the OTIME and IFILTER fields do not + overflow the 23 character space allotted for them in the output file. + + Davis, Oct 12, 1994 + +apphot/center/t_center.x +apphot/daofind/t_daofind.x +apphot/fitpsf/t_fitpsf.x +apphot/fitsky/t_fitsky.x +apphot/phot/t_phot.x +apphot/phot/t_qphot.x +apphot/polyphot/t_polymark.x +apphot/polyphot/t_polyphot.x +apphot/radprof/t_radprof.x +apphot/wphot/t_wphot.x + Fixed a bug in the default input and output file naming code which was + causing the directory specifications to be stripped from the names. + + Davis, Oct 4, 1994 + +apphot/phot/apphot.x +apphot/phot/apqphot.x +apphot/wphot/apwphot.x +apphot/polyphot/apyphot.x +apphot/radprof/apradprof.x +apphot/phot/phot.key +apphot/phot/qphot.key +apphot/wphot/wphot.key +apphot/polyphot/polyphot.key +apphot/radprof/radprof.key +apphot/doc/phot.hlp +apphot/doc/qphot.hlp +apphot/doc/wphot.hlp +apphot/doc/polyphot.hlp +apphot/doc/radprof.hlp + Added a new keystroke command 'a' to the phot, qphot, wphot, polyphot + and radprof commands. The a keystroke command compute a sky value + by averaging several sky values sampled in different regions of the + image. Basically it is a loop over the the t keystroke command. + The sky value in each region is computed using the current algorithm + and geometry and the individual sky, sky sigma and sky skew values + are averaged to produce a final sky, sigma and skew, whereas the + number of sky pixels and number of rejected sky pixels are summed. + The a keystroke command is intended for use with the p and o keystroke + commands to produce an offset sky measurement capability. + + Davis, Feb 10, 1994 + +apphot/fitpsf/apsffit.x +apphot/fitpsf/apsfrefit.x +apphot/aplib/apwres4.x + 1. Modified the fitpsf task fitting routines so that the parameter and + parameter error arrays are initialized to INDEF (instead of being left + with the values from the previous fit), in the case that the + fitting box is entirely off the image or that that there are too few + pixels in the fitting box to fit the model psf. + 2. Modified the output formatting routines to print the errors in + the fitted rsigma (function=radgauss), xsigma and ysigma (function= + elgauss), and rgyrat and ellip (function=moments) to three decimal + places instead of two. + + Davis, Jan 17, 1994 + +apphot/center/t_center.x +apphot/fitpsf/t_fitpsf.x +apphot/fitsky/t_fitsky.x +apphot/phot/t_phot.x +apphot/polyphot/t_polyphot.x +apphot/phot/t_qphot.x +apphot/phot/t_radprof.x +apphot/wphot/t_wphot.x + If the number of input images was greater than one, the number of output + files exactly equal to one, and the input coordinate file for the image + did not contain any decodable coordinates the coordinate file rather + than the empty output file is deleted. This was ocurring because the + output file was not being correctly stored each time through the image + loop and empty output files are deleted by the apphot tasks. + + Davis, Dec 31, 1993 + +apphot/fitsky/aprefitsky.x + The SCALE parameter in the call to ap_crossor was incorrectly + dereferenced as AP_SCALE(sky) instead of AP_SCALE(ap). + + Davis, Sep 13, 1993 + +apphot/aplib/apinpars2.x + The shiclip parameter, default = 0.0, was incorrectly being set to the + value of the sloclip parameter at startup time. + + Davis, Sep 9, 1993 + +apphot/center/aprefitcen.x + The CMAXITER parameter was incorrectly referenced in the call to + the ap_lgctr1d routine inside the routine aprefitcenter. + This centering routine is not often used, and the bug is trigggered + only if an object is recentered using different algorithm parameters + but the same image data, something only likely to occur in interactive + mode. + + Davis, Sep 6, 1993 + +apphot/center/apcencolon.x + The arugument cmdstr in the routine apcentercolon was declared as + "char cmdstr" instead of "char cmdstr[ARB]. This has not caused any + errors in the code but is poor style. + + Davis, Sep 6, 1993 + +apphot/phot/apgqppars.x +apphot/doc/qphot.hlp +apphot/fitskypars.par +apphot/doc/fitskypars.hlp + Changed the default sky fitting algorithm for the qphot and phot tasks from + "mode" to "centroid" with histogram smoothing, to minimize problems + with data taken at low light levels which have poorly sampled + histograms. + + Davis, Aug 14, 1993 + +apphot$ + The sky fitting routines were revised. Two new parameters, ploclip and + phiclip, which define the percentage of pixels to clip on the low + and high sides of the sky pixel distribution were added to fitskypars. The + fitskypars parameter skreject was split into two parameters + sloreject and shireject which define the low and high side rejection + parameters respectively. For the mean, median, and mode algorithms + the first rejection cut is now made below sky - min (smax - sky, sky - smin, + sloreject * skysigma) and above sky + min (smax - sky, sky - smin, + shireject * skysigma) where sky is the first estimate of the mean, median, + and median of the sky pixels respectively, instead of below and above the + skreject rejection limits alone. The median is computed using + the average of 5% of the pixels around the median instead of 10 pixels. + All the histogram dependent algorithms: histplot, centroid, gauss, + crosscor, ofilt now use the median of the sky pixels as the center + of the histogram, and define the extent of the + histogram in a manner similar to that used for the first cut in + the mean, median, and mode algorithms. The sigma parameter is + no longer used to define the extent and binsize of the sky histogram. + Instead the computed sky sigma is used. + + Added m and n keys to the apphot tasks. These keys operate in the same + way as the :m and :n keys which have no arguments. + + Added the o key to the apphot tasks. This behaves in the same way + as the p key but outputs the results to the output results file. + + Davis, Feb 24, 1993 + +apphot/aputil/apgflags.x + Removed this routine which was not being used and referenced gio.h from + the apphot library. + + Davis, Feb 11, 1993 + +apphot/daofind + + Added the findpars pset to the daofind task and removed the parameter + threshold from datapars to findpars. All the detection algorithm + parameters moved to findpars. + + Changed the name of the output convolved image to starmap. Added + an option to output the best fit sky image skymap. + + Davis, Sept 17, 1992 + +apphot$ + Modified all tasks (daofind, center, fitpsf, fitsky, phot, polymark, + polyphot, qphot, radprof, and wphot) that were designed to draw marks + on the image display to use the imd kernel. All graphics + drawing commands are done with portable gio calls. A temporary routine + which uses the imd interface to fetch the display device viewport and + window is called each time a new image is mapped. A warning message + is issued if the image is not loaded in the display and the default + full frame viewport is used. All display drawing is done to the + current frame, even if the current frame is not the frame containing + the image. The imd kernel does not support the gflush command so + a gframe command is used instead. This can create a messy metacode + file but is a reasonable approximation for interactive use. + + Davis, Sep 2, 1992 + +apphot$phot/apphotcolon.x +apphot$phot/apqcolon.x +apphot$radprof/aprpcolon.x +apphot$wphot/apwpcolon.x +apphot$wphot/aptmeasure.x +apphot$wphot/apgmeasure.x +apphot$aplib/apverify1.x +apphot$daofind/apfcolon.x +apphot$fitpsf/apppsf.x +apphot$fitpsf/apsfcolon.x +apphot$polyphot/apycolon.x + Added some missing sfree statements. + + Davis, Sep 2, 1992 + +apphot$fitsky/aplgsky,x + The test "if (ier != AP_OK)" was being made instead of the proper test + "if (iter < 0)". The local variable ier was never defined or used which + tripped a bug in the DEC fortran compiler. + + Davis, August 3, 1992 + +apphot$datapars.par +apphot$centerpars.par +apphot$doc/datapars.hlp +apphot$doc/centerpars.hlp +apphot$lib/noisedef.h +apphot$lib/noise.h +apphot$lib/centerdef.h +apphot$lib/center.h +apphot$center/apcinit.x +apphot$center/apcencolon.x +apphot$center/apcshow.x +apphot$center/apcconfirm.x +apphot$center/apcplot.x +apphot$center/apfitcen.x +apphot$center/refitcen.x +apphot$aplib/apinit.x +apphot$aplib/apnscolon.x +apphot$aplib/apnshow.x +apphot$aplib/apinpars.x +apphot$aplib/apoutpars.x +apphot$aplib/aprcursor1.x +apphot$aplib/apverify1.x +apphot$aplib/apset2.x +apphot$aplib/apstat2.x +apphot$aplib/apwparam1.x + Changed the units of the cthreshold parameter to sigma and moved it + to the centerpars parameter set. + + Davis, July 7, 1992 + +apphot$center/t_center.x +apphot$fitpsf/t_fitpsf.x +apphot$fitsky/t_fitsky.x +apphot$phot/t_phot.x +apphot$phot/t_qphot.x +apphot$polyphot/t_polyphot.x +apphot$radprof/t_radprof.x +apphot$wphot/t_wphot.x + 1. The apphot tasks center, fitspf, fitsky, phot, qphot, polyphot, + radprof, anbd wphot were not closing the coordinate files correctly + in the case that coords="default" was the length of the coordinate + list was being incorrectly set to 1. + + Davis, June 24, 1992 + +apphot$aplib/apapcolon.x + 1. The interactive :image <imname> command was not updating the time of + observation correctly since the obstime keyword was not being read. + + Davis, June 23, 1992 + +apphot$polyphot/apyfit.x + 1. Improved the precision of the polyphot fractional pixel algorithm. + + Davis, April 1, 1992 + +apphot$polyphot/apyfit.x + 1. The intersection points of an image line and a polygon could + be incorrectly translated into a list of ranges if the polygon was + concave and contained a side collinear with the image line. + + Davis, February 25, 1991 + +apphot$daofind/apfdstars.x + 1. Removed an extraneous "include <fset.h> statement from daofind. + + Davis, November 20, 1991 + + *** Ran spplint on the apphot code + +apphot$daofind/apfshow.x +apphot$aplib/apnshow.x +apphot$aplib/apqshow.x +apphot$aplib/apwparam1.x + 1. Fixed several places in the code where the boolean function itob + was declared an integer. + +apphot$aplib/apoutpars.x + 1. Removed an extra maxch argument from all the clppset calls. + +apphot$fitpsf/apppfpars.x +apphot$phot/apqppars.x + 1. Removed an extra argument from the clpstr call. + +apphot$aplib/aprcursor2.x + 1. The call to ap_rparam in ap_cpapert was being made with the integer + argument PSFAPERT instead of the string argument KY_PSFAPERT. + +apphot$fitsky/apskycolon.x + 1. The calls to ap_apcolon and ap_nscolon were being made with a type + real junk variable instead of a type in junk variable. This was harmless. + +apphot$fitsky/apspshow.x + 1. Changed a pargi call to a pargb call. + + Davis, Oct 7, 1991 + +apphot$test/aptest.cl + 1. Made some minor formatting changes to the aptest CL script. + + Davis, Aug 23, 1991 + +apphot$aplib/apfrprof.x + 1. Radprof was incorrectly normalizing the integral of the total intensity, + by failing to multiply by the step size. + + Davis, Aug 23, 1991 + +apphot$aplib/apwres2.x +apphot$radprof/apprprof.x + 1. Changed the unit on output for the radial profile and fwhm from "pixels" + to "scale". + + Davis, Aug 23, 1991 + +apphot$aplib/apwres1.x + 1. Changed the unit for RAPERT on output from "pixels" to "scale". + + Davis, Aug 23, 1991 + +apphot$ + 1. Support for picking up the time of observation, for example UT, was + added to all the apphot routines. + + 2. Apphot will now print out INDEF for all object which have bad data + inside the photometry apertures. + + 3. Whitespace is stripped from the filter id and the iraf version + definition before either of these quantities is written to the photometry + files. + + 4. The output file header parameters are now 23 characters long instead + of 15. + + 5. The numerical values of the error codes have been changed for book- + keeping purposes. + + Davis, August 1, 1991 + +apphot$apselect/ + 1. Added the replacement task for apselect, txdump, to the package. + + 2. Added the pexamine task to the package. + + 3. Removed the apselect subdirectory. + + Davis, July 29, 1991 + +apphot$qphot/ +apphot$polymark/ +apphot$nlfit/ + + 1. Moved all the routines in the qphot subdirectory into the phot + subdirectory and deleted the qphot subdirectory. + + 2. Moved all the routines in the polymark subdirectory into the polyphot + subdirectory and deleted the polymark subdirectory. + + 3. Removed the old nlfit library from the apphot package and replaced it + with the new version which has been installed in the math package. + The affected algorithms are the gauss centering algorithm, the gauss + sky fitting algorithm, and the fitpsf task radial and elliptical gaussian + function fitting algorithms. + + 4. The errors computed by the gauss centering routine are smaller in the + new version than the old version as the old code was dividing by sqrt + (nfree) instead of sqrt (npts). + + Davis, July 28, 1991 + +apphot$fitpsf/apsffit.x +apphot$fitpsf/apsfrefit.x +apphot$fitpsf/apsfradgauss.x +apphot$fitpsf/apsfelgauss.x + 1. The errors computed by the fitpsf radial and elliptical gaussian + fitting routines are smaller in the new version than the old version + as the old code was dividing by sqrt (nfree) instead of sqrt (npts). + + 2. The error output for rsigma in the fitpsf radial gaussian fitting + routine and for xsigma/ysigma in the elliptical gaussian fitting routines + in the old code was actually the error in rsigma ** 2 or xsigma ** 2 + and ysigma ** 2 respectively. These errors were too small. + + Davis, July 28, 1991 + +apphot$center/apfitcen.x +apphot$center/aprefitcen.x +apphot$center/apgctr1d.x +apphot$center/aplgctr1d.x +apphot$aputil/aptopt.x +apphot$aputil/apqzero.x + 1. Modified all the centering routines so that the fitted centers are + contrained to stay in the fitting box after each iteration. The gauss + algorithm in particular could runaway when fitting objects near the + edge of the frame or very weak objects. + + 2. Fixed a bug in the optimal filter algorithm wherein the + normalization procedure could fail if there wa no star in the + centering box. + + Davis, May 30, 1991 + +apphot$center/apcconfirm.x +apphot$fitsky/apsconfirm.x +apphot$phot/appconfirm.x +apphot$wphot/apwconfirm.x +apphot$polyphot/apyconfirm.x +apphot$radprof/aprconfirm.x +apphot$fitpsf/appsfconfirm.x + 1. Modified all the apphot task verify routines to verify datamin and + datamax. + + Davis, Mar 29, 1991 + +apphot$nlfit/nliter.x +apphot$nlfit/nlacpts.x + 1. Modified nlfit routines to get rid of the wtflag argument in those + routines where it was not actually used. + + Davis, Nov 20, 1990 + +apphot$aputil/apwlimr.x +apphot$fitpsf/apsfradgauss.x +apphot$fitpsf/apsfelgauss.x +apphot$fitpsf/apsffit.x +apphot$fitpsf/apsfrefit.x + 1. Modified the fitpsf task so the the radial gaussian and elliptical + gaussian fitting routines use the maximum (emission objects) or + minimum (absorption objects) pixel position as the first guess for + a good position instead of the center position. + + Davis, Nov 16/1990 + +apphot$daofind/apbfdfind.x +apphot$daofind/apconvolve.x +apphot$daofind/apfdstars.x + 1. Fixed a bug in the batch mode execution of DAOFIND wherein + DAOFIND quit with an "cannot write pixel file error" when run on + a previously existing convolved image. This bug was introduced by the + Mar 12 1990 bugfix. + + Davis, Nov 8, 1990 + +apphot$polyphot/t_polyphot.x +apphot$lib/polyphot.h + 1. Changed the default size of MAX_NVERTICES from 100 to 900 to satisfy + some surface photometry people. Removed a redundant MAX_NVERTICES + declaration in t_polyphot.x + + Davis, Aug 24, 1990 + +apphot$phot/apmagbuf.x + 1. Phot was refusing to fit stars whose apertures were < 1.0 pixels from + the edge of the image because the out-of-bounds criterion was too + conservative. I modified the code to remove this problem. + + Davis, Aug 6, 1990 + +apphot$daofind/apbfdfind.x +apphot$daofind/apfdstars.x +apphot$daofind/apfind.x + 1. Changed the daofind program to automatically include the relative + error in the detection threshold. + +Davis, July 17, 1990 + +apphot$fitsky/apskybuf.x + 1. In a few cases due to fractional pixel effects the skyfitting + routines were not preallocating sufficient space to hold the sky + pixels resulting in a memory corruption error. + + Davis, June 27, 1990 + +apphot$aplib/apfrprof.x,mkpkg + 1. Modified radprof so that it would integrate 2*PI*r*I instead of + just I itself. + + Davis, June 18, 1990 + +apphot$aplib/apfdres.x + 1. Renamed the round and sharp parameters to roundness and sharp to + remove and ambiguity in the naming convention. + + Davis, May 24, 1990 + +apphot$daofind/apconvolve.x + 1. Added an imflush after the last write in apconolve which cured + a "pixel file is truncated error". This error showed up when + daofind was run on an image that was 641 by 1025 but not on + one that was 640 by 1024. Apparently this problem has been there + all along but only occurs very rarely. + + Davis, Mar 29, 1980 + +apphot$aptest.cl +apphot$aptest.par + 1. Added the aptest task to the apphot package. + + Davis, Mar 19, 1990 + +apphot$aplib/ + 1. Fixed two bugs in the output formating code. Long file names could + overflow the fixed format space allotted and destroy the syntax of the + file making it impossible for apselect to decode it. Second the COORDS + parameter was mistakenly typed as integer instead of string. + Davis, Mar 14, 1990 + +apphot$daofind/ + 1. Fixed a bug which was causing daofind to fail to compute the convolved + image when the input and output images were in hhh format. The hhh format + was failing the test [if (IM_PIXFILE(im) == EOS)] as the pixel + file names are set at different places in the oif and stf kernel. + The test was dangerous and redundant, and has been removed. + + Davis, Mar 12, 1990 + +apphot$qphot/mkpkg + 1. Removed a duplicate entry for apqcolon.x from the mkpkg file. + + Davis, Feb 20, 1990 + +apphot$center/apcsnratio.x + 1. Recoded this routine slightly to avoid an optimizer bug in + the 386i version. + + Davis, Feb 13, 1990 + +apphot$center/apcinit.x +apphot$fitsky/apsinit.x,apsplot.x +apphot$phot/appplot.x + 1. The sky fitting algorithm string was not being correctly set if + salgorithm was "gauss" or "median" resulting in garbage in the output + file header. The correct algorithm was being used. + + 2. A floating point error would occur if salgorithm = "constant", + sigma = "INDEFR" and radial profile plotting was enabled. The problem + occurred because the plot was trying to draw the 3 * sigma of the + sky line by adding the sky value and the sky sigma which is INDEFR. + + 3. Disabled plotting the centering pixel buffer in the case where + "calgorithm" was none and the sky pixel buffer when salgorithm is + "none". + + Davis, Feb 7, 1990 + +apphot$fitpsf/apfitpsf.x +apphot$fitpsf/aprefitpsf.x + Fixed a bug in the weighting scheme for fitpsf in which the gain was + not scaling the image intensities correctly. I also added a check + for 0 valued weights. + + Davis, Jan29, 1990 + +apphot$ + Added a setup menu mode to all the apphot tasks. When the user types + i they enter the setup menu instead of a pre-defined set of commands. + The default setup is still available as the v key, but each parameter + can now be set individually as well. + + The documentation has been brought up-to-date. + + Davis, Jan 29, 1990 + +apphot$phot/t_phot.x + + Added calls to ap_airmass and ap_filter to the phot task as the filter + and airmass were not updating correctly. + + Davis, Jan 16, 1990 + +apphot$ + Four new parameters airmass, xairmass, filter, ifilter were added to + the datapars task to permit users to pick up the filter and airmass + quantities form the image headers for later transmission to calibration + programs. + + Davis, Nov 28, 1989 + +apphot$radprof.par + The default value of the verbose parameter in radprof was yes + instead of no as it should have been. + + Davis, Nov 28, 1989 + +apphot$ + Added a new algorithm "mean" to the sky fitting options. + + Davis, Nov 17, 1989 + +apphot$ + Added an update parameter to all the apphot tasks. If verify is yes + and the task is run in non-interactive mode update will update + the critical parameters into the psets. + + Davis, Nov 16, 1989 + +apphot$radprof/t_radprof.x + Removed a defunct define MAX_NAPERTS 15 statement from the + radprof task. It now uses the definition in phot.h like all + the other tasks. + + Davis, Nov 9, 1989 + +apphot$daofind/ + Changed daofind so that a new .coo file is output everytime daofind + is run in interactive mode. + + Davis, Oct 30, 1989 + +apphot$fitsky/apmode.x + Made some subtle mods to the mode fitting algorithm. In particular + only the first cut is made around the median the remainder are around + the mode. + + Davis, October 11, 1989 + +apphot$ + 1. apphot$center, fitsky, phot, wphot, polyphot, fitpsf and radprof tasks + Activated the datamin and datamax parameters. Pixels outside + this range are rejected from sky fitting algorithms and from the + non-linear least squares fits in fitpsf and radprof. If a bad pixel + is in the centering aperture or in a photometry aperture a magnitude + is still computed but a warning message is issued. + + The only task where these parameters are not currently implemented + is daofind, pending algorithm review. + + 2. apphot$polyphot/apyphot.x + Added a keystroke option to fit polygons that are not shifted to the + current cursor position. + + 3. apphot$fitsky/aprefitsky.x + Fixed an error in the stellar position reported on the plot in the + radplot option for sky fitting. The last cursor position was not + being reported. + + 4. apphot$fitsky/apmode.x + Changed the cut to one around the mode. Things look ok. + + Davis, October 10, 1989 + +apphot$apselect/apkeywords.x + 1. Fixed a bug in the apselect task. Apselect was not picking up changes + int the keywords (#K) values correctly. The pointer in the ky_addval + procedure was being incorrectly computed and the new value was being + put in the wrong place. + + Davis, Sept 15, 1989 + +apphot$ + 1. I removed the query for fwhmpsf from phot. + + 2. I fixed a serious problem in daofind when interactive = yes and + the task was rerun on the same convolved image but using a new + threshold. There was also a problem with the naming of the + temporary image. + + Davis, Aug 22, 1989 + +apphot$aplib/aprcursor.x +apphot$aplib/apradpsf.x + + 1. The prompt for the psf fitting box parameter box has been changed from + "centering radius" to "fitting box half width". + The prompt for the centering box parameter cbox has been changed from + "centering radius" to "centering box half width". + + 2. The code to quickly center the radial profile before fitting has + been added to the interactive setup routine. Somehow the fitpsf + task was overlooked when this update was made originally. + + Davis, Aug 1, 1989 + +apphot$aprcursor.x + The procedure ap_caper() inside apphot$aplib/aprcursor.x was define as + a type real procedure but called as a subroutine. I removed the type + real declaration. + + Davis, July 31, 1989 + +Version 2.8 export + +************************************************************************* + +apphot$ + 1. The inverse of the scale was being incorrectly printed out by + the :show command. + + 2. Fwhmpsf is in scale units not pixels as listed in datapars. + + 3. Exposure, ccdread and gain were not being updated correctly + in interactive mode. + + Davis, June 20, 1989 + +apphot$ + 1. A new parameter scale has been added to datapars and integrated into + the apphot tasks. All the radial profile plots will now display + units of scale and of pixels. The .hlp. .key and : commands + have all be changed appropritately. Testing is complete. + + 2. Some minor changes have been made to the quick look output formats. + + 3. A verbose and verify switch have been added to all the appropriate + tasks. + + 4. Daofind has been modifed so that the convolved image is automatically + up to date if any of the convolution kernel parameters have been + modified. + + Davis, May 27, 1989 + +apphot$ + 1. Add the verify switch to radprof and wphot. + + 2. Began separation of the scale and fwhmpsf parameter. + Scale was added to the apphot structure. + + Davis, May 17, 1989 + +apphot$ + 1. Fixed an error in the definition of the skyfile format in phot.hlp + and wphot.hlp. The are seven columns not five with the x and y position + in columns 1 and 2. + + 2. Added the verify switch to the center, fitsky, fitpsf and polyphot tasks. + + Davis, Mar 20, 1989 + +apphot$ + 1. Modified the prompts in datapars.par, centerpars.par, fitskypars.par + and photpars.par. + + 2. Added a confirm switch to the phot task. + + Davis, Mar 15, 1989 + +apphot$ + 1. Changed the interactive setup routine in daofind so that the radial + profile is centered before the interactive setup menu is entered. + + 2. A confirm switch has been added to the daofind task so that in batch + mode (the default) the user can check/confirm/modify the critical + task parameters. A similar 'v' for verify key has been added to + the list of interactive menu setup commands. + + Davis, Mar 14, 1989 + +apphot$ + 1. Edited the daofind parameter file to make the prompts more illuminating. + + 2. Changed all the daofind subdirectory procedure names beginning with + ap to ap_. This continues the apphot cleanup begun in January. + + 3. Fixed a bug in the interactive daofind code. If no convolution image + was opened daofind was trying to delete a nonexistent image at + task termination. + + Davis, Mar 13, 1989 + +apphot$apselect/ + I changed all the apselect subdirectory procedure names to begin with + ap_. This continues the cleanup begun in January. Moved the apkeysdef.h + file into the aplib subdirectory with all the other .h files. + + 1. Davis, Mar 3, 1989 + +apphot$ + I changed all the .keys and .skeys file extensions to .key extensions. + This removes a problem with installations which do a strip operation. + + Davis, Feb 3, 1989 + +apphot$apyfit.x + I fixed a potential problem in polyphot. If a user specified a concave + polygon and the image line intersected the polygon exactly on a vertex + polyphot might not be able to tell whether a line segment was inside + or outside the polygon, causing a error in the total flux computation. + The affected routine was ap_yclip in apyfit.x + + 1. Davis, Jan 30, 1989 + +apphot$ + All the tasks doing interactive setup using a radial profile now + center the profile before plotting. This facilitates marking the full + width half maximum of the psf on the plot. + + Davis, Jan 23, 1989 + +apphot + 1. Davis, Jan 21, 1989 + Began cleanup of file and procedure names. All file names now begin with + ap. All procedure names begin with ap. Eventually I will clean up + the ap to ap_ convention. The subdirectories polyphot and polymark + have been completely overhauled. Note caution about updates is in order. + +apphot + 1. Davis, Nov 11, 1988 + Removed a call to imparse in apimroot.x and a call to iki_parse in + apoutname.x. The calls were changed to imgimage. + +apphot + 1. Davis, Nov 3, 1988 + Daofind was outputing an incorrect magnitude estimate due to an indexing + problem. The correct stellar position was being output. + +apphot + 1. Davis, Oct 27, 1988 + The :aperts coomand in qphot.keys, phot.keys and wphot.keys was changed + to the correct :apertures command. The corresponding help pages were + also modified. + +apphot + 1. Davis, Oct 4, 1988 + The statement z = z + p[4] was out of order in the routine cdgauss1d + in cgauss1d.x. The evaluation of the derivative with respect to sigma + was in error. This bug would not be noticed in the apphot code as + sigma was being held constant whenever this routine was called. + +apphot + 1. Davis, Sept 12, 1988 + The APPHOT package was installed in the apphot subdirectory of the + digiphot package. + +apphot + 1. Davis, Aug 15, 1988 + If the i key (interactive setup option) was used after the first object + record was written to the database file then the changed parameters + were not being updated in the database file. The : commands were + being updated correctly. This problem has been fixed in all the + interactive tasks. + +apphot + 1. Davis, Aug 18, 1988 + Apselect will now accept a list of text files as input. + +apphot + 1. Davis, Aug 16, 1988 + The apphot tasks now save the apertures string as well as the list + of apertures. The phot, qphot and wphot phot tasks will noe accept + a ranges syntax of the form ap1:apn:apstep. This syntax can be + mixed with the former syntax. In addition it is know possible to read + the apertures from a text file. + +apphot + 1. Davis, Aug 11, 1988 + Fixed a bug in the angle computation for the elliptical Gaussian fitting + routine in fitpsf. Positive angles from 0 to 90 were correct, the + rest were being forced to be positive. + + 2. It is now possible to change the image, coordinate file and output + file name from apphot interactive mode. + +apphot + 1. Changed the maximum number of apertures from 15 to 100. + 2. Changed apwparam to allocate astring of SZ_LINE long. + + Davis, Aug 4, 1988 + +apphot + 1. Fixed a bug in polyget.x. The program was hanging in batch mode when + one tried to read a polygons file created by the imtool cursor readback + facility. I removed an incorrectly placed next statement. + + Davis, Jul 29, 1988 + +apphot + 1. Added id strings to all the parameter files which request + algorithm names etc. + + Davis, Jun 1, 1988 + +apphot + 1. I fixed a potentially serious problem in the way daofind handles + out of bounds regions. Daofind was accessing an out of bounds array + which accasionally would fail with divide by zeros NaNs etc. + The positions of stars near the edge of the image could be affected. + + Davis, Apr29, 1988 + +apphot$ + 1. Added a new parameter threshold and changed old parameter threshold + to cthreshold. + + 2. Daofind now reads the datapars file. It can now work on both emission + and absorption features. + + 3. Cleaned up the output and integrated with rest of apphot. + + Davis, Apr22, 1988 + +apphot$ + 1. Removed redundant MISC string definitions. + + 2. Added the DATAMIN and DATAMAX parameters required by daophot. This + required changes to the apphot structure, the get and put pars routines + and the set and stat calls. + + Davis, Apr12, 1988 + +apphot$ + 1. Added correct error code handling for the case where cbox <= 0.0 + or dannulus = 0.0. The correct action but incorrect error code was + being returned. + + 2. Fixed the same bug in the code for fitpsf. + + Davis, Apr4, 1988 + +apphot$ + 1. Fixed a bug in decoding the apertures string. If a nonsensical + apertures string was given then the apertures could be decoded into + some strange number. + + Davis, Apr4, 1988 + +apphot$apselect.x + 1. I fixed a bug in the apselect task which occurred when the user + requested all the output fields with the * command and the output + records contained array valued fields. The select buffer + was being allocated space equal to the number of unique keys, not + space for the total number of elements causing memory overflow + problems. + + Davis, Apr1, 1988 + +apphot$ + 1. Added a needed gdeactivate command to i setup key menus when they + terminate prematurely. Otherwise the terminal is left in graphics + mode. + + 2. A bug in the batch mode of running apphot tasks occurred if a single + output file was specified and there were no stars in the first file. + The header could be written several times and cause and error in apselect. + + Davis, Mar31, 1988 + +apphot$fitpsf/ + 1. I changed the initial guess for the sigma to be the fwhmpsf instead + of a small fraction of the fitting box as before. This affects both the + radial Gaussian and the elliptical Gaussian. + + Davis, Mar15,1988 + +apphot$ + 1. Floating divide by 0 errors were occurring in daofind when the threshold + was set to zero. These were arising in two different places. The + magnitude estimate is based on a ratio with respect to threshold + and the sharpness computation can blow up when the peak pixel is zero. + + 2. I have added a warning message to aptime.x, appadu.x and aprdnoise.x + so that they will print an error message if the header parameter + keyword cannot be found in the image header. + + Davis, Mar8,1988 + +apphot$ + The graphics and image device opens have been moved outside of the + image loop in interactive mode. + + Davis, Feb23,1988 + +apphot$ + 1. All the next now print out a short help page at startup time if they + are run in interactive mode. + + 2. I changed the task termination sequence. q from inside the cursor + loop calls up a verification sequence, return goes back into the cursor + loop, n exits the cursor loop and asks for the next image, q quits the + task and w quits the task and writes to the pset parameter files. + + 3. I have added the bell character to the end of all warning messages. + More specific error messages were added to tell people that they are + at the end of a coordinate lists etc. + + Davis, Feb18,1988 + +apphot$ + I switched the exposure and itime parameters from the photpars and + polypars psets to the datapars pset where they more properly belong. + + Davis, Feb9, 1988 + +apphot$ + If salgorithm = constant then the algorithm which computes the magnitude + errors will try to use the value of the sigma parameter to estimate the + random noise inside the aperture. If sigma is INDEFR it will use only the + poisson statistics of the star. + + Davis, Feb 6, 1988 + +apphot$ + Moved the pfeature parameter from centerpars and placed it in datapars + where it logically belongs. + + Corrected a radprof error in which the extracted pixel array was being + call out of bounds even when it wasn't. + + Polyphot was centering on the cursor position even when no polygon + had been defined. + + Davis, Feb 5, 1988 + +apphot$radprof/,apphot$apselect/ + Fixed a minor bug in apselect. If string parameters were exactly equal + to their formatted lengths then a single extra character would get + printed at the end of each selected field. This happened for example + when the photometry parameter was out of bounds. + + In the radprof task the sky subtracted sums were being printed out + instead of the total sums. The mangnitudes were being computed + correctly. + + Davis, Feb 2, 1988 + +apphot$apselect/ + Made extensive changes to the keyword and units string maintenance + facilities, mostly to make the package easier to maintain. + + Changed the pfeature keyword to emission which makes more sense. + + Davis, Jan 25, 1988 + +apphot$t_apselect.x + Corrected a bug in the apselect program in which the package would + crash if the fields string was set to NULL. I included a check for + the null string in the t_apselect.x procedure. + + Davis, Jan 20, 1988 + +apphot$ + I made the task lintran part of the apphot package. This allows the + user to manipulate the coordinate lists. + + Davis, Jan 20, 1988 + +apphot$polyphot/pyprint + I corrected an error in the format string for the polyphot magnitude + error which was shifting the number over 2 columns. + + Davis, Jan 9, 1988 + +apphot$daofind/apfind.x + A bug in the way daofind computed the convolution kernel for very + small kernels was discovered and corrected. The kernel is supposed to + be defined for all pixels < 2.0 pixels from the center. For small + kernels these elements were being left at zero. IN most cases this + causes no problems except for the fact that the sharpness parameter + was lower than seen from daofind and that the nomalization for the + magnitudes is different. Workarounds are to increase nsigma from the + default of 1.5. + + Davis, Jan 6, 1988 + +apphot$polyphot/polyfit.x + The itime normalization was not working correctly in the polyphot + task. The time was being picked up correctly but the zero-point + correction was not being made to the magnitude. + + Davis, Dec 31, 1987 + +apphot$polyphot/pybphot.x + Davis, Dec 30, 1987 + I fixed a bug in the polyphot batch mode processing routine. An + "illegal file descriptor" error was occurring when polyphot was run + in batch mode with a null coordinate file list and a polygons list. + +apphot$ + I continued the clean up of apphot output files. Some of these + bugs could cause problems for potential users of apselect. + Changed the units string for CERROR, SERROR, PERROR and RERROR to + "cerrors", "serrors", "rerrors" and "perrors" from "cerror", + "serror", "perror" and "rerror" respectively to make things consistent + with the other tasks. + + I changed to polyphot units string for ZMAGNITUDE and EXPOSURE to + "zeropoint" and "keyword" respectively for consistency with the phot + bug. + + Fixed a bug in the polyphot output file where a # was missing in front + of the line beginning with XCENTER. + + Fixed a bug in the output of fitpsf with function = radgauss where + the SIGMA keyword was used for two different quantities and only the + first one was being output. + + I changed the order of the output table headers from for example + #N#N#N #U#U#U and #F#F#F to #N#U#F #N#U#F and #N#U#F. I rechecked + apselect on all this. + + Davis, Dec 22, 1987 + +apphot$ + I added a comment about the definition of box in the fitpsf parameter + file. + + Changed the output format of the center task slightly. The units for + HOST are now "computer". Similarly the units string for GAIN and + CCDREAD are now "keyword" and "keyword". These changes will affect + all tasks in the apphot package which use the datapars parameter set. + + Changed the units string for SALGORITHM to "algorithm". I also corrected + an error in the COORDS keyword by changing it from CCORDS to COORDS. + I added an s to the ERROR units string, changing it from error to + errors. + + I corrected a bug in the output file for the wphot task. The record + names, units and formats were not being written to the output file. + The problem was that the task name in the batch program had not + been changed from ophot to wphot. See also that the task statement + was incorrect. + + Davis, Dec 21, 1987 + +apphot$ + I changed the default mode for the binary version of the plotfile from + NEW_FILE to append. This avoids annoying cannot open plotfile + information when phot is run many times. The user must be aware + however that very long plot files can be generated. The affected + tasks are center, fitsky, phot, wphot, and radprof. + + Davis, Dec 21, 1987 + +apphot$apselect/apselect.x + I installed the new apselect in apphot. In the process I fixed the last + memory allocation bug which only showed up in the output of the radprof + program where the records were unusually long. + + Davis, Dec 21, 1987 + +apphot$radprof/apprprof.x + I fixed some minor bugs in the output format of radprof which were + causing apselect errors. First the records PRADIUS, INTENSITY, INTENSITY + should read PRADIUS, INTENSITY and TINTENSITY. The total intensity + record was never being read. I added a trailing slash at the end of the + magnitude record to indicate that the record continued on to include + the radial profile. If the radial profile was long > 20 records a + segmentation violation would occur as the program was not reallocating + extra memory correctly. + + Davis, Dec 21, 1987 + +apphot$radprof/aprpinit.x + Radprof was not reading multiple appertures from the photpars parameter + file correctly. The problem was that the napert and weight arguments + were reversed in the call to ap_photsetup making napert always equal + to 1. + + Davis, Dec 15, 1987 + +apphot$apselect/ + Array subscripts in the apselect task were not being handled correctly + on the sun machines. The problem was in the call to the stridx routine. + A character constant was being placed in the first argument which is + interpreted as an integer. This wa ok on Vax machines with their reverse + byte order but did not work on the Suns. I set up some character + constants and taht removed the problem. + + Arrays and array elements were not always being handled correctly by the + expression parser. In fact arrays are curently illegal in expression. + The program will now abort with a more informative error message if + it detects an array in an expression. Array elements are permitted + however. + + I added some missing mfree statements which were causing random + segmentation violation errors from time to time. + + Finally I made some changes for the sake of efficiency. For example + I call the routine apchoose only once instead of once for each record + in the output file. + + Davis, Dec 15, 1987 + +apphot$apphot.hd + Changed the name of the wphot help page from ophot.hlp to wphot.hlp + and the same of the source code file from t_ophot.x to t_wphot.x. + Ophot was the historical name of this package. + + Corrected an error in the installation guide instructions on installing + the help database. The help apphot command was not functioning + correctly. The problem was a missing apphot defintion infront of the + .men, .sys etc commands. + + Davis, Dec 15, 1987 + +apphot$apimroot.x + Fixed a bug in the output file name generating code. If output = default + and the image name specification included an image section then apphot + tasks would try to create an output file name of the form .extension. + version. The left square brackett made the image name appear like a + directory to fio. I included code to strip the image section off the + image name before constructing the output file name. The image + section information is however preserved in the output file. + + Davis, Dec 10, 1987 + +--------------------------------------------------------------------------- + + October 27, 1987 Alpha Test Version Released + +-------------------------------------------------------------------------- +.endhelp diff --git a/noao/digiphot/apphot/aplib/apairmass.x b/noao/digiphot/apphot/aplib/apairmass.x new file mode 100644 index 00000000..3dcb9cdf --- /dev/null +++ b/noao/digiphot/apphot/aplib/apairmass.x @@ -0,0 +1,36 @@ +include <imhdr.h> +include "../lib/apphot.h" + +# AP_AIRMASS - Procedure to determine the image airmass. + +procedure ap_airmass (im, ap) + +pointer im # pointer to IRAF image +pointer ap # pointer to apphot structure + +pointer sp, key +real xair +real imgetr(), apstatr() + +begin + call smark (sp) + call salloc (key, SZ_FNAME, TY_CHAR) + call apstats (ap, AIRMASS, Memc[key], SZ_FNAME) + if (Memc[key] == EOS) + xair = apstatr (ap, XAIRMASS) + else { + iferr { + xair = imgetr (im, Memc[key]) + } then { + xair = apstatr (ap, XAIRMASS) + call eprintf ("Warning: Image %s Keyword: %s not found\n") + call pargstr (IM_HDRFILE(im)) + call pargstr (Memc[key]) + } + } + if (IS_INDEFR(xair) || xair <= 0.0) + call apsetr (ap, XAIRMASS, INDEFR) + else + call apsetr (ap, XAIRMASS, xair) + call sfree (sp) +end diff --git a/noao/digiphot/apphot/aplib/apapcolon.x b/noao/digiphot/apphot/aplib/apapcolon.x new file mode 100644 index 00000000..1a906345 --- /dev/null +++ b/noao/digiphot/apphot/aplib/apapcolon.x @@ -0,0 +1,353 @@ +include <error.h> +include "../lib/apphot.h" + +# AP_APCOLON -- Process colon commands for setting the top level apphot package +# parameters. + +procedure ap_apcolon (ap, im, cl, out, stid, ltid, cmdstr, newimage, + newcenterbuf, newcenter, newskybuf, newsky, newbuf, newfit) + +pointer ap # pointer to the apphot structure +pointer im # pointer to the iraf image +int cl # coordinate file descriptor +int out # output file descriptor +int stid # output file sequence number +int ltid # coordinate file sequence number +char cmdstr[ARB] # command string +int newimage # new image ? +int newcenterbuf, newcenter # new centering parameters ? +int newskybuf, newsky # new sky fitting parameters ? +int newbuf, newfit # new photometry parameters ? + +bool bval +int ncmd, ip +pointer sp, cmd, str +real rval + +bool streq(), itob() +int strdic(), nscan(), btoi(), apstati(), ctowrd(), open() +pointer immap() +real apstatr() +errchk immmap, open + +begin + # Allocate working space. + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + call salloc (str, SZ_LINE, TY_CHAR) + + # Get the command. + ip = 1 + call sscan (cmdstr) + call gargwrd (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call sfree (sp) + return + } + + # Process the command. + ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, APCMDS) + switch (ncmd) { + + case APCMD_FWHMPSF: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_FWHMPSF) + call pargr (apstatr (ap, FWHMPSF)) + call pargstr (UN_ASCALEUNIT) + } else { + call apsetr (ap, FWHMPSF, rval) + if (stid > 1) + call ap_rparam (out, KY_FWHMPSF, rval, UN_ASCALEUNIT, + "full width half max of psf") + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newbuf = YES; newfit = YES + } + + case APCMD_SCALE: + call gargr (rval) + if (nscan () == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_SCALE) + call pargr (1.0 / apstatr (ap, SCALE)) + call pargstr (UN_AUNITS) + } else if (rval > 0.0) { + call apsetr (ap, SCALE, (1.0 / rval)) + if (stid > 1) + call ap_rparam (out, KY_SCALE, (1.0 / rval), UN_AUNITS, + "scale in units / pixel") + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newbuf = YES; newfit = YES + } + + case APCMD_EMISSION: + call gargb (bval) + if (nscan() == 1) { + call printf ("%s = %b\n") + call pargstr (KY_POSITIVE) + call pargb (itob (apstati (ap, POSITIVE))) + } else { + call apseti (ap, POSITIVE, btoi (bval)) + if (stid > 1) + call ap_bparam (out, KY_POSITIVE, bval, UN_ASWITCH, + "emission feature") + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newbuf = YES; newfit = YES + } + + case APCMD_FILTER: + call gargstr (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call apstats (ap, FILTER, Memc[str], SZ_LINE) + call printf ("%s = %s\n") + call pargstr (KY_FILTER) + call pargstr (Memc[str]) + } else { + if (ctowrd (Memc[cmd], ip, Memc[str], SZ_LINE) <= 0) + Memc[str] = EOS + call apsets (ap, FILTER, Memc[str]) + if (im != NULL) + call ap_filter (im, ap) + if (stid > 1) + call ap_sparam (out, KY_FILTER, Memc[str], UN_AKEYWORD, + "filter keyword") + } + + case APCMD_FILTERID: + call gargstr (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call apstats (ap, FILTERID, Memc[str], SZ_LINE) + call printf ("%s = %s\n") + call pargstr (KY_FILTERID) + call pargstr (Memc[str]) + } else { + if (ctowrd (Memc[cmd], ip, Memc[str], SZ_LINE) <= 0) + Memc[str] = EOS + call apsets (ap, FILTERID, Memc[str]) + } + + case APCMD_OBSTIME: + call gargstr (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call apstats (ap, OBSTIME, Memc[str], SZ_LINE) + call printf ("%s = %s\n") + call pargstr (KY_OBSTIME) + call pargstr (Memc[str]) + } else { + if (ctowrd (Memc[cmd], ip, Memc[str], SZ_LINE) <= 0) + Memc[str] = EOS + call apsets (ap, OBSTIME, Memc[str]) + if (im != NULL) + call ap_otime (im, ap) + if (stid > 1) + call ap_sparam (out, KY_OBSTIME, Memc[str], UN_AKEYWORD, + "obstime keyword") + } + + case APCMD_OTIME: + call gargstr (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call apstats (ap, OTIME, Memc[str], SZ_LINE) + call printf ("%s = %s %s\n") + call pargstr (KY_OTIME) + call pargstr (Memc[str]) + call pargstr (UN_ATIMEUNIT) + } else { + if (ctowrd (Memc[cmd], ip, Memc[str], SZ_LINE) <= 0) + Memc[str] = EOS + call apsets (ap, OTIME, Memc[str]) + } + + case APCMD_AIRMASS: + call gargstr (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call apstats (ap, AIRMASS, Memc[str], SZ_LINE) + call printf ("%s = %s\n") + call pargstr (KY_AIRMASS) + call pargstr (Memc[str]) + } else { + if (ctowrd (Memc[cmd], ip, Memc[str], SZ_LINE) <= 0) + Memc[str] = EOS + call apsets (ap, AIRMASS, Memc[str]) + if (im != NULL) + call ap_airmass (im, ap) + if (stid > 1) + call ap_sparam (out, KY_AIRMASS, Memc[str], UN_AKEYWORD, + "airmass keyword") + } + + case APCMD_XAIRMASS: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_XAIRMASS) + call pargr (apstatr (ap, XAIRMASS)) + call pargstr (UN_ANUMBER) + } else { + call apsetr (ap, XAIRMASS, rval) + #if (stid > 1) + #call ap_rparam (out, KY_XAIRMASS, rval, UN_ANUMBER, + #"airmass") + } + + case APCMD_EXPOSURE: + call gargstr (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call apstats (ap, EXPOSURE, Memc[str], SZ_LINE) + call printf ("%s = %s\n") + call pargstr (KY_EXPOSURE) + call pargstr (Memc[str]) + } else { + if (ctowrd (Memc[cmd], ip, Memc[str], SZ_LINE) <= 0) + Memc[str] = EOS + call apsets (ap, EXPOSURE, Memc[str]) + if (im != NULL) + call ap_itime (im, ap) + if (stid > 1) + call ap_sparam (out, KY_EXPOSURE, Memc[str], UN_AKEYWORD, + "exposure time keyword") + newfit = YES + } + + case APCMD_ITIME: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_ITIME) + call pargr (apstatr (ap, ITIME)) + call pargstr (UN_ATIMEUNIT) + } else { + call apsetr (ap, ITIME, rval) + #if (stid > 1) + #call ap_rparam (out, KY_ITIME, rval, UN_ATIMEUNIT, + #"exposure time") + newfit = YES + } + + case APCMD_DATAMIN: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_DATAMIN) + call pargr (apstatr (ap, DATAMIN)) + call pargstr (UN_ACOUNTS) + } else { + call apsetr (ap, DATAMIN, rval) + if (stid > 1) + call ap_rparam (out, KY_DATAMIN, rval, UN_ACOUNTS, + "minimim good data value") + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newbuf = YES; newfit = YES + } + + case APCMD_DATAMAX: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_DATAMAX) + call pargr (apstatr (ap, DATAMAX)) + call pargstr (UN_ACOUNTS) + } else { + call apsetr (ap, DATAMAX, rval) + if (stid > 1) + call ap_rparam (out, KY_DATAMAX, rval, UN_ACOUNTS, + "maximum good data value") + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newbuf = YES; newfit = YES + } + + case APCMD_IMAGE: + call gargwrd (Memc[cmd], SZ_LINE) + call apstats (ap, IMNAME, Memc[str], SZ_FNAME) + if (Memc[cmd] == EOS || streq (memc[cmd], Memc[str])) { + call printf ("%s: %s\n") + call pargstr (KY_IMNAME) + call pargstr (Memc[str]) + } else { + if (im != NULL) { + call imunmap (im) + im = NULL + } + iferr { + im = immap (Memc[cmd], READ_ONLY, 0) + } then { + call erract (EA_WARN) + im = immap (Memc[str], READ_ONLY, 0) + } else { + call apimkeys (ap, im, Memc[cmd]) + newimage = YES + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newbuf = YES; newfit = YES + } + } + + case APCMD_COORDS: + call gargwrd (Memc[cmd], SZ_LINE) + call apstats (ap, CLNAME, Memc[str], SZ_FNAME) + if (Memc[cmd] == EOS || streq (Memc[cmd], Memc[str])) { + call printf ("%s: %s\n") + call pargstr (KY_CLNAME) + call pargstr (Memc[str]) + } else { + if (cl != NULL) { + call close( cl) + cl = NULL + } + iferr { + cl = open (Memc[cmd], READ_ONLY, TEXT_FILE) + } then { + cl = NULL + call erract (EA_WARN) + call apsets (ap, CLNAME, "") + call apsets (ap, CLROOT, "") + call printf ("Coordinate file is undefined.\n") + } else { + call apsets (ap, CLNAME, Memc[cmd]) + call apfroot (Memc[cmd], Memc[str], SZ_FNAME) + call apsets (ap, CLROOT, Memc[str]) + ltid = 0 + } + } + + case APCMD_OUTPUT: + call gargwrd (Memc[cmd], SZ_LINE) + call apstats (ap, OUTNAME, Memc[str], SZ_FNAME) + if (Memc[cmd] == EOS || streq (Memc[cmd], Memc[str])) { + call printf ("%s: %s\n") + call pargstr (KY_OUTNAME) + call pargstr (Memc[str]) + } else { + if (out != NULL) { + call close (out) + out = NULL + if (stid <= 1) + call delete (Memc[str]) + } + iferr { + out = open (Memc[cmd], NEW_FILE, TEXT_FILE) + } then { + call erract (EA_WARN) + call printf ("Reopening output file: %s\n") + call pargstr (Memc[str]) + if (Memc[str] != EOS) + out = open (Memc[str], APPEND, TEXT_FILE) + else + out = NULL + } else { + call apsets (ap, OUTNAME, Memc[cmd]) + stid = 1 + } + } + default: + call printf ("Unknown or ambiguous colon command\7\n") + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/aplib/aparrays.x b/noao/digiphot/apphot/aplib/aparrays.x new file mode 100644 index 00000000..563608fd --- /dev/null +++ b/noao/digiphot/apphot/aplib/aparrays.x @@ -0,0 +1,52 @@ +include "../lib/apphotdef.h" +include "../lib/photdef.h" +include "../lib/phot.h" + +# AP_ARRAYR -- Procedure to move apphot parameters stored as real arrays +# into a user allocated array. + +procedure ap_arrayr (ap, param, array) + +pointer ap # pointer to apphot structure +int param # parameter +real array[ARB] # array + +pointer phot + +begin + phot = AP_PPHOT(ap) + switch (param) { + case APERTS: + call amovr (Memr[AP_APERTS(phot)], array, AP_NAPERTS(phot)) + case MAGS: + call amovr (Memr[AP_MAGS(phot)], array, AP_NAPERTS(phot)) + case MAGERRS: + call amovr (Memr[AP_MAGERRS(phot)], array, AP_NAPERTS(phot)) + default: + call error (0, "AP_ARRAYR: Unknown apphot real array") + } +end + + +# AP_ARRAYD -- Procedure to move apphot parameters stored as double arrays +# into a user allocated array. + +procedure ap_arrayd (ap, param, array) + +pointer ap # pointer to apphot structure +int param # parameter +double array[ARB] # array + +pointer phot + +begin + phot = AP_PPHOT(ap) + switch (param) { + case AREAS: + call amovd (Memd[AP_AREA(phot)], array, AP_NAPERTS(phot)) + case SUMS: + call amovd (Memd[AP_SUMS(phot)], array, AP_NAPERTS(phot)) + default: + call error (0, "AP_ARRAYD: Unknown apphot double array") + } +end diff --git a/noao/digiphot/apphot/aplib/apfilter.x b/noao/digiphot/apphot/aplib/apfilter.x new file mode 100644 index 00000000..b9bfcc9d --- /dev/null +++ b/noao/digiphot/apphot/aplib/apfilter.x @@ -0,0 +1,41 @@ +include <imhdr.h> +include "../lib/apphot.h" + +# AP_FILTER -- Procedure to set the image airmass. + +procedure ap_filter (im, ap) + +pointer im # pointer to IRAF image +pointer ap # pointer to apphot structure + +pointer sp, key, filt + +begin + call smark (sp) + call salloc (key, SZ_FNAME, TY_CHAR) + call salloc (filt, SZ_FNAME, TY_CHAR) + + call apstats (ap, FILTER, Memc[key], SZ_FNAME) + Memc[filt] = EOS + if (Memc[key] == EOS) + call apstats (ap, FILTERID, Memc[filt], SZ_FNAME) + else { + iferr { + call imgstr (im, Memc[key], Memc[filt], SZ_FNAME) + } then { + call apstats (ap, FILTERID, Memc[filt], SZ_FNAME) + call eprintf ("Warning: Image %s Keyword: %s not found\n") + call pargstr (IM_HDRFILE(im)) + call pargstr (Memc[key]) + } + } + + if (Memc[filt] == EOS) { + call apsets (ap, FILTERID, "INDEF") + } else { + call ap_rmwhite (Memc[filt], Memc[filt], SZ_FNAME) + call apsets (ap, FILTERID, Memc[filt]) + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/aplib/apfree.x b/noao/digiphot/apphot/aplib/apfree.x new file mode 100644 index 00000000..30c6c396 --- /dev/null +++ b/noao/digiphot/apphot/aplib/apfree.x @@ -0,0 +1,25 @@ +include "../lib/apphotdef.h" + +# AP_NOISECLS -- Procedure to close up the noise structure and arrays. + +procedure ap_noisecls (ap) + +pointer ap # pointer to apphot structure + +begin + if (AP_NOISE(ap) == NULL) + return + call mfree (AP_NOISE(ap), TY_STRUCT) +end + + +# AP_DISPCLS -- Procedure to close up the dislay structure and arrays. + +procedure ap_dispcls (ap) + +pointer ap # pointer to the apphot structure + +begin + if (AP_PDISPLAY(ap) != NULL) + call mfree (AP_PDISPLAY(ap), TY_STRUCT) +end diff --git a/noao/digiphot/apphot/aplib/apgaperts.x b/noao/digiphot/apphot/aplib/apgaperts.x new file mode 100644 index 00000000..05558cc1 --- /dev/null +++ b/noao/digiphot/apphot/aplib/apgaperts.x @@ -0,0 +1,214 @@ +include <lexnum.h> +include <ctype.h> + +# AP_GETAPERTS -- Procedure to extract real aperture values from a string + +int procedure ap_getaperts (str, aperts, max_naperts) + +char str[ARB] # string +real aperts[ARB] # number of apertures +int max_naperts # maximum number of apertures + +int fd, naperts +int open(), ap_rdaperts(), ap_decaperts() +errchk open(), close() + +begin + naperts = 0 + + iferr { + fd = open (str, READ_ONLY, TEXT_FILE) + naperts = ap_rdaperts (fd, aperts, max_naperts) + call close (fd) + } then { + naperts = ap_decaperts (str, aperts, max_naperts) + } + + return (naperts) +end + + +# AP_RDAPERTS -- Procedure to read out the apertures listed one per line +# from a file. + +int procedure ap_rdaperts (fd, aperts, max_naperts) + +int fd # aperture list file descriptor +real aperts[ARB] # list of apertures +int max_naperts # maximum number of apertures + +int naperts +pointer sp, line +int getline(), ap_decaperts() + +begin + call smark (sp) + call salloc (line, SZ_LINE, TY_CHAR) + + naperts = 0 + while (getline (fd, Memc[line]) != EOF && naperts < max_naperts) { + naperts = naperts + ap_decaperts (Memc[line], aperts[1+naperts], + max_naperts - naperts) + } + + call sfree (sp) + + return (naperts) +end + + +# AP_DECAPERTS -- Procedure to decode the aperture string. + +int procedure ap_decaperts (str, aperts, max_naperts) + +char str[ARB] # aperture string +real aperts[ARB] # aperture array +int max_naperts # maximum number of apertures + +char outstr[SZ_LINE] +int naperts, ip, op, ndecode, nap +real apstart, apend, apstep +bool fp_equalr() +int gctor() + +begin + naperts = 0 + + for (ip = 1; str[ip] != EOS && naperts < max_naperts;) { + + apstart = 0.0 + apend = 0.0 + apstep = 0.0 + ndecode = 0 + + # Skip past white space and commas. + while (IS_WHITE(str[ip])) + ip = ip + 1 + if (str[ip] == ',') + ip = ip + 1 + + # Get the number. + op = 1 + while (IS_DIGIT(str[ip]) || str[ip] == '.') { + outstr[op] = str[ip] + ip = ip + 1 + op = op + 1 + } + outstr[op] = EOS + + # Decode the starting aperture. + op = 1 + if (gctor (outstr, op, apstart) > 0) { + apend = apstart + ndecode = 1 + } else + apstart = 0.0 + + # Skip past white space and commas. + while (IS_WHITE(str[ip])) + ip = ip + 1 + if (str[ip] == ',') + ip = ip + 1 + + # Get the ending aperture + if (str[ip] == ':') { + ip = ip + 1 + + # Get the ending aperture. + op = 1 + while (IS_DIGIT(str[ip]) || str[ip] == '.') { + outstr[op] = str[ip] + ip = ip + 1 + op = op + 1 + } + outstr[op] = EOS + + # Decode the ending aperture. + op = 1 + if (gctor (outstr, op, apend) > 0) { + ndecode = 2 + apstep = apend - apstart + } + } + + # Skip past white space and commas. + while (IS_WHITE(str[ip])) + ip = ip + 1 + if (str[ip] == ',') + ip = ip + 1 + + # Get the step size. + if (str[ip] == ':') { + ip = ip + 1 + + # Get the step size. + op = 1 + while (IS_DIGIT(str[ip]) || str[ip] == '.') { + outstr[op] = str[ip] + ip = ip + 1 + op = op + 1 + } + outstr[op] = EOS + + # Decode the step size. + op = 1 + if (gctor (outstr, op, apstep) > 0) { + if (fp_equalr (apstep, 0.0)) + apstep = apend - apstart + else + ndecode = (apend - apstart) / apstep + 1 + if (ndecode < 0) { + ndecode = -ndecode + apstep = - apstep + } + } + } + + # Negative apertures are not permitted. + if (apstart <= 0.0 || apend <= 0.0) + break + + # Fill in the apertures. + if (ndecode == 0) { + ; + } else if (ndecode == 1) { + naperts = naperts + 1 + aperts[naperts] = apstart + } else if (ndecode == 2) { + naperts = naperts + 1 + aperts[naperts] = apstart + if (naperts >= max_naperts) + break + naperts = naperts + 1 + aperts[naperts] = apend + } else { + for (nap = 1; nap <= ndecode && naperts < max_naperts; + nap = nap + 1) { + naperts = naperts + 1 + aperts[naperts] = apstart + (nap - 1) * apstep + } + } + } + + return (naperts) +end + + +# GCTOR -- Procedure to convert a character variable to a real number. +# This routine is just an interface routine to the IRAF procedure gctod. + +int procedure gctor (str, ip, rval) + +char str[ARB] # string to be converted +int ip # pointer to the string +real rval # real value + +double dval +int nchars +int gctod() + +begin + nchars = gctod (str, ip, dval) + rval = dval + return (nchars) +end diff --git a/noao/digiphot/apphot/aplib/apgqverify.x b/noao/digiphot/apphot/aplib/apgqverify.x new file mode 100644 index 00000000..b7114e37 --- /dev/null +++ b/noao/digiphot/apphot/aplib/apgqverify.x @@ -0,0 +1,68 @@ +include <ttyset.h> +include <fset.h> + +define QUERY "[Hit return to continue, n next image, q quit, w quit and save parameters]" + +# APGQVERIFY -- Print a message in the status line asking the user if they +# really want to quit, returning YES if they really want to quit, NO otherwise. + +int procedure apgqverify (task, ap, ch) + +char task[ARB] # name of the apphot task +pointer ap # pointer to apphot structure +int ch # character keystroke command + +pointer tty +int getci(), strmatch() +pointer ttyodes() + +begin + tty = ttyodes ("terminal") + call ttyclearln (STDOUT, tty) + call ttyso (STDOUT, tty, YES) + + call printf (QUERY) + call flush (STDOUT) + call fseti (STDIN, F_RAW, YES) + if (getci (STDIN, ch) == EOF) + ; + call fseti (STDIN, F_RAW, NO) + call ttyso (STDOUT, tty, NO) + call ttyclearln (STDOUT, tty) + call printf ("\n") + call flush (STDOUT) + + call ttycdes (tty) + + if (ch == 'q') { + return (YES) + } else if (ch == 'w') { + if (strmatch ("^center", task) > 0) { + call ap_pcpars (ap) + } else if (strmatch ("^fitsky", task) > 0) { + call ap_pspars (ap) + } else if (strmatch ("^phot", task) > 0) { + call ap_ppars (ap) + } else if (strmatch ("^wphot", task) > 0) { + call ap_wpars (ap) + } else if (strmatch ("^qphot", task) > 0) { + call ap_qppars (ap) + } else if (strmatch ("^polyphot", task) > 0) { + call ap_pypars (ap) + } else if (strmatch ("^radprof", task) > 0) { + call ap_rpars (ap) + } else if (strmatch ("^fitpsf", task) > 0) { + call ap_ppfpars (ap) + } else if (strmatch ("^daofind", task) > 0) { + call ap_fdpars (ap) + } else if (strmatch ("^polymark", task) > 0) { + ; + } + return (YES) + } else if (ch == 'n') { + return (YES) + } else { + return (NO) + } + +end diff --git a/noao/digiphot/apphot/aplib/apgsvw.x b/noao/digiphot/apphot/aplib/apgsvw.x new file mode 100644 index 00000000..00f35e90 --- /dev/null +++ b/noao/digiphot/apphot/aplib/apgsvw.x @@ -0,0 +1,162 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <imio.h> +include <imhdr.h> +include <math.h> + +# AP_GSWV -- Set the data window and viewport for the image display. + +procedure ap_gswv (id, image, im, max_nframes) + +pointer id # pointer to the image display graphics stream +char image # the input image name +pointer im # pointer to the input image +int max_nframes # the maximum number of display frames + +real vx1, vx2, vy1, vy2 + +begin + if (id == NULL) + return + call ap_gsview (image, im, max_nframes, vx1, vx2, vy1, vy2) + call gsview (id, vx1, vx2, vy1, vy2) + call gswind (id, 1.0, real (IM_LEN(im,1)), 1.0, real (IM_LEN(im,2))) +end + + +# AP_GSVIEW -- Map the viewport and window of the image display. + +procedure ap_gsview (image, im, max_nframes, vx1, vx2, vy1, vy2) + +char image # the input image name +pointer im # pointer to the input image +int max_nframes # the maximum number of display frames +real vx1, vx2, vy1, vy2 # the output viewport + +int i, frame, wcs_status, dim1, dim2, step1, step2 +pointer sp, rimname, frimage, frimname, frim, iw +real x1, x2, y1, y2, fx1, fx2, fy1, fy2, junkx, junky +bool streq() +pointer imd_mapframe(), iw_open() + +begin + # Allocate some memory. + call smark (sp) + call salloc (rimname, SZ_FNAME, TY_CHAR) + call salloc (frimage, SZ_FNAME, TY_CHAR) + call salloc (frimname, SZ_FNAME, TY_CHAR) + + # Get the root image name. + call imgimage (image, Memc[rimname], SZ_FNAME) + + # Loop through the defined image frames searching for the one + # which has the image loaded. + + frame = 0 + do i = 1, max_nframes { + frim = imd_mapframe (i, READ_ONLY, NO) + iw = iw_open (frim, i, Memc[frimage], SZ_FNAME, wcs_status) + call imgimage (Memc[frimage], Memc[frimname], SZ_FNAME) + if (streq (Memc[rimname], Memc[frimname])) { + frame = i + break + } else { + call iw_close (iw) + call imunmap (frim) + } + } + + # Default to current frame if the image has not been displayes? + if (frame == 0) { + call eprintf ("Warning: image %s is not loaded in the display\n") + call pargstr (Memc[rimname]) + vx1 = 0.0 + vx2 = 1.0 + vy1 = 0.0 + vy2 = 1.0 + call sfree (sp) + return + } + + # Find the beginning and end points of the requested image section. + # We already know at this point that the input logical image is + # 2-dimensional. However this 2-dimensional section may be part of + # n-dimensional image. + + # X dimension. + dim1 = IM_VMAP(im,1) + step1 = IM_VSTEP(im,dim1) + if (step1 >= 0) { + x1 = IM_VOFF(im,dim1) + 1 + x2 = x1 + IM_LEN(im,1) - 1 + } else { + x1 = IM_VOFF(im,dim1) - 1 + x2 = x1 - IM_LEN(im,1) + 1 + } + + # Y dimension. + dim2 = IM_VMAP(im,2) + step2 = IM_VSTEP(im,dim2) + if (step2 >= 0) { + y1 = IM_VOFF(im,dim2) + 1 + y2 = y1 + IM_LEN(im,2) - 1 + } else { + y1 = IM_VOFF(im,dim2) - 1 + y2 = y1 - IM_LEN(im,2) + 1 + } + + # Get the frame buffer coordinates corresponding to the lower left + # and upper right corners of the image section. + + call iw_im2fb (iw, x1, y1, fx1, fy1) + call iw_im2fb (iw, x2, y2, fx2, fy2) + if (fx1 > fx2) { + junkx = fx1 + fx1 = fx2 + fx2 = junkx + } + if (fy1 > fy2) { + junky = fy1 + fy1 = fy2 + fy2 = junky + } + + # Check that some portion of the input image is in the display. + # If not select the default viewport and window coordinates. + if (fx1 > IM_LEN(frim,1) || fx2 < 1.0 || fy1 > IM_LEN(frim,2) || + fy2 < 1.0) { + vx1 = 0.0 + vx2 = 1.0 + vy1 = 0.0 + vy2 = 1.0 + call iw_close (iw) + call imunmap (frim) + call sfree (sp) + return + } + + # Compute a new viewport and window for X. + if (fx1 >= 1.0) + vx1 = max (0.0, min (1.0, (fx1 - 0.5) / IM_LEN(frim,1))) + else + vx1 = 0.0 + if (fx2 <= IM_LEN(frim,1)) + vx2 = max (0.0, min (1.0, (fx2 + 0.5) / IM_LEN(frim,1))) + else + vx2 = 1.0 + + # Compute a new viewport and window for Y. + if (fy1 >= 1.0) + vy1 = max (0.0, min (1.0, (fy1 - 0.5) / IM_LEN(frim,2))) + else + vy1 = 0.0 + if (fy2 <= IM_LEN(frim,2)) + vy2 = max (0.0, min (1.0, (fy2 + 0.5) / IM_LEN(frim,2))) + else + vy2 = 1.0 + + # Clean up. + call iw_close (iw) + call imunmap (frim) + call sfree (sp) +end diff --git a/noao/digiphot/apphot/aplib/apgtverify.x b/noao/digiphot/apphot/aplib/apgtverify.x new file mode 100644 index 00000000..a2d8bed8 --- /dev/null +++ b/noao/digiphot/apphot/aplib/apgtverify.x @@ -0,0 +1,19 @@ +# APGTVERIFY -- Print a message in the status line asking the user if they +# really want to quit, returning YES if they really want to quit, NO otherwise. + +int procedure apgtverify (ch) + +int ch # character keystroke command + +begin + if (ch == 'q') { + return (YES) + } else if (ch == 'w') { + return (YES) + } else if (ch == 'n') { + return (NO) + } else { + return (NO) + } + +end diff --git a/noao/digiphot/apphot/aplib/apimbuf.x b/noao/digiphot/apphot/aplib/apimbuf.x new file mode 100644 index 00000000..d600a15d --- /dev/null +++ b/noao/digiphot/apphot/aplib/apimbuf.x @@ -0,0 +1,17 @@ +include "../lib/apphotdef.h" + +# AP_IMBUF -- Set the parameters for the image buffer. + +procedure ap_imbuf (ap, hwidth, sequential) + +pointer ap # pointer to the apphot structure +int hwidth # halfwidth of the line buffer +int sequential # optimize for sequntial i/o + +begin + AP_SEQUENTIAL(ap) = sequential + AP_HWIDTH(ap) = hwidth + if (AP_IMBUF(ap) != NULL) + call mfree (AP_IMBUF(ap), TY_REAL) + AP_IMBUF(ap) = NULL +end diff --git a/noao/digiphot/apphot/aplib/apimkeys.x b/noao/digiphot/apphot/aplib/apimkeys.x new file mode 100644 index 00000000..74105404 --- /dev/null +++ b/noao/digiphot/apphot/aplib/apimkeys.x @@ -0,0 +1,72 @@ +include "../lib/apphot.h" + +# APIMKEYS - Set the image name and keyword parameters after an image +# is mapped. + +procedure apimkeys (ap, im, imname) + +pointer ap # pointer to the apphot structure +pointer im # the image descriptor +char imname[ARB] # the input image name + +pointer sp, imroot, mw, ct +int apstati() +pointer mw_openim(), mw_sctran() +errchk mw_openim(), mw_sctran() + +begin + call smark (sp) + call salloc (imroot, SZ_FNAME, TY_CHAR) + + # Set the image and root names. + call apsets (ap, IMNAME, imname) + call apimroot (imname, Memc[imroot], SZ_FNAME) + call apsets (ap, IMROOT, Memc[imroot]) + + # Set the wcs descriptors. + mw = apstati (ap, MW) + if (mw != NULL) + call mw_close (mw) + iferr { + mw = mw_openim (im) + } then { + call apseti (ap, MW, NULL) + call apseti (ap, CTIN, NULL) + call apseti (ap, CTOUT, NULL) + } else { + call apseti (ap, MW, mw) + switch (apstati (ap, WCSIN)) { + case WCS_WORLD: + iferr (ct = mw_sctran (mw, "world", "logical", 03B)) + ct = NULL + case WCS_PHYSICAL: + iferr (ct = mw_sctran (mw, "physical", "logical", 03B)) + ct = NULL + case WCS_TV, WCS_LOGICAL: + ct = NULL + default: + ct = NULL + } + call apseti (ap, CTIN, ct) + switch (apstati (ap, WCSOUT)) { + case WCS_PHYSICAL: + iferr (ct = mw_sctran (mw, "logical", "physical", 03B)) + ct = NULL + case WCS_TV, WCS_LOGICAL: + ct = NULL + default: + ct = NULL + } + call apseti (ap, CTOUT, ct) + } + + # Set the keywords. + call ap_rdnoise (im, ap) + call ap_padu (im, ap) + call ap_itime (im, ap) + call ap_airmass (im, ap) + call ap_filter (im, ap) + call ap_otime (im, ap) + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/aplib/apinit.x b/noao/digiphot/apphot/aplib/apinit.x new file mode 100644 index 00000000..19e87eee --- /dev/null +++ b/noao/digiphot/apphot/aplib/apinit.x @@ -0,0 +1,106 @@ +include "../lib/apphotdef.h" +include "../lib/apphot.h" +include "../lib/noisedef.h" +include "../lib/noise.h" +include "../lib/displaydef.h" + +# AP_DEFSETUP -- Initialize the global apphot package parameters to their +# default values. + +procedure ap_defsetup (ap, fwhmpsf) + +pointer ap # pointer to the apphot package +real fwhmpsf # the FWHM of the stellar images + +begin + # Initalize the file names. + AP_IMNAME(ap) = EOS + AP_IMROOT(ap) = EOS + AP_CLNAME(ap) = EOS + AP_CLROOT(ap) = EOS + AP_OUTNAME(ap) = EOS + AP_PLOTFILE(ap) = EOS + AP_OUTNAME(ap) = EOS + + AP_WCSIN(ap) = WCS_LOGICAL + AP_WCSOUT(ap) = WCS_LOGICAL + AP_MW(ap) = NULL + AP_CTIN(ap) = NULL + AP_CTOUT(ap) = NULL + + # Initialize the cursor positions. + AP_CWX(ap) = INDEFR + AP_CWY(ap) = INDEFR + AP_WX(ap) = INDEFR + AP_WY(ap) = INDEFR + + # Set up the data characteristics. + AP_SCALE(ap) = DEF_SCALE + AP_FWHMPSF(ap) = fwhmpsf + AP_POSITIVE(ap) = DEF_POSITIVE + AP_DATAMIN(ap) = DEF_DATAMIN + AP_DATAMAX(ap) = DEF_DATAMAX + + # Set up the image header keywords. + AP_EXPOSURE(ap) = EOS + AP_ITIME(ap) = DEF_ITIME + AP_FILTER(ap) = EOS + call strcpy (DEF_FILTERID, AP_FILTERID(ap), SZ_FNAME) + AP_AIRMASS(ap) = EOS + AP_XAIRMASS(ap) = DEF_XAIRMASS + AP_OBSTIME(ap) = EOS + call strcpy (DEF_OTIME, AP_OTIME(ap), SZ_FNAME) + + # Set buffer parameters. + AP_SEQUENTIAL(ap) = NULL + AP_IMBUF(ap) = NULL + AP_HWIDTH(ap) = 0 +end + + +# AP_NOISESETUP -- Procedure to intialize noise model parameters. + +procedure ap_noisesetup (ap, noise) + +pointer ap # pointer to apphot structure +int noise # noise model + +pointer nse + +begin + call malloc (AP_NOISE(ap), LEN_APNOISE, TY_STRUCT) + nse = AP_NOISE(ap) + AP_NOISEFUNCTION(nse) = noise + switch (noise) { + case AP_NCONSTANT: + call strcpy ("constant", AP_NSTRING(nse), SZ_FNAME) + case AP_NPOISSON: + call strcpy ("poisson", AP_NSTRING(nse), SZ_FNAME) + default: + call strcpy ("poisson", AP_NSTRING(nse), SZ_FNAME) + } + AP_READNOISE(nse) = DEF_READNOISE + AP_SKYSIGMA(nse) = DEF_SKYSIGMA + AP_EPADU(nse) = DEF_EPADU + AP_GAIN(nse) = EOS + AP_CCDREAD(nse) = EOS +end + + +# AP_DISPSETUP -- Procedure to setup the display parameters. + +procedure ap_dispsetup (ap) + +pointer ap # pointer to apphot structure + +pointer dsp + +begin + call malloc (AP_PDISPLAY(ap), LEN_DISPLAYSTRUCT, TY_STRUCT) + dsp = AP_PDISPLAY(ap) + AP_MKSKY(dsp) = DEF_MKSKY + AP_MKCENTER(dsp) = DEF_MKCENTER + AP_MKAPERT(dsp) = DEF_MKAPERT + AP_RADPLOTS(dsp) = DEF_RADPLOTS + AP_MKDETECTIONS(dsp) = DEF_MKDETECTIONS +end diff --git a/noao/digiphot/apphot/aplib/apinpars1.x b/noao/digiphot/apphot/aplib/apinpars1.x new file mode 100644 index 00000000..cc332004 --- /dev/null +++ b/noao/digiphot/apphot/aplib/apinpars1.x @@ -0,0 +1,104 @@ +include "../lib/apphot.h" +include "../lib/display.h" +include "../lib/noise.h" +include "../lib/find.h" + +# AP_GDAPARS-- Read in the data dependent parameters from the datapars file. + +procedure ap_gdapars (ap) + +pointer ap # pointer to the apphot structure + +int noise +pointer sp, str, np +bool clgpsetb() +int strdic(), btoi() +pointer clopset() +real clgpsetr() + +begin + # Allocate workin space. + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + + # Open the pset parameter file. + np = clopset ("datapars") + + # Get the data dependent parameters. + call apsetr (ap, FWHMPSF, clgpsetr (np, "fwhmpsf")) + call apsetr (ap, SCALE, 1.0 / clgpsetr (np, "scale")) + call apseti (ap, POSITIVE, btoi (clgpsetb (np, "emission"))) + call apsetr (ap, DATAMIN, clgpsetr (np, "datamin")) + call apsetr (ap, DATAMAX, clgpsetr (np, "datamax")) + call apsetr (ap, SKYSIGMA, clgpsetr (np, "sigma")) + + # Get the noise function parameters. + call clgpset (np, "noise", Memc[str], SZ_LINE) + noise = strdic (Memc[str], Memc[str], SZ_LINE, NFUNCS) + call apsets (ap, NSTRING, Memc[str]) + call apseti (ap, NOISEFUNCTION, noise) + call clgpset (np, "gain", Memc[str], SZ_LINE) + call apsets (ap, GAIN, Memc[str]) + call apsetr (ap, EPADU, clgpsetr (np, "epadu")) + call clgpset (np, "ccdread", Memc[str], SZ_LINE) + call apsets (ap, CCDREAD, Memc[str]) + call apsetr (ap, READNOISE, clgpsetr (np, "readnoise")) + + # Get the image header parameters. + call clgpset (np, "exposure", Memc[str], SZ_LINE) + call apsets (ap, EXPOSURE, Memc[str]) + call apsetr (ap, ITIME, clgpsetr (np, "itime")) + call clgpset (np, "airmass", Memc[str], SZ_LINE) + call apsets (ap, AIRMASS, Memc[str]) + call apsetr (ap, XAIRMASS, clgpsetr (np, "xairmass")) + call clgpset (np, "filter", Memc[str], SZ_LINE) + call apsets (ap, FILTER, Memc[str]) + call clgpset (np, "ifilter", Memc[str], SZ_LINE) + call apsets (ap, FILTERID, Memc[str]) + call clgpset (np, "obstime", Memc[str], SZ_LINE) + call apsets (ap, OBSTIME, Memc[str]) + call clgpset (np, "otime", Memc[str], SZ_LINE) + call apsets (ap, OTIME, Memc[str]) + + # Close the parameter set files. + call clcpset (np) + + call sfree (sp) +end + + +# AP_GFIPARS -- Read in the object finding parametes from the findpars +# parameter file. + +procedure ap_gfipars (ap) + +pointer ap # pointer to the apphot structure + +pointer pp +bool clgpsetb() +int btoi() +pointer clopset() +real clgpsetr() + +begin + # Open the pset parameter file. + pp = clopset ("findpars") + + # Get the kernel statistics. + call apsetr (ap, NSIGMA, clgpsetr (pp, "nsigma")) + call apsetr (ap, RATIO, clgpsetr (pp, "ratio")) + call apsetr (ap, THETA, clgpsetr (pp, "theta")) + + # Get the image detection characteristics. + call apsetr (ap, THRESHOLD, clgpsetr (pp, "threshold")) + call apsetr (ap, SHARPLO, clgpsetr (pp, "sharplo")) + call apsetr (ap, SHARPHI, clgpsetr (pp, "sharphi")) + call apsetr (ap, ROUNDLO, clgpsetr (pp, "roundlo")) + call apsetr (ap, ROUNDHI, clgpsetr (pp, "roundhi")) + + # Set the marking parameter. + call apseti (ap, MKDETECTIONS, btoi (clgpsetb (pp, "mkdetections"))) + + # Close the parameter set file. + call clcpset (pp) +end diff --git a/noao/digiphot/apphot/aplib/apinpars2.x b/noao/digiphot/apphot/aplib/apinpars2.x new file mode 100644 index 00000000..ff9cf3eb --- /dev/null +++ b/noao/digiphot/apphot/aplib/apinpars2.x @@ -0,0 +1,207 @@ +include "../lib/display.h" +include "../lib/center.h" +include "../lib/fitsky.h" +include "../lib/phot.h" +include "../lib/polyphot.h" + +# AP_GCEPARS -- Read in the centering algorithm parameters from the +# centerpars parameter file. + +procedure ap_gcepars (ap) + +pointer ap # pointer to the apphot structure + +int function +pointer sp, str, pp +bool clgpsetb() +int strdic(), btoi(), clgpseti() +pointer clopset() +real clgpsetr() + +begin + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + + # Open the pset parameter file. + pp = clopset ("centerpars") + + # Get the centering parameters. + call clgpset (pp, "calgorithm", Memc[str], SZ_LINE) + function = strdic (Memc[str], Memc[str], SZ_LINE, CFUNCS) + call apsets (ap, CSTRING, Memc[str]) + call apseti (ap, CENTERFUNCTION, function) + call apsetr (ap, CAPERT, clgpsetr (pp, "cbox") / 2.0) + call apsetr (ap, CTHRESHOLD, clgpsetr (pp, "cthreshold")) + call apsetr (ap, MINSNRATIO, clgpsetr (pp, "minsnratio")) + call apseti (ap, CMAXITER, clgpseti (pp, "cmaxiter")) + call apsetr (ap, MAXSHIFT, clgpsetr (pp, "maxshift")) + call apseti (ap, CLEAN, btoi (clgpsetb (pp, "clean"))) + call apsetr (ap, RCLEAN, clgpsetr (pp, "rclean")) + call apsetr (ap, RCLIP, clgpsetr (pp, "rclip")) + call apsetr (ap, SIGMACLEAN, clgpsetr (pp, "kclean")) + + call apseti (ap, MKCENTER, btoi (clgpsetb (pp, "mkcenter"))) + + + # Close the parameter set file. + call clcpset (pp) + + call sfree (sp) +end + + +# AP_GSAPARS -- Read in the sky fitting parameters from the fitskypars +# parameter file. + +procedure ap_gsapars (ap) + +pointer ap # pointer to the apphot strucuture + +int function +pointer sp, str, pp +bool clgpsetb() +int strdic(), clgpseti(), btoi() +pointer clopset() +real clgpsetr() + +begin + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + + # Open the pset parameter file. + pp = clopset ("fitskypars") + + # Get the sky fitting algorithm parameters. + call clgpset (pp, "salgorithm", Memc[str], SZ_LINE) + function = strdic (Memc[str], Memc[str], SZ_LINE, SFUNCS) + call apsets (ap, SSTRING, Memc[str]) + call apseti (ap, SKYFUNCTION, function) + call apsetr (ap, SKY_BACKGROUND, clgpsetr (pp, "skyvalue")) + call apsetr (ap, ANNULUS, clgpsetr (pp, "annulus")) + call apsetr (ap, DANNULUS, clgpsetr (pp, "dannulus")) + call apsetr (ap, K1, clgpsetr (pp, "khist")) + call apsetr (ap, BINSIZE, clgpsetr (pp, "binsize")) + call apseti (ap, SMOOTH, btoi (clgpsetb (pp, "smooth"))) + call apseti (ap, SMAXITER, clgpseti (pp, "smaxiter")) + call apsetr (ap, SLOCLIP, clgpsetr (pp, "sloclip")) + call apsetr (ap, SHICLIP, clgpsetr (pp, "shiclip")) + call apseti (ap, SNREJECT, clgpseti (pp, "snreject")) + call apsetr (ap, SLOREJECT, clgpsetr (pp, "sloreject")) + call apsetr (ap, SHIREJECT, clgpsetr (pp, "shireject")) + call apsetr (ap, RGROW, clgpsetr (pp, "rgrow")) + + # Get the marking parameter. + call apseti (ap, MKSKY, btoi (clgpsetb (pp, "mksky"))) + + # Close the parameter set file. + call clcpset (pp) + + call sfree (sp) +end + + +# AP_GPHPARS -- Get the photometry algorithm parameters from the photometry +# file. + +procedure ap_gphars (ap) + +pointer ap # pointer to the apphot strucuture + +pointer sp, str, pp +bool clgpsetb() +int btoi() +pointer clopset() +real clgpsetr() + +begin + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + + # Open the pset parameter file. + pp = clopset ("photpars") + + # Get the photometry parameters. + call clgpset (pp, "apertures", Memc[str], SZ_LINE) + call apsets (ap, APERTS, Memc[str]) + call apsetr (ap, ZMAG, clgpsetr (pp, "zmag")) + call apseti (ap, MKAPERT, btoi (clgpsetb (pp, "mkapert"))) + call apsets (ap, PWSTRING, "constant") + call apseti (ap, PWEIGHTS, AP_PWCONSTANT) + + # Close the parameter set file. + call clcpset (pp) + + call sfree (sp) +end + + +# AP_GPOPARS -- Get the polygonal aperture photometry parameters. + +procedure ap_gpopars (ap) + +pointer ap # pointer to the apphot strucuture + +pointer sp, str, pp +bool clgpsetb() +int btoi() +pointer clopset() +real clgpsetr() + +begin + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + + # Open the pset parameter file. + pp = clopset ("polypars") + + # Get the parameters. + call apsetr (ap, PYZMAG, clgpsetr (pp, "zmag")) + call apseti (ap, MKPOLYGON, btoi (clgpsetb (pp, "mkpolygon"))) + + # Close the parameter set file. + call clcpset (pp) + + call sfree (sp) +end + + +# AP_GWHPARS -- Get the photometry algorithm parameters from the photometry +# file. + +procedure ap_gwhars (ap) + +pointer ap # pointer to the apphot strucuture + +int weight +pointer sp, str, pp +bool clgpsetb() +int btoi(), strdic() +pointer clopset() +real clgpsetr() + +begin + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + + # Open the pset parameter file. + pp = clopset ("photpars") + + # Get the photometry parameters. + call clgpset (pp, "apertures", Memc[str], SZ_LINE) + call apsets (ap, APERTS, Memc[str]) + call apsetr (ap, ZMAG, clgpsetr (pp, "zmag")) + call apseti (ap, MKAPERT, btoi (clgpsetb (pp, "mkapert"))) + call apsets (ap, PWSTRING, "constant") + call apseti (ap, PWEIGHTS, AP_PWCONSTANT) + + # Get the major parameters. + call clgpset (pp, "weighting", Memc[str], SZ_LINE) + weight = strdic (Memc[str], Memc[str], SZ_LINE, PWFUNCS) + call apsets (ap, PWSTRING, Memc[str]) + call apseti (ap, PWEIGHTS, weight) + + # Close the parameter set file. + call clcpset (pp) + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/aplib/apitime.x b/noao/digiphot/apphot/aplib/apitime.x new file mode 100644 index 00000000..c01dfc9e --- /dev/null +++ b/noao/digiphot/apphot/aplib/apitime.x @@ -0,0 +1,36 @@ +include <imhdr.h> +include "../lib/apphot.h" + +# AP_ITIME - Procedure to set the image exposure time . + +procedure ap_itime (im, ap) + +pointer im # pointer to IRAF image +pointer ap # pointer to apphot structure + +pointer sp, key +real itime +real imgetr(), apstatr() + +begin + call smark (sp) + call salloc (key, SZ_FNAME, TY_CHAR) + call apstats (ap, EXPOSURE, Memc[key], SZ_FNAME) + if (Memc[key] == EOS) + itime = apstatr (ap, ITIME) + else { + iferr { + itime = imgetr (im, Memc[key]) + } then { + itime = apstatr (ap, ITIME) + call eprintf ("Warning: Image %s Keyword: %s not found\n") + call pargstr (IM_HDRFILE(im)) + call pargstr (Memc[key]) + } + } + if (IS_INDEFR(itime) || itime <= 0.0) + call apsetr (ap, ITIME, 1.0) + else + call apsetr (ap, ITIME, itime) + call sfree (sp) +end diff --git a/noao/digiphot/apphot/aplib/apmark1.x b/noao/digiphot/apphot/aplib/apmark1.x new file mode 100644 index 00000000..1982a679 --- /dev/null +++ b/noao/digiphot/apphot/aplib/apmark1.x @@ -0,0 +1,270 @@ +include <gset.h> +include "../lib/apphot.h" +include "../lib/center.h" +include "../lib/fitsky.h" +include "../lib/phot.h" +include "../lib/polyphot.h" +include "../lib/radprof.h" + +# APMARK -- Procedure to mark center, fitsky and phot parameters on the display. + +procedure apmark (ap, id, mkcenter, mksky, mkapert) + +pointer ap # apphot pointer +pointer id # pointer to image display stream +int mkcenter # mark the computed center +int mksky # mark the sky annulus +int mkapert # mark the aperture(s) + +int i, marktype +pointer sp, temp +real inner_sky, outer_sky, apert +int apstati(), gstati() +real apstatr() +errchk greactivate, gdeactivate, gamove, gadraw, gmark + +begin + if (id == NULL) + return + if (mkcenter == NO && mksky == NO && mkapert == NO) + return + iferr { + call greactivate (id, 0) + } then { + return + } + + marktype = gstati (id, G_PMLTYPE) + + # Mark the center and shift on the display. + if (mkcenter == YES) { + iferr { + call gseti (id, G_PMLTYPE, GL_SOLID) + call gamove (id, (apstatr (ap, XCENTER) - apstatr (ap, XSHIFT)), + (apstatr (ap, YCENTER) - apstatr (ap, YSHIFT))) + call gadraw (id, apstatr (ap, XCENTER), apstatr (ap, YCENTER)) + call gmark (id, apstatr (ap, XCENTER), apstatr (ap, YCENTER), + GM_PLUS, -2.0, -2.0) + } then + ; + } + + # Draw the sky annuli on the display. + if (mksky == YES) { + iferr { + call gseti (id, G_PMLTYPE, GL_DASHED) + call gmark (id, apstatr (ap, SXCUR), apstatr (ap, SYCUR), + GM_PLUS, -2.0, -2.0) + inner_sky = 2.0 * apstatr (ap, SCALE) * apstatr (ap, ANNULUS) + call gmark (id, apstatr (ap, SXCUR), apstatr (ap, SYCUR), + GM_CIRCLE, -inner_sky, -inner_sky) + outer_sky = 2.0 * apstatr (ap, SCALE) * (apstatr (ap, + ANNULUS) + apstatr (ap, DANNULUS)) + call gmark (id, apstatr (ap, SXCUR), apstatr (ap, SYCUR), + GM_CIRCLE, -outer_sky, -outer_sky) + } then + ; + } + + # Draw the apertures on the display. + if (mkapert == YES) { + iferr { + call smark (sp) + call salloc (temp, apstati (ap, NAPERTS), TY_REAL) + call ap_arrayr (ap, APERTS, Memr[temp]) + call gseti (id, G_PMLTYPE, GL_DASHED) + call gmark (id, apstatr (ap, PXCUR), apstatr (ap, PYCUR), + GM_PLUS, -2.0, -2.0) + do i = 1, apstati (ap, NAPERTS) { + apert = 2.0 * apstatr (ap, SCALE) * Memr[temp+i-1] + call gmark (id, apstatr (ap, PXCUR), apstatr (ap, PYCUR), + GM_CIRCLE, -apert, -apert) + } + call sfree (sp) + } then + call sfree (sp) + } + + # Restore the mark type. + call gseti (id, G_PMLTYPE, marktype) + + iferr { + call gdeactivate (id, 0) + } then + return +end + +# APPYMARK -- Procedure to mark center, fitsky and polyphot parameters on the +# display. + +procedure appymark (ap, id, x, y, nver, mkcenter, mksky, mkpolygon) + +pointer ap # apphot pointer +pointer id # pointer to image display stream +real x[ARB] # coordinates of x vertices +real y[ARB] # coordinates of y vertices +int nver # number of vertices +int mkcenter # mark the computed center +int mksky # mark the sky annulus +int mkpolygon # mark the aperture(s) + +int marktype, linetype +real inner_sky, outer_sky +int gstati() +real apstatr() +errchk greactivate, gdeactivate, gamove, gadraw, gmark, gline + +begin + if (id == NULL) + return + if (mkcenter == NO && mksky == NO && mkpolygon == NO) + return + iferr { + call greactivate (id, 0) + } then + return + + marktype = gstati (id, G_PMLTYPE) + linetype = gstati (id, G_PLTYPE) + + if (mkcenter == YES) { + iferr { + call gseti (id, G_PMLTYPE, GL_SOLID) + call gamove (id, (apstatr (ap, XCENTER) - apstatr (ap, XSHIFT)), + (apstatr (ap, YCENTER) - apstatr (ap, YSHIFT))) + call gadraw (id, apstatr (ap, XCENTER), apstatr (ap, YCENTER)) + call gmark (id, apstatr (ap, XCENTER), apstatr (ap, YCENTER), + GM_PLUS, -2.0, -2.0) + } then + ; + } + + if (mksky == YES) { + iferr { + call gseti (id, G_PMLTYPE, GL_DASHED) + call gmark (id, apstatr (ap, SXCUR), apstatr (ap, SYCUR), + GM_PLUS, -2.0, -2.0) + inner_sky = 2.0 * apstatr (ap, SCALE) * apstatr (ap, ANNULUS) + call gmark (id, apstatr (ap, SXCUR), apstatr (ap, SYCUR), + GM_CIRCLE, -inner_sky, -inner_sky) + outer_sky = 2.0 * apstatr (ap, SCALE) * (apstatr (ap, + ANNULUS) + apstatr (ap, DANNULUS)) + call gmark (id, apstatr (ap, SXCUR), apstatr (ap, SYCUR), + GM_CIRCLE, -outer_sky, -outer_sky) + } then + ; + } + + if (mkpolygon == YES) { + iferr { + call gseti (id, G_PLTYPE, GL_DASHED) + call gmark (id, apstatr (ap, PYCX), apstatr (ap, PYCY), + GM_PLUS, -2.0, -2.0) + call gpline (id, x, y, nver) + } then + ; + } + + call gseti (id, G_PMLTYPE, marktype) + call gseti (id, G_PLTYPE, linetype) + + iferr (call gdeactivate (id, 0)) + return +end + + +# APRMARK -- Procedure to mark center, fitsky and radprof parameters on the +# display. + +procedure aprmark (ap, id, mkcenter, mksky, mkapert) + +pointer ap # apphot pointer +pointer id # pointer to image display stream +int mkcenter # mark the computed center +int mksky # mark the sky annulus +int mkapert # mark the aperture(s) + +int i, marktype +pointer sp, temp +real inner_sky, outer_sky, apert, radius, xc, yc +int apstati(), gstati() +real apstatr() +errchk greactivate, gdeactivate, gamove, gadraw, gmark + +begin + if (id == NULL) + return + if (mkcenter == NO && mksky == NO && mkapert == NO) + return + + iferr { + call greactivate (id, 0) + } then + return + + marktype = gstati (id, G_PMLTYPE) + + # Mark the center and shift on the display. + if (mkcenter == YES) { + iferr { + call gseti (id, G_PMLTYPE, GL_SOLID) + call gamove (id, (apstatr (ap, XCENTER) - apstatr (ap, XSHIFT)), + (apstatr (ap, YCENTER) - apstatr (ap, YSHIFT))) + call gadraw (id, apstatr (ap, XCENTER), apstatr (ap, YCENTER)) + call gmark (id, apstatr (ap, XCENTER), apstatr (ap, YCENTER), + GM_PLUS, -2.0, -2.0) + call gflush (id) + } then + ; + } + + # Draw the sky annuli on the display. + if (mksky == YES) { + iferr { + call gseti (id, G_PMLTYPE, GL_DASHED) + call gmark (id, apstatr (ap, SXCUR), apstatr (ap, SYCUR), + GM_PLUS, -2.0, -2.0) + inner_sky = 2.0 * apstatr (ap, SCALE) * apstatr (ap, ANNULUS) + call gmark (id, apstatr (ap, SXCUR), apstatr (ap, SYCUR), + GM_CIRCLE, -inner_sky, -inner_sky) + outer_sky = 2.0 * apstatr (ap, SCALE) * (apstatr (ap, + ANNULUS) + apstatr (ap, DANNULUS)) + call gmark (id, apstatr (ap, SXCUR), apstatr (ap, SYCUR), + GM_CIRCLE, -outer_sky, -outer_sky) + call gflush (id) + } then + ; + } + + # Draw the apertures on the display. + if (mkapert == YES) { + iferr { + call smark (sp) + call salloc (temp, apstati (ap, NAPERTS), TY_REAL) + call gseti (id, G_PMLTYPE, GL_DASHED) + call gmark (id, apstatr (ap, XCENTER), apstatr (ap, YCENTER), + GM_PLUS, -2.0, -2.0) + call ap_arrayr (ap, APERTS, Memr[temp]) + do i = 1, apstati (ap, NAPERTS) { + apert = 2.0 * apstatr (ap, SCALE) * Memr[temp+i-1] + call gmark (id, apstatr (ap, XCENTER), apstatr (ap, + YCENTER), GM_CIRCLE, -apert, -apert) + } + xc = apstatr (ap, XCENTER) + yc = apstatr (ap, YCENTER) + radius = apstatr (ap, SCALE) * apstatr (ap, RPRADIUS) + call gamove (id, xc - radius, yc - radius) + call gadraw (id, xc + radius, yc - radius) + call gadraw (id, xc + radius, yc + radius) + call gadraw (id, xc - radius, yc + radius) + call gadraw (id, xc - radius, yc - radius) + call sfree (sp) + } then + call sfree (sp) + } + + call gseti (id, G_PMLTYPE, marktype) + + iferr (call gdeactivate (id, 0)) + return +end diff --git a/noao/digiphot/apphot/aplib/apmark2.x b/noao/digiphot/apphot/aplib/apmark2.x new file mode 100644 index 00000000..96896e56 --- /dev/null +++ b/noao/digiphot/apphot/aplib/apmark2.x @@ -0,0 +1,46 @@ +include <gset.h> +include "../lib/apphot.h" +include "../lib/fitpsf.h" + + +# AP_PFMARK -- Procedure to mark the psf fitting box on the display. + +procedure appfmark (ap, id, mkbox) + +pointer ap # pointer to the apphot procedure +pointer id # pointer to the display stream +int mkbox # mark the psf fitting box + +int marktype +real radius, xc, yc +int gstati() +real apstatr() +errchk greactivate, gdeactivate, gamove, gadraw + +begin + if (id == NULL) + return + if (mkbox == NO) + return + + iferr (call greactivate (id, 0)) + return + + marktype = gstati (id,G_PMLTYPE) + iferr { + call gseti (id, G_PMLTYPE, GL_DASHED) + xc = apstatr (ap, PFXCUR) + yc = apstatr (ap, PFYCUR) + radius = apstatr (ap, SCALE) * apstatr (ap, PSFAPERT) + call gamove (id, xc - radius, yc - radius) + call gadraw (id, xc + radius, yc - radius) + call gadraw (id, xc + radius, yc + radius) + call gadraw (id, xc - radius, yc + radius) + call gadraw (id, xc - radius, yc - radius) + } then + ; + call gseti (id, G_PMLTYPE, marktype) + + iferr (call gdeactivate (id, 0)) + return +end diff --git a/noao/digiphot/apphot/aplib/apnew.x b/noao/digiphot/apphot/aplib/apnew.x new file mode 100644 index 00000000..b5da6fc1 --- /dev/null +++ b/noao/digiphot/apphot/aplib/apnew.x @@ -0,0 +1,46 @@ +include "../lib/apphot.h" + +# APNEW -- Procedure to determine whether the current star is the same as +# the previous star and/or whether the current star belongs to the coordinate +# list or not. + +int procedure apnew (ap, wx, wy, xlist, ylist, newlist) + +pointer ap # pointer to the apphot structure +real wx # x cursor coordinate +real wy # y cursor coordinate +real xlist # x list coordinate +real ylist # y list coordinate +int newlist # integer new list + +bool fp_equalr() +int newobject +real deltaxy +real apstatr() + +begin + deltaxy = apstatr (ap, FWHMPSF) * apstatr (ap, SCALE) + + if (newlist == NO) { + if (! fp_equalr (wx, apstatr (ap, WX)) || ! fp_equalr (wy, + apstatr (ap, WY))) + newobject = YES + else + newobject = NO + } else if ((abs (xlist - wx) <= deltaxy) && + (abs (ylist - wy) <= deltaxy)) { + wx = xlist + wy = ylist + newobject = NO + } else if (fp_equalr (wx, apstatr (ap, WX)) && fp_equalr (wy, + apstatr (ap, WY))) { + wx = xlist + wy = ylist + newobject = NO + } else { + newlist = NO + newobject = YES + } + + return (newobject) +end diff --git a/noao/digiphot/apphot/aplib/apnscolon.x b/noao/digiphot/apphot/aplib/apnscolon.x new file mode 100644 index 00000000..34bc43fc --- /dev/null +++ b/noao/digiphot/apphot/aplib/apnscolon.x @@ -0,0 +1,165 @@ +include <error.h> +include "../lib/noise.h" + +# AP_NSCOLON -- Procedure to process colon commands for setting +# noise fitting parameters. + +procedure ap_nscolon (ap, im, out, stid, cmdstr, newcenterbuf, + newcenter, newskybuf, newsky, newbuf, newfit) + +pointer ap # pointer to the apphot structure +pointer im # pointer to the iraf image +int out # output file descriptor +int stid # output file sequence number +char cmdstr[ARB] # command string +int newcenterbuf, newcenter # new centering parameters ? +int newskybuf, newsky # new sky fitting parameters ? +int newbuf, newfit # new photometry parameters ? + +int ncmd, stat, ip +pointer sp, cmd, str +real rval +int strdic(), nscan(), ctowrd() +real apstatr() +errchk immmap + +begin + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + call salloc (str, SZ_LINE, TY_CHAR) + + # Get the command. + ip = 1 + call sscan (cmdstr) + call gargwrd (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call sfree (sp) + return + } + + # Process the command. + ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, NCMDS) + switch (ncmd) { + + case NCMD_NOISE: + call gargwrd (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call apstats (ap, NSTRING, Memc[str], SZ_FNAME) + call printf ("%s = %s %s\n") + call pargstr (KY_NSTRING) + call pargstr (Memc[str]) + call pargstr (UN_NMODEL) + } else { + stat = strdic (Memc[cmd], Memc[cmd], SZ_LINE, NFUNCS) + if (stat > 0) { + call apseti (ap, NOISEFUNCTION, stat) + call apsets (ap, NSTRING, Memc[cmd]) + if (stid > 1) + call ap_sparam (out, KY_NSTRING, Memc[cmd], UN_NMODEL, + "noise model") + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newbuf = YES; newfit = YES + } + } + + case NCMD_SIGMA: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_SKYSIGMA) + call pargr (apstatr (ap, SKYSIGMA)) + call pargstr (UN_NCOUNTS) + } else { + call apsetr (ap, SKYSIGMA, rval) + if (stid > 1) + call ap_rparam (out, KY_SKYSIGMA, rval, UN_NCOUNTS, + "standard deviation of 1 pixel") + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newbuf = YES; newfit = YES + } + + case NCMD_EPADU: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_EPADU) + call pargr (apstatr (ap, EPADU)) + call pargstr (UN_NEPADU) + } else { + call apsetr (ap, EPADU, rval) + if (stid > 1) + call ap_rparam (out, KY_EPADU, rval, UN_NEPADU, + "photons per adu") + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newbuf = YES; newfit = YES + } + + case NCMD_GAIN: + call gargstr (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call apstats (ap, GAIN, Memc[str], SZ_LINE) + call printf ("%s = %s\n") + call pargstr (KY_GAIN) + call pargstr (Memc[str]) + } else { + if (ctowrd (Memc[cmd], ip, Memc[str], SZ_LINE) <= 0) + Memc[str] = EOS + call apsets (ap, GAIN, Memc[str]) + if (im != NULL) + call ap_padu (im, ap) + if (stid > 1) + call ap_sparam (out, KY_GAIN, Memc[str], UN_NKEYWORD, + "gain keyword") + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newbuf = YES; newfit = YES + } + + case NCMD_CCDREAD: + call gargstr (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call apstats (ap, CCDREAD, Memc[str], SZ_LINE) + call printf ("%s = %s\n") + call pargstr (KY_CCDREAD) + call pargstr (Memc[str]) + } else { + if (ctowrd (Memc[cmd], ip, Memc[str], SZ_LINE) <= 0) + Memc[str] = EOS + call apsets (ap, CCDREAD, Memc[str]) + if (im != NULL) + call ap_rdnoise (im, ap) + if (stid > 1) + call ap_sparam (out, KY_CCDREAD, Memc[str], UN_NKEYWORD, + "read noise keyword") + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newbuf = YES; newfit = YES + } + + case NCMD_READNOISE: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_READNOISE) + call pargr (apstatr (ap, READNOISE)) + call pargstr (UN_NELECTRONS) + } else { + call apsetr (ap, READNOISE, rval) + if (stid > 1) + call ap_rparam (out, KY_READNOISE, rval, UN_NELECTRONS, + "readout noise") + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newbuf = YES; newfit = YES + } + + + default: + call printf ("Unknown or ambiguous colon command\7\n") + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/aplib/apnshow.x b/noao/digiphot/apphot/aplib/apnshow.x new file mode 100644 index 00000000..a0a173a0 --- /dev/null +++ b/noao/digiphot/apphot/aplib/apnshow.x @@ -0,0 +1,118 @@ +include "../lib/apphot.h" +include "../lib/noise.h" + +# AP_NSHOW -- Procedure to display the current data parameters. + +procedure ap_nshow (ap) + +pointer ap # pointer to the apphot structure + +pointer sp, str1, str2 +bool itob() +int apstati() +real apstatr() + +begin + call smark (sp) + call salloc (str1, SZ_LINE, TY_CHAR) + call salloc (str2, SZ_LINE, TY_CHAR) + + # Set the object charactersitics. + call printf ("\nData Characteristics\n") + call apstats (ap, IMNAME, Memc[str1], SZ_FNAME) + call printf (" %s: %s (%.2f, %.2f) %s: %g\n") + call pargstr (KY_IMNAME) + call pargstr (Memc[str1]) + call pargr (apstatr (ap, CWX)) + call pargr (apstatr (ap, CWY)) + call pargstr (KY_SCALE) + call pargr (1.0 / apstatr (ap, SCALE)) + + call apstats (ap, OUTNAME, Memc[str1], SZ_FNAME) + call printf (" %s: %s") + call pargstr (KY_OUTNAME) + call pargstr (Memc[str1]) + + call apstats (ap, CLNAME, Memc[str1], SZ_FNAME) + call printf (" %s: %s\n") + call pargstr (KY_CLNAME) + call pargstr (Memc[str1]) + + call printf (" %s = %g %s %s = %b\n") + call pargstr (KY_FWHMPSF) + call pargr (apstatr (ap, FWHMPSF)) + call pargstr (UN_ASCALEUNIT) + call pargstr (KY_POSITIVE) + call pargb (itob (apstati (ap, POSITIVE))) + + call printf (" %s = %g %s %s = %g %s\n") + call pargstr (KY_DATAMIN) + call pargr (apstatr (ap, DATAMIN)) + call pargstr (UN_ACOUNTS) + call pargstr (KY_DATAMAX) + call pargr (apstatr (ap, DATAMAX)) + call pargstr (UN_ACOUNTS) + + call apstats (ap, EXPOSURE, Memc[str1], SZ_FNAME) + call printf (" %s = %s %s = %g %s\n") + call pargstr (KY_EXPOSURE) + call pargstr (Memc[str1]) + call pargstr (KY_ITIME) + call pargr (apstatr (ap, ITIME)) + call pargstr (UN_ATIMEUNIT) + + # Set the filter ID. + call apstats (ap, FILTER, Memc[str1], SZ_FNAME) + call apstats (ap, FILTERID, Memc[str2], SZ_FNAME) + call printf (" %s = %s %s = %s\n") + call pargstr (KY_FILTER) + call pargstr (Memc[str1]) + call pargstr (KY_FILTERID) + call pargstr (Memc[str2]) + + # Set the airmass. + call apstats (ap, AIRMASS, Memc[str1], SZ_FNAME) + call printf (" %s = %s %s = %g\n") + call pargstr (KY_AIRMASS) + call pargstr (Memc[str1]) + call pargstr (KY_XAIRMASS) + call pargr (apstatr (ap, XAIRMASS)) + + # Set the time of observation. + call apstats (ap, OBSTIME, Memc[str1], SZ_FNAME) + call apstats (ap, OTIME, Memc[str2], SZ_FNAME) + call printf (" %s = %s %s = %s\n") + call pargstr (KY_OBSTIME) + call pargstr (Memc[str1]) + call pargstr (KY_OTIME) + call pargstr (Memc[str2]) + + # Set the noise model. + call printf ("\nNoise Model\n") + call apstats (ap, NSTRING, Memc[str1], SZ_FNAME) + call printf (" %s = %s %s %s = %g %s\n") + call pargstr (KY_NSTRING) + call pargstr (Memc[str1]) + call pargstr (UN_NMODEL) + call pargstr (KY_SKYSIGMA) + call pargr (apstatr (ap, SKYSIGMA)) + call pargstr (UN_NCOUNTS) + + call apstats (ap, GAIN, Memc[str1], SZ_LINE) + call printf (" %s = %s %s = %g %s\n") + call pargstr (KY_GAIN) + call pargstr (Memc[str1]) + call pargstr (KY_EPADU) + call pargr (apstatr (ap, EPADU)) + call pargstr (UN_NEPADU) + + call apstats (ap, CCDREAD, Memc[str1], SZ_LINE) + call printf (" %s = %s %s = %g %s\n") + call pargstr (KY_CCDREAD) + call pargstr (Memc[str1]) + call pargstr (KY_READNOISE) + call pargr (apstatr (ap, READNOISE)) + call pargstr (UN_NELECTRONS) + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/aplib/apotime.x b/noao/digiphot/apphot/aplib/apotime.x new file mode 100644 index 00000000..2da01e3e --- /dev/null +++ b/noao/digiphot/apphot/aplib/apotime.x @@ -0,0 +1,52 @@ +include <imhdr.h> +include "../lib/apphot.h" + +# AP_OTIME -- Fetch the time or epoch of the observation from the image +# header. + +procedure ap_otime (im, ap) + +pointer im # pointer to IRAF image +pointer ap # pointer to apphot structure + +char timechar +int index +pointer sp, key, otime +bool streq() +int strldx() + +begin + call smark (sp) + call salloc (key, SZ_FNAME, TY_CHAR) + call salloc (otime, SZ_FNAME, TY_CHAR) + + call apstats (ap, OBSTIME, Memc[key], SZ_FNAME) + Memc[otime] = EOS + if (Memc[key] == EOS) + call apstats (ap, OTIME, Memc[otime], SZ_FNAME) + else { + iferr { + call imgstr (im, Memc[key], Memc[otime], SZ_FNAME) + } then { + call apstats (ap, OTIME, Memc[otime], SZ_FNAME) + call eprintf ("Warning: Image %s Keyword: %s not found\n") + call pargstr (IM_HDRFILE(im)) + call pargstr (Memc[key]) + } + } + if (Memc[otime] == EOS) { + call apsets (ap, OTIME, "INDEF") + } else if (streq ("DATE-OBS", Memc[key]) || streq ("date-obs", + Memc[key])) { + timechar = 'T' + index = strldx (timechar, Memc[otime]) + if (index > 0) + call apsets (ap, OTIME, Memc[otime+index]) + else + call apsets (ap, OTIME, "INDEF") + } else { + call apsets (ap, OTIME, Memc[otime]) + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/aplib/apoutpars1.x b/noao/digiphot/apphot/aplib/apoutpars1.x new file mode 100644 index 00000000..c4894bbb --- /dev/null +++ b/noao/digiphot/apphot/aplib/apoutpars1.x @@ -0,0 +1,99 @@ +include "../lib/apphot.h" +include "../lib/noise.h" +include "../lib/display.h" +include "../lib/find.h" + + +# AP_DAPARS -- Procedure to write out the current DATAPARS parameters +# to the current DATAPARS parameter file. + +procedure ap_dapars (ap) + +pointer ap # pointer to apphot structure + +pointer sp, str, np +bool itob() +int apstati() +pointer clopset() +real apstatr() + +begin + # Open the parameter sets. + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + + np = clopset ("datapars") + + # Set the noise model. + call apstats (ap, NSTRING, Memc[str], SZ_FNAME) + call clppset (np, "noise", Memc[str]) + + # Get the rest of the data dependent parameters. + call clppsetr (np, "fwhmpsf", apstatr (ap, FWHMPSF)) + call clppsetr (np, "scale", 1.0 / apstatr (ap, SCALE)) + call clppsetb (np, "emission", itob (apstati (ap, POSITIVE))) + call clppsetr (np, "datamin", apstatr (ap, DATAMIN)) + call clppsetr (np, "datamax", apstatr (ap, DATAMAX)) + + call clppsetr (np, "sigma", apstatr (ap, SKYSIGMA)) + call apstats (ap, GAIN, Memc[str], SZ_LINE) + call clppset (np, "gain", Memc[str]) + call clppsetr (np, "epadu", apstatr (ap, EPADU)) + call apstats (ap, CCDREAD, Memc[str], SZ_LINE) + call clppset (np, "ccdread", Memc[str]) + call clppsetr (np, "readnoise", apstatr (ap, READNOISE)) + + call apstats (ap, EXPOSURE, Memc[str], SZ_LINE) + call clppset (np, "exposure", Memc[str]) + call clppsetr (np, "itime", apstatr (ap, ITIME)) + + call apstats (ap, AIRMASS, Memc[str], SZ_LINE) + call clppset (np, "airmass", Memc[str]) + call clppsetr (np, "xairmass", apstatr (ap, XAIRMASS)) + + call apstats (ap, FILTER, Memc[str], SZ_LINE) + call clppset (np, "filter", Memc[str]) + call apstats (ap, FILTERID, Memc[str], SZ_LINE) + call clppset (np, "ifilter", Memc[str]) + + call apstats (ap, OBSTIME, Memc[str], SZ_LINE) + call clppset (np, "obstime", Memc[str]) + call apstats (ap, OTIME, Memc[str], SZ_LINE) + call clppset (np, "otime", Memc[str]) + + # Close the pset files. + call clcpset (np) + call sfree (sp) +end + + +# AP_FIPARS -- Procedure to write out the current FINDPARS parameters +# to the current FINDPARS parameter file. + +procedure ap_fipars (ap) + +pointer ap # pointer to apphot structure + +pointer pp +bool itob() +int apstati() +pointer clopset() +real apstatr() + +begin + pp = clopset ("findpars") + + call clppsetr (pp, "nsigma", apstatr (ap, NSIGMA) ) + call clppsetr (pp, "ratio", apstatr (ap, RATIO)) + call clppsetr (pp, "theta", apstatr (ap, THETA)) + + call clppsetr (pp, "threshold", apstatr (ap, THRESHOLD)) + call clppsetr (pp, "sharplo", apstatr (ap, SHARPLO)) + call clppsetr (pp, "sharphi", apstatr (ap, SHARPHI)) + call clppsetr (pp, "roundlo", apstatr (ap, ROUNDLO)) + call clppsetr (pp, "roundhi", apstatr (ap, ROUNDHI)) + + call clppsetb (pp, "mkdetections", itob (apstati (ap, MKDETECTIONS))) + + call clcpset (pp) +end diff --git a/noao/digiphot/apphot/aplib/apoutpars2.x b/noao/digiphot/apphot/aplib/apoutpars2.x new file mode 100644 index 00000000..79b929c4 --- /dev/null +++ b/noao/digiphot/apphot/aplib/apoutpars2.x @@ -0,0 +1,146 @@ +include "../lib/display.h" +include "../lib/center.h" +include "../lib/fitsky.h" +include "../lib/phot.h" +include "../lib/polyphot.h" + + +# AP_CEPARS -- Procedure to write out the current CENTERPARS parameters +# to the current CENTERPARS parameter file. + +procedure ap_cepars (ap) + +pointer ap # pointer to apphot structure + +pointer sp, str, cp +bool itob() +int apstati() +pointer clopset() +real apstatr() + +begin + # Open the parameter set. + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + cp = clopset ("centerpars") + + # Write the centering parameters. + call apstats (ap, CSTRING, Memc[str], SZ_FNAME) + call clppset (cp, "calgorithm", Memc[str]) + call clppsetr (cp, "cbox", 2.0 * apstatr (ap, CAPERT)) + call clppsetr (cp, "cthreshold", apstatr (ap, CTHRESHOLD)) + call clppsetr (cp, "minsnratio", apstatr (ap, MINSNRATIO)) + call clppseti (cp, "cmaxiter", apstati (ap, CMAXITER)) + call clppsetr (cp, "maxshift", apstatr (ap, MAXSHIFT)) + call clppsetb (cp, "clean", itob (apstati (ap, CLEAN))) + call clppsetr (cp, "rclean", apstatr (ap, RCLEAN)) + call clppsetr (cp, "rclip", apstatr (ap, RCLIP)) + call clppsetr (cp, "kclean", apstatr (ap, SIGMACLEAN)) + call clppsetb (cp, "mkcenter", itob (apstati (ap, MKCENTER))) + + # Close the pset file. + call clcpset (cp) + call sfree (sp) +end + + +# AP_SAPARS -- Procedure to write out the current FITSKYPARS parameters +# to the FITSKYPARS file. + +procedure ap_sapars (ap) + +pointer ap # pointer to apphot structure + +pointer mp, str, sp +bool itob() +int apstati() +pointer clopset() +real apstatr() + +begin + # Open the parameter sets. + call smark (mp) + call salloc (str, SZ_LINE, TY_CHAR) + sp = clopset ("fitskypars") + + # Set the sky fitting parameters. + call apstats (ap, SSTRING, Memc[str], SZ_FNAME) + call clppset (sp, "salgorithm", Memc[str]) + call clppsetr (sp, "annulus", apstatr (ap, ANNULUS)) + call clppsetr (sp, "dannulus", apstatr (ap, DANNULUS)) + call clppsetr (sp, "skyvalue", apstatr (ap, SKY_BACKGROUND)) + call clppsetr (sp, "khist", apstatr (ap, K1)) + call clppsetr (sp, "binsize", apstatr (ap, BINSIZE)) + call clppsetb (sp, "smooth", itob (apstati (ap, SMOOTH))) + call clppsetr (sp, "sloclip", apstatr (ap, SLOCLIP)) + call clppsetr (sp, "shiclip", apstatr (ap, SHICLIP)) + call clppseti (sp, "smaxiter", apstati (ap, SMAXITER)) + call clppseti (sp, "snreject", apstati (ap, SNREJECT)) + call clppsetr (sp, "sloreject", apstatr (ap, SLOREJECT)) + call clppsetr (sp, "shireject", apstatr (ap, SHIREJECT)) + call clppsetr (sp, "rgrow", apstatr (ap, RGROW)) + call clppsetb (sp, "mksky", itob (apstati (ap, MKSKY))) + + # Close up the pset files. + call clcpset (sp) + call sfree (mp) +end + + +# AP_PHPARS -- Procedure to write out the PHOTPARS parameters to the +# PHOTPARS task. + +procedure ap_phpars (ap) + +pointer ap # pointer to apphot structure + +pointer mp, str, pp +bool itob() +int apstati() +pointer clopset() +real apstatr() + +begin + # Open the parameter set. + call smark (mp) + call salloc (str, SZ_LINE, TY_CHAR) + pp = clopset ("photpars") + + # Set the photometry parameters. + call apstats (ap, APERTS, Memc[str], SZ_LINE) + call clppset (pp, "apertures", Memc[str]) + call clppsetr (pp, "zmag", apstatr (ap, ZMAG)) + call apstats (ap, PWSTRING, Memc[str], SZ_FNAME) + call clppset (pp, "weighting", Memc[str]) + call clppsetb (pp, "mkapert", itob (apstati (ap, MKAPERT))) + + # Close the pset file. + call clcpset (pp) + call sfree (mp) +end + + +# AP_POPARS -- Procedure to write the current POLYPARS parameters to the +# current POLYPARS parameter file. + +procedure ap_popars (ap) + +pointer ap # pointer to apphot structure + +pointer pp +bool itob() +int apstati() +pointer clopset() +real apstatr() + +begin + # Open the psets. + pp = clopset ("polypars") + + # Set the photometry parameters. + call clppsetr (pp, "zmag", apstatr (ap, PYZMAG)) + call clppsetb (pp, "mkpolygon", itob (apstati (ap, MKPOLYGON))) + + # Close the pset files. + call clcpset (pp) +end diff --git a/noao/digiphot/apphot/aplib/appadu.x b/noao/digiphot/apphot/aplib/appadu.x new file mode 100644 index 00000000..121decaf --- /dev/null +++ b/noao/digiphot/apphot/aplib/appadu.x @@ -0,0 +1,37 @@ +include <imhdr.h> +include "../lib/noise.h" + +# AP_PADU -- Procedure to set the gain parameter for the noise model +# computation. + +procedure ap_padu (im, ap) + +pointer im # pointer to IRAF image +pointer ap # pointer to apphot structure + +pointer sp, key +real padu +real imgetr(), apstatr() + +begin + call smark (sp) + call salloc (key, SZ_FNAME, TY_CHAR) + call apstats (ap, GAIN, Memc[key], SZ_FNAME) + if (Memc[key] == EOS) + padu = apstatr (ap, EPADU) + else { + iferr { + padu = imgetr (im, Memc[key]) + } then { + padu = apstatr (ap, EPADU) + call eprintf ("Warning: Image %s Keyword %s not found.\n") + call pargstr (IM_HDRFILE(im)) + call pargstr (Memc[key]) + } + } + if (IS_INDEFR(padu) || padu <= 0.0) + call apsetr (ap, EPADU, 1.0) + else + call apsetr (ap, EPADU, padu) + call sfree (sp) +end diff --git a/noao/digiphot/apphot/aplib/apqrad.x b/noao/digiphot/apphot/aplib/apqrad.x new file mode 100644 index 00000000..6c035d7f --- /dev/null +++ b/noao/digiphot/apphot/aplib/apqrad.x @@ -0,0 +1,119 @@ +include <mach.h> +include "../lib/apphot.h" +include "../lib/center.h" + +define RADIUS 15.0 +define CRADIUS 5 + +# AP_QRAD -- Simple radial profile plotter. + +procedure ap_qrad (ap, im, wx, wy, gd) + +pointer ap # pointer to apphot structure +pointer im # pointero to the IRAF image +real wx, wy # cursor coordinates +pointer gd # pointer to graphics stream + +real gwx, gwy, xcenter, ycenter, xc, yc, radius, rmin, rmax, imin, imax +real u1, u2, v1, v2, x1, x2, y1, y2, xold, yold +pointer gt, sp, pix, coords, index, r, cmd +int maxpix, npix, nx, ny, wcs, key, niter + +real apstatr() +pointer ap_gtinit() +int ap_skypix(), clgcur(), apstati() +int nscan(), scan() + +begin + # Check for open graphics stream. + if (gd == NULL) + return + call greactivate (gd, 0) + call gclear (gd) + call gflush (gd) + + # Get the radius of the extraction region. + call printf ("Half width of extraction box (%4.1f) pixels:") + call pargr (RADIUS) + call flush (STDOUT) + if (scan () == EOF) + radius = RADIUS + else { + call gargr (radius) + if (nscan () < 1) + radius = RADIUS + } + maxpix = (2 * int (radius) + 1) ** 2 + + # Allocate temporary space. + call smark (sp) + call salloc (coords, maxpix, TY_INT) + call salloc (index, maxpix, TY_INT) + call salloc (pix, maxpix, TY_REAL) + call salloc (r, maxpix, TY_REAL) + call salloc (cmd, SZ_LINE, TY_CHAR) + + # Fit the center using 3 iterations. + xold = wx + yold = wy + niter = 0 + repeat { + call ap_ictr (im, xold, yold, CRADIUS, apstati (ap, + POSITIVE), xcenter, ycenter) + niter = niter + 1 + if (abs (xcenter - xold) <= 1.0 && abs (ycenter - yold) <= 1.0) + break + xold = xcenter + yold = ycenter + } until (niter >= 3) + + # Fetch the pixels for the radial profile. + npix = ap_skypix (im, xcenter, ycenter, 0.0, radius, Memr[pix], + Memi[coords], xc, yc, nx, ny) + if (npix <= 0) { + call gdeactivate (gd, 0) + call sfree (sp) + return + } + call ap_index (Memi[index], npix) + + + # Store old viewport and window coordinates. + call ggview (gd, u1, u2, v1, v2) + call ggwind (gd, x1, x2, y1, y2) + + # Initialize the plot and store the viewport and window limits. + #call apstats (ap, IMNAME, Memc[cmd], SZ_FNAME) + call apstats (ap, IMROOT, Memc[cmd], SZ_FNAME) + call ap_ltov (im, xcenter, ycenter, xcenter, ycenter, 1) + gt = ap_gtinit (Memc[cmd], xcenter, ycenter) + + # Compute the radius values. + call ap_xytor (Memi[coords], Memi[index], Memr[r], npix, xc, yc, nx) + call alimr (Memr[r], npix, rmin, rmax) + call alimr (Memr[pix], npix, imin, imax) + + # Plot radial profiles. + call gclear (gd) + call ap_rset (gd, gt, 0.0, rmax, imin, imax, apstatr (ap, SCALE)) + call ap_plotrad (gd, gt, Memr[r], Memr[pix], npix, "plus") + + # Go into cursor mode. + call printf ("Waiting for cursor mode command: [:.help=help,q=quit]") + while (clgcur ("gcommands", gwx, gwy, wcs, key, Memc[cmd], SZ_LINE) != + EOF) { + if (key == 'q') + break + call printf ( + "Waiting for cursor mode command: [:.help=help,q=quit]") + } + + # Restore old window and viewport coordinates. + call gsview (gd, u1, u2, v1, v2) + call gswind (gd, x1, x2, y1, y2) + + # Free plots and working space. + call ap_gtfree (gt) + call sfree (sp) + call gdeactivate (gd, 0) +end diff --git a/noao/digiphot/apphot/aplib/aprcursor1.x b/noao/digiphot/apphot/aplib/aprcursor1.x new file mode 100644 index 00000000..594cbbeb --- /dev/null +++ b/noao/digiphot/apphot/aplib/aprcursor1.x @@ -0,0 +1,584 @@ +include "../lib/apphot.h" +include "../lib/noise.h" +include "../lib/center.h" +include "../lib/fitsky.h" +include "../lib/phot.h" + + +# AP_CFWHMPSF -- Read the fwhmpsf from the radial profile plot. + +real procedure ap_cfwhmpsf (ap, gd, out, stid, rmin, rmax, imin, imax) + +pointer ap # pointer to the apphot structure +pointer gd # pointer to the grapics stream +int out # output file descriptor +int stid # sequence number in output file +real rmin, rmax # x axis limits +real imin, imax # y axis limits + +int wcs, key, stat +pointer sp, cmd +real scale, fwhmpsf, xjunk, yjunk +int clgcur() +real apstatr(), ap_vfwhmpsf() + +begin + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + scale = apstatr (ap, SCALE) + + # Mark the FWHM of the PSF on the plot. + call printf ("Mark half-width half-maximum of the psf (%g) pixels:") + call pargr (apstatr (ap, FWHMPSF) * scale / 2.0) + call gscur (gd, apstatr (ap, FWHMPSF) * scale / 2.0, (imin + imax) / + 2.0) + stat = clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], SZ_LINE) + if (stat == EOF || xjunk <= 0.0 || xjunk > rmax) + fwhmpsf = apstatr (ap, FWHMPSF) + else + fwhmpsf = 2.0 * xjunk / scale + + # Verify the results. + call apsetr (ap, FWHMPSF, fwhmpsf) + fwhmpsf = ap_vfwhmpsf (ap) + + # Save the results. + if (out != NULL && stid > 1) + call ap_rparam (out, KY_FWHMPSF, fwhmpsf, UN_ASCALEUNIT, + "full width half maximum of the psf") + + call sfree (sp) + + return (fwhmpsf) +end + + +# AP_CDATAMIN -- Read the good data minimum off the radial profile plot. + +real procedure ap_cdatamin (ap, gd, out, stid, rmin, rmax, imin, imax) + +pointer ap # pointer to the apphot structure +pointer gd # pointer to the grapics stream +int out # output file descriptor +int stid # sequence number in output file +real rmin, rmax # x axis limits +real imin, imax # y axis limits + +int wcs, key, stat +pointer sp, cmd +real datamin, xjunk, yjunk +int clgcur() +real apstatr(), ap_vdatamin() + +begin + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + # Mark the datamin on the plot. + call printf ("Mark the good data minimum (%g) counts:") + call pargr (apstatr (ap, DATAMIN)) + if (IS_INDEFR (apstatr (ap, DATAMIN))) + call gscur (gd, (rmin + rmax) / 2.0, imin - 1.0) + else + call gscur (gd, (rmin + rmax) / 2.0, apstatr (ap, DATAMIN)) + stat = clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], SZ_LINE) + if (stat == EOF || yjunk < imin || yjunk > imax) + datamin = apstatr (ap, DATAMIN) + else + datamin = yjunk + + # Verify the results. + call apsetr (ap, DATAMIN, datamin) + datamin = ap_vdatamin (ap) + + # Store the results. + if (out != NULL && stid > 1) + call ap_rparam (out, KY_DATAMIN, datamin, UN_ACOUNTS, + "minimum good data value") + call sfree (sp) + + return (datamin) +end + + +# AP_CDATAMAX -- Read the good data maximum off the radial profile plot. + +real procedure ap_cdatamax (ap, gd, out, stid, rmin, rmax, imin, imax) + +pointer ap # pointer to the apphot structure +pointer gd # pointer to the grapics stream +int out # output file descriptor +int stid # sequence number in output file +real rmin, rmax # x axis limits +real imin, imax # y axis limits + +int wcs, key, stat +pointer sp, cmd +real datamax, xjunk, yjunk +int clgcur() +real apstatr(), ap_vdatamax() + +begin + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + # Mark the datamax on the plot. + call printf ("Mark the good data maximum (%g) counts:") + call pargr (apstatr (ap, DATAMAX)) + if (IS_INDEFR (apstatr (ap, DATAMAX))) + call gscur (gd, (rmin + rmax) / 2.0, imax + 1.0) + else + call gscur (gd, (rmin + rmax) / 2.0, apstatr (ap, DATAMAX)) + stat = clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], SZ_LINE) + if (stat == EOF || yjunk < imin || yjunk > imax) + datamax = apstatr (ap, DATAMAX) + else + datamax = yjunk + + # Verify the result. + call apsetr (ap, DATAMAX, datamax) + datamax = ap_vdatamax (ap) + + # Store the results. + if (out != NULL && stid > 1) + call ap_rparam (out, KY_DATAMAX, datamax, UN_ACOUNTS, + "maximum good data value") + call sfree (sp) + + return (datamax) +end + + +# AP_CCAPERT -- Read the centering aperture of the radial profile plot. + +real procedure ap_ccapert (ap, gd, out, stid, rmin, rmax, imin, imax) + +pointer ap # pointer to the apphot structure +pointer gd # pointer to the grapics stream +int out # output file descriptor +int stid # output file sequence number +real rmin, rmax # x axis limits +real imin, imax # y axis limits + +int wcs, key, stat +pointer sp, cmd +real scale, capert, xjunk, yjunk +int clgcur() +real apstatr(), ap_vcapert() + +begin + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + scale = apstatr (ap, SCALE) + + # Mark the centering aperture on the plot. + call printf ("Mark centering box half width (%g) pixels:") + call pargr (apstatr (ap, CAPERT) * scale) + call gscur (gd, apstatr (ap, CAPERT) * scale, (imin + imax) / 2.0) + stat = clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], SZ_LINE) + if (stat == EOF || xjunk <= 0.0 || xjunk > rmax) + capert = apstatr (ap, CAPERT) + else + capert = xjunk / scale + + # Verify the results. + call apsetr (ap, CAPERT, capert) + capert = ap_vcapert (ap) + + # Store the results. + if (out != NULL && stid > 1) + call ap_rparam (out, KY_CAPERT, 2.0 * capert, UN_CSCALEUNIT, + "centering box width") + call sfree (sp) + + return (capert) +end + + +# AP_CRCLEAN -- Read the cleaning radius off the radial profile plot. + +real procedure ap_crclean (ap, gd, out, stid, rmin, rmax, imin, imax) + +pointer ap # pointer to the apphot structure +pointer gd # pointer to the grapics stream +int out # output file descriptor +int stid # sequence number in output file +real rmin, rmax # x axis limits +real imin, imax # y axis limits + +int wcs, key, stat +pointer sp, cmd +real scale, rclean, xjunk, yjunk +int clgcur() +real apstatr(), ap_vrclean() + +begin + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + scale = apstatr (ap, SCALE) + + # Mark the cleaning radius on the plot. + call printf ( + "Mark the centering algorithm cleaning radius (%g) pixels:") + call pargr (apstatr (ap, RCLEAN) * scale) + call gscur (gd, apstatr (ap, RCLEAN) * scale, (imin + imax) / + 2.0) + stat = clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], SZ_LINE) + if (stat == EOF || xjunk <= 0.0 || xjunk > rmax) + rclean = apstatr (ap, RCLEAN) + else + rclean = xjunk / scale + + # Verify the results. + call apsetr (ap, RCLEAN, rclean) + rclean = ap_vrclean (ap) + + # Save the results. + if (out != NULL && stid > 1) + call ap_rparam (out, KY_RCLEAN, rclean, UN_CSCALEUNIT, + "cleaning radius") + call sfree (sp) + + return (rclean) +end + + +# AP_CRCLIP -- Read the clipping radius off the radial profile plot. + +real procedure ap_crclip (ap, gd, out, stid, rmin, rmax, imin, imax) + +pointer ap # pointer to the apphot structure +pointer gd # pointer to the grapics stream +int out # output file descriptor +int stid # sequence number in output file +real rmin, rmax # x axis limits +real imin, imax # y axis limits + +int wcs, key, stat +pointer sp, cmd +real scale, rclip, xjunk, yjunk +int clgcur() +real apstatr(), ap_vrclip() + +begin + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + scale = apstatr (ap, SCALE) + + # Mark clipping radius on the plot. + call printf ( + "Mark the centering algorithm clipping radius (%g) pixels:") + call pargr (apstatr (ap, RCLIP) * scale) + call gscur (gd, apstatr (ap, RCLIP) * scale, (imin + imax) / + 2.0) + stat = clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], SZ_LINE) + if (stat == EOF || xjunk <= 0.0 || xjunk > rmax) + rclip = apstatr (ap, RCLIP) + else + rclip = xjunk / scale + + # Verify the results. + call apsetr (ap, RCLIP, rclip) + rclip = ap_vrclip (ap) + + # Save the results. + if (out != NULL && stid > 1) + call ap_rparam (out, KY_RCLIP, rclip, UN_CSCALEUNIT, + "clipping radius") + call sfree (sp) + + return (rclip) +end + + +# AP_CANNULUS -- Read the sky annulus of the radial profile plot. + +real procedure ap_cannulus (ap, gd, out, stid, rmin, rmax, imin, imax) + +pointer ap # pointer to the apphot structure +pointer gd # pointer to the grapics stream +int out # output file descriptor +int stid # output file sequence number +real rmin, rmax # x axis limits +real imin, imax # y axis limits + +int wcs, key, stat +pointer sp, cmd +real scale, annulus, xjunk, yjunk +int clgcur() +real apstatr(), ap_vannulus() + +begin + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + scale = apstatr (ap, SCALE) + + # Mark the inner sky radius. + call printf ("Mark inner sky radius (%g) pixels:") + call pargr (apstatr (ap, ANNULUS) * apstatr (ap, SCALE)) + call gscur (gd, apstatr (ap, ANNULUS) * apstatr (ap, SCALE), + (imin + imax) / 2.0) + stat = clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], SZ_LINE) + if (stat == EOF || xjunk < 0.0 || xjunk > rmax) + annulus = apstatr (ap, ANNULUS) + else + annulus = xjunk / scale + + # Verify the result. + call apsetr (ap, ANNULUS, annulus) + annulus = ap_vannulus (ap) + + # Save the results. + if (out != NULL && stid > 1) + call ap_rparam (out, KY_ANNULUS, annulus, UN_SSCALEUNIT, + "radius of the inner sky annulus") + call sfree (sp) + + return (annulus) +end + + +# AP_CRGROW -- Read the region growing radius off the radial profile plot. + +real procedure ap_crgrow (ap, gd, out, stid, rmin, rmax, imin, imax) + +pointer ap # pointer to the apphot structure +pointer gd # pointer to the grapics stream +int out # the output file descriptor +int stid # output file sequence number +real rmin, rmax # x axis limits +real imin, imax # y axis limits + +int wcs, key, stat +pointer sp, cmd +real scale, rgrow, xjunk, yjunk +int clgcur() +real apstatr(), ap_vrgrow() + +begin + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + scale = apstatr (ap, SCALE) + + # Mark the inner sky radius. + call printf ("Mark region growing radius (%g) pixels:") + call pargr (apstatr (ap, RGROW) * apstatr (ap, SCALE)) + call gscur (gd, apstatr (ap, RGROW) * apstatr (ap, SCALE), + (imin + imax) / 2.0) + stat = clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], SZ_LINE) + if (stat == EOF || xjunk < 0.0 || xjunk > rmax) + rgrow = apstatr (ap, RGROW) + else + rgrow = xjunk / scale + + # Verify the region growing radius. + call apsetr (ap, RGROW, rgrow) + rgrow = ap_vrgrow (ap) + + # Save the results. + if (out != NULL && stid > 1) + call ap_rparam (out, KY_RGROW, rgrow, UN_SSCALEUNIT, + "region growing radius") + call sfree (sp) + + return (rgrow) +end + + +# AP_CDANNULUS -- Read the sky annulus width off the radial profile plot. + +real procedure ap_cdannulus (ap, gd, out, stid, annulus, rmin, rmax, imin, imax) + +pointer ap # pointer to the apphot structure +pointer gd # pointer to the grapics stream +int out # output file descriptor +int stid # output file sequence number +real rmin, rmax # x axis limits +real imin, imax # y axis limits + +int wcs, key, stat +pointer sp, cmd +real scale, annulus, dannulus, xjunk, yjunk +int clgcur() +real apstatr(), ap_vdannulus() + +begin + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + scale = apstatr (ap, SCALE) + + # Mark the outer sky radius. + call printf ("Mark outer sky radius (%g) pixels:") + call pargr (apstatr (ap, SCALE) * (apstatr (ap, ANNULUS) + + apstatr (ap, DANNULUS))) + call gscur (gd, apstatr (ap, SCALE) * (apstatr (ap, ANNULUS) + + apstatr (ap, DANNULUS)), (imin + imax) / 2.0) + stat = clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], SZ_LINE) + if (stat == EOF || (xjunk / scale < annulus) || xjunk > rmax) + dannulus = apstatr (ap, DANNULUS) + else + dannulus = (xjunk / scale - annulus) + + # Verify the width of the annulus. + call apsetr (ap, DANNULUS, dannulus) + dannulus = ap_vdannulus (ap) + + # Save the results. + if (out != NULL && stid > 1) + call ap_rparam (out, KY_DANNULUS, dannulus, UN_SSCALEUNIT, + "width of the sky annulus") + call sfree (sp) + + return (dannulus) +end + + +# AP_CSIGMA -- Read the sky sigma from the radial profile plot. + +real procedure ap_csigma (ap, gd, out, stid, rmin, rmax, imin, imax) + +pointer ap # pointer to the apphot structure +pointer gd # pointer to the grapics stream +int out # output file descriptor +int stid # sequence number in output file +real rmin, rmax # x axis limits +real imin, imax # y axis limits + +int wcs, key, stat +pointer sp, cmd +real mean, sigma3, xjunk, yjunk +int clgcur() +int apstati() +real apstatr(), ap_vsigma() + +begin + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + # Estimate the mean sky. + if (apstati (ap, POSITIVE) == YES) + mean = imin + else + mean = imax + call printf ("Estimate sky sigma. Mark mean sky level (%g):") + call pargr (mean) + call gscur (gd, (rmin + rmax) / 2.0, mean) + stat = clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], SZ_LINE) + if (stat == EOF || yjunk < imin || yjunk > imax) + mean = mean + else + mean = yjunk + + # Estimate the sky sigma. + if (IS_INDEFR (apstatr (ap, SKYSIGMA))) + sigma3 = INDEFR + else + sigma3 = 3.0 * apstatr (ap, SKYSIGMA) + call printf ("Next mark 3 sigma sky level (%g):") + call pargr (sigma3) + if (IS_INDEFR(sigma3)) + call gscur (gd, (rmin + rmax) / 2.0, imin - 1.0) + else + call gscur (gd, (rmin + rmax) / 2.0, mean + sigma3) + stat = clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], SZ_LINE) + if (stat == EOF || yjunk < imin || yjunk > imax) { + sigma3 = apstatr (ap, SKYSIGMA) + if (! IS_INDEFR (sigma3)) + sigma3 = 3.0 * sigma3 + } else + sigma3 = abs (yjunk - mean) + + # Verify the results. + if (IS_INDEFR(sigma3)) + call apsetr (ap, SKYSIGMA, INDEFR) + else + call apsetr (ap, SKYSIGMA, sigma3 / 3.0) + sigma3 = ap_vsigma (ap) + + # Save the results. + if (out != NULL && stid > 1) + call ap_rparam (out, KY_SKYSIGMA, sigma3, UN_NCOUNTS, + "standard deviation of 1 sky pixel") + + call sfree (sp) + + if (IS_INDEFR(sigma3)) + return (sigma3) + else + return (sigma3 / 3.0) +end + + +# AP_CAPER -- Read the apertures off the radial profile plot. + +procedure ap_caper (ap, gd, out, stid, outstr, rmin, rmax, imin, imax) + +pointer ap # pointer to the apphot structure +pointer gd # pointer to the grapics stream +int out # output file descriptor +int stid # output file number sequence +char outstr[ARB] # output apertures +real rmin, rmax # x axis limits +real imin, imax # y axis limits + +int i, wcs, key, naperts +pointer sp, cmd, tstr, aperts +real scale, xjunk, yjunk +int clgcur() +int apstati(), strlen() +real apstatr() + +begin + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + call salloc (tstr, SZ_LINE, TY_CHAR) + scale = apstatr (ap, SCALE) + + # Get the apertures. + naperts = apstati (ap, NAPERTS) + call salloc (aperts, naperts, TY_REAL) + call ap_arrayr (ap, APERTS, Memr[aperts]) + + # Encode the old aperture string. + outstr[1] = EOS + do i = 1, naperts - 1 { + call sprintf (outstr[1+strlen(outstr)], SZ_FNAME,"%.2f,") + call pargr (Memr[aperts+i-1] * scale) + } + call sprintf (outstr[1+strlen(outstr)], SZ_FNAME,"%.2f") + call pargr (Memr[aperts+naperts-1] * scale) + + # Type prompt string. + call printf ("Mark apertures (%s) pixels [q=quit]:") + call pargstr (outstr) + call gscur (gd, Memr[aperts] * scale, (imin + imax) / 2.0) + + # Mark the apertures. + outstr[1] = EOS + Memc[tstr] = EOS + while (clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], + SZ_LINE) != EOF) { + if (key == 'q') + break + if (xjunk <= 0.0 || xjunk > rmax) + next + call sprintf (outstr[1+strlen(outstr)], SZ_FNAME,"%.2f,") + call pargr (xjunk / scale) + call sprintf (Memc[tstr+strlen(Memc[tstr])], SZ_FNAME,"%.2f,") + call pargr (xjunk) + call printf ("Mark apertures (%s) pixels [q=quit]:") + call pargstr (Memc[tstr]) + } + outstr[strlen(outstr)] = EOS + + # Verify the results. + call apsets (ap, APERTS, outstr) + call ap_vaperts (ap, outstr, SZ_LINE) + + # Save the results. + if (out != NULL && stid > 1) + call ap_sparam (out, KY_APERTS, outstr, UN_PSCALEUNIT, + "list of aperture radii") + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/aplib/aprcursor2.x b/noao/digiphot/apphot/aplib/aprcursor2.x new file mode 100644 index 00000000..e24049b5 --- /dev/null +++ b/noao/digiphot/apphot/aplib/aprcursor2.x @@ -0,0 +1,144 @@ +include "../lib/apphot.h" +include "../lib/radprof.h" +include "../lib/fitpsf.h" + +# AP_CRPROF -- Read the radial profile size off the radial profile plot. + +real procedure ap_crprof (ap, gd, out, stid, rmin, rmax, imin, imax) + +pointer ap # pointer to the apphot structure +pointer gd # pointer to the grapics stream +int out # output file descriptor +int stid # output file sequence number +real rmin, rmax # x axis limits +real imin, imax # y axis limits + +int wcs, key, stat +pointer sp, cmd +real scale, radius, xjunk, yjunk +int clgcur() +real apstatr(), ap_vrpradius() + +begin + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + scale = apstatr (ap, SCALE) + + # Estimate the minimum (maximum) data level. + # Mark maximum radius of the radial profile. + call printf ("Mark maximum radius for profile (%g) pixels:") + call pargr (apstatr (ap, RPRADIUS) * scale) + call gscur (gd, apstatr (ap, RPRADIUS) * scale, (imin + imax) / 2.0) + stat = clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], SZ_LINE) + if (stat == EOF || xjunk < 0.0 || xjunk > rmax) + radius = apstatr (ap, RPRADIUS) + else + radius = xjunk / scale + + # Verify the results. + call apsetr (ap, RPRADIUS, radius) + radius = ap_vrpradius (ap) + + # Store the results. + if (out != NULL && stid > 1) + call ap_rparam (out, KY_RPRADIUS, radius, UN_RSCALEUNIT, + "fitting radius") + + call sfree (sp) + + return (radius) +end + + +# AP_CRPSTEP -- Read the radial profile size off the radial profile plot. + +real procedure ap_crpstep (ap, gd, out, stid, rmin, rmax, imin, imax) + +pointer ap # pointer to the apphot structure +pointer gd # pointer to the grapics stream +int out # output file descriptor +int stid # output file sequence number +real rmin, rmax # x axis limits +real imin, imax # y axis limits + +int wcs, key, stat +pointer sp, cmd +real scale, step, xjunk, yjunk +int clgcur() +real apstatr(), ap_vstep() + +begin + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + scale = apstatr (ap, SCALE) + + # Mark the radial profile step size. + call printf ("Mark step size (%g) pixels:") + call pargr (apstatr (ap, RPSTEP) * scale) + call gscur (gd, apstatr (ap, RPSTEP) * scale, (imin + imax) / 2.0) + stat = clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], SZ_LINE) + if (stat == EOF || xjunk < 0.0 || xjunk > rmax) + step = apstatr (ap, RPSTEP) + else + step = xjunk / scale + + # Verify the results. + call apsetr (ap, RPSTEP, step) + step = ap_vstep (ap) + + # Store the results. + if (out != NULL && stid > 1) + call ap_rparam (out, KY_RPSTEP, step, UN_RSCALEUNIT, + "step size in pixels") + + call sfree (sp) + + return (step) +end + + +# AP_CPAPERT -- Read the fitting radius on the radial profile plot. + +real procedure ap_cpapert (ap, gd, out, stid, rmin, rmax, imin, imax) + +pointer ap # pointer to the apphot structure +pointer gd # pointer to the grapics stream +int out # output file descriptor +int stid # output file sequence number +real rmin, rmax # x axis limits +real imin, imax # y axis limits + +int wcs, key, stat +pointer sp, cmd +real scale, psfapert, xjunk, yjunk +int clgcur() +real apstatr(), ap_vpsfapert() + +begin + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + scale = apstatr (ap, SCALE) + + # Mark the fitting radius on the plot. + call printf ("Mark fitting box half width (%g) pixels:") + call pargr (apstatr (ap, PSFAPERT) * scale) + call gscur (gd, apstatr (ap, PSFAPERT) * scale, (imin + imax) / 2.0) + stat = clgcur ("gcommands", xjunk, yjunk, wcs, key, Memc[cmd], SZ_LINE) + if (stat == EOF || xjunk <= 0.0 || xjunk > rmax) + psfapert = apstatr (ap, PSFAPERT) + else + psfapert = xjunk / scale + + # Verify the results. + call apsetr (ap, PSFAPERT, psfapert) + psfapert = ap_vpsfapert (ap) + + # Store the results. + if (out != NULL && stid > 1) + call ap_rparam (out, KY_PSFAPERT, 2.0 * psfapert, UN_PSFSCALEUNIT, + "width of the fitting box") + + call sfree (sp) + + return (psfapert) +end diff --git a/noao/digiphot/apphot/aplib/aprdnoise.x b/noao/digiphot/apphot/aplib/aprdnoise.x new file mode 100644 index 00000000..e4fbda2c --- /dev/null +++ b/noao/digiphot/apphot/aplib/aprdnoise.x @@ -0,0 +1,36 @@ +include <imhdr.h> +include "../lib/noise.h" + +# AP_RDNOISE - Procedure to set the image read noise parameter. + +procedure ap_rdnoise (im, ap) + +pointer im # pointer to IRAF image +pointer ap # pointer to apphot structure + +pointer sp, key +real rdnoise +real imgetr(), apstatr() + +begin + call smark (sp) + call salloc (key, SZ_FNAME, TY_CHAR) + call apstats (ap, CCDREAD, Memc[key], SZ_FNAME) + if (Memc[key] == EOS) + rdnoise = apstatr (ap, READNOISE) + else { + iferr { + rdnoise = imgetr (im, Memc[key]) + } then { + rdnoise = apstatr (ap, READNOISE) + call eprintf ("Warning: Image %s Keyword %s not found.\n") + call pargstr (IM_HDRFILE(im)) + call pargstr (Memc[key]) + } + } + if (IS_INDEFR(rdnoise) || rdnoise <= 0.0) + call apsetr (ap, READNOISE, 0.0) + else + call apsetr (ap, READNOISE, rdnoise) + call sfree (sp) +end diff --git a/noao/digiphot/apphot/aplib/apset.x b/noao/digiphot/apphot/aplib/apset.x new file mode 100644 index 00000000..2248f561 --- /dev/null +++ b/noao/digiphot/apphot/aplib/apset.x @@ -0,0 +1,72 @@ +define MAXERR1 500 +define MAXERR2 1000 + + +# APSETS -- Procedure to set an apphot string parameter. + +procedure apsets (ap, param, str) + +pointer ap # pointer to apphot structure +int param # parameter +char str[ARB] # string parameter + +begin + if (param <= MAXERR1) + call ap1sets (ap, param, str) + else if (param <= MAXERR2) + call ap2sets (ap, param, str) +end + + +# APSETI -- Procedure to set an integer apphot parameter. + +procedure apseti (ap, param, ival) + +pointer ap # pointer to apphot structure +int param # parameter +int ival # integer value + +begin + if (param <= MAXERR1) + call ap1seti (ap, param, ival) + else if (param <= MAXERR2) + call ap2seti (ap, param, ival) + else + call error (0, "Unknown APPHOT integer parameter") +end + + +# APSETR -- Procedure to set a real apphot parameter. + +procedure apsetr (ap, param, rval) + +pointer ap # pointer to apphot structure +int param # parameter +real rval # real value + +begin + if (param <= MAXERR1) + call ap1setr (ap, param, rval) + else if (param <= MAXERR2) + call ap2setr (ap, param, rval) + else + call error (0, "Unknown APPHOT real parameter") +end + + +# APSETD -- Procedure to set a double apphot parameter. + +procedure apsetd (ap, param, dval) + +pointer ap # pointer to apphot structure +int param # parameter +double dval # double value + +begin + if (param <= MAXERR1) + call ap1setd (ap, param, dval) + else if (param <= MAXERR2) + call ap2setd (ap, param, dval) + else + call error (0, "Unknown APPHOT double parameter") +end diff --git a/noao/digiphot/apphot/aplib/apset1.x b/noao/digiphot/apphot/aplib/apset1.x new file mode 100644 index 00000000..6c4d6f1b --- /dev/null +++ b/noao/digiphot/apphot/aplib/apset1.x @@ -0,0 +1,330 @@ +include "../lib/apphotdef.h" +include "../lib/apphot.h" +include "../lib/centerdef.h" +include "../lib/center.h" +include "../lib/fitskydef.h" +include "../lib/fitsky.h" +include "../lib/photdef.h" +include "../lib/phot.h" +include "../lib/fitpsfdef.h" +include "../lib/fitpsf.h" + +# AP1SETS -- Procedure to set an apphot string parameter. + +procedure ap1sets (ap, param, str) + +pointer ap # pointer to apphot structure +int param # parameter +char str[ARB] # string parameter + +int naperts +pointer ctr, sky, phot, psf +real aperts[MAX_NAPERTS] +int ap_getaperts() + +begin + ctr = AP_PCENTER(ap) + sky = AP_PSKY(ap) + phot = AP_PPHOT(ap) + psf = AP_PPSF(ap) + + switch (param) { + case IMNAME: + call strcpy (str, AP_IMNAME(ap), SZ_FNAME) + case IMROOT: + call strcpy (str, AP_IMROOT(ap), SZ_FNAME) + case CLNAME: + call strcpy (str, AP_CLNAME(ap), SZ_FNAME) + case CLROOT: + call strcpy (str, AP_CLROOT(ap), SZ_FNAME) + case PLOTFILE: + call strcpy (str, AP_PLOTFILE(ap), SZ_FNAME) + case OUTNAME: + call strcpy (str, AP_OUTNAME(ap), SZ_FNAME) + case EXPOSURE: + call strcpy (str, AP_EXPOSURE(ap), SZ_FNAME) + case AIRMASS: + call strcpy (str, AP_AIRMASS(ap), SZ_FNAME) + case FILTER: + call strcpy (str, AP_FILTER(ap), SZ_FNAME) + case FILTERID: + call strcpy (str, AP_FILTERID(ap), SZ_FNAME) + case OBSTIME: + call strcpy (str, AP_OBSTIME(ap), SZ_FNAME) + case OTIME: + call strcpy (str, AP_OTIME(ap), SZ_FNAME) + + case CSTRING: + call strcpy (str, AP_CSTRING(ctr), SZ_FNAME) + + case SSTRING: + call strcpy (str, AP_SSTRING(sky), SZ_FNAME) + + case APSTRING: + call strcpy (str, AP_APSTRING(phot), SZ_FNAME) + case APERTS: + naperts = ap_getaperts (str, aperts, MAX_NAPERTS) + if (naperts > 0) { + call strcpy (str, AP_APSTRING(phot), SZ_LINE) + AP_NAPERTS(phot) = naperts + call realloc (AP_APERTS(phot), AP_NAPERTS(phot), TY_REAL) + call realloc (AP_AREA(phot), AP_NAPERTS(phot), TY_DOUBLE) + call realloc (AP_SUMS(phot), AP_NAPERTS(phot), TY_DOUBLE) + call realloc (AP_MAGS(phot), AP_NAPERTS(phot), TY_REAL) + call realloc (AP_MAGERRS(phot), AP_NAPERTS(phot), TY_REAL) + call amovr (aperts, Memr[AP_APERTS(phot)], AP_NAPERTS(phot)) + call asrtr (Memr[AP_APERTS(phot)], Memr[AP_APERTS(phot)], + AP_NAPERTS(phot)) + } + case PWSTRING: + call strcpy (str, AP_PWSTRING(phot), SZ_FNAME) + + case PSFSTRING: + call strcpy (str, AP_PSFSTRING(psf), SZ_FNAME) + + default: + call error (0, "APSETS: Unknown apphot string parameter") + } +end + + +# AP1SETI -- Procedure to set an integer apphot parameter. + +procedure ap1seti (ap, param, ival) + +pointer ap # pointer to apphot structure +int param # parameter +int ival # integer value + +pointer cen, sky, phot, psf + +begin + cen = AP_PCENTER(ap) + sky = AP_PSKY(ap) + phot = AP_PPHOT(ap) + psf = AP_PPSF(ap) + + switch (param) { + case POSITIVE: + AP_POSITIVE(ap) = ival + case WCSIN: + AP_WCSIN(ap) = ival + case WCSOUT: + AP_WCSOUT(ap) = ival + case MW: + AP_MW(ap) = ival + case CTIN: + AP_CTIN(ap) = ival + case CTOUT: + AP_CTOUT(ap) = ival + + case CENTERFUNCTION: + AP_CENTERFUNCTION(cen) = ival + case CLEAN: + AP_CLEAN(cen) = ival + case CMAXITER: + AP_CMAXITER(cen) = ival + + case SKYFUNCTION: + AP_SKYFUNCTION(sky) = ival + case SMAXITER: + AP_SMAXITER(sky) = ival + case SNREJECT: + AP_SNREJECT(sky) = ival + case SMOOTH: + AP_SMOOTH(sky) = ival + case NSKY: + AP_NSKY(sky) = ival + case NSKY_REJECT: + AP_NSKY_REJECT(sky) = ival + + case PWEIGHTS: + AP_PWEIGHTS(phot) = ival + + case PSFUNCTION: + AP_PSFUNCTION(psf) = ival + case NPARS: + AP_PSFNPARS(psf) = ival + case MAXNPARS: + AP_MAXNPARS(psf) = ival + case PMAXITER: + AP_PMAXITER(psf) = ival + case PNREJECT: + AP_PNREJECT(psf) = ival + + default: + call error (0, "APSETI: Unknown apphot integer parameter") + } +end + + +# AP1SETR -- Procedure to set a real apphot parameter. + +procedure ap1setr (ap, param, rval) + +pointer ap # pointer to apphot structure +int param # parameter +real rval # real value + +pointer cen, sky, phot, psf + +begin + cen = AP_PCENTER(ap) + sky = AP_PSKY(ap) + phot = AP_PPHOT(ap) + psf = AP_PPSF(ap) + + switch (param) { + + case FWHMPSF: + AP_FWHMPSF(ap) = rval + case SCALE: + AP_SCALE(ap) = rval + case WX: + AP_WX(ap) = rval + case WY: + AP_WY(ap) = rval + case ITIME: + AP_ITIME(ap) = rval + case CWX: + AP_CWX(ap) = rval + case CWY: + AP_CWY(ap) = rval + case DATAMIN: + AP_DATAMIN(ap) = rval + case DATAMAX: + AP_DATAMAX(ap) = rval + case XAIRMASS: + AP_XAIRMASS(ap) = rval + + case CDATALIMIT: + AP_CDATALIMIT(cen) = rval + case XSHIFT: + AP_XSHIFT(cen) = rval + case YSHIFT: + AP_YSHIFT(cen) = rval + case OXSHIFT: + AP_OXSHIFT(cen) = rval + case OYSHIFT: + AP_OYSHIFT(cen) = rval + case CXCUR: + AP_CXCUR(cen) = rval + case CYCUR: + AP_CYCUR(cen) = rval + case CAPERT: + AP_CAPERT(cen) = rval + case CTHRESHOLD: + AP_CTHRESHOLD(cen) = rval + case MAXSHIFT: + AP_MAXSHIFT(cen) = rval + case MINSNRATIO: + AP_MINSNRATIO(cen) = rval + case RCLEAN: + AP_RCLEAN(cen) = rval + case RCLIP: + AP_RCLIP(cen) = rval + case SIGMACLEAN: + AP_SIGMACLEAN(cen) = rval + case OXINIT: + AP_OXINIT(cen) = rval + case OYINIT: + AP_OYINIT(cen) = rval + case XCENTER: + AP_XCENTER(cen) = rval + case YCENTER: + AP_YCENTER(cen) = rval + case OXCENTER: + AP_OXCENTER(cen) = rval + case OYCENTER: + AP_OYCENTER(cen) = rval + case XERR: + AP_XERR(cen) = rval + case YERR: + AP_YERR(cen) = rval + + case ANNULUS: + AP_ANNULUS(sky) = rval + case DANNULUS: + AP_DANNULUS(sky) = rval + case SXCUR: + AP_SXCUR(sky) = rval + case SYCUR: + AP_SYCUR(sky) = rval + case OSXCUR: + AP_OSXCUR(sky) = rval + case OSYCUR: + AP_OSYCUR(sky) = rval + case K1: + AP_K1(sky) = rval + case SLOREJECT: + AP_SLOREJECT(sky) = rval + case SHIREJECT: + AP_SHIREJECT(sky) = rval + case SLOCLIP: + AP_SLOCLIP(sky) = rval + case SHICLIP: + AP_SHICLIP(sky) = rval + case BINSIZE: + AP_BINSIZE(sky) = rval + case RGROW: + AP_RGROW(sky) = rval + case SKY_BACKGROUND: + AP_SKYBACKGROUND(sky) = rval + case SKY_MODE: + AP_SKY_MODE(sky) = rval + case SKY_SIGMA: + AP_SKY_SIG(sky) = rval + case SKY_SKEW: + AP_SKY_SKEW(sky) = rval + + case PXCUR: + AP_PXCUR(phot) = rval + case PYCUR: + AP_PYCUR(phot) = rval + case OPXCUR: + AP_OPXCUR(phot) = rval + case OPYCUR: + AP_OPYCUR(phot) = rval + case ZMAG: + AP_ZMAG(phot) = rval + + case PK2: + AP_PK2(psf) = rval + case PSFAPERT: + AP_PSFAPERT(psf) = rval + case PFXCUR: + AP_PFXCUR(psf) = rval + case PFYCUR: + AP_PFYCUR(psf) = rval + case OPFXCUR: + AP_OPFXCUR(psf) = rval + case OPFYCUR: + AP_OPFYCUR(psf) = rval + + default: + call error (0, "APSETR: Unknown apphot real parameter") + } +end + + +# AP1SETD -- Procedure to set a double apphot parameter. + +procedure ap1setd (ap, param, dval) + +pointer ap # pointer to apphot structure +int param # parameter +double dval # double value + +pointer cen, sky, phot, psf + +begin + cen = AP_PCENTER(ap) + sky = AP_PSKY(ap) + phot = AP_PPHOT(ap) + psf = AP_PPSF(ap) + + switch (param) { + default: + call error (0, "APSETD: Unknown apphot double parameter") + } +end diff --git a/noao/digiphot/apphot/aplib/apset2.x b/noao/digiphot/apphot/aplib/apset2.x new file mode 100644 index 00000000..85200daf --- /dev/null +++ b/noao/digiphot/apphot/aplib/apset2.x @@ -0,0 +1,227 @@ +include "../lib/apphotdef.h" +include "../lib/apphot.h" +include "../lib/displaydef.h" +include "../lib/display.h" +include "../lib/noisedef.h" +include "../lib/noise.h" +include "../lib/polyphotdef.h" +include "../lib/polyphot.h" +include "../lib/radprofdef.h" +include "../lib/radprof.h" +include "../lib/finddef.h" +include "../lib/find.h" + +# AP2SETS -- Procedure to set an apphot string parameter. + +procedure ap2sets (ap, param, str) + +pointer ap # pointer to apphot structure +int param # parameter +char str[ARB] # string parameter + +pointer nse, ply + +begin + nse = AP_NOISE(ap) + ply = AP_POLY(ap) + + switch (param) { + case PYNAME: + call strcpy (str, AP_PYNAME(ply), SZ_FNAME) + case PYROOT: + call strcpy (str, AP_PYROOT(ply), SZ_FNAME) + case GAIN: + call strcpy (str, AP_GAIN(nse), SZ_FNAME) + case NSTRING: + call strcpy (str, AP_NSTRING(nse), SZ_FNAME) + case CCDREAD: + call strcpy (str, AP_CCDREAD(nse), SZ_FNAME) + default: + call error (0, "APSETS: Unknown apphot string parameter") + } +end + + +# AP2SETI -- Procedure to set an integer apphot parameter. + +procedure ap2seti (ap, param, ival) + +pointer ap # pointer to apphot structure +int param # parameter +int ival # integer value + +pointer dsp, nse, ply, rprof + +begin + nse = AP_NOISE(ap) + dsp = AP_PDISPLAY(ap) + ply = AP_POLY(ap) + rprof = AP_RPROF(ap) + + switch (param) { + case RPORDER: + AP_RPORDER(rprof) = ival + case RPNREJECT: + AP_RPNREJECT(rprof) = ival + case PYNVER: + AP_PYNVER(ply) = ival + case PYBADPIX: + AP_PYBADPIX(ply) = ival + case MKSKY: + AP_MKSKY(dsp) = ival + case MKCENTER: + AP_MKCENTER(dsp) = ival + case MKAPERT: + AP_MKAPERT(dsp) = ival + case MKPOLYGON: + AP_MKPOLYGON(dsp) = ival + case MKDETECTIONS: + AP_MKDETECTIONS(dsp) = ival + case NOISEFUNCTION: + AP_NOISEFUNCTION(nse) = ival + case MKPSFBOX: + AP_MKPSFBOX(dsp) = ival + case RADPLOTS: + AP_RADPLOTS(dsp) = ival + case RPNPTS: + AP_RPNPTS(rprof) = ival + case RPNDATA: + AP_RPNDATA(rprof) = ival + case RPNDATAREJ: + AP_RPNDATAREJ(rprof) = ival + default: + call error (0, "APSETI: Unknown apphot integer parameter") + } +end + + +# AP2SETR -- Procedure to set a real apphot parameter. + +procedure ap2setr (ap, param, rval) + +pointer ap # pointer to apphot structure +int param # parameter +real rval # real value + +pointer nse, ply, rprof, fnd + +begin + nse = AP_NOISE(ap) + ply = AP_POLY(ap) + rprof = AP_RPROF(ap) + fnd = AP_PFIND(ap) + + switch (param) { + case RPFWHM: + AP_RPFWHM(rprof) = rval + case INORM: + AP_INORM(rprof) = rval + case TNORM: + AP_TINORM(rprof) = rval + case DNORM: + AP_DNORM(rprof) = rval + case RPXCUR: + AP_RPXCUR(rprof) = rval + case RPYCUR: + AP_RPYCUR(rprof) = rval + case ORPXCUR: + AP_ORPXCUR(rprof) = rval + case ORPYCUR: + AP_ORPYCUR(rprof) = rval + case RPRADIUS: + AP_RPRADIUS(rprof) = rval + AP_RPNPTS(rprof) = int (AP_RPRADIUS(rprof) / AP_RPSTEP(rprof)) + 1 + call realloc (AP_RPDIST(rprof), AP_RPNPTS(rprof), TY_REAL) + call realloc (AP_INTENSITY(rprof), AP_RPNPTS(rprof), TY_REAL) + call realloc (AP_DINTENSITY(rprof), AP_RPNPTS(rprof), TY_REAL) + call realloc (AP_TINTENSITY(rprof), AP_RPNPTS(rprof), TY_REAL) + case RPSTEP: + AP_RPSTEP(rprof) = rval + AP_RPNPTS(rprof) = int (AP_RPRADIUS(rprof) / AP_RPSTEP(rprof)) + 1 + call realloc (AP_RPDIST(rprof), AP_RPNPTS(rprof), TY_REAL) + call realloc (AP_INTENSITY(rprof), AP_RPNPTS(rprof), TY_REAL) + call realloc (AP_DINTENSITY(rprof), AP_RPNPTS(rprof), TY_REAL) + call realloc (AP_TINTENSITY(rprof), AP_RPNPTS(rprof), TY_REAL) + case RPKSIGMA: + AP_RPKSIGMA(rprof) = rval + case PYZMAG: + AP_PYZMAG(ply) = rval + case PYMAG: + AP_PYMAG(ply) = rval + case PYMAGERR: + AP_PYMAGERR(ply) = rval + case PYX: + AP_PYX(ply) = rval + case PYY: + AP_PYY(ply) = rval + case PYMINRAD: + AP_PYMINRAD(ply) = rval + case PYCX: + AP_PYCX(ply) = rval + case PYCY: + AP_PYCY(ply) = rval + case OPYCX: + AP_OPYCX(ply) = rval + case OPYCY: + AP_OPYCY(ply) = rval + case PYXMEAN: + AP_PYXMEAN(ply) = rval + case PYYMEAN: + AP_PYYMEAN(ply) = rval + case OPYXMEAN: + AP_OPYXMEAN(ply) = rval + case OPYYMEAN: + AP_OPYYMEAN(ply) = rval + case SKYSIGMA: + AP_SKYSIGMA(nse) = rval + case EPADU: + AP_EPADU(nse) = rval + case READNOISE: + AP_READNOISE(nse) = rval + case THRESHOLD: + AP_THRESHOLD(fnd) = rval + case RATIO: + AP_RATIO(fnd) = rval + case THETA: + AP_THETA(fnd) = rval + case NSIGMA: + AP_NSIGMA(fnd) = rval + case SHARPLO: + AP_SHARPLO(fnd) = rval + case SHARPHI: + AP_SHARPHI(fnd) = rval + case ROUNDLO: + AP_ROUNDLO(fnd) = rval + case ROUNDHI: + AP_ROUNDHI(fnd) = rval + default: + call error (0, "APSETR: Unknown apphot real parameter") + } +end + + +# AP2SETD -- Procedure to set a double apphot parameter. + +procedure ap2setd (ap, param, dval) + +pointer ap # pointer to apphot structure +int param # parameter +double dval # double value + +pointer nse, ply, rprof, fnd + +begin + nse = AP_NOISE(ap) + ply = AP_POLY(ap) + rprof = AP_RPROF(ap) + fnd = AP_PFIND(ap) + + switch (param) { + case PYNPIX: + AP_PYNPIX(ply) = dval + case PYFLUX: + AP_PYFLUX(ply) = dval + default: + call error (0, "APSETD: Unknown apphot double parameter") + } +end diff --git a/noao/digiphot/apphot/aplib/apshowplot.x b/noao/digiphot/apphot/aplib/apshowplot.x new file mode 100644 index 00000000..ed188d52 --- /dev/null +++ b/noao/digiphot/apphot/aplib/apshowplot.x @@ -0,0 +1,83 @@ +include "../lib/apphot.h" + +define RADIUS 15.0 +define CRADIUS 5 + +# AP_SHOWPLOT -- Plot a radial profile of a star. + +int procedure ap_showplot (ap, im, wx, wy, gd, xcenter, ycenter, rmin, + rmax, imin, imax) + +pointer ap # pointer to the apphot structure +pointer im # pointer to the image +real wx, wy # the cursor coordinates +pointer gd # pointer to the graphics stream +real xcenter, ycenter # the centered coordinates +real rmin, rmax # minimum and maximum radius +real imin, imax # minimum and maximum intensity + +real radius, xc, yc, xold, yold +pointer sp, r, skypix, coords, index, str, gt +int niter, lenbuf, nx, ny, nsky + +real apstatr() +pointer ap_gtinit() +int ap_gvrad(), apstati(), ap_skypix() + +begin + call gclear (gd) + call gflush (gd) + + # Set the pixel extraction parameters. + lenbuf = ap_gvrad (RADIUS, radius) + + # Initialize. + call smark (sp) + call salloc (r, lenbuf, TY_REAL) + call salloc (skypix, lenbuf, TY_REAL) + call salloc (coords, lenbuf, TY_INT) + call salloc (index, lenbuf, TY_INT) + call salloc (str, SZ_LINE, TY_CHAR) + + # Center the star. + niter = 0 + xold = wx + yold = wy + repeat { + call ap_ictr (im, xold, yold, CRADIUS, apstati (ap, POSITIVE), + xcenter, ycenter) + niter = niter + 1 + if (abs (xcenter - xold) <= 1.0 && abs (ycenter - yold) <= 1.0) + break + xold = xcenter + yold = ycenter + } until (niter >= 3) + + # Fetch the pixels. + nsky = ap_skypix (im, xcenter, ycenter, 0.0, radius, Memr[skypix], + Memi[coords], xc, yc, nx, ny) + if (nsky <= 0) { + call sfree (sp) + return (ERR) + } + call ap_index (Memi[index], nsky) + + # Compute the radius and intensity values. + call ap_xytor (Memi[coords], Memi[index], Memr[r], nsky, xc, yc, nx) + call alimr (Memr[r], nsky, rmin, rmax) + call alimr (Memr[skypix], nsky, imin, imax) + + # Plot the radial profiles. + #call apstats (ap, IMNAME, Memc[str], SZ_FNAME) + call apstats (ap, IMROOT, Memc[str], SZ_FNAME) + call ap_ltov (im, xcenter, ycenter, xc, yc, 1) + gt = ap_gtinit (Memc[str], xc, yc) + call ap_rset (gd, gt, 0.0, rmax, imin, imax, apstatr (ap, SCALE)) + call ap_plotrad (gd, gt, Memr[r], Memr[skypix], nsky, "plus") + + # Cleanup. + call ap_gtfree (gt) + call sfree (sp) + + return (OK) +end diff --git a/noao/digiphot/apphot/aplib/apstat.x b/noao/digiphot/apphot/aplib/apstat.x new file mode 100644 index 00000000..9ddc98ca --- /dev/null +++ b/noao/digiphot/apphot/aplib/apstat.x @@ -0,0 +1,77 @@ +define MAXERR1 500 +define MAXERR2 1000 + +# APSTATS -- Procedure to fetch an apphot string parameter. + +procedure apstats (ap, param, str, maxch) + +pointer ap # pointer to apphot structure +int param # parameter +char str[ARB] # string +int maxch # maximum number of characters + +begin + if (param <= MAXERR1) + call ap1stats (ap, param, str, maxch) + else if (param <= MAXERR2) + call ap2stats (ap, param, str, maxch) + else + call error (0, "APSTATS: Unknown apphot string parameter") +end + + +# APSTATI -- Procedure to set an integer apphot parameter. + +int procedure apstati (ap, param) + +pointer ap # pointer to apphot structure +int param # parameter + +int ap1stati(), ap2stati() + +begin + if (param <= MAXERR1) + return (ap1stati (ap, param)) + else if (param <= MAXERR2) + return (ap2stati (ap, param)) + else + call error (0, "APSTATI: Unknown apphot integer parameter") +end + + +# APSTATR -- Procedure to set a real apphot parameter. + +real procedure apstatr (ap, param) + +pointer ap # pointer to apphot structure +int param # parameter + +real ap1statr(), ap2statr() + +begin + if (param <= MAXERR1) + return (ap1statr (ap, param)) + else if (param <= MAXERR2) + return (ap2statr (ap, param)) + else + call error (0, "APSTATR: Unknown apphot real parameter") +end + + +# APSTATD -- Procedure to set a double apphot parameter. + +double procedure apstatd (ap, param) + +pointer ap # pointer to apphot structure +int param # parameter + +double ap1statd(), ap2statd() + +begin + if (param <= MAXERR1) + return (ap1statd (ap, param)) + else if (param <= MAXERR2) + return (ap2statd (ap, param)) + else + call error (0, "APSTATD: Unknown apphot double parameter") +end diff --git a/noao/digiphot/apphot/aplib/apstat1.x b/noao/digiphot/apphot/aplib/apstat1.x new file mode 100644 index 00000000..0df220ae --- /dev/null +++ b/noao/digiphot/apphot/aplib/apstat1.x @@ -0,0 +1,316 @@ +include "../lib/apphotdef.h" +include "../lib/apphot.h" +include "../lib/centerdef.h" +include "../lib/center.h" +include "../lib/fitskydef.h" +include "../lib/fitsky.h" +include "../lib/photdef.h" +include "../lib/phot.h" +include "../lib/fitpsfdef.h" +include "../lib/fitpsf.h" + +# AP1STATS -- Procedure to fetch an apphot string parameter. + +procedure ap1stats (ap, param, str, maxch) + +pointer ap # pointer to apphot structure +int param # parameter +char str[ARB] # string +int maxch # maximum number of characters + +pointer cen, sky, phot, psf + +begin + cen = AP_PCENTER(ap) + sky = AP_PSKY(ap) + phot = AP_PPHOT(ap) + psf = AP_PPSF(ap) + + switch (param) { + case IMNAME: + call strcpy (AP_IMNAME(ap), str, maxch) + case IMROOT: + call strcpy (AP_IMROOT(ap), str, maxch) + case CLNAME: + call strcpy (AP_CLNAME(ap), str, maxch) + case CLROOT: + call strcpy (AP_CLROOT(ap), str, maxch) + case PLOTFILE: + call strcpy (AP_PLOTFILE(ap), str, maxch) + case OUTNAME: + call strcpy (AP_OUTNAME(ap), str, maxch) + case EXPOSURE: + call strcpy (AP_EXPOSURE(ap), str, maxch) + case AIRMASS: + call strcpy (AP_AIRMASS(ap), str, maxch) + case FILTER: + call strcpy (AP_FILTER(ap), str, maxch) + case FILTERID: + call strcpy (AP_FILTERID(ap), str, maxch) + case OBSTIME: + call strcpy (AP_OBSTIME(ap), str, maxch) + case OTIME: + call strcpy (AP_OTIME(ap), str, maxch) + + case CSTRING: + call strcpy (AP_CSTRING(cen), str, maxch) + + case SSTRING: + call strcpy (AP_SSTRING(sky), str, maxch) + + case APSTRING: + call strcpy (AP_APSTRING(phot), str, maxch) + case APERTS: + call strcpy (AP_APSTRING(phot), str, maxch) + case PWSTRING: + call strcpy (AP_PWSTRING(phot), str, maxch) + + case PSFSTRING: + call strcpy (AP_PSFSTRING(psf), str, maxch) + + default: + call error (0, "APSTATS: Unknown apphot string parameter") + } +end + + +# AP1STATI -- Procedure to set an integer apphot parameter. + +int procedure ap1stati (ap, param) + +pointer ap # pointer to apphot structure +int param # parameter + +pointer cen, sky, phot, psf + +begin + cen = AP_PCENTER(ap) + sky = AP_PSKY(ap) + phot = AP_PPHOT(ap) + psf = AP_PPSF(ap) + + switch (param) { + case POSITIVE: + return (AP_POSITIVE(ap)) + case WCSIN: + return (AP_WCSIN(ap)) + case WCSOUT: + return (AP_WCSOUT(ap)) + case MW: + return (AP_MW(ap)) + case CTIN: + return (AP_CTIN(ap)) + case CTOUT: + return (AP_CTOUT(ap)) + + case CENTERFUNCTION: + return (AP_CENTERFUNCTION(cen)) + case CLEAN: + return (AP_CLEAN(cen)) + case CMAXITER: + return (AP_CMAXITER(cen)) + + case SKYFUNCTION: + return (AP_SKYFUNCTION(sky)) + case SMAXITER: + return (AP_SMAXITER(sky)) + case SNREJECT: + return (AP_SNREJECT(sky)) + case SMOOTH: + return (AP_SMOOTH(sky)) + case NSKY: + return (AP_NSKY(sky)) + case NSKY_REJECT: + return (AP_NSKY_REJECT(sky)) + + case NAPERTS: + return (AP_NAPERTS(phot)) + case PWEIGHTS: + return (AP_PWEIGHTS(phot)) + + case MAXNPARS: + return (AP_MAXNPARS(psf)) + case NPARS: + return (AP_PSFNPARS(psf)) + case PMAXITER: + return (AP_PMAXITER(psf)) + case PSFUNCTION: + return (AP_PSFUNCTION(psf)) + case PNREJECT: + return (AP_PNREJECT(psf)) + + default: + call error (0, "APSTATI: Unknown apphot integer parameter") + } +end + + +# AP1STATR -- Procedure to set a real apphot parameter. + +real procedure ap1statr (ap, param) + +pointer ap # pointer to apphot structure +int param # parameter + +pointer cen, sky, phot, psf + +begin + cen = AP_PCENTER(ap) + sky = AP_PSKY(ap) + phot = AP_PPHOT(ap) + psf = AP_PPSF(ap) + + switch (param) { + + case FWHMPSF: + return (AP_FWHMPSF(ap)) + case SCALE: + return (AP_SCALE(ap)) + case WX: + return (AP_WX(ap)) + case WY: + return (AP_WY(ap)) + case ITIME: + return (AP_ITIME(ap)) + case CWX: + return (AP_CWX(ap)) + case CWY: + return (AP_CWY(ap)) + case DATAMIN: + return (AP_DATAMIN(ap)) + case DATAMAX: + return (AP_DATAMAX(ap)) + case XAIRMASS: + return (AP_XAIRMASS(ap)) + + case CDATALIMIT: + return (AP_CDATALIMIT(cen)) + case XSHIFT: + return (AP_XSHIFT(cen)) + case YSHIFT: + return (AP_YSHIFT(cen)) + case OXSHIFT: + return (AP_OXSHIFT(cen)) + case OYSHIFT: + return (AP_OYSHIFT(cen)) + case CXCUR: + return (AP_CXCUR(cen)) + case CYCUR: + return (AP_CYCUR(cen)) + case CAPERT: + return (AP_CAPERT(cen)) + case CTHRESHOLD: + return (AP_CTHRESHOLD(cen)) + case MAXSHIFT: + return (AP_MAXSHIFT(cen)) + case MINSNRATIO: + return (AP_MINSNRATIO(cen)) + case RCLEAN: + return (AP_RCLEAN(cen)) + case RCLIP: + return (AP_RCLIP(cen)) + case SIGMACLEAN: + return (AP_SIGMACLEAN(cen)) + + case OXINIT: + return (AP_OXINIT(cen)) + case OYINIT: + return (AP_OYINIT(cen)) + case XCENTER: + return (AP_XCENTER(cen)) + case YCENTER: + return (AP_YCENTER(cen)) + case OXCENTER: + return (AP_OXCENTER(cen)) + case OYCENTER: + return (AP_OYCENTER(cen)) + case XERR: + return (AP_XERR(cen)) + case YERR: + return (AP_YERR(cen)) + + case SXCUR: + return (AP_SXCUR(sky)) + case SYCUR: + return (AP_SYCUR(sky)) + case OSXCUR: + return (AP_OSXCUR(sky)) + case OSYCUR: + return (AP_OSYCUR(sky)) + case ANNULUS: + return (AP_ANNULUS(sky)) + case DANNULUS: + return (AP_DANNULUS(sky)) + case K1: + return (AP_K1(sky)) + case SLOREJECT: + return (AP_SLOREJECT(sky)) + case SHIREJECT: + return (AP_SHIREJECT(sky)) + case SLOCLIP: + return (AP_SLOCLIP(sky)) + case SHICLIP: + return (AP_SHICLIP(sky)) + case BINSIZE: + return (AP_BINSIZE(sky)) + case RGROW: + return (AP_RGROW(sky)) + case SKY_BACKGROUND: + return (AP_SKYBACKGROUND(sky)) + case SKY_MODE: + return (AP_SKY_MODE(sky)) + case SKY_SIGMA: + return (AP_SKY_SIG(sky)) + case SKY_SKEW: + return (AP_SKY_SKEW(sky)) + + case PXCUR: + return (AP_PXCUR(phot)) + case PYCUR: + return (AP_PYCUR(phot)) + case OPXCUR: + return (AP_OPXCUR(phot)) + case OPYCUR: + return (AP_OPYCUR(phot)) + case ZMAG: + return (AP_ZMAG(phot)) + + case PSFAPERT: + return (AP_PSFAPERT(psf)) + case PK2: + return (AP_PK2(psf)) + case PFXCUR: + return (AP_PFXCUR(psf)) + case PFYCUR: + return (AP_PFYCUR(psf)) + case OPFXCUR: + return (AP_OPFXCUR(psf)) + case OPFYCUR: + return (AP_OPFYCUR(psf)) + + default: + call error (0, "APSTATR: Unknown apphot real parameter") + } +end + + +# AP1STATD -- Procedure to set a double apphot parameter. + +double procedure ap1statd (ap, param) + +pointer ap # pointer to apphot structure +int param # parameter + +pointer cen, sky, phot, psf + +begin + cen = AP_PCENTER(ap) + sky = AP_PSKY(ap) + phot = AP_PPHOT(ap) + psf = AP_PPSF(ap) + + switch (param) { + default: + call error (0, "APSTATD: Unknown apphot double parameter") + } +end diff --git a/noao/digiphot/apphot/aplib/apstat2.x b/noao/digiphot/apphot/aplib/apstat2.x new file mode 100644 index 00000000..032b19e5 --- /dev/null +++ b/noao/digiphot/apphot/aplib/apstat2.x @@ -0,0 +1,215 @@ +include "../lib/apphotdef.h" +include "../lib/apphot.h" +include "../lib/displaydef.h" +include "../lib/display.h" +include "../lib/noisedef.h" +include "../lib/noise.h" +include "../lib/polyphotdef.h" +include "../lib/polyphot.h" +include "../lib/radprofdef.h" +include "../lib/radprof.h" +include "../lib/finddef.h" +include "../lib/find.h" + +# AP2STATS -- Procedure to fetch an apphot string parameter. + +procedure ap2stats (ap, param, str, maxch) + +pointer ap # pointer to apphot structure +int param # parameter +char str[ARB] # string +int maxch # maximum number of characters + +pointer nse, ply + +begin + nse = AP_NOISE(ap) + ply = AP_POLY(ap) + + switch (param) { + case PYNAME: + call strcpy (AP_PYNAME(ply), str, maxch) + case PYROOT: + call strcpy (AP_PYROOT(ply), str, maxch) + case GAIN: + call strcpy (AP_GAIN(nse), str, maxch) + case NSTRING: + call strcpy (AP_NSTRING(nse), str, maxch) + case CCDREAD: + call strcpy (AP_CCDREAD(nse), str, maxch) + default: + call error (0, "APSTATS: Unknown apphot string parameter") + } +end + + +# AP2STATI -- Procedure to set an integer apphot parameter. + +int procedure ap2stati (ap, param) + +pointer ap # pointer to apphot structure +int param # parameter + +pointer dsp, nse, ply, rprof + +begin + dsp = AP_PDISPLAY(ap) + nse = AP_NOISE(ap) + ply = AP_POLY(ap) + rprof = AP_RPROF(ap) + + switch (param) { + case RPORDER: + return (AP_RPORDER(rprof)) + case RPNREJECT: + return (AP_RPNREJECT(rprof)) + case PYNVER: + return (AP_PYNVER(ply)) + case PYBADPIX: + return (AP_PYBADPIX(ply)) + case MKSKY: + return (AP_MKSKY(dsp)) + case MKCENTER: + return (AP_MKCENTER(dsp)) + case MKAPERT: + return (AP_MKAPERT(dsp)) + case MKPOLYGON: + return (AP_MKPOLYGON(dsp)) + case MKDETECTIONS: + return (AP_MKDETECTIONS(dsp)) + case NOISEFUNCTION: + return (AP_NOISEFUNCTION(nse)) + case MKPSFBOX: + return (AP_MKPSFBOX(dsp)) + case RADPLOTS: + return (AP_RADPLOTS(dsp)) + case RPNPTS: + return (AP_RPNPTS(rprof)) + case RPNDATA: + return (AP_RPNDATA(rprof)) + case RPNDATAREJ: + return (AP_RPNDATAREJ(rprof)) + default: + call error (0, "APSTATI: Unknown apphot integer parameter") + } +end + + +# AP2STATR -- Procedure to set a real apphot parameter. + +real procedure ap2statr (ap, param) + +pointer ap # pointer to apphot structure +int param # parameter + +pointer nse, ply, rprof, fnd + +begin + nse = AP_NOISE(ap) + ply = AP_POLY(ap) + rprof = AP_RPROF(ap) + fnd = AP_PFIND(ap) + + switch (param) { + case RPFWHM: + return (AP_RPFWHM(rprof)) + case INORM: + return (AP_INORM(rprof)) + case TNORM: + return (AP_TINORM(rprof)) + case DNORM: + return (AP_DNORM(rprof)) + case RPXCUR: + return (AP_RPXCUR(rprof)) + case RPYCUR: + return (AP_RPYCUR(rprof)) + case ORPXCUR: + return (AP_ORPXCUR(rprof)) + case ORPYCUR: + return (AP_ORPYCUR(rprof)) + case RPRADIUS: + return (AP_RPRADIUS(rprof)) + case RPSTEP: + return (AP_RPSTEP(rprof)) + case RPKSIGMA: + return (AP_RPKSIGMA(rprof)) + case PYZMAG: + return (AP_PYZMAG(ply)) + case PYMAG: + return (AP_PYMAG(ply)) + case PYMAGERR: + return (AP_PYMAGERR(ply)) + case PYX: + return (AP_PYX(ply)) + case PYY: + return (AP_PYY(ply)) + case PYMINRAD: + return (AP_PYMINRAD(ply)) + case PYXMEAN: + return (AP_PYXMEAN(ply)) + case PYYMEAN: + return (AP_PYYMEAN(ply)) + case OPYXMEAN: + return (AP_OPYXMEAN(ply)) + case OPYYMEAN: + return (AP_OPYYMEAN(ply)) + case PYCX: + return (AP_PYCX(ply)) + case PYCY: + return (AP_PYCY(ply)) + case OPYCX: + return (AP_OPYCX(ply)) + case OPYCY: + return (AP_OPYCY(ply)) + case SKYSIGMA: + return (AP_SKYSIGMA(nse)) + case EPADU: + return (AP_EPADU(nse)) + case READNOISE: + return (AP_READNOISE(nse)) + case THRESHOLD: + return (AP_THRESHOLD(fnd)) + case RATIO: + return (AP_RATIO(fnd)) + case THETA: + return (AP_THETA(fnd)) + case NSIGMA: + return (AP_NSIGMA(fnd)) + case SHARPLO: + return (AP_SHARPLO(fnd)) + case SHARPHI: + return (AP_SHARPHI(fnd)) + case ROUNDLO: + return (AP_ROUNDLO(fnd)) + case ROUNDHI: + return (AP_ROUNDHI(fnd)) + default: + call error (0, "APSTATR: Unknown apphot real parameter") + } +end + + +# AP2STATD -- Procedure to set a double apphot parameter. + +double procedure ap2statd (ap, param) + +pointer ap # pointer to apphot structure +int param # parameter + +pointer nse, ply, rprof, fnd + +begin + nse = AP_NOISE(ap) + ply = AP_POLY(ap) + rprof = AP_RPROF(ap) + fnd = AP_PFIND(ap) + + switch (param) { + case PYNPIX: + return (AP_PYNPIX(ply)) + case PYFLUX: + return (AP_PYFLUX(ply)) + default: + call error (0, "APSTATD: Unknown apphot double parameter") + } +end diff --git a/noao/digiphot/apphot/aplib/apverify1.x b/noao/digiphot/apphot/aplib/apverify1.x new file mode 100644 index 00000000..1ecd04b6 --- /dev/null +++ b/noao/digiphot/apphot/aplib/apverify1.x @@ -0,0 +1,582 @@ +include <math.h> +include "../lib/apphot.h" +include "../lib/noise.h" +include "../lib/center.h" +include "../lib/fitsky.h" +include "../lib/phot.h" + +# AP_GVRAD -- Verify or get the radius of the extraction box. + +int procedure ap_gvrad (defradius, radius) + +real defradius # the default radius +real radius # the output radius + +int lenbuf +int scan(), nscan() + +begin + call printf ( + "Radius of extraction box in pixels (%4.1f) (CR or value): ") + call pargr (defradius) + call flush (STDOUT) + + if (scan () == EOF) + radius = defradius + else { + call gargr (radius) + if (nscan () < 1) + radius = defradius + } + lenbuf = PI * radius * (radius + 1.0) + + return (lenbuf) +end + + +# AP_VFWHMPSF -- Verify the full width maximum of the psf. + +real procedure ap_vfwhmpsf (ap) + +pointer ap # pointer to the apphot structure + +real scale, fwhmpsf +int scan(), nscan() +real apstatr() + +begin + scale = apstatr (ap, SCALE) + call printf ("FWHM of features in scale units (%g) (CR or value): ") + call pargr (apstatr (ap, FWHMPSF)) + call flush (STDOUT) + + # Confirm the fwhmpsf. + if (scan() == EOF) + fwhmpsf = apstatr (ap, FWHMPSF) + else { + call gargr (fwhmpsf) + if (nscan () != 1) + fwhmpsf = apstatr (ap, FWHMPSF) + } + + call printf ("\tNew FWHM of features: %g scale units %g pixels\n") + call pargr (fwhmpsf) + call pargr (scale * fwhmpsf) + call apsetr (ap, FWHMPSF, fwhmpsf) + + return (fwhmpsf) +end + + +# AP_VDATAMIN-- Verify the minimum good data value. + +real procedure ap_vdatamin (ap) + +pointer ap # pointer to the apphot structure + +real datamin +int scan(), nscan() +real apstatr() + +begin + # Confirm the threshold parameter. + call printf ("Minimum good data value (%g) (CR or value): ") + call pargr (apstatr (ap, DATAMIN)) + call flush (STDOUT) + if (scan() == EOF) + datamin = apstatr (ap, DATAMIN) + else { + call gargr (datamin) + if (nscan () != 1) + datamin = apstatr (ap, DATAMIN) + } + + call printf ("\tNew minimum good data value: %g counts\n") + call pargr (datamin) + call apsetr (ap, DATAMIN, datamin) + + return (datamin) +end + + +# AP_VDATAMAX-- Verify the maximum good data value. + +real procedure ap_vdatamax (ap) + +pointer ap # pointer to the apphot structure + +real datamax +int scan(), nscan() +real apstatr() + +begin + # Confirm the threshold parameter. + call printf ("Maximum good data value (%g) (CR or value): ") + call pargr (apstatr (ap, DATAMAX)) + call flush (STDOUT) + if (scan() == EOF) + datamax = apstatr (ap, DATAMAX) + else { + call gargr (datamax) + if (nscan () != 1) + datamax = apstatr (ap, DATAMAX) + } + + call printf ("\tNew maximum good data value: %g counts\n") + call pargr (datamax) + call apsetr (ap, DATAMAX, datamax) + + return (datamax) +end + + +# AP_VSIGMA -- Verify the standard deviation of the sky + +real procedure ap_vsigma (ap) + +pointer ap # pointer to the apphot structure + +real skysigma +int scan(), nscan() +real apstatr() + +begin + # Confirm the sky sigma parameter. + call printf ( + "Standard deviation of background in counts (%g) (CR or value): ") + call pargr (apstatr (ap, SKYSIGMA)) + call flush (STDOUT) + if (scan() == EOF) + skysigma = apstatr (ap, SKYSIGMA) + else { + call gargr (skysigma) + if (nscan () != 1) + skysigma = apstatr (ap, SKYSIGMA) + } + + call printf ("\tNew standard deviation of background: %g counts\n") + call pargr (skysigma) + call apsetr (ap, SKYSIGMA, skysigma) + + return (skysigma) +end + + +# AP_VCSTRING -- Verify the centering string. + +procedure ap_vcstring (ap, str, maxch) + +pointer ap # pointer to the apphot strucuture +char str[ARB] # output string +int maxch # maximum number of characters + +int cfunc +int scan(), strdic(), nscan() + +begin + # Print the old centering algorithm. + call apstats (ap, CSTRING, str, maxch) + call printf ("Centering algorithm (%s) (CR or value): ") + call pargstr (str) + call flush (STDOUT) + + # Confirm the centering algorithm. + if (scan() != EOF) { + call gargwrd (str, maxch) + cfunc = strdic (str, str, maxch, CFUNCS) + if (nscan () == 1 && cfunc > 0) { + call apseti (ap, CENTERFUNCTION, cfunc) + call apsets (ap, CSTRING, str) + } + } + + # Print the new result. + call apstats (ap, CSTRING, str, maxch) + call printf ("\tNew centering algorithm: %s\n") + call pargstr (str) +end + + +# AP_VCAPERT -- Verify the centering aperture. + +real procedure ap_vcapert (ap) + +pointer ap # pointert to the apphot strucuture + +real scale, capert +int scan(), nscan() +real apstatr() + +begin + # Get the apphot scale factor. + scale = apstatr (ap, SCALE) + + # Print the old centering value. + call printf ("Centering box width in scale units (%g) (CR or value): ") + call pargr (2.0 * apstatr (ap, CAPERT)) + call flush (STDOUT) + + # Get the new centering value. + if (scan() == EOF) + capert = 2.0 * apstatr (ap, CAPERT) + else { + call gargr (capert) + if (nscan () != 1) + capert = 2.0 * apstatr (ap, CAPERT) + } + + # Type the new value. + call apsetr (ap, CAPERT, capert / 2.0) + call printf ("\tNew centering box width: %g scale units %g pixels\n") + call pargr (capert) + call pargr (scale * capert) + + return (capert / 2.0) +end + + +# AP_VCTHRESHOLD -- Verify the centering threshold parameter. + +real procedure ap_vcthreshold (ap) + +pointer ap # pointer to the apphot structure + +real skysigma, cthreshold +int scan(), nscan() +real apstatr() + +begin + # Get the sky sigma. + skysigma = apstatr (ap, SKYSIGMA) + + # Print the old centering threshold. + call printf ( + "Centering threshold in sigma above data minimum (%g) (CR or value): ") + call pargr (apstatr (ap, CTHRESHOLD)) + call flush (STDOUT) + + # Confirm the centering threshold parameter. + if (scan() == EOF) + cthreshold = apstatr (ap, CTHRESHOLD) + else { + call gargr (cthreshold) + if (nscan () != 1) + cthreshold = apstatr (ap, CTHRESHOLD) + } + + # Print the new centering threshold. + call apsetr (ap, CTHRESHOLD, cthreshold) + call printf ("\tNew centering threshold: %g skysigma %g counts\n") + call pargr (cthreshold) + if (IS_INDEFR(skysigma)) + call pargr (INDEFR) + else + call pargr (cthreshold * skysigma) + + return (cthreshold) +end + + +# AP_VRCLEAN -- Verify the cleaning radius + +real procedure ap_vrclean (ap) + +pointer ap # pointer to the apphot structure + +real scale, rclean +int scan(), nscan() +real apstatr() + +begin + # Confirm the cleaning radius. + scale = apstatr (ap, SCALE) + call printf ("Cleaning radius in scale units (%g) (CR or value): ") + call pargr (apstatr (ap, RCLEAN)) + call flush (STDOUT) + if (scan() == EOF) + rclean = apstatr (ap, RCLEAN) + else { + call gargr (rclean) + if (nscan () != 1) + rclean = apstatr (ap, RCLEAN) + } + + call apsetr (ap, RCLEAN, rclean) + call printf ("\tNew cleaning radius: %g scale units %g pixels\n") + call pargr (rclean) + call pargr (scale * rclean) + + return (rclean) +end + + +# AP_VRCLIP -- Verify the clipping radius. + +real procedure ap_vrclip (ap) + +pointer ap # pointer to the apphot structure + +real scale, rclip +int scan(), nscan() +real apstatr() + +begin + # Confirm the clipping radius. + scale = apstatr (ap, SCALE) + call printf ("Clipping radius in scale units (%g) (CR or value): ") + call pargr (apstatr (ap, RCLIP)) + call flush (STDOUT) + if (scan() == EOF) + rclip = apstatr (ap, RCLIP) + else { + call gargr (rclip) + if (nscan () != 1) + rclip = apstatr (ap, RCLIP) + } + + call apsetr (ap, RCLIP, rclip) + call printf ("\tNew FWHM clipping radius: %g scale units %g pixels\n") + call pargr (rclip) + call pargr (scale * rclip) + + return (rclip) +end + + +# AP_VSSTRING -- Verify the sky fitting algorithm string. + +procedure ap_vsstring (ap, str, maxch) + +pointer ap # pointer to the apphot structure +char str[ARB] # output string +int maxch # maximum number of characteristics + +int sfunc +int scan(), nscan(), strdic() + +begin + # Print the old salgorithm string. + call apstats (ap, SSTRING, str, maxch) + call printf ("Sky fitting algorithm (%s) (CR or value): ") + call pargstr (str) + call flush (STDOUT) + + # Confirm the sky fitting algorithm. + if (scan() != EOF) { + call gargwrd (str, maxch) + sfunc = strdic (str, str, maxch, SFUNCS) + if (nscan () == 1 && sfunc > 0) { + call apseti (ap, SKYFUNCTION, sfunc) + call apsets (ap, SSTRING, str) + } + } + + # Print the new salgorithm string. + call apstats (ap, SSTRING, str, maxch) + call printf ("\tSky fitting algorithm: %s\n") + call pargstr (str) +end + + +# AP_VANNULUS -- Verify the inner radius of sky annulus. + +real procedure ap_vannulus (ap) + +pointer ap # pointer to the apphot structure + +real scale, annulus +int scan(), nscan() +real apstatr() + +begin + scale = apstatr (ap, SCALE) + + # Print the old inner sky radius value. + call printf ( + "Inner radius of sky annulus in scale units (%g) (CR or value): ") + call pargr (apstatr (ap, ANNULUS)) + call flush (STDOUT) + + # Verify the new value. + if (scan () == EOF) + annulus = apstatr (ap, ANNULUS) + else { + call gargr (annulus) + if (nscan () != 1) + annulus = apstatr (ap, ANNULUS) + } + + # Print the old inner sky radius value. + call apsetr (ap, ANNULUS, annulus) + call printf ( + "\tNew inner radius of sky annulus: %g scale units %g pixels\n") + call pargr (annulus) + call pargr (scale * annulus) + + return (annulus) +end + + +# AP_VDANNULUS -- Verify the width of the sky annulus. + +real procedure ap_vdannulus (ap) + +pointer ap # pointer to the apphot structure + +real scale, dannulus +int scan(), nscan() +real apstatr() + +begin + scale = apstatr (ap, SCALE) + + # Print the old sky annulus width. + call printf ( + "Width of the sky annulus in scale units (%g) (CR or value): ") + call pargr (apstatr (ap, DANNULUS)) + call flush (STDOUT) + + # Confirm the width of the sky annulus. + if (scan() == EOF) + dannulus = apstatr (ap, DANNULUS) + else { + call gargr (dannulus) + if (nscan () != 1) + dannulus = apstatr (ap, DANNULUS) + } + + # Print the new sky annulus width. + call apsetr (ap, DANNULUS, dannulus) + call printf ( + "\tNew width of the sky annulus: %g scale units %g pixels\n") + call pargr (dannulus) + call pargr (scale * dannulus) + + return (dannulus) +end + + +# AP_VRGROW -- Verify the region growing radius + +real procedure ap_vrgrow (ap) + +pointer ap # pointer to the apphot structure + +real scale, rgrow +int scan(), nscan() +real apstatr() + +begin + scale = apstatr (ap, SCALE) + + # Print the old region growing radius. + call printf ( + "Region growing radius in scale units (%g) (CR or value): ") + call pargr (apstatr (ap, RGROW)) + call flush (STDOUT) + + # Confirm the region growing radius. + if (scan() == EOF) + rgrow = apstatr (ap, RGROW) + else { + call gargr (rgrow) + if (nscan () != 1) + rgrow = apstatr (ap, RGROW) + } + + # Print the region growing radius. + call apsetr (ap, RGROW, rgrow) + call printf ( + "\tNew region growing radius: %g scale units %g pixels\n") + call pargr (rgrow) + call pargr (scale * rgrow) + + return (rgrow) +end + + +# AP_VAPERTS -- Verify the photometric apertures. + +procedure ap_vaperts (ap, str, maxch) + +pointer ap # pointer to the apphot structure +char str[ARB] # output string +int maxch # maximum number of characters + +int i, naperts +pointer sp, aperts +real scale +int scan(), nscan(), ap_getaperts() +real apstatr() + +begin + call smark (sp) + call salloc (aperts, MAX_NAPERTS, TY_REAL) + + scale = apstatr (ap, SCALE) + + # Print the old aperture string. + call apstats (ap, APERTS, str, maxch) + call printf ( + "File/list of aperture radii in scale units (%s) (CR or value): ") + call pargstr (str) + call flush (STDOUT) + + # Get the new apertures. + if (scan() == EOF) + call apstats (ap, APERTS, str, maxch) + else { + call gargwrd (str, maxch) + if (nscan () != 1) + call apstats (ap, APERTS, str, maxch) + } + + # Print the new apertures. + naperts = ap_getaperts (str, Memr[aperts], MAX_NAPERTS) + do i = 1, naperts { + call printf ("\tAperture radius %d: %g scale units %g pixels\n") + call pargi (i) + call pargr (Memr[aperts+i-1]) + call pargr (scale * Memr[aperts+i-1]) + } + + call apsets (ap, APERTS, str) + call sfree (sp) +end + + +# AP_VPWSTRING -- Verify the weighting string. + +procedure ap_vpwstring (ap, str, maxch) + +pointer ap # pointer to the apphot structure +char str[ARB] # output string +int maxch # maximum number of characters + +int wfunc +int scan(), nscan(), strdic() + +begin + # Print the old string. + call apstats (ap, PWSTRING, str, maxch) + call printf ("Weighting algorithm (%s) (CR or value): ") + call pargstr (str) + call flush (STDOUT) + + # Get the new value. + if (scan() != EOF) { + call gargwrd (str, maxch) + wfunc = strdic (str, str, maxch, PWFUNCS) + if (nscan () == 1 && wfunc > 0) { + call apseti (ap, PWEIGHTS, wfunc) + call apsets (ap, PWSTRING, str) + } + } + + # Print the new value. + call apstats (ap, PWSTRING, str, maxch) + call printf ("\tNew weighting algorithm: %s\n") + call pargstr (str) + + call apsets (ap, PWSTRING, str) +end diff --git a/noao/digiphot/apphot/aplib/apverify2.x b/noao/digiphot/apphot/aplib/apverify2.x new file mode 100644 index 00000000..b5f02f46 --- /dev/null +++ b/noao/digiphot/apphot/aplib/apverify2.x @@ -0,0 +1,188 @@ +include "../lib/apphot.h" +include "../lib/noise.h" +include "../lib/find.h" +include "../lib/fitpsf.h" +include "../lib/radprof.h" + + +# AP_VTHRESHOLD -- Verify the full detection threshold. + +real procedure ap_vthreshold (ap) + +pointer ap # pointer to the apphot structure + +real skysigma, threshold +int scan(), nscan() +real apstatr() + +begin + skysigma = apstatr (ap, SKYSIGMA) + + # Confirm the threshold parameter. + call printf ( + "Detection threshold in sigma (%g) (CR or value): ") + call pargr (apstatr (ap, THRESHOLD)) + call flush (STDOUT) + if (scan() == EOF) + threshold = apstatr (ap, THRESHOLD) + else { + call gargr (threshold) + if (nscan () != 1) + threshold = apstatr (ap, THRESHOLD) + } + + call printf ("\tNew detection threshold: %g sigma %g counts\n") + call pargr (threshold) + call apsetr (ap, THRESHOLD, threshold) + if (IS_INDEFR(skysigma)) + call pargr (INDEFR) + else + call pargr (threshold * skysigma) + + return (threshold) +end + +# AP_VPFSTRING -- Verify the psf fitting function. + +procedure ap_vpfstring (ap, str, maxch) + +pointer ap # pointer to the apphot structure +char str[ARB] # output string +int maxch # maximum number of characters + +int pfunc +int scan(), nscan(), strdic() + +begin + # Print the old string value. + call apstats (ap, PSFSTRING, str, maxch) + call printf ("Fitting function (%s) (CR or value): ") + call pargstr (str) + call flush (STDOUT) + + # Get the new value. + if (scan() != EOF) { + call gargwrd (str, maxch) + pfunc = strdic (str, str, maxch, PSFFUNCS) + if (nscan () == 1 && pfunc > 0) { + call apseti (ap, PSFUNCTION, pfunc) + call apsets (ap, PSFSTRING, str) + } + } + + # Print the new value. + call apstats (ap, PSFSTRING, str, SZ_LINE) + call printf ("\tNew fitting function: %s\n") + call pargstr (str) +end + + +# AP_VPSFAPERT -- Verify the point spread function fitting aperture. + +real procedure ap_vpsfapert (ap) + +pointer ap # pointer to the apphot strucuture + +real scale, psfapert +int scan(), nscan() +real apstatr() + +begin + scale = apstatr (ap, SCALE) + + # Print the old value. + call printf ("Fitting box width in scale units (%g) (CR or value): ") + call pargr (2.0 * apstatr (ap, PSFAPERT)) + call flush (STDOUT) + + # Get the new value. + if (scan() == EOF) + psfapert = 2.0 * apstatr (ap, PSFAPERT) + else { + call gargr (psfapert) + if (nscan () != 1) + psfapert = 2.0 * apstatr (ap, PSFAPERT) + } + + # Print the new value. + call printf ("\tNew fitting box width: %g scale units %g pixels\n") + call pargr (psfapert) + call pargr (scale * psfapert) + call apsetr (ap, PSFAPERT, psfapert / 2.0) + + return (psfapert / 2.0) +end + + +# AP_VRPRADIUS -- Verify the radial profile fitting radius. + +real procedure ap_vrpradius (ap) + +pointer ap # pointer to the apphot strucuture + +real scale, radius +int scan(), nscan() +real apstatr() + +begin + scale = apstatr (ap, SCALE) + + # Print the old value. + call printf ("Fitting radius in scale units (%g) (CR or value): ") + call pargr (apstatr (ap, RPRADIUS)) + call flush (STDOUT) + + # Get the new value. + if (scan() == EOF) + radius = apstatr (ap, RPRADIUS) + else { + call gargr (radius) + if (nscan () != 1) + radius = apstatr (ap, RPRADIUS) + } + + # Print the new value. + call printf ("\tNew fitting radius: %g scale units %g pixels\n") + call pargr (radius) + call pargr (scale * radius) + call apsetr (ap, RPRADIUS, radius) + + return (radius) +end + + +# AP_VSTEP -- Verify the profile step size. + +real procedure ap_vstep (ap) + +pointer ap # pointer to the apphot strucuture + +real scale, step +int scan(), nscan() +real apstatr() + +begin + scale = apstatr (ap, SCALE) + + # Print the old value. + call printf ("Step size in scale units (%g) (CR or value): ") + call pargr (apstatr (ap, RPSTEP)) + call flush (STDOUT) + + # Get the new value. + if (scan() == EOF) + step = apstatr (ap, RPSTEP) + else { + call gargr (step) + if (nscan () != 1) + step = apstatr (ap, RPSTEP) + } + + # Print the new value. + call printf ("\tNew step size: %g scale units %g pixels\n") + call pargr (step) + call pargr (scale * step) + call apsetr (ap, RPSTEP, step) + + return (step) +end diff --git a/noao/digiphot/apphot/aplib/apwcs.x b/noao/digiphot/apphot/aplib/apwcs.x new file mode 100644 index 00000000..21ff7831 --- /dev/null +++ b/noao/digiphot/apphot/aplib/apwcs.x @@ -0,0 +1,117 @@ +# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc. + +include <imio.h> +include "../lib/apphot.h" + +# AP_ITOL -- Convert coordinates from the input coordinate system to the +# logical coordinate system. + +procedure ap_itol (ap, xin, yin, xout, yout, npts) + +pointer ap # the apphot package descriptor +real xin[ARB] # the input x coordinate +real yin[ARB] # the input y coordinate +real xout[ARB] # the output x coordinate +real yout[ARB] # the output y coordinate +int npts # the number of coordinates to convert + +double xt, yt +pointer ct +int i +int apstati() + +begin + ct = apstati (ap, CTIN) + if (ct == NULL) { + call amovr (xin, xout, npts) + call amovr (yin, yout, npts) + return + } + + do i = 1, npts { + call mw_c2trand (ct, double (xin[i]), double (yin[i]), xt, yt) + xout[i] = xt + yout[i] = yt + } +end + + +# AP_LTOO -- Convert coordinates from the logical coordinate system to the +# output coordinate system. + +procedure ap_ltoo (ap, xin, yin, xout, yout, npts) + +pointer ap # the apphot package descriptor +real xin[ARB] # the input x coordinate +real yin[ARB] # the input y coordinate +real xout[ARB] # the output x coordinate +real yout[ARB] # the output y coordinate +int npts # the number of coordinates to convert + +double xt, yt +pointer ct +int i +int apstati() + +begin + ct = apstati (ap, CTOUT) + if (ct == NULL) { + call amovr (xin, xout, npts) + call amovr (yin, yout, npts) + return + } + + do i = 1, npts { + call mw_c2trand (ct, double (xin[i]), double (yin[i]), xt, yt) + xout[i] = xt + yout[i] = yt + } +end + + +# AP_LTOV -- Convert coordinate from the logical coordinate system to the +# output coordinate system. + +procedure ap_ltov (im, xin, yin, xout, yout, npts) + +pointer im # the input image descriptor +real xin[ARB] # the input x coordinate +real yin[ARB] # the input y coordinate +real xout[ARB] # the output x coordinate +real yout[ARB] # the output y coordinate +int npts # the number of coordinates to convert + +int i, index1, index2 + +begin + index1 = IM_VMAP(im,1) + index2 = IM_VMAP(im,2) + do i = 1, npts { + xout[i] = xin[i] * IM_VSTEP(im,index1) + IM_VOFF(im,index1) + yout[i] = yin[i] * IM_VSTEP(im,index2) + IM_VOFF(im,index2) + } +end + + +# AP_VTOL -- Convert coordinate from the tv coordinate system to the +# logical coordinate system. + +procedure ap_vtol (im, xin, yin, xout, yout, npts) + +pointer im # the input image descriptor +real xin[ARB] # the input x coordinate +real yin[ARB] # the input y coordinate +real xout[ARB] # the output x coordinate +real yout[ARB] # the output y coordinate +int npts # the number of coordinates to convert + +int i, index1, index2 + +begin + index1 = IM_VMAP(im,1) + index2 = IM_VMAP(im,2) + do i = 1, npts { + xout[i] = (xin[i] - IM_VOFF(im,index1)) / IM_VSTEP(im,index1) + yout[i] = (yin[i] - IM_VOFF(im,index2)) / IM_VSTEP(im,index2) + } +end diff --git a/noao/digiphot/apphot/aplib/apwparam1.x b/noao/digiphot/apphot/aplib/apwparam1.x new file mode 100644 index 00000000..54086aeb --- /dev/null +++ b/noao/digiphot/apphot/aplib/apwparam1.x @@ -0,0 +1,415 @@ +include <time.h> +include "../lib/apphotdef.h" +include "../lib/apphot.h" +include "../lib/noise.h" +include "../lib/center.h" +include "../lib/fitsky.h" +include "../lib/phot.h" + +# AP_PARAM -- Procedure to write the apphot parameters to a text file. + +procedure ap_param (ap, out, task) + +pointer ap # pointer to the apphot structure +int out # output file descriptor +char task[ARB] # task name + +int nchars +pointer sp, outstr, date, time +bool itob() +int strmatch(), envfind(), gstrcpy(), apstati() +real apstatr() + +begin + if (out == NULL) + return + + # Allocate working space. + call smark (sp) + call salloc (outstr, SZ_LINE, TY_CHAR) + call salloc (date, SZ_DATE, TY_CHAR) + call salloc (time, SZ_DATE, TY_CHAR) + + # Write the id. + + nchars = envfind ("version", Memc[outstr], SZ_LINE) + if (nchars <= 0) + nchars = gstrcpy ("NOAO/IRAF", Memc[outstr], SZ_LINE) + call ap_rmwhite (Memc[outstr], Memc[outstr], SZ_LINE) + call ap_sparam (out, "IRAF", Memc[outstr], "version", + "current version of IRAF") + + nchars = envfind ("userid", Memc[outstr], SZ_LINE) + call ap_sparam (out, "USER", Memc[outstr], "name", "user id") + + call gethost (Memc[outstr], SZ_LINE) + call ap_sparam (out, "HOST", Memc[outstr], "computer", + "IRAF host machine") + + call apdate (Memc[date], Memc[time], SZ_DATE) + call ap_sparam (out, "DATE", Memc[date], "yyyy-mm-dd", "date") + call ap_sparam (out, "TIME", Memc[time], "hh:mm:ss", "time") + + call ap_sparam (out, "PACKAGE", "apphot", "name", + "name of IRAF package") + call ap_sparam (out, "TASK", task, "name", "name of apphot task") + call fprintf (out, "#\n") + + # Write out the apphot parameters. + call ap_rparam (out, KY_SCALE, 1.0 / apstatr (ap, SCALE), UN_AUNITS, + "scale in units per pixel") + call ap_rparam (out, KY_FWHMPSF, apstatr (ap, FWHMPSF), UN_ASCALEUNIT, + "full width half maximum of the psf") + call ap_bparam (out, KY_POSITIVE, itob (apstati (ap, POSITIVE)), + UN_ASWITCH, "positive feature") + call ap_rparam (out, KY_DATAMIN, apstatr (ap, DATAMIN), UN_ACOUNTS, + "minimum good data value") + call ap_rparam (out, KY_DATAMAX, apstatr (ap, DATAMAX), UN_ACOUNTS, + "maximum good data value") + + # Write out the image header keyword parameters. + call apstats (ap, EXPOSURE, Memc[outstr], SZ_FNAME) + if (Memc[outstr] == EOS) + call strcpy ("\"\"", Memc[outstr], SZ_FNAME) + call ap_sparam (out, KY_EXPOSURE, Memc[outstr], UN_AKEYWORD, + "exposure time keyword") + call apstats (ap, AIRMASS, Memc[outstr], SZ_FNAME) + if (Memc[outstr] == EOS) + call strcpy ("\"\"", Memc[outstr], SZ_FNAME) + call ap_sparam (out, KY_AIRMASS, Memc[outstr], UN_AKEYWORD, + "airmass keyword") + call apstats (ap, FILTER, Memc[outstr], SZ_FNAME) + if (Memc[outstr] == EOS) + call strcpy ("\"\"", Memc[outstr], SZ_FNAME) + call ap_sparam (out, KY_FILTER, Memc[outstr], UN_AKEYWORD, + "filter keyword") + call apstats (ap, OBSTIME, Memc[outstr], SZ_FNAME) + if (Memc[outstr] == EOS) + call strcpy ("\"\"", Memc[outstr], SZ_FNAME) + call ap_sparam (out, KY_OBSTIME, Memc[outstr], UN_AKEYWORD, + "obstime keyword") + call fprintf (out, "#\n") + + # Write the noise model parameters. + call ap_wnse (ap, out) + + # Write the centering parameters. + call ap_wctrs (ap, out) + + # Write sky fitting parameters. + call ap_wskys (ap, out) + + # Write the phot parameters. + call ap_wwphot (ap, out) + + # Write the polyphot parameters. + call ap_wpoly (ap, out) + + # Write the radial profile parameters. + call ap_wprofs (ap, out) + + # Write the psf fitting parameters. + call ap_wpsf (ap, out) + + # Write the header banner + if (strmatch ("^center", task) > 0) + call ap_cphdr (ap, out) + else if (strmatch ("^fitsky", task) > 0) + call ap_sphdr (ap, out) + else if (strmatch ("^phot", task) > 0) + call ap_maghdr (ap, out) + else if (strmatch ("^qphot", task) > 0) + call ap_maghdr (ap, out) + else if (strmatch ("^wphot", task) > 0) + call ap_maghdr (ap, out) + else if (strmatch ("^polyphot", task) > 0) + call ap_yhdr (ap, out) + else if (strmatch ("^fitpsf", task) > 0) + call ap_pfhdr (ap, out) + else if (strmatch ("^radprof", task) > 0) + call ap_rphdr (ap, out) + #else if (strmatch ("^daofind", task) > 0) + #call ap_fdhdr (ap, out) + + call sfree (sp) +end + + +# AP_WCTRS -- Procedure to write out the centering parameters. + +procedure ap_wctrs (ap, out) + +pointer ap # apphot pointer +int out # output file descriptor + +pointer sp, str +bool itob() +int apstati() +real apstatr() + +begin + if (out == NULL) + return + + call smark (sp) + call salloc (str, SZ_FNAME, TY_CHAR) + + if (AP_PCENTER(ap) != NULL) { + call apstats (ap, CSTRING, Memc[str], SZ_FNAME) + call ap_sparam (out, KY_CSTRING, Memc[str], UN_CALGORITHM, + "centering algorithm") + call ap_rparam (out, KY_CAPERT, 2.0* apstatr (ap, CAPERT), + UN_CSCALEUNIT, "centering box width") + call ap_rparam (out, KY_CTHRESHOLD, apstatr (ap, CTHRESHOLD), + UN_CSIGMA, "threshold for centering") + call ap_rparam (out, KY_MINSNRATIO, apstatr (ap, MINSNRATIO), + UN_CNUMBER, "minimum signal to noise ratio") + call ap_iparam (out, KY_CMAXITER, apstati (ap, CMAXITER), + UN_CNUMBER, "maximum number of iterations") + call ap_rparam (out, KY_MAXSHIFT, apstatr (ap, MAXSHIFT), + UN_CSCALEUNIT, "maximum shift") + call ap_bparam (out, KY_CLEAN, itob (apstati (ap, CLEAN)), + UN_CSWITCH, "apply clean algorithm before centering") + call ap_rparam (out, KY_RCLEAN, apstatr (ap, RCLEAN), + UN_CSCALEUNIT, "cleaning radius") + call ap_rparam (out, KY_RCLIP, apstatr (ap, RCLIP), UN_CSCALEUNIT, + "clipping radius") + call ap_rparam (out, KY_SIGMACLEAN, apstatr (ap, SIGMACLEAN), + UN_CSIGMA, "k-sigma clean rejection criterion") + call fprintf (out, "#\n") + } + + call sfree (sp) +end + + +# AP_WSKYS -- Procedure to write out the sky fitting parameters. + +procedure ap_wskys (ap, out) + +pointer ap # apphot structure +int out # output pointer + +pointer sp, str +bool itob() +int apstati() +real apstatr() + +begin + if (out == NULL) + return + + call smark (sp) + call salloc (str, SZ_FNAME, TY_CHAR) + + if (AP_PSKY(ap) != NULL) { + call apstats (ap, SSTRING, Memc[str], SZ_FNAME) + call ap_sparam (out, KY_SSTRING, Memc[str], UN_SALGORITHM, + " sky fitting algorithm") + call ap_rparam (out, KY_ANNULUS, apstatr (ap, ANNULUS), + UN_SSCALEUNIT, "inner radius of sky annulus") + call ap_rparam (out, KY_DANNULUS, apstatr (ap, DANNULUS), + UN_SSCALEUNIT, "width of the sky annulus") + call ap_rparam (out, KY_SKY_BACKGROUND, apstatr (ap, + SKY_BACKGROUND), UN_SCOUNTS, "user supplied sky value") + call ap_rparam (out, KY_K1, apstatr (ap, K1), UN_SSIGMA, + "half width of sky histogram") + call ap_rparam (out, KY_BINSIZE, apstatr (ap, BINSIZE), + UN_SSIGMA, "width of sky histogram bin") + call ap_bparam (out, KY_SMOOTH, itob (apstati (ap, SMOOTH)), + UN_SSWITCH, "Lucy smooth the histogram") + call ap_iparam (out, KY_SMAXITER, apstati (ap, SMAXITER), + UN_SNUMBER, "maximum number of iterations") + call ap_rparam (out, KY_SLOCLIP, apstatr (ap, SLOCLIP), + UN_SPERCENT, "lower clipping limit") + call ap_rparam (out, KY_SHICLIP, apstatr (ap, SHICLIP), + UN_SPERCENT, "upper clipping limit") + call ap_iparam (out, KY_SNREJECT, apstati (ap, SNREJECT), + UN_SNUMBER, "maximum number of rejection cycles") + call ap_rparam (out, KY_SLOREJECT, apstatr (ap, SLOREJECT), + UN_SSIGMA, "lower k-sigma rejection criterion") + call ap_rparam (out, KY_SHIREJECT, apstatr (ap, SHIREJECT), + UN_SSIGMA, "upper k-sigma rejection criterion") + call ap_rparam (out, KY_RGROW, apstatr (ap, RGROW), UN_SSCALEUNIT, + "region growing radius") + call fprintf (out, "#\n") + } + + call sfree (sp) +end + + +# AP_WNSE -- Porcedure to compute the noise model parameters. + +procedure ap_wnse (ap, out) + +pointer ap # apphot pointer +int out # output file descriptor + +pointer sp, str +real apstatr() + +begin + if (out == NULL) + return + call smark (sp) + call salloc (str, SZ_FNAME, TY_CHAR) + + if (AP_NOISE(ap) != NULL) { + call apstats (ap, NSTRING, Memc[str], SZ_FNAME) + call ap_sparam (out, KY_NSTRING, Memc[str], UN_NMODEL, + "noise model") + call ap_rparam (out, KY_SKYSIGMA, apstatr (ap, SKYSIGMA), + UN_NCOUNTS, "standard deviation of 1 sky pixel") + call apstats (ap, GAIN, Memc[str], SZ_FNAME) + if (Memc[str] == EOS) + call strcpy ("\"\"", Memc[str], SZ_FNAME) + call ap_sparam (out, KY_GAIN, Memc[str], UN_NKEYWORD, + "gain keyword") + call ap_rparam (out, KY_EPADU, apstatr (ap, EPADU), UN_NEPADU, + "electrons per adu") + call apstats (ap, CCDREAD, Memc[str], SZ_FNAME) + if (Memc[str] == EOS) + call strcpy ("\"\"", Memc[str], SZ_FNAME) + call ap_sparam (out, KY_CCDREAD, Memc[str], UN_NKEYWORD, + "read noise keyword") + call ap_rparam (out, KY_READNOISE, apstatr (ap, READNOISE), + UN_NELECTRONS, "electrons") + call fprintf (out, "#\n") + } + + call sfree (sp) +end + + +# AP_WWPHOT -- Procedure to write out the photometry parameters. + +procedure ap_wwphot (ap, out) + +pointer ap # apphot structure pointer +int out # output file descriptor + +pointer sp, str +real apstatr() + +begin + if (out == NULL) + return + + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + + if (AP_PPHOT(ap) != NULL) { + call apstats (ap, PWSTRING, Memc[str], SZ_LINE) + call ap_sparam (out, KY_PWSTRING, Memc[str], UN_PMODEL, + "photometric weighting scheme") + call apstats (ap, APERTS, Memc[str], SZ_LINE) + call ap_sparam (out, KY_APERTS, Memc[str], UN_PSCALEUNIT, + "list of apertures") + call ap_rparam (out, KY_ZMAG, apstatr (ap, ZMAG), UN_PZMAG, + "zero point of magnitdue scale") + call fprintf (out, "#\n") + } + + call sfree (sp) +end + + +# AP_RPARAM -- Procedure to encode a real apphot parameter. + +procedure ap_rparam (out, keyword, value, units, comments) + +int out # output file descriptor +char keyword[ARB] # keyword string +real value # parameter value +char units[ARB] # units string +char comments[ARB] # comment string + +begin + if (out == NULL) + return + + call strupr (keyword) + call fprintf (out, + "#K%4t%-10.10s%14t = %17t%-23.7g%41t%-10.10s%52t%-10s\n") + call pargstr (keyword) + call pargr (value) + call pargstr (units) + call pargstr ("%-23.7g") + call pargstr (comments) +end + + +# AP_IPARAM -- Procedure to encode an apphot integer parameter. + +procedure ap_iparam (out, keyword, value, units, comments) + +int out # output file descriptor +char keyword[ARB] # keyword string +int value # parameter value +char units[ARB] # units string +char comments[ARB] # comment string + +begin + if (out == NULL) + return + + call strupr (keyword) + call fprintf (out, + "#K%4t%-10.10s%14t = %17t%-23d%41t%-10.10s%52t%-10s\n") + call pargstr (keyword) + call pargi (value) + call pargstr (units) + call pargstr ("%-23d") + call pargstr (comments) +end + + +# AP_BPARAM -- Procedure to encode an apphot boolean parameter. + +procedure ap_bparam (out, keyword, value, units, comments) + +int out # output file descriptor +char keyword[ARB] # keyword string +bool value # parameter value +char units[ARB] # units string +char comments[ARB] # comment string + +begin + if (out == NULL) + return + + call strupr (keyword) + call fprintf (out, + "#K%4t%-10.10s%14t = %17t%-23b%41t%-10.10s%52t%-10s\n") + call pargstr (keyword) + call pargb (value) + call pargstr (units) + call pargstr ("%-23b") + call pargstr (comments) +end + + +# AP_SPARAM -- Procedure to encode an apphot string parameter. + +procedure ap_sparam (out, keyword, value, units, comments) + +int out # output file descriptor +char keyword[ARB] # keyword string +char value[ARB] # parameter value +char units[ARB] # units string +char comments[ARB] # comment string + +begin + if (out == NULL) + return + + call strupr (keyword) + call fprintf (out, + "#K%4t%-10.10s%14t = %17t%-23.23s%41t%-10.10s%52t%-10s\n") + call pargstr (keyword) + call pargstr (value) + call pargstr (units) + call pargstr ("%-23s") + call pargstr (comments) +end diff --git a/noao/digiphot/apphot/aplib/apwparam2.x b/noao/digiphot/apphot/aplib/apwparam2.x new file mode 100644 index 00000000..1c15f26c --- /dev/null +++ b/noao/digiphot/apphot/aplib/apwparam2.x @@ -0,0 +1,104 @@ +include "../lib/apphotdef.h" +include "../lib/polyphot.h" +include "../lib/fitpsf.h" +include "../lib/radprof.h" + + +# AP_WPROFS -- Procedure to print out the profile fitting parameters. + +procedure ap_wprofs (ap, out) + +pointer ap # apphot structure pointer +int out # output file descriptor + +pointer sp, str +int apstati() +real apstatr() + +begin + if (out == NULL) + return + + call smark (sp) + call salloc (str, SZ_FNAME, TY_CHAR) + + if (AP_RPROF(ap) != NULL) { + call ap_rparam (out, KY_RPRADIUS, apstatr (ap, RPRADIUS), + UN_RSCALEUNIT, "fitting radius") + call ap_rparam (out, KY_RPSTEP, apstatr (ap, RPSTEP), + UN_RSCALEUNIT, "step size in radius") + call ap_iparam (out, KY_RPORDER, apstati (ap, RPORDER), UN_RNUMBER, + "number of splines pieces") + call ap_rparam (out, KY_RPKSIGMA, apstatr (ap, RPKSIGMA), + UN_RSIGMA, "k-sigma rejection criterion") + call ap_iparam (out, KY_RPNREJECT, apstati (ap, RPNREJECT), + UN_RNUMBER, "maximum number of rejection cycles") + call fprintf (out, "#\n") + } + + call sfree (sp) +end + + +# AP_WPOLY -- Procedure to write out the polyphot parameters. + +procedure ap_wpoly (ap, out) + +pointer ap # apphot structure pointer +int out # output file descriptor + +pointer sp, str +real apstatr() + +begin + if (out == NULL) + return + + call smark (sp) + call salloc (str, SZ_FNAME, TY_CHAR) + + if (AP_POLY(ap) != NULL) { + call ap_sparam (out, "WEIGHTING", "constant", "model", "") + call ap_rparam (out, KY_PYZMAG, apstatr (ap, PYZMAG), UN_PYZMAG, + "zero point of magnitdue scale") + call fprintf (out, "#\n") + } + + call sfree (sp) +end + + +# AP_WPSF -- Procedure to write the psf fitting parameters . + +procedure ap_wpsf (ap, out) + +pointer ap # apphot strucuture pointer +int out # output file descriptor + +pointer sp, str +int apstati() +real apstatr() + +begin + if (out == NULL) + return + call smark (sp) + call salloc (str, SZ_FNAME, TY_CHAR) + + if (AP_PPSF(ap) != NULL) { + call apstats (ap, PSFSTRING, Memc[str], SZ_FNAME) + call ap_sparam (out, KY_PSFUNCTION, Memc[str], UN_PSFMODEL, + "fitting function") + call ap_rparam (out, KY_PSFAPERT, 2.0 * apstatr (ap, PSFAPERT), + UN_PSFSCALEUNIT, "width of the fitting box") + call ap_iparam (out, KY_PMAXITER, apstati (ap, PMAXITER), + UN_PSFSCALEUNIT, "maximum number of iterations") + call ap_rparam (out, KY_PK2, apstatr (ap, PK2), UN_PSFSIGMA, + "k-sigma rejection limit for the fit") + call ap_iparam (out, KY_PNREJECT, apstati (ap, PNREJECT), + UN_PSFNUMBER, "maximum number of rejection cycles") + call fprintf (out, "#\n") + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/aplib/apwres1.x b/noao/digiphot/apphot/aplib/apwres1.x new file mode 100644 index 00000000..3d7b490a --- /dev/null +++ b/noao/digiphot/apphot/aplib/apwres1.x @@ -0,0 +1,437 @@ +include "../lib/apphot.h" +include "../lib/find.h" +include "../lib/center.h" +include "../lib/fitsky.h" + +# define the #N, #U, and #F daofind strings + +define FD_NSTR "#N%4tXCENTER%14tYCENTER%24tMAG%33tSHARPNESS%45t\ +SROUND%57tGROUND%69tID%80t\\\n" +define FD_USTR "#U%4tpixels%14tpixels%24t#%33t#%45t#%57t#%69t#%80t\\\n" +define FD_FSTR "#F%4t%%-13.3f%14t%%-10.3f%24t%%-9.3f%33t%%-12.3f%45t\ +%%-12.3f%57t%%-12.3f%69t%%-6d%80t\\\n" +define FD_WSTR "%4t%-10.3f%-10.3f%-9.3f%-12.3f%-12.3f%-12.3f%-6d\n" + +# AP_WFDPARAM -- Write the daofind parameters to the output file. + +procedure ap_wfdparam (out, ap) + +int out # the output file descriptor +pointer ap # pointer to the apphot structure + +pointer sp, str +real apstatr() + +begin + if (out == NULL) + return + + call smark (sp) + call salloc (str, SZ_FNAME, TY_CHAR) + + # Write out the parameters. + call ap_param (ap, out, "daofind") + #call apstats (ap, IMNAME, Memc[str], SZ_FNAME) + call apstats (ap, IMROOT, Memc[str], SZ_FNAME) + call ap_sparam (out, KY_IMNAME, Memc[str], "imagename", "image name") + call ap_rparam (out, KY_FWHMPSF, apstatr (ap, FWHMPSF), UN_ASCALEUNIT, + "fwhm of the psf") + call ap_rparam (out, KY_THRESHOLD, apstatr (ap, THRESHOLD), + UN_FSIGMA, "detection threshold in sigma") + call ap_rparam (out, KY_NSIGMA, apstatr (ap, NSIGMA), UN_FSIGMA, + "size of the kernel in fwhmpsf") + call ap_rparam (out, KY_RATIO, apstatr (ap, RATIO), UN_FNUMBER, + "ratio of ysigma to xsigma") + call ap_rparam (out, KY_THETA, apstatr (ap, THETA), UN_FDEGREES, + "position angle in degrees") + call fprintf (out, "#\n") + call ap_rparam (out, KY_SHARPLO, apstatr (ap, SHARPLO), UN_FNUMBER, + "lower sharpness bound") + call ap_rparam (out, KY_SHARPHI, apstatr (ap, SHARPHI), UN_FNUMBER, + "higher sharpness bound") + call ap_rparam (out, KY_ROUNDLO, apstatr (ap, ROUNDLO), UN_FNUMBER, + "lower roundness bound") + call ap_rparam (out, KY_ROUNDHI, apstatr (ap, ROUNDHI), UN_FNUMBER, + "higher roundness bound") + call fprintf (out, "#\n") + + # Write out the header banner. + call ap_fdhdr (ap, out) + + call sfree (sp) +end + + +# AP_FDHDR -- Write the daofind column banner to the output file. + +procedure ap_fdhdr (ap, out) + +pointer ap # pointer to the apphot structure (unused) +int out # output file descriptor + +begin + if (out == NULL) + return + + call fprintf (out, FD_NSTR) + call fprintf (out, FD_USTR) + call fprintf (out, FD_FSTR) + call fprintf (out, "#\n") +end + + +# APSTDOUT -- Print the daofind results on the standard output. + +procedure apstdout (density, ptrs, ncols, nbox, cols, x, y, sharp, round1, + round2, nstars, ntotal, threshold) + +real density[ncols,nbox] # array of densities +int ptrs[ARB] # array of line pointers +int ncols, nbox # dimensions of the data +int cols[ARB] # array of column numbers +real x[ARB] # x coordinates +real y[ARB] # y coordinates +real sharp[ARB] # sharpness +real round1[ARB] # first roundness parameter +real round2[ARB] # second roundness parameter +int nstars # number of detected stars in the line +int ntotal # total number of detected objects +real threshold # threshold for detection + +int i, middle +real den + +begin + middle = 1 + nbox / 2 + do i = 1, nstars { + call printf (" %7.2f %7.2f %7.3f %6.3f %6.3f %6.3f %4d\n") + call pargr (x[i]) + call pargr (y[i]) + if (threshold <= 0.0) + den = INDEFR + else + den = -2.5 * log10 (density[cols[i],ptrs[middle]] / + threshold) + call pargr (den) + call pargr (sharp[i]) + call pargr (round1[i]) + call pargr (round2[i]) + call pargi (ntotal + i) + } +end + + +# APDTFOUT -- Write the daofind results to the output file. + +procedure apdtfout (fd, density, ptrs, ncols, nbox, cols, x, y, sharp, round1, + round2, nstars, ntotal, threshold, stid) + +int fd # the output file descriptor +real density[ncols, nbox] # densities +int ptrs[ARB] # array of line pointers +int ncols, nbox # dimensions of the data +int cols[ARB] # column numbers +real x[ARB] # xcoords +real y[ARB] # y coords +real sharp[ARB] # sharpnesses +real round1[ARB] # first roundness +real round2[ARB] # second roundness +int nstars # number of detected stars in the line +int ntotal # total number of detected objects +real threshold # threshold for detection +int stid # output file sequence number + +int i, middle +real den + +begin + if (fd == NULL) + return + + middle = 1 + nbox / 2 + do i = 1, nstars { + call fprintf (fd, FD_WSTR) + call pargr (x[i]) + call pargr (y[i]) + if (threshold <= 0.0) + den = INDEFR + else + den = -2.5 * log10 (density[cols[i],ptrs[middle]] / + threshold) + call pargr (den) + call pargr (sharp[i]) + call pargr (round1[i]) + call pargr (round2[i]) + call pargi (stid + ntotal + i - 1) + } +end + + +# define the #N, #U and #K id strings + +define ID_NSTR "#N%4tIMAGE%24tXINIT%34tYINIT%44tID%50tCOORDS%73tLID%80t\\\n" +define ID_USTR "#U%4timagename%24tpixels%34tpixels%44t##%50tfilename%73t\ +##%80t\\\n" +define ID_FSTR "#F%4t%%-23s%24t%%-10.3f%34t%%-10.3f%44t%%-6d%50t%%-23s%73t\ +%%-6d%80t \n" +define ID_WSTR "%-23.23s%24t%-10.3f%34t%-10.3f%44t%-6d%50t%-23.23s%73t\ +%-6d%80t%c\n" + +# AP_IDHDR -- Print the id column header strings. + +procedure ap_idhdr (ap, fd) + +pointer ap # apphot descriptor (unused) +int fd # output file descriptor + +begin + if (fd == NULL) + return + call fprintf (fd, ID_NSTR) + call fprintf (fd, ID_USTR) + call fprintf (fd, ID_FSTR) + call fprintf (fd, "#\n") +end + + +# AP_WID -- Write the id record to a file. + +procedure ap_wid (ap, fd, xpos, ypos, id, lid, lastchar) + +pointer ap # pointer to apphot structure +int fd # output file descriptor +real xpos # x position +real ypos # y position +int id # id of the star +int lid # list number +int lastchar # last character in record + +pointer sp, imname, clname + +begin + if (fd == NULL) + return + + call smark (sp) + call salloc (imname, SZ_FNAME, TY_CHAR) + call salloc (clname, SZ_FNAME, TY_CHAR) + + # Print description of object. + call apstats (ap, IMROOT, Memc[imname], SZ_FNAME) + call apstats (ap, CLROOT, Memc[clname], SZ_FNAME) + if (Memc[clname] == EOS) + call strcpy ("nullfile", Memc[clname], SZ_FNAME) + call fprintf (fd, ID_WSTR) + call pargstr (Memc[imname]) + call pargr (xpos) + call pargr (ypos) + call pargi (id) + call pargstr (Memc[clname]) + call pargi (lid) + call pargi (lastchar) + + call sfree (sp) +end + + +# define the #N, #U and #K center strings + +define CTR_NSTR "#N%4tXCENTER%15tYCENTER%26tXSHIFT%34tYSHIFT%42tXERR%50t\ +YERR%66tCIER%71tCERROR%80t\\\n" +define CTR_USTR "#U%4tpixels%15tpixels%26tpixels%34tpixels%42tpixels%50t\ +pixels%66t##%71tcerrors%80t\\\n" +define CTR_FSTR "#F%4t%%-14.3f%15t%%-11.3f%26t%%-8.3f%34t%%-8.3f%42t\ +%%-8.3f%50t%%-15.3f%66t%%-5d%71t%%-9s%80t \n" +define CTR_WSTR "%4t%-11.3f%-11.3f%-8.3f%-8.3f%-8.3f%-15.3f%-5d%-9.9s\ +%80t%c\n" + + +# AP_CHDR -- Print the center algorithm column header strings. + +procedure ap_chdr (ap, fd) + +pointer ap # apphot descriptor (unused) +int fd # output file descriptor + +begin + if (fd == NULL) + return + call fprintf (fd, CTR_NSTR) + call fprintf (fd, CTR_USTR) + call fprintf (fd, CTR_FSTR) + call fprintf (fd, "#\n") +end + + +# AP_WCRES -- Write out the centering algorithm results to a file. + +procedure ap_wcres (ap, fd, ier, lastchar) + +pointer ap # pointer to apphot structure +int fd # output file descriptor +int ier # error code +int lastchar # last character written out + +pointer sp, str +real apstatr() + +begin + if (fd == NULL) + return + + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + call ap_cserrors (ier, Memc[str], SZ_LINE) + + # Print the computed centers. + call fprintf (fd, CTR_WSTR) + call pargr (apstatr (ap, OXCENTER)) + call pargr (apstatr (ap, OYCENTER)) + call pargr (apstatr (ap, OXSHIFT)) + call pargr (apstatr (ap, OYSHIFT)) + call pargr (apstatr (ap, XERR)) + call pargr (apstatr (ap, YERR)) + call pargi (ier) + call pargstr (Memc[str]) + call pargi (lastchar) + + call sfree (sp) +end + + +# AP_CSERRORS -- Encode the centering task error messages into a string. + +procedure ap_cserrors (ier, str, maxch) + +int ier # error code +char str[ARB] # output str +int maxch # maximum number of characters + +begin + switch (ier) { + case AP_CTR_NOAREA: + call strcpy ("OffImage", str, maxch) + case AP_CTR_OUTOFBOUNDS: + call strcpy ("EdgeImage", str, maxch) + case AP_CTR_NTOO_SMALL: + call strcpy ("TooFewPts", str, maxch) + case AP_CTR_SINGULAR: + call strcpy ("Singular", str, maxch) + case AP_CTR_NOCONVERGE: + call strcpy ("BadFit", str, maxch) + case AP_CTR_BADSHIFT: + call strcpy ("BigShift", str, maxch) + case AP_CTR_LOWSNRATIO: + call strcpy ("LowSnr", str, maxch) + case AP_CTR_BADDATA: + call strcpy ("BadPixels", str, maxch) + default: + call strcpy ("NoError", str, maxch) + } +end + + +# define the #N, #U and #K fitsky strings + +define SKY_NSTR "#N%4tMSKY%19tSTDEV%34tSSKEW%49tNSKY%56tNSREJ%66tSIER\ +%71tSERROR%80t\\\n" +define SKY_USTR "#U%4tcounts%19tcounts%34tcounts%49tnpix%56tnpix%66t##\ +%71tserrors%80t\\\n" +define SKY_FSTR "#F%4t%%-18.7g%19t%%-15.7g%34t%%-15.7g%49t%%-7d%56t\ +%%-9d%66t%%-5d%71t%%-9s%80t \n" +define SKY_WSTR "%4t%-15.7g%-15.7g%-15.7g%-7d%-9d%-5d%-9.9s%80t%c\n" + +# AP_SHDR -- Print the sky fitting column header strings. + +procedure ap_shdr (ap, fd) + +pointer ap # apphot descriptor (unused) +int fd # output file descriptor + +begin + if (fd == NULL) + return + + call fprintf (fd, SKY_NSTR) + call fprintf (fd, SKY_USTR) + call fprintf (fd, SKY_FSTR) + call fprintf (fd, "#\n") +end + + +# AP_WSRES -- Write the results of the sky fitting algorithms to the output +# file. + +procedure ap_wsres (ap, fd, ier, lastchar) + +pointer ap # pointer to apphot structure +int fd # output file descriptor +int ier # error code +int lastchar # last character + +int apstati() +real apstatr() + +pointer sp, str + +begin + if (fd == NULL) + return + + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + call ap_sserrors (ier, Memc[str], SZ_LINE) + + # Print the computed sky value and statistics. + call fprintf (fd, SKY_WSTR) + call pargr (apstatr (ap, SKY_MODE)) + call pargr (apstatr (ap, SKY_SIGMA)) + call pargr (apstatr (ap, SKY_SKEW)) + call pargi (apstati (ap, NSKY)) + call pargi (apstati (ap, NSKY_REJECT)) + call pargi (ier) + call pargstr (Memc[str]) + call pargi (lastchar) + + call sfree (sp) +end + + +# AP_SSERRORS -- Encode the sky fitting error messages in a string. + +procedure ap_sserrors (ier, str, maxch) + +int ier # integer error code +char str[ARB] # the output string +int maxch # maximum number of characters + +begin + switch (ier) { + case AP_NOSKYAREA: + call strcpy ("OffImage", str, maxch) + case AP_SKY_OUTOFBOUNDS: + call strcpy ("EdgeImage", str, maxch) + case AP_NOHISTOGRAM: + call strcpy ("NoHist", str, maxch) + case AP_FLAT_HIST: + call strcpy ("FlatHist", str, maxch) + case AP_NSKY_TOO_SMALL: + call strcpy ("TooFewPts", str, maxch) + case AP_SKY_SINGULAR: + call strcpy ("Singular", str, maxch) + case AP_SKY_NOCONVERGE: + call strcpy ("BadFit", str, maxch) + case AP_NOGRAPHICS: + call strcpy ("NoGraph", str, maxch) + case AP_NOSKYFILE: + call strcpy ("NoFile", str, maxch) + case AP_EOFSKYFILE: + call strcpy ("ShortFile", str, maxch) + case AP_BADSKYSCAN: + call strcpy ("BadRecord", str, maxch) + case AP_BADPARAMS: + call strcpy ("BadParams", str, maxch) + default: + call strcpy ("NoError", str, maxch) + } +end diff --git a/noao/digiphot/apphot/aplib/apwres2.x b/noao/digiphot/apphot/aplib/apwres2.x new file mode 100644 index 00000000..1c5d38a5 --- /dev/null +++ b/noao/digiphot/apphot/aplib/apwres2.x @@ -0,0 +1,347 @@ +include "../lib/apphotdef.h" +include "../lib/photdef.h" + +include "../lib/apphot.h" +include "../lib/fitsky.h" +include "../lib/phot.h" +include "../lib/polyphot.h" + +# define the #N, #U and #K phot/wphot strings + +define MAG1_NSTR "#N%4tITIME%19tXAIRMASS%34tIFILTER%57tOTIME%80t\\\n" +define MAG1_USTR "#U%4ttimeunit%19tnumber%34tname%57ttimeunit%80t\\\n" +define MAG1_FSTR "#F%4t%%-18.7g%19t%%-15.7g%34t%%-23s%57t%%-23s%80t \n" +define MAG1_WSTR "%4t%-15.7g%-15.7g%-23.23s%-23.23s%80t\\\n" + +define MAG2_NSTR "#N%4tRAPERT%13tSUM%27tAREA%38tFLUX%52tMAG%59tMERR%66t\ +PIER%71tPERROR%80t\\\n" +define MAG2_USTR "#U%4tscale%13tcounts%27tpixels%38tcounts%52tmag%59t\ +mag%66t##%71tperrors%80t\\\n" +define MAG2_FSTR "#F%4t%%-12.2f%13t%%-14.7g%27t%%-11.7g%38t%%-14.7g%52t\ +%%-7.3f%59t%%-6.3f%66t%%-5d%71t%%-9s%80t \n" +define MAG2_WSTR "%4t%-9.2f%-14.7g%-11.7g%-14.7g%-7.3f%-6.3f%-5d%-9.9s\ +%79t%2s\n" + + +# AP_MHDR -- Print the phot/wphot/qphot column header strings. + +procedure ap_mhdr (ap, fd) + +pointer ap # apphot descriptor (unused) +int fd # output file descriptor + +begin + if (fd == NULL) + return + + call fprintf (fd, MAG1_NSTR) + call fprintf (fd, MAG1_USTR) + call fprintf (fd, MAG1_FSTR) + call fprintf (fd, "#\n") + + call fprintf (fd, MAG2_NSTR) + call fprintf (fd, MAG2_USTR) + call fprintf (fd, MAG2_FSTR) + call fprintf (fd, "#\n") +end + + +# AP_WMRES -- Write the results of the phot/qphot/wphot tasks to the output +# file. + +procedure ap_wmres (ap, fd, i, pier, endstr) + +pointer ap # pointer to apphot structure +int fd # output text file +int i # index of variable length field +int pier # photometric error +char endstr[ARB] # termination string + +int ier +pointer sp, str, phot +real sky_val +real apstatr() + +begin + # Initialize. + if (fd == NULL) + return + + phot = AP_PPHOT(ap) + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + + # Write out the exposure time, airmass and filter information. + if (i <= 1) { + call fprintf (fd, MAG1_WSTR) + call pargr (apstatr (ap, ITIME)) + call pargr (apstatr (ap, XAIRMASS)) + call apstats (ap, FILTERID, Memc[str], SZ_FNAME) + call pargstr (Memc[str]) + call apstats (ap, OTIME, Memc[str], SZ_FNAME) + call pargstr (Memc[str]) + } + + # Write out the error code. + if (IS_INDEFR(Memr[AP_MAGS(phot)+i-1])) { + if (pier != AP_APERT_OUTOFBOUNDS) + ier = pier + else if (i > AP_NMAXAP(phot)) + ier = AP_APERT_OUTOFBOUNDS + else + ier = AP_OK + } else if (i >= AP_NMINAP(phot)) { + ier = AP_APERT_BADDATA + } else { + ier = AP_OK + } + call ap_pserrors (ier, Memc[str], SZ_LINE) + + # Write out the photometry results. + call fprintf (fd, MAG2_WSTR) + if (i == 0) { + call pargr (0.0) + call pargr (0.0) + call pargr (0.0) + call pargr (INDEFR) + call pargr (INDEFR) + call pargi (ier) + call pargstr (Memc[str]) + call pargstr (endstr) + } else { + call pargr (Memr[AP_APERTS(phot)+i-1]) + call pargd (Memd[AP_SUMS(phot)+i-1]) + call pargd (Memd[AP_AREA(phot)+i-1]) + sky_val = apstatr (ap, SKY_MODE) + if (IS_INDEFR(sky_val)) + call pargr (0.0) + else + call pargr (real (Memd[AP_SUMS(phot)+i-1] - sky_val * + Memd[AP_AREA(phot)+i-1])) + call pargr (Memr[AP_MAGS(phot)+i-1]) + if (Memr[AP_MAGERRS(phot)+i-1] > 99.999) + call pargr (INDEFR) + else + call pargr (Memr[AP_MAGERRS(phot)+i-1]) + call pargi (ier) + call pargstr (Memc[str]) + call pargstr (endstr) + } + + call sfree (sp) +end + + +# AP_PSERRORS -- Encode the photometric errors string. + +procedure ap_pserrors (ier, str, maxch) + +int ier # photometry error code +char str[ARB] # output string +int maxch # maximum length of string + +begin + switch (ier) { + case AP_APERT_NOAPERT: + call strcpy ("OffImage", str, maxch) + case AP_APERT_OUTOFBOUNDS: + call strcpy ("EdgeImage", str, maxch) + case AP_APERT_NOSKYMODE: + call strcpy ("NoSky", str, maxch) + case AP_APERT_NEGMAG: + call strcpy ("NoFlux", str, maxch) + case AP_APERT_BADDATA: + call strcpy ("BadPixels", str, maxch) + default: + call strcpy ("NoError", str, maxch) + } +end + + +# define the #N, #U and #K polyphot strings + +define PY_NSTR1 "#N%4tITIME%19tXAIRMASS%34tIFILTER%57tOTIME%80t\\\n" +define PY_USTR1 "#U%4ttimeunit%19tnumber%34tname%57ttimeunit%80t\\\n" +define PY_FSTR1 "#F%4t%%-18.7g%19t%%-15.7g%34t%%-23s%57t%%-23s%80t \n" +define PY_WSTR1 "%4t%-15.7g%-15.7g%-23.23s%-23.23s%80t\\\n" + +define PY_NSTR2 "#N%4tSUM%19tAREA%34tFLUX%49tMAG%58tMERR%66tPIER%71t\ +PERROR%80t\\\n" +define PY_USTR2 "#U%4tcounts%19tpixels%34tcounts%49tmag%58tmag%66t##%71t\ +perrors%80t\\\n" +define PY_FSTR2 "#F%4t%%-18.7g%19t%%-15.7g%34t%%-15.7g%49t%%-9.3f%58t\ +%%-7.3f%66t%%-5d%71t%%-9s%80t \n" +define PY_WSTR2 "%4t%-15.7g%-15.7g%-15.7g%-9.3f%-7.3f%-5d%-9.9s%80t\\\n" + +define PY_NSTR3 "#N%4tPOLYGONS%24tPID%29tOLDXMEAN%38tOLDYMEAN%47t\ +XMEAN%56tYMEAN%65tMINRAD%74tNVER%80t\\\n" +define PY_USTR3 "#U%4tfilename%24t##%29tpixels%38tpixels%47t\ +pixels%56tpixels%65tpixels%74t##%80t\\\n" +define PY_FSTR3 "#F%4t%%-23s%24t%%-5d%29t%%-9.2f%38t%%-9.2f%47t\ +%%-9.2f%56t%%-9.2f%65t%%-9.2f%74t%%-5d%80t \n" +define PY_WSTR3 "%4t%-20.20s%-5d%-9.2f%-9.2f%-9.2f%-9.2f%-9.2f%-5d%80t\\\n" + +define PY_NSTR4 "#N%4tXVERTEX%13tYVERTEX%80t\\\n" +define PY_USTR4 "#U%4tpixels%13tpixels%80t\\\n" +define PY_FSTR4 "#F%4t%%-12.2f%13t%%-9.2f%80t \n" +define PY_WSTR4 "%4t%-9.2f%-9.2f%79t%2s\n" + + +# AP_PLHDR -- Print the polyphot column header strings. + +procedure ap_plhdr (ap, fd) + +pointer ap # apphot descriptor (unused) +int fd # output file descriptor + +begin + if (fd == NULL) + return + + call fprintf (fd, PY_NSTR1) + call fprintf (fd, PY_USTR1) + call fprintf (fd, PY_FSTR1) + call fprintf (fd, "#\n") + + call fprintf (fd, PY_NSTR2) + call fprintf (fd, PY_USTR2) + call fprintf (fd, PY_FSTR2) + call fprintf (fd, "#\n") + + call fprintf (fd, PY_NSTR3) + call fprintf (fd, PY_USTR3) + call fprintf (fd, PY_FSTR3) + call fprintf (fd, "#\n") + + call fprintf (fd, PY_NSTR4) + call fprintf (fd, PY_USTR4) + call fprintf (fd, PY_FSTR4) + call fprintf (fd, "#\n") +end + + +# AP_WLRES -- Write the results of the polyphot task to the output file. + +procedure ap_wlres (py, fd, xver, yver, nver, pid, pier) + +pointer py # pointer to apphot structure +int fd # output file descriptor +real xver[ARB] # coords of x vertices +real yver[ARB] # coords of y vertices +int nver # number of vertices +int pid # polygon number +int pier # photometric error + +int i +pointer sp, str, pyname +real sky_val +int apstati() +double apstatd() +real apstatr() + +begin + if (fd == NULL) + return + + # Allocate space. + call smark (sp) + call salloc (pyname, SZ_FNAME, TY_CHAR) + call salloc (str, SZ_LINE, TY_CHAR) + + # Write out the exposure time, airmass and filter id. + call fprintf (fd, PY_WSTR1) + call pargr (apstatr (py, ITIME)) + call pargr (apstatr (py, XAIRMASS)) + call apstats (py, FILTERID, Memc[str], SZ_FNAME) + call pargstr (Memc[str]) + call apstats (py, OTIME, Memc[str], SZ_FNAME) + call pargstr (Memc[str]) + + # Write the photometry results. + call ap_spyerrors (pier, Memc[str], SZ_LINE) + sky_val = apstatr (py, SKY_MODE) + call fprintf (fd, PY_WSTR2) + call pargd (apstatd (py, PYFLUX)) + call pargd (apstatd (py, PYNPIX)) + if (IS_INDEFR(sky_val)) + call pargr (0.0) + else + call pargr (real (apstatd (py, PYFLUX) - sky_val * + apstatd (py, PYNPIX))) + call pargr (apstatr (py, PYMAG)) + if (apstatr (py, PYMAGERR) > 99.999) + call pargr (INDEFR) + else + call pargr (apstatr (py, PYMAGERR)) + call pargi (pier) + call pargstr (Memc[str]) + + # Write the polygon characteristics + #call apstats (py, PYNAME, Memc[pyname], SZ_FNAME) + call apstats (py, PYROOT, Memc[pyname], SZ_FNAME) + call fprintf (fd, PY_WSTR3) + if (Memc[pyname] == EOS) + call pargstr ("nullfile") + else + call pargstr (Memc[pyname]) + call pargi (pid) + call pargr (apstatr (py, OPYXMEAN)) + call pargr (apstatr (py, OPYYMEAN)) + call pargr (apstatr (py, OPYCX)) + call pargr (apstatr (py, OPYCY)) + call pargr (apstatr (py, PYMINRAD)) + call pargi (apstati (py, PYNVER)) + + # Write out the vertices of the polygon. + if (nver == 0) { + call fprintf (fd, PY_WSTR4) + call pargr (INDEFR) + call pargr (INDEFR) + call pargstr (" ") + } else { + do i = 1, nver { + call fprintf (fd, PY_WSTR4) + if (nver == 1) { + call pargr (xver[i]) + call pargr (yver[i]) + call pargstr (" ") + } else if (i == nver) { + call pargr (xver[i]) + call pargr (yver[i]) + call pargstr ("* ") + } else { + call pargr (xver[i]) + call pargr (yver[i]) + call pargstr ( "*\\") + } + } + } + + call sfree (sp) +end + + +# AP_SPYERRORS -- Encode the polygon fitting error in a string. + +procedure ap_spyerrors (ier, str, maxch) + +int ier # error code +char str[ARB] # output string +int maxch # maximum number of characters + +begin + switch (ier) { + case PY_NOPOLYGON: + call strcpy ("NoPolygon", str, maxch) + case PY_OUTOFBOUNDS: + call strcpy ("EdgeImage", str, maxch) + case PY_NOPIX: + call strcpy ("NoPixels", str, maxch) + case PY_NOSKYMODE: + call strcpy ("NoSky", str, maxch) + case PY_BADDATA: + call strcpy ("BadPixels", str, maxch) + default: + call strcpy ("NoError", str, maxch) + } +end diff --git a/noao/digiphot/apphot/aplib/apwres3.x b/noao/digiphot/apphot/aplib/apwres3.x new file mode 100644 index 00000000..757361dc --- /dev/null +++ b/noao/digiphot/apphot/aplib/apwres3.x @@ -0,0 +1,132 @@ +include "../lib/apphotdef.h" +include "../lib/radprofdef.h" +include "../lib/apphot.h" +include "../lib/radprof.h" + +# define the #N, #U and #K radprof strings + +define RP_NSTR1 "#N%4tPFWHM%14tINORM%29tTINORM%66tRIER%71tRERROR%80t\\\n" +define RP_USTR1 "#U%4tScale%14tcounts%29tcounts%66t##%71trerrors%80t\\\n" +define RP_FSTR1 "#F%4t%%-13.3f%14t%%-15.7f%29t%%-36.7f%66t%%-5d%71t\ +%%-9s%80t \n" +define RP_WSTR1 "%4t%-10.3f%-15.7g%-36.7g%-5d%-9.9s%80t\\\n" + +define RP_NSTR2 "#N%4tPRADIUS%14tINTENSITY%29tTINTENSITY%80t\\\n" +define RP_USTR2 "#U%4tscale%14tcounts%29tcounts%80t\\\n" +define RP_FSTR2 "#F%4t%%-13.3f%14t%%-15.7f%29t%%-15.7f%80t \n" +define RP_WSTR2 "%4t%-10.3f%-15.7g%-15.7g%79t%2s\n" + + +# AP_RHDR -- Print the radprof column header strings. + +procedure ap_rhdr (ap, fd) + +pointer ap # apphot descriptor (unused) +int fd # output file descriptor + +begin + if (fd == NULL) + return + call fprintf (fd, RP_NSTR1) + call fprintf (fd, RP_USTR1) + call fprintf (fd, RP_FSTR1) + call fprintf (fd, "#\n") + call fprintf (fd, RP_NSTR2) + call fprintf (fd, RP_USTR2) + call fprintf (fd, RP_FSTR2) + call fprintf (fd, "#\n") +end + + +# AP_WRRES -- Write the results of the radprof task to the output file. + +procedure ap_wrres (ap, fd, ier) + +pointer ap # pointer to apphot structure +int fd # output text file descriptor +int ier # radial profile error + +int i, nrpts +pointer sp, str, rprof +real apstatr() + +begin + # Initialize. + if (fd == NULL) + return + rprof = AP_RPROF(ap) + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + + # Print the radprof parameters. + call ap_srerrors (ier, Memc[str], SZ_LINE) + call fprintf (fd, RP_WSTR1) + call pargr (apstatr (ap, RPFWHM) / apstatr (ap, SCALE)) + call pargr (apstatr (ap, INORM)) + call pargr (apstatr (ap, TNORM)) + call pargi (ier) + call pargstr (Memc[str]) + + # Print the radial profile. + nrpts = apstatr (ap, RPRADIUS) / apstatr (ap, RPSTEP) + 1 + if (nrpts == 0) { + call fprintf (fd, RP_WSTR2) + call pargr (INDEFR) + call pargr (INDEFR) + call pargr (INDEFR) + call pargstr (" ") + } else { + do i = 1, nrpts { + if (nrpts == 1) { + call fprintf (fd, RP_WSTR2) + call pargr (Memr[AP_RPDIST(rprof)+i-1] / AP_SCALE(ap)) + call pargr (Memr[AP_INTENSITY(rprof)+i-1]) + call pargr (Memr[AP_TINTENSITY(rprof)+i-1]) + call pargstr (" ") + } if (i == nrpts) { + call fprintf (fd, RP_WSTR2) + call pargr (Memr[AP_RPDIST(rprof)+i-1] / AP_SCALE(ap)) + call pargr (Memr[AP_INTENSITY(rprof)+i-1]) + call pargr (Memr[AP_TINTENSITY(rprof)+i-1]) + call pargstr ("* ") + } else { + call fprintf (fd, RP_WSTR2) + call pargr (Memr[AP_RPDIST(rprof)+i-1] / AP_SCALE(ap)) + call pargr (Memr[AP_INTENSITY(rprof)+i-1]) + call pargr (Memr[AP_TINTENSITY(rprof)+i-1]) + call pargstr ("*\\") + } + } + } + + call sfree (sp) +end + + +# AP_SRERRORS -- Encode the radial profile error message in a string. + +procedure ap_srerrors (ier, str, maxch) + +int ier # error code +char str[ARB] # encoded error string +int maxch # maximum number of characters + +begin + switch (ier) { + case AP_RP_NOPROFILE: + call sprintf (str, maxch, "%s") + call pargstr ("OffImage") + case AP_RP_OUTOFBOUNDS: + call sprintf (str, maxch, "%s") + call pargstr ("EdgeImage") + case AP_RP_NPTS_TOO_SMALL: + call sprintf (str, maxch, "%s") + call pargstr ("TooFewPts") + case AP_RP_SINGULAR: + call sprintf (str, maxch, "%s") + call pargstr ("Singular") + default: + call sprintf (str, maxch, "%s") + call pargstr ("NoError") + } +end diff --git a/noao/digiphot/apphot/aplib/apwres4.x b/noao/digiphot/apphot/aplib/apwres4.x new file mode 100644 index 00000000..67276ea1 --- /dev/null +++ b/noao/digiphot/apphot/aplib/apwres4.x @@ -0,0 +1,238 @@ +include "../lib/apphotdef.h" +include "../lib/fitpsfdef.h" +include "../lib/apphot.h" +include "../lib/fitpsf.h" + +# define the #N, #U and #K fitpsf strings + +define PSF_RNSTR1 "#N%4tXCENTER%14tYCENTER%24tRSIGMA%33tAMPLITUDE%48t\ +SKY%80t\\\n" +define PSF_RUSTR1 "#U%4tpixels%14tpixels%24tpixels%33tcounts%48t\ +counts%80t\\\n" +define PSF_RFSTR1 "#F%4t%%-13.3f%14t%%-10.3f%24t%%-9.2f%33t%%-15.7g%48t\ +%%-15.7g%80t \n" +define PSF_RWSTR1 "%4t%-10.3f%14t%-10.3f%24t%-9.2f%33t%-15.7g%48t\ +%-15.7g%80t\\\n" + +define PSF_RNSTR2 "#N%4tEXCENTER%14tEYCENTER%24tERSIGMA%33tEAMPLITUDE%48t\ +ESKY%63tIER%68tERROR%80t\\\n" +define PSF_RUSTR2 "#U%4tpixels%14tpixels%24tpixels%33tcounts%48t\ +counts%63t##%68terrors%80t\\\n" +define PSF_RFSTR2 "#F%4t%%-13.3f%14t%%-10.3f%24t%%-9.3f%33t%%-15.7g%48t\ +%%-15.7g%63t%%-5d%68t%%-13s%80t \n" +define PSF_RWSTR2 "%4t%-10.3f%14t%-10.3f%24t%-9.3f%33t%-15.7g%48t\ +%-15.7g%63t%-5d%68t%-13.13s\n" + +define PSF_ENSTR1 "#N%4tXCENTER%14tYCENTER%24tXSIGMA%33tYSIGMA%42t\ +ROT%49tAMPLITUDE%64tSKY%80t\\\n" +define PSF_EUSTR1 "#U%4tpixels%14tpixels%24tpixels%33tpixels%42t\ +deg%49tcounts%64tcounts%80t\\\n" +define PSF_EFSTR1 "#F%4t%%-13.3f%14t%%-10.3f%24t%%-9.2f%33t%%-9.2f%42t\ +%%-7.2f%49t%%-15.7g%64t%%-15.7g%80t \n" +define PSF_EWSTR1 "%4t%-10.3f%-10.3f%-9.2f%-9.2f%-7.2f%-15.7g%-15.7g%80t\\\n" + +define PSF_ENSTR2 "#N%4tEXCENTER%14tEYCENTER%24tEXSIGMA%33tEYSIGMA%42t\ +EROT%49tEAMPLITDE%64tESKY%80t\\\n" +define PSF_EUSTR2 "#U%4tpixels%14tpixels%24tpixels%33tpixels%42t\ +deg%49tcounts%64tcounts%80t\\\n" +define PSF_EFSTR2 "#F%4t%%-13.3f%14t%%-10.3f%24t%%-9.3f%33t%%-9.3f%42t\ +%%-7.2f%49t%%-15.7g%64t%%-15.7g%80t \n" +define PSF_EWSTR2 "%4t%-10.3f%-10.3f%-9.3f%-9.3f%-7.2f%-15.7g%-15.7g%80t\\\n" + +define PSF_ENSTR3 "#N%4tIER%9tERROR%80t\\\n" +define PSF_EUSTR3 "#U%4t##%9terrors%80t\\\n" +define PSF_EFSTR3 "#F%4t%%-8d%9t%%-13s%80t \n" +define PSF_EWSTR3 "%4t%-5d%-13.13s%80t \n" + + +define PSF_MNSTR1 "#N%4tXCENTER%14tYCENTER%24tRGYRAT%33tELLIP%42t\ +ROT%49tAMPLITUDE%64tSKY%80t\\\n" +define PSF_MUSTR1 "#U%4tpixels%14tpixels%24tpixels%33tratio%42tdeg%49t\ +counts%64tcounts%80t\\\n" +define PSF_MFSTR1 "#F%4t%%-13.3f%14t%%-10.3f%24t%%-9.2f%33t%%-9.2f%42t\ +%%-7.2f%49t%%-15.7g%64t%%-15.7f%80t \n" +define PSF_MWSTR1 "%4t%-10.3f%-10.3f%-9.2f%-9.2f%-7.2f%-15.7g%-15.7g%80t\\\n" + +define PSF_MNSTR2 "#N%4tEXCENTER%14tEYCENTER%24tERGYRAT%33tEELLIP%42t\ +EROT%49tEAMPLITUDE%64tESKY%80t\\\n" +define PSF_MUSTR2 "#U%4tpixels%14tpixels%24tpixels%33tratio%42tdeg%49t\ +counts%64tcounts%80t\\\n" +define PSF_MFSTR2 "#F%4t%%-13.3f%14t%%-10.3f%24t%%-9.3f%33t%%-9.3f%42t\ +%%-7.2f%49t%%-15.7g%64t%%-15.7g%80t \n" +define PSF_MWSTR2 "%4t%-10.3f%-10.3f%-9.3f%-9.3f%-7.2f%-15.7g%-15.7g%80t\\\n" + +define PSF_MNSTR3 "#N%4tIER%9tERROR%80t\\\n" +define PSF_MUSTR3 "#U%4t##%9terrors%80t\\\n" +define PSF_MFSTR3 "#F%4t%%-8d%9t%%-13s%80t \n" +define PSF_MWSTR3 "%4t%-5d%-13.13s%80t \n" + + +# AP_WFRES -- Write the results of the fitpsf task to the output file. + +procedure ap_wfres (ap, fd, ier) + +pointer ap # pointer to apphot structure +int fd # output file descriptor +int ier # comment string + +pointer psf + +begin + # Initialize. + if (fd == NULL) + return + psf = AP_PPSF(ap) + + # Print the parameters. + switch (AP_PSFUNCTION(psf)) { + case AP_RADGAUSS: + call fprintf (fd, PSF_RWSTR1) + call pargr (Memr[AP_PPARS(psf)+1]) + call pargr (Memr[AP_PPARS(psf)+2]) + call pargr (Memr[AP_PPARS(psf)+3]) + call pargr (Memr[AP_PPARS(psf)]) + call pargr (Memr[AP_PPARS(psf)+4]) + call fprintf (fd, PSF_RWSTR2) + call pargr (Memr[AP_PPERRS(psf)+1]) + call pargr (Memr[AP_PPERRS(psf)+2]) + call pargr (Memr[AP_PPERRS(psf)+3]) + call pargr (Memr[AP_PPERRS(psf)]) + call pargr (Memr[AP_PPERRS(psf)+4]) + call pargi (ier) + case AP_ELLGAUSS: + call fprintf (fd, PSF_EWSTR1) + call pargr (Memr[AP_PPARS(psf)+1]) + call pargr (Memr[AP_PPARS(psf)+2]) + call pargr (Memr[AP_PPARS(psf)+3]) + call pargr (Memr[AP_PPARS(psf)+4]) + call pargr (Memr[AP_PPARS(psf)+5]) + call pargr (Memr[AP_PPARS(psf)]) + call pargr (Memr[AP_PPARS(psf)+6]) + call fprintf (fd, PSF_EWSTR2) + call pargr (Memr[AP_PPERRS(psf)+1]) + call pargr (Memr[AP_PPERRS(psf)+2]) + call pargr (Memr[AP_PPERRS(psf)+3]) + call pargr (Memr[AP_PPERRS(psf)+4]) + call pargr (Memr[AP_PPERRS(psf)+5]) + call pargr (Memr[AP_PPERRS(psf)]) + call pargr (Memr[AP_PPERRS(psf)+6]) + call fprintf (fd, PSF_EWSTR3) + call pargi (ier) + case AP_MOMENTS: + call fprintf (fd, PSF_MWSTR1) + call pargr (Memr[AP_PPARS(psf)+1]) + call pargr (Memr[AP_PPARS(psf)+2]) + call pargr (Memr[AP_PPARS(psf)+3]) + call pargr (Memr[AP_PPARS(psf)+4]) + call pargr (Memr[AP_PPARS(psf)+5]) + call pargr (Memr[AP_PPARS(psf)]) + call pargr (Memr[AP_PPARS(psf)+6]) + call fprintf (fd, PSF_MWSTR2) + call pargr (Memr[AP_PPERRS(psf)+1]) + call pargr (Memr[AP_PPERRS(psf)+2]) + call pargr (Memr[AP_PPERRS(psf)+3]) + call pargr (Memr[AP_PPERRS(psf)+4]) + call pargr (Memr[AP_PPERRS(psf)+5]) + call pargr (Memr[AP_PPERRS(psf)]) + call pargr (Memr[AP_PPERRS(psf)+6]) + call fprintf (fd, PSF_MWSTR3) + call pargi (ier) + default: + ; + } + + # Print the error message. + switch (ier) { + case AP_NOPSFAREA: + call pargstr ("OffImage") + case AP_PSF_OUTOFBOUNDS: + call pargstr ("EdgeImage") + case AP_NPSF_TOO_SMALL: + call pargstr ("TooFewPts") + case AP_PSF_SINGULAR: + call pargstr ("Singular") + case AP_PSF_NOCONVERGE: + call pargstr ("BadFit") + default: + call pargstr ("NoError") + } +end + + +# RADHDR -- Write the column headers for the radial gaussian function. + +procedure radhdr (ap, fd) + +pointer ap # pointer to apphot structure +int fd # output file descriptor + +begin + # Print the keyword names. + call ap_idhdr (ap, fd) + + call fprintf (fd, PSF_RNSTR1) + call fprintf (fd, PSF_RUSTR1) + call fprintf (fd, PSF_RFSTR1) + call fprintf (fd, "#\n") + + call fprintf (fd, PSF_RNSTR2) + call fprintf (fd, PSF_RUSTR2) + call fprintf (fd, PSF_RFSTR2) + call fprintf (fd, "#\n") +end + + +# ELHDR -- Write the column headers for the elliptical gaussian function. + +procedure elhdr (ap, fd) + +pointer ap # pointer to apphot structure +int fd # output file descriptor + +begin + # Print the keywords. + call ap_idhdr (ap, fd) + + call fprintf (fd, PSF_ENSTR1) + call fprintf (fd, PSF_EUSTR1) + call fprintf (fd, PSF_EFSTR1) + call fprintf (fd, "#\n") + + call fprintf (fd, PSF_ENSTR2) + call fprintf (fd, PSF_EUSTR2) + call fprintf (fd, PSF_EFSTR2) + call fprintf (fd, "#\n") + + call fprintf (fd, PSF_ENSTR3) + call fprintf (fd, PSF_EUSTR3) + call fprintf (fd, PSF_EFSTR3) + call fprintf (fd, "#\n") +end + + +# MOMHDR -- Write the column headers for the moments function. + +procedure momhdr (ap, fd) + +pointer ap # pointer to apphot structure +int fd # output file descriptor + +begin + # Print the keywords. + call ap_idhdr (ap, fd) + + call fprintf (fd, PSF_MNSTR1) + call fprintf (fd, PSF_MUSTR1) + call fprintf (fd, PSF_MFSTR1) + call fprintf (fd, "#\n") + + call fprintf (fd, PSF_MNSTR2) + call fprintf (fd, PSF_MUSTR2) + call fprintf (fd, PSF_MFSTR2) + call fprintf (fd, "#\n") + + call fprintf (fd, PSF_MNSTR3) + call fprintf (fd, PSF_MUSTR3) + call fprintf (fd, PSF_MFSTR3) + call fprintf (fd, "#\n") +end diff --git a/noao/digiphot/apphot/aplib/mkpkg b/noao/digiphot/apphot/aplib/mkpkg new file mode 100644 index 00000000..a426075f --- /dev/null +++ b/noao/digiphot/apphot/aplib/mkpkg @@ -0,0 +1,102 @@ +# APPHOT Library Tools + +$checkout libpkg.a ".." +$update libpkg.a +$checkin libpkg.a ".." +$exit + +libpkg.a: + apairmass.x <imhdr.h> ../lib/apphot.h + apapcolon.x <error.h> ../lib/apphot.h + aparrays.x ../lib/phot.h ../lib/photdef.h \ + ../lib/apphotdef.h + apfree.x ../lib/apphotdef.h + apgaperts.x <lexnum.h> <ctype.h> + apgqverify.x <ttyset.h> <fset.h> + apgsvw.x <imio.h> <imhdr.h> \ + <math.h> + apgtverify.x + apinit.x ../lib/apphotdef.h ../lib/apphot.h \ + ../lib/noisedef.h ../lib/noise.h \ + ../lib/displaydef.h + apinpars1.x ../lib/apphot.h ../lib/noise.h \ + ../lib/find.h ../lib/display.h + apinpars2.x ../lib/display.h ../lib/center.h \ + ../lib/fitsky.h ../lib/phot.h \ + ../lib/polyphot.h + apitime.x ../lib/apphot.h <imhdr.h> + apfilter.x <imhdr.h> ../lib/apphot.h + apimbuf.x ../lib/apphotdef.h + apmark1.x <gset.h> ../lib/center.h \ + ../lib/fitsky.h ../lib/apphot.h \ + ../lib/phot.h ../lib/polyphot.h \ + ../lib/radprof.h + apmark2.x <gset.h> ../lib/apphot.h \ + ../lib/fitpsf.h + apnew.x ../lib/apphot.h + apnscolon.x <error.h> ../lib/noise.h + apnshow.x ../lib/apphot.h ../lib/noise.h + apotime.x ../lib/apphot.h <imhdr.h> + apoutpars1.x ../lib/apphot.h ../lib/noise.h \ + ../lib/display.h ../lib/find.h + apoutpars2.x ../lib/display.h ../lib/center.h \ + ../lib/fitsky.h ../lib/phot.h \ + ../lib/polyphot.h + apqrad.x ../lib/apphot.h ../lib/center.h \ + <mach.h> + appadu.x ../lib/noise.h <imhdr.h> + aprcursor1.x ../lib/apphot.h ../lib/noise.h \ + ../lib/center.h ../lib/fitsky.h \ + ../lib/phot.h + aprcursor2.x ../lib/apphot.h ../lib/fitpsf.h \ + ../lib/radprof.h + aprdnoise.x ../lib/noise.h <imhdr.h> + apset.x + apset1.x ../lib/center.h ../lib/centerdef.h \ + ../lib/fitsky.h ../lib/apphot.h \ + ../lib/apphotdef.h ../lib/fitskydef.h \ + ../lib/phot.h ../lib/photdef.h \ + ../lib/fitpsfdef.h ../lib/fitpsf.h + apset2.x ../lib/apphot.h ../lib/apphotdef.h \ + ../lib/display.h ../lib/polyphot.h \ + ../lib/radprofdef.h ../lib/radprof.h \ + ../lib/polyphotdef.h ../lib/noisedef.h \ + ../lib/noise.h ../lib/finddef.h \ + ../lib/find.h ../lib/displaydef.h + apstat.x + apstat1.x ../lib/center.h ../lib/centerdef.h \ + ../lib/fitsky.h ../lib/apphot.h \ + ../lib/apphotdef.h ../lib/fitskydef.h \ + ../lib/phot.h ../lib/photdef.h \ + ../lib/fitpsfdef.h ../lib/fitpsf.h + apstat2.x ../lib/apphot.h ../lib/apphotdef.h \ + ../lib/display.h ../lib/polyphot.h \ + ../lib/radprofdef.h ../lib/radprof.h \ + ../lib/polyphotdef.h ../lib/noisedef.h \ + ../lib/noise.h ../lib/finddef.h \ + ../lib/find.h ../lib/displaydef.h + apshowplot.x ../lib/apphot.h + apverify1.x <math.h> ../lib/apphot.h \ + ../lib/center.h ../lib/fitsky.h \ + ../lib/phot.h ../lib/noise.h + apverify2.x ../lib/apphot.h ../lib/fitpsf.h \ + ../lib/noise.h ../lib/find.h \ + ../lib/radprof.h + apwres1.x ../lib/apphot.h ../lib/find.h \ + ../lib/center.h ../lib/fitsky.h + apwres2.x ../lib/apphotdef.h ../lib/photdef.h \ + ../lib/apphot.h ../lib/fitsky.h \ + ../lib/phot.h ../lib/polyphot.h + apwres3.x ../lib/apphotdef.h ../lib/radprofdef.h \ + ../lib/apphot.h ../lib/radprof.h + apwres4.x ../lib/apphotdef.h ../lib/fitpsfdef.h \ + ../lib/fitpsf.h ../lib/apphot.h + apwparam1.x <time.h> ../lib/apphot.h \ + ../lib/noise.h ../lib/center.h \ + ../lib/fitsky.h ../lib/phot.h \ + ../lib/apphotdef.h + apwparam2.x ../lib/apphotdef.h ../lib/polyphot.h \ + ../lib/radprof.h ../lib/fitpsf.h + apimkeys.x ../lib/apphot.h + apwcs.x ../lib/apphot.h <imio.h> + ; diff --git a/noao/digiphot/apphot/apphot.cl b/noao/digiphot/apphot/apphot.cl new file mode 100644 index 00000000..d4b3b94f --- /dev/null +++ b/noao/digiphot/apphot/apphot.cl @@ -0,0 +1,58 @@ +#{ APPHOTX -- Digital aperture photometry package. + +dataio # rfits task required by aptest.cl script +lists # lintran task in the lists package + +package apphot + +task center, + daofind, + fitpsf, + fitsky, + radprof, + phot, + polymark, + polyphot, + qphot, + wphot = "apphot$x_apphot.e" + +task centerpars = "apphot$centerpars.par" +task datapars = "apphot$datapars.par" +task findpars = "apphot$findpars.par" +task fitskypars = "apphot$fitskypars.par" +task photpars = "apphot$photpars.par" +task polypars = "apphot$polypars.par" + +task aptest = "apphot$aptest.cl" + +# PTOOLS tasks + +task pexamine = "apphot$x_ptools.e" + +task pconvert, + istable, + txcalc, + txdump, + txrenumber, + txselect, + txsort = "ptools$x_ptools.e" + +task xyplot = "ptools$xyplot.par" +task histplot = "ptools$histplot.par" +task radplot = "ptools$radplot.par" +task surfplot = "ptools$surfplot.par" +task cntrplot = "ptools$cntrplot.par" + +# PTOOLS scripts which depend on PTOOLS and TTOOLS tasks +# Note TTOOLS is not loaded + +task pcalc = "ptools$pcalc.cl" +task pdump = "ptools$pdump.cl" +task prenumber = "ptools$prenumber.cl" +task pselect = "ptools$pselect.cl" +task psort = "ptools$psort.cl" + +hidetask istable, txcalc, txdump, txrenumber, txselect, txsort +hidetask xyplot, histplot, radplot, surfplot, cntrplot + +clbye() diff --git a/noao/digiphot/apphot/apphot.hd b/noao/digiphot/apphot/apphot.hd new file mode 100644 index 00000000..6061b68d --- /dev/null +++ b/noao/digiphot/apphot/apphot.hd @@ -0,0 +1,34 @@ +# Help directory for the APPHOT package + +$doc = "./doc/" + +$aptest = "apphot$aptest/" +$center = "apphot$center/" +$daofind = "apphot$daofind/" +$fitpsf = "apphot$fitpsf/" +$fitsky = "apphot$fitsky/" +$phot = "apphot$phot/" +$polyphot = "apphot$polyphot/" +$pexamine = "ptools$pexamine/" +$radprof = "apphot$radprof/" +$wphot = "apphot$wphot/" + +aptest hlp=doc$aptest.hlp +center hlp=doc$center.hlp, src=center$t_center.x +centerpars hlp=doc$centerpars.hlp, src=apphot$centerpars.par +daofind hlp=doc$daofind.hlp, src=daofind$t_daofind.x +datapars hlp=doc$datapars.hlp, src=apphot$datapars.par +findpars hlp=doc$findpars.hlp, src=apphot$findpars.par +fitpsf hlp=doc$fitpsf.hlp, src=fitpsf$t_fitpsf.x +fitsky hlp=doc$fitsky.hlp, src=fitsky$t_fitsky.x +fitskypars hlp=doc$fitskypars.hlp, src=apphot$fitskypars.par +pexamine hlp=doc$pexamine.hlp, src=pexamine$t_pexamine.x +phot hlp=doc$phot.hlp, src=phot$t_phot.x +photpars hlp=doc$photpars.hlp, src=apphot$photpars.par +polymark hlp=doc$polymark.hlp, src=polyphot$t_polymark.x +polyphot hlp=doc$polyphot.hlp, src=polyphot$t_polyphot.x +polypars hlp=doc$polypars.hlp, src=apphot$polypars.par +qphot hlp=doc$qphot.hlp, src=phot$t_qphot.x +radprof hlp=doc$radprof.hlp, src=radprof$t_radprof.x +wphot hlp=doc$wphot.hlp, src=wphot$t_wphot.x +revisions sys=Revisions diff --git a/noao/digiphot/apphot/apphot.men b/noao/digiphot/apphot/apphot.men new file mode 100644 index 00000000..e83c00ff --- /dev/null +++ b/noao/digiphot/apphot/apphot.men @@ -0,0 +1,26 @@ + aptest - Run basic tests on the apphot package tasks + center - Compute accurate centers for a list of objects + centerpars - Edit the centering parameters + daofind - Find stars in an image using the dao algorithm + datapars - Edit the data dependent parameters + findpars - Edit the star detection parameters + fitpsf - Model the stellar psf with an analytic function + fitsky - Compute sky values in a list of annular or circular regions + fitskypars - Edit the sky fitting parameters + phot - Measure magnitudes for a list of stars + photpars - Edit the photometry parameters + polymark - Create polygon lists for polyphot + polyphot - Measure magnitudes inside a list of polygonal regions + polypars - Edit the polyphot parameters + qphot - Measure quick magnitudes for a list of stars + radprof - Compute the stellar radial profile of a list of stars + wphot - Measure magnitudes for a list of stars with weighting + + lintran - Linearly transform a coordinate list + pcalc - Do arithmetic operations on a list of apphot databases + pconvert - Convert a text database to a tables database + pdump - Print selected fields from a list of apphot databases + pexamine - Interactively examine and edit an apphot database + prenumber - Renumber stars in an apphot database + pselect - Select records from an apphot database + psort - Sort an apphot database diff --git a/noao/digiphot/apphot/apphot.par b/noao/digiphot/apphot/apphot.par new file mode 100644 index 00000000..ba37d156 --- /dev/null +++ b/noao/digiphot/apphot/apphot.par @@ -0,0 +1,11 @@ +# APPHOTX package parameter file + +version,s,h,"May00" +wcsin,s,h,logical,"logical|tv|physical|world",,"The input coordinates wcs" +wcsout,s,h,logical,"logical|tv|physical",,"The output coordinates wcs" +cache,b,h,no,,,"Cache image in memory ?" +verify,b,h,yes,,,"Verify critical parameters ?" +update,b,h,no,,,"Update critial parameters ?" +verbose,b,h,no,,,"Print verbose output ?" +graphics,s,h,stdgraph,,,"Default graphics device" +display,s,h,stdimage,,,"Default display device" diff --git a/noao/digiphot/apphot/aptest.cl b/noao/digiphot/apphot/aptest.cl new file mode 100644 index 00000000..58dad449 --- /dev/null +++ b/noao/digiphot/apphot/aptest.cl @@ -0,0 +1,220 @@ +# APTEST - Self testing procedure for the APPHOT package. + +procedure aptest (imname) + +string imname {prompt="Name of the output test image"} +string aplogfile {"", prompt="Name of the output log file"} +string applotfile {"", prompt="Name of the output plot file"} + +begin + # Declare local variables. + string im, aplog, applot, apcoords + + # Check that the user truly wants to proceed. + s1 = "" + print ("") + print ("APTEST INITIALIZES THE APPHOT TASK PARAMETERS") + print ("TYPE q or Q TO QUIT, ANY OTHER KEY TO PROCEED") + if (scan (s1) != EOF) { + if (s1 == "q" || s1 == "Q") { + print ("TERMINATING THE APTEST TASK") + bye + } + } + print ("") + + # Define some local variables. + im = imname + aplog = aplogfile + if (aplog == "") { + aplog = im // ".log" + } + applot = applotfile + if (applot == "") { + applot = im // ".plot" + } + + # Read in the fits file and check for existance of the log and + # plot files. + if (! access (im // ".imh") && ! access (im // ".hhh")) { + rfits ("apphot$test/fits3.fits", "0", im, make_image=yes, + long_header=no, short_header=yes, datatype="",blank=0, + scale=yes,oldirafname=no,offset=0, >& "dev$null") + } else { + error (0, "Error: The image already exists on disk") + } + if (access (aplog)) { + error (0, "Error: The log file already exists on disk") + } + if (access (applot)) { + error (0, "Error: The plot file already exists on disk") + } + + # Initialize the APPHOT package. + print ("INITIALIZE THE APPHOT PACKAGE", >> aplog) + print ("", >> aplog) + print ("") + print ("INITIALIZE THE APPHOT PACKAGE") + print ("") + + unlearn ("txdump") + unlearn ("center") + unlearn ("centerpars") + unlearn ("daofind") + unlearn ("datapars") + unlearn ("findpars") + unlearn ("fitpsf") + unlearn ("fitsky") + unlearn ("fitskypars") + unlearn ("phot") + unlearn ("photpars") + unlearn ("polymark") + unlearn ("polyphot") + unlearn ("polypars") + unlearn ("qphot") + unlearn ("radprof") + unlearn ("wphot") + + # Test the DAOFIND task. + + print ("TESTING THE DAOFIND TASK", >> aplog) + print ("TESTING THE DAOFIND TASK") + print ("", >> aplog) + + datapars.fwhmpsf=2.354820 + datapars.sigma=10.0 + findpars.threshold=3.0 + + apcoords = im // ".coo.1" + daofind (im, output=apcoords, interactive-, verify-) + concat (apcoords, aplog, append=yes) + + # Test the CENTER task. + + print ("", >> aplog) + print ("TESTING THE CENTER TASK", >> aplog) + print ("TESTING THE CENTER TASK") + print ("", >> aplog) + + center (im, coords=apcoords, interactive-, verify-) + concat (im // ".ctr.1", aplog, append=yes) + delete (im // ".ctr.1", ver-, >& "dev$null") + + # Test the FITSKY task. + + print ("", >> aplog) + print ("TESTING THE FITSKY TASK", >> aplog) + print ("TESTING THE FITSKY TASK") + print ("", >> aplog) + + fitskypars.annulus=6.0 + fitskypars.dannulus=7.0 + + fitsky (im, coords=apcoords, interactive-, verify-) + concat (im // ".sky.1", aplog, append=yes) + delete (im // ".sky.1", ver-, >& "dev$null") + + # Test the QPHOT task. + + print ("", >> aplog) + print ("TESTING THE QPHOT TASK", >> aplog) + print ("TESTING THE QPHOT TASK") + print ("", >> aplog) + + qphot (im, 5.0, 6.0, 7.0, "3.0,5.0", coords=apcoords, interactive-) + concat (im // ".mag.1", aplog, append=yes) + delete (im // ".mag.1", ver-, >& "dev$null") + + # Test the PHOT task. + + print ("", >> aplog) + print ("TESTING THE PHOT TASK", >> aplog) + print ("TESTING THE PHOT TASK") + print ("", >> aplog) + + photpars.apertures="3.0,5.0" + + phot (im, coords=apcoords, interactive-, verify-) + concat (im // ".mag.1", aplog, append=yes) + delete (im // ".mag.1", ver-, >& "dev$null") + + # Test the WPHOT task. + + print ("", >> aplog) + print ("TESTING THE WPHOT TASK", >> aplog) + print ("TESTING THE WPHOT TASK") + print ("", >> aplog) + + photpars.weighting="gauss" + + wphot (im, coords=apcoords, interactive-, verify-) + concat (im // ".omag.1", aplog, append=yes) + delete (im // ".omag.1", ver-, >& "dev$null") + + # Test the POLYPHOT task. + + print ("", >> aplog) + print ("TESTING THE POLYPHOT TASK", >> aplog) + print ("TESTING THE POLYPHOT TASK") + print ("", >> aplog) + print ("COPY OF THE POLYGONS FILE", >> aplog) + print ("", >> aplog) + concat ("apphot$test/polygons.dat", aplog, append=yes) + print ("", >> aplog) + + polyphot (im, coords=apcoords, polygons="apphot$test/polygons.dat", + interactive-, verify-) + concat (im // ".ply.1", aplog, append=yes) + delete (im // ".ply.1", ver-, >& "dev$null") + + # Test the RADPROF task. + + print ("", >> aplog) + print ("TESTING THE RADPROF TASK", >> aplog) + print ("TESTING THE RADPROF TASK") + print ("", >> aplog) + + radprof (im, 8.0, 0.25, coords=apcoords, output="default", + plotfile=applot, order=4, nreject=3, kreject=3.0, interactive-, + verify-) + concat (im // ".prf.1", aplog, append=yes) + delete (im // ".prf.1", ver-, >& "dev$null") + + # Test the FITPSF task. + + print ("", >> aplog) + print ("TESTING THE FITPSF TASK", >> aplog) + print ("TESTING THE FITPSF TASK") + print ("", >> aplog) + + fitpsf (im, 7.0, coords=apcoords, interactive-, verify-) + concat (im // ".psf.1", aplog, append=yes) + delete (im // ".psf.1", ver-, >& "dev$null") + + print ("", >> aplog) + print ("APPHOT PACKAGE TESTS COMPLETED", >> aplog) + print ("") + print ("APPHOT PACKAGE TESTS COMPLETED") + print ("", >> aplog) + + # Clean up. + delete (apcoords, ver-, >& "dev$null") + unlearn ("txdump") + unlearn ("center") + unlearn ("centerpars") + unlearn ("daofind") + unlearn ("datapars") + unlearn ("findpars") + unlearn ("fitpsf") + unlearn ("fitsky") + unlearn ("fitskypars") + unlearn ("phot") + unlearn ("photpars") + unlearn ("polymark") + unlearn ("polyphot") + unlearn ("polypars") + unlearn ("qphot") + unlearn ("radprof") + unlearn ("wphot") + bye +end diff --git a/noao/digiphot/apphot/aputil/apbsmooth.x b/noao/digiphot/apphot/aputil/apbsmooth.x new file mode 100644 index 00000000..28c53c00 --- /dev/null +++ b/noao/digiphot/apphot/aputil/apbsmooth.x @@ -0,0 +1,33 @@ +# AP_BSMOOTH - Box car smooth a histogram 1, 2 or 3 times. + +procedure ap_bsmooth (hgm, shgm, nbins, nker, iter) + +real hgm[ARB] # the original histogram +real shgm[ARB] # the smoothed histogram +int nbins # length of the histogram +int nker # half width of box kernel +int iter # number of iterations + +pointer sp, work1, work2 + +begin + # Smooth the histogram + switch (iter) { + case 1: + call ap_sboxr (hgm, shgm, nbins, nker) + case 2: + call smark (sp) + call salloc (work1, nbins, TY_REAL) + call ap_sboxr (hgm, Memr[work1], nbins, nker) + call ap_sboxr (Memr[work1], shgm, nbins, nker) + call sfree (sp) + default: + call smark (sp) + call salloc (work1, nbins, TY_REAL) + call salloc (work2, nbins, TY_REAL) + call ap_sboxr (hgm, Memr[work1], nbins, nker) + call ap_sboxr (Memr[work1], Memr[work2], nbins, nker) + call ap_sboxr (Memr[work2], shgm, nbins, nker) + call sfree (sp) + } +end diff --git a/noao/digiphot/apphot/aputil/apclip.x b/noao/digiphot/apphot/aputil/apclip.x new file mode 100644 index 00000000..62a52c30 --- /dev/null +++ b/noao/digiphot/apphot/aputil/apclip.x @@ -0,0 +1,23 @@ +# AP_CLIP -- Clip the ends of a sorted pixel distribution by a certain +# percent. + +int procedure ap_clip (skypix, index, npix, loclip, hiclip, loindex, hiindex) + +real skypix[ARB] # the unsorted array of sky pixels +int index[ARB] # the array of sorted indices +int npix # the number of sky pixels +real loclip, hiclip # the clipping factors in percent +int loindex, hiindex # the clipping indices + +begin + # Sort the pixels. + call apqsort (skypix, index, index, npix) + + # Determine the clipping factors. + loindex = nint (0.01 * loclip * npix) + 1 + hiindex = npix - nint (0.01 * hiclip * npix) + if ((hiindex - loindex + 1) <= 0) + return (npix) + else + return (loindex - 1 + npix - hiindex) +end diff --git a/noao/digiphot/apphot/aputil/apdate.x b/noao/digiphot/apphot/aputil/apdate.x new file mode 100644 index 00000000..21faea88 --- /dev/null +++ b/noao/digiphot/apphot/aputil/apdate.x @@ -0,0 +1,29 @@ +include <time.h> + +# APDATE -- Fetch the date and time strings required for the apphot output +# files. + +procedure apdate (date, time, maxch) + +char date[ARB] # the date string +char time[ARB] # the time string +int maxch # the maximum number of character in the string + +int tm[LEN_TMSTRUCT] +long ctime +long clktime() +#long lsttogmt() + +begin + ctime = clktime (long(0)) + #ctime = lsttogmt (ctime) + call brktime (ctime, tm) + call sprintf (date, maxch, "%04d-%02d-%02d") + call pargi (TM_YEAR(tm)) + call pargi (TM_MONTH(tm)) + call pargi (TM_MDAY(tm)) + call sprintf (time, maxch, "%02d:%02d:%02d") + call pargi (TM_HOUR(tm)) + call pargi (TM_MIN(tm)) + call pargi (TM_SEC(tm)) +end diff --git a/noao/digiphot/apphot/aputil/apdiverr.x b/noao/digiphot/apphot/aputil/apdiverr.x new file mode 100644 index 00000000..d3c36444 --- /dev/null +++ b/noao/digiphot/apphot/aputil/apdiverr.x @@ -0,0 +1,7 @@ +# AP_DIVERR -- Error condition procedure which returns a value of unity. + +real procedure ap_diverr () + +begin + return (1.0) +end diff --git a/noao/digiphot/apphot/aputil/apfnames.x b/noao/digiphot/apphot/aputil/apfnames.x new file mode 100644 index 00000000..95e56167 --- /dev/null +++ b/noao/digiphot/apphot/aputil/apfnames.x @@ -0,0 +1,280 @@ + +# APINNAME -- Construct an apphot input file name. +# If input is null or a directory, a name is constructed from the root +# of the image name and the extension. The disk is searched to avoid +# name collisions. + +procedure apinname (image, input, ext, name, maxch) + +char image[ARB] # image name +char input[ARB] # input directory or name +char ext[ARB] # extension +char name[ARB] # input name +int maxch # maximum size of name + +int ndir, nimdir, clindex, clsize +pointer sp, root, str +int fnldir(), strlen() + +begin + call smark (sp) + call salloc (root, SZ_FNAME, TY_CHAR) + call salloc (str, SZ_FNAME, TY_CHAR) + + ndir = fnldir (input, name, maxch) + if (strlen (input) == ndir) { + call imparse (image, Memc[root], SZ_FNAME, Memc[str], SZ_FNAME, + Memc[str], SZ_FNAME, clindex, clsize) + nimdir = fnldir (Memc[root], Memc[str], SZ_FNAME) + if (clindex >= 0) { + call sprintf (name[ndir+1], maxch, "%s%d.%s.*") + call pargstr (Memc[root+nimdir]) + call pargi (clindex) + call pargstr (ext) + } else { + call sprintf (name[ndir+1], maxch, "%s.%s.*") + call pargstr (Memc[root+nimdir]) + call pargstr (ext) + } + call apiversion (name, name, maxch) + } else + call strcpy (input, name, maxch) + + call sfree (sp) +end + + +# APOUTNAME -- Construct an apphot output file name. +# If output is null or a directory, a name is constructed from the root +# of the image name and the extension. The disk is searched to avoid +# name collisions. + +procedure apoutname (image, output, ext, name, maxch) + +char image[ARB] # image name +char output[ARB] # output directory or name +char ext[ARB] # extension +char name[ARB] # output name +int maxch # maximum size of name + +int ndir, nimdir, clindex, clsize +pointer sp, root, str +int fnldir(), strlen() + +begin + call smark (sp) + call salloc (root, SZ_FNAME, TY_CHAR) + call salloc (str, SZ_FNAME, TY_CHAR) + + ndir = fnldir (output, name, maxch) + if (strlen (output) == ndir) { + call imparse (image, Memc[root], SZ_FNAME, Memc[str], SZ_FNAME, + Memc[str], SZ_FNAME, clindex, clsize) + nimdir = fnldir (Memc[root], Memc[str], SZ_FNAME) + if (clindex >= 0) { + call sprintf (name[ndir+1], maxch, "%s%d.%s.*") + call pargstr (Memc[root+nimdir]) + call pargi (clindex) + call pargstr (ext) + } else { + call sprintf (name[ndir+1], maxch, "%s.%s.*") + call pargstr (Memc[root+nimdir]) + call pargstr (ext) + } + call apoversion (name, name, maxch) + } else + call strcpy (output, name, maxch) + + call sfree (sp) +end + + +# APTMPIMAGE -- Generate a temporary image name either by calling a system +# routine or by appending the image name to a user specified prefix. + +int procedure aptmpimage (image, prefix, tmp, name, maxch) + +char image[ARB] # image name +char prefix[ARB] # user supplied prefix +char tmp[ARB] # user supplied temporary root +char name[ARB] # output name +int maxch # max number of chars + +int npref, ndir, nimdir, clindex, clsize +pointer sp, root, str +int fnldir(), strlen() + +begin + npref = strlen (prefix) + ndir = fnldir (prefix, name, maxch) + if (npref == ndir) { + call mktemp (tmp, name[ndir+1], maxch) + return (NO) + } else { + call smark (sp) + call salloc (root, SZ_FNAME, TY_CHAR) + call salloc (str, SZ_FNAME, TY_CHAR) + call strcpy (prefix, name, npref) + call imparse (image, Memc[root], SZ_FNAME, Memc[str], SZ_FNAME, + Memc[str], SZ_FNAME, clindex, clsize) + nimdir = fnldir (Memc[root], Memc[str], SZ_FNAME) + if (clindex >= 0) { + call sprintf (name[npref+1], maxch, "%s%d") + call pargstr (Memc[root+nimdir]) + call pargi (clindex) + } else { + call sprintf (name[npref+1], maxch, "%s") + call pargstr (Memc[root+nimdir]) + } + call sfree (sp) + return (YES) + } +end + + +# APIMROOT -- Fetch the root image name minus the directory specification +# and the section notation. + +procedure apimroot (image, root, maxch) + +char image[ARB] # image specification +char root[ARB] # output root name +int maxch # maximum number of characters + +pointer sp, imroot, kernel, section, str +int clindex, clsize, nchars +int fnldir() + +begin + call smark (sp) + call salloc (imroot, SZ_PATHNAME, TY_CHAR) + call salloc (kernel, SZ_FNAME, TY_CHAR) + call salloc (section, SZ_FNAME, TY_CHAR) + call salloc (str, SZ_PATHNAME, TY_CHAR) + + call imparse (image, Memc[imroot], SZ_PATHNAME, Memc[kernel], SZ_FNAME, + Memc[section], SZ_FNAME, clindex, clsize) + nchars = fnldir (Memc[imroot], Memc[str], SZ_PATHNAME) + if (clindex >= 0) { + call sprintf (root, maxch, "%s[%d]%s%s") + call pargstr (Memc[imroot+nchars]) + call pargi (clindex) + call pargstr (Memc[kernel]) + call pargstr (Memc[section]) + } else { + call sprintf (root, maxch, "%s%s%s") + call pargstr (Memc[imroot+nchars]) + call pargstr (Memc[kernel]) + call pargstr (Memc[section]) + } + + call sfree (sp) +end + + + +# APFROOT -- Fetch the file name minus the directory specification, + +procedure apfroot (filename, root, maxch) + +char filename[ARB] # input file name +char root[ARB] # output root file name +int maxch # maximum number of characters + +pointer sp, str +int nchars +int fnldir() + +begin + call smark (sp) + call salloc (str, SZ_PATHNAME, TY_CHAR) + + nchars = fnldir (filename, Memc[str], SZ_PATHNAME) + call strcpy (filename[nchars+1], root, maxch) + + call sfree (sp) +end + + +# APOVERSION -- Compute the next available version number of a given file +# name template and output the new file name. + +procedure apoversion (template, filename, maxch) + +char template[ARB] # name template +char filename[ARB] # output name +int maxch # maximum number of characters + +char period +int newversion, version, len +pointer sp, list, name +int fntgfnb() strldx(), ctoi(), fntopnb() + +begin + # Allocate temporary space + call smark (sp) + call salloc (name, maxch, TY_CHAR) + period = '.' + list = fntopnb (template, NO) + + # Loop over the names in the list searchng for the highest version. + newversion = 0 + while (fntgfnb (list, Memc[name], maxch) != EOF) { + len = strldx (period, Memc[name]) + len = len + 1 + if (ctoi (Memc[name], len, version) <= 0) + next + newversion = max (newversion, version) + } + + # Make new output file name. + len = strldx (period, template) + call strcpy (template, filename, len) + call sprintf (filename[len+1], maxch, "%d") + call pargi (newversion + 1) + + call fntclsb (list) + call sfree (sp) +end + + +# APIVERSION -- Compute the highest available version number of a given file +# name template and output the file name. + +procedure apiversion (template, filename, maxch) + +char template[ARB] # name template +char filename[ARB] # output name +int maxch # maximum number of characters + +char period +int newversion, version, len +pointer sp, list, name +int fntgfnb() strldx(), ctoi(), fntopnb() + +begin + # Allocate temporary space + call smark (sp) + call salloc (name, maxch, TY_CHAR) + period = '.' + list = fntopnb (template, NO) + + # Loop over the names in the list searchng for the highest version. + newversion = 0 + while (fntgfnb (list, Memc[name], maxch) != EOF) { + len = strldx (period, Memc[name]) + len = len + 1 + if (ctoi (Memc[name], len, version) <= 0) + next + newversion = max (newversion, version) + } + + # Make new output file name. + len = strldx (period, template) + call strcpy (template, filename, len) + call sprintf (filename[len+1], maxch, "%d") + call pargi (newversion) + + call fntclsb (list) + call sfree (sp) +end diff --git a/noao/digiphot/apphot/aputil/apgscur.x b/noao/digiphot/apphot/aputil/apgscur.x new file mode 100644 index 00000000..5cc8a6df --- /dev/null +++ b/noao/digiphot/apphot/aputil/apgscur.x @@ -0,0 +1,88 @@ +include <gset.h> +include <fset.h> + +# APGSCUR -- Read the x and y coordinates of an object from a file and move +# the cursor to those coordinates. + +int procedure apgscur (sl, gd, xcur, ycur, prev_num, req_num, num) + +int sl # coordinate file descriptor +pointer gd # pointer to graphics stream +real xcur, ycur # x cur and y cur +int prev_num # previous number +int req_num # requested number +int num # list number + +int stdin, nskip, ncount +pointer sp, fname +int fscan(), nscan(), strncmp() +errchk greactivate, gdeactivate, gscur + +begin + if (sl == NULL) + return (EOF) + + call smark (sp) + call salloc (fname, SZ_FNAME, TY_CHAR) + + # Find the number of objects to be skipped. + call fstats (sl, F_FILENAME, Memc[fname], SZ_FNAME) + if (strncmp ("STDIN", Memc[fname], 5) == 0) { + stdin = YES + nskip = 1 + } else { + stdin = NO + if (req_num <= prev_num) { + call seek (sl, BOF) + nskip = req_num + } else + nskip = req_num - prev_num + } + + # Initialize. + ncount = 0 + num = prev_num + + # Read the coordinates and write the cursor. + repeat { + + # Print the prompt if file is STDIN. + if (stdin == YES) { + call printf ("Type object x and y coordinates: ") + call flush (STDOUT) + } + + # Fetch the coordinates. + if (fscan (sl) != EOF) { + call gargr (xcur) + call gargr (ycur) + if (nscan () == 2) { + ncount = ncount + 1 + num = num + 1 + } + } else + ncount = EOF + + # Move the cursor. + if (gd != NULL && (ncount == nskip || ncount == EOF)) { + iferr { + call greactivate (gd, 0) + call gscur (gd, xcur, ycur) + call gdeactivate (gd, 0) + } then + ; + } + + } until (ncount == EOF || ncount == nskip) + + call sfree (sp) + + if (ncount == EOF) { + return (EOF) + } else if (nskip == req_num) { + num = ncount + return (ncount) + } else { + return (num) + } +end diff --git a/noao/digiphot/apphot/aputil/apgtools.x b/noao/digiphot/apphot/aputil/apgtools.x new file mode 100644 index 00000000..e35cb543 --- /dev/null +++ b/noao/digiphot/apphot/aputil/apgtools.x @@ -0,0 +1,141 @@ +include <gset.h> +include <pkg/gtools.h> + +# AP_GTINIT -- Initialize the gtools package for the apphot routines. + +pointer procedure ap_gtinit (image, wx, wy) + +char image[ARB] # the image name +real wx, wy # center of sky subraster + +pointer sp, gt, str +pointer gt_init() + +begin + # Allocate working space. + gt = gt_init () + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + + # Set the plot title. + call sprintf (Memc[str], SZ_LINE, "Image: %s: %.2f %.2f\n") + call pargstr (image) + call pargr (wx) + call pargr (wy) + call gt_sets (gt, GTTITLE, Memc[str]) + + call sfree (sp) + return (gt) +end + + +# AP_GTFREE -- Free the gtools package. + +procedure ap_gtfree (gt) + +pointer gt # pointer to gtools structure + +begin + call gt_free (gt) +end + + +# AP_PLOTRAD -- Plot the radial profile of a list of pixels. + +procedure ap_plotrad (gd, gt, r, i, npts, polymark) + +pointer gd # pointer to graphics stream +pointer gt # the GTOOLS pointer +real r[ARB] # the radii array +real i[ARB] # the intensity array +int npts # number of points +char polymark[ARB] # polyline type + +begin + call gt_sets (gt, GTTYPE, "mark") + call gt_sets (gt, GTMARK, polymark) + call gt_plot (gd, gt, r, i, npts) +end + + +# AP_PLOTPTS -- Plot the radial profile of a list of pixels excluding points +# that are outside the plotting window altogether. + +procedure ap_plotpts (gd, gt, r, i, npts, xmin, xmax, ymin, ymax, polymark) + +pointer gd # pointer to graphics stream +pointer gt # the GTOOLS pointer +real r[ARB] # the radii array +real i[ARB] # the intensity array +int npts # number of points +real xmin, xmax # the x plot limits +real ymin, ymax # the y plot limits +char polymark[ARB] # polyline type + +int j + +begin + call gt_sets (gt, GTTYPE, "mark") + call gt_sets (gt, GTMARK, polymark) + do j = 1, npts { + if (r[j] < xmin || r[j] > xmax) + next + if (i[j] < ymin || i[j] > ymax) + next + call gt_plot (gd, gt, r[j], i[j], 1) + + } +end + + +# AP_RSET -- Set up the parameters for the radial profile plot. + +procedure ap_rset (gd, gt, xmin, xmax, ymin, ymax, xscale) + +pointer gd # pointer to GRAPHICS stream +pointer gt # pointer to GTOOLS structure +real xmin, xmax # min and max of x vector +real ymin, ymax # min and max of y vector +real xscale # image scale + +pointer sp, str, title +real vx1, vx2, vy1, vy2, aspect +real gstatr() + +begin + call smark (sp) + call salloc (title, 3 * SZ_LINE, TY_CHAR) + call salloc (str, SZ_LINE, TY_CHAR) + + # Reset the aspect ratio. + aspect = gstatr (gd, G_ASPECT) + call gsetr (gd, G_ASPECT, 0.75) + + # Construct the title. + call sysid (Memc[title], 3 * SZ_LINE) + call strcat ("\n", Memc[title], 3 * SZ_LINE) + call gt_gets (gt, GTTITLE, Memc[str], SZ_LINE) + call strcat (Memc[str], Memc[title], 3 * SZ_LINE) + call strcat ("\n\n", Memc[title], 3 * SZ_LINE) + + # Draw three axes. + call gseti (gd, G_XDRAWAXES, 2) + call gswind (gd, xmin / xscale, xmax / xscale, ymin, ymax) + call glabax (gd, Memc[title], "", "Intensity") + + # Draw the bottom x axis + call gseti (gd, G_YDRAWAXES, 0) + call gseti (gd, G_XDRAWAXES, 1) + call ggview (gd, vx1, vx2, vy1, vy2) + call gsview (gd, vx1, vx2, vy1, vy2) + call gswind (gd, xmin, xmax, ymin, ymax) + call glabax (gd, "", + "Radial Distance (lower-pixels, upper-scale units)", "") + + # Reset to standard gio parameters. + call gseti (gd, G_YDRAWAXES, 3) + call gseti (gd, G_XDRAWAXES, 3) + call gsetr (gd, G_ASPECT, aspect) + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/aputil/aplucy.x b/noao/digiphot/apphot/aputil/aplucy.x new file mode 100644 index 00000000..f70a39ed --- /dev/null +++ b/noao/digiphot/apphot/aputil/aplucy.x @@ -0,0 +1,47 @@ +# AP_LUCY_SMOOTH - Lucy smooth a histogram with a box shaped function. + +procedure ap_lucy_smooth (hgm, shgm, nbins, nker, iter) + +real hgm[ARB] # the original histogram +real shgm[ARB] # smoothed histogram +int nbins # length of the histogram +int nker # length of box kernel +int iter # number of iterations + +int i, j, nsmooth +pointer sp, work1, work2 +real ap_diverr() + +begin + # Allocate space and clear the work arrays. + call smark (sp) + call salloc (work1, nbins, TY_REAL) + call salloc (work2, nbins, TY_REAL) + call aclrr (Memr[work1], nbins) + call aclrr (Memr[work2], nbins) + call aclrr (shgm, nbins) + + # Compute the smoothing length and initialize output array. + nsmooth = nbins - nker + 1 + #call ap_aboxr (hgm, shgm[1+nker/2], nsmooth, nker) + call ap_sboxr (hgm, shgm, nbins, nker) + + # Iterate on the solution. + do i = 1, iter { + #call ap_aboxr (shgm, Memr[work1+nker/2], nsmooth, nker) + call ap_sboxr (shgm, Memr[work1], nbins, nker) + #do j = 1 + nker / 2, nsmooth + nker / 2 { + do j = 1, nbins { + if (Memr[work1+j-1] == 0.0) + Memr[work1+j-1] = ap_diverr () + else + #Memr[work1+j-1] = hgm[j] / Memr[work1+j-1] + Memr[work1+j-1] = shgm[j] / Memr[work1+j-1] + } + #call ap_aboxr (Memr[work1], Memr[work2+nker/2], nsmooth, nker) + call ap_sboxr (Memr[work1], Memr[work2], nbins, nker) + call amulr (shgm, Memr[work2], shgm, nbins) + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/aputil/apmapr.x b/noao/digiphot/apphot/aputil/apmapr.x new file mode 100644 index 00000000..0d4159ab --- /dev/null +++ b/noao/digiphot/apphot/aputil/apmapr.x @@ -0,0 +1,21 @@ +# APMAPR -- Vector linear transformation. Map the range of pixel values +# a1, a2 from a into the range b1, b2 into b. It is assumed that a1 < a2 +# and b1 < b2. + +real procedure apmapr (a, a1, a2, b1, b2) + +real a # the value to be mapped +real a1, a2 # the numbers specifying the input data range +real b1, b2 # the numbers specifying the output data range + +real minout, maxout, aoff, boff +real scalar + +begin + scalar = (real (b2) - real (b1)) / (real (a2) - real (a1)) + minout = min (b1, b2) + maxout = max (b1, b2) + aoff = a1 + boff = b1 + return (max(minout, min(maxout, real((a - aoff) * scalar) + boff))) +end diff --git a/noao/digiphot/apphot/aputil/apmeds.x b/noao/digiphot/apphot/aputil/apmeds.x new file mode 100644 index 00000000..0a206c8a --- /dev/null +++ b/noao/digiphot/apphot/aputil/apmeds.x @@ -0,0 +1,154 @@ +# APSMED -- Compute the averaged median given a sorted array and an averaging +# half width. + +real procedure apsmed (pix, index, npts, medcut) + +real pix[ARB] # array of sky pixels +int index[ARB] # sorted index array +int npts # number of pixels +int medcut # averaging half width + +int med, j, nmed, medlo, medhi +real sumed + +begin + med = (npts + 1) / 2 + if (mod (med, 2) == 1) { + medlo = max (1, med - medcut) + medhi = min (npts, med + medcut) + } else { + medlo = max (1, med - medcut) + medhi = min (npts, med + medcut + 1) + } + + sumed = 0.0 + nmed = 0 + do j = medlo, medhi { + sumed = sumed + pix[index[j]] + nmed = nmed + 1 + } + + return (sumed / nmed) +end + + +# APIMED -- Compute the index of new median value. Weight is an arbitrary +# weight array which is assumed to be zero if the pixels has been rejected +# and is positive otherwise. + +int procedure apimed (weight, index, lo, hi, nmed) + +real weight[ARB] # array of weights +int index[ARB] # array of sorted indices +int lo, hi # ranges of weights +int nmed # number of good sky pixels + +int npts, med + +begin + npts = 0 + for (med = lo; med <= hi && npts < nmed; med = med + 1) { + if (weight[index[med]] > 0.0) + npts = npts + 1 + } + + if (npts == 0) + return (0) + else + return (med) +end + + +# APWSMED -- Compute the new averaged median given a sorted input array, +# an averaging half-width, and assuming that there has been pixel rejection. + +real procedure apwsmed (pix, index, weight, npix, med, medcut) + +real pix[ARB] # pixel values array +int index[ARB] # sorted indices array +real weight[ARB] # the weights array +int npix # number of pixels +int med # index of median value +int medcut # of median cut + +int j, nmed, maxmed +real sumed + +begin + sumed = pix[index[med]] + if (mod (med, 2) == 1) + maxmed = 2 * medcut + 1 + else + maxmed = 2 * medcut + 2 + + nmed = 1 + for (j = med - 1; j >= 1; j = j - 1) { + if (nmed >= medcut + 1) + break + if (weight[index[j]] > 0.0) { + sumed = sumed + pix[index[j]] + nmed = nmed + 1 + } + } + for (j = med + 1; j <= npix; j = j + 1) { + if (nmed >= maxmed) + break + if (weight[index[j]] > 0.0) { + sumed = sumed + pix[index[j]] + nmed = nmed + 1 + } + } + + return (sumed / nmed) +end + + +# APMEDR -- Vector median selection. The selection is carried out in a temporary +# array, leaving the input vector unmodified. Especially demanding applications +# may wish to call the asok routine directory to avoid the call to the memory +# allocator. + +real procedure apmedr (a, index, npix) + +real a[ARB] # input array of values +int index[ARB] # sorted index array +int npix # number of pixels + +int i +pointer sp, aa +real median +real asokr() # select the Kth smallest element from A + +begin + switch (npix) { + case 1, 2: + return (a[1]) + + case 3: + if (a[1] < a[2]) { + if (a[2] < a[3]) + return (a[2]) + else if (a[1] < a[3]) + return (a[3]) + else + return (a[1]) + } else { + if (a[2] > a[3]) + return (a[2]) + else if (a[1] < a[3]) + return (a[1]) + else + return (a[3]) + } + + default: + call smark (sp) + call salloc (aa, npix, TY_REAL) + do i = 1, npix + Memr[aa+i-1] = a[index[i]] + median = asokr (Memr[aa], npix, (npix + 1) / 2) + call sfree (sp) + + return (median) + } +end diff --git a/noao/digiphot/apphot/aputil/apmoments.x b/noao/digiphot/apphot/aputil/apmoments.x new file mode 100644 index 00000000..5a1bfbd4 --- /dev/null +++ b/noao/digiphot/apphot/aputil/apmoments.x @@ -0,0 +1,138 @@ +# APMOMENTS -- Procedure to compute the first three moments of a +# distribution given the appropriate sums. + +procedure apmoments (sumpx, sumsqpx, sumcbpx, npix, sky_zero, mean, sigma, skew) + +double sumpx # sum of the pixels +double sumsqpx # sum of pixels squared +double sumcbpx # sum of cubes of pixels +int npix # number of pixels +real sky_zero # sky zero point for moment analysis +real mean # mean of pixels +real sigma # sigma of pixels +real skew # skew of pixels + +double dmean, dsigma, dskew + +begin + # Recompute the moments. + dmean = sumpx / npix + dsigma = sumsqpx / npix - dmean ** 2 + if (dsigma <= 0.0d0) { + sigma = 0.0 + skew = 0.0 + } else { + dskew = sumcbpx / npix - 3.0d0 * dmean * dsigma - dmean ** 3 + sigma = sqrt (dsigma) + if (dskew < 0.0d0) + skew = - (abs (dskew) ** (1.0d0 / 3.0d0)) + else if (dskew > 0.0d0) + skew = dskew ** (1.0d0 / 3.0d0) + else + skew = 0.0 + } + mean = sky_zero + dmean +end + + +# APFMOMENTS -- Procedure to compute the first three moments of a distribution +# given the data. The sums are returned as well. + +procedure apfmoments (pix, npix, sky_zero, sumpx, sumsqpx, sumcbpx, mean, + sigma, skew) + +real pix[npix] # array of pixels +int npix # number of pixels +real sky_zero # sky zero point for moment analysis +double sumpx # sum of the pixels +double sumsqpx # sum of pixels squared +double sumcbpx # sum of cubes of pixels +real mean # mean of pixels +real sigma # sigma of pixels +real skew # skew of pixels + +double dpix, dmean, dsigma, dskew +int i + +begin + # Zero and accumulate the sums. + sumpx = 0.0d0 + sumsqpx = 0.0d0 + sumcbpx = 0.0d0 + do i = 1, npix { + dpix = pix[i] - sky_zero + sumpx = sumpx + dpix + sumsqpx = sumsqpx + dpix * dpix + sumcbpx = sumcbpx + dpix * dpix * dpix + } + + # Compute the moments. + dmean = sumpx / npix + dsigma = sumsqpx / npix - dmean ** 2 + if (dsigma <= 0.0) { + sigma = 0.0 + skew = 0.0 + } else { + dskew = sumcbpx / npix - 3.0d0 * dmean * dsigma - dmean ** 3 + sigma = sqrt (dsigma) + if (dskew < 0.0d0) + skew = - (abs (dskew) ** (1.0d0 / 3.0d0)) + else if (dskew > 0.0d0) + skew = dskew ** (1.0d0 / 3.0d0) + else + skew = 0.0 + } + mean = sky_zero + dmean +end + + +# APFIMOMENTS -- Procedure to compute the first three moments of a distribution +# given the data. The sums are returned as well. + +procedure apfimoments (pix, index, npix, sky_zero, sumpx, sumsqpx, sumcbpx, + mean, sigma, skew) + +real pix[ARB] # array of pixels +int index[ARB] # the index array +int npix # number of pixels +real sky_zero # sky zero point for moment analysis +double sumpx # sum of the pixels +double sumsqpx # sum of pixels squared +double sumcbpx # sum of cubes of pixels +real mean # mean of pixels +real sigma # sigma of pixels +real skew # skew of pixels + +double dpix, dmean, dsigma, dskew +int i + +begin + # Zero and accumulate the sums. + sumpx = 0.0d0 + sumsqpx = 0.0d0 + sumcbpx = 0.0d0 + do i = 1, npix { + dpix = pix[index[i]] - sky_zero + sumpx = sumpx + dpix + sumsqpx = sumsqpx + dpix * dpix + sumcbpx = sumcbpx + dpix * dpix * dpix + } + + # Compute the moments. + dmean = sumpx / npix + dsigma = sumsqpx / npix - dmean ** 2 + if (dsigma <= 0.0d0) { + sigma = 0.0 + skew = 0.0 + } else { + dskew = sumcbpx / npix - 3.0d0 * dmean * dsigma - dmean ** 3 + sigma = sqrt (dsigma) + if (dskew < 0.0d0) + skew = - (abs (dskew) ** (1.0d0 / 3.0d0)) + else if (dskew > 0.0d0) + skew = dskew ** (1.0d0 / 3.0d0) + else + skew = 0.0 + } + mean = dmean + sky_zero +end diff --git a/noao/digiphot/apphot/aputil/apnlfuncs.x b/noao/digiphot/apphot/aputil/apnlfuncs.x new file mode 100644 index 00000000..290b9e90 --- /dev/null +++ b/noao/digiphot/apphot/aputil/apnlfuncs.x @@ -0,0 +1,375 @@ + +include <math.h> +include <mach.h> + +# CGAUSS1D - Compute the value of a 1-D Gaussian function on a constant +# background. + +procedure cgauss1d (x, nvars, p, np, z) + +real x[ARB] # variables, x[1] = position coordinate +int nvars # the number of variables, not used +real p[ARB] # p[1]=amplitude p[2]=center p[3]=variance p[4]=sky +int np # number of parameters np = 4 +real z # function return + +real r2 + +begin + if (p[3] == 0.) + r2 = 36.0 + else + r2 = (x[1] - p[2]) ** 2 / (2. * p[3]) + if (abs (r2) > 25.0) + z = p[4] + else + z = p[1] * exp (-r2) + p[4] +end + + +# CDGAUSS1D -- Compute the value a 1-D Gaussian profile on a constant +# background and its derivatives. + +procedure cdgauss1d (x, nvars p, dp, np, z, der) + +real x[ARB] # variables, x[1] = position coordinate +int nvars # the number of variables, not used +real p[ARB] # p[1]=amplitude, p[2]=center, p[3]=sky p[4]=variance +real dp[ARB] # parameter derivatives +int np # number of parameters np=4 +real z # function value +real der[ARB] # derivatives + +real dx, r2 + +begin + dx = x[1] - p[2] + if (p[3] == 0.) + r2 = 36.0 + else + r2 = dx * dx / (2.0 * p[3]) + if (abs (r2) > 25.0) { + z = p[4] + der[1] = 0.0 + der[2] = 0.0 + der[3] = 0.0 + der[4] = 1.0 + } else { + der[1] = exp (-r2) + z = p[1] * der[1] + der[2] = z * dx / p[3] + der[3] = z * r2 / p[3] + der[4] = 1.0 + z = z + p[4] + } +end + + +# GAUSSR -- Compute the value of a 2-D radially symmetric Gaussian profile +# which is assumed to be sitting on a constant background. + +# Parameter Allocation: +# 1 Amplitude +# 2 X-center +# 3 Y-center +# 4 Variance +# 5 Sky + +procedure gaussr (x, nvars, p, np, z) + +real x[ARB] # the input variables +int nvars # the number of variables +real p[np] # parameter vector +int np # number of parameters +real z # function return + +real dx, dy, r2 + +begin + dx = x[1] - p[2] + dy = x[2] - p[3] + if (p[4] == 0.) + r2 = 36.0 + else + r2 = (dx * dx + dy * dy) / (2.0 * p[4]) + if (abs (r2) > 25.0) + z = p[5] + else + z = p[1] * exp (- r2) + p[5] +end + + +# DGAUSSR -- Compute the value of a 2-D Gaussian profile and its derivatives +# which assumed to be sitting on top of a constant background. + +procedure dgaussr (x, nvars, p, dp, np, z, der) + +real x[ARB] # the input variables +int nvars # the number of variables +real p[np] # parameter vector +real dp[np] # dummy array of parameter increments +int np # number of parameters +real z # function return +real der[np] # derivatives + +real dx, dy, r2 + +begin + dx = x[1] - p[2] + dy = x[2] - p[3] + if (p[4] == 0.) + r2 = 36.0 + else + r2 = (dx * dx + dy * dy) / (2.0 * p[4]) + + if (abs (r2) > 25.0) { + z = p[5] + der[1] = 0.0 + der[2] = 0.0 + der[3] = 0.0 + der[4] = 0.0 + der[5] = 1.0 + } else { + der[1] = exp (-r2) + z = p[1] * der[1] + der[2] = z * dx / p[4] + der[3] = z * dy / p[4] + der[4] = z * r2 / p[4] + z = z + p[5] + der[5] = 1.0 + } +end + + +# ELGAUSS -- Compute the value of a 2-D elliptical Gaussian function which +# is assumed to be sitting on top of a constant background. + +# Parameter Allocation: +# 1 Amplitude +# 2 X-center +# 3 Y-center +# 4 Variance-x +# 5 Variance-y +# 6 Theta-rotation +# 7 Sky + +procedure elgauss (x, nvars, p, np, z) + +real x[ARB] # input variables, x[1] = x, x[2] = y +int nvars # number of variables, not used +real p[np] # parameter vector +int np # number of parameters +real z # function return + +real dx, dy, crot, srot, xt, yt, r2 + +begin + dx = x[1] - p[2] + dy = x[2] - p[3] + crot = cos (p[6]) + srot = sin (p[6]) + xt = (dx * crot + dy * srot) + yt = (-dx * srot + dy * crot) + if (p[4] == 0. || p[5] == 0.) + r2 = 36.0 + else + r2 = (xt ** 2 / p[4] + yt ** 2 / p[5]) / 2.0 + if (abs (r2) > 25.0) + z = p[7] + else + z = p[1] * exp (-r2) + p[7] +end + + +# DELGAUSS -- Compute the value of a 2-D elliptical Gaussian assumed to +# sitting on top of a constant background and its derivatives. + +procedure delgauss (x, nvars, p, dp, np, z, der) + +real x[ARB] # input variables, x[1] = x, x[2] = y +int nvars # number of variables, not used +real p[np] # parameter vector +real dp[np] # delta of parameters +int np # number of parameters +real z # function value +real der[np] # function return + +real crot, srot, crot2, srot2, sigx2, sigy2, a, b, c +real dx, dy, dx2, dy2, r2 + +begin + crot = cos (p[6]) + srot = sin (p[6]) + crot2 = crot ** 2 + srot2 = srot ** 2 + sigx2 = p[4] + sigy2 = p[5] + if (sigx2 == 0. || sigy2 == 0.) + r2 = 36.0 + else { + a = (crot2 / sigx2 + srot2 / sigy2) + b = 2.0 * crot * srot * (1.0 / sigx2 - 1.0 /sigy2) + c = (srot2 / sigx2 + crot2 / sigy2) + + dx = x[1] - p[2] + dy = x[2] - p[3] + dx2 = dx ** 2 + dy2 = dy ** 2 + r2 = 0.5 * (a * dx2 + b * dx * dy + c * dy2) + } + + if (abs (r2) > 25.0) { + z = p[7] + der[1] = 0.0 + der[2] = 0.0 + der[3] = 0.0 + der[4] = 0.0 + der[5] = 0.0 + der[6] = 0.0 + der[7] = 1.0 + } else { + der[1] = exp (-r2) + z = p[1] * der[1] + der[2] = z * (2.0 * a * dx + b * dy) + der[3] = z * (b * dx + 2.0 * c * dy) + der[4] = z * (crot2 * dx2 + 2.0 * crot * srot * dx * dy + + srot2 * dy2) / (2.0 * sigx2 * sigx2) + der[5] = z * (srot2 * dx2 - 2.0 * crot * srot * dx * dy + + crot2 * dy2) / (2.0 * sigy2 * sigy2) + der[6] = z * (b * dx2 + 2.0 * (c - a) * dx * dy - b * dy2) + z = z + p[7] + der[7] = 1.0 + } +end + + + +# GAUSS1D -- Compute the profile of a 1d Gaussian with a background value +# of zero. + +procedure gauss1d (x, nvars, p, np, z) + +real x[ARB] # list of variables, x[1] = position coordinate +int nvars # number of variables +real p[ARB] # p[1]=amplitude p[2]=center p[3]=sigma +int np # number of parameters == 3 +real z # function return + +real r + +begin + if (p[3] == 0.) + r = 6.0 + else + r = (x[1] - p[2]) / (p[3] * SQRTOF2) + if (abs (r) > 5.0) + z = 0.0 + else + z = p[1] * exp (- r ** 2) +end + + +# DGAUSS1D -- Compute the function value and derivatives of a 1-D Gaussian +# function with a background value of zero. + +procedure dgauss1d (x, nvars, p, dp, np, z, der) + +real x[ARB] # list of variables, x[1] = position coordinate +int nvars # number of variables +real p[ARB] # p[1]=amplitude, p[2]=center, p[3]=sigma +real dp[ARB] # parameter derivatives +int np # number of parameters +real z # function value +real der[ARB] # derivatives + +real r + +begin + if (p[3] == 0.) + r = 6.0 + else + r = (x[1] - p[2]) / (SQRTOF2 * p[3]) + if (abs (r) > 5.0) { + z = 0.0 + der[1] = 0.0 + der[2] = 0.0 + der[3] = 0.0 + } else { + der[1] = exp (- r ** 2) + z = der[1] * p[1] + der[2] = z * r * SQRTOF2 / p[3] + der[3] = der[2] * SQRTOF2 * r + } +end + + +# GAUSSKEW - Compute the value of a 1-D skewed Gaussian profile. +# The background value is assumed to be zero. + +procedure gausskew (x, nvars, p, np, z) + +real x[ARB] # list of variables, x[1] = position coordinate +int nvars # number of variables, not used +real p[ARB] # p[1]=amplitude p[2]=center p[3]=variance p[4]=skew +int np # number of parameters == 3 +real z # function return + +real dx, r2, r3 + +begin + dx = (x[1] - p[2]) + if (p[3] == 0.) + r2 = 36.0 + else { + r2 = dx ** 2 / (2.0 * p[3]) + r3 = r2 * dx / sqrt (2.0 * abs (p[3])) + } + if (abs (r2) > 25.0) + z = 0.0 + else + z = (1.0 + p[4] * r3) * p[1] * exp (-r2) +end + + +# DGAUSSKEW -- Compute the value of a 1-D skewed Gaussian and its derivatives. +# The background value is assumed to be zero. + +procedure dgausskew (x, nvars, p, dp, np, z, der) + +real x[ARB] # list of variables, x[1] = position coordinate +int nvars # number of variables, not used +real p[ARB] # p[1]=amplitude, p[2]=center, p[3]=variance, p[4]=skew +real dp[ARB] # parameter derivatives +int np # number of parameters +real z # function value +real der[ARB] # derivatives + +real dx, d1, d2, d3, r, r2, r3, rint + +begin + dx = x[1] - p[2] + if (p[3] == 0.) + r2 = 36.0 + else + r2 = dx ** 2 / (2.0 * p[3]) + if (abs (r2) > 25.0) { + z = 0.0 + der[1] = 0.0 + der[2] = 0.0 + der[3] = 0.0 + der[4] = 0.0 + } else { + r = dx / sqrt (2.0 * abs (p[3])) + r3 = r2 * r + d1 = exp (-r2) + z = d1 * p[1] + d2 = z * dx / p[3] + d3 = z * r2 / p[3] + rint = 1.0 + p[4] * r3 + der[1] = d1 * rint + der[2] = d2 * (rint - 1.5 * p[4] * r) + der[3] = d3 * (rint - 1.5 * p[4] * r) + der[4] = z * r3 + z = z * rint + } +end diff --git a/noao/digiphot/apphot/aputil/appcache.x b/noao/digiphot/apphot/aputil/appcache.x new file mode 100644 index 00000000..d1059583 --- /dev/null +++ b/noao/digiphot/apphot/aputil/appcache.x @@ -0,0 +1,83 @@ +include <imhdr.h> +include <imset.h> + +# AP_MEMSTAT -- Figure out if there is enough memory to cache the image +# pixels. If it is necessary to request more memory and the memory is +# avalilable return YES otherwise return NO. + +int procedure ap_memstat (cache, req_size, old_size) + +int cache #I cache memory ? +int req_size #I the requested working set size in chars +int old_size #O the original working set size in chars + +int cur_size, max_size +int begmem() + +begin + # Find the default working set size. + cur_size = begmem (0, old_size, max_size) + + # If cacheing is disabled return NO regardless of the working set size. + if (cache == NO) + return (NO) + + # If the requested working set size is less than the current working + # set size return YES. + if (req_size <= cur_size) + return (YES) + + # Reset the current working set size. + cur_size = begmem (req_size, old_size, max_size) + if (req_size <= cur_size) { + return (YES) + } else { + return (NO) + } +end + + +# AP_PCACHE -- Cache the image pixels im memory by resetting the default image +# buffer size. If req_size is INDEF the size of the image is used to determine +# the size of the image i/o buffers. + +procedure ap_pcache (im, req_size, buf_size) + +pointer im #I the input image point +int req_size #I the requested working set size in chars +int buf_size #O the new image buffer size + +int def_size, new_imbufsize +int sizeof(), imstati() + +begin + # Find the default buffer size. + def_size = imstati (im, IM_BUFSIZE) + + # Return if the image is not 2-dimensional. + if (IM_NDIM(im) != 2) { + buf_size = def_size + return + } + + # Compute the new required image i/o buffer size in chars. + if (IS_INDEFI(req_size)) { + new_imbufsize = IM_LEN(im,1) * IM_LEN(im,2) * + sizeof (IM_PIXTYPE(im)) + } else { + new_imbufsize = req_size + } + + # If the default image i/o buffer size is already bigger than + # the requested size do nothing. + if (def_size >= new_imbufsize) { + buf_size = def_size + return + } + + # Reset the image i/o buffer. + call imseti (im, IM_BUFSIZE, new_imbufsize) + call imseti (im, IM_BUFFRAC, 0) + buf_size = new_imbufsize + return +end diff --git a/noao/digiphot/apphot/aputil/aprmwhite.x b/noao/digiphot/apphot/aputil/aprmwhite.x new file mode 100644 index 00000000..071ea7ed --- /dev/null +++ b/noao/digiphot/apphot/aputil/aprmwhite.x @@ -0,0 +1,22 @@ +include <ctype.h> + +# AP_RMWHITE -- Remove whitespace from a string. + +procedure ap_rmwhite (instr, outstr, maxch) + +char instr[ARB] # the input string +char outstr[ARB] # the output string, may be the same as instr +int maxch # maximum number of characters in outstr + +int ip, op + +begin + op = 1 + for (ip = 1; (instr[ip] != EOS) && (op <= maxch); ip = ip + 1) { + if (IS_WHITE(instr[ip])) + next + outstr[op] = instr[ip] + op = op + 1 + } + outstr[op] = EOS +end diff --git a/noao/digiphot/apphot/aputil/aptopt.x b/noao/digiphot/apphot/aputil/aptopt.x new file mode 100644 index 00000000..0e5bc212 --- /dev/null +++ b/noao/digiphot/apphot/aputil/aptopt.x @@ -0,0 +1,232 @@ +include <mach.h> +include <math.h> + +# APTOPT - One-dimensional centering routine using repeated convolutions to +# locate image center. + +define MAX_SEARCH 3 # Max initial search steps + +int procedure aptopt (data, npix, center, sigma, tol, maxiter, ortho) + +real data[ARB] # initial data +int npix # number of pixels +real center # initial guess at center +real sigma # sigma of Gaussian +real tol # gap tolerance for sigma +int maxiter # maximum number of iterations +int ortho # orthogonalize weighting vector + +int i, iter +pointer sp, wgt +real newx, x[3], news, s[3], delx +real adotr(), apqzero() + +begin + if (sigma <= 0.0) + return (-1) + + # Allocate working space. + call smark (sp) + call salloc (wgt, npix, TY_REAL) + + # Initialize. + x[1] = center + call mkt_prof_derv (Memr[wgt], npix, x[1], sigma, ortho) + s[1] = adotr (Memr[wgt], data, npix) + #if (abs (s[1]) <= EPSILONR) { + if (s[1] == 0.0) { + center = x[1] + call sfree (sp) + return (0) + } else + s[3] = s[1] + + # Search for the correct interval. + for (i = 1; (s[3] * s[1] >= 0.0) && (i <= MAX_SEARCH); i = i + 1) { + s[3] = s[1] + x[3] = x[1] + x[1] = x[3] + sign (sigma, s[3]) + call mkt_prof_derv (Memr[wgt], npix, x[1], sigma, ortho) + s[1] = adotr (Memr[wgt], data, npix) + #if (abs (s[1]) <= EPSILONR) { + if (s[1] == 0.0) { + center = x[1] + call sfree (sp) + return (0) + } + } + + # Location not bracketed. + if (s[3] * s[1] > 0.0) { + call sfree (sp) + return (-1) + } + + # Intialize the quadratic search. + delx = x[1] - x[3] + x[2] = x[3] - s[3] * delx / (s[1] - s[3]) + call mkt_prof_derv (Memr[wgt], npix, x[2], sigma, ortho) + s[2] = adotr (Memr[wgt], data, npix) + #if (abs (s[2]) <= EPSILONR) { + if (s[2] == 0.0) { + center = x[2] + call sfree (sp) + return (1) + } + + # Search quadratically. + for (iter = 2; iter <= maxiter; iter = iter + 1) { + + # Check for completion. + #if (abs (s[2]) <= EPSILONR) + if (s[2] == 0.0) + break + if (abs (x[2] - x[1]) <= tol) + break + if (abs (x[3] - x[2]) <= tol) + break + + # Compute new intermediate value. + newx = x[1] + apqzero (x, s) + call mkt_prof_derv (Memr[wgt], npix, newx, sigma, ortho) + news = adotr (Memr[wgt], data, npix) + + if (s[1] * s[2] > 0.0) { + s[1] = s[2] + x[1] = x[2] + s[2] = news + x[2] = newx + } else { + s[3] = s[2] + x[3] = x[2] + s[2] = news + x[2] = newx + } + } + + # Evaluate the center. + center = x[2] + call sfree (sp) + return (iter) +end + + +# AP_TPROFDER -- Procedure to estimate the approximating triangle function +# and its derivatives. + +procedure ap_tprofder (data, der, npix, center, sigma, ampl) + +real data[ARB] # input data +real der[ARB] # derivatives +int npix # number of pixels +real center # center of input Gaussian function +real sigma # sigma of input Gaussian function +real ampl # amplitude + +int i +real x, xabs, width + +begin + width = sigma * 2.35 + do i = 1, npix { + x = (i - center) / width + xabs = abs (x) + if (xabs <= 1.0) { + data[i] = ampl * (1.0 - xabs) + der[i] = x * data[i] + } else { + data[i] = 0.0 + der[i] = 0.0 + } + } +end + + +# MKT_PROF_DERV - Make orthogonal profile derivative vector. + +procedure mkt_prof_derv (weight, npix, center, sigma, norm) + +real weight[ARB] # input weight +int npix # number of pixels +real center # center +real sigma # center +int norm # orthogonalise weight + +pointer sp, der +real coef +real asumr(), adotr() + +begin + call smark (sp) + call salloc (der, npix, TY_REAL) + + # Fetch the weighting function and derivatives. + call ap_tprofder (Memr[der], weight, npix, center, sigma, 1.0) + + if (norm == YES) { + + # Make orthogonal to level background. + coef = -asumr (weight, npix) / npix + call aaddkr (weight, coef, weight, npix) + coef = -asumr (Memr[der], npix) / npix + call aaddkr (Memr[der], coef, Memr[der], npix) + + # Make orthogonal to profile vector. + coef = adotr (Memr[der], Memr[der], npix) + if (coef <= 0.0) + coef = 1.0 + else + coef = adotr (weight, Memr[der], npix) / coef + call amulkr (Memr[der], coef, Memr[der], npix) + call asubr (weight, Memr[der], weight, npix) + + # Normalize the final vector. + coef = adotr (weight, weight, npix) + if (coef <= 0.0) + coef = 1.0 + else + coef = sqrt (1.0 / coef) + call amulkr (weight, coef, weight, npix) + } + + call sfree (sp) +end + +define QTOL .125 + +# APQZERO - Solve for the root of a quadratic function defined by three +# points. + +real procedure apqzero (x, y) + +real x[3] +real y[3] + +real a, b, c, det, dx +real x2, x3, y2, y3 + +begin + # Compute the determinant. + x2 = x[2] - x[1] + x3 = x[3] - x[1] + y2 = y[2] - y[1] + y3 = y[3] - y[1] + det = x2 * x3 * (x2 - x3) + + # Compute the shift in x. + #if (abs (det) > 100.0 * EPSILONR) { + if (abs (det) > 0.0) { + a = (x3 * y2 - x2 * y3) / det + b = - (x3 * x3 * y2 - x2 * x2 * y3) / det + c = a * y[1] / (b * b) + if (abs (c) > QTOL) + dx = (-b / (2.0 * a)) * (1.0 - sqrt (1.0 - 4.0 * c)) + else + dx = - (y[1] / b) * (1.0 + c) + return (dx) + #} else if (abs (y3) > EPSILONR) + } else if (abs (y3) > 0.0) + return (-y[1] * x3 / y3) + else + return (0.0) +end diff --git a/noao/digiphot/apphot/aputil/apvectors.x b/noao/digiphot/apphot/aputil/apvectors.x new file mode 100644 index 00000000..7c9dbcfd --- /dev/null +++ b/noao/digiphot/apphot/aputil/apvectors.x @@ -0,0 +1,515 @@ + +# AP_ABOXR -- Vector boxcar smooth. The input vector is convolved with a +# uniform kernel of length knpix. Boundary extension is assumed to have +# been performed on the input array before entering the routine. + +procedure ap_aboxr (in, out, npix, knpix) + +real in[npix+knpix-1] # input array with boundary exntension +real out[npix] # output array +int npix # number of pixels +int knpix # length of the kernel + +int i +real sum + +begin + sum = 0.0 + do i = 1, knpix - 1 + sum = sum + in[i] + + do i = 1, npix { + sum = sum + in[i+knpix-1] + out[i] = sum / knpix + sum = sum - in[i] + } + +end + + +# AP_SBOXR -- Boxcar smooth for a vector that has not been boundary +# extended. + +procedure ap_sboxr (in, out, npix, nsmooth) + +real in[npix] # input array +real out[npix] # output array +int npix # number of pixels +int nsmooth # half width of smoothing box + +int i, j, ib, ie, ns +real sum + +begin + ns = 2 * nsmooth + 1 + do i = 1, npix { + ib = max (i - nsmooth, 1) + ie = min (i + nsmooth, npix) + sum = 0.0 + do j = ib, ie + sum = sum + in[j] + out[i] = sum / ns + } +end + + +# AP_ALIMR -- Compute the maximum and minimum data values and indices of a +# 1D array. + +procedure ap_alimr (data, npts, mindat, maxdat, imin, imax) + +real data[npts] # data array +int npts # number of points +real mindat, maxdat # min and max data value +int imin, imax # indices of min and max data values + +int i + +begin + imin = 1 + imax = 1 + mindat = data[1] + maxdat = data[1] + + do i = 2, npts { + if (data[i] > maxdat) { + imax = i + maxdat = data[i] + } + if (data[i] < mindat) { + imin = i + mindat = data[i] + } + } +end + + +# AP_IALIMR -- Compute the maximum and minimum data values of a 1D indexed +# array + +procedure ap_ialimr (data, index, npts, mindat, maxdat) + +real data[npts] # data array +int index[npts] # index array +int npts # number of points +real mindat, maxdat # min and max data value + +int i + +begin + mindat = data[index[1]] + maxdat = data[index[1]] + do i = 2, npts { + if (data[index[i]] > maxdat) + maxdat = data[index[i]] + if (data[index[i]] < mindat) + mindat = data[index[i]] + } +end + + +# AP_ASUMR - Compute the sum of an index sorted array + +real procedure ap_asumr (data, index, npts) + +real data[npts] # data array +int index[npts] # index array +int npts # number of points + +double sum +int i + +begin + sum = 0.0d0 + do i = 1, npts + sum = sum + data[index[i]] + return (real (sum)) +end + + +# AP_AMAXEL -- Find the maximum value and its index of a 1D array. + +procedure ap_amaxel (a, npts, maxdat, imax) + +real a[ARB] # the data array +int npts # number of points +real maxdat # maximum value +int imax # imdex of max value + +int i + +begin + maxdat = a[1] + imax = 1 + do i = 2, npts { + if (a[i] > maxdat) { + maxdat = a[i] + imax = i + } + } +end + + +# AHGMR -- Accumulate the histogram of the input vector. The output vector +# hgm (the histogram) should be cleared prior to the first call. The procedure +# returns the number of data values it could not include in the histogram. + +int procedure aphgmr (data, wgt, npix, hgm, nbins, z1, z2) + +real data[ARB] # data vector +real wgt[ARB] # weights vector +int npix # number of pixels +real hgm[ARB] # output histogram +int nbins # number of bins in histogram +real z1, z2 # greyscale values of first and last bins + +real dz +int bin, i, nreject + +begin + if (nbins < 2) + return (0) + + nreject = 0 + dz = real (nbins - 1) / real (z2 - z1) + do i = 1, npix { + if (data[i] < z1 || data[i] > z2) { + nreject = nreject + 1 + wgt[i] = 0.0 + next + } + bin = int ((data[i] - z1) * dz) + 1 + hgm[bin] = hgm[bin] + 1.0 + } + + return (nreject) +end + + +# APHIGMR -- Accumulate the histogram of the input vector. The output vector +# hgm (the histogram) should be cleared prior to the first call. The procedure +# returns the number of data values it could not include in the histogram. + +int procedure aphigmr (data, wgt, index, npix, hgm, nbins, z1, z2) + +real data[ARB] # data vector +real wgt[ARB] # weights vector +int index[ARB] # index vector +int npix # number of pixels +real hgm[ARB] # output histogram +int nbins # number of bins in histogram +real z1, z2 # greyscale values of first and last bins + +real dz +int bin, i, nreject + +begin + if (nbins < 2) + return (0) + + nreject = 0 + dz = real (nbins - 1) / real (z2 - z1) + do i = 1, npix { + if (data[index[i]] < z1 || data[index[i]] > z2) { + nreject = nreject + 1 + wgt[index[i]] = 0.0 + next + } + bin = int ((data[index[i]] - z1) * dz) + 1 + hgm[bin] = hgm[bin] + 1.0 + } + + return (nreject) +end + + +# AP_IJTOR -- Compute radius values given the center coordinates, the line +# number in a the subraster and the length of the subraster x axis. + +procedure ap_ijtor (r, nr, line, xc, yc) + +real r[nr] # array of output r values +int nr # length of r array +int line # line number +real xc, yc # subraster center + +int i +real temp + +begin + temp = (line - yc ) ** 2 + do i = 1, nr + r[i] = sqrt ((i - xc) ** 2 + temp) +end + + +# AP_IJTOR2 -- Compute radius values given the center coordinates and the size +# of the subraster. + +procedure ap_ijtor2 (r, nx, ny, xc, yc) + +real r[nx,ARB] # array of output r values +int nx # x dimension of output array +int ny # Y dimension of output array +real xc, yc # subraster center + +int i, j +real temp + +begin + do j = 1, ny { + temp = (j - yc) ** 2 + do i = 1, nx + r[i,j] = sqrt ((i - xc) ** 2 + temp) + } +end + + +# AP_2DALIMR -- Compute min and max values of a 2D array along with +# the indices of the minimum and maximum pixel. + +procedure ap_2dalimr (data, nx, ny, mindat, maxdat, imin, jmin, imax, jmax) + +real data[nx, ny] # data +int nx, ny # array dimensions +real mindat, maxdat # min, max data values +int imin, jmin # indices of min element +int imax, jmax # indices of max element + +int i, j + +begin + imin = 1 + jmin = 1 + imax = 1 + jmax = 1 + mindat = data[1,1] + maxdat = data[1,1] + + do j = 2, ny { + do i = 1, nx { + if (data[i,j] < mindat) { + imin = i + jmin = j + mindat = data[i,j] + } else if (data[i,j] > maxdat) { + imax = i + jmax = j + maxdat = data[i,j] + } + } + } +end + + +define LOGPTR 20 # log2(maxpts) (1e6) + +# APQSORT -- Vector Quicksort. In this version the index array is +# sorted. + +procedure apqsort (data, a, b, npix) + +real data[ARB] # data array +int a[ARB], b[ARB] # index array +int npix # number of pixels + +int i, j, lv[LOGPTR], p, uv[LOGPTR], temp +real pivot + +begin + # Initialize the indices for an inplace sort. + do i = 1, npix + a[i] = i + call amovi (a, b, npix) + + p = 1 + lv[1] = 1 + uv[1] = npix + while (p > 0) { + + # If only one elem in subset pop stack otherwise pivot line. + if (lv[p] >= uv[p]) + p = p - 1 + else { + i = lv[p] - 1 + j = uv[p] + pivot = data[b[j]] + + while (i < j) { + for (i=i+1; data[b[i]] < pivot; i=i+1) + ; + for (j=j-1; j > i; j=j-1) + if (data[b[j]] <= pivot) + break + if (i < j) { # out of order pair + temp = b[j] # interchange elements + b[j] = b[i] + b[i] = temp + } + } + + j = uv[p] # move pivot to position i + temp = b[j] # interchange elements + b[j] = b[i] + b[i] = temp + + if (i-lv[p] < uv[p] - i) { # stack so shorter done first + lv[p+1] = lv[p] + uv[p+1] = i - 1 + lv[p] = i + 1 + } else { + lv[p+1] = i + 1 + uv[p+1] = uv[p] + uv[p] = i - 1 + } + + p = p + 1 # push onto stack + } + } +end + + + +# APRECIPROCAL -- Compute the reciprocal of the absolute value of a vector. + +procedure apreciprocal (a, b, npts, value) + +real a[ARB] # the input vector +real b[ARB] # the output vector +int npts # the number of data points +real value # the value to be assigned to b[i] if a[i] = 0 + +int i + +begin + do i = 1, npts { + if (a[i] > 0.0) + b[i] = 1.0 / a[i] + else if (a[i] < 0.0) + b[i] = - 1.0 / a[i] + else + b[i] = value + } +end + + +# AP_WLIMR -- Set the weights of all data points outside a given minimum and +# maximum values to zero. Compute the minimum and maximum values and their +# indices of the remaining data. + +procedure ap_wlimr (pix, w, npts, datamin, datamax, dmin, dmax, imin, imax) + +real pix[ARB] # input pixel array +real w[ARB] # weight array +int npts # number of points +real datamin # minimum good data point +real datamax # maximum good data point +real dmin # output data minimum +real dmax # output data maximum +int imin # index of the data minimum +int imax # index of the data maximum + +int i +real value + +begin + dmin = datamax + dmax = datamin + imin = 1 + imax = 1 + + do i = 1, npts { + value = pix[i] + if ((value < datamin) || (value > datamax)) { + w[i] = 0.0 + next + } + if (value < dmin) { + dmin = value + imin = i + } else if (value > dmax) { + dmax = value + imax = i + } + } +end + + +# APWSSQR -- Compute the weighted sum of the squares of a vector. + +real procedure apwssqr (a, wgt, npts) + +real a[ARB] # data array +real wgt[ARB] # array of weights +int npts # number of points + +int i +real sum + +begin + sum = 0.0 + do i = 1, npts + sum = sum + wgt[i] * a[i] * a[i] + return (sum) +end + + +# AP_XYTOR -- Change the single integer coord of the sky pixels to a radial +# distance value. The integer coordinate is equal to coord = (i - xc + 1) + +# blklen * (j - yc). + +procedure ap_xytor (coords, index, r, nskypix, xc, yc, blklen) + +int coords[ARB] # coordinate array +int index[ARB] # the index array +real r[ARB] # radial coordinates +int nskypix # number of sky pixels +real xc, yc # center of sky subraster +int blklen # x dimension of sky subraster + +int i +real x, y + +begin + do i = 1, nskypix { + x = real (mod (coords[index[i]], blklen)) + if (x == 0) + x = real (blklen) + y = (coords[index[i]] - x) / blklen + 1 + r[i] = sqrt ((x - xc) ** 2 + (y - yc) ** 2) + } +end + + +# AP_W1SUR -- Linearly combine two vectors where the weight for the first +# vectors is 1.0 and is k2 for the second vector + +procedure ap_w1sur (a, b, c, npts, k2) + +real a[ARB] # the first input vector +real b[ARB] # the second input vector +real c[ARB] # the output vector +int npts # number of points +real k2 # the weigting factor for the second vector + +int i + +begin + do i = 1, npts + c[i] = a[i] + k2 * b[i] +end + + +# AP_INDEX -- Define an index array. + +procedure ap_index (index, npix) + +int index[ARB] # the index array +int npix # the number of pixels + +int i + +begin + do i = 1, npix + index[i] = i +end diff --git a/noao/digiphot/apphot/aputil/mkpkg b/noao/digiphot/apphot/aputil/mkpkg new file mode 100644 index 00000000..eefeed9d --- /dev/null +++ b/noao/digiphot/apphot/aputil/mkpkg @@ -0,0 +1,25 @@ +# Miscellaneous Routines used by the APPHOT Package + +$checkout libpkg.a ".." +$update libpkg.a +$checkin libpkg.a ".." +$exit + +libpkg.a: + apbsmooth.x + apclip.x + apdate.x <time.h> + apdiverr.x + apfnames.x + apgscur.x <gset.h> <fset.h> + apgtools.x <pkg/gtools.h> <gset.h> + aplucy.x + apnlfuncs.x <mach.h> <math.h> + apmapr.x + apmeds.x + apmoments.x + appcache.x <imhdr.h> <imset.h> + aprmwhite.x <ctype.h> + aptopt.x <math.h> <mach.h> + apvectors.x + ; diff --git a/noao/digiphot/apphot/center.par b/noao/digiphot/apphot/center.par new file mode 100644 index 00000000..3dbe8ad8 --- /dev/null +++ b/noao/digiphot/apphot/center.par @@ -0,0 +1,21 @@ +# CENTER + +image,f,a,,,,"Input image(s)" +coords,f,h,"",,,"Input coordinate list(s) (default: image.coo.?)" +output,f,h,"default",,,"Output center file(s) (default: image.ctr.?)" +plotfile,s,h,"",,,"Output plot metacode file" +datapars,pset,h,"",,,"Data dependent parameters" +centerpars,pset,h,"",,,"Centering parameters" +interactive,b,h,yes,,,"Interactive mode ?" +radplots,b,h,no,,,"Plot the radial profiles in interactive mode ?" +icommands,*imcur,h,"",,,"Image cursor: [x y wcs] key [cmd]" +gcommands,*gcur,h,"",,,"Graphics cursor: [x y wcs] key [cmd]" +wcsin,s,h,)_.wcsin,,,"The input coordinate system (logical,tv,physical,world)" +wcsout,s,h,)_.wcsout,,,"The output coordinate system (logical,tv,physical)" +cache,b,h,)_.cache,,,"Cache the input image pixels in memory ?" +verify,b,h,)_.verify,,,"Verify critical parameters in non-interactive mode ?" +update,b,h,)_.update,,,"Update critical parameters in non-interactive mode ?" +verbose,b,h,)_.verbose,,,"Print messages in non-interactive mode ?" +graphics,s,h,)_.graphics,,,"Graphics device" +display,s,h,)_.display,,,"Display device" +mode,s,h,'ql' diff --git a/noao/digiphot/apphot/center/apbcenter.x b/noao/digiphot/apphot/center/apbcenter.x new file mode 100644 index 00000000..9a607ee3 --- /dev/null +++ b/noao/digiphot/apphot/center/apbcenter.x @@ -0,0 +1,96 @@ +include <fset.h> +include "../lib/apphot.h" +include "../lib/display.h" + +# APBCENTER -- Procedure to determine accurate centers for a list of objects +# in batch mode using a simple text file list. + +procedure apbcenter (ap, im, cl, out, id, ld, mgd, gid, interactive) + +pointer ap # pointer to the apphot structure +pointer im # pointer to the IRAF image +int cl # the coordinate file descriptor +int out # output file descriptor +int id # output file sequence number +int ld # the coordinate file list number +pointer mgd # pointer to the metacode file stream +pointer gid # pointer to the image display stream +int interactive # mode of use + +int stdin, ier, ild +pointer sp, str +real wx, wy +int apfitcenter(), fscan(), nscan(), strncmp(), apstati() + +begin + call smark (sp) + call salloc (str, SZ_FNAME, TY_CHAR) + call fstats (cl, F_FILENAME, Memc[str], SZ_FNAME) + + # Initialize. + ild = ld + + # Print query. + if (strncmp ("STDIN", Memc[str], 5) == 0) { + stdin = YES + call printf ("Type object x and y coordinates (^D or ^Z to end): ") + call flush (STDOUT) + } else + stdin = NO + + # Loop over the coordinate file. + while (fscan (cl) != EOF) { + + # Get and store the coordinates. + call gargr (wx) + call gargr (wy) + if (nscan () != 2) { + if (stdin == YES) { + call printf ( + "Type object x and y coordinates (^D or ^Z to end): ") + call flush (STDOUT) + } + next + } + + # Transform the input coordinates. + switch (apstati(ap,WCSIN)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_itol (ap, wx, wy, wx, wy, 1) + case WCS_TV: + call ap_vtol (im, wx, wy, wx, wy, 1) + default: + ; + } + + call apsetr (ap, CWX, wx) + call apsetr (ap, CWY, wy) + + # Fit the center. + ier = apfitcenter (ap, im, wx, wy) + + # Print and/or plot the results. + if (interactive == YES) { + call ap_qcenter (ap, ier) + if (gid != NULL) + call apmark (ap, gid, apstati (ap, MKCENTER), NO, NO) + } + call ap_cplot (ap, id, mgd, YES) + if (id == 1) + call ap_param (ap, out, "center") + call ap_pcenter (ap, out, id, ild, ier) + + # Setup for the next object. + id = id + 1 + ild = ild + 1 + call apsetr (ap, WX, wx) + call apsetr (ap, WY, wy) + if (stdin == YES) { + call printf ( + "Type object x and y coordinates (^D or ^Z to end): ") + call flush (STDOUT) + } + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/center/apcconfirm.x b/noao/digiphot/apphot/center/apcconfirm.x new file mode 100644 index 00000000..6c570bd4 --- /dev/null +++ b/noao/digiphot/apphot/center/apcconfirm.x @@ -0,0 +1,75 @@ +include "../lib/apphot.h" +include "../lib/noise.h" +include "../lib/center.h" + +# AP_CCONFIRM -- Procedure to confirm the critical center parameters. + +procedure ap_cconfirm (ap, out, stid) + +pointer ap # pointer to the apphot structure +int out # output file descriptor +int stid # output file sequence number + +pointer sp, str +real fwhmpsf, capert, skysigma, datamin, datamax +int apstati() +real apstatr(), ap_vfwhmpsf(), ap_vcapert(), ap_vsigma() +real ap_vdatamin(), ap_vdatamax() + +begin + call smark (sp) + call salloc (str, SZ_FNAME, TY_CHAR) + + call printf ("\n") + + # Confirm the centering algorithm. + call ap_vcstring (ap, Memc[str], SZ_FNAME) + + if (apstati (ap, CENTERFUNCTION) != AP_NONE) { + + # Confirm the fwhmpsf. + if (apstati (ap, CENTERFUNCTION) != AP_CENTROID1D) { + fwhmpsf = ap_vfwhmpsf (ap) + } else + fwhmpsf = apstatr (ap, FWHMPSF) + + # Confirm the centering box. + capert = 2.0 * ap_vcapert (ap) + + # Confirm the sky sigma parameter. + skysigma = ap_vsigma (ap) + + } else { + + fwhmpsf = apstatr (ap, FWHMPSF) + capert = 2.0 * apstatr (ap, CAPERT) + skysigma = apstatr (ap, SKYSIGMA) + + } + + # Confirm the sky sigma parameter. + + # Confirm the minimum and maximum good data values. + datamin = ap_vdatamin (ap) + datamax = ap_vdatamax (ap) + + call printf ("\n") + + # Update the database file. + if (out != NULL && stid > 1) { + call ap_sparam (out, KY_CSTRING, Memc[str], UN_CALGORITHM, + "centering algorithm") + call ap_rparam (out, KY_FWHMPSF, fwhmpsf, UN_ASCALEUNIT, + "full width half maximum of the psf") + call ap_rparam (out, KY_CAPERT, capert, UN_CSCALEUNIT, + "centering box width") + call ap_rparam (out, KY_SKYSIGMA, skysigma, UN_NCOUNTS, + "standard deviation of 1 sky pixel") + call ap_rparam (out, KY_DATAMIN, datamin, UN_ACOUNTS, + "minimum good data value") + call ap_rparam (out, KY_DATAMAX, datamax, UN_ACOUNTS, + "maximum good data value") + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/center/apcencolon.x b/noao/digiphot/apphot/center/apcencolon.x new file mode 100644 index 00000000..9f2f40f8 --- /dev/null +++ b/noao/digiphot/apphot/center/apcencolon.x @@ -0,0 +1,329 @@ +include "../lib/apphot.h" +include "../lib/display.h" +include "../lib/noise.h" +include "../lib/center.h" + +# APCENTERCOLON -- Process colon commands from the centering task. + +procedure apcentercolon (ap, im, cl, out, stid, ltid, cmdstr, newimage, + newbuf, newfit) + +pointer ap # pointer to the apphot structure +pointer im # pointer to the iraf image +int cl # coordinate file descriptor +int out # output file descriptor +int stid # output file sequence number +int ltid # input list sequence number +char cmdstr[ARB] # command string +int newimage # new image ? +int newbuf # new center buffer ? +int newfit # new center fit ? + +int junk +pointer sp, incmd, outcmd +int strdic() + +begin + # Allocate working space. + call smark (sp) + call salloc (incmd, SZ_LINE, TY_CHAR) + call salloc (outcmd, SZ_LINE, TY_CHAR) + + # Get the command. + call sscan (cmdstr) + call gargwrd (Memc[incmd], SZ_LINE) + if (Memc[incmd] == EOS) { + call sfree (sp) + return + } + + # Process the command. + if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, CCMDS) != 0) + call ap_ccolon (ap, out, stid, cmdstr, newbuf, newfit) + else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, APCMDS) != 0) + call ap_apcolon (ap, im, cl, out, stid, ltid, cmdstr, newimage, + newbuf, newfit, junk, junk, junk, junk) + else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, NCMDS) != 0) + call ap_nscolon (ap, im, out, stid, cmdstr, newbuf, newfit, + junk, junk, junk, junk) + else + call ap_cimcolon (ap, cmdstr) + + call sfree (sp) +end + + +# AP_CCOLON -- Process colon commands affecting the centering parameters. + +procedure ap_ccolon (ap, out, stid, cmdstr, newbuf, newfit) + +pointer ap # pointer to the apphot structure +int out # output file descriptor +int stid # output list id number +char cmdstr # command string +int newbuf # new sky buffer +int newfit # new sky fit + +bool bval +int ival, ncmd, stat +pointer sp, cmd, str +real rval + +bool itob() +int nscan(), strdic(), btoi(), apstati() +real apstatr() + +begin + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + call salloc (str, SZ_FNAME, TY_CHAR) + + # Get the command. + call sscan (cmdstr) + call gargwrd (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call sfree (sp) + return + } + + # Process the command. + ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, CCMDS) + switch (ncmd) { + + case CCMD_CBOXWIDTH: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_CAPERT) + call pargr (2.0 * apstatr (ap, CAPERT)) + call pargstr (UN_CSCALEUNIT) + } else { + call apsetr (ap, CAPERT, (rval / 2.0)) + if (stid > 1) + call ap_rparam (out, KY_CAPERT, rval, UN_CSCALEUNIT, + "centering subraster width") + newbuf = YES + newfit = YES + } + + case CCMD_CALGORITHM: + call gargwrd (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call apstats (ap, CSTRING, Memc[str], SZ_FNAME) + call printf ("%s = %s %s\n") + call pargstr (KY_CSTRING) + call pargstr (Memc[str]) + call pargstr (UN_CALGORITHM) + } else { + stat = strdic (Memc[cmd], Memc[cmd], SZ_LINE, CFUNCS) + if (stat > 0) { + call apseti (ap, CENTERFUNCTION, stat) + call apsets (ap, CSTRING, Memc[cmd]) + if (stid > 1) + call ap_sparam (out, KY_CSTRING, Memc[cmd], + UN_CALGORITHM, "centering algorihtm") + newbuf = YES + newfit = YES + } + } + + case CCMD_CTHRESHOLD: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_CTHRESHOLD) + call pargr (apstatr (ap, CTHRESHOLD)) + call pargstr (UN_CSIGMA) + } else { + call apsetr (ap, CTHRESHOLD, rval) + if (stid > 1) + call ap_rparam (out, KY_CTHRESHOLD, rval, UN_CSIGMA, + "threshold for centering") + newbuf = YES + newfit = YES + } + + case CCMD_MAXSHIFT: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_MAXSHIFT) + call pargr (apstatr (ap, MAXSHIFT)) + call pargstr (UN_CSCALEUNIT) + } else { + call apsetr (ap, MAXSHIFT, rval) + if (stid > 1) + call ap_rparam (out, KY_MAXSHIFT, rval, UN_CSCALEUNIT, + "maximum shift") + newfit = YES + } + + case CCMD_MINSNRATIO: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g\n") + call pargstr (KY_MINSNRATIO) + call pargr (apstatr (ap, MINSNRATIO)) + } else { + call apsetr (ap, MINSNRATIO, rval) + if (stid > 1) + call ap_rparam (out, KY_MINSNRATIO, rval, + UN_CNUMBER, "minimum signal-to-noise ratio") + newfit = YES + } + + case CCMD_CMAXITER: + call gargi (ival) + if (nscan () == 1) { + call printf ("%s = %d\n") + call pargstr (KY_CMAXITER) + call pargi (apstati (ap, CMAXITER)) + } else { + call apseti (ap, CMAXITER, ival) + if (stid > 1) + call ap_iparam (out, KY_CMAXITER, ival, UN_CNUMBER, + "maximum number of iterations") + newfit = YES + } + + case CCMD_CLEAN: + call gargb (bval) + if (nscan () == 1) { + call printf ("%s = %b\n") + call pargstr (KY_CLEAN) + call pargb (itob (apstati (ap, CLEAN))) + } else { + call apseti (ap, CLEAN, btoi (bval)) + if (stid > 1) + call ap_bparam (out, KY_CLEAN, bval, UN_CSCALEUNIT, + "apply clean algorithm before centering") + newbuf = YES + newfit = YES + } + + case CCMD_RCLEAN: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_RCLEAN) + call pargr (apstatr (ap, RCLEAN)) + call pargstr (UN_CSCALEUNIT) + } else { + call apsetr (ap, RCLEAN, rval) + if (stid > 1) + call ap_rparam (out, KY_RCLEAN, rval, UN_CSCALEUNIT, + "cleaning radius") + newbuf = YES + newfit = YES + } + + case CCMD_RCLIP: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_RCLIP) + call pargr (apstatr (ap, RCLIP)) + call pargstr (UN_CSCALEUNIT) + } else { + call apsetr (ap, RCLIP, rval) + if (stid > 1) + call ap_rparam (out, KY_RCLIP, rval, UN_CSCALEUNIT, + "clipping radius") + newbuf = YES + newfit = YES + } + + case CCMD_KCLEAN: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_SIGMACLEAN) + call pargr (apstatr (ap, SIGMACLEAN)) + call pargstr (UN_CSIGMA) + } else { + call apsetr (ap, SIGMACLEAN, rval) + if (stid > 1) + call ap_rparam (out, KY_SIGMACLEAN, rval, + UN_CSIGMA, "k-sigma clean rejection criterion") + newbuf = YES + newfit = YES + } + + case CCMD_MKCENTER: + call gargb (bval) + if (nscan() == 1) { + call printf ("%s = %b\n") + call pargstr (KY_MKCENTER) + call pargb (itob (apstati (ap, MKCENTER))) + } else + call apseti (ap, MKCENTER, btoi (bval)) + + default: + call printf ("Unknown or ambiguous colon command\7\n") + } + + call sfree (sp) +end + + +# AP_CIMCOLON -- Process colon commands for the center task that do +# not affect the centering parameters + +procedure ap_cimcolon (ap, cmdstr) + +pointer ap # pointer to the apphot structure +char cmdstr[ARB] # command string + +bool bval +int ncmd +pointer sp, cmd +bool itob() +int strdic(), nscan(), apstati(), btoi() + +begin + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + # Get the command. + call sscan (cmdstr) + call gargwrd (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call sfree (sp) + return + } + + # Process the command. + ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, MISC) + switch (ncmd) { + case ACMD_SHOW: + call gargwrd (Memc[cmd], SZ_LINE) + ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, CSHOWARGS) + switch (ncmd) { + case CCMD_DATA: + call printf ("\n") + call ap_nshow (ap) + call printf ("\n") + case CCMD_CENTER: + call printf ("\n") + call ap_cpshow (ap) + call printf ("\n") + default: + call printf ("\n") + call ap_cshow (ap) + call printf ("\n") + } + case ACMD_RADPLOTS: + call gargb (bval) + if (nscan () == 1) { + call printf ("%s = %b\n") + call pargstr (KY_RADPLOTS) + call pargb (itob (apstati (ap, RADPLOTS))) + } else { + call apseti (ap, RADPLOTS, btoi (bval)) + } + default: + call printf ("Unknown or ambiguous colon command\7\n") + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/center/apcenter.x b/noao/digiphot/apphot/center/apcenter.x new file mode 100644 index 00000000..8e1b4c68 --- /dev/null +++ b/noao/digiphot/apphot/center/apcenter.x @@ -0,0 +1,357 @@ +include <ctype.h> +include <gset.h> +include <imhdr.h> +include "../lib/apphot.h" +include "../lib/display.h" +include "../lib/center.h" + +define HELPFILE "apphot$center/center.key" + +# APCENTER -- Procedure to determine accurate centers for a list of objects +# interactively. + +int procedure apcenter (ap, im, cl, gd, mgd, id, out, stid, interactive, cache) + +pointer ap # pointer to the apphot structure +pointer im # pointer to the IRAF image +int cl # coordinate list file descriptor +pointer gd # pointer to the graphics stream +pointer mgd # pointer to the plot metacode stream +pointer id # pointer to the image display stream +int out # output file descriptor +int stid # output file sequence number +int interactive # interactive mode +int cache # cache the input pixels + +real wx, wy, xlist, ylist +pointer sp, cmd +int wcs, key, colonkey, newimage, newobject, newcenter, newlist, ier, oid +int ip, prev_num, req_num, ltid, buf_size, old_size, req_size, memstat + +real apstatr() +int ctoi(), clgcur(), apgscur(), apfitcenter(), aprefitcenter(), apstati() +int apgqverify(), apgtverify(), apnew(), ap_memstat(), sizeof() + +define endswitch_ 99 + +begin + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + # Initialize cursor command. + key = ' ' + Memc[cmd] = EOS + + # Initialize fitting parameters. + newimage = NO + newobject = YES + newcenter = YES + ier = AP_OK + + # Initialize sequencing. + newlist = NO + ltid = 0 + + # Loop over the cursor commands. + while (clgcur ("icommands", wx, wy, wcs, key, Memc[cmd], SZ_LINE) != + EOF) { + + # Store the current cursor coordinates. + call ap_vtol (im, wx, wy, wx, wy, 1) + call apsetr (ap, CWX, wx) + call apsetr (ap, CWY, wy) + + # Test to see if the cursor has moved. + if (apnew (ap, wx, wy, xlist, ylist, newlist) == YES) { + newobject = YES + newcenter = YES + } + + # Process the colon commands. + switch (key) { + + # Quit. + case 'q': + if (interactive == YES) { + if (apgqverify ("center", ap, key) == YES) { + call sfree (sp) + return (apgtverify (key)) + } + } else { + call sfree (sp) + return (NO) + } + + # Print error messages. + case 'e': + if (interactive == YES) + call ap_cerrors (ap, ier) + + # Get information on keystroke commands. + case '?': + if ((id != NULL) && (id == gd)) + call gpagefile (id, HELPFILE, "") + else if (interactive == YES) + call pagefile (HELPFILE, "[space=cmhelp,q=quit,?=help]") + + # Rewind the coord list. + case 'r': + if (cl != NULL) { + call seek (cl, BOF) + ltid = 0 + } else if (interactive == YES) + call printf ("No coordinate list\n") + + # Draw a centered stellar radial profile plot. + case 'd': + if (interactive == YES) { + call ap_qrad (ap, im, wx, wy, gd) + newobject = YES + newcenter = YES + } + + # Interactively set the centering parameters. + case 'i': + if (interactive == YES) { + call ap_cradsetup (ap, im, wx, wy, gd, out, stid) + newobject = YES + newcenter = YES + } + + # Verify critical parameters. + case 'v': + call ap_cconfirm (ap, out, stid) + newobject = YES + newcenter = YES + + # Measure the next object. + case 'm', 'n': + + # No coordinate file. + if (cl == NULL) { + if (interactive == YES) + call printf ("No coordinate list\n") + goto endswitch_ + } + + # Need to rewind coordinate file. + prev_num = ltid + req_num = ltid + 1 + if (apgscur (cl, id, xlist, ylist, prev_num, req_num, ltid) == + EOF) { + if (interactive == YES) + call printf ( + "End of coordinate list, use r key to rewind\n") + goto endswitch_ + } + + # Convert coordinates if necessary. + switch (apstati (ap, WCSIN)) { + case WCS_PHYSICAL, WCS_WORLD: + call ap_itol (ap, xlist, ylist, xlist, ylist, 1) + case WCS_TV: + call ap_vtol (im, xlist, ylist, xlist, ylist, 1) + default: + ; + } + + # Move to next object. + newlist = YES + if (key == 'm') { + newobject = YES + newcenter = YES + goto endswitch_ + } + + # Measure next object. + ier = apfitcenter (ap, im, xlist, ylist) + if (id != NULL) { + call apmark (ap, id, apstati (ap, MKCENTER), NO, NO) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_cplot (ap, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qcenter (ap, ier) + if (stid == 1) + call ap_param (ap, out, "center") + call ap_cplot (ap, stid, mgd, YES) + call ap_pcenter (ap, out, stid, ltid, ier) + stid = stid + 1 + newobject = NO + newcenter = NO + + # Save centering parameters in the pset files. + case 'w': + call ap_pcpars (ap) + + # Process apphot : commands. + case ':': + for (ip = 1; IS_WHITE(Memc[cmd+ip-1]); ip = ip + 1) + ; + colonkey = Memc[cmd+ip-1] + + # Process the apphot :n command. + switch (colonkey) { + case 'm', 'n': + + # Show/set apphot commands + if (Memc[cmd+ip] != EOS && Memc[cmd+ip] != ' ') { + call apcentercolon (ap, im, cl, out, stid, ltid, + Memc[cmd], newimage, newobject, newcenter) + goto endswitch_ + } + + # No coordinate list. + if (cl == NULL) { + if (interactive == YES) + call printf ("No coordinate list\n") + goto endswitch_ + } + + # Get next object from list. + ip = ip + 1 + prev_num = ltid + if (ctoi (Memc[cmd], ip, req_num) <= 0) + req_num = ltid + 1 + + # Fetch the next object from the list. + if (apgscur (cl, id, xlist, ylist, prev_num, req_num, + ltid) == EOF) { + if (interactive == YES) + call printf ( + "End of coordinate list, use r key to rewind\n") + goto endswitch_ + } + + # Convert the coordinates. + switch (apstati (ap, WCSIN)) { + case WCS_PHYSICAL, WCS_WORLD: + call ap_itol (ap, xlist, ylist, xlist, ylist, 1) + case WCS_TV: + call ap_vtol (im, xlist, ylist, xlist, ylist, 1) + default: + ; + } + + # Move to the next object. + newlist = YES + if (colonkey == 'm') { + newobject = YES + newcenter = YES + goto endswitch_ + } + + # Measure next object. + ier = apfitcenter (ap, im, xlist, ylist) + if (id != NULL) { + call apmark (ap, id, apstati (ap, MKCENTER), NO, NO) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_cplot (ap, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qcenter (ap, ier) + if (stid == 1) + call ap_param (ap, out, "center") + call ap_cplot (ap, stid, mgd, YES) + call ap_pcenter (ap, out, stid, ltid, ier) + stid = stid + 1 + newobject = NO + newcenter = NO + + # Show/set apphot parameters. + default: + call apcentercolon (ap, im, cl, out, stid, ltid, Memc[cmd], + newimage, newobject, newcenter) + } + + if (newimage == YES) { + if ((id != NULL) && (id != gd)) + call ap_gswv (id, Memc[cmd], im, 4) + req_size = MEMFUDGE * IM_LEN(im,1) * IM_LEN(im,2) * + sizeof (IM_PIXTYPE(im)) + memstat = ap_memstat (cache, req_size, old_size) + if (memstat == YES) + call ap_pcache (im, INDEFI, buf_size) + } + + newimage = NO + + # Fit the center, and save the results. + case 'f', ' ': + + # Compute the center. + if (newobject == YES) + ier = apfitcenter (ap, im, wx, wy) + else if (newcenter == YES) + ier = aprefitcenter (ap, im, ier) + if (id != NULL) { + call apmark (ap, id, apstati (ap, MKCENTER), NO, NO) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_cplot (ap, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qcenter (ap, ier) + newobject = NO; newcenter = NO + + # Write the results to the output file(s). + if (key == ' ') { + if (stid == 1) + call ap_param (ap, out, "center") + if (newlist == YES) + call ap_pcenter (ap, out, stid, ltid, ier) + else + call ap_pcenter (ap, out, stid, 0, ier) + call ap_cplot (ap, stid, mgd, YES) + stid = stid + 1 + } + + # Fit centers for the rest of the list. + case 'l': + + # No coordinate list. + if (cl == NULL) { + if (interactive == YES) + call printf ("No coordinate list\n") + goto endswitch_ + } + + # Center rest of coordinate list. + ltid = ltid + 1 + oid = stid + call apbcenter (ap, im, cl, out, stid, ltid, mgd, id, YES) + ltid = ltid + stid - oid + 1 + if (id != NULL) { + if (id == gd) + call gflush (id) + else + call gframe (id) + } + + # Unknown command. + default: + call printf ("Unknown or ambiguous keystroke command\n") + } + +endswitch_ + # Setup for the next object by setting the default keystroke + # command and storing the old cursor coordinates in the + # centering structure. + + key = ' ' + Memc[cmd] = EOS + call apsetr (ap, WX, apstatr (ap, CWX)) + call apsetr (ap, WY, apstatr (ap, CWY)) + + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/center/apcerrors.x b/noao/digiphot/apphot/center/apcerrors.x new file mode 100644 index 00000000..4f8c32bb --- /dev/null +++ b/noao/digiphot/apphot/center/apcerrors.x @@ -0,0 +1,32 @@ +include "../lib/center.h" + +# AP_CERRORS -- Procedure to print the centering task error messages. + +procedure ap_cerrrors (ap, ier) + +pointer ap # apphot pointer (unused) +int ier # centering error code + +begin + switch (ier) { + case AP_CTR_NOAREA: + call printf ("There are no pixels in the centering box.\n") + case AP_CTR_OUTOFBOUNDS: + call printf ( + "The centering region is partially outside the image.\n") + case AP_CTR_NTOO_SMALL: + call printf ("The centering box has too few points.\n") + case AP_CTR_SINGULAR: + call printf ("The centering solution is singular.\n") + case AP_CTR_NOCONVERGE: + call printf ("The centering algorithm does not converge.\n") + case AP_CTR_BADSHIFT: + call printf ("The center shift is large.\n") + case AP_CTR_LOWSNRATIO: + call printf ("The signal to noise ratio is low.\n") + case AP_CTR_BADDATA: + call printf ("Bad data in the centering subraster.\n") + default: + call printf ("") + } +end diff --git a/noao/digiphot/apphot/center/apcfree.x b/noao/digiphot/apphot/center/apcfree.x new file mode 100644 index 00000000..7fb219c7 --- /dev/null +++ b/noao/digiphot/apphot/center/apcfree.x @@ -0,0 +1,46 @@ +include "../lib/apphotdef.h" +include "../lib/centerdef.h" + +# APCFREE -- Procedure to free the centering data structure. + +procedure apcfree (ap) + +pointer ap # pointer to the apphot structure + +begin + if (ap == NULL) + return + if (AP_NOISE(ap) != NULL) + call ap_noisecls (ap) + if (AP_PCENTER(ap) != NULL) + call ap_ctrcls (ap) + if (AP_PDISPLAY(ap) != NULL) + call ap_dispcls (ap) + if (AP_IMBUF(ap) != NULL) + call mfree (AP_IMBUF(ap), TY_REAL) + if (AP_MW(ap) != NULL) + call mw_close (AP_MW(ap)) + call mfree (ap, TY_STRUCT) +end + + +# AP_CTRCLS -- Procedure to close up the centering structure arrays. + +procedure ap_ctrcls (ap) + +pointer ap # pointer to apphot structure + +pointer ctr + +begin + ctr = AP_PCENTER(ap) + if (ctr == NULL) + return + if (AP_CTRPIX(ctr) != NULL) + call mfree (AP_CTRPIX(ctr), TY_REAL) + if (AP_XCTRPIX(ctr) != NULL) + call mfree (AP_XCTRPIX(ctr), TY_REAL) + if (AP_YCTRPIX(ctr) != NULL) + call mfree (AP_YCTRPIX(ctr), TY_REAL) + call mfree (AP_PCENTER(ap), TY_STRUCT) +end diff --git a/noao/digiphot/apphot/center/apcinit.x b/noao/digiphot/apphot/center/apcinit.x new file mode 100644 index 00000000..a9f38fd7 --- /dev/null +++ b/noao/digiphot/apphot/center/apcinit.x @@ -0,0 +1,94 @@ +include "../lib/apphotdef.h" +include "../lib/centerdef.h" +include "../lib/center.h" + +# APCINIT - Procedure to initialize the centering structure. + +procedure apcinit (ap, function, cbox, fwhmpsf, noise) + +pointer ap # pointer to the apphot structure +int function # centering algorithm +real cbox # half width of centering box +real fwhmpsf # FWHM of the PSF +int noise # noise function + +begin + # Allocate space. + call malloc (ap, LEN_APSTRUCT, TY_STRUCT) + + # Set up the global apphot package parameters. + call ap_defsetup (ap, fwhmpsf) + + # Setup the noise structure. + call ap_noisesetup (ap, noise) + + # Initialize the centering parameters. + call ap_ctrsetup (ap, function, cbox) + + # Display the options. + call ap_dispsetup (ap) + + # Unused structures are set to null. + AP_PSKY(ap) = NULL + AP_PPSF(ap) = NULL + AP_PPHOT(ap) = NULL + AP_POLY(ap) = NULL + AP_RPROF(ap) = NULL +end + + +# AP_CTRSETUP -- Procedure to setup the centering array parameters. + +procedure ap_ctrsetup (ap, function, cbox) + +pointer ap # pointer to apphot structure +int function # centering function +real cbox # radius of centering aperture + +pointer ctr + +begin + # Allocate space for the centering structure. + call malloc (AP_PCENTER(ap), LEN_CENSTRUCT, TY_STRUCT) + ctr = AP_PCENTER(ap) + AP_CXCUR(ctr) = INDEFR + AP_CYCUR(ctr) = INDEFR + + AP_CENTERFUNCTION(ctr) = function + switch (function) { + case AP_CENTROID1D: + call strcpy ("centroid", AP_CSTRING(ctr), SZ_FNAME) + case AP_GAUSS1D: + call strcpy ("gauss", AP_CSTRING(ctr), SZ_FNAME) + case AP_NONE: + call strcpy ("none", AP_CSTRING(ctr), SZ_FNAME) + case AP_OFILT1D: + call strcpy ("ofilter", AP_CSTRING(ctr), SZ_FNAME) + default: + AP_CENTERFUNCTION(ctr) = DEF_CENTERFUNCTION + call strcpy ("centroid", AP_CSTRING(ctr), SZ_FNAME) + } + AP_CAPERT(ctr) = cbox + AP_CTHRESHOLD(ctr) = DEF_CTHRESHOLD + AP_MINSNRATIO(ctr) = DEF_MINSNRATIO + AP_CMAXITER(ctr) = DEF_CMAXITER + AP_MAXSHIFT(ctr) = DEF_MAXSHIFT + AP_CLEAN(ctr) = DEF_CLEAN + AP_RCLEAN(ctr) = DEF_RCLEAN + AP_RCLIP(ctr) = DEF_RCLIP + AP_SIGMACLEAN(ctr) = DEF_CLEANSIGMA + + AP_NCTRPIX(ctr) = 0 + AP_CTRPIX(ctr) = NULL + AP_XCTRPIX(ctr) = NULL + AP_YCTRPIX(ctr) = NULL + + AP_OXINIT(ctr) = INDEFR + AP_OYINIT(ctr) = INDEFR + AP_XCENTER(ctr) = INDEFR + AP_YCENTER(ctr) = INDEFR + AP_OXCENTER(ctr) = INDEFR + AP_OYCENTER(ctr) = INDEFR + AP_XERR(ctr) = INDEFR + AP_YERR(ctr) = INDEFR +end diff --git a/noao/digiphot/apphot/center/apclean.x b/noao/digiphot/apphot/center/apclean.x new file mode 100644 index 00000000..2e3a827a --- /dev/null +++ b/noao/digiphot/apphot/center/apclean.x @@ -0,0 +1,152 @@ +include "../lib/apphot.h" +include "../lib/noise.h" +include "../lib/center.h" + +# AP_CLEAN -- Procedure to clean a data array. + +procedure ap_clean (ap, pix, nx, ny, xc, yc) + +pointer ap # pointer to the apphot structure +real pix[nx,ny] # data array +int nx, ny # size of subarray +real xc, yc # center of subarray + +int apstati() +real apstatr() + +begin + switch (apstati (ap, NOISEFUNCTION)) { + case AP_NCONSTANT: + call ap_cclean (pix, nx, ny, xc, yc, apstatr (ap, SCALE) * + apstatr (ap, RCLIP), apstatr (ap, SIGMACLEAN), + apstatr (ap, SKYSIGMA), apstatr (ap, MAXSHIFT)) + case AP_NPOISSON: + call ap_pclean (pix, nx, ny, xc, yc, apstatr (ap, SCALE) * + apstatr (ap, RCLEAN), apstatr (ap, SCALE) * apstatr (ap, + RCLIP), apstatr (ap, SIGMACLEAN), apstatr (ap, SKYSIGMA), + apstatr (ap, EPADU), apstatr (ap, MAXSHIFT)) + default: + return + } +end + + +# AP_CCLEAN -- Procedure to clean the subraster assuming the noise is +# due to a constant sky sigma. + +procedure ap_cclean (pix, nx, ny, cxc, cyc, rclip, kclean, skysigma, + maxshift) + +real pix[nx, ny] # array of pixels +int nx, ny # dimensions of the subarray +real cxc, cyc # initial center +real rclip # cleaning and clipping radius +real kclean # k-sigma clipping factor +real skysigma # maxshift +real maxshift # maximum shift + +int i, ii, ixc, j, jj, jyc, ijunk, jjunk +real mindat, maxdat, rclip2, r2, ksigma + +begin + # Return if indef valued sigma or sigma <= 0. + if (IS_INDEFR(skysigma) || (skysigma <= 0.0)) + return + + # Find the maximum pixel in the subarray and treat this point as + # the center of symmetry if it is less than maxshift from the + # initial center. + + call ap_2dalimr (pix, nx, ny, mindat, maxdat, ijunk, jjunk, ixc, jyc) + if (abs (cxc - ixc) > maxshift || abs (cyc - jyc) > maxshift) { + ixc = int (cxc) + jyc = int (cyc) + } + + # Clip. + rclip2 = rclip ** 2 + ksigma = kclean * skysigma + do j = 1, ny { + jj = 2 * jyc - j + if (jj < 1 || jj > ny) + next + do i = 1, ixc { + ii = 2 * ixc - i + if (ii < 1 || ii > nx) + next + r2 = (i - ixc) ** 2 + (j - jyc) ** 2 + if (r2 > rclip2) { + if (pix[ii,jj] > pix[i,j] + ksigma) + pix[ii,jj] = pix[i,j] + else if (pix[i,j] > pix[ii,jj] + ksigma) + pix[i,j] = pix[ii,jj] + } + } + } +end + + +# AP_PCLEAN -- Procedure to clean the subraster assuming that the noise is +# due to a constant sky value plus poisson noise. + +procedure ap_pclean (pix, nx, ny, cxc, cyc, rclean, rclip, kclean, skysigma, + padu, maxshift) + +real pix[nx, ny] # array of pixels +int nx, ny # dimensions of the subarray +real cxc, cyc # initial center +real rclean, rclip # cleaning and clipping radius +real kclean # k-sigma clipping factor +real skysigma # maxshift +real padu # photons per adu +real maxshift # maximum shift + +int i, ii, ixc, j, jj, jyc, ijunk, jjunk +real mindat, maxdat, rclean2, rclip2, r2, ksigma, ksigma2 + +begin + # Return if indef-valued sigma. + if (IS_INDEFR(skysigma)) + return + + # Find the maximum pixel in the subarray and treat this point as + # the center of symmetry if it is less than maxshift from the + # initial center. + + call ap_2dalimr (pix, nx, ny, mindat, maxdat, ijunk, jjunk, ixc, jyc) + if (abs (cxc - ixc) > maxshift || abs (cyc - jyc) > maxshift) { + ixc = int (cxc) + jyc = int (cyc) + } + + # Clip. + rclean2 = rclean ** 2 + rclip2 = rclip ** 2 + ksigma = kclean * skysigma + ksigma2 = ksigma ** 2 + do j = 1, ny { + jj = 2 * jyc - j + if (jj < 1 || jj > ny) + next + do i = 1, ixc { + ii = 2 * ixc - i + if (ii < 1 || ii > nx) + next + r2 = (i - ixc) ** 2 + (j - jyc) ** 2 + if (r2 > rclean2 && r2 <= rclip2) { + if (pix[ii,jj] > (pix[i,j] + sqrt (pix[i,j] / padu + + ksigma2))) + pix[ii,jj] = pix[i,j] + else if (pix[i,j] > (pix[ii,jj] + sqrt (pix[ii,jj] / padu + + ksigma2))) + pix[i,j] = pix[ii,jj] + } + if (r2 > rclip2) { + if (pix[ii,jj] > pix[i,j] + ksigma) + pix[ii,jj] = pix[i,j] + else if (pix[i,j] > pix[ii,jj] + ksigma) + pix[i,j] = pix[ii,jj] + } + } + } +end diff --git a/noao/digiphot/apphot/center/apcplot.x b/noao/digiphot/apphot/center/apcplot.x new file mode 100644 index 00000000..6e2845c3 --- /dev/null +++ b/noao/digiphot/apphot/center/apcplot.x @@ -0,0 +1,304 @@ +include <mach.h> +include <gset.h> +include <pkg/gtools.h> +include "../lib/apphotdef.h" +include "../lib/apphot.h" +include "../lib/noise.h" +include "../lib/centerdef.h" +include "../lib/center.h" + +# AP_CPLOT -- Procedure to compute radial profile plots for the centering +# routine. + +procedure ap_cplot (ap, sid, gd, makeplot) + +pointer ap # the pointer to the apphot structure +int sid # the output sequence number of the star +pointer gd # the graphics stream +int makeplot # the make a plot ? + +int nx, ny +pointer ctr, sp, str, r, gt +real xcenter, ycenter, xc, yc, rmin, rmax, imin, imax +real u1, u2, v1, v2, x1, x2, y1, y2 +int apstati() +pointer ap_gtinit() +real apstatr() + +begin + # Check for enabled graphics stream. + if (gd == NULL || makeplot == NO) + return + + # Check for defined center. + xcenter = apstatr (ap, XCENTER) + ycenter = apstatr (ap, YCENTER) + if (IS_INDEFR(xcenter) || IS_INDEFR(ycenter)) + return + + # Check for a centering algorithm. + if (apstati (ap, CENTERFUNCTION) == AP_NONE) + return + + # Get the pixel buffer parameters. + ctr = AP_PCENTER(ap) + nx = AP_CNX(ctr) + ny = AP_CNY(ctr) + if (AP_CTRPIX(ctr) == NULL || nx <= 0 || ny <= 0) + return + xc = AP_CXC(ctr) + (xcenter - apstatr (ap, CXCUR)) + yc = AP_CYC(ctr) + (ycenter - apstatr (ap, CYCUR)) + + # Allocate working space. + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + call salloc (r, nx * ny, TY_REAL) + + # Compute the radii and the plot limits. + call ap_ijtor2 (Memr[r], nx, ny, xc, yc) + call alimr (Memr[r], nx * ny, rmin, rmax) + call alimr (Memr[AP_CTRPIX(ctr)], nx * ny, imin, imax) + + # Reactivate the work station. + call greactivate (gd, 0) + + # Save old viewport and window coordinates. + call ggview (gd, u1, u2, v1, v2) + call ggwind (gd, x1, x2, y1, y2) + + # Initialize the plot. + call apstats (ap, IMROOT, Memc[str], SZ_LINE) + call sprintf (Memc[str], SZ_LINE, "%s Star %d") + call pargstr (Memc[str]) + call pargi (sid) + gt = ap_gtinit (Memc[str], apstatr (ap,OXINIT), apstatr (ap, OYINIT)) + + # Make the plot. + call gclear (gd) + call ap_cpset (gd, gt, ap, rmin, rmax, imin, imax) + if (apstati (ap, POSITIVE) == YES) + call ap_plotpts (gd, gt, Memr[r], Memr[AP_CTRPIX(ctr)], nx * ny, + rmin, rmax, imin + EPSILONR, imax, "plus") + else + call ap_plotpts (gd, gt, Memr[r], Memr[AP_CTRPIX(ctr)], nx * ny, + rmin, rmax, imin, imax - EPSILONR, "plus") + call ap_cpreset (gd, gt, ap, rmin, rmax, imin, imax) + call ap_cpannotate (gd, ap) + + # Restore the viewport and window coordinates. + call gsview (gd, u1, u2, v1, v2) + call gswind (gd, x1, x2, y1, y2) + + # Free the space. + call ap_gtfree (gt) + call gdeactivate (gd, 0) + call sfree (sp) +end + + +# AP_CPSET -- Procedure to set up the parameters for the center radial profile +# plot. + +procedure ap_cpset (gd, gt, ap, xmin, xmax, ymin, ymax) + +pointer gd # the graphics stream +pointer gt # the gtools pointer +pointer ap # the apphot pointer +real xmin, xmax # the minimum and maximum radial distance +real ymin, ymax # the minimum and maximum of y axis (ymin not used) + +int fd +pointer sp, str, title +real scale, aspect, datalimit, skysigma, threshold, vx1, vx2, vy1, vy2 +real cthreshold +int stropen(), apstati() +real apstatr(), gstatr() + +begin + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + call salloc (title, SZ_LINE, TY_CHAR) + + # Encode the parameter string. + fd = stropen (Memc[str], SZ_LINE, WRITE_ONLY) + call sysid (Memc[title], SZ_LINE) + call fprintf (fd, "%s\n") + call pargstr (Memc[title]) + call fprintf (fd, + "Center: xc=%0.2f yc=%0.2f xerr=%0.2f yerr=%0.2f\n") + call pargr (apstatr (ap, OXCENTER)) + call pargr (apstatr (ap, OYCENTER)) + call pargr (apstatr (ap, XERR)) + call pargr (apstatr (ap, YERR)) + call gt_gets (gt, GTTITLE, Memc[title], SZ_LINE) + call fprintf (fd, "%s\n") + call pargstr (Memc[title]) + call strclose (fd) + + # Store some default plotting parameters. + scale = apstatr (ap, SCALE) + aspect = gstatr (gd, G_ASPECT) + call gsetr (gd, G_ASPECT, 0.75) + + # Set the labels and window. + datalimit = apstatr (ap, CDATALIMIT) + skysigma = apstatr (ap, SKYSIGMA) + cthreshold = apstatr (ap, CTHRESHOLD) + if (IS_INDEFR(skysigma) || IS_INDEFR(cthreshold)) + threshold = 0.0 + else + threshold = cthreshold * skysigma + if (apstati (ap, POSITIVE) == YES) { + call gseti (gd, G_XDRAWAXES, 2) + call gswind (gd, xmin / scale, xmax / scale, datalimit + threshold, + datalimit + threshold + ymax) + call glabax (gd, Memc[str], "", "Intensity") + call gseti (gd, G_YDRAWAXES, 0) + call gseti (gd, G_XDRAWAXES, 1) + call ggview (gd, vx1, vx2, vy1, vy2) + call gswind (gd, vx1, vx2, vy1, vy2) + call gswind (gd, xmin, xmax, datalimit + threshold, + datalimit + threshold + ymax) + call glabax (gd, "", + "Radial Distance (lower-pixels, upper-scale units)", "") + } else { + call gseti (gd, G_XDRAWAXES, 2) + call gswind (gd, xmin / scale, xmax / scale, datalimit - + threshold - ymax, datalimit - threshold) + call glabax (gd, Memc[str], "", "Intensity") + call gseti (gd, G_YDRAWAXES, 0) + call gseti (gd, G_XDRAWAXES, 1) + call ggview (gd, vx1, vx2, vy1, vy2) + call gswind (gd, vx1, vx2, vy1, vy2) + call gswind (gd, xmin, xmax, datalimit - threshold - ymax, + datalimit - threshold) + call glabax (gd, "", + "Radial Distance (lower-pixels, upper-scale units)", "") + } + + # Set the window up for plotting the data. + call gseti (gd, G_YDRAWAXES, 3) + call gseti (gd, G_XDRAWAXES, 3) + call gsetr (gd, G_ASPECT, aspect) + call gt_sets (gt, GTTYPE, "mark") + call gt_setr (gt, GTXMIN, xmin) + call gt_setr (gt, GTXMAX, xmax) + if (apstati (ap, POSITIVE) == YES) { + call gt_setr (gt, GTYMIN, ymin) + call gt_setr (gt, GTYMAX, ymax) + } else { + call gt_setr (gt, GTYMIN, ymin) + call gt_setr (gt, GTYMAX, ymax) + } + call gt_swind (gd, gt) + + call sfree (sp) +end + + +# AP_CPANNOTATE -- Procedure to annotate the radial plot in center. + +procedure ap_cpannotate (gd, ap) + +pointer gd # the graphics stream +pointer ap # the apphot structure + +pointer sp, str +real fwhmpsf, capert, datalimit, threshold, skysigma, cthreshold +real xmin, xmax, ymin, ymax +int apstati() +real apstatr() + +begin + # Allocate working space. + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + call gseti (gd, G_PLTYPE, GL_DASHED) + call ggwind (gd, xmin, xmax, ymin, ymax) + + fwhmpsf = 0.5 * apstatr (ap, FWHMPSF) * apstatr (ap, SCALE) + capert = 2.0 * fwhmpsf * apstatr (ap, CAPERT) + datalimit = apstatr (ap, CDATALIMIT) + skysigma = apstatr (ap, SKYSIGMA) + cthreshold = apstatr (ap, CTHRESHOLD) + if (IS_INDEFR(skysigma) || IS_INDEFR(cthreshold)) + threshold = 0.0 + else + threshold = cthreshold * skysigma + if (apstati (ap, POSITIVE) == YES) + threshold = datalimit + threshold + else + threshold = datalimit - threshold + + # Plot the full width half maximum of the radial profile. + if (fwhmpsf >= xmin && fwhmpsf <= xmax) { + call gamove (gd, fwhmpsf, ymin) + call gadraw (gd, fwhmpsf, ymax) + call sprintf (Memc[str], SZ_LINE, "hwhm = %0.2f") + call pargr (fwhmpsf) + call gtext (gd, fwhmpsf, ymax, Memc[str], "q=h;u=180;v=t;p=r") + } + + # Mark the centering aperture. + if (capert >= xmin && capert <= xmax) { + call gamove (gd, capert, ymin) + call gadraw (gd, capert, ymax) + call sprintf (Memc[str], SZ_LINE, "cbox half-width = %0.2f") + call pargr (capert) + call gtext (gd, capert, ymax, Memc[str], "q=h;u=180;v=t;p=r") + } + + # Mark the threshold level for centering. + call sprintf (Memc[str], SZ_LINE, "threshold = %g") + call pargr (threshold) + call gtext (gd, xmin, ymin, Memc[str], "q=h") + + # Mark the sky sigma if defined. + if (! IS_INDEFR(skysigma) && skysigma >= ymin && skysigma <= ymax) { + call gmark (gd, (xmin + xmax) / 2.0, (ymin + ymax) / 2.0, + GM_VEBAR, -0.25, -skysigma) + call sprintf (Memc[str], SZ_LINE, "sigma = %g") + call pargr (skysigma) + call gtext (gd, (xmin + xmax) / 2.0, (ymin + ymax + skysigma) / 2.0, + Memc[str], "q=h;h=c") + } + + call sfree (sp) +end + + +# AP_CPRSET -- Procedure to reset the plot window after the data points +# have been plotted. + +procedure ap_cpreset (gd, gt, ap, xmin, xmax, ymin, ymax) + +pointer gd # the graphics stream +pointer gt # the gtools pointer +pointer ap # the apphot pointer +real xmin, xmax # the minimum and maximum radial distance +real ymin, ymax # the minimum and maximum of the y axis (ymin not used) + +real datalimit, skysigma, threshold, cthreshold +int apstati() +real apstatr() + +begin + # Set the data window. + datalimit = apstatr (ap, CDATALIMIT) + skysigma = apstatr (ap, SKYSIGMA) + cthreshold = apstatr (ap, CTHRESHOLD) + if (IS_INDEFR(skysigma) || IS_INDEFR(cthreshold)) + threshold = 0.0 + else + threshold = cthreshold * skysigma + call gt_setr (gt, GTXMIN, xmin) + call gt_setr (gt, GTXMAX, xmax) + if (apstati (ap, POSITIVE) == YES) { + call gt_setr (gt, GTYMIN, datalimit + threshold) + call gt_setr (gt, GTYMAX, ymax + datalimit + threshold) + } else { + call gt_setr (gt, GTYMIN, datalimit - ymax - threshold) + call gt_setr (gt, GTYMAX, datalimit - threshold) + } + call gt_swind (gd, gt) +end diff --git a/noao/digiphot/apphot/center/apcpshow.x b/noao/digiphot/apphot/center/apcpshow.x new file mode 100644 index 00000000..79fdf43e --- /dev/null +++ b/noao/digiphot/apphot/center/apcpshow.x @@ -0,0 +1,66 @@ +include "../lib/center.h" +include "../lib/display.h" + +# AP_CPSHOW -- Procedure to display the current centering algorithm +# parameters. + +procedure ap_cpshow (ap) + +pointer ap # pointer to the apphot strucuture + +pointer sp, str +bool itob() +int apstati() +real apstatr() + +begin + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + + # Print the centering algorithm. + call printf ("Centering Parameters\n") + call apstats (ap, CSTRING, Memc[str], SZ_FNAME) + call printf (" %s = %s %s\n") + call pargstr (KY_CSTRING) + call pargstr (Memc[str]) + call pargstr (UN_CALGORITHM) + + # Print the rest of the centering parameters. + call printf (" %s = %g %s %s = %g %s %s = %g\n") + call pargstr (KY_CAPERT) + call pargr (2.0 * apstatr (ap, CAPERT)) + call pargstr (UN_CSCALEUNIT) + call pargstr (KY_CTHRESHOLD) + call pargr (apstatr (ap, CTHRESHOLD)) + call pargstr (UN_CSIGMA) + call pargstr (KY_MINSNRATIO) + call pargr (apstatr (ap, MINSNRATIO)) + + call printf (" %s = %d %s = %g %s\n") + call pargstr (KY_CMAXITER) + call pargi (apstati (ap, CMAXITER)) + call pargstr (KY_MAXSHIFT) + call pargr (apstatr (ap, MAXSHIFT)) + call pargstr (UN_CNUMBER) + + call printf (" %s = %b %s = %g %s\n") + call pargstr (KY_CLEAN) + call pargb (itob (apstati (ap, CLEAN))) + call pargstr (KY_SIGMACLEAN) + call pargr (apstatr (ap, SIGMACLEAN)) + call pargstr (UN_CSIGMA) + + call printf (" %s = %g %s %s = %g %s\n") + call pargstr (KY_RCLEAN) + call pargr (apstatr (ap, RCLEAN)) + call pargstr (UN_CSCALEUNIT) + call pargstr (KY_RCLIP) + call pargr (apstatr (ap, RCLIP)) + call pargstr (UN_CSCALEUNIT) + + call printf (" %s = %b\n") + call pargstr (KY_MKCENTER) + call pargb (itob (apstati (ap, MKCENTER))) + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/center/apcradsetup.x b/noao/digiphot/apphot/center/apcradsetup.x new file mode 100644 index 00000000..8902c5ef --- /dev/null +++ b/noao/digiphot/apphot/center/apcradsetup.x @@ -0,0 +1,99 @@ +include "../lib/display.h" + +define HELPFILE "apphot$center/icenter.key" + +# AP_CRADSETUP -- Procedure to set up apphot interactively + +procedure ap_cradsetup (ap, im, wx, wy, gd, out, stid) + +pointer ap # pointer to apphot structure +pointer im # pointero to the IRAF image +real wx, wy # cursor coordinates +pointer gd # pointer to graphics stream +int out # output file descriptor +int stid # output file sequence number + +int cier, wcs, key +pointer sp, cmd +real xcenter, ycenter, xc, yc, rmin, rmax, imin, imax, rval +real u1, u2, v1, v2, x1, x2, y1, y2 + +int ap_showplot(), apfitcenter(), apstati(), clgcur() +real ap_cfwhmpsf(), ap_ccapert(), ap_csigma() +real ap_cdatamin(), ap_cdatamax(), ap_crclean(), ap_crclip() + +begin + # Check for open graphics stream. + if (gd == NULL) + return + call greactivate (gd, 0) + + # Store old viewport and window coordinates. + call ggview (gd, u1, u2, v1, v2) + call ggwind (gd, x1, x2, y1, y2) + + # Make the plot. + if (ap_showplot (ap, im, wx, wy, gd, xcenter, ycenter, rmin, rmax, + imin, imax) == ERR) { + call gdeactivate (gd, 0) + return + } + + # Allocate temporary space. + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + call printf ( + "Waiting for setup menu command (?=help, v=default setup, q=quit):\n") + + while (clgcur ("gcommands", xc, yc, wcs, key, Memc[cmd], + SZ_LINE) != EOF) { + + switch (key) { + case 'q': + break + case '?': + call gpagefile (gd, HELPFILE, "") + case 'f': + rval = ap_cfwhmpsf (ap, gd, out, stid, rmin, rmax, imin, imax) + case 's': + rval = ap_csigma (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'l': + rval = ap_cdatamin (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'u': + rval = ap_cdatamax (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'c': + rval = ap_ccapert (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'n': + rval = ap_crclean (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'p': + rval = ap_crclip (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'v': + rval = ap_cfwhmpsf (ap, gd, out, stid, rmin, rmax, imin, imax) + rval = ap_ccapert (ap, gd, out, stid, rmin, rmax, imin, imax) + rval = ap_csigma (ap, gd, out, stid, rmin, rmax, imin, imax) + #rval = ap_ccthresh (ap, gd, out, stid, rmin, rmax, imin, imax) + default: + call printf ("Unknown or ambiguous keystroke command\007\n") + } + call printf ( + "Waiting for setup menu command (?=help, v=default setup, q=quit):\n") + } + + # Set up interactively. + call printf ( + "Interactive setup is complete [Type w to save parameters].\n") + + # Restore old window and viewport coordinates. + call gsview (gd, u1, u2, v1, v2) + call gswind (gd, x1, x2, y1, y2) + + # Free plots and working space. + call sfree (sp) + call gdeactivate (gd, 0) + + # Fit the center and plot the results. + cier = apfitcenter (ap, im, xcenter, ycenter) + call ap_cplot (ap, 0, gd, apstati (ap, RADPLOTS)) + call ap_qcenter (ap, cier) +end diff --git a/noao/digiphot/apphot/center/apcshow.x b/noao/digiphot/apphot/center/apcshow.x new file mode 100644 index 00000000..8cedbfc2 --- /dev/null +++ b/noao/digiphot/apphot/center/apcshow.x @@ -0,0 +1,19 @@ +include "../lib/display.h" + +# AP_CSHOW -- Procedure to display the current centering parameters. + +procedure ap_cshow (ap) + +pointer ap # pointer to the apphot strucuture + +bool itob() +int apstati() + +begin + call ap_nshow (ap) + call printf ("\n") + call ap_cpshow (ap) + call printf (" %s = %b\n") + call pargstr (KY_RADPLOTS) + call pargb (itob (apstati (ap, RADPLOTS))) +end diff --git a/noao/digiphot/apphot/center/apcsnratio.x b/noao/digiphot/apphot/center/apcsnratio.x new file mode 100644 index 00000000..0fd0e20d --- /dev/null +++ b/noao/digiphot/apphot/center/apcsnratio.x @@ -0,0 +1,92 @@ +include <mach.h> +include "../lib/center.h" +include "../lib/noise.h" + +# AP_CSNRATIO -- Procedure to estimate the signal to noise ratio for centering. + +real procedure ap_csnratio (ap, array, nx, ny, threshold) + +pointer ap # apphot structure +real array[nx,ny] # data array +int nx, ny # subraster dimensions +real threshold # threshold value for snr computation + +int apstati() +real apstatr(), ap_cratio(), ap_pratio() + +begin + switch (apstati (ap, NOISEFUNCTION)) { + case AP_NCONSTANT: + return (ap_cratio (array, nx, ny, threshold, apstatr (ap, + SKYSIGMA))) + case AP_NPOISSON: + return (ap_pratio (array, nx, ny, threshold, apstatr (ap, + SKYSIGMA), apstatr (ap, EPADU))) + default: + return (MAX_REAL) + } +end + + +# AP_CRATIO -- Procedure to estimate the signal to noise ratio in the +# centering aperture assuming that the noise is due to a constant sky +# sigma. These computations are approximate only. + +real procedure ap_cratio (array, nx, ny, sky, noise) + +real array[nx,ny] # centering buffer +int nx, ny # dimensions of the centering buffer +real sky # mean sky value of the data in ADU +real noise # estimate of sky noise in ADU + +int npts +real signal, tnoise +real asumr() + +begin + npts = nx * ny + signal = asumr (array, npts) - npts * sky + if (IS_INDEFR(noise)) + tnoise = 0.0 + else + tnoise = sqrt (npts * noise ** 2) + if (signal <= 0.0) + return (0.0) + else if (tnoise <= 0.0) + return (MAX_REAL) + else + return (signal / tnoise) +end + + +# AP_PRATIO -- Procedure to estimate the signal to noise ratio in the +# centering aperture assuming the noise is due to a constant sky sigma +# and poisson statistics in the image. These computations are +# approximate only. + +real procedure ap_pratio (array, nx, ny, sky, noise, padu) + +real array[nx,ny] # centering buffer +int nx, ny # dimensions of the centering buffer +real sky # mean sky value of the data in ADU +real noise # estimate of sky noise in ADU +real padu # photons per adu + +int npts +real signal, tnoise +real asumr() + +begin + npts = nx * ny + signal = asumr (array, npts) - npts * sky + if (IS_INDEFR(noise)) + tnoise = sqrt (abs (signal / padu)) + else + tnoise = sqrt (abs (signal / padu) + npts * noise ** 2) + if (signal <= 0.0) + return (0.0) + else if (tnoise <= 0.0) + return (MAX_REAL) + else + return (signal / tnoise) +end diff --git a/noao/digiphot/apphot/center/apctr1d.x b/noao/digiphot/apphot/center/apctr1d.x new file mode 100644 index 00000000..10ee109e --- /dev/null +++ b/noao/digiphot/apphot/center/apctr1d.x @@ -0,0 +1,113 @@ +include <mach.h> +include "../lib/center.h" + +# AP_CTR1D -- Procedure to compute the center from the 1D marginal +# distributions. + +int procedure ap_ctr1d (ctrpix, nx, ny, norm, xc, yc, xerr, yerr) + +real ctrpix[nx, ny] # object to be centered +int nx, ny # dimensions of subarray +real norm # the normalization factor +real xc, yc # computed centers +real xerr, yerr # estimate of centering error + +pointer sp, xm, ym + +begin + call smark (sp) + call salloc (xm, nx, TY_REAL) + call salloc (ym, ny, TY_REAL) + + # Compute the marginal distributions. + call ap_mkmarg (ctrpix, Memr[xm], Memr[ym], nx, ny) + call adivkr (Memr[xm], real (ny), Memr[xm], nx) + call adivkr (Memr[ym], real (nx), Memr[ym], ny) + + # Get the centers and errors. + call ap_cmarg (Memr[xm], nx, norm, xc, xerr) + call ap_cmarg (Memr[ym], ny, norm, yc, yerr) + + call sfree (sp) + return (AP_OK) +end + + +# AP_CMARG -- Compute the center and estimate its error given the +# marginal distribution and the number of points. + +procedure ap_cmarg (a, npts, norm, xc, err) + +real a[npts] # array +int npts # number of points +real norm # the normalization factor +real xc # center value +real err # error + +int i, npos +real val, sumi, sumix, sumix2 + +begin + # Initialize. + npos = 0 + sumi = 0.0 + sumix = 0.0 + sumix2 = 0.0 + + # Accumulate the sums. + do i = 1, npts { + val = a[i] + if (val > 0.0) + npos = npos + 1 + sumi = sumi + val + sumix = sumix + val * i + sumix2 = sumix2 + val * i ** 2 + } + + # Compute the position and the error. + if (npos <= 0) { + xc = (1.0 + npts) / 2.0 + err = INDEFR + } else { + xc = sumix / sumi + err = (sumix2 / sumi - xc * xc) + if (err <= 0.0) { + err = 0.0 + } else { + err = sqrt (err / (sumi * norm)) + if (err > real (npts)) + err = INDEFR + } + } +end + + +# AP_MKMARG -- Accumulate the marginal distributions. + +procedure ap_mkmarg (ctrpix, xm, ym, nx, ny) + +real ctrpix[nx, ny] # pixels +real xm[nx] # x marginal distribution +real ym[ny] # y marginal distribution +int nx, ny # dimensions of array + +int i, j +real sum + +begin + # Compute the x marginal. + do i = 1, nx { + sum = 0.0 + do j = 1, ny + sum = sum + ctrpix[i,j] + xm[i] = sum + } + + # Compute the y marginal. + do j = 1, ny { + sum = 0.0 + do i = 1, nx + sum = sum + ctrpix[i,j] + ym[j] = sum + } +end diff --git a/noao/digiphot/apphot/center/apctrbuf.x b/noao/digiphot/apphot/center/apctrbuf.x new file mode 100644 index 00000000..0a8053b8 --- /dev/null +++ b/noao/digiphot/apphot/center/apctrbuf.x @@ -0,0 +1,115 @@ +include <imhdr.h> +include <math.h> +include <mach.h> +include "../lib/apphotdef.h" +include "../lib/centerdef.h" +include "../lib/center.h" + +# APCTRBUF -- Procedure to fetch the center pixels given the pointer to the +# IRAF image, the coordinates of the initial center and the width of the APPHOT +# centering box. + +int procedure apctrbuf (ap, im, wx, wy) + +pointer ap # pointer to apphot structure +pointer im # pointer to the IRAF image +real wx, wy # center coordinates + +int icpix +pointer ctr +real cpix, gdatamin, gdatamax, datamin, datamax +pointer ap_ctrpix() + +begin + # Get pointer to centering structure. + ctr = AP_PCENTER(ap) + + # Check for 0 sized aperture. + if (AP_CAPERT(ctr) <= 0.0) + return (AP_CTR_NOAREA) + + # Get the centering buffer of pixels. + cpix = max (1.0, AP_CAPERT(ctr) * AP_SCALE(ap)) + icpix = 2 * int (cpix) + 1 + if (AP_CTRPIX(ctr) != NULL) + call mfree (AP_CTRPIX(ctr), TY_REAL) + AP_CTRPIX(ctr) = ap_ctrpix (im, wx, wy, icpix, + AP_CXC(ctr), AP_CYC(ctr), AP_CNX(ctr), AP_CNY(ctr)) + if (AP_CTRPIX(ctr) == NULL) + return (AP_CTR_NOAREA) + + # Compute the data limits. + if (IS_INDEFR(AP_DATAMIN(ap))) + gdatamin = -MAX_REAL + else + gdatamin = AP_DATAMIN(ap) + if (IS_INDEFR(AP_DATAMAX(ap))) + gdatamax = MAX_REAL + else + gdatamax = AP_DATAMAX(ap) + call alimr (Memr[AP_CTRPIX(ctr)], AP_CNX(ctr) * AP_CNY(ctr), + datamin, datamax) + + if (datamin < gdatamin || datamax > gdatamax) + return (AP_CTR_BADDATA) + else if (AP_CNX(ctr) < icpix || AP_CNY(ctr) < icpix) + return (AP_CTR_OUTOFBOUNDS) + else + return (AP_OK) +end + + +# AP_CTRPIX -- Procedure to fetch the pixels to be used for centering. + +pointer procedure ap_ctrpix (im, wx, wy, capert, xc, yc, nx, ny) + +pointer im # pointer to IRAF image +real wx, wy # center of subraster to be extracted +int capert # width of subraster to be extracted +real xc, yc # center of extracted subraster +int nx, ny # dimensions of extracted subraster + +int i, ncols, nlines, c1, c2, l1, l2, half_capert +pointer buf, lbuf +real xc1, xc2, xl1, xl2 +pointer imgs2r() + +begin + # Check for nonsensical input. + half_capert = (capert - 1) / 2 + if (half_capert <= 0) + return (NULL) + + # Test for out of bounds pixels + ncols = IM_LEN(im,1) + nlines = IM_LEN(im,2) + xc1 = wx - half_capert + xc2 = wx + half_capert + xl1 = wy - half_capert + xl2 = wy + half_capert + if (xc1 > real (ncols) || xc2 < 1.0 || xl1 > real (nlines) || xl2 < 1.0) + return (NULL) + + # Get column and line limits, dimensions and center of subraster. + c1 = max (1.0, min (real (ncols), xc1)) + 0.5 + c2 = min (real (ncols), max (1.0, xc2)) + 0.5 + l1 = max (1.0, min (real (nlines), xl1)) + 0.5 + l2 = min (real (nlines), max (1.0, xl2)) + 0.5 + nx = c2 - c1 + 1 + ny = l2 - l1 + 1 + xc = wx - c1 + 1 + yc = wy - l1 + 1 + + # Get pixels and return. + if (nx < 1 && ny < 1) + return (NULL) + else { + call malloc (buf, nx * ny, TY_REAL) + lbuf = buf + do i = l1, l2 { + call amovr (Memr[imgs2r (im, c1, c2, i, i)], Memr[lbuf], nx) + lbuf = lbuf + nx + } + return (buf) + } +end diff --git a/noao/digiphot/apphot/center/apfitcen.x b/noao/digiphot/apphot/center/apfitcen.x new file mode 100644 index 00000000..bd7224e8 --- /dev/null +++ b/noao/digiphot/apphot/center/apfitcen.x @@ -0,0 +1,291 @@ +include <mach.h> +include "../lib/apphotdef.h" +include "../lib/apphot.h" +include "../lib/noisedef.h" +include "../lib/centerdef.h" +include "../lib/center.h" + +define CONVERT .424660900 # conversion from fwhmpsf to sigma + +# APFITCENTER -- Procedure to fit the centers using either 1) the intensity +# weighted mean of the marginal distributions, 2) a Gaussian fit to the +# marginals assuming a fixed sigma or 3) a simplified version of the optimal +# filtering method using a Gaussian of fixed sigma to model the profile. + +int procedure apfitcenter (ap, im, wx, wy) + +pointer ap # pointer to the apphot structure +pointer im # pointer to the IRAF image +real wx, wy # object coordinates + +int i, niter, ier, fier, lowsnr +pointer ctr, nse +real cthreshold, datamin, datamax, owx, owy, xshift, yshift, med +int apctrbuf(), ap_ctr1d(), ap_mctr1d(), ap_gctr1d(), ap_lgctr1d() +real ap_csnratio(), amedr() + +begin + ctr = AP_PCENTER(ap) + nse = AP_NOISE(ap) + ier = AP_OK + + # Initialize. + AP_CXCUR(ctr) = wx + AP_CYCUR(ctr) = wy + AP_OXINIT(ctr) = INDEFR + AP_OYINIT(ctr) = INDEFR + AP_XCENTER(ctr) = INDEFR + AP_YCENTER(ctr) = INDEFR + AP_OXCENTER(ctr) = INDEFR + AP_OYCENTER(ctr) = INDEFR + AP_XSHIFT(ctr) = 0.0 + AP_YSHIFT(ctr) = 0.0 + AP_OXSHIFT(ctr) = 0.0 + AP_OYSHIFT(ctr) = 0.0 + AP_XERR(ctr) = INDEFR + AP_YERR(ctr) = INDEFR + + # Return input coordinates if centering is disabled. + if (IS_INDEFR(wx) || IS_INDEFR(wy)) { + return (AP_CTR_NOAREA) + } else if (AP_CENTERFUNCTION(ctr) == AP_NONE) { + AP_XCENTER(ctr) = wx + AP_YCENTER(ctr) = wy + switch (AP_WCSOUT(ap)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_ltoo (ap, wx, wy, AP_OXINIT(ctr), AP_OYINIT(ctr), 1) + call ap_ltoo (ap, wx, wy, AP_OXCENTER(ctr), AP_OYCENTER(ctr), 1) + case WCS_TV: + call ap_ltov (im, wx, wy, AP_OXINIT(ctr), AP_OYINIT(ctr), 1) + call ap_ltov (im, wx, wy, AP_OXCENTER(ctr), AP_OYCENTER(ctr), 1) + default: + AP_OXINIT(ctr) = wx + AP_OYINIT(ctr) = wy + AP_OXCENTER(ctr) = wx + AP_OYCENTER(ctr) = wy + } + return (AP_OK) + } + + # Intialize. + owx = wx + owy = wy + niter = 0 + if (IS_INDEFR(AP_SKYSIGMA(nse)) || IS_INDEFR(AP_CTHRESHOLD(ctr)) || + AP_CTHRESHOLD(ctr) <= 0.0) + cthreshold = 0.0 + else + cthreshold = AP_CTHRESHOLD(ctr) * AP_SKYSIGMA(nse) + + repeat { + + # Set initial cursor position. + AP_CXCUR(ctr) = owx + AP_CYCUR(ctr) = owy + + # Get centering pixels. + ier = apctrbuf (ap, im, owx, owy) + if (ier == AP_CTR_NOAREA) { + AP_XCENTER(ctr) = wx + AP_YCENTER(ctr) = wy + AP_XSHIFT(ctr) = 0.0 + AP_YSHIFT(ctr) = 0.0 + AP_XERR(ctr) = INDEFR + AP_YERR(ctr) = INDEFR + switch (AP_WCSOUT(ap)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_ltoo (ap, wx, wy, AP_OXINIT(ctr), AP_OYINIT(ctr), 1) + call ap_ltoo (ap, wx, wy, AP_OXCENTER(ctr), + AP_OYCENTER(ctr), 1) + case WCS_TV: + call ap_ltov (im, wx, wy, AP_OXINIT(ctr), AP_OYINIT(ctr), 1) + call ap_ltov (im, wx, wy, AP_OXCENTER(ctr), + AP_OYCENTER(ctr), 1) + default: + AP_OXINIT(ctr) = wx + AP_OYINIT(ctr) = wy + AP_OXCENTER(ctr) = wx + AP_OYCENTER(ctr) = wy + } + AP_OXSHIFT(ctr) = 0.0 + AP_OYSHIFT(ctr) = 0.0 + return (ier) + } + + # Clean the subraster. + if (AP_CLEAN(ctr) == YES) + call apclean (ap, Memr[AP_CTRPIX(ctr)], AP_CNX(ctr), + AP_CNY(ctr), AP_CXC(ctr), AP_CYC(ctr)) + + # Compute the datalimits. + if (cthreshold <= 0.0) + call alimr (Memr[AP_CTRPIX(ctr)], AP_CNX(ctr) * AP_CNY(ctr), + datamin, datamax) + else { + datamin = MAX_REAL + datamax = -MAX_REAL + do i = 1, AP_CNY(ctr) { + med = amedr (Memr[AP_CTRPIX(ctr)+(i-1)*AP_CNX(ctr)], + AP_CNX(ctr)) + if (med < datamin) + datamin = med + if (med > datamax) + datamax = med + } + } + + # Apply threshold and check for positive or negative features. + if (AP_POSITIVE(ap) == YES) { + call apsetr (ap, CDATALIMIT, datamin) + call asubkr (Memr[AP_CTRPIX(ctr)], datamin + + cthreshold, Memr[AP_CTRPIX(ctr)], AP_CNX(ctr) * + AP_CNY(ctr)) + call amaxkr (Memr[AP_CTRPIX(ctr)], 0.0, Memr[AP_CTRPIX(ctr)], + AP_CNX(ctr) * AP_CNY(ctr)) + } else { + call apsetr (ap, CDATALIMIT, datamax) + call anegr (Memr[AP_CTRPIX(ctr)], Memr[AP_CTRPIX(ctr)], + AP_CNX(ctr) * AP_CNY(ctr)) + call aaddkr (Memr[AP_CTRPIX(ctr)], datamax - + cthreshold, Memr[AP_CTRPIX(ctr)], AP_CNX(ctr) * + AP_CNY(ctr)) + call amaxkr (Memr[AP_CTRPIX(ctr)], 0.0, + Memr[AP_CTRPIX(ctr)], AP_CNX(ctr) * AP_CNY(ctr)) + } + + # Test signal to noise ratio. + if (ap_csnratio (ap, Memr[AP_CTRPIX(ctr)], AP_CNX(ctr), + AP_CNY(ctr), 0.0) < AP_MINSNRATIO(ctr)) + lowsnr = YES + else + lowsnr = NO + + # Compute the x and y centers. + switch (AP_CENTERFUNCTION(ctr)) { + + case AP_CENTROID1D: + if (AP_CTHRESHOLD(ctr) <= 0.0) { + fier = ap_mctr1d (Memr[AP_CTRPIX(ctr)], AP_CNX(ctr), + AP_CNY(ctr), AP_EPADU(nse), AP_XCENTER(ctr), + AP_YCENTER(ctr), AP_XERR(ctr), AP_YERR(ctr)) + if (IS_INDEFR (AP_XERR(ctr))) + AP_XCENTER(ctr) = AP_CXC(ctr) + if (IS_INDEFR (AP_YERR(ctr))) + AP_YCENTER(ctr) = AP_CYC(ctr) + } else { + fier = ap_ctr1d (Memr[AP_CTRPIX(ctr)], AP_CNX(ctr), + AP_CNY(ctr), AP_EPADU(nse), AP_XCENTER(ctr), + AP_YCENTER(ctr), AP_XERR(ctr), AP_YERR(ctr)) + if (IS_INDEFR (AP_XERR(ctr))) + AP_XCENTER(ctr) = AP_CXC(ctr) + if (IS_INDEFR (AP_YERR(ctr))) + AP_YCENTER(ctr) = AP_CYC(ctr) + } + + case AP_GAUSS1D: + + fier = ap_gctr1d (Memr[AP_CTRPIX(ctr)], AP_CNX(ctr), + AP_CNY(ctr), CONVERT * AP_FWHMPSF(ap) * AP_SCALE(ap), + AP_CMAXITER(ctr), AP_XCENTER(ctr), AP_YCENTER(ctr), + AP_XERR(ctr), AP_YERR(ctr)) + + case AP_OFILT1D: + + fier = ap_lgctr1d (Memr[AP_CTRPIX(ctr)], AP_CNX(ctr), + AP_CNY(ctr), AP_CXC(ctr), AP_CYC(ctr), CONVERT * + AP_FWHMPSF(ap) * AP_SCALE(ap), AP_CMAXITER(ctr), + AP_EPADU(nse), AP_SKYSIGMA(nse), AP_XCENTER(ctr), + AP_YCENTER(ctr), AP_XERR(ctr), AP_YERR(ctr)) + + default: + # do nothing gracefully + } + + # Confine the next x center to the data box. + AP_XCENTER(ctr) = max (0.5, min (AP_CNX(ctr) + 0.5, + AP_XCENTER(ctr))) + xshift = AP_XCENTER(ctr) - AP_CXC(ctr) + AP_XCENTER(ctr) = xshift + owx + AP_XSHIFT(ctr) = AP_XCENTER(ctr) - wx + + # Confine the next y center to the data box. + AP_YCENTER(ctr) = max (0.5, min (AP_CNY(ctr) + 0.5, + AP_YCENTER(ctr))) + yshift = AP_YCENTER(ctr) - AP_CYC(ctr) + AP_YCENTER(ctr) = yshift + owy + AP_YSHIFT(ctr) = AP_YCENTER(ctr) - wy + + switch (AP_WCSOUT(ap)) { + case WCS_PHYSICAL, WCS_WORLD: + call ap_ltoo (ap, AP_XCENTER(ctr), AP_YCENTER(ctr), + AP_OXCENTER(ctr), AP_OYCENTER(ctr), 1) + call ap_ltoo (ap, AP_XCENTER(ctr) - AP_XSHIFT(ctr), + AP_YCENTER(ctr) - AP_YSHIFT(ctr), AP_OXINIT(ctr), + AP_OYINIT(ctr), 1) + AP_OXSHIFT(ctr) = AP_OXCENTER(ctr) - AP_OXINIT(ctr) + AP_OYSHIFT(ctr) = AP_OYCENTER(ctr) - AP_OYINIT(ctr) + case WCS_TV: + call ap_ltov (im, AP_XCENTER(ctr), AP_YCENTER(ctr), + AP_OXCENTER(ctr), AP_OYCENTER(ctr), 1) + call ap_ltov (im, AP_XCENTER(ctr) - AP_XSHIFT(ctr), + AP_YCENTER(ctr) - AP_YSHIFT(ctr), AP_OXINIT(ctr), + AP_OYINIT(ctr), 1) + AP_OXSHIFT(ctr) = AP_OXCENTER(ctr) - AP_OXINIT(ctr) + AP_OYSHIFT(ctr) = AP_OYCENTER(ctr) - AP_OYINIT(ctr) + default: + AP_OXINIT(ctr) = AP_XCENTER(ctr) - AP_XSHIFT(ctr) + AP_OYINIT(ctr) = AP_YCENTER(ctr) - AP_YSHIFT(ctr) + AP_OXCENTER(ctr) = AP_XCENTER(ctr) + AP_OYCENTER(ctr) = AP_YCENTER(ctr) + AP_OXSHIFT(ctr) = AP_XSHIFT(ctr) + AP_OYSHIFT(ctr) = AP_YSHIFT(ctr) + + } + + # Setup for next iteration. + niter = niter + 1 + owx = AP_XCENTER(ctr) + owy = AP_YCENTER(ctr) + + } until ((fier != AP_OK && fier != AP_CTR_NOCONVERGE) || + (niter >= AP_CMAXITER(ctr)) || (abs (xshift) < 1.0 && + abs (yshift) < 1.0)) + + # Return appropriate error code. + if (fier != AP_OK) { + AP_XCENTER(ctr) = wx + AP_YCENTER(ctr) = wy + AP_XSHIFT(ctr) = 0.0 + AP_YSHIFT(ctr) = 0.0 + AP_XERR(ctr) = INDEFR + AP_YERR(ctr) = INDEFR + switch (AP_WCSOUT(ap)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_ltoo (ap, wx, wy, AP_OXINIT(ctr), AP_OYINIT(ctr), 1) + call ap_ltoo (ap, wx, wy, AP_OXCENTER(ctr), AP_OYCENTER(ctr), 1) + case WCS_TV: + call ap_ltov (im, wx, wy, AP_OXINIT(ctr), AP_OYINIT(ctr), 1) + call ap_ltov (im, wx, wy, AP_OXCENTER(ctr), AP_OYCENTER(ctr), 1) + default: + AP_OXINIT(ctr) = wx + AP_OYINIT(ctr) = wy + AP_OXCENTER(ctr) = wx + AP_OYCENTER(ctr) = wy + } + AP_OXSHIFT(ctr) = 0.0 + AP_OYSHIFT(ctr) = 0.0 + return (fier) + } else if (ier == AP_CTR_BADDATA) { + return (AP_CTR_BADDATA) + } else if (lowsnr == YES) { + return (AP_CTR_LOWSNRATIO) + } else if (abs (AP_XSHIFT(ctr)) > (AP_MAXSHIFT(ctr) * AP_SCALE(ap))) { + return (AP_CTR_BADSHIFT) + } else if (abs (AP_YSHIFT(ctr)) > (AP_MAXSHIFT(ctr) * AP_SCALE(ap))) { + return (AP_CTR_BADSHIFT) + } else if (ier == AP_CTR_OUTOFBOUNDS) { + return (AP_CTR_OUTOFBOUNDS) + } else { + return (AP_OK) + } +end diff --git a/noao/digiphot/apphot/center/apgcpars.x b/noao/digiphot/apphot/center/apgcpars.x new file mode 100644 index 00000000..e40db12e --- /dev/null +++ b/noao/digiphot/apphot/center/apgcpars.x @@ -0,0 +1,27 @@ +include "../lib/display.h" +include "../lib/noise.h" +include "../lib/center.h" + +# AP_GCPARS -- Procedure to read in the centering parameters from the +# appropriate parameters files. + +procedure ap_gcpars (ap) + +pointer ap # pointer to the apphot structure + +bool clgetb() +int btoi() + +begin + # Initialize the structure. + call apcinit (ap, AP_CENTROID1D, 2.5, 2.0, AP_NPOISSON) + + # Get the data dependent parameters. + call ap_gdapars (ap) + + # Get the centering algorithm parameters. + call ap_gcepars (ap) + + # Make radial plots on stdgraph. + call apseti (ap, RADPLOTS, btoi (clgetb ("radplots"))) +end diff --git a/noao/digiphot/apphot/center/apgctr1d.x b/noao/digiphot/apphot/center/apgctr1d.x new file mode 100644 index 00000000..e0ac8077 --- /dev/null +++ b/noao/digiphot/apphot/center/apgctr1d.x @@ -0,0 +1,105 @@ +include <math/nlfit.h> +include "../lib/center.h" + +define NPARS 4 # the total number of parameters +define NAPARS 3 # the total number of active parameters +define TOL 0.001 # the tolerance for convergence + +# AP_GCTR1D -- Procedure to compute the x and y centers from the 1D marginal +# distributions using 1D Gaussian fits. Three parameters are fit for each +# marginal, the amplitude, the center of the Gaussian function itself +# and a constant background value. The sigma is set by the user and is +# assumed to be fixed. + +int procedure ap_gctr1d (ctrpix, nx, ny, sigma, maxiter, xc, yc, xerr, yerr) + +real ctrpix[nx, ny] # data subarray +int nx, ny # dimensions of data subarray +real sigma # sigma of PSF +int maxiter # maximum number of iterations +real xc, yc # computed centers +real xerr, yerr # estimate of centering error + +extern cgauss1d, cdgauss1d +int i, minel, maxel, xier, yier, npar, npts +pointer sp, x, xm, ym, w, fit, list, nl +real chisqr, variance, p[NPARS], dp[NPARS] +int locpr() + +begin + # Check the number of points. + if (nx < NAPARS || ny < NAPARS) + return (AP_CTR_NTOO_SMALL) + npts = max (nx, ny) + + call smark (sp) + call salloc (list, NAPARS, TY_INT) + call salloc (xm, nx, TY_REAL) + call salloc (ym, ny, TY_REAL) + call salloc (x, npts, TY_REAL) + call salloc (w, npts, TY_REAL) + call salloc (fit, npts, TY_REAL) + do i = 1, npts + Memr[x+i-1] = i + + # Compute the marginal distributions. + call ap_mkmarg (ctrpix, Memr[xm], Memr[ym], nx, ny) + call adivkr (Memr[xm], real (nx), Memr[xm], nx) + call adivkr (Memr[ym], real (ny), Memr[ym], ny) + + # Specify which parameters are to be fit. + Memi[list] = 1 + Memi[list+1] = 2 + Memi[list+2] = 4 + + # Initialize the x fit parameters. + call ap_alimr (Memr[xm], nx, p[4], p[1], minel, maxel) + p[1] = p[1] - p[4] + p[2] = maxel + p[3] = sigma ** 2 + + # Compute the x center and error. + call nlinitr (nl, locpr (cgauss1d), locpr (cdgauss1d), p, dp, NPARS, + Memi[list], NAPARS, TOL, maxiter) + call nlfitr (nl, Memr[x], Memr[xm], Memr[w], nx, 1, WTS_UNIFORM, xier) + call nlvectorr (nl, Memr[x], Memr[fit], nx, 1) + call nlpgetr (nl, p, npar) + call nlerrorsr (nl, Memr[xm], Memr[fit], Memr[w], nx, variance, + chisqr, dp) + call nlfreer (nl) + xc = p[2] + xerr = dp[2] / sqrt (real (nx)) + if (xerr > real (nx)) + xerr = INDEFR + + # Initialize the y fit parameters. + call ap_alimr (Memr[ym], ny, p[4], p[1], minel, maxel) + p[1] = p[1] - p[4] + p[2] = maxel + p[3] = sigma ** 2 + + # Fit the y marginal. + call nlinitr (nl, locpr (cgauss1d), locpr (cdgauss1d), p, dp, NPARS, + Memi[list], NAPARS, TOL, maxiter) + call nlfitr (nl, Memr[x], Memr[ym], Memr[w], ny, 1, WTS_UNIFORM, yier) + call nlvectorr (nl, Memr[x], Memr[fit], ny, 1) + call nlpgetr (nl, p, npar) + call nlerrorsr (nl, Memr[ym], Memr[fit], Memr[w], ny, variance, + chisqr, dp) + call nlfreer (nl) + yc = p[2] + yerr = dp[2] / sqrt (real (ny)) + if (yerr > real (ny)) + yerr = INDEFR + + # Return the appropriate error code. + call sfree (sp) + if (xier == NO_DEG_FREEDOM || yier == NO_DEG_FREEDOM) + return (AP_CTR_NTOO_SMALL) + else if (xier == SINGULAR || yier == SINGULAR) + return (AP_CTR_SINGULAR) + else if (xier == NOT_DONE || yier == NOT_DONE) + return (AP_CTR_NOCONVERGE) + else + return (AP_OK) +end diff --git a/noao/digiphot/apphot/center/apictr.x b/noao/digiphot/apphot/center/apictr.x new file mode 100644 index 00000000..3a3bd31e --- /dev/null +++ b/noao/digiphot/apphot/center/apictr.x @@ -0,0 +1,48 @@ +# AP_ICTR -- Given a subraster of pixels and an initial center compute +# the centroid of the pixels. + +procedure ap_ictr (im, wx, wy, radius, emission, xcenter, ycenter) + +pointer im # pointer to the iraf image +real wx # initial x coordinate +real wy # initial y coordinate +int radius # half width of centering box +int emission # emission feature +real xcenter # fitted x coordinate +real ycenter # fitted y coordinate + +int nx, ny, ier +pointer cbuf +real xc, yc, datamin, datamax, junk +int ap_mctr1d() +pointer ap_ctrpix() + +begin + # Get the pixels. + cbuf = ap_ctrpix (im, wx, wy, radius, xc, yc, nx, ny) + if (cbuf == NULL) { + xcenter = wx + ycenter = wy + return + } + + # Fit the center of the subraster. + call alimr (Memr[cbuf], nx * ny, datamin, datamax) + if (emission == YES) + call asubkr (Memr[cbuf], datamin, Memr[cbuf], nx * ny) + else { + call anegr (Memr[cbuf], Memr[cbuf], nx * ny) + call aaddkr (Memr[cbuf], datamax, Memr[cbuf], nx * ny) + } + ier = ap_mctr1d (Memr[cbuf], nx, ny, 1.0, xcenter, ycenter, junk, junk) + + # Compute the center in image coordinates. + if (IS_INDEFR(xcenter)) + xcenter = wx + else + xcenter = xcenter + wx - xc + if (IS_INDEFR(ycenter)) + ycenter = wy + else + ycenter = ycenter + wy - yc +end diff --git a/noao/digiphot/apphot/center/aplgctr1d.x b/noao/digiphot/apphot/center/aplgctr1d.x new file mode 100644 index 00000000..ce6d7c53 --- /dev/null +++ b/noao/digiphot/apphot/center/aplgctr1d.x @@ -0,0 +1,87 @@ +include <math.h> +include "../lib/center.h" + +define TOL 0.001 # tolerance for fitting algorithm + +# AP_LGCTR1D -- Procedure to compute the center from the 1D marginal +# distributions using a simplified version of the optimal filtering +# technique and addopting a Gaussian model for the fit. The method +# is streamlined by replacing the Gaussian with a simple triangle +# following L.Goad. + +int procedure ap_lgctr1d (ctrpix, nx, ny, cx, cy, sigma, maxiter, norm, + skysigma, xc, yc, xerr, yerr) + +real ctrpix[nx, ny] # object to be centered +int nx, ny # dimensions of subarray +real cx, cy # center in subraster coordinates +real sigma # sigma of PSF +int maxiter # maximum number of iterations +real norm # the normalization factor +real skysigma # standard deviation of the pixels +real xc, yc # computed centers +real xerr, yerr # first guess at errors + +int nxiter, nyiter +pointer sp, xm, ym +real ratio, constant + +int aptopt() +real asumr() + +begin + # Allocate working space. + call smark (sp) + call salloc (xm, nx, TY_REAL) + call salloc (ym, ny, TY_REAL) + + # Compute the marginal distributions. + call ap_mkmarg (ctrpix, Memr[xm], Memr[ym], nx, ny) + xerr = asumr (Memr[xm], nx) + yerr = asumr (Memr[ym], ny) + call adivkr (Memr[xm], real (nx), Memr[xm], nx) + call adivkr (Memr[ym], real (ny), Memr[ym], ny) + + # Compute the x center and error. + xc = cx + nxiter = aptopt (Memr[xm], nx, xc, sigma, TOL, maxiter, YES) + if (xerr <= 0.0) + xerr = INDEFR + else { + if (IS_INDEFR(skysigma)) + constant = 0.0 + else + constant = 4.0 * SQRTOFPI * sigma * skysigma ** 2 + ratio = constant / xerr + xerr = sigma ** 2 / (xerr * norm) + xerr = sqrt (max (xerr, ratio * xerr)) + if (xerr > real (nx)) + xerr = INDEFR + } + + # Compute the y center and error. + yc = cy + nyiter = aptopt (Memr[ym], ny, yc, sigma, TOL, maxiter, YES) + if (yerr <= 0.0) + yerr = INDEFR + else { + if (IS_INDEFR(skysigma)) + constant = 0.0 + else + constant = 4.0 * SQRTOFPI * sigma * skysigma ** 2 + ratio = constant / yerr + yerr = sigma ** 2 / (yerr * norm) + yerr = sqrt (max (yerr, ratio * yerr)) + if (yerr > real (ny)) + yerr = INDEFR + } + + # Return appropriate error code. + call sfree (sp) + if (nxiter < 0 || nyiter < 0) + return (AP_CTR_SINGULAR) + else if (nxiter > maxiter || nyiter > maxiter) + return (AP_CTR_NOCONVERGE) + else + return (AP_OK) +end diff --git a/noao/digiphot/apphot/center/apmctr1d.x b/noao/digiphot/apphot/center/apmctr1d.x new file mode 100644 index 00000000..5dc47f60 --- /dev/null +++ b/noao/digiphot/apphot/center/apmctr1d.x @@ -0,0 +1,88 @@ +include <mach.h> +include "../lib/center.h" + +# AP_MCTR1D -- Procedure to compute the center from the 1D marginal +# distributions. + +int procedure ap_mctr1d (ctrpix, nx, ny, norm, xc, yc, xerr, yerr) + +real ctrpix[nx, ny] # object to be centered +int nx, ny # dimensions of subarray +real norm # the normalization factor +real xc, yc # computed centers +real xerr, yerr # estimate of centering error + +pointer sp, xm, ym + +begin + call smark (sp) + call salloc (xm, nx, TY_REAL) + call salloc (ym, ny, TY_REAL) + + # Compute the marginal distributions. + call ap_mkmarg (ctrpix, Memr[xm], Memr[ym], nx, ny) + call adivkr (Memr[xm], real (ny), Memr[xm], nx) + call adivkr (Memr[ym], real (nx), Memr[ym], ny) + + # Get the centers and errors. + call ap_cmmarg (Memr[xm], nx, norm, xc, xerr) + call ap_cmmarg (Memr[ym], ny, norm, yc, yerr) + + call sfree (sp) + return (AP_OK) +end + + +# AP_CMMARG -- Compute the center and estimate its error given the +# marginal distribution and the number of points. The center is estimated +# using a centroid which is an optimal solution for a gaussian star with +# no background noise. The centering error is computing using a variance +# estimate based on a gaussian star with no background noise. + +procedure ap_cmmarg (a, npts, norm, xc, err) + +real a[npts] # array +int npts # number of points +real norm # the normalization factor +real xc # center value +real err # error + +int i, npos +real sumi, sumix, sumix2, mean, val +real asumr() + +begin + # Initialize. + mean = asumr (a, npts) / npts + npos = 0 + sumi = 0.0 + sumix = 0.0 + sumix2 = 0.0 + + # Accumulate the sums. + do i = 1, npts { + val = (a[i] - mean) + if (val > 0.0) { + npos = npos + 1 + sumi = sumi + val + sumix = sumix + val * i + sumix2 = sumix2 + val * i ** 2 + } + } + + # Compute the position and the error. + if (npos <= 0) { + xc = (1.0 + npts) / 2.0 + err = INDEFR + } else { + xc = sumix / sumi + err = (sumix2 / sumi - xc * xc) + if (err <= 0.0) { + err = 0.0 + } else { + err = sqrt (err / ((sumi + mean * npts) * norm)) + if (err > real (npts)) + err = INDEFR + } + } +end diff --git a/noao/digiphot/apphot/center/appcenter.x b/noao/digiphot/apphot/center/appcenter.x new file mode 100644 index 00000000..c2590fa3 --- /dev/null +++ b/noao/digiphot/apphot/center/appcenter.x @@ -0,0 +1,84 @@ +include "../lib/apphot.h" +include "../lib/center.h" + +# AP_PCENTER -- Procedure to write the output of centering task to a file. + +procedure ap_pcenter (ap, fd, id, lid, ier) + +pointer ap # pointer to apphot structure +int fd # output file descriptor +int id # id of the star +int lid # list number +int ier # comment string + +real xpos, ypos +real apstatr() + +begin + if (fd == NULL) + return + + # Print description of object. + xpos = apstatr (ap, OXINIT) + ypos = apstatr (ap, OYINIT) + call ap_wid (ap, fd, xpos, ypos, id, lid, '\\') + + # Print the computed centers. + call ap_wcres (ap, fd, ier, ' ') +end + + +# AP_QCENTER -- Procedure to print a quick summary of the center task output +# on the standard output. + +procedure ap_qcenter (ap, ier) + +pointer ap # pointer to apphot structure +int ier # comment string + +real owx, owy, wx, wy +pointer sp, imname +real apstatr() + +begin + call smark (sp) + call salloc (imname, SZ_FNAME, TY_CHAR) + + owx = apstatr (ap, OXINIT) + owy = apstatr (ap, OYINIT) + wx = apstatr (ap, OXCENTER) + wy = apstatr (ap, OYCENTER) + + call apstats (ap, IMROOT, Memc[imname], SZ_FNAME) + call printf ( "%s %7.2f %7.2f %7.2f %7.2f ") + call pargstr (Memc[imname]) + call pargr (owx) + call pargr (owy) + call pargr (wx) + call pargr (wy) + call printf ("%6.2f %6.2f %s\n") + call pargr (apstatr (ap, XERR)) + call pargr (apstatr (ap, YERR)) + if (ier != AP_OK) + call pargstr ("err") + else + call pargstr ("ok") + + call sfree (sp) +end + + +# AP_CPHDR -- Procedure to write the banner for the center task to the +# output file. + +procedure ap_cphdr (ap, fd) + +pointer ap # apphot descriptor +int fd # output file descriptor + +begin + if (fd == NULL) + return + call ap_idhdr (ap, fd) + call ap_chdr (ap, fd) +end diff --git a/noao/digiphot/apphot/center/appcpars.x b/noao/digiphot/apphot/center/appcpars.x new file mode 100644 index 00000000..272fcc07 --- /dev/null +++ b/noao/digiphot/apphot/center/appcpars.x @@ -0,0 +1,21 @@ +include "../lib/display.h" + +# AP_PCPARS -- Procedure to write out the current centering parameters +# to the current parameter files. + +procedure ap_pcpars (ap) + +pointer ap # pointer to apphot structure +bool itob() +int apstati() + +begin + # Write the data dependent parameters. + call ap_dapars (ap) + + # Write the centering parameters. + call ap_cepars (ap) + + # Set the plotting command. + call clputb ("radplots", itob (apstati (ap, RADPLOTS))) +end diff --git a/noao/digiphot/apphot/center/aprefitcen.x b/noao/digiphot/apphot/center/aprefitcen.x new file mode 100644 index 00000000..c50e2efb --- /dev/null +++ b/noao/digiphot/apphot/center/aprefitcen.x @@ -0,0 +1,193 @@ +include <mach.h> +include "../lib/apphotdef.h" +include "../lib/apphot.h" +include "../lib/noisedef.h" +include "../lib/centerdef.h" +include "../lib/center.h" + +define CONVERT .424660900 # conversion factor from fwhmpsf to sigma + +# APREFITCENTER -- Procedure to refit the centers assuming that the appropriate +# pixel buffer is in memory. See apfitcenter for further information. + +int procedure aprefitcenter (ap, im, ier) + +pointer ap # pointer to the apphot structure +pointer im # the input image descriptor +int ier # previous error code + +int fier +pointer cen, nse +int ap_ctr1d(), ap_mctr1d(), ap_gctr1d(), ap_lgctr1d() + +begin + cen = AP_PCENTER(ap) + nse = AP_NOISE(ap) + + # Initialize + AP_XCENTER(cen) = AP_CXCUR(cen) + AP_YCENTER(cen) = AP_CYCUR(cen) + AP_XSHIFT(cen) = 0.0 + AP_YSHIFT(cen) = 0.0 + AP_OXSHIFT(cen) = 0.0 + AP_OYSHIFT(cen) = 0.0 + AP_XERR(cen) = INDEFR + AP_YERR(cen) = INDEFR + + # Return if the center is undefined. + if (IS_INDEFR(AP_CXCUR(cen)) || IS_INDEFR(AP_CYCUR(cen))) { + AP_OXINIT(cen) = INDEFR + AP_OYINIT(cen) = INDEFR + AP_OXCENTER(cen) = INDEFR + AP_OYCENTER(cen) = INDEFR + return (AP_CTR_NOAREA) + } + + # Convert the coordinates. + switch (AP_WCSOUT(ap)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_ltoo (ap, AP_CXCUR(cen), AP_CYCUR(cen), AP_OXINIT(cen), + AP_OYINIT(cen), 1) + call ap_ltoo (ap, AP_CXCUR(cen), AP_CYCUR(cen), AP_OXCENTER(cen), + AP_OYCENTER(cen), 1) + case WCS_TV: + call ap_ltov (im, AP_CXCUR(cen), AP_CYCUR(cen), AP_OXINIT(cen), + AP_OYINIT(cen), 1) + call ap_ltov (im, AP_CXCUR(cen), AP_CYCUR(cen), AP_OXCENTER(cen), + AP_OYCENTER(cen), 1) + default: + AP_OXINIT(cen) = AP_CXCUR(cen) + AP_OYINIT(cen) = AP_CYCUR(cen) + AP_OXCENTER(cen) = AP_CXCUR(cen) + AP_OYCENTER(cen) = AP_CYCUR(cen) + } + + # Return input coordinates if no center fitting. + if (AP_CENTERFUNCTION(cen) == AP_NONE) + return (AP_OK) + + # Choose the centering algorithm. + switch (AP_CENTERFUNCTION(cen)) { + + case AP_CENTROID1D: + + # Compute the x and y centroids. + if (AP_CTHRESHOLD(cen) <= 0.0) { + fier = ap_mctr1d (Memr[AP_CTRPIX(cen)], AP_CNX(cen), + AP_CNY(cen), AP_EPADU(nse), AP_XCENTER(cen), + AP_YCENTER(cen), AP_XERR(cen), AP_YERR(cen)) + if (IS_INDEFR(AP_XERR(cen))) + AP_XCENTER(cen) = AP_CXC(cen) + if (IS_INDEFR(AP_YERR(cen))) + AP_YCENTER(cen) = AP_CYC(cen) + } else { + fier = ap_ctr1d (Memr[AP_CTRPIX(cen)], AP_CNX(cen), + AP_CNY(cen), AP_EPADU(nse), AP_XCENTER(cen), + AP_YCENTER(cen), AP_XERR(cen), AP_YERR(cen)) + if (IS_INDEFR(AP_XERR(cen))) + AP_XCENTER(cen) = AP_CXC(cen) + if (IS_INDEFR(AP_YERR(cen))) + AP_YCENTER(cen) = AP_CYC(cen) + } + AP_XCENTER(cen) = AP_XCENTER(cen) + AP_CXCUR(cen) - AP_CXC(cen) + AP_YCENTER(cen) = AP_YCENTER(cen) + AP_CYCUR(cen) - AP_CYC(cen) + AP_XSHIFT(cen) = AP_XCENTER(cen) - AP_CXCUR(cen) + AP_YSHIFT(cen) = AP_YCENTER(cen) - AP_CYCUR(cen) + + case AP_GAUSS1D: + + # Compute the 1D Gaussian x and y centers. + fier = ap_gctr1d (Memr[AP_CTRPIX(cen)], AP_CNX(cen), AP_CNY(cen), + CONVERT * AP_FWHMPSF(ap) * AP_SCALE(ap), AP_CMAXITER(cen), + AP_XCENTER(cen), AP_YCENTER(cen), AP_XERR(cen), AP_YERR(cen)) + AP_XCENTER(cen) = AP_XCENTER(cen) + AP_CXCUR(cen) - AP_CXC(cen) + AP_YCENTER(cen) = AP_YCENTER(cen) + AP_CYCUR(cen) - AP_CYC(cen) + AP_XSHIFT(cen) = AP_XCENTER(cen) - AP_CXCUR(cen) + AP_YSHIFT(cen) = AP_YCENTER(cen) - AP_CYCUR(cen) + + case AP_OFILT1D: + + # Compute the Goad 1D x and y centers. + fier = ap_lgctr1d (Memr[AP_CTRPIX(cen)], AP_CNX(cen), AP_CNY(cen), + AP_CXC(cen), AP_CYC(cen), CONVERT * AP_FWHMPSF(ap) * + AP_SCALE(ap), AP_CMAXITER(cen), AP_EPADU(nse), + AP_SKYSIGMA(nse), AP_XCENTER(cen), AP_YCENTER(cen), + AP_XERR(cen), AP_YERR(cen)) + AP_XCENTER(cen) = AP_XCENTER(cen) + AP_CXCUR(cen) - AP_CXC(cen) + AP_YCENTER(cen) = AP_YCENTER(cen) + AP_CYCUR(cen) - AP_CYC(cen) + AP_XSHIFT(cen) = AP_XCENTER(cen) - AP_CXCUR(cen) + AP_YSHIFT(cen) = AP_YCENTER(cen) - AP_CYCUR(cen) + + default: + + # do nothing gracefully + } + + # Convert the coordinates. + switch (AP_WCSOUT(ap)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_ltoo (ap, AP_XCENTER(cen), AP_YCENTER(cen), + AP_OXCENTER(cen), AP_OYCENTER(cen), 1) + call ap_ltoo (ap, AP_XCENTER(cen) - AP_XSHIFT(cen), + AP_YCENTER(cen) - AP_YSHIFT(cen), AP_OXINIT(cen), + AP_OYINIT(cen), 1) + AP_OXSHIFT(cen) = AP_OXCENTER(cen) - AP_OXINIT(cen) + AP_OYSHIFT(cen) = AP_OYCENTER(cen) - AP_OYINIT(cen) + case WCS_TV: + call ap_ltov (im, AP_XCENTER(cen), AP_YCENTER(cen), + AP_OXCENTER(cen), AP_OYCENTER(cen), 1) + call ap_ltov (im, AP_XCENTER(cen) - AP_XSHIFT(cen), + AP_YCENTER(cen) - AP_YSHIFT(cen), AP_OXINIT(cen), + AP_OYINIT(cen), 1) + AP_OXSHIFT(cen) = AP_OXCENTER(cen) - AP_OXINIT(cen) + AP_OYSHIFT(cen) = AP_OYCENTER(cen) - AP_OYINIT(cen) + default: + AP_OXCENTER(cen) = AP_XCENTER(cen) + AP_OYCENTER(cen) = AP_YCENTER(cen) + AP_OXINIT(cen) = AP_XCENTER(cen) - AP_XSHIFT(cen) + AP_OYINIT(cen) = AP_YCENTER(cen) - AP_YSHIFT(cen) + AP_OXSHIFT(cen) = AP_XSHIFT(cen) + AP_OYSHIFT(cen) = AP_YSHIFT(cen) + } + + # Return appropriate error code. + if (fier != AP_OK) { + AP_XCENTER(cen) = AP_CXCUR(cen) + AP_YCENTER(cen) = AP_CYCUR(cen) + AP_XSHIFT(cen) = 0.0 + AP_YSHIFT(cen) = 0.0 + AP_XERR(cen) = INDEFR + AP_YERR(cen) = INDEFR + switch (AP_WCSOUT(ap)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_ltoo (ap, AP_CXCUR(cen), AP_CYCUR(cen), AP_OXINIT(cen), + AP_OYINIT(cen), 1) + call ap_ltoo (ap, AP_CXCUR(cen), AP_CYCUR(cen), + AP_OXCENTER(cen), AP_OYCENTER(cen), 1) + case WCS_TV: + call ap_ltov (im, AP_CXCUR(cen), AP_CYCUR(cen), AP_OXINIT(cen), + AP_OYINIT(cen), 1) + call ap_ltov (im, AP_CXCUR(cen), AP_CYCUR(cen), + AP_OXCENTER(cen), AP_OYCENTER(cen), 1) + default: + AP_OXCENTER(cen) = AP_CXCUR(cen) + AP_OYCENTER(cen) = AP_CYCUR(cen) + AP_OXINIT(cen) = AP_CXCUR(cen) + AP_OYINIT(cen) = AP_CYCUR(cen) + } + AP_OXSHIFT(cen) = 0.0 + AP_OYSHIFT(cen) = 0.0 + return (fier) + } else if (ier == AP_CTR_BADDATA) { + return (AP_CTR_BADDATA) + } else if (ier == AP_CTR_LOWSNRATIO) { + return (AP_CTR_LOWSNRATIO) + } else if (abs (AP_XSHIFT(cen)) > (AP_MAXSHIFT(cen) * AP_SCALE(ap))) { + return (AP_CTR_BADSHIFT) + } else if (abs (AP_YSHIFT(cen)) > (AP_MAXSHIFT(cen) * AP_SCALE(ap))) { + return (AP_CTR_BADSHIFT) + } else if (ier == AP_CTR_OUTOFBOUNDS) { + return (AP_CTR_OUTOFBOUNDS) + } else + return (AP_OK) +end diff --git a/noao/digiphot/apphot/center/center.key b/noao/digiphot/apphot/center/center.key new file mode 100644 index 00000000..f71cd8d3 --- /dev/null +++ b/noao/digiphot/apphot/center/center.key @@ -0,0 +1,78 @@ + Interactive Keystroke Commands + +? Print help +: Colon commands +v Verify the critical parameters +w Save the current parameters +d Plot radial profile of current star +i Interactively set parameters using current star +f Fit center of current star +spbar Fit center of current star, output results +m Move to next star in coordinate list +n Center next star in coordinate list, output results +l Center remaining stars in coordinate list, output results +e Print error messages +r Rewind the coordinate list +q Exit task + + + Colon Commands + +:show [data/center] List the parameters +:m [n] Move to next [nth] star in coordinate list +:n [n] Center next [nth] star in coordinate list, output results + + + Colon Parameter Editing Commands + +# Image and file name parameters + +:image [string] Image name +:coords [string] Coordinate file name +:output [string] Output file name + +# Data dependent parameters + +:scale [value] Image scale (units per pixel) +:fwhmpsf [value] Full-width half-maximum of PSF (scale units) +:emission [y/n] Emission feature (y), absorption (n) +:sigma [value] Standard deviation of sky (counts) +:datamin [value] Minimum good data value (counts) +:datamax [value] Maximum good data value (counts) + +# Noise parameters + +:noise [string] Noise model (constant|poisson) +:gain [string] Gain image header keyword +:ccdread [string] Readout noise image header keyword +:epadu [value] Gain (electrons per adu) +:readnoise [value] Readout noise (electrons) + +# Observations parameters + +:exposure [string] Exposure time image header keyword +:airmass [string] Airmass image header keyword +:filter [string] Filter image header keyword +:obstime [string] Time of observation image header keyword +:itime [value] Exposure time (time units) +:xairmass [value] Airmass value (number) +:ifilter [string] Filter id string +:otime [string] Time of observation (time units) + +# Centering parameters + +:calgorithm [string] Centering algorithm +:cbox [value] Width of centering box (scale units) +:cthreshold [value] Centering intensity threshold (sigma) +:cmaxiter [value] Maximum number of iterations +:maxshift [value] Maximum center shift (scale units) +:minsnratio [value] Minimum signal to noise for centering +:clean [y/n] Clean subraster before centering +:rclean [value] Cleaning radius (scale units) +:rclip [value] Clipping radius (scale units) +:kclean [value] Clean K-sigma rejection limit (sigma) + +# Plotting and marking parameters + +:mkcenter [y/n] Mark computed centers on the display +:radplot [y/n] Plot radial profile of object diff --git a/noao/digiphot/apphot/center/icenter.key b/noao/digiphot/apphot/center/icenter.key new file mode 100644 index 00000000..0e5379f0 --- /dev/null +++ b/noao/digiphot/apphot/center/icenter.key @@ -0,0 +1,12 @@ + Interactive Center Setup Menu + + v Mark and verify the critical center parameters (f,s,c) + + f Mark and verify the full-width half-maximum of the psf + s Mark and verify the standard deviation of the background + l Mark and verify the minimum good data value + u Mark and verify the maximum good data value + + c Mark and verify the centering box half-width + n Mark and verify the cleaning radius + p Mark and verify the clipping radius diff --git a/noao/digiphot/apphot/center/mkpkg b/noao/digiphot/apphot/center/mkpkg new file mode 100644 index 00000000..dde81929 --- /dev/null +++ b/noao/digiphot/apphot/center/mkpkg @@ -0,0 +1,54 @@ +# CENTER task + +$checkout libpkg.a ".." +$update libpkg.a +$checkin libpkg.a ".." +$exit + +libpkg.a: + apbcenter.x ../lib/apphot.h ../lib/display.h \ + <fset.h> + apcconfirm.x ../lib/apphot.h ../lib/noise.h \ + ../lib/center.h + apcencolon.x ../lib/apphot.h ../lib/center.h \ + ../lib/display.h ../lib/noise.h + apcenter.x ../lib/apphot.h ../lib/center.h \ + ../lib/display.h <ctype.h> \ + <gset.h> <imhdr.h> + apcerrors.x ../lib/center.h + apcfree.x ../lib/apphotdef.h ../lib/centerdef.h + apictr.x + apcinit.x ../lib/apphotdef.h ../lib/center.h \ + ../lib/centerdef.h + apclean.x ../lib/apphot.h ../lib/center.h \ + ../lib/noise.h + appcpars.x ../lib/display.h + apcplot.x ../lib/apphot.h ../lib/apphotdef.h \ + ../lib/center.h ../lib/centerdef.h \ + ../lib/noise.h <gset.h> \ + <pkg/gtools.h> <mach.h> + apcpshow.x ../lib/center.h ../lib/display.h + apcshow.x ../lib/display.h + apcsnratio.x ../lib/center.h ../lib/noise.h \ + <mach.h> + apctr1d.x ../lib/center.h <mach.h> + apctrbuf.x ../lib/apphotdef.h ../lib/center.h \ + ../lib/centerdef.h <imhdr.h> <math.h> \ + <mach.h> + apmctr1d.x ../lib/center.h <mach.h> + apfitcen.x ../lib/apphotdef.h ../lib/center.h \ + ../lib/centerdef.h ../lib/noisedef.h \ + ../lib/apphot.h <mach.h> + apgcpars.x ../lib/center.h ../lib/display.h \ + ../lib/noise.h + apgctr1d.x ../lib/center.h <math/nlfit.h> + aplgctr1d.x ../lib/center.h <math.h> + appcenter.x ../lib/apphot.h ../lib/center.h + apcradsetup.x ../lib/display.h + aprefitcen.x ../lib/apphotdef.h ../lib/center.h \ + ../lib/centerdef.h ../lib/noisedef.h \ + ../lib/apphot.h <mach.h> + t_center.x ../lib/apphot.h ../lib/noise.h \ + <fset.h> <gset.h> \ + <imhdr.h> + ; diff --git a/noao/digiphot/apphot/center/t_center.x b/noao/digiphot/apphot/center/t_center.x new file mode 100644 index 00000000..456b93d2 --- /dev/null +++ b/noao/digiphot/apphot/center/t_center.x @@ -0,0 +1,306 @@ +include <fset.h> +include <gset.h> +include <imhdr.h> +include "../lib/apphot.h" +include "../lib/noise.h" + +# T_CENTER -- Procedure to compute accurate centers for a list of objects +# given a list of starting centers, a set of starting parameters and a list +# of images. + +procedure t_center () + +pointer image # pointer to name of the image +pointer output # pointer to output file name +pointer coords # pointer to coordinate file +pointer plotfile # name of plot metacode file +pointer graphics # pointer to graphics device +pointer display # pointer to display device +int interactive # interactive mode +int cache # cache image buffer in memory +int verify # verify parameters +int update # update parameters +int verbose # verbose mode + +pointer sp, str, cname, outfname, ap, im, id, gd, mgd +int limlist, lclist, lolist, sid, lid, cl, pfd, out, root, stat, memstat +int imlist, clist, olist, wcs, req_size, old_size, buf_size + +pointer immap(), gopen() +int imtlen(), imtgetim(), clplen(), clgfil(), btoi(), fnldir(), strncmp() +int open(), strlen(), apcenter(), imtopenp(), clpopnu(), clgwrd() +int ap_memstat(), sizeof() +bool clgetb(), streq() +errchk gopen + +begin + # Allocate working space. + call smark (sp) + call salloc (image, SZ_FNAME, TY_CHAR) + call salloc (output, SZ_FNAME, TY_CHAR) + call salloc (coords, SZ_FNAME, TY_CHAR) + call salloc (plotfile, SZ_FNAME, TY_CHAR) + call salloc (graphics, SZ_FNAME, TY_CHAR) + call salloc (display, SZ_FNAME, TY_CHAR) + call salloc (outfname, SZ_FNAME, TY_CHAR) + call salloc (cname, SZ_FNAME, TY_CHAR) + call salloc (str, SZ_LINE, TY_CHAR) + + # Set standard output to flush on newline. + call fseti (STDOUT, F_FLUSHNL, YES) + + # Get input and output file names. + imlist = imtopenp ("image") + limlist = imtlen (imlist) + clist = clpopnu ("coords") + lclist = clplen (clist) + olist = clpopnu ("output") + lolist = clplen (olist) + + # Check that image and coordinate list lengths match. + if (limlist < 1 || (lclist > 1 && lclist != limlist)) { + call imtclose (imlist) + call clpcls (clist) + call clpcls (olist) + call error (0, "Imcompatible image and coordinate list lengths") + } + + # Check that image and output list lengths match. + if (lolist > 1 && lolist != limlist) { + call imtclose (imlist) + call clpcls (clist) + call clpcls (olist) + call error (0, "Imcompatible image and output list lengths") + } + + call clgstr ("icommands.p_filename", Memc[cname], SZ_FNAME) + if (Memc[cname] != EOS) + interactive = NO + #else if (lclist == 0) + #interactive = YES + else + interactive = btoi (clgetb ("interactive")) + cache = btoi (clgetb ("cache")) + verbose = btoi (clgetb ("verbose")) + verify = btoi (clgetb ("verify")) + update = btoi (clgetb ("update")) + + # Get the centering parameters. + call ap_gcpars (ap) + + # confirm the centering algorithm parameters. + if (verify == YES && interactive == NO) { + call ap_cconfirm (ap, NULL, 1) + if (update == YES) + call ap_pcpars (ap) + } + + # Get the wcs information. + wcs = clgwrd ("wcsin", Memc[str], SZ_LINE, WCSINSTR) + if (wcs <= 0) { + call eprintf ( + "Warning: Setting the input coordinate system to logical\n") + wcs = WCS_LOGICAL + } + call apseti (ap, WCSIN, wcs) + wcs = clgwrd ("wcsout", Memc[str], SZ_LINE, WCSOUTSTR) + if (wcs <= 0) { + call eprintf ( + "Warning: Setting the output coordinate system to logical\n") + wcs = WCS_LOGICAL + } + call apseti (ap, WCSOUT, wcs) + + # Get the graphics and display devices. + call clgstr ("graphics", Memc[graphics], SZ_FNAME) + call clgstr ("display", Memc[display], SZ_FNAME) + + # Open the graphics and image deisplay devices. + if (interactive == YES) { + if (Memc[graphics] == EOS) + gd = NULL + else { + iferr { + gd = gopen (Memc[graphics], APPEND+AW_DEFER, STDGRAPH) + } then { + call eprintf ( + "Warning: Error opening the graphics device.\n") + gd = NULL + } + } + if (Memc[display] == EOS) + id = NULL + else if (streq (Memc[graphics], Memc[display])) + id = gd + else { + iferr { + id = gopen (Memc[display], APPEND, STDIMAGE) + } then { + call eprintf ( + "Warning: Graphics overlay not available for display device.\n") + id = NULL + } + } + } else { + gd = NULL + id = NULL + } + + # Open the plot metacode file. + call clgstr ("plotfile", Memc[plotfile], SZ_FNAME) + if (Memc[plotfile] == EOS) + pfd = NULL + else + pfd = open (Memc[plotfile], APPEND, BINARY_FILE) + if (pfd != NULL) + mgd = gopen (Memc[graphics], NEW_FILE, pfd) + else + mgd = NULL + + # Begin looping over the image list. + sid = 1 + while (imtgetim (imlist, Memc[image], SZ_FNAME) != EOF) { + + # Open image. + im = immap (Memc[image], READ_ONLY, 0) + call apimkeys (ap, im, Memc[image]) + + # Set the image display viewport. + if ((id != NULL) && (id != gd)) + call ap_gswv (id, Memc[image], im, 4) + + # Cache the input image pixels. + req_size = MEMFUDGE * IM_LEN(im,1) * IM_LEN(im,2) * + sizeof (IM_PIXTYPE(im)) + memstat = ap_memstat (cache, req_size, old_size) + if (memstat == YES) + call ap_pcache (im, INDEFI, buf_size) + + # Open the coordinate file; where coords is assumed to be a simple + # text file in which the x and y positions are in columns 1 and 2 + # respectively and all remaining fields are ignored. + + if (lclist <= 0) { + cl = NULL + call strcpy ("", Memc[outfname], SZ_FNAME) + } else { + stat = clgfil (clist, Memc[coords], SZ_FNAME) + root = fnldir (Memc[coords], Memc[outfname], SZ_FNAME) + if (strncmp ("default", Memc[coords+root], 7) == 0 || root == + strlen (Memc[coords])) { + call ap_inname (Memc[image], Memc[outfname], "coo", + Memc[outfname], SZ_FNAME) + lclist = limlist + cl = open (Memc[outfname], READ_ONLY, TEXT_FILE) + } else if (stat != EOF) { + call strcpy (Memc[coords], Memc[outfname], SZ_FNAME) + cl = open (Memc[outfname], READ_ONLY, TEXT_FILE) + } else { + call apstats (ap, CLNAME, Memc[outfname], SZ_FNAME) + call seek (cl, BOF) + } + } + call apsets (ap, CLNAME, Memc[outfname]) + call apfroot (Memc[outfname], Memc[str], SZ_LINE) + call apsets (ap, CLROOT, Memc[str]) + + # Open output text file; if output is "default", dir$default or + # a directory specification then the extension "ctr" is added to + # the root image name and a suitable version number is appended to + # the output name. If the output string is null then no output + # file is created. + + if (lolist == 0) { + out = NULL + call strcpy ("", Memc[outfname], SZ_FNAME) + } else { + stat = clgfil (olist, Memc[output], SZ_FNAME) + root = fnldir (Memc[output], Memc[outfname], SZ_FNAME) + if (strncmp ("default", Memc[output+root], 7) == 0 || root == + strlen (Memc[output])) { + call apoutname (Memc[image], Memc[outfname], "ctr", + Memc[outfname], SZ_FNAME) + out = open (Memc[outfname], NEW_FILE, TEXT_FILE) + lolist = limlist + } else if (stat != EOF) { + call strcpy (Memc[output], Memc[outfname], SZ_FNAME) + out = open (Memc[outfname], NEW_FILE, TEXT_FILE) + } else + call apstats (ap, OUTNAME, Memc[outfname], SZ_FNAME) + } + call apsets (ap, OUTNAME, Memc[outfname]) + + # Fit the centers. + if (interactive == NO) { + if (Memc[cname] != EOS) + stat = apcenter (ap, im, cl, NULL, mgd, NULL, out, sid, + NO, cache) + else if (cl != NULL) { + lid = 1 + call apbcenter (ap, im, cl, out, sid, lid, mgd, id, + verbose) + stat = NO + } else + stat = NO + } else + stat = apcenter (ap, im, cl, gd, mgd, id, out, sid, YES, cache) + + # Close up image, coordinates, and output file. + call imunmap (im) + if (cl != NULL) { + if (lclist > 1) + call close (cl) + } + if (out != NULL && lolist != 1) { + call close (out) + if (sid <= 1) { + call apstats (ap, OUTNAME, Memc[outfname], SZ_FNAME) + call delete (Memc[outfname]) + } + sid = 1 + } + + # Uncache memory. + call fixmem (old_size) + + if (stat == YES) + break + + } + + # If only one coordinate file for a list of images close it. + if (cl != NULL && lclist == 1) + call close (cl) + + # If only one output file defined for a list of images close it. + if (out != NULL && lolist == 1) { + call close (out) + if (sid <= 1) { + call apstats (ap, OUTNAME, Memc[outfname], SZ_FNAME) + call delete (Memc[outfname]) + } + } + + # Close up graphics and image display streams and the plot files. + if (id == gd && id != NULL) + call gclose (gd) + else { + if (gd != NULL) + call gclose (gd) + if (id != NULL) + call gclose (id) + } + if (mgd != NULL) + call gclose (mgd) + if (pfd != NULL) + call close (pfd) + + # Free centering structure. + call apcfree (ap) + + # Close up the file lists. + call imtclose (imlist) + call clpcls (clist) + call clpcls (olist) + call sfree (sp) +end diff --git a/noao/digiphot/apphot/centerpars.par b/noao/digiphot/apphot/centerpars.par new file mode 100644 index 00000000..1692b29e --- /dev/null +++ b/noao/digiphot/apphot/centerpars.par @@ -0,0 +1,14 @@ +# CENTERPARS + +calgorithm,s,h,"centroid","|centroid|gauss|none|ofilter|",,Centering algorithm +cbox,r,h,5.0,,,Centering box width in scale units +cthreshold,r,h,0.0,,,Centering threshold in sigma above background +minsnratio,r,h,1.0,0.0,,Minimum signal-to-noise ratio for centering algorithm +cmaxiter,i,h,10,,,Maximum number of iterations for centering algorithm +maxshift,r,h,1.0,,,Maximum center shift in scale units +clean,b,h,no,,,Symmetry clean before centering ? +rclean,r,h,1.0,,,Cleaning radius in scale units +rclip,r,h,2.0,,,Clipping radius in scale units +kclean,r,h,3.0,,,Rejection limit in sigma +mkcenter,b,h,no,,,Mark the computed center on display ? +mode,s,h,'ql' diff --git a/noao/digiphot/apphot/daofind.par b/noao/digiphot/apphot/daofind.par new file mode 100644 index 00000000..b6af78c1 --- /dev/null +++ b/noao/digiphot/apphot/daofind.par @@ -0,0 +1,21 @@ +# DAOFIND + +image,s,a,,,,"Input image(s)" +output,f,h,"default",,,"The output coordinates list(s) (default: image.coo.?)" +starmap,s,h,"",,,"The output density enhancement image(s)" +skymap,s,h,"",,,"The output sky image(s)" +datapars,pset,h,"",,,"Data dependent parameters" +findpars,pset,h,"",,,"Object detection parameters" +boundary,s,h,nearest,,,"Boundary extension (constant, nearest, reflect, wrap)" +constant,r,h,0.0,,,"Constant for constant boundary extension" +interactive,b,h,no,,,"Interactive mode ?" +icommands,*imcur,h,"",,,"Image cursor: [x y wcs] key [cmd]" +gcommands,*gcur,h,"",,,"Graphics cursor: [x y wcs] key [cmd]" +wcsout,s,h,)_.wcsout,,,"The output coordinate system (logical,tv,physical)" +cache,b,h,)_.cache,,,"Cache the image pixels ?" +verify,b,h,)_.verify,,,"Verify critical parameters in non-interactive mode ?" +update,b,h,)_.update,,,"Update critical parameters in non-interactive mode ?" +verbose,b,h,)_.verbose,,,"Print messages in non-interactive mode ?" +graphics,s,h,)_.graphics,,,"Graphics device" +display,s,h,)_.display,,,"Display device" +mode,s,h,'ql' diff --git a/noao/digiphot/apphot/daofind/apbfdfind.x b/noao/digiphot/apphot/daofind/apbfdfind.x new file mode 100644 index 00000000..acf34ae4 --- /dev/null +++ b/noao/digiphot/apphot/daofind/apbfdfind.x @@ -0,0 +1,139 @@ +include <imhdr.h> +include <imio.h> +include <mach.h> +include "../lib/apphot.h" +include "../lib/noise.h" +include "../lib/find.h" + +# AP_BFDFIND -- Find stars in an image using a pattern matching +# technique. + +procedure ap_bfdfind (im, cnv, sky, out, ap, boundary, constant, verbose) + +pointer im # pointer to the input image +pointer cnv # pointer to the convolved image +pointer sky # pointer to the sky image +int out # the output file descriptor +pointer ap # pointer to the apphot structure +int boundary # type of boundary extension +real constant # constant for constant boundary extension +int verbose # verbose switch + +int norm, nxk, nyk, nstars, stid +pointer sp, gker2d, ngker2d, dker2d, skip +real a, b, c, f, gsums[LEN_GAUSS], skysigma, skymode, threshold, relerr +real dmax, dmin, xsigsq, ysigsq +int apstati(), ap_find() +real ap_egkernel(), apstatr() + +begin + # Compute the parameters of the Gaussian kernel. + call ap_egparams (FWHM_TO_SIGMA * apstatr (ap, FWHMPSF) * + apstatr (ap, SCALE), apstatr (ap, RATIO), apstatr (ap, THETA), + apstatr (ap, NSIGMA), a, b, c, f, nxk, nyk) + + # Allocate working space. + call smark (sp) + call salloc (gker2d, nxk * nyk, TY_REAL) + call salloc (ngker2d, nxk * nyk, TY_REAL) + call salloc (dker2d, nxk * nyk, TY_REAL) + call salloc (skip, nxk * nyk, TY_INT) + + # Compute the 1 and 2 D kernels. + if (IS_INDEFR(apstatr(ap, DATAMIN)) && IS_INDEFR(apstatr(ap, + DATAMAX))) { + norm = YES + dmin = -MAX_REAL + dmax = MAX_REAL + } else { + norm = NO + if (IS_INDEFR(apstatr (ap, DATAMIN))) + dmin = -MAX_REAL + else + dmin = apstatr (ap, DATAMIN) + if (IS_INDEFR(apstatr (ap, DATAMAX))) + dmax = MAX_REAL + else + dmax = apstatr (ap, DATAMAX) + } + relerr = ap_egkernel (Memr[gker2d], Memr[ngker2d], Memr[dker2d], + Memi[skip], nxk, nyk, gsums, a, b, c, f) + + # Set up the image boundary extension characteristics. + call ap_imset (im, boundary, max (1 + nxk / 2, 1 + nyk / 2), + constant) + call ap_imset (cnv, boundary, max (1 + nxk / 2, 1 + nyk / 2), + constant) + + # Convolve the input image with the Gaussian kernel. The resultant + # picture constains in each pixel the height of the Gaussian + # function centered in the subarray which best represents the data + # within a circle of nsigma * sigma of the Gaussian. + + if (IM_ACMODE(cnv) != READ_ONLY) { + if (norm == YES) + call ap_fconvolve (im, cnv, sky, Memr[ngker2d], Memr[dker2d], + Memi[skip], nxk, nyk, gsums[GAUSS_SGOP]) + else + call ap_gconvolve (im, cnv, sky, Memr[gker2d], Memi[skip], + nxk, nyk, gsums, dmin, dmax) + } + + # Save the task parameters in the database file if the savepars + # switch is enabled, otherwise a simple list of detected objects + # is written to the data base file. + + call ap_wfdparam (out, ap) + + # Find all the objects in the input image with the specified image + # characteristics. + + if (verbose == YES) { + call printf ("\nImage: %s ") + call pargstr (IM_HDRFILE(im)) + call printf ("fwhmpsf: %g ratio: %g theta: %g nsigma: %g\n\n") + call pargr (apstatr (ap, FWHMPSF)) + call pargr (apstatr (ap, RATIO)) + call pargr (apstatr (ap, THETA)) + call pargr (apstatr (ap, NSIGMA)) + } + + # Get the skymode and threshold. + skysigma = apstatr (ap, SKYSIGMA) + if (IS_INDEFR(skysigma)) { + skymode = 0.0 + threshold = 0.0 + } else { + skymode = apstatr (ap, EPADU) * (skysigma ** 2 - + (apstatr (ap, READNOISE) / apstatr (ap, EPADU)) ** 2) + skymode = max (0.0, skymode) + threshold = apstatr (ap, THRESHOLD) * skysigma + } + + # Compute the x and y sigma. + xsigsq = (apstatr (ap, SCALE) * apstatr (ap, FWHMPSF) / 2.35482) ** 2 + ysigsq = (apstatr (ap, SCALE) * apstatr (ap, RATIO) * + apstatr (ap, FWHMPSF) / 2.35482) ** 2 + + # Find the stars. + stid = 1 + nstars = ap_find (ap, im, cnv, out, NULL, Memr[gker2d], + Memi[skip], nxk, nyk, skymode, threshold, relerr, + apstati (ap,POSITIVE), xsigsq, ysigsq, dmin, dmax, + apstatr (ap, SHARPLO), apstatr (ap, SHARPHI), apstatr (ap, + ROUNDLO), apstatr (ap, ROUNDHI), verbose, stid, NO) + + if (verbose == YES) { + call printf ( + "\nthreshold: %g relerr: %5.3f %g <= sharp <= %g ") + call pargr (threshold) + call pargr (relerr) + call pargr (apstatr (ap, SHARPLO)) + call pargr (apstatr (ap, SHARPHI)) + call printf ("%g <= round <= %g \n\n") + call pargr (apstatr (ap, ROUNDLO)) + call pargr (apstatr (ap, ROUNDHI)) + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/daofind/apconvolve.x b/noao/digiphot/apphot/daofind/apconvolve.x new file mode 100644 index 00000000..0c6f58aa --- /dev/null +++ b/noao/digiphot/apphot/daofind/apconvolve.x @@ -0,0 +1,320 @@ +include <imhdr.h> +include <imset.h> +include "../lib/find.h" + +# AP_FCONVOLVE -- Solve for the density enhancement image and optionally +# the sky enhancement image in the case where datamin and datamax are not +# defined. + +procedure ap_fconvolve (im, den, sky, kernel1, kernel2, skip, nxk, nyk, const2) + +pointer im # pointer to the input image +pointer den # pointer to the output density image +pointer sky # pointer to the output sky image +real kernel1[nxk,nyk] # the first convolution kernel +real kernel2[nxk,nyk] # the second convolution kernel +int skip[nxk,nyk] # the skip array +int nxk, nyk # dimensions of the kernel +real const2 # subtraction constant for the skyimage + +int i, ncols, nlines, col1, col2, inline, outline +pointer sp, lineptrs, outbuf1, outbuf2 +pointer imgs2r(), impl2r() +errchk imgs2r, impl2r, imflush + +begin + # Set up an array of linepointers. + call smark (sp) + call salloc (lineptrs, nyk, TY_POINTER) + + # Set the number of image buffers. + call imseti (im, IM_NBUFS, nyk) + + ncols = IM_LEN(den,1) + nlines = IM_LEN(den,2) + + # Set input image column limits. + col1 = 1 - nxk / 2 + col2 = IM_LEN(im,1) + nxk / 2 + + # Initialise the line buffers. + inline = 1 - nyk / 2 + do i = 1 , nyk - 1 { + Memi[lineptrs+i] = imgs2r (im, col1, col2, inline, inline) + inline = inline + 1 + } + + # Generate the output image line by line. + do outline = 1, nlines { + + # Scroll the input buffers. + do i = 1, nyk - 1 + Memi[lineptrs+i-1] = Memi[lineptrs+i] + + # Read in new image line. + Memi[lineptrs+nyk-1] = imgs2r (im, col1, col2, inline, + inline) + + # Get first output image line. + outbuf1 = impl2r (den, outline) + if (outbuf1 == EOF) + call error (0, "Error writing first output image.") + + # Generate first output image line. + call aclrr (Memr[outbuf1], ncols) + do i = 1, nyk + call ap_skcnvr (Memr[Memi[lineptrs+i-1]], Memr[outbuf1], + ncols, kernel1[1,i], skip[1,i], nxk) + + if (sky != NULL) { + + # Get second output image line. + outbuf2 = impl2r (sky, outline) + if (outbuf2 == EOF) + call error (0, "Error writing second output image.") + + # Generate second output image line. + call aclrr (Memr[outbuf2], ncols) + do i = 1, nyk + call ap_skcnvr (Memr[Memi[lineptrs+i-1]], Memr[outbuf2], + ncols, kernel2[1,i], skip[1,i], nxk) + call ap_w1sur (Memr[outbuf2], Memr[outbuf1], Memr[outbuf2], + ncols, -const2) + } + + inline = inline + 1 + } + + # Flush the output image(s). + call imflush (den) + if (sky != NULL) + call imflush (sky) + + # Free the image buffer pointers. + call sfree (sp) +end + + +# AP_GCONVOLVE -- Solve for the density enhancement image and optionally +# the sky enhancement image in the case where datamin and datamax are defined. + +procedure ap_gconvolve (im, den, sky, kernel1, skip, nxk, nyk, gsums, + datamin, datamax) + +pointer im # pointer to the input image +pointer den # pointer to the output density image +pointer sky # pointer to the output sky image +real kernel1[nxk,nyk] # the first convolution kernel +int skip[nxk,nyk] # the sky array +int nxk, nyk # dimensions of the kernel +real gsums[ARB] # array of kernel sums +real datamin, datamax # the good data minimum and maximum + +int i, ncols, nlines, col1, col2, inline, outline +pointer sp, lineptrs, sd, sgd, sg, sgsq, p, outbuf2 +pointer imgs2r(), impl2r() +errchk imgs2r, impl2r, imflush + +begin + # Set up an array of linepointers. + call smark (sp) + call salloc (lineptrs, nyk, TY_POINTER) + + # Set the number of image buffers. + call imseti (im, IM_NBUFS, nyk) + + ncols = IM_LEN(den,1) + nlines = IM_LEN(den,2) + + # Allocate some working space. + call salloc (sd, ncols, TY_REAL) + call salloc (sgsq, ncols, TY_REAL) + call salloc (sg, ncols, TY_REAL) + call salloc (p, ncols, TY_REAL) + + # Set input image column limits. + col1 = 1 - nxk / 2 + col2 = IM_LEN(im,1) + nxk / 2 + + # Initialise the line buffers. + inline = 1 - nyk / 2 + do i = 1 , nyk - 1 { + Memi[lineptrs+i] = imgs2r (im, col1, col2, inline, inline) + inline = inline + 1 + } + + # Generate the output image line by line. + do outline = 1, nlines { + + # Scroll the input buffers. + do i = 1, nyk - 1 + Memi[lineptrs+i-1] = Memi[lineptrs+i] + + # Read in new image line. + Memi[lineptrs+nyk-1] = imgs2r (im, col1, col2, inline, + inline) + + # Get first output image line. + sgd = impl2r (den, outline) + if (sgd == EOF) + call error (0, "Error writing first output image.") + + # Generate first output image line. + call aclrr (Memr[sgd], ncols) + call aclrr (Memr[sd], ncols) + call amovkr (gsums[GAUSS_SUMG], Memr[sg], ncols) + call amovkr (gsums[GAUSS_SUMGSQ], Memr[sgsq], ncols) + call amovkr (gsums[GAUSS_PIXELS], Memr[p], ncols) + do i = 1, nyk + call ap_gdsum (Memr[Memi[lineptrs+i-1]], Memr[sgd], Memr[sd], + Memr[sg], Memr[sgsq], Memr[p], ncols, kernel1[1,i], + skip[1,i], nxk, datamin, datamax) + call ap_gdavg (Memr[sgd], Memr[sd], Memr[sg], Memr[sgsq], + Memr[p], ncols, gsums[GAUSS_PIXELS], gsums[GAUSS_DENOM], + gsums[GAUSS_SGOP]) + + if (sky != NULL) { + + # Get second output image line. + outbuf2 = impl2r (sky, outline) + if (outbuf2 == EOF) + call error (0, "Error writing second output image.") + + # Generate second output image line. + call ap_davg (Memr[sd], Memr[sgd], Memr[sg], Memr[p], + Memr[outbuf2], ncols) + } + + inline = inline + 1 + } + + # Flush the output image(s). + call imflush (den) + if (sky != NULL) + call imflush (sky) + + # Free the image buffer pointers. + call sfree (sp) +end + + +# AP_SKCNVR -- Compute the convolution kernel using a skip array. + +procedure ap_skcnvr (in, out, npix, kernel, skip, nk) + +real in[npix+nk-1] # the input vector +real out[npix] # the output vector +int npix # the size of the vector +real kernel[ARB] # the convolution kernel +int skip[ARB] # the skip array +int nk # the size of the convolution kernel + +int i, j +real sum + +begin + do i = 1, npix { + sum = out[i] + do j = 1, nk { + if (skip[j] == YES) + next + sum = sum + in[i+j-1] * kernel[j] + } + out[i] = sum + } +end + + +# AP_GDSUM -- Compute the vector sums required to do the convolution. + +procedure ap_gdsum (in, sgd, sd, sg, sgsq, p, npix, kernel, skip, nk, + datamin, datamax) + +real in[npix+nk-1] # the input vector +real sgd[ARB] # the computed input/output convolution vector +real sd[ARB] # the computed input/output sum vector +real sg[ARB] # the input/ouput first normalization factor +real sgsq[ARB] # the input/ouput second normalization factor +real p[ARB] # the number of points vector +int npix # the size of the vector +real kernel[ARB] # the convolution kernel +int skip[ARB] # the skip array +int nk # the size of the convolution kernel +real datamin, datamax # the good data limits. + +int i, j +real data + +begin + do i = 1, npix { + do j = 1, nk { + if (skip[j] == YES) + next + data = in[i+j-1] + if (data < datamin || data > datamax) { + sgsq[i] = sgsq[i] - kernel[j] ** 2 + sg[i] = sg[i] - kernel[j] + p[i] = p[i] - 1.0 + } else { + sgd[i] = sgd[i] + kernel[j] * data + sd[i] = sd[i] + data + } + } + } +end + + +# AP_GDAVG -- Compute the vector averages required to do the convolution. + +procedure ap_gdavg (sgd, sd, sg, sgsq, p, npix, pixels, denom, sgop) + +real sgd[ARB] # the computed input/output convolution vector +real sd[ARB] # the computed input/output sum vector +real sg[ARB] # the input/ouput first normalization factor +real sgsq[ARB] # the input/ouput second normalization factor +real p[ARB] # the number of points vector +int npix # the size of the vector +real pixels # number of pixels +real denom # kernel normalization factor +real sgop # kernel normalization factor + +int i + +begin + do i = 1, npix { + if (p[i] > 1.5) { + if (p[i] < pixels) { + sgsq[i] = sgsq[i] - (sg[i] ** 2) / p[i] + if (sgsq[i] != 0.0) + sgd[i] = (sgd[i] - sg[i] * sd[i] / p[i]) / sgsq[i] + else + sgd[i] = 0.0 + } else + sgd[i] = (sgd[i] - sgop * sd[i]) / denom + } else + sgd[i] = 0.0 + } +end + + +# AP_DAVG -- Generate the results the optional sky output image. + +procedure ap_davg (sd, sgd, sg, p, out, npix) + +real sd[ARB] # the computed input/output sum vector +real sgd[ARB] # the computed input/output convolution vector +real sg[ARB] # the input/ouput first normalization factor +real p[ARB] # the number of points vector +real out[ARB] # the output array +int npix # the size of the vector + +int i + +begin + do i = 1, npix { + if (p[i] > 0.0) + out[i] = (sd[i] - sgd[i] * sg[i]) / p[i] + else + out[i] = 0.0 + } +end diff --git a/noao/digiphot/apphot/daofind/apegkernel.x b/noao/digiphot/apphot/daofind/apegkernel.x new file mode 100644 index 00000000..3023098d --- /dev/null +++ b/noao/digiphot/apphot/daofind/apegkernel.x @@ -0,0 +1,132 @@ +include <math.h> +include "../lib/find.h" + +# Set up the gaussian fitting structure. + +# AP_EGPARAMS -- Calculate the parameters of the elliptical Gaussian needed +# to compute the kernel. + +procedure ap_egparams (sigma, ratio, theta, nsigma, a, b, c, f, nx, ny) + +real sigma # sigma of Gaussian in x +real ratio # Ratio of half-width in y to x +real theta # position angle of Gaussian +real nsigma # limit of convolution +real a, b, c, f # ellipse parameters +int nx, ny # dimensions of the kernel + +real sx2, sy2, cost, sint, discrim +bool fp_equalr () + +begin + # Define some temporary variables. + sx2 = sigma ** 2 + sy2 = (ratio * sigma) ** 2 + cost = cos (DEGTORAD (theta)) + sint = sin (DEGTORAD (theta)) + + # Compute the ellipse parameters. + if (fp_equalr (ratio, 0.0)) { + if (fp_equalr (theta, 0.0) || fp_equalr (theta, 180.)) { + a = 1. / sx2 + b = 0.0 + c = 0.0 + } else if (fp_equalr (theta, 90.0)) { + a = 0.0 + b = 0.0 + c = 1. / sx2 + } else + call error (0, "AP_EGPARAMS: Cannot make 1D Gaussian.") + f = nsigma ** 2 / 2. + nx = 2 * int (max (sigma * nsigma * abs (cost), RMIN)) + 1 + ny = 2 * int (max (sigma * nsigma * abs (sint), RMIN)) + 1 + } else { + a = cost ** 2 / sx2 + sint ** 2 / sy2 + b = 2. * (1.0 / sx2 - 1.0 / sy2) * cost * sint + c = sint ** 2 / sx2 + cost ** 2 / sy2 + discrim = b ** 2 - 4. * a * c + f = nsigma ** 2 / 2. + nx = 2 * int (max (sqrt (-8. * c * f / discrim), RMIN)) + 1 + ny = 2 * int (max (sqrt (-8. * a * f / discrim), RMIN)) + 1 + } +end + + +# AP_EGKERNEL -- Compute the elliptical Gaussian kernel. + +real procedure ap_egkernel (gkernel, ngkernel, dkernel, skip, nx, ny, gsums, a, + b, c, f) + +real gkernel[nx,ny] # output Gaussian amplitude kernel +real ngkernel[nx,ny] # output normalized Gaussian amplitude kernel +real dkernel[nx,ny] # output Gaussian sky kernel +int skip[nx,ny] # output skip subraster +int nx, ny # input dimensions of the kernel +real gsums[ARB] # output array of gsums +real a, b, c, f # ellipse parameters + +int i, j, x0, y0, x, y +real npts, rjsq, rsq, relerr,ef + +begin + # Initialize. + x0 = nx / 2 + 1 + y0 = ny / 2 + 1 + gsums[GAUSS_SUMG] = 0.0 + gsums[GAUSS_SUMGSQ] = 0.0 + npts = 0.0 + + # Compute the kernel and principal sums. + do j = 1, ny { + y = j - y0 + rjsq = y ** 2 + do i = 1, nx { + x = i - x0 + rsq = sqrt (x ** 2 + rjsq) + ef = 0.5 * (a * x ** 2 + c * y ** 2 + b * x * y) + gkernel[i,j] = exp (-1.0 * ef) + if (ef <= f || rsq <= RMIN) { + #gkernel[i,j] = exp (-ef) + ngkernel[i,j] = gkernel[i,j] + dkernel[i,j] = 1.0 + gsums[GAUSS_SUMG] = gsums[GAUSS_SUMG] + gkernel[i,j] + gsums[GAUSS_SUMGSQ] = gsums[GAUSS_SUMGSQ] + + gkernel[i,j] ** 2 + skip[i,j] = NO + npts = npts + 1.0 + } else { + #gkernel[i,j] = 0.0 + ngkernel[i,j] = 0.0 + dkernel[i,j] = 0.0 + skip[i,j] = YES + } + } + } + + # Store the remaining sums. + gsums[GAUSS_PIXELS] = npts + gsums[GAUSS_DENOM] = gsums[GAUSS_SUMGSQ] - gsums[GAUSS_SUMG] ** 2 / + npts + gsums[GAUSS_SGOP] = gsums[GAUSS_SUMG] / npts + + # Normalize the amplitude kernel. + do j = 1, ny { + do i = 1, nx { + if (skip[i,j] == NO) + ngkernel[i,j] = (gkernel[i,j] - gsums[GAUSS_SGOP]) / + gsums[GAUSS_DENOM] + } + } + + # Normalize the sky kernel + do j = 1, ny { + do i = 1, nx { + if (skip[i,j] == NO) + dkernel[i,j] = dkernel[i,j] / npts + } + } + + relerr = 1.0 / gsums[GAUSS_DENOM] + + return (sqrt (relerr)) +end diff --git a/noao/digiphot/apphot/daofind/apfdcolon.x b/noao/digiphot/apphot/daofind/apfdcolon.x new file mode 100644 index 00000000..cb618bb9 --- /dev/null +++ b/noao/digiphot/apphot/daofind/apfdcolon.x @@ -0,0 +1,282 @@ +include "../lib/apphot.h" +include "../lib/display.h" +include "../lib/noise.h" +include "../lib/find.h" + +# AP_FDCOLON -- Process colon commands from the daofind task. + +procedure ap_fdcolon (ap, im, out, stid, cmdstr, newimage, newbuf, newfit) + +pointer ap # pointer to the apphot structure +pointer im # pointer to the iraf image +int out # output file descriptor +int stid # output file sequence number +char cmdstr # command string +int newimage # new mage ? +int newbuf # new center buffer ? +int newfit # new center fit ? + +int cl, junk +pointer sp, incmd, outcmd +int strdic() + +begin + call smark (sp) + call salloc (incmd, SZ_LINE, TY_CHAR) + call salloc (outcmd, SZ_LINE, TY_CHAR) + + # Get the command. + call sscan (cmdstr) + call gargwrd (Memc[incmd], SZ_LINE) + if (Memc[incmd] == EOS) { + call sfree (sp) + return + } + + # Process the command making sure that the pointer to the + # coords file is always NULL. + if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, APCMDS) != 0) { + cl = NULL + call ap_apcolon (ap, im, cl, out, stid, junk, cmdstr, newimage, + junk, junk, junk, junk, newbuf, newfit) + if (cl != NULL) { + call close (cl) + cl = NULL + call apsets (ap, CLNAME, "") + } + } else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, NCMDS) != 0) { + call ap_nscolon (ap, im, out, stid, cmdstr, junk, junk, + junk, junk, newbuf, newfit) + } else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, FCMDS) != 0) { + call ap_fcolon (ap, out, stid, cmdstr, newbuf, newfit) + } else { + call ap_fimcolon (ap, cmdstr) + } + + call sfree (sp) +end + + +# AP_FCOLON -- Process colon commands for setting the find algorithm +# parameters. + +procedure ap_fcolon (ap, out, stid, cmdstr, newbuf, newfit) + +pointer ap # pointer to the apphot structure +int out # output file descriptor +int stid # file number id +char cmdstr[ARB] # command string +int newbuf, newfit # change magnitude parameters + +bool bval +int ncmd +pointer sp, cmd, str +real rval + +bool itob() +int strdic(), nscan(), btoi(), apstati() +real apstatr() + +begin + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + call salloc (str, SZ_LINE, TY_CHAR) + + # Get the command. + call sscan (cmdstr) + call gargwrd (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call sfree (sp) + return + } + + # Process the command. + ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, FCMDS) + switch (ncmd) { + + case FCMD_NSIGMA: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_NSIGMA) + call pargr (apstatr (ap, NSIGMA)) + call pargstr (UN_FSIGMA) + } else { + call apsetr (ap, NSIGMA, rval) + if (stid > 1) + call ap_rparam (out, KY_NSIGMA, rval, UN_FSIGMA, + "size of kernel in sigma") + newbuf = YES; newfit = YES + } + + case FCMD_RATIO: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_RATIO) + call pargr (apstatr (ap, RATIO)) + call pargstr (UN_FNUMBER) + } else { + call apsetr (ap, RATIO, rval) + if (stid > 1) + call ap_rparam (out, KY_RATIO, rval, UN_FNUMBER, + "sigma y / x of Gaussian kernel") + newbuf = YES; newfit = YES + } + + case FCMD_SHARPLO: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_SHARPLO) + call pargr (apstatr (ap, SHARPLO)) + call pargstr (UN_FNUMBER) + } else { + call apsetr (ap, SHARPLO, rval) + if (stid > 1) + call ap_rparam (out, KY_SHARPLO, rval, UN_FNUMBER, + "lower sharpness bound") + newfit = YES + } + + case FCMD_SHARPHI: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_SHARPHI) + call pargr (apstatr (ap, SHARPHI)) + call pargstr (UN_FNUMBER) + } else { + call apsetr (ap, SHARPHI, rval) + if (stid > 1) + call ap_rparam (out, KY_SHARPHI, rval, UN_FNUMBER, + "upper sharpness bound") + newfit = YES + } + + case FCMD_ROUNDLO: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_ROUNDLO) + call pargr (apstatr (ap, ROUNDLO)) + call pargstr (UN_FNUMBER) + } else { + call apsetr (ap, ROUNDLO, rval) + if (stid > 1) + call ap_rparam (out, KY_ROUNDLO, rval, UN_FNUMBER, + "lower roundness bound") + newfit = YES + } + + case FCMD_ROUNDHI: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_ROUNDHI) + call pargr (apstatr (ap, ROUNDHI)) + call pargstr (UN_FNUMBER) + } else { + call apsetr (ap, ROUNDHI, rval) + if (stid > 1) + call ap_rparam (out, KY_ROUNDHI, rval, UN_FNUMBER, + "upper roundness bound") + newfit = YES + } + + case FCMD_MKDETECTIONS: + call gargb (bval) + if (nscan () == 1) { + call printf ("%s = %b\n") + call pargstr (KY_MKDETECTIONS) + call pargb (itob (apstati (ap, MKDETECTIONS))) + } else + call apseti (ap, MKDETECTIONS, btoi (bval)) + + case FCMD_THETA: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_THETA) + call pargr (apstatr (ap, THETA)) + call pargstr (UN_FDEGREES) + } else { + call apsetr (ap, THETA, rval) + if (stid > 1) + call ap_rparam (out, KY_THETA, rval, UN_FDEGREES, + "position angle") + newbuf = YES; newfit = YES + } + + case FCMD_THRESHOLD: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_THRESHOLD) + call pargr (apstatr (ap, THRESHOLD)) + call pargstr (UN_FSIGMA) + } else { + call apsetr (ap, THRESHOLD, rval) + if (stid > 1) + call ap_rparam (out, KY_THRESHOLD, rval, UN_FSIGMA, + "detection threshold in sigma") + newfit = YES + } + + default: + call printf ("Unknown or ambiguous colon command\7\n") + } + + call sfree (sp) +end + + +# AP_FIMCOLON -- Process colon commands for the daofind task that do +# not affect the data dependent or find parameters. + +procedure ap_fimcolon (ap, cmdstr) + +pointer ap # pointer to the apphot structure +char cmdstr[ARB] # command string + +int ncmd +pointer sp, cmd +int strdic() + +begin + # Get the command. + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + call sscan (cmdstr) + call gargwrd (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call sfree (sp) + return + } + + # Process the command. + ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, MISC1) + switch (ncmd) { + case ACMD_SHOW: + call gargwrd (Memc[cmd], SZ_LINE) + ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, FSHOWARGS) + switch (ncmd) { + case FCMD_DATA: + call printf ("\n") + call ap_nshow (ap) + call printf ("\n") + case FCMD_FIND: + call printf ("\n") + call ap_fshow (ap) + call printf ("\n") + default: + call printf ("\n") + call ap_fdshow (ap) + call printf ("\n") + } + default: + call printf ("Unknown or ambiguous colon command\7\n") + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/daofind/apfdconfirm.x b/noao/digiphot/apphot/daofind/apfdconfirm.x new file mode 100644 index 00000000..ce69cbd9 --- /dev/null +++ b/noao/digiphot/apphot/daofind/apfdconfirm.x @@ -0,0 +1,22 @@ +# AP_FDCONFIRM -- Procedure to confirm the critical daofind parameters. + +procedure ap_fdconfirm (ap) + +pointer ap # pointer to the apphot structure + +real rval +real ap_vfwhmpsf(), ap_vsigma(), ap_vthreshold() +real ap_vdatamin(), ap_vdatamax() + +begin + call printf ("\n") + + # Verify the critical parameters. + rval = ap_vfwhmpsf (ap) + rval = ap_vsigma (ap) + rval = ap_vthreshold (ap) + rval = ap_vdatamin (ap) + rval = ap_vdatamax (ap) + + call printf ("\n") +end diff --git a/noao/digiphot/apphot/daofind/apfdfind.x b/noao/digiphot/apphot/daofind/apfdfind.x new file mode 100644 index 00000000..7778c946 --- /dev/null +++ b/noao/digiphot/apphot/daofind/apfdfind.x @@ -0,0 +1,213 @@ +include <imhdr.h> +include "../lib/apphot.h" +include "../lib/display.h" +include "../lib/find.h" + +define HELPFILE "apphot$daofind/daofind.key" + +# AP_FDFIND -- Find objects in an image interactively. + +int procedure ap_fdfind (denname, skyname, ap, im, gd, id, out, boundary, + constant, save, skysave, interactive, cache) + +char denname[ARB] # name of density enhancement image +char skyname[ARB] # name of the fitted sky image +pointer ap # pointer to the apphot structure +pointer im # pointer to the IRAF image +pointer gd # pointer to the graphics stream +pointer id # pointer to the image display stream +int out # output file descriptor +int boundary # type of boundary extension +real constant # constatn for constant boundary extension +int save # save convolved image +int skysave # save the sky image +int interactive # interactive mode +int cache # cache the input image pixels + +real wx, wy +pointer sp, cmd, root, den, sky +int wcs, key, newimage, newden, newfit, stid, memstat, req_size, old_size +int buf_size + +real apstatr() +pointer ap_immap() +int clgcur(), apgqverify(), apgtverify(), sizeof(), ap_memstat() + +begin + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + call salloc (root, SZ_FNAME, TY_CHAR) + + # Initialize cursor command. + key = ' ' + Memc[cmd] = EOS + call strcpy (" ", Memc[root], SZ_FNAME) + + # Initialize fitting parameters. + den = NULL + sky = NULL + newimage = NO + newden = YES + newfit = YES + memstat = NO + + # Loop over the cursor commands. + stid = 1 + while (clgcur ("icommands", wx, wy, wcs, key, Memc[cmd], SZ_LINE) != + EOF) { + + # Store the current cursor coordinates. + call ap_vtol (im, wx, wy, wx, wy, 1) + call apsetr (ap, CWX, wx) + call apsetr (ap, CWY, wy) + + # Process the colon commands. + switch (key) { + + # Quit. + case 'q': + if (interactive == YES && apgqverify ("daofind", + ap, key) == YES) { + call sfree (sp) + if (den != NULL) { + call imunmap (den) + if (save == NO) + call imdelete (denname) + } + if (sky != NULL) + call imunmap (sky) + return (apgtverify (key)) + } else { + if (den != NULL) { + call imunmap (den) + if (save == NO) + call imdelete (denname) + } + if (sky != NULL) + call imunmap (sky) + call sfree (sp) + return (YES) + } + + # Get information on keystroke commands. + case '?': + if ((id != NULL) && (gd == id)) + call gpagefile (id, HELPFILE, "") + else if (interactive == YES) + call pagefile (HELPFILE, "[space=morehelp,q=quit,?=help]") + + # Plot a centered stellar radial profile + case 'd': + if (interactive == YES) + call ap_qrad (ap, im, wx, wy, gd) + + # Interactively set the daofind parameters. + case 'i': + if (interactive == YES) { + call ap_fdradsetup (ap, im, wx, wy, gd, out, stid) + newden = YES + newfit = YES + } + + # Verify the critical daofind parameters. + case 'v': + call ap_fdconfirm (ap) + newden = YES + newfit = YES + + # Save daofind parameters in the pset files. + case 'w': + call ap_fdpars (ap) + + # Process apphot : commands. + case ':': + call ap_fdcolon (ap, im, out, stid, Memc[cmd], newimage, + newden, newfit) + + # Determine the viewport and data window of image display. + if (newimage == YES) { + if ((id != NULL) && (id != gd)) + call ap_gswv (id, Memc[cmd], im, 4) + req_size = MEMFUDGE * (IM_LEN(im,1) * IM_LEN(im,2) * + sizeof (IM_PIXTYPE(im)) + 2 * IM_LEN(im,1) * + IM_LEN(im,2) * sizeof (TY_REAL)) + memstat = ap_memstat (cache, req_size, old_size) + if (memstat == YES) + call ap_pcache (im, INDEFI, buf_size) + } + newimage = NO + + # Find the stars. + case 'f', ' ': + + if (newden == YES) { + + if (den != NULL) { + call imunmap (den) + call imdelete (denname) + } + den = ap_immap (denname, im, ap, save) + if (memstat == YES) + call ap_pcache (den, INDEFI, buf_size) + + if (sky != NULL) + call imunmap (sky) + if (skysave == YES) { + sky = ap_immap (skyname, im, ap, YES) + if (memstat == YES) + call ap_pcache (den, INDEFI, buf_size) + } else + sky = NULL + newden = NO + + if (key == 'f') { + call ap_fdstars (im, ap, den, sky, NULL, id, + boundary, constant, NO, stid) + } else { + call ap_outmap (ap, out, Memc[root]) + call ap_fdstars (im, ap, den, sky, out, id, + boundary, constant, NO, stid) + newfit = NO + } + + } else if (newfit == YES) { + + if (key == 'f') { + call ap_fdstars (im, ap, den, sky, NULL, id, + boundary, constant, YES, stid) + } else { + call ap_outmap (ap, out, Memc[root]) + call ap_fdstars (im, ap, den, sky, out, id, + boundary, constant, YES, stid) + newfit = NO + } + + } else { + call printf ("Detection parameters have not changed\n") + } + + if (id != NULL) { + if (id == gd) + call gflush (id) + else + call gframe (id) + } + + stid = 1 + #newden = NO + #newfit = NO + + default: + # do nothing + call printf ("Unknown or ambiguous keystroke command\n") + } + + # Setup for the next object. + key = ' ' + Memc[cmd] = EOS + call apsetr (ap, WX, apstatr (ap, CWX)) + call apsetr (ap, WY, apstatr (ap, CWY)) + + } + +end diff --git a/noao/digiphot/apphot/daofind/apfdfree.x b/noao/digiphot/apphot/daofind/apfdfree.x new file mode 100644 index 00000000..3f1ea762 --- /dev/null +++ b/noao/digiphot/apphot/daofind/apfdfree.x @@ -0,0 +1,34 @@ +include "../lib/apphotdef.h" + +# AP_FDFREE -- Free the apphot data structure. + +procedure ap_fdfree (ap) + +pointer ap # pointer to the apphot structure + +begin + if (ap == NULL) + return + if (AP_NOISE(ap) != NULL) + call ap_noisecls (ap) + if (AP_PFIND(ap) != NULL) + call ap_fdcls (ap) + if (AP_PDISPLAY(ap) != NULL) + call ap_dispcls (ap) + if (AP_IMBUF(ap) != NULL) + call mfree (AP_IMBUF(ap), TY_REAL) + if (AP_MW(ap) != NULL) + call mw_close (AP_MW(ap)) + call mfree (ap, TY_STRUCT) +end + + +# AP_FDCLS -- Free the find data structure. + +procedure ap_fdcls (ap) + +pointer ap # pointer to the apphot structure + +begin + call mfree (AP_PFIND(ap), TY_STRUCT) +end diff --git a/noao/digiphot/apphot/daofind/apfdgpars.x b/noao/digiphot/apphot/daofind/apfdgpars.x new file mode 100644 index 00000000..95d87d23 --- /dev/null +++ b/noao/digiphot/apphot/daofind/apfdgpars.x @@ -0,0 +1,20 @@ +include "../lib/noise.h" +include "../lib/display.h" + +# AP_FDGPARS -- Open up the apphot data structure and get the daofind input +# parameters. + +procedure ap_fdgpars (ap) + +pointer ap # pointer to the apphot structure + +begin + # Open the apphot structure. + call ap_fdinit (ap, 2.0, AP_NPOISSON) + + # Get the data dependent parameters. + call ap_gdapars (ap) + + # Get the find parameters. + call ap_gfipars (ap) +end diff --git a/noao/digiphot/apphot/daofind/apfdinit.x b/noao/digiphot/apphot/daofind/apfdinit.x new file mode 100644 index 00000000..9c31b494 --- /dev/null +++ b/noao/digiphot/apphot/daofind/apfdinit.x @@ -0,0 +1,59 @@ +include "../lib/apphotdef.h" +include "../lib/finddef.h" + +# AP_FDINIT - Initialize the daofind data structure. + +procedure ap_fdinit (ap, fwhmpsf, noise) + +pointer ap # pointer to the apphot structure +real fwhmpsf # FWHM of the PSF +int noise # noise function + +begin + # Allocate space. + call malloc (ap, LEN_APSTRUCT, TY_STRUCT) + + # Set the default global apphot package parameters. + call ap_defsetup (ap, fwhmpsf) + + # Setup the noise structure. + call ap_noisesetup (ap, noise) + + # Setup the display structure. + call ap_dispsetup (ap) + + # Setup the find structure. + call ap_fdsetup (ap) + + # Unused structures are set to null. + AP_PCENTER(ap) = NULL + AP_PSKY(ap) = NULL + AP_PPSF(ap) = NULL + AP_PPHOT(ap) = NULL + AP_POLY(ap) = NULL + AP_RPROF(ap) = NULL +end + + +# AP_FDSETUP -- Initialize the find structure. + +procedure ap_fdsetup (ap) + +pointer ap # pointer to the apphot strucuture + +pointer fnd + +begin + call malloc (AP_PFIND(ap), LEN_FIND, TY_STRUCT) + fnd = AP_PFIND(ap) + + AP_RATIO(fnd) = DEF_RATIO + AP_THETA(fnd) = DEF_RATIO + AP_NSIGMA(fnd) = DEF_NSIGMA + + AP_THRESHOLD(fnd) = DEF_THRESHOLD + AP_SHARPLO(fnd) = DEF_SHARPLO + AP_SHARPHI(fnd) = DEF_SHARPHI + AP_ROUNDLO(fnd) = DEF_ROUNDLO + AP_ROUNDHI(fnd) = DEF_ROUNDLO +end diff --git a/noao/digiphot/apphot/daofind/apfdpars.x b/noao/digiphot/apphot/daofind/apfdpars.x new file mode 100644 index 00000000..108f205b --- /dev/null +++ b/noao/digiphot/apphot/daofind/apfdpars.x @@ -0,0 +1,16 @@ +include "../lib/display.h" + +# AP_FDPARS -- Write out the current daofind parameters to the current +# parameter files. + +procedure ap_fdpars (ap) + +pointer ap # pointer to apphot structure + +begin + # Write the data dependent parameters. + call ap_dapars (ap) + + # Write the daofind parameters. + call ap_fipars (ap) +end diff --git a/noao/digiphot/apphot/daofind/apfdradsetup.x b/noao/digiphot/apphot/daofind/apfdradsetup.x new file mode 100644 index 00000000..708d2690 --- /dev/null +++ b/noao/digiphot/apphot/daofind/apfdradsetup.x @@ -0,0 +1,82 @@ +define HELPFILE "apphot$daofind/idaofind.key" + +# AP_FDRADSETUP -- Procedure to set up daofind interactively using the radial +# profile plot of a bright star. + +procedure ap_fdradsetup (ap, im, wx, wy, gd, out, stid) + +pointer ap # pointer to apphot structure +pointer im # pointer to the IRAF image +real wx, wy # cursor coordinates +pointer gd # pointer to graphics stream +int out # output file descriptor +int stid # output file sequence number) + +int key, wcs +pointer sp, cmd +real rmin, rmax, imin, imax, xcenter, ycenter, rval +real u1, u2, v1, v2, x1, x2, y1, y2 +int ap_showplot(), clgcur() +real ap_cfwhmpsf(), ap_csigma(), ap_cdatamin(), ap_cdatamax() + +begin + # Check for open graphics stream. + if (gd == NULL) + return + call greactivate (gd, 0) + + # Store the old viewport and window coordinates. + call ggview (gd, u1, u2, v1, v2) + call ggwind (gd, x1, x2, y1, y2) + + # Make the plot. + if (ap_showplot (ap, im, wx, wy, gd, xcenter, ycenter, rmin, rmax, + imin, imax) == ERR) { + call gdeactivate (gd, 0) + return + } + + # Initialize. + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + call printf ( + "Waiting for setup menu command (?=help, v=default setup, q=quit):\n") + while (clgcur ("gcommands", xcenter, ycenter, wcs, key, Memc[cmd], + SZ_LINE) != EOF) { + + # Enter the cursor setup loop. + switch (key) { + case 'q': + break + case '?': + call gpagefile (gd, HELPFILE, "") + case 'f': + rval = ap_cfwhmpsf (ap, gd, out, stid, rmin, rmax, imin, imax) + case 's': + rval = ap_csigma (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'l': + rval = ap_cdatamin (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'u': + rval = ap_cdatamax (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'v': + rval = ap_cfwhmpsf (ap, gd, out, stid, rmin, rmax, imin, imax) + rval = ap_csigma (ap, gd, out, stid, rmin, rmax, imin, imax) + default: + call printf ("Unknown or ambiguous keystroke command\007\n") + } + call printf ( + "Waiting for setup menu command (?=help, v=default setup, q=quit):\n") + } + + # Interactive setup is complete. + call printf ( + "Interactive setup is complete. Type w to store parameters.\n") + + # Restore the viewport and window coordinates. + call gsview (gd, u1, u2, v1, v2) + call gswind (gd, x1, x2, y1, y2) + + call gdeactivate (gd, 0) + call sfree (sp) +end diff --git a/noao/digiphot/apphot/daofind/apfdshow.x b/noao/digiphot/apphot/daofind/apfdshow.x new file mode 100644 index 00000000..61be95ca --- /dev/null +++ b/noao/digiphot/apphot/daofind/apfdshow.x @@ -0,0 +1,72 @@ +include "../lib/apphot.h" +include "../lib/noise.h" +include "../lib/find.h" + +# AP_FDSHOW -- Display the current find parameters. + +procedure ap_fdshow (ap) + +pointer ap # pointer to the apphot strucuture + +begin + call ap_nshow (ap) + call printf ("\n") + call ap_fshow (ap) +end + + +# AP_FSHOW -- Procedure to display the current data parameters. + +procedure ap_fshow (ap) + +pointer ap # pointer to the apphot strucuture + +pointer sp, str +bool itob() +int apstati() +real apstatr() + +begin + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + + # Set the object charactersitics. + call printf ("Kernel Parameters\n") + call printf (" %s = %g %s %s = %b\n") + call pargstr (KY_FWHMPSF) + call pargr (apstatr (ap, FWHMPSF)) + call pargstr (UN_ASCALEUNIT) + call pargstr (KY_POSITIVE) + call pargb (itob (apstati (ap, POSITIVE))) + + call printf (" %s = %g %s %s = %g %s = %g %s\n") + call pargstr (KY_NSIGMA) + call pargr (apstatr (ap, NSIGMA)) + call pargstr (UN_FSIGMA) + call pargstr (KY_RATIO) + call pargr (apstatr (ap, RATIO)) + call pargstr (KY_THETA) + call pargr (apstatr (ap, THETA)) + call pargstr (UN_FDEGREES) + + # Print the rest of the data dependent parameters. + call printf ("\nDetection Parameters\n") + call printf (" %s = %g %s\n") + call pargstr (KY_THRESHOLD) + call pargr (apstatr (ap, THRESHOLD)) + call pargstr (UN_FSIGMA) + + call printf (" %s = %g %s = %g\n") + call pargstr (KY_SHARPLO) + call pargr (apstatr (ap, SHARPLO)) + call pargstr (KY_SHARPHI) + call pargr (apstatr (ap, SHARPHI)) + + call printf (" %s = %g %s = %g\n") + call pargstr (KY_ROUNDLO) + call pargr (apstatr (ap, ROUNDLO)) + call pargstr (KY_ROUNDHI) + call pargr (apstatr (ap, ROUNDHI)) + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/daofind/apfdstars.x b/noao/digiphot/apphot/daofind/apfdstars.x new file mode 100644 index 00000000..893619f5 --- /dev/null +++ b/noao/digiphot/apphot/daofind/apfdstars.x @@ -0,0 +1,151 @@ +include <imhdr.h> +include <mach.h> +include "../lib/apphot.h" +include "../lib/noise.h" +include "../lib/display.h" +include "../lib/find.h" + +# AP_FDSTARS -- Find stars in an image using a pattern matching technique. + +procedure ap_fdstars (im, ap, cnv, sky, out, id, boundary, constant, + refit, stid) + +pointer im # pointer to the input image +pointer ap # pointer to the apphot structure +pointer cnv # pointer to the convolved image +pointer sky # pointer to the sky image +int out # the output file descriptor +pointer id # pointer to image display stream +int boundary # type of boundary extension +real constant # constant for constant boundary extension +int refit # detect stars again +int stid # output file sequence number + +int norm, nxk, nyk, nstars +pointer sp, str, gker2d, ngker2d, dker2d, skip +real a, b, c, f, skysigma, skymode, threshold, relerr, gsums[LEN_GAUSS] +real dmin, dmax, xsigsq, ysigsq +int apstati(), ap_find() +real ap_egkernel(), apstatr() +data gker2d/NULL/, ngker2d/NULL/, dker2d/NULL/ skip /NULL/ + +define detect_ 99 + +begin + call smark (sp) + call salloc (str, SZ_FNAME, TY_CHAR) + + if (refit == YES) + goto detect_ + + # Compute the parameters of the Gaussian kernel. + call ap_egparams (FWHM_TO_SIGMA * apstatr (ap, FWHMPSF) * apstatr (ap, + SCALE), apstatr (ap, RATIO), apstatr (ap, THETA), apstatr (ap, + NSIGMA), a, b, c, f, nxk, nyk) + + # Allocate working space. + if (gker2d != NULL) + call mfree (gker2d, TY_REAL) + call malloc (gker2d, nxk * nyk, TY_REAL) + if (ngker2d != NULL) + call mfree (ngker2d, TY_REAL) + call malloc (ngker2d, nxk * nyk, TY_REAL) + if (dker2d != NULL) + call mfree (dker2d, TY_REAL) + call malloc (dker2d, nxk * nyk, TY_REAL) + if (skip != NULL) + call mfree (skip, TY_INT) + call malloc (skip, nxk * nyk, TY_INT) + + # Compute the 1 and 2 D kernels. + if (IS_INDEFR(apstatr(ap, DATAMIN)) && IS_INDEFR(apstatr(ap, + DATAMAX))) { + norm = YES + dmin = -MAX_REAL + dmax = MAX_REAL + } else { + norm = NO + if (IS_INDEFR(apstatr (ap, DATAMIN))) + dmin = -MAX_REAL + else + dmin = apstatr (ap, DATAMIN) + if (IS_INDEFR(apstatr (ap, DATAMAX))) + dmax = MAX_REAL + else + dmax = apstatr (ap, DATAMAX) + } + relerr = ap_egkernel (Memr[gker2d], Memr[ngker2d], Memr[dker2d], + Memi[skip], nxk, nyk, gsums, a, b, c, f) + + # Set up the image boundary extension characteristics. + call ap_imset (im, boundary, max (1 + nxk / 2, 1 + nyk / 2), + constant) + call ap_imset (cnv, boundary, max (1 + nxk / 2, 1 + nyk / 2), + constant) + + # Convolve the input image with the Gaussian kernel. The resultant + # picture constains in each pixel the height of the Gaussian + # function centered in the subarray which best represents the data + # within a circle of nsigma * sigma of the Gaussian. + + if (norm == YES) + call ap_fconvolve (im, cnv, sky, Memr[ngker2d], Memr[dker2d], + Memi[skip], nxk, nyk, gsums[GAUSS_SGOP]) + else + call ap_gconvolve (im, cnv, sky, Memr[gker2d], Memi[skip], + nxk, nyk, gsums, dmin, dmax) + +detect_ + + # Write the output header file. + if (stid <= 1) + call ap_wfdparam (out, ap) + + call printf ("\nImage: %s ") + call pargstr (IM_HDRFILE(im)) + call printf ("fwhmpsf: %g ratio: %g theta: %g nsigma: %g\n\n") + call pargr (apstatr (ap, FWHMPSF)) + call pargr (apstatr (ap, RATIO)) + call pargr (apstatr (ap, THETA)) + call pargr (apstatr (ap, NSIGMA)) + + # Find all the objects in the input image with the specified image + # characteristics. + + skysigma = apstatr (ap, SKYSIGMA) + if (IS_INDEFR(skysigma)) { + skymode = 0.0 + threshold = 0.0 + } else { + skymode = apstatr (ap, EPADU) * (skysigma ** 2 - (apstatr (ap, + READNOISE) / apstatr (ap, EPADU)) ** 2) + skymode = max (0.0, skymode) + threshold = apstatr (ap, THRESHOLD) * skysigma + } + xsigsq = (apstatr (ap, SCALE) * apstatr (ap, FWHMPSF) / 2.35482) ** 2 + ysigsq = (apstatr (ap, SCALE) * apstatr (ap, RATIO) * + apstatr (ap, FWHMPSF) / 2.35482) ** 2 + + nstars = ap_find (ap, im, cnv, out, id, Memr[gker2d], + Memi[skip], nxk, nyk, skymode, threshold, relerr, + apstati (ap, POSITIVE), xsigsq, ysigsq, dmin, dmax, + apstatr (ap, SHARPLO), apstatr (ap, SHARPHI), apstatr (ap, + ROUNDLO), apstatr (ap, ROUNDHI), YES, stid, apstati (ap, + MKDETECTIONS)) + stid = stid + nstars + + call printf ("\nthreshold: %g relerr: %5.3f %g <= sharp <= %g ") + call pargr (threshold) + call pargr (relerr) + call pargr (apstatr (ap, SHARPLO)) + call pargr (apstatr (ap, SHARPHI)) + call printf ("%g <= round <= %g \n\n") + call pargr (apstatr (ap, ROUNDLO)) + call pargr (apstatr (ap, ROUNDHI)) + + call apstats (ap, OUTNAME, Memc[str], SZ_FNAME) + call printf ("Output file: %s\n\n") + call pargstr (Memc[str]) + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/daofind/apfind.x b/noao/digiphot/apphot/daofind/apfind.x new file mode 100644 index 00000000..1bcbdd52 --- /dev/null +++ b/noao/digiphot/apphot/daofind/apfind.x @@ -0,0 +1,626 @@ +include <gset.h> +include <mach.h> +include <imhdr.h> +include "../lib/apphot.h" + +# AP_FIND -- Detect images in the convolved image and then compute image +# characteristics using the original image. + +int procedure ap_find (ap, im, cnv, out, id, ker2d, skip, nxk, nyk, skymode, + threshold, relerr, emission, xsigsq, ysigsq, datamin, datamax, + sharplo, sharphi, roundlo, roundhi, interactive, stid, mkdetections) + +pointer ap # the apphot descriptor +pointer im # pointer to the input image +pointer cnv # pointer to the output image +int out # the output file descriptor +pointer id # pointer to the display stream +real ker2d[nxk,ARB] # 2D Gaussian kernel +int skip[nxk,ARB] # 2D skip kernel +int nxk, nyk # dimensions of the kernel +real skymode # estimate of the sky +real threshold # threshold for image detection +real relerr # the relative error of the convolution kernel +int emission # emission features +real xsigsq, ysigsq # sigma of gaussian in x and y +real datamin, datamax # minimum and maximum good data values +real sharplo, sharphi # sharpness limits +real roundlo,roundhi # roundness parameter limits +int interactive # interactive mode +int stid # sequence number +int mkdetections # mark detections + +int inline, i, j, ncols, col1, col2, line1, line2, index, pos +int xmiddle, ymiddle, nonzero, nobjs, nstars, ntotal +pointer sp, bufptrs, imlbuf, cnvlbuf, imbuf, cnvbuf, cols +pointer satur, sharp, round1, round2, x, y + +int ap_detect(), ap_test(), apstati() +pointer imgs2r() +errchk imgs2r() + +begin + # Set up useful line and column limits. + ncols = IM_LEN(im,1) + nxk - 1 + col1 = 1 - nxk / 2 + col2 = IM_LEN(im,1) + nxk / 2 + line1 = 1 + nyk / 2 + line2 = IM_LEN(im,2) + nyk / 2 + xmiddle = 1 + nxk / 2 + ymiddle = 1 + nyk / 2 + + # Compute find the number of defined elements in the kernel. + nonzero = 0 + #skip[xmiddle,ymiddle] = NO + do j = 1, nyk { + do i = 1, nxk { + if (skip[i,j] == NO) + nonzero = nonzero + 1 + } + } + skip[xmiddle,ymiddle] = YES + nonzero = nonzero - 1 + + # Set up a cylindrical buffers and some working space for + # the detected images. + call smark (sp) + call salloc (bufptrs, nyk, TY_INT) + call salloc (imbuf, nyk * ncols, TY_REAL) + call salloc (cnvbuf, nyk * ncols, TY_REAL) + call salloc (cols, ncols, TY_INT) + call salloc (satur, ncols, TY_INT) + call salloc (sharp, ncols, TY_REAL) + call salloc (round1, ncols, TY_REAL) + call salloc (round2, ncols, TY_REAL) + call salloc (x, ncols, TY_REAL) + call salloc (y, ncols, TY_REAL) + + # Read in the first nyk - 1 lines. + pos = nyk + do inline = 1 - nyk / 2, nyk / 2 { + imlbuf = imgs2r (im, col1, col2, inline, inline) + cnvlbuf = imgs2r (cnv, col1, col2, inline, inline) + if (emission == YES) { + call amovr (Memr[imlbuf], Memr[imbuf+(inline+ymiddle-2)*ncols], + ncols) + call amovr (Memr[cnvlbuf], Memr[cnvbuf+(inline+ymiddle-2)* + ncols], ncols) + } else { + call amulkr (Memr[imlbuf], -1.0, Memr[imbuf+(inline+ymiddle-2)* + ncols], ncols) + call amulkr (Memr[cnvlbuf], -1.0, Memr[cnvbuf+(inline+ymiddle- + 2)* ncols], ncols) + } + Memi[bufptrs+pos-1] = pos - 1 + pos = pos - 1 + } + + # Generate the starlist line by line. + ntotal = 0 + pos = nyk + do inline = line1, line2 { + + # Setup the buffer pointer array. + do j = 2, nyk + Memi[bufptrs+j-2] = Memi[bufptrs+j-1] + Memi[bufptrs+nyk-1] = pos + index = (pos - 1) * ncols + + # Read in new image line. + imlbuf = imgs2r (im, col1, col2, inline, inline) + cnvlbuf = imgs2r (cnv, col1, col2, inline, inline) + + # Copy new lines into cylindrical buffer. + if (emission == YES) { + call amovr (Memr[imlbuf], Memr[imbuf+index], ncols) + call amovr (Memr[cnvlbuf], Memr[cnvbuf+index], ncols) + } else { + call amulkr (Memr[imlbuf], -1.0, Memr[imbuf+index], ncols) + call amulkr (Memr[cnvlbuf], -1.0, Memr[cnvbuf+index], ncols) + } + + # Detect stars in each image line. In order for a given pixel + # to be detected as an image the pixel must be above threshold + # and be greater than any other pixel within nsigma sigma. + + # Increment the cylindrical buffer. + if (mod (pos, nyk) == 0) + pos = 1 + else + pos = pos + 1 + + nobjs = ap_detect (Memr[cnvbuf], Memi[bufptrs], ncols, skip, nxk, + nyk, relerr * threshold, Memi[cols]) + if (nobjs <= 0) + next + + # Compute the sharpness parameter. + call ap_sharp_round (Memr[imbuf], Memr[cnvbuf], Memi[bufptrs], + ncols, skip, nxk, nyk, Memi[cols], Memi[satur], Memr[round1], + Memr[sharp], nobjs, nonzero, skymode, datamin, datamax) + + # Compute the roundness parameters. + call ap_xy_round (Memr[imbuf], Memi[bufptrs], ncols, ker2d, nxk, + nyk, Memi[cols], inline, Memr[round2], Memr[x], + Memr[y], nobjs, skymode, datamin, datamax, xsigsq, ysigsq) + + # Test the image characeteristics of detected objects. + nstars = ap_test (Memi[cols], Memr[x], Memr[y], Memi[satur], + Memr[round1], Memr[round2], Memr[sharp], nobjs, IM_LEN(im,1), + IM_LEN(im,2), sharplo, sharphi, roundlo, roundhi) + + # Mark the stars on the display. + if ((nstars > 0) && (interactive == YES) && (id != NULL) && + (mkdetections == YES)) { + call greactivate (id, 0) + do j = 1, nstars { + #call ap_ltov (im, Memr[x+j-1], Memr[y+j-1], xc, yc, 1) + #call gmark (id, xc, yc, GM_PLUS, 1.0, 1.0) + call gmark (id, Memr[x+j-1], Memr[y+j-1], GM_PLUS, 1.0, 1.0) + } + call gdeactivate (id, 0) + } + + switch (apstati (ap, WCSOUT)) { + case WCS_PHYSICAL: + call ap_ltoo (ap, Memr[x], Memr[y], Memr[x], Memr[y], nstars) + case WCS_TV: + call ap_ltov (im, Memr[x], Memr[y], Memr[x], Memr[y], nstars) + default: + ; + } + + # Print results on the standard output. + if (interactive == YES) + call apstdout (Memr[cnvbuf], Memi[bufptrs], ncols, nyk, + Memi[cols], Memr[x], Memr[y], Memr[sharp], Memr[round1], + Memr[round2], nstars, ntotal, relerr * threshold) + + # Save the results in the file. + call apdtfout (out, Memr[cnvbuf], Memi[bufptrs], ncols, nyk, + Memi[cols], Memr[x], Memr[y], Memr[sharp], Memr[round1], + Memr[round2], nstars, ntotal, relerr * threshold, stid) + + + ntotal = ntotal + nstars + + } + + # Free space + call sfree (sp) + + return (ntotal) +end + + +# AP_DETECT -- Detec stellar objects in an image line. In order to be +# detected as a star the candidate object must be above threshold and have +# a maximum pixel value greater than any pixels within nsigma * sigma. + +int procedure ap_detect (density, ptrs, ncols, skip, nxk, nyk, threshold, cols) + +real density[ncols, ARB] # density array +int ptrs[ARB] # pointer array +int ncols # x dimesnsion of intensity buffer +int skip[nxk,ARB] # skip array +int nxk, nyk # size of convolution kernel +real threshold # density threshold +int cols[ARB] # column numbers of detected stars + +int i, j, k, kk, middle, nhalf, nobjs +define nextpix_ 11 + +begin + middle = 1 + nyk / 2 + nhalf = nxk / 2 + + # Loop over all the columns in an image line. + nobjs = 0 + for (i = 1 + nhalf; i <= ncols - nhalf; ) { + + # Test whether the density enhancement is above threshold. + if (density[i,ptrs[middle]] < threshold) + goto nextpix_ + + # Test whether a given density enhancement is a local maximum. + do j = 1, nyk { + kk = 1 + do k = i - nhalf, i + nhalf { + if (skip[kk,j] == NO) { + if (density[i,ptrs[middle]] < density[k,ptrs[j]]) + goto nextpix_ + } + kk = kk + 1 + } + } + + # Add the detected object to the list. + nobjs = nobjs + 1 + cols[nobjs] = i + + # If a local maximum is detected there can be no need to + # check pixels in this row between i and i + nhalf. + i = i + nhalf +nextpix_ + # Work on the next pixel. + i = i + 1 + } + + return (nobjs) +end + + +# AP_SHARP_ROUND -- Compute an estimate of the roundness and sharpness of the +# detected objects. The roundness parameter is computed by comparing a measure +# of the bilateral symmetry with a measure of the four-fold symmetry. The +# sharpness parameter is defined as the ratio of the difference between the +# height of the central pixel and the mean of the surrounding pixels to the +# density enhancement of the central pixel. + +procedure ap_sharp_round (data, density, ptrs, ncols, skip, nxk, nyk, cols, + satur, round, sharps, nobjs, nonzero, skymode, datamin, datamax) + +real data[ncols,ARB] # image data +real density[ncols,ARB] # density enhancements +int ptrs[ARB] # buffer pointers +int ncols # length of data array +int skip[nxk,ARB] # 2D kernel +int nxk, nyk # size of convolution kernel +int cols[ARB] # array of columns +int satur[ARB] # array of saturated state parameters +real round[ARB] # array of roundness parameters +real sharps[ARB] # array of sharpness parameters +int nobjs # number of objects +int nonzero # number of nonzero kernel elements +real skymode # estimate of the sky mode +real datamin, datamax # minimum and maximum good data values + +int i, j, k, xmiddle, ymiddle, npixels, nhalf +real pixval, midpix, temp, sharp, sum2, sum4 + +begin + # Loop over the detected objects. + nhalf = min (nxk / 2, nyk / 2) + xmiddle = 1 + nxk / 2 + ymiddle = 1 + nyk / 2 + do i = 1, nobjs { + + # Compute the first estimate of roundness. + sum2 = 0.0 + sum4 = 0.0 + do k = 0, nhalf { + do j = 1, nhalf { + sum2 = sum2 + + density[cols[i]-k,ptrs[ymiddle-j]] + + density[cols[i]+k,ptrs[ymiddle+j]] - + density[cols[i]-j,ptrs[ymiddle+k]] - + density[cols[i]+j,ptrs[ymiddle-k]] + sum4 = sum4 + + abs (density[cols[i]-k,ptrs[ymiddle-j]]) + + abs (density[cols[i]+k,ptrs[ymiddle+j]]) + + abs (density[cols[i]-j,ptrs[ymiddle+k]]) + + abs (density[cols[i]+j,ptrs[ymiddle-k]]) + } + } + if (sum2 == 0.0) + round[i] = 0.0 + else if (sum4 <= 0.0) + round[i] = INDEFR + else + round[i] = 2.0 * sum2 / sum4 + + satur[i] = NO + + # Eliminate the sharpness test if the central pixel is bad. + midpix = data[cols[i],ptrs[ymiddle]] + if (midpix > datamax) { + satur[i] = YES + sharps[i] = INDEFR + next + } + if (midpix < datamin) { + sharps[i] = INDEFR + next + } + + # Accumulate the sharpness statistic. + sharp = 0.0 + npixels = nonzero + do j = 1, nyk { + temp = 0.0 + do k = 1, nxk { + if (skip[k,j] == YES) + next + pixval = data[cols[i]-xmiddle+k,ptrs[j]] + if (pixval > datamax) { + satur[i] = YES + npixels = npixels - 1 + } else if (pixval < datamin) { + npixels = npixels - 1 + } else { + temp = temp + (pixval - skymode) + } + } + sharp = sharp + temp + } + + # Compute the sharpness statistic. + if (density[cols[i],ptrs[ymiddle]] <= 0.0 || npixels <= 0) + sharps[i] = INDEFR + else + sharps[i] = (midpix - skymode - sharp / real (npixels)) / + density[cols[i],ptrs[ymiddle]] + + } +end + + +# AP_XY_ROUND -- Estimate the x-y centers and the roundness of the detected +# objects. The height of the equivalent Gaussian function in x and y is fit by +# least squares to the marginal distribution of the image data. If either +# of these of these heights is negative set the roundess characteristic to +# -MAX_REAL, otherwise compute a roundness characteristic. At the same +# time setup the necessary sums for computing the first order corection +# to the centroid of the gaussian profile. + +procedure ap_xy_round (data, ptrs, ncols, ker2d, nxk, nyk, cols, inline, + rounds, x, y, nobjs, skymode, datamin, datamax, xsigsq, ysigsq) + +real data[ncols,ARB] # density enhancements +int ptrs[ARB] # buffer pointers +int ncols # number of columns in cylindrical buffer +real ker2d[nxk,ARB] # the gaussian convolution kernel +int nxk # size of kernel in x +int nyk # size of kernel in y +int cols[ARB] # the input positions +int inline # the input image line +real rounds[ARB] # array of sharpness parameters +real x[ARB] # output x coords +real y[ARB] # output y coords +int nobjs # number of objects +real skymode # estimate of the sky mode +real datamin, datamax # minium and maximum data values +real xsigsq, ysigsq # x-y gaussian sigma squared + +int i, j, k, xmiddle, ymiddle, n +real sumgd, sumgsq, sumg, sumd, sumdx, dgdx, sdgdx, sdgdxsq, sddgdx, sgdgdx +real pixval, p, sg, sd, wt, hx, hy, dx, dy, skylvl, xhalf, yhalf + +begin + xhalf = real (nxk / 2) + 0.5 + yhalf = real (nyk / 2) + 0.5 + xmiddle = 1 + nxk / 2 + ymiddle = 1 + nyk / 2 + + # Loop over the detected objects. + do i = 1, nobjs { + + # Initialize the x fit. + sumgd = 0.0 + sumgsq = 0.0 + sumg = 0.0 + sumd = 0.0 + sumdx = 0.0 + sdgdx = 0.0 + sdgdxsq = 0.0 + sddgdx = 0.0 + sgdgdx = 0.0 + p = 0.0 + n = 0 + + # Compute the sums required for the x fit. + do k = 1, nxk { + + sg = 0.0 + sd = 0.0 + do j = 1, nyk { + wt = real (ymiddle - abs (j - ymiddle)) + pixval = data[cols[i]-xmiddle+k,ptrs[j]] + if (pixval < datamin || pixval > datamax) + next + sd = sd + (pixval - skymode) * wt + sg = sg + ker2d[k,j] * wt + } + + if (sg <= 0.0) + next + wt = real (xmiddle - abs (k - xmiddle)) + sumgd = sumgd + wt * sg * sd + sumgsq = sumgsq + wt * sg ** 2 + sumg = sumg + wt * sg + sumd = sumd + wt * sd + sumdx = sumdx + wt * sd * (xmiddle - k) + p = p + wt + n = n + 1 + dgdx = sg * (xmiddle - k) + sdgdxsq = sdgdxsq + wt * dgdx ** 2 + sdgdx = sdgdx + wt * dgdx + sddgdx = sddgdx + wt * sd * dgdx + sgdgdx = sgdgdx + wt * sg * dgdx + } + + # Need at least three points to estimate the x height, position + # and local sky brightness of the star. + + if (n <= 2 || p <= 0.0) { + x[i] = INDEFR + y[i] = INDEFR + rounds[i] = INDEFR + next + } + + # Solve for the height of the best-fitting gaussian to the + # xmarginal. Reject the star if the height is non-positive. + + hx = sumgsq - (sumg ** 2) / p + if (hx <= 0.0) { + x[i] = INDEFR + y[i] = INDEFR + rounds[i] = INDEFR + next + } + hx = (sumgd - sumg * sumd / p) / hx + if (hx <= 0.0) { + x[i] = INDEFR + y[i] = INDEFR + rounds[i] = INDEFR + next + } + + # Solve for the new x centroid. + skylvl = (sumd - hx * sumg) / p + dx = (sgdgdx - (sddgdx - sdgdx * (hx * sumg + skylvl * p))) / + (hx * sdgdxsq / xsigsq) + if (abs (dx) > xhalf) { + if (sumd == 0.0) + dx = 0.0 + else + dx = sumdx / sumd + if (abs (dx) > xhalf) + dx = 0.0 + } + x[i] = (cols[i] - xmiddle + 1) + dx + + # Initialize y fit. + sumgd = 0.0 + sumgsq = 0.0 + sumg = 0.0 + sumd = 0.0 + sumdx = 0.0 + sdgdx = 0.0 + sdgdxsq = 0.0 + sddgdx = 0.0 + sgdgdx = 0.0 + p = 0.0 + n = 0 + + do j = 1, nyk { + sg = 0.0 + sd = 0.0 + do k = 1, nxk { + wt = real (xmiddle - abs (k - xmiddle)) + pixval = data[cols[i]-xmiddle+k,ptrs[j]] + if (pixval < datamin || pixval > datamax) + next + sd = sd + (pixval - skymode) * wt + sg = sg + ker2d[k,j] * wt + } + if (sg <= 0.0) + next + wt = real (ymiddle - abs (j - ymiddle)) + sumgd = sumgd + wt * sg * sd + sumgsq = sumgsq + wt * sg ** 2 + sumg = sumg + wt * sg + sumd = sumd + wt * sd + sumdx = sumdx + wt * sd * (j - ymiddle) + p = p + wt + n = n + 1 + dgdx = sg * (ymiddle - j) + sdgdx = sdgdx + wt * dgdx + sdgdxsq = sdgdxsq + wt * dgdx ** 2 + sddgdx = sddgdx + wt * sd * dgdx + sgdgdx = sgdgdx + wt * sg * dgdx + } + + # Need at least three points to estimate the y height, position + # and local sky brightness of the star. + + if (n <= 2 || p <= 0.0) { + x[i] = INDEFR + y[i] = INDEFR + rounds[i] = INDEFR + next + } + + # Solve for the height of the best-fitting gaussian to the + # y marginal. Reject the star if the height is non-positive. + + hy = sumgsq - (sumg ** 2) / p + if (hy <= 0.0) { + x[i] = INDEFR + y[i] = INDEFR + rounds[i] = INDEFR + next + } + hy = (sumgd - sumg * sumd / p) / (sumgsq - (sumg ** 2) / p) + if (hy <= 0.0) { + x[i] = INDEFR + y[i] = INDEFR + rounds[i] = INDEFR + next + } + + # Solve for the new x centroid. + skylvl = (sumd - hy * sumg) / p + dy = (sgdgdx - (sddgdx - sdgdx * (hy * sumg + skylvl * p))) / + (hy * sdgdxsq / ysigsq) + if (abs (dy) > yhalf) { + if (sumd == 0.0) + dy = 0.0 + else + dy = sumdx / sumd + if (abs (dy) > yhalf) + dy = 0.0 + } + y[i] = (inline - ymiddle + 1) + dy + + # Compute the roundness. + rounds[i] = 2.0 * (hx - hy) / (hx + hy) + } +end + + +# AP_TEST -- Test the characteristic of the detected images for roundness +# and sharpness. + +int procedure ap_test (cols, x, y, satur, round1, round2, sharps, nobjs, + ncols, nlines, sharplo, sharphi, roundlo, roundhi) + +int cols[ARB] # col IDS of detected images +real x[ARB] # x positions +real y[ARB] # y positions +int satur[ARB] # saturation condition +real round1[ARB] # first roundness parameters +real round2[ARB] # second roundness parameters +real sharps[ARB] # sharpness parameters +int nobjs # number of objects +int ncols, nlines # size of the input image +real sharplo, sharphi # sharpness parameters +real roundlo, roundhi # roundness parameters + +int i, nstars + +begin + # Loop over the detected objects. + nstars = 0 + do i = 1, nobjs { + + # Compute the sharpness statistic + if (! IS_INDEFR(sharps[i]) && (sharps[i] < sharplo || + sharps[i] > sharphi)) + next + if (IS_INDEFR(round1[i]) || round1[i] < roundlo || + round1[i] > roundhi) + next + if (satur[i] == NO) { + if (IS_INDEFR(round2[i]) || round2[i] < roundlo || + round2[i] > roundhi) + next + } + if (IS_INDEFR(x[i]) || x[i] < 0.5 || x[i] > (ncols+0.5)) + next + if (IS_INDEFR(y[i]) || y[i] < 0.5 || y[i] > (nlines+0.5)) + next + + # Add object to the list. + nstars = nstars + 1 + cols[nstars] = cols[i] + x[nstars] = x[i] + y[nstars] = y[i] + sharps[nstars] = sharps[i] + round1[nstars] = round1[i] + round2[nstars] = round2[i] + } + + return (nstars) +end diff --git a/noao/digiphot/apphot/daofind/apimset.x b/noao/digiphot/apphot/daofind/apimset.x new file mode 100644 index 00000000..6f1e8cdc --- /dev/null +++ b/noao/digiphot/apphot/daofind/apimset.x @@ -0,0 +1,17 @@ +include <imset.h> + +# AP_IMSET -- Setup image boundary extension charactersitics. + +procedure ap_imset (im, boundary, npix, constant) + +pointer im # pointer to the image +int boundary # type of boundary condition +int npix # number of pixels of boundary entension +real constant # constant for constant boundary extension + +begin + call imseti (im, IM_TYBNDRY, boundary) + call imseti (im, IM_NBNDRYPIX, npix) + if (boundary == BT_CONSTANT) + call imsetr (im, IM_BNDRYPIXVAL, constant) +end diff --git a/noao/digiphot/apphot/daofind/daofind.key b/noao/digiphot/apphot/daofind/daofind.key new file mode 100644 index 00000000..e68ceb80 --- /dev/null +++ b/noao/digiphot/apphot/daofind/daofind.key @@ -0,0 +1,66 @@ + Interactive Keystroke Commands + +? Print help +: Colon commands +v Verify the critical parameters +w Save the current parameters +d Plot radial profile of star near cursor +i Interactively set parameters using star near cursor +f Find stars in the image +spbar Find stars in the image, output results +q Exit task + + + Colon Commands + +:show [data/center] List the parameters + + Colon Parameter Editing Commands + +# Image and file name parameters + +:image [string] Image name +:output [string] Output file name + +# Data dependent parameters + +:scale [value] Image scale (units per pixel) +:fwhmpsf [value] Full width half maximum of psf (scale units) +:emission [y/n] Emission feature (y), absorption (n) +:sigma [value] Standard deviation of sky (counts) +:datamin [value] Minimum good data value (counts) +:datamax [value] Maximum good data value (counts) + +# Noise description parameters + +:noise [string] Noise model (constant|poisson) +:gain [string] Gain image header keyword +:ccdread [string] Readout noise image header keyword +:epadu [value] Gain (electrons per adu) +:readnoise [value] Readout noise (electrons) + +# Observation parameters + +:exposure [string] Exposure time image header keyword +:airmass [string] Airmass image header keyword +:filter [string] Filter image header keyword +:obstime [string] Time of observation image header keyword +:itime [value] Exposure time (time units) +:xairmass [value] Airmass value (number) +:ifilter [string] Filter id string +:otime [string] Time of observation (time units) + +# Object detection parameters + +:nsigma [value] Size of Gaussian kernel (sigma) +:threshold [value] Detection intensity threshold (counts) +:ratio [value] Sigmay / sigmax of Gaussian kernel +:theta [value] Position angle of Gaussian kernel +:sharplo [value] Lower bound on sharpness +:sharphi [value] Upper bound on sharpness +:roundlo [value] Lower bound on roundness +:roundhi [value] Upper bound on roundness + +# Plotting and marking commands + +:mkdetections [y/n] Mark detections on the image display diff --git a/noao/digiphot/apphot/daofind/idaofind.key b/noao/digiphot/apphot/daofind/idaofind.key new file mode 100644 index 00000000..7da8fe42 --- /dev/null +++ b/noao/digiphot/apphot/daofind/idaofind.key @@ -0,0 +1,8 @@ + Interactive Daofind Setup Menu + + v Mark and verify critical daofind parameters (f,s) + + f Mark and verify the full-width half-maximum of the psf + s Mark and verify the standard deviation of the background + l Mark and verify the minimum good data value + u Mark and verify the maximum good data value diff --git a/noao/digiphot/apphot/daofind/mkpkg b/noao/digiphot/apphot/daofind/mkpkg new file mode 100644 index 00000000..28935c11 --- /dev/null +++ b/noao/digiphot/apphot/daofind/mkpkg @@ -0,0 +1,37 @@ +# DAOFIND task + +$checkout libpkg.a ".." +$update libpkg.a +$checkin libpkg.a ".." +$exit + +libpkg.a: + apbfdfind.x <imhdr.h> <mach.h> \ + <imio.h> "../lib/apphot.h" \ + "../lib/noise.h" "../lib/find.h" + apconvolve.x <imhdr.h> <imset.h> \ + "../lib/find.h" + apegkernel.x <math.h> "../lib/find.h" + apfdcolon.x "../lib/apphot.h" "../lib/noise.h" \ + "../lib/find.h" "../lib/display.h" + apfdconfirm.x + apfdfind.x "../lib/apphot.h" "../lib/display.h" \ + "../lib/find.h" <imhdr.h> + apfdfree.x "../lib/apphotdef.h" + apfdgpars.x "../lib/noise.h" "../lib/display.h" + apfdinit.x "../lib/apphotdef.h" "../lib/finddef.h" + apfdpars.x "../lib/display.h" + apfdradsetup.x + apfdshow.x "../lib/apphot.h" "../lib/noise.h" \ + "../lib/find.h" + apfdstars.x <imhdr.h> <mach.h> \ + "../lib/apphot.h" "../lib/noise.h" \ + "../lib/find.h" "../lib/display.h" + apfind.x <imhdr.h> <mach.h> \ + <gset.h> "../lib/apphot.h" + apimset.x <imset.h> + t_daofind.x <fset.h> <imhdr.h> \ + <gset.h> "../lib/apphot.h" \ + "../lib/noise.h" "../lib/find.h" \ + <imhdr.h> + ; diff --git a/noao/digiphot/apphot/daofind/t_daofind.x b/noao/digiphot/apphot/daofind/t_daofind.x new file mode 100644 index 00000000..eaf77fbf --- /dev/null +++ b/noao/digiphot/apphot/daofind/t_daofind.x @@ -0,0 +1,419 @@ +include <imhdr.h> +include <gset.h> +include <fset.h> +include <imhdr.h> +include "../lib/apphot.h" +include "../lib/noise.h" +include "../lib/find.h" + +# T_DAOFIND -- Automatically detect objects in an image given the full +# width half maximum of the image point spread function and a detection +# threshold. + +procedure t_daofind () + +pointer image # pointer to input image +pointer denimage # pointer to density enhancement image +pointer skyimage # pointer to the sky image +int output # the results file descriptor +int boundary # type of boundary extension +real constant # constant for constant boundary extension +int interactive # interactive mode +int verify # verify mode +int update # update critical parameters +int verbose # verbose mode +int cache # cache the image pixels + +pointer im, cnv, sky, sp, outfname, denname, skyname, str +pointer ap, cname, display, graphics, id, gd +int limlist, lolist, densave, skysave, out, root, stat, imlist, olist +int wcs, req_size, old_size, buf_size, memstat + +real clgetr() +pointer gopen(), immap(), ap_immap() +int imtlen(), clplen(), btoi(), clgwrd(), aptmpimage() +int open(), strncmp(), strlen(), fnldir(), ap_fdfind() +int imtopenp(), clpopnu(), clgfil(), imtgetim(), ap_memstat(), sizeof() +bool clgetb(), streq() + +begin + # Flush STDOUT on a new line. + call fseti (STDOUT, F_FLUSHNL, YES) + + # Allocate working space. + call smark (sp) + call salloc (image, SZ_FNAME, TY_CHAR) + call salloc (output, SZ_FNAME, TY_CHAR) + call salloc (denimage, SZ_FNAME, TY_CHAR) + call salloc (skyimage, SZ_FNAME, TY_CHAR) + call salloc (display, SZ_FNAME, TY_CHAR) + call salloc (graphics, SZ_FNAME, TY_CHAR) + + call salloc (outfname, SZ_FNAME, TY_CHAR) + call salloc (denname, SZ_FNAME, TY_CHAR) + call salloc (skyname, SZ_FNAME, TY_CHAR) + call salloc (cname, SZ_FNAME, TY_CHAR) + call salloc (str, SZ_LINE, TY_CHAR) + + # Fetch the image and output file lists. + imlist = imtopenp ("image") + limlist = imtlen (imlist) + olist = clpopnu ("output") + lolist = clplen (olist) + + # Get prefix for density enhancement and sky images. + call clgstr ("starmap", Memc[denimage], SZ_FNAME) + call clgstr ("skymap", Memc[skyimage], SZ_FNAME) + + # Get the image boundary extensions parameters. + boundary = clgwrd ("boundary", Memc[str], SZ_LINE, + ",constant,nearest,reflect,wrap,") + constant = clgetr ("constant") + + call clgstr ("icommands.p_filename", Memc[cname], SZ_FNAME) + if (Memc[cname] != EOS) + interactive = NO + else + interactive = btoi (clgetb ("interactive")) + verbose = btoi (clgetb ("verbose")) + verify = btoi (clgetb ("verify")) + update = btoi (clgetb ("update")) + cache = btoi (clgetb ("cache")) + + # Get the parameters. + call ap_fdgpars (ap) + + # Confirm the algorithm parameters. + if (verify == YES && interactive == NO) { + call ap_fdconfirm (ap) + if (update == YES) + call ap_fdpars (ap) + } + + # Get the wcs info. + wcs = clgwrd ("wcsout", Memc[str], SZ_LINE, WCSOUTSTR) + if (wcs <= 0) { + call eprintf ( + "Warning: Setting the output coordinate system to logical\n") + wcs = WCS_LOGICAL + } + call apseti (ap, WCSOUT, wcs) + + # Get the graphics and display devices. + call clgstr ("graphics", Memc[graphics], SZ_FNAME) + call clgstr ("display", Memc[display], SZ_FNAME) + + # Open the graphics and display devices. + if (interactive == YES) { + if (Memc[graphics] == EOS) + gd = NULL + else { + iferr { + gd = gopen (Memc[graphics], APPEND+AW_DEFER, STDGRAPH) + } then { + call eprintf ( + "Warning: Error opening the graphics device.\n") + gd = NULL + } + } + if (Memc[display] == EOS) + id = NULL + else if (streq (Memc[graphics], Memc[display])) + id = gd + else { + iferr { + id = gopen (Memc[display], APPEND, STDIMAGE) + } then { + call eprintf ( + "Warning: Graphics overlay not available for display device.\n") + id = NULL + } + } + } else { + gd = NULL + id = NULL + } + + # Loop over the images. + while (imtgetim (imlist, Memc[image], SZ_FNAME) != EOF) { + + # Open the image and get the required keywords from the header. + + im = immap (Memc[image], READ_ONLY, 0) + call apimkeys (ap, im, Memc[image]) + + # Set the image display viewport. + if ((id != NULL) && (id != gd)) + call ap_gswv (id, Memc[image], im, 4) + + # Cache the input image pixels. + req_size = MEMFUDGE * (IM_LEN(im,1) * IM_LEN(im,2) * + sizeof (IM_PIXTYPE(im)) + 2 * IM_LEN(im,1) * IM_LEN(im,2) * + sizeof (TY_REAL)) + memstat = ap_memstat (cache, req_size, old_size) + if (memstat == YES) + call ap_pcache (im, INDEFI, buf_size) + + # Determine the results file name. If output is a null string or + # a directory name then the extension "coo" is added to the + # root image name and the appropriate version number is appended + # in order to construct a default output file name. + + out = NULL + if (lolist == 0) { + call strcpy ("", Memc[outfname], SZ_FNAME) + } else { + stat = clgfil (olist, Memc[output], SZ_FNAME) + root = fnldir (Memc[output], Memc[outfname], SZ_FNAME) + if (strncmp ("default", Memc[output+root], 7) == 0 || root == + strlen (Memc[output])) { + call apoutname (Memc[image], Memc[outfname], "coo", + Memc[outfname], SZ_FNAME) + lolist = limlist + } else if (stat != EOF) { + call strcpy (Memc[output], Memc[outfname], SZ_FNAME) + } else { + call apoutname (Memc[image], Memc[outfname], "coo", + Memc[outfname], SZ_FNAME) + lolist = limlist + } + } + call apsets (ap, OUTNAME, Memc[outfname]) + + # Set up the directory and name for the density enhancement image. + # Note that the default value for denimage is the null string + # indicating the current directory. If denimage is null or + # contains only a directory specification make a temporary image + # name using the prefix "den", otherwise use the user specified + # prefix. + + densave = aptmpimage (Memc[image], Memc[denimage], "den", + Memc[denname], SZ_FNAME) + + # Set up the directory and name for the sky values image. + + skysave = aptmpimage (Memc[image], Memc[skyimage], "sky", + Memc[skyname], SZ_FNAME) + + # Find the stars in an image. + if (interactive == NO) { + + cnv = NULL + if (Memc[cname] != EOS) { + stat = ap_fdfind (Memc[denname], Memc[skyname], ap, im, + NULL, NULL, out, boundary, constant, densave, + skysave, NO, cache) + } else { + cnv = ap_immap (Memc[denname], im, ap, densave) + if (memstat == YES) + call ap_pcache (cnv, INDEFI, buf_size) + if (skysave == YES) { + sky = ap_immap (Memc[skyname], im, ap, skysave) + if (memstat == YES) + call ap_pcache (sky, INDEFI, buf_size) + } else + sky = NULL + if (Memc[outfname] != EOS) + out = open (Memc[outfname], NEW_FILE, TEXT_FILE) + else + out = NULL + call ap_bfdfind (im, cnv, sky, out, ap, boundary, + constant, verbose) + call imunmap (cnv) + if (sky != NULL) + call imunmap (sky) + if (densave == NO) + call imdelete (Memc[denname]) + stat = NO + } + + } else + stat = ap_fdfind (Memc[denname], Memc[skyname], ap, im, gd, + id, out, boundary, constant, densave, skysave, YES, + cache) + + # Clean up files. + call imunmap (im) + call close (out) + + # Uncache memory + call fixmem (old_size) + + if (stat == YES) + break + } + + # Close up the graphics system. + if (id == gd && id != NULL) + call gclose (id) + else { + if (gd != NULL) + call gclose (gd) + if (id != NULL) + call gclose (id) + } + + # Close image and output file lists. + call ap_fdfree (ap) + call imtclose (imlist) + call clpcls (olist) + call sfree (sp) +end + + +# AP_IMMAP -- Map the output image. + +pointer procedure ap_immap (outname, im, ap, save) + +char outname[ARB] # convolved image name +pointer im # pointer to input image +pointer ap # pointer to the apphot structure +int save # save the convolved image + +int newimage +pointer outim +real tmp_scale, tmp_fwhmpsf, tmp_ratio, tmp_theta, tmp_nsigma +real tmp_datamin, tmp_datamax +bool fp_equalr() +int imaccess() +pointer immap() +real apstatr(), imgetr() +errchk imgetr() + +begin + # Check to see if the image already exists. If it does not + # open a new image and write the PSF characteristics into the + # image user area, otherwise fetch the PSF parameters from the image + # header. + + if (save == NO || imaccess (outname, READ_ONLY) == NO) { + + outim = immap (outname, NEW_COPY, im) + IM_PIXTYPE(outim) = TY_REAL + call imaddr (outim, "SCALE", 1.0 / apstatr (ap, SCALE)) + call imaddr (outim, "FWHMPSF", apstatr (ap, FWHMPSF)) + call imaddr (outim, "NSIGMA", apstatr (ap, NSIGMA)) + call imaddr (outim, "RATIO", apstatr (ap, RATIO)) + call imaddr (outim, "THETA", apstatr (ap, THETA)) + call imaddr (outim, "DATAMIN", apstatr (ap, DATAMIN)) + call imaddr (outim, "DATAMAX", apstatr (ap, DATAMIN)) + + } else { + + outim = immap (outname, READ_ONLY, 0) + iferr (tmp_scale = 1.0 / imgetr (outim, "SCALE")) + tmp_scale = INDEFR + iferr (tmp_fwhmpsf = imgetr (outim, "FWHMPSF")) + tmp_fwhmpsf = INDEFR + iferr (tmp_nsigma = imgetr (outim, "NSIGMA")) + tmp_nsigma = INDEFR + iferr (tmp_ratio = imgetr (outim, "RATIO")) + tmp_ratio = INDEFR + iferr (tmp_theta = imgetr (outim, "THETA")) + tmp_theta = INDEFR + iferr (tmp_datamin = imgetr (outim, "DATAMIN")) + tmp_datamin = INDEFR + iferr (tmp_datamax = imgetr (outim, "DATAMAX")) + tmp_datamax = INDEFR + + if (IS_INDEFR(tmp_scale) || ! fp_equalr (tmp_scale, apstatr (ap, + SCALE))) + newimage = YES + else if (IS_INDEFR(tmp_fwhmpsf) || ! fp_equalr (tmp_fwhmpsf, + apstatr (ap, FWHMPSF))) + newimage = YES + else if (IS_INDEFR(tmp_nsigma) || ! fp_equalr (tmp_nsigma, + apstatr (ap, NSIGMA))) + newimage = YES + else if (IS_INDEFR(tmp_ratio) || ! fp_equalr (tmp_ratio, + apstatr (ap, RATIO))) + newimage = YES + else if (IS_INDEFR(tmp_theta) || ! fp_equalr (tmp_theta, + apstatr (ap, THETA))) + newimage = YES + else if (IS_INDEFR(tmp_datamin) || ! fp_equalr (tmp_datamin, + apstatr (ap, DATAMIN))) + newimage = YES + else if (IS_INDEFR(tmp_datamax) || ! fp_equalr (tmp_datamax, + apstatr (ap, DATAMAX))) + newimage = YES + else + newimage = NO + + if (newimage == YES) { + call imunmap (outim) + call imdelete (outname) + outim = immap (outname, NEW_COPY, im) + IM_PIXTYPE(outim) = TY_REAL + call imaddr (outim, "SCALE", 1.0 / apstatr (ap, SCALE)) + call imaddr (outim, "FWHMPSF", apstatr (ap, FWHMPSF)) + call imaddr (outim, "NSIGMA", apstatr (ap, NSIGMA)) + call imaddr (outim, "RATIO", apstatr (ap, RATIO)) + call imaddr (outim, "THETA", apstatr (ap, THETA)) + } + } + + return (outim) +end + + +# AP_OUTMAP -- Manufacture an output coordinate file name. + +procedure ap_outmap (ap, out, root) + +pointer ap # pointer to the apphot structure +int out # the output file descriptor +char root[ARB] # root of the previous output file name, may be + # updated + +int findex, lindex, version +pointer sp, image, outname, newoutname +int strmatch(), gstrmatch(), open(), fnldir(), access() + +begin + if (out != NULL) + call close (out) + + call smark (sp) + call salloc (image, SZ_FNAME, TY_CHAR) + call salloc (outname, SZ_FNAME, TY_CHAR) + call salloc (newoutname, SZ_FNAME, TY_CHAR) + + # Get the old names. + call apstats (ap, IMNAME, Memc[image], SZ_FNAME) + call apstats (ap, OUTNAME, Memc[outname], SZ_FNAME) + + # Manufacture a new name. Search first for existing files with + # the form "outname.coo.*" and create a new version number. + # If the first search fails look for names containing root + # and append a version number to create a new output file + # name. Otherwise simply use the output name. + + if (Memc[outname] == EOS) { + Memc[newoutname] = EOS + } else if (strmatch (Memc[outname], "\.coo\.") > 0) { + findex = fnldir (Memc[outname], Memc[newoutname], SZ_FNAME) + call apoutname (Memc[image], Memc[newoutname], "coo", + Memc[newoutname], SZ_FNAME) + } else if (gstrmatch (Memc[outname], root, findex, lindex) > 0) { + repeat { + version = version + 1 + call strcpy (Memc[outname], Memc[newoutname], SZ_FNAME) + call sprintf (Memc[newoutname+lindex], SZ_FNAME, ".%d") + call pargi (version) + } until (access (Memc[newoutname], 0, 0) == NO) + } else { + version = 1 + call strcpy (Memc[outname], root, SZ_FNAME) + call strcpy (Memc[outname], Memc[newoutname], SZ_FNAME) + } + + # Open the output image. + if (Memc[newoutname] == EOS) + out = NULL + else + out = open (Memc[newoutname], NEW_FILE, TEXT_FILE) + call apsets (ap, OUTNAME, Memc[newoutname]) + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/datapars.par b/noao/digiphot/apphot/datapars.par new file mode 100644 index 00000000..15778b9f --- /dev/null +++ b/noao/digiphot/apphot/datapars.par @@ -0,0 +1,25 @@ +# DATAPARS + +scale,r,h,1.0,0.0,,Image scale in units per pixel +fwhmpsf,r,h,2.5,0.0,,FWHM of the PSF in scale units +emission,b,h,y,,,Features are positive ? +sigma,r,h,INDEF,,,Standard deviation of background in counts +datamin,r,h,INDEF,,,Minimum good data value +datamax,r,h,INDEF,,,Maximum good data value + +noise,s,h,"poisson","|constant|poisson|",,Noise model +ccdread,s,h,"",,,CCD readout noise image header keyword +gain,s,h,"",,,CCD gain image header keyword +readnoise,r,h,0.0,,,CCD readout noise in electrons +epadu,r,h,1.0,,,Gain in electrons per count + +exposure,s,h,"",,,Exposure time image header keyword +airmass,s,h,"",,,Airmass image header keyword +filter,s,h,"",,,Filter image header keyword +obstime,s,h,"",,,Time of observation image header keyword +itime,r,h,1.0,,,Exposure time +xairmass,r,h,INDEF,,,Airmass +ifilter,s,h,"INDEF",,,Filter +otime,s,h,"INDEF",,,Time of observation + +mode,s,h,'ql' diff --git a/noao/digiphot/apphot/doc/apsums.apps b/noao/digiphot/apphot/doc/apsums.apps new file mode 100644 index 00000000..ea5843bf --- /dev/null +++ b/noao/digiphot/apphot/doc/apsums.apps @@ -0,0 +1,19 @@ +The apphot and daophot package aperture photometry tasks have been modified +to compute the aperture sums and areas in double precision instead of real +precision. This change minimizes machine precision errors that can become +significant for large apertures and very low noise or synthetic data. + +These tasks have also been modified to output negative values of the total +flux should they occur. Formerly these values were being artificially set to +0.0. This change makes it easier to see the effects of any sky value and machine +errors. + +The modified apertures photometry tasks are available as part of the +external addon package digiphotx. To retrieve and install digiphotx, ftp +to 140.252.1.1, login as anonymous, cd to iraf/extern, retrieve the file +digiphotx.readme, and follow the installation instructions. + + + + Lindsey Davis + davis@noao.edu diff --git a/noao/digiphot/apphot/doc/apsums.noao b/noao/digiphot/apphot/doc/apsums.noao new file mode 100644 index 00000000..fd920b49 --- /dev/null +++ b/noao/digiphot/apphot/doc/apsums.noao @@ -0,0 +1,17 @@ +The apphot and daophot package aperture photometry tasks have been modified +to compute the aperture sums and areas in double precision instead of real +precision. This change minimizes machine precision errors that can become +significant for large apertures and very low noise or synthetic data. + +These tasks have also been modified to output negative values of the total +flux should they occur. Formerly these values were being artificially set to +0.0. This change makes it easier to see the effects of any sky value and machine +errors. + +The modified apertures photometry tasks are available under irafx. Let me +know if you have any questions about the modified tasks or encounter and +problems using them. + + + Lindsey Davis + davis@noao.edu diff --git a/noao/digiphot/apphot/doc/aptest.hlp b/noao/digiphot/apphot/doc/aptest.hlp new file mode 100644 index 00000000..85fad0d9 --- /dev/null +++ b/noao/digiphot/apphot/doc/aptest.hlp @@ -0,0 +1,68 @@ +.help aptest Dec92 noao.digiphot.apphot +.ih +NAME +aptest -- run basic tests on the apphot package tasks +.ih +USAGE +aptest imname +.ih +PARAMETERS +.ls imname +The name of the output test image. The actual test image is stored in fits +format in the APPHOT package subdirectory test. If the image already exists +APTEST will exit with a warning message. +.le +.ls aplogfile = "" +The name of the output log file. By default all the text output is logged +in a file called \fI"imname.log"\fR. If the log file already exists APTEST will +exit with a warning message. +.le +.ls applotfile = "" +The name of the output log file. By default all the plot output is logged in +a file called \fI"imname.plot"\fR. If the plot file already exists APTEST will +exit with a warning message. +.le +.ih +DESCRIPTION +APTEST is a simple script which exercises each of the tasks in the APPHOT +package in turn. At startup APTEST reads a small fits image stored in the +APPHOT test subdirectory and creates the image \fIimname\fR in the user's +working directory. APTEST initializes the APPHOT package by returning +all the parameters to their default state, runs each of the APPHOT +tasks in non-interactive mode, spools the text output to the file +\fIaplogfile\fR, and spools the plot output from the RADPROF task to the plot +metacode file \fIapplotfile\fR. +.ih +EXAMPLES + +1. Check to see that all the APPHOT tasks are functioning correctly. + +.nf + ap> apphot + + ... load the apphot package + + ap> aptest testim + + ... run the test script + + ap> lprint testim.log + + ... print the text output + + ap> gkidir testim.plot + + ... list the contents of the plot file + + ap> gkiextract testim.plot 1-N | stdplot + + ... send the plots to the plotter +.fi + +.ih +TIME REQUIREMENTS +.ih +BUGS +.ih +SEE ALSO +.endhelp diff --git a/noao/digiphot/apphot/doc/center.hlp b/noao/digiphot/apphot/doc/center.hlp new file mode 100644 index 00000000..c409c49b --- /dev/null +++ b/noao/digiphot/apphot/doc/center.hlp @@ -0,0 +1,638 @@ +.help center May00 noao.digiphot.apphot +.ih +NAME +center -- compute accurate centers for a list of objects +.ih +USAGE +center image +.ih +PARAMETERS +.ls image +The list of images containing the objects to be centered. +.le +.ls coords = "" +The list of text files containing initial coordinates for the objects to +be centered. Objects are listed in coords one object per line with the +initial coordinate values in columns one and two. The number of coordinate +files must be zero, one, or equal to the number of images. +If coords is "default", "dir$default", or a directory specification then an +coords file name of the form dir$root.extension.version is constructed and +searched for, where dir is the directory, root is the root image name, +extension is "coo" and version is the next available version number for the +file. +.le +.ls output = "default" +The name of the results file or results directory. If output is +"default", "dir$default", or a directory specification then an output file name +of the form dir$root.extension.version is constructed, where dir is the +directory, root is the root image name, extension is "ctr" and version is +the next available version number for the file. The number of output files +must be zero, one, or equal to the number of image files. In both interactive +and batch mode full output is written to output. In interactive mode +an output summary is also written to the standard output. +.le +.ls plotfile = "" +The name of the file containing radial profile plots of the stars written +to the output file. If plotfile is defined then a radial profile plot +is written to plotfile every time a record is written to \fIoutput\fR. +The user should be aware that this can be a time consuming operation. +.le +.ls datapars = "" +The name of the file containing the data dependent parameters. +The critical parameters \fIfwhmpsf\fR and \fIsigma\fR are located in +datapars. If datapars is undefined then the default parameter set in +uparm directory is used. +.le +.ls centerpars = "" +The name of the file containing the centering algorithm parameters. +The critical parameters \fIcalgorithm\fR and \fIcbox\fR are located in +centerpars. If centerpars is undefined then the default parameter +set in uparm is used. +.le +.ls interactive = yes +Interactive or non-interactive mode? +.le +.ls radplots = no +If \fIradplots\fR is "yes" and CENTER is run in interactive mode, a radial +profile of each star is plotted on the screen after the center is fit. +.le +.ls icommands = "" +The image display cursor or image cursor command file. +.le +.ls gcommands = "" +The graphics cursor or graphics cursor command file. +.le +.ls wcsin = ")_.wcsin", wcsout = ")_.wcsout" +The coordinate system of the input coordinates read from \fIcoords\fR and +of the output coordinates written to \fIoutput\fR respectively. The image +header coordinate system is used to transform from the input coordinate +system to the "logical" pixel coordinate system used internally, +and from the internal "logical" pixel coordinate system to the output +coordinate system. The input coordinate system options are "logical", tv", +"physical", and "world". The output coordinate system options are "logical", +"tv", and "physical". The image cursor coordinate system is assumed to +be the "tv" system. +.ls logical +Logical coordinates are pixel coordinates relative to the current image. +The logical coordinate system is the coordinate system used by the image +input/output routines to access the image data on disk. In the logical +coordinate system the coordinates of the first pixel of a 2D image, e.g. +dev$ypix and a 2D image section, e.g. dev$ypix[200:300,200:300] are +always (1,1). +.le +.ls tv +Tv coordinates are the pixel coordinates used by the display servers. Tv +coordinates include the effects of any input image section, but do not +include the effects of previous linear transformations. If the input +image name does not include an image section, then tv coordinates are +identical to logical coordinates. If the input image name does include a +section, and the input image has not been linearly transformed or copied from +a parent image, tv coordinates are identical to physical coordinates. +In the tv coordinate system the coordinates of the first pixel of a +2D image, e.g. dev$ypix and a 2D image section, e.g. dev$ypix[200:300,200:300] +are (1,1) and (200,200) respectively. +.le +.ls physical +Physical coordinates are pixel coordinates invariant with respect to linear +transformations of the physical image data. For example, if the current image +was created by extracting a section of another image, the physical +coordinates of an object in the current image will be equal to the physical +coordinates of the same object in the parent image, although the logical +coordinates will be different. In the physical coordinate system the +coordinates of the first pixel of a 2D image, e.g. dev$ypix and a 2D +image section, e.g. dev$ypix[200:300,200:300] are (1,1) and (200,200) +respectively. +.le +.ls world +World coordinates are image coordinates in any units which are invariant +with respect to linear transformations of the physical image data. For +example, the ra and dec of an object will always be the same no matter +how the image is linearly transformed. The units of input world coordinates +must be the same as those expected by the image header wcs, e. g. +degrees and degrees for celestial coordinate systems. +.le +The wcsin and wcsout parameters default to the values of the package +parameters of the same name. The default values of the package parameters +wcsin and wcsout are "logical" and "logical" respectively. +.le +.ls cache = ")_.cache" +Cache the image pixels in memory. Cache may be set to the value of the apphot +package parameter (the default), "yes", or "no". By default cacheing is +disabled. +.le +.ls verify = ")_.verify" +Verify the critical parameters in non-interactive mode ? Verify may be set to +the apphot package parameter value (the default), "yes", or "no. +.le +.ls update = ")_.update" +Update the critical parameters in non-interactive mode if \fIverify\fR is +set to yes? Update may be set to the apphot package parameter value (the +default), "yes", or "no. +.le +.ls verbose = ")_.verbose" +Print messages on the terminal in non-interactive mode ? Verbose may be set +to the apphot package parameter value (the default), "yes", or "no. +.le +.ls graphics = ")_.graphics" +The default graphics device. +Graphics may be set to the apphot package parameter value (the default), "yes", +or "no. +.le +.ls display = ")_.display" +The default display device. Display may be set to the apphot package +parameter value (the default), "yes", or "no. By default graphics overlay +is disabled. Setting display to one of "imdr", "imdg", "imdb", or "imdy" +enables graphics overlay with the IMD graphics kernel. Setting display to +"stdgraph" enables CENTER to work interactively from a contour plot. +.le + +.ih +DESCRIPTION +CENTER computes accurate centers for a set of objects in the IRAF image +\fIimage\fR, whose initial coordinates are read from the image display cursor, +from the text file \fIcoords\fR, or from a cursor command file. +The computed x and y coordinates, the errors, and the fitting parameters +are written to the text file \fIoutput\fR. + +The coordinates read from \fIcoords\fR are assumed to be in coordinate +system defined by \fIwcsin\fR. The options are "logical", "tv", "physical", +and "world" and the transformation from the input coordinate system to +the internal "logical" system is defined by the image coordinate system. +The simplest default is the "logical" pixel system. Users working on with +image sections but importing pixel coordinate lists generated from the parent +image must use the "tv" or "physical" input coordinate systems. +Users importing coordinate lists in world coordinates, e.g. ra and dec, +must use the "world" coordinate system and may need to convert their +equatorial coordinate units from hours and degrees to degrees and degrees first. + +The coordinates written to \fIoutput\fR are in the coordinate +system defined by \fIwcsout\fR. The options are "logical", "tv", +and "physical". The simplest default is the "logical" system. Users +wishing to correlate the output coordinates of objects measured in +image sections or mosaic pieces with coordinates in the parent +image must use the "tv" or "physical" coordinate systems. + +If \fIcache\fR is yes and the host machine physical memory and working set size +are large enough, the input image pixels are cached in memory. If cacheing +is enabled and CENTER is run interactively the first measurement will appear +to take a long time as the entire image must be read in before the measurement +is actually made. All subsequent measurements will be very fast because CENTER +is accessing memory not disk. The point of cacheing is to speed up random +image access by making the internal image i/o buffers the same size as the +image itself. However if the input object lists are sorted in row order and +sparse cacheing may actually worsen not improve the execution time. Also at +present there is no point in enabling cacheing for images that are less than +or equal to 524288 bytes, i.e. the size of the test image dev$ypix, as the +default image i/o buffer is exactly that size. However if the size of dev$ypix +is doubled by converting it to a real image with the chpixtype task then the +effect of cacheing in interactive is can be quite noticeable if measurements +of objects in the top and bottom halves of the image are alternated. + +CENTER can be run either interactively or in batch mode by setting the +parameter \fIinteractive\fR. In interactive mode starting x and y positions +can either be read directly from the image cursor or read from the text +file \fIcoords\fR. In interactive mode the user can examine, adjust, and +save the algorithm parameters, change ojects interactively, query for +the next or nth object in the list, or fit the entire coordinate list with +the chosen parameter set. In batch mode the positions can be read from the +text file \fIcoords\fR or the image cursor can be redirected to a text file +containing a list of cursor commands as specified by the parameter +\fIicommands\fR. + +.ih +CURSOR COMMANDS + +The following cursor commands are currently available. + +.nf + Interactive Keystroke Commands + +? Print help +: Colon commands +v Verify the critical parameters +w Save the current parameters +d Plot radial profile of current star +i Interactively set parameters using current star +f Fit center of current star +spbar Fit center of current star, output results +m Move to next star in coordinate list +n Center next star in coordinate list, output results +l Center remaining stars in coordinate list, output results +e Print error messages +r Rewind the coordinate list +q Exit task + + + Colon Commands + +:show [data/center] List the parameters +:m [n] Move to next [nth] star in coordinate list +:n [n] Center next [nth] star in coordinate list, + output results + + + Colon Parameter Editing Commands + +# Image and file name parameters + +:image [string] Image name +:coords [string] Coordinate file name +:output [string] Output file name + +# Data dependent parameters + +:scale [value] Image scale (units per pixel) +:fwhmpsf [value] Full-width half-maximum of PSF (scale units) +:emission [y/n] Emission feature (y), absorption (n) +:sigma [value] Standard deviation of sky (counts) +:datamin [value] Minimum good data value (counts) +:datamax [value] Maximum good data value (counts) + +# Noise parameters + +:noise [string] Noise model (constant|poisson) +:gain [string] Gain image header keyword +:ccdread [string] Readout noise image header keyword +:epadu [value] Gain (electrons per adu) +:readnoise [value] Readout noise (electrons) + +# Observations parameters + +:exposure [string] Exposure time image header keyword +:airmass [string] Airmass image header keyword +:filter [string] Filter image header keyword +:obstime [string] Time of observation image header keyword +:itime [value] Exposure time (time units) +:xairmass [value] Airmass value (number) +:ifilter [string] Filter id string +:otime [string] Time of observation (time units) + +# Centering parameters + +:calgorithm [string] Centering algorithm +:cbox [value] Width of centering box (scale units) +:cthreshold [value] Centering intensity threshold (sigma) +:cmaxiter [value] Maximum number of iterations +:maxshift [value] Maximum center shift (scale units) +:minsnratio [value] Minimum signal to noise for centering +:clean [y/n] Clean subraster before centering +:rclean [value] Cleaning radius (scale units) +:rclip [value] Clipping radius (scale units) +:kclean [value] Clean K-sigma rejection limit (sigma) + +# Plotting and marking parameters + +:mkcenter [y/n] Mark computed centers on the display +:radplot [y/n] Plot radial profile of object + + +The following keystroke commands are available from the interactive setup +menu. + + Interactive Center Setup Menu + + v Mark and verify the critical center parameters (f,s,c) + + f Mark and verify the full-width half-maximum of the psf + s Mark and verify the standard deviation of the background + l Mark and verify the minimum good data value + u Mark and verify the maximum good data value + + c Mark and verify the centering box half-width + n Mark and verify the cleaning radius + p Mark and verify the clipping radius +.fi + +.ih +ALGORITHMS + +Descriptions of the data dependent parameters and the centering +algorithm parameters can be found in the online manual pages for +\fIdatapars\fR and \fIcenterpars\fR. + +.ih +OUTPUT + +In interactive mode the following quantities are written to the terminal +as each object is measured. Error is a simple string which indicates +whether an error condition has been flagged. The centers and their errors are +in pixel units. + +.nf + image xinit yinit xcenter ycenter xerr yerr error +.fi + +In both interactive and batch mode the full output is written to the +text file \fIoutput\fR. At the beginning of each file is a header +listing the current values of the parameters when the first stellar +record was written. These parameters can be subsequently altered. +For each star measured the following record is written + +.nf + image xinit yinit id coords lid + xcenter ycenter xshift yshift xerr yerr cier error +.fi + +Image and coords are the name of the image and coordinate file respectively. +Id and lid are the sequence numbers of stars in the output and coordinate +files respectively. Cier and error are the centering error code and accompanying +error message respectively. Xinit, yinit, xcenter, ycenter, xshift, yshift, +and xerr, yerr are self explanatory and output in pixel units. The sense of +the xshift and yshift definitions is the following. + +.nf + xshift = xcenter - xinit + yshift = ycenter - yinit +.fi + +In interactive mode a radial profile of each measured object is plotted +in the graphics window if \fIradplots\fR is "yes". + +In interactive and batchmode a radial profile plot is written to +\fIplotfile\fR if it is defined each time the result of an object +measurement is written to \fIoutput\fR . + +.ih +ERRORS + +If the object centering was error free then the field cier will be zero. +Non-zero values in the cier column flag the following error conditions. + +.nf + 0 # No error + 101 # The centering box is off the image + 102 # The centering box is partially off the image + 103 # The S/N ratio is low in the centering box + 104 # There are two few points for a good fit + 105 # The x or y center fit is singular + 106 # The x or y center fit did not converge + 107 # The x or y center shift is greater than maxshift + 108 # There is bad data in the centering box +.fi + +.ih +EXAMPLES + +1. Compute the centers for a few stars in dev$ypix using the image display +and the image cursor. Setup the task parameters using the interactive +setup menu defined by the i keystroke command and a radial profile plot. + +.nf + ap> display dev$ypix 1 fi+ + + ... display the image + + ap> center dev$ypix + + ... type ? to see help screen + + ... move image cursor to a star + ... type i to enter the interactive setup menu + ... enter the maximum radius in pixels for the radial profile or + accept the default with a CR + ... type v to get the default menu + ... set the fwhmpsf, sigma, and centering box half-width using the + graphics cursor and the stellar radial profile plot + ... typing <CR> after a prompt leaves the parameter at its default + value + ... type q to exit setup menu + + ... type the v key to verify the critical parameters + + ... type the w key to save the parameters in the parameter files + + ... move the image cursor to the stars of interest and tap + the space bar + + ... type q to quit followed by q to confirm the quit + + ... the output will appear in ypix.ctr.1 + +.fi + +2. Compute the centers for a few stars in dev$ypix using the contour plot +and the graphics cursor. This option is only useful for those (now very few) +users who have access to a graphics terminal but not to an image display +server. Setup the task parameters using the interactive setup menu defined by +the i key command as in example 1. + +.nf + ap> show stdimcur + + ... record the default value of stdimcur + + ap> set stdimcur = stdgraph + + ... define the image cursor to be the graphics cursor + + ap> contour dev$ypix + + ... make a contour plot of dev$ypix + + ap> contour dev$ypix >G ypix.plot1 + + ... store the contour plot of ypix in the file ypix.plot + + ap> center dev$ypix display=stdgraph + + ... type ? to see the help screen + + ... move graphics cursor to a star + ... type i to enter the interactive setup menu + ... enter the maximum radius in pixels for the radial profile or + accept the default with a CR + ... type v key to get the default setup menu + ... enter maximum radius in pixels of the radial profile + ... set the fwhmpsf, sigma, and centering box half-width + using the graphics cursor and the stellar radial profile plot + ... typing <CR> after the prompt leaves the parameter at its + default value + ... type q to quit the setup menu + + ... type the v key to verify critical parameters + + ... type the w key to save the parameters in the parameter files + + ... retype :.read ypix.plot1 to reload the contour plot + + ... move the graphics cursor to the stars of interest and tap + the space bar + + ... a one line summary of the answers will appear on the standard + output for each star measured + + ... type q to quit followed by q to confirm the quit + + ... full output will appear in the text file ypix.ctr.2 + + ap> set stdimcur = <default> + + ... reset stdimcur to its previous value +.fi + + +3. Setup and run CENTER interactively on a list of objects temporarily +overriding the fwhmpsf, sigma, and cbox parameters determined in examples +1 or 2. + +.nf + ap> daofind dev$ypix fwhmpsf=2.6 sigma=25.0 verify- + + ... make a coordinate list + + ... the output will appear in the text file ypix.coo.1 + + ap> center dev$ypix cbox=7.0 coords=ypix.coo.1 + + ... type ? for optional help + + + ... move the graphics cursor to the stars and tap space bar + + or + + ... select stars from the input coordinate list with m / :m # + and measure with spbar + + ... measure stars selected from the input coordinate list + with n / n # + + ... a one line summary of results will appear on the standard output + for each star measured + + ... the output will appear in ypix.ctr.3 ... +.fi + + +4. Display and measure some stars in an image section and write the output +coordinates in the coordinate system of the parent image. + +.nf + ap> display dev$ypix[150:450,150:450] 1 + + ... display the image section + + ap> center dev$ypix[150:450,150:450] wcsout=tv + + ... move cursor to stars and type spbar + + ... type q to quit and q again to confirm quit + + ... output will appear in ypix.ctr.4 + + ap> pdump ypix.ctr.4 xc,yc yes | tvmark 1 STDIN col=204 +.fi + + +5. Run CENTER in batch mode using the coordinate file and the previously +saved parameters. Verify the critical parameters. + +.nf + ap> center dev$ypix coords=ypix.coo.1 verify+ inter- + + ... output will appear in ypix.ctr.5 ... +.fi + + +6. Repeat example 5 but assume that the input coordinate are ra and dec +in degrees and degrees, turn off verification, and submit the task to to +the background. + +.nf + ap> display dev$ypix + + ap> rimcursor wcs=world > radec.coo + + ... move to selected stars and type any key + + ... type ^Z to quit + + ap> center dev$ypix coords=radec.coo wcsin=world verify- inter- & + + ... output will appear in ypix.ctr.6 + + ap> pdump ypix.ctr.6 xc,yc yes | tvmark 1 STDIN col=204 + + ... mark the stars on the display + + +7. Run CENTER interactively without using the image display. + +.nf + ap> show stdimcur + + ... record the default value of stdimcur + + ap> set stdimcur = text + + ... set the image cursor to the standard input + + ap> center dev$ypix coords=ypix.coo.1 + + ... type ? for optional help + + ... type :m 3 to set the initial coordinates to those of the + third star in the list + + ... type i to enter the interactive setup menu + ... enter the maximum radius in pixels for the radial profile or + accept the default with a CR + ... type v to enter the default menu + ... set the fwhmpsf, sigma, and centering box half-width + using the graphics cursor and the stellar radial profile plot + ... typing <CR> after the prompt leaves the parameter at its default + value + + ... type r to rewind the coordinate list + + ... type l to measure all the stars in the coordinate list + + ... a one line summary of the answers will appear on the standard + output for each star measured + + ... type q to quit followed by q to confirm the quit + + ... full output will appear in the text file ypix.ctr.7 + + ap> set stdimcur = <default> + + ... reset the value of stdimcur +.fi + +8. Use a image cursor command file to drive the CENTER task. The cursor command +file shown below sets the fwhmpsf, calgorithm, and cbox parameters, computes +the centers for 3 stars, updates the parameter files, and quits the task. + +.nf + ap> type cmdfile + : calgorithm gauss + : fwhmpsf 2.5 + : cbox 9.0 + 442 410 101 \040 + 349 188 101 \040 + 225 131 101 \040 + w + q + + ap> center dev$ypix icommands=cmdfile verify- + + ... full output will appear in ypix.ctr.8 +.fi + +.ih +BUGS + +It is the responsibility of the user to make sure that the image displayed +in the image display is the same as the image specified by the image parameter. + +Commands which draw to the image display are disabled by default. +To enable graphics overlay on the image display, set the display +parameter to "imdr", "imdg", "imdb", or "imdy" to get red, green, +blue or yellow overlays and set the centerpars mkcenter switch to +"yes". It may be necessary to run gflush and to redisplay the image +to get the overlays position correctly. + +.ih +SEE ALSO +datapars, centerpars +.endhelp diff --git a/noao/digiphot/apphot/doc/centerpars.hlp b/noao/digiphot/apphot/doc/centerpars.hlp new file mode 100644 index 00000000..008869f4 --- /dev/null +++ b/noao/digiphot/apphot/doc/centerpars.hlp @@ -0,0 +1,206 @@ +.help centerpars May00 noao.digiphot.apphot +.ih +NAME +centerpars -- edit the centering algorithm parameters +.ih +USAGE +centerpars +.ih +PARAMETERS +.ls calgorithm = "centroid" +The centering algorithm. The "gauss" and "ofilter" options depend critically +on the value of the fwhmpsf parameter in the DATAPARS task. The centering +options are: +.ls none +The initial positions are assumed to be the true centers. Users +may select this option if the initial centers are know to be accurate, +e.g. they were computed by DAOFIND task. +.le +.ls centroid +The object centers are determined by computing the intensity weighted means +of the marginal profiles in x and y. This is the recommended default algorithm +for APPHOT users. +.le +.ls gauss +The object centers are computed by fitting a Gaussian of fixed fwhmpsf, +specified by the DATAPARS fwhmpsf parameter, to the marginal profiles in +x and y using non-linear least squares techniques. +.le +.ls ofilter +The object centers are computed using optimal filtering techniques, +a triangular weighting function of half width equal to fwhmpsf as +specified by the DATAPARS fwhmpsf parameter, and the marginal distributions +in x and y. +.le +.le +.ls cbox = 5.0 (scale units) +The width of the subraster used for object centering in units of the +DATAPARS scale parameter. Cbox must be big enough to include a reasonable +number of pixels for center determination but not so large so as to include +a lot of noise. Recommended initial values are 2.5-4.0 * the FWHM of the PSF +value. +.le +.ls cthreshold = 0.0 (sigma units) +Pixels cthreshold * sigma above (emission features) or below (absorption +features) the data minimum or maximum respectively are used by the centering +algorithms where sigma is equal to the value of the DATAPARS sigma parameter. +Most APPHOT users should leave this value at 0.0 which invokes the appropriate +default thresholding technique for each centering algorithm. Setting cthreshold +to INDEF turns off thresholding altogether for all the centering algorithms. +.le +.ls minsnratio = 1.0 +The minimum signal to noise ratio for object centering. If the estimated signal +to noise ratio is less than minsnratio the computed center will be returned +with an error flag. +.le +.ls cmaxiter = 10 +The maximum number of iterations performed by the centering algorithm. +All the centering algorithms use this parameter. +.le +.ls maxshift = 1.0 (scale units) +The maximum permissible shift of the center with respect to the initial +coordinates in units of the scale parameter. If the shift produced by the +centering algorithms is larger than maxshift, the computed center is returned +with an error flag. +.le +.ls clean = no +Symmetry-clean the centering subrater before centering? APPHOT users should +leave clean set to "no". +.le +.ls rclean = 1.0 (scale units) +The cleaning radius for the symmetry-clean algorithm in units of the scale +parameter. +.le +.ls rclip = 2.0 (scale units) +The clipping radius for the symmetry-clean algorithm in units of the scale +parameter. +.le +.ls kclean = 3.0 (sigma) +The number of sky background standard deviations for the symmetry-clean +algorithm where sigma is the value of the DATAPARS parameter sigma. +.le +.ls mkcenter = no +Mark the fitted object centers on the displayed image ? +.le +.ih +DESCRIPTION + +The centering algorithm parameters control the action of the centering +algorithms. The default parameters values have been proven to produce +reasonable results in the majority of cases. Several of the centering +parameters are defined in terms of the DATAPARS parameter \fIscale\fR, +the scale of the image, and \fIsigma\fR the standard deviation of +the sky pixels. + +For each object to be measured a subraster of data \fIcbox\fR / \fIscale\fR +pixels wide around the initial position supplied by the user is extracted +from the IRAF image. If scale is defined in units of the number +the half-width half-maximum of the psf per pixel, then a single value of +cbox can be used for centering objects in images with different psfs. + +If \fIclean\fR is "yes" the symmetry-clean algorithm is applied to the +centering subraster prior to centering. The cleaning algorithm attempts +to correct defects in the centering subraster by assuming that the image +is radially symmetric and comparing pixels on opposite sides of the center +of symmetry. The center of symmetry is assumed to be the maximum pixel +in the subraster, unless the maximum pixel is more than \fImaxshift / +scale\fR from the initial center, in which case the initial center is used +as the center of symmetry. Pixels inside the cleaning radius are not edited. +Pairs of pixels in the cleaning region, r > \fIrclean\fR / \fIscale\fR +and r <= \fIrclip\fR / \fIscale\fR and diametrically opposed about the +center of symmetry are tested for equality. If the difference between the +pixels is greater than \fIkclean * sigma\fR, the larger value is replaced +by the smaller. In the cleaning region the sigma is determined by the +noise model assumed for the data. Pairs of pixels in the clipping region, +r > \fIrclip\fR / \fIscale\fR are tested in the same manner as those in +the cleaning region. However the sigma employed is the sigma of the +sky background. Most APPHOT users should leave clean set to "no". + +New centers are computed using the centering algorithm specified by +\fIcalgorithm\fR, the data specified by \fIcbox / scale\fR, and pixels +that are some threshold above (below) an estimate of the local minimum +(maximum). \fICthreshold\fR values of 0.0, a positive number, and INDEF +invoke the default thresholding algorithm, a threshold equal to the +local minimum (maximum) plus (minus) \fIdatapars.sigma * cthreshold\fR, +and a threshold exactly equal to the local minimum (maximum) respectively. + +After thresholding the signal to noise ratio of the subraster is estimated. +If the SNR < \fIminsnratio\fR the new center is still computed but an error +flag is set. + +The default centering algorithm is \fIcentroid\fR. Centroid computes the +intensity weighted mean and mean error of the centering box x and y marginal +distributions using points in the marginal arrays above (below) the minimum +(maximum) data pixel plus (minus) a threshold value. + +The threshold value is either the mean, \fIdatapars.sigma * cthreshold\fR +above (below) the local minimum (maximum) if \fIcthreshold\fR is greater +than zero, or zero above (below) the local minimum (maximum) if +\fIcthreshold\fR is INDEF. The centroid algorithm is similar to that +by the old KPNO Mountain Photometry Code. Note that centroid is the only +centering algorithm which does not depend on the value of +\fIdatapars.fwhmpsf\fR. + +The centering algorithm \fIgauss\fR computes the new centers by fitting a +1D Gaussian function to the marginal distributions in x and y using a +fixed fwhmpsf set by \fIdatapars.fwhmpsf\fR. Initial guesses for the fit +parameters are derived from the data. The gauss algorithm iterates until +a best fit solution is achieved. + +The final centering algorithm choice \fIofilter\fR employs a variation of the +optimal filtering technique in which the profile is simulated by a triangle +function of width \fIdatapars.fwhmpsf\fR. + +The default thresholding algorithm for all centering algorithms other +than "centroid" is no thresholding. + +If the computed shift in either coordinate > \fImaxshift\fR / \fIscale\fR, +the new center is returned but an error flag is set. + +.ih +EXAMPLES +1. List the centering parameters. + +.nf + ap> lpar centerpars +.fi + +2. Edit the centering parameters + +.nf + ap> centerpars +.fi + +3. Edit the CENTERPARS parameters from with the PHOT task. + +.nf + da> epar phot + + ... edit a few phot parameters + + ... move to the centerpars parameter and type :e + + ... edit the centerpars parameters and type :wq + + ... finish editing the phot parameters and type :wq +.fi + +4. Save the current CENTERPARS parameter set in a text file ctrnite1.par. +This can also be done from inside a higher level task as in the +previous example. + +.nf + da> centerpars + + ... edit the parameters + + ... type ":w ctrnite1.par" from within epar +.fi + +.ih +BUGS + +.ih +SEE ALSO +center,phot,wphot,polyphot,radprof +.endhelp diff --git a/noao/digiphot/apphot/doc/daofind.hlp b/noao/digiphot/apphot/doc/daofind.hlp new file mode 100644 index 00000000..ad9687e5 --- /dev/null +++ b/noao/digiphot/apphot/doc/daofind.hlp @@ -0,0 +1,579 @@ +.help daofind May00 noao.digiphot.apphot +.ih +NAME +daofind -- automatically detect objects in an image +.ih +USAGE +daofind image +.ih +PARAMETERS +.ls image +The list of images in which objects are to be detected. +.le +.ls output = "default" +The name of the results file or the results directory. If output is +"default", "dir$default" or a directory specification then a results file +name of the form dir$root.extension.version is constructed, where +dir is the directory, root is the root image name, extension is "coo" +and version is the next available version number for the file. If the +output string is undefined then no output file is created. One output +file is created for every input image. +.le +.ls starmap = "" +The name of the image prefix and/or directory where the density enhancement +image will be stored. If starmap is undefined or a directory, +DAOFIND will create a temporary image which is deleted on exit from +the program. Otherwise starmap is prefixed to the image name +and the density enhancement image will be saved for use in a subsequent +run of DAOFIND. +.le +.ls skymap = "" +The name of the image prefix and/or directory where the mean density +image will be stored. If skymap is undefined or a directory, no mean density +image is created. Otherwise skymap is prefixed to the image name +and the mean density image will be saved on disk. Skymap is not used by +the DAOFIND algorithms, but may be used by the user as a check on DAOFIND, +since the sum of starmap and skymap is a type of best fit to the original +image. +.le +.ls datapars = "" +The name of the file containing the data dependent parameters. The critical +parameters \fIfwhmpsf\fR and \fIsigma\fR are located here. If \fIdatapars\fR +is undefined then the default parameter set in the user's uparm directory is +used. +.le +.ls findpars = "" +The name of the file containing the object detection parameters. The +parameter \fIthreshold\fR is located here. If findpars is undefined then +the default parameter set in the user's uparm directory is used. +.le +.ls boundary = "nearest" +The type of boundary extension. The choices are: +.ls nearest +Use the value of the nearest boundary pixel. +.le +.ls constant +Use a constant value. +.le +.ls reflect +Generate a value by reflecting around the boundary. +.le +.ls wrap +Generate a value by wrapping around to the other side of the image. +.le +.le +.ls constant = 0 +The constant for constant boundary extension. +.le +.ls interactive = no +Interactive or batch mode? +.le +.ls icommands = "" +The image display cursor or image cursor command file. +.le +.ls gcommands = "" +The graphics cursor or graphics cursor command file. +.le +.ls wcsout = ")_.wcsout" +The coordinate system of the output coordinates written to \fIoutput\fR. The +image header coordinate system is used to transform from the internal "logical" +pixel coordinate system to the output coordinate system. The output coordinate +system options are "logical", "tv", and "physical". The image cursor coordinate + system is assumed to be the "tv" system. +.ls logical +Logical coordinates are pixel coordinates relative to the current image. +The logical coordinate system is the coordinate system used by the image +input/output routines to access the image data on disk. In the logical +coordinate system the coordinates of the first pixel of a 2D image, e.g. +dev$ypix and a 2D image section, e.g. dev$ypix[200:300,200:300] are +always (1,1). +.le +.ls tv +Tv coordinates are the pixel coordinates used by the display servers. Tv +coordinates include the effects of any input image section, but do not +include the effects of previous linear transformations. If the input +image name does not include an image section, then tv coordinates are +identical to logical coordinates. If the input image name does include a +section, and the input image has not been linearly transformed or copied from +a parent image, tv coordinates are identical to physical coordinates. +In the tv coordinate system the coordinates of the first pixel of a +2D image, e.g. dev$ypix and a 2D image section, e.g. dev$ypix[200:300,200:300] +are (1,1) and (200,200) respectively. +.le +.ls physical +Physical coordinates are pixel coordinates invariant with respect to linear +transformations of the physical image data. For example, if the current image +was created by extracting a section of another image, the physical +coordinates of an object in the current image will be equal to the physical +coordinates of the same object in the parent image, although the logical +coordinates will be different. In the physical coordinate system the +coordinates of the first pixel of a 2D image, e.g. dev$ypix and a 2D +image section, e.g. dev$ypix[200:300,200:300] are (1,1) and (200,200) +respectively. +.le +The wcsout parameter defaults to the value of the package parameter of the same + name. The default values of the package parameters wcsin and wcsout are +"logical" and "logical" respectively. +.le +.ls cache = ")_.cache" +Cache the image pixels in memory. Cache may be set to the value of the apphot +package parameter (the default), "yes", or "no". By default cacheing is +disabled. +.le +.ls verify = ")_.verify" +Automatically confirm the critical parameters when running in non-interactive +mode? Verify may be set to the apphot package parameter value (the default), +"yes", or "no". +.le +.ls update = ")_.update" +Automatically update the algorithm parameters in non-interactive mode if +verify is "yes". Update may be set to the apphot package parameter value +(the default), "yes", or "no". +.le +.ls verbose = ")_.verbose" +Print out information about the progress of the task in non-interactive mode. +Verbose may be set to the apphot package parameter value (the default), "yes", +or "no". +.le +.ls graphics = ")_.graphics" +The standard graphics device. Graphics may be set to the apphot package +parameter value (the default), "yes", or "no". +.le +.ls display = ")_.display" +The standard image display device. Display may be set to the apphot package +parameter value (the default), "yes", or "no". By default graphics overlay is +disabled. Setting display to one of "imdr", "imdg", "imdb", or "imdy" enables +graphics overlay with the IMD graphics kernel. Setting display to "stdgraph" +enables DAOFIND to work interactively from a contour plot. + +.le + +.ih +DESCRIPTION + +DAOFIND searches the IRAF images \fIimage\fR for local density maxima, +which have a full-width half-maximum of \fIdatapars.fwhmpsf\fR and a peak +amplitude greater than \fIfindpars.threshold\fR * \fIdatapars.sigma\fR above +the local background, and writes a list of detected objects in the file +\fIoutput\fR. The detected objects are also listed on the standard output +if the program is running in interactive mode, or in non-interactive mode +with the \fIverbose\fR switch is turned on. + +The coordinates written to \fIoutput\fR are in the coordinate +system defined by \fIwcsout\fR. The options are "logical", "tv", +and "physical". The simplest default is the "logical" system. Users +wishing to correlate the output coordinates of objects measured in +image sections or mosaic pieces with coordinates in the parent +image must use the "tv" or "physical" coordinate systems. + +If \fIcache\fR is yes and the host machine physical memory and working set size +are large enough, the input and output image pixels are cached in memory. If +cacheing is enabled and DAOFIND is run interactively the first measurement +will appear to take a long time as the entire image must be read in before the +measurement is actually made. All subsequent measurements will be very fast +because DAOFIND is accessing memory not disk. The point of cacheing is to speed +up random image access by making the internal image i/o buffers the same size +as the image itself. However if the input object lists are sorted in row order +and sparse cacheing may actually worsen not improve the execution time. Also at +present there is no point in enabling cacheing for images that are less than +or equal to 524288 bytes, i.e. the size of the test image dev$ypix, as the +default image i/o buffer is exactly that size. However if the size of dev$ypix +is doubled by converting it to a real image with the chpixtype task then the +effect of cacheing in interactive is can be quite noticeable if measurements +of objects in the top and bottom halfs of the image are alternated. + +DAOFIND can be run either interactively or in batch mode by setting the +parameter \fIinteractive\fR. In interactive mode the user can examine, +adjust, and save algorithm parameters, and fit or refit the entire coordinate +list with the chosen parameter set. The \fIverify\fR parameter can be used +to automatically enable confirmation of the critical parameters +\fIdatapars.fwhmpsf\fR and \fIdatapars.sigma\fR when running in +non-interactive mode. + + +.ih +CURSOR COMMANDS + +.nf + + Interactive Keystroke Commands + +? Print help +: Colon commands +v Verify the critical parameters +w Save the current parameters +d Plot radial profile of star near cursor +i Interactively set parameters using star near cursor +f Find stars in the image +spbar Find stars in the image, output results +q Exit task + + + Colon Commands + +:show [data/find] List the parameters + + Colon Parameter Editing Commands + +# Image and file name parameters + +:image [string] Image name +:output [string] Output file name + +# Data dependent parameters + +:scale [value] Image scale (units per pixel) +:fwhmpsf [value] Full width half maximum of psf (scale units) +:emission [y/n] Emission feature (y), absorption (n) +:sigma [value] Standard deviation of sky (counts) +:datamin [value] Minimum good data value (counts) +:datamax [value] Maximum good data value (counts) + +# Noise description parameters + +:noise [string] Noise model (constant|poisson) +:gain [string] Gain image header keyword +:ccdread [string] Readout noise image header keyword +:epadu [value] Gain (electrons per adu) +:readnoise [value] Readout noise (electrons) + +# Observation parameters + +:exposure [string] Exposure time image header keyword +:airmass [string] Airmass image header keyword +:filter [string] Filter image header keyword +:obstime [string] Time of observation image header keyword +:itime [value] Exposure time (time units) +:xairmass [value] Airmass value (number) +:ifilter [string] Filter id string +:otime [string] Time of observation (time units) + +# Object detection parameters + +:nsigma [value] Size of Gaussian kernel (sigma) +:threshold [value] Detection intensity threshold (counts) +:ratio [value] Sigmay / sigmax of Gaussian kernel +:theta [value] Position angle of Gaussian kernel +:sharplo [value] Lower bound on sharpness +:sharphi [value] Upper bound on sharpness +:roundlo [value] Lower bound on roundness +:roundhi [value] Upper bound on roundness + +# Plotting and marking commands + +:mkdetections [y/n] Mark detections on the image display + + +The following commands are available inside the interactive setup menu. + + + Interactive Daofind Setup Menu + + v Mark and verify critical daofind parameters (f,s) + + f Mark and verify the full-width half-maximum of the psf + s Mark and verify the standard deviation of the background + l Mark and verify the minimum good data value + u Mark and verify the maximum good data value +.fi + +.ih +ALGORITHMS + +DAOFIND approximates the stellar point spread function with an elliptical +Gaussian function, whose sigma along the semi-major axis is 0.42466 * +\fIdatapars.fwhmpsf\fR / \fIdatapars.scale\fR pixels, semi-minor to semi-major +axis ratio is \fIratio\fR, and major axis position angle is \fItheta\fR. +Using this model, a convolution kernel, truncated at \fInsigma\fR sigma, +and normalized so as to sum to zero, is constructed. + +The density enhancement image \fIstarmap\fR is computed by convolving the input +image with the Gaussian kernel. This operation is mathematically equivalent to +fitting, in the least-squares sense, the image data at each point with a +truncated, lowered elliptical Gaussian function. After convolution each point +in \fIstarmap\fR contains as estimate of the amplitude of the best fitting +Gaussian function at that point. Each point in \fIskymap\fR, if the user +chooses to compute it, contains an estimate of the best fitting sky value +at that point. + +After image convolution , DAOFIND steps through \fIstarmap\fR searching +for density enhancements greater than \fIfindpars.threshold\fR * +\fIdatapars.sigma\fR, and brighter than all other density enhancements within +a semi-major axis of 0.42466 \fIfindpars.nsigma\fR * \fIdatapars.fwhmpsf\fR. +As the program selects candidates, it computes three shape characteristics, +sharpness and 2 estimates of roundness. The sharpness statistic measures the +ratio of, the difference between the height of the central pixel and the mean +of the surrounding non-bad pixels, to the height of the best fitting Gaussian +function at that point. The first roundness characteristic computes the ratio +of a measure of the bilateral symmetry of the object to a measure of the +four-fold symmetry of the object. The second roundness statistic measures the +ratio of, the difference in the height of the best fitting Gaussian function +in x minus the best fitting Gaussian function in y, over the average of the +best fitting Gaussian functions in x and y. The limits on these parameters +\fIfindpars.sharplo\fR, \fIfindpars.sharphi\fR \fIfindpars.roundlo\fR, and +\fIfindpars.roundhi\fR, are set to weed out non-astronomical objects and +brightness enhancements that are elongated in x and y respectively. + +Lastly the x and y centroids of the detected objects are computed by estimating +the x and y positions of the best fitting 1D Gaussian functions in x and y +respectively, a rough magnitude is estimated by computing the ratio of the +amplitude of the best fitting Gaussian at the object position to +\fIfindpars.threshold\fR * \fIdatapars.sigma\fR, and the object is added to +the output coordinate file. + +.ih +OUTPUT + +In interactive mode or in non-interactive with the verbose switch turned on +the following quantities are written to the terminal as each object is +detected. + +.nf + xcenter ycenter mag sharpness sround ground id + + where + + mag = -2.5 * log10 (peak density / detection threshold) +.fi + +The object centers are in pixels and the magnitude estimate measures the +ratio of the maximum density enhancement to the detection threshold. +Sharpness is typically around .5 to .8 for a star with a fwhmpsf similar to +the pattern star. Both sround and ground are close to zero for a truly +round star. Id is the sequence number of the star in the list. + +In both interactive and batch mode the full output is written to the text +file \fIoutput\fR. At the beginning of each file is a header, listing +the current values of the parameters when the first stellar record was +written. The parameters can subsequently be altered. + +.ih +EXAMPLES + +1. Run daofind interactively on dev$ypix using the image display +and image display cursor. Set the fwhmpsf and sigma parameters +with the graphics cursor, radial profile plot, and the interactive +setup key i. + +.nf + ap> display dev$ypix 1 fi+ + + ... display the image + + ap> daofind dev$ypix interactive+ + + ... type ? to see help screen + + ... move display cursor to a star + ... type i to enter the interactive setup menu + ... enter maximum radius in pixels of the radial profile or + accept default with a CR + ... set the fwhmpsf and sigma using the graphics cursor and the + radial profile plot + ... typing <CR> leaves the parameters at their default values + ... type q to quit setup menu + + ... type the v key to verify the critical parameters + + ... type the w key to save the parameters in the parameter files + + ... type the space bar to detect stars in the image + + ... a 1 line summary of the answers will appear on the standard + output for each star measured + + ... type q to quit and q again to confirm the quit + + ... full output will appear in the text file ypix.coo.1 + +.fi + +2. Run daofind interactively on a single image using a contour plot in place +of the image and the graphics cursor in place of the image cursor. +This option is only useful for those (now very few) users who have access to +a graphics terminal but not to an image display server. Set the fwhmpsf and +sigma parameters with the graphics cursor and radial profile plot and the +interactive setup key i. + +.nf + ap> show stdimcur + + ... record the default value of stdimcur + + ap> set stdimcur = stdgraph + + ... define the image cursor to be the graphics cursor + + ap> contour dev$ypix + + ... make a contour plot of dev$ypix + + ap> contour dev$ypix >G ypix.plot1 + + ... store the contour plot of ypix in the file ypix.plot + + ap> daofind dev$ypix display=stdgraph interactive+ + + ... type ? to see the help screen + + ... move graphics cursor to a setup star + ... type i to enter the interactive setup menu + ... enter maximum radius in pixels of the radial profile or + accept the default with a CR + ... set the fwhmpsf and sigma using the graphics cursor and the + radial profile plot + ... typing <CR> leaves the parameters at their default values + ... type q to quit the setup menu + + ... type the v key to confirm the critical parameters + + ... type the w key to save the parameters in the parameter files + + ... retype :.read ypix.plot1 to reload the contour plot + + ... type the space bar to detect stars in the image + + ... a 1 line summary of the answers will appear on the standard + output for each star measured + + ... full output will appear in the text file ypix.coo.2 + + ap> set stdimcur = <default> + + ... reset the image cursor to its default value + +.fi + + +3. Run DAOFIND interactively without using the image display cursor. + +.nf + ap> show stdimcur + + ... record the default value of stdimcur + + ap> set stdimcur = text + + ... set the image cursor to the standard input + + ap> display dev$ypix 1 + + ... display the image + + ap> daofind dev$ypix interactive+ + + ... type ? for help + + ... type "442 409 101 i" in response to the image cursor query where + x and y are the coordinates of the star to be used as setup, + 101 is the default world coordinate system, and i enters the + interactive setup menu. + ... enter maximum radius in pixels of the radial profile or + type CR to accept the default + ... set the fwhmpsf and sigma using the graphics cursor and the + radial profile plot + ... typing <CR> leaves the parameters at their default values + ... type q to quit the setup menu + + ... type the v key to verify the parameters + + ... type the w key to save the parameters in the parameter files + + ... type the space bar to detect stars in the image + + ... a 1 line summary of the answers will appear on the standard + output for each star measured + + ... type q to quit and q again to confirm + + ... full output will appear in the text file ypix.coo.3 + + ap> set stdimcur = <default> + + ... reset the image cursor to its default value +.fi + + +4. Run daofind on a list of 3 images contained in the file imlist in batch mode. +The program will ask the user to verify that the fwhmpsf and the threshold are +correct before beginning execution. + +.nf + ap> type imlist + dev$ypix + dev$wpix + dev$pix + + ap> daofind @imlist + + ... the output will appear in ypix.coo.4, wpix.coo.1, pix.coo.1 +.fi + + +5. Display and find stars in an image section. Write the output coordinates +in the coordinate system of the parent image. Mark the detected stars on +the displayed image. + +.nf + ap> display dev$ypix[150:450,150:450] + + ... display the image section + + ap> daofind dev$ypix[150:450,150:450] wcsout=tv + + ... output will appear in ypix.coo.5 + + ap> tvmark 1 ypix.coo.5 col=204 +.fi + + +6. Repeat example 4 but submit the job to the background and turn off the +verify switch. + +.nf + ap> daofind @imlist verify- & + + ... the output will appear in ypix.coo.6, wpix.coo.2, pix.coo.2 +.fi + + +7. Use an image cursor command file to drive the daofind task. The cursor +command file shown below sets the fwhmpsf, sigma, and threshold parameters, +located stars in the image, updates the parameter files, and quits the task. + +.nf + ap> type cmdfile + : fwhmpsf 2.5 + : sigma 5.0 + : threshold 10.0 + \040 + w + q + + ap> daofind dev$ypix icommands=cmdfile verify- + + ... full output will appear in ypix.coo.7 +.fi + + +.ih +TIME REQUIREMENTS + +.ih +BUGS + +It is currently the responsibility of the user to make sure that the +image displayed in the frame is the same as that specified by the image +parameter. + +Commands which draw to the image display are disabled by default. +To enable graphics overlay on the image display, set the display +parameter to "imdr", "imdg", "imdb", or "imdy" to get red, green, +blue or yellow overlays and set the findpars mkdetections switch to +"yes". It may be necessary to run gflush and to redisplay the image +to get the overlays position correctly. + +.ih +SEE ALSO +datapars, findpars +.endhelp diff --git a/noao/digiphot/apphot/doc/daofind.noao b/noao/digiphot/apphot/doc/daofind.noao new file mode 100644 index 00000000..74cc8f00 --- /dev/null +++ b/noao/digiphot/apphot/doc/daofind.noao @@ -0,0 +1,21 @@ + + +There is a bug in the iraf/daophot ii daofind centering code which results in +incorrect fractional pixel corrections being computed for the detected objects. +This error can most easily be detected by plotting the histogram of the +fractional pixel corrections for an image with a large number of detected +objects. The histogram will be modulated at around the 20% level with "peaks" +around the 0.33 and 0.66 fractional pixel values. + +This bug is fixed for the next release of iraf and in the external addon +package digiphotx version of daofind. There is no workaround although it +should be emphasized that this bug does not affect the centers computed by +the psf fitting code in the peak, nstar, and allstar tasks. Users concerned +with precision in the daofind results should upgrade their software, or +recenter the objects with the phot "centroid" (fast) or "gauss" (more precise) +routines. + +This bug is also present in the standalone version of daophot ii. I have +reported this problem to Peter Stetson and he has fixed it. Users concerned +about this bug in the standalone version of daophot ii should obtain a fix +from Peter Stetson. diff --git a/noao/digiphot/apphot/doc/datapars.hlp b/noao/digiphot/apphot/doc/datapars.hlp new file mode 100644 index 00000000..bacc5c77 --- /dev/null +++ b/noao/digiphot/apphot/doc/datapars.hlp @@ -0,0 +1,290 @@ +.help datapars May00 noao.digiphot.apphot +.ih +NAME +datapars -- edit the data dependent parameters +.ih +USAGE +datapars +.ih +PARAMETERS +.ls scale = 1.0 +The scale of the image in user units, e.g arcseconds per pixel. +All APPHOT distance dependent parameters are assumed to be in units of scale. +If scale = 1.0 these parameters are assumed to be in units of pixels. +Most APPHOT users should leave scale set to 1.0 unless they intend to +compare their aperture photometry results directly with data +in the literature. +.le +.ls fwhmpsf = 2.5 (scale units) +The full-width at half-maximum of the point spread function in scale units. +The DAOFIND, FITPSF and WPHOT tasks and the "gauss" and "ofilter" centering +algorithms depend on the value of fwhmpsf. APPHOT users can either determine +a value for fwhmpsf using an external task such as IMEXAMINE, or make use of +the interactive capabilities of the APPHOT tasks to set and store it. +.le +.ls emission = yes +The features to be measured are above sky. By default the APPHOT package +considers all features to be emission features. However all the package tasks +measure absorption features if emission is set to no. +.le +.ls sigma = INDEF +The standard deviation of the sky pixels. The DAOFIND task and the "constant" +sky fitting algorithm error estimate depend on the value of sigma. APPHOT +users should set sigma to a value which is representative of the noise +in the sky background. +.le +.ls datamin = INDEF +The minimum good pixel value. Datamin defaults to -MAX_REAL, the minimum +floating point number supported by the host computer. APPHOT users should +set this parameter if they wish to remove bad data from the sky pixel +distribution before the sky is fit or if they wish to flag stars with +bad data in the centering and / or photometry apertures. +.le +.ls datamax = INDEF +The maximum good pixel value. Datamax defaults to MAX_REAL the maximum +floating point number supported by the host computer. +APPHOT users should set this parameter if they wish to flag +saturated stars or stars with bad data in the centering and / or +photometry apertures. +.le +.ls noise = "poisson" +The noise model used to estimate the uncertainties in the computed APPHOT +magnitudes. The options are the following: +.ls poisson +Poisson statistics in the object and the sky background are used to estimate +the error in the object measurement. There are two components to the sky +noise measurement the sky noise in the object aperture and the mean error +in the estimated sky value. +.le +.ls constant +The standard deviation of the sky background is used to estimate the +error in the object measurement. There are two components to the error +estimate the sky noise in the object aperture and the mean error in the +estimated sky value. +.le + +Most APPHOT users should use the Poisson model appropriate for CCD detectors. +APPHOT users should also be aware that one or other of the parameters +gain or epadu must be set correctly in order to compute the magnitude +errors correctly. +.le +.ls ccdread = "" +The image header keyword defining the readout noise parameter whose units are +assumed to be electrons. +.le +.ls gain = "" +The image header keyword defining the gain parameter whose units are assumed +to be electrons per adu. +.le +.ls readnoise = 0.0 +The readout noise of the image in electrons. APPHOT users should set this +parameter or the ccdread parameter to its correct value before running any +of the APPHOT tasks. +.le +.ls epadu = 1.0 +The gain in electrons per adu. APPHOT users should set epadu or ain to its +correct value before running any of the APPHOT tasks in order to insure that +the magnitude error estimates are correct. +.le +.ls exposure = "" +The image header exposure time keyword. The time units are arbitrary but +must be consistent for any list of images whose magnitudes are to be compared. +The computed magnitudes are normalized to 1 timeunit. Setting the exposure +parameter will greatly simplify future reduction steps. The value of exposure +is recorded in the APPHOT output file. +.le +.ls airmass = "" +The image header airmass keyword. The airmass parameter is not used +directly by APPHOT but the airmass value is stored in the output file +and its presence there will simplify future calibration steps. +.le +.ls filter = "" +The image header filter id keyword. The filter parameter is not used +directly by APPHOT but the filter id is stored in the output file +and its presence there will simplify future calibration steps. +.le +.ls obstime = "" +The image header time of observation keyword. The obstime parameter is not used +directly by APPHOT but the obstime value is stored in the output file +and its presence there will simplify future calibration steps. +.le +.ls itime = 1.0 +The exposure time for the image in arbitrary units. The APPHOT magnitudes are +normalized to 1 timeunit using the value of exposure in the image header +if exposure is defined or the value of itime. +.le +.ls xairmass = INDEF +The airmass value. The airmass is read from the image header if airmass +is defined or from xairmass. The airmass value is stored in the APPHOT +output files. +.le +.ls ifilter = "INDEF" +The filter id string. The filter id is read from the image header if filter +is defined otherwise from ifilter. The filter id is stored in the APPHOT +output files. +.le +.ls otime = "INDEF" +The value of the time of observation. The time of observation is read from +the image header if obstime is defined otherwise from otime. The time of +observation is stored in the APPHOT output files. +.le +.ih +DESCRIPTION +\fIDatapars\fR sets the image data dependent parameters. These parameters are +functions, of the instrument optics, the noise characteristics and range of +linearity of the detector, and the observing conditions. Many of the +centering, sky fitting, and photometry algorithm parameters in the CENTERPARS, +FITSKYPARS and PHOTPARS parameter sets scale with the data dependent +parameters. + +The parameter \fIscale\fR sets the scale of the apertures used by the +centering, sky fitting and photometry algorithms. Scale converts radial +distance measurements in pixel units to radial distance measurements in +scale units. The APPHOT parameters, cbox, maxshift, rclean and rclip +in the CENTERPARS parameter set; annulus, dannulus, and rgrow in +the FITSKYPARS parameter set; and apertures in the PHOTPARS +parameter set are expressed in units of the scale. The scale parameter is +useful in cases where the observations are to be compared to published +aperture photometry measurements in the literature. + +The parameter \fIfwhmpsf\fR defines the full-width at half-maximum of the +stellar point spread function. Most APPHOT tasks and algorithms do not +require this parameter. The exceptions are the DAOFIND task, the centering +algorithms "gauss" and "ofilter", the FITPSF task, and the WPHOT task. + +By setting the \fIscale\fR and \fIfwhmpsf\fR appropriately the aperture +sizes and radial distances may be expressed in terms of the half-width +at half-maximum of the stellar point spread function. The way to do this +is to define the scale parameter in units of the number of half-width at +half-maximum per pixel, set the fwhmpsf parameter to 2.0, and then +set the remaining scale dependent centering, sky fitting and photometry +algorithm parameters in CENTERPARS, FITSKYPARS and PHOTPARS to +appropriate values in units of the half-width at half-maximum of the +point-spread function. Once an optimum set of algorithm parameters is +chosen, the user need only alter the DATAPARS scale parameter before +executing an APPHOT task on a new image. + +If \fIemission\fR is "yes", the features to be measured are assumed to be +above sky. By default the APPHOT package considers all measurements to +be measurements of emission features. In most cases APPHOT users should +leave emission set to "yes". + +The parameter \fIsigma\fR estimates the standard deviation of the sky +background pixels. The star finding algorithm in DAOFIND uses sigma +and the \fIfindpars.threshold\fR parameter to define the stellar +detection threshold in adu. The centering algorithms uses sigma, +1) with the \fIcenterpars.kclean\fR parameter to define deviant pixels +if \fIcenterpars.clean\fR is enabled; 2) to estimate the signal to +noise ratio in the centering box; 3) and with the \fIcenterpars.cthreshold\fR +parameter to define the lower intensity limit for the pixels to be used +for centering. If sigma is undefined or <= 0.0 1) no cleaning is performed +regardless of the value of centerpars.clean; 2) the background +noise in the centering box is assumed to be 0; and 3) default cutoff +intensity intensity is used for centering. + +The \fIdatamin\fR and \fIdatamax\fR parameters define the good data range. +If datamin or datamax are defined bad data is removed from the sky pixel +distribution before the sky is fit, data containing bad pixels in the +photometry apertures is flagged, and the corresponding aperture photometry +magnitudes are set to INDEF. APPHOT users should set datamin and datamax +to appropriate values before running the APPHOT tasks. + +Two noise models are available "constant" and "poisson". If \fInoise\fR = +constant, the total noise is assumed to be due to noise in the sky background +alone. If \fInoise\fR = poisson, the total noise includes Poisson noise from +the object and the sky noise. + +The parameters \fIgain\fR and \fIepadu\fR define the image gain. +The gain parameter specifies which keyword in the image header contains +the gain value. If gain is undefined or not present in the image header +the value of epadu is used. Epadu must be in units of electrons per adu. +APPHOT users should set either gain or epadu before running any +APPHOT tasks to insure the magnitude error computations are correct. + +The two parameters \fIccdread\fR and \fIreadnoise\fR define the image +readout noise. The ccdread parameter specifies which keyword in the +image header contains the readout noise value. If ccdread is undefined or +not present in the image header the value of readnoise is used. +Readnoise is assumed to be in units of electrons. +APPHOT users should set either ccdread or readnoise before running any +APPHOT tasks to insure the magnitude error computations are correct. + +The magnitudes are normalized to an exposure time of 1 timeunit using +the value of the exposure time in the image header parameter \fIexposure\fR +or \fIitime\fR. If exposure is undefined or not present in the image header +the value of itime is used. Itime can be in arbitrary units. +Setting either exposure or itime will simplify future analysis steps. + +The parameters \fIairmass\fR and \fIxairmass\fR define the airmass +of the observation. The airmass parameter specifies which keyword in the +image header contains the airmass value. If airmass is undefined or +not present in the image header the value of xairmass is used. +The airmass values are not used in any APPHOT computations, however their +presence in the APPHOT output files will simplify future reduction steps. + +The parameters \fIfilter\fR and \fIifilter\fR define the filter +of the observation. The filter parameter specifies which keyword in the +image header contains the filter id. If filter is undefined or not present +in the image header the value of ifilter is used. The filter id values are +not used in any APPHOT computations, however their presence in the APPHOT +output files can will simplify future reduction steps. + +The parameters \fIobstime\fR and \fIotime\fR define the time +of the observation (e.g. UT). The obstime parameter specifies which keyword +in the image header contains the time stamp of the observation. If obstime is +undefined or not present in the image header the value of otime is used. +The time of observations values are not used in any APPHOT +computations, however their presence in the APPHOT output files can +greatly simplify future reduction steps. + +.ih +EXAMPLES + +1. List the data dependent parameters. + +.nf + ap> lpar datapars +.fi + +2. Edit the data dependent parameters. + +.nf + ap> datapars +.fi + +3. Edit the DATAPARS parameters from within the PHOT task. + +.nf + da> epar phot + + ... edit a few parameters + + ... move to the datapars parameter and type :e + + ... edit the datapars parameters and type :wq + + ... finish editing the phot parameters and type :wq +.fi + +4. Save the current DATAPARS parameter set in a text file datnite1.par. +This can also be done from inside a higher level task as in the +previous example. + +.nf + da> datapars + + ... edit a few parameters + + ... type ":w datnite1.par" from within epar +.fi + +.ih +TIME REQUIREMENTS + +.ih +BUGS + +.ih +SEE ALSO +epar,lpar,daofind,center,fitsky,phot,wphot,polyphot,radprof,fitpsf +.endhelp diff --git a/noao/digiphot/apphot/doc/findpars.hlp b/noao/digiphot/apphot/doc/findpars.hlp new file mode 100644 index 00000000..22fa7668 --- /dev/null +++ b/noao/digiphot/apphot/doc/findpars.hlp @@ -0,0 +1,134 @@ +.help findpars May00 noao.digiphot.apphot +.ih +NAME +findpars -- edit the star detection parameters +.ih +USAGE +findpars +.ih +PARAMETERS +.ls threshold = 4.0 (sigma) +The object detection threshold above local background in units of +\fIdatapars.sigma\fR. +.le +.ls nsigma = 1.5 +The semi-major axis of the Gaussian convolution kernel used to computed the +density enhancement and mean density images in Gaussian sigma. This semi- +major axis is equal to min (2.0, 0.42466 * \fInsigma\fR * +\fIdatapars.fwhmpsf\fR / \fIdatapars.scale\fR) pixels. +.le +.ls ratio = 1.0 +The ratio of the sigma of the Gaussian convolution kernel along the minor axis +direction to the sigma along the major axis direction. \fIRatio\fR defaults +to 1.0 in which case the image is convolved with a circular Gaussian. +.le +.ls theta = 0.0 +The position angle of the major axis of the Gaussian convolution kernel. +\fITheta\fR is measured in degrees counter-clockwise from the x axis. +.le +.ls sharplo = .2, sharphi = 1.0 +\fISharplo\fR and \fIsharphi\fR are numerical cutoffs on the image sharpness +statistic designed to eliminate brightness maxima which are due to bad pixels +rather than to astronomical objects. +.le +.ls roundlo = -1.0 roundhi = 1.0 +\fIRoundlo\fR and \fIroundhi\fR are numerical cutoffs on the image roundness +statistic designed to eliminate brightness maxima which are due to bad rows or +columns, rather than to astronomical objects. +.le +.ls mkdetections = no +Mark the positions of the detected objects on the displayed image ? +.le + +.ih +DESCRIPTION + +DAOFIND approximates the stellar point spread function with an elliptical +Gaussian function, whose sigma along the semi-major axis is 0.42466 * +\fIdatapars.fwhmpsf\fR / \fIdatapars.scale\fR pixels, semi-minor to semi-major +axis ratio is \fIratio\fR, and major axis position angle is \fItheta\fR. +Using this model, a convolution kernel, truncated at \fInsigma\fR sigma, +and normalized to sum to zero, is constructed. + +The density enhancement image \fIstarmap\fR is computed by convolving the input +image with the Gaussian kernel. This operation is mathematically equivalent to +fitting, in the least-squares sense, the image data at each point with a +truncated, lowered elliptical Gaussian function. After convolution each point +in \fIstarmap\fR contains as estimate of the amplitude of the best fitting +Gaussian function at that point. Each point in \fIskymap\fR, if the user +chooses to compute it, contains an estimate of the best fitting sky value +at that point. + +After image convolution DAOFIND steps through \fIstarmap\fR searching +for density enhancements greater than \fIfindpars.threshold\fR * +\fIdatapars.sigma\fR, and brighter than all other density enhancements +within a semi-major axis of 0.42466 \fIfindpars.nsigma\fR * +\fIdatapars.fwhmpsf\fR. As the program selects candidates, it computes two +shape characteristics sharpness and roundness. The sharpness statistic +measures the ratio of the difference between the height of the central pixel +and the mean of the surrounding non-bad pixels, to the height of the best +fitting Gaussian function at that point. The roundness statistics measures +the ratio of, the difference in the height of the best fitting Gaussian +function in x minus the best fitting Gaussian function in y, over the average +of the best fitting Gaussian functions in x and y. The limits on these +parameters \fIfindpars.sharplo\fR, \fIfindpars.sharphi\fR, +\fIfindpars.roundlo\fR, and \fIfindpars.roundhi\fR, are set to weed out +non-astronomical objects and brightness enhancements that are elongated in +x and y respectively. + +Lastly the x and y centroids of the detected objects are computed by +estimating the x and y positions of the best fitting 1D Gaussian +functions in x and y respectively, a rough magnitude is estimated +by computing the ratio of the amplitude of the best fitting Gaussian at +the object position to \fIfindpars.threshold\fR * \fIdatapars.sigma\fR, +and the object is added to the output coordinate file. + + +.ih +EXAMPLES + +1. List the object detection parameters. + +.nf + da> lpar findpars +.fi + +2. Edit the object detection parameters. + +.nf + da> findpars +.fi + +3. Edit the FINDPARS parameters from within the DAOFIND task. + +.nf + da> epar daofind + + ... edit a few daofind parameters + + ... move to the findpars parameter and type :e + + ... edit the findpars parameter and type :wq + + ... finish editing the daofind parameters and type :wq +.fi + +4. Save the current FINDPARS parameter set in a text file fndnite1.par. +This can also be done from inside a higher level task as in the previous +example. + +.nf + da> findpars + + ... edit the parameters + + ... type ":w fndnite1.par" from within epar +.fi + +.ih +BUGS + +.ih +SEE ALSO +daofind, datapars +.endhelp diff --git a/noao/digiphot/apphot/doc/fitpsf.hlp b/noao/digiphot/apphot/doc/fitpsf.hlp new file mode 100644 index 00000000..8a229508 --- /dev/null +++ b/noao/digiphot/apphot/doc/fitpsf.hlp @@ -0,0 +1,680 @@ +.help fitpsf May00 noao.digiphot.apphot +.ih +NAME +fitpsf -- model the point spread function with an analytic function +.ih +USAGE +fitpsf image box +.ih +PARAMETERS +.ls image +The list of images containing the objects to be measured. +.le +.ls box +The width of the fitting box in scale units. +.le +.ls coords = "" +The list of text files containing initial coordinates for the objects to +be centered. Objects are listed in coords one object per line with the +initial coordinate values in columns one and two. The number of coordinate +files must be zero, one, or equal to the number of images. +If coords is "default", "dir$default", or a directory specification then an +coords file name of the form dir$root.extension.version is constructed and +searched for, where dir is the directory, root is the root image name, +extension is "coo" and version is the next available version number for the +file. +.le +.ls output = "default" +The name of the results file or results directory. If output is +"default", "dir$default", or a directory specification then an output file name +of the form dir$root.extension.version is constructed, where dir is the +directory, root is the root image name, extension is "psf" and version is +the next available version number for the file. The number of output files +must be zero, one, or equal to the number of image files. In both interactive +and batch mode full output is written to output. In interactive mode +an output summary is also written to the standard output. +.le +.ls datapars = "" +The name of the file containing the data dependent parameters. +The critical parameters \fIfwhmpsf\fR and \fIsigma\fR are located in +datapars. If datapars is undefined then the default parameter set in +uparm directory is used. +.le +.ls function = "radgauss" +The function to be fit. The options are: +.ls radgauss +A 2D radial Gaussian function is fit. The parameters of the fitting function +are: x and y center, sigma of the Gaussian, amplitude of the Gaussian and +the local sky value. +.le +.ls elgauss +A 2D elliptical Gaussian function is fit. The parameters of the fitting +function are: x and y center, x and y sigma of the Gaussian, amplitude of +the Gaussian and the local sky value. +.le +.ls moments +The 0th, 1st and 2nd order moments are computed and used to derive +estimates of the +x and y center values, radius of gyration, ellipticity and position +angle of the object. +.le +.le +.ls maxiter = 50 +The maximum number of iterations that the non-linear fitting routines will +perform in an attempt to find a satisfactory fit. +.le +.ls nreject = 0 +The maximum number of rejection cycles performed after the fit. +The default is no rejection. +.le +.ls kreject = 3.0 +The k-sigma rejection limit in units of sigma. +.le +.ls mkbox = no +Draw the fitting box on the image display? +.le +.ls interactive = yes +Run the task interactively ? +.le +.ls icommands = "" +The image cursor or image cursor command file. +.le +.ls gcommands = "" +The graphics cursor or graphics cursor command file. +.le +.ls wcsin = ")_.wcsin", wcsout = ")_.wcsout" +The coordinate system of the input coordinates read from \fIcoords\fR and +of the output coordinates written to \fIoutput\fR respectively. The image +header coordinate system is used to transform from the input coordinate +system to the "logical" pixel coordinate system used internally, +and from the internal "logical" pixel coordinate system to the output +coordinate system. The input coordinate system options are "logical", tv", +"physical", and "world". The output coordinate system options are "logical", +"tv", and "physical". The image cursor coordinate system is assumed to +be the "tv" system. +.ls logical +Logical coordinates are pixel coordinates relative to the current image. +The logical coordinate system is the coordinate system used by the image +input/output routines to access the image data on disk. In the logical +coordinate system the coordinates of the first pixel of a 2D image, e.g. +dev$ypix and a 2D image section, e.g. dev$ypix[200:300,200:300] are +always (1,1). +.le +.ls tv +Tv coordinates are the pixel coordinates used by the display servers. Tv +coordinates include the effects of any input image section, but do not +include the effects of previous linear transformations. If the input +image name does not include an image section, then tv coordinates are +identical to logical coordinates. If the input image name does include a +section, and the input image has not been linearly transformed or copied from +a parent image, tv coordinates are identical to physical coordinates. +In the tv coordinate system the coordinates of the first pixel of a +2D image, e.g. dev$ypix and a 2D image section, e.g. dev$ypix[200:300,200:300] +are (1,1) and (200,200) respectively. +.le +.ls physical +Physical coordinates are pixel coordinates invariant with respect to linear +transformations of the physical image data. For example, if the current image +was created by extracting a section of another image, the physical +coordinates of an object in the current image will be equal to the physical +coordinates of the same object in the parent image, although the logical +coordinates will be different. In the physical coordinate system the +coordinates of the first pixel of a 2D image, e.g. dev$ypix and a 2D +image section, e.g. dev$ypix[200:300,200:300] are (1,1) and (200,200) +respectively. +.le +.ls world +World coordinates are image coordinates in any units which are invariant +with respect to linear transformations of the physical image data. For +example, the ra and dec of an object will always be the same no matter +how the image is linearly transformed. The units of input world coordinates +must be the same as those expected by the image header wcs, e. g. +degrees and degrees for celestial coordinate systems. +.le +The wcsin and wcsout parameters default to the values of the package +parameters of the same name. The default values of the package parameters +wcsin and wcsout are "logical" and "logical" respectively. +.le +.le +.ls cache = ")_.cache" +Cache the image pixels in memory. Cache may be set to the value of the apphot +package parameter (the default), "yes", or "no". By default cacheing is +disabled. +.le +.ls verify = ")_.verify" +Verify the critical parameters in non-interactive mode ? Verify may be set to +the apphot package parameter value (the default), "yes", or "no. +.le +.ls update = ")_.update" +Update the critical parameters in non-interactive mode if verify is set of +"yes" ? Update may be set to the apphot package parameter value (the default), +"yes", or "no. + +.le +.ls verbose = ")_.verbose" +Print messages on the terminal in non-interactive mode ? Verbose may be set +to the apphot package parameter value (the default), "yes", or "no. + +.le +.ls graphics = ")_.graphics" +The default graphics device. Graphics may be set to the apphot package +parameter value (the default), "yes", or "no. +.le +.ls display = ")_.display" +The default display device. Display may be set to the apphot package +parameter value (the default), "yes", or "no. By default graphics overlay +is disabled. Setting display to one of "imdr", "imdg", "imdb", or "imdy" +enables graphics overlay with the IMD graphics kernel. Setting display to +"stdgraph" enables FITPSF to work interactively from a contour plot. +.le + +.ih +DESCRIPTION + +FITPSF models the stellar brightness distribution of objects in the IRAF image +\fIimage\fR using non-linear least squares techniques and writes the +list of model parameters and associated errors to the file \fIoutput\fR. +Initial coordinates for the objects are read from the image cursor or +the text file \fIcoords\fR. Pixels in a subraster of width \fIbox * scale\fR +are extracted and used in the fit. + +The coordinates read from \fIcoords\fR are assumed to be in coordinate +system defined by \fIwcsin\fR. The options are "logical", "tv", "physical", +and "world" and the transformation from the input coordinate system to +the internal "logical" system is defined by the image coordinate system. +The simplest default is the "logical" pixel system. Users working on with +image sections but importing pixel coordinate lists generated from the parent +image must use the "tv" or "physical" input coordinate systems. +Users importing coordinate lists in world coordinates, e.g. ra and dec, +must use the "world" coordinate system and may need to convert their +equatorial coordinate units from hours and degrees to degrees and degrees first. + +The coordinates written to \fIoutput\fR are in the coordinate +system defined by \fIwcsout\fR. The options are "logical", "tv", +and "physical". The simplest default is the "logical" system. Users +wishing to correlate the output coordinates of objects measured in +image sections or mosaic pieces with coordinates in the parent +image must use the "tv" or "physical" coordinate systems. + +If \fIcache\fR is yes and the host machine physical memory and working set size +are large enough, the input image pixels are cached in memory. If cacheing +is enabled and FITPSF is run interactively the first measurement will appear +to take a long time as the entire image must be read in before the measurement +is actually made. All subsequent measurements will be very fast because FITPSF +is accessing memory not disk. The point of cacheing is to speed up random +image access by making the internal image i/o buffers the same size as the +image itself. However if the input object lists are sorted in row order and +sparse cacheing may actually worsen not improve the execution time. Also at +present there is no point in enabling cacheing for images that are less than +or equal to 524288 bytes, i.e. the size of the test image dev$ypix, as the +default image i/o buffer is exactly that size. However if the size of dev$ypix +is doubled by converting it to a real image with the chpixtype task then the +effect of cacheing in interactive is can be quite noticeable if measurements +of objects in the top and bottom halfs of the image are alternated. + +FITPSF can be run either interactively or in batch mode by setting the +parameter \fIinteractive\fR. In interactive mode starting x and y positions +can either be read directly from the image cursor or read from the text +file specified by \fIcoords\fR. In batch mode the estimated +positions can be read from the text file \fIcoords\fR or the image cursor +parameter \fIicommands\fR can be redirected to a text file containing +a list of cursor commands. + +.ih +CURSOR COMMANDS + +The currently available cursor commands are listed below. + +.nf + Interactive Keystroke Commands + +? Print help +: Colon commands +v Verify the critical parameters +w Save the current parameters +d Plot radial profile of current star +i Interactively set parameters using current star +f Fit current star +spbar Fit current star, output results +m Move to next star in coordinate list +n Fit next star in coordinate list, output results +l Fit remaining stars in coordinate list, output results +e Print error messages +r Rewind the coordinate list +q Exit task + + + + Colon Commands + +:show [data/fit] List the parameters +:m [n] Move to next [nth] star in coordinate list +:n [n] Fit next [nth] star in coordinate list, output results + + + Colon Parameter Editing Commands + +# Image and file name parameters + +:image [string] Image name +:coords [string] Coordinate file name +:output [string] Output file name + +# Data dependent parameters + +:scale [value] Image scale (units per pixel) +:fwhmpsf [value] Scale factor (scale units) +:emission [y/n] Emission feature (y), absorption (n) +:sigma [value] Standard deviation of sky (counts) +:datamin [value] Minimum good data value (counts) +:datamax [value] Maximum good data value (counts) + +# Noise description parameters + +:noise [string] Noise model (constant|poisson) +:gain [string] Gain image header keyword +:ccdread [string] Readout noise image header keyword +:epadu [value] Gain (electrons per adu) +:readnoise [value] Readnoise (electrons) + +# Observation parameters + +:exposure [string] Exposure time image header keyword +:airmass [string] Airmass image header keyword +:filter [string] Filter image header keyword +:obstime [string] Time of observation image header keyword +:itime [value] Exposure time (time units) +:xairmass [value] Airmass value (number) +:ifilter [string] Filter id string +:otime [string] Time of observation (time units) + +# Fitting parameters + +:function [string] PSF model (radgauss|elgauss|moments) +:box [value] Width of the fitting box (scale units) +:maxiter [value] Maximum number of iterations +:nreject [value] Maximum number of rejection cycles +:kreject [value] Rejection limit (sigma) + +# Plotting and marking functions + +:mkbox [y/n] Mark the fitting box on the display + + +The following command are available from within the interactive setup menu. + + + Interactive Fitpsf Setup Menu + + v Mark and verify the critical fitpsf parameters (f,s,b) + + f Mark and verify the full-width half-maximum of the psf + s Mark and verify the standard deviation of the background + l Mark and verify the minimum good data value + u Mark and verify the maximum good data value + + b Mark and verify the half-width of the fitting box +.fi + +.ih +ALGORITHMS + +The fitting parameters are \fIfunction\fR, the functional form of the model +to be fit, \fImaxiter\fR, the maximum number of iterations per fit, +\fIkreject\fR, the K-sigma rejection limit and \fInreject\fR, the maximum +number of rejection cycles. The currently available functions are a 2D +moments analysis "moments", a 2D radial Gaussian "radgauss", and a +2D elliptical Gaussian "elgauss". + +The weighting of the fit is determined by the parameter \fInoise\fR in the +\fIdatapars\fR file. The two options are \fIconstant\fR, in which all the +weights are set to 1 and \fIpoisson\fR in which the weights are equal to +the inverse of the counts divided by the image gain read from the datapars +\fIgain\fR or \fIepadu\fR parameters plus the square of the readout noise +determined from the datapars parameters \fIccdread\fR or \fIreadnoise\fR. +If \fIfunction\fR is either "radgauss" or "ellgauss" then the datapars +parameter \fIfwhmpsf\fR is used to determine the initial guess for the +Gaussian sigma. The datapars parameter \fIthreshold\fR determines the +intensity threshold above which the moment analysis is performed. + +.ih +OUTPUT + +In interactive mode the following quantities are printed on the +terminal as shown below, for the radial Gaussian, elliptical Gaussian and +moments functions respectively. + +.nf + image xcenter ycenter rsigma amplitude sky err + + image xcenter ycenter xsigma ysigma rot amplitude sky err + + image xcenter ycenter rgyrat ellip pa amplitude sky err + +.fi + +In both interactive and batch mode the full output is written to the +text file \fIoutput\fR. At the beginning of each file is a header +listing the values of the parameters when the first stellar +record was written. These parameters can be subsequently altered. +For each star measured the following record is written for the radial +Gaussian, elliptical Gaussian, and moments functions respectively. + +.nf + image xinit yinit id coords lid + xcenter ycenter rsigma amplitude sky + excenter eycenter ersigma eamplitude esky ier error + + image xinit yinit id coords lid + xcenter ycenter xsigma ysigma rot amplitude sky + excenter eycenter exsigma eysigma erot eamplitude esky ier\ + error + + image xinit yinit id coords lid + xcenter ycenter rgyrat ellip pa amplitude sky + excenter eycenter ergyrat eellip epa eamplitude esky ier\ + error +.fi + +Image and coords are the name of the image and coordinate files respectively. +Id and lid are the sequence numbers of stars in the output and coordinate +files respectively and xinit and yinit are the initial positions. +Xcenter and ycenter are the computed x and y +positions of the object. Rsigma, xsigma and ysigma are the distance from +the center of the Gaussian at which the Gaussian is equal to exp (-0.5) +of its central value. Xsigma and ysigma refer to those values along the major +and minor axes of the ellipse respectively. The amplitude and sky refer to +the amplitude of +the Gaussian function and a constant background value respectively. +If function = "moments" amplitude and sky refer to the total intensity +above threshold and sky is the threshold value. Rot and pa are position angles +of the major axis measured counter-clockwise with respect to the x axis. +Rgyrat is the radius +of gyration of the object and ellip its ellipticity. +Quantities prefixed by an e represent the errors in the corresponding +fitted parameters. + +.ih +ERRORS + +If all went well in the fitting process the error code stored in the ier +field described above is 0. Non-zero values of ier flag the following error +conditions. + +.nf + 0 # No error + 401 # The fitting box is off the image + 402 # The fitting box is partially off the image + 403 # There are too few points to fit the function + 404 # The fit is singular + 405 # The fit did not converge +.fi + +.ih +EXAMPLES + +1. Compute the radial Gaussian function parameters for a few stars in dev$ypix +using the display and the image cursor. Setup the task parameters using +the interactive setup menu defined by the i key command. Use uniform +weighting. + +.nf + ap> display dev$ypix 1 fi+ + + ... display the image + + ap> fitpsf dev$ypix 11 noise=constant + + ... type ? to see the help screen + + ... move the image cursor to a star + ... type i to enter the interactive setup menu + ... enter maximum radius in pixels of the radial profile or type + CR to accept the default value + ... set the fitting box width, fwhmpsf, and sigma using the graphics + cursor and the stellar radial profile plot + ... typing <CR> leaves everything at the default value + ... type q to quit the setup menu + + ... type the v key to verify the parameters + + ... type the w key to save the parameters in the parameter files + + ... move the image cursor to the stars of interest and tap + the space bar + + ... a one line summary of the fitted parameters will appear on the + standard output for each star measured + + ... type q to quit and another q to confirm the quit + + ... the full output will appear in ypix.psf.1 +.fi + +2. Compute the radial Gaussian function parameters for a few stars in +dev$ypix using the contour plot and the graphics cursor. Setup the task +parameters using the interactive setup menu defined by the i key command. +Use uniform weighting. + +.nf + ap> show stdimcur + + ... save the current value of stdimcur + + ap> set stdimcur = stdgraph + + ... define the image cursor to be the graphics cursor + + ap> contour dev$ypix >G ypix.plot1 + + ... store the contour plot of dev$ypix in the file ypix.plot1 + + ap> fitpsf dev$ypix 11.0 noise=constant display=stdgraph + + ... type ? to get a short help page on the screen + + ... move the graphics cursor to a star + ... type i to enter the interactive setup menu + ... enter the maximum radius in pixels of the radial profile or + type CR to accept the default value + ... set the fitting box width, fwhmpsf, and sigma using the graphics + cursor and the stellar radial profile plot + ... typing <CR> leaves everything at the default value + ... type q to quit the setup menu + + ... type the v key to verify critical parameters + + ... type the w key to save the parameters in the parameter files + + ... retype :.read ypix.plot1 to reload the contour plot + + ... move the graphics cursor to the stars of interest and tap + the space bar + + ... a one line summary of the fitted parameters will appear on the + standard output for each star measured + + ... type q to quit and q again to confirm the quit + + ... full output will appear in the text file ypix.psf.2 +.fi + + +3. Setup and run FITPSF interactively on a list of objects temporarily +overriding the fwhmpsf and sigma parameters determined in examples 1 or 2. +Use uniform weighting. + +.nf + ap> daofind dev$ypix fwhmpsf=2.6 sigma=25.0 verify- + + ... make a coordinate list + + ... the output will appear in the text file ypix.coo.1 + + ap> fitpsf dev$ypix 11.0 fwhmpsf=2.6 noise=constant coords=ypix.coo.1 + + ... type ? for optional help + + + ... move the graphics cursor to the stars and tap space bar + + or + + ... select stars from the input coordinate list with m / :m # + and measure with spbar + + ... measure stars selected from the input coordinate list + with n / n # + + ... a one line summary of results will appear on the standard output + for each star measured + + ... type q to quit and q again to confirm the quit + + ... the output will appear in ypix.psf.3 ... +.fi + + +4. Display and fit some stars in an image section and write the output +coordinates in the coordinate system of the parent image. Use uniform +weighting. + +.nf + ap> display dev$ypix[150:450,150:450] 1 + + ... display the image section + + ap> fitpsf dev$ypix[150:450,150:450] 11.0 noise=constant wcsout=tv + + ... move cursor to stars and type spbar + + ... type q to quit and q again to confirm quit + + ... output will appear in ypix.psf.4 + + ap> pdump ypix.psf.4 xc,yc yes | tvmark 1 STDIN col=204 +.fi + + +5. Run FITPSF in batch mode using the coordinate file and the previously +saved parameters. Use uniform weighting. Verify the critical parameters. + +.nf + ap> fitpsf dev$ypix 11.0 coords=ypix.coo.1 noise=constant verify+ \ + inter- + + ... output will appear in ypix.psf.5 ... +.fi + +6. Repeat example 5 but assume that the input coordinate are ra and dec +in degrees and degrees, turn off verification, and submit the task to to +the background. Use uniform weighting. + +.nf + ap> display dev$ypix 1 + + ap> rimcursor wcs=world > radec.coo + + ... move to selected stars and type any key + + ... type ^Z to quit + + ap> fitpsf dev$ypix 11.0 coords=radec.coo noise=constant \ + wcsin=world verify- inter- & + + ... output will appear in ypix.psf.6 + + ap> pdump ypix.psf.6 xc,yc yes | tvmark 1 STDIN col=204 + + ... mark the stars on the display +.fi + +7. Run FITPSF interactively without using the image display. + +.nf + ap> show stdimcur + + ... record the default value of stdimcur + + ap> set stdimcur = text + + ... set the image cursor to the standard input + + ap> fitpsf dev$ypix 11.0 coords=ypix.coo.1 noise=constant + + ... type ? for optional help + + ... type :m 3 to set the initial coordinates to those of the + third star in the list + + ... type i to enter the interactive setup menu + ... enter the maximum radius in pixels for the radial profile or + accept the default with a CR + ... type v to enter the default menu + ... set the fwhmpsf, sigma, and fitting box size using the + graphics cursor and the stellar radial profile plot + ... typing <CR> after the prompt leaves the parameter at its default + value + ... type q to quit the setup menu + + ... type r to rewind the coordinate list + + ... type l to measure all the stars in the coordinate list + + ... a one line summary of the answers will appear on the standard + output for each star measured + + ... type q to quit followed by q to confirm the quit + + ... full output will appear in the text file ypix.psf.7 + + ap> set stdimcur = <default> + + ... reset the value of stdimcur +.fi + +8. Use an image cursor command file to drive the FITPSF task. The cursor command +file shown below sets the fwhmpsf, sigma, and noise, computes the model +fit parameter values for 3 stars, updates the parameter files, and quits +the task. + +.nf + ap> type cmdfile + : fwhmpsf 2.6 + : sigma 5.0 + : noise constant + 442 410 101 \040 + 349 188 101 \040 + 225 131 101 \040 + w + q + + ap> fitpsf dev$ypix 11.0 icommands=cmdfile verify- + + ... full output will appear in ypix.psf.8 +.fi + + +.ih +BUGS + +In interactive mode the user should not change the type function to be fit +after the first record is written to the output file. In this case the file +header and record structure will not match. + +It is currently the responsibility of the user to make sure that the +image displayed in the frame is the same as that specified by the image +parameter. + +Commands which draw to the image display are disabled by default. +To enable graphics overlay on the image display, set the display +parameter to "imdr", "imdg", "imdb", or "imdy" to get red, green, +blue or yellow overlays and set the mkbox switch to"yes". +It may be necessary to run gflush and to redisplay the image +to get the overlays position correctly. + +.ih +SEE ALSO + +datapars, radprof +.endhelp diff --git a/noao/digiphot/apphot/doc/fitsky.hlp b/noao/digiphot/apphot/doc/fitsky.hlp new file mode 100644 index 00000000..5fc07de9 --- /dev/null +++ b/noao/digiphot/apphot/doc/fitsky.hlp @@ -0,0 +1,632 @@ +.help fitsky Dec92 noao.digiphot.apphot +.ih +NAME +fitsky - determine the mode, sigma and skew of the sky pixels +.ih +USAGE +fitsky image +.ih +PARAMETERS +.ls image +The list of images containing the sky regions to be fit. +.le +.ls coords = "" +The list of text files containing initial coordinates for the objects to +be centered. Objects are listed in coords one object per line with the +initial coordinate values in columns one and two. The number of coordinate +files must be zero, one, or equal to the number of images. +If coords is "default", "dir$default", or a directory specification then an +coords file name of the form dir$root.extension.version is constructed and +searched for, where dir is the directory, root is the root image name, +extension is "coo" and version is the next available version number for the +file. +.le +.ls output = "default" +The name of the results file or results directory. If output is +"default", "dir$default", or a directory specification then an output file name +of the form dir$root.extension.version is constructed, where dir is the +directory, root is the root image name, extension is "sky" and version is +the next available version number for the file. The number of output files +must be zero, one, or equal to the number of image files. In both interactive +and batch mode full output is written to output. In interactive mode +an output summary is also written to the standard output. +.le +.ls plotfile = "" +The name of the file containing radial profile plots of the stars written +to the output file. If plotfile is defined then a radial profile plot +is written to plotfile every time a record is written to \fIoutput\fR. +The user should be aware that this can be a time consuming operation. +.le +.ls datapars = "" +The name of the file containing the data dependent parameters. +The critical parameters \fIfwhmpsf\fR and \fIsigma\fR are located in +datapars. If datapars is undefined then the default parameter set in +uparm directory is used. +.le +.ls fitskypars = "" +The name of the text file containing the sky fitting parameters. The critical +parameters \fIsalgorithm\fR, \fIannulus\fR, and \fIdannulus\fR are located here. +If \fIfitskypars\fR is undefined then the default parameter set in uparm +directory is used. +.le +.ls interactive = yes +Run the task interactively ? +.le +.ls radplots = no +If \fIradplots\fR is "yes" and PHOT is run in interactive mode, a radial +profile of each star is plotted on the screen after the star is measured. +.le +.ls icommands = "" +The image display cursor or image cursor command file. +.le +.ls gcommands = "" +The graphics cursor or graphics cursor command file. +.le +.ls wcsin = ")_.wcsin", wcsout = ")_.wcsout" +The coordinate system of the input coordinates read from \fIcoords\fR and +of the output coordinates written to \fIoutput\fR respectively. The image +header coordinate system is used to transform from the input coordinate +system to the "logical" pixel coordinate system used internally, +and from the internal "logical" pixel coordinate system to the output +coordinate system. The input coordinate system options are "logical", tv", +"physical", and "world". The output coordinate system options are "logical", +"tv", and "physical". The image cursor coordinate system is assumed to +be the "tv" system. +.ls logical +Logical coordinates are pixel coordinates relative to the current image. +The logical coordinate system is the coordinate system used by the image +input/output routines to access the image data on disk. In the logical +coordinate system the coordinates of the first pixel of a 2D image, e.g. +dev$ypix and a 2D image section, e.g. dev$ypix[200:300,200:300] are +always (1,1). +.le +.ls tv +Tv coordinates are the pixel coordinates used by the display servers. Tv +coordinates include the effects of any input image section, but do not +include the effects of previous linear transformations. If the input +image name does not include an image section, then tv coordinates are +identical to logical coordinates. If the input image name does include a +section, and the input image has not been linearly transformed or copied from +a parent image, tv coordinates are identical to physical coordinates. +In the tv coordinate system the coordinates of the first pixel of a +2D image, e.g. dev$ypix and a 2D image section, e.g. dev$ypix[200:300,200:300] +are (1,1) and (200,200) respectively. +.le +.ls physical +Physical coordinates are pixel coordinates invariant with respect to linear +transformations of the physical image data. For example, if the current image +was created by extracting a section of another image, the physical +coordinates of an object in the current image will be equal to the physical +coordinates of the same object in the parent image, although the logical +coordinates will be different. In the physical coordinate system the +coordinates of the first pixel of a 2D image, e.g. dev$ypix and a 2D +image section, e.g. dev$ypix[200:300,200:300] are (1,1) and (200,200) +respectively. +.le +.ls world +World coordinates are image coordinates in any units which are invariant +with respect to linear transformations of the physical image data. For +example, the ra and dec of an object will always be the same no matter +how the image is linearly transformed. The units of input world coordinates +must be the same as those expected by the image header wcs, e. g. +degrees and degrees for celestial coordinate systems. +.le +The wcsin and wcsout parameters default to the values of the package +parameters of the same name. The default values of the package parameters +wcsin and wcsout are "logical" and "logical" respectively. +.le +.le +.ls cache = ")_.cache" +Cache the image pixels in memory. Cache may be set to the value of the apphot +package parameter (the default), "yes", or "no". By default cacheing is +disabled. +.le +.ls verify = ")._verify" +Verify the critical parameters in non-interactive mode ? Verify may be set to + the apphot package parameter value (the default), "yes", or "no. +.le +.ls update = ")_.update" +Update the critical parameters in non-interactive mode if verify is yes ? +Update may be set to the apphot package parameter value (the default), "yes", +or "no. + +.le +.ls verbose = ")_.verbose" +Print messages on the terminal in non-interactive mode ? Verbose may be set to +the apphot package parameter value (the default), "yes", or "no. + +.le +.ls graphics = ")_.graphics" +The default graphics device. Graphics may be set to the apphot package +parameter value (the default), "yes", or "no. +.le +.ls display = ")_.display" +The default display device. Display may be set to the apphot package parameter +value (the default), "yes", or "no. By default graphics overlay is disabled. +Setting display to one of "imdr", "imdg", "imdb", or "imdy" enables graphics +overlay with the IMD graphics kernel. Setting display to "stdgraph" enables +FITSKY to work interactively from a contour plot. +.le + +.ih +DESCRIPTION +FITSKY computes accurate sky values for a set of objects in the IRAF image +\fIimage\fR, whose coordinates are read from the text file \fIcoords\fR or +the image display cursor, and writes the computed sky values to the text +file \fIoutput\fR. + +The coordinates read from \fIcoords\fR are assumed to be in coordinate +system defined by \fIwcsin\fR. The options are "logical", "tv", "physical", +and "world" and the transformation from the input coordinate system to +the internal "logical" system is defined by the image coordinate system. +The simplest default is the "logical" pixel system. Users working on with +image sections but importing pixel coordinate lists generated from the parent +image must use the "tv" or "physical" input coordinate systems. +Users importing coordinate lists in world coordinates, e.g. ra and dec, +must use the "world" coordinate system and may need to convert their +equatorial coordinate units from hours and degrees to degrees and degrees first. + +The coordinates written to \fIoutput\fR are in the coordinate +system defined by \fIwcsout\fR. The options are "logical", "tv", +and "physical". The simplest default is the "logical" system. Users +wishing to correlate the output coordinates of objects measured in +image sections or mosaic pieces with coordinates in the parent +image must use the "tv" or "physical" coordinate systems. + +If \fIcache\fR is yes and the host machine physical memory and working set size +are large enough, the input image pixels are cached in memory. If cacheing +is enabled and FITSKY is run interactively the first measurement will appear +to take a long time as the entire image must be read in before the measurement +is actually made. All subsequent measurements will be very fast because FITSKY +is accessing memory not disk. The point of cacheing is to speed up random +image access by making the internal image i/o buffers the same size as the +image itself. However if the input object lists are sorted in row order and +sparse cacheing may actually worsen not improve the execution time. Also at +present there is no point in enabling cacheing for images that are less than +or equal to 524288 bytes, i.e. the size of the test image dev$ypix, as the +default image i/o buffer is exactly that size. However if the size of dev$ypix +is doubled by converting it to a real image with the chpixtype task then the +effect of cacheing in interactive is can be quite noticeable if measurements +of objects in the top and bottom halfs of the image are alternated. + +FITSKY can be run either interactively or in batch mode by setting the parameter +\fIinteractive\fR. In interactive mode the user may either define the +list of objects to be measured interactively with the image cursor or +create an object list prior to running FITSKY. In either case the user may +adjust the sky fitting parameters until a satisfactory measurement is achieved. +coordinate list with that set of parameters. In batch mode +positions are read from the text file \fIcoords\fR or the image cursor +parameter \fIicommands\fR can be redirected to a cursor command file. + +.ih +CURSOR COMMANDS + +The following cursor commands are currently available. + +.nf + Interactive Keystroke Commands + +? Print help +: Colon commands +v Verify the critical parameters +w Save the current parameters +d Plot radial profile of current star +i Interactively set parameters using current star +f Fit sky for current star +spbar Fit sky for current star, output results +m Move to next star in coordinate list +m Fit sky for next star in coordinate list, output results +l Fit sky for remaining stars in coordinate list, output results +e Print error messages +r Rewind the coordinate list +q Exit task + + + Colon commands + +:show [data/sky] List the parameters +:m [n] Move to the next [nth] star in coordinate list +:n [n] Fit sky to next [nth] star in coordinate list, output results + + Colon Parameter Editing Commands + +# Image and file name parameters + +:image [string] Image name +:coords [string] Coordinate file name +:output [string] Output file name + +# Data dependent parameters + +:scale [value] Image scale (units per pixel) +:fwhmpsf [value] Full width half maximum PSF (scale units) +:emission [y/n] Emission feature (y), absorption (n) +:sigma [value] Standard deviation of sky (counts) +:datamin [value] Minimum good pixel value (counts) +:datamax [value] Maximum good pixel value (counts) + +# Noise parameters + +:noise [string] Noise model (constant|poisson) +:gain [string] Gain image header keyword +:ccdread [string] Readout noise image header keyword +:epadu [value] Gain (electrons per adu) +:readnoise [value] Readout noise (electrons) + +# Observations parameters + +:exposure [string] Exposure time image header keyword +:airmass [string] Airmass image header keyword +:filter [string] Filter image header keyword +:obstime [string] Time of observation image header keyword +:itime [value] Exposure time (time units) +:xairmass [value] Airmass value (number) +:ifilter [string] Filter id string +:otime [string] Time of observation (time units) + +# Sky fitting algorithm parameters + +:salgorithm [string] Sky fitting algorithm +:skyvalue [value] User supplied sky value (counts) +:annulus [value] Inner radius of sky annulus (scale units) +:dannulus [value] Width of sky annulus (scale units) +:khist [value] Sky histogram extent (+/- sky sigma) +:smooth [y/n] Lucy smooth the sky histogram +:binsize [value] Resolution of sky histogram (sky sigma) +:smaxiter [value] Maximum number of iterations +:sloclip [value] Low side clipping factor (percent) +:shiclip [value] High side clipping factor (percent) +:snreject [value] Maximum number of rejection cycles +:sloreject [value] Low side pixel rejection limits (sky sigma) +:shireject [value] High side pixel rejection limits (sky sigma) +:rgrow [value] Region growing radius (scale units) + +# Marking and plotting parameters + +:mksky [y/n] Mark sky annuli on the display +:radplot [y/n] Plot radial profile of sky pixels + + +The following commands are available from within the interactive setup menu. + + + Interactive Fitsky Setup Menu + + v Mark and verify the critical parameters (a,d,s) + + s Mark and verify the standard deviation of the sky + l Mark and verify the minimum good data value + u Mark and verify the maximum good data value + + a Mark and verify the inner radius of the sky annulus + d Mark and verify the width of the sky annulus + g Mark and verify the region growing radius +.fi + +.ih +ALGORITHMS +A brief description of the data dependent parameters and the sky fitting +parameters can be found in the online manual pages for the DATAPARS +and FITSKYPARS tasks. + +.ih +OUTPUT +In interactive mode the following quantities are printed on the standard +output as each object is measured. + +.nf + image xinit yinit msky stdev sskew nsky nsrej error +.fi + +In both interactive and batch mode full output is written to the +text file \fIoutput\fR. At the beginning of each file is a header listing +the current values of the parameters when the first stellar record was +written. These parameters can be subsequently altered. For each star +measured the following record is written. + +.nf + image xinit yinit id coords lid + msky stdev sskew nsky nsrej sier error +.fi + +Image and coords are the name of the image and coordinate file respectively. +Id and lid are the sequence numbers of stars in the output and coordinate +files respectively. Sier and error are the error code and accompanying +error message respectively. Xinit and yinit are the center coordinates +of the sky annulus in pixels. Msky, stdev and sskew are the sky value, +standard deviation and skew respectively. Nsky and nsrej are the number of +sky pixels used and the number of sky pixels rejected respectively. + +In interactive mode a radial profile of each measured object is plotted +in the graphics window if \fIradplots\fR is "yes". + +In interactive and batch mode a radial profile plot is written to +\fIplotfile\fR if it is defined each time the result of an object +measurement is written to \fIoutput\fR . + +.ih +ERRORS +If all goes well during the sky fitting process then the error code sier +will be 0. Non-zero values of sier flag the following error conditions. + +.nf + 0 # No error + 201 # There are no sky pixels in the sky annulus + 202 # Sky annulus is partially off the image + 203 # The histogram of sky pixels has no width + 204 # The histogram of sky pixels is flat or concave + 205 # There are too few points for a good sky fit + 206 # The sky fit is singular + 207 # The sky fit did not converge + 208 # The graphics stream is undefined + 209 # The file of sky values does not exist + 210 # The sky file is at EOF + 211 # Cannot read the sky value correctly + 212 # The best fit parameters are non-physical +.fi + +.ih +EXAMPLES + +1. Compute the sky values for a few stars in dev$ypix using the display +and the image cursor. Setup the task parameters using the interactive +setup menu defined by the i key command and a radial profile plot. + +.nf + ap> display dev$ypix 1 fi+ + + ... display the image + + ap> fitsky dev$ypix + + ... type ? to print an optional help page + + ... move the image cursor to a star + ... type i to enter the interactive setup menu + ... enter maximum radius in pixels of the radial profile or hit + CR to accept the default + ... set the inner and outer sky annuli, and sigma using the + graphics cursor and the stellar radial profile plot + ... typing <CR> leaves everything at the default value + ... type q to quit the setup menu + + ... type the v key to verify the parameters + + ... type the w key to save the parameters in the parameter files + + ... move the image cursor to the stars of interest and tap + the space bar + + ... a one line summary of the fitted parameters will appear on the + standard output for each star measured + + ... type q to quit and q again to confirm the quit + + ... the output will appear in ypix.sky.1 +.fi + +2. Compute the sky values for a few stars in dev$ypix using a contour plot +and the graphics cursor. This option is only useful for those (now very few) +users who have access to a graphics terminal but not to an image display +server. Setup the task parameters using the interactive setup menu defined by +the i key command as in example 1. + +.nf + ap> show stdimcur + + ... record the default value of stdimcur + + ap> set stdimcur = stdgraph + + ... define the image cursor to be the graphics cursor + + ap> contour dev$ypix + + ... make a contour plot of dev$ypix + + ap> contour dev$ypix >G ypix.plot1 + + ... store the contour plot of dev$ypix in the file ypix.plot1 + + ap> fitsky dev$ypix display=stdgraph + + ... type ? to get an optional help page + + ... move graphics cursor to a star + ... type i to enter the interactive setup menu + ... enter maximum radius in pixels of the radial profile or CR + to accept the default value + ... set the inner and outer sky annuli, and sigma using the + graphics cursor and the stellar radial profile plot + ... typing <CR> leaves everything at the default value + ... type q to quit the setup menu + + ... type the v key to verify the critical parameters + + ... type the w key to save the parameters in the parameter files + + ... retype :.read ypix.plot1 to reload the contour plot + + ... move the graphics cursor to the stars of interest and tap + the space bar + + ... a one line summary of the fitted parameters will appear on the + standard output for each star measured + + ... type q to quit and q again to verify + + ... full output will appear in the text file ypix.sky.2 + + ap> set stdimcur = <default> + + ... reset stdimcur to its previous value +.fi + +3. Setup and run FITSKY interactively on a list of objects temporarily +overriding the fwhmpsf, sigma, annulus, and dannulus parameters determined +in examples 1 or 2. + +.nf + ap> daofind dev$ypix fwhmpsf=2.6 sigma=25.0 verify- + + ... make a coordinate list + + ... the output will appear in the text file ypix.coo.1 + + ap> fitsky dev$ypix annulus=12.0 dannulus=5.0 coords=ypix.coo.1 + + ... type ? for optional help + + + ... move the graphics cursor to the stars and tap space bar + + or + + ... select stars from the input coordinate list with m / :m # + and measure with spbar + + ... measure stars selected from the input coordinate list + with n / n # + + ... a one line summary of results will appear on the standard output + for each star measured + + ... type q to quit and q again to confirm the quit + + ... the output will appear in ypix.sky.3 ... +.fi + + +4. Display and measure some stars in an image section and write the output +coordinates in the coordinate system of the parent image. + +.nf + ap> display dev$ypix[150:450,150:450] 1 + + ... display the image section + + ap> fitsky dev$ypix[150:450,150:450] wcsout=tv + + ... move cursor to stars and type spbar + + ... type q to quit and q again to confirm quit + + ... output will appear in ypix.sky.4 + + ap> pdump ypix.sky.4 xi,yi yes | tvmark 1 STDIN col=204 +.fi + +5. Run FITSKY in batch mode using the coordinate file and the previously +saved parameters. Verify the critical parameters. + +.nf + ap> fitsky dev$ypix coords=ypix.coo.1 verify+ inter- + + ... output will appear in ypix.sky.5 ... +.fi + +6. Repeat example 5 but assume that the input coordinate are ra and dec +in degrees and degrees, turn off verification, and submit the task to to +the background. + +.nf + ap> display dev$ypix 1 + + ap> rimcursor wcs=world > radec.coo + + ... move to selected stars and type any key + + ... type ^Z to quit + + ap> fitsky dev$ypix coords=radec.coo wcsin=world verify- inter- & + + ... output will appear in ypix.sky.6 + + ap> pdump ypix.sky.6 xi,yi yes | tvmark 1 STDIN col=204 + + ... mark the stars on the display +.fi + +7. Run FITSKY interactively without using the image display. + +.nf + ap> show stdimcur + + ... record the default value of stdimcur + + ap> set stdimcur = text + + ... set the image cursor to the standard input + + ap> fitsky dev$ypix coords=ypix.coo.1 + + ... type ? for optional help + + ... type :m 3 to set the initial coordinates to those of the + third star in the list + + ... type i to enter the interactive setup menu + ... enter the maximum radius in pixels for the radial profile or + accept the default with a CR + ... type v to enter the default menu + ... set the inner and outer sky annuli, and sigma using the + graphics cursor and the stellar radial profile plot + ... typing <CR> after the prompt leaves the parameter at its default + value + ... type q to quit the setup menu + + ... type r to rewind the coordinate list + + ... type l to measure all the stars in the coordinate list + + ... a one line summary of the answers will appear on the standard + output for each star measured + + ... type q to quit followed by q to confirm the quit + + ... full output will appear in the text file ypix.sky.7 + + ap> set stdimcur = <default> + + ... reset the value of stdimcur +.fi + +8. Use an image cursor command file to drive the FITSKY task. The cursor command +file shown below sets the annulus and dannulus parameters, computes the sky +values for 3 stars, updates the parameter files, and quits the task. + +.nf + ap> type cmdfile + : annulus 12.0 + : dannulus 5.0 + 442 410 101 \040 + 349 188 101 \040 + 225 131 101 \040 + w + q + + ap> fitsky dev$ypix icommands=cmdfile verify- + + ... full output will appear in ypix.sky.8 +.fi + +.ih +TIME REQUIREMENTS + +.ih +BUGS +It is currently the responsibility of the user to make sure that the +image displayed in the frame is the same as that specified by the image +parameter. + +Commands which draw to the image display are disabled by default. +To enable graphics overlay on the image display, set the display +parameter to "imdr", "imdg", "imdb", or "imdy" to get red, green, +blue or yellow overlays and set the fitskypars mksky switch to"yes". +It may be necessary to run gflush and to redisplay the image +to get the overlays position correctly. + +.ih +SEE ALSO +datapars, fitskypars, phot, polyphot, radprof +.endhelp diff --git a/noao/digiphot/apphot/doc/fitskypars.hlp b/noao/digiphot/apphot/doc/fitskypars.hlp new file mode 100644 index 00000000..cdb541ba --- /dev/null +++ b/noao/digiphot/apphot/doc/fitskypars.hlp @@ -0,0 +1,219 @@ +.help fitskypars May00 noao.digiphot.apphot +.ih +NAME +fitskypars - edit the sky fitting algorithm parameters +.ih +USAGE +fitskypars +.ih +PARAMETERS +.ls salgorithm = "centroid" +The sky fitting algorithm to be employed. The sky fitting options are: +.ls constant +Use a user supplied constant value \fIskyvalue\fR for the sky. +This algorithm is useful for measuring large resolved objects on flat +backgrounds such as galaxies or comments. +.le +.ls file +Read sky values from a text file. This option is useful for importing +user determined sky values into APPHOT. +.le +.ls mean +Compute the mean of the sky pixel distribution. This algorithm is useful +for computing sky values in regions with few background counts. +.le +.ls median +Compute the median of the sky pixel distribution. This algorithm is a useful +for computing sky values in regions with rapidly varying sky backgrounds +and is a good alternative to "centroid". +.le +.ls mode +Compute the mode of the sky pixel distribution using the computed mean and +median. This is the recommended algorithm for APPHOT users trying to +measuring stellar objects in crowded stellar fields. Mode may not perform +well in regions with rapidly varying sky backgrounds. +.le +.ls centroid +Compute the intensity-weighted mean or centroid of the sky pixel histogram. +This is the algorithm recommended for most APPHOT users. It is reasonably +robust in rapidly varying and crowded regions. +.le +.ls gauss +Fit a single Gaussian function to the sky pixel histogram using non-linear +least-squares techniques. +.le +.ls ofilter +Compute the sky using the optimal filtering algorithm and a triangular +weighting function and the histogram of the sky pixels. +.le +.ls crosscor +Compute the sky value using the cross-correlation function of the sky pixel +histogram and a Gaussian noise function with a sigma equal to the +computed sigma of the sky pixel distribution. +.le +.ls histplot +Mark the peak of the histogram of the sky pixels on a plot of the histogram. +This algorithm is useful for making careful interactive sky measurements +for a small number of objects in complicated regions or for checking the +behavior of other sky algorithms. +.le +.ls radplot +Mark the sky value on a radial distribution plot of the sky pixels. +This algorithm is useful for making careful interactive sky measurements +for a small number of objects in complicated regions or for checking the +behavior of other sky algorithms. +.le +.le +.ls annulus = 10.0 (scale units) +The inner radius of the annular sky fitting region in units of the DATAPARS +scale parameter. +.le +.ls dannulus = 10.0 (scale units) +The width of the annular sky fitting region in units of the DATAPARS +scale parameter. +.le +.ls skyvalue +The constant for constant sky subtraction. +.le +.ls smaxiter = 10 +The maximum number of iterations performed by the sky fitting algorithm. +\fISmaxiter\fR is required by the "gauss" and "ofilter" sky fitting algorithms. +.le +.ls sloclip = 0.0 (percent) +The low-side clipping factor in percentage points of the total number of +sky pixels. +.le +.ls shiclip = 0.0 (percent) +The high-side clipping factor in percentage points of the total number of +sky pixels. +.le +.ls snreject = 50 +The maximum number of pixel rejection cycles. +.le +.ls sloject = 3.0 +The ksigma low-side clipping factor for the pixel rejection phase of the +sky fitting algorithm. \fIsloreject\fR is in units of the computed sky +sigma. +.le +.ls shiject = 3.0 +The ksigma high-side clipping factor for the pixel rejection phase of the +sky fitting algorithm. \fIshireject\fR is in units of the computed sky +sigma. +.le +.ls khist = 3.0 +The ksigma clipping factor for computing the histogram of the sky pixels. +\fIKhist\fR is in units of the computed sky sigma. +The computed histogram will be 2.0 * khist * sigma wide. +.le +.ls binsize = 0.10 +The width of a single bin of the histogram of sky values. +\fIBinsize\fR is in units of the computed sky sigma. +.le +.ls smooth = no +Boxcar smooth the histogram before computing a sky value ? +.le +.ls rgrow = 0.0 (scale units) +The region growing radius for pixel rejection in the sky region, in units +of the DATAPARS \fIscale\fR parameter. When a bad sky pixel is detected, +all pixels within rgrow / scale will be rejected. If rgrow is 0.0 +region growing is not performed. +.le +.ls mksky = no +Mark the sky annulus on the displayed image ? +.le +.ih +DESCRIPTION +The sky fitting algorithm parameters control the action of the sky fitting +algorithms. The default parameter settings should give reasonable results in +the majority of cases. Several of the sky fitting parameters scale with +image scale, \fIscale\fR which is data dependent. \fIScale\fR is defined in +the DATAPARS parameter set. + +Sky pixels in an annular region of inner radius \fIannulus / scale\fR pixels +and a width of \fIdannulus / scale\fR pixels are extracted from the IRAF image. +If the \fIscale\fR parameter is defined in terms of the number of half-width +at half-maximum of the point spread function per pixel, then single values of +annulus and dannulus will work well for images with different seeing and +detector characteristics. + +Pixels outside of the good data range specified by \fIdatamin\fR and +\fIdatamax\fR are rejected from the sky pixel distribution. After bad +data rejection \fIPloclip\fR and \fIphiclip\fR percent pixels are rejected +from the low and high sides of the sorted pixel distribution before any +sky fitting is done. + +Sky values are computed using the sky fitting algorithm specified by +\fIsalgorithm\fR. The default value is "centroid". If \fIsalgorithm\fR += "mean", "median" or "mode", the sky value is computed directly from the +array of sky pixels. The remaining sky fitting algorithms use the histogram +of the object sky pixels. The computed histogram is \fIkhist\fR * sigma wide +with a bin width of \fIbinsize\fR * sigma where sigma is the computed +standard deviation of the sky pixels for each object. If \fIsmooth\fR = yes, +boxcar smoothing is performed on the computed histogram before sky fitting. +The mode of the histogram is computed using, a non-linear least squares +fit to a Gaussian (salgorithm = "gauss"), optimal filtering of the histogram +(salgorithm = "ofilter"), computing the intensity weighted mean of the +histogram (salgorithm = "centroid"), or by cross-correlation techniques +(salgorithm = "crosscor"). + +Two interactive methods of fitting sky are also available. If \fIsalgorithm\fR +is "radplot" or "histplot", the user must interactively set the value of the +sky using a radial profile or a histogram profile plot. + +Pixels which deviate from the sky value by more than \fIkreject\fR times the +computed sky sigma are rejected from the fit. If \fIrgrow\fR > 0, pixels +within a radius of rgrow / scale of the rejected pixel are also rejected from +the fit. The rejection procedure iterates until no further pixels are rejected, +all pixels are rejected, or the maximum number of rejection cycles +\fIsnreject\fR iterations is reached. + +.ih +EXAMPLES +1. List the sky fitting parameters. + +.nf + ap> lpar fitskypars +.fi + +2. Edit the sky fitting parameters. + +.nf + ap> fitskypars +.fi + +3. Edit the FITSKYPARS parameters from within the PHOT task. + +.nf + da> epar phot + + ... edit a few phot parameters + + ... move to the fitskypars parameter and type :e + + ... edit the fitskypars parameters and type :wq + + ... finish editing the phot parameters and type :wq +.fi + +4. Save the current FITSKYPARS parameter set in a text file skynite1.par. +This can also be done from inside a higher level task as in the +above example. + +.nf + da> fitskypars + + ... edit some parameters + + ... type ":w skynite1.par" from within epar +.fi + +.ih +TIME REQUIREMENTS + +.ih +BUGS + +.ih +SEE ALSO +radprof,fitsky,phot,wphot,polyphot +.endhelp diff --git a/noao/digiphot/apphot/doc/pexamine.hlp b/noao/digiphot/apphot/doc/pexamine.hlp new file mode 100644 index 00000000..f3a031ec --- /dev/null +++ b/noao/digiphot/apphot/doc/pexamine.hlp @@ -0,0 +1,836 @@ +.help pexamine May00 noao.digiphot.apphot +.ih +NAME +pexamine -- interactively examine or edit a photometry catalog +.ih +USAGE +pexamine input output image +.ih +PARAMETERS +.ls input +The name of the input photometry catalog. \fIInput\fR may be either an +APPHOT/DAOPHOT text database file or an STSDAS binary table database. +.le +.ls output +The name of the edited output catalog. \fIOutput\fR is either an +APPHOT/DAOPHOT text database or an STSDAS binary table database +depending on the file type of \fIinput\fR. If \fIoutput\fR = "" no output +catalog is written. +.le +.ls image +The name of the input image corresponding to the input photometry +catalog. If \fIimage\fR is "" no image will be attached to PEXAMINE +and some interactive catalog examining commands will not be available. +All the catalog editing commands however are still available. +.le +.ls deletions = "" +The name of an optional output deletions photometry catalog. \fIDeletions\fR +is either an APPHOT/DAOPHOT text database or an STSDAS binary +table database depending on the file type of \fIinput\fR. If \fIdeletions\fR +is "" no deletions file is written. +.le +.ls photcolumns = "apphot" +The list of standard photometry columns that are loaded when pexamine is +run. The options are listed below. +.ls "apphot" +The standard columns for the APPHOT package. The current list is ID, +XCENTER, YCENTER, MSKY, MAG, and MERR. +If any of these +columns are multi-valued, (as in the case of magnitudes measured through +more than one aperture), the first value is selected. +The standard list may easily be extended at user request. +.le +.ls "daophot" +The standard columns for the DAOPHOT package. The current list is GROUP, ID, +XCENTER, YCENTER, MSKY, MAG, MERR, CHI, SHARP and NITER. +If any of these +columns are multi-valued, (as in the case of magnitudes measured through +more than one aperture), the first value is selected. +The standard list may easily be extended at user request. +.le +.ls user list +A user supplied list of standard columns. +Column names are listed in full in either upper or +lower case letters, separated by commas. If more than one value of +a multi-valued column is requested +the individual values +must be listed separately as in the following example +ID, XCENTER, YCENTER, MAG[1], MERR[1], MAG[2], MERR[2]. +.le + +\fIPhotcolumns\fR can be changed interactively from within PEXAMINE at +the cost of rereading the database. +.le +.ls xcolumn = "mag" (magnitude), ycolumn = "merr" (magnitude error) +The names of the two columns which define the default X-Y plot. +\fIXcolumn\fR and \fIycolumn\fR must be listed in \fIphotcolumns\fR or +\fIusercolumns\fR but may be changed interactively by the user. +If either \fIxcolumn\fR or \fIycolumn\fR is a multi-valued quantity +and more than one value is listed in \fIphotcolumns\fR or \fIusercolumns\fR +then the desired value number must be specified explicitly in, e.g. +MAG[2] or MERR[2]. +.le +.ls hcolumn = "mag" (magnitude) +The name of the column which defines the default histogram plot. +\fIHcolumn\fR must be listed in \fIphotcolumns\fR or +\fIusercolumns\fR but may be changed interactively by the user. +If \fIhcolumn\fR is a multi-valued quantity and more than one value is +listed in \fIphotcolumns\fR or \fIusercolumns\fR then the desired value +must be specified explicitly in \fIhcolumn\fR, e.g. MAG[2]. +.le +.ls xposcolumn = "xcenter", yposcolumn = "ycenter" +The names of the two columns which define the X and Y coordinates in +\fIimage\fR of the objects in the catalog. This information is +required if the image display and image cursor are to be used to visually +identify objects in the image with objects in the catalog or if plots +of image data are requested. \fIXposcolumn\fR and \fIyposcolumn\fR must +be listed in \fIphotcolumns\fR or \fIusercolumns\fR but may +be changed interactively by the user. +.le +.ls usercolumns = "" +The list of columns loaded into memory in addition to the +standard photometry columns \fIphotcolumns\fR. The column +names are listed in full in upper or lower case letters and separated by +commas. +\fIUsercolumns\fR can be changed interactively from within PEXAMINE at +the cost of rereading the database. +.le +.ls first_star = 1 +The index of the first object to be read out of the catalog. +.le +.ls max_nstars = 5000 +The maximum number of objects that are loaded into memory at task +startup time, beginning at object \fIfirst_star\fR. If there are more +than \fImax_nstars\fR in the catalog only the first \fImax_nstars\fR +objects are read in. +.le +.ls match_radius = 2.0 +The tolerance in pixels to be used for matching objects in the catalog with +objects marked on the display with the image cursor. +.le +.ls graphics = "stdgraph" +The default graphics device. +.le +.ls use_display = yes +Use the image display? Users without access to an image display should +set \fIuse_display\fR to "no". +.le +.ls icommands = "" +The image display cursor. If null the standard image cursor is used whenever +image cursor input is requested. A cursor file in the appropriate +format may be substituted by specifying the name of the file. +Also the image cursor may be changed to query the graphics device or the +terminal by setting the environment variable "stdimcur" to "stdgraph" +or "text" respectively. +.le +.ls gcommands = "" +The graphics cursor. If null the standard graphics cursor is used whenever +graphics cursor input is requested. A cursor file in the appropriate +format may be substituted by specifying the name of the file. +.le + +.ih +PLOTTING PARAMETERS + +PEXAMINE supports five types of plots 1) an X-Y column plot +2) a histogram column plot 3) a radial profile plot 4) a surface +plot and 5) a contour plot. +Each supported plot type has its own parameter set which +controls the appearance of the plot. +The names of the five parameter sets are listed below. + +.nf + cntrplot Parameters for the contour plot + histplot Parameters for the column histogram plot + radplot Parameters for radial profile plot + surfplot Parameters for surface plot + xyplot Parameters for the X-Y column plot +.fi + +The same parameters dealing with graph formats occur in many of the parameter +sets while some are specific only to one parameter set. In the +summary below those common to more than one parameter set are shown +only once. The characters in parenthesis are the graph key prefixes +for the parameter sets in which the parameter occurs. + +.ls angh = -33., angv = 25. (s) +Horizontal and vertical viewing angles in degrees for surface plots. +.le +.ls axes = yes (s) +Draw axes along the edge of surface plots? +.le +.ls banner = yes (chrsx) +Add a standard banner to a graph? The standard banner includes the +IRAF user and host identification and the date and time. +.le +.ls box = yes (chrx) +Draw graph box and axes? +.le +.ls ceiling = INDEF (cs) +Ceiling data value for contour and surface plots. A value of INDEF does +not apply a ceiling. In contour plots a value of 0. also does not +apply a ceiling. +.le +.ls dashpat = 528 (c) +Dash pattern for negative contours. +.le +.ls fill = no (yes) (c) (hrx) +Fill the output viewport regardless of the device aspect ratio? +.le +.ls floor = INDEF (cs) +Floor data value for contour and surface plots. A value of INDEF does +not apply a floor. In contour plots a value of 0. also does not +apply a floor. +.le +.ls grid = no (rx) +Draw grid lines at major tick marks? +.le +.ls interval = 0.0 (c) +Contour interval. If 0.0, a contour interval is chosen which places 20 to 30 +contours spanning the intensity range of the image. +.le +.ls label= no (c) +Label the major contours in the contour plot? +.le +.ls logx = no, logy = no (rx) (hrx) +Plot the x or y axis logarithmically? The default for histogram plots is +to plot the y axis logarithmically. +.le +.ls majrx=5, minrx=5, majry=5, minry=5 (chrx) +Maximum number of major tick marks on each axis and number of minor tick marks +between major tick marks. +.le +.ls marker = "box" (rx) +Marker to be drawn. Markers are "point", "box", +"cross", "plus", "circle", "hline", "vline" or "diamond". +.le +.ls nbins = 512 (h) +The number of bins in, or resolution of, histogram plots. +.le +.ls ncolumns = 21, nlines = 21 (cs) +Number of columns and lines used in contour and surface plots. +.le +.ls ncontours = 5 (c) +Number of contours to be drawn. If 0, the contour interval may be specified, +otherwise 20 to 30 nicely spaced contours are drawn. A maximum of 40 contours +can be drawn. +.le +.ls nhi = -1 (c) +If -1, highs and lows are not marked. If 0, highs and lows are marked +on the plot. If 1, the intensity of each pixel is marked on the plot. +.le +.ls rinner = 0, router = 8 +The inner and outer radius of the region whose radial profile is to +be plotted. +.le +.ls round = no (chrx) +Extend the axes up to "nice" values? +.le +.ls szmarker = 1 (rx) +Size of mark except for points. A positive size less than 1 specifies +a fraction of the device size. Values of 1, 2, 3, and 4 signify +default sizes of increasing size. +.le +.ls ticklabels = yes (chrx) +Label the tick marks? +.le +.ls top_closed = no (h) +Include z2 in the top histogram bin? Each bin of the histogram is a +subinterval that is half open at the top. \fITop_closed\fR decides whether +those pixels with values equal to z2 are to be counted in the histogram. If +\fBtop_closed\fR is yes, the top bin will be larger than the other bins. +.le +.ls x1 = INDEF, x2 = INDEF, y1 = INDEF, y2 = INDEF (hrx) +Range of graph along each axis. If INDEF the range is determined from +the data range. The default y1 for histogram plots is 0. +.le +.ls zero = 0. (c) +Greyscale value of the zero contour, i.e., the value of a zero point shift +to be applied to the image data before plotting. Does not affect the values +of the floor and ceiling parameters. +.le +.ls z1 = INDEF, z2 = INDEF (h) +Range of pixel values to be used in histogram. INDEF values default to +the range in the region being histogramed. +.le + +.ih +DESCRIPTION + +PEXAMINE is a general purpose tool for interactively examining and editing +photometry catalogs produced by the APPHOT or DAOPHOT packages. It is +intended to aid the user in assessing the accuracy of the photometry, +in diagnosing problems with particular catalog objects, +in searching the photometry data for relationships +between the computed quantities, and in editing the catalog based on +those observed relationships. PEXAMINE is intended to complement the +more batch oriented editing facilities of the SELECT task. + +PEXAMINE takes the input catalog \fIinput\fR and the corresponding +image \fIimage\fR (if defined) and produces an output catalog of selected +objects \fIoutput\fR (if defined) and an output catalog of deleted objects +\fIdeletions\fR (if defined). The input catalog may be either an +APPHOT/DAOPHOT text database or an ST binary table database. +The file type of the output catalogs \fIoutput\fR and \fIdeletions\fR +is the same as that of \fIinput\fR. + +READING IN THE DATA + +PEXAMINE reads the column data specified by \fIphotcolumns\fR and +\fIusercolumns\fR for up to \fImax_nstars\fR beginning at star +\fIfirst_star\fR into memory. +The \fIphotcolumns\fR parameter +defines the list of standard photometry columns to be loaded. If +"daophot" or "apphot" is selected then the standard columns +are GROUP, ID, XCENTER, YCENTER, MSKY, MAG, MERR, CHI, SHARP and NITER +and ID, XCENTER, YCENTER, MSKY, MAG and MERR respectively. +Otherwise the user must set \fIphotcolumns\fR to his or her own preferred +list of standard photometry columns. Non-standard columns may also be +specified using the parameter \fIusercolumns\fR. +Valid column lists contain the full names of the specified columns +in upper or lower case letters, separated by commas. +Either \fIphotcolumns\fR or +\fIusercolumns\fR may be redefined interactively by the user after +the task has started up, but only at the +expense of rereading the data from \fIinput\fR. + +PEXAMINE will fail to load a specified column if that column is +not in the photometry database, is of a datatype other than +integer or real, or adding that column would exceed the maximum +number of columns limit currently set at twenty. The user can +interactively examine the list of requested and loaded standard +photometry columns, as well as list all the columns in the input +after the task has started up. + +GRAPHICS AND IMAGE COMMAND MODE + +PEXAMINE accepts commands either from the graphics cursor \fIgcommands\fR +(graphics command mode) or the image display cursor \fIicommands\fR +if available (image command mode). +PEXAMINE starts up in graphics command mode, but all the +interactive commands are accessible from both modes and the user can +switch modes at any time assuming that the \fIuse_display\fR parameter +is set to "yes". + +PEXAMINE interprets the cursor position in graphics command mode +differently from how it interprets it in image command mode. +In graphics command mode the cursor coordinates are the position +of the cursor in the current plot, whereas in image command mode they +are the x and y coordinates of the cursor in the displayed image. +For example, if the user issues a command to PEXAMINE to locate the object +in the catalog nearest the point in the current X-Y plot marked by +the graphics cursor, PEXAMINE does so by searching +the data for the object whose values of \fIxcolumn\fR and \fIycolumn\fR +most closely match those of the current cursor position. +If the user issues a command to PEXAMINE to locate the +object in the catalog corresponding to the object marked on the image +display with the image cursor, +PEXAMINE does so by searching the data for +the object whose values of \fIxposcolumn\fR and \fIyposcoumn\fR +most closely match and fall within \fImatch_radius\fR of the current +cursor position. + +Input to PEXAMINE is through single keystroke commands or colon +commands. Keystroke commands are simple commands that may +optionally use the cursor position but otherwise require no arguments. +The PEXAMINE keystroke commands fall into three categories, basic +commands, data examining commands and data editing commands, all +described in detail in the following sections. Colon commands +take an optional argument and function differently depending on +the presence or absence of that argument. When the argument is absent +colon commands are used to display the +current value of a parameter or list of parameters. When the argument is +present they change their current value to that argument. +The basic colon commands are described in detail below. + +BASIC KEYSTROKE COMMANDS + +These keystroke commands are used to display the help page, switch from +graphics to image command mode and quit the task. + +.ls ? +Page through the help for the PEXAMINE task +.le +.ls : +Execute a PEXAMINE colon command. +.le +.ls g +Change to graphics command mode. Throughout PEXAMINE graphics command mode +is the default. All PEXAMINE commands are available in graphics command +mode. +.le +.ls i +Change to image command mode. +All the PEXAMINE commands are available in image command mode. +However if \fIuse_display\fR is no and the image +cursor has not been aliased to the standard input or a text file +image command mode is disabled. +.le +.ls q +Quit PEXAMINE without writing an output catalog. +PEXAMINE queries the user for confirmation of this option. +.le +.ls e +Quit PEXAMINE and write the output catalog. +.le + +DATA EXAMINING COMMANDS + +The data examining commands fall into two categories, those that examine +the catalog data including 'l' (catalog listing), 'o' (object listing), +'x' (Y column versus X column plot) and 'h' (histogram column plot) +commands, and those which examine the image data around specific catalog +objects including 'r' (radial profile plotting), 's' (surface plotting), +'c' (contour plotting) and 'm' (pixel dumping). The latter group +require that \fIimage\fR be defined. A brief summary of each data +examining command is given below. +.ls l +Print out the name, datatype, and units for all the columns in the input +catalog. The list command can be used to check the contents of the input +catalog and/or determine why a particualar column was not loaded. +.le +.ls o +Print out the names and values of the stored columns of the object +nearest the cursor. In graphics mode the current plot type must be +X-Y. In image command mode the object nearest the cursor must also be +no more than \fImatch-radius\fR pixels away from the image cursor to be +found. If an object is found and the current plot type is X-Y +the graphics cursor is moved to the position of the selected object +in the X-Y plot. +.le +.ls x +Plot the data in \fIycolumn\fR versus the data in \fIxcolumn\fR excluding +any already deleted points and identifying objects marked for deletion +with a cross. X-Y plotting is undefined if \fIxcolumn\fR or \fIycolumn\fR +is undefined. +.le +.ls h +Plot the histogram of the data in \fIhcolumn\fR excluding any already +deleted points and those marked for deletion. Histogram plotting is +disabled if \fIhcolumn\fR is undefined. +.le +.ls r +Plot the radial profile of the object nearest the cursor including +only pixels within a distance of \fIrinner\fR and \fRrouter\R of +the object center. Radial profile plotting is disabled if \fIimage\fR +or \fIxposcolumn\fR or \fIyposcolumn\fR is undefined. +.le +.ls s +Plot the surface plot of the object nearest the cursor including +only pixels within an image section \fIncols\fR by \fInlines\fR +around the object center. Surface plotting is disabled if \fIimage\fR +or \fIxposcolumn\fR or \fIyposcolumn\fR is undefined. +.le +.ls c +Plot the contour plot of the object nearest the cursor including +only pixels within an image section \fIncols\fR by \fInlines\fR +around the object center. Contour plotting is disabled if \fIimage\fR +or \fIxposcolumn\fR or \fIyposcolumn\fR is undefined. +.le +.ls m +Dump the pixel values of a grid of 10 by 10 pixels around the object +nearest the cursor. Pixel value dumping is disabled if \fIimage\fR +or \fIxposcolumn\fR or \fIyposcolumn\fR is undefined. +.le +.ls p +Replot the current graph. +.le + +DATA EDITING COMMANDS + +Data points can be deleted from the catalog in either graphics command +mode or image +command mode. In graphics command mode the +graphics cursor and either the X-Y or histogram plot is used to delete points. +In image command mode the image cursor and the displayed +image are used to delete points. A data point has three possible states +good, marked for deletion and deleted. +Any one of the keystroke commands 'd' (delete point), '(' (delete points +with x less than x cursor), ')' (delete points with x greater than x cursor, +'^' (delete points with y > y cursor), 'v' (delete points with y < y cursor) +or 'b' (delete points in a box) can be used to mark points for deletion. +The 'f' key is used to actually delete the points and replot the data. +In between marking the points for deletion and actually deleting the marked +points the 't' (toggle) key can be used to undelete the last set marked. +The full list of the data editing keystroke commands is given below. + +.ls z +Undelete not just unmark all the data points replot. +.le +.ls f +Delete points marked for deletion and replot. Points marked for deletion +but not actually deleted will be written to the output catalog and not +written to the deletions catalog. +.le +.ls d +Mark the point nearest the cursor for deletion. +.le +.ls u +Undelete the marked point nearest the cursor. +.le +.ls ( +Mark all points with x values less than the x value of the cursor for +deletion. In graphics command mode points can only be marked for deletion if +the current plot type is "xyplot" or "histplot". In image command +mode \fIxposcolumn\fR and \fIyposcolumn\fR must be defined before +points can be marked for deletion. +.le +.ls ) +Mark all points with x values greater than the x value of the cursor for +deletion. In graphics command mode points can only be marked for deletion if +the current plot type is "xyplot" or "histplot". In image command +mode \fIxposcolumn\fR and \fIyposcolumn\fR must be defined before +points can be marked for deletion. +.le +.ls v +Mark all points with y values less than the y value of the cursor for +deletion. In graphics command mode points can only be marked for deletion if +the current plot type is "xyplot". In image command +mode \fIxposcolumn\fR and \fIyposcolumn\fR must be defined before +points can be marked for deletion. +.le +.ls ^ +Mark all points with y values greater than the y value of the cursor for +deletion. In graphics command mode points can only be marked for deletion if +the current plot type is "xyplot". In image command +mode \fIxposcolumn\fR and \fIyposcolumn\fR must be defined before +points can be marked for deletion. +.le +.ls b +Mark all points within a box whose lower left and upper right hand corners +are marked by the cursor for deletion. +In graphics mode points can only be marked for deletion if the current +plot type is "xyplot". In image command mode \fIxposcolumn\fR and +\fIyposcolumn\fR must be defined before points can be marked for +deletion. +.le +.ls t +Toggle between marking points for deletion or undeletion. The default +is to mark points for deletion. +.le + +BASIC COLON COMMANDS + +All the PEXAMINE parameters can be changed interactively with colon +commands, including those which determine which data is read in, +which data is plotted and the parameters of each plot. A brief description +of the basic commands is given here. The full list is given in the +following section. + +.ls :photcolumns [col1,col2,...] +Show or set the list of requested standard photometry columns and the list +of loaded +photometry columns. If the user supplies a new list of columns the data will be +reread from disk. +.le +.ls :usercolumns [col1,col2,...] +Show or set the list of requested user columns and the list of loaded +user columns. If the user supplies a new list of columns the data will be +reread from disk. +.le +.ls :xcolumn [colname] +Show or set the name of the column to be plotted along the x axis of the +X-Y plot. +.le +.ls :ycolumn [colname] +Show or set the name of the column to be plotted along the y axis of the +X-Y plot. +.le +.ls :hcolumn [colname] +Show or set the name of the column to be whose histogram is to be plotted. +.le +.ls :eparam [cntrplot/histplot/radplot/surfplot/xyplot] +Review or edit the list of parameters for the various plot types. +.le +.ls :unlearn [cntrplot/histplot/radplot/surfplot/xyplot] +Return the list of parameters for the various plot types to their default +values. +.le +.ls :x y key cmd +Execute any defined keystroke "key" supplying the appropriate x and y +value in place of the cursor position. In graphics command mode the x +and y position are assumed to be the position in the current graph. +In image command mode the x and y position are assumed to be the x and +y coordinate in the image display. +.le + +.ih +CURSOR COMMANDS + +.nf + PEXAMINE Interactive Cursor Keystroke Commands + + Basic Commands + +? Print help for the PEXAMINE task +: PEXAMINE colon commands +g Activate the graphics cursor +i Activate the image cursor +e Exit PEXAMINE and save the edited catalog +q Quit PEXAMINE and discard the edited catalog + + Data Examining Commands + +l List the name, datatype and units for all columns in the catalog +o Print out the names and values of the stored columns for the + object nearest the cursor +x Replot the current y column versus the current x column +h Replot the current histogram +r Plot the radial profile of the object nearest the cursor +s Plot the surface of the object nearest the cursor +c Plot the contour plot of the object nearest the cursor +m Print the data values of the object nearest the cursor +p Replot the current graph + + Data Editing Commands + +z Reinitialize the data by removing all deletions and replot +d Mark the point nearest the cursor for deletion +u Undelete the marked point nearest the cursor +t Toggle between marking points for deletion or undeletion +( Mark points with X < X (cursor) for deletion or undeletion +) Mark points with X > X (cursor) for deletion or undeletion +v Mark points with Y < Y (cursor) for deletion or undeletion +^ Mark points with Y > Y (cursor) for deletion or undeletion +b Mark points inside a box for deletion or undeletion +f Actually delete the marked points and replot + + + PEXAMINE Interactive Colon Commands + +:xcolumn [name] Show/set the X-Y plot X axis quantity +:ycolumn [name] Show/set the X-Y plot Y axis quantity +:hcolumn [name] Show/set the histogram plot quantity +:photcolumns [col1,col2,...] Show/set the list of photometry columns +:usercolumns [col1,col2,...] Show/set the list of user columns +:delete [yes/no] Delete or undelete points +:eparam [x/h/r/s/c] Edit/unlearn the specified plot pset + or +:unlearn + + + PEXAMINE Interactive X-Y Plotting Commands + +:x1 [value] Left world x-coord if not autoscaling +:x2 [value] Right world x-coord if not autoscaling +:y1 [value] Lower world y-coord if not autoscaling +:y2 [value] Upper world y-coord if not autoscaling +:szmarker [value] Marker size +:marker [point|box|plus|cross|circle|diamond|hline|vline] Marker type +:logx [yes/no] Log scale the x axis? +:logy [yes/no] Log scale the y axis? +:box [yes/no] Draw box around periphery of window? +:ticklabels [yes/no] Label tick marks? +:grid [yes/no] Draw grid lines at major tick marks? +:majrx [value] Number of major divisions along x axis +:minrx [value] Number of minor divisions along x axis +:majry [value] Number of major divisions along y axis +:minry [value] Number of minor divisions along y axis +:round [yes/no] Round axes to nice values? +:fill [yes/no] Fill viewport vs enforce unity aspect ratio? + + + PEXAMINE Interactive Histogram Plotting Commands + +:nbins [value] Number of bins in the histogram +:z1 [value] Minimum histogram intensity +:z2 [value] Maximum histogram intensity +:top_closed [y/n] Include z in the top bin? +:x1 [value] Left world x-coord if not autoscaling +:x2 [value] Right world x-coord if not autoscaling +:y1 [value] Lower world y-coord if not autoscaling +:y2 [value] Upper world y-coord if not autoscaling +:logy [yes/no] Log scale the y axis? +:box [yes/no] Draw box around periphery of window? +:ticklabels [yes/no] Label tick marks? +:majrx [value] Number of major divisions along x axis +:minrx [value] Number of minor divisions along x axis +:majry [value] Number of major divisions along y axis +:minry [value] Number of minor divisions along y axis +:round [yes/no] Round axes to nice values? +:fill [yes/no] Fill viewport vs enforce unity aspect ratio? + + PEXAMINE Interactive Radial Profile Plotting Commands + +:rinner [value] Inner radius of the region to be plotted +:router [value] Outer radius of the region to be plotted +:x1 [value] Left world x-coord if not autoscaling +:x2 [value] Right world x-coord if not autoscaling +:y1 [value] Lower world y-coord if not autoscaling +:y2 [value] Upper world y-coord if not autoscaling +:szmarker [value] Marker size +:marker [point|box|plus|cross|circle|diamond|hline|vline] Marker type +:logx [yes/no] Log scale the x axis? +:logy [yes/no] Log scale the y axis? +:box [yes/no] Draw box around periphery of window? +:ticklabels [yes/no] Label tick marks? +:grid [yes/no] Draw grid lines at major tick marks? +:majrx [value] Number of major divisions along x axis +:minrx [value] Number of minor divisions along x axis +:majry [value] Number of major divisions along y axis +:minry [value] Number of minor divisions along y axis +:round [yes/no] Round axes to nice values? +:fill [yes/no] Fill viewport vs enforce unity aspect ratio? + + + PEXAMINE Interactive Surface Plotting Commands + +:ncolumns [value] Number of columns to be plotted +:nlines [value] Number of lines to be plotted +:axes [yes/no] Draw axes? +:angh [value] Horizontal viewing angle +:angv [value] Vertical viewing angle +:floor [value] Minimum value to be plotted +:ceiling [value] Maximum value to be plotted + + + PEXAMINE Interactive Contour Plotting Commands + +:ncolumns [value] Number of columns to be plotted +:nlines [value] Number of lines to be plotted +:floor [value] Minimum value to be plotted +:ceiling [value] Maximum value to be plotted +:zero [value] Greyscale value of zero contour +:ncontours [value] Number of contours to be drawn +:interval [value] Contour interval +:nhi [value] Hi/low marking option +:dashpat [value] Bit pattern for generating dashed lines +:label [yes/no] Label major contours with their values? +:box [yes/no] Draw box around periphery of window? +:ticklabels [yes/no] Label tick marks? +:majrx [value] Number of major divisions along x axis +:minrx [value] Number of minor divisions along x axis +:majry [value] Number of major divisions along y axis +:minry [value] Number of minor divisions along y axis +:round [yes/no] Round axes to nice values? +:fill [yes/no] Fill viewport vs enforce unity aspect ratio? +.fi + +.ih +EXAMPLES + +1. Examine and edit an APPHOT aperture photometry catalog and a DAOPHOT +allstar catalog without either attaching the associated image or using the +image display. + +.nf + pt> pexamine m92.mag.1 m92.mag.ed use_display- + + ... a plot of magnitude error versus magnitude appears on + the screen and the graphics cursor comes up ready to accept + commands + + ... the user sees a generally smooth trend of increasing + magnitude error with increasing magnitude except for a + single deviant point at the bright end of the plot + + ... the user decides to remove the deviant point using the + 'd' keystroke command to mark the point and the 'f' + keystroke command to actually delete and replot the graph + + ... after examining the plot further the user decides to delete + all objects for which the magnitude error is > 0.1 magnitudes + using the '^' keystroke command, followed by the 'f' + keystroke command to actually replot and delete the data. + + ... after deciding that this new plot is satisfactory the user + issues the 'e' keystroke command to exit pexamine and save + the good data in m92.mag.ed + + pt> pexamine m92.als.1 m92.als.ed use_display- + + ... a plot of magnitude error versus magnitude appears on the + screen and the graphics cursor comes up ready to accept + commands + + ... after looking at the plot the user decides that what they + really want to see is a plot of the goodness of fit parameter + chi versus magnitude + + ... the user issues the colon command :ycol chi followed by 'p' + keystroke command to replot the data + + ... the user sees a generally smooth trend of increasing + chi with increasing magnitude + + ... after examining the plot further the user decides to delete + all objects for which the chi value > 2.0 and the + magnitude is > 25 using the '^' key and ')' keystroke + commands followed by 'f' to save the deletions and replot + the data + + ... after deciding that this new plot is satisfactory the user + issues the 'e' keystroke command to exit pexamine and save + the good data in m92.als.ed +.fi + +2. Examine and edit a DAOPHOT allstar catalog using the subracted image, the +original image and the image display. + +.nf + pt> display image.sub 1 + + ... display the subtracted image + + pt> pexamine orionk.als.1 orionk.als.ed image xcol=mag ycol=chi + + ... a plot of the goodness of fit versus magnitude appears + on the terminal and the graphics cursor comes up ready to + accept commands + + ... the user notices some very anomalous chi values and decides + to see if these correspond to objects which have poor + subtraction on the displayed image + + ... the user switches to image command mode by tapping the 'i' + key, moves to the first poorly subtracted object and taps + the 'o' key + + ... a list of the values of the loaded columns including chi + appears in the text window , the program switchs to graphics + mode and places the graphics cursor on the corresponding + point in the X-Y plot + + ... the point in question indeed has a very high chi value + and the user decides to try and investigate the reason for the + anomalous value + + ... the user taps the 'r' key to get a radial profile of the + object in the original image + + ... after carefully examining the profile it appears that the + object's profile is too broad and that it is not a star + + ... the user switches back to the X-Y plot with the 'x' key, + marks the point with the 'd' key and saves the deletions + and replots with the 'f' key. + + ... the user goes back to image command mode with the 'i' key + and begins investigating the next object + + ... finally after examining the image and making all the changes + the user decides to quit and save the changes with the 'e' key + +.fi + +.ih +TIME REQUIREMENTS + +.ih +BUGS +If the display device is on a remote resource the first image cursor +request will cause PEXAMINE to hang. The remote resource is expecting +the appropriate password which the user must type in to cause the +the image cursor to appear. The normal password prompt is +not being issued or flushed to the terminal. The solution to the problem +is to put the password in the .irafhosts file + +INDEF valued points cannot be accessed by +PEXAMINE. INDEF valued points should be removed from the input catalog +with SELECT prior to entering PEXAMINE. + +.ih +SEE ALSO +ptools.select, ptools.txselect,ptools.tselect + +.endhelp diff --git a/noao/digiphot/apphot/doc/phot.hlp b/noao/digiphot/apphot/doc/phot.hlp new file mode 100644 index 00000000..a4ee6ffb --- /dev/null +++ b/noao/digiphot/apphot/doc/phot.hlp @@ -0,0 +1,767 @@ +.help phot May00 noao.digiphot.apphot +.ih +NAME +phot -- do aperture photometry on a list of stars +.ih +USAGE +phot image +.ih +PARAMETERS +.ls image +The list of images containing the objects to be measured. +.le +.ls skyfile = "" +The list of text files containing the sky values, of the measured objects, +one object per line with x, y, the sky value, sky sigma, sky skew, number of sky +pixels and number of rejected sky pixels in columns one to seven respectively. +The number of sky files must be zero, one, or equal to the number of input +images. A skyfile value is only requested if \fIfitskypars.salgorithm\fR = +"file" and if PHOT is run non-interactively. +.le +.ls coords = "" +The list of text files containing initial coordinates for the objects to +be centered. Objects are listed in coords one object per line with the +initial coordinate values in columns one and two. The number of coordinate +files must be zero, one, or equal to the number of images. If coords is +"default", "dir$default", or a directory specification then a coords file name +of the form dir$root.extension.version is constructed and searched for, +where dir is the directory, root is the root image name, extension is "coo" +and version is the next available version number for the file. +.le +.ls output = "default" +The name of the results file or results directory. If output is +"default", "dir$default", or a directory specification then an output file name +of the form dir$root.extension.version is constructed, where dir is the +directory, root is the root image name, extension is "mag" and version is +the next available version number for the file. The number of output files +must be zero, one, or equal to the number of image files. In both interactive +and batch mode full output is written to output. In interactive mode +an output summary is also written to the standard output. +.le +.ls plotfile = "" +The name of the file containing radial profile plots of the stars written +to the output file. If plotfile is defined then a radial profile plot +is written to plotfile every time a record is written to \fIoutput\fR. +The user should be aware that this can be a time consuming operation. +.le +.ls datapars = "" +The name of the file containing the data dependent parameters. The critical +parameters \fIfwhmpsf\fR and \fIsigma\fR are located here. If \fIdatapars\fR +is undefined then the default parameter set in uparm directory is used. +.le +.ls centerpars = "" +The name of the file containing the centering parameters. The critical +parameters \fIcalgorithm\fR and \fIcbox\fR are located here. +If \fIcenterpars\fR is undefined then the default parameter set in +uparm directory is used. +.le +.ls fitskypars = "" +The name of the text file containing the sky fitting parameters. The critical +parameters \fIsalgorithm\fR, \fIannulus\fR, and \fIdannulus\fR are located here. +If \fIfitskypars\fR is undefined then the default parameter set in uparm +directory is used. +.le +.ls photpars = "" +The name of the file containing the photometry parameters. The critical +parameter \fIapertures\fR is located here. If \fIphotpars\fR is undefined +then the default parameter set in uparm directory is used. +.le +.ls interactive = yes +Run the task interactively ? +.le +.ls radplots = no +If \fIradplots\fR is "yes" and PHOT is run in interactive mode, a radial +profile of each star is plotted on the screen after the star is measured. +.le +.ls icommands = "" +The image display cursor or image cursor command file. +.le +.ls gcommands = "" +The graphics cursor or graphics cursor command file. +.le +.ls wcsin = ")_.wcsin", wcsout = ")_.wcsout" +The coordinate system of the input coordinates read from \fIcoords\fR and +of the output coordinates written to \fIoutput\fR respectively. The image +header coordinate system is used to transform from the input coordinate +system to the "logical" pixel coordinate system used internally, +and from the internal "logical" pixel coordinate system to the output +coordinate system. The input coordinate system options are "logical", tv", +"physical", and "world". The output coordinate system options are "logical", +"tv", and "physical". The image cursor coordinate system is assumed to +be the "tv" system. +.ls logical +Logical coordinates are pixel coordinates relative to the current image. +The logical coordinate system is the coordinate system used by the image +input/output routines to access the image data on disk. In the logical +coordinate system the coordinates of the first pixel of a 2D image, e.g. +dev$ypix and a 2D image section, e.g. dev$ypix[200:300,200:300] are +always (1,1). +.le +.ls tv +Tv coordinates are the pixel coordinates used by the display servers. Tv +coordinates include the effects of any input image section, but do not +include the effects of previous linear transformations. If the input +image name does not include an image section, then tv coordinates are +identical to logical coordinates. If the input image name does include a +section, and the input image has not been linearly transformed or copied from +a parent image, tv coordinates are identical to physical coordinates. +In the tv coordinate system the coordinates of the first pixel of a +2D image, e.g. dev$ypix and a 2D image section, e.g. dev$ypix[200:300,200:300] +are (1,1) and (200,200) respectively. +.le +.ls physical +Physical coordinates are pixel coordinates invariant with respect to linear +transformations of the physical image data. For example, if the current image +was created by extracting a section of another image, the physical +coordinates of an object in the current image will be equal to the physical +coordinates of the same object in the parent image, although the logical +coordinates will be different. In the physical coordinate system the +coordinates of the first pixel of a 2D image, e.g. dev$ypix and a 2D +image section, e.g. dev$ypix[200:300,200:300] are (1,1) and (200,200) +respectively. +.le +.ls world +World coordinates are image coordinates in any units which are invariant +with respect to linear transformations of the physical image data. For +example, the ra and dec of an object will always be the same no matter +how the image is linearly transformed. The units of input world coordinates +must be the same as those expected by the image header wcs, e. g. +degrees and degrees for celestial coordinate systems. +.le +The wcsin and wcsout parameters default to the values of the package +parameters of the same name. The default values of the package parameters +wcsin and wcsout are "logical" and "logical" respectively. +.le +.le +.ls cache = ")_.cache" +Cache the image pixels in memory. Cache may be set to the value of the apphot +package parameter (the default), "yes", or "no". By default cacheing is +disabled. +.le +.ls verify = ")_.verify" +Verify the critical parameters in non-interactive mode. Verify may +be set to the value of the apphot package parameter (the default), "yes", or +"no". +.le +.ls update = ")_.update" +Automatically update the algorithm parameters in non-interactive mode +if verify is "yes". Update may be set to the value of the apphot +package parameter (the default), "yes", or "no". +.le +.ls verbose = ")_.verbose" +Print results on the screen in non-interactive mode? Verbose may +be set to the value of the apphot package parameter (the default), +"yes", or "no". +.le +.ls graphics = ")_.graphics" +The default graphics device. Graphics may be set to the value of the apphot +package parameter (the default), "yes", or "no". +.le +.ls display = ")_.display" +The default display device. Display may be set to the apphot package +parameter value (the default), "yes", or "no. By default graphics overlay is +disabled. Setting display to one of "imdr", "imdg", "imdb", or "imdy" enables +graphics overlay with the IMD graphics kernel. Setting display to +"stdgraph" enables PHOT to work interactively from a contour plot. +.le + +.ih +DESCRIPTION + +PHOT computes accurate centers, sky values, and magnitudes for a list of +objects in the IRAF image \fIimage\fR whose coordinates are read from +the text file \fIcoords\fR or the image display cursor, and writes the +computed x and y coordinates, sky values, and magnitudes to the text +file \fIoutput\fR. + +The coordinates read from \fIcoords\fR are assumed to be in coordinate +system defined by \fIwcsin\fR. The options are "logical", "tv", "physical", +and "world" and the transformation from the input coordinate system to +the internal "logical" system is defined by the image coordinate system. +The simplest default is the "logical" pixel system. Users working on with +image sections but importing pixel coordinate lists generated from the parent +image must use the "tv" or "physical" input coordinate systems. +Users importing coordinate lists in world coordinates, e.g. ra and dec, +must use the "world" coordinate system and may need to convert their +equatorial coordinate units from hours and degrees to degrees and degrees first. + +The coordinates written to \fIoutput\fR are in the coordinate +system defined by \fIwcsout\fR. The options are "logical", "tv", +and "physical". The simplest default is the "logical" system. Users +wishing to correlate the output coordinates of objects measured in +image sections or mosaic pieces with coordinates in the parent +image must use the "tv" or "physical" coordinate systems. + +In interactive mode the user may either define the list of objects to be +measured interactively with the image curspr or create an object list prior +to running PHOT. In either case the user may adjust the centering, sky fitting, + and photometry algorithm parameters until a satisfactory fit is achieved +and optionally store the final results in \fIoutput\fR. In batch mode the +initial positions are read from the text file \fIcoords\fR or the image +cursor parameter \fIicommands\fR can be redirected to a text file containing +a list of cursor commands. In batch mode the current set of algorithm +parameters is used. + +If \fIcache\fR is yes and the host machine physical memory and working set size +are large enough, the input image pixels are cached in memory. If cacheing +is enabled and PHOT is run interactively the first measurement will appear +to take a long time as the entire image must be read in before the measurement +is actually made. All subsequent measurements will be very fast because PHOT +is accessing memory not disk. The point of cacheing is to speed up random +image access by making the internal image i/o buffers the same size as the +image itself. However if the input object lists are sorted in row order and +sparse cacheing may actually worsen not improve the execution time. Also at +present there is no point in enabling cacheing for images that are less than +or equal to 524288 bytes, i.e. the size of the test image dev$ypix, as the +default image i/o buffer is exactly that size. However if the size of dev$ypix +is doubled by converting it to a real image with the chpixtype task then the +effect of cacheing in interactive is can be quite noticeable if measurements +of objects in the top and bottom halfs of the image are alternated. + +PHOT computes accurate centers for each object using the centering +parameters defined in \fIcenterpars\fR, computes an accurate sky value +for each object using the sky fitting parameters defined in \fIfitskypars\fR, +and computes magnitudes using the photometry parameters defined in +\fIphotpars\fR. The image data characteristics of the data are specified +in \fIdatapars\fR. + +.ih +CURSOR COMMANDS + +The following list of cursor commands are currently available. + +.nf + Interactive Keystroke Commands + +? Print help +: Colon commands +v Verify the critical parameters +w Save the current parameters +d Plot radial profile of current star +i Interactively set parameters using current star +c Fit center for current star +t Fit sky around the cursor +a Average sky values fit around several cursor positions +s Fit sky around current centered star +p Do photometry for current star, using current sky +o Do photometry for current star, using current sky, output results +f Do photometry for current star +spbar Do photometry for current star, output results +m Move to next star in coordinate list +n Do photometry for next star in coordinate list, output results +l Do photometry for remaining stars in coordinate list, output results +e Print error messages +r Rewind coordinate list +q Exit task + + +Photometry parameters are listed or set with the following commands. + + Colon commands + +:show [data/center/sky/phot] List the parameters +:m [n] Move to next [nth] star in coordinate list +:n [n] Do photometry for next [nth] star in coordinate list, output results + + Colon Parameter Editing Commands + +# Image and file name parameters + +:image [string] Image name +:coords [string] Coordinate file name +:output [string] Output file name + +# Data dependent parameters + +:scale [value] Image scale (units per pixel) +:fwhmpsf [value] Full width half maximum of PSF (scale units) +:emission [y/n] Emission feature (y), absorption (n) +:sigma [value] Standard deviation of sky (counts) +:datamin [value] Minimum good data value (counts) +:datamax [value] Maximum good data value (counts) + +# Noise parameters + +:noise [string] Noise model (constant|poisson) +:gain [string] Gain image header keyword +:ccdread [string] Readout noise image header keyword +:epadu [value] Gain (electrons per adu) +:readnoise [value] Readout noise (electrons) + +# Observations parameters + +:exposure [string] Exposure time image header keyword +:airmass [string] Airmass image header keyword +:filter [string] Filter image header keyword +:obstime [string] Time of observation image header keyword +:itime [value] Integration time (time units) +:xairmass [value] Airmass value (number) +:ifilter [string] Filter id string +:otime [string] Time of observation (time units) + +# Centering algorithm parameters + +:calgorithm [string] Centering algorithm +:cbox [value] Width of the centering box (scale units) +:cthreshold [value] Centering intensity threshold (sigma) +:cmaxiter [value] Maximum number of iterations +:maxshift [value] Maximum center shift (scale units) +:minsnratio [value] Minimum S/N ratio for centering +:clean [y/n] Clean subraster before centering +:rclean [value] Cleaning radius (scale units) +:rclip [value] Clipping radius (scale units) +:kclean [value] Clean K-sigma rejection limit (sigma) + +# Sky fitting algorithm parameters + +:salgorithm [string] Sky fitting algorithm +:skyvalue [value] User supplied sky value (counts) +:annulus [value] Inner radius of sky annulus (scale units) +:dannulus [value] Width of sky annulus (scale units) +:khist [value] Sky histogram extent (+/- sky sigma) +:binsize [value] Resolution of sky histogram (sky sigma) +:smooth [y/n] Lucy smooth the sky histogram +:sloclip [value] Low-side clipping factor in percent +:shiclip [value] High-side clipping factor in percent +:smaxiter [value] Maximum number of iterations +:snreject [value] Maximum number of rejection cycles +:sloreject [value] Low-side pixel rejection limits (sky sigma) +:shireject [value] High-side pixel rejection limits (sky sigma) +:rgrow [value] Region growing radius (scale units) + +# Photometry parameters + +:apertures [string] List of aperture radii (scale units) +:zmag [value] Zero point of magnitude scale + +# Plotting and marking parameters + +:mkcenter [y/n] Mark computed centers on display +:mksky [y/n] Mark the sky annuli on the display +:mkapert [y/n] Mark apertures on the display +:radplot [y/n] Plot radial profile of object + + + Interactive Phot Setup Menu + + v Mark and verify the critical parameters (f,s,c,a,d,r) + + f Mark and verify the full-width half-maximum of psf + s Mark and verify the standard deviation of the background + l Mark and verify the minimum good data value + u Mark and verify the maximum good data value + + c Mark and verify the centering box width + n Mark and verify the cleaning radius + p Mark and verify the clipping radius + + a Mark and verify the inner radius of the sky annulus + d Mark and verify the width of the sky annulus + g Mark and verify the region growing radius + + r Mark and verify the aperture radii +.fi + +.ih +ALGORITHMS + +A brief description of the data dependent parameters, centering algorithms, +sky fitting algorithms and photometry parameters can be found in the +online help pages for the DATAPARS, CENTERPARS, FITSKYPARS, and PHOTPARS +tasks. + +.ih +OUTPUT + +In interactive mode the following quantities are printed on the standard +output as each object is measured. Err is a simple string indicating whether +or not an error was detected in the centering algorithm, the sky fitting +algorithm or the photometry algorithm. Mag are the magnitudes in apertures 1 +through N respectively and xcenter, ycenter and msky are the x and y centers +and the sky value respectively. + +.nf + image xcenter ycenter msky mag[1 ... N] error +.fi + +In both interactive and batch mode full output is written to the text file +\fIoutput\fR. At the beginning of each file is a header listing the +current values of the parameters when the first stellar record was written. +These parameters can be subsequently altered. For each star measured the +following record is written + +.nf + image xinit yinit id coords lid + xcenter ycenter xshift yshift xerr yerr cier error + msky stdev sskew nsky nsrej sier serror + itime xairmass ifilter otime + rapert sum area flux mag merr pier perr +.fi + +Image and coords are the name of the image and coordinate file respectively. +Id and lid are the sequence numbers of stars in the output and coordinate +files respectively. Cier and cerror are the centering algorithm error code +and accompanying error message respectively. Xinit, yinit, xcenter, ycenter, +xshift, yshift, and xerr, yerr are self explanatory and output in pixel units. +The sense of the xshift and yshift definitions is the following. + +.nf + xshift = xcenter - xinit + yshift = ycenter - yinit +.fi + +Sier and serror are the sky fitting error code and accompanying error +message respectively. Msky, stdev and sskew are the best estimate of the sky +value (per pixel), standard deviation and skew respectively. Nsky and nsrej +are the number of sky pixels and the number of sky pixels rejected respectively. + +Itime is the exposure time, xairmass is self-evident, ifilter is an +id string identifying the filter used in the observations, and otime is +a string containing the time of the observation in whatever units the +user has set up. + +Rapert, sum, area, and flux are the radius of the aperture in scale units, +the total number of counts including sky in the aperture, the area of the +aperture in square pixels, and the total number of counts excluding sky +in the aperture. Mag and merr are the magnitude and error in the magnitude +in the aperture (see below). + +.nf + flux = sum - area * msky + mag = zmag - 2.5 * log10 (flux) + 2.5 * log10 (itime) + merr = 1.0857 * error / flux + error = sqrt (flux / epadu + area * stdev**2 + + area**2 * stdev**2 / nsky) +.fi + +Pier and perror are photometry error code and accompanying error message. + +In interactive mode a radial profile of each measured object is plotted +in the graphics window if \fIradplots\fR is "yes". + +In interactive and batchmode a radial profile plot is written to +\fIplotfile\fR if it is defined each time the result of an object +measurement is written to \fIoutput\fR . + +.ih +ERRORS + +If the object centering was error free then the field cier will be zero. +Non-zero values of cier flag the following error conditions. + +.nf + 0 # No error + 101 # The centering box is off image + 102 # The centering box is partially off the image + 103 # The S/N ratio is low in the centering box + 104 # There are two few points for a good fit + 105 # The x or y center fit is singular + 106 # The x or y center fit did not converge + 107 # The x or y center shift is greater than maxshift + 108 # There is bad data in the centering box +.fi + +If all goes well during the sky fitting process then the error code sier +will be 0. Non-zero values of sier flag the following error conditions. + +.nf + 0 # No error + 201 # There are no sky pixels in the sky annulus + 202 # Sky annulus is partially off the image + 203 # The histogram of sky pixels has no width + 204 # The histogram of sky pixels is flat or concave + 205 # There are too few points for a good sky fit + 206 # The sky fit is singular + 207 # The sky fit did not converge + 208 # The graphics stream is undefined + 209 # The file of sky values does not exist + 210 # The sky file is at EOF + 211 # Cannot read the sky value correctly + 212 # The best fit parameter are non-physical +.fi + +If no error occursor during the measurement of the magnitudes then pier is +0. Non-zero values of pier flag the following error conditions. + +.nf + 0 # No error + 301 # The aperture is off the image + 302 # The aperture is partially off the image + 303 # The sky value is undefined + 305 # There is bad data in the aperture +.fi + +.ih +EXAMPLES + +1. Compute the magnitudes for a few stars in dev$ypix using the display +and the image cursor. Setup the task parameters using the interactive +setup menu defined by the i key command and a radial profile plot. + +.nf + ap> display dev$ypix 1 fi+ + + ... display the image + + ap> phot dev$ypix + + ... type ? to print an optional help page + + ... move the image cursor to a star + ... type i to enter the interactive setup menu + ... enter maximum radius in pixels of the radial profile or hit + CR to accept the default + ... set the fwhmpsf, centering radius, inner and outer sky annuli, + photometry apertures, and sigma using the graphics cursor and + the stellar radial profile plot + ... typing <CR> leaves everything at the default value + ... type q to quit the setup menu + + ... type the v key to verify the parameters + + ... type the w key to save the parameters in the parameter files + + ... move the image cursor to the stars of interest and tap + the space bar + + ... a one line summary of the fitted parameters will appear on the + standard output for each star measured + + ... type q to quit and q again to confirm the quit + + ... the output will appear in ypix.mag.1 +.fi + +2. Compute the magnitudes for a few stars in dev$ypix using a contour plot +and the graphics cursor. This option is only useful for those (now very few) +users who have access to a graphics terminal but not to an image display +server. Setup the task parameters using the interactive setup menu defined by +the i key command as in example 1. + +.nf + ap> show stdimcur + + ... record the default value of stdimcur + + ap> set stdimcur = stdgraph + + ... define the image cursor to be the graphics cursor + + ap> contour dev$ypix + + ... make a contour plot of dev$ypix + + ap> contour dev$ypix >G ypix.plot1 + + ... store the contour plot of dev$ypix in the file ypix.plot1 + + ap> phot dev$ypix display=stdgraph + + ... type ? to get an optional help page + + ... move graphics cursor to a star + ... type i to enter the interactive setup menu + ... enter maximum radius in pixels of the radial profile or CR + to accept the default value + ... set the fwhmpsf, centering radius, inner and outer sky annuli, + apertures, and sigma using the graphics cursor and the + stellar radial profile plot + ... typing <CR> leaves everything at the default value + ... type q to quit the setup menu + + ... type the v key to verify the critical parameters + + ... type the w key to save the parameters in the parameter files + + ... retype :.read ypix.plot1 to reload the contour plot + + ... move the graphics cursor to the stars of interest and tap + the space bar + + ... a one line summary of the fitted parameters will appear on the + standard output for each star measured + + ... type q to quit and q again to verify + + ... full output will appear in the text file ypix.mag.2 + + ap> set stdimcur = <default> + + ... reset stdimcur to its previous value +.fi + + +3. Setup and run PHOT interactively on a list of objects temporarily +overriding the fwhmpsf, sigma, cbox, annulus, dannulus, and apertures +parameters determined in examples 1 or 2. + +.nf + ap> daofind dev$ypix fwhmpsf=2.6 sigma=25.0 verify- + + ... make a coordinate list + + ... the output will appear in the text file ypix.coo.1 + + ap> phot dev$ypix cbox=7.0 annulus=12.0 dannulus=5.0 \ + apertures="3.0,5.0" coords=ypix.coo.1 + + ... type ? for optional help + + + ... move the graphics cursor to the stars and tap space bar + + or + + ... select stars from the input coordinate list with m / :m # + and measure with spbar + + ... measure stars selected from the input coordinate list + with n / n # + + ... a one line summary of results will appear on the standard output + for each star measured + + ... type q to quit and q again to confirm the quit + + ... the output will appear in ypix.mag.3 ... +.fi + + +4. Display and measure some stars in an image section and write the output +coordinates in the coordinate system of the parent image. + +.nf + ap> display dev$ypix[150:450,150:450] 1 + + ... display the image section + + ap> phot dev$ypix[150:450,150:450] wcsout=tv + + ... move cursor to stars and type spbar + + ... type q to quit and q again to confirm quit + + ... output will appear in ypix.mag.4 + + ap> pdump ypix.mag.4 xc,yc yes | tvmark 1 STDIN col=204 +.fi + +5. Run PHOT in batch mode using the coordinate file and the previously +saved parameters. Verify the critical parameters. + +.nf + ap> phot dev$ypix coords=ypix.coo.1 verify+ inter- + + ... output will appear in ypix.mag.5 ... +.fi + +6. Repeat example 5 but assume that the input coordinate are ra and dec +in degrees and degrees, turn off verification, and submit the task to to +the background. + +.nf + ap> display dev$ypix 1 + + ap> rimcursor wcs=world > radec.coo + + ... move to selected stars and type any key + + ... type ^Z to quit + + ap> phot dev$ypix coords=radec.coo wcsin=world verify- inter- & + + ... output will appear in ypix.mag.6 + + ap> pdump ypix.mag.6 xc,yc yes | tvmark 1 STDIN col=204 + + ... mark the stars on the display +.fi + + +7. Run PHOT interactively without using the image display. + +.nf + ap> show stdimcur + + ... record the default value of stdimcur + + ap> set stdimcur = text + + ... set the image cursor to the standard input + + ap> phot dev$ypix coords=ypix.coo.1 + + ... type ? for optional help + + ... type :m 3 to set the initial coordinates to those of the + third star in the list + + ... type i to enter the interactive setup menu + ... enter the maximum radius in pixels for the radial profile or + accept the default with a CR + ... type v to enter the default menu + ... set the fwhmpsf, centering radius, inner and outer sky annuli, + apertures, and sigma using the graphics cursor and the + stellar radial profile plot + ... typing <CR> after the prompt leaves the parameter at its default + value + ... type q to quit the setup menu + + ... type r to rewind the coordinate list + + ... type l to measure all the stars in the coordinate list + + ... a one line summary of the answers will appear on the standard + output for each star measured + + ... type q to quit followed by q to confirm the quit + + ... full output will appear in the text file ypix.mag.7 + + ap> set stdimcur = <default> + + ... reset the value of stdimcur +.fi + +8. Use a image cursor command file to drive the PHOT task. The cursor command +file shown below sets the cbox, annulus, dannulus, and apertures parameters +computes the centers, sky values, and magnitudes for 3 stars, updates the +parameter files, and quits the task. + +.nf + ap> type cmdfile + : cbox 9.0 + : annulus 12.0 + : dannulus 5.0 + : apertures 5.0 + 442 410 101 \040 + 349 188 101 \040 + 225 131 101 \040 + w + q + + ap> phot dev$ypix icommands=cmdfile verify- + + ... full output will appear in ypix.mag.8 +.fi + + +.ih +BUGS + +It is currently the responsibility of the user to make sure that the +image displayed in the frame is the same as that specified by the image +parameter. + +Commands which draw to the image display are disabled by default. +To enable graphics overlay on the image display, set the display +parameter to "imdr", "imdg", "imdb", or "imdy" to get red, green, +blue or yellow overlays and set the centerpars mkcenter switch to +"yes", the fitskypars mksky switch to"yes", or the photpars mkapert +switch to "yes". It may be necessary to run gflush and to redisplay the image +to get the overlays position correctly. + +.ih +SEE ALSO +datapars, centerpars, fitskypars, photpars, qphot, wphot, polyphot +.endhelp diff --git a/noao/digiphot/apphot/doc/photpars.hlp b/noao/digiphot/apphot/doc/photpars.hlp new file mode 100644 index 00000000..0a172ba3 --- /dev/null +++ b/noao/digiphot/apphot/doc/photpars.hlp @@ -0,0 +1,102 @@ +.help photpars May00 noao.digiphot.apphot +.ih +NAME +photpars -- edit the photometry parameters +.ih +USAGE +photpars +.ih +PARAMETERS +.ls weighting = "constant" +The type of weighting for the WPHOT task. The weighting parameter is +ignored by the PHOT task. The options are: +.ls constant +Uniform weights of 1 for each pixel are used. +.le +.ls cone +A conical weighting function of full width half maximum \fIfwhmpsf\fR as +defined in the DATAPARS parameter set is used. +.le +.ls gauss +A Gaussian weighting function of full width half maximum \fIfwhmpsf\fR as +defined in the DATAPARS parameter set is used. +.le +.le +.ls apertures = "3" (scale units) +A list of aperture radii in units of the scale parameter or the name of the +file containing the list of aperture radii. List elements may be separated by +whitespace or commas. A range syntax of the form ap1:apN:apstep is also +supported. +.le +.ls zmag = 25.00 +The zero point offset for the magnitude scale. +.le +.ls mkapert = no +Mark the photometry apertures on the displayed image ? +.le + +.ih +DESCRIPTION + +The integral of the flux within the circular apertures specified by +\fIapertures\fR is computed by summing pixels in the aperture with +the specified weighting function \fIweighting\fR. The fraction of each pixel +lying within the aperture is computed by an approximation and all the +approximations are summed. The zero point of the magnitude +scale is determined by \fIzmag\fR. + +\fRApertures\fR is specified in units of the image scale. If \fIscale\fR +is specified in units of the half-width at half-maximum of the point +spread function the aperture per pixel a single value of apertures +will work well on images with differing psfs. + +.ih +EXAMPLES + +1. List the PHOTPARS parameters. + +.nf + da> lpar photpars +.fi + +2. Edit the PHOTPARS parameters. + +.nf + da> photpars +.fi + +3. Edit the PHOTPARS parameters from within the PHOT task. + +.nf + da> epar phot + + ... edit a few phot parameters + + ... move to the photpars parameter and type :e + + ... edit the photpars parameters and type :wq + + ... finish editing the phot parameters and type :wq + +.fi + +4. Save the current PHOTPARS parameter set in a text file photnite1.par. +This can also be done from inside a higher level task as in the +above example. + +.nf + da> photpars + + ... edit some parameters + + ... type ":w photnite1.par" from within epar +.fi + +.ih +TIME REQUIREMENTS +.ih +BUGS +.ih +SEE ALSO +phot,wphot,radprof +.endhelp diff --git a/noao/digiphot/apphot/doc/polymark.hlp b/noao/digiphot/apphot/doc/polymark.hlp new file mode 100644 index 00000000..e88bc089 --- /dev/null +++ b/noao/digiphot/apphot/doc/polymark.hlp @@ -0,0 +1,430 @@ +.help polymark May00 noao.digiphot.apphot +.ih +NAME +polymark -- create or review polygon and coordinate lists for input to the +polyphot task +.ih +USAGE +polymark image +.ih +PARAMETERS +.ls images +The list of input images used to define the polygons. +.le +.ls coords = "default" +The input / output center positions file. The center positions for each +polygonal aperture are read from or written to coords. There may more than one +center position per polygon. Center positions are written to coords 1 center +position per line. When the current polygon changes POLYMARK inserts a line +containing a single ';' after the last center position. If coords is +"default", "dir$default" or a directory specification then a center position +file name of the form dir$root.extension.version is constructed, where dir is +the directory, root is the root image name, extension is "coo" and version is +the next available version of the file. +.le +.ls polygons = "default" +The name of the polygons file. The vertices of each polygon are read from or +written to the polygons file. The polygons file contains a list of the +polygon vertices. Each vertex list is terminated by a line containing a ';' +after the last vertex. If polygons is "default", "dir$default" or a directory +specification then an output name of the form dir$root.extension.version is +constructed, where dir is the directory, root is the root image name, extension +is "ver" and the version is next available version of the file. The number of +polygon files must be equal to the number of image files. +.le +.ls icommands = "" +The image cursor or image cursor command file. +.le +.ls gcommands = "" +The graphics cursor or graphics cursor command file. +.le +.ls wcsin = ")_.wcsin", wcsout = ")_.wcsout" +The coordinate system of the input coordinates read from or written +to \fIcoords\fR and \fIpolygons\fR. The image header coordinate system is +used to transform from the input coordinate system to the "logical" pixel +coordinate system used internally, and from the internal "logical" pixel +coordinate system to the output coordinate system. The input coordinate +system options are "logical", tv", "physical", and "world". The output +coordinate system options are "logical", "tv", and "physical". The image +cursor coordinate system is assumed to be the "tv" system. +.ls logical +Logical coordinates are pixel coordinates relative to the current image. +The logical coordinate system is the coordinate system used by the image +input/output routines to access the image data on disk. In the logical +coordinate system the coordinates of the first pixel of a 2D image, e.g. +dev$ypix and a 2D image section, e.g. dev$ypix[200:300,200:300] are +always (1,1). +.le +.ls tv +Tv coordinates are the pixel coordinates used by the display servers. Tv +coordinates include the effects of any input image section, but do not +include the effects of previous linear transformations. If the input +image name does not include an image section, then tv coordinates are +identical to logical coordinates. If the input image name does include a +section, and the input image has not been linearly transformed or copied from +a parent image, tv coordinates are identical to physical coordinates. +In the tv coordinate system the coordinates of the first pixel of a +2D image, e.g. dev$ypix and a 2D image section, e.g. dev$ypix[200:300,200:300] +are (1,1) and (200,200) respectively. +.le +.ls physical +Physical coordinates are pixel coordinates invariant with respect to linear +transformations of the physical image data. For example, if the current image +was created by extracting a section of another image, the physical +coordinates of an object in the current image will be equal to the physical +coordinates of the same object in the parent image, although the logical +coordinates will be different. In the physical coordinate system the +coordinates of the first pixel of a 2D image, e.g. dev$ypix and a 2D +image section, e.g. dev$ypix[200:300,200:300] are (1,1) and (200,200) +respectively. +.le +.ls world +World coordinates are image coordinates in any units which are invariant +with respect to linear transformations of the physical image data. For +example, the ra and dec of an object will always be the same no matter +how the image is linearly transformed. The units of input world coordinates +must be the same as those expected by the image header wcs, e. g. +degrees and degrees for celestial coordinate systems. +.le +The wcsin and wcsout parameters default to the values of the package +parameters of the same name. The default values of the package parameters +wcsin and wcsout are "logical" and "logical" respectively. +.le +.ls cache = ")_.cache" +Cache the image pixels in memory. Cache may be set to the value of the apphot +package parameter (the default), "yes", or "no". By default cacheing is +disabled. +.le +.ls graphics = ")_.graphics" +The standard graphics device. +.le +.ls display = ")_.display" +The default display device. Display may be set to the apphot package +parameter value (the default), "yes", or "no. By default graphics overlay is +disabled. Setting display to one of "imdr", "imdg", "imdb", or "imdy" enables +graphics overlay with the IMD graphics kernel. Setting display to +"stdgraph" enables POLYMARK to work interactively from a contour plot. +.le + +.ih +DESCRIPTION + +POLYMARK creates and / or displays center position and polygons files +suitable for input to POLYPHOT. For each image in the input list POLYMARK +creates a polygons file \fIpolygons\fR and center positions file \fIcoords\fR, +if these do not already exist. The format of the polygons and center +position files is described in the OUTPUT section. + +Polygonal apertures are defined and drawn on the image display using +the image display cursor and then shifted to the desired center +using the image display cursor. At any point in the marking process +the user may rewind the polygon and coordinate file and draw the previously +defined polygons on the display. + +The coordinates read from \fIpolygons\fR or \fIcoords\fR are assumed to be +in coordinate system defined by \fIwcsin\fR. The options are "logical", "tv", +"physical", and "world" and the transformation from the input coordinate +system to the internal "logical" system is defined by the image coordinate +system. The simplest default is the "logical" pixel system. Users working on +with image sections but importing pixel coordinate lists generated from the +parent image must use the "tv" or "physical" input coordinate systems. +Users importing coordinate lists in world coordinates, e.g. ra and dec, +must use the "world" coordinate system and may need to convert their +equatorial coordinate units from hours and degrees to degrees and degrees first. + +The coordinates written to \fIpolygons\fR or \fIcoords\fR are in the coordinate +system defined by \fIwcsout\fR. The options are "logical", "tv", and +"physical". The simplest default is the "logical" system. Users +wishing to correlate the output coordinates of objects measured in +image sections or mosaic pieces with coordinates in the parent +image must use the "tv" or "physical" coordinate systems. + +If \fIcache\fR is yes and the host machine physical memory and working set size +are large enough, the input image pixels are cached in memory. If cacheing +is enabled and POLYMARK is run interactively the first measurement will appear +to take a long time as the entire image must be read in before the measurement +is actually made. All subsequent measurements will be very fast because POLYMARK +is accessing memory not disk. The point of cacheing is to speed up random +image access by making the internal image i/o buffers the same size as the +image itself. However if the input object lists are sorted in row order and +sparse cacheing may actually worsen not improve the execution time. Also at +present there is no point in enabling cacheing for images that are less than +or equal to 524288 bytes, i.e. the size of the test image dev$ypix, as the +default image i/o buffer is exactly that size. However if the size of dev$ypix +is doubled by converting it to a real image with the chpixtype task then the +effect of cacheing in interactive is can be quite noticeable if measurements +of objects in the top and bottom halfs of the image are alternated. +.ih +CURSOR COMMANDS + +The following interactive keystroke and colon commands are available. + +.nf + Interactive Keystroke Commands + +? Print help +: Colon commands +d Plot radial profile of star near cursor +g Define the current polygonal aperture +f Draw the current polygon on the display +spbar Draw the current polygon on the display, output the polygon +r Rewind the polygon list +m Draw the next polygon in the polygon list on the display +l Draw all the remaining polygons in the list on the display +q Exit + + Colon commands + +:m [n] Draw the next [nth] polygon in the polygon list on the display +.fi + +.ih +OUTPUT + +A sample polygons file and accompanying coordinates file is listed below. + +.nf + # Sample Polygons File (2 polygons) + + 200.5 200.5 + 300.5 200.5 + 300.5 300.5 + 200.5 300.5 + ; + 100.4 100.4 + 120.4 100.4 + 120.4 120.4 + 100.4 120.4 + ; +.fi + +.nf + # Sample Coordinates File (2 groups, 1 for each polygon) + + 123.4 185.5 + 110.4 130.4 + 150.9 200.5 + ; + 85.6 35.7 + 400.5 300.5 + 69.5 130.5 + ; +.fi + +.ih +EXAMPLES + +1. Create a coordinate list and polygon file using the image display and +image display cursor. Use polymark to both create and display the +polygon and polygon center lists. + +.nf + ap> display dev$ypix 1 fi+ + + ... display the image + + ap> polymark dev$ypix display=imdg + + ... type ? for an optional help page + + ... type g to enter the "define a polygon" menu + ... move the cursor to the first vertex, tap the space bar + to mark the vertex, and repeat for each vertex + ... type q to quit the "define a polygon" menu + ... mark each vertex only once, POLYPHOT will close the + polygon for you + + ... move the cursor to the desired polygon center and + tap the space bar to record the polygon + ... repeat for all desired polygon centers + + ... type g to define the next polygon + ... move the cursor to the first vertex, tap the space bar + to mark the vertex and repeat for each vertex + ... type q to quit the polygon menu + ... mark each vertex only once, POLYPHOT will close the + polygon for you + + ... move the cursor to the desired polygon center and + tap the space bar + ... repeat for all desired polygon centers + + ... type q to quit and q to confirm the quit + + ... output will appear in ypix.coo.1 and ypix.ver.1 + + + ap> display dev$ypix 2 fi+ + + ... display the image + + ap> polymark dev$ypix coords=ypix.coo.1 polygons=ypix.ver.1 \ + display=imdg + + ... type m to mark the first polygon / polygon center on the display + + ... type m to mark the next polygon / polygon center on the display + + ... type l to mark the remaining polygons + + ... type q to quit and q to confirm the quit + + + ap> display dev$ypix 2 fi+ + + ... redisplay the image + + ap> polymark dev$ypix coords="" polygons=ypix.ver.1 \ + display=imdg + + ... type l to mark the polygon list, note that since there is + no coords file the polygons are not shifted + + ... type q to quit and q to confirm the quit +.fi + + +2. Repeat the previous example using an image section. + +.nf + ap> display dev$ypix[150:450,150:450] 1 fi+ + + ... display the image + + + ap> polymark dev$ypix[150:450,150:450]] display=imdg wcsout=tv + + ... type ? for an optional help page + + ... type g to enter the "define a polygon" menu + ... move the cursor to the first vertex, tap the space bar + to mark the vertex, and repeat for each vertex + ... type q to quit the "define a polygon" menu + ... mark each vertex only once, POLYPHOT will close the + polygon for you + + ... move the cursor to the desired polygon center and + tap the space bar to record the polygon + ... repeat for all desired polygon centers + + ... type g to define the next polygon + ... move the cursor to the first vertex, tap the space bar + to mark the vertex and repeat for each vertex + ... type q to quit the polygon menu + ... mark each vertex only once, POLYPHOT will close the + polygon for you + + ... move the cursor to the desired polygon center and + tap the space bar + ... repeat for all desired polygon centers + + ... type q to quit and q to confirm the quit + + ... output will appear in ypix.coo.2 and ypix.ver.2 + + + ap> display dev$ypix[150:450,150:450] 2 fi+ + + ... display the image + + + ap> polymark dev$ypix[150:450,150:450] coords=ypix.coo.2 \ + polygons=ypix.ver.2 display=imdg wcsin=tv + + ... type m to mark the first polygon / polygon center on the display + + ... type m to mark the next polygon / polygon center on the display + + ... type l to mark the remaining polygons + +.fi + + +3. Repeat example 1 using a contour plot instead of the image display. + +.nf + ap> show stdimcur + + ... record the default value of stdimcur + + ap> set stdimcur = stdgraph + + ... define the image cursor to be the graphics cursor + + ap> contour dev$ypix + + ... draw a contour plot on the screen + + ap> contour dev$ypix >G ypix.plot1 + + ... store the contour plot of dev$ypix in the file ypix.plot1 + + ap> polymark dev$ypix display=stdgraph + + ... type g to enter the define a polygon menu + ... move the cursor to the first vertex, tap the space bar + to mark the vertex, and repeat for each vertex + ... type q to quit the define a polygon menu + ... mark each vertex only once, POLYPHOT will close the + polygon for you + + ... move the cursor to the desired polygon center and + tap the space bar to record the polygon + ... repeat for all desired polygon centers + + ... type g to define the next polygon + ... move the cursor to the first vertex, tap the space bar + to mark the vertex and repeat for each vertex + ... type q to quit the define a polygon menu + ... mark each vertex only once, POLYPHOT will close the + polygon for you + + ... move the cursor to the desired polygon center and + tap the space bar + ... repeat for all desired polygon centers + + ... type r to rewind the coordinate and polygon lists + + ... type :.read ypix.plot1 to reread the contour plot + + ... type l to display all the polygons ... + + ... type q to quit and q again to confirm the quit + + ... output will appear in ypix.ver.3 and ypix.coo.3 + + ap> contour dev$ypix + + ... redraw the contour plot + + ap> polymark dev$ypix coords="ypix.coo.3" polygons=ypix.ver.3 \ + display=stdgraph + + ap> set stdimcur = <default> + + ... reset the value of the stdimcur parameter +.fi + +.ih +BUGS + +It is the responsibility of the user to make sure that the image displayed +in the image display is the same as the image specified by the image parameter. + +Commands which draw to the image display are disabled by default. To enable +graphics overlay on the image display, set the display parameter to "imdr", +"imdg", "imdb", or "imdy" to get red, green, blue or yellow overlays. It +may be necessary to run gflush and to redisplay the image to get the overlays +position correctly. + +There are no restrictions on the shape of the polygon but the vertices +must be listed in order either clockwise or counterclockwise in the +polygons file. + +It is not necessary to close the polygon when drawing on the display. +POLYMARK will complete the polygon for you. + +.ih +SEE ALSO +polyphot +.endhelp diff --git a/noao/digiphot/apphot/doc/polypars.hlp b/noao/digiphot/apphot/doc/polypars.hlp new file mode 100644 index 00000000..e31e4dcd --- /dev/null +++ b/noao/digiphot/apphot/doc/polypars.hlp @@ -0,0 +1,69 @@ +.help polypars May00 noao.digiphot.apphot +.ih +NAME +polypars -- edit the polygonal aperture photometry parameters +.ih +USAGE +polypars +.ih +PARAMETERS +.ls zmag = 25.00 +The zero point offset for the magnitude scale. +.le +.ls mkpolygon = no +Draw the polygons on the screen. +.le +.ih +DESCRIPTION +The zero point of the magnitude scale is determined by \fIzmag\fR. + +If the \fImkpolygon\fR switch is enabled polygons are marked on the screen. +.ih +EXAMPLES + +1. List the polygonal aperture photometry parameters. + +.nf + ap> lpar polypars +.fi + +2. Edit the polygonal aperture photometry parameters. + +.nf + ap> polypars +.fi + +3. Edit the POLYPARS parameters from within the POLYPHOT task. + +.nf + da> epar polyphot + + ... edit a few polyphot parameters + + ... move to the polypars parameter and type :e + + ... edit the polypars parameters and type :wq + + ... finish editing the polyphot parameters and type :wq +.fi + +4. Save the current POLYPARS parameter set in a text file polynite1.par. +This can also be done from inside a higher level task as in the +above example. + +.nf + da> polypars + + ... edit some parameters + + ... type ":w polynite1.par" from within epar + +.fi +.ih +TIME REQUIREMENTS +.ih +BUGS +.ih +SEE ALSO +polyphot. polymark +.endhelp diff --git a/noao/digiphot/apphot/doc/polyphot.hlp b/noao/digiphot/apphot/doc/polyphot.hlp new file mode 100644 index 00000000..8bec19d4 --- /dev/null +++ b/noao/digiphot/apphot/doc/polyphot.hlp @@ -0,0 +1,791 @@ +.help polyphot May00 noao.digiphot.apphot +.ih +NAME +polyphot -- compute magnitudes inside polygonal apertures +.ih +USAGE +polyphot image +.ih +PARAMETERS +.ls image +The list of images containing the objects to be measured. +.le +.ls coords = "" +The list of text files containing the center coordinates of the polygons +to be measured. Polygon centers are listed one per line with the x and y +coordinates in columns one and two. A ";" character in column terminates +the polygon center list for the current polygon and tells POLYPHOT to skip +to the next polygon listed in \fIpolygons\fR. If coords is undefined the +polygons are not shifted. The number of polygon center files must be +zero, one, or equal to the number of images. If coords is "default", +"dir$default", or a directory specification then a coords file name +of the form dir$root.extension.version is constructed and searched for, +where dir is the directory, root is the root image name, extension is "coo" +and version is the next available version number for the file. +.le +.ls polygons = "" +The list of text files containing the vertices of the polygons to be +measured. The polygon vertices are listed 1 vertext per line with the x and y +coordinates of each vertex in columns 1 and 2. The vertices list is terminated +a ';' in column 1. The number of polygon files must be zero, one, or +equal to the number of images. If polygons is "default", "dir$default", or +a directory specification then a coords file name of the form +dir$root.extension.version is constructed and searched for, where dir is the +directory, root is the root image name, extension is "ver" +and version is the next available version number for the file. +.le +.ls output = "default" +The name of the results file or results directory. If output is +"default", "dir$default", or a directory specification then an output file name +of the form dir$root.extension.version is constructed, where dir is the +directory, root is the root image name, extension is "ply" and version is +the next available version number for the file. The number of output files +must be zero, one, or equal to the number of image files. In both interactive +and batch mode full output is written to output. In interactive mode +an output summary is also written to the standard output. +.le +.ls datapars = "" +The name of the file containing the data dependent parameters. The critical +parameters \fIfwhmpsf\fR and \fIsigma\fR are located here. If \fIdatapars\fR +is undefined then the default parameter set in uparm directory is used. +.le +.ls centerpars = "" +The name of the file containing the centering parameters. The critical +parameters \fIcalgorithm\fR and \fIcbox\fR are located here. +If \fIcenterpars\fR is undefined then the default parameter set in +uparm directory is used. +.le +.ls fitskypars = "" +The name of the text file containing the sky fitting parameters. The critical +parameters \fIsalgorithm\fR, \fIannulus\fR, and \fIdannulus\fR are located here. +If \fIfitskypars\fR is undefined then the default parameter set in uparm +directory is used. +.le +.ls polypars = "" +The name of the text file containing the polygon photometry parameters, +If \fIpolypars\fR is undefined then the default parameter set in + uparm directory is used. +.le +.ls interactive = yes +Run the task interactively ? +.le +.ls icommands = "" +The image cursor or image cursor command file. +.le +.ls gcommands = "" +The graphics cursor or graphics cursor command file. +.le +.ls wcsin = ")_.wcsin", wcsout = ")_.wcsout" +The coordinate system of the input coordinates read from \fIcoords\fR and +of the output coordinates written to \fIoutput\fR respectively. The image +header coordinate system is used to transform from the input coordinate +system to the "logical" pixel coordinate system used internally, +and from the internal "logical" pixel coordinate system to the output +coordinate system. The input coordinate system options are "logical", tv", +"physical", and "world". The output coordinate system options are "logical", +"tv", and "physical". The image cursor coordinate system is assumed to +be the "tv" system. +.ls logical +Logical coordinates are pixel coordinates relative to the current image. +The logical coordinate system is the coordinate system used by the image +input/output routines to access the image data on disk. In the logical +coordinate system the coordinates of the first pixel of a 2D image, e.g. +dev$ypix and a 2D image section, e.g. dev$ypix[200:300,200:300] are +always (1,1). +.le +.ls tv +Tv coordinates are the pixel coordinates used by the display servers. Tv +coordinates include the effects of any input image section, but do not +include the effects of previous linear transformations. If the input +image name does not include an image section, then tv coordinates are +identical to logical coordinates. If the input image name does include a +section, and the input image has not been linearly transformed or copied from +a parent image, tv coordinates are identical to physical coordinates. +In the tv coordinate system the coordinates of the first pixel of a +2D image, e.g. dev$ypix and a 2D image section, e.g. dev$ypix[200:300,200:300] +are (1,1) and (200,200) respectively. +.le +.ls physical +Physical coordinates are pixel coordinates invariant with respect to linear +transformations of the physical image data. For example, if the current image +was created by extracting a section of another image, the physical +coordinates of an object in the current image will be equal to the physical +coordinates of the same object in the parent image, although the logical +coordinates will be different. In the physical coordinate system the +coordinates of the first pixel of a 2D image, e.g. dev$ypix and a 2D +image section, e.g. dev$ypix[200:300,200:300] are (1,1) and (200,200) +respectively. +.le +.ls world +World coordinates are image coordinates in any units which are invariant +with respect to linear transformations of the physical image data. For +example, the ra and dec of an object will always be the same no matter +how the image is linearly transformed. The units of input world coordinates +must be the same as those expected by the image header wcs, e. g. +degrees and degrees for celestial coordinate systems. +.le +The wcsin and wcsout parameters default to the values of the package +parameters of the same name. The default values of the package parameters +wcsin and wcsout are "logical" and "logical" respectively. +.le +.le +.ls cache = ")_.cache" +Cache the image pixels in memory. Cache may be set to the value of the apphot +package parameter (the default), "yes", or "no". By default cacheing is +disabled. +.le +.ls verify = ")_.verify" +Verify the critical parameters in non-interactive mode ? Verify may be set to +the apphot package parameter value (the default), "yes", or "no. +.le +.ls update = ")_.update" +Update the critical parameters in non-interactive mode if verify is yes ? +Update may be set to the apphot package parameter value (the default), "yes", +or "no. +.le +.ls verbose = ")_.verbose" +Print messages in non-interactive mode? Verbose may be set to the apphot +package parameter value (the default), "yes", or "no. +.le +.ls graphics = ")_.graphics" +The default graphics device. Graphics may be set to the apphot package +parameter value (the default), "yes", +or "no. +.le +.ls display = ")_.display" +The default display device. By default graphics overlay is disabled. Display +may be set to the apphot package parameter value (the default), "yes", or "no. +Setting display to one of "imdr", "imdg", "imdb", or "imdy" enables graphics +overlay with the IMD graphics kernel. Setting display to "stdgraph" enables +POLYPHOT to work interactively from a contour plot. +.le + +.ih +DESCRIPTION + +POLYPHOT computes the magnitude of objects in the IRAF image \fIimage\fR +inside a list of polygonal apertures whose vertices are listed in the text file +\fIpolygons\fR or are marked on the display interactively with the +image cursor. The polygon centers may be read from the polygon center +file \fIcoords\fR or set interactively with the image cursor. + +The coordinates read from \fIcoords\fR are assumed to be in coordinate +system defined by \fIwcsin\fR. The options are "logical", "tv", "physical", +and "world" and the transformation from the input coordinate system to +the internal "logical" system is defined by the image coordinate system. +The simplest default is the "logical" pixel system. Users working on with +image sections but importing pixel coordinate lists generated from the parent +image must use the "tv" or "physical" input coordinate systems. +Users importing coordinate lists in world coordinates, e.g. ra and dec, +must use the "world" coordinate system and may need to convert their +equatorial coordinate units from hours and degrees to degrees and degrees first. + +The coordinates written to \fIoutput\fR are in the coordinate +system defined by \fIwcsout\fR. The options are "logical", "tv", +and "physical". The simplest default is the "logical" system. Users +wishing to correlate the output coordinates of objects measured in +image sections or mosaic pieces with coordinates in the parent +image must use the "tv" or "physical" coordinate systems. + +If \fIcache\fR is yes and the host machine physical memory and working set size +are large enough, the input image pixels are cached in memory. If cacheing +is enabled and POLYPHOT is run interactively the first measurement will appear +to take a long time as the entire image must be read in before the measurement +is actually made. All subsequent measurements will be very fast because POLYPHOT +is accessing memory not disk. The point of cacheing is to speed up random +image access by making the internal image i/o buffers the same size as the +image itself. However if the input object lists are sorted in row order and +sparse cacheing may actually worsen not improve the execution time. Also at +present there is no point in enabling cacheing for images that are less than +or equal to 524288 bytes, i.e. the size of the test image dev$ypix, as the +default image i/o buffer is exactly that size. However if the size of dev$ypix +is doubled by converting it to a real image with the chpixtype task then the +effect of cacheing in interactive is can be quite noticeable if measurements +of objects in the top and bottom halfs of the image are alternated. + +In interactive mode the user may either define the list of objects to be +measured interactively with the image cursor or create a polygon and polygon +center list prior to running POLYPHOT. In either case the user may adjust +the centering, sky fitting, and photometry algorithm parameters until a +satisfactory fit is achieved and optionally store the final results +in \fIoutput\fR. In batch mode the polygon and polygon centers are read +from the text files \fIpolygons\fR and \fIcoords\fR or the image cursor +parameter \fIicommands\fR can be redirected to a text file containing +a list of cursor commands. In batch mode the current set of algorithm +parameters is used. + +.ih +THE POLYGON and POLYGON CENTERS FILES + +A sample polygons file and accompanying coordinates file is listed below. + +.nf + # Sample Polygons File (2 polygons) + + 200.5 200.5 + 300.5 200.5 + 300.5 300.5 + 200.5 300.5 + ; + 100.4 100.4 + 120.4 100.4 + 120.4 120.4 + 100.4 120.4 + ; +.fi + +.nf + # Sample Coordinates File (2 groups, 1 for each polygon) + + 123.4 185.5 + 110.4 130.4 + 150.9 200.5 + ; + 85.6 35.7 + 400.5 300.5 + 69.5 130.5 + ; +.fi + + +.ih +CURSOR COMMANDS + +The following polyphot commands are currently available. + +.nf + Interactive Keystroke Commands + +? Print help +: Colon commands +v Verify the critical parameters +w Store the current parameters +d Plot radial profile of current object +i Define current polygon, graphically set parameters using current object +g Define current polygon +c Fit center for current object +t Fit sky around cursor +a Average sky values fit around several cursor positions +s Fit sky around current object +h Do photometry for current polygon +j Do photometry for current polygon, output results +p Do photometry for current object using current sky +o Do photometry for current object using current sky, output results +f Do photometry for current object +spbar Do photometry for current object, output results +m Move to next object in coordinate list +n Do photometry for next object in coordinate list, output results +l Do photometry for remaining objects in list, output results +r Rewind the polygon list +e Print error messages +q Exit task + + + Colon Commands + +:show [data/center/sky/phot] List the parameters +:m [n] Move to next [nth] object in coordinate list +:n [n] Do photometry for next [nth] object in coordinate list, output results + + + Colon Parameter Editing Commands + +# Image and file name parameters + +:image [string] Image name +:polygon [string] Polygon file +:coords [string] Coordinate file +:output [string] Results file + +# Data dependent parameters + +:scale [value] Image scale (units per pixel) +:fwhmpsf [value] Full-width half-maximum of PSF (scale units) +:emission [y/n] Emission feature (y), absorption (n) +:sigma [value] Standard deviation of sky (counts) +:datamin [value] Minimum good pixel value (counts) +:datamax [value] Maximum good pixel value (counts) + +# Noise parameters + +:noise [string] Noise model (constant|poisson) +:gain [string] Gain image header keyword +:ccdread [string] Readout noise image header keyword +:epadu [value] Gain (electrons per count) +:epadu [value] Readout noise (electrons) + +# Observing parameters + +:exposure [string] Exposure time image header keyword +:airmass [string] Airmass image header keyword +:filter [string] Filter image header keyword +:obstime [string] Time of observation image header keyword +:itime [value] Integration time (time units) +:xairmass [value] Airmass value (number) +:ifilter [string] Filter id string +:otime [string] Time of observation (time units) + +# Centering algorithm parameters + +:calgorithm [string] Centering algorithm +:cbox [value] Width of centering box (scale units) +:cthreshold [value] Centering intensity threshold (sigma) +:cmaxiter [value] Maximum number of iterations +:maxshift [value] Maximum center shift (scale units) +:minsnratio [value] Minimum S/N ratio for centering +:clean [y/n] Clean subraster before centering +:rclean [value] Cleaning radius (scale units) +:rclip [value] Clipping radius (scale units) +:kclean [value] Clean K-sigma rejection limit (sigma) + +# Sky fitting algorithm parameters + +:salgorithm [string] Sky fitting algorithm +:skyvalue [value] User supplied sky value (counts) +:annulus [value] Inner radius of sky annulus (scale units) +:dannulus [value] Width of sky annulus (scale units) +:khist [value] Sky histogram extent (+/- sigma) +:binsize [value] Resolution of sky histogram (sigma) +:sloclip [value] Low-side clipping factor in percent +:shiclip [value] High-side clipping factor in percent +:smooth [y/n] Lucy smooth the sky histogram +:smaxiter [value] Maximum number of iterations +:snreject [value] Maximum number of rejection cycles +:sloreject [value] Low-side pixel rejection limits (sky sigma) +:shireject [value] High-side pixel rejection limits (sky sigma) +:rgrow [value] Region growing radius (scale units) + +# Photometry parameters + +:zmag [value] Zero point of magnitude scale + +# Plotting and marking parameters + +:mkcenter [y/n] Mark computed centers on the display +:mksky [y/n] Mark the sky annuli on the display +:mkpolygon [y/n] Mark the polygon on the display + + + +The following commands are available from inside the interactive setup menu. + + + Interactive Photometry Setup Menu + + v Mark and verify the critical parameters (f,c,s,a,d) + + f Mark and verify the psf full-width half-maximum + s Mark and verify the standard deviation of the background + l Mark and verify the minimum good data value + u Mark and verify the maximum good data value + + c Mark and verify the centering box width + n Mark and verify the cleaning radius + p Mark and verify the clipping radius + + a Mark and verify the inner radius of the sky annulus + d Mark and verify the width of the sky annulus + g Mark and verify the region growing radius +.fi + +.ih +ALGORITHMS + +A brief description of the data dependent parameters, the centering +algorithms and the sky fitting algorithms can be found in the online +manual pages for the DATAPARS, CENTERPARS, and FITSKYPARS tasks. +User measuring extended "fuzzy" features may wish to set the CENTERPARS +\fIcalgorithm\fR parameter to "none", the FITSKYPARS parameters +\fIsalgorithm\fR and \fIskyvalue\fR to "constant" and <uservalue> before +running POLYPHOT. + +POLYPHOT computes the intersection of each image line with the line segments +composing the polygon in order to determine the extent of the polygon. A one +dimensional summation including a fractional approximation for the end pixels +is performed over those regions of the image line which intersect the polygon. +All the 1D summations are summed to give the total integral. The vertices of +the polygon must be specified in order either clockwise or counterclockwise. + +.ih +OUTPUT + +In interactive mode the following quantities are printed on the standard +output as each object is measured. Error is a simple string which indicates +whether the task encountered an error in the centering algorithm, the sky +fitting algorithm or the photometry algorithm. Mag are the magnitudes in +the polygonal aperture and xcenter, ycenter and msky are the x and y centers +and the sky value respectively. + +.nf + image xcenter ycenter msky mag merr error +.fi + +In both interactive and batch mode full output is written to the text file +\fIoutput\fR. At the beginning of each file is a header listing the current +values of the parameters when the first stellar record was written. These +parameters can be subsequently altered. For each star measured the following +record is written + +.nf + image xinit yinit id coords lid + xcenter ycenter xshift yshift xerr yerr cier error + msky stdev sskew nsky nsrej sier serror + itime xairmass ifilter otime + sum area flux mag merr pier perr + polygons pid oldxmean oldymean xmean ymean maxrad nver + xvertex yvertex +.fi + +Image and coords are the name of the image and coordinate file respectively. +Id and lid are the sequence numbers of objects in the output and coordinate +files respectively. Cier and cerror are the centering error code and +accompanying error message respectively. Xinit, yinit, xcenter, ycenter, +xshift, yshift, and xerr, yerr are self explanatory and output in pixel units. +The sense of the xshift and yshift definitions is the following. + +.nf + xshift = xcenter - xinit + yshift = ycenter - yinit +.fi + +Sier and serror are the sky fitting error code and accompanying error +message respectively. Msky, stdev and sskew are the best estimate of the +sky value (per pixel), standard deviation and skew respectively. Nsky and +nsrej are the number of sky pixels used and the number of sky pixels rejected +from the fit respectively. + +Itime is the exposure time, xairmass is self-evident, ifilter is an id string +identifying the filter used during the observation, and otime is a string +specifying the time of the observation in whatever units the user has chosen. + +Sum, area, and flux are the total number of counts including sky in the +polygonal aperture, the area of the aperture in square pixels, and the total +number of counts in the aperture excluding sky. Mag and merr are the magnitude +and error in the magnitude in the aperture after subtracting the sky value +(see below). + +.nf + flux = sum - area * msky + mag = zmag - 2.5 * log10 (flux) + 2.5 * log10 (itime) + merr = 1.0857 * error / flux + error = sqrt (flux / epadu + area * stdev**2 + + area**2 * stdev**2 / nsky) +.fi + +Pier and perror are photometry error code and accompanying error message. + +Polygons and pid are the name of the polygons file and the polygon id +respectively. Oldxmean, oldymean, xmean and ymean are the original and +current average coordinates of the current polygon. Oldxmean and oldymean +are the values in the polygons file or the values which correspond to the +polygon drawn on the display. Xinit and yinit define the position to +which the polygonal aperture was shifted. Xmean and ymean are generally +identical to xcenter and ycenter and describe the position of the +centered polygonal aperture. Maxrad is the maximum +distance of a polygon vertex from the average of the vertices. Nver, xvertex +and yvertex are the number of vertices and the coordinates of the vertices +of the polygonal aperture. + +.ih +ERRORS + +If the object centering was error free then the field cier will be zero. +Non-zero values of cier flag the following error conditions. + +.nf + 0 # No error + 101 # The centering box is off image + 102 # The centering box is partially off the image + 103 # The S/N ratio is low in the centering box + 104 # There are two few points for a good fit + 105 # The x or y center fit is singular + 106 # The x or y center fit did not converge + 107 # The x or y center shift is greater than maxshift + 108 # There is bad data in the centering box +.fi + +If all goes well during the sky fitting process then the error code sier +will be 0. Non-zero values of sier flag the following error conditions. + +.nf + 0 # No error + 201 # There are no sky pixels in the sky annulus + 202 # Sky annulus is partially off the image + 203 # The histogram of sky pixels has no width + 204 # The histogram of sky pixels is flat or concave + 205 # There are too few points for a good sky fit + 206 # The sky fit is singular + 207 # The sky fit did not converge + 208 # The graphics stream is undefined + 209 # The file of sky values does not exist + 210 # The sky file is at EOF + 211 # Cannot read the sky value correctly + 212 # The best fit parameter are non-physical +.fi + +If no error occurs during the measurement of the magnitudes then pier is +0. Non-zero values of pier flag the following error conditions. + +.nf + 0 # No error + 801 # The polygon is undefined + 802 # The polygon is partially off the image + 803 # The polygon is off the image + 804 # The sky value is undefined + 805 # There is bad data in the aperture +.fi + +.ih +EXAMPLES + +1. Compute the magnitudes inside 2 polygonal aperture for a few regions in +dev$ypix using the display and the image cursor. Turn off centering and set +the sky background to 0.0. + +.nf + ap> display dev$ypix 1 fi+ + + ... display the image + + ap> polyphot dev$ypix calgorithm=none salgorithm=constant \ + skyvalue=0.0 display=imdg mkpolygon+ + + ... type ? to print a help page + + ... move image cursor to a region of interest + + ... type g to enter the polygon definition menu + ... use the image cursor and spbar key to mark the vertices of + the polygonal aperture + ... mark each vertex only once, POLYPHOT will close the polygon + for you + ... type q to quit the polygon definition menu + + ... type the v key to verify the parameters + + ... type the w key to save the parameters in the parameter files + + ... move the image cursor to the objects of interest and tap + the space bar, the polygon will be marked on the image + display + + ... type g to enter the polygon definition menu + ... use the image cursor and spbar key to mark the vertices of + the polygonal aperture + ... mark each vertex only once, POLYPHOT will close the polygon + for you + ... type q to quit the polygon definition menu + + ... move the image cursor to the objects of interest and tap + the space bar, the polygon will be marked on the image + display + + ... a one line summary of the fitted parameters will appear on the + standard output for each star measured + + ... the output will appear in ypix.ply.1 +.fi + + +2. Repeat the previous example but use a contour plot and the graphics +cursor in place of the image display and image cursor. This option is +really only useful for users (very few these days) with access to a graphics +terminal but not an image display server. + +.nf + ap> show stdimcur + + ... determine the default value of stdimcur + + ap> set stdimcur = stdgraph + + ... define the image cursor to be the graphics cursor + + ap> contour dev$ypix + + ... create a contour plot of dev$ypix + + ap> contour dev$ypix >G ypix.plot1 + + ... store the contour plot of dev$ypix in the file ypix.plot1 + + ap> polyphot dev$ypix calgorithm=none salgorithm=constant \ + skyvalue=0.0 display=stdgraph mkpolygon+ + + ... type ? to print a help page + + ... type the v key to verify the parameters + + ... type the w key to save the parameters in the parameter files + + ... move image cursor to a region of interest + ... type g to enter the polygon definition menu + ... use the image cursor and spbar key to mark the vertices of + the polygonal aperture + ... mark each vertex only once, POLYPHOT will close the polygon + for you + ... type q to quit the polygon definition menu + + ... move the image cursor to the objects of interest and tap + the space bar, the polygon will be marked on the contour + plot + + ... move image cursor to a region of interest + ... type g to enter the polygon definition menu + ... use the image cursor and spbar key to mark the vertices of + the polygonal aperture + ... mark each vertex only once, POLYPHOT will close the polygon + for you + ... type q to quit the polygon definition menu + + ... move the image cursor to the objects of interest and tap + the space bar, the polygon will be marked on the image + display + + ... a one line summary of the fitted parameters will appear on the + standard output for each star measured and the polygons will + be drawn on the display + + ... full output will appear in the text file ypix.ply.2 + + ap> reset stdimcur = <default> + + ... reset stdimcur to its default value + + +.fi + +3. Setup and run POLYPHOT interactively on a list of objects created with +POLYMARK. + +.nf + ap> display dev$ypix 1 + + ... display the image + + ap> polymark dev$ypix display=imdg + + ... type g to enter the polygon definition menu + ... mark each vertex with the spbar + ... mark each vertex only once, POLYPHOT will close the + polygon for you + ... type q to quit the polygon definition menu + + ... move the cursor to the regions of interest and tap + the space bar, the polygon will be marked on the image + display + + ... the polygon and polygon centers will be written to the text + files ypix.ver.1 and ypix.coo.1 respectively + + ... type q to quit and q again to confirm the quit + + ap> display dev$ypix 2 + + ... redisplay the image + + ap> polyphot dev$ypix calgorithm=none salgorithm=constant skyvalue=0.0 \ + coords=default polygon=default display=imdg mkpolygon+ + + ... type n to measure the first polygon in the list + + ... if everything looks okay type l to measure the rest of the stars + + ... a one line summary of results will appear on the standard output + for each star measured and the aperture will be drawn on the + image display + + ... type q to quit and q again to confirm the quit + + ... the output will appear in ypix.ply.3 +.fi + + +4. Repeat example 3 but work on a section of the input image while +preserving the coordinate system of the original image. + +.nf + ap> display dev$ypix[150:450,150:450] 1 + + ... display the image + + p> polymark dev$ypix[150:450,150:450] wcsout=tv display=imdg + + ... type g to enter the polygon definition menu + ... mark each vertex with the spbar + ... mark each vertex only once, POLYPHOT will close the + polygon for you + ... type q to quit the polygon definition menu + + ... move the cursor to the regions of interest and tap + the space bar, the polygon will be marked on the image + display + + ... the polygon and polygon centers will be written to the text + files ypix.ver.1 and ypix.coo.1 respectively + + ... type q to quit and q again to confirm the quit + + ap> display dev$ypix[150:450,150:450] 2 + + ... redisplay the image + + ap> polyphot dev$ypix[150:450,150:450] calgorithm=none \ + salgorithm=constant skyvalue=0.0 coords=default polygon=default \ + display=imdg mkpolygon+ wcsin=tv wcsout=tv + + ... type n to measure the first polygon in the list + + ... if everything looks okay type l to measure the rest of the stars + + ... a one line summary of results will appear on the standard output + for each star measured and the aperture will be drawn on the + image display + + ... type q to quit and q again to confirm the quit + + ... the output will appear in ypix.ply.4 + + ap> pdump ypix.ply.4 xc,yc yes | tvmark 2 STDIN col=204 + + ... mark the centers of the polygons on the display +.fi + + +5. Run POLYPHOT in batch mode using a polygon and coordinate file and the +default parameters. Verify the critical parameters. + +.nf + ap> polyphot dev$ypix coords=default polygon=default inter- verify+ + + ... output will appear in ypix.ply.5 +.fi + + +.ih +TIMINGS +.ih +BUGS +There are no restrictions on the shape of the polygon but the vertices +must be listed or marked in order. + +When marking the polygon on the display it is not necessary to close +the polygon. When the user types q to quit the marking the program +will automatically close the polygon. + +It is currently the responsibility of the user to make sure that the +image displayed on the display is the same as that specified by the image +parameter. + +Commands which draw to the image display are disabled by default. +To enable graphics overlay on the image display, set the display +parameter to "imdr", "imdg", "imdb", or "imdy" to get red, green, +blue or yellow overlays and set the centerpars mkcenter switch to +"yes", the fitskypars mksky switch to"yes", or the polypars mkpolygon +switch to "yes". It may be necessary to run gflush and to redisplay the image +to get the overlays position correctly. + +.ih +SEE ALSO +datapars,centerpars,fitskypars,polypars,qphot,phot,wphot +.endhelp diff --git a/noao/digiphot/apphot/doc/qphot.hlp b/noao/digiphot/apphot/doc/qphot.hlp new file mode 100644 index 00000000..42e3f5bf --- /dev/null +++ b/noao/digiphot/apphot/doc/qphot.hlp @@ -0,0 +1,647 @@ +.help qphot May00 noao.digiphot.apphot +.ih +NAME +qphot -- quick aperture photometer +.ih +USAGE +qphot image cbox annulus dannulus apertures +.ih +PARAMETERS +.ls image +The list of images containing the objects to be measured. +.le +.ls cbox +The width of the centering box in pixels. +.le +.ls annulus +The inner radius of the sky annulus in pixels. +.le +.ls dannulus +The width of the sky annulus in pixels. +.le +.ls apertures +The list of aperture radii in pixels. Apertures is a string parameter +specifying either a single aperture radius e.g. "3.0", a list of aperture +radii separated by commas e.g. "3.0,5.0,10.0", or a range of aperture radii +e.g. "1.0:20.0:1.0". +.le +.ls coords = "" +The list of text files containing initial coordinates for the objects to +be measured. Objects are listed in coords one object per line with the +initial coordinate values in columns one and two. The number of coordinate +files must be zero, one, or equal to the number of images. If coords is +"default", "dir$default", or a directory specification then a coords file name +of the form dir$root.extension.version is constructed and searched for, +where dir is the directory, root is the root image name, extension is "coo" +and version is the next available version number for the file. +.le +.ls output = "default" +The name of the results file or results directory. If output is +"default", "dir$default", or a directory specification then an output file name +of the form dir$root.extension.version is constructed, where dir is the +directory, root is the root image name, extension is "mag" and version is +the next available version number for the file. The number of output files +must be zero, one, or equal to the number of image files. In both interactive +and batch mode full output is written to output. In interactive mode +an output summary is also written to the standard output. +.le +.ls plotfile = "" +The name of the file containing radial profile plots of the stars written +to the output file. If plotfile is defined then a radial profile plot +is written to plotfile every time a record is written to \fIoutput\fR. +The user should be aware that this can be a time consuming operation. +.le +.ls zmag = 25.0 +The zero point of the magnitude scale. +.le +.ls exposure = "" +The image header keyword containing the exposure time. +.le +.ls airmass = "" +The image header keyword containing the airmass of the observation. +.le +.ls filter = "" +The image header keyword containing the filter id of the observation. +.le +.ls obstime = "" +The image header keyword containing the time of the observation. +.le +.ls epadu = 1.0 +The gain in photons per adu. Epadu is used to compute the magnitude errors. +.le +.ls interactive = yes +Interactive or batch mode. +.le +.ls radplots = no +If radplots is "yes" and QPHOT is run in interactive mode then a radial profile +of each star is plotted on the screen after it is measured. +.le +.ls icommands = "" +The image display cursor or image cursor command file. +.le +.ls gcommands = "" +The graphics cursor or graphics cursor command file. +.le +.ls wcsin = ")_.wcsin", wcsout = ")_.wcsout" +The coordinate system of the input coordinates read from \fIcoords\fR and +of the output coordinates written to \fIoutput\fR respectively. The image +header coordinate system is used to transform from the input coordinate +system to the "logical" pixel coordinate system used internally, +and from the internal "logical" pixel coordinate system to the output +coordinate system. The input coordinate system options are "logical", tv", +"physical", and "world". The output coordinate system options are "logical", +"tv", and "physical". The image cursor coordinate system is assumed to +be the "tv" system. +.ls logical +Logical coordinates are pixel coordinates relative to the current image. +The logical coordinate system is the coordinate system used by the image +input/output routines to access the image data on disk. In the logical +coordinate system the coordinates of the first pixel of a 2D image, e.g. +dev$ypix and a 2D image section, e.g. dev$ypix[200:300,200:300] are +always (1,1). +.le +.ls tv +Tv coordinates are the pixel coordinates used by the display servers. Tv +coordinates include the effects of any input image section, but do not +include the effects of previous linear transformations. If the input +image name does not include an image section, then tv coordinates are +identical to logical coordinates. If the input image name does include a +section, and the input image has not been linearly transformed or copied from +a parent image, tv coordinates are identical to physical coordinates. +In the tv coordinate system the coordinates of the first pixel of a +2D image, e.g. dev$ypix and a 2D image section, e.g. dev$ypix[200:300,200:300] +are (1,1) and (200,200) respectively. +.le +.ls physical +Physical coordinates are pixel coordinates invariant with respect to linear +transformations of the physical image data. For example, if the current image +was created by extracting a section of another image, the physical +coordinates of an object in the current image will be equal to the physical +coordinates of the same object in the parent image, although the logical +coordinates will be different. In the physical coordinate system the +coordinates of the first pixel of a 2D image, e.g. dev$ypix and a 2D +image section, e.g. dev$ypix[200:300,200:300] are (1,1) and (200,200) +respectively. +.le +.ls world +World coordinates are image coordinates in any units which are invariant +with respect to linear transformations of the physical image data. For +example, the ra and dec of an object will always be the same no matter +how the image is linearly transformed. The units of input world coordinates +must be the same as those expected by the image header wcs, e. g. +degrees and degrees for celestial coordinate systems. +.le +The wcsin and wcsout parameters default to the values of the package +parameters of the same name. The default values of the package parameters +wcsin and wcsout are "logical" and "logical" respectively. +.le +.le +.ls cache = ")_.cache" +Cache the image pixels in memory. Cache may be set to the value of the apphot +package parameter (the default), "yes", or "no". By default cacheing is +disabled. +.le +.ls verbose = ")_.verbose" +Print messages in non-interactive mode ? Verbose may be set to the apphot +package parameter value (the default), "yes", or "no. +.le +.ls graphics = ")_.graphics" +The default graphics device. Graphics may be set to the apphot package +parameter value (the default), "yes", or "no. +.le +.ls display = ")_.display" +The default display device. Display may be set to the apphot package parameter +value (the default), "yes", or "no. By default graphics overlay is disabled. +Setting display to one of "imdr", "imdg", "imdb", or "imdy" enables graphics +overlay with the IMD graphics kernel. Setting display to "stdgraph" enables +QPHOT to work interactively from a contour plot. +.le + +.ih +DESCRIPTION +QPHOT computes accurate centers, sky values, and magnitudes for a list of +objects in the IRAF image \fIimage\fR whose initial coordinates are +read from the image cursor or the coordinate file \fIcoords\fR, +and writes the computed x and y coordinates, sky values, and +magnitudes to the text file \fIoutput\fR. + +The coordinates read from \fIcoords\fR are assumed to be in coordinate +system defined by \fIwcsin\fR. The options are "logical", "tv", "physical", +and "world" and the transformation from the input coordinate system to +the internal "logical" system is defined by the image coordinate system. +The simplest default is the "logical" pixel system. Users working on with +image sections but importing pixel coordinate lists generated from the parent +image must use the "tv" or "physical" input coordinate systems. +Users importing coordinate lists in world coordinates, e.g. ra and dec, +must use the "world" coordinate system and may need to convert their +equatorial coordinate units from hours and degrees to degrees and degrees first. + +The coordinates written to \fIoutput\fR are in the coordinate +system defined by \fIwcsout\fR. The options are "logical", "tv", +and "physical". The simplest default is the "logical" system. Users +wishing to correlate the output coordinates of objects measured in +image sections or mosaic pieces with coordinates in the parent +image must use the "tv" or "physical" coordinate systems. + +In interactive mode the user measure objects interactively with the image +cursor, or select them interactively from the coordinate list \fIcoords\fR. +In batch mode the coordinates can be read directly from \fIcoords\fR, or from +the cursor command file specified by the parameter \fIicommands\fR. + +If \fIcache\fR is yes and the host machine physical memory and working set size +are large enough, the input image pixels are cached in memory. If cacheing +is enabled and QPHOT is run interactively the first measurement will appear +to take a long time as the entire image must be read in before the measurement +is actually made. All subsequent measurements will be very fast because QPHOT +is accessing memory not disk. The point of cacheing is to speed up random +image access by making the internal image i/o buffers the same size as the +image itself. However if the input object lists are sorted in row order and +sparse cacheing may actually worsen not improve the execution time. Also at +present there is no point in enabling cacheing for images that are less than +or equal to 524288 bytes, i.e. the size of the test image dev$ypix, as the +default image i/o buffer is exactly that size. However if the size of dev$ypix +is doubled by converting it to a real image with the chpixtype task then the +effect of cacheing in interactive is can be quite noticeable if measurements +of objects in the top and bottom halfs of the image are alternated. + +QPHOT computes accurate centers for each object using the centroid +centering algorithm, pixels inside \fIcbox\fR and the default values of the +\fIcenterpars\fR parameters. Accurate sky values for each object are +computed using the \fIcentroid\fR sky fitting algorithm with histogram +smoothing turned on, pixels inside the sky annulus defined by \fIannulus\fR +and \fIdannulus\fR, and the default values of the remaining sky fitting +parameters as defined in the \fIfitskypars\fR parameter set. Magnitudes +are computed using pixels inside the apertures defined by \fIapertures\fR. +The user must set the gain \fIepadu\fR to ensure that the magnitude error +estimates are correctly computed and \fIexposure\fR to normalize the computed +magnitudes to an exposure time of 1 time unit. The zero point of the magnitude +scale can be adjusted by setting \fIzmag\fR. \fIAirmass\fR, \fIfilter\fR, +and \fIobstime\fR are book-keeping parameters. Setting them to appropriate +values will simplify future analysis and calibration steps. + +.ih +CURSOR COMMANDS + +The following list of cursor commands are currently available. + +.nf + Interactive Photometry Commands + +? Print help +: Colon commands +w Save the current parameters +d Plot radial profile of current star +i Interactively set parameters using current star +c Fit center of current star +t Fit sky around the cursor +a Average sky values fit around several cursor positions +s Fit sky for current centered star +p Do photometry for current star, using current sky +o Do photometry for current star, using current sky, output results +f Do photometry for current star +spbar Do photometry for current star, output results +e Print error messages +m Move to next star in coordinate list +n Do photometry for next star in coordinate list, output results +l Do photometry for remaining stars in coordinate list, output results +r Rewind the coordinate list +q Exit task + + + Colon Commands + +:show List the parameters +:m [n] Move to next [nth] star in coordinate list +:n [n] Do photometry for next [nth] star in coordinate list, output results + + Colon Parameter Editing Commands + +:image [string] Image name +:output [string] Output file name +:coords [string] Coords file name + +:cbox [value] Width of the centering box (pixels) +:annulus [value] Inner radius of sky annulus (pixels) +:dannulus [value] Width of sky annulus (pixels) +:apertures [string] List of aperture radii (pixels) +:zmag [value] Zero point of magnitude scale (magnitudes) +:epadu [value] Gain (electrons per adu) + +:exposure [string] Exposure time image header keyword +:airmass [string] Airmass image header keyword +:filter [string] Filter image header keyword +:obstime [string] Time of observation image header keyword + +:radplot [y/n] Plot radial profile of object + + +The following commands are available from inside the interactive setup menu +using the i key. + + + Interactive Qphot Setup Menu + + v Mark and verify the critical parameters (c,a,d,r) + + c Mark and verify the centering box width + a Mark and verify the inner radius of the sky annulus + d Mark and verify the width of the sky annulus + r Mark and verify the aperture radii +.fi + +.ih +OUTPUT +In interactive mode the following quantities are printed on the standard +output as each object is measured. Error is a simple string which indicates +whether the task encountered an error condition from +the centering algorithm, the sky fitting algorithm or the photometry +algorithm respectively. Mag are the magnitudes in +apertures 1 through N respectively and xcenter, ycenter and msky are the +x and y centers and the sky value respectively. + +.nf + image xcenter ycenter msky mag[1 ... N] error +.fi + +In both interactive and batch mode full output is written to the text file +\fIoutput\fR. At the beginning of each file is a header listing the +current values of the parameters when the first stellar record was written. +These parameters can be subsequently altered. For each star measured the +following record is written. + +.nf + image xinit yinit id coords lid + xcenter ycenter xshift yshift xerr yerr cier cerror + msky stdev sskew nsky nsrej sier serror + itime xairmass ifilter otime + rapert sum area flux mag merr pier perror +.fi + +Image and coords are the name of the image and coordinate file respectively. +Id and lid are the sequence numbers of stars in the output and coordinate +files respectively. Cier and cerror are the error code and accompanying +error message for the center computation. Xinit, yinit, xcenter, ycenter, +xshift, yshift, and xerr, yerr are self explanatory and output in pixel units. +The sense of the xshift and yshift definitions is the following. + +.nf + xshift = xcenter - xinit + yshift = ycenter - yinit +.fi + +Sier and serror are the sky fitting error code and accompanying error message +respectively. Msky, stdev and sskew are the best estimate of the sky value +(per pixel), standard deviation and skew respectively. Nsky and nsrej are +the number of sky pixels used and the number of sky pixels rejected +respectively. + +Itime is the exposure time, xairmass is self-evident, ifilter is an +id string used to identify the filter used during the observation, and +otime is a string containing the time stamp in whatever units the +user has written into the image header or the otime parameter. + +Rapert, sum, area, and flux are the radius of the aperture in pixels, the +total number of counts including sky in the aperture, the area of the aperture +in square pixels, and the total number of counts in the aperture excluding +sky. Mag and merr are the magnitude and error in the magnitude in the aperture. + +.nf + flux = sum - area * msky + mag = zmag - 2.5 * log10 (flux) + 2.5 * log10 (itime) + merr = 1.0857 * err / flux + err = sqrt (flux / epadu + area * stdev**2 + + area**2 * stdev**2 / nsky) +.fi + +Pier and perror are photometry error code and accompanying error message. + +In interactive mode a radial profile of each measured object is plotted +in the graphics window if \fIradplots\fR is "yes". + +In interactive and batchmode a radial profile plot is written to +\fIplotfile\fR if it is defined each time the result of an object +measurement is written to \fIoutput\fR . + + +.ih +ERRORS +If the object centering was error free then the field cier will be zero. +Non-zero values of cier flag the following error conditions. + +.nf +0 # No error +101 # The centering box is off image +102 # The centering box is partially off the image +103 # The S/N ratio is low in the centering box +104 # There are two few points for a good fit +105 # The x or y center fit is singular +106 # The x or y center fit did not converge +107 # The x or y center shift is greater than 1 pixel +108 # There is bad data in the centering box + +.fi + +If all goes well during the sky fitting process then the error code sier +will be 0. Non-zero values of sier flag the following error conditions. + +.nf +0 # No error +201 # There are no sky pixels in the sky annulus +202 # Sky annulus is partially off the image +203 # The histogram of sky pixels has no width +204 # The histogram of sky pixels is flat or concave +205 # There are too few points for a good sky fit +206 # The sky fit is singular +207 # The sky fit did not converge +208 # The graphics stream is undefined +209 # The file of sky values does not exist +210 # The sky file is at EOF +211 # Cannot read the sky value correctly +212 # The best fit parameter are non-physical + +.fi + +If no error occurs during the measurement of the magnitudes then pier is +0. Non-zero values of pier flag the following error conditions. + +.nf +0 # No error +301 # The aperture is off the image +302 # The aperture is partially off the image +303 # The sky value is undefined +305 # There is bad data in the aperture +.fi + +.ih +EXAMPLES + +1. Perform aperture photometry interactively for a few stars in dev$ypix using +the display and the image cursor. + +.nf + ap> display dev$ypix 1 fi+ + + ... display the image + + ap> qphot dev$ypix 5. 10. 5. 2.,4.,6.0 + + ... move image cursor to objects of interest and tap space bar + + ... a 1 line summary will be printed on the standard output + for each object measured + + ... type q to quit and q again to confirm the quit + + ... full output will appear in ypix.mag.1 +.fi + + +2. Perform aperture photometry interactively for a few stars in dev$ypix +using the contour plot and the graphics cursor. This option is only useful +for those (now very few) users who have access to a graphics terminal but +not to an image display server. Setup the task parameters using the +interactive setup menu defined by the i key command as in example 1. + + +.nf + ap> show stdimcur + + ... record the default value of stdimcur + + ap> set stdimcur = stdgraph + + ... define the image cursor to be the graphics cursor + + ap> contour dev$ypix + + ... make a contour plot of dev$ypix + + ap> contour dev$pix >G ypix.plot1 + + ... store the contour plot of dev$ypix in the file ypix.plot1 + + ap> qphot dev$ypix 5. 10. 5. 2.,4.,6.0 + + ... type ? to see the help screen + + ... move image cursor to objects of interest and tap space bar + + ... a 1 line summary will be printed on the standard output + for each object measured + + ... type q to quit and q again to confirm the quit + + ... full output will be written to ypix.mag.2 + + ap> set stdimcur = <default> + + ... reset stdimcur to its previous value +.fi + + + +3. Setup and run QPHOT interactively on a list of objects temporarily +overriding the fwhmpsf, sigma, cbox, annulus, dannulus, and apertures + parameters determined in examples 1 or 2. + +.nf + ap> daofind dev$ypix fwhmpsf=2.6 sigma=25.0 verify- + + ... make a coordinate list + + ... the output will appear in the text file ypix.coo.1 + + ap> qphot dev$ypix 7.0 12.0 5.0 "3.0,5.0" coords=ypix.coo.1 + + ... type ? for optional help + + + ... move the graphics cursor to the stars and tap space bar + + or + + ... select stars from the input coordinate list with m / :m # + and measure with spbar + + ... measure stars selected from the input coordinate list + with n / n # + + ... a one line summary of results will appear on the standard output + for each star measured + + ... type q to quit and q again to confirm the quit + + ... the output will appear in ypix.mag.3 ... +.fi + + +4. Display and measure some stars in an image section and write the output +coordinates in the coordinate system of the parent image. + +.nf + ap> display dev$ypix[150:450,150:450] 1 + + ... display the image section + + ap> qphot dev$ypix[150:450,150:450] 7.0 12.0 5.0 "3.0,5.0" wcsout=tv + + ... move cursor to stars and type spbar + + ... type q to quit and q again to confirm quit + + ... output will appear in ypix.mag.4 + + ap> pdump ypix.mag.4 xc,yc yes | tvmark 1 STDIN col=204 +.fi + + +5. Run QPHOT in batch mode using the coordinate file and the previously +saved parameters. + +.nf + ap> qphot dev$ypix 7. 12.0 5.0 "3.0,5.0" coords=ypix.coo.1 inter- + + ... output will appear in ypix.mag.5 ... +.fi + + +6. Repeat example 5 but assume that the input coordinate are ra and dec +in degrees and degrees and submit the task to the background. + +.nf + ap> display dev$ypix + + ap> rimcursor wcs=world > radec.coo + + ... move to selected stars and type any key + + ... type ^Z to quit + + ap> qphot dev$ypix 7.0 12.0 5.0 "3.0,5.0" coords=radec.coo \ + wcsin=world inter- & + + ... output will appear in ypix.ctr.6 + + ap> pdump ypix.mag.6 xc,yc yes | tvmark 1 STDIN col=204 + + ... mark the stars on the display +.fi + + +7. Run QPHOT interactively without using the image display. + +.nf + ap> show stdimcur + + ... record the default value of stdimcur + + ap> set stdimcur = text + + ... set the image cursor to the standard input + + ap> qphot dev$ypix 7.0 12.0 5.0 "3.0,5.0" coords=ypix.coo.1 + + ... type ? for optional help + + ... type :m 3 to set the initial coordinates to those of the + third star in the list + + ... type "442 409 101 i" to enter the interactive setup menu + ... enter the maximum radius in pixels for the radial profile or + accept the default with a CR + ... type v to enter the default menu + ... reset cbox, annulus, dannulus, and apertures using the graphics + cursor and the stellar radial profile plot + ... typing <CR> after the prompt leaves the parameter at its default + value + ... type q to quit the setup menu + + ... type r to rewind the coordinate list + + ... type l to measure all the stars in the coordinate list + + ... a one line summary of the answers will appear on the standard + output for each star measured + + ... type q to quit followed by q to confirm the quit + + ... full output will appear in the text file ypix.mag.7 + + ap> set stdimcur = <default> + + ... reset the value of stdimcur +.fi + +8. Use a image cursor command file to drive the qphot task. The cursor command +file shown below computes the centers, sky values, and magnitudes for 3 stars +and quits the task. + +.nf + ap> type cmdfile + 442 410 101 \040 + 349 188 101 \040 + 225 131 101 \040 + q + + ap> qphot dev$ypix 7.0 12.0 5.0 "3.0,5.0" icommands=cmdfile + + ... full output will appear in ypix.mag.8 +.fi + + +.ih +BUGS + +It is the responsibility of the user to make sure that the image displayed +in the image display is the same as that specified by the image parameter. + +Commands which draw to the image display are disabled by default. +To enable graphics overlay on the image display, set the display +parameter to "imdr", "imdg", "imdb", or "imdy" to get red, green, +blue or yellow overlays. It may be necessary to run gflush and to +redisplay the image to get the overlays position correctly. + +.ih +SEE ALSO +phot,wphot,polyphot +.endhelp diff --git a/noao/digiphot/apphot/doc/radprof.hlp b/noao/digiphot/apphot/doc/radprof.hlp new file mode 100644 index 00000000..c6d79251 --- /dev/null +++ b/noao/digiphot/apphot/doc/radprof.hlp @@ -0,0 +1,813 @@ +.help radprof May00 noao.digiphot.apphot +.ih +NAME +radprof -- compute the radial profile of an object +.ih +USAGE +radprof image radius step +.ih +PARAMETERS +.ls image +The name of the image containing the objects to be measured. +.le +.ls radius, step +The size and resolution of the computed radial profile in scale units which is +equal to radius * \fIscale\fR and step * \fIscale\fR in pixels. +.le +.ls coords = "" +The list of text files containing initial coordinates for the objects to +be centered. Objects are listed in coords one object per line with the +initial coordinate values in columns one and two. The number of coordinate +files must be zero, one, or equal to the number of images. If coords is +"default", "dir$default", or a directory specification then a coords file name +of the form dir$root.extension.version is constructed and searched for, +where dir is the directory, root is the root image name, extension is "prf" +and version is the next available version number for the file. +.le +.ls output = "" +The name of the results file or results directory. +If output is "default", "dir$default" or a directory specification then an +output file name of the form dir$root.extension.version is constructed, where +dir is the directory, root is the root image name, extension is "prf" and +version is the next available version of the file. If output is undefined, +then no output file is created. If output is defined, the number of output files +is either 1 or the same as the number of input images. +.le +.ls plotfile = "" +The name of the file containing radial profile plots of the stars written +to the output file. If plotfile is defined then a radial profile plot +is written to plotfile every time a record is written to \fIoutput\fR. +The user should be aware that this can be a time consuming operation. +.le +.ls datapars = "" +The name of the file containing the data dependent parameters. The critical +parameters \fIfwhmpsf\fR and \fIsigma\fR are located here. If \fIdatapars\fR +is undefined then the default parameter set in uparm directory is used. +.le +.ls centerpars = "" +The name of the file containing the centering parameters. The critical +parameters \fIcalgorithm\fR and \fIcbox\fR are located here. +If \fIcenterpars\fR is undefined then the default parameter set in +uparm directory is used. +.le +.ls fitskypars = "" +The name of the text file containing the sky fitting parameters. The critical +parameters \fIsalgorithm\fR, \fIannulus\fR, and \fIdannulus\fR are located here. +If \fIfitskypars\fR is undefined then the default parameter set in uparm +directory is used. +.le +.ls photpars = "" +The name of the file containing the photometry parameters. The critical +parameter \fIapertures\fR is located here. If \fIphotpars\fR is undefined +then the default parameter set in uparm directory is used. +.le +.ls order = 5 +The number of pieces in the spline fit. +.le +.ls nreject = 1 +The maximum number of rejection cycles. +.le +.ls kreject = 3.0 +The k-sigma rejection limit for the radial profile fit. +.le +.ls interactive = yes +Run the task interactively ? +.le +.ls radplots = yes +If \fIradplots\fR is "yes" and RADPROF is run in interactive mode, a radial +profile of each star is plotted on the screen after the star is measured. +.le +.ls icommands = "" +The image cursor or image cursor command file. +.le +.ls gcommands = "" +The graphics cursor or graphics cursor command file. +.le +.ls wcsin = ")_.wcsin", wcsout = ")_.wcsout" +The coordinate system of the input coordinates read from \fIcoords\fR and +of the output coordinates written to \fIoutput\fR respectively. The image +header coordinate system is used to transform from the input coordinate +system to the "logical" pixel coordinate system used internally, +and from the internal "logical" pixel coordinate system to the output +coordinate system. The input coordinate system options are "logical", "tv", +"physical", and "world". The output coordinate system options are "logical", +"tv", and "physical". The image cursor coordinate system is assumed to +be the "tv" system. +.ls logical +Logical coordinates are pixel coordinates relative to the current image. +The logical coordinate system is the coordinate system used by the image +input/output routines to access the image data on disk. In the logical +coordinate system the coordinates of the first pixel of a 2D image, e.g. +dev$ypix and a 2D image section, e.g. dev$ypix[200:300,200:300] are +always (1,1). +.le +.ls tv +Tv coordinates are the pixel coordinates used by the display servers. Tv +coordinates include the effects of any input image section, but do not +include the effects of previous linear transformations. If the input +image name does not include an image section, then tv coordinates are +identical to logical coordinates. If the input image name does include a +section, and the input image has not been linearly transformed or copied from +a parent image, tv coordinates are identical to physical coordinates. +In the tv coordinate system the coordinates of the first pixel of a +2D image, e.g. dev$ypix and a 2D image section, e.g. dev$ypix[200:300,200:300] +are (1,1) and (200,200) respectively. +.le +.ls physical +Physical coordinates are pixel coordinates invariant with respect to linear +transformations of the physical image data. For example, if the current image +was created by extracting a section of another image, the physical +coordinates of an object in the current image will be equal to the physical +coordinates of the same object in the parent image, although the logical +coordinates will be different. In the physical coordinate system the +coordinates of the first pixel of a 2D image, e.g. dev$ypix and a 2D +image section, e.g. dev$ypix[200:300,200:300] are (1,1) and (200,200) +respectively. +.le +.ls world +World coordinates are image coordinates in any units which are invariant +with respect to linear transformations of the physical image data. For +example, the ra and dec of an object will always be the same no matter +how the image is linearly transformed. The units of input world coordinates +must be the same as those expected by the image header wcs, e. g. +degrees and degrees for celestial coordinate systems. +.le +The wcsin and wcsout parameters default to the values of the package +parameters of the same name. The default values of the package parameters +wcsin and wcsout are "logical" and "logical" respectively. +.le +.le +.ls cache = ")_.cache" +Cache the image pixels in memory. Cache may be set to the value of the apphot +package parameter (the default), "yes", or "no". By default cacheing is +disabled. +.le +.ls verify = ")_.verify" +Verify the critical parameters in non-interactive mode ? Verify may be set to +the apphot package parameter value (the default), "yes", or "no". +.le +.ls update = ")_.update" +Update the critical parameter in non-interactive mode if verify is yes ? +Update may be set to the apphot package parameter value (the default), "yes", +or "no". +.le +.ls verbose = ")_.verbose" +Print messages on the screen in non-interactive mode ? Verbose may be set +to the apphot package parameter value (the default), "yes", or "no". + +.le +.ls graphics = ")_.graphics" +The default graphics device. Graphics may be set to the apphot package +parameter value (the default), "yes", or "no. +.le +.ls display = ")_.display" +The default display device. Display may be set to the apphot package +parameter value (the default), "yes", or "no. By default graphics overlay +is disabled. Setting display to one of "imdr", "imdg", "imdb", or "imdy" +enables graphics overlay with the IMD graphics kernel. Setting display to +"stdgraph" enables RADPROF to work interactively from a contour plot. +.le + +.ih +DESCRIPTION + +The radial profiles of objects in the image \fIimage\fR are computed +the object center out to the radius \fIradius * scale\fR, in steps of +\fIstep * scale\fR pixels, and plotted. The initial positions are +read from the image cursor or the text file \fIcoords\fR. + +The coordinates read from \fIcoords\fR are assumed to be in coordinate +system defined by \fIwcsin\fR. The options are "logical", "tv", "physical", +and "world" and the transformation from the input coordinate system to +the internal "logical" system is defined by the image coordinate system. +The simplest default is the "logical" pixel system. Users working on with +image sections but importing pixel coordinate lists generated from the parent +image must use the "tv" or "physical" input coordinate systems. +Users importing coordinate lists in world coordinates, e.g. ra and dec, +must use the "world" coordinate system and may need to convert their +equatorial coordinate units from hours and degrees to degrees and degrees first. + +The coordinates written to \fIoutput\fR are in the coordinate +system defined by \fIwcsout\fR. The options are "logical", "tv", +and "physical". The simplest default is the "logical" system. Users +wishing to correlate the output coordinates of objects measured in +image sections or mosaic pieces with coordinates in the parent +image must use the "tv" or "physical" coordinate systems. + +If \fIcache\fR is yes and the host machine physical memory and working set size +are large enough, the input image pixels are cached in memory. If cacheing +is enabled and RADPROF is run interactively the first measurement will appear +to take a long time as the entire image must be read in before the measurement +is actually made. All subsequent measurements will be very fast because RADPROF +is accessing memory not disk. The point of cacheing is to speed up random +image access by making the internal image i/o buffers the same size as the +image itself. However if the input object lists are sorted in row order and +sparse cacheing may actually worsen not improve the execution time. Also at +present there is no point in enabling cacheing for images that are less than +or equal to 524288 bytes, i.e. the size of the test image dev$ypix, as the +default image i/o buffer is exactly that size. However if the size of dev$ypix +is doubled by converting it to a real image with the chpixtype task then the +effect of cacheing in interactive is can be quite noticeable if measurements +of objects in the top and bottom halfs of the image are alternated. + +RADPROF can be run either interactively or in batch mode by setting the +interactive switch to yes. In interactive mode starting x and y coordinates +can either be read directly from the image cursor or read from the text +file specified by \fIcoords\fR. In interactive mode the results are +plotted on the terminal. In batch mode the estimated positions +are read from the text file \fIcoords\fR or the image cursor parameter +\fIicommands\fR is redirected to a text file containing a list of cursor +commands. + +.ih +CURSOR COMMANDS + +The RADPROF cursor commands are listed below. + +.nf + Interactive Keystroke Commands + +? Print help +: Colon commands +v Verify the critical parameters +w Store the current parameters +d Plot radial profile of current star +i Interactively set parameters using current star +c Fit center of current star +t Fit sky around the cursor position +a Average sky values fit around several cursor positions +s Fit sky around the current star +p Fit star using current sky +o Fit star using current sky, output results +f Fit current star +spbar Fit current star, output results +m Move to next star in coordinate list +n Fit next star in coordinate list, output results +l Fit remaining stars in coordinate list, output results +r Rewind the coordinate list +e Print error messages +q Exit task + + + Colon Commands + +:show [data/center/sky/fit] List the parameters +:m [n] Move to next [nth] object in coordinate list +:n [n] Fit next [nth] object in coordinate list, output results + + + Colon Parameter Editing Commands + +# Image and file name parameters + +:image [string] Image name +:coords [string] Coordinate file name +:output [string] Output file name + +# Data dependent parameters + +:scale [value] Image scale (units per pixel) +:fwhmpsf [value] Full-width half-maximum of psf (scale units) +:emission [y/n] Emission features (y), absorption (n) +:sigma [value] Standard deviation of sky (counts) +:datamin [value] Minimum good pixel value (counts) +:datamax [value] Maximum good pixel value (counts) + +# Noise parameters + +:noise [string] Noise model (constant|poisson) +:gain [string] Gain image header keyword +:ccdread [string] Readout noise image header keyword +:epadu [value] Gain (electrons per adu) +:readnoise [value] Readout noise (electrons) + +# Observing parameters + +:exposure [value] Exposure time image header keyword +:airmass [string] Airmass image header keyword +:filter [string] Filter image header keyword +:obstime [string] Time of observation image header keyword +:itime [value] Integration time (time units) +:xairmass [value] Airmass value (number) +:ifilter [string] Filter id string +:otime [string] Time of observation (time units) + +# Centering algorithm parameters + +:calgorithm [string] Centering algorithm +:cbox [value] Width of the centering box (scale units) +:cthreshold [value] Centering intensity threshold (sigma) +:cmaxiter [value] Maximum number of iterations +:maxshift [value] Maximum center shift (scale units) +:minsnratio [value] Minimum S/N ratio for centering +:clean [y/n] Clean subraster before centering +:rclean [value] Cleaning radius (scale units) +:rclip [value] Clipping radius (scale units) +:kclean [value] Clean K-sigma rejection limit (sigma) + +# Sky fitting algorithm parameters + +:salgorithm [string] Sky fitting algorithm +:skyvalue [value] User supplied sky value (counts) +:annulus [value] Inner radius of sky annulus (scale units) +:dannulus [value] Width of sky annulus (scale units) +:khist [value] Sky histogram extent (+/- sigma) +:binsize [value] Resolution of sky histogram (sigma) +:sloclip [value] Low-side clipping factor in percent +:shiclip [value] High-side clipping factor in percent +:smaxiter [value] Maximum number of iterations +:smooth [y/n] Lucy smooth the sky histogram +:snreject [value] Maximum number of rejection cycles +:sloreject [value] Low-side pixel rejection limits (sky sigma) +:shireject [value] High-side pixel rejection limits (sky sigma) +:rgrow [value] Region growing radius (scale units) + +# Photometry parameters + +:apertures [string] List of apertures (scale units) +:zmag [value] Zero point of magnitude scale + +# Profile fitting parameters + +:radius [value] Maximum profile radius (scale units) +:step [value] Step size for computed profile (scale units) +:order [value] Number of spline pieces in fit +:kreject [value] K-sigma rejection for fit (fit sigma) +:nreject [value] Maximum number of rejection cycles + +# Marking and plotting parameters + +:mkcenter [y/n] Mark computed centers on display +:mksky [y/n] Mark the sky annuli on the display +:mkapert [y/n] Mark apertures on the display +:radplot [y/n] Plot the radial profile + + + +The following commands are available from inside the interactive setup menu. + + + Interactive Radprof Setup Menu + + v Mark and verify the critical parameters (f,c,s,a,d,r,w,x) + + f Mark and verify the psf full-width half-maximum + s Mark and verify the standard deviation of the background + l Mark and verify the minimum good data value + u Mark and verify the maximum good data value + + c Mark and verify the centering box width + n Mark and verify the cleaning radius + p Mark and verify the clipping radius + + a Mark and verify the inner radius of the sky annulus + d Mark and verify the width of the sky annulus + g Mark and verify the region growing radius + + r Mark and verify the photometry aperture radii + w Mark and verify the radius of the radial profile + x Mark and verify the step size of radial profile +.fi + +.ih +ALGORITHMS + +Prior to computing the radial profile of the star, RADPROF computes the +center, estimates a sky value, and does aperture photometry on the star +using the parameters in the DATAPARS, CENTERPARS, FITSKYPARS, and +PHOTPARS tasks. + +Next the radial and intensity coordinates of all the pixels inside +\fIradius * scale\fR are computed using the calculated center and sky +values and fit to a least squares cubic spline of order \fIorder\fR with +optional bad data rejection. The fit is interpolated at intervals of +\fIstep_size * scale\fR to derive the output profile and estimate the +full width at half maximum of the object. The fit noise model parameters +are defined in DATAPARS. + +.ih +OUTPUT + +In interactive mode the following quantities are printed on the standard +output as each object is measured. Error is a simple string which +indicates whether an error was encountered in the +the centering algorithm, the sky fitting algorithm, the photometry +algorithm or the spline fitting algorithm respectively. +Mag and merr are the magnitudes and errors in +aperture N and xcenter, ycenter and msky are the +x and y centers and the sky value respectively. +Pfwhm is the fitted full width half maximum of the fitted radial profile. + +.nf + image xcenter ycenter msky pfwhm mag[N] merr[N] iers +.fi + +In both interactive and batch mode full output is written to the text file +\fIoutput\fR. At the beginning of each file is a header listing the +current values of the parameters when the first stellar record was written. +These parameters can be subsequently altered. For each star measured the +following record is written + +.nf + image xinit yinit id coords lid + xcenter ycenter xshift yshift xerr yerr cier error + msky stdev sskew nsky nsrej sier serror + itime xairmass ifilter otime + rapert sum area flux mag merr pier perr + pfwhm inorm tinorm rier rerror + pradius intensity tintensity +.fi + +Image and coords are the name of the image and coordinate file respectively. +Id and lid are the sequence numbers of stars in the output and coordinate +files respectively. Cier and cerror are the error code and accompanying +error message respectively. Xinit, yinit, xcenter, ycenter, xshift, yshift, +and xerr, yerr are self explanatory and output in pixel units. The sense of +the xshift and yshift definitions is the following. + +.nf + xshift = xcenter - xinit + yshift = ycenter - yinit +.fi + +Sier and serror are the error code and accompanying error message respectively. +Msky, stdev and sskew are the best estimate of the sky value (per pixel), +standard deviation and skew respectively. Nsky and nsrej are the number of +sky pixels and the number of sky pixels rejected respectively. + +Itime is the exposure time, xairmass is self-evident, filter is an id +string specifying the filter used during the observation and otime is +a string containing the time of observation in whatever units the user +has defined. + +Rapert, sum, area and flux are the radius of the aperture in pixels, the total +number of counts including sky in the aperture, the area of the aperture in +square pixels, and the total number of counts in the aperture excluding sky. +Mag and merr are the magnitude and error in the magnitude in the aperture +(see below). + +.nf + flux = sum - area * msky + mag = zmag - 2.5 * log10 (flux) + 2.5 * log10 (itime) + merr = 1.0857 * error / flux + error = sqrt (flux / epadu + area * stdev**2 + + area**2 * stdev**2 / nsky) +.fi + +Pier and perror are photometry error code and accompanying error message. + +Pfwhm is the full width at half intensity of the fitted profile. Inorm and +tinorm are the normalization factors for the fitted radial profile and the +fitted total intensity profile respectively. Rier and rerror are the spline +fitting error code and accompanying error message. Pradius, intensity +and tintensity are the computed radii, intensity and total intensity +values at each radial step. + + +.ih +ERRORS + +If the object centering was error free then the field cier will be zero. +Non-zero values of cier flag the following error conditions. + +.nf + 0 # No error + 101 # The centering box is off image + 102 # The centering box is partially off the image + 103 # The S/N ratio is low in the centering box + 104 # There are two few points for a good fit + 105 # The x or y center fit is singular + 106 # The x or y center fit did not converge + 107 # The x or y center shift is greater than maxshift + 108 # There is bad data in the centering box +.fi + +If all goes well during the sky fitting process then the error code sier +will be 0. Non-zero values of sier flag the following error conditions. + +.nf + 0 # No error + 201 # There are no sky pixels in the sky annulus + 202 # Sky annulus is partially off the image + 203 # The histogram of sky pixels has no width + 204 # The histogram of sky pixels is flat or concave + 205 # There are too few points for a good sky fit + 206 # The sky fit is singular + 207 # The sky fit did not converge + 208 # The graphics stream is undefined + 209 # The file of sky values does not exist + 210 # The sky file is at EOF + 211 # Cannot read the sky value correctly + 212 # The best fit parameter are non-physical +.fi + +If no error occurs during the measurement of the magnitudes then pier is +0. Non-zero values of pier flag the following error conditions. + +.nf + 0 # No error + 301 # The aperture is off the image + 302 # The aperture is partially off the image + 303 # The sky value is undefined + 305 # There is bad data in the aperture +.fi + +If no error occurs during the profile fitting then rier is 0. +Non-zero values of rier flag the following error conditions. + +.nf + 0 # No error + 901 # The profile region is off the image + 902 # The profile region is partially off the image + 903 # There are too few points in the profile + 904 # The fit is singular + 905 # The sky value is undefined +.fi + +.ih +EXAMPLES + +1. Compute the radial profiles for a few stars in dev$ypix using the +display and the image cursor. Setup the task parameters using the +interactive setup menu defined by the i key command. + +.nf + ap> display dev$ypix 1 fi+ + + ... display the image + + ap> radprof dev$ypix 7.0 0.5 + + ... type ? to print a short help page + + ... move the image cursor to a star + ... type i to enter the interactive setup menu + ... enter maximum radius in pixels of the radial profile or + CR to accept the default value + ... set the fwhmpsf, centering radius, inner and outer sky + annuli, apertures, sigma, profile radius and step size + using the graphics cursor and the stellar radial profile + plot + ... typing <CR> leaves everything at the default value + ... type q to quit the setup menu + + ... type the v key to verify the parameters + + ... type the w key to save the parameters in the parameter files + + ... move the image cursor to the star of interest and tap + the space bar + + ... type :order 3 to change the spline order and see if the + fit improves, if it does type w + + ... a radial profile plot will appear on the graphics terminal + + ... type q to quit and q to confirm the quit + + ... by default radprof does not create an output file +.fi + +2. Compute the radial profiles for a few stars in dev$ypix using a contour +plot and the graphics cursor. Setup the task parameters using the interactive +setup menu defined by the i key command. This option is only useful for +those users (now very few) who do not have access to an image display server +but do have access to a graphics terminal. + +.nf + ap> show stdimcur + + ... determine the default value of stdimcur + + ap> set stdimcur = stdgraph + + ... define the image cursor to be the graphics cursor + + ap> contour dev$ypix + + ... make a contour plot of dev$ypix + + ap> contour dev$ypix >G ypix.plot1 + + ... store the contour plot of dev$ypix in ypix.plot1 + + ap> radprof dev$ypix 7.0 0.5 + + ... type ? to print the help page + + ... move graphics cursor to a star + ... type i to enter the interactive setup menu + ... enter maximum radius in pixels of the radial profile or + hit CR to accept the default value + ... set the fwhmpsf, centering radius, inner and outer sky annuli, + apertures, sigma, profile radius and step size using the + graphics cursor and the stellar radial profile plot + ... typing <CR> leaves everything at the default value + ... type q to quit the setup menu + + ... type the v key to verify the parameters + + ... type the w key to save the parameters in the parameter files + + ... type :.read ypix.plot1 to reload the contour plot + + ... move the graphics cursor to the star of interest and tap + the space bar + + ... a radial profile plot will appear on the graphics terminal + + ... repeat the above sequence for each additional star + + ... type q to quit and q to confirm the quit + + ... by default radprof does not create an output file +.fi + +3. Setup and run RADPROF interactively on a list of objects temporarily +overriding the fwhmpsf, sigma, cbox, annulus, dannulus, apertures, +radius, and step parameters determined in examples 1 or 2. + +.nf + ap> daofind dev$ypix fwhmpsf=2.6 sigma=25.0 verify- + + ... make a coordinate list + + ... the output will appear in the text file ypix.coo.1 + + ap> radprof dev$ypix 7.0 0.5 fwhmpsf=2.6 sigma=5.0 cbox=7.0 \ + annulus=10.0 dannulus=5.0 apertures=5.0 coords=ypix.coo.1 + + ... type ? for optional help + + + ... move the graphics cursor to the stars and tap space bar + + or + + ... select stars from the input coordinate list with m / :m # + and measure with spbar + + ... measure stars selected from the input coordinate list + with n / n # + + ... a one line summary of results will appear on the standard output + for each star measured + + ... type q to quit and q again to confirm the quit + + ... by default radprof does not create an output file +.fi + +4. Display and fit some stars in an image section and write the output +coordinates in the coordinate system of the parent image. + +.nf + ap> display dev$ypix[150:450,150:450] 1 + + ... display the image section + + ap> radprof dev$ypix[150:450,150:450] 7.0 0.5 output=default \ + wcsout=tv + + ... move cursor to stars and type spbar + + ... type q to quit and q again to confirm quit + + ... output will appear in ypix.prf.1 + + ap> pdump ypix.prf.1 xc,yc yes | tvmark 1 STDIN col=204 +.fi + + +5. Run RADPROF in batch mode using the coordinate file and the previously +saved parameters. Save the text and plot output. + +.nf + ap> radprof dev$ypix 7. 0.5 coords=ypix.coo.1 output="default" \ + plotfile=ypix.rplots inter- verify- + + ... output will appear in m92.prf.2 and ypix.rplots + + ap> gkidir ypix.rplots + + ... get a listing of the plots in ypix.rplots + + ap> gkiextract ypix.rplots 1-3 | stdplot dev=lw16 + + ... extract plots 1-3 and plot them on device lw16 +.fi + +6. Repeat example 5 but assume that the input coordinates are ra and dec +in degrees and degrees, turn off verification, and submit the task to to +the background. + +.nf + ap> display dev$ypix 1 + + ap> rimcursor wcs=world > radec.coo + + ... move to selected stars and type any key + + ... type ^Z to quit + + ap> radprof dev$ypix 7.0 0.5 coords=radec.coo output=default \ + plotfile=ypix.rplots2 wcsin=world verify- inter- & + + ... output will appear in ypix.prf.3, plots will appear in + ypix.rplots2 + + ap> pdump ypix.prf.3 xc,yc yes | tvmark 1 STDIN col=204 + + ... mark the stars on the display +.fi + + +7. Run RADPROF interactively without using the image display. + +.nf + ap> show stdimcur + + ... record the default value of stdimcur + + ap> set stdimcur = text + + ... set the image cursor to the standard input + + ap> radprof dev$ypix 7.0 0.5 coords=ypix.coo.1 + + ... type ? for optional help + + ... type :m 3 to set the initial coordinates to those of the + third star in the list + + ... type i to enter the interactive setup menu + ... enter the maximum radius in pixels for the radial profile or + accept the default with a CR + ... type v to enter the default menu + ... set the fwhmpsf, centering radius, inner and outer sky annuli, + apertures, and sigma using the graphics cursor and the + stellar radial profile plot + ... typing <CR> after the prompt leaves the parameter at its default + value + ... type q to quit the setup menu + + ... type r to rewind the coordinate list + + ... type n to measure the next star + + ... a one line summary of the answers will appear on the standard + output for each star measured + + ... type q to quit followed by q to confirm the quit + + ... by default no output file is written + + ap> set stdimcur = <default> + + ... reset the value of stdimcur +.fi + +8. Use a image cursor command file to drive the RADPROF task. The cursor +command file shown below sets the cbox, annulus, dannulus, and apertures +parameters computes the centers, sky values, magnitudes, and readial profiles +for 3 stars, updates the parameter files, and quits the task. + +.nf + ap> type cmdfile + : cbox 9.0 + : annulus 12.0 + : dannulus 5.0 + : apertures 5.0 + 442 410 101 \040 + 349 188 101 \040 + 225 131 101 \040 + w + q + + ap> radprof dev$ypix 7.0 0.5 icommands=cmdfile \ + plotfile=ypix.rplots3 verify- + + ... by default no output file is written, plots will appear in + ypix.rplots3 +.fi + + +.ih +BUGS + +It is currently the responsibility of the user to make sure that the +image displayed in the frame is the same as that specified by the image +parameter. + +Commands which draw to the image display are disabled by default. +To enable graphics overlay on the image display, set the display +parameter to "imdr", "imdg", "imdb", or "imdy" to get red, green, +blue or yellow overlays and set the centerpars mkcenter switch to +"yes", the fitskypars mksky switch to"yes", or the photpars mkapert +witch to "yes". It may be necessary to run gflush and to redisplay the image +to get the overlays position correctly. + +.ih +SEE ALSO +datapars, centerpars, fitskypars, photpars +.endhelp diff --git a/noao/digiphot/apphot/doc/specs/Ap.doc b/noao/digiphot/apphot/doc/specs/Ap.doc new file mode 100644 index 00000000..66744d58 --- /dev/null +++ b/noao/digiphot/apphot/doc/specs/Ap.doc @@ -0,0 +1,1071 @@ +APPHOT (Aug83) Digital Aperture Photometry Package APPHOT (Aug83) + + + +1. Introduction + + The APPHOT package will provide a set of routines for performing +aperture photometry on uncrowded or moderately crowded fields, in +either interactive or batch mode. The basic photometry technique +employed shall be fractional-pixel aperture integration; no PSF +fitting techniques shall be employed, and no knowledge of the PSF +shall be required. This document presents the formal requirements and +specifications for the package, and describes the algorithms to be +used. + + + +2. Requirements + + (1) The program shall take as input an IRAF imagefile containing a + starfield which has been corrected for pixel to pixel gain + variations, high frequency fluctuations in the background, + nonlinearity, and any other instrumental defects affecting the + intensity value of a pixel. + + (2) Given as input the approximate coordinates of a single object + in the image, the program shall perform the following + operations: + + o Determine a constant background value by analysis of + an annular region surrounding the object. The + background is assumed to be flat in the region of the + object, but may contain contaminating objects or + defects which shall be detected and eliminated by the + fitting algorithm. It shall be permissible for the + background region to extend beyond the boundaries of + the image; the out of bounds region of the annulus + shall be excluded from the fit. + + o Determine the center of the object, taking the + approximate object coordinates given as input as a + starting point. The center determination shall be + resistant to the affects of nearby contaminating + objects. The centering algorithm may assume that the + object is circularly symmetric, or nearly so, and that + the object flux is positive. + + o Determine the integral of object minus background + within one or more circular apertures centered upon + the object. The integration shall be performed using + partial pixel techniques, to minimize the effects of + sampling. If the aperture contains any indefinite + pixels, or if the aperture extends beyond the boundary + of the image, an indefinite result shall be returned. + + (3) The following options shall be provided to modify the + operation of the above functions: + + + -1- +APPHOT (Aug83) Digital Aperture Photometry Package APPHOT (Aug83) + + + + o Use a user supplied constant background value and + background noise estimate instead of fitting the + background. + + o Use the starting center as the actual center in all + cases. + + o Use the starting center as the actual center if the + object is very faint, but tweak up the center if the + signal to noise is above a certain threshold. + + o Allow the object aperture to extend beyond the image + boundary, using only that portion of the aperture + which is in bounds when computing the aperture + integral. + + (4) At a minimum, the following parameters shall be calculated and + output for each object: + + o The coordinates of the object, and the estimated error + in these coordinates. + + o The mode and standard deviation of the background; the + number of pixels left in the background region after + pixel rejection. + + o The magnitude of the object, to within an arbitary + zero-point, and the statistical uncertainty of the + magnitude. If multiple concentric apertures are used, + a magnitude and uncertainty shall be given for each. + + (5) The program shall be usable both interactively and in batch + mode. In interactive use, the user shall be able to mark the + positions of the objects by interactively positioning a cursor + on a 2-dim display device. It shall be possible to enter the + control parameters for the analysis routines interactively for + each object. In batch mode, the control parameters shall be + fixed, and object coordinates shall be taken from a user + supplied list. The display device shall not be required in + batch mode. + + (6) The APPHOT package shall be written in the SPP language in + conformance with the standards and conventions of IRAF. The + code shall be portable and device independent. + + + +2.1 Summary of the Limitations of APPHOT + + The APPHOT package is designed to perform simple aperture +photometry subject to the following restrictions: + + (1) Objects must be circular or nearly circular, since the + + + -2- +APPHOT (Aug83) Digital Aperture Photometry Package APPHOT (Aug83) + + + + aperture is circular. + + (2) All pixels within the object aperture are weighted equally. + All pixels in the object aperture must be present; the object + aperture may not normally extend outside the image. Defective + pixels within the object aperture may not be detected. + + (3) The background must be approximately flat in the neighborhood + of the object being measured. The background must have a + unique mode, or the background fitting routine will reject the + object. Any low frequency fluctuations in the background + should be removed before using APPHOT. + + (4) The object aperture must be kept small to minimize the + degradation of signal to noise caused by sky pixels within the + aperture, and to minimize the effects of crowding. Therefore, + the wings of the object will extend beyond the aperture. Good + photometric results will be obtained only if the aperture is + consistently well centered, and if the shape and diameter of + an object is constant throughout the image and invariant with + respect to magnitude. + + + +3. Specifications + + The APPHOT package performs aperture photometry on digitized +starfields maintained as IRAF imagefiles. Input to the package +consists of an imagefile, a list of object coordinates, and numerous +parameters controlling the analysis algorithms. Output consists of +successive lines of text, where each line summarizes the results of +the analysis for a particular object. The output may be saved in a +textfile, which may easily be printed or written onto a card image +tape for export. The package routines may be used either +interactively or in batch mode. + +The CL callable part of the APPHOT package consists of the following +routines: + + apphot -- the main aperture photometry routine. + coordtr -- translations and rotations of coord lists. + fitsky -- computes mode and sigma of a sky region. + fitpsf -- compute the FWHM of the PSF. + imcursor -- reads the image cursor; used to make lists. + immark -- marks objects on the display device. + radprof -- computes the radial profile of an object. + +Routines for general list manipulation, reading and writing card image +tapes, reading and writing images to FITS tapes, removing the +instrumental signature from the data, and so on are available +elsewhere in the IRAF system. The package is easily extended to +include peak finding, matching of object lists from different images, +background fitting and removal, and so on. The APPHOT package shall + + + -3- +APPHOT (Aug83) Digital Aperture Photometry Package APPHOT (Aug83) + + + +eventually supplant both the KPNO AUTOPHOT and KPNO "Mountain +Photometry Code" packages. + + + +3.1 Standard Analysis Procedures + + Before performing aperture photometry one must determine the radius +of the object aperture to be used, the inner radius and size of the +annulus to be used to fit the background, the full width at half max +(FWHM) of the point spread function (PSF), and so on. Additional +parameters are required by the centering algorithm. A list of object +centers must be prepared if APPHOT is to be used in batch mode. The +standard procedure is as follows: + + (1) Use RADPROF to determine values for the following parameters: + + - the object aperture radius or radii, in pixels + - the inner radius of the annular (sky) region + - the width of the annular region + + (2) Use FITPSF to fit gaussians to isolated, high signal to noise + data objects, to determine the FWHM of the point spread + function. + + (3) Use FITSKY to determine the sky sigma (standard deviation). + APPHOT assumes that sigma is approximately constant throughout + the image. + + (4) If one does not wish to manually mark object positions with + the cursor during analysis, i.e. when the analysis is to be + done in batch, a list of object coordinates must be prepared. + This may be done in many ways: + + o By running RCURSOR with the standard output redirected + into the list file. + + o By transforming an existing list with COORDTR, OPSTRM, + MATCH, SORT, WINDOW, the editor, or some other filter. + + o By an automatic object finding procedure, if one is + available. + + o By any other program which generates a list of object + coordinates, where each line of the list describes one + object, and where x and y in pixel coordinates are + given in columns one and two. Additional columns, if + present, are ignored. + + o APPHOT output may be used as coordinate input in a + subsequent run. + + (5) Finally, APPHOT is run to measure the objects. The user + + + -4- +APPHOT (Aug83) Digital Aperture Photometry Package APPHOT (Aug83) + + + + should be familiar with the algorithms used to fit the + background, measure the object center, and compute the + aperture integral, magnitude, and errors. The values of all + visible and hidden APPHOT parameters should be inspected + before doing any serious processing. + +The general purpose IRAF list processing tools may be used for further +analysis of APPHOT output. Output lists may be filtered to select +objects based on the value of a list column, i.e., all the objects +within a certain magnitude range may be selected, objects with +estimated errors larger than a certain value may be deleted, or a list +may be sorted using the value in any column. Columns may be extracted +from a list to form new lists or to provide input to a plot filter, +and lists may be merged. Arithmetic may be performed on lists to +calculate colors, etc. + +The remainder of this section presents detailed specifications for the +analysis procedures in the APPHOT package. + + + +3.2 The APPHOT Program + + The function of the APPHOT procedure is to perform aperture +photometry on isolated objects within an image. The principal input +operands are the name of the imagefile and the rough coordinates of +the objects to be processed. The principal output operands are the +coordinates and magnitudes of the objects. + +In order to perform aperture photometry APPHOT must perform the +following sequence of operations (the algorithms employed are +explained in more detail later in this section): + + (1) The mode and sigma of an annular background region centered on + the object is calculated. + + (2) The center of the object is determined. + + (3) The background is subracted from the object, and the total + flux within the object aperture or apertures is calculated. + +Steps (1) and (2) above are optional; the background and center may be +determined externally, rather than by APPHOT, if desired. + + +3.2.1 APPHOT parameters + + APPHOT has quite a few parameters due to the complexity of the +algorithms employed. All data dependent parameters are query mode to +ensure that they get set properly when a new image is processed. The +data independent algorithm control parameters are hidden mode, and are +given reasonable default values. The names, datatypes, and default +values of the APPHOT parameters are shown below. + + + -5- +APPHOT (Aug83) Digital Aperture Photometry Package APPHOT (Aug83) + + + +Positional or query mode parameters: + + image filename + apertures string + annulus real + width_annulus real + fwhm_psf real + sky_sigma real + + +List structured parameters (filename may be given on command line): + + sky_mode *real + coords *imcur + + +Hidden parameters: + + spool boolean no + output filename "apphot.out" + fitsky boolean yes + max_sky_iter integer 50 + growing_radius real 1.0 (fwhm_psf units) + k1 real 5.0 + k2 real 2.0 + center boolean yes + clean boolean yes + cleaning_radius real 0.8 (fwhm_psf units) + clipping_radius real 1.5 (fwhm_psf units) + max_cen_shift real 1.0 (fwhm_psf units) + min_snratio real 0.5 + zmag real 26.0 + verbose boolean yes + + +The function and format of each of these parameters is explained in +more detail below. + + + image The name of the image or image section to be + processed. + + output The name of the output textfile used to spool + APPHOT output. If null, output will not be + spooled. Note that output always appears on the + standard output, whether or not spooling is in + effect. + + apertures The radii in pixels of the concentric object + apertures, given all on the same line, delimited + by blanks. At least one aperture must be given; + the maximum number of apertures is limited by the + length of a line. A sample input string might be + + + -6- +APPHOT (Aug83) Digital Aperture Photometry Package APPHOT (Aug83) + + + + "5.0 5.5 6.0 6.5 7.0". If only a single aperture + is to be used, a real expression may be used + instead of a string type argument. The apertures + need not be given in any particular order. The + average radius will be used to compute the + uncertainty in the object magnitude. + + annulus The inner radius of the annular sky region, in + pixels. + + width_annulus The width of the annular sky region, in pixels. + + fwhm_psf The FWHM of the psf, in pixels. Used as a scale + factor to control the internal algorithms. + + sky_sigma The standard deviation (noise value) of a typical + region of sky in the image. Used for pixel + rejection in the sky fitting algorithm. + + sky_mode The name of a list file containing the mode of the + background of each of the objects to be + processed. Required only if FITSKY is switched + off. If sky fitting is disabled, and no list file + is given, APPHOT will query for the sky value. + + coords The name of a list file containing the coordinates + of the objects to be processed. If absent, + objects may be marked interactively with the + cursor. + + fitsky A switch used to specify whether or not the + background will be fitted. If background fitting + is disabled, the mode and sigma of the background + will be read from the SKY_FILE list each time an + object is processed. + + max_sky_iter The maximum number of iterations for the sky + fitting algorithm. Since the sky fitting + algorithm is guaranteed to converge, this + parameter should normally have a large value. If + the value is zero, the median of the sky region + will be used instead of the mode. + + growing_radius The region growing radius for pixel rejection in + the sky region, in units of FWHM_PSF. When a bad + sky pixel is detected, all pixels within + (growing_radius * fwhm_psf) pixels of the bad + pixel will be rejected. Used to exclude the wings + of contaminating objects from the sky sample, to + avoid biasing the mode. + + k1 The k-sigma clipping factor for the first phase of + the sky fitting algorithm. + + + -7- +APPHOT (Aug83) Digital Aperture Photometry Package APPHOT (Aug83) + + + + k2 The k-sigma clipping factor for the second, + iterative, phase of the sky fitting algorithm. + + center A switch used to specify whether or not centering + is to be performed. If centering is disabled, the + initial center will be used as the object center. + + clean A switch used to specify whether or not the + symmetry-clean algorithm is to be employed during + centering. + + cleaning_radius The cleaning radius for the symmetry-clean + algorithm, in units of FWHM_PSF. + + clipping_radius The clipping radius for the symmetry-clean + algorithm, in units of FWHM_PSF. + + max_cen_shift The maximum permissible shift of center, in units + of FWHM_PSF. If the shift produced by the + centering algorithm is larger than this value, the + fit will terminate and no magnitude will be + calculated. + + min_snratio Centering will be skipped if the signal to noise + of the object, as calculated from the initial + center, is less than the value given by this + parameter. + + zmag Zero point for the output magnitude scale. + + verbose If enabled, the output columns are labeled. Note + that the presence of column labels in the output + may interfere with the use of the list processing + tools. + + + +3.2.2 The APPHOT Background Fitting Algorithm + + A good background fit is essential to aperture photometry. Fitting +the background is trivial in a sparse field, but difficult in a crowded +field. In general the background region will contain contaminating +objects which must be detected and excluded if a good fit is to be +obtained. + +The algorithm employed here is based on the fact that contaminated +pixels are almost always spatially correlated. Background fitting +algorithms which work with a one dimensional sample (mode, median), or +with the one dimensional histogram (mode of hgm) have difficulty +rejecting the faint wings of contaminated regions. This is a serious +defect of one dimensional fitting algorithms, because it is these +faint wings, not the bright central pixels, which are most likely to +bias the calculated background value. + + + -8- +APPHOT (Aug83) Digital Aperture Photometry Package APPHOT (Aug83) + + + +The algorithm used in APPHOT is as follows: + + + algorithm fit_sky + + begin + # Reject gross deviants. + compute the median of the annular region + detect pixels more than (k1*sky_sigma) from the median + reject all such pixels, without region growing + + # Detect and reject contaminating objects. + while (number of iterations <= max_sky_iter) { + compute the histogram of the reduced sample + compute the sigma and mode of the histogram + detect pixels more than k2*sigma from the mode + reject all such pixels, with region growing + if (no pix rejected or all pix rejected) + terminate loop + } + + return the final mode, sigma, and sample size + end + + +The mode of the histogram is found by cross correlating the noise +function with the histogram. The width of the the noise function is +given by the standard deviation of the current sample. Pixel +rejection is performed by locating all pixels more than k2*sigma from +the mode, and blindly rejecting all pixels within a certain radius of +each deviant pixel. This simple algorithm works well because the +sample is large, and therefore there is little penalty for discarding +pixels that might not be deviant. Region growing also tends to +accelerate convergence significantly. + +Very faint contaminating objects are difficult to detect and reject. +If there are enough such objects, they should not be rejected, because +there are probably a few in the object aperture as well. A higher sky +sigma will be calculated and the computed uncertainty in the magnitude +will increase. The best solution to this problem may be to increase +the size of the annulus to minimize the bias and maximize the liklihood +of a detection. + + + +3.2.3 The APPHOT Centering Algorithm + + The centering algorithm used in APPHOT is that of Auer and Van +Altena, with the addition of the symmetry-clean algorithm developed by +Barry Newell. The main algorithm is as follows: + + + + + + -9- +APPHOT (Aug83) Digital Aperture Photometry Package APPHOT (Aug83) + + + + algorithm get_center + + begin + if (centering is disabled) { + return initial center, zero uncertainty estimate + + } else if (signal to noise of object < MIN_SNRATIO) { + compute uncertainty using initial center + return initial center, computed uncertainty + + } else { + call measure_center + return image center and estimated uncertainty + } + end + + +The actual center determination is carried out by the following +algorithm: + + + algorithm measure_center + + begin + extract subarray from the main data array + + # Perform symmetry-cleaning. + if (cleaning is enabled) { + for (each pair of pixels diametrically opposed about + the image center beyond the cleaning radius) + if (i2 > i1 + 2*sky_sigma) + replace i2 by i1 + else if (i1 > i2 + 2*sky_sigma) + replace i1 by i2 + + perform 2*sky_sigma noniterative clip of all pixels + beyond the clipping radius, to remove any remaining + radially symmetric structures + } + + # Compute the image center and uncertainty. + compute x and y marginals of the cleaned subarray + fit a gaussian of width FWHM_PSF to each marginal + compute the centering error from the covariance matrix + + return image center and estimated uncertainty + end + + +The effect of the symmetry-clean algorithm is to edit the raster, +removing any contaminating objects in the vicinity of the primary +object. This simplifies the fitting algorithm and increases its +reliability, since it does not have to deal with multipeak marginal + + + -10- +APPHOT (Aug83) Digital Aperture Photometry Package APPHOT (Aug83) + + + +distributions. + +A gaussian is fitted to the marginal distributions because it is +expected to yield a better center determination for undersampled +data. An alternative is to empirically derive the marginal +distributions of the psf and fit these to each data object. This is a +better approach in some cases, but in the case of undersampled data it +is difficult to derive the marginal distributions due to sampling +effects, and fitting is difficult due to interpolation error. The use +of a gaussian eliminates interpolation error. Eventually, both +techniques should be made available. + + + +3.2.4 The APPHOT Aperture Integration Algorithm + + The integral of the flux within a circular aperture is computed by +fractional pixel techniques. Pixels are assumed to be square apertures +arranged in a rectangular grid. The fraction of a pixel which lies +within the circular APPHOT aperture is computed by an approximation, +and all such contributions are summed to produce the total integral. + +The simplicity of aperture photometry limits the amount of information +available for error analysis. Using only the noise value for the +background, the estimated error in the aperture integral is given by + + flux_error = sky_sigma * sqrt (aperture_area) + +where "sky_sigma" is either the sigma calculated by the background +fitting algorithm or the parameter SKY_SIGMA, depending on whether sky +fitting is enabled, and where "aperture_area" is the fractional pixel +area of the aperture. + +It is possible, however, to produce a more useful error estimate if we +include some information about the psf. For the purposes of an +improved error estimate, we assume that the PSF is a gaussian. Given +the object center, the background, and the FWHM of the PSF, it is +trivial to fit a two dimensional gaussian to the object. An estimate +of the average noise value for the pixels within the aperture may then +be obtained by computing the standard deviation of the residual formed +by subtracting the fitted two-dimensional gaussian from the data. +This value is used in place of SKY_SIGMA in the above equation for an +improved estimate of the actual flux error. + +In the limit as the gaussian goes to zero, both uncertainty estimates +tend to the same value, as they should. For bright objects, the +uncertainty produced by analysis of the residual will tend to be +pessimistic, since it is unlikely that the PSF can actually be modeled +by a simple gaussian. Nonetheless, a plot of uncertainty versus +magnitude should reveal objects which are blended, which contain bad +pixels, and so on. The accuracy of the gaussian model will determine +how reliably deviant objects can be discriminated. + + + + -11- +APPHOT (Aug83) Digital Aperture Photometry Package APPHOT (Aug83) + + + +3.2.5 APPHOT Output + + For each object processed, APPHOT prints a single line of text on +the standard output. If desired, APPHOT will simultaneously spool +output into a user specified text file. Each output line will contain +the following information (excluding the commas): + + + x,y,cenerr,shift, mode,sigma,nskypix, mag1,...,magn,magerr + +where + + x,y object coordinates in pixels + cenerr estimated uncertainty in the object center + shift shift of center from initial coordinates + mode mode of the background + sigma sigma of the background + nskypix number of sky pixels left after rejection + mag1 magnitude within the first annulus + magn magnitude within the Nth annulus + magerr estimated mag. uncertainty at the average radius + + +Note that the estimated uncertainty in the magnitude is given only for +the average object aperture radius. The uncertainty for the other +apertures can easily be calculated given SIGMA and the area of each +aperture. The zero point for the magnitude scale is given by the +hidden parameter ZMAG. + +Additional information could be calculated and output (such as the +moments of the object and the skew of the background), but in our +experience few people ever look at such information, and a more complex +output format would be required. Probably the calculation of anything +but object centers, magnitudes, and errors should be left to other +programs. + + + +3.3 The COORDTR Program + + The function of COORDTR is to effect a linear translation and/or +rotation of a coordinate list. COORDTR is a filter; coordinate lines +are read from the standard input and written to the standard output. +COORDTR is concerned only with coordinate transformations, and knows +nothing about image boundaries. A transformed coordinate may no longer +lie within an image. + + x y other_stuff + +The format of a coordinate line is shown above. COORDTR operates only +on the coordinate pair x,y. Any additional information on the line is +passed on to the output without modification. + + + + -12- +APPHOT (Aug83) Digital Aperture Photometry Package APPHOT (Aug83) + + + +COORDTR is actually a general purpose list processing operator, and +belongs in a list processing package, rather than in the APPHOT +package. When a list processing package is developed, COORDTR will be +moved to that package. + +A COORDTR transformation consists of a linear translation followed by +a rotation. Either the translation, the rotation, or both may be +skipped. The COORDTR parameters are summarized below. + + +positional arguments: + + xshift real + yshift real + xcenter real + ycenter real + theta real + + +hidden parameters: + + translate boolean yes + rotate boolean no + + +If more than two positional arguments are given, COORDTR knows that +both a translation and a rotation are desired. Otherwise the boolean +parameters TRANSLATE and ROTATE are read to determine what additional +parameters are needed. Thus a simple linear translation of +2.5 +pixels in X and -0.2 pixels in Y would be specified by the command + + coordtr (2.5, -.2, < "input", > "output") + +which transforms the list in file "input", writing the output into the +new file "output". + +If a rotation is desired, XCENTER, YCENTER, and THETA must be given. +The first two parameters specify the pixel coordinates of the point +about which the rotation is to be performed, while THETA specifies the +rotation angle in degrees. Positive THETA produces a counterclockwise +rotation, if positive X is to the right and positive Y is up. + + + +3.4 The FITSKY Program + + The function of the FITSKY program is to determine the mode and +sigma of the specified annular regions, printing the results (mode, +sigma, and npix) on the standard output. FITSKY is similar in +operation to APPHOT, except that its function is to fit sky, not +perform aperture photometry. The FITSKY parameters are the following: + + + + + -13- +APPHOT (Aug83) Digital Aperture Photometry Package APPHOT (Aug83) + + + +Positional or query mode parameters: + + image filename + annulus real + width_annulus real + fwhm_psf real + + +List structured parameters (filename may be given on command line): + + coords *imcur + + +Hidden parameters: + + spool boolean no + output filename "fitsky.out" + max_sky_iter integer 50 + growing_radius real 1.0 (fwhm_psf units) + k1 real 5.0 + k2 real 2.0 + verbose boolean yes + + +The names and functions of the FITSKY parameters are the same as those +for APPHOT. Note that ANNULUS may be set to zero to measure the +background within a circular aperture. The maximum number of +iterations may be set to zero to measure the median of the sky sample. +FITSKY output may be spooled into a file and used as input to APPHOT. + + + +3.5 The FITPSF Program + + The function of the FITPSF program is to determine the FWHM of the +point spread function. This is done by selecting an isolated, high +signal to noise object, computing the x and y marginal profiles, and +fitting a gaussian to each profile. Output consists of the object +center, the error in the center, and the FWHM of the fitted gaussians. +Note that the sigma of a gaussian may be obtained by dividing the FWHM +by 2.354. + + x y err x_fwhm y_fwhm + +The input parameters for the FITPSF program are shown below. + + + + + + + + + + + -14- +APPHOT (Aug83) Digital Aperture Photometry Package APPHOT (Aug83) + + + +Positional parameters: + + image filename + aperture real + annulus real + width_annulus real + sky_mode real + coords *imcur + + +Hidden parameters: + + fitsky boolean yes + center boolean yes + spool boolean no + output filename "fitpsf.out" + verbose boolean yes + + +If background fitting is disabled, the parameter SKY_MODE defines the +sky level. The background fitting algorithm is a simple median +calculation without pixel rejection or iteration. This should be +sufficient, since FITPSF is expected to be used mainly in uncrowded +regions on high signal to noise objects. + +Note that FITPSF is set up to process a list of input objects. The +list processing tools (i.e., AVERAGE) may be used to average the +results to produce the final FWHM of the PSF for the image. + + + +3.6 The IMCURSOR Program + + The function of the IMCURSOR program is to read the STDIMAGE +cursor, writing the cursor coordinates on the standard output. The +cursor is read until the EOF character is entered to terminate the +loop. The standard output may be redirected into a file to generate a +coordinate list. IMCURSOR has no parameters. + + + +3.7 The IMMARK Program + + The function of IMMARK is to draw marks on the diplay device. +IMMARK is useful for verifying coordinate lists. + + +parameters: + + mark_type string + mark_size real + coords *imcur + + + + -15- +APPHOT (Aug83) Digital Aperture Photometry Package APPHOT (Aug83) + + + +Output is the current frame of the STDIMAGE device. Mark types +include "circle", "box", "cross", "plus", and "diamond". The size of +a mark is given in pixels. The third parameter is a standard +coordinate list. If no list is given, the image cursor will be read +instead. + + + +3.8 The RADPROF Program + + The function of the RADPROF program is to compute the radial +profile of an object. The output of RADPROF consists of a sequence of +lines of text, each line defining the profile at a single radius. +Since RADPROF may generate many lines of output for a single input +object, it is set up to process only a single input object. A CL +while loop may be written to process multiple objects, if desired. + + +positional arguments: + + image filename + aperture real + step_size real + annulus real + width_annulus real + sky_mode real + + +hidden parameters: + + fitsky boolean yes + center boolean yes + verbose boolean yes + + +The radial profile is calculated from the image center out to the +radius specified by the parameter APERTURE, in steps of STEP_SIZE +pixels. The remaining RADPROF parameters are similar to those of +APPHOT and will not be discussed in detail. If background fitting is +disabled, the parameter SKY_MODE defines the sky level. The +background fitting algorithm is a simple median calculation without +pixel rejection or iteration. This should be sufficient, since +RADPROF is expected to be used mainly in uncrowded regions on high +signal to noise objects. Centering is via gaussian fits to the +marginal profiles, without cleaning. + +RADPROF output lines contain the following fields: + + r, i(r), inorm(r), fraction(r) + +where + + r radius in pixels + + + -16- +APPHOT (Aug83) Digital Aperture Photometry Package APPHOT (Aug83) + + + + i(r) raw intensity at r + inorm(r) normalized intensity at r (range 0-1) + fraction(r) fraction of total integral at r + + +RADPROF does not generate any plots. If one wishes to plot the +contents of an output column, the column may be extracted with a list +processing filter and piped to a graphics task. + + + +4.0 Example + + A brief example may help illustrate the use of the package. +Suppose we want to process a few hundred stars on images "blue" and +"red". We start by analyzing the blue image. + + ap> radprof blue,15,0.5,20,10 + +This gives us a radial profile printout for one of the "blue" stars. +We decide that an aperture radius of 2.5 pixels is about right. The +annulus will start at a radius of 10.0 pixels and extend to 20.0 +pixels. The next step is to determine the FWHM of the PSF: + + ap> fitpsf blue,3,10,20 | tee spoolfile + +By default, the program will take coordinate input by reading the image +display cursor. When the program is waiting for cursor input, it will +cause the display cursor to blink rapidly; normally the cursor does not +blink. One has to be aware of this, because no other prompt is issued. +We postion the cursor on several stars, and tap the space bar to +measure each one. When finished we type the EOF character (<ctrl/z> +on our systems) to terminate the loop. The screen will now look like +this (the output column labels are ommitted): + + ap> fitpsf blue,3,10,20 | tee spoolfile + 283.12 157.40 0.035 2.887 2.751 + 546.08 213.45 0.023 2.833 2.902 + 318.32 354.73 0.064 2.791 2.824 + +Since we elected to use TEE to spool the output, rather than the SPOOL +parameter of FITPSF, we will not see the results until all stars have +been measured. The next step is to average the results, to determine +the final FWHM (the FITPSF output could have been piped directly to +GETCOLS without using an intermediate spoolfile, if desired). + + ap> getcols spoolfile,"4-5" | getcols | average + 2.83133 0.0569725 6 + +There are many ways this average could have been computed, of course; +this is only one example. Next, to avoid having to write down the +FWHM value, we put it into the appropriate APPHOT parameter (note that +the parameter name is abbreviated). + + + -17- +APPHOT (Aug83) Digital Aperture Photometry Package APPHOT (Aug83) + + + + ap> apphot.fwhm = 2.831 + +Finally, we must determine a representative backround sigma value for +the image. This is done by using FITSKY to measure several sky areas, +and averaging column two of the output, much as we did for FITPSF. The +final value may be saved in "apphot.sky_sigma". + +By this point we have determined all the necessary parameters, and it +is time to do some photometry. The only APPHOT argument we are sure +of is the image name parameter, so that is all we include on the +command line: + + ap> apphot blue + aperture radii, pixels: 2.4 2.5 2.75 3.0 + inner radius of sky annulus: 10 + width of sky annulus (1 - ): 10 + full width at half max of psf (2.831): + standard deviation of the image noise function (23.733): + +After responding to the prompts shown above, APPHOT will ask for the +first pair of object coordinates, and the cursor blink prompt will +again be given. Several objects may be measured to verify that all is +working. + +The last step is to prepare a list of objects to be processed. The +simplest way to do this is to interactively mark the objects with the +cursor. Later, when we process the "red" image, the same coordinate +list may again be used, possibly after filtering with COORDTR. + + ap> imcursor > objlist + +At this point, all of the APPHOT parameters have been set, we have a +list of objects to be processed, and we are ready to run APPHOT in +batch mode. We decide to save the output in the file "blue.out". To +ensure that we have a record of the parameters used for the fit, we +first print the APPHOT parameters into the output file, then we start +up the APPHOT batch run. + + ap> lparam apphot > blue.out + ap> apphot >> blue.out & + [1] + +The batch job is now running, appending output lines to the file +"blue.out". We can proceed to set up the job for the red image, in +much the same way that we set up the job for the blue image. When +both jobs finish, we can use the list processing tools to filter out +the good objects and calculate colors. diff --git a/noao/digiphot/apphot/doc/specs/Ap.spc b/noao/digiphot/apphot/doc/specs/Ap.spc new file mode 100644 index 00000000..911d04f1 --- /dev/null +++ b/noao/digiphot/apphot/doc/specs/Ap.spc @@ -0,0 +1,1032 @@ +.help apphot Aug83 "Digital Aperture Photometry Package" +.sh +1. Introduction + + The APPHOT package will provide a set of routines for performing +aperture photometry on uncrowded or moderately crowded fields, in either +interactive or batch mode. The basic photometry technique employed +shall be fractional-pixel aperture integration; no PSF fitting techniques +shall be employed, and no knowledge of the PSF shall be required. +This document presents the formal requirements and specifications for +the package, and describes the algorithms to be used. + +.sh +2. Requirements +.ls 4 +.ls (1) +The program shall take as input an IRAF imagefile containing a starfield +which has been corrected for pixel to pixel gain variations, high frequency +fluctuations in the background, nonlinearity, and any other instrumental +defects affecting the intensity value of a pixel. +.le +.ls (2) +Given as input the approximate coordinates of a single object in the image, +the program shall perform the following operations: +.ls 4 +.ls o +Determine a constant background value by analysis of an annular region +surrounding the object. The background is assumed to be flat in the region +of the object, but may contain contaminating objects or defects which +shall be detected and eliminated by the fitting algorithm. +It shall be permissible for the background region to extend beyond the +boundaries of the image; the out of bounds region of the annulus shall +be excluded from the fit. +.le +.ls o +Determine the center of the object, taking the approximate object +coordinates given as input as a starting point. +The center determination shall be resistant to the affects of nearby +contaminating objects. The centering algorithm may assume that the object +is circularly symmetric, or nearly so, and that the object flux is positive. +.le +.ls o +Determine the integral of object minus background within one or more +circular apertures centered upon the object. The integration shall be +performed using partial pixel techniques, to minimize the effects of +sampling. If the aperture contains any indefinite pixels, or if the +aperture extends beyond the boundary of the image, an indefinite result +shall be returned. +.le +.le +.le +.ls (3) +The following options shall be provided to modify the operation of the +above functions: +.ls +.ls o +Use a user supplied constant background value and background noise estimate +instead of fitting the background. +.le +.ls o +Use the starting center as the actual center in all cases. +.le +.ls o +Use the starting center as the actual center if the object is very faint, +but tweak up the center if the signal to noise is above a certain threshold. +.le +.ls o +Allow the object aperture to extend beyond the image boundary, +using only that portion of the aperture which is in bounds when computing +the aperture integral. +.le +.le +.le +.ls (4) +At a minimum, the following parameters shall be calculated and output +for each object: +.ls +.ls o +The coordinates of the object, and the estimated error in these coordinates. +.le +.ls o +The mode and standard deviation of the background; the number of pixels +left in the background region after pixel rejection. +.le +.ls o +The magnitude of the object, to within an arbitary zero-point, and +the statistical uncertainty of the magnitude. If multiple concentric +apertures are used, a magnitude and uncertainty shall be given for each. +.le +.le +.le +.ls (5) +The program shall be usable both interactively and in batch mode. +In interactive use, the user shall be able to mark the positions of the +objects by interactively positioning a cursor on a 2-dim display device. +It shall be possible to enter the control parameters for the analysis +routines interactively for each object. In batch mode, the control +parameters shall be fixed, and object coordinates shall be taken from +a user supplied list. The display device shall not be required in +batch mode. +.le +.ls (6) +The APPHOT package shall be written in the SPP language in conformance +with the standards and conventions of IRAF. The code shall be portable +and device independent. +.le +.le + +.sh +2.1 Summary of the Limitations of APPHOT + + The APPHOT package is designed to perform simple aperture photometry +subject to the following restrictions: +.ls +.ls (1) +Objects must be circular or nearly circular, since the aperture is +circular. +.le +.ls (2) +All pixels within the object aperture are weighted equally. All pixels +in the object aperture must be present; the object aperture may not normally +extend outside the image. Defective pixels within the object +aperture may not be detected. +.le +.ls (3) +The background must be approximately flat in the neighborhood of the +object being measured. The background must have a unique mode, +or the background fitting routine will reject the object. Any low +frequency fluctuations in the background should be removed before +using APPHOT. +.le +.ls (4) +The object aperture must be kept small to minimize the degradation of +signal to noise caused by sky pixels within the aperture, and to +minimize the effects of crowding. Therefore, the wings of the object +will extend beyond the aperture. Good photometric results will be +obtained only if the aperture is consistently well centered, and if the +shape and diameter of an object is constant throughout the image and +invariant with respect to magnitude. +.le +.le + +.sh +3. Specifications + + The APPHOT package performs aperture photometry on digitized starfields +maintained as IRAF imagefiles. Input to the package consists of an imagefile, +a list of object coordinates, and numerous parameters controlling the analysis +algorithms. Output consists of successive lines of text, where each line +summarizes the results of the analysis for a particular object. The output +may be saved in a textfile, which may easily be printed or written onto a +card image tape for export. The package routines may be used either +interactively or in batch mode. + +The CL callable part of the APPHOT package consists of the following +routines: + +.ks +.nf + apphot -- the main aperture photometry routine. + coordtr -- translations and rotations of coord lists. + fitsky -- computes mode and sigma of a sky region. + fitpsf -- compute the FWHM of the PSF. + imcursor -- reads the image cursor; used to make lists. + immark -- marks objects on the display device. + radprof -- computes the radial profile of an object. +.fi +.ke + +Routines for general list manipulation, reading and writing card image tapes, +reading and writing images to FITS tapes, removing the instrumental signature +from the data, and so on are available elsewhere in the IRAF system. +The package is easily extended to include peak finding, +matching of object lists from different images, +background fitting and removal, and so on. The APPHOT package shall eventually +supplant both the KPNO AUTOPHOT and KPNO "Mountain Photometry Code" packages. + +.sh +3.1 Standard Analysis Procedures + + Before performing aperture photometry one must determine the radius +of the object aperture to be used, the inner radius and size of the annulus +to be used to fit the background, the full width at half max (FWHM) of +the point spread function (PSF), and so on. +Additional parameters are required by the centering algorithm. +A list of object centers must be prepared if APPHOT is to be used in +batch mode. The standard procedure is as follows: +.ls +.ls (1) +Use RADPROF to determine values for the following parameters: + +.nf + - the object aperture radius or radii, in pixels + - the inner radius of the annular (sky) region + - the width of the annular region +.fi +.le +.ls (2) +Use FITPSF to fit gaussians to isolated, high signal to noise data objects, +to determine the FWHM of the point spread function. +.le +.ls (3) +Use FITSKY to determine the sky sigma (standard deviation). +APPHOT assumes that sigma is approximately constant throughout the image. +.le +.ls (4) +If one does not wish to manually mark object positions with the cursor +during analysis, i.e. when the analysis is to be done in batch, a list +of object coordinates must be prepared. This may be done in many ways: +.ls +.ls o +By running RCURSOR with the standard output redirected into the list file. +.le +.ls o +By transforming an existing list with COORDTR, OPSTRM, MATCH, SORT, WINDOW, +the editor, or some other filter. +.le +.ls o +By an automatic object finding procedure, if one is available. +.le +.ls o +By any other program which generates a list of object coordinates, +where each line of the list describes one object, and where x and y +in pixel coordinates are given in columns one and two. Additional +columns, if present, are ignored. +.le +.ls o +APPHOT output may be used as coordinate input in a subsequent run. +.le +.le +.le +.ls (5) +Finally, APPHOT is run to measure the objects. The user should be familiar +with the algorithms used to fit the background, measure the object center, +and compute the aperture integral, magnitude, and errors. The values of +all visible and hidden APPHOT parameters should be inspected before doing +any serious processing. +.le +.le + +The general purpose IRAF list processing tools may be used for further +analysis of APPHOT output. +Output lists may be filtered to select objects based on the value of a +list column, i.e., all the objects within a certain magnitude range may +be selected, objects with estimated errors larger than a certain value +may be deleted, or a list may be sorted using the value in any column. +Columns may be extracted from a list to form new lists or to provide input +to a plot filter, and lists may be merged. +Arithmetic may be performed on lists to calculate colors, etc. + +The remainder of this section presents detailed specifications for the analysis +procedures in the APPHOT package. + +.sh +3.2 The APPHOT Program + + The function of the APPHOT procedure is to perform aperture photometry +on isolated objects within an image. The principal input operands are the +name of the imagefile and the rough coordinates of the objects to be processed. +The principal output operands are the coordinates and magnitudes of the +objects. + +In order to perform aperture photometry APPHOT must perform the following +sequence of operations (the algorithms employed are explained in +more detail later in this section): +.ls +.ls (1) +The mode and sigma of an annular background region centered on the object +is calculated. +.le +.ls (2) +The center of the object is determined. +.le +.ls (3) +The background is subracted from the object, and the total flux within +the object aperture or apertures is calculated. +.le +.le + +Steps (1) and (2) above are optional; the background and center may be +determined externally, rather than by APPHOT, if desired. +.sh +3.2.1 APPHOT parameters + + APPHOT has quite a few parameters due to the complexity of the +algorithms employed. All data dependent parameters are query mode to +ensure that they get set properly when a new image is processed. +The data independent algorithm control parameters are hidden mode, +and are given reasonable default values. The names, datatypes, and +default values of the APPHOT parameters are shown below. + + +.ks +.nf +Positional or query mode parameters: + + image filename + apertures string + annulus real + width_annulus real + fwhm_psf real + sky_sigma real +.fi +.ke + + +.ks +.nf +List structured parameters (filename may be given on command line): + + sky_mode *real + coords *imcur +.fi +.ke + + +.ks +.nf +Hidden parameters: + + spool boolean no + output filename "apphot.out" + fitsky boolean yes + max_sky_iter integer 50 + growing_radius real 1.0 (fwhm_psf units) + k1 real 5.0 + k2 real 2.0 + center boolean yes + clean boolean yes + cleaning_radius real 0.8 (fwhm_psf units) + clipping_radius real 1.5 (fwhm_psf units) + max_cen_shift real 1.0 (fwhm_psf units) + min_snratio real 0.5 + zmag real 26.0 + verbose boolean yes +.fi +.ke + + +The function and format of each of these parameters is explained in more +detail below. + +.ls +.ls 16 image +The name of the image or image section to be processed. +.le +.ls output +The name of the output textfile used to spool APPHOT output. +If null, output will not be spooled. Note that output always appears on +the standard output, whether or not spooling is in effect. +.le +.ls apertures +The radii in pixels of the concentric object apertures, given all on the +same line, delimited by blanks. At least one aperture must be given; +the maximum number of apertures is limited by the length of a line. +A sample input string might be "5.0 5.5 6.0 6.5 7.0". If only a single +aperture is to be used, a real expression may be used instead of a string +type argument. The apertures need not be given in any particular order. +The average radius will be used to compute the uncertainty in the +object magnitude. +.le +.ls annulus +The inner radius of the annular sky region, in pixels. +.le +.ls width_annulus +The width of the annular sky region, in pixels. +.le +.ls fwhm_psf +The FWHM of the psf, in pixels. Used as a scale factor to control the +internal algorithms. +.le +.ls sky_sigma +The standard deviation (noise value) of a typical region of sky in +the image. Used for pixel rejection in the sky fitting algorithm. +.le +.ls sky_mode +The name of a list file containing the mode of the background of each of +the objects to be processed. Required only if FITSKY is switched off. +If sky fitting is disabled, and no list file is given, APPHOT will query +for the sky value. +.le +.ls coords +The name of a list file containing the coordinates of the objects to +be processed. If absent, objects may be marked interactively with the +cursor. +.le +.ls fitsky +A switch used to specify whether or not the background will be fitted. +If background fitting is disabled, the mode and sigma of the background +will be read from the SKY_FILE list each time an object is processed. +.le +.ls max_sky_iter +The maximum number of iterations for the sky fitting algorithm. +Since the sky fitting algorithm is guaranteed to converge, +this parameter should normally have a large value. If the value +is zero, the median of the sky region will be used instead of the mode. +.le +.ls growing_radius +The region growing radius for pixel rejection in the sky region, in units +of FWHM_PSF. When a bad sky pixel is detected, all pixels within +(growing_radius * fwhm_psf) pixels of the bad pixel will be rejected. +Used to exclude the wings of contaminating objects from the sky sample, +to avoid biasing the mode. +.le +.ls k1 +The k-sigma clipping factor for the first phase of the sky fitting algorithm. +.le +.ls k2 +The k-sigma clipping factor for the second, iterative, phase of the +sky fitting algorithm. +.le +.ls center +A switch used to specify whether or not centering is to be performed. +If centering is disabled, the initial center will be used as the object center. +.le +.ls clean +A switch used to specify whether or not the symmetry-clean algorithm +is to be employed during centering. +.le +.ls cleaning_radius +The cleaning radius for the symmetry-clean algorithm, in units of +FWHM_PSF. +.le +.ls clipping_radius +The clipping radius for the symmetry-clean algorithm, in units of +FWHM_PSF. +.le +.ls max_cen_shift +The maximum permissible shift of center, in units of FWHM_PSF. +If the shift produced by the centering algorithm is larger than this value, +the fit will terminate and no magnitude will be calculated. +.le +.ls min_snratio +Centering will be skipped if the signal to noise of the object, +as calculated from the initial center, is less than the value given +by this parameter. +.le +.ls zmag +Zero point for the output magnitude scale. +.le +.ls verbose +If enabled, the output columns are labeled. Note that the presence +of column labels in the output may interfere with the use of the list +processing tools. +.le +.le + +.sh +3.2.2 The APPHOT Background Fitting Algorithm + + A good background fit is essential to aperture photometry. Fitting +the background is trivial in a sparse field, but difficult in a crowded +field. In general the background region will contain contaminating objects +which must be detected and excluded if a good fit is to be obtained. + +The algorithm employed here is based on the fact that contaminated pixels +are almost always spatially correlated. Background fitting algorithms +which work with a one dimensional sample (mode, median), or with the one +dimensional histogram (mode of hgm) have difficulty rejecting the faint +wings of contaminated regions. This is a serious defect of one dimensional +fitting algorithms, because it is these faint wings, not the bright +central pixels, which are most likely to bias the calculated background value. + +The algorithm used in APPHOT is as follows: + + +.ks +.nf + algorithm fit_sky + + begin + # Reject gross deviants. + compute the median of the annular region + detect pixels more than (k1*sky_sigma) from the median + reject all such pixels, without region growing + + # Detect and reject contaminating objects. + while (number of iterations <= max_sky_iter) { + compute the histogram of the reduced sample + compute the sigma and mode of the histogram + detect pixels more than k2*sigma from the mode + reject all such pixels, with region growing + if (no pix rejected or all pix rejected) + terminate loop + } + + return the final mode, sigma, and sample size + end +.fi +.ke + + +The mode of the histogram is found by cross correlating the noise function +with the histogram. The width of the the noise function is given by the +standard deviation of the current sample. Pixel rejection is +performed by locating all pixels more than k2*sigma from the mode, +and blindly rejecting all pixels within a certain radius of each deviant +pixel. This simple algorithm works well because the sample is large, +and therefore there is little penalty for discarding pixels that might +not be deviant. Region growing also tends to accelerate convergence +significantly. + +Very faint contaminating objects are difficult to detect and reject. +If there are enough such objects, they should not be rejected, because +there are probably a few in the object aperture as well. A higher sky +sigma will be calculated and the computed uncertainty in the magnitude +will increase. The best solution to this problem may be to increase +the size of the annulus to minimize the bias and maximize the liklihood +of a detection. + +.sh +3.2.3 The APPHOT Centering Algorithm + + The centering algorithm used in APPHOT is that of Auer and Van Altena, +with the addition of the symmetry-clean algorithm developed by Barry Newell. +The main algorithm is as follows: + + +.ks +.nf + algorithm get_center + + begin + if (centering is disabled) { + return initial center, zero uncertainty estimate + + } else if (signal to noise of object < MIN_SNRATIO) { + compute uncertainty using initial center + return initial center, computed uncertainty + + } else { + call measure_center + return image center and estimated uncertainty + } + end +.fi +.ke + + +The actual center determination is carried out by the following +algorithm: + + +.ks +.nf + algorithm measure_center + + begin + extract subarray from the main data array + + # Perform symmetry-cleaning. + if (cleaning is enabled) { + for (each pair of pixels diametrically opposed about + the image center beyond the cleaning radius) + if (i2 > i1 + 2*sky_sigma) + replace i2 by i1 + else if (i1 > i2 + 2*sky_sigma) + replace i1 by i2 + + perform 2*sky_sigma noniterative clip of all pixels + beyond the clipping radius, to remove any remaining + radially symmetric structures + } + + # Compute the image center and uncertainty. + compute x and y marginals of the cleaned subarray + fit a gaussian of width FWHM_PSF to each marginal + compute the centering error from the covariance matrix + + return image center and estimated uncertainty + end +.fi +.ke + + +The effect of the symmetry-clean algorithm is to edit the raster, +removing any contaminating objects in the vicinity of the primary object. +This simplifies the fitting algorithm and increases its reliability, +since it does not have to deal with multipeak marginal distributions. + +A gaussian is fitted to the marginal distributions because it is expected +to yield a better center determination for undersampled data. +An alternative is to empirically derive the marginal distributions of +the psf and fit these to each data object. This is a better approach in +some cases, but in the case of undersampled data it is difficult to derive +the marginal distributions due to sampling effects, and fitting is difficult +due to interpolation error. The use of a gaussian eliminates interpolation +error. Eventually, both techniques should be made available. + +.sh +3.2.4 The APPHOT Aperture Integration Algorithm + + The integral of the flux within a circular aperture is computed by +fractional pixel techniques. Pixels are assumed to be square apertures +arranged in a rectangular grid. The fraction of a pixel which lies within +the circular APPHOT aperture is computed by an approximation, and all +such contributions are summed to produce the total integral. + +The simplicity of aperture photometry limits the amount of information +available for error analysis. Using only the noise value for the background, +the estimated error in the aperture integral is given by + + flux_error = sky_sigma * sqrt (aperture_area) + +where "sky_sigma" is either the sigma calculated by the background fitting +algorithm or the parameter SKY_SIGMA, depending on whether sky fitting +is enabled, and where "aperture_area" is the fractional pixel area of the +aperture. + +It is possible, however, to produce a more useful error estimate if we +include some information about the psf. For the purposes of an improved +error estimate, we assume that the PSF is a gaussian. Given the object center, +the background, and the FWHM of the PSF, it is trivial to fit a two dimensional +gaussian to the object. An estimate of the average noise value for the +pixels within the aperture may then be obtained by computing the standard +deviation of the residual formed by subtracting the fitted two-dimensional +gaussian from the data. This value is used in place of SKY_SIGMA in the +above equation for an improved estimate of the actual flux error. + +In the limit as the gaussian goes to zero, both uncertainty estimates tend +to the same value, as they should. For bright objects, the uncertainty +produced by analysis of the residual will tend to be pessimistic, since +it is unlikely that the PSF can actually be modeled by a simple gaussian. +Nonetheless, a plot of uncertainty versus magnitude should reveal objects +which are blended, which contain bad pixels, and so on. The accuracy of +the gaussian model will determine how reliably deviant objects can be +discriminated. + +.sh +3.2.5 APPHOT Output + + For each object processed, APPHOT prints a single line of text on the +standard output. If desired, APPHOT will simultaneously spool output into +a user specified text file. Each output line will contain the following +information (excluding the commas): + + +.nf + x,y,cenerr,shift, mode,sigma,nskypix, mag1,...,magn,magerr + +where + + x,y object coordinates in pixels + cenerr estimated uncertainty in the object center + shift shift of center from initial coordinates + mode mode of the background + sigma sigma of the background + nskypix number of sky pixels left after rejection + mag1 magnitude within the first annulus + magn magnitude within the Nth annulus + magerr estimated mag. uncertainty at the average radius +.fi + + +Note that the estimated uncertainty in the magnitude is given only for +the average object aperture radius. The uncertainty for the other +apertures can easily be calculated given SIGMA and the area of each +aperture. The zero point for the magnitude scale is given by the +hidden parameter ZMAG. + +Additional information could be calculated and output (such as the +moments of the object and the skew of the background), but in our +experience few people ever look at such information, and a more complex +output format would be required. Probably the calculation of anything +but object centers, magnitudes, and errors should be left to other +programs. + +.sh +3.3 The COORDTR Program + + The function of COORDTR is to effect a linear translation and/or +rotation of a coordinate list. COORDTR is a filter; coordinate lines +are read from the standard input and written to the standard output. +COORDTR is concerned only with coordinate transformations, and knows +nothing about image boundaries. A transformed coordinate may no longer +lie within an image. + + x y other_stuff + +The format of a coordinate line is shown above. COORDTR operates only +on the coordinate pair x,y. Any additional information on the line is +passed on to the output without modification. + +COORDTR is actually a general purpose list processing operator, and +belongs in a list processing package, rather than in the APPHOT package. +When a list processing package is developed, COORDTR will be moved to +that package. + +A COORDTR transformation consists of a linear translation followed +by a rotation. Either the translation, the rotation, or both may be +skipped. The COORDTR parameters are summarized below. + + +.ks +.nf +positional arguments: + + xshift real + yshift real + xcenter real + ycenter real + theta real +.fi +.ke + + +.ks +.nf +hidden parameters: + + translate boolean yes + rotate boolean no +.fi +.ke + + +If more than two positional arguments are given, COORDTR knows +that both a translation and a rotation are desired. Otherwise the +boolean parameters TRANSLATE and ROTATE are read to determine +what additional parameters are needed. Thus a simple linear translation +of +2.5 pixels in X and -0.2 pixels in Y would be specified by the +command + + coordtr (2.5, -.2, < "input", > "output") + +which transforms the list in file "input", writing the output into the +new file "output". + +If a rotation is desired, XCENTER, YCENTER, and THETA must be given. +The first two parameters specify the pixel coordinates of the point +about which the rotation is to be performed, while THETA specifies +the rotation angle in degrees. Positive THETA produces a counterclockwise +rotation, if positive X is to the right and positive Y is up. + +.sh +3.4 The FITSKY Program + + The function of the FITSKY program is to determine the mode and sigma +of the specified annular regions, printing the results (mode, sigma, and npix) +on the standard output. FITSKY is similar in operation to APPHOT, except +that its function is to fit sky, not perform aperture photometry. The +FITSKY parameters are the following: + + +.ks +.nf +Positional or query mode parameters: + + image filename + annulus real + width_annulus real + fwhm_psf real +.fi +.ke + + +.ks +.nf +List structured parameters (filename may be given on command line): + + coords *imcur +.fi +.ke + + +.ks +.nf +Hidden parameters: + + spool boolean no + output filename "fitsky.out" + max_sky_iter integer 50 + growing_radius real 1.0 (fwhm_psf units) + k1 real 5.0 + k2 real 2.0 + verbose boolean yes +.fi +.ke + + +The names and functions of the FITSKY parameters are the same as those +for APPHOT. Note that ANNULUS may be set to zero to measure the +background within a circular aperture. The maximum number of iterations +may be set to zero to measure the median of the sky sample. +FITSKY output may be spooled into a file and used as input to APPHOT. + +.sh +3.5 The FITPSF Program + + The function of the FITPSF program is to determine the FWHM of the +point spread function. This is done by selecting an isolated, high +signal to noise object, computing the x and y marginal profiles, +and fitting a gaussian to each profile. Output consists of the object +center, the error in the center, and the FWHM of the fitted gaussians. +Note that the sigma of a gaussian may be obtained by dividing the FWHM +by 2.354. + + x y err x_fwhm y_fwhm + +The input parameters for the FITPSF program are shown below. + + +.ks +.nf +Positional parameters: + + image filename + aperture real + annulus real + width_annulus real + sky_mode real + coords *imcur +.fi +.ke + + +.ks +.nf +Hidden parameters: + + fitsky boolean yes + center boolean yes + spool boolean no + output filename "fitpsf.out" + verbose boolean yes +.fi +.ke + + +If background fitting is disabled, the parameter SKY_MODE defines +the sky level. The background fitting algorithm is a simple median +calculation without pixel rejection or iteration. +This should be sufficient, since FITPSF is expected to be used mainly +in uncrowded regions on high signal to noise objects. + +Note that FITPSF is set up to process a list of input objects. +The list processing tools (i.e., AVERAGE) may be used to average the +results to produce the final FWHM of the PSF for the image. + +.sh +3.6 The IMCURSOR Program + + The function of the IMCURSOR program is to read the STDIMAGE cursor, +writing the cursor coordinates on the standard output. The cursor is read +until the EOF character is entered to terminate the loop. The standard +output may be redirected into a file to generate a coordinate list. +IMCURSOR has no parameters. + +.sh +3.7 The IMMARK Program + + The function of IMMARK is to draw marks on the diplay device. +IMMARK is useful for verifying coordinate lists. + + +.ks +.nf +parameters: + + mark_type string + mark_size real + coords *imcur +.fi +.ke + + +Output is the current frame of the STDIMAGE device. Mark types +include "circle", "box", "cross", "plus", and "diamond". The size of +a mark is given in pixels. The third parameter is a standard coordinate +list. If no list is given, the image cursor will be read instead. + +.sh +3.8 The RADPROF Program + + The function of the RADPROF program is to compute the radial profile +of an object. The output of RADPROF consists of a sequence of lines of +text, each line defining the profile at a single radius. Since RADPROF +may generate many lines of output for a single input object, it is set up +to process only a single input object. A CL while loop may be written +to process multiple objects, if desired. + + +.ks +.nf +positional arguments: + + image filename + aperture real + step_size real + annulus real + width_annulus real + sky_mode real +.fi +.ke + + +.ks +.nf +hidden parameters: + + fitsky boolean yes + center boolean yes + verbose boolean yes +.fi +.ke + + +The radial profile is calculated from the image center out to the radius +specified by the parameter APERTURE, in steps of STEP_SIZE pixels. +The remaining RADPROF parameters are similar to those of APPHOT and will not be +discussed in detail. If background fitting is disabled, the parameter +SKY_MODE defines the sky level. The background fitting algorithm is +a simple median calculation without pixel rejection or iteration. +This should be sufficient, since RADPROF is expected to be used mainly +in uncrowded regions on high signal to noise objects. +Centering is via gaussian fits to the marginal profiles, without cleaning. + +RADPROF output lines contain the following fields: + + r, i(r), inorm(r), fraction(r) + +.nf +where + + r radius in pixels + i(r) raw intensity at r + inorm(r) normalized intensity at r (range 0-1) + fraction(r) fraction of total integral at r +.fi + + +RADPROF does not generate any plots. If one wishes to plot the contents +of an output column, the column may be extracted with a list processing +filter and piped to a graphics task. + +.sh +4.0 Example + + A brief example may help illustrate the use of the package. Suppose +we want to process a few hundred stars on images "blue" and "red". We +start by analyzing the blue image. + + ap> radprof blue,15,0.5,20,10 + +This gives us a radial profile printout for one of the "blue" stars. +We decide that an aperture radius of 2.5 pixels is about right. +The annulus will start at a radius of 10.0 pixels and extend to 20.0 pixels. +The next step is to determine the FWHM of the PSF: + + ap> fitpsf blue,3,10,20 | tee spoolfile + +By default, the program will take coordinate input by reading the image +display cursor. When the program is waiting for cursor input, it will +cause the display cursor to blink rapidly; normally the cursor does not +blink. One has to be aware of this, because no other prompt is issued. +We postion the cursor on several stars, and tap the space bar to measure +each one. When finished we type the EOF character (<ctrl/z> on our systems) +to terminate the loop. The screen will now look like this (the output +column labels are ommitted): + +.nf + ap> fitpsf blue,3,10,20 | tee spoolfile + 283.12 157.40 0.035 2.887 2.751 + 546.08 213.45 0.023 2.833 2.902 + 318.32 354.73 0.064 2.791 2.824 +.fi + +Since we elected to use TEE to spool the output, rather than the SPOOL +parameter of FITPSF, we will not see the results until all stars have been +measured. The next step is to average the results, to determine the +final FWHM (the FITPSF output could have been piped directly to GETCOLS +without using an intermediate spoolfile, if desired). + +.nf + ap> getcols spoolfile,"4-5" | getcols | average + 2.83133 0.0569725 6 +.fi + +There are many ways this average could have been computed, of course; +this is only one example. Next, to avoid having to write down the FWHM value, +we put it into the appropriate APPHOT parameter (note that the parameter +name is abbreviated). + + ap> apphot.fwhm = 2.831 + +Finally, we must determine a representative backround sigma value for +the image. This is done by using FITSKY to measure several sky areas, +and averaging column two of the output, much as we did for FITPSF. The +final value may be saved in "apphot.sky_sigma". + +By this point we have determined all the necessary parameters, and it is +time to do some photometry. The only APPHOT argument we are sure of is +the image name parameter, so that is all we include on the command line: + +.nf + ap> apphot blue + aperture radii, pixels: 2.4 2.5 2.75 3.0 + inner radius of sky annulus: 10 + width of sky annulus (1 - ): 10 + full width at half max of psf (2.831): + standard deviation of the image noise function (23.733): +.fi + +After responding to the prompts shown above, APPHOT will ask for the +first pair of object coordinates, and the cursor blink prompt will again +be given. Several objects may be measured to verify that all is working. + +The last step is to prepare a list of objects to be processed. The simplest +way to do this is to interactively mark the objects with the cursor. +Later, when we process the "red" image, the same coordinate list may again +be used, possibly after filtering with COORDTR. + + ap> imcursor > objlist + +At this point, all of the APPHOT parameters have been set, we have +a list of objects to be processed, and we are ready to run APPHOT in +batch mode. We decide to save the output in the file "blue.out". +To ensure that we have a record of the parameters used for the fit, +we first print the APPHOT parameters into the output file, then we +start up the APPHOT batch run. + +.nf + ap> lparam apphot > blue.out + ap> apphot >> blue.out & + [1] +.fi + +The batch job is now running, appending output lines to the file "blue.out". +We can proceed to set up the job for the red image, in much the same way +that we set up the job for the blue image. When both jobs finish, we +can use the list processing tools to filter out the good objects and +calculate colors. diff --git a/noao/digiphot/apphot/doc/specs/apphot.db b/noao/digiphot/apphot/doc/specs/apphot.db new file mode 100644 index 00000000..df5dc2f3 --- /dev/null +++ b/noao/digiphot/apphot/doc/specs/apphot.db @@ -0,0 +1,366 @@ +# APPHOT.DDF -- Data definition for apphot package output + +builtin catalog functions +builtin domain statements + +------------------------------------------------------------------------------- + +# domain statements + +domain bool type=short format="%b" +domain posint type=short format="%5d" +domain pixels type=real format="%9.3f" +domain fwhmpsf type=real format="%9.3f" +domain counts type=real format="%15.7g" +domain sigma type=real format="%15.7g" +domain mag type=real format="%7.3f" +domain pars type=real format="%15.7g" +domain electrons type=short format="%5d" +domain ratio type=real format=%15.7g" + +# Apphot database descriptor +record apphot { + iraf char[] "current version of iraf" + host char[] "host machine" + user char[] "user name" + package char[] "package name" + version char[] "package version" +} + +-------------------------------------------------------------------------------- + +# History record (1 per modification of the apphot database) +record history { + task char[] "task name" + date ltime "date dask was run" + firstrec posint "first record written by task" + lastrec posint "last record written by task" +} + +------------------------------------------------------------------------------ + +# Data dependent parameter set (>= 1 per task execution) +record datapars { + fwhmpsf pixels "full width half max of the psf" + emission bool "emission/absorption" + noise model char[] "data noise mode" + threshold counts "intensity threshold" + sigma counts "sigma of sky pixels" + gain char[] "image gain keyword" + epadu ratio "gain electrons/adu" + ccread char[] "image readout noise keyword" + readnoise electrons "readout noise electrons" +} + +# Centering algorithm parameter set (>= 1 per task execution) +record centerpars { + calgorithm char[] "centering algoritm" + cboxwidth fwhmpsf "centering box width" + maxshift fwhmpsf "maximum shift" + cmaxiter posint "maximum number of iterations" + minsnratio ratio "minimum signal to noise ratio" + clean bool "use clean algorithm" + rclean fwhmpsf "cleaning radius" + rclip fwhmpsf "clipping radius" + kclean sigma "sigma clean" +} + +# Sky fitting algorithm parameter set (>= 1 per task execution) +record fitskypars { + salgorithm char[] "sky fitting algorithm" + annulus fwhmpsf "inner sky annulus" + dannulus fwhmpsf[] "width of inner sky annulus" + smaxiter posint "maximum number od iterations" + skreject sigma "ksigma rejection" + snreject posint "maximum number of rejections" + khist sigma "half width of histogram" + binsize sigma "binsize of histogram" + smooth bool "smooth the histogram" + rgrow fwhmpsf "region growing radius" + skyvalue counts "user supplied sky value" +} + +# Photometry parameter set (>= 1 per task execution) +record photpars { + weighting char[] "weighting scheme" + apertures fwhmpsf "list of apertures" + zmagnitude mag "magnitude zero point" + exposure char[] "image exposure time keyword" + itime "" "exposure time" +} + +# Polygonal photometry parameter set (>= 1 per task execution) +record polypars { + zmagnitude mag "magnitude zero point" + exposure char[] "image exposure time keyword" + itime "" "exposure time" +} + +# Radial profile fitting parameters (>= 1 per task execution) +record radprofpars { + radius fwhmpsf "maximum profile radius" + stepsize fwhmpsf "profile step size" + order posint "number of spline pieces in fit" + kreject sigma "k sigma rejection" + nreject posint "max number of rejection cycles" +} + +# Point spread function modeling parameters (>= 1 per task execution) +record psfpars { + function char[] "analytic function" + box fwhmpsf "fitting box size" + kreject sigma "sigma rejection limit" + nreject posint "max number of rejections" +} + +-------------------------------------------------------------------------------- + +# Computed center answers (1 per star) +record center { + + datapars posint "record id of datapars record" + centerpars posint "record id of centerpars record" + + image char[] "image name" + xinit pixels "initial x position" + yinit pixels "initial y position + id posint "sequence number in table" + coords char[] "coordinate list filename" + lid posint "sequence number in coord list" + + xcenter pixels "x center position" + ycenter pixels "y center position" + xshift pixels "x position shift" + yshift pixels "y position shift" + xerror pixels "x position error" + yerror pixels "y position error" + cerrcode posint "centering error code" + cerrstring char[] "centering error message" + +} + +# Computed fitsky answers (1 per star) +record fitsky { + + datapars posint "record id of datapars record" + fitskypars posint "record id of fitskyprs record" + + image char[] "image name" + xinit pixels "initial x position" + yinit pixels "initial y position + id posint "sequence number in table" + coords char[] "coordinate list filename" + lid posint "sequence number in coord list" + + skyvalue counts "sky value" + skysigma counts "standard deviation of sky" + skyskew counts "skew of sky pixels" + nskypix posint "number of sky pixels" + nskyreject posint "number of rejected pixels" + serrcode posint "sky fitting error code" + serrstring char[] "sky fitting error message" + +} + +# Computed phot answers (1 per star) +record phot { + + datapars posint "record id of datapars record" + centerpars posint "record id of centerpars record" + photpars posint "record id of photometry record" + + image char[] "image name" + xinit pixels "initial x position" + yinit pixels "initial y position + id posint "sequence number in table" + coords char[] "coordinate list filename" + lid posint "sequence number in coord list" + + xcenter pixels "x center position" + ycenter pixels "y center position" + xshift pixels "x position shift" + yshift pixels "y position shift" + xerror pixels "x position error" + yerror pixels "y position error" + cerrcode posint "centering error code" + cerrstring char[] "centering error message" + + skyvalue counts "sky value" + skysigma counts "standard deviation of sky" + skyskew counts "skew of sky pixels" + nskypix posint "number of sky pixels" + nskyreject posint "number of rejected pixels" + serrcode posint "sky fitting error code" + serrstring char[] "sky fitting error message" + + aperts pixels[] "list of apertures" + sums counts[] "list of sums" + areas pixels[] "list of areas" + mags mag[] "list of magnitudes" + magerrs mag[] "list of mag errors + merrcodes posint[] "list of errcodes + merrstrings char[] "list of error messages" + +} + +# Computed wphot answers (1 per star) +record wphot { + + datapars posint "record id of datapars record" + centerpars posint "record id of centerpars record" + fitskypars posint "record id of fitskypars record" + photpars posint "record id of photpars record" + + image char[] "image name" + xinit pixels "initial x position" + yinit pixels "initial y position + id posint "sequence number in table" + coords char[] "coordinate list filename" + lid posint "sequence number in coord list" + + xcenter pixels "x center position" + ycenter pixels "y center position" + xshift pixels "x position shift" + yshift pixels "y position shift" + xerror pixels "x position error" + yerror pixels "y position error" + cerrcode posint "centering error code" + cerrstring char[] "centering error message" + + skyvalue counts "sky value" + skysigma counts "standard deviation of sky" + skyskew counts "skew of sky pixels" + nskypix posint "number of sky pixels" + nskyreject posint "number of rejected pixels" + serrcode posint "sky fitting error code" + serrstring char[] "sky fitting error message" + + aperts pixels[] "list of apertures" + sums counts[] "list of sums" + areas pixels[] "list of areas" + mags mag[] "list of magnitudes" + magerrs mag[] "list of mag errors + merrcode posint[] "list of errcodes + merrstrings char[] "list of error messages" +} + +# Computed polyphot answers (1 per star) +record polyphot { + + datapars posint "record id of datapars record" + centerpars posint "record id of centerpars record" + fitskypars posint "record id of fitskypars record" + polypars posint "record id of polypars record" + + image char[] "image name" + xinit pixels "initial x position" + yinit pixels "initial y position + id posint "sequence number in table" + coords char[] "coordinate list filename" + lid posint "sequence number in coord list" + + xcenter pixels "x center position" + ycenter pixels "y center position" + xshift pixels "x position shift" + yshift pixels "y position shift" + xerror pixels "x position error" + yerror pixels "y position error" + cerrcode posint "centering error code" + cerrstring char[] "centering error message" + + skyvalue counts "sky value" + skysigma counts "standard deviation of sky" + skyskew counts "skew of sky pixels" + nskypix posint "number of sky pixels" + nskyreject posint "number of rejected pixels" + serrcode posint "sky fitting error code" + serrstring char[] "sky fitting error message" + + sum counts[] "aperture sum" + area pixels[] "aperture area" + mag mag[] "magnitude" + magerr mag[] "magnitude error" + merrcode posint[] "error code" + merrstring char[] "error message" + + polygons char[] "name of polygons files" + pid posint "polygon sequence number" + oldxmean pixels "original mean x of polygon" + oldymean pixels "original mean y of polygon" + minradius pixels "min sky radius to exclude polygon" + nver posint "number of vertices" + xvertices pixels[] "list of x vertices coords" + yvertices pixels[] "list of y vertices coords" +} + +# Computed radprof answers (1 per star) +record radprof { + + datapars posint "record id of datapars record" + centerpars posint "record id of centerpars record" + fitskypars posint "record id of fitskypars record" + photpars posint "record id of photpars record" + radprofpars posint "record id of radprofpars record" + + image char[] "image name" + xinit pixels "initial x position" + yinit pixels "initial y position + id posint "sequence number in table" + coords char[] "coordinate list filename" + lid posint "sequence number in coord list" + + xcenter pixels "x center position" + ycenter pixels "y center position" + xshift pixels "x position shift" + yshift pixels "y position shift" + xerror pixels "x position error" + yerror pixels "y position error" + cerrcode posint "centering error code" + cerrstring char[] "centering error message" + + skyvalue counts "sky value" + skysigma counts "standard deviation of sky" + skyskew counts "skew of sky pixels" + nskypix posint "number of sky pixels" + nskyreject posint "number of rejected pixels" + serrcode posint "sky fitting error code" + serrstring char[] "sky fitting error message" + + aperts pixels[] "list of apertures" + sums counts[] "list of sums" + areas pixels[] "list of areas" + mags mag[] "list of magnitudes" + magerrs mag[] "list of mag errors + merrs posint[] "list of error codes + merrstrings char[] "list of error messages" + + pfwhm pixels "fitted profile fwhmpsf" + inorm counts "intensity normalization factor" + tinorm counts "total intensity normalization factor" + errcode posint "error code" + errstring char[] "error message" + rlist pixels[] "radii" + intensities counts[] "fitted intensities" + tintensities counts[] "integral of fitted total intensities" +} + +# Computed fitpsf answers (1 per star) +record fitpsf { + + datapars posint "record id of datapars record" + fitpsfpars posint "record id of fitpsf record" + + image char[] "image name" + xinit pixels "initial x position" + yinit pixels "initial y position + id posint "sequence number in table" + coords char[] "coordinate list filename" + lid posint "sequence number in coord list" + + npars posint "number of parameters" + params pars[] "list of parameters" + parerrs pars[] "list of parameter errors" + +} + +------------------------------------------------------------------------------- diff --git a/noao/digiphot/apphot/doc/specs/apphot.spc b/noao/digiphot/apphot/doc/specs/apphot.spc new file mode 100644 index 00000000..ecfdf364 --- /dev/null +++ b/noao/digiphot/apphot/doc/specs/apphot.spc @@ -0,0 +1,1296 @@ +.EQ +delim $$ +.EN + +.RP +.TL +Specifications for the Aperture Photometry Package +.AU +Lindsey Davis +.AI +.K2 "" "" "*" +Revised October 1987 + +.AB +The APPHOT package is a set of tasks for performing aperture photometry +on uncrowded or moderately crowded fields, in either interactive or batch mode. +The photometric technique employed is fractional pixel aperture +integration. Point spread function fitting techniques are not used and no +knowledge of the point spread function is required for the computation of +magnitudes. Separate tasks are provided for creating and modifying object lists, +computing accurate centers for a list of objects, computing sky values for +a list of objects and performing aperture photometry inside circular or +polygonal apertures. +.AE + +.NH +Introduction +.PP +The APPHOT package is a set of tasks for performing +aperture photometry on uncrowded or moderately crowded fields. +The photometric technique employed is fractional pixel integration. Point +spread function techniques are not used and no knowledge of the point spread +function is required for the computation of magnitudes. +.PP +The APPHOT package performs multi-aperture photometry on digitized starfields +maintained as IRAF image files. Input to the package consists of an +image file, a list of object coordinates, numerous parameters controlling +the analysis algorithms and, optionally, the graphics terminal and/or +display. APPHOT output consists of successive lines of text where each line +summarizes the results of the analysis for a particular object. +.PP +Given starting coordinates and an IRAF image, the principal APPHOT +task computes accurate centers, sky values and magnitudes +for a list of objects. Separate +IRAF callable tasks in APPHOT exist to create and modify object +lists, to determine image characteristics such as the full width half maximum +of the point spread function or standard deviation of the sky pixels, +to compute accurate centers for a list of objects, to compute accurate local sky +values for a list of objects, and to compute magnitudes inside a polygonal +aperture. + +.NH +APPHOT Package Requirements +.NH 2 +APPHOT Package Input +.NH 3 +The IRAF Image +.PP +APPHOT assumes that images exist on disk in IRAF format. Facilities for reading +and writing images exist elsewhere in IRAF such as in package DATAIO or +MTLOCAL. +.PP +APPHOT assumes that the image data is linear. +The input image is assumed to have been corrected for those instrumental +defects which affect the intensity of a pixel. These include pixel to +pixel variations in the bias values, pixel to pixel gain variations, +cosmic rays, cosmetic defects, geometric distortion, +and detector non-linearities. +.PP +APPHOT assumes that the local sky background is approximately flat in the +vicinity of the object being measured. This assumption is equivalent to +assuming that the local sky region has a unique mode. Therefore any +variations in the sky background which occur at the same scale as the +sky region should be removed prior to entering APPHOT. +.PP +The point spread function of the image is assumed to be constant for all +regions of the image. This is particularly critical in the case of faint objects +for which small apertures which minimize the effects of crowding and +sky noise in the aperture are used. The wings of the object will +almost certainly extend beyond the aperture and good results will only be +obtained if +objects are consistently well centered and the shape and diameter of an object +is constant throughout the image and invariant to magnitude. + +.NH 3 +The Coordinate Lists +.PP +All APPHOT tasks operate on lists of object coordinates or interactive cursor +input. Lists are maintained as text files, +one object per line with the x and y coordinates in +columns one and two respectively. List files may be created interactively +with either the graphics or image cursor, by a previously executed APPHOT +task, by a previously executed IRAF task or by a user task. +.PP +The x and y coordinates contained in the list file can be either the +starting centers for the objects of interest or the true centers. +In either case the aperture centered around the object position must +not extend beyond the boundary of the image. To obtain reliable results +from the centering algorithm the starting centers should not be more than +1 fwhmpsf pixels from the true centers. + +.NH 3 +Algorithm Parameters +.PP +Many tasks in the APPHOT package have an associated set of algorithm parameters +which control the operation of the analysis routines. For example the +centering and sky fitting algorithms each have an associated group of +parameters. +The APPHOT tasks supply reasonable defaults for these parameters. However +the user may alter them at any time in interactive mode or by editing the +appropriate parameter file before running the task in batch. + +.NH 3 +Terminal Graphics and the Image Display +.PP +Most APPHOT programs may be run in either interactive or batch mode. +In interactive mode, the user can mark the positions of objects by +interactively, positioning the image cursor on the display device. +Simple cursor commands can interactively alter the algorithm parameters. +In batch mode the algorithm parameters are +fixed and object coordinates are taken from the user supplied coordinate list. +The display device is not required in batch mode. +.PP +At present there is no high level IRAF display interface. Therefore the present +version of APPHOT replaces the display device with terminal +graphics. For example it is possible to load a contour plot of an image +or image section, and run the APPHOT tasks, interactively marking +positions on the plot. This is a temporary measure to tide thing over until +the display interface is available. Furthermore this option is only +really suitable for those terminal which have both text and graphics +windows displayed at the same time. +.PP +Certain APPHOT tasks such as FITSKY occasionally require an interactive graphics +capability. For example it is sometimes desirable to plot the histogram +of the sky pixels and mark the peak of the histogram interactively rather +than using the automatic sky fitting routines. +Graphics capablity has been added to APPHOT tasks as deemed useful. + +.NH 2 +APPHOT Package Functions +.NH 3 +Creating Coordinate Lists +.PP +APPHOT task(s) shall exist to create coordinate lists interactively within +APPHOT by loading the IRAF image into the image display +and successively marking the objects to be measured with the image cursor. +It shall be possible to mark the positions of objects on the display, and draw +circles of arbitrary size around the objects of interest. +It shall be possible to verify existing coordinate lists by marking the object +coordinates on the image display. +.PP +At present the full image display cababilities do not exist in IRAF. +Therefore as a temporary measure most tasks will run with a contour +plot and the graphics cursor as a substitute for the image display and +image cursor by setting the image cursor to stdgraph and the display +parameter for each task to stdgraph. +The output coordinates will be written to a text file and may be used as +starting coordinates for the APPHOT routines. +.PP +Those sites which have SUN workstations can use the IMTOOL facilites to +create cursor lists. +.PP +APPHOT tasks shall exist to automatically detect objects by specifying the IRAF +image to be searched, plus a few image characteristics such as a detection +threshold and the full width half maximum of the point spread function. +The output coordinates plus a few object statistics will be written to a +text file. + +.NH 3 +Coordinate List Operations +.PP +General list processing tasks are or will be available in the IRAF lists +package. Examples of useful currently existing tasks are list sorting by for +example magnitude and performing a linear transformations +on coordinate lists. +.PP +It may eventually be necessary to add some specialized list processing tasks +to APPHOT. One example is a list matching facility in which objects in +common to two lists are combined and output to a third list. + +.NH 3 +Determining the Image Characteristics +.PP +APPHOT tasks shall exist to estimate certain image +characteristics such as the full width half maximum of the image point spread +function and the standard deviation of the background. In order to obtain +meaningful error estimates it is also necessary to specify the noise +charactersitics of the detector and a noise model. +In this version of APPHOT two noise +functions will be supported a constant sky background noise, +and constant background noise plus Poisson statistics in the object. +.PP +The reason for this capability is that the majority of the APPHOT +algorithm parameters scale with these two image characteristics. +For example all the pixel scale dependent parameters such as the centering +aperture, object apertures, the two sky annuli and the +maximum shift parameter all scale with the full width half +maximum of the point spread function. Similarly most of the pixel intensity +dependent parameters scale with the standard deviation of the sky pixels. + +.NH 3 +Centering +.PP +An APPHOT task shall exist to determine accurate centers for a list of objects, +using the approximate object coordinates as a starting point. +The centering aperture may extend beyond the boundaries of the image but +a warning message will be generated. +.PP +A choice of centering algorithms with a range of efficiency and accuracy will +be available. The center determination must be resistant to the affects of +nearby contaminating objects. +.PP +The user may opt to use the starting center as the actual center in all cases, +to use the starting center as the actual center if the object is very faint, +or tweak up the center if the signal to noise is above a certain threshold. +.PP +The output of the centering algorithm will the set of computed coordinates +and their errors. + +.NH 3 +Fitting the Sky +.PP +An APPHOT task shall exist to compute a constant background value by analysis +of an annular region surrounding the object. +The background is assumed to be flat in the region +of the object, but may contain contaminating objects or defects which +shall be detected and eliminated by the fitting algorithm. +It shall be permissible for the background region to extend beyond the +boundaries of the image; the out of bounds region of the background shall +be excluded from the fit. +.PP +The user may supply a constant background, with zero-valued noise and skew +value or read appropriate values from a file instead of computing the +background. +.PP +The output of the sky fitting algorithm shall be +the mode, standard deviation and skew of the sky as well as the number +of pixels left in the background region after pixel rejection and the number +rejected. + +.NH 3 +Multi-aperture Photometry +.PP +APPHOT routines shall exist to compute the integral of object minus background +within one or more circular apertures centered upon the object. +The integration shall be +performed using partial pixel techniques, to minimize the effects of +sampling. If the aperture contains any indefinite pixels, or if the +aperture extends beyond the boundary of the image, an indefinite result +shall be returned. Both normal and weighted photometry routines shall +be available. +.PP +It shall be possible to normalize the output magnitudes to a user specified +integration time using values stored in the IRAF image header. +.PP +The output shall consist of magnitudes and errors for each of the specified +apertures. +.NH 3 +Polygonal Aperture Photometry +.PP +Determine the integral of the object within a specified +polygon. Aperture integration shall be by fractional pixel summation +of successive image lines. + +.NH +Specifications +.NH 2 +Apphot CL Callable Tasks +.PP +The CL callable part of the APPHOT package consists of the following +routines:\fL + +.nf +.na + mark -- create/verify coordinate lists interactively + polymark -- create/verify polygon lists interactively + daofind -- automatic image finder from DAOPHOT + lintran -- linearly transform a list of coordinates (LISTS package) + + radprof -- compute the radial profile of an object. + fitpsf -- model the PSF + + center -- compute accurate centers for a list of objects + fitsky -- compute accurate sky values for a list of objects + phot -- perform multi-aperture photometry on a set of objects + polyphot -- compute the flux inside a set of irregular polygons\fR + wphot -- perform weighted multi-aperture photometry +.ad +.fi + +.NH 2 +Standard Analysis Procedures +.PP +A standard reduction procedure would be something as follows. +.IP 1. +Estimate the image and data characteristics in the following manner. +.RS +.IP 1. +Use the interactive setup option (i key) in the PHOT task to specify the +fwhm of the psf, +the centering apperture, the sky annuli, the photometry apertures as +well as estimate the sky sigma. +Examine the results (:show command) and optionally store the +new parameters in the parameter files (w key). +.IP 2. +Use the EPAR task to edit the parameter files directly. For example the +detector gain and readout noise must be known before running PHOT in +order to get reliable error estimates. +.RE +.IP 2. +Prepare a coodinate list in one of the following ways. +.RS +.IP 1. +Running MARK or POLYMARK. +.IP 2. +Run DAOFIND or some other automatic image finder. +.IP 3. +Run another APPHOT task such as CENTER . +.IP 4. +Run any other IRAF or user program which generates the appropriate +format. +.IP 5. +Transform an existing list using the LISTS package facilities +.RE +.IP 3. +Run PHOT or WHOT in non-interactive mode to perform the multi-aperture +photometry. The user should be familiar +with the algorithms used to measure the object center, to fit the background, +and compute the aperture integral, magnitude, and errors. The values of +all visible and hidden PHOT parameters should be inspected before doing +any serious processing. Note that CENTER and FITSKY can be run independently +of PHOT and their output used as input to PHOT. +.EQ +delim $$ +.EN + +.NH 2 +The APPHOT Algorithms +.PP +The principal APPHOT algorithms are described below. + +.NH 3 +The RADPROF Algorithm +.PP +The function of the RADPROF task is to compute the radial profile of +selected, isolated, high signal to noise objects in an IRAF image. +.PP +Given the IRAF image, an initial center, an aperture and a step size, +RADPROF computes the radial profile of an object in the following manner. +.IP 1. +The APPHOT centering routines are used to compute an accurate center for the +object. The new center is used to compute the radial coordinate for each +pixel in the subraster. +.IP 2. +The APPHOT sky fitting routines are used to compute an accurate sky value +for the object. The new sky value is used to compute the object intensity +for each pixel in the subraster. +.IP 3. +The CURFIT package routines are used to produce a smooth intensity versus +radius curve by fitting a cubic least squares spline function to the data +using linear least squares techniques. +.IP 4. +The fitted curve is evaluated at equally spaced intervals to produce the +final radial profile. The profile is normalised using the r = 0 value. +.IP 5. +The smoothed curve is integrated using the +1D integration routines IMINTERP to evalute the fraction of the total +integral at each interval. +.IP 6. +The three quantities $I sub r$ the raw intensity, $Inorm sub r$ the +normalized intensity, and $Ifraction sub r$ the fraction of the total +intensity inside radius at r, are plotted on the terminal and +output as a function of r to a text file. +.PP +RADPROF is used principally to compute the stellar image and setup the +parameters for doing photometry. Its default output is a radial profile +plot with the phot parameters marked on it. + +.NH 3 +The FITPSF Algorithm +.PP +The function of the FITPSF task is to fit an analytic model to an object +in order to derive information about the point spread function. Given +an IRAF image, an initial center and an aperture, FITPSF computes the +model parameters in the following manner. +.IP 1. +The fitting function is chosen. +The present version of FITPSF offers two function choices a 2D radial Gaussian +function and an elliptical Gaussian function. +A third option, moment analysis, has been added to the FITPSF package. +The image characteristics are evaluted by using the 0th, 1st and 2nd order +moments of the image. +.IP 2 +Initial guesses for the parameters are made from the subraster data. +.IP 3 +The parameters and their errors are derived using standard non-linear least +squares techniques and the NLFIT package. + +.NH 3 +The DAOFIND Algorithm +.PP +The function of the DAOFIND task is to automatically detect objects +in an IRAF image above a certain intensity threshold. +The user specifies an intensiyt threshold, +the estimated full width half maximum of +the point spread function, +and limits on the sharpness and roundness of the objects to be detected. +DAOFIND produces a list of x and y coordinates and a sharpness +and roundness statistic for each detected object. +.PP +The DAOFIND algorithm works in the following way. +.IP 1. +The user specifies an intensity threshold above local sky and estimates +the full width half maximum of the point spread function. +.IP 2. +DAOFIND computes a convolution kernel which is a linear +function of the brightness values in an approximately circular array of +pixels. The original data is convolved with the computed kernel. +The equivalent mathematical +operation is a convolution of the original data +with truncated, lowered circular Gaussian function with the specified FWHM, +computed in such a way as to be the mathematical +equivalent of fitting a Gaussian stellar profile to the object data by least +squares. The coefficients of the linear function sum to zero so that the +overall bias level (local sky) cancels out exactly. Since the function is +symmetric about a single pixel, a smooth gradient in the sky brightness +also cancels exactly. Therefore the user does not have to specify an +absolute brightness threshold but only a threshold above local sky. +.IP 3 +The convolved data is searched for local maxima. Local maxima which are +less than the specified threshold are rejected. A pixel is defined to be +a local maximum when it is the brightest pixel within +$n ~*~ sigma sub Gauss$. +.IP 4. +Using the original data, DAOFIND computes an object sharpness statistic which +can be used to reject +hot or cold pixels. The sharp parameter is defined below. +Detected objects with a sharpness parameter outside the range specifed +by sharplo and sharphi are rejected. Typical values for sharplo and +sharphi are 0.2 and 1.0 respectively. +.nf + + $I sub delta$ = height of best fitting $delta$ function = pixel value + + $I sub Gauss$ = height of best fitting Gaussian function = convolved value + + sharplo <= sharp = ${I sub delta} over {I sub Gauss}$ <= sharphi + +.fi +If the brightness enhancement detected in the convolved data is due to +a single bright pixel, then the best fitting delta function will have an +amplitude equal to the height of this pixel above the local background, +while the amplitude of the best fitting Gaussian will be pulled down by +the surrounding low valued pixels. Sharp will be a number significantly +greater than one. A single cold pixel will produce +brightness enhancements approximately 0.5 * FWHM away +from the pixel in question in all directions. In this case the height +of the delta +function which best fits these spurious maxima is close to zero, while the +height of the best fitting Gaussian is some small positive number. +In this case sharp will be close to zero. +.IP 5. +The roundess statistic is computed from the original picture data by fitting +1D Gaussians +to the marginal sums in x and y. If the height of either 1D +Gaussian is negative the object is rejected. If both heights are +positive the roundness parameter is computed. +.nf + + $DELTA I ~=~ I sub {x ~ Gauss} ~-~ I sub {y ~ Gauss}$ + + $<I> ~=~ I sub {x ~ Gauss} ~+~ I sub {y ~ Gauss}$ + + $roundlo ~<=~ round ~=~ {DELTA I} over <I> ~<=~ roundhi$ + +.fi +Objects which are elongated in the +x direction have roundness values less than zero and those elongated in +the y direction have roundness greater than zero. +Round discriminates only against objects which are elongated +along either rows or columns. Objects elongated at a 45 degree angle will +not be rejected. +.IP 6. +Finally the approximate x and y centroids of the detected objects, +rough magnitudes relative to threshold are computed, and object is added +to the output file. + + +.NH 3 +The CENTER Task + +.NH 4 +Centering Package Routines +.PP +The following are the principal programmer callable routines routines in the +centering package. +.nf +\fL + + apcinit (ap, cfunction, cbox, fwhmpsf, noise) + ier = apfitcenter (ap, im, xinit, yinit) + ier = aprefitcenter (ap) + value = apstat[ir] (ap, param) + apstats (ap, param, str, maxch) + apset[sir] (ap, param, value) + apcfree (ap) + +\fR +.fi +.PP +The following quantities can be examined or set by apstat/apset calls +.nf +\fL + data 1. fwhmpsf full width half maximum of psf in pixels +parameters 2. threshold minimum intensity for centering + 3. noise noise model + 4. sigma standard deviation of background + 5. readnoise readout noise of CCD in electrons + 6. epadu electrons per adu + +centering 1. calgorithm centering algorithm +parameters 2. positive emission / absorption features + 3. cbox centering radius in fwhmpsf + 4. cmaxiter maximum number of fitting iterations + 5. maxshift maximum permitted shift in fwhmpsf + 6. minsnratio minimum permitted signal to noise ratio + 7. clean clean subraster before centering + 8. rclean cleaning radius in fwhmpsf + 9. rclip clipping radius in fwhmpsf + 10.kclean k-sigma rejection for cleaning in sigma +\fR +.fi + +.PP +The following computed quantities can be examined by apstat calls. +.nf +\fL + 1. xcenter computed x coordinate + 2. ycenter computed y coordinate + 3. xerr computed x coordinate error + 4. yerr computed y coordinate error +\fR +.fi +.PP +See the manual pages for CENTER and CENTERPARS for a detailed description +of the centering parameters. + +.NH 4 +The Centering Algorithm +.PP +The function of the CENTER task is to compute accurate centers and errors +for objects in an IRAF image given a list of initial positions and a +centering aperture. +.IP 1. +If the centering algorithm is disabled, the computed center is set to the +initial center and the uncertainty estimate is set to zero. +.IP 2. +If the cleaning algorithm is enabled, clean the subraster before centering. +.IP 3. +Estimate is made of the signal to noise of the object. If this quantity is +less than a certain minimum value the computed center is kept +but a warning message is issued. +.IP 4. +The center and errors are computed using one of several algorithms. +.IP 5. +If the computed center is greater than a user specified distance from the +initial center then the computed center is returned with an error +message. + +.NH 4 +Symmetry Clean Algorithm +.PP +The symmetry-clean algorithm attempts to remove defects in the centering +subraster by assuming that the object has radial symmetry and comparing +pixels on the opposite sides of the center of symmetry. The algorithm +works in the following way. +.IP 1. +The center of symmetry is computed. Normally the center of symmetry is assumed +to coincide with the position of the brightest pixel in the subarray. +However if the maximum pixel is more than a user specified distance away +from the intial center, the initial center is used as the center of symmetry. +.IP 2. +Pixels inside a specified cleaning radius are unaltered. +.IP 3. +Pairs of pixels diametrically opposed about the center +in the cleaning region between the cleaning and clipping +radii are tested for equality. If the difference between the pixels is +greater than a specified k-sigma rejection limit, the larger value is replaced +by the smaller. +In this region sigma is computed from Poisson statistics. +.IP 4. +Pairs of pixels in the clippping +region are compared in the same manner as those in the cleaning region +except that sigma is the standard deviation of the sky pixels. +.PP +The effect of the symmetry-clean algorithm is to edit the raster, +removing any contaminating objects in the vicinity of the primary object. +This simplifies the fitting algorithm and increases its reliability, +since it does not have to deal with multipeak marginal distributions. + +.NH 4 +Signal to Noise Estimate + +.PP +The signal to noise of the object is estimated from the data values +in the subraster in the following way. +.nf + + $SNR ~=~ N sub object over {sqrt {n sub pix ~*~sigma sub sky sup 2}}$ + + or + + $SNR ~=~ N sub object over {sqrt {N sub object ~+~ n sub pix~*~sigma sub sky sup 2}}$ + +.fi +where $N sub *$ is the number of counts in the object above threshold, +$sigma sub sky$ +is the standard deviation of the pixels in the sky region and +$n sub pix$ is the number of pixels in the object aperture. +The first approximation corresponds to constant sky noise only, +the second includes Poisson noise in the object. + +.NH 4 +Centroid +.PP +The centroid centering algorithm is similar to that used in MPC and can +be briefly described as follows. For more detailed description +see (Stellar Magnitudes From Digital Pictures, 1980, Adams et al). +.IP 1. +The marginal distributions in x and y are accumulated. +.IP 2. +The intensity weighted centroid positions for the marginals is computed +using only data pixels which are above the threshold intensity. If the +threshold parameter is 0 the mean intensity of the marginal is used +in place of the threshold +.nf + + $I sub i ~=~ I sub i ~-~ threshold ~~~~~ I sub i ~>~ 0.0$ + + $x sub c ~=~ {sum I sub i ~ x sub i} over {sum I sub i}$ + +.fi +.IP 3. +The errors are estimated in the following way +.nf + + $sigma sup 2 ~=~ {sum I sub i ~ x sub i sup 2} over {sum I sub i} ~-~ x sub c sup 2$ + + $err sub xc ~=~ sqrt {{sigma sup 2} ~/~ sum I sub i}$ + +.fi + +.NH 4 +Gaussian Fit to the Marginals +.PP +The fit is performed in the following way. +.IP 1. +The marginal distributions in x and y are accumulated. +.IP 2. +Initial guesses for the parameters of the 1D Gaussians $I sub Gauss$, +$x sub c$ and $I sub sky$ are derived from the marginal distributions +themselves. The width $sigma$ is held constant. +.IP 3. +The best fit parameters and their errors are derived using non-linear +least-squares techniques and the NLFIT package. + +.NH 4 +Optimal Filtering of Marginals +.PP +The fit is performed is the following way. +.IP 1. +The marginal distributions in x and y are accumulated. +.IP 2. +The centroid of the observed distribution is computed by solving the +following equation. +.nf + + $PSI (x sub c ) ~=~ sum omega sub i (x sub c ) ~ PHI sub i ~=~ 0$ + + $omega sub i ~=~ {{partial phi sub i} ~/~ {partial x sub c}} over {phi sub i~+~b}$ + +.fi +The assumptions are that the observed distribution $PHI sub i$ is correctly +modeled by the profile function $phi sub i$. The usual choise of profile +model for centering is a Gaussian. Howver in the interests of speed a triangle +function has been substituted. This causes at most a 7% increase in the +random centering error. +.IP 3. +The startup procedure is based on the following fact. +.nf + + $PSI (x sub n )~>~0~~for~~ x sub n ~<~ x sub c$ + + $PSI (x sub n ) ~<~0~~for~~ x sub n ~>~ x sub c$ + +.fi +The iteration is initialized by assuming that $x sub 1$ = $x sub c$ and +computing $PSI (x sub 1 )$. The initial x +value is incremented by $+- sigma sub Gauss$ depending on the sign of $PSI$. The +search is repeated until $PSI (x sub {n-1})$ and $PSI (x sub n)$ have +opposite signs. At this point the true center is bracketed by the +estimated positions $(x sub n, ~ x sub {n-1})$ and we have a table of at +least 2 values of $PSI (x sub n )$. +.IP 4. +The computation proceeds by interpolating in the table of values for the +estimated position $x sub {n+1}$ where $PSI$ = 0. If the table contains only +two values as may be the case for the inititial interpolation, linear +interpolation is used. In all other cases a quadratic fit to the three +most recent $PSI$ values is used. The computation is complete when +two successive estimates differ by less than some tolerance typically +0.001 pixel. +.IP 5. +The errors are estimated as follows. +.nf + + $sigma sup 2 ~=~ ( {int {( partial phi ~/~ partial x sub c )} sup 2 over { + phi + b}} ) sup -1$ + + $err sub xc ~=~ sqrt {sigma sup 2}$ + +.fi + +.NH 4 +Other Centering Methods +.PP +The code is constructed in such a way that new algorithms may be +easily added at a future date, such as the more sophisticated techniques +required for accurate astrometry. +.EQ +delim $$ +.EN +.NH 3 +The FITSKY Task + +.NH 4 +Sky Fitting Routines + +.PP +The following are the main entry points in the sky fitting package. +.nf +\fL + apsinit (ap, function, annulus, dannulus, fwhmpsf, noise) + ier = apfitsky (ap, im, xpos, ypos, sd, gd) + ier = aprefitsky (ap, sd, gd) + value = apstat[ir] (ap, param) + apstats (ap, param, str, maxch) + apset[irs] (ap, param, value) + apsfree (ap) +\fR +.fi +.PP +The following quantities can be examined or set with apset/apstat calls. +.nf +\fL +data 1. fwhmpsf full width half maximum of the psf +parameters 2. sigma standard deviation of sky pixels + +sky fitting 1. annulus inner radius of sky annulus in fwhmpsf +parameters 2. dannulus outer radius of sky annulus in fwhmpsf + 3. sfunction sky fitting algorithm + 4. smaxiter maximum number of fitting iterations + 5. kreject k-sigma rejection limit sigma + 6. nreject maximum number of rejection cycles + 7. rgrow region growing radius in fwhmpsf + + 8. khist half-wdth of histogram in sigma + 9. binsize binsize of histogram in sigma + 10.smooth Lucy smooth the histogram + + 11.skyfile name of text file containing sky values + 12.skyvaluser supplied constant value for sky +\fR +.fi +.PP +The following computed quantities can only be examined with apstat calls. +.nf +\fL + 1. skymode computed sky value + 2. skysig computed sky sigma + 3. skyskew computed sky skew + 4. nsky number of sky pixels + 5. nsky_reject number of rejected sky pixels +\fR +.fi + +.NH 4 +The Sky Fitting Algorithms +.PP +A good background fit is essential to aperture photometry. Fitting +the background is trivial in a sparse field, but difficult in a crowded +field. In general the background region will contain contaminating objects +which must be detected and excluded if a good fit is to be obtained. +.PP +The main algorithm used in APPHOT is the following. +.IP 1. +If the skyfitting switch is disabled either read the sky values from a text +file or accept a user supplied constant for the sky. +.IP 2. +Perform the initial sky fit using one of the specified algorithms. The +sky fitting algorithms fall into three general categories, those that use +the actual sky pixel array itself, those that operate on a histogram of +sky values and those that rely on user interaction. +.IP 3. +If the pixel rejection flags are set perform pixels rejection with optional +region growing. + +.NH 4 +Sky Pixel Array Techniques + +.NH 5 +Median +.IP 1. +Sort the array of sky pixels. This is necessary to avoid quantization effects. +.IP 2. +Compute the median, and the standard deviation and skew with respect to the +mean. +.IP 3. +If the k-sigma rejection limit is greater than zero and the maximum number +of rejection cycles is greater than one, perform pixel rejection. +Pixels greater than k-sigma from the median are rejected. Region growing +is optional. +.IP 4. +Stop the rejection cycle on any given iteration if the maximum number of +rejection cycles ix exceeded, no more sky pixels are left or no more +pixels are rejected. + +.NH 5 +Mode +.IP 1. +Sort the array of sky pixels. This is necessary to avoid quantization effects. +.IP 2. +Compute the mode, and the standard deviation and skew +with respect to the mean. +.nf + + $I sub mode ~=~ 3.0 ~*~ I sub median ~-~ 2.0 ~*~ I sub mean$ + +.fi +.IP 3. +If the k-sigma rejection limit is greater than zero and the maximum number +of rejection cycles is greater than one, perform pixel rejection. +Pixels greater than k-sigma from the mode are rejected. Region growing +is optional. +.IP 4. +Stop the rejection cycle on any given iteration if the maximum number of +rejection cycles ix exceeded, no more sky pixels are left or no more +pixels are rejected. + + +.NH 4 +Histogram Techniques +.PP +The following three techniques all operate on the histogram of the sky pixels. +The routines all construct the histogram in the following identical manner. +.IP 1. +The mean of the sky distribution is computed. +.IP 2. +If the user specified standard deviation of the sky pixels is INDEF the +algorithm computes the standard deviation of the sky pixels with respect +to the mean. +.IP 3. +All pixels within plus or minus sigma standard +deviations are accumulated into a histogram. The user specifies the bin size. +.IP 4. +The histogram may optionally be Lucy smoothed before any operation is performed +on it. + +.NH 5 +Centroid +.PP +The mode, sigma and skew of the sky pixels are computed in the following +manner. +.IP 1. +The histogram is compiled as above. +.IP 2. +The mode, standard deviation and skew of the sky pixels are computed in the +following manner. + +.nf + $I sub 0 ~=~ sum I sub i$ + $I sub 1 ~=~ sum I sub i ~ x sub i$ + $I sub 2 ~=~ sum I sub i ~ x sub i sup 2$ + $I sub 3 ~=~ sum I sub i ~ x sub i sup 3$ + + $I sub mode ~=~ {I sub 1} ~/~ {I sub 0}$ + $sigma ~=~ {( I sub 2 ~/~ I sub 0 ~-~ I sub mode sup 2 )} sup {1/2}$ + $skew ~=~ ( {I sub 3 ~/~ I sub 0 ~-~ I sub mode ~*~ sigma sup 2 ~-~ I sub mode sup 3} ) sup {1/3}$ + +.fi +.IP 3 +If pixel rejection is enabled sky pixels within a user supplied limit of +the mode are rejected with optional region growing. + +.NH 5 +Gaussian Fit +.PP +The mode, standard deviation and skew of the sky pixels are derived from a +model fit in the following way. +.IP 1. +The histogram of the sky pixels is compiled as above. +.IP 2. +Initial guesses to the model parameters, $N sub max$, $I sub mode$, +$sigma$, and $skew$ are made from the histogram itself. +.IP 3. +Final parameters and their errors are derived using non-linear least squares +techniques and the NLFIT package. +.IP 4. +If pixel rejection is enabled sky pixels within a user supplied limit of +the computed mode are rejected with optional region growing. + +.NH 5 +Optimal Filtering +.PP +The method is as follows. +.IP 1. +The histogram is compiled as above. +.IP 2. +Using the mean of the sky pixels as the intital value of the sky mode, +a new mode is computed using the optimal filtering technique +described for centering. +.IP 4 +If pixel rejection is enabled sky pixels within a user supplied limit of +the computed mode are rejected with optional region growing. + +.NH 5 +Cross Correlation +.PP +The method is as follows. +.IP 1. +The histogram is compiled as above. +.IP 2. +The noise function is estimated using the standard deviation of the sky +pixels and the cross-correlation function is computed. +.IP 3. +The mode is computed using quadratic interpolation around the peak of the +distribution. +.IP 4 +If pixel rejection is enabled sky pixels within a user supplied limit of +the mode are rejected with optional region growing. + +.NH 4 +Interactive Techniques + +.NH 5 +Histogram Plot +.PP +The histogram is compiled as described above and the user marks the peak +on the histogram plot with the graphics cursor. The sigma and skew of the +sky distribution with respect to the mean is also computed. + +.NH 5 +Radial Distribution +.PP +A radial profile plot of the sky region is plotted and the user marks the +sky value on the plot with the graphics cursor. The sigma and skew of the sky +distribution with respect to the mean is computed. + +.NH 4 +Pixel Rejection and Region Growing +.PP +All the sky fitting algorithms permit pixel rejection and +optional region growing. +Pixel rejection and region growing are +performed by locating all pixels more than k * sigma from the mode, +and blindly rejecting all pixels within a certain radius of each deviant +pixel. This simple algorithm works well because the sample is large, +and therefore there is little penalty for discarding pixels that might +not be deviant. Region growing also tends to accelerate convergence +significantly. +.PP +Very faint contaminating objects are difficult to detect and reject. +If there are enough such objects, they should not be rejected, because +there are probably a few in the object aperture as well. A higher sky +sigma will be calculated and the computed uncertainty in the magnitude +will increase. The best solution to this problem may be to increase +the size of the annulus to minimize the bias. + +.NH 4 +The Principal PHOT Routines +.PP +The main entries in the photometry routine are the following. +.nf +\fL + apinit (ap, cfunction, cbox, sfunction, annulus, dannulus, + aperts, napert, fwhmpsf, noise) + ier = apfitcenter (ap, im, xinit, yinit) + ier = aprefitcenter (ap) + ier = apfitsky (ap, im, xcenter, ycenter, sd, gd) + ier = aprefitsky (ap, sd, gd) + ier = apmag (ap, im, xcenter, ycenter, skyval, skysig, nsky) + ier = apwmag (ap, im, xcenter, ycenter, positive, skyval, skysig, nsky) + ier = apremag (ap, positive, skyval, skysig, nsky) + ier = apwremag (ap, positive, skyval, skysig, nsky) + value = apstat[ir] (ap, param) + apstats (ap, param, str, maxch) + apset[sir] (ap, param, value) + apfree (ap) + +\fR +.fi +.PP +The following parameters can be examined or altered by apset/apstat calls. +.nf +\fL + 1. weighting weighting scheme for wphot + 2. aperts list of apertues + 3. naperts number of apertures + 4. zmag zero point of magnitude scale + 5. itime effective integration time +\fR +.fi +.PP +The following quantities can be examined with apstat calls. +.nf +\fL + + 1. sums array of aperture sums + 2. areas array of areas + 3. mags array of magnitudes + 4. magerrs array of magnitude errors + +\fR +.fi + +.NH 4 +The PHOT Aperture Integration Algorithm +.PP +The integral of the flux within a circular aperture is computed by +fractional pixel techniques. Pixels are assumed to be square apertures +arranged in a rectangular grid. The fraction of a pixel which lies within +the circular APPHOT aperture is computed by an approximation, and all +such contributions are summed to produce the total integral. +.PP +The inclusion of a partial pixel inside the aperture is done as follows. +.IP 1. +If the distance of the current pixel from the center of the star, r, is +exactly equal to the radius of the aperture R then one-half the counts in +the pixel are included. +.IP 2. +If r < R - 0.5 the entire pixel is included while if r > R + 0.5 the pixel +is wholly excluded. +.IP 3. +In between the fraction of the counts varies linearly. A circular aperture +is approximated by an irregular polygon. +.PP +The simplicity of aperture photometry limits the amount of information +available for error analysis. The following three sources of error are +considered. +.IP 1. +The error due to sky noise in the aperture. +.nf + + $error sub 1 ~=~ sigma sub sky ~*~ {A sub apert} sup {1/2}$ + +.fi +.IP 2. +The error in the aperture sum. +.nf + + $error sub 2 ~=~ ( {A sub "sum" ~/~ phpadu} ) sup {1/2}$ + +.fi +.IP 3. +The mean error of the sky. +.nf + + $error sub 3 ~=~ sigma sub sky ~*~ A sub apert ~/~ nsky sup {1/2}$ + + +.fi +where $sigma sub sky$ is either computed by the background fitting +algorithm or set by the user, +and $A sub apert$ is the fractional pixel area of the +aperture. + +.NH 4 +The WPHOT Algorithm +.PP +The WPHOT algorithm computes a weighted aperture sum in an attempt to +minimize noise in the sky. The algorithm is the following where w is +the weight for each pixel, p is the noise free profile value and +$sigma$ is the noise per pixel from all sources. (See the paper +by Stover and Allen 1987 for details) +.nf + + $A sub sum ~=~ sum {w sub i ~*~ (I sub i ~-~ sky)}$ + + $w sub i ~=~ C ~*~ p sub i ~/~ sigma sup 2 sub i$ + + $C ~=~ sum {p sub j} / sum {p sub j ~*~ w sub j}$ +.fi + +.NH 4 +The POLYPHOT ROUTINES +.PP +The principal polyphot routines are the following. + +.nf +\fL + apyinit (ap, sfunction, annulus, dannulus, noise) + ier = apfitcenter (ap, im, wx, wy) + ier = aprefitcenter (ap) + ier = apfitsky (ap, im, xcenter, ycenter, sd, gd) + ier = aprefitsky (ap, sd, gd) + ier = polyfit (ap, im, xver, yver, nver) + value = apstat[ir] (ap, param) + apstats (ap, param, str, maxch) + apset[sir] (ap, param, value) + apfree (ap) + +\fR +.fi + +.PP +.NH 4 +The POLYPHOT Algorithm +.PP +The function of the POLYPHOT task is to compute the flux inside an +irregular polygon given a list of the coordinates of the vertices of a polygon. +The polygon must be entirely inside the image and the vertices of the polygon +must be specified in clockwise or counterclockwise order. +The actual algorithm used is as follows. +.IP 1. +The range of image lines which intersect the polygon are computed. +.IP 2. +For each image line in the specified range the intersection points with the +polygon are computed. +.IP 3. +The flux between pairs of limits is summed using a fractional pixel +approximation for the endpoints. +.IP 4. +The sky is fitted using any of the methods previously discussed and a +user specified annular region. +.IP 5. +The errors are computed as specified in the PHOT specifications. +.PP +.EQ +delim $$ +.EN + +.NH +Example +.PP +A brief example may help illustrate the use of the package. Suppose +we want to process a few hundred stars on image "blue". +.PP +The first step is to prepare a list of objects to be measured. The simplest +way to do this is to interactively mark the objects with the image +cursor using the display (graphics) device and the RIMCURSOR (RGCURSOR) +task. +.nf +\fL + + ... load image on the display ... + + ap> rimcursor > starlist + + ... move cursor and mark stars ... + + + ... load contour plot on graphics terminal ... + + ap> rgcursor > starlist + + ... move cursor and mark stars ... +\fR +.fi + +Alternatively one can run DAOFIND to compute a list of candidate objects +in the frame. +The name of the coordinate file is stored in the PHOT parameter set. + +.nf +\fL + ap> phot.coords=starlist +\fR +.fi + +.PP +The next step is to set up the PHOT parameters interactively. +First we load the image (contour plot) blue on the display (graphics +terminal). Next we call up PHOT in interactive mode. + +.nf +\fL + ap> phot blue + ... cursor appears ... + +\fR +.fi + +.PP +PHOT takes input by reading the image (graphics) +display (terminal) cursor. In order to display the available commands +we tap the ? key and the following text appears on the screen. + +.nf +\fL + Interactive Phot Commands + +? Print options +: Colon command see below +i Setup PHOT parameters interactively +w Write PHOT parameters to the parameter files +l Process the remainder of the coordinate list +r Rewind the coordinate list +c Fit center around the current cursor position +t Fit sky around the current cursor position +s Fit sky around the current center position +p Compute magnitudes around the cursor position +f Fit center, sky and compute magnitudes +sp Fit center, sky, compute magnitudes, and save +q Exit program + +Phot parameters are listed or set with the following commands. + +:m [n] Move cursor to the [nth] object in the coordinate list +:n [n] Measure the [nth] object in the coordinate list + +:show [center/sky/phot/all] List the aphot parameters +:fwhmpsf [value] Full width half maximum of the PSF +:noise [string] Noise model +:threshold [value] Threshold value for centering +:sigma [value] Standard deviation of the background +:ccdread CCD readout noise keyword +:readnoise Readout noise in electrons +:gain Gain keyword +:epadu Electrons per adu + +:calgorithm [string] Centering function +:positive [y/n] Emission or absorption feature +:cbox [value] Width of the centering box in fwhmpsf +:cmaxiter [value] Maximum number of centering iterations +:maxshift [value] Maximum shift in fwhmpf +:minsnratio [value] Minimum signal to noise ratio of pixels +:clean [y/n] Clean subraster before centering +:rclip [value] Clipping radius in fwhmpsf +:rclean [value] Cleaning radius in fwhmpsf +:kclean [value] Sigma for clean algorithm +:mkcenter [y/n] Mark the centers on the display + +:salgorithm [string] Sky fitting algorithm +:annulus [value] Inner radius of sky annulus in fwhmpsf +:dannulus [value] Width of sky annulus in fwhmpsf +:skyvalue [value] User supplied sky +:smaxiter [value] Maximum number of rejection cycles +:skreject [value] +/- Pixel rejection limits in sky sigma +:snreject [value] Maximum number of rejection interations +:khist [value] +/- Sky histogram size in sky sigma +:binsize [value] Resolution of sky histogram in sky sigma +:smooth [y/n] Lucy smooth the sky histogram +:rgrow [value] Region growing radius in fwhmpsf +:marksky [y/n] Mark the sky annuli on the display + +:weighting Weighting for wphot +:aperts [string] Aperture radii in fwhmpsf +:zmag [value] Zero point of magnitude scale +:exposure [string] Exposure time keyword +:itime [value] Integration time +\fR +.fi + +.PP +We select the interactive setup option, move the image +cursor to a high signal-to-noise, isolated star and tap the i key. +PHOT responds by plotting the radial profile of the star on the +screen and requesting the user to mark the fwhm of +the psf, the centering aperture, the inner and outer sky annuli, +the sky background and sigma and the set of circular apertures. +The parameters so set can be examined and/or reset with the : commands as shown +above. Sample measurements can be made of several stars by moving the +cursor and typing the f command. Finally when we are happy with the +parameter set we type w to store the parameters and q to exit the program. +.PP +Now we are ready to do photometry. We enter the PHOT program in batch mode. + +.nf +\fL + ap> phot blue inter- & +\fR +.fi + +The batch job is now running, appending output lines to the file "blue.mag.#". +We can proceed to set up the job for the red image, in much the same way +that we set up the job for the blue image. When both jobs finish, we +can use the list processing tools to filter out the good objects and +calculate colors. + +.NH +The APPHOT Tasks +.PP +Manual pages for the APHOT tasks are attached. Although the working of the +various tasks may change in detail, the help pages attached here should +provide a good description of the function of each task. +.PP +When the package has stabilized a detailed users guide will be written. diff --git a/noao/digiphot/apphot/doc/specs/apphot.spc.lw b/noao/digiphot/apphot/doc/specs/apphot.spc.lw new file mode 100644 index 00000000..71285557 --- /dev/null +++ b/noao/digiphot/apphot/doc/specs/apphot.spc.lw @@ -0,0 +1,1296 @@ +.EQ +delim $$ +.EN + +.RP +.TL +Specifications for the Aperture Photometry Package +.AU +Lindsey Davis +.AI +.K2 "" "" "*" +Revised October 1987 + +.AB +The APPHOT package is a set of tasks for performing aperture photometry +on uncrowded or moderately crowded fields, in either interactive or batch mode. +The photometric technique employed is fractional pixel aperture +integration. Point spread function fitting techniques are not used and no +knowledge of the point spread function is required for the computation of +magnitudes. Separate tasks are provided for creating and modifying object lists, +computing accurate centers for a list of objects, computing sky values for +a list of objects and performing aperture photometry inside circular or +polygonal apertures. +.AE + +.NH +Introduction +.PP +The APPHOT package is a set of tasks for performing +aperture photometry on uncrowded or moderately crowded fields. +The photometric technique employed is fractional pixel integration. Point +spread function techniques are not used and no knowledge of the point spread +function is required for the computation of magnitudes. +.PP +The APPHOT package performs multi-aperture photometry on digitized starfields +maintained as IRAF image files. Input to the package consists of an +image file, a list of object coordinates, numerous parameters controlling +the analysis algorithms and, optionally, the graphics terminal and/or +display. APPHOT output consists of successive lines of text where each line +summarizes the results of the analysis for a particular object. +.PP +Given starting coordinates and an IRAF image, the principal APPHOT +task computes accurate centers, sky values and magnitudes +for a list of objects. Separate +IRAF callable tasks in APPHOT exist to create and modify object +lists, to determine image characteristics such as the full width half maximum +of the point spread function or standard deviation of the sky pixels, +to compute accurate centers for a list of objects, to compute accurate local sky +values for a list of objects, and to compute magnitudes inside a polygonal +aperture. + +.NH +APPHOT Package Requirements +.NH 2 +APPHOT Package Input +.NH 3 +The IRAF Image +.PP +APPHOT assumes that images exist on disk in IRAF format. Facilities for reading +and writing images exist elsewhere in IRAF such as in package DATAIO or +MTLOCAL. +.PP +APPHOT assumes that the image data is linear. +The input image is assumed to have been corrected for those instrumental +defects which affect the intensity of a pixel. These include pixel to +pixel variations in the bias values, pixel to pixel gain variations, +cosmic rays, cosmetic defects, geometric distortion, +and detector non-linearities. +.PP +APPHOT assumes that the local sky background is approximately flat in the +vicinity of the object being measured. This assumption is equivalent to +assuming that the local sky region has a unique mode. Therefore any +variations in the sky background which occur at the same scale as the +sky region should be removed prior to entering APPHOT. +.PP +The point spread function of the image is assumed to be constant for all +regions of the image. This is particularly critical in the case of faint objects +for which small apertures which minimize the effects of crowding and +sky noise in the aperture are used. The wings of the object will +almost certainly extend beyond the aperture and good results will only be +obtained if +objects are consistently well centered and the shape and diameter of an object +is constant throughout the image and invariant to magnitude. + +.NH 3 +The Coordinate Lists +.PP +All APPHOT tasks operate on lists of object coordinates or interactive cursor +input. Lists are maintained as text files, +one object per line with the x and y coordinates in +columns one and two respectively. List files may be created interactively +with either the graphics or image cursor, by a previously executed APPHOT +task, by a previously executed IRAF task or by a user task. +.PP +The x and y coordinates contained in the list file can be either the +starting centers for the objects of interest or the true centers. +In either case the aperture centered around the object position must +not extend beyond the boundary of the image. To obtain reliable results +from the centering algorithm the starting centers should not be more than +1 fwhmpsf pixels from the true centers. + +.NH 3 +Algorithm Parameters +.PP +Many tasks in the APPHOT package have an associated set of algorithm parameters +which control the operation of the analysis routines. For example the +centering and sky fitting algorithms each have an associated group of +parameters. +The APPHOT tasks supply reasonable defaults for these parameters. However +the user may alter them at any time in interactive mode or by editing the +appropriate parameter file before running the task in batch. + +.NH 3 +Terminal Graphics and the Image Display +.PP +Most APPHOT programs may be run in either interactive or batch mode. +In interactive mode, the user can mark the positions of objects by +interactively, positioning the image cursor on the display device. +Simple cursor commands can interactively alter the algorithm parameters. +In batch mode the algorithm parameters are +fixed and object coordinates are taken from the user supplied coordinate list. +The display device is not required in batch mode. +.PP +At present there is no high level IRAF display interface. Therefore the present +version of APPHOT replaces the display device with terminal +graphics. For example it is possible to load a contour plot of an image +or image section, and run the APPHOT tasks, interactively marking +positions on the plot. This is a temporary measure to tide thing over until +the display interface is available. Furthermore this option is only +really suitable for those terminal which have both text and graphics +windows displayed at the same time. +.PP +Certain APPHOT tasks such as FITSKY occasionally require an interactive graphics +capability. For example it is sometimes desirable to plot the histogram +of the sky pixels and mark the peak of the histogram interactively rather +than using the automatic sky fitting routines. +Graphics capablity has been added to APPHOT tasks as deemed useful. + +.NH 2 +APPHOT Package Functions +.NH 3 +Creating Coordinate Lists +.PP +APPHOT task(s) shall exist to create coordinate lists interactively within +APPHOT by loading the IRAF image into the image display +and successively marking the objects to be measured with the image cursor. +It shall be possible to mark the positions of objects on the display, and draw +circles of arbitrary size around the objects of interest. +It shall be possible to verify existing coordinate lists by marking the object +coordinates on the image display. +.PP +At present the full image display cababilities do not exist in IRAF. +Therefore as a temporary measure most tasks will run with a contour +plot and the graphics cursor as a substitute for the image display and +image cursor by setting the image cursor to stdgraph and the display +parameter for each task to stdgraph. +The output coordinates will be written to a text file and may be used as +starting coordinates for the APPHOT routines. +.PP +Those sites which have SUN workstations can use the IMTOOL facilites to +create cursor lists. +.PP +APPHOT tasks shall exist to automatically detect objects by specifying the IRAF +image to be searched, plus a few image characteristics such as a detection +threshold and the full width half maximum of the point spread function. +The output coordinates plus a few object statistics will be written to a +text file. + +.NH 3 +Coordinate List Operations +.PP +General list processing tasks are or will be available in the IRAF lists +package. Examples of useful currently existing tasks are list sorting by for +example magnitude and performing a linear transformations +on coordinate lists. +.PP +It may eventually be necessary to add some specialized list processing tasks +to APPHOT. One example is a list matching facility in which objects in +common to two lists are combined and output to a third list. + +.NH 3 +Determining the Image Characteristics +.PP +APPHOT tasks shall exist to estimate certain image +characteristics such as the full width half maximum of the image point spread +function and the standard deviation of the background. In order to obtain +meaningful error estimates it is also necessary to specify the noise +charactersitics of the detector and a noise model. +In this version of APPHOT two noise +functions will be supported a constant sky background noise, +and constant background noise plus Poisson statistics in the object. +.PP +The reason for this capability is that the majority of the APPHOT +algorithm parameters scale with these two image characteristics. +For example all the pixel scale dependent parameters such as the centering +aperture, object apertures, the two sky annuli and the +maximum shift parameter all scale with the full width half +maximum of the point spread function. Similarly most of the pixel intensity +dependent parameters scale with the standard deviation of the sky pixels. + +.NH 3 +Centering +.PP +An APPHOT task shall exist to determine accurate centers for a list of objects, +using the approximate object coordinates as a starting point. +The centering aperture may extend beyond the boundaries of the image but +a warning message will be generated. +.PP +A choice of centering algorithms with a range of efficiency and accuracy will +be available. The center determination must be resistant to the affects of +nearby contaminating objects. +.PP +The user may opt to use the starting center as the actual center in all cases, +to use the starting center as the actual center if the object is very faint, +or tweak up the center if the signal to noise is above a certain threshold. +.PP +The output of the centering algorithm will the set of computed coordinates +and their errors. + +.NH 3 +Fitting the Sky +.PP +An APPHOT task shall exist to compute a constant background value by analysis +of an annular region surrounding the object. +The background is assumed to be flat in the region +of the object, but may contain contaminating objects or defects which +shall be detected and eliminated by the fitting algorithm. +It shall be permissible for the background region to extend beyond the +boundaries of the image; the out of bounds region of the background shall +be excluded from the fit. +.PP +The user may supply a constant background, with zero-valued noise and skew +value or read appropriate values from a file instead of computing the +background. +.PP +The output of the sky fitting algorithm shall be +the mode, standard deviation and skew of the sky as well as the number +of pixels left in the background region after pixel rejection and the number +rejected. + +.NH 3 +Multi-aperture Photometry +.PP +APPHOT routines shall exist to compute the integral of object minus background +within one or more circular apertures centered upon the object. +The integration shall be +performed using partial pixel techniques, to minimize the effects of +sampling. If the aperture contains any indefinite pixels, or if the +aperture extends beyond the boundary of the image, an indefinite result +shall be returned. Both normal and weighted photometry routines shall +be available. +.PP +It shall be possible to normalize the output magnitudes to a user specified +integration time using values stored in the IRAF image header. +.PP +The output shall consist of magnitudes and errors for each of the specified +apertures. +.NH 3 +Polygonal Aperture Photometry +.PP +Determine the integral of the object within a specified +polygon. Aperture integration shall be by fractional pixel summation +of successive image lines. + +.NH +Specifications +.NH 2 +Apphot CL Callable Tasks +.PP +The CL callable part of the APPHOT package consists of the following +routines:\f(CW + +.nf +.na + mark -- create/verify coordinate lists interactively + polymark -- create/verify polygon lists interactively + daofind -- automatic image finder from DAOPHOT + lintran -- linearly transform a list of coordinates (LISTS package) + + radprof -- compute the radial profile of an object. + fitpsf -- model the PSF + + center -- compute accurate centers for a list of objects + fitsky -- compute accurate sky values for a list of objects + phot -- perform multi-aperture photometry on a set of objects + polyphot -- compute the flux inside a set of irregular polygons + wphot -- perform weighted multi-aperture photometry\fR +.ad +.fi + +.NH 2 +Standard Analysis Procedures +.PP +A standard reduction procedure would be something as follows. +.IP 1. +Estimate the image and data characteristics in the following manner. +.RS +.IP 1. +Use the interactive setup option (i key) in the PHOT task to specify the +fwhm of the psf, +the centering apperture, the sky annuli, the photometry apertures as +well as estimate the sky sigma. +Examine the results (:show command) and optionally store the +new parameters in the parameter files (w key). +.IP 2. +Use the EPAR task to edit the parameter files directly. For example the +detector gain and readout noise must be known before running PHOT in +order to get reliable error estimates. +.RE +.IP 2. +Prepare a coodinate list in one of the following ways. +.RS +.IP 1. +Running MARK or POLYMARK. +.IP 2. +Run DAOFIND or some other automatic image finder. +.IP 3. +Run another APPHOT task such as CENTER . +.IP 4. +Run any other IRAF or user program which generates the appropriate +format. +.IP 5. +Transform an existing list using the LISTS package facilities +.RE +.IP 3. +Run PHOT or WHOT in non-interactive mode to perform the multi-aperture +photometry. The user should be familiar +with the algorithms used to measure the object center, to fit the background, +and compute the aperture integral, magnitude, and errors. The values of +all visible and hidden PHOT parameters should be inspected before doing +any serious processing. Note that CENTER and FITSKY can be run independently +of PHOT and their output used as input to PHOT. +.EQ +delim $$ +.EN + +.NH 2 +The APPHOT Algorithms +.PP +The principal APPHOT algorithms are described below. + +.NH 3 +The RADPROF Algorithm +.PP +The function of the RADPROF task is to compute the radial profile of +selected, isolated, high signal to noise objects in an IRAF image. +.PP +Given the IRAF image, an initial center, an aperture and a step size, +RADPROF computes the radial profile of an object in the following manner. +.IP 1. +The APPHOT centering routines are used to compute an accurate center for the +object. The new center is used to compute the radial coordinate for each +pixel in the subraster. +.IP 2. +The APPHOT sky fitting routines are used to compute an accurate sky value +for the object. The new sky value is used to compute the object intensity +for each pixel in the subraster. +.IP 3. +The CURFIT package routines are used to produce a smooth intensity versus +radius curve by fitting a cubic least squares spline function to the data +using linear least squares techniques. +.IP 4. +The fitted curve is evaluated at equally spaced intervals to produce the +final radial profile. The profile is normalised using the r = 0 value. +.IP 5. +The smoothed curve is integrated using the +1D integration routines IMINTERP to evalute the fraction of the total +integral at each interval. +.IP 6. +The three quantities $I sub r$ the raw intensity, $Inorm sub r$ the +normalized intensity, and $Ifraction sub r$ the fraction of the total +intensity inside radius at r, are plotted on the terminal and +output as a function of r to a text file. +.PP +RADPROF is used principally to compute the stellar image and setup the +parameters for doing photometry. Its default output is a radial profile +plot with the phot parameters marked on it. + +.NH 3 +The FITPSF Algorithm +.PP +The function of the FITPSF task is to fit an analytic model to an object +in order to derive information about the point spread function. Given +an IRAF image, an initial center and an aperture, FITPSF computes the +model parameters in the following manner. +.IP 1. +The fitting function is chosen. +The present version of FITPSF offers two function choices a 2D radial Gaussian +function and an elliptical Gaussian function. +A third option, moment analysis, has been added to the FITPSF package. +The image characteristics are evaluted by using the 0th, 1st and 2nd order +moments of the image. +.IP 2 +Initial guesses for the parameters are made from the subraster data. +.IP 3 +The parameters and their errors are derived using standard non-linear least +squares techniques and the NLFIT package. + +.NH 3 +The DAOFIND Algorithm +.PP +The function of the DAOFIND task is to automatically detect objects +in an IRAF image above a certain intensity threshold. +The user specifies an intensiyt threshold, +the estimated full width half maximum of +the point spread function, +and limits on the sharpness and roundness of the objects to be detected. +DAOFIND produces a list of x and y coordinates and a sharpness +and roundness statistic for each detected object. +.PP +The DAOFIND algorithm works in the following way. +.IP 1. +The user specifies an intensity threshold above local sky and estimates +the full width half maximum of the point spread function. +.IP 2. +DAOFIND computes a convolution kernel which is a linear +function of the brightness values in an approximately circular array of +pixels. The original data is convolved with the computed kernel. +The equivalent mathematical +operation is a convolution of the original data +with truncated, lowered circular Gaussian function with the specified FWHM, +computed in such a way as to be the mathematical +equivalent of fitting a Gaussian stellar profile to the object data by least +squares. The coefficients of the linear function sum to zero so that the +overall bias level (local sky) cancels out exactly. Since the function is +symmetric about a single pixel, a smooth gradient in the sky brightness +also cancels exactly. Therefore the user does not have to specify an +absolute brightness threshold but only a threshold above local sky. +.IP 3 +The convolved data is searched for local maxima. Local maxima which are +less than the specified threshold are rejected. A pixel is defined to be +a local maximum when it is the brightest pixel within +$n ~*~ sigma sub Gauss$. +.IP 4. +Using the original data, DAOFIND computes an object sharpness statistic which +can be used to reject +hot or cold pixels. The sharp parameter is defined below. +Detected objects with a sharpness parameter outside the range specifed +by sharplo and sharphi are rejected. Typical values for sharplo and +sharphi are 0.2 and 1.0 respectively. +.nf + + $I sub delta$ = height of best fitting $delta$ function = pixel value + + $I sub Gauss$ = height of best fitting Gaussian function = convolved value + + sharplo <= sharp = ${I sub delta} over {I sub Gauss}$ <= sharphi + +.fi +If the brightness enhancement detected in the convolved data is due to +a single bright pixel, then the best fitting delta function will have an +amplitude equal to the height of this pixel above the local background, +while the amplitude of the best fitting Gaussian will be pulled down by +the surrounding low valued pixels. Sharp will be a number significantly +greater than one. A single cold pixel will produce +brightness enhancements approximately 0.5 * FWHM away +from the pixel in question in all directions. In this case the height +of the delta +function which best fits these spurious maxima is close to zero, while the +height of the best fitting Gaussian is some small positive number. +In this case sharp will be close to zero. +.IP 5. +The roundess statistic is computed from the original picture data by fitting +1D Gaussians +to the marginal sums in x and y. If the height of either 1D +Gaussian is negative the object is rejected. If both heights are +positive the roundness parameter is computed. +.nf + + $DELTA I ~=~ I sub {x ~ Gauss} ~-~ I sub {y ~ Gauss}$ + + $<I> ~=~ I sub {x ~ Gauss} ~+~ I sub {y ~ Gauss}$ + + $roundlo ~<=~ round ~=~ {DELTA I} over <I> ~<=~ roundhi$ + +.fi +Objects which are elongated in the +x direction have roundness values less than zero and those elongated in +the y direction have roundness greater than zero. +Round discriminates only against objects which are elongated +along either rows or columns. Objects elongated at a 45 degree angle will +not be rejected. +.IP 6. +Finally the approximate x and y centroids of the detected objects, +rough magnitudes relative to threshold are computed, and object is added +to the output file. + + +.NH 3 +The CENTER Task + +.NH 4 +Centering Package Routines +.PP +The following are the principal programmer callable routines routines in the +centering package. +.nf +\f(CW + + apcinit (ap, cfunction, cbox, fwhmpsf, noise) + ier = apfitcenter (ap, im, xinit, yinit) + ier = aprefitcenter (ap) + value = apstat[ir] (ap, param) + apstats (ap, param, str, maxch) + apset[sir] (ap, param, value) + apcfree (ap) + +\fR +.fi +.PP +The following quantities can be examined or set by apstat/apset calls +.nf +\f(CW + data 1. fwhmpsf full width half maximum of psf in pixels +parameters 2. threshold minimum intensity for centering + 3. noise noise model + 4. sigma standard deviation of background + 5. readnoise readout noise of CCD in electrons + 6. epadu electrons per adu + +centering 1. calgorithm centering algorithm +parameters 2. positive emission / absorption features + 3. cbox centering radius in fwhmpsf + 4. cmaxiter maximum number of fitting iterations + 5. maxshift maximum permitted shift in fwhmpsf + 6. minsnratio minimum permitted signal to noise ratio + 7. clean clean subraster before centering + 8. rclean cleaning radius in fwhmpsf + 9. rclip clipping radius in fwhmpsf + 10.kclean k-sigma rejection for cleaning in sigma +\fR +.fi + +.PP +The following computed quantities can be examined by apstat calls. +.nf +\f(CW + 1. xcenter computed x coordinate + 2. ycenter computed y coordinate + 3. xerr computed x coordinate error + 4. yerr computed y coordinate error +\fR +.fi +.PP +See the manual pages for CENTER and CENTERPARS for a detailed description +of the centering parameters. + +.NH 4 +The Centering Algorithm +.PP +The function of the CENTER task is to compute accurate centers and errors +for objects in an IRAF image given a list of initial positions and a +centering aperture. +.IP 1. +If the centering algorithm is disabled, the computed center is set to the +initial center and the uncertainty estimate is set to zero. +.IP 2. +If the cleaning algorithm is enabled, clean the subraster before centering. +.IP 3. +Estimate is made of the signal to noise of the object. If this quantity is +less than a certain minimum value the computed center is kept +but a warning message is issued. +.IP 4. +The center and errors are computed using one of several algorithms. +.IP 5. +If the computed center is greater than a user specified distance from the +initial center then the computed center is returned with an error +message. + +.NH 4 +Symmetry Clean Algorithm +.PP +The symmetry-clean algorithm attempts to remove defects in the centering +subraster by assuming that the object has radial symmetry and comparing +pixels on the opposite sides of the center of symmetry. The algorithm +works in the following way. +.IP 1. +The center of symmetry is computed. Normally the center of symmetry is assumed +to coincide with the position of the brightest pixel in the subarray. +However if the maximum pixel is more than a user specified distance away +from the intial center, the initial center is used as the center of symmetry. +.IP 2. +Pixels inside a specified cleaning radius are unaltered. +.IP 3. +Pairs of pixels diametrically opposed about the center +in the cleaning region between the cleaning and clipping +radii are tested for equality. If the difference between the pixels is +greater than a specified k-sigma rejection limit, the larger value is replaced +by the smaller. +In this region sigma is computed from Poisson statistics. +.IP 4. +Pairs of pixels in the clippping +region are compared in the same manner as those in the cleaning region +except that sigma is the standard deviation of the sky pixels. +.PP +The effect of the symmetry-clean algorithm is to edit the raster, +removing any contaminating objects in the vicinity of the primary object. +This simplifies the fitting algorithm and increases its reliability, +since it does not have to deal with multipeak marginal distributions. + +.NH 4 +Signal to Noise Estimate + +.PP +The signal to noise of the object is estimated from the data values +in the subraster in the following way. +.nf + + $SNR ~=~ N sub object over {sqrt {n sub pix ~*~sigma sub sky sup 2}}$ + + or + + $SNR ~=~ N sub object over {sqrt {N sub object ~+~ n sub pix~*~sigma sub sky sup 2}}$ + +.fi +where $N sub *$ is the number of counts in the object above threshold, +$sigma sub sky$ +is the standard deviation of the pixels in the sky region and +$n sub pix$ is the number of pixels in the object aperture. +The first approximation corresponds to constant sky noise only, +the second includes Poisson noise in the object. + +.NH 4 +Centroid +.PP +The centroid centering algorithm is similar to that used in MPC and can +be briefly described as follows. For more detailed description +see (Stellar Magnitudes From Digital Pictures, 1980, Adams et al). +.IP 1. +The marginal distributions in x and y are accumulated. +.IP 2. +The intensity weighted centroid positions for the marginals is computed +using only data pixels which are above the threshold intensity. If the +threshold parameter is 0 the mean intensity of the marginal is used +in place of the threshold +.nf + + $I sub i ~=~ I sub i ~-~ threshold ~~~~~ I sub i ~>~ 0.0$ + + $x sub c ~=~ {sum I sub i ~ x sub i} over {sum I sub i}$ + +.fi +.IP 3. +The errors are estimated in the following way +.nf + + $sigma sup 2 ~=~ {sum I sub i ~ x sub i sup 2} over {sum I sub i} ~-~ x sub c sup 2$ + + $err sub xc ~=~ sqrt {{sigma sup 2} ~/~ sum I sub i}$ + +.fi + +.NH 4 +Gaussian Fit to the Marginals +.PP +The fit is performed in the following way. +.IP 1. +The marginal distributions in x and y are accumulated. +.IP 2. +Initial guesses for the parameters of the 1D Gaussians $I sub Gauss$, +$x sub c$ and $I sub sky$ are derived from the marginal distributions +themselves. The width $sigma$ is held constant. +.IP 3. +The best fit parameters and their errors are derived using non-linear +least-squares techniques and the NLFIT package. + +.NH 4 +Optimal Filtering of Marginals +.PP +The fit is performed is the following way. +.IP 1. +The marginal distributions in x and y are accumulated. +.IP 2. +The centroid of the observed distribution is computed by solving the +following equation. +.nf + + $PSI (x sub c ) ~=~ sum omega sub i (x sub c ) ~ PHI sub i ~=~ 0$ + + $omega sub i ~=~ {{partial phi sub i} ~/~ {partial x sub c}} over {phi sub i~+~b}$ + +.fi +The assumptions are that the observed distribution $PHI sub i$ is correctly +modeled by the profile function $phi sub i$. The usual choise of profile +model for centering is a Gaussian. Howver in the interests of speed a triangle +function has been substituted. This causes at most a 7% increase in the +random centering error. +.IP 3. +The startup procedure is based on the following fact. +.nf + + $PSI (x sub n )~>~0~~for~~ x sub n ~<~ x sub c$ + + $PSI (x sub n ) ~<~0~~for~~ x sub n ~>~ x sub c$ + +.fi +The iteration is initialized by assuming that $x sub 1$ = $x sub c$ and +computing $PSI (x sub 1 )$. The initial x +value is incremented by $+- sigma sub Gauss$ depending on the sign of $PSI$. The +search is repeated until $PSI (x sub {n-1})$ and $PSI (x sub n)$ have +opposite signs. At this point the true center is bracketed by the +estimated positions $(x sub n, ~ x sub {n-1})$ and we have a table of at +least 2 values of $PSI (x sub n )$. +.IP 4. +The computation proceeds by interpolating in the table of values for the +estimated position $x sub {n+1}$ where $PSI$ = 0. If the table contains only +two values as may be the case for the inititial interpolation, linear +interpolation is used. In all other cases a quadratic fit to the three +most recent $PSI$ values is used. The computation is complete when +two successive estimates differ by less than some tolerance typically +0.001 pixel. +.IP 5. +The errors are estimated as follows. +.nf + + $sigma sup 2 ~=~ ( {int {( partial phi ~/~ partial x sub c )} sup 2 over { + phi + b}} ) sup -1$ + + $err sub xc ~=~ sqrt {sigma sup 2}$ + +.fi + +.NH 4 +Other Centering Methods +.PP +The code is constructed in such a way that new algorithms may be +easily added at a future date, such as the more sophisticated techniques +required for accurate astrometry. +.EQ +delim $$ +.EN +.NH 3 +The FITSKY Task + +.NH 4 +Sky Fitting Routines + +.PP +The following are the main entry points in the sky fitting package. +.nf +\f(CW + apsinit (ap, function, annulus, dannulus, fwhmpsf, noise) + ier = apfitsky (ap, im, xpos, ypos, sd, gd) + ier = aprefitsky (ap, sd, gd) + value = apstat[ir] (ap, param) + apstats (ap, param, str, maxch) + apset[irs] (ap, param, value) + apsfree (ap) +\fR +.fi +.PP +The following quantities can be examined or set with apset/apstat calls. +.nf +\f(CW +data 1. fwhmpsf full width half maximum of the psf +parameters 2. sigma standard deviation of sky pixels + +sky fitting 1. annulus inner radius of sky annulus in fwhmpsf +parameters 2. dannulus outer radius of sky annulus in fwhmpsf + 3. sfunction sky fitting algorithm + 4. smaxiter maximum number of fitting iterations + 5. kreject k-sigma rejection limit sigma + 6. nreject maximum number of rejection cycles + 7. rgrow region growing radius in fwhmpsf + + 8. khist half-wdth of histogram in sigma + 9. binsize binsize of histogram in sigma + 10.smooth Lucy smooth the histogram + + 11.skyfile name of text file containing sky values + 12.skyvaluser supplied constant value for sky +\fR +.fi +.PP +The following computed quantities can only be examined with apstat calls. +.nf +\f(CW + 1. skymode computed sky value + 2. skysig computed sky sigma + 3. skyskew computed sky skew + 4. nsky number of sky pixels + 5. nsky_reject number of rejected sky pixels +\fR +.fi + +.NH 4 +The Sky Fitting Algorithms +.PP +A good background fit is essential to aperture photometry. Fitting +the background is trivial in a sparse field, but difficult in a crowded +field. In general the background region will contain contaminating objects +which must be detected and excluded if a good fit is to be obtained. +.PP +The main algorithm used in APPHOT is the following. +.IP 1. +If the skyfitting switch is disabled either read the sky values from a text +file or accept a user supplied constant for the sky. +.IP 2. +Perform the initial sky fit using one of the specified algorithms. The +sky fitting algorithms fall into three general categories, those that use +the actual sky pixel array itself, those that operate on a histogram of +sky values and those that rely on user interaction. +.IP 3. +If the pixel rejection flags are set perform pixels rejection with optional +region growing. + +.NH 4 +Sky Pixel Array Techniques + +.NH 5 +Median +.IP 1. +Sort the array of sky pixels. This is necessary to avoid quantization effects. +.IP 2. +Compute the median, and the standard deviation and skew with respect to the +mean. +.IP 3. +If the k-sigma rejection limit is greater than zero and the maximum number +of rejection cycles is greater than one, perform pixel rejection. +Pixels greater than k-sigma from the median are rejected. Region growing +is optional. +.IP 4. +Stop the rejection cycle on any given iteration if the maximum number of +rejection cycles ix exceeded, no more sky pixels are left or no more +pixels are rejected. + +.NH 5 +Mode +.IP 1. +Sort the array of sky pixels. This is necessary to avoid quantization effects. +.IP 2. +Compute the mode, and the standard deviation and skew +with respect to the mean. +.nf + + $I sub mode ~=~ 3.0 ~*~ I sub median ~-~ 2.0 ~*~ I sub mean$ + +.fi +.IP 3. +If the k-sigma rejection limit is greater than zero and the maximum number +of rejection cycles is greater than one, perform pixel rejection. +Pixels greater than k-sigma from the mode are rejected. Region growing +is optional. +.IP 4. +Stop the rejection cycle on any given iteration if the maximum number of +rejection cycles ix exceeded, no more sky pixels are left or no more +pixels are rejected. + + +.NH 4 +Histogram Techniques +.PP +The following three techniques all operate on the histogram of the sky pixels. +The routines all construct the histogram in the following identical manner. +.IP 1. +The mean of the sky distribution is computed. +.IP 2. +If the user specified standard deviation of the sky pixels is INDEF the +algorithm computes the standard deviation of the sky pixels with respect +to the mean. +.IP 3. +All pixels within plus or minus sigma standard +deviations are accumulated into a histogram. The user specifies the bin size. +.IP 4. +The histogram may optionally be Lucy smoothed before any operation is performed +on it. + +.NH 5 +Centroid +.PP +The mode, sigma and skew of the sky pixels are computed in the following +manner. +.IP 1. +The histogram is compiled as above. +.IP 2. +The mode, standard deviation and skew of the sky pixels are computed in the +following manner. + +.nf + $I sub 0 ~=~ sum I sub i$ + $I sub 1 ~=~ sum I sub i ~ x sub i$ + $I sub 2 ~=~ sum I sub i ~ x sub i sup 2$ + $I sub 3 ~=~ sum I sub i ~ x sub i sup 3$ + + $I sub mode ~=~ {I sub 1} ~/~ {I sub 0}$ + $sigma ~=~ {( I sub 2 ~/~ I sub 0 ~-~ I sub mode sup 2 )} sup {1/2}$ + $skew ~=~ ( {I sub 3 ~/~ I sub 0 ~-~ I sub mode ~*~ sigma sup 2 ~-~ I sub mode sup 3} ) sup {1/3}$ + +.fi +.IP 3 +If pixel rejection is enabled sky pixels within a user supplied limit of +the mode are rejected with optional region growing. + +.NH 5 +Gaussian Fit +.PP +The mode, standard deviation and skew of the sky pixels are derived from a +model fit in the following way. +.IP 1. +The histogram of the sky pixels is compiled as above. +.IP 2. +Initial guesses to the model parameters, $N sub max$, $I sub mode$, +$sigma$, and $skew$ are made from the histogram itself. +.IP 3. +Final parameters and their errors are derived using non-linear least squares +techniques and the NLFIT package. +.IP 4. +If pixel rejection is enabled sky pixels within a user supplied limit of +the computed mode are rejected with optional region growing. + +.NH 5 +Optimal Filtering +.PP +The method is as follows. +.IP 1. +The histogram is compiled as above. +.IP 2. +Using the mean of the sky pixels as the intital value of the sky mode, +a new mode is computed using the optimal filtering technique +described for centering. +.IP 4 +If pixel rejection is enabled sky pixels within a user supplied limit of +the computed mode are rejected with optional region growing. + +.NH 5 +Cross Correlation +.PP +The method is as follows. +.IP 1. +The histogram is compiled as above. +.IP 2. +The noise function is estimated using the standard deviation of the sky +pixels and the cross-correlation function is computed. +.IP 3. +The mode is computed using quadratic interpolation around the peak of the +distribution. +.IP 4 +If pixel rejection is enabled sky pixels within a user supplied limit of +the mode are rejected with optional region growing. + +.NH 4 +Interactive Techniques + +.NH 5 +Histogram Plot +.PP +The histogram is compiled as described above and the user marks the peak +on the histogram plot with the graphics cursor. The sigma and skew of the +sky distribution with respect to the mean is also computed. + +.NH 5 +Radial Distribution +.PP +A radial profile plot of the sky region is plotted and the user marks the +sky value on the plot with the graphics cursor. The sigma and skew of the sky +distribution with respect to the mean is computed. + +.NH 4 +Pixel Rejection and Region Growing +.PP +All the sky fitting algorithms permit pixel rejection and +optional region growing. +Pixel rejection and region growing are +performed by locating all pixels more than k * sigma from the mode, +and blindly rejecting all pixels within a certain radius of each deviant +pixel. This simple algorithm works well because the sample is large, +and therefore there is little penalty for discarding pixels that might +not be deviant. Region growing also tends to accelerate convergence +significantly. +.PP +Very faint contaminating objects are difficult to detect and reject. +If there are enough such objects, they should not be rejected, because +there are probably a few in the object aperture as well. A higher sky +sigma will be calculated and the computed uncertainty in the magnitude +will increase. The best solution to this problem may be to increase +the size of the annulus to minimize the bias. + +.NH 4 +The Principal PHOT Routines +.PP +The main entries in the photometry routine are the following. +.nf +\f(CW + apinit (ap, cfunction, cbox, sfunction, annulus, dannulus, + aperts, napert, fwhmpsf, noise) + ier = apfitcenter (ap, im, xinit, yinit) + ier = aprefitcenter (ap) + ier = apfitsky (ap, im, xcenter, ycenter, sd, gd) + ier = aprefitsky (ap, sd, gd) + ier = apmag (ap, im, xcenter, ycenter, skyval, skysig, nsky) + ier = apwmag (ap, im, xcenter, ycenter, positive, skyval, skysig, + nsky) + ier = apremag (ap, positive, skyval, skysig, nsky) + ier = apwremag (ap, positive, skyval, skysig, nsky) + value = apstat[ir] (ap, param) + apstats (ap, param, str, maxch) + apset[sir] (ap, param, value) + apfree (ap) + +\fR +.fi +.PP +The following parameters can be examined or altered by apset/apstat calls. +.nf +\f(CW + 1. weighting weighting scheme for wphot + 2. aperts list of apertues + 3. naperts number of apertures + 4. zmag zero point of magnitude scale + 5. itime effective integration time +\fR +.fi +.PP +The following quantities can be examined with apstat calls. +.nf +\f(CW + + 1. sums array of aperture sums + 2. areas array of areas + 3. mags array of magnitudes + 4. magerrs array of magnitude errors + +\fR +.fi + +.NH 4 +The PHOT Aperture Integration Algorithm +.PP +The integral of the flux within a circular aperture is computed by +fractional pixel techniques. Pixels are assumed to be square apertures +arranged in a rectangular grid. The fraction of a pixel which lies within +the circular APPHOT aperture is computed by an approximation, and all +such contributions are summed to produce the total integral. +.PP +The inclusion of a partial pixel inside the aperture is done as follows. +.IP 1. +If the distance of the current pixel from the center of the star, r, is +exactly equal to the radius of the aperture R then one-half the counts in +the pixel are included. +.IP 2. +If r < R - 0.5 the entire pixel is included while if r > R + 0.5 the pixel +is wholly excluded. +.IP 3. +In between the fraction of the counts varies linearly. A circular aperture +is approximated by an irregular polygon. +.PP +The simplicity of aperture photometry limits the amount of information +available for error analysis. The following three sources of error are +considered. +.IP 1. +The error due to sky noise in the aperture. +.nf + + $error sub 1 ~=~ sigma sub sky ~*~ {A sub apert} sup {1/2}$ + +.fi +.IP 2. +The error in the aperture sum. +.nf + + $error sub 2 ~=~ ( {A sub "sum" ~/~ phpadu} ) sup {1/2}$ + +.fi +.IP 3. +The mean error of the sky. +.nf + + $error sub 3 ~=~ sigma sub sky ~*~ A sub apert ~/~ nsky sup {1/2}$ + + +.fi +where $sigma sub sky$ is either computed by the background fitting +algorithm or set by the user, +and $A sub apert$ is the fractional pixel area of the +aperture. + +.NH 4 +The WPHOT Algorithm +.PP +The WPHOT algorithm computes a weighted aperture sum in an attempt to +minimize noise in the sky. The algorithm is the following where w is +the weight for each pixel, p is the noise free profile value and +$sigma$ is the noise per pixel from all sources. (See the paper +by Stover and Allen 1987 for details) +.nf + + $A sub sum ~=~ sum {w sub i ~*~ (I sub i ~-~ sky)}$ + + $w sub i ~=~ C ~*~ p sub i ~/~ sigma sup 2 sub i$ + + $C ~=~ sum {p sub j} / sum {p sub j ~*~ w sub j}$ +.fi + +.NH 4 +The POLYPHOT ROUTINES +.PP +The principal polyphot routines are the following. + +.nf +.na +\f(CW + apyinit (ap, sfunction, annulus, dannulus, noise) + ier = apfitcenter (ap, im, wx, wy) + ier = aprefitcenter (ap) + ier = apfitsky (ap, im, xcenter, ycenter, sd, gd) + ier = aprefitsky (ap, sd, gd) + ier = polyfit (ap, im, xver, yver, nver) + value = apstat[ir] (ap, param) + apstats (ap, param, str, maxch) + apset[sir] (ap, param, value) + apfree (ap) + +\fR +.ad +.fi + +.PP +.NH 4 +The POLYPHOT Algorithm +.PP +The function of the POLYPHOT task is to compute the flux inside an +irregular polygon given a list of the coordinates of the vertices of a polygon. +The polygon must be entirely inside the image and the vertices of the polygon +must be specified in clockwise or counterclockwise order. +The actual algorithm used is as follows. +.IP 1. +The range of image lines which intersect the polygon are computed. +.IP 2. +For each image line in the specified range the intersection points with the +polygon are computed. +.IP 3. +The flux between pairs of limits is summed using a fractional pixel +approximation for the endpoints. +.IP 4. +The sky is fitted using any of the methods previously discussed and a +user specified annular region. +.IP 5. +The errors are computed as specified in the PHOT specifications. +.PP +.EQ +delim $$ +.EN + +.NH +Example +.PP +A brief example may help illustrate the use of the package. Suppose +we want to process a few hundred stars on image "blue". +.PP +The first step is to prepare a list of objects to be measured. The simplest +way to do this is to interactively mark the objects with the image +cursor using the display (graphics) device and the RIMCURSOR (RGCURSOR) +task. +.nf +\f(CW + + ... load image on the display ... + + ap> rimcursor > starlist + + ... move cursor and mark stars ... + + + ... load contour plot on graphics terminal ... + + ap> rgcursor > starlist + + ... move cursor and mark stars ... +\fR +.fi + +Alternatively one can run DAOFIND to compute a list of candidate objects +in the frame. +The name of the coordinate file is stored in the PHOT parameter set. + +.nf +\f(CW + ap> phot.coords=starlist +\fR +.fi + +.PP +The next step is to set up the PHOT parameters interactively. +First we load the image (contour plot) blue on the display (graphics +terminal). Next we call up PHOT in interactive mode. + +.nf +\f(CW + ap> phot blue + ... cursor appears ... + +\fR +.fi + +.PP +PHOT takes input by reading the image (graphics) +display (terminal) cursor. In order to display the available commands +we tap the ? key and the following text appears on the screen. + +.nf +\f(CW + Interactive Phot Commands + +? Print options +: Colon command see below +i Setup PHOT parameters interactively +w Write PHOT parameters to the parameter files +l Process the remainder of the coordinate list +r Rewind the coordinate list +c Fit center around the current cursor position +t Fit sky around the current cursor position +s Fit sky around the current center position +p Compute magnitudes around the cursor position +f Fit center, sky and compute magnitudes +sp Fit center, sky, compute magnitudes, and save +q Exit program + +Phot parameters are listed or set with the following commands. + +:m [n] Move cursor to the [nth] object in the coordinate list +:n [n] Measure the [nth] object in the coordinate list + +:show [center/sky/phot/all] List the aphot parameters +:fwhmpsf [value] Full width half maximum of the PSF +:noise [string] Noise model +:threshold [value] Threshold value for centering +:sigma [value] Standard deviation of the background +:ccdread CCD readout noise keyword +:readnoise Readout noise in electrons +:gain Gain keyword +:epadu Electrons per adu + +:calgorithm [string] Centering function +:positive [y/n] Emission or absorption feature +:cbox [value] Width of the centering box in fwhmpsf +:cmaxiter [value] Maximum number of centering iterations +:maxshift [value] Maximum shift in fwhmpf +:minsnratio [value] Minimum signal to noise ratio of pixels +:clean [y/n] Clean subraster before centering +:rclip [value] Clipping radius in fwhmpsf +:rclean [value] Cleaning radius in fwhmpsf +:kclean [value] Sigma for clean algorithm +:mkcenter [y/n] Mark the centers on the display + +:salgorithm [string] Sky fitting algorithm +:annulus [value] Inner radius of sky annulus in fwhmpsf +:dannulus [value] Width of sky annulus in fwhmpsf +:skyvalue [value] User supplied sky +:smaxiter [value] Maximum number of rejection cycles +:skreject [value] +/- Pixel rejection limits in sky sigma +:snreject [value] Maximum number of rejection interations +:khist [value] +/- Sky histogram size in sky sigma +:binsize [value] Resolution of sky histogram in sky sigma +:smooth [y/n] Lucy smooth the sky histogram +:rgrow [value] Region growing radius in fwhmpsf +:marksky [y/n] Mark the sky annuli on the display + +:weighting Weighting for wphot +:aperts [string] Aperture radii in fwhmpsf +:zmag [value] Zero point of magnitude scale +:exposure [string] Exposure time keyword +:itime [value] Integration time +\fR +.fi + +.PP +We select the interactive setup option, move the image +cursor to a high signal-to-noise, isolated star and tap the i key. +PHOT responds by plotting the radial profile of the star on the +screen and requesting the user to mark the fwhm of +the psf, the centering aperture, the inner and outer sky annuli, +the sky background and sigma and the set of circular apertures. +The parameters so set can be examined and/or reset with the : commands as shown +above. Sample measurements can be made of several stars by moving the +cursor and typing the f command. Finally when we are happy with the +parameter set we type w to store the parameters and q to exit the program. +.PP +Now we are ready to do photometry. We enter the PHOT program in batch mode. + +.nf +\f(CW + ap> phot blue inter- & +\fR +.fi + +The batch job is now running, appending output lines to the file "blue.mag.#". +We can proceed to set up the job for the red image, in much the same way +that we set up the job for the blue image. When both jobs finish, we +can use the list processing tools to filter out the good objects and +calculate colors. + +.NH +The APPHOT Tasks +.PP +Manual pages for the APPHOT tasks are available in the IRAF on line help +database. diff --git a/noao/digiphot/apphot/doc/specs/apphot.spc.toc b/noao/digiphot/apphot/doc/specs/apphot.spc.toc new file mode 100644 index 00000000..757f9a79 --- /dev/null +++ b/noao/digiphot/apphot/doc/specs/apphot.spc.toc @@ -0,0 +1,111 @@ +.LP +.sp +1.\h'|0.4i'\fBIntroduction\fP\l'|5.6i.'\0\01 +.sp +2.\h'|0.4i'\fBAPPHOT Package Requirements\fP\l'|5.6i.'\0\01 +.br +\h'|0.4i'2.1.\h'|0.9i'APPHOT Package Input\l'|5.6i.'\0\01 +.br +\h'|0.9i'2.1.1.\h'|1.5i'The IRAF Image\l'|5.6i.'\0\01 +.br +\h'|0.9i'2.1.2.\h'|1.5i'The Coordinate Lists\l'|5.6i.'\0\02 +.br +\h'|0.9i'2.1.3.\h'|1.5i'Algorithm Parameters\l'|5.6i.'\0\02 +.br +\h'|0.9i'2.1.4.\h'|1.5i'Terminal Graphics and the Image Display\l'|5.6i.'\0\02 +.br +\h'|0.4i'2.2.\h'|0.9i'APPHOT Package Functions\l'|5.6i.'\0\03 +.br +\h'|0.9i'2.2.1.\h'|1.5i'Creating Coordinate Lists\l'|5.6i.'\0\03 +.br +\h'|0.9i'2.2.2.\h'|1.5i'Coordinate List Operations\l'|5.6i.'\0\03 +.br +\h'|0.9i'2.2.3.\h'|1.5i'Determining the Image Characteristics\l'|5.6i.'\0\03 +.br +\h'|0.9i'2.2.4.\h'|1.5i'Centering\l'|5.6i.'\0\03 +.br +\h'|0.9i'2.2.5.\h'|1.5i'Fitting the Sky\l'|5.6i.'\0\04 +.br +\h'|0.9i'2.2.6.\h'|1.5i'Multi-aperture Photometry\l'|5.6i.'\0\04 +.br +\h'|0.9i'2.2.7.\h'|1.5i'Polygonal Aperture Photometry\l'|5.6i.'\0\04 +.sp +3.\h'|0.4i'\fBAPPHOT Package Specifications\fP\l'|5.6i.'\0\04 +.br +\h'|0.4i'3.1.\h'|0.9i'Apphot CL Callable Tasks\l'|5.6i.'\0\04 +.br +\h'|0.4i'3.2.\h'|0.9i'Standard Analysis Procedures\l'|5.6i.'\0\05 +.br +\h'|0.4i'3.3.\h'|0.9i'The APPHOT Algorithms\l'|5.6i.'\0\05 +.br +\h'|0.9i'3.3.1.\h'|1.5i'The RADPROF Algorithm\l'|5.6i.'\0\05 +.br +\h'|0.9i'3.3.2.\h'|1.5i'The FITPSF Algorithm\l'|5.6i.'\0\06 +.br +\h'|0.9i'3.3.3.\h'|1.5i'The DAOFIND Algorithm\l'|5.6i.'\0\06 +.br +\h'|0.9i'3.3.4.\h'|1.5i'The CENTER Algorithm\l'|5.6i.'\0\08 +.br +\h'|1.5i'3.3.4.1.\h'|2.2i'Centering Package Routines\l'|5.6i.'\0\08 +.br +\h'|1.5i'3.3.4.2.\h'|2.2i'The General Centering Procedure\l'|5.6i.'\0\09 +.br +\h'|1.5i'3.3.4.3.\h'|2.2i'Symmetry Clean Algorithm\l'|5.6i.'\010 +.br +\h'|1.5i'3.3.4.4.\h'|2.2i'Signal to Noise Estimate\l'|5.6i.'\010 +.br +\h'|1.5i'3.3.4.5.\h'|2.2i'Centroid\l'|5.6i.'\010 +.br +\h'|1.5i'3.3.4.6.\h'|2.2i'Gaussian Fit to the Marginals\l'|5.6i.'\011 +.br +\h'|1.5i'3.3.4.7.\h'|2.2i'Radial Gaussian Fit to the Subraster\l'|5.6i.'\011 +.br +\h'|1.5i'3.3.4.8.\h'|2.2i'Optimal Filtering of Marginals\l'|5.6i.'\011 +.br +\h'|1.5i'3.3.4.9.\h'|2.2i'2D Optimal Filtering\l'|5.6i.'\012 +.br +\h'|1.5i'3.3.4.10.\h'|2.2i'Other Centering Methods\l'|5.6i.'\012 +.br +\h'|0.9i'3.3.5.\h'|1.5i'The FITSKY Task\l'|5.6i.'\013 +.br +\h'|1.5i'3.3.5.1.\h'|2.2i'Sky Fitting Package Routines\l'|5.6i.'\013 +.br +\h'|1.5i'3.3.5.2.\h'|2.2i'General Sky Fitting Procedures\l'|5.6i.'\014 +.br +\h'|1.5i'3.3.5.3.\h'|2.2i'Sky Pixel Array Techniques\l'|5.6i.'\014 +.br +\h'|2.2i'3.3.5.3.1.\h'|2.9i'Mean\l'|5.6i.'\014 +.br +\h'|2.2i'3.3.5.3.2.\h'|2.9i'Median\l'|5.6i.'\014 +.br +\h'|2.2i'3.3.5.3.3.\h'|2.9i'Mode\l'|5.6i.'\015 +.br +\h'|1.5i'3.3.5.4.\h'|2.2i'Histogram Techniques\l'|5.6i.'\015 +.br +\h'|2.2i'3.3.5.4.1.\h'|2.9i'Centroid\l'|5.6i.'\015 +.br +\h'|2.2i'3.3.5.4.2.\h'|2.9i'Gaussian Fit\l'|5.6i.'\016 +.br +\h'|2.2i'3.3.5.4.3.\h'|2.9i'Optimal Filtering\l'|5.6i.'\016 +.br +\h'|2.2i'3.3.5.4.4.\h'|2.9i'Cross Correlation\l'|5.6i.'\016 +.br +\h'|1.5i'3.3.5.5.\h'|2.2i'Interactive Techniques\l'|5.6i.'\016 +.br +\h'|2.2i'3.3.5.5.1.\h'|2.9i'Histogram Plot\l'|5.6i.'\016 +.br +\h'|2.2i'3.3.5.5.2.\h'|2.9i'Radial Distribution\l'|5.6i.'\016 +.br +\h'|1.5i'3.3.5.6.\h'|2.2i'Pixel Rejection and Region Growing\l'|5.6i.'\017 +.br +\h'|0.9i'3.3.6.\h'|1.5i'The APPHOT Task\l'|5.6i.'\017 +.br +\h'|1.5i'3.3.6.1.\h'|2.2i'The APPHOT Package Routines\l'|5.6i.'\017 +.br +\h'|1.5i'3.3.6.2.\h'|2.2i'The APPHOT Aperture Integration Algorithm\l'|5.6i.'\018 +.br +\h'|0.9i'3.3.7.\h'|1.5i'The POLYPHOT Algorithm \l'|5.6i.'\018 +.sp +4.\h'|0.4i'\fBExample\fP\l'|5.6i.'\019 +.sp +5.\h'|0.4i'\fBThe APHOT Tasks\fP\l'|5.6i.'\021 diff --git a/noao/digiphot/apphot/doc/ucache.hlp b/noao/digiphot/apphot/doc/ucache.hlp new file mode 100644 index 00000000..34a091dd --- /dev/null +++ b/noao/digiphot/apphot/doc/ucache.hlp @@ -0,0 +1,15 @@ +If \fIcache\fR is yes and the host machine physical memory and working set size +are large enough, the input image pixels are cached in memory. If cacheing +is enabled and the task is run interactively the first measurement will appear +to take a long time as the entire image must be read in before the measurement +is actually made. All subsequent measurements will be very fast because the task +is accessing memory not disk. The point of cacheing is to speed up random +image access by making the internal image i/o buffers the same size as the +image itself. However if the input object lists are sorted in row order and +sparse cacheing may actually worsen not improve the execution time. Also at +present there is no point in enabling cacheing for images that are less than +or equal to 524288 bytes, i.e. the size of the test image dev$ypix, as the +default image i/o buffer is exactly that size. However if the size of dev$ypix +is doubled by converting it to a real image with the chpixtype task then the +effect of cacheing in interactive is can be quite noticeable if measurements +of objects in the top and bottom halfs of the image are alternated. diff --git a/noao/digiphot/apphot/doc/userdocs/apuser.ms b/noao/digiphot/apphot/doc/userdocs/apuser.ms new file mode 100644 index 00000000..24492bcc --- /dev/null +++ b/noao/digiphot/apphot/doc/userdocs/apuser.ms @@ -0,0 +1,1881 @@ +.RP + +.TL +A User's Guide to the IRAF Apphot Package + +.AU +Lindsey Elspeth Davis +.AI + +.K2 "" "" "*" +Revised May 1989 + +.AB +.PP +The APPHOT package is a set of tasks for performing aperture photometry +on uncrowded or moderately crowded stellar fields in either interactive or batch +mode. The photometric technique employed is fractional pixel +integration. Point spread function fitting techniques are not used and no +knowledge of the point spread function is required for the computation of +magnitudes. Separate tasks are provided for creating and modifying object +lists, computing accurate centers and sky values for a list of objects, +and performing photometry inside concentric +circular or polygonal apertures. +.PP +This document describes the data preparation required to run APPHOT, how +to set up the display and graphics devices, how to set the algorithm +parameters, how to run the package tasks in interactive or batch mode +and how to selectively examine the results. Detailed descriptions of the +algorithms can be found in the document \fISpecifications for the +APPHOT Package\fR by the author. +.PP +This document applies to APPHOT under IRAF version 2.8. APPHOT +can be run under IRAF versions 2.5, 2.6 and 2.7 with only minor changes in +the task setup. These differences are documented +where appropriate in the text. +.AE + +.NH +Introduction +.PP +The APPHOT package is a set of tasks for performing +aperture photometry on uncrowded or moderately crowded fields. +The photometric technique employed is fractional pixel integration. Point +spread function techniques are not used and no knowledge of the point spread +function is required for the computation of magnitudes. +.PP +The APPHOT package performs multi-aperture photometry on digitized starfields +maintained as IRAF image files. Input to the package consists of an +image file(s), an optional list(s) of object coordinates, +numerous parameters controlling +the analysis algorithms and, optionally, the graphics terminal and/or +display. APPHOT output consists of successive records, where each record +records the results of the analysis for a single object. Some tasks +also produce graphics output in the form of plot metacode files. +.PP +Given starting coordinates and an IRAF image, the principal APPHOT +task \fBphot\fR computes accurate centers, sky values and magnitudes +for a list of objects. Separate +IRAF callable tasks in APPHOT exist to create and modify object +lists, to determine image characteristics such as the full width half maximum +of the point spread function or standard deviation of the sky pixels, +to compute accurate centers for a list of objects, to compute accurate local sky +values for a list of objects, and to compute magnitudes inside a polygonal +aperture. +.PP +The image data requirements of the APPHOT package are described in section 2. +Section 3 describes various ways to tailor the IRAF environment to run +the APPHOT package. Section 4 describes how to load the APPHOT tasks and how +use the on-help facility. Section 5 describes how to examine and edit the +APPHOT task and algorithm parameters. Several methods of creating and +modifying APPHOT coordinate lists files are described in section 6. +Sections 7 and 8 describe how to run the APPHOT tasks interactively without +and with a coordinate list respectively. Batch mode reductions in APPHOT are +described in section 9. Section 10 describes the format of the APPHOT output +catalogue and plot files. Section 12 lists various APPHOT recipes for reducing +common types of astronomical data with APPHOT. + +.NH +Data Preparation and Requirements +.PP +APPHOT assumes that the images to be analyzed exist on disk in IRAF readable +format. Facilities for reading and writing images exist elsewhere in IRAF +in the DATAIO and MTLOCAL packages. None of the current APPHOT +tasks alter the disk input images in any way. +.PP +APPHOT assumes that the pixel data is linear. The input images should be +corrected for those instrumental defects which affect the intensity +of a pixel prior to entering the APPHOT package. These defects include pixel +to pixel variations in the bias values, +pixel to pixel gain variations, cosmic rays, cosmetic defects, geometric +distortion and detector non-linearities. Users should be aware of the IRAF +CCDRED package for reducing CCD data and the DTOI package for converting +photographic density data to intensity data. +.PP +Extreme valued pixels should be removed from the images prior to entering +the APPHOT package. These include pixel values at or near the data limits of the +host machine as well as any host machine values such as INDEF, +produced by divide by zero, and floating point underflows and overflows. +Floating point operations involving such numbers may crash +with arithmetic exception errors. For efficiency and portability reasons +the APPHOT package and most IRAF routines do not test for these numbers. +The \fBimreplace\fR and \fBimedit\fP tasks in the PROTO package can be used to replace extreme +valued pixels. More general system facilities for handling bad pixels +inside IRAF are planned for the near future. +.PP +In order to normalize the magnitude scales of a list of images to a common +integration time, +APPHOT requires that the image exposure times be stored in the image header. +Similarly the correct computation of magnitude errors requires that +the readout noise and gain parameters also be present in the image +header or be supplied as constants in the APPHOT parameter files. +The readout noise must be supplied in units of electrons and the gain +is assumed to be in electrons per adu. The time units are arbitrary +but must be consistent for a given set of images. +APPHOT tasks access this information using a keyword and value scheme. +The IMAGES package task \fBhedit\fR can be used to insert or edit this +information prior to entering the APPHOT package. For example the following +commands will enter the gain, readout noise and exposure time information +into the headers of a list of images. + +.nf + \f(CWcl> hedit *.imh gain 14.0 add+ ver- + cl> hedit *.imh readout 20.0 add+ ver- + cl> hedit *.imh exptime add+ ver+\fR +.fi + +.PP +The point spread function is assumed to be constant for all regions +of the image. This is critical in the case of faint objects for +which small apertures which minimize the effects of crowding and sky noise in +the aperture are used. The wings of the object will almost certainly extend +beyond the aperture and good results will only be obtained if objects +are consistently well centered and the shape and diameter of an object is +constant throughout the object and invariant to magnitude. +.PP +The centering routines built into the APPHOT package assume that +the images are close to circularly symmetric over the region to be used +in centering although small deviations do not +significantly affect the accuracy of the results. +The user should be aware of the more sophisticated +but less efficient centering routines in the \fBdaofind\fR and \fBfitpsf\fR +routines. Several choices of centering algorithm are available in +APPHOT including no centering. +.PP +APPHOT assumes that the local sky background is approximately flat in the +vicinity of the object being measured. This assumption is equivalent to +assuming that +the local sky region has a unique mode. Therefore any variations in the +sky background which occur at the same scale as the sky region should be +removed prior to entering the APPHOT package. + +.NH +Setting up the IRAF Environment for APPHOT +.NH 2 +Script, Compiled and Pset Tasks +.PP +IRAF supports three types of tasks: scripts, compiled tasks and pset tasks. +In order to distinguish one type of task from another, APPHOT users should +set the cl parameter \fBshowtype\fR to yes as shown below. + +.nf + \f(CWcl> cl.showtype=yes\fR +.fi + +The cl command \fB?\fR or \fB?\fR \fIpackage\fR identifies script +tasks by a terminating period and pset tasks by a terminating @. +No trailing characters are added to the compiled task names. Pset tasks are +important to the APPHOT package and will be discussed further in +section 5. + +.NH 2 +Other IRAF Packages +.PP +Before running APPHOT, users may wish to load the IRAF packages, DATAIO, +IMAGES, +TV and PLOT. Various input and output routines exist in the DATAIO package, +including the fits reader and writer and the cardimage reader and +writer. The IMAGES package contains routines for basic image arithmetic, +for computing image statistics, for listing individual pixel values, +and for examining and +modifying the image headers. TV, a subpackage of IMAGES, contains the +\fBdisplay\fR task for loading images into the display device. +The PLOT package contains tasks for plotting +image data and for extracting and displaying individual plots from the plot +metacode files produced by the APPHOT tasks. +.PP +Various useful tasks for manipulating and displaying the data produced by +APPHOT can be found in the PROTO package under the NOAO package. In +particular the user should be aware of the \fBfields\fR, \fBmkhistogram\fR +and \fBtvmark\fP tasks. + +.NH 2 +The Image Cursor and Display Device +.PP +The APPHOT tasks are designed in interactive mode to read the image cursor +and to perform various actions based on the position of the image cursor +and the keystroke typed. The image cursor is directed to the display +device defined by the environment variable \fBstdimage\fR. To check the +value of the default display device, type the following command. + +.nf + \f(CWcl> show stdimage + imt512\fR +.fi + +In this example the default display device is the 512 pixel square SUN +imtool window. +All tasks which write images to the display access this +device. For example the +TV package \fBdisplay\fR program will load an image onto this device. +.PP +In normal operation IRAF tasks which read the image cursor would read +the hardware cursor from this device. +In response to the user command + +.nf + \f(CWcl> =imcur + or + cl> show imcur\fR +.fi + +the cursor would come up on the image display ready to accept a +keystroke command. At this point the user should check that the display +is reading the correct image coordinates by moving the image cursor to +the lower left hand corner of the display image and tapping any key. +The coordinates should read x,y = (1,1) if the whole image was +displayed. +.PP +Cursor readback is currently implemented under IRAF version 2.7 for the +SUN workstations and the IIS model 70. Users with older versions of IRAF +or other devices cannot run APPHOT tasks directly from the image display +device and must redirect the image cursor. +Two choices are available. +.IP [1] +The image cursor can be directed to accept commands from +the standard input. This is the default setup under IRAF version 2.6. +This setup can be checked by typing the following command. + +.nf + \f(CWcl> show stdimcur + text\fR +.fi + +If the value of \fBstdimcur\fR is not "text" the user can set this value by +typing the following. + +.nf + \f(CWcl> set stdimcur = text\fR +.fi + +Each time the cursor is to be read the user will be prompted for image +cursor mode text input. The form and syntax of this command are +described in detail in section 7.3. +.IP [2] +Alternatively a contour plot of the image can be used in place of the +image display and APPHOT tasks can be directed to read the graphics cursor. +To direct the image cursor to the graphics device the user types + +.nf + \f(CWcl> set stdimcur = stdgraph\fR +.fi + +This usage permits interactive use of the APPHOT package for users with graphics +terminals but no image display. This setup is most suitable for terminals +which permit the text and graphics planes to be displayed simultaneously. +.RS +.LP +It is currently the responsibility of the user to ensure that the image +displayed on the image display is the same as the image operated on by +the APPHOT tasks. +.RE + +.NH +Loading the Apphot Package +.PP +At this point the user has the local environment set up and is ready to +load the APPHOT package. APPHOT resides in the DIGIPHOT package (IRAF +version 2.8 and later) under the NOAO suite of packages. +Assuming +that the NOAO package is already loaded the user types the following. + +.nf + \f(CWcl> digiphot + cl> apphot\fR +.fi + +APPHOT can also be an add-on package (IRAF version 2.7 and earlier) +installed under the +LOCAL package. In this case the user types. + +.nf + \f(CWcl> local + cl> apphot\fR +.fi + +The following menu of tasks is displayed. + +.nf +\f(CW + apselect daofind fitsky photpars@ polyphot wphot + center datapars@ fitskypars@ polymark qphot + centerpars@ fitpsf phot polypars@ radprof +\fR +.fi + +The APPHOT package is now loaded and ready to run. +A quick one line description of each APPHOT task can be obtained by typing +the following command. + +.nf + \f(CWap> help apphot\fR +.fi + +The following text appears. +.KS +.nf +\f(CW +digiphot.apphot: + apselect - Extract select fields from apphot output files + center - Compute accurate centers for a list of objects + centerpars - Edit the centering parameters + daofind - Find stars in an image using the DAO algorithm + datapars - Edit the data dependent parameters + fitpsf - Model the stellar psf with an analytic function + fitsky - Compute sky values in a list of annular or circular + regions + fitskypars - Edit the sky fitting parameters + phot - Measure magnitudes for a list of stars + photpars - Edit the photometry parameters + polymark - Create polygon and coordinate lists for polyphot + polyphot - Measure magnitudes inside a list of polygonal regions + polypars - Edit the polyphot parameters + qphot - Measure quick magnitudes for a list of stars + radprof - Compute the stellar radial profile of a list of stars + wphot - Measure magnitudes with weighting +\fR +.fi +.KE +For the remainder of this document +we will use the principal APPHOT task \fBphot\fR as an example of how to +setup the parameters in both interactive and batch mode. +To get detailed help on the phot task the user types the following. + +.nf + \f(CWcl> help phot | lprint\fR +.fi + +The help page(s) for the \fBphot\fR task will appear on the local default +printer. + +.NH +Setting the APPHOT Photometry Task Parameters +.PP +The principal APPHOT task PHOT is described in sections 5.1 to 5.6. The +quick photometry task QPHOT is described in section 5.7 and the +polygonal aperture photometry task POLYPHOT is described in section +5.8. +.NH 2 +The Task Parameters +.PP +The \fBphot\fR task parameter set specifies the required image, coordinate +and output files, the graphics and display devices, the graphics and image +cursor and the mode of use of the task, interactive or batch. To enter +and edit the parameter set for the \fBphot\fR task the user types the +following. + +.nf + \f(CWcl> epar phot\fR +.fi + +The parameter set for the \fBphot\fR task will appear on the terminal ready +for editing as follows. + +.nf +\f(CW + IRAF + Image Reduction and Analysis Facility + + PACKAGE = apphot + TASK = phot + + image = Input image + (datapar= ) Data dependent parameters + (centerp= ) Centering parameters + (fitskyp= ) Sky fitting parameters + (photpar= ) Photometry parameters + (coords = ) Coordinate list + skyfile = Sky file + (output = default) Results file + (plotfil= ) File of plot metacode + (graphic= stdgraph) Graphics device + (display= stdimage) Display device + (command= ) Image cursor: [x y wcs] key [cmd] + (cursor = ) Graphics cursor: [x y wcs] key [cmd] + (radplot= no) Plot the radial profiles + (interac= yes) Mode of use + (verify = yes) Verify critical parameters in non + interactive mode + (verbose= no) Print messages in non interactive mode + (mode = ql) +\fR +.fi + +The \fBphot\fR parameters can be edited in the usual fashion by successively +moving +the cursor to the line opposite the parameter name, entering the new value, +followed by a carriage return, and finally typing a ^Z to exit the +\fBepar\fR task and update the parameters. +Some general points about the task +parameter sets are summarized below. For more detailed descriptions of each +parameter see the help pages for each task. +.IP [1] +\fBImage\fR specifies the list of input image(s) containing the +stars to be measured. \fBImage\fR may be a list of images, an image +template or a file containing a list of images. +For example if we wish to measure stars in three images: m31U, m31B and +m31V we could specify the \fBimage\fR parameter in the following three ways. + +.nf +\f(CW + image = m31B,m31U,m31V Input image + or + image = m31*.imh Input image + or + image = @imlist Input image +\fR +.fi + +"Imlist" is the name of a text file containing the list of images +one image name per line. The image list file can easily be created with the cl +package \fBfiles\fR task or the editor. +.IP [2] +Four parameter sets, henceforth psets, \fBdatapars\fR, \fBcenterpars\fR, +\fBfitskypars\fR and \fBphotpars\fR specify the algorithm parameters. +They are described in detail in later sections. +.IP [3] +\fBCoords\fR specifies the name of the coordinate file(s) containing the +initial positions of the stars to be measured. If \fBcoords\fR = "", +the current image cursor position is read and used as the initial position. +The number of files specified by +\fBcoords\fR must be either one, in which +case the same coordinate file is used for all the images, or equal in +number to the set of input images. +\fBCoords\fR can be a list of files, a file name template, +or a file +containing the list of x and y coordinates one per line. +For example if we have three coordinate files "m31B.coo", "m31U.coo" and +"m31V.coo" for the three images listed above, we could set the \fBcoords\fR +parameter in the following three ways. + +.nf +\f(CW + (coords = m31B.coo,m31U.coo,m31V.coo) Coordinate list + or + (coords = m31*.coo) Coordinate list + or + (coords = @coordlist) Coordinate list +\fR +.fi + +"Coordlist" is the name of a text file containing the names of the coordinate +files in the desired order one per line. +.IP [4] +\fBOutput\fR specifies the name of the results file(s). If \fBoutput\fR = +"default" then a single output file is created for +each input image and the root of the output file name is the name of the +input image. In the case of the above example \fBphot\fR would create three +output files called "m31B.mag.1", "m31U.mag.1" and "m31V.mag.1" assuming +that this was the initial run of \fBphot\fR on these images. +If the user sets the \fBoutput\fR parameter then the number of output files +must be either one or equal to the number of input images. For example the +user could set \fBoutput\fR to either + +.nf +\f(CW + (output = m31.out) Results + or + (output = m31b.out,m31u.out,m31v.out) Results +\fR +.fi + +If the user sets \fBoutput\fR = "" then no output file is written. +.IP [5] +The parameters \fBgraphics\fR and \fBdisplay\fR specify the graphics and +image display devices. In IRAF version 2.6 and later the APPHOT tasks +which reference these parameters will in interactive mode issue a warning +if they cannot open either of these devices +and continue execution. In IRAF version 2.5 the \fBdisplay\fR parameter must +be set to "stdgraph" as listed below + +.nf +\f(CW + (display= stdgraph) Display device +\fR +.fi + +or the following system error will be generated. + +.nf +\f(CW + "cannot execute connected subprocess x_stdimage.e" +\fR +.fi +Most of the APPHOT tasks use IRAF graphics in interactive mode to allow +users to set up their parameters and /or examine their results using radial +profile plots. The \fBgraphics\fR specifies which graphics device these plots +will be written to. Similarly most IRAF tasks permit the user to optionally +mark the star positions, apertures and sky annuli on the display device. +The parameter \fBdisplay\fR specifies which image display device this +information will be written to. Currently IRAF does not support an image display +kernel so the display marking features of APPHOT are not available unless +the user chooses to run APPHOT interactively from a contour plot. +.IP [6] +If \fBplotfile\fR is not equal to "", then for each star written to +\fBoutput\fR +a radial profile plot is written to the plot metacode file \fBplotfile\fR. +The \fBplotfile\fR is opened in append mode and succeeding executions +of \fBphot\fR write to the end of the same file which may in the process +become very large. +\fIThe user should be aware that writing radial profile plots +to \fBplotfile\fI can significantly slow the execution of \fBphot\fR. +The variable \fBradplots\fR enables radial profile plotting in interactive mode. +For each star measured a radial profile plot displaying the answers is +plotted on the screen. +.IP [7] +The \fBinteractive\fR parameter switches the task between interactive +and batch mode. +In interactive mode plots and text are written to the terminal as well as the +output file and the user can show and set the parameters. In batch mode +\fBphot\fR executes silently. +.IP [8] +The \fBverify\fP parameter allows the user to verify the critical task +parameters in non interactive mode. It is normally set to yes but +should be turned off when submitting jobs to background. +.IP [9] +The \fBverbose\fP switch permits the printing of results to the standard +output in non interactive mode. It is normally turned off. + +.NH 2 +APPHOT Psets +.PP +APPHOT algorithm parameters have been gathered together into logical +groups and stored in parameter files. The use of psets permits the +user to store APPHOT parameters with their relevant datasets rather than +in the uparm directory and allows APPHOT tasks to share common parameter +sets. APPHOT presently supports 5 pset files: 1) \fBdatapars\fR which contains +the data dependent parameter 2) \fBcenterpars\fR which contains the +centering algorithm parameters 3) \fBfitskypars\fR which contains the +sky fitting +algorithm parameters 4) \fBphotpars\fR which contains the multiaperture +photometry parameters and 5) \fBpolypars\fR which contains the polygonal +aperture +photometry parameters. The user should consult the manual page for each +of the named pset files as well as the attached parameter set document, +\fIExternal Parameter Sets in the CL and Related Revisions\fR, by Doug Tody. +.PP +The default mode of running APPHOT is to edit and store the pset parameter +files in the uparm directory. For example to edit the +\fBdatapars\fR parameter set, the user types either + +.nf + \f(CWcl> epar datapars\fR + or + \f(CWcl> datapars\fR +.fi + +and edits the file as usual. All the top level tasks which reference this +pset will pick up the changes from the uparm directory, assuming +datapars = "". +.PP +Alternatively the user can edit the \fBphot\fR +task and its psets all at once as follows using \fBepar\fR. + +.nf + \f(CWcl> epar phot\fR +.fi + +Move the cursor to the \fBdatapars\fR parameter line and type \fB:e\fR. +The menu for the +\fBdatapars\fR pset will appear and is ready for editing. Edit the desired +parameters and type \fB:q\fR. \fBEpar\fR will return to the main +\fBphot\fR parameter set. +Follow the same procedure for the other three psets +\fBcenterpars\fR, \fBfitskypars\fR and \fBphotpars\fR and exit the program +in the usual manner. +.PP +Sometimes it is desirable to store a given pset along with the data. +This provides a facility for keeping many different copies of say the +\fBdatapars\fR pset with the data. +The example below shows how to write a pset out to a file in the same directory +as the data. The user types + +.nf + \f(CWcl> epar phot\fR +.fi + +as before, enters the datapars menu with \f(CW:e\fR and edits the parameters. +The command + +.nf + \f(CW:w data1.par\fR +.fi + +writes the parameter set to a file called "data1.par" and a \fB:q\fR +returns to the main task menu. +A file called "data1.par" containing the new \fBdatapars\fR parameters +will be written in the current directory. At this point the user is in the +\fBphot\fR parameter set at the line opposite \fBdatapars\fR and +enters "data1.par" on the line opposite this parameter. +The next time \fBphot\fR is run the parameters will +be read from "data1.par" not from the pset in the uparm directory. +This procedure can be repeated for each data set which has distinct parameters, +as in for example data taken on separate nights. + +.NH 2 +Datapars +.PP +All the data dependent parameters have been gathered together in one +pset \fBdatapars\fR. The idea behind this organization is to facilitate +setting up the algorithm +psets for data taken under different conditions. For example the +user may have determined the optimal centering box size, sky annulus radius +and width and aperture radii in terms of the current \fBfwhmpsf\fR and the +rejection criteria in terms of the current background standard deviation +\fBsigma\fR. In order to use the same setup on +the next image the user need only reset the \fBscale\fR and background +\fBsigma\fR parameters to the new values. +The only pset which need be edited is \fBdatapars\fR. +.PP +To examine and edit the \fBdatapars\fR pset type + +.nf + \f(CWap> datapars\fR +.fi + +and the following menu will appear on the screen. + +.nf +\f(CW + IRAF + Image Reduction and Analysis Facility + + PACKAGE = apphot + TASK = datapars + + (fwhmpsf= 1.) FWHM of the PSF in scale units + (emissio= yes) Features are positive + (noise = poisson) Noise model + (thresho= 0.) Detection threshold in counts above + background + (cthresh= 0.) Centering threshold in counts above + background + (sigma = INDEF) Standard deviation of background in counts + (scale = 1.) Image scale in units per pixel + (ccdread= ) CCD readout noise image header keyword + (readnoi= INDEF) CCD readout noise in electrons + (gain = ) CCD gain image header keyword + (epadu = 1.) Gain in electrons per count + (exposur= ) Exposure time image header keyword + (itime = INDEF) Integration time + (datamin= INDEF) Minimum good data pixel + (datamax= INDEF) Maximum good data pixel + (mode = ql) + ($nargs = 0) +\fR +.fi + +.PP +The following is a brief description of the parameters and their function +as well as some initial setup recommendations. + +.PP +\fBScale\fP is the image scale parameter in units per pixel, for example +arc-seconds per pixel. All distance dependent parameters in the APPHOT package +including the centering box width \fBcbox\fP in \fBcenterpars\fP, the +inner radius and width of the sky annulus, \fBannulus\fP and +\fBdannulus\fP in \fBfitskypars\fP, and the radii of the concentric +circular apertures \fBapertures\fP in \fBphotpars\fP are defined +in scale units, for example arc seconds. This permits easy comparison +with apertures published in the literature. Some other algorithm +parameters such as \fBmaxshift\fP in \fBcenterpars\fP and the region +growing radius \fBrgrow\fP in +\fBfitskypars\fP are also defined in scale units. By default all +distance parameters are defined in pixels. +.PP +\fBFwhmpsf\fP is used as a first guess for modelling the psf in the +\fBfitpsf\fP task, is important for the optimal use of the \fBdaofind\fP +algorithm, and critical for the centering algorithms "gauss" and +"ofilter" as well as the \fBwphot\fP task. +\fBFwhmpsf\fR as well as the other distance dependent parameters +can be set interactively from inside most of the APPHOT tasks. +.PP +\fBFwhmpsf\fP and \fBscale\fP can be combined in an interesting way. +\fBScale\fP can be defined in units of half width half maximum of the psf per +pixel in which case the value of \fBfwhmpsf\fP should be set to +\fB2.0\fP by definition. By trial and error and use of the interactive +setup menu optimal values of the remaining distance dependent parameters +can be determined in units of \fBscale\fP. Once determined the same +setup can be reused on another image by simply reseting the \fBscale\fP +parameter. +.PP +APPHOT photometry routines permit measurement of both emission and absorption +features. For the majority of applications including photometry of +stars and galaxies +all "objects" are emission "objects" and the \fBemission\fR parameter should +be left at yes. +.PP +APPHOT currently supports two noise models "constant" and "poisson". +If \fBnoise\fR = "constant" the magnitude errors are computed from the +Poisson noise in the sky background plus the readout noise. +If \fBnoise\fR = "poisson" +the magnitude errors are computed on the basis of the Poisson noise in the +constant sky background, Poisson noise in the object and readout noise. +Most users +with CCD data will wish to leave \fBnoise\fR = "poisson". +\fBCthreshold\fR is a parameter required by the centering algorithms. +If \fBcthreshold\fR > 0.0, pixels below the data minimum plus +threshold in the centering subraster are not used by the centering algorithm. +For difficult centering problems the user may wish to adjust +this parameter. +The \fBsigma\fR parameter specifies the standard deviation of the background +in a single pixel. \fBSigma\fR is used +to estimate the signal to noise ratio in the centering subraster and to set +the width and bin size of the histogram of sky pixels, the \fBkhist\fR and +\fBbinsize\fR parameters in the pset \fBfitskypars\fR. Both \fBcthreshold\fR and +\fBsigma\fR can be set interactively from inside the \fBphot\fR task. +.PP +APPHOT currently recognizes three image header keywords \fBccdread\fR, +\fBgain\fR and \fBexposure\fR. Knowledge of the instrument gain and +readout noise is required for the correct computation of the magnitude +errors but not required for the magnitude computation. The units of +the gain and readout noise are assumed to be electrons per adu +and electrons respectively. +Exposure time information is required to normalize the magnitudes computed +for a series of images to a common exposure time. +The time units are arbitrary but must be consistent for a set of images. +If this information is already in the +image header the user can enter the appropriate header keywords. +Otherwise the instrument constants gain and readout noise can be entered +into the parameters \fBepadu\fR and \fBreadnoise\fR. +If the exposure time information is not present in the image header, the +user can either edit it in with the \fBhedit\fR task or change the \fBitime\fR +parameter for each image reduced. If both image header keywords and +default parameter values are defined the image header keywords take +precedence. +.PP +The two parameters \fBdatamin\fP and \fBdatamax\fP which define the upper +and lower good data limits respectively are not currently implemented by +the APPHOT tasks. They will be used in future versions of the package +to, for example, set the limits over which a detector is linear. +.PP +After editing, the new \fBdatapars\fR pset might look like the following. +This user has chosen to wait and set \fBfwhmpsf\fR, \fBthreshold\fR, +\fBcthreshold\fR, and \fBsigma\fR interactively from inside \fBphot\fR but +has decided to set the +image header parameters \fBccdread\fR, \fBgain\fR and \fBexposure\fR. + +.nf +\f(CW + IRAF + Image Reduction and Analysis Facility + + PACKAGE = apphot + TASK = datapars + + (fwhmpsf= 1.) FWHM of the PSF in scale units + (emissio= yes) Features are positive + (noise = poisson) Noise model + (thresho= 0.) Detection threshold in counts above + background + (cthresh= 0.) Centering threshold in counts above + background + (sigma = INDEF) Standard deviation of background in counts + (scale = 1.) Image scale in units per pixel + (ccdread= readout) CCD readout noise image header keyword + (readnoi= INDEF) CCD readout noise in electrons + (gain = gain) CCD gain image header keyword + (epadu = 1.) Gain in electrons per count + (exposur= exptime) Exposure time image header keyword + (itime = INDEF) Integration time + (datamin= INDEF) Minimum good data pixel + (datamax= INDEF) Maximum good data pixel + (mode = ql) + ($nargs = 0) +\fR +.fi + +.NH 2 +The Centering Parameters +.PP +The centering algorithm parameters have been grouped together in a single +parameter set \fBcenterpars\fR. To display and edit these parameters type +the command. + +.nf + \f(CWap> centerpars\fR +.fi + +The following menu will appear on the terminal. + +.nf +\f(CW + IRAF + Image Reduction and Analysis Facility + + PACKAGE = apphot + TASK = centerpars + + (calgori= centroid) Centering algorithm + (cbox = 5.) Centering box width in scale units + (maxshif= 1.) Maximum center shift in scale units + (minsnra= 1.) Minimum SNR ratio for centering + (cmaxite= 10) Maximum iterations for centering algorithm + (clean = no) Symmetry clean before centering + (rclean = 1.) Cleaning radius in scale units + (rclip = 2.) Clipping radius in scale units + (kclean = 3.) K-sigma rejection criterion in skysigma + (mkcente= no) Mark the computed center + (mode = ql) + ($nargs = 0) +\fR +.fi + +.PP +APPHOT offers three choices for the centering algorithm: +the default "centroid", "gauss" and "ofilter". +The default centering algorithm does not depend on \fBfwhmpsf\fR but the +remaining two do. For reasons of simplicity and efficiency the author +recommends the default algorithm. In cases where there is significant +crowding or the data is very noisy users may wish to experiment with +the other algorithms. Centering can be disabled by setting +\fBcalgorithm\fR = "none". This option is useful if accurate centers +have already been computed with the \fBdaofind\fR or \fBfitpsf\fR +tasks. More detailed information on the APPHOT centering algorithms +can be found in the document, \fISpecifications for the Apphot Package\fR +by Lindsey Davis. +.PP +The centering box \fBcbox\fR is defined in units of \fBscale\fR. +Users should try to set \fBcbox\fR as small as possible to avoid +adding noisy pixels to the centering subraster. +\fBCbox\fR can also be set interactively from inside the APPHOT \fBphot\fR +task. +.PP +If the computed centers are more than \fBmaxshift\fR / \fBscale\fR pixels +from the initial centers or the signal-to-noise ratio in the centering +subraster is less than \fBminsnratio\fR the new center will be computed but +flagged with a warning message. +.PP +For stars which are crowded or contaminated by bad pixels the user may +wish to enable the cleaning algorithm by setting \fBclean\fR = yes. +Its use is complicated and not recommended for most data. The algorithm is +described in the APPHOT specifications document. +.PP +If \fBmkcenter\fR=yes, \fBphot\fR tasks will mark the initial +and final centers and draw a line between them on the default display +device. At present this option only works if \fBdisplay\fR="stdgraph". +.PP +In the above example we have elected to leave the \fBcalgorithm\fR parameter +at its default value and set \fBcbox\fR interactively from inside the \fBphot\fR +task. + + +.NH 2 +The Sky Fitting Parameters +.PP +The sky fitting algorithm parameters have been grouped together in a single +parameter set \fBfitskypars\fR. To display and edit these parameters type +the following command. + +.nf + \f(CWap> fitskypars\fR +.fi + +The following menu will appear on the terminal. + +.nf +\f(CW + IRAF + Image Reduction and Analysis Facility + + PACKAGE = apphot + TASK = fitskypars + + (salgori= mode) Sky fitting algorithm + (annulus= 10.) Inner radius of sky annulus in scale units + (dannulu= 10.) Width of sky annulus in scale units + (skyvalu= 0.) User sky value + (smaxite= 10) Maximum number of sky fitting iterations + (snrejec= 50) Maximum number of sky fitting rejection + iterations + (skrejec= 3.) K-sigma rejection limit in sky sigma + (khist = 3.) Half width of histogram in sky sigma + (binsize= 0.1) Binsize of histogram in sky sigma + (smooth = no) Lucy smooth the histogram + (rgrow = 0.) Region growing radius in scale units + (mksky = no) Mark sky annuli on the display + (mode = ql) + ($nargs = 0) +\fR +.fi + +.PP +APPHOT offers ten sky fitting algorithms. The algorithms can be grouped +into 4 categories 1) user supplied sky values including "constant" and "file" +2) sky pixel distribution algorithms including "median" and "mode", +3) sky pixel histogram algorithms including "centroid", "crosscor", +"gauss" and "ofilter" 4) interactive algorithms including "radplot" +and "histplot". +The definitions of the mode used by APPHOT is the following. + +.nf +\f(CW mode = 3.0 * median - 2.0 * mean\fP +.fi + +Detailed descriptions of the algorithms can be found in the document, +\fISpecifications for the Apphot Package\fR by the author. The author recommends +"mode" the default, and one of the two histogram algorithms "centroid" and +"crosscor". +.PP +The inner radius and width of the sky annulus in terms of \fBscale\fR +are set by the parameters \fBannulus\fR and \fBdannulus\fR. These can +easily be set interactively from within the \fBphot\fR task. +Good statistics require several hundred sky pixels. +The user should be aware that a circular sky region can be defined by +setting \fBannulus\fR to 0. +.PP +The user should ensure that the parameter \fBsigma\fR in the +\fBdatapars\fR parameter set is defined if one of the histogram dependent +sky fitting algorithms is selected. +The extent and resolution of the sky pixel histogram is determined +by \fBkhist\fR and \fBbinsize\fR and their relation to \fBsigma\fR. +If \fBsigma\fR is undefined then the standard deviation of the local +sky background is used to parameterise \fBkhist\fR and \fBbinsize\fR +and the histograms of different stars can deviate widely in resolution. +.PP +The sky rejection algorithms are controlled by the parameters \fBskreject\fR, +\fBsnreject\fR and \fBrgrow\fR. It is strongly recommended that the user +leave pixel rejection enabled. The user should experiment with the region +growing radius if the local sky regions are severely crowded. +.PP +If \fBmksky\fR = yes, \fBphot\fR will mark the inner +and outer sky annuli. At present this option +will only work if \fBdisplay\fR = "stdgraph". + +.NH 2 +The Photometry Parameters +.PP +The photometry algorithm parameters have been grouped together in a single +parameter set \fBphotpars\fR. To display and edit these parameters type. + +.nf + \f(CWap> photpars\fR +.fi + +The following menu will appear on the terminal. + +.nf +\f(CW + IRAF + Image Reduction and Analysis Facility + + PACKAGE = apphot + TASK = photpars + + (weighti= constant) Photometric weighting scheme for wphot + (apertur= 3.) List of aperture radii in scale units + (zmag = 26.) Zero point of magnitude scale + (mkapert= no) Draw apertures on the display + (mode = ql) + ($nargs = 0) +\fR +.fi + +.PP +There are three weighting options inside APPHOT. The default is "constant". +Inside the \fBphot\fR, \fBradprof\fR and \fBpolyphot\fR tasks only constant +weighting is used. Two other weighting schemes are available for the +experimental \fBwphot\fR task, "gauss" and "cone". "Gauss" is the more +highly recommended. +.PP +The aperture list is specified by \fBapert\fR in terms of \fBscale\fR. +The apertures can be entered in any order but are sorted on output. +\fBApert\fR can be string or the name of a text file containing the +list of apertures. Apertures can either be listed individually and +separated by whitespace or commas or a ranges notation of the +form apstart:apend:apstep can be used. +These can be set interactively from within the \fBphot\fR task. +.PP +Examples of valid aperture strings are listed below. + +.nf +\f(CW + 1 2 3 + 1.0,2.0,3.0 + 1:10:1 +\fR +.fi + +.PP +An arbitrary zero point is applied to the magnitude scale with \fBzmag\fR. +The user can accept the default or experiment with his/her data until +a suitable value is found. The computation of the magnitude errors +does not depend on the zero point. +.PP +If \fBmkapert\fR = yes, the \fBphot\fR task will draw the concentric +apertures on the display. At present this option +works only if \fBdisplay\fR = "stdgraph". + +.NH 2 +The QPHOT Task +.PP +\fBQphot\fP computes accurate centers, sky values and magnitudes for a list +of objects using a restricted subset of the full \fBphot\fP parameter set. +It is intended to be a quick look photometer suitable for use when +observing on the mountain or in well behaved uncrowded stellar fields. +.PP +The user is automatically queried for the critical parameters \fBcbox\fP, +\fBannulus\fP, \fBdannulus\fP and \fBapertures\fP which are defined in +terms of pixels. The noise characteristics of the detector are assumed +to obey Poisson statistics. \fBQphot\fP computes centers for each +object using the "centroid" centering algorithm. Sky values are +calculated using the "mode" algorithm. The user can set the zero point +of the magnitude scale, \fBzmag\fP, the gain of the detector, \fBepadu\fP, +and exposure time image header keyword, \fBexposure\fP, but all the +remaining parameters are set to their default values. +.PP +\fBQphot\fP can be driven by the image cursor or a coordinate list in +interactive mode or by a coordinate list in batch mode in exactly +the same manner as the \fBphot\fP task. + +.NH 2 +The \fBPOLYPHOT\fP Task +.PP +\fBPolyphot\fP computes accurate centers, sky values and magnitudes for +a list of objects using polygonal shaped apertures. It is most suitable +for measuring the magnitudes of large extended irregularly shaped objects. +.PP +\fBPolyphot\fP uses \fBdatapars\fP, \fBcenterpars\fP, and +\fBfitskypars\fP in exactly the same manner as the \fBphot\fP task. In +general users should set the task parameters in the same way as they +set them in \fBphot\fP. However users who have defined their polygonal +apertures interactively may wish to set the centering algorithm +parameter \fBcalgorithm =\fP "none", to avoid the task trying to center +on the brightest feature in the aperture. +.PP +The apertures are defined either interactively with the image or graphics +cursor or by two files \fBpolygons\fP and \fBcoords\fP. +Polygons defines the shape of the polygonal aperture and coords defines the +initial positions of the apertures. The polygons file may contain +more than one aperture and the flux through each aperture may be measured +at more than one position. A detailed description of the file formats +is given in section 6.4 + +.NH +Creating A Coordinate List +.PP +All APPHOT tasks operate on either lists of object coordinates or +interactive cursor +input. Lists are maintained as text files, one object per line with the x +and y coordinates in columns one and two respectively. The coordinate and +polygon files required by the \fBpolyphot\fR task have a different +format which is described below. List files may be +created interactively with either the graphics or the image cursor, by a +previously executed APPHOT task, by a previously executed IRAF task or by +a user program. Various means of creating coordinate lists within IRAF +are described below. Comments preceded by a # character and blank lines +are ignored. + +.nf +\f(CW + #Sample Coordinate List + 53.6 83.25 + 100.0 35.8 + 2.134 86.89 + .... .... +\fR +.fi + +.NH 2 +Daofind +.PP +\fBDaofind\fR is an APPHOT task which detects stellar objects in an image +automatically. The user sets the \fBfwhmpsf\fR of the psf for which the +detection algorithm is to be +optimized as well as an intensity threshold for detection. \fBDaofind\fR +locates all the qualifying stars and writes their positions, rough magnitudes +and shape characteristics to a file. This file can then be assigned to +the \fBphot\fR task \fBcoords\fR parameter and read directly. +.PP +For example if we have an image containing stars for which the \fBfwhmpsf\fR +is 4.0 pixels and the sigma of the sky background is 10 we might run +\fBdaofind\fR as follows, + +.nf + \f(CWcl> daofind image fwhmpsf=4.0 threshold=30.0\fR +.fi + +where we have set our detection threshold at 3.0 * sigma. + +.NH 2 +Imtool On the SUN Machines +.PP +The SUN IRAF \fBimtool\fR facility supports both image world coordinate +systems and output coordinate files. Coordinate lists can be created +interactively by the users in the following way. +.PP +Display the IRAF image in the imtool window using the \fBdisplay\fR task. +Move the mouse to the top of the \fBimtool\fR window, press the right mouse +button to enter the \fBimtool\fR menu, move the mouse to the setup option and +release the mouse button. Press +the return key until the black triangle is opposite the coordinate list file +name parameter. +Delete the default file name, enter the full host system path name of the +desired coordinate file and press return. This name should now appear at +the top of the imtool window. +Move the mouse to the quit option and press the left mouse button to +quit the setup window. +.PP +To enter the \fBimtool\fR cursor readout mode type the \fBF6\fR key. +The x, y and intensity values at the cursor position +are displayed in the lower right corner of the image. +To mark stars and output their coordinates to the coordinate file, move +the image cursor a star and press the left mouse button. A sequence number +will appear on the display next to the marked position. The numbers can +be changed from black to white and vice versa by toggling the \fBF5\fR key. +The coordinate files are opened in append mode in order that stars may be +added to an already existing list. \fBImtool\fR coordinate files are directly +readable by all APPHOT tasks. + +.NH 2 +Rgcursor and Rimcursor +.PP +The LISTS package tasks \fBrgcursor\fR and \fBrimcursor\fR can be used to +generate coordinate lists interactively. For example a coordinate +list can be created interactively using the display cursor and +the image display. + +.nf +\f(CW + cl> display image + + ... image appears on the display ... + + cl> rimcursor > image.coo + + ... move display cursor to stars of interest and tape space bar ... + + ... type ^Z to terminate the list ... +\fR +.fi + +Similarly a coordinate list +can be created using the graphics cursor and a contour +plot as shown below. + +.nf +\f(CW + cl> contour image + + ... contour plot appears on the terminal ... + + cl> rgcursor > image.coo + + ... move cursor to stars of interest and tap space bar ... + + ... type ^Z to terminate the list ... +\fR +.fi + +The text file "image.coo" contains the x and y coordinates of the marked stars +in image pixel units. The output of \fBrimcursor\fR or \fBrgcursor\fR can +be read directly by the APPHOT \fBphot\fR task. +\fBRimcursor\fR is only available in IRAF versions 2.7 and later and +only for selected devices. + +.NH 2 +The Polygon List +.PP +A utility routine \fBpolymark\fR has been added to the APPHOT package to +generate polygon and initial center lists for the \fBpolyphot\fR task. +The format of the polygon files is 1 vertex per line with the +x and y coordinates of the vertex in columns 1 and 2 respectively. +A line containing the single character ';' terminates the lists of vertices. +There can be more than one polygon in a single polygon file. + +.nf +\f(CW + Sample Polygon File + + 1.0 1.0 + 1.0 51.0 + 51.0 51.0 + 51.0 1.0 + ; + 80.0 80.0 + 80.0 131.0 + 131.0 131.0 + 131.0 80.0 + ; +\fR +.fi + +.PP +The accompanying coordinate file is optional. If no coordinate file is given +the initial center for the polygon is the mean of its vertices in the +polygon file. If a +coordinate file is specified the initial center for the polygon is the +position in the coordinate file. Each polygonal aperture may be moved +to several positions. + +.nf +\f(CW + Sample Polyphot Coords File + + 50. 30. + 80. 100. + 60. 33. + ; + 90. 50. + 55. 90. + 12. 122. + ; +\fR +.fi + +For example all the coordinates in group 1 will be measured using the +aperture defined by polygon 1 and all the coordinates +in group 2 will be measured with the aperture defined by polygon 2. + +.NH 2 +User Program +.PP +Obviously any user program which produces a text file with the coordinates +listed 1 per line with x and y in columns 1 and 2 can be used to produce +APPHOT coordinate files. + +.NH 2 +Modifying an Existing Coordinate List +.PP +The LISTS package routine \fBlintran\fR has been linked into the APPHOT +package. It can be used to perform simple coordinate transformations on +coordinate lists including shifts, magnifications, and rotations. + +.NH +Running Apphot in Interactive Mode Without a Coordinate List +.PP +There are currently three ways to run the \fBphot\fR interactively without +a coordinate list: +1) read image display cursor commands 2) read +graphics cursor commands 3) read commands +from the standard input. The three methods are briefly discussed below. +Detailed examples of all three methods of operation can be found in +the manual pages for each task. + +.NH 2 +Reading Image Cursor Commands +.PP +The default method of running APPHOT. The user loads an image onto +the display, types \fBphot\fR and enters the image name. The image cursor +appears on the display and the program is ready to accept user commands. +This option is not available under IRAF version 2.6 and earlier +because interactive image cursor readback was not available. + +.NH 2 +Redirecting the Image Cursor to the Graphics Cursor +.PP +\fBPhot\fR reads the graphics cursor and executes various keystroke +commands. The environment variable \fBstdimcur\fR must be set to "stdgraph". +For full access +to all the graphics commands the parameter \fBdisplay\fR must also be set +to "stdgraph". +The user creates a contour plot of the image on the graphics terminal +with the \fBcontour\fR task, types \fBphot\fR and answers the image name query. +The graphics cursor appears on the contour plot ready for input. +The user can move around the plot with the cursor successively marking stars. + +.NH 2 +Redirecting the Image Cursor to the Standard Input +.PP +The user can enter cursor commands directly on the standard input. +The environment variable \fBstdimcur\fR must be set to "text". +When the user types the task name \fBphot\fR and enters the image +name, the following prompt appears. + +.nf + \f(CWImage cursor [xcoord ycoord wcs] key [cmd]:\fR +.fi + +\fIXcoord\fR and \fIycoord\fR are the coordinates of the object of +interest, \fIwcs\fR is the current world coordinate system, always 1, +\fIkey\fR is a single +character and \fIcmd\fR is an APPHOT task command. +To perform the default action of +the \fBphot\fR task the user responds as follows. + +.nf + \f(CWImage cursor [xcoord ycoord wcs] key [cmd]: 36. 42. 1\fR +.fi + +\fBPhot\fR measures the magnitude of the star near pixel coordinates +x,y = (36.,42.) and writes the result to the output file. +In IRAF version 2.5 all the cursor command fields must be typed. +The square brackets +indicate those fields which are optional under IRAF version 2.6 and later. +Users with SUN +workstations may wish to combine the IMTOOL coordinate list cursor readback +facilities which generate coordinate lists with this mode of running APPHOT +interactively. + +.NH 2 +The Interactive Keystroke Commands +.PP +A conscious effort has been made to keep the definitions of all the +keystroke commands within the APPHOT package as similar as possible. +The following are the most commonly used keystrokes in the APPHOT package. + +.NH 3 +The ? (Help) Keystroke Command +.PP +The ? key prints the help page describing the cursor keystroke and colon +show commands for the specific APPHOT task. An abbreviated help page +is typed by default when a user enters a task in interactive mode. +The ? key can be typed at any point in the APPHOT task. + +.NH 3 +The :show (Set and Print parameter) Commands +.PP +Any APPHOT parameter can be displayed by typing :\fIparameter\fR command +in interactive mode. +For example to show the current value of the \fBfwhmpsf\fR parameter +type the following command. + +.nf + \f(CW:fwhmpsf\fR +.fi + +To set any APPHOT parameter type :\fIparameter\fR "value". For example +to set the \fBfwhmpsf\fR to 2.0 type. + +.nf + \f(CW:fwhmpsf 2.0\fR +.fi + +To display all the centering parameters type. + +.nf + \f(CW:show center\fR +.fi + +Similarly the sky fitting and photometry parameters can be displayed by +typing. + +.nf + \f(CW:show sky\fR + \f(CW:show phot\fR +.fi + +All the parameters can be displayed with the following command. + +.nf + \f(CW:show\fR +.fi + +.NH 3 +The i (Interactive Setup) Keystroke Command +.PP +This extremely useful key allows one to set up the principal APPHOT +parameters interactively. To use this feature move the image cursor to a star on +the display, or move the graphics cursor to a star on the contour plot +and tap the i key, +or enter the x and y coordinates, and the world coordinate system +of the star and the i key manually. The program will query the user for +the size of the extraction box and plot a radial profile of the star +on the terminal. The user sets the \fBfwhmpsf\fR, the centering +aperture \fBcbox\fR, the inner sky annulus \fBannulus\fR and \fBdannulus\fR, +the list of apertures \fBaperts\fR and the data \fBsigma\fR, +\fBthreshold\fR and \fBcthreshold\fR using the graphics cursor and the +radial profile plot. +The cursor comes up on the plot at the position of the appropriate parameter. +Typing return will preserve the old value. +If the cursor is outside the range of values on the plot the old value +is kept. +.PP +Setting \fBsigma\fP, \fBcthreshold\fP, and \fBthreshold\fP +interactively requires two keystrokes. In each case the measured parameter +is the difference between the two y coordinates of the graphics +cursor. It is recommended in general that the user leave \fBcthreshold\fP +at zero. + +.NH 3 +The v (Verify) Keystroke Command +.PP +The v key verifies that the values of the critical task parameters +currently in memory are the ones that the user wants. To each verify query +the user either types CR to verify the current value or enters a new +value. + +.NH 3 +The w (Write to Psets) Keystroke Command +.PP +The w key writes the current values of the parameters in memory to the +appropriate psets. +This feature is useful for saving values marked with the +i key. On exiting APPHOT a prompt will remind the user that the current +parameters in memory must be stored in the psets or lost. + +.NH 3 +The d (Radial Profile Plot) Keystroke Command +.PP +The d key plots a centered radial profile of a star on the graphics device. + +.NH 3 +The f (Fit) Keystroke Command +.PP +This key performs the default action of each APPHOT task without writing +any results +to the output file. In the \fBphot\fR task the f key will center, fit the +local sky and compute the magnitudes for a star. This key allows the user to +experiment interactively with the data, changing the default parameters, +remeasuring magnitudes and so on before actually writing out any data. + +.NH 3 +The Space Bar (Fit and Write out Results) Keystroke Command +.PP +This key performs the default action of the task and writes the results +to the output catalog. + +.NH +Running Apphot In Interactive Mode From A Coordinate List +.PP +This is currently the best method for running APPHOT interactively for users +without image cursor readback facilities. APPHOT tasks +can pick stars out of the list sequentially or by number, measure stars +sequentially or by number, rewind the coordinate lists and remeasure all +the stars. Stars which are not in the coordinate list can still be +measured and added to the output catalog. + +.IP [1] +The :m (Move) Keystroke Command +.RS +.LP +This command moves the cursor to the next or a specified star in the +coordinate list. If the hardware cursor on the +device being read from is enabled the actual physical cursor will move +to the requested star. For +example a user might decide that star # 10 in the coordinate list is the best +setup star. He/she simply types a :m 10 to move to the star in +question followed by the i key to setup the parameters interactively. +.RE + +.IP [2] +The :n (Next) Keystroke Command +.RS +.LP +This command moves to the next or specified star in the list, performs the +default action of the task and writes the results to the output file. +This key is particularly useful in examining the results of a large batch +run. +For example, a user measures the magnitudes of 500 stars using APPHOT in +batch mode. He/she is suspicious about the results for twenty of the most +crowded stars. By rerunning APPHOT in interactive mode using the original +coordinate list, the user can selectively call up the stars in question, +plot their radial profiles, and examine the results interactively. +.RE + +.IP [3] +The l (List) Keystroke Command +.RS +.LP +This command measures all the stars in the coordinate list sequentially from +the current position in the file. +.RE + +.IP [4] +The r (Rewind) Keystroke Command +.RS +.LP +This command rewinds the coordinate list. +.RE + +.NH +Running Apphot in Batch Mode +.PP +This is the simplest way to run APPHOT. Once the parameters are set and stored +in the pset files the program can be run in batch by setting the parameter +\fBinteractive\fR = no. The program will read the coordinate list +sequentially computing results for each star and writing them to the +output file. + +.NH +Apphot Output +.PP +APPHOT tasks write their output to text and/or plot files as well as to the +standard output and graphics terminals. + +.NH 2 +Text Files +.PP +All APPHOT records are written to text files. +The parameters for the task are listed at the beginning of each APPHOT +output text file and identified with a #K string. +The header record is not written until the record +for the first star is to be written to the database. Parameter changes will +generate a one line entry in the output text file. +The data records follow the header record in the order in which they +were computed. +If the output file parameter \fBoutput\fR = "" no output file is written. +This is the default action for the \fBradprof\fR task. +If \fBoutput\fR = "default", +the output file name is constructed using the image name. + +.NH 2 +Plot Files +.PP +Some APPHOT tasks can optionally produce graphics output. +These files are maintained as plot metacode and may contain many individual +plots. +A directory of plots in each metacode file can be obtained with +\fBgkidir\fR. Individual plots can be extracted with \fBgkiextract\fR and +combined and plotted with \fBgkimosaic\fR. + +.NH 2 +Running Apselect on Apphot Output Files +.PP +Individual fields can be extracted from the APPHOT output files using +the \fBapselect\fR task and a keyword and expression scheme. +For example the user may wish +to extract the x and y center coordinates, the sky value and the +magnitudes from the APPHOT \fBphot\fR catalog. Using apselect they +would type. + +.nf + \f(CWcl> apselect output xc,yc,msky,mag yes > magsfile\fR +.fi + +The selected fields would appear in the textfile "magsfile". + +.NH +Apphot Recipes +.PP +In the following section three APPHOT reduction sessions which illustrate +different methods of using the APPHOT package are described. In the +first example the user wishes to compute magnitudes for a large number +of stars in a single image. In the second example he/she wishes to +measure the magnitude of a single standard star in each of a long list of +images. Finally in the last example the user wishes to measure the +magnitude of an elliptical galaxy through a list of apertures. +Each example assumes that the user has started with the default set of +package parameters. + +.NH 2 +Infrared photometry of a Star Field in Orion +.PP +An observer has an IRAF image on disk of a star forming region in Orion taken +with the +IR CCD camera. The Orion image is a composite formed from 64 separate +IR images using the PROTO \fBirmosaic\fR and \fBiralign\fR tasks. +The Orion image contains about 400 stars but is only moderately crowded. The +observer decides to use the APPHOT package to reduce his data. +.PP +The observer decides to run the \fBdaofind\fR routines to create a coordinate +list of stars, to run \fBphot\fR in interactive mode with the image cursor +directed to the standard input to setup and store the \fBphot\fR task +parameters and finally, to run \fBphot\fR in batch mode to do the photometry. +.PP +To create the coordinate list the user needs to supply the full width half +maximum of the pointspread function and an intensity threshold +above background to the +\fBdaofind\fR program. Using the PLOT package task \fBimplot\fR the user +examines several stars in the image and decides that the \fBfwhmpsf\fR +should be 3.0 +pixels and that the standard deviation of the background should be 10.0 +counts. +The user decides to include all stars with a peak intensity greater +than five standard deviations above local background in the coordinate list. +The user runs \fBdaofind\fR as follows. + +.nf + \f(CWap> daofind orion fwhmpsf=3.0 threshold=50.0\fR +.fi + +The x and y coordinates, a magnitude estimate and some statistics on image +sharpness and roundness are output to the file "orion.coo.1". +The user can obtain a printout of the coordinate +list by typing. + +.nf + \f(CWap> lprint orion.coo.1\fR +.fi + +.PP +Next the user decides to set up the parameters of the \fBphot\fR task. +Using the \fBepar\fR task he enters the phot task parameter menu, +types "orion" opposite the \fBimage\fR parameter and "orion.coo.1" +opposite the \fBcoords\fR parameter. Next he moves the cursor opposite +the \fBdatapars\fR parameter and types \fB:e\fR to enter the \fBdatapars\fR +menu. He sets the gain parameter \fBepadu\fR to 5.0 electrons per adu +and the readout noise \fBreadnoise\fR to 5.0 electrons. He types \fB:q\fR to +quit and save the \fBdatapars\fR parameters and \fB^Z\fR to quit and save the +\fBphot\fR parameters. +.PP +Now the user is ready to enter the \fBphot\fR task in interactive mode to set +up the remaining data dependent parameters. The user types the following +sequence of commands in response to the cursor prompt. Note that the +example below assumes that the image cursor has been directed to the +standard input. The image cursor comes up on the screen in the form of +a prompt. This example could equally well be run from the image hardware +cursor in which case the cursor would appear on the displayed image. The +keystroke commands are identical in the two cases. + +.br + +.nf +\f(CW + ap> phot orion + + ... \fIload the phot task\fR ... + + Image cursor [xcoord ycoord wcs] key [cmd]: ? + + ... \fIprint help page for phot task\fR ... + + Image cursor [xcoord ycoord wcs] key [cmd]: :radplots yes + + ... \fIenable radial profile plotting\fR ... + + Image cursor [xcoord ycoord wcs] key [cmd]: :m 10 + + ... \fImove to star 10 in the coordinate list\fR ... + + Image cursor [xcoord ycoord wcs] key [cmd]: i + + ... \fIenter interactive setup mode using star 10\fR ... + + ... \fImark fwhmpsf, cbox, sky annulus, apertures on the plot\fR ... + + ... \fIleave sigma and cthreshold at their default values\fR ... + + ... \fIcheck answers on radial profile plot of the results\fR ... + + Image cursor [xcoord ycoord wcs] key [cmd]: v + + ... \fIverify the critical parameters\fR ... + + Image cursor [xcoord ycoord wcs] key [cmd]: :radplots no + + ... \fIdisable radial profile plotting\fR ... + + Image cursor [xcoord ycoord wcs] key [cmd]: w + + ... \fIstore new parameters in the psets\fR ... + + Image cursor [xcoord ycoord wcs] key [cmd]: q + + ... \fIquit interactive cursor loop\fR ... + + q + + ... \fIquit the phot task\fR ... + +\fR +.fi +.PP +The user decides he is happy with the current parameter set and decides +to run the \fBphot\fR task in batch and submit it as a background task. + +.nf + \f(CWap> phot orion inter- verify- &\fR +.fi + +The results will appear in the text file "orion.mag.1". + +.NH 2 +Landolt Standards +.PP +The user has 100 UBVRI images of 20 Landolt Standards +taken on a single night. These frames have been taken at various short +exposures. +The user wishes to process all this data +in batch mode with the output records going to a single file. +.PP +The observer decides to run the \fBdaofind\fR task to create a coordinate +list for each image, to run \fBphot\fR on a representative image +in interactive mode with the image cursor +directed to the standard input to set up and store the \fBphot\fR task +parameters, and finally to run \fBphot\fR in batch mode on all the images +to do the photometry. +.PP +Note that the example below assumes that the image cursor has been redirected +to the standard input. The image cursor comes up on the screen in the +form of a prompt. This example could equally well be run from the image +hardware cursor in which case the cursor would appear on the displayed +image. The keystroke commands are identical in the two cases. +.PP +To create the coordinate list the user needs to supply the full width half +maximum of the point spread function and an intensity threshold above +local background to the +\fBdaofind\fR task. Using the PLOT package task \fBimplot\fR the user +examines the Landolt standards in several images and decides that the +average \fBfwhmpsf\fR is 4.3 +pixels and that the standard deviation of the background is 15.0 counts. +Note that if the user has access to an image display \fBfwhmpsf\fP and +\fBthreshold\fP can be determined interactively from inside the +daofind task itself. +The user decides to include all stars with a peak intensity greater +than five standard deviations above local background in the coordinate list, +which should include weak and spurious objects. +The user runs \fBdaofind\fR as follows. + +.nf + \f(CWap> daofind lan*.imh fwhmpsf=4.3 threshold=75.0 verify- &\fP +.fi + +The x and y coordinates, an initial guess at the magnitude and some +sharpness and roundness characteristics are output to the files "lan*.coo.1". +For example the image lan100350.imh will now have a corresponding +coordinate file lan100350.coo;1. The user may wish at this point +to quickly check the coordinate files for spurious objects. +.PP +Next the user decides to set up the parameters of the phot task. +Using the \fBepar\fR task he enters the phot task parameter set, +enters "lan100350b" opposite the \fBimage\fR parameter and "lan100350b.coo.1" +opposite the \fBcoords\fR parameter. Next he moves the cursor opposite +the \fBdatapars\fR parameter and types \fB:e\fR to enter the \fBdatapars\fR +menu. He sets the gain parameter \fBepadu\fR to 10 electrons per adu +and the readout noise \fBreadnoise\fR to 50.0 electrons. +Finally in order to normalize all the magnitudes the user enters +the image header exposure time keyword "itime" opposite the +\fBexposure\fP parameter. He types \fB:q\fR to +quit and save the \fBdatapars\fR parameters and \fB^Z\fR to quit and save the +\fBphot\fR parameters. +.PP +Now the user is ready to enter the \fBphot\fR task in interactive mode to set +up the remaining data dependent parameters. The user types the following +sequence of commands in response to the cursor prompt. + +.nf +\f(CW + ap> phot lan100350.imh + + ... \fIload the phot task\fR ... + + Image cursor [xcoord ycoord wcs] key [cmd]: ? + + ... \fIprint help page for phot task\fR ... + + Image cursor [xcoord ycoord wcs] key [cmd]: :radplots yes + + ... \fIenable radial profile plotting\fR ... + + Image cursor [xcoord ycoord wcs] key [cmd]: :m #n + + ... \fImove to star n in the coordinate list\fR ... + + Image cursor [xcoord ycoord wcs] key [cmd]: i + + ... \fIenter interactive setup mode using star n\fR ... + + ... \fImark fwhmpsf, cbox, sky annulus, apertures on the plot\fR ... + + ... \fIleave sigma and cthreshold at their default values\fR ... + + ... \fIcheck answers on radial profile plot of the results\fR ... + + Image cursor [xcoord ycoord wcs] key [cmd]: v + + ... \fIverify the critical parameters\fR ... + + Image cursor [xcoord ycoord wcs] key [cmd]: :radplots no + + ... \fIdisable radial profile plotting\fR ... + + Image cursor [xcoord ycoord wcs] key [cmd]: w + + ... \fIstore new parameters in the psets\fR ... + + Image cursor [xcoord ycoord wcs] key [cmd]: q + + ... \fIquit interactive cursor loop\fR ... + + q + + ... \fIquit the phot task\fR ... + +\fR +.fi +.PP +Finally the user runs the \fBphot\fR task on the full list of images, +with their corresponding parameter sets and dumps the output to a single +text file named "output". + +.nf + \f(CWap> phot lan*.imh coords="lan*.coo.*" output=output veri- inter- &\fR +.fi + +The results will appear in the text file "output". + +.NH 2 +Aperture Photometry of an Elliptical Galaxy +.PP +The user has a single image of the elliptical galaxy N315. She +wishes to measure the magnitude of this galaxy through a list of apertures +equal to those published in a well known catalogue of photoelectric photometry. +Her data has been sky subtracted to give an average background value of 0.0 +and the standard deviation of the sky background is 20.0 counts. +From the published aperture photometry +and the scale of her telescope she knows that she wishes to measure +the galaxy through aperture radii of 10.5, 15.2, 20.8, and 25.6 arc seconds. +.PP +The user wishes to work in interactive mode using a contour plot +of the image and the graphics cursor to enter commands to the \fBphot\fR +task. She therefore sets the image cursor to "stdgraph" as follows. + +.nf + \f(CWap> set stdimcur = stdgraph\fR +.fi + +.PP +Next she makes a contour plot of the image and writes it to +a plot metacode file as follows. + +.nf +\f(CW + ap> contour N315 + + ... \fIcontour plot appears on the terminal\fR ... + + ap> =gcur + + ... \fIenter cursor mode\fR ... + + :.write n315.plot + + ... \fIwrite the plot to a file\fR ... + + q + + ... \fIexit cursor mode\fR ... + +\fR +.fi +.PP +Now the user is ready to set up the parameters of the \fBphot\fR task. +Since she already knows the values of the parameters she wishes to use +she types + +.nf + \f(CWap> epar phot\fR +.fi + +to enter the phot task menu. She positions the cursor opposite +\fBimage\fR parameter and types "N315", opposite \fBdispay\fR and +types "stdgraph". +Next she moves the cursor opposite +the \fBdatapars\fR parameter and types \fB:e\fR to enter the \fBdatapars\fR +menu. She makes sure that \fBscale =\fP 0.75 arc-seconds per pixel the scale +of the telescope, sets the standard deviation +of the sky background \fBsigma\fR to 20.0, sets the gain +parameter \fBepadu\fR to 5 electrons per adu +and the readout noise \fBreadnoise\fR to 5.0 electrons. She types \fB:q\fR to +quit and save the \fBdatapars\fR parameters. She decides to leave the +centering parameters in \fBcenterpars\fR at their default values. +\fBCbox\fP in particular will be 5.0 arcseconds wide. The user +has already removed a low order polynomial sky background from this image. +She wishes to fix the sky value at 0.0. She moves the cursor opposite +the \fBfitskypars\fR parameter and types \fB:e\fR to enter the sky fitting menu. +She types "constant" opposite the \fBsalgorithm\fR parameter, "0.0" +opposite the \fBskyvalue\fR parameter and \fB:e\fR to exit +the sky fitting parameter menu. Finally she enters the \fBphotpars\fR +menu and enters the aperture string "10.5,15.2,20.8,25.6" opposite +the \fBapert\fR parameter. +.PP +To measure the galaxy she types + +.nf + \f(CWap> phot N315\fR +.fi + +to enter the phot task, positions the cursor on the center of the +galaxy in the contour plot and taps the space bar to make the measurement. +The results are written to the file "N315.mag.1". diff --git a/noao/digiphot/apphot/doc/wphot.hlp b/noao/digiphot/apphot/doc/wphot.hlp new file mode 100644 index 00000000..69bfd7c7 --- /dev/null +++ b/noao/digiphot/apphot/doc/wphot.hlp @@ -0,0 +1,780 @@ +.help wphot May00 noao.digiphot.apphot +.ih +NAME +wphot -- perform weighted aperture photometry on a list of stars +.ih +USAGE +wphot image +.ih +PARAMETERS +.ls image +The list of images containing the objects to be measured. +.le +.ls skyfile = "" +The list of text files containing the sky values, of the measured objects, +one object per line with x, y, the sky value, sky sigma, sky skew, number of sky +pixels and number of rejected sky pixels in columns one to seven respectively. +The number of sky files must be zero, one, or equal to the number of input +images. A skyfile value is only requested if \fIfitskypars.salgorithm\fR = +"file" and if WPHOT is run non-interactively. +.le +.ls coords = "" +The list of text files containing initial coordinates for the objects to +be centered. Objects are listed in coords one object per line with the +initial coordinate values in columns one and two. The number of coordinate +files must be zero, one, or equal to the number of images. If coords is +"default", "dir$default", or a directory specification then a coords file name +of the form dir$root.extension.version is constructed, where dir is the +directory, root is the root image name, extension is "coo" and version is +the next available version number for the file. +.le +.ls output = "default" +The name of the results file or results directory. If output is +"default", "dir$default", or a directory specification then an output file name +of the form dir$root.extension.version is constructed, where dir is the +directory, root is the root image name, extension is "omag" and version is +the next available version number for the file. The number of output files +must be zero, one, or equal to the number of image files. In both interactive +and batch mode full output is written to output. In interactive mode +an output summary is also written to the standard output. +.le +.ls plotfile = "" +The name of the file containing radial profile plots of the stars written +to the output file. If plotfile is defined then a radial profile plot +is written to plotfile every time a record is written to \fIoutput\fR. +The user should be aware that this can be a time consuming operation. +.le +.ls datapars = "" +The name of the file containing the data dependent parameters. The critical +parameters \fIfwhmpsf\fR and \fIsigma\fR are located here. If \fIdatapars\fR +is undefined then the default parameter set in uparm directory is used. +.le +.ls centerpars = "" +The name of the file containing the centering parameters. The critical +parameters \fIcalgorithm\fR and \fIcbox\fR are located here. +If \fIcenterpars\fR is undefined then the default parameter set in +uparm directory is used. +.le +.ls fitskypars = "" +The name of the text file containing the sky fitting parameters. The critical +parameters \fIsalgorithm\fR, \fIannulus\fR, and \fIdannulus\fR are located here. +If \fIfitskypars\fR is undefined then the default parameter set in uparm +directory is used. +.le +.ls photpars = "" +The name of the file containing the photometry parameters. The critical +parameter \fIapertures\fR is located here. If \fIphotpars\fR is undefined +then the default parameter set in uparm directory is used. +.le +.ls interactive = yes +Run the task interactively ? +.le +.ls radplots = no +If \fIradplots\fR is "yes" and PHOT is run in interactive mode, a radial +profile of each star is plotted on the screen after the star is measured. +.le +.ls icommands = "" +The image display cursor or image cursor command file. +.le +.ls gcommands = "" +The graphics cursor or graphics cursor command file. +.le +.ls wcsin = ")_.wcsin", wcsout = ")_.wcsout" +The coordinate system of the input coordinates read from \fIcoords\fR and +of the output coordinates written to \fIoutput\fR respectively. The image +header coordinate system is used to transform from the input coordinate +system to the "logical" pixel coordinate system used internally, +and from the internal "logical" pixel coordinate system to the output +coordinate system. The input coordinate system options are "logical", tv", +"physical", and "world". The output coordinate system options are "logical", +"tv", and "physical". The image cursor coordinate system is assumed to +be the "tv" system. +.ls logical +Logical coordinates are pixel coordinates relative to the current image. +The logical coordinate system is the coordinate system used by the image +input/output routines to access the image data on disk. In the logical +coordinate system the coordinates of the first pixel of a 2D image, e.g. +dev$ypix and a 2D image section, e.g. dev$ypix[200:300,200:300] are +always (1,1). +.le +.ls tv +Tv coordinates are the pixel coordinates used by the display servers. Tv +coordinates include the effects of any input image section, but do not +include the effects of previous linear transformations. If the input +image name does not include an image section, then tv coordinates are +identical to logical coordinates. If the input image name does include a +section, and the input image has not been linearly transformed or copied from +a parent image, tv coordinates are identical to physical coordinates. +In the tv coordinate system the coordinates of the first pixel of a +2D image, e.g. dev$ypix and a 2D image section, e.g. dev$ypix[200:300,200:300] +are (1,1) and (200,200) respectively. +.le +.ls physical +Physical coordinates are pixel coordinates invariant with respect to linear +transformations of the physical image data. For example, if the current image +was created by extracting a section of another image, the physical +coordinates of an object in the current image will be equal to the physical +coordinates of the same object in the parent image, although the logical +coordinates will be different. In the physical coordinate system the +coordinates of the first pixel of a 2D image, e.g. dev$ypix and a 2D +image section, e.g. dev$ypix[200:300,200:300] are (1,1) and (200,200) +respectively. +.le +.ls world +World coordinates are image coordinates in any units which are invariant +with respect to linear transformations of the physical image data. For +example, the ra and dec of an object will always be the same no matter +how the image is linearly transformed. The units of input world coordinates +must be the same as those expected by the image header wcs, e. g. +degrees and degrees for celestial coordinate systems. +.le +The wcsin and wcsout parameters default to the values of the package +parameters of the same name. The default values of the package parameters +wcsin and wcsout are "logical" and "logical" respectively. +.le +.le +.ls cache = ")_.cache" +Cache the image pixels in memory. Cache may be set to the value of the apphot +package parameter (the default), "yes", or "no". By default cacheing is +disabled. +.le +.ls verify = ")_.verify" +Verify the critical parameters in non-interactive mode. Verify may be set to +the apphot package parameter value (the default), "yes", or "no". +.le +.ls update = ")_.update" +Update the critical parameters in non-interactive mode if verify is yes. +Update may be set to the apphot package parameter value (the default), "yes", +or "no". + +.le +.ls verbose = ")_.verbose" +Print messages on the terminal about actions taken in non-interactive mode. +Verbose may be set to the apphot package parameter value (the default), "yes", +or "no". +.le +.ls graphics = ")_.graphics" +The default graphics device. Graphics may be set to the apphot package +parameter value (the default), "yes", or "no". + +.le +.ls display = ")_.display" +The default display device. Graphics may be set to the apphot package +parameter value (the default), "yes", or "no. By default graphics overlay +is disabled. Setting display to one of "imdr", "imdg", "imdb", or "imdy" +enables graphics overlay with the IMD graphics kernel. Setting display to +"stdgraph" enables WPHOT to work interactively from a contour plot. +.le + +.ih +DESCRIPTION +WPHOT computes accurate centers, sky values, and weighted magnitudes for a +list of objects in the IRAF image \fIimage\fR whose initial coordinates are read +from the text file \fIcoords\fR or image display cursor, and writes the +computed x and y coordinates, sky values and magnitudes to the text file +\fIoutput\fR. + +The coordinates read from \fIcoords\fR are assumed to be in coordinate +system defined by \fIwcsin\fR. The options are "logical", "tv", "physical", +and "world" and the transformation from the input coordinate system to +the internal "logical" system is defined by the image coordinate system. +The simplest default is the "logical" pixel system. Users working on with +image sections but importing pixel coordinate lists generated from the parent +image must use the "tv" or "physical" input coordinate systems. +Users importing coordinate lists in world coordinates, e.g. ra and dec, +must use the "world" coordinate system and may need to convert their +equatorial coordinate units from hours and degrees to degrees and degrees first. + +The coordinates written to \fIoutput\fR are in the coordinate +system defined by \fIwcsout\fR. The options are "logical", "tv", +and "physical". The simplest default is the "logical" system. Users +wishing to correlate the output coordinates of objects measured in +image sections or mosaic pieces with coordinates in the parent +image must use the "tv" or "physical" coordinate systems. + +If \fIcache\fR is yes and the host machine physical memory and working set size +are large enough, the input image pixels are cached in memory. If cacheing +is enabled and WPHOT is run interactively the first measurement will appear +to take a long time as the entire image must be read in before the measurement +is actually made. All subsequent measurements will be very fast because WPHOT +is accessing memory not disk. The point of cacheing is to speed up random +image access by making the internal image i/o buffers the same size as the +image itself. However if the input object lists are sorted in row order and +sparse cacheing may actually worsen not improve the execution time. Also at +present there is no point in enabling cacheing for images that are less than +or equal to 524288 bytes, i.e. the size of the test image dev$ypix, as the +default image i/o buffer is exactly that size. However if the size of dev$ypix +is doubled by converting it to a real image with the chpixtype task then the +effect of cacheing in interactive is can be quite noticeable if measurements +of objects in the top and bottom halfs of the image are alternated. + +In interactive mode the user may either define the list of objects to be +measured interactively with the image cursor or create an object list prior +to entering WPHOT. In either case the user may adjust the centering, sky +fitting and photometry parameters until a satisfactory fit is achieved and +only then store the final results in \fIoutput\fR. In batch +mode the initial positions are read from the text file \fIcoords\fR +or the image cursor parameter \fIicommands\fR is redirected to a text +file containing a list of cursor commands. + +.ih +CURSOR COMMANDS + +The following list of cursor commands are currently available. + +.nf + Interactive Photometry Commands + +? Print help +: Colon commands +v Verify the critical parameters +w Store the current parameters +d Plot radial profile of current star +i Interactively set parameters using current star +c Fit center of current star +t Fit sky around the cursor +a Average sky values fit around several cursor positions +s Fit sky around the current star +p Do photometry for current star, using current sky +o Do photometry for current star, using current sky, output results +f Do photometry for current star +spbar Do photometry for current star, output results +m Move to next star in coordinate list +n Do photometry for next star in coordinate list, output results +l Do photometry for remaining stars in coordinate list, output results +r Rewind the coordinate list +e Print error messages +q Exit task + + + Colon Commands + +:show [data/center/sky/fit] Show parameters +:m [n] Move to next [nth] star in the coordinate list +:n [n] Do photometry for next [nth] star in coordinate list, output results + + + Colon Parameter Editing Commands + +# Image and file parameters + +:image [string] Image name +:coords [string] Coordinate file name +:output [string] Output file name + +# Data dependent parameters + +:scale [value] Image scale (units per pixel) +:fwhmpsf [value] Full-width half-maximum of PSF (scale units) +:emission [y/n] Emission features (y), absorption (n) +:sigma [value] Standard deviation of sky (counts) +:datamin [value] Minimum good pixel value (counts) +:datamax [value] Maximum good pixel value (counts) + +# Noise parameters + +:noise [string] Noise model (constant|poisson) +:gain [string] Gain image header keyword +:ccdread [string] Readout noise image header keyword +:epadu [value] Gain (electrons per adu) +:readnoise [value] Readout noise (electrons) + +# Observations parameters + +:exposure [string] Exposure time image header keyword +:airmass [string] Airmass image header keyword +:filter [string] Filter image header keyword +:obstime [string] Time of observation image header keyword +:itime [value] Integration time (time units) +:xairmass [value] Airmass value (number) +:ifilter [string] Filter id string +:otime [string] Time of observations (time units) + +# Centering algorithm parameters + +:calgorithm [string] Centering algorithm +:cbox [value] Width of the centering box (scale units) +:cthreshold [value] Centering intensity threshold (sigma) +:cmaxiter [value] Maximum number of iterations +:maxshift [value] Maximum center shift (scale units) +:minsnratio [value] Minimum S/N ratio for centering +:clean [y/n] Clean subraster before centering +:rclean [value] Cleaning radius (scale units) +:rclip [value] Clipping radius (scale units) +:kclean [value] Clean K-sigma rejection limit (sigma) + +# Sky fitting algorithm parameters + +:salgorithm [string] Sky fitting algorithm +:skyvalue [value] User supplied sky value (counts) +:annulus [value] Inner radius of sky annulus (scale units) +:dannulus [value] Width of sky annulus (scale units) +:khist [value] Sky histogram extent (+/- sigma) +:binsize [value] Resolution of sky histogram (sigma) +:smooth [y/n] Lucy smooth the sky histogram +:sloclip [value] Low-side clipping factor in percent +:shiclip [value] High-side clipping factor in percent +:smaxiter [value] Maximum number of iterations +:snreject [value] Maximum number of rejection cycles +:sloreject [value] Low-side pixel rejection limits (sky sigma) +:shireject [value] High-side pixel rejection limits (sky sigma) +:rgrow [value] Region growing radius (scale units) + +# Photometry parameters + +:weighting [string] Weighting function (constant|cone|gauss) +:apertures [string] List of aperture radii (scale units) +:zmag [value] Zero point of magnitude scale + +# Plotting and marking parameters + +:mkcenter [y/n] Mark computed centers on display +:mksky [y/n] Mark the sky annuli on the display +:mkapert [y/n] Mark apertures on the display +:radplot [y/n] Plot radial profile of object + + + +The following commands are available from inside the interactive setup menu. + + + Interactive Phot/Wphot Setup Menu + + v Mark and verify the critical parameters (f,s,c,a,d,r) + + f Mark and verify the full-width half-maximum of psf + s Mark and verify the standard deviation of the background + l Mark and verify the minimum good data value + u Mark and verify the maximum good data value + + c Mark and verify the centering box width + n Mark and verify the cleaning radius + p Mark and verify the clipping radius + + a Mark and verify the inner radius of the sky annulus + d Mark and verify the width of the sky annulus + g Mark and verify the region growing radius + + r Mark and verify the aperture radii +.fi + +.ih +ALGORITHMS + +WPHOT computes accurate centers for each object using the centering +parameters defined in the CENTERPARS task, computes an accurate sky value +for each object using the sky fitting parameters defined in FITSKYPARS task, +and computes magnitudes using the photometry parameters defined in the +PHOTPARS task. The data dependent parameter are defined in the DATAPARS task. + +Three weighting functions are currently supported: constant, cone and gauss. +Constant weighting, the default gives identical results to the PHOT task. +Pixels are weighted by the fraction of their area inside the circular +aperture. For cone and gauss weighting an additional triangular or gaussian +weighting function of full width half maximum equal to \fIfwhmpsf\fR is +applied to the pixels before aperture summing. + +This task is currently experimental. Further algorithm work is required. + +.ih +OUTPUT + +In interactive mode the following quantities are printed on the standard +output as each object is measured. Error is a simple string which +indicates whether the task encountered any errors in the +the centering algorithm, the sky fitting algorithm or the photometry +algorithm. Mag and merr are the magnitudes and errors in +apertures 1 through N respectively and xcenter, ycenter and msky are the +x and y centers and the sky value respectively. + +.nf + image xcenter ycenter msky mag[1 ... N] error +.fi + +In both interactive and batch mode full output is written to the text file +\fIoutput\fR. At the beginning of each file is a header listing the +current values of the parameters when the first stellar record was written. +These parameters can be subsequently altered. For each star measured the +following record is written + +.nf + image xinit yinit id coords lid + xcenter ycenter xshift yshift xerr yerr cier error + msky stdev sskew nsky nsrej sier serror + itime xairmass ifilter otime + rapert sum area flux mag merr pier perr +.fi + +Image and coords are the name of the image and coordinate file respectively. +Id and lid are the sequence numbers of stars in the output and coordinate +files respectively. Cier and cerror are the error code and accompanying +error message respectively. Xinit, yinit, xcenter, ycenter, xshift, yshift, +and xerr, yerr are self explanatory and output in pixel units. The sense of +the xshift and yshift definitions is the following. + +.nf + xshift = xcenter - xinit + yshift = ycenter - yinit +.fi + +Sier and serror are the error code and accompanying error message respectively. +Msky, stdev and sskew are the best estimate of the sky value (per pixel), +standard deviation and skew respectively. Nsky and nsrej are the number of +sky pixels and the number of sky pixels rejected respectively. + +Itime is the exposure time, xairmass is self-evident, ifilter is an id +string identifying the filter used during the observation, and otime is +a string specifying the time of the observation in whatever units the +user has defined. + +Rapert, sum, area, and flux are the radius of the aperture in pixels, the total +number of counts including sky in the aperture, the area of the aperture +in square pixels, and the total number of counts in the aperture excluding +sky. Mag and merr are the magnitude and error in the magnitude +in the aperture (see below). + +.nf + flux = sum - area * msky + mag = zmag - 2.5 * log10 (flux) + 2.5 * log10 (itime) + merr = 1.0857 * error / flux + error = sqrt (flux / epadu + area * stdev**2 + + area**2 * stdev**2 / nsky) +.fi + +Pier and perror are photometry error code and accompanying error message. + +In interactive mode a radial profile of each measured object is plotted +in the graphics window if \fIradplots\fR is "yes". + +In interactive and batchmode a radial profile plot is written to +\fIplotfile\fR if it is defined each time the result of an object +measurement is written to \fIoutput\fR . + +.ih +ERRORS +If the object centering was error free then the field cier will be zero. +Non-zero values of cier flag the following error conditions. + +.nf + 0 # No error + 101 # The centering box is off image + 102 # The centering box is partially off the image + 103 # The S/N ratio is low in the centering box + 104 # There are two few points for a good fit + 105 # The x or y center fit is singular + 106 # The x or y center fit did not converge + 107 # The x or y center shift is greater than maxshift + 108 # There is bad data in the centering box +.fi + +If all goes well during the sky fitting process then the error code sier +will be 0. Non-zero values of sier flag the following error conditions. + +.nf + 0 # No error + 201 # There are no sky pixels in the sky annulus + 202 # Sky annulus is partially off the image + 203 # The histogram of sky pixels has no width + 204 # The histogram of sky pixels is flat or concave + 205 # There are too few points for a good sky fit + 206 # The sky fit is singular + 207 # The sky fit did not converge + 208 # The graphics stream is undefined + 209 # The file of sky values does not exist + 210 # The sky file is at EOF + 211 # Cannot read the sky value correctly + 212 # The best fit parameter are non-physical +.fi + +If no error occurs during the measurement of the magnitudes then pier is +0. Non-zero values of pier flag the following error conditions. + +.nf + 0 # No error + 301 # The aperture is off the image + 302 # The aperture is partially off the image + 303 # The sky value is undefined + 305 # There is bad data in the aperture +.fi + +.ih +EXAMPLES + +1. Compute the magnitudes for a few stars in dev$ypix using the display +and the image cursor. Setup the task parameters using the interactive +setup menu defined by the i key command and a radial profile plot. + +.nf + ap> display dev$ypix 1 fi+ + + ... display the image + + ap> wphot dev$ypix + + ... type ? to print an optional help page + + ... move the image cursor to a star + ... type i to enter the interactive setup menu + ... enter maximum radius in pixels of the radial profile or hit + CR to accept the default + ... set the fwhmpsf, centering radius, inner and outer sky annuli, + photometry apertures, and sigma using the graphics cursor and the + stellar radial profile plot + ... typing <CR> leaves everything at the default value + ... type q to quit the setup menu + + ... type the v key to verify the parameters + + ... type the w key to save the parameters in the parameter files + + ... move the image cursor to the stars of interest and tap + the space bar + + ... a one line summary of the fitted parameters will appear on the + standard output for each star measured + + ... type q to quit and q again to confirm the quit + + ... the output will appear in ypix.omag.1 +.fi + +2. Compute the magnitudes for a few stars in dev$ypix using a contour plot +and the graphics cursor. This option is only useful for those (now very few) +users who have access to a graphics terminal but not to an image display +server. Setup the task parameters using the interactive setup menu defined by +the i key command as in example 1. + +.nf + ap> show stdimcur + + ... record the default value of stdimcur + + ap> set stdimcur = stdgraph + + ... define the image cursor to be the graphics cursor + + ap> contour dev$ypix + + ... make a contour plot of dev$ypix + + ap> contour dev$ypix >G ypix.plot1 + + ... store the contour plot of dev$ypix in the file ypix.plot1 + + ap> wphot dev$ypix display=stdgraph + + ... type ? to get an optional help page + + ... move graphics cursor to a star + ... type i to enter the interactive setup menu + ... enter maximum radius in pixels of the radial profile or CR + to accept the default value + ... set the fwhmpsf, centering radius, inner and outer sky annuli, + apertures, and sigma using the graphics cursor and the + stellar radial profile plot + ... typing <CR> leaves everything at the default value + ... type q to quit the setup menu + + ... type the v key to verify the critical parameters + + ... type the w key to save the parameters in the parameter files + + ... retype :.read ypix.plot1 to reload the contour plot + + ... move the graphics cursor to the stars of interest and tap + the space bar + + ... a one line summary of the fitted parameters will appear on the + standard output for each star measured + + ... type q to quit and q again to verify + + ... full output will appear in the text file ypix.omag.2 + + ap> set stdimcur = <default> + + ... reset stdimcur to its previous value +.fi + + +3. Setup and run PHOT interactively on a list of objects temporarily +overriding the fwhmpsf, sigma, cbox, annulus, dannulus, and apertures +parameters determined in examples 1 or 2. + +.nf + ap> daofind dev$ypix fwhmpsf=2.6 sigma=25.0 verify- + + ... make a coordinate list + + ... the output will appear in the text file ypix.coo.1 + + ap> wphot dev$ypix cbox=7.0 annulus=12.0 dannulus=5.0 \ + apertures="3.0,5.0" coords=ypix.coo.1 + + ... type ? for optional help + + + ... move the graphics cursor to the stars and tap space bar + + or + + ... select stars from the input coordinate list with m / :m # + and measure with spbar + + ... measure stars selected from the input coordinate list + with n / n # + + ... a one line summary of results will appear on the standard output + for each star measured + + ... type q to quit and q again to confirm the quit + + ... the output will appear in ypix.omag.3 ... +.fi + + +4. Display and measure some stars in an image section and write the output +coordinates in the coordinate system of the parent image. + +.nf + ap> display dev$ypix[150:450,150:450] 1 + + ... display the image section + + ap> wphot dev$ypix[150:450,150:450] wcsout=tv + + ... move cursor to stars and type spbar + + ... type q to quit and q again to confirm quit + + ... output will appear in ypix.omag.4 + + ap> pdump ypix.omag.4 xc,yc yes | tvmark 1 STDIN col=204 +.fi + + +5. Run PHOT in batch mode using the coordinate file and the previously +saved parameters. Verify the critical parameters. + +.nf + ap> wphot dev$ypix coords=ypix.coo.1 verify+ inter- + + ... output will appear in ypix.omag.5 ... +.fi + + +6. Repeat example 5 but assume that the input coordinate are ra and dec +in degrees and degrees, turn off verification, and submit the task to to +the background. + +.nf + ap> display dev$ypix 1 + + ap> rimcursor wcs=world > radec.coo + + ... move to selected stars and type any key + + ... type ^Z to quit + + ap> wphot dev$ypix coords=radec.coo wcsin=world verify- inter- & + + ... output will appear in ypix.omag.6 + + ap> pdump ypix.omag.6 xc,yc yes | tvmark 1 STDIN col=204 + + ... mark the stars on the display +.fi + + +7. Run PHOT interactively without using the image display. + +.nf + ap> show stdimcur + + ... record the default value of stdimcur + + ap> set stdimcur = text + + ... set the image cursor to the standard input + + ap> wphot dev$ypix coords=ypix.coo.1 + + ... type ? for optional help + + ... type :m 3 to set the initial coordinates to those of the + third star in the list + + ... type i to enter the interactive setup menu + ... enter the maximum radius in pixels for the radial profile or + accept the default with a CR + ... type v to enter the default menu + ... set the fwhmpsf, centering radius, inner and outer sky annuli, + apertures, and sigma using the graphics cursor and the + stellar radial profile plot + ... typing <CR> after the prompt leaves the parameter at its default + value + ... type q to quit the setup menu + + ... type r to rewind the coordinate list + + ... type l to measure all the stars in the coordinate list + + ... a one line summary of the answers will appear on the standard + output for each star measured + + ... type q to quit followed by q to confirm the quit + + ... full output will appear in the text file ypix.omag.7 + + ap> set stdimcur = <default> + + ... reset the value of stdimcur +.fi + + +8. Use a image cursor command file to drive the PHOT task. The cursor command +file shown below sets the cbox, annulus, dannulus, and apertures parameters +computes the centers, sky values, and magnitudes for 3 stars, updates the +parameter files, and quits the task. + +.nf + ap> type cmdfile + : cbox 9.0 + : annulus 12.0 + : dannulus 5.0 + : apertures 5.0 + 442 410 101 \040 + 349 188 101 \040 + 225 131 101 \040 + w + q + + ap> wphot dev$ypix icommands=cmdfile verify- + + ... full output will appear in ypix.omag.8 +.fi + + + + +.ih +BUGS +This task is experimental and requires more work. + +It is currently the responsibility of the user to make sure that the +image displayed in the frame is the same as that specified by the image +parameter. + +Commands which draw to the image display are disabled by default. +To enable graphics overlay on the image display, set the display +parameter to "imdr", "imdg", "imdb", or "imdy" to get red, green, +blue or yellow overlays and set the centerpars mkcenter switch to +"yes", the fitskypars mksky switch to"yes", or the photpars mkapert +witch to "yes". It may be necessary to run gflush and to redisplay the image +to get the overlays position correctly. + + +.ih +SEE ALSO +datapars, centerpars, fitskypars, photpars, qphot, phot, polyphot +.endhelp diff --git a/noao/digiphot/apphot/findpars.par b/noao/digiphot/apphot/findpars.par new file mode 100644 index 00000000..f357fd76 --- /dev/null +++ b/noao/digiphot/apphot/findpars.par @@ -0,0 +1,12 @@ +# FINDPARS + +threshold,r,h,4.0,,,Threshold in sigma for feature detection +nsigma,r,h,1.5,,,Width of convolution kernel in sigma +ratio,r,h,1.0,0.0,1.0,Ratio of minor to major axis of Gaussian kernel +theta,r,h,0.0,0.0,180.0,Position angle of major axis of Gaussian kernel +sharplo,r,h,.2,,,Lower bound on sharpness for feature detection +sharphi,r,h,1.0,,,Upper bound on sharpness for feature detection +roundlo,r,h,-1.0,,,Lower bound on roundness for feature detection +roundhi,r,h,1.0,,,Upper bound on roundness for feature detection +mkdetections,b,h,no,,,Mark detected stars on the display ? +mode,s,h,'ql' diff --git a/noao/digiphot/apphot/fitpsf.par b/noao/digiphot/apphot/fitpsf.par new file mode 100644 index 00000000..d578683b --- /dev/null +++ b/noao/digiphot/apphot/fitpsf.par @@ -0,0 +1,24 @@ +# FITPSF + +image,f,a,,,,"The input image(s)" +box,r,a,,,,"The fitting box width in scale units" +coords,f,h,"",,,"The input coordinate list(s) (default: image.coo.?)" +output,f,h,"default",,,"The output fit file(s) (default: image.psf.?)" +datapars,pset,h,"",,,"Data dependent parameters" +function,s,h,"radgauss","|radgauss|elgauss|moments|",,"The fitting function" +maxiter,i,h,50,,,"The maximum number of fitting iterations" +nreject,i,h,0,,,"The maximum number of rejection cycles" +kreject,r,h,3.0,,,The K-sigma rejection limit" +mkbox,b,h,no,,,"Draw the fitting box on the display ?" +interactive,b,h,yes,,,"Interactive mode ?" +icommands,*imcur,h,"",,,"Image cursor: [x y wcs] key [cmd]" +gcommands,*gcur,h,"",,,"Graphics cursor: [x y wcs] key [cmd]" +wcsin,s,h,)_.wcsin,,,"The input coordinate system (logical,tv,physical,world)" +wcsout,s,h,)_.wcsout,,,"The output coordinate system (logical,tv,physical)" +cache,b,h,)_.cache,,,"Cache the input image pixels in memory ?" +verify,b,h,)_.verify,,,"Verify critical parameters in non-interactive mode ?" +update,b,h,)_.update,,,"Update critical parameters in non-interactive mode ?" +verbose,b,h,)_.verbose,,,"Print messages in non-interactive mode ?" +graphics,s,h,)_.graphics,,,"Graphics device" +display,s,h,)_.display,,,"Display device" +mode,s,h,'ql' diff --git a/noao/digiphot/apphot/fitpsf/apbfitpsf.x b/noao/digiphot/apphot/fitpsf/apbfitpsf.x new file mode 100644 index 00000000..9854ab9f --- /dev/null +++ b/noao/digiphot/apphot/fitpsf/apbfitpsf.x @@ -0,0 +1,95 @@ +include <fset.h> +include "../lib/apphot.h" +include "../lib/display.h" + +# APBFITPSF -- Procedure to fit a functional form to the PSF for a list of +# objects. + +procedure apbfitpsf (ap, im, cl, out, gid, id, ld, interactive) + +pointer ap # pointer to apphot structure +pointer im # pointer to IRAF image +int cl # starlist file descriptor +int out # output file descriptor +pointer gid # image display stream +int id # initial id +int ld # list number +int interactive # interactive mode + +int ier, ild, stdin +pointer sp, str +real wx, wy +int fscan, nscan(), strncmp(), apsffit(), apstati() + +begin + call smark (sp) + call salloc (str, SZ_FNAME, TY_CHAR) + call fstats (cl, F_FILENAME, Memc[str], SZ_FNAME) + + # Initialize. + ild = ld + + # Print query if input is STDIN. + if (strncmp ("STDIN", Memc[str], 5) == 0) { + stdin = YES + call printf ("Type object x and y coordinates (^Z or ^D to end): ") + call flush (STDOUT) + } else + stdin = NO + + # Loop over the interesting objects. + while (fscan(cl) != EOF) { + + # Decode the centers. + call gargr (wx) + call gargr (wy) + if (nscan () != 2) { + if (stdin == YES) { + call printf ( + "Type object x and y coordinates (^Z or ^D to end): ") + call flush (STDOUT) + } + next + } + + # Transform the input coordinates. + switch (apstati(ap,WCSIN)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_itol (ap, wx, wy, wx, wy, 1) + case WCS_TV: + call ap_vtol (im, wx, wy, wx, wy, 1) + default: + ; + } + + # Store the current cursor coordinates. + call apsetr (ap, CWX, wx) + call apsetr (ap, CWY, wy) + + # Fit the psf. + ier = apsffit (ap, im, wx, wy) + + # Output the results. + if (interactive == YES) { + call ap_qppsf (ap, ier) + if (gid != NULL) + call appfmark (ap, gid, apstati (ap, MKPSFBOX)) + } + if (id == 1) + call ap_param (ap, out, "fitpsf") + call ap_ppsf (ap, out, id, ild, ier) + + # Prepare for the next object. + id = id + 1 + ild = ild + 1 + call apsetr (ap, WX, wx) + call apsetr (ap, WY, wy) + if (stdin == YES) { + call printf ( + "Type object x and y coordinates (^D or ^Z to end): ") + call flush (STDOUT) + } + + } + call sfree (sp) +end diff --git a/noao/digiphot/apphot/fitpsf/apfbuf.x b/noao/digiphot/apphot/fitpsf/apfbuf.x new file mode 100644 index 00000000..428c30cb --- /dev/null +++ b/noao/digiphot/apphot/fitpsf/apfbuf.x @@ -0,0 +1,88 @@ +include <imhdr.h> +include "../lib/apphotdef.h" +include "../lib/fitpsfdef.h" +include "../lib/fitpsf.h" + +# APFBUF -- Procedure to fetch the subraster of pixels to be fitted given the +# pointer to the IRAF image, the coordinates of the center and the apphot +# structure. + +int procedure apfbuf (ap, im, wx, wy) + +pointer ap # pointer to apphot structure +pointer im # pointer to the IRAF image +real wx, wy # center coordinates + +int ippix +pointer psf +real ppix +pointer ap_psfpix() + +begin + # Check for 0 sized aperture. + psf = AP_PPSF(ap) + if (AP_PSFAPERT(psf) <= 0.0) + return (AP_NOPSFAREA) + + # Get the PSF pixels. + ppix = max (1.0, AP_PSFAPERT(psf) * AP_SCALE(ap)) + ippix = 2 * int (ppix) + 1 + AP_PSFPIX(psf) = ap_psfpix (im, wx, wy, ippix, AP_PXC(psf), AP_PYC(psf), + AP_PNX(psf), AP_PNY(psf)) + if (AP_PSFPIX(psf) == NULL) + return (AP_NOPSFAREA) + else if (AP_PNX(psf) < ippix || AP_PNY(psf) < ippix) + return (AP_PSF_OUTOFBOUNDS) + else + return (AP_OK) +end + + +# AP_PSFPIX -- Procedure to fetch the pixels to be used for centering. + +pointer procedure ap_psfpix (im, wx, wy, papert, xc, yc, nx, ny) + +pointer im # pointer to IRAF image +real wx, wy # center of subraster to be extracted +int papert # width of subraster to be extracted +real xc, yc # center of extracted subraster +int nx, ny # dimensions of extracted subraster + +int ncols, nlines, c1, c2, l1, l2, half_papert +pointer buf +real xc1, xc2, xl1, xl2 +pointer imgs2r() + +begin + # Check for nonsensical input. + half_papert = (papert - 1) / 2 + if (half_papert <= 0) + return (NULL) + + # Test for out of bounds pixels + ncols = IM_LEN(im,1) + nlines = IM_LEN(im,2) + xc1 = wx - half_papert + xc2 = wx + half_papert + xl1 = wy - half_papert + xl2 = wy + half_papert + if (xc1 > real (ncols) || xc2 < 1.0 || xl1 > real (nlines) || xl2 < 1.0) + return (NULL) + + # Get column and line limits, dimensions and center of subraster. + c1 = max (1.0, min (real (ncols), xc1)) + 0.5 + c2 = min (real (ncols), max (1.0, xc2)) + 0.5 + l1 = max (1.0, min (real (nlines), xl1)) + 0.5 + l2 = min (real (nlines), max (1.0, xl2)) + 0.5 + nx = c2 - c1 + 1 + ny = l2 - l1 + 1 + xc = wx - c1 + 1 + yc = wy - l1 + 1 + + # Get pixels and return. + buf = imgs2r (im, c1, c2, l1, l2) + if (buf == EOF) + return (NULL) + else + return (buf) +end diff --git a/noao/digiphot/apphot/fitpsf/apfitpsf.x b/noao/digiphot/apphot/fitpsf/apfitpsf.x new file mode 100644 index 00000000..94957b6a --- /dev/null +++ b/noao/digiphot/apphot/fitpsf/apfitpsf.x @@ -0,0 +1,344 @@ +include <ctype.h> +include <gset.h> +include <imhdr.h> +include "../lib/apphot.h" +include "../lib/display.h" +include "../lib/fitpsf.h" + +define HELPFILE "apphot$fitpsf/fitpsf.key" + +# APFITPSF -- Procedure to fit a functional form to the PSF for a list of +# objects in interactive mode. + +int procedure apfitpsf (ap, im, cl, gd, id, out, stid, interactive, cache) + +pointer ap # pointer to apphot structure +pointer im # pointer to IRAF image +int cl # starlist file descriptor +pointer gd # graphics pointer +pointer id # display pointer +int out # output file descriptor +int stid # output file sequence number +int interactive # interactive mode +int cache # cache the input image pixels + +real wx, wy, xlist, ylist +pointer sp, cmd +int wcs, key, newimage, newbuf, newfit, newlist, ltid, ier +int ip, oid, colonkey, prev_num, req_num, buf_size, req_size, old_size +int memstat + +real apstatr() +int clgcur(), apgscur(), apsffit(), apsfrefit(), apstati() +int apgqverify(), apgtverify(), ctoi(), apnew(), ap_memstat(), sizeof() + +define endswitch_ 99 + +begin + # Initialize. + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + # Initialize the cursor commands. + key = ' ' + Memc[cmd] = EOS + + # Initialize the fitting commands. + newimage = NO + newbuf = YES + newfit = YES + ier = AP_OK + + # Initialize the sequencing. + newlist = NO + ltid = 0 + + # Loop over the cursor commands. + while (clgcur ("icommands", wx, wy, wcs, key, Memc[cmd], SZ_LINE) != + EOF) { + + # Store the cursor coordinates + call ap_vtol (im, wx, wy, wx, wy, 1) + call apsetr (ap, CWX, wx) + call apsetr (ap, CWY, wy) + + # Test to see if the cursor moved. + if (apnew (ap, wx, wy, xlist, ylist, newlist) == YES) { + newbuf = YES + newfit = YES + } + + # Loop over the cursor commands. + switch (key) { + + # Quit. + case 'q': + if (interactive == YES) { + if (apgqverify ("fitpsf", ap, key) == YES) { + call sfree (sp) + return (apgtverify (key)) + } + } else { + call sfree (sp) + return (NO) + } + + + # Print error messages. + case 'e': + if (interactive == YES) + call ap_pferrors (ap, ier) + + # Print the help pages. + case '?': + if ((id != NULL) && (id == gd)) + call gpagefile (id, HELPFILE, "") + else if (interactive == YES) + call pagefile (HELPFILE, "[space=morehelp,q=quit,?=help]") + + # Rewind the list. + case 'r': + if (cl != NULL) { + call seek (cl, BOFL) + ltid = 0 + } else if (interactive == YES) + call printf ("No coordinate list\n") + + # Process the fitpsf colon commands. + case ':': + for (ip = 1; IS_WHITE(Memc[cmd+ip-1]); ip = ip + 1) + ; + colonkey = Memc[cmd+ip-1] + + switch (colonkey) { + case 'm', 'n': + + # Show/set fitpsf parameters. + if (Memc[cmd+ip] != EOS && Memc[cmd+ip] != ' ') { + call apsfcolon (ap, im, cl, out, stid, ltid, Memc[cmd], + newimage, newbuf, newfit) + goto endswitch_ + } + + # No coordinate list. + if (cl == NULL) { + if (interactive == YES) + call printf ("No coordinate list\n") + goto endswitch_ + } + + # Get next object from the list. + ip = ip + 1 + prev_num = ltid + if (ctoi (Memc[cmd], ip, req_num) <= 0) + req_num = ltid + 1 + + # Fetch the next object from the list. + if (apgscur (cl, id, xlist, ylist, prev_num, req_num, + ltid) == EOF) { + if (interactive == YES) + call printf ( + "End of coordinate list, use r key to rewind\n") + goto endswitch_ + } + + # Convert the coordinates. + switch (apstati (ap, WCSIN)) { + case WCS_PHYSICAL, WCS_WORLD: + call ap_itol (ap, xlist, ylist, xlist, ylist, 1) + case WCS_TV: + call ap_vtol (im, xlist, ylist, xlist, ylist, 1) + default: + ; + } + + # Move to the next object. + newlist = YES + if (colonkey == 'm') { + newbuf = YES + newfit = YES + goto endswitch_ + } + + # Measure the next object. + ier = apsffit (ap, im, xlist, ylist) + if (id != NULL) { + call appfmark (ap, id, apstati (ap, MKPSFBOX)) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + if (interactive == YES) + call ap_qppsf (ap, ier) + if (stid == 1) + call ap_param (ap, out, "fitpsf") + call ap_ppsf (ap, out, stid, ltid, ier) + stid = stid + 1 + newbuf = NO + newfit = NO + + default: + call apsfcolon (ap, im, cl, out, stid, ltid, Memc[cmd], + newimage, newbuf, newfit) + } + + # Reestablish the image viewport and window. + if (newimage == YES) { + if ((id != NULL) && (id != gd)) + call ap_gswv (id, Memc[cmd], im, 4) + req_size = MEMFUDGE * IM_LEN(im,1) * IM_LEN(im,2) * + sizeof (IM_PIXTYPE(im)) + memstat = ap_memstat (cache, req_size, old_size) + if (memstat == YES) + call ap_pcache (im, INDEFI, buf_size) + } + + newimage = NO + + # Plot a centered stellar radial profile. + case 'd': + if (interactive == YES) { + call ap_qrad (ap, im, wx, wy, gd) + newbuf = YES + newfit = YES + } + + # Verify the parameters interactively. + case 'v': + call ap_pfconfirm (ap, out, stid) + newbuf = YES + newfit = YES + + # Interactively set up fitpsf parameters. + case 'i': + if (interactive == YES) { + call ap_pfradsetup (ap, im, wx, wy, gd, out, stid) + newbuf = YES + newfit = YES + } + + # Save the parameters. + case 'w': + call ap_ppfpars (ap) + + # Fit the PSF and save the results. + case 'f', ' ': + if (newbuf == YES) + ier = apsffit (ap, im, wx, wy) + else if (newfit == YES) + ier = apsfrefit (ap, im) + if (id != NULL) { + call appfmark (ap, id, apstati (ap, MKPSFBOX)) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + if (interactive == YES) + call ap_qppsf (ap, ier) + newbuf = NO + newfit = NO + + if (key == ' ') { + if (stid == 1) + call ap_param (ap, out, "fitpsf") + if (newlist == YES) + call ap_ppsf (ap, out, stid, ltid, ier) + else + call ap_ppsf (ap, out, stid, 0, ier) + stid = stid + 1 + } + + + # Get, measure the next star in the coordinate list. + case 'm', 'n': + + # No coordinate file. + if (cl == NULL) { + if (interactive == YES) + call printf ("No coordinate list\n") + goto endswitch_ + } + + prev_num = ltid + req_num = ltid + 1 + if (apgscur (cl, id, xlist, ylist, prev_num, req_num, + ltid) == EOF) { + if (interactive == YES) + call printf ( + "End of coordinate list, use r key to rewind\n") + goto endswitch_ + } + + # Convert coordinates if necessary. + switch (apstati (ap, WCSIN)) { + case WCS_PHYSICAL, WCS_WORLD: + call ap_itol (ap, xlist, ylist, xlist, ylist, 1) + case WCS_TV: + call ap_vtol (im, xlist, ylist, xlist, ylist, 1) + default: + ; + } + + # Move to next object. + newlist = YES + if (key == 'm') { + newbuf = YES + newfit = YES + goto endswitch_ + } + + # Measure next object. + ier = apsffit (ap, im, xlist, ylist) + if (id != NULL) { + call appfmark (ap, id, apstati (ap, MKPSFBOX)) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + if (interactive == YES) + call ap_qppsf (ap, ier) + if (stid == 1) + call ap_param (ap, out, "fitpsf") + call ap_ppsf (ap, out, stid, ltid, ier) + stid = stid + 1 + newbuf = NO + newfit = NO + + # Process the remainder of the coordinate list. + case 'l': + if (cl != NULL) { + oid = stid + ltid = ltid + 1 + call apbfitpsf (ap, im, cl, out, id, stid, ltid, YES) + ltid = ltid + stid - oid + 1 + if (id != NULL) { + if (id == gd) + call gflush (id) + else + call gframe (id) + } + } else if (interactive == YES) + call printf ("No coordinate list\n") + + default: + # do nothing + call printf ("Unknown keystroke command\n") + } + +endswitch_ + # Setup for the next object by setting the default keystroke + # command and storing the old cursor coordinates in the + # centering structure. + + key = ' ' + Memc[cmd] = EOS + call apsetr (ap, WX, apstatr (ap, CWX)) + call apsetr (ap, WY, apstatr (ap, CWY)) + + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/fitpsf/apgpfpars.x b/noao/digiphot/apphot/fitpsf/apgpfpars.x new file mode 100644 index 00000000..ed4b93ab --- /dev/null +++ b/noao/digiphot/apphot/fitpsf/apgpfpars.x @@ -0,0 +1,40 @@ +include "../lib/display.h" +include "../lib/noise.h" +include "../lib/fitpsf.h" + +# AP_GPFPARS -- Procedure to fetch the fitpsf parameters. + +procedure ap_gpfpars (ap) + +pointer ap # pointer to the apphot structure + +int function +pointer sp, str +bool clgetb() +int clgeti(), btoi(), clgwrd() +real clgetr() + +begin + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + + # Open the apphot structure. + call apsfinit (ap, AP_RADGAUSS, 3.5, 2.0, AP_NPOISSON) + call apsetr (ap, PSFAPERT, clgetr ("box") / 2.0) + + # Get the data dependent parameters. + call ap_gdapars (ap) + + # Get the rest of the FITPSF fitting parameters. + function = clgwrd ("function", Memc[str], SZ_LINE, PSFFUNCS) + call apsets (ap, PSFSTRING, Memc[str]) + call apseti (ap, PSFUNCTION, function) + call apseti (ap, PMAXITER, clgeti ("maxiter")) + call apseti (ap, PNREJECT, clgeti ("nreject")) + call apsetr (ap, PK2, clgetr ("kreject")) + + # Get the plotting parameters. + call apseti (ap, MKPSFBOX, btoi (clgetb ("mkbox"))) + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/fitpsf/appfconfirm.x b/noao/digiphot/apphot/fitpsf/appfconfirm.x new file mode 100644 index 00000000..30e111b2 --- /dev/null +++ b/noao/digiphot/apphot/fitpsf/appfconfirm.x @@ -0,0 +1,58 @@ +include "../lib/apphot.h" +include "../lib/noise.h" +include "../lib/fitpsf.h" + +# AP_PFCONFIRM -- Procedure to confirm the critical fitpsf parameters. + +procedure ap_pfconfirm (ap, out, stid) + +pointer ap # pointer to the apphot structure +int out # the output file descriptor +int stid # the output file sequence number + +pointer sp, str +real fwhmpsf, psfapert, datamin, datamax +int apstati() +real apstatr(), ap_vfwhmpsf(), ap_vpsfapert() +real ap_vdatamin(), ap_vdatamax() + +begin + call smark (sp) + call salloc (str, SZ_FNAME, TY_CHAR) + + call printf ("\n") + + # Confirm the fitting function. + call ap_vpfstring (ap, Memc[str], SZ_FNAME) + + # Confirm the fwhmpsf. + if (apstati (ap, PSFUNCTION) != AP_MOMENTS) + fwhmpsf = ap_vfwhmpsf (ap) + else + fwhmpsf = apstatr (ap, FWHMPSF) + + # Confirm the fitting box. + psfapert = 2.0 * ap_vpsfapert (ap) + + # Confirm the good data minimum and maximum values. + datamin = ap_vdatamin (ap) + datamax = ap_vdatamax (ap) + + call printf ("\n") + + # Update the database file. + if (out != NULL && stid > 1) { + call ap_sparam (out, KY_PSFSTRING, Memc[str], UN_PSFMODEL, + "psf fitting function") + call ap_rparam (out, KY_FWHMPSF, fwhmpsf, UN_ASCALEUNIT, + "full width half maximum of the psf") + call ap_rparam (out, KY_PSFAPERT, psfapert, UN_PSFSCALEUNIT, + "width of fitting box") + call ap_rparam (out, KY_DATAMIN, datamin, UN_ACOUNTS, + "minimum good data value") + call ap_rparam (out, KY_DATAMAX, datamax, UN_ACOUNTS, + "maximum good data value") + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/fitpsf/appferrors.x b/noao/digiphot/apphot/fitpsf/appferrors.x new file mode 100644 index 00000000..20ed8820 --- /dev/null +++ b/noao/digiphot/apphot/fitpsf/appferrors.x @@ -0,0 +1,26 @@ +include "../lib/fitpsf.h" + +# AP_PFERRORS -- Print detailed fitpsf error messages on the standard output. + +procedure ap_pferrors (ap, ier) + +pointer ap # pointer to apphot structure (unused) +int ier # integer error code + +begin + switch (ier) { + case AP_NOPSFAREA: + call printf ( + "The psf fitting aperture is outside the image.\n") + case AP_PSF_OUTOFBOUNDS: + call printf ( + "The psf fitting aperture is partially outside the image.\n") + case AP_NPSF_TOO_SMALL: + call printf ( + "The number of data points is too few for psf fitting.\n") + case AP_PSF_SINGULAR: + call printf ("The psf fitting solution is singular.\n") + case AP_PSF_NOCONVERGE: + call printf ("The psf fitting solution did not converge.\n") + } +end diff --git a/noao/digiphot/apphot/fitpsf/appfradsetup.x b/noao/digiphot/apphot/fitpsf/appfradsetup.x new file mode 100644 index 00000000..aaae9be6 --- /dev/null +++ b/noao/digiphot/apphot/fitpsf/appfradsetup.x @@ -0,0 +1,86 @@ +define HELPFILE "apphot$fitpsf/ifitpsf.key" + +# AP_PFRADSETUP -- Procedure to set up fitpsf interactively + +procedure ap_pfradsetup (ap, im, wx, wy, gd, out, stid) + +pointer ap # pointer to apphot structure +pointer im # pointer to to the IRAF image +real wx, wy # cursor coordinates +pointer gd # pointer to graphics stream +int out # output file descriptor +int stid # output file sequence number + +int ier, wcs, key +pointer sp, cmd +real xcenter, ycenter, rmin, rmax, imin, imax, xc, yc, rval +real u1, u2, v1, v2, x1, x2, y1, y2 + +int apsffit(), clgcur(), ap_showplot() +real ap_cfwhmpsf(), ap_cpapert(), ap_cdatamin(), ap_cdatamax() + +begin + if (gd == NULL) + return + call greactivate (gd, 0) + call gclear (gd) + + # Save old viewport and window coordinates + call ggview (gd, u1, u2, v1, v2) + call ggwind (gd, x1, x2, y1, y2) + + # plot the radial profile. + if (ap_showplot (ap, im, wx, wy, gd, xcenter, ycenter, rmin, rmax, + imin, imax) == ERR) { + call gdeactivate (gd, 0) + return + } + + # Allocate temporary space. + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + call printf ( + "Waiting for setup menu command (?=help, v=default setup, q=quit):\n") + while (clgcur ("gcommands", xc, yc, wcs, key, Memc[cmd], SZ_LINE) != + EOF) { + + switch (key) { + + case 'q': + break + case '?': + call gpagefile (gd, HELPFILE, "") + case 'f': + rval = ap_cfwhmpsf (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'l': + rval = ap_cdatamin (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'u': + rval = ap_cdatamax (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'b': + rval = ap_cpapert (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'v': + rval = ap_cpapert (ap, gd, out, stid, rmin, rmax, imin, imax) + rval = ap_cfwhmpsf (ap, gd, out, stid, rmin, rmax, imin, imax) + default: + call printf ("Unknown or ambiguous keystroke command\007\n") + } + call printf ( + "Waiting for setup menu command (?=help, v=default setup, q=quit):\n") + } + + # Interactive setup is complete. + call printf ( + "Interactive setup is complete. Type w to save parameters.\n") + + # Restore old viewport and window coords. + call gsview (gd, u1, u2, v1, v2) + call gswind (gd, x1, x2, y1, y2) + + call gdeactivate (gd, 0) + call sfree (sp) + + # Fit the object. + ier = apsffit (ap, im, xcenter, ycenter) + call ap_qppsf (ap, ier) +end diff --git a/noao/digiphot/apphot/fitpsf/apppfpars.x b/noao/digiphot/apphot/fitpsf/apppfpars.x new file mode 100644 index 00000000..58f40bcf --- /dev/null +++ b/noao/digiphot/apphot/fitpsf/apppfpars.x @@ -0,0 +1,34 @@ +include "../lib/fitpsf.h" +include "../lib/display.h" + +# AP_PPFPARS -- Procedure to write the fitpsf parameters to a parameter file. + +procedure ap_ppfpars (ap) + +pointer ap # pointer to apphot structure + +pointer sp, str +bool itob() +int apstati() +real apstatr() + +begin + # Initialize and open psets. + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + + # Store the psf fitting parameters. + call clputr ("box", 2.0 * apstatr (ap, PSFAPERT)) + call apstats (ap, PSFSTRING, Memc[str], SZ_FNAME) + call clpstr ("function", Memc[str]) + call clputi ("maxiter", apstati (ap, PMAXITER)) + call clputr ("kreject", apstatr (ap, PK2)) + call clputi ("nreject", apstati (ap, PNREJECT)) + call clputb ("mkbox", itob (apstati (ap, MKPSFBOX))) + + # Store the data dependent parameters. + call ap_dapars (ap) + + # Closeup. + call sfree (sp) +end diff --git a/noao/digiphot/apphot/fitpsf/apppsf.x b/noao/digiphot/apphot/fitpsf/apppsf.x new file mode 100644 index 00000000..c3604c87 --- /dev/null +++ b/noao/digiphot/apphot/fitpsf/apppsf.x @@ -0,0 +1,123 @@ +include "../lib/apphotdef.h" +include "../lib/fitpsfdef.h" +include "../lib/apphot.h" +include "../lib/fitpsf.h" + +# AP_PPSF -- Procedure to write the results of fitpsf to the output file. + +procedure ap_ppsf (ap, fd, id, lid, ier) + +pointer ap # pointer to apphot structure +int fd # output file descriptor +int id # sequence number of star +int lid # list id of star +int ier # comment string + +real apstatr() + +begin + # Initialize. + if (fd == NULL) + return + + # Print the stars id. + call ap_wid (ap, fd, apstatr (ap, OPFXCUR), apstatr (ap, OPFYCUR), id, + lid, '\\') + + # Print the parameters. + call ap_wfres (ap, fd, ier) +end + + +# AP_QPPSF -- Procedure to print the results of fitpsf on the standard output +# in short form. + +procedure ap_qppsf (ap, ier) + +pointer ap # pointer to apphot structure +int ier # comment string + +pointer sp, imname, psf + +begin + # Initialize. + call smark (sp) + call salloc (imname, SZ_FNAME, TY_CHAR) + psf = AP_PPSF(ap) + + # Print the parameters on the standard output. + call apstats (ap, IMROOT, Memc[imname], SZ_FNAME) + switch (AP_PSFUNCTION(psf)) { + case AP_RADGAUSS: + call printf ( + "%s %8.2f %8.2f %6.3f %8g %8g %s\n") + call pargstr (Memc[imname]) + call pargr (Memr[AP_PPARS(psf)+1]) + call pargr (Memr[AP_PPARS(psf)+2]) + call pargr (Memr[AP_PPARS(psf)+3]) + call pargr (Memr[AP_PPARS(psf)]) + call pargr (Memr[AP_PPARS(psf)+4]) + if (ier != AP_OK) + call pargstr ("err") + else + call pargstr ("ok") + case AP_ELLGAUSS: + call printf ("%s %8.2f %8.2f %6.3f %6.3f ") + call pargstr (Memc[imname]) + call pargr (Memr[AP_PPARS(psf)+1]) + call pargr (Memr[AP_PPARS(psf)+2]) + call pargr (Memr[AP_PPARS(psf)+3]) + call pargr (Memr[AP_PPARS(psf)+4]) + call printf ("%6.1f %8g %8g %s\n") + call pargr (Memr[AP_PPARS(psf)+5]) + call pargr (Memr[AP_PPARS(psf)]) + call pargr (Memr[AP_PPARS(psf)+6]) + if (ier != AP_OK) + call pargstr ("err") + else + call pargstr ("ok") + case AP_MOMENTS: + call printf ("%s %8.2f %8.2f %6.3f %6.3f ") + call pargstr (Memc[imname]) + call pargr (Memr[AP_PPARS(psf)+1]) + call pargr (Memr[AP_PPARS(psf)+2]) + call pargr (Memr[AP_PPARS(psf)+3]) + call pargr (Memr[AP_PPARS(psf)+4]) + call printf ("%6.1f %8g %8g %s\n") + call pargr (Memr[AP_PPARS(psf)+5]) + call pargr (Memr[AP_PPARS(psf)]) + call pargr (Memr[AP_PPARS(psf)+6]) + if (ier != AP_OK) + call pargstr ("err") + else + call pargstr ("ok") + } + + call sfree (sp) +end + + +# AP_PFHDR -- Procedure to write the banner for the fitpsf output file. + +procedure ap_pfhdr (ap, fd) + +pointer ap # pointer to the apphot strucuture +int fd # output file descriptor + +int apstati() + +begin + if (fd == NULL) + return + + switch (apstati (ap, PSFUNCTION)) { + case AP_RADGAUSS: + call radhdr (ap, fd) + case AP_ELLGAUSS: + call elhdr (ap, fd) + case AP_MOMENTS: + call momhdr (ap, fd) + default: + ; + } +end diff --git a/noao/digiphot/apphot/fitpsf/appsfshow.x b/noao/digiphot/apphot/fitpsf/appsfshow.x new file mode 100644 index 00000000..3317bd22 --- /dev/null +++ b/noao/digiphot/apphot/fitpsf/appsfshow.x @@ -0,0 +1,59 @@ +include "../lib/display.h" +include "../lib/fitpsf.h" + +# AP_PSFSHOW -- Procedure to print the fitpsf parameters on the standard output. + +procedure ap_psfshow (ap) + +pointer ap # pointer to the apphot structure + +begin + call ap_nshow (ap) + call printf ("\n") + call ap_pfshow (ap) +end + + +# AP_PFSHOW -- Procedure to print out the fitting parameters on the standard +# output. + +procedure ap_pfshow (ap) + +pointer ap # pointer to apphot structure + +pointer sp, str +bool itob() +int apstati() +real apstatr() + +begin + # Print the PSF fitting parameters. + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + + call printf ("Psf Modelling Parameters\n") + call apstats (ap, PSFSTRING, Memc[str], SZ_FNAME) + call printf (" %s = %s\n") + call pargstr (KY_PSFSTRING) + call pargstr (Memc[str]) + + call printf (" %s = %g %s %s = %d\n") + call pargstr (KY_PSFAPERT) + call pargr (2.0 * apstatr (ap, PSFAPERT)) + call pargstr (UN_PSFSCALEUNIT) + call pargstr (KY_PMAXITER) + call pargi (apstati (ap, PMAXITER)) + + call printf (" %s = %g %s %s = %d\n") + call pargstr (KY_PK2) + call pargr (apstatr (ap, PK2)) + call pargstr (UN_PSFSIGMA) + call pargstr (KY_PNREJECT) + call pargi (apstati (ap, PNREJECT)) + + call printf (" %s = %b\n") + call pargstr (KY_MKPSFBOX) + call pargb (itob (apstati (ap, MKPSFBOX))) + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/fitpsf/apsfcolon.x b/noao/digiphot/apphot/fitpsf/apsfcolon.x new file mode 100644 index 00000000..cb4d4521 --- /dev/null +++ b/noao/digiphot/apphot/fitpsf/apsfcolon.x @@ -0,0 +1,238 @@ +include "../lib/apphot.h" +include "../lib/display.h" +include "../lib/noise.h" +include "../lib/fitpsf.h" + +# APSFCOLON -- Process the fitpsf task colon commands. + +procedure apsfcolon (ap, im, cl, out, stid, ltid, cmdstr, newimage, newbuf, + newfit) + +pointer ap # pointer to the apphot structure +pointer im # pointer to the iraf image +int cl # coordinate file descriptor +int out # output file descriptor +int stid # output file sequence number +int ltid # coord file sequence number +char cmdstr # command string +int newimage # new image ? +int newbuf # new psf buffer ? +int newfit # new psf fit ? + +int junk +pointer sp, incmd, outcmd +int strdic() + +begin + call smark (sp) + call salloc (incmd, SZ_LINE, TY_CHAR) + call salloc (outcmd, SZ_LINE, TY_CHAR) + + # Get the command. + call sscan (cmdstr) + call gargwrd (Memc[incmd], SZ_LINE) + if (Memc[incmd] == EOS) { + call sfree (sp) + return + } + + # Process the command. + if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, PSFCMDS) != 0) + call ap_fitcolon (ap, out, stid, cmdstr, newbuf, newfit) + else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, APCMDS) != 0) + call ap_apcolon (ap, im, cl, out, stid, ltid, cmdstr, newimage, + junk, junk, junk, junk, newbuf, newfit) + else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, NCMDS) != 0) + call apnscolon (ap, im, out, stid, cmdstr, junk, junk, + junk, junk, newbuf, newfit) + else + call ap_pfimcolon (ap, cmdstr) + + call sfree (sp) +end + + +# AP_FITCOLON -- Procedure to show/set the fitpsf parameters. + +procedure ap_fitcolon (ap, out, stid, cmdstr, newbuf, newfit) + +pointer ap # pointer to the apphot structure +int out # output file descriptor +int stid # output file sequence number +char cmdstr # command string +int newbuf # new psf buffer +int newfit # new psf fit + +bool bval +int ncmd, ival, stat +pointer sp, cmd, str +real rval + +bool itob() +int nscan(), strdic(), apstati(), btoi() +real apstatr() + +begin + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + call salloc (str, SZ_FNAME, TY_CHAR) + + # Get the command. + call sscan (cmdstr) + call gargwrd (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call sfree (sp) + return + } + + # Process the command. + ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, PSFCMDS) + switch (ncmd) { + case PFCMD_FUNCTION: + call gargwrd (Memc[cmd], SZ_LINE) + if (nscan() == 1) { + call apstats (ap, PSFSTRING, Memc[str], SZ_FNAME) + call printf ("%s = %s\n") + call pargstr (KY_PSFSTRING) + call pargstr (Memc[str]) + } else { + stat = strdic (Memc[cmd], Memc[cmd], SZ_LINE, PSFFUNCS) + if (stat > 0) { + call apseti (ap, PSFUNCTION, stat) + call apsets (ap, PSFSTRING, Memc[cmd]) + switch (stat) { + case AP_RADGAUSS: + call apseti (ap, NPARS, 5) + case AP_ELLGAUSS: + call apseti (ap, NPARS, 7) + case AP_MOMENTS: + call apseti (ap, NPARS, 7) + } + if (stid > 1) + call ap_sparam (out, "FUNCTION", Memc[cmd], "model", + "fitting function") + newfit = YES + } + } + case PFCMD_BOX: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_PSFAPERT) + call pargr (2.0 * apstatr (ap, PSFAPERT)) + call pargstr (UN_PSFSCALEUNIT) + } else { + call apsetr (ap, PSFAPERT, rval / 2.0) + if (stid > 1) + call ap_rparam (out, KY_PSFAPERT, rval, UN_PSFSCALEUNIT, + "fitting box width") + newbuf = YES + newfit = YES + } + case PFCMD_KREJECT: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_PK2) + call pargr (apstatr (ap, PK2)) + call pargstr (UN_PSFSIGMA) + } else { + call apsetr (ap, PK2, rval) + if (stid > 1) + call ap_rparam (out, KY_PK2, rval, UN_PSFSIGMA, + "k-sigma rejection criterion") + newfit = YES + } + case PFCMD_MAXITER: + call gargi (ival) + if (nscan () == 1) { + call printf ("%s = %d\n") + call pargstr (KY_PMAXITER) + call pargi (apstati (ap, PMAXITER)) + } else { + call apseti (ap, PMAXITER, ival) + if (stid > 1) + call ap_iparam (out, KY_PMAXITER, ival, UN_PSFNUMBER, + "maximum number of iterations") + newfit = YES + } + case PFCMD_NREJECT: + call gargi (ival) + if (nscan () == 1) { + call printf ("%s = %d\n") + call pargstr (KY_PNREJECT) + call pargi (apstati (ap, PNREJECT)) + } else { + call apseti (ap, PNREJECT, ival) + if (stid > 1) + call ap_iparam (out, KY_PNREJECT, ival, UN_PSFNUMBER, + "maximum number of rejection cycles") + newfit = YES + } + case PFCMD_MKBOX: + call gargb (bval) + if (nscan() == 1) { + call printf ("%s = %b\n") + call pargstr (KY_MKPSFBOX) + call pargb (itob (apstati (ap, MKPSFBOX))) + } else + call apseti (ap, MKPSFBOX, btoi (bval)) + default: + # do nothing gracefully + call printf ("Unknown or ambiguous colon command\n") + } + + call sfree (sp) +end + + +# AP_PFIMCOLON -- Procedure to process fitpsf commands that are not fitpsf +# parameters. + +procedure ap_pfimcolon (ap, cmdstr) + +pointer ap # pointer to the apphot structure +char cmdstr # command string + +int ncmd +pointer sp, cmd +int strdic() + +begin + # Get the command. + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + call sscan (cmdstr) + call gargwrd (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call sfree (sp) + return + } + + # Process the command. + ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, MISC1) + switch (ncmd) { + case ACMD_SHOW: + call gargwrd (Memc[cmd], SZ_LINE) + ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, PFSHOWARGS) + switch (ncmd) { + case PFCMD_DATA: + call printf ("\n") + call ap_nshow (ap) + call printf ("\n") + case PFCMD_FIT: + call printf ("\n") + call ap_pfshow (ap) + call printf ("\n") + default: + call printf ("\n") + call ap_psfshow (ap) + call printf ("\n") + } + default: + call printf ("Unknown or ambigous colon command\7\n") + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/fitpsf/apsfelgauss.x b/noao/digiphot/apphot/fitpsf/apsfelgauss.x new file mode 100644 index 00000000..df1a9ef4 --- /dev/null +++ b/noao/digiphot/apphot/fitpsf/apsfelgauss.x @@ -0,0 +1,185 @@ +include <math.h> +include <math/nlfit.h> +include "../lib/noise.h" +include "../lib/fitpsf.h" + +define NPARAMETERS 7 +define TOL 0.001 + +# APSFELGAUSS -- Procedure to fit an elliptical Gaussian function to the +# stellar data. + +int procedure apsfelgauss (ctrpix, nx, ny, emission, fwhmpsf, datamin, + datamax, noise, gain, sigma, maxiter, k2, nreject, par, perr, npar) + +real ctrpix[nx,ny] # object to be centered +int nx, ny # dimensions of subarray +int emission # emission or absorption object +real fwhmpsf # full width half max of the psf +real datamin # minimum good data value +real datamax # maximum good data value +int noise # noise model +real gain # the gain parameter +real sigma # constant term to noise +int maxiter # maximum number of iterations +real k2 # k-sigma rejection criterion +int nreject # maximum number of rejection cycles +real par[ARB] # parameters +real perr[ARB] # errors in parameters +int npar # number of parameters + +extern elgauss, delgauss +int i, j, npts, fier, imin,imax +pointer sp, x, w, list, zfit, nl, ptr +real sumw, dummy, chisqr, locut, hicut, ptemp +int locpr(), apreject() +real asumr(), apwssqr() + +begin + # Initialize. + npts = nx * ny + if (npts < NPARAMETERS) + return (AP_NPSF_TOO_SMALL) + + # Allocate working space. + call smark (sp) + call salloc (x, 2 * npts, TY_REAL) + call salloc (w, npts, TY_REAL) + call salloc (zfit, npts, TY_REAL) + call salloc (list, NPARAMETERS, TY_INT) + + # Define the active parameters. + do i = 1, NPARAMETERS + Memi[list+i-1] = i + + # Set up the varaibles array. + ptr = x + do j = 1, ny { + do i = 1, nx { + Memr[ptr] = i + Memr[ptr+1] = j + ptr = ptr + 2 + } + } + + # Set up the weight array. + switch (noise) { + case AP_NCONSTANT: + call amovkr (1.0, Memr[w], npts) + case AP_NPOISSON: + call amaxkr (ctrpix, 0.0, Memr[w], npts) + if (gain > 0.0) + call adivkr (Memr[w], gain, Memr[w], npts) + if (! IS_INDEFR(sigma)) + call aaddkr (Memr[w], sigma ** 2, Memr[w], npts) + call apreciprocal (Memr[w], Memr[w], npts, 1.0) + default: + call amovkr (1.0, Memr[w], npts) + } + + # Make an initial guess at the fitting parameters. + if (emission == YES) + call ap_wlimr (ctrpix, Memr[w], nx * ny, datamin, datamax, + par[7], par[1], imin, imax) + else + call ap_wlimr (ctrpix, Memr[w], nx * ny, datamin, datamax, + par[7], par[1], imax, imin) + par[1] = par[1] - par[7] + if (mod (imax, nx) == 0) + imin = imax / nx + else + imin = imax / nx + 1 + par[3] = imin + imin = imax - (imin - 1) * nx + par[2] = imin + par[4] = (fwhmpsf ** 2 / 4.0) + par[5] = (fwhmpsf ** 2 / 4.0) + par[6] = 0.0 + + # Get the centers and errors. + call nlinitr (nl, locpr (elgauss), locpr (delgauss), par, perr, + NPARAMETERS, Memi[list], NPARAMETERS, TOL, maxiter) + call nlfitr (nl, Memr[x], ctrpix, Memr[w], npts, 2, WTS_USER, fier) + + # Perform the rejection cycle. + if (nreject > 0 && k2 > 0.0) { + do i = 1, nreject { + call nlvectorr (nl, Memr[x], Memr[zfit], npts, 2) + call asubr (ctrpix, Memr[zfit], Memr[zfit], npts) + chisqr = apwssqr (Memr[zfit], Memr[w], npts) + sumw = asumr (Memr[w], npts) + if (sumw <= 0.0) + break + else if (chisqr <= 0.0) + break + else + chisqr = sqrt (chisqr / sumw) + locut = - k2 * chisqr + hicut = k2 * chisqr + if (apreject (Memr[zfit], Memr[w], npts, locut, hicut) == 0) + break + call nlpgetr (nl, par, npar) + call nlfreer (nl) + call nlinitr (nl, locpr (elgauss), locpr (delgauss), par, + perr, NPARAMETERS, Memi[list], NPARAMETERS, TOL, maxiter) + call nlfitr (nl, Memr[x], ctrpix, Memr[w], npts, 2, WTS_USER, + fier) + } + } + + # Fetch the parameters. + call nlvectorr (nl, Memr[x], Memr[zfit], npts, 2) + call nlpgetr (nl, par, npar) + par[4] = sqrt (abs(par[4])) + par[5] = sqrt (abs(par[5])) + + # Fetch the errors. + call nlerrorsr (nl, ctrpix, Memr[zfit], Memr[w], npts, dummy, + chisqr, perr) + perr[4] = sqrt (perr[4]) + perr[5] = sqrt (perr[5]) + + # Compute the mean errors. + dummy = 0.0 + do i = 1, npts { + if (Memr[w+i-1] > 0.0) + dummy = dummy + 1.0 + } + dummy = sqrt (dummy) + if (dummy > 0.0) + call adivkr (perr, dummy, perr, npar) + + # Transform the parameters. + par[6] = mod (RADTODEG(par[6]), 360.0) + if (par[6] < 0.0) + par[6] = 360.0 + par[6] + if (par[6] > 90.0 && par[6] <= 270.0) + par[6] = par[6] - 180.0 + else if (par[6] > 270.0 && par[6] <= 360.0) + par[6] = par[6] - 360.0 + if (par[5] > par[4]) { + if (par[6] > 0.0) + par[6] = par[6] - 90.0 + else if (par[6] < 0.0) + par[6] = par[6] + 90.0 + ptemp = par[4] + par[4] = par[5] + par[5] = ptemp + } + perr[6] = mod (RADTODEG(perr[6]), 360.0) + + call nlfreer (nl) + + call sfree (sp) + + # Return the appropriate error code. + if (fier == NO_DEG_FREEDOM) { + return (AP_NPSF_TOO_SMALL) + } else if (fier == SINGULAR) { + return (AP_PSF_SINGULAR) + } else if (fier == NOT_DONE) { + return (AP_PSF_NOCONVERGE) + } else { + return (AP_OK) + } +end diff --git a/noao/digiphot/apphot/fitpsf/apsffit.x b/noao/digiphot/apphot/fitpsf/apsffit.x new file mode 100644 index 00000000..2e6d6dbc --- /dev/null +++ b/noao/digiphot/apphot/fitpsf/apsffit.x @@ -0,0 +1,136 @@ +include <mach.h> +include "../lib/apphotdef.h" +include "../lib/apphot.h" +include "../lib/fitpsfdef.h" +include "../lib/noisedef.h" +include "../lib/fitpsf.h" + +# APSFFIT -- Procedure to fit an analytic function to the PSF. + +int procedure apsffit (ap, im, wx, wy) + +pointer ap # pointer to the apphot structure +pointer im # pointer to the IRAF image +real wx, wy # object coordinates + +int ier, fier +pointer psf, nse +real datamin, datamax, dmin, dmax, threshold +int apfbuf(), apsfradgauss(), apsfelgauss(), apsfmoments() + +begin + # Initialize. + psf = AP_PPSF(ap) + nse = AP_NOISE(ap) + AP_PFXCUR(psf) = wx + AP_PFYCUR(psf) = wy + if (IS_INDEFR(wx) || IS_INDEFR(wy)) { + AP_OPFXCUR(psf) = INDEFR + AP_OPFYCUR(psf) = INDEFR + } else { + switch (AP_WCSOUT(ap)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_ltoo (ap, wx, wy, AP_OPFXCUR(psf), AP_OPFYCUR(psf), 1) + case WCS_TV: + call ap_ltov (im, wx, wy, AP_OPFXCUR(psf), AP_OPFYCUR(psf), 1) + default: + AP_OPFXCUR(psf) = wx + AP_OPFYCUR(psf) = wy + } + } + call amovkr (INDEFR, Memr[AP_PPARS(psf)], AP_MAXNPARS(psf)) + call amovkr (INDEFR, Memr[AP_PPERRS(psf)], AP_MAXNPARS(psf)) + + # Fetch the buffer of pixels. + ier = apfbuf (ap, im, wx, wy) + if (ier == AP_NOPSFAREA) + return (AP_NOPSFAREA) + + # Compute the min and max of the data subraster. + if (IS_INDEFR(AP_DATAMIN(ap))) + datamin = -MAX_REAL + else + datamin = AP_DATAMIN(ap) + if (IS_INDEFR(AP_DATAMAX(ap))) + datamax = MAX_REAL + else + datamax = AP_DATAMAX(ap) + + switch (AP_PSFUNCTION(psf)) { + + case AP_RADGAUSS: + + fier = apsfradgauss (Memr[AP_PSFPIX(psf)], AP_PNX(psf), AP_PNY(psf), + AP_POSITIVE(ap), AP_FWHMPSF(ap) * AP_SCALE(ap), datamin, + datamax, AP_NOISEFUNCTION(nse), AP_EPADU(nse), + AP_READNOISE(nse) / AP_EPADU(nse), AP_PMAXITER(psf), + AP_PK2(psf), AP_PNREJECT(psf), Memr[AP_PPARS(psf)], + Memr[AP_PPERRS(psf)], AP_PSFNPARS(psf)) + + Memr[AP_PPARS(psf)+1] = Memr[AP_PPARS(psf)+1] + wx - AP_PXC(psf) + Memr[AP_PPARS(psf)+2] = Memr[AP_PPARS(psf)+2] + wy - AP_PYC(psf) + + case AP_ELLGAUSS: + + fier = apsfelgauss (Memr[AP_PSFPIX(psf)], AP_PNX(psf), AP_PNY(psf), + AP_POSITIVE(ap), AP_FWHMPSF(ap) * AP_SCALE(ap), datamin, + datamax, AP_NOISEFUNCTION(nse), AP_EPADU(nse), + AP_READNOISE(nse) / AP_EPADU(nse), AP_PMAXITER(psf), + AP_PK2(psf), AP_PNREJECT(psf), Memr[AP_PPARS(psf)], + Memr[AP_PPERRS(psf)], AP_PSFNPARS(psf)) + + Memr[AP_PPARS(psf)+1] = Memr[AP_PPARS(psf)+1] + wx - AP_PXC(psf) + Memr[AP_PPARS(psf)+2] = Memr[AP_PPARS(psf)+2] + wy - AP_PYC(psf) + + case AP_MOMENTS: + + call alimr (Memr[AP_PSFPIX(psf)], AP_PNX(psf) * AP_PNY(psf), + dmin, dmax) + dmin = max (dmin, datamin) + dmax = min (dmax, datamax) + threshold = 0.0 + + if (AP_POSITIVE(ap) == YES) + fier = apsfmoments (Memr[AP_PSFPIX(psf)], AP_PNX(psf), + AP_PNY(psf), dmin + threshold, dmax, + AP_POSITIVE(ap), Memr[AP_PPARS(psf)], Memr[AP_PPERRS(psf)], + AP_PSFNPARS(psf)) + else + fier = apsfmoments (Memr[AP_PSFPIX(psf)], AP_PNX(psf), + AP_PNY(psf), dmax - threshold, dmin, + AP_POSITIVE(ap), Memr[AP_PPARS(psf)], + Memr[AP_PPERRS(psf)], AP_PSFNPARS(psf)) + + Memr[AP_PPARS(psf)+1] = Memr[AP_PPARS(psf)+1] + wx - AP_PXC(psf) + Memr[AP_PPARS(psf)+2] = Memr[AP_PPARS(psf)+2] + wy - AP_PYC(psf) + + default: + + # do nothing gracefully + + } + + switch (AP_WCSOUT(ap)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_ltoo (ap, Memr[AP_PPARS(psf)+1], Memr[AP_PPARS(psf)+2], + Memr[AP_PPARS(psf)+1], Memr[AP_PPARS(psf)+2], 1) + case WCS_TV: + call ap_ltov (im, Memr[AP_PPARS(psf)+1], Memr[AP_PPARS(psf)+2], + Memr[AP_PPARS(psf)+1], Memr[AP_PPARS(psf)+2], 1) + default: + ; + } + + # Return the appropriate error code. + if (fier == AP_OK) { + if (ier == AP_PSF_OUTOFBOUNDS) + return (AP_PSF_OUTOFBOUNDS) + else + return (AP_OK) + } else if (fier == AP_NPSF_TOO_SMALL) { + call amovkr (INDEFR, Memr[AP_PPARS(psf)], AP_PSFNPARS(psf)) + call amovkr (INDEFR, Memr[AP_PPERRS(psf)], AP_PSFNPARS(psf)) + return (AP_NPSF_TOO_SMALL) + } else + return (fier) +end diff --git a/noao/digiphot/apphot/fitpsf/apsffree.x b/noao/digiphot/apphot/fitpsf/apsffree.x new file mode 100644 index 00000000..6bac4607 --- /dev/null +++ b/noao/digiphot/apphot/fitpsf/apsffree.x @@ -0,0 +1,52 @@ +include "../lib/apphotdef.h" +include "../lib/fitpsfdef.h" + +# APSFFREE -- Procedure to free the point spread fitting structure. + +procedure apsffree (ap) + +pointer ap # pointer to the apphot structure + +begin + if (ap == NULL) + return + if (AP_NOISE(ap) != NULL) + call ap_noisecls (ap) + if (AP_PDISPLAY(ap) != NULL) + call ap_dispcls (ap) + if (AP_PPSF(ap) != NULL) + call ap_psfcls (ap) + if (AP_IMBUF(ap) != NULL) + call mfree (AP_IMBUF(ap), TY_REAL) + if (AP_MW(ap) != NULL) + call mw_close (AP_MW(ap)) + call mfree (ap, TY_STRUCT) +end + + +# AP_PSFCLS -- Procedure to close up the point spread fitting function +# and arrays + +procedure ap_psfcls (ap) + +pointer ap # pointer to apphot structure + +pointer psf + +begin + if (AP_PPSF(ap) == NULL) + return + psf = AP_PPSF(ap) + #if (AP_PSFPIX(psf) != NULL) + #call mfree (AP_PSFPIX(psf), TY_REAL) + if (AP_PSFXPIX(psf) != NULL) + call mfree (AP_PSFXPIX(psf), TY_REAL) + if (AP_PSFYPIX(psf) != NULL) + call mfree (AP_PSFYPIX(psf), TY_REAL) + if (AP_PPARS(psf) != NULL) + call mfree (AP_PPARS(psf), TY_REAL) + if (AP_PPERRS(psf) != NULL) + call mfree (AP_PPERRS(psf), TY_REAL) + if (AP_PPSF(ap) != NULL) + call mfree (AP_PPSF(ap), TY_STRUCT) +end diff --git a/noao/digiphot/apphot/fitpsf/apsfinit.x b/noao/digiphot/apphot/fitpsf/apsfinit.x new file mode 100644 index 00000000..19e5a42d --- /dev/null +++ b/noao/digiphot/apphot/fitpsf/apsfinit.x @@ -0,0 +1,94 @@ +include "../lib/apphotdef.h" +include "../lib/fitpsfdef.h" +include "../lib/fitpsf.h" + +# APSFINIT - Procedure to initialize the point spread modelling structure. + +procedure apsfinit (ap, function, rbox, fwhmpsf, noise) + +pointer ap # pointer to the apphot structure +int function # fitting function +real rbox # fitting radius +real fwhmpsf # full width half max of psf +int noise # noise model + +begin + # Initialize the image parameters. + call malloc (ap, LEN_APSTRUCT, TY_STRUCT) + + # Set up the global apphot package parameters. + call ap_defsetup (ap, fwhmpsf) + + # Setup noise model. + call ap_noisesetup (ap, noise) + + # Set up the point spread fitting function. + call ap_psfsetup (ap, function, rbox) + + # Set display options. + call ap_dispsetup (ap) + + # Set remaining unused structure pointers to NULL. + AP_PCENTER(ap) = NULL + AP_PSKY(ap) = NULL + AP_PPHOT(ap) = NULL + AP_POLY(ap) = NULL + AP_RPROF(ap) = NULL +end + + +# AP_PSFSETUP -- Procedure to define the PSF fitting parameters. + +procedure ap_psfsetup (ap, function, rbox) + +pointer ap # pointer to apphot structure +int function # fitting function +real rbox # fitting aperture + +pointer psf + +begin + call malloc (AP_PPSF(ap), LEN_PSFSTRUCT, TY_STRUCT) + psf = AP_PPSF(ap) + + # Set PSF fitting function. + AP_PSFUNCTION(psf) = function + switch (function) { + case AP_RADGAUSS: + call strcpy ("radgauss", AP_PSFSTRING(psf), SZ_FNAME) + case AP_ELLGAUSS: + call strcpy ("elgauss", AP_PSFSTRING(psf), SZ_FNAME) + case AP_MOMENTS: + call strcpy ("moments", AP_PSFSTRING(psf), SZ_FNAME) + default: + call strcpy ("radgauss", AP_PSFSTRING(psf), SZ_FNAME) + } + AP_PFXCUR(psf) = INDEFR + AP_PFYCUR(psf) = INDEFR + switch (function) { + case AP_RADGAUSS: + AP_PSFNPARS(psf) = 5 + case AP_ELLGAUSS: + AP_PSFNPARS(psf) = 7 + case AP_MOMENTS: + AP_PSFNPARS(psf) = 7 + } + + # Set remaining PSF parameters. + AP_PSFAPERT(psf) = rbox + AP_MAXNPARS(psf) = DEF_MAXNPARS + AP_PK2(psf) = DEF_PK2 + AP_PMAXITER(psf) = DEF_PMAXITER + AP_PNREJECT(psf) = DEF_PNREJECT + + # Initialize buffers. + AP_LENPSFBUF(psf) = 0 + AP_NPSFPIX(psf) = 0 + AP_PSFPIX(psf) = NULL + AP_PSFXPIX(psf) = NULL + AP_PSFYPIX(psf) = NULL + + # Allocate space for computed parameters. + call calloc (AP_PPARS(psf), AP_MAXNPARS(psf), TY_REAL) + call calloc (AP_PPERRS(psf), AP_MAXNPARS(psf), TY_REAL) +end diff --git a/noao/digiphot/apphot/fitpsf/apsfmoments.x b/noao/digiphot/apphot/fitpsf/apsfmoments.x new file mode 100644 index 00000000..ddae00f2 --- /dev/null +++ b/noao/digiphot/apphot/fitpsf/apsfmoments.x @@ -0,0 +1,106 @@ +include <math.h> +include "../lib/fitpsf.h" + +define NPARAMETERS 7 + +# APSFMOMENTS -- Procedure to compute the 0, 1st and second moments of an +# image and estimate the x,y center, the ellipticity and the position angle. + +int procedure apsfmoments (ctrpix, nx, ny, lthreshold, uthreshold, positive, + par, perr, npar) + +real ctrpix[nx, ny] # object to be centered +int nx, ny # dimensions of subarray +real lthreshold # lower threshold for moment computation +real uthreshold # upper threshold for moment computation +int positive # emission feature +real par[ARB] # parameters +real perr[ARB] # errors in parameters +int npar # number of parameters + +int i, j +real temp, sumi, sumxi, sumyi, sumx2i, sumy2i, sumxyi, r2, varx, vary, varxy +bool fp_equalr() + +begin + # Initialize the sums. + sumi = 0.0 + sumxi = 0.0 + sumyi = 0.0 + sumxyi = 0.0 + sumx2i = 0.0 + sumy2i = 0.0 + + # Accumulate the moments. + if (positive == YES) { + do j = 1, ny { + do i = 1, nx { + if (ctrpix[i,j] > uthreshold) + next + temp = ctrpix[i,j] - lthreshold + if (temp <= 0.0) + next + sumi = sumi + temp + sumxi = sumxi + i * temp + sumyi = sumyi + j * temp + sumxyi = sumxyi + i * j * temp + sumx2i = sumx2i + i * i * temp + sumy2i = sumy2i + j * j * temp + } + } + } else { + do j = 1, ny { + do i = 1, nx { + if (ctrpix[i,j] < uthreshold) + next + temp = lthreshold - ctrpix[i,j] + if (temp <= 0.0) + next + sumi = sumi + temp + sumxi = sumxi + i * temp + sumyi = sumyi + j * temp + sumxyi = sumxyi + i * j * temp + sumx2i = sumx2i + i * i * temp + sumy2i = sumy2i + j * j * temp + } + } + } + + # Compute the parameters. + if (fp_equalr (sumi, 0.0)) { + par[1] = 0.0 + par[2] = (1 + nx) / 2.0 + par[3] = (1 + ny) / 2.0 + par[4] = 0.0 + par[5] = 0.0 + par[6] = 0.0 + par[7] = lthreshold + } else { + par[1] = sumi + par[2] = sumxi / sumi + par[3] = sumyi / sumi + varx = max (0.0, sumx2i / sumi - par[2] ** 2) + vary = max (0.0, sumy2i / sumi - par[3] ** 2) + r2 = varx + vary + if (r2 <= 0.0) { + par[4] = 0.0 + par[5] = 0.0 + par[6] = 0.0 + } else { + par[4] = sqrt (r2) + varxy = sumxyi / sumi - par[2] * par[3] + par[5] = sqrt ((varx - vary) ** 2 + 4.0 * varxy ** 2) / r2 + par[6] = (0.5 * r2 * (1.0 + par[5]) - vary) + if (fp_equalr (par[6], 0.0)) + par[6] = 90.0 + else + par[6] = RADTODEG (atan (varxy / par[6])) + } + par[7] = lthreshold + } + + # Compute the errors. + npar = NPARAMETERS + call amovkr (0.0, perr, NPARAMETERS) + return (AP_OK) +end diff --git a/noao/digiphot/apphot/fitpsf/apsfradgauss.x b/noao/digiphot/apphot/fitpsf/apsfradgauss.x new file mode 100644 index 00000000..0b4a93c6 --- /dev/null +++ b/noao/digiphot/apphot/fitpsf/apsfradgauss.x @@ -0,0 +1,183 @@ +include <math/nlfit.h> +include "../lib/noise.h" +include "../lib/fitpsf.h" + +define NPARAMETERS 5 +define TOL 0.001 + +# APSFRADGAUSS -- Fit a radial Gaussian function to the data. + +int procedure apsfradgauss (ctrpix, nx, ny, emission, fwhmpsf, datamin, + datamax, noise, gain, sigma, maxiter, k2, nreject, par, perr, npar) + +real ctrpix[nx, ny] # object to be centered +int nx, ny # dimensions of subarray +int emission # emission or absorption version +real fwhmpsf # full width half max of the psf +real datamin # minimum good data value +real datamax # maximum good data value +int noise # noise model to be used +real gain # the gain in the data +real sigma # sigma of constant noise term +int maxiter # maximum number of iterations +real k2 # k-sigma rejection criterion +int nreject # maximum number of rejection cycles +real par[ARB] # parameters +real perr[ARB] # errors in parameters +int npar # number of parameters + +extern gaussr, dgaussr +int i, j, npts, list, imin, imax, fier +pointer sp, x, w, zfit, nl, ptr +real sumw, dummy, chisqr, locut, hicut +int locpr(), apreject() +real asumr(), apwssqr() + +begin + # Initialize. + npts = nx * ny + if (npts < NPARAMETERS) + return (AP_NPSF_TOO_SMALL) + + call smark (sp) + call salloc (x, 2 * npts, TY_REAL) + call salloc (w, npts, TY_REAL) + call salloc (zfit, npts, TY_REAL) + call salloc (list, NPARAMETERS, TY_INT) + + # Define the active parameters. + do i = 1, NPARAMETERS + Memi[list+i-1] = i + + # Set variables array. + ptr = x + do j = 1, ny { + do i = 1, nx { + Memr[ptr] = i + Memr[ptr+1] = j + ptr = ptr + 2 + } + } + + # Define the weight array. + switch (noise) { + case AP_NCONSTANT: + call amovkr (1.0, Memr[w], npts) + case AP_NPOISSON: + call amaxkr (ctrpix, 0.0, Memr[w], npts) + if (gain > 0.0) + call adivkr (Memr[w], gain, Memr[w], npts) + if (! IS_INDEFR(sigma)) + call aaddkr (Memr[w], sigma ** 2, Memr[w], npts) + call apreciprocal (Memr[w], Memr[w], npts, 1.0) + default: + call amovkr (1.0, Memr[w], npts) + } + + # Make an initial guess at the parameters. + if (emission == YES) + call ap_wlimr (ctrpix, Memr[w], npts, datamin, datamax, + par[5], par[1], imin, imax) + else + call ap_wlimr (ctrpix, Memr[w], npts, datamin, datamax, + par[1], par[5], imax, imin) + par[1] = par[1] - par[5] + if (mod (imax, nx) == 0) + imin = imax / nx + else + imin = imax / nx + 1 + par[3] = imin + imin = imax - (imin - 1) * nx + par[2] = imin + par[4] = (fwhmpsf ** 2 / 4.0) + + # Fit the function and the errors. + call nlinitr (nl, locpr (gaussr), locpr (dgaussr), par, perr, + NPARAMETERS, Memi[list], NPARAMETERS, TOL, maxiter) + call nlfitr (nl, Memr[x], ctrpix, Memr[w], npts, 2, WTS_USER, fier) + + # Perform the rejection cycle. + if ((nreject > 0) && (k2 > 0.0)) { + do i = 1, nreject { + call nlvectorr (nl, Memr[x], Memr[zfit], npts, 2) + call asubr (ctrpix, Memr[zfit], Memr[zfit], npts) + chisqr = apwssqr (Memr[zfit], Memr[w], npts) + sumw = asumr (Memr[w], npts) + if (sumw <= 0.0) + break + else if (chisqr <= 0.0) + break + else + chisqr = sqrt (chisqr / sumw) + locut = - k2 * chisqr + hicut = k2 * chisqr + if (apreject (Memr[zfit], Memr[w], npts, locut, hicut) == 0) + break + call nlpgetr (nl, par, npar) + call nlfreer (nl) + call nlinitr (nl, locpr (gaussr), locpr (dgaussr), par, perr, + NPARAMETERS, Memi[list], NPARAMETERS, TOL, maxiter) + call nlfitr (nl, Memr[x], ctrpix, Memr[w], npts, 2, WTS_USER, + fier) + } + } + + # Get the parameters. + call nlpgetr (nl, par, npar) + par[4] = sqrt (abs(par[4])) + + # Get the errors. + call nlvectorr (nl, Memr[x], Memr[zfit], npts, 2) + call nlerrorsr (nl, ctrpix, Memr[zfit], Memr[w], npts, dummy, + chisqr, perr) + perr[4] = sqrt (abs(perr[4])) + + # Compute the mean errors in the parameters. + dummy = 0.0 + do i = 1, npts { + if (Memr[w+i-1] > 0.0) + dummy = dummy + 1.0 + } + dummy = sqrt (dummy) + if (dummy > 0.0) + call adivkr (perr, dummy, perr, npar) + + call nlfreer (nl) + + call sfree (sp) + + # Return the appropriate error code. + if (fier == NO_DEG_FREEDOM) { + return (AP_NPSF_TOO_SMALL) + } else if (fier == SINGULAR) { + return (AP_PSF_SINGULAR) + } else if (fier == NOT_DONE) { + return (AP_PSF_NOCONVERGE) + } else { + return (AP_OK) + } +end + + +# APREJECT -- Reject points outside of the specified intensity limits by +# setting their weights to zero. + +int procedure apreject (pix, w, npts, locut, hicut) + +real pix[ARB] # data +real w[ARB] # weights +int npts # number of data points +real locut, hicut # data limits + +int i, nreject + +begin + nreject = 0 + do i = 1, npts { + if ((pix[i] < locut || pix[i] > hicut) && w[i] > 0.0) { + w[i] = 0.0 + nreject = nreject + 1 + } + } + return (nreject) +end diff --git a/noao/digiphot/apphot/fitpsf/apsfrefit.x b/noao/digiphot/apphot/fitpsf/apsfrefit.x new file mode 100644 index 00000000..a1b950fa --- /dev/null +++ b/noao/digiphot/apphot/fitpsf/apsfrefit.x @@ -0,0 +1,113 @@ +include <mach.h> +include "../lib/apphotdef.h" +include "../lib/apphot.h" +include "../lib/fitpsfdef.h" +include "../lib/fitpsf.h" +include "../lib/noisedef.h" + +# APSFREFIT -- Procedure to fit a function to the data already in the +# data buffers. + +int procedure apsfrefit (ap, im) + +pointer ap # pointer to the apphot structure +pointer im # the input image descriptor + +int ier +pointer psf, nse +int apsfradgauss(), apsfelgauss(), apsfmoments() +real datamin, datamax, dmin, dmax, threshold + +begin + psf = AP_PPSF(ap) + nse = AP_NOISE(ap) + call amovkr (INDEFR, Memr[AP_PPARS(psf)], AP_MAXNPARS(psf)) + call amovkr (INDEFR, Memr[AP_PPERRS(psf)], AP_MAXNPARS(psf)) + + # Compute the minimum and maximum good data value. + if (IS_INDEFR(AP_DATAMIN(ap))) + datamin = -MAX_REAL + else + datamin = AP_DATAMIN(ap) + if (IS_INDEFR(AP_DATAMAX(ap))) + datamax = MAX_REAL + else + datamax = AP_DATAMAX(ap) + + switch (AP_PSFUNCTION(psf)) { + + case AP_RADGAUSS: + + ier = apsfradgauss (Memr[AP_PSFPIX(psf)], AP_PNX(psf), AP_PNY(psf), + AP_POSITIVE(ap), AP_FWHMPSF(ap) * AP_SCALE(ap), datamin, + datamax, AP_NOISEFUNCTION(nse), AP_EPADU(nse), + AP_READNOISE(nse) / AP_EPADU(nse), AP_PMAXITER(psf), + AP_PK2(psf), AP_PNREJECT(psf), Memr[AP_PPARS(psf)], + Memr[AP_PPERRS(psf)], AP_PSFNPARS(psf)) + + Memr[AP_PPARS(psf)+1] = Memr[AP_PPARS(psf)+1] + AP_PFXCUR(psf) - + AP_PXC(psf) + Memr[AP_PPARS(psf)+2] = Memr[AP_PPARS(psf)+2] + AP_PFYCUR(psf) - + AP_PYC(psf) + + case AP_ELLGAUSS: + + ier = apsfelgauss (Memr[AP_PSFPIX(psf)], AP_PNX(psf), AP_PNY(psf), + AP_POSITIVE(ap), AP_FWHMPSF(ap) * AP_SCALE(ap), datamin, + datamax, AP_NOISEFUNCTION(nse), AP_EPADU(nse), + AP_READNOISE(nse) / AP_EPADU(nse), AP_PMAXITER(psf), + AP_PK2(psf), AP_PNREJECT(psf), Memr[AP_PPARS(psf)], + Memr[AP_PPERRS(psf)], AP_PSFNPARS(psf)) + + Memr[AP_PPARS(psf)+1] = Memr[AP_PPARS(psf)+1] + AP_PFXCUR(psf) - + AP_PXC(psf) + Memr[AP_PPARS(psf)+2] = Memr[AP_PPARS(psf)+2] + AP_PFYCUR(psf) - + AP_PYC(psf) + + case AP_MOMENTS: + + call alimr (Memr[AP_PSFPIX(psf)], AP_PNX(psf) * AP_PNY(psf), + dmin, dmax) + dmin = max (dmin, datamin) + dmax = min (dmax, datamax) + threshold = 0.0 + + if (AP_POSITIVE(ap) == YES) + ier = apsfmoments (Memr[AP_PSFPIX(psf)], AP_PNX(psf), + AP_PNY(psf), dmin + threshold, dmax, + AP_POSITIVE(ap), Memr[AP_PPARS(psf)], + Memr[AP_PPERRS(psf)], AP_PSFNPARS(psf)) + else + ier = apsfmoments (Memr[AP_PSFPIX(psf)], AP_PNX(psf), + AP_PNY(psf), dmax + threshold, dmin, + AP_POSITIVE(ap), Memr[AP_PPARS(psf)], + Memr[AP_PPERRS(psf)], AP_PSFNPARS(psf)) + + Memr[AP_PPARS(psf)+1] = Memr[AP_PPARS(psf)+1] + AP_PFXCUR(psf) - + AP_PXC(psf) + Memr[AP_PPARS(psf)+2] = Memr[AP_PPARS(psf)+2] + AP_PFYCUR(psf) - + AP_PYC(psf) + + default: + + # do nothing gracefully + } + + switch (AP_WCSOUT(ap)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_ltoo (ap, Memr[AP_PPARS(psf)+1], Memr[AP_PPARS(psf)+2], + Memr[AP_PPARS(psf)+1], Memr[AP_PPARS(psf)+2], 1) + case WCS_TV: + call ap_ltov (im, Memr[AP_PPARS(psf)+1], Memr[AP_PPARS(psf)+2], + Memr[AP_PPARS(psf)+1], Memr[AP_PPARS(psf)+2], 1) + default: + ; + } + + if (ier == AP_NPSF_TOO_SMALL) { + call amovkr (INDEFR, Memr[AP_PPARS(psf)], AP_PSFNPARS(psf)) + call amovkr (INDEFR, Memr[AP_PPERRS(psf)], AP_PSFNPARS(psf)) + } + + return (ier) +end diff --git a/noao/digiphot/apphot/fitpsf/fitpsf.key b/noao/digiphot/apphot/fitpsf/fitpsf.key new file mode 100644 index 00000000..f7ab725e --- /dev/null +++ b/noao/digiphot/apphot/fitpsf/fitpsf.key @@ -0,0 +1,73 @@ + Interactive Keystroke Commands + +? Print help +: Colon commands +v Verify the critical parameters +w Save the current parameters +d Plot radial profile of current star +i Interactively set parameters using current star +f Fit current star +spbar Fit current star, output results +m Move to next star in coordinate list +n Fit next star in coordinate list, output results +l Fit remaining stars in coordinate list, output results +e Print error messages +r Rewind the coordinate list +q Exit task + + + + Colon Commands + +:show [data/fit] List the parameters +:m [n] Move to next [nth] star in coordinate list +:n [n] Fit next [nth] star in coordinate list, output results + + + Colon Parameter Editing Commands + +# Image and file name parameters + +:image [string] Image name +:coords [string] Coordinate file name +:output [string] Output file name + +# Data dependent parameters + +:scale [value] Image scale (units per pixel) +:fwhmpsf [value] Scale factor (scale units) +:emission [y/n] Emission feature (y), absorption (n) +:sigma [value] Standard deviation of sky (counts) +:datamin [value] Minimum good data value (counts) +:datamax [value] Maximum good data value (counts) + +# Noise description parameters + +:noise [string] Noise model (constant|poisson) +:gain [string] Gain image header keyword +:ccdread [string] Readout noise image header keyword +:epadu [value] Gain (electrons per adu) +:readnoise [value] Readnoise (electrons) + +# Observation parameters + +:exposure [string] Exposure time image header keyword +:airmass [string] Airmass image header keyword +:filter [string] Filter image header keyword +:obstime [string] Time of observation image header keyword +:itime [value] Exposure time (time units) +:xairmass [value] Airmass value (number) +:ifilter [string] Filter id string +:otime [string] Time of observation (time units) + +# Fitting parameters + +:function [string] PSF model (radgauss|elgauss|moments) +:box [value] Width of the fitting box (scale units) +:maxiter [value] Maximum number of iterations +:nreject [value] Maximum number of rejection cycles +:kreject [value] Rejection limit (sigma) + +# Plotting and marking functions + +:mkbox [y/n] Mark the fitting box on the display diff --git a/noao/digiphot/apphot/fitpsf/ifitpsf.key b/noao/digiphot/apphot/fitpsf/ifitpsf.key new file mode 100644 index 00000000..9bbb4ba9 --- /dev/null +++ b/noao/digiphot/apphot/fitpsf/ifitpsf.key @@ -0,0 +1,10 @@ + Interactive Fitpsf Setup Menu + + v Mark and verify the critical fitpsf parameters (f,s,b) + + f Mark and verify the full-width half-maximum of the psf + s Mark and verify the standard deviation of the background + l Mark and verify the minimum good data value + u Mark and verify the maximum good data value + + b Mark and verify the half-width of the fitting box diff --git a/noao/digiphot/apphot/fitpsf/mkpkg b/noao/digiphot/apphot/fitpsf/mkpkg new file mode 100644 index 00000000..8e8efb12 --- /dev/null +++ b/noao/digiphot/apphot/fitpsf/mkpkg @@ -0,0 +1,44 @@ +# FITPSF Task Routines + +$checkout libpkg.a ".." +$update libpkg.a +$checkin libpkg.a ".." +$exit + +libpkg.a: + apbfitpsf.x <fset.h> ../lib/apphot.h \ + ../lib/display.h + apfbuf.x <imhdr.h> ../lib/apphotdef.h \ + ../lib/fitpsfdef.h ../lib/fitpsf.h + apfitpsf.x <ctype.h> <gset.h> \ + ../lib/apphot.h ../lib/display.h \ + ../lib/fitpsf.h <imhdr.h> + apppfpars.x ../lib/display.h ../lib/fitpsf.h + apgpfpars.x ../lib/display.h ../lib/fitpsf.h \ + ../lib/noise.h + appfconfirm.x ../lib/apphot.h ../lib/noise.h \ + ../lib/fitpsf.h + appferrors.x ../lib/fitpsf.h + apppsf.x ../lib/apphotdef.h ../lib/fitpsfdef.h \ + ../lib/fitpsf.h ../lib/apphot.h + appsfshow.x ../lib/display.h ../lib/fitpsf.h + appfradsetup.x + apsfcolon.x ../lib/display.h ../lib/fitpsf.h \ + ../lib/apphot.h ../lib/noise.h + apsfelgauss.x <math.h> ../lib/fitpsf.h \ + <math/nlfit.h> ../lib/noise.h + apsffree.x ../lib/apphotdef.h ../lib/fitpsfdef.h + apsfinit.x ../lib/apphotdef.h ../lib/fitpsfdef.h \ + ../lib/fitpsf.h + apsffit.x ../lib/apphotdef.h ../lib/fitpsfdef.h \ + ../lib/noisedef.h ../lib/fitpsf.h \ + ../lib/apphot.h <mach.h> + apsfmoments.x <math.h> ../lib/fitpsf.h + apsfradgauss.x ../lib/fitpsf.h <math/nlfit.h> \ + ../lib/noise.h + apsfrefit.x ../lib/apphotdef.h ../lib/fitpsfdef.h \ + ../lib/fitpsf.h ../lib/noisedef.h \ + ../lib/apphot.h <mach.h> + t_fitpsf.x <fset.h> <gset.h> \ + ../lib/apphot.h <imhdr.h> + ; diff --git a/noao/digiphot/apphot/fitpsf/t_fitpsf.x b/noao/digiphot/apphot/fitpsf/t_fitpsf.x new file mode 100644 index 00000000..28345a09 --- /dev/null +++ b/noao/digiphot/apphot/fitpsf/t_fitpsf.x @@ -0,0 +1,288 @@ +include <gset.h> +include <fset.h> +include <imhdr.h> +include "../lib/apphot.h" + +# T_FITPSF -- Procedure to fit an analytic function to the PSF for a list +# of objects in a list of images. + +procedure t_fitpsf () + +pointer image # pointer to the name of the image +pointer output # pointer to the output file name +pointer coords # pointer to the coordinate file +pointer graphics # pointer to the graphics display device +pointer display # pointer to the display device +int interactive # mode of use +int cache # cache the input image pixels +int verify # verify critical parameters +int update # update the critical parameter +int verbose # verbose mode + +pointer sp, outfname, ap, im, gd, id, cname, str +int cl, out, limlist, lclist, lolist, lid, sid, root, stat, memstat +int imlist, clist, olist, wcs, req_size, buf_size, old_size + +pointer gopen(), immap() +int imtlen(), imtgetim(), clplen(), btoi(), clgfil(), fnldir() +int open(), strncmp(), strlen(), apfitpsf(), imtopenp(), clpopnu() +int clgwrd(), ap_memstat(), sizeof() +bool clgetb(), streq() +errchk gopen + +begin + # Allocate workin space. + call smark (sp) + call salloc (image, SZ_FNAME, TY_CHAR) + call salloc (output, SZ_FNAME, TY_CHAR) + call salloc (coords, SZ_FNAME, TY_CHAR) + call salloc (graphics, SZ_FNAME, TY_CHAR) + call salloc (display, SZ_FNAME, TY_CHAR) + call salloc (outfname, SZ_FNAME, TY_CHAR) + call salloc (cname, SZ_FNAME, TY_CHAR) + call salloc (str, SZ_LINE, TY_CHAR) + + # Set standard output to flush on newline. + call fseti (STDOUT, F_FLUSHNL, YES) + + # Get input image list. + imlist = imtopenp ("image") + limlist = imtlen (imlist) + + # Get input coordinate lists. + clist = clpopnu ("coords") + lclist = clplen (clist) + + # Get output file list and check for zero length list. + olist = clpopnu ("output") + lolist = clplen (olist) + + # Check that image and coordinate list lengths match. + if (limlist < 1 || (lclist > 1 && lclist != limlist)) { + call imtclose (imlist) + call clpcls (clist) + call clpcls (olist) + call error (0, "Imcompatable image and coordinate list lengths") + } + + # Check that image and output list lengths match. + if (lolist > 1 && lolist != limlist) { + call imtclose (imlist) + call clpcls (clist) + call clpcls (olist) + call error (0, "Imcompatable image and output list lengths") + } + + call clgstr ("icommands.p_filename", Memc[cname], SZ_FNAME) + if (Memc[cname] != EOS) + interactive = NO + #else if (lclist == 0) + #interactive = YES + else + interactive = btoi (clgetb ("interactive")) + cache = btoi (clgetb("cache")) + verify = btoi (clgetb ("verify")) + update = btoi (clgetb ("update")) + verbose = btoi (clgetb ("verbose")) + + # Get the parameters. + call ap_gpfpars (ap) + if (verify == YES && interactive == NO) { + call ap_pfconfirm (ap, NULL, 1) + if (update == YES) + call ap_ppfpars (ap) + } + + # Get the wcs information. + wcs = clgwrd ("wcsin", Memc[str], SZ_LINE, WCSINSTR) + if (wcs <= 0) { + call eprintf ( + "Warning: Setting the input coordinate system to logical\n") + wcs = WCS_LOGICAL + } + call apseti (ap, WCSIN, wcs) + wcs = clgwrd ("wcsout", Memc[str], SZ_LINE, WCSOUTSTR) + if (wcs <= 0) { + call eprintf ( + "Warning: Setting the output coordinate system to logical\n") + wcs = WCS_LOGICAL + } + call apseti (ap, WCSOUT, wcs) + + # Get the graphics and display devices. + call clgstr ("graphics", Memc[graphics], SZ_FNAME) + call clgstr ("display", Memc[display], SZ_FNAME) + + # Open the graphics and display devices. + if (interactive == YES) { + if (Memc[graphics] == EOS) + gd = NULL + else { + iferr { + gd = gopen (Memc[graphics], APPEND+AW_DEFER, STDGRAPH) + } then { + call eprintf ( + "Warning: Error opening graphics device.\n") + gd = NULL + } + } + if (Memc[display] == EOS) + id = NULL + else if (streq (Memc[graphics], Memc[display])) + id = gd + else { + iferr { + id = gopen (Memc[display], APPEND, STDIMAGE) + } then { + call eprintf ( + "Warning: Graphics overlay not available for display device.\n") + id = NULL + } + } + } else { + id = NULL + gd = NULL + } + + # Begin looping over the image list. + sid = 1 + while (imtgetim (imlist, Memc[image], SZ_FNAME) != EOF) { + + # Open the image. + im = immap (Memc[image], READ_ONLY, 0) + call apimkeys (ap, im, Memc[image]) + + # Set the image display viewport. + if ((id != NULL) && (id != gd)) + call ap_gswv (id, Memc[image], im, 4) + + # Cache the input image pixels. + req_size = MEMFUDGE * IM_LEN(im,1) * IM_LEN(im,2) * + sizeof (IM_PIXTYPE(im)) + memstat = ap_memstat (cache, req_size, old_size) + if (memstat == YES) + call ap_pcache (im, INDEFI, buf_size) + + # Open coordinate file, where coords is assumed to be a simple text + # file in which the x and y positions are in columns 1 and 2 + # respectively and all remaining fields are ignored. + + if (lclist <= 0) { + cl = NULL + call strcpy ("", Memc[outfname], SZ_FNAME) + } else { + stat = clgfil (clist, Memc[coords], SZ_FNAME) + root = fnldir (Memc[coords], Memc[outfname], SZ_FNAME) + if (strncmp ("default", Memc[coords+root], 7) == 0 || root == + strlen (Memc[coords])) { + call ap_inname (Memc[image], Memc[outfname], "coo", + Memc[outfname], SZ_FNAME) + lclist = limlist + cl = open (Memc[outfname], READ_ONLY, TEXT_FILE) + } else if (stat != EOF) { + call strcpy (Memc[coords], Memc[outfname], SZ_FNAME) + cl = open (Memc[outfname], READ_ONLY, TEXT_FILE) + } else { + call apstats (ap, CLNAME, Memc[outfname], SZ_FNAME) + call seek (cl, BOF) + } + } + call apsets (ap, CLNAME, Memc[outfname]) + call apfroot (Memc[outfname], Memc[str], SZ_LINE) + call apsets (ap, CLROOT, Memc[str]) + + # Open output text file, if output is "default", dir$default or + # a directory specification then the extension "psf" is added on + # to the image name and a suitable version number is appended to + # the output name. If the output string is null then no output + # file is written. + + if (lolist == 0) { + out = NULL + call strcpy ("", Memc[outfname], SZ_FNAME) + } else { + stat = clgfil (olist, Memc[output], SZ_FNAME) + root = fnldir (Memc[output], Memc[outfname], SZ_FNAME) + if (strncmp ("default", Memc[output+root], 7) == 0 || root == + strlen (Memc[output])) { + call apoutname (Memc[image], Memc[outfname], "psf", + Memc[outfname], SZ_FNAME) + out = open (Memc[outfname], NEW_FILE, TEXT_FILE) + lolist = limlist + } else if (stat != EOF) { + call strcpy (Memc[output], Memc[outfname], SZ_FNAME) + out = open (Memc[outfname], NEW_FILE, TEXT_FILE) + } else + call apstats (ap, OUTNAME, Memc[outfname], SZ_FNAME) + } + call apsets (ap, OUTNAME, Memc[outfname]) + + # Fit the PSF. + if (interactive == NO) { + if (Memc[cname] != EOS) + stat = apfitpsf (ap, im, cl, NULL, NULL, out, sid, NO, + cache) + else if (cl != NULL) { + lid = 1 + call apbfitpsf (ap, im, cl, out, id, sid, lid, verbose) + stat = NO + } else + stat = NO + } else + stat = apfitpsf (ap, im, cl, gd, id, out, sid, YES, cache) + + # Cleanup. + call imunmap (im) + if (cl != NULL) { + if (lclist > 1) + call close (cl) + } + if (out != NULL && lolist != 1) { + call close (out) + if (sid <= 1) { + call apstats (ap, OUTNAME, Memc[outfname], SZ_FNAME) + call delete (Memc[outfname]) + } + sid = 1 + } + + # Uncache memory. + call fixmem (old_size) + + if (stat == YES) + break + } + + # Close the plot files. + if (id == gd && id != NULL) + call gclose (id) + else { + if (id != NULL) + call gclose (id) + if (gd != NULL) + call gclose (gd) + } + + # If only one coordinate file for a list of images close file. + if (cl != NULL && lclist == 1) + call close (cl) + + # If only one output file for a list of images close file. + if (out != NULL && lolist == 1) { + call close (out) + if (sid <= 1) { + call apstats (ap, OUTNAME, Memc[outfname], SZ_FNAME) + call delete (Memc[outfname]) + } + } + + # Close up the PSF fitting structure. + call apsffree (ap) + + # Close up the lists. + call imtclose (imlist) + call clpcls (clist) + call clpcls (olist) + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/fitsky.par b/noao/digiphot/apphot/fitsky.par new file mode 100644 index 00000000..3899b0e8 --- /dev/null +++ b/noao/digiphot/apphot/fitsky.par @@ -0,0 +1,21 @@ +# FITSKY + +image,f,a,,,,"The input image(s)" +coords,f,h,"",,,"The input coordinate list(s) (default: image.coo.?)" +output,f,h,"default",,,"The output sky file(s) (default: image.sky.?)" +plotfile,f,h,"",,,"The output metacode plot file" +datapars,pset,h,"",,,"Data dependent parameters" +fitskypars,pset,h,"",,,"Sky fitting parameters" +interactive,b,h,yes,,,"Interactive mode ?" +radplots,b,h,no,,,"Plot radial profiles in interactive mode ?" +icommands,*imcur,h,"",,,"Image cursor: [x y wcs] key [cmd]" +gcommands,*gcur,h,"",,,"Graphics cursor: [x y wcs] key [cmd]" +wcsin,s,h,)_.wcsin,,,"The input coordinate system (logical,tv,physical,world)" +wcsout,s,h,)_.wcsout,,,"The output coordinate system (logical,tv,physical)" +cache,b,h,)_.cache,,,"Cache the input image pixels in memory ?" +verify,b,h,)_.verify,,,"Verify critical parameters in non-interactive mode ?" +update,b,h,)_.update,,,"Update critical parameters in non-interactive mode ?" +verbose,b,h,)_.verbose,,,"Print messages in non-interactive mode ?" +graphics,s,h,)_.graphics,,,"Graphics device" +display,s,h,)_.display,,,"Display device" +mode,s,h,'ql' diff --git a/noao/digiphot/apphot/fitsky/apavsky.x b/noao/digiphot/apphot/fitsky/apavsky.x new file mode 100644 index 00000000..c7e38c0e --- /dev/null +++ b/noao/digiphot/apphot/fitsky/apavsky.x @@ -0,0 +1,107 @@ +include "../lib/display.h" +include "../lib/fitsky.h" + +# AP_AVSKY -- Compute an estimate of the sky value by averaging several +# individual sky values measured in different parts of the frame. + +int procedure ap_avsky (ap, im, stid, sd, id, gd, interactive) + +pointer ap # the pointer to the main apphot data structure +pointer im # the pointer to the input image +int stid # the current sequence number +int sd # the sky file descriptor +pointer id # the display stream descriptor +pointer gd # the graphics stream descriptor +int interactive # interactive mode + +int wcs, key, nmsky, nmsigma, nmskew, nsky, nrej, sier, ier +pointer sp, cmd +real wx, wy, msky, msigma, mskew +int clgcur(), apfitsky(), apstati() +real apstatr() + +begin + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + # Initialize the skyvalues. + msky = 0.0 + nmsky = 0 + msigma = 0.0 + nmsigma = 0 + mskew = 0.0 + nmskew = 0 + nsky = 0 + nrej = 0 + ier = AP_OK + + call printf ( + "\nMeasure sky around several cursor positions (t=measure, q=quit)\n") + while (clgcur ("icommands", wx, wy, wcs, key, Memc[cmd], SZ_LINE) != + EOF) { + + switch (key) { + case 'q': + break + + case 't': + sier = apfitsky (ap, im, wx, wy, sd, gd) + if (sier != AP_OK) + ier = sier + + if (id != NULL) { + call apmark (ap, id, NO, apstati (ap, MKSKY), NO) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_splot (ap, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qspsky (ap, sier) + + if (! IS_INDEFR(apstatr (ap, SKY_MODE))) { + msky = msky + apstatr (ap, SKY_MODE) + nmsky = nmsky + 1 + } + if (! IS_INDEFR(apstatr (ap, SKY_SIGMA))) { + msigma = msigma + apstatr (ap, SKY_SIGMA) + nmsigma = nmsigma + 1 + } + if (! IS_INDEFR(apstatr (ap, SKY_SKEW))) { + mskew = mskew + apstatr (ap, SKY_SKEW) + nmskew = nmskew + 1 + } + nsky = nsky + apstati (ap, NSKY) + nrej = nrej + apstati (ap, NSKY_REJECT) + + default: + ; + } + } + + # Compute the average values. + if (nmsky > 0) + msky = msky / nmsky + else + msky = INDEFR + if (nmsigma > 0) + msigma = msigma / nmsigma + else + msigma = INDEFR + if (nmskew > 0) + mskew = mskew / nmskew + else + mskew = INDEFR + + # Store the average values. + call apsetr (ap, SKY_MODE, msky) + call apsetr (ap, SKY_SIGMA, msigma) + call apsetr (ap, SKY_SKEW, mskew) + call apseti (ap, NSKY, nsky) + call apseti (ap, NSKY_REJECT, nrej) + + call sfree (sp) + + return (ier) +end diff --git a/noao/digiphot/apphot/fitsky/apbsky.x b/noao/digiphot/apphot/fitsky/apbsky.x new file mode 100644 index 00000000..28e96288 --- /dev/null +++ b/noao/digiphot/apphot/fitsky/apbsky.x @@ -0,0 +1,98 @@ +include <fset.h> +include "../lib/apphot.h" +include "../lib/display.h" + +# APBSKY -- Procedure to determine the sky statistics for a list of objects +# in batch mode using a simple coordinate list. + +procedure apbsky (ap, im, cl, sd, out, id, ld, gd, mgd, gid, interactive) + +pointer ap # pointer to apphot structure +pointer im # pointer to IRAF image +int cl # starlist file descriptor +int sd # sky file descriptor +int out # output file descriptor +int id, ld # sequence and list numbers +int gd # pointer to stdgraph stream +pointer mgd # pointer to graphics metacode file +pointer gid # pointer to image display stream +int interactive # interactive mode + +int stdin, ier, ild +pointer sp, str +real wx, wy +int apfitsky(), fscan(), nscan(), strncmp(), apstati() + +begin + call smark (sp) + call salloc (str, SZ_FNAME, TY_CHAR) + call fstats (cl, F_FILENAME, Memc[str], SZ_FNAME) + + # Initialize. + ild = ld + + # Print the query. + if (strncmp ("STDIN", Memc[str], 5) == 0) { + stdin = YES + call printf ("Type object x and y coordinates (^D or ^Z to end): ") + call flush (STDOUT) + } else + stdin = NO + + # Loop over the coordinate file. + while (fscan (cl) != EOF) { + + # Fetch and store the coordinates. + call gargr (wx) + call gargr (wy) + if (nscan () != 2) { + if (stdin == YES) { + call printf ( + "Type object x and y coordinates (^D or ^Z to end): ") + call flush (STDOUT) + } + next + } + + # Transform the input coordinates. + switch (apstati(ap,WCSIN)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_itol (ap, wx, wy, wx, wy, 1) + case WCS_TV: + call ap_vtol (im, wx, wy, wx, wy, 1) + default: + ; + } + call apsetr (ap, CWX, wx) + call apsetr (ap, CWY, wy) + + # Fit the sky value. + ier = apfitsky (ap, im, wx, wy, sd, gd) + + # Print the sky values. + if (interactive == YES) { + call ap_qspsky (ap, ier) + if (gid != NULL) + call apmark (ap, gid, NO, apstati (ap, MKSKY), NO) + } + call ap_splot(ap, id, mgd, YES) + if (id == 1) + call ap_param (ap, out, "fitsky") + call ap_pssky (ap, out, id, ild, ier) + + # Set up for the next object. + id = id + 1 + ild = ild + 1 + call apsetr (ap, WX, wx) + call apsetr (ap, WY, wy) + + # print query + if (stdin == YES) { + call printf ( + "Type object x and y coordinates (^D or ^Z to end): ") + call flush (STDOUT) + } + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/fitsky/apcentroid.x b/noao/digiphot/apphot/fitsky/apcentroid.x new file mode 100644 index 00000000..310db85d --- /dev/null +++ b/noao/digiphot/apphot/fitsky/apcentroid.x @@ -0,0 +1,244 @@ +include <mach.h> +include "../lib/fitsky.h" + +# AP_CENTROID -- Procedure to find the mode, width and skew of the sky +# distribution by computing the moments of the histogram. + +int procedure ap_centroid (skypix, coords, wgt, index, nskypix, snx, sny, k1, + hwidth, binsize, smooth, losigma, hisigma, rgrow, maxiter, sky_mode, + sky_sigma, sky_skew, nsky, nsky_reject) + +real skypix[ARB] # array of sky pixels +int coords[ARB] # array of coordinates for regions growing +real wgt[ARB] # array of weights for rejection +int index[ARB] # array of sorted indices +int nskypix # the number of sky pixels +int snx, sny # the maximum dimensions of sky raster +real k1 # extent of the histogram in skysigma +real hwidth # width of the histogram +real binsize # the size of the histogram in sky sigma +int smooth # smooth the histogram before fitting +real losigma, hisigma # upper and lower k-sigma rejection limits +real rgrow # region growing radius in pixels +int maxiter # maximum number of rejection cycles +real sky_mode # computed sky value +real sky_sigma # computed sigma of the sky pixels +real sky_skew # skew of sky pixels +int nsky # number of sky pixels used in fit +int nsky_reject # number of sky pixels rejected + +double dsky, sumpx, sumsqpx, sumcbpx +int nreject, nbins, nker, ier, i, j +pointer sp, hgm, shgm +real dmin, dmax, sky_mean, hmin, hmax, dh, locut, hicut, cut +real sky_zero +int ap_grow_hist2(), aphigmr() +real ap_asumr(), apmedr() + +begin + # Intialize. + nsky = nskypix + nsky_reject = 0 + sky_mode = INDEFR + sky_sigma = INDEFR + sky_skew = INDEFR + if (nskypix <= 0) + return (AP_NOSKYAREA) + + # Compute the histogram width and binsize. + sky_zero = ap_asumr (skypix, index, nskypix) / nskypix + call ap_ialimr (skypix, index, nskypix, dmin, dmax) + call apfimoments (skypix, index, nskypix, sky_zero, sumpx, sumsqpx, + sumcbpx, sky_mean, sky_sigma, sky_skew) + sky_mean = apmedr (skypix, index, nskypix) + sky_mean = max (dmin, min (sky_mean, dmax)) + if (! IS_INDEFR(hwidth) && hwidth > 0.0) { + hmin = sky_mean - k1 * hwidth + hmax = sky_mean + k1 * hwidth + dh = binsize * hwidth + } else { + cut = min (sky_mean - dmin, dmax - sky_mean, k1 * sky_sigma) + hmin = sky_mean - cut + hmax = sky_mean + cut + dh = binsize * cut / k1 + } + + # Compute the number of histogram bins and the histogram resolution. + if (dh <= 0.0) { + nbins = 1 + dh = 0.0 + } else { + nbins = 2 * nint ((hmax - sky_mean) / dh) + 1 + dh = (hmax - hmin) / (nbins - 1) + } + + # Check for a valid histogram. + if (nbins < 2 || k1 <= 0.0 || sky_sigma < dh || dh <= 0.0 || + sky_sigma <= 0.0) { + sky_mode = sky_mean + sky_sigma = 0.0 + sky_skew = 0.0 + return (AP_NOHISTOGRAM) + } + + # Allocate temporary space. + call smark (sp) + call salloc (hgm, nbins, TY_REAL) + call salloc (shgm, nbins, TY_REAL) + + # Accumulate the histogram. + call aclrr (Memr[hgm], nbins) + nsky_reject = nsky_reject + aphigmr (skypix, wgt, index, nskypix, + Memr[hgm], nbins, hmin, hmax) + nsky = nskypix - nsky_reject + + # Do the initial rejection. + if (nsky_reject > 0) { + do i = 1, nskypix { + if (wgt[index[i]] <= 0.0) { + dsky = skypix[index[i]] - sky_zero + sumpx = sumpx - dsky + sumsqpx = sumsqpx - dsky ** 2 + sumcbpx = sumcbpx - dsky ** 3 + } + } + call apmoments (sumpx, sumsqpx, sumcbpx, nsky, sky_zero, sky_mean, + sky_sigma, sky_skew) + } + + # Fit the mode, sigma an skew of the histogram. + if (smooth == YES) { + nker = max (1, nint (sky_sigma / dh)) + #call ap_lucy_smooth (Memr[hgm], Memr[shgm], nbins, nker, 2) + call ap_bsmooth (Memr[hgm], Memr[shgm], nbins, nker, 2) + call ap_imode (Memr[shgm], nbins, hmin, hmax, YES, sky_mode, ier) + } else + call ap_imode (Memr[hgm], nbins, hmin, hmax, NO, sky_mode, ier) + sky_mode = max (dmin, min (sky_mode, dmax)) + if ((IS_INDEFR(losigma) && IS_INDEFR(hisigma)) || (sky_sigma < dh) || + maxiter < 1) { + call sfree (sp) + return (AP_OK) + } + + # Fit histogram with pixel rejection and optional region growing. + do i = 1, maxiter { + + # Compute new histogram limits. + if (IS_INDEFR(losigma)) + locut = -MAX_REAL + else + locut = sky_mode - losigma * sky_sigma + if (IS_INDEFR(hisigma)) + hicut = MAX_REAL + else + hicut = sky_mode + hisigma * sky_sigma + + # Reject pixels. + nreject = 0 + do j = 1, nskypix { + if (skypix[index[j]] >= locut && skypix[index[j]] <= hicut) + next + if (rgrow > 0.0) + nreject = nreject + ap_grow_hist2 (skypix, coords, + wgt, nskypix, sky_zero, index[j], snx, sny, Memr[hgm], + nbins, hmin, hmax, rgrow, sumpx, sumsqpx, sumcbpx) + else if (wgt[index[j]] > 0.0) { + call ap_hgmsub2 (Memr[hgm], nbins, hmin, hmax, + skypix[index[j]], sky_zero, sumpx, sumsqpx, sumcbpx) + wgt[index[j]] = 0.0 + nreject = nreject + 1 + } + } + if (nreject == 0) + break + nsky_reject = nsky_reject + nreject + nsky = nskypix - nsky_reject + if (nsky <= 0) + break + + # Recompute the moments. + call apmoments (sumpx, sumsqpx, sumcbpx, nsky, sky_zero, sky_mean, + sky_sigma, sky_skew) + + # Recompute the histogram peak. + if (smooth == YES) { + nker = max (1, nint (sky_sigma / dh)) + #call ap_lucy_smooth (Memr[hgm], Memr[shgm], nbins, nker, 2) + call ap_bsmooth (Memr[hgm], Memr[shgm], nbins, nker, 2) + call ap_imode (Memr[shgm], nbins, hmin, hmax, YES, sky_mode, + ier) + } else + call ap_imode (Memr[hgm], nbins, hmin, hmax, NO, sky_mode, ier) + sky_mode = max (dmin, min (sky_mode, dmax)) + if (sky_sigma <= dh || ier != AP_OK) + break + } + + # Return the error codes. + call sfree (sp) + if (nsky == 0 || nsky_reject == nskypix || ier == AP_NOHISTOGRAM) { + nsky = 0 + nsky_reject = nskypix + sky_mode = INDEFR + sky_sigma = INDEFR + sky_skew = INDEFR + return (AP_NSKY_TOO_SMALL) + } else + return (AP_OK) +end + + +# AP_IMODE -- Procedure to compute the 1st, 2nd and third moments of the +# histogram of sky pixels. + +procedure ap_imode (hgm, nbins, z1, z2, smooth, sky_mode, ier) + +real hgm[ARB] # histogram +int nbins # number of bins +real z1, z2 # min and max of the histogram +int smooth # is the histogram smoothed +real sky_mode # mode of histogram +int ier # error code + +int i, noccup +double sumi, sumix, x, dh +real hmean, dz +real asumr() + +begin + # Initialize the sums. + sumi = 0.0 + sumix = 0.0 + + # Compute a continuum level. + if (smooth == NO) + hmean = asumr (hgm, nbins) / nbins + else { + call alimr (hgm, nbins, dz, hmean) + hmean = 2.0 * hmean / 3.0 + } + + # Accumulate the sums. + noccup = 1 + dz = (z2 - z1) / (nbins - 1) + x = z1 + 0.5 * dz + do i = 1, nbins { + dh = hgm[i] - hmean + if (dh > 0.0d0) { + sumi = sumi + dh + sumix = sumix + dh * x + noccup = noccup + 1 + } + x = x + dz + } + + # Compute the sky mode, sigma and skew. + if (sumi > 0.0) { + sky_mode = sumix / sumi + ier = AP_OK + } else { + sky_mode = INDEFR + ier = AP_NOHISTOGRAM + } +end diff --git a/noao/digiphot/apphot/fitsky/apcrosscor.x b/noao/digiphot/apphot/fitsky/apcrosscor.x new file mode 100644 index 00000000..757addcc --- /dev/null +++ b/noao/digiphot/apphot/fitsky/apcrosscor.x @@ -0,0 +1,288 @@ +include <mach.h> +include "../lib/fitsky.h" + +# AP_CROSSCOR -- Procedure to compute the sky value by calculating the +# cross-correlation function of the histogram of the sky pixels and +# a Gaussian function with the same sigma as the sky distribution. +# The peak of the cross-correlation function is found by parabolic +# interpolation. + +int procedure ap_crosscor (skypix, coords, wgt, index, nskypix, snx, sny, k1, + hwidth, binsize, smooth, losigma, hisigma, rgrow, maxiter, sky_mode, + sky_sigma, sky_skew, nsky, nsky_reject) + +real skypix[ARB] # array of sky pixels +int coords[ARB] # array of sky coordinates for region growing +real wgt[ARB] # array of weights for rejection +int index[ARB] # array of sort indices +int nskypix # the number of sky pixels +int snx, sny # the maximum dimensions of sky raster +real k1 # half-width of the histogram in sky sigma +real hwidth # the input sky sigma +real binsize # the size of the histogram in sky sigma +int smooth # smooth the histogram before fitting (not used) +real losigma, hisigma # upper and lower rejection limits +real rgrow # region growing radius in pixels +int maxiter # maximum number of rejection cycles +real sky_mode # computed sky value +real sky_sigma # computed standard deviation of the sky pixels +real sky_skew # computed skew of sky pixels +int nsky # number of sky pixels used in fit +int nsky_reject # number of sky pixels rejected + +double dsky, sumpx, sumsqpx, sumcbpx +int nreject, nbins, nker, nsmooth, ier, i, j +pointer sp, x, hgm, shgm, kernel +real dmin, dmax, hmin, hmax, dh, kmin, kmax, locut, hicut, sky_mean, cut +real sky_zero +int ap_grow_hist2(), aphigmr() +real ap_asumr(), apmedr() + +begin + # Initialize. + nsky = nskypix + nsky_reject = 0 + sky_mode = INDEFR + sky_sigma = INDEFR + sky_skew = INDEFR + if (nskypix <= 0) + return (AP_NOSKYAREA) + + # Set up initial guess at sky mean, sigma and skew. + sky_zero = ap_asumr (skypix, index, nskypix) / nskypix + call ap_ialimr (skypix, index, nskypix, dmin, dmax) + call apfimoments (skypix, index, nskypix, sky_zero, + sumpx, sumsqpx, sumcbpx, sky_mean, sky_sigma, sky_skew) + sky_mean = apmedr (skypix, index, nskypix) + sky_mean = max (dmin, min (sky_mean, dmax)) + + # Compute the width and bin size of the histogram. + if (! IS_INDEFR(hwidth) && hwidth > 0.0) { + hmin = sky_mean - k1 * hwidth + hmax = sky_mean + k1 * hwidth + dh = binsize * hwidth + } else { + cut = min (sky_mean - dmin, dmax - sky_mean, k1 * sky_sigma) + hmin = sky_mean - cut + hmax = sky_mean + cut + dh = binsize * cut / k1 + } + + # Compute the number of bins in and the width of the kernel. + if (dh <= 0.0) { + nbins = 1 + nker = 1 + nsmooth = 1 + dh = 0.0 + } else { + nbins = 2 * nint ((hmax - sky_mean) / dh) + 1 + nker = 2 * nint (2.0 * (hmax - sky_mean) / (dh * 3.0)) + 1 + nsmooth = nbins - nker + 1 + dh = (hmax - hmin) / (nbins - 1) + } + kmin = - dh * (nker / 2 + 0.5) + kmax = dh * (nker / 2 + 0.5) + + # Test for a valid histogram. + if (nbins < 2 || k1 <= 0.0 || sky_sigma <= 0.0 || dh <= 0.0 || + sky_sigma <= dh) { + sky_mode = sky_mean + sky_sigma = 0.0 + sky_skew = 0.0 + return (AP_NOHISTOGRAM) + } + + # Allocate space for the histogram and kernel. + call smark (sp) + call salloc (x, nbins, TY_REAL) + call salloc (hgm, nbins, TY_REAL) + call salloc (shgm, nbins, TY_REAL) + call salloc (kernel, nker, TY_REAL) + + # Set up x array. + do i = 1, nbins + Memr[x+i-1] = i + call amapr (Memr[x], Memr[x], nbins, 1.0, real (nbins), + hmin + 0.5 * dh, hmax + 0.5 * dh) + + # Accumulate the histogram. + call aclrr (Memr[hgm], nbins) + call aclrr (Memr[shgm], nbins) + nsky_reject = nsky_reject + aphigmr (skypix, wgt, index, nskypix, + Memr[hgm], nbins, hmin, hmax) + nsky = nskypix - nsky_reject + + # Perform the initial rejection cycle. + if (nsky_reject > 0.0) { + do i = 1, nskypix { + if (wgt[index[i]] <= 0.0) { + dsky = skypix[index[i]] - sky_zero + sumpx = sumpx - dsky + sumsqpx = sumsqpx - dsky ** 2 + sumcbpx = sumcbpx - dsky ** 3 + } + } + call apmoments (sumpx, sumsqpx, sumcbpx, nsky, sky_zero, sky_mean, + sky_sigma, sky_skew) + } + + # Construct kernel and convolve with histogram. + if (sky_sigma > 0.0) { + call ap_gauss_kernel (Memr[kernel], nker, kmin, kmax, sky_sigma) + call acnvr (Memr[hgm], Memr[shgm+nker/2], nsmooth, Memr[kernel], + nker) + } else + call amovr (Memr[hgm], Memr[shgm], nbins) + call ap_corfit (Memr[x], Memr[shgm], nbins, sky_mode, ier) + sky_mode = max (dmin, min (sky_mode, dmax)) + if (ier != OK) { + call sfree (sp) + return (ier) + } + if ((IS_INDEFR(losigma) && IS_INDEFR(hisigma)) || (sky_sigma <= dh) || + maxiter < 1) { + call sfree (sp) + return (AP_OK) + } + + # Fit histogram with pixel rejection and optional region growing. + do i = 1, maxiter { + + # Compute new histogram limits. + if (IS_INDEFR(losigma)) + locut = -MAX_REAL + else + locut = sky_mode - losigma * sky_sigma + if (IS_INDEFR(hisigma)) + hicut = MAX_REAL + else + hicut = sky_mode + hisigma * sky_sigma + + # Detect rejected pixels. + nreject = 0 + do j = 1, nskypix { + if (skypix[index[j]] >= locut && skypix[index[j]] <= hicut) + next + if (rgrow > 0.0) + nreject = nreject + ap_grow_hist2 (skypix, coords, + wgt, nskypix, sky_zero, index[j], snx, sny, + Memr[hgm], nbins, hmin, hmax, rgrow, sumpx, sumsqpx, + sumcbpx) + else if (wgt[index[j]] > 0.0) { + call ap_hgmsub2 (Memr[hgm], nbins, hmin, hmax, + skypix[index[j]], sky_zero, sumpx, sumsqpx, sumcbpx) + wgt[index[j]] = 0.0 + nreject = nreject + 1 + } + } + if (nreject == 0) + break + + # Update the sky parameters. + nsky_reject = nsky_reject + nreject + nsky = nskypix - nsky_reject + if (nsky <= 0) + break + call apmoments (sumpx, sumsqpx, sumcbpx, nsky, sky_zero, sky_mean, + sky_sigma, sky_skew) + if (sky_sigma <= dh) + break + + # Recompute the peak of the histogram. + call ap_gauss_kernel (Memr[kernel], nker, kmin, kmax, sky_sigma) + call aclrr (Memr[shgm], nbins) + call acnvr (Memr[hgm], Memr[shgm+nker/2], nsmooth, Memr[kernel], + nker) + call ap_corfit (Memr[x], Memr[shgm], nbins, sky_mode, ier) + sky_mode = max (dmin, min (sky_mode, dmax)) + if (ier != AP_OK) + break + } + + # Return the appropriate error code. + call sfree (sp) + if (nsky == 0 || nsky_reject == nskypix) { + nsky = 0 + nsky_reject = nskypix + sky_mode = INDEFR + sky_sigma = INDEFR + sky_skew = INDEFR + return (AP_NSKY_TOO_SMALL) + } else if (ier != AP_OK) { + sky_mode = sky_mean + sky_sigma = 0.0 + sky_skew = 0.0 + return (ier) + } else + return (AP_OK) +end + + +# AP_GAUSS_KERNEL -- Procedure to compute a Gaussian kernel of given length +# and sigma. + +procedure ap_gauss_kernel (kernel, nker, kmin, kmax, sky_sigma) + +real kernel[ARB] # kernel +int nker # length of kernel +real kmin, kmax # limits of the kernel +real sky_sigma # sigma of the sky + +int i +real dk, x, sumx + +begin + # Return 1 if unit sized kernel. + if (nker == 1) { + kernel[1] = 1.0 + return + } + + # Intialize. + sumx = 0.0 + x = kmin + dk = (kmax - kmin ) / (nker - 1) + + # Compute and normalize the kernel. + do i = 1, nker { + kernel[i] = exp (- (x ** 2) / (2. * sky_sigma ** 2)) + sumx = sumx + kernel[i] + x = x + dk + } + do i = 1, nker + kernel[i] = kernel[i] / sumx +end + + +# AP_CORFIT -- Procedure to compute the peak of the cross-correlation +# function using parabolic interpolation. + +procedure ap_corfit (x, shgm, nbins, sky_mode, ier) + +real x[ARB] # x coordinates of histogram +real shgm[ARB] # convolved histogram +int nbins # number of histogram bins +real sky_mode # computed sky_mode +int ier # error code + +int bin +real max, xo, dh1, dh2 + +begin + call ap_amaxel (shgm, nbins, max, bin) + if (max <= 0) { + ier = AP_FLAT_HIST + } else if (bin == 1) { + sky_mode = x[1] + ier = AP_OK + } else if (bin == nbins) { + sky_mode = x[nbins] + ier = AP_OK + } else { + xo = 0.5 * (x[bin] + x[bin-1]) + dh1 = shgm[bin] - shgm[bin-1] + dh2 = shgm[bin] - shgm[bin+1] + sky_mode = xo + (x[bin] - x[bin-1]) * (dh1 / (dh1 + dh2)) + ier = AP_OK + } +end diff --git a/noao/digiphot/apphot/fitsky/apfitsky.x b/noao/digiphot/apphot/fitsky/apfitsky.x new file mode 100644 index 00000000..1c105b79 --- /dev/null +++ b/noao/digiphot/apphot/fitsky/apfitsky.x @@ -0,0 +1,452 @@ +include "../lib/apphotdef.h" +include "../lib/apphot.h" +include "../lib/noisedef.h" +include "../lib/fitskydef.h" +include "../lib/fitsky.h" + +# APFITSKY -- Procedure to the compute the sky value in an annular region +# around a given position in the IRAF image. + +int procedure apfitsky (ap, im, wx, wy, sd, gd) + +pointer ap # pointer to the apphot structure +pointer im # pointer to the IRAF image +real wx # object x coordinate +real wy # object y coordinate +int sd # pointer to input text file containing sky values +pointer gd # pointer to graphics stream + +int ier, nclip, nsky, ilo, ihi +pointer sky, nse, gt +real x, y +int apskybuf(), ap_mode(), ap_centroid(), ap_histplot(), ap_readsky() +int ap_median(), ap_radplot(), ap_gauss(), ap_lgsky(), ap_crosscor() +int ap_mean(), ap_clip() +pointer ap_gtinit() + +begin + # Initialize. + sky = AP_PSKY(ap) + nse = AP_NOISE(ap) + AP_SXCUR(sky) = wx + AP_SYCUR(sky) = wy + if (IS_INDEFR(wx) || IS_INDEFR(wy)) { + AP_OSXCUR(sky) = INDEFR + AP_OSYCUR(sky) = INDEFR + } else { + switch (AP_WCSOUT(ap)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_ltoo (ap, wx, wy, AP_OSXCUR(sky), AP_OSYCUR(sky), 1) + case WCS_TV: + call ap_ltov (im, wx, wy, AP_OSXCUR(sky), AP_OSYCUR(sky), 1) + default: + AP_OSXCUR(sky) = wx + AP_OSYCUR(sky) = wy + } + } + + AP_SKY_MODE(sky) = INDEFR + AP_SKY_SIG(sky) = INDEFR + AP_SKY_SKEW(sky) = INDEFR + AP_NSKY(sky) = 0 + AP_NSKY_REJECT(sky) = 0 + if (IS_INDEFR(wx) || IS_INDEFR(wy)) + return (AP_NOSKYAREA) + + switch (AP_SKYFUNCTION(sky)) { + + case AP_MEAN: + + # Fetch the sky pixels. + ier = apskybuf (ap, im, wx, wy) + if (ier != AP_OK) + return (ier) + + # Initialze the weights. + call amovkr (1.0, Memr[AP_SWGT(sky)], AP_NSKYPIX(sky)) + + # Clip the data. + if (AP_SLOCLIP(sky) > 0.0 || AP_SHICLIP(sky) > 0.0) { + nclip = ap_clip (Memr[AP_SKYPIX(sky)], Memi[AP_INDEX(sky)], + AP_NSKYPIX(sky), AP_SLOCLIP(sky), AP_SHICLIP(sky), ilo, + ihi) + if (nclip >= AP_NSKYPIX(sky)) + return (AP_NSKY_TOO_SMALL) + nsky = AP_NSKYPIX(sky) - nclip + } else { + nclip = 0 + call ap_index (Memi[AP_INDEX(sky)], AP_NSKYPIX(sky)) + ilo = 1 + nsky = AP_NSKYPIX(sky) + } + + # Compute the mean of the sky pixel distribution with pixel + # rejection and region growing. + ier = ap_mean (Memr[AP_SKYPIX(sky)], Memi[AP_COORDS(sky)], + Memr[AP_SWGT(sky)], Memi[AP_INDEX(sky)+ilo-1], + nsky, AP_SNX(sky), AP_SNY(sky), AP_SLOREJECT(sky), + AP_SHIREJECT(sky), AP_RGROW(sky) * AP_SCALE(ap), + AP_SNREJECT(sky), AP_SKY_MODE(sky), AP_SKY_SIG(sky), + AP_SKY_SKEW(sky), AP_NSKY(sky), AP_NSKY_REJECT(sky)) + AP_NSKY_REJECT(sky) = AP_NBADSKYPIX(sky) + nclip + + AP_NSKY_REJECT(sky) + + return (ier) + + case AP_MEDIAN: + + # Fetch the sky pixels. + ier = apskybuf (ap, im, wx, wy) + if (ier != AP_OK) + return (ier) + + # Initialze the weights. + call amovkr (1.0, Memr[AP_SWGT(sky)], AP_NSKYPIX(sky)) + + # Clip the data. + if (AP_SLOCLIP(sky) > 0.0 || AP_SHICLIP(sky) > 0.0) { + nclip = ap_clip (Memr[AP_SKYPIX(sky)], Memi[AP_INDEX(sky)], + AP_NSKYPIX(sky), AP_SLOCLIP(sky), AP_SHICLIP(sky), ilo, + ihi) + if (nclip >= AP_NSKYPIX(sky)) + return (AP_NSKY_TOO_SMALL) + nsky = AP_NSKYPIX(sky) - nclip + } else { + nclip = 0 + call apqsort (Memr[AP_SKYPIX(sky)], Memi[AP_INDEX(sky)], + Memi[AP_INDEX(sky)], AP_NSKYPIX(sky)) + ilo = 1 + nsky = AP_NSKYPIX(sky) + } + + # Compute the median of the sky pixel distribution with pixel + # rejection and region growing. + ier = ap_median (Memr[AP_SKYPIX(sky)], Memi[AP_COORDS(sky)], + Memr[AP_SWGT(sky)], Memi[AP_INDEX(sky)+ilo-1], nsky, + AP_SNX(sky), AP_SNY(sky), AP_SLOREJECT(sky), + AP_SHIREJECT(sky), AP_RGROW(sky) * AP_SCALE(ap), + AP_SNREJECT(sky), AP_SKY_MODE(sky), AP_SKY_SIG(sky), + AP_SKY_SKEW(sky), AP_NSKY(sky), AP_NSKY_REJECT(sky)) + AP_NSKY_REJECT(sky) = AP_NBADSKYPIX(sky) + nclip + + AP_NSKY_REJECT(sky) + + return (ier) + + case AP_MODE: + + # Fetch the sky pixels. + ier = apskybuf (ap, im, wx, wy) + if (ier != AP_OK) + return (ier) + + # Initialze the weights. + call amovkr (1.0, Memr[AP_SWGT(sky)], AP_NSKYPIX(sky)) + + # Clip the data. + if (AP_SLOCLIP(sky) > 0.0 || AP_SHICLIP(sky) > 0.0) { + nclip = ap_clip (Memr[AP_SKYPIX(sky)], Memi[AP_INDEX(sky)], + AP_NSKYPIX(sky), AP_SLOCLIP(sky), AP_SHICLIP(sky), ilo, + ihi) + if (nclip >= AP_NSKYPIX(sky)) + return (AP_NSKY_TOO_SMALL) + nsky = AP_NSKYPIX(sky) - nclip + } else { + nclip = 0 + call apqsort (Memr[AP_SKYPIX(sky)], Memi[AP_INDEX(sky)], + Memi[AP_INDEX(sky)], AP_NSKYPIX(sky)) + ilo = 1 + nsky = AP_NSKYPIX(sky) + } + + # Compute the median of the sky pixel distribution with pixel + # rejection and region growing. + ier = ap_mode (Memr[AP_SKYPIX(sky)], Memi[AP_COORDS(sky)], + Memr[AP_SWGT(sky)], Memi[AP_INDEX(sky)+ilo-1], nsky, + AP_SNX(sky), AP_SNY(sky), AP_SLOREJECT(sky), + AP_SHIREJECT(sky), AP_RGROW(sky) * AP_SCALE(ap), + AP_SNREJECT(sky), AP_SKY_MODE(sky), AP_SKY_SIG(sky), + AP_SKY_SKEW(sky), AP_NSKY(sky), AP_NSKY_REJECT(sky)) + AP_NSKY_REJECT(sky) = AP_NBADSKYPIX(sky) + nclip + + AP_NSKY_REJECT(sky) + + return (ier) + + case AP_CENTROID: + + # Fetch the sky pixels. + ier = apskybuf (ap, im, wx, wy) + if (ier != AP_OK) + return (ier) + + # Initialze the weights. + call amovkr (1.0, Memr[AP_SWGT(sky)], AP_NSKYPIX(sky)) + + # Clip the data. + if (AP_SLOCLIP(sky) > 0.0 || AP_SHICLIP(sky) > 0.0) { + nclip = ap_clip (Memr[AP_SKYPIX(sky)], Memi[AP_INDEX(sky)], + AP_NSKYPIX(sky), AP_SLOCLIP(sky), AP_SHICLIP(sky), ilo, + ihi) + if (nclip >= AP_NSKYPIX(sky)) + return (AP_NSKY_TOO_SMALL) + nsky = AP_NSKYPIX(sky) - nclip + } else { + nclip = 0 + call ap_index (Memi[AP_INDEX(sky)], AP_NSKYPIX(sky)) + ilo = 1 + nsky = AP_NSKYPIX(sky) + } + + # Compute the sky value by performing a moment analysis of the + # sky pixel histogram. + ier = ap_centroid (Memr[AP_SKYPIX(sky)], Memi[AP_COORDS(sky)], + Memr[AP_SWGT(sky)], Memi[AP_INDEX(sky)+ilo-1], nsky, + AP_SNX(sky), AP_SNY(sky), AP_K1(sky), INDEFR, + AP_BINSIZE(sky), AP_SMOOTH(sky), AP_SLOREJECT(sky), + AP_SHIREJECT(sky), AP_RGROW(sky) * AP_SCALE(ap), + AP_SMAXITER(sky), AP_SKY_MODE(sky), AP_SKY_SIG(sky), + AP_SKY_SKEW(sky), AP_NSKY(sky), AP_NSKY_REJECT(sky)) + AP_NSKY_REJECT(sky) = AP_NBADSKYPIX(sky) + nclip + + AP_NSKY_REJECT(sky) + + return (ier) + + case AP_CONSTANT: + + # Set the sky value to a constant. + AP_SKY_MODE(sky) = AP_SKYBACKGROUND(sky) + AP_SKY_SIG(sky) = AP_SKYSIGMA(nse) + AP_SKY_SKEW(sky) = INDEFR + AP_NSKY(sky) = 0 + AP_NSKY_REJECT(sky) = 0 + return (AP_OK) + + case AP_SKYFILE: + + # Read the sky values from a file. + if (sd == NULL) + return (AP_NOSKYFILE) + ier = ap_readsky (sd, x, y, AP_SKY_MODE(sky), AP_SKY_SIG(sky), + AP_SKY_SKEW(sky), AP_NSKY(sky), AP_NSKY_REJECT(sky)) + if (ier == EOF) + return (AP_EOFSKYFILE) + else if (ier != 7) + return (AP_BADSKYSCAN) + else if (AP_NSKY(sky) <= 0) + return (AP_NOSKYAREA) + else + return (AP_OK) + + case AP_RADPLOT: + + # Check the status of the graphics stream. + if (gd == NULL) + return (AP_NOGRAPHICS) + + # Fetch the sky pixels. + ier = apskybuf (ap, im, wx, wy) + if (ier != AP_OK) + return (ier) + + # Clip the data. + if (AP_SLOCLIP(sky) > 0.0 || AP_SHICLIP(sky) > 0.0) { + nclip = ap_clip (Memr[AP_SKYPIX(sky)], Memi[AP_INDEX(sky)], + AP_NSKYPIX(sky), AP_SLOCLIP(sky), AP_SHICLIP(sky), ilo, + ihi) + if (nclip >= AP_NSKYPIX(sky)) + return (AP_NSKY_TOO_SMALL) + nsky = AP_NSKYPIX(sky) - nclip + } else { + nclip = 0 + call ap_index (Memi[AP_INDEX(sky)], AP_NSKYPIX(sky)) + ilo = 1 + nsky = AP_NSKYPIX(sky) + } + + # Mark the sky level on the radial profile plot. + call gactivate (gd, 0) + gt = ap_gtinit (AP_IMROOT(ap), wx, wy) + ier = ap_radplot (gd, gt, Memr[AP_SKYPIX(sky)], + Memi[AP_COORDS(sky)], Memi[AP_INDEX(sky)+ilo-1], nsky, + AP_SXC(sky), AP_SYC(sky), AP_SNX(sky), AP_SNY(sky), + AP_SCALE(ap), AP_SKY_MODE(sky), AP_SKY_SKEW(sky), + AP_SKY_SIG(sky), AP_NSKY(sky), AP_NSKY_REJECT(sky)) + AP_NSKY_REJECT(sky) = AP_NBADSKYPIX(sky) + nclip + + AP_NSKY_REJECT(sky) + call ap_gtfree (gt) + call gdeactivate (gd, 0) + + return (ier) + + case AP_HISTPLOT: + + # Check the status of the graphics stream. + if (gd == NULL) + return (AP_NOGRAPHICS) + + # Fetch the sky pixels. + ier = apskybuf (ap, im, wx, wy) + if (ier != AP_OK) + return (ier) + + # Initialze the weights. + call amovkr (1.0, Memr[AP_SWGT(sky)], AP_NSKYPIX(sky)) + + # Clip the data. + if (AP_SLOCLIP(sky) > 0.0 || AP_SHICLIP(sky) > 0.0) { + nclip = ap_clip (Memr[AP_SKYPIX(sky)], Memi[AP_INDEX(sky)], + AP_NSKYPIX(sky), AP_SLOCLIP(sky), AP_SHICLIP(sky), + ilo, ihi) + if (nclip >= AP_NSKYPIX(sky)) + return (AP_NSKY_TOO_SMALL) + nsky = AP_NSKYPIX(sky) - nclip + } else { + nclip = 0 + call ap_index (Memi[AP_INDEX(sky)], AP_NSKYPIX(sky)) + ilo = 1 + nsky = AP_NSKYPIX(sky) + } + + # Mark the peak of the histogram on the histogram plot. + #call gactivate (gd, 0) + gt = ap_gtinit (AP_IMROOT(ap), wx, wy) + ier = ap_histplot (gd, gt, Memr[AP_SKYPIX(sky)], + Memr[AP_SWGT(sky)], Memi[AP_INDEX(sky)+ilo-1], nsky, + AP_K1(sky), INDEFR, AP_BINSIZE(sky), AP_SMOOTH(sky), + AP_SKY_MODE(sky), AP_SKY_SIG(sky), AP_SKY_SKEW(sky), + AP_NSKY(sky), AP_NSKY_REJECT(sky)) + AP_NSKY_REJECT(sky) = AP_NBADSKYPIX(sky) + nclip + + AP_NSKY_REJECT(sky) + call ap_gtfree (gt) + #call gdeactivate (gd, 0) + + return (ier) + + case AP_OFILT: + + # Fetch the sky pixels. + ier = apskybuf (ap, im, wx, wy) + if (ier != AP_OK) + return (ier) + + # Initialze the weights. + call amovkr (1.0, Memr[AP_SWGT(sky)], AP_NSKYPIX(sky)) + + # Clip the data. + if (AP_SLOCLIP(sky) > 0.0 || AP_SHICLIP(sky) > 0.0) { + nclip = ap_clip (Memr[AP_SKYPIX(sky)], Memi[AP_INDEX(sky)], + AP_NSKYPIX(sky), AP_SLOCLIP(sky), AP_SHICLIP(sky), + ilo, ihi) + if (nclip >= AP_NSKYPIX(sky)) + return (AP_NSKY_TOO_SMALL) + nsky = AP_NSKYPIX(sky) - nclip + } else { + nclip = 0 + call ap_index (Memi[AP_INDEX(sky)], AP_NSKYPIX(sky)) + ilo = 1 + nsky = AP_NSKYPIX(sky) + } + + # Compute the sky value using the histogram of the sky pixels + # and a variation of the optimal filtering technique. + ier = ap_lgsky (Memr[AP_SKYPIX(sky)], Memi[AP_COORDS(sky)], + Memr[AP_SWGT(sky)], Memi[AP_INDEX(sky)+ilo-1], nsky, + AP_SNX(sky), AP_SNY(sky), AP_K1(sky), INDEFR, + AP_BINSIZE(sky), AP_SMOOTH(sky), AP_SLOREJECT(sky), + AP_SHIREJECT(sky), AP_RGROW(sky) * AP_SCALE(ap), + AP_SMAXITER(sky), AP_SKY_MODE(sky), AP_SKY_SIG(sky), + AP_SKY_SKEW(sky), AP_NSKY(sky), AP_NSKY_REJECT(sky)) + AP_NSKY_REJECT(sky) = AP_NBADSKYPIX(sky) + nclip + + AP_NSKY_REJECT(sky) + + return (ier) + + case AP_GAUSS: + + # Fetch the sky pixels. + ier = apskybuf (ap, im, wx, wy) + if (ier != AP_OK) + return (ier) + + # Initialze the weights. + call amovkr (1.0, Memr[AP_SWGT(sky)], AP_NSKYPIX(sky)) + + # Clip the data. + if (AP_SLOCLIP(sky) > 0.0 || AP_SHICLIP(sky) > 0.0) { + nclip = ap_clip (Memr[AP_SKYPIX(sky)], Memi[AP_INDEX(sky)], + AP_NSKYPIX(sky), AP_SLOCLIP(sky), AP_SHICLIP(sky), + ilo, ihi) + if (nclip >= AP_NSKYPIX(sky)) + return (AP_NSKY_TOO_SMALL) + nsky = AP_NSKYPIX(sky) - nclip + } else { + nclip = 0 + call ap_index (Memi[AP_INDEX(sky)], AP_NSKYPIX(sky)) + ilo = 1 + nsky = AP_NSKYPIX(sky) + } + + # Compute the sky value by a fitting a skewed Gaussian function + # to the sky pixel histogram. + ier = ap_gauss (Memr[AP_SKYPIX(sky)], Memi[AP_COORDS(sky)], + Memr[AP_SWGT(sky)], Memi[AP_INDEX(sky)+ilo-1], nsky, + AP_SNX(sky), AP_SNY(sky), AP_SMAXITER(sky), AP_K1(sky), + INDEFR, AP_BINSIZE(sky), AP_SMOOTH(sky), + AP_SLOREJECT(sky), AP_SHIREJECT(sky), AP_RGROW(sky) * + AP_SCALE(ap), AP_SNREJECT(sky), AP_SKY_MODE(sky), + AP_SKY_SIG(sky), AP_SKY_SKEW(sky), AP_NSKY(sky), + AP_NSKY_REJECT(sky)) + AP_NSKY_REJECT(sky) = AP_NBADSKYPIX(sky) + nclip + + AP_NSKY_REJECT(sky) + + return (ier) + + case AP_CROSSCOR: + + # Fetch the sky pixels. + ier = apskybuf (ap, im, wx, wy) + if (ier != AP_OK) + return (ier) + + # Initialze the weights. + call amovkr (1.0, Memr[AP_SWGT(sky)], AP_NSKYPIX(sky)) + + # Clip the data. + if (AP_SLOCLIP(sky) > 0.0 || AP_SHICLIP(sky) > 0.0) { + nclip = ap_clip (Memr[AP_SKYPIX(sky)], Memi[AP_INDEX(sky)], + AP_NSKYPIX(sky), AP_SLOCLIP(sky), AP_SHICLIP(sky), + ilo, ihi) + if (nclip >= AP_NSKYPIX(sky)) + return (AP_NSKY_TOO_SMALL) + nsky = AP_NSKYPIX(sky) - nclip + } else { + nclip = 0 + call ap_index (Memi[AP_INDEX(sky)], AP_NSKYPIX(sky)) + ilo = 1 + nsky = AP_NSKYPIX(sky) + } + + # Fit the sky value by computing the cross-correlation + # function of the histogram and an estimate of the noise + # distribution. + ier = ap_crosscor (Memr[AP_SKYPIX(sky)], Memi[AP_COORDS(sky)], + Memr[AP_SWGT(sky)], Memi[AP_INDEX(sky)+ilo-1], nsky, + AP_SNX(sky), AP_SNY(sky), AP_K1(sky), INDEFR, + AP_BINSIZE(sky), AP_SMOOTH(sky), AP_SLOREJECT(sky), + AP_SHIREJECT(sky), AP_RGROW(sky) * AP_SCALE(ap), + AP_SMAXITER(sky), AP_SKY_MODE(sky), AP_SKY_SIG(sky), + AP_SKY_SKEW(sky), AP_NSKY(sky), AP_NSKY_REJECT(sky)) + AP_NSKY_REJECT(sky) = AP_NBADSKYPIX(sky) + nclip + + AP_NSKY_REJECT(sky) + + return (ier) + + default: + + AP_SKY_MODE(sky) = INDEFR + AP_SKY_SIG(sky) = INDEFR + AP_SKY_SKEW(sky) = INDEFR + AP_NSKY(sky) = AP_NSKYPIX(sky) + AP_NSKY_REJECT(sky) = 0 + return (AP_OK) + } +end diff --git a/noao/digiphot/apphot/fitsky/apgauss.x b/noao/digiphot/apphot/fitsky/apgauss.x new file mode 100644 index 00000000..860301dc --- /dev/null +++ b/noao/digiphot/apphot/fitsky/apgauss.x @@ -0,0 +1,296 @@ +include <mach.h> +include <math/nlfit.h> +include "../lib/fitsky.h" + +define TOL .001 # Fitting tolerance + +# AP_GAUSS -- Procedure to compute the peak, width and skew of the histogram +# by fitting a skewed Gaussian function to the histogram. + +int procedure ap_gauss (skypix, coords, wgt, index, nskypix, snx, sny, maxfit, + k1, hwidth, binsize, smooth, losigma, hisigma, rgrow, maxiter, + sky_mode, sky_sigma, sky_skew, nsky, nsky_reject) + +real skypix[ARB] # array of unsorted sky pixels +int coords[ARB] # array of coordinates for region growing +real wgt[ARB] # weights for pixel rejection +int index[ARB] # array of sort indices +int nskypix # the number of sky pixels +int snx, sny # the maximum dimensions of sky raster +int maxfit # maximum number of iterations per fit +real k1 # extent of the histogram in skysigma +real hwidth # width of the histogram +real binsize # the size of the histogram in sky sigma +int smooth # smooth the histogram before fitting +real losigma, hisigma # upper and lower sigma rejection criterion +real rgrow # region growing radius in pixels +int maxiter # maximum number of rejection cycles +real sky_mode # computed sky value +real sky_sigma # computed sigma of the sky pixels +real sky_skew # skew of sky pixels +int nsky # number of sky pixels used in fit +int nsky_reject # number of sky pixels rejected + +double dsky, sumpx, sumsqpx, sumcbpx +int i, j, nreject, nbins, nker, ier +pointer sp, x, hgm, shgm, w +real sky_mean, sky_msigma, dmin, dmax, hmin, hmax, dh, locut, hicut, cut +real sky_zero +int ap_grow_hist2(), aphigmr() +real ap_asumr(), apmedr() + +begin + # Initialize. + nsky = nskypix + nsky_reject = 0 + sky_mode = INDEFR + sky_sigma = INDEFR + sky_skew = INDEFR + if (nskypix <= 0) + return (AP_NOSKYAREA) + + # Compute initial guess for sky statistics. + sky_zero = ap_asumr (skypix, index, nskypix) / nskypix + call ap_ialimr (skypix, index, nskypix, dmin, dmax) + call apfimoments (skypix, index, nskypix, sky_zero, sumpx, sumsqpx, + sumcbpx, sky_mean, sky_msigma, sky_skew) + sky_mean = apmedr (skypix, index, nskypix) + sky_mean = max (dmin, min (sky_mean, dmax)) + + # Compute the width and bin size of the sky histogram. + if (! IS_INDEFR(hwidth) && hwidth > 0.0) { + hmin = sky_mean - k1 * hwidth + hmax = sky_mean + k1 * hwidth + dh = binsize * hwidth + } else { + cut = min (sky_mean - dmin, dmax - sky_mean, k1 * sky_msigma) + hmin = sky_mean - cut + hmax = sky_mean + cut + dh = binsize * cut / k1 + } + + # Compute the number of histogram bins and width of smoothing kernel. + if (dh <= 0.0) { + nbins = 1 + dh = 0.0 + } else { + nbins = 2 * nint ((hmax - sky_mean) / dh) + 1 + dh = (hmax - hmin) / (nbins - 1) + } + + # Test for a valid histogram. + if (sky_msigma <= dh || dh <= 0.0 || k1 <= 0.0 || sky_msigma <= 0.0 || + nbins < 4) { + sky_mode = sky_mean + sky_sigma = 0.0 + sky_skew = 0.0 + return (AP_NOHISTOGRAM) + } + + # Allocate temporary working space. + call smark (sp) + call salloc (x, nbins, TY_REAL) + call salloc (hgm, nbins, TY_REAL) + call salloc (shgm, nbins, TY_REAL) + call salloc (w, nbins, TY_REAL) + + # Compute the x array. + do i = 1, nbins + Memr[x+i-1] = i + call amapr (Memr[x], Memr[x], nbins, 1.0, real (nbins), + hmin + 0.5 * dh, hmax + 0.5 * dh) + + # Accumulate the histogram. + call aclrr (Memr[hgm], nbins) + nsky_reject = nsky_reject + aphigmr (skypix, wgt, index, nskypix, + Memr[hgm], nbins, hmin, hmax) + nsky = nskypix - nsky_reject + + # Do the initial rejection. + if (nsky_reject > 0) { + do i = 1, nskypix { + if (wgt[index[i]] <= 0.0) { + dsky = skypix[index[i]] - sky_zero + sumpx = sumpx - dsky + sumsqpx = sumsqpx - dsky ** 2 + sumcbpx = sumcbpx - dsky ** 3 + } + } + call apmoments (sumpx, sumsqpx, sumcbpx, nsky, sky_zero, + sky_mean, sky_msigma, sky_skew) + } + + # Find the mode, sigma and skew of the histogram. + if (smooth == YES) { + nker = max (1, nint (sky_msigma / dh)) + #call ap_lucy_smooth (Memr[hgm], Memr[shgm], nbins, nker, 2) + call ap_bsmooth (Memr[hgm], Memr[shgm], nbins, nker, 2) + call ap_hist_mode (Memr[x], Memr[shgm], Memr[w], nbins, + sky_mode, sky_sigma, sky_skew, maxfit, TOL, ier) + } else + call ap_hist_mode (Memr[x], Memr[hgm], Memr[w], nbins, + sky_mode, sky_sigma, sky_skew, maxfit, TOL, ier) + sky_mode = max (dmin, min (sky_mode, dmax)) + if (ier != AP_OK) { + call sfree (sp) + return (ier) + } + if ((IS_INDEFR(losigma) && IS_INDEFR(hisigma)) || sky_sigma <= dh || + maxiter < 1) { + call sfree (sp) + return (AP_OK) + } + + # Fit histogram with pixel rejection and optional region growing. + do i = 1, maxiter { + + # Compute the new rejection limits. + if (IS_INDEFR(losigma)) + locut = -MAX_REAL + else + locut = sky_mode - losigma * sky_msigma + if (IS_INDEFR(hisigma)) + hicut = MAX_REAL + else + hicut = sky_mode + hisigma * sky_msigma + + # Detect and reject pixels. + nreject = 0 + do j = 1, nskypix { + if (skypix[index[j]] >= locut && skypix[index[j]] <= hicut) + next + if (rgrow > 0.0) + nreject = nreject + ap_grow_hist2 (skypix, coords, + wgt, nskypix, sky_zero, index[j], snx, sny, Memr[hgm], + nbins, hmin, hmax, rgrow, sumpx, sumsqpx, sumcbpx) + else if (wgt[index[j]] > 0.0) { + call ap_hgmsub2 (Memr[hgm], nbins, hmin, hmax, + skypix[index[j]], sky_zero, sumpx, sumsqpx, sumcbpx) + wgt[index[j]] = 0.0 + nreject = nreject + 1 + } + } + if (nreject == 0) + break + nsky_reject = nsky_reject + nreject + nsky = nskypix - nsky_reject + if (nsky <= 0) + break + call apmoments (sumpx, sumsqpx, sumcbpx, nsky, sky_zero, + sky_mean, sky_msigma, sky_skew) + + # Recompute mean, mode, sigma and skew. + if (smooth == YES) { + nker = max (1, nint (sky_msigma / dh)) + #call ap_lucy_smooth (Memr[hgm], Memr[shgm], nbins, nker, 2) + call ap_bsmooth (Memr[hgm], Memr[shgm], nbins, nker, 2) + call ap_hist_mode (Memr[x], Memr[shgm], Memr[w], nbins, + sky_mode, sky_sigma, sky_skew, maxfit, TOL, ier) + } else + call ap_hist_mode (Memr[x], Memr[hgm], Memr[w], nbins, + sky_mode, sky_sigma, sky_skew, maxfit, TOL, ier) + sky_mode = max (dmin, min (sky_mode, dmax)) + if (ier != AP_OK) + break + if (sky_sigma <= dh) + break + } + + # Return appropriate error code. + call sfree (sp) + if (nsky == 0 || nsky_reject == nskypix) { + nsky = 0 + nsky_reject = nskypix + sky_mode = INDEFR + sky_sigma = INDEFR + sky_skew = INDEFR + return (AP_NSKY_TOO_SMALL) + } else if (ier == AP_NSKY_TOO_SMALL) { + return (AP_NSKY_TOO_SMALL) + } else if (ier != AP_OK) { + return (ier) + } else + return (AP_OK) +end + + +# AP_HIST_MODE -- Procedure to fit the skewed Gaussian function to the histogram +# of the sky pixels. + +procedure ap_hist_mode (x, hgm, w, nbins, sky_mode, sky_sigma, sky_skew, + maxiter, tol, ier) + +real x[ARB] # x array +real hgm[ARB] # histogram +real w[ARB] # weights +int nbins # number of bins +real sky_mode # sky value +real sky_sigma # sky sigma +real sky_skew # sky skew +int maxiter # max number of iterations +real tol # tolerances +int ier # error code + +extern gausskew, dgausskew +int i, imin, imax, np, fier +pointer sp, list, fit, nl +real p[4], dp[4], dummy1 +int locpr() + +begin + # Allocate working memory. + call smark (sp) + call salloc (list, 4, TY_INT) + call salloc (fit, nbins, TY_REAL) + + # Initialize. + do i = 1, 4 + Memi[list+i-1] = i + + # Compute initial guesses for the parameters. + call ap_alimr (hgm, nbins, dummy1, p[1], imin, imax) + p[2] = x[imax] + #p[3] = max (sky_sigma ** 2, abs (x[2] - x[1]) ** 2) + p[3] = abs ((x[nbins] - x[1]) / 6.0) ** 2 + p[4] = 0.0 + np = 4 + + # Fit the histogram. + call nlinitr (nl, locpr (gausskew), locpr (dgausskew), p, dp, np, + Memi[list], 4, tol, maxiter) + call nlfitr (nl, x, hgm, w, nbins, 1, WTS_UNIFORM, fier) + call nlvectorr (nl, x, Memr[fit], nbins, 1) + call nlpgetr (nl, p, np) + call nlfreer (nl) + + call sfree (sp) + + # Return the appropriate error code. + ier = AP_OK + if (fier == NO_DEG_FREEDOM) { + sky_mode = INDEFR + sky_sigma = INDEFR + sky_skew = INDEFR + ier = AP_NSKY_TOO_SMALL + } else { + if (fier == SINGULAR) + ier = AP_SKY_SINGULAR + else if (fier == NOT_DONE) + ier = AP_SKY_NOCONVERGE + if (p[2] < x[1] || p[2] > x[nbins]) { + sky_mode = x[imax] + ier = AP_BADPARAMS + } else + sky_mode = p[2] + if (p[3] <= 0.0) { + sky_sigma = 0.0 + sky_skew = 0.0 + ier = AP_BADPARAMS + } else { + sky_sigma = sqrt (p[3]) + sky_skew = 1.743875281 * abs (p[4]) ** (1.0 / 3.0) * sky_sigma + if (p[4] < 0.0) + sky_skew = - sky_skew + } + } +end diff --git a/noao/digiphot/apphot/fitsky/apgrowhist.x b/noao/digiphot/apphot/fitsky/apgrowhist.x new file mode 100644 index 00000000..6f01a789 --- /dev/null +++ b/noao/digiphot/apphot/fitsky/apgrowhist.x @@ -0,0 +1,136 @@ +# AP_GROW_HIST -- Procedure to reject pixels with region growing. + +int procedure ap_grow_hist (skypix, coords, wgt, nskypix, index, snx, sny, hgm, + nbins, z1, z2, rgrow) + +real skypix[ARB] # sky pixels +int coords[ARB] # sky pixel coordinates +real wgt[ARB] # array of weights +int nskypix # number of sky pixels +int index # index of pixel to be rejected +int snx, sny # size of sky subraster +real hgm[ARB] # histogram +int nbins # number of bins +real z1, z2 # value of first and last histogram bin +real rgrow # region growing radius + +int j, k, ixc, iyc, ymin, ymax, xmin, xmax, nreject, cstart, c, bin +real dh, r2, rgrow2, d + +begin + # Find the x and y coordinates of the pixel to be rejected. + ixc = mod (coords[index], snx) + if (ixc == 0) + ixc = snx + iyc = (coords[index] - ixc) / snx + 1 + + # Find the coordinate space to be used for regions growing. + ymin = max (1, int (iyc - rgrow)) + ymax = min (sny, int (iyc + rgrow)) + xmin = max (1, int (ixc - rgrow)) + xmax = min (snx, int (ixc + rgrow)) + if (ymin <= iyc) + cstart = min (nskypix, max (1, index - int (rgrow) + snx * + (ymin - iyc))) + else + cstart = index + + # Perform the region growing. + dh = real (nbins - 1) / (z2 - z1) + rgrow2 = rgrow ** 2 + nreject = 0 + do j = ymin, ymax { + d = rgrow2 - (j - iyc) ** 2 + if (d <= 0.0) + d = 0.0 + else + d = sqrt (d) + do k = max (xmin, int (ixc - d)), min (xmax, int (ixc + d)) { + c = k + (j - 1) * snx + while (coords[cstart] < c && cstart < nskypix) + cstart = cstart + 1 + r2 = (k - ixc) ** 2 + (j - iyc) ** 2 + if (r2 <= rgrow2 && c == coords[cstart] && wgt[cstart] > 0.0) { + nreject = nreject + 1 + wgt[cstart] = 0.0 + if (skypix[cstart] >= z1 && skypix[cstart] <= z2) { + bin = int ((skypix[cstart] - z1) * dh) + 1 + hgm[bin] = hgm[bin] - 1.0 + } + } + } + } + + return (nreject) +end + + +# AP_GROW_HIST2 -- Procedure to reject pixels with region growing. + +int procedure ap_grow_hist2 (skypix, coords, wgt, nskypix, sky_zero, index, + snx, sny, hgm, nbins, z1, z2, rgrow, sumpx, sumsqpx, sumcbpx) + +real skypix[ARB] # sky pixels +int coords[ARB] # coordinates +real wgt[ARB] # array of weights +int nskypix # number of sky pixels +real sky_zero # the sky zero point for moment analysis +int index # index of pixel to be rejected +int snx, sny # size of sky subraster +real hgm[ARB] # histogram +int nbins # number of bins +real z1, z2 # value of first and last histogram bin +real rgrow # region growing radius +double sumpx # sum of sky values +double sumsqpx # sum of sky values squared +double sumcbpx # sum of sky values cubed + +double dsky +int j, k, ixc, iyc, ymin, ymax, xmin, xmax, nreject, cstart, c, bin +real dh, r2, rgrow2, d + +begin + # Find the coordinates of the region growing center. + ixc = mod (coords[index], snx) + if (ixc == 0) + ixc = snx + iyc = (coords[index] - ixc) / snx + 1 + + ymin = max (1, int (iyc - rgrow)) + ymax = min (sny, int (iyc + rgrow)) + xmin = max (1, int (ixc - rgrow)) + xmax = min (snx, int (ixc + rgrow)) + dh = real (nbins - 1) / (z2 - z1) + if (ymin <= iyc) + cstart = min (nskypix, max (1, index - int (rgrow) + snx * + (ymin - iyc))) + else + cstart = index + + # Perform the region growing. + nreject = 0 + rgrow2 = rgrow ** 2 + do j = ymin, ymax { + d = sqrt (rgrow2 - (j - iyc) ** 2) + do k = max (xmin, int (ixc - d)), min (xmax, int (ixc + d)) { + c = k + (j - 1) * snx + while (coords[cstart] < c && cstart < nskypix) + cstart = cstart + 1 + r2 = (k - ixc) ** 2 + (j - iyc) ** 2 + if (r2 <= rgrow2 && c == coords[cstart] && wgt[cstart] > 0.0) { + nreject = nreject + 1 + wgt[cstart] = 0.0 + dsky = skypix[cstart] - sky_zero + sumpx = sumpx - dsky + sumsqpx = sumsqpx - dsky ** 2 + sumcbpx = sumcbpx - dsky ** 3 + if (skypix[cstart] >= z1 && skypix[cstart] <= z2) { + bin = int ((skypix[cstart] - z1) * dh) + 1 + hgm[bin] = hgm[bin] - 1.0 + } + } + } + } + + return (nreject) +end diff --git a/noao/digiphot/apphot/fitsky/apgspars.x b/noao/digiphot/apphot/fitsky/apgspars.x new file mode 100644 index 00000000..8ca7f52c --- /dev/null +++ b/noao/digiphot/apphot/fitsky/apgspars.x @@ -0,0 +1,26 @@ +include "../lib/display.h" +include "../lib/noise.h" +include "../lib/fitsky.h" + +# AP_SGPARS -- Procedure to fetch the parameters for the fitsky task. + +procedure ap_sgpars (ap) + +pointer ap # pointer to apphot structure + +bool clgetb() +int btoi() + +begin + # Open the apphot structure. + call apsinit (ap, AP_MODE, 10.0, 10.0, 2.0, AP_NPOISSON) + + # Get the data dependent parameters. + call ap_gdapars (ap) + + # Get the sky fitting parameters. + call ap_gsapars (ap) + + # Get radial plots. + call apseti (ap, RADPLOTS, btoi (clgetb ("radplots"))) +end diff --git a/noao/digiphot/apphot/fitsky/aphgmsub.x b/noao/digiphot/apphot/fitsky/aphgmsub.x new file mode 100644 index 00000000..ae969bba --- /dev/null +++ b/noao/digiphot/apphot/fitsky/aphgmsub.x @@ -0,0 +1,51 @@ +# AP_HGMSUB -- Procedure to subtract a point from an existing histogram. + +procedure ap_hgmsub (hgm, nbins, z1, z2, skypix) + +real hgm[ARB] # histogram +int nbins # number of bins +real z1, z2 # range of histogram +real skypix # sky value + +int bin +real dh + +begin + if (skypix < z1 || skypix > z2) + return + dh = real (nbins - 1) / (z2 - z1) + bin = int ((skypix - z1) * dh) + 1 + hgm[bin] = hgm[bin] - 1.0 +end + + +# AP_HGMSUB2 -- Procedure to subract points from the accumulated sums +# and the existing histogram. + +procedure ap_hgmsub2 (hgm, nbins, z1, z2, skypix, sky_zero, sumpx, sumsqpx, + sumcbpx) + +real hgm[ARB] # histogram +int nbins # number of bins +real z1, z2 # range of histogram +real skypix # sky value +real sky_zero # sky zero point for moment analysis +double sumpx # sum of the sky pixel values +double sumsqpx # sum of the squares of the sky pixel values +double sumcbpx # sum of the cubes of the sky pixel values + +double dsky +int bin +real dh + +begin + if (skypix < z1 || skypix > z2) + return + dsky = skypix - sky_zero + sumpx = sumpx - dsky + sumsqpx = sumsqpx - dsky ** 2 + sumcbpx = sumcbpx - dsky ** 3 + dh = real (nbins - 1) / (z2 - z1) + bin = int ((skypix - z1) * dh) + 1 + hgm[bin] = hgm[bin] - 1.0 +end diff --git a/noao/digiphot/apphot/fitsky/aphistplot.x b/noao/digiphot/apphot/fitsky/aphistplot.x new file mode 100644 index 00000000..49c00071 --- /dev/null +++ b/noao/digiphot/apphot/fitsky/aphistplot.x @@ -0,0 +1,233 @@ +include <gset.h> +include <pkg/gtools.h> +include "../lib/fitsky.h" + +# AP_HISTPLOT -- Procedure to the sky value using a plot of the sky histogram +# and cursor readback. + +int procedure ap_histplot (gd, gt, skypix, wgt, index, nskypix, k1, hwidth, + binsize, smooth, sky_mode, sky_sigma, sky_skew, nsky, nsky_reject) + +pointer gd # pointer to graphics stream +pointer gt # pointer to GTOOLS structure +real skypix[ARB] # array of unsorted sky pixels +real wgt[ARB] # array of weights for rejection +int index[ARB] # array of sort indices +int nskypix # number of sky pixels +real k1 # rejection criterion +real hwidth # half width of histogram in k1 units +real binsize # histogram binsize in units of sigma +int smooth # smooth the histogram +real sky_mode # sky value +real sky_sigma # sigma of sky pixels +real sky_skew # skew of sky pixels +int nsky # number of sky pixels +int nsky_reject # number of rejected sky pixels + +double dsky, sumpx, sumsqpx, sumcbpx +int i, nbins, nker, wcs, key +pointer sp, x, hgm, shgm, cmd +real dmin, dmax, hmin, hmax, dh, ymin, ymax, symin, symax, wx, wy +real u1, u2, v1, v2, x1, x2, y1, y2, cut, sky_mean, sky_zero +int clgcur(), aphigmr() +real apmedr(), ap_asumr() + +begin + # Check for valid graphics stream. + if (gd == NULL) + return (AP_NOGRAPHICS) + + # Initialize. + nsky = nskypix + nsky_reject = 0 + sky_mode = INDEFR + sky_sigma = INDEFR + sky_skew = INDEFR + if (nskypix <= 0) + return (AP_SKY_OUTOFBOUNDS) + + # Compute an initial guess at the sky distribution. + sky_zero = ap_asumr (skypix, index, nskypix) / nskypix + call ap_ialimr (skypix, index, nskypix, dmin, dmax) + call apfimoments (skypix, index, nskypix, sky_zero, sumpx, sumsqpx, + sumcbpx, sky_mean, sky_sigma, sky_skew) + sky_mode = apmedr (skypix, index, nskypix) + sky_mode = max (dmin, min (sky_mode, dmax)) + + # Compute histogram width and binsize. + if (! IS_INDEFR(hwidth) && hwidth > 0.0) { + hmin = sky_mode - k1 * hwidth + hmax = sky_mode + k1 * hwidth + dh = binsize * hwidth + } else { + cut = min (sky_mode - dmin, dmax - sky_mode, k1 * sky_sigma) + hmin = sky_mode - cut + hmax = sky_mode + cut + dh = binsize * cut / k1 + } + + # Compute the number of histgram bins and the histogram resolution. + if (dh <= 0.0) { + nbins = 1 + dh = 0.0 + } else { + nbins = 2 * nint ((hmax - sky_mode) / dh) + 1 + dh = (hmax - hmin) / (nbins - 1) + } + + # Test for a valid histogram. + if (dh <= 0.0 || k1 <= 0.0 || sky_sigma <= 0.0 || sky_sigma <= dh || + nbins < 2) { + sky_mode = sky_mode + sky_sigma = 0.0 + sky_skew = 0.0 + return (AP_NOHISTOGRAM) + } + + # Allocate temporary space. + call smark (sp) + call salloc (x, nbins, TY_REAL) + call salloc (hgm, nbins, TY_REAL) + call salloc (shgm, nbins, TY_REAL) + call salloc (cmd, SZ_LINE, TY_CHAR) + + # Compute the x array and accumulate the histogram. + do i = 1, nbins + Memr[x+i-1] = i + call amapr (Memr[x], Memr[x], nbins, 1.0, real (nbins), + hmin + 0.5 * dh, hmax + 0.5 * dh) + call aclrr (Memr[hgm], nbins) + nsky_reject = nsky_reject + aphigmr (skypix, wgt, index, nskypix, + Memr[hgm], nbins, hmin, hmax) + nsky = nskypix - nsky_reject + + # Subtract rejected pixels and recompute the moments. + if (nsky_reject > 0) { + do i = 1, nskypix { + if (wgt[index[i]] <= 0.0) { + dsky = skypix[index[i]] - sky_zero + sumpx = sumpx - dsky + sumsqpx = sumsqpx - dsky ** 2 + sumcbpx = sumcbpx - dsky ** 3 + } + } + } + call apmoments (sumpx, sumsqpx, sumcbpx, nsky, sky_zero, sky_mean, + sky_sigma, sky_skew) + + # Smooth the histogram and compute the histogram plot limits. + if (smooth == YES) { + nker = max (1, nint (sky_sigma / dh)) + #call ap_lucy_smooth (Memr[hgm], Memr[shgm], nbins, nker, 2) + call ap_bsmooth (Memr[hgm], Memr[shgm], nbins, nker, 2) + call alimr (Memr[hgm], nbins, ymin, ymax) + call alimr (Memr[shgm], nbins, symin, symax) + ymin = min (ymin, symin) + ymax = max (ymax, symax) + } else + call alimr (Memr[hgm], nbins, ymin, ymax) + + # Store the old viewport and window coordinates. + call greactivate (gd, 0) + call ggview (gd, u1, u2, v1, v2) + call ggwind (gd, x1, x2, y1, y2) + + # Plot the raw and smoothed histograms. + call ap_set_hplot (gd, gt, hmin, hmax, ymin, ymax, nbins, smooth) + if (smooth == YES) { + call ap_plothist (gd, gt, Memr[x], Memr[hgm], nbins, "histogram", + GL_SOLID) + call ap_plothist (gd, gt, Memr[x], Memr[shgm], nbins, "line", + GL_SOLID) + } else + call ap_plothist (gd, gt, Memr[x], Memr[hgm], nbins, "histogram", + GL_SOLID) + + # Mark the peak of the histogram with the cursor. + call printf ( + "Mark histogram peak (%g) [space=mark,q=quit,:.help=help:]") + call pargr (sky_mode) + call gscur (gd, sky_mode, (ymin + ymax) / 2.0) + while (clgcur ("gcommands", wx, wy, wcs, key, Memc[cmd], SZ_LINE) != + EOF) { + if (key == 'q') + break + else + sky_mode = max (hmin, min (wx, hmax)) + call printf ( + "Mark histogram peak (%g) [space=mark,q=quit,:.help=help:]") + call pargr (sky_mode) + } + + # Store the old viewport and window coordinates. + call gsview (gd, u1, u2, v1, v2) + call gswind (gd, x1, x2, y1, y2) + + # Close up. + call gflush (gd) + call gdeactivate (gd, 0) + call sfree (sp) + return (AP_OK) +end + + +# AP_PLOTHIST -- Procedure plot the histogram. + +procedure ap_plothist (gd, gt, x, hgm, nbins, plottype, polytype) + +pointer gd # pointer to graphics stream +pointer gt # GTOOLS pointer +real x[ARB] # the histogram bin values +real hgm[ARB] # histogram +int nbins # number of bins +char plottype[ARB] # the plot type "histogram" or "line" +int polytype # polyline type + +begin + call gt_sets (gt, GTTYPE, plottype) + call gt_seti (gt, GTLINE, polytype) + call gt_plot (gd, gt, x, hgm, nbins) + call gflush (gd) +end + + +# AP_SET_HPLOT -- Procedure to set up the histogram plot. + +procedure ap_set_hplot (gd, gt, xmin, xmax, ymin, ymax, nbins, smooth) + +pointer gd # pointer to GRAPHICS stream +pointer gt # pointer to GTOOLS structure +real xmin, xmax # min and max of x vector +real ymin, ymax # min and max of y vector +int nbins # number of bins +int smooth # smooth histogram + +pointer sp, str + +begin + # Initialize + call gclear (gd) + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + + # Set up the gtools parameter string. + call sprintf (Memc[str], SZ_LINE, + "Sky Histogram: nbins = %d hmin = %g hmax = %g smooth=%b") + call pargi (nbins) + call pargr (xmin) + call pargr (xmax) + call pargi (smooth) + call gt_sets (gt, GTPARAMS, Memc[str]) + + # Set up the plot axes. + call gt_sets (gt, GTXLABEL, "Sky Values") + call gt_sets (gt, GTYLABEL, "Number of Pixels") + call gt_setr (gt, GTXMIN, xmin) + call gt_setr (gt, GTXMAX, xmax) + call gt_setr (gt, GTYMIN, ymin) + call gt_setr (gt, GTYMAX, ymax) + call gt_swind (gd, gt) + call gt_labax (gd, gt) + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/fitsky/aplgsky.x b/noao/digiphot/apphot/fitsky/aplgsky.x new file mode 100644 index 00000000..db5b4a19 --- /dev/null +++ b/noao/digiphot/apphot/fitsky/aplgsky.x @@ -0,0 +1,216 @@ +include <mach.h> +include "../lib/fitsky.h" + +define TOL 0.001 # Fitting tolerance + +# AP_LGSKY -- Procedure to fit the peak and width of the histogram using +# repeated convolutions and a triangle function. + +int procedure ap_lgsky (skypix, coords, wgt, index, nskypix, snx, sny, k1, + hwidth, binsize, smooth, losigma, hisigma, rgrow, maxiter, sky_mode, + sky_sigma, sky_skew, nsky, nsky_reject) + +real skypix[ARB] # array of sky pixels +int coords[ARB] # array of coordinates of region growing +real wgt[ARB] # array of weights for rejection +int index[ARB] # array of sort indices +int nskypix # the number of sky pixels +int snx, sny # the maximum dimensions of sky raster +real k1 # extent of the histogram in skysigma +real hwidth # width of histogram +real binsize # the size of the histogram in sky sigma +int smooth # smooth the histogram before fitting +real losigma, hisigma # upper and lower sigma rejection limits +real rgrow # region growing radius in pixels +int maxiter # maximum number of rejection cycles +real sky_mode # computed sky value +real sky_sigma # computed sigma of the sky pixels +real sky_skew # skew of sky pixels +int nsky # number of sky pixels used in fit +int nsky_reject # number of sky pixels rejected + +double dsky, sumpx, sumsqpx, sumcbpx +int nreject, nbins, nker, i, j, iter +pointer sp, hgm, shgm +real dmin, dmax, hmin, hmax, dh, locut, hicut, sky_mean, center, cut +real sky_zero +int ap_grow_hist2(), aphigmr(), aptopt() +real ap_asumr(), apmedr(), apmapr() + +begin + # Initialize. + nsky = nskypix + nsky_reject = 0 + sky_mode = INDEFR + sky_sigma = INDEFR + sky_skew = INDEFR + if (nskypix <= 0) + return (AP_NOSKYAREA) + + # Compute a first guess for the parameters. + sky_zero = ap_asumr (skypix, index, nskypix) / nskypix + call ap_ialimr (skypix, index, nskypix, dmin, dmax) + call apfimoments (skypix, index, nskypix, sky_zero, sumpx, sumsqpx, + sumcbpx, sky_mean, sky_sigma, sky_skew) + sky_mean = apmedr (skypix, index, nskypix) + sky_mean = max (dmin, min (sky_mean, dmax)) + + # Compute the width and bin size of histogram. + if (! IS_INDEFR(hwidth) && hwidth > 0.0) { + hmin = sky_mean - k1 * hwidth + hmax = sky_mean + k1 * hwidth + dh = binsize * hwidth + } else { + cut = min (sky_mean - dmin, dmax - sky_mean, k1 * sky_sigma) + hmin = sky_mean - cut + hmax = sky_mean + cut + dh = binsize * cut / k1 + } + + # Compute the number of histogram bins and the resolution. + # filter. + if (dh <= 0.0) { + nbins = 1 + dh = 0.0 + } else { + nbins = 2 * nint ((hmax - sky_mean) / dh) + 1 + dh = (hmax - hmin) / (nbins - 1) + } + + # Test for a valid histogram. + if (nbins < 2 || k1 <= 0.0 || sky_sigma <= 0.0 || dh <= 0.0 || + sky_sigma <= dh) { + sky_mode = sky_mean + sky_sigma = 0.0 + sky_skew = 0.0 + return (AP_NOHISTOGRAM) + } + + # Allocate temporary space. + call smark (sp) + call salloc (hgm, nbins, TY_REAL) + call salloc (shgm, nbins, TY_REAL) + + # Accumulate the histogram. + call aclrr (Memr[hgm], nbins) + nsky_reject = nsky_reject + aphigmr (skypix, wgt, index, nskypix, + Memr[hgm], nbins, hmin, hmax) + nsky = nskypix - nsky_reject + + # Perform the initial rejection. + if (nsky_reject > 0) { + do i = 1, nskypix { + if (wgt[index[i]] <= 0.0) { + dsky = skypix[index[i]] - sky_zero + sumpx = sumpx - dsky + sumsqpx = sumsqpx - dsky ** 2 + sumcbpx = sumcbpx - dsky ** 3 + } + } + call apmoments (sumpx, sumsqpx, sumcbpx, nsky, sky_zero, + sky_mean, sky_sigma, sky_skew) + } + + # Fit the peak of the histogram. + center = apmapr ((hmin + hmax) / 2.0, hmin + 0.5 * dh, + hmax + 0.5 * dh, 1.0, real (nbins)) + if (smooth == YES) { + nker = max (1, nint (sky_sigma / dh)) + #call ap_lucy_smooth (Memr[hgm], Memr[shgm], nbins, nker, 2) + call ap_bsmooth (Memr[hgm], Memr[shgm], nbins, nker, 2) + iter = aptopt (Memr[shgm], nbins, center, sky_sigma / dh, + TOL, maxiter, NO) + } else + iter = aptopt (Memr[hgm], nbins, center, sky_sigma / dh, TOL, + maxiter, NO) + sky_mode = apmapr (center, 1.0, real (nbins), hmin + 0.5 * dh, + hmax + 0.5 * dh) + sky_mode = max (dmin, min (sky_mode, dmax)) + if (iter < 0) { + call sfree (sp) + return (AP_SKY_NOCONVERGE) + } + if ((IS_INDEFR(losigma) && IS_INDEFR(hisigma)) || (sky_sigma <= dh) || + (maxiter < 1)) { + call sfree (sp) + return (AP_OK) + } + + # Fit the histogram with pixel rejection and optional region growing. + do i = 1, maxiter { + + # Compute new histogram limits. + if (IS_INDEFR(losigma)) + locut = -MAX_REAL + else + locut = sky_mode - losigma * sky_sigma + if (IS_INDEFR(hisigma)) + hicut = MAX_REAL + else + hicut = sky_mode + hisigma * sky_sigma + + # Detect and reject the pixels. + nreject = 0 + do j = 1, nskypix { + if (skypix[index[j]] >= locut && skypix[index[j]] <= hicut) + next + if (rgrow > 0.0) + nreject = nreject + ap_grow_hist2 (skypix, coords, + wgt, nskypix, sky_zero, index[j], snx, sny, Memr[hgm], + nbins, hmin, hmax, rgrow, sumpx, sumsqpx, sumcbpx) + else if (wgt[index[j]] > 0.0) { + call ap_hgmsub2 (Memr[hgm], nbins, hmin, hmax, + skypix[index[j]], sky_zero, sumpx, sumsqpx, sumcbpx) + wgt[index[j]] = 0.0 + nreject = nreject + 1 + } + } + if (nreject == 0) + break + + # Recompute the data limits. + nsky_reject = nsky_reject + nreject + nsky = nskypix - nsky_reject + if (nsky <= 0) + break + call apmoments (sumpx, sumsqpx, sumcbpx, nsky, sky_zero, + sky_mean, sky_sigma, sky_skew) + if (sky_sigma <= dh) + break + + # Refit the sky. + if (smooth == YES) { + nker = max (1, nint (sky_sigma / dh)) + #call ap_lucy_smooth (Memr[hgm], Memr[shgm], nbins, nker, 2) + call ap_bsmooth (Memr[hgm], Memr[shgm], nbins, nker, 2) + iter = aptopt (Memr[shgm], nbins, center, sky_sigma / dh, + TOL, maxiter, NO) + } else + iter = aptopt (Memr[hgm], nbins, center, sky_sigma / dh, + TOL, maxiter, NO) + sky_mode = apmapr (center, 1.0, real (nbins), hmin + 0.5 * dh, + hmax + 0.5 * dh) + sky_mode = max (dmin, min (sky_mode, dmax)) + if (iter < 0) + break + } + + # Return an appropriate error code. + call sfree (sp) + if (nsky == 0 || nsky_reject == nskypix) { + nsky = 0 + nsky_reject = nskypix + sky_mode = INDEFR + sky_sigma = INDEFR + sky_skew = INDEFR + return (AP_NSKY_TOO_SMALL) + } else if (sky_sigma <= 0.0) { + sky_sigma = 0.0 + sky_skew = 0.0 + return (AP_OK) + } else if (iter < 0) { + return (AP_SKY_NOCONVERGE) + } else { + return (AP_OK) + } +end diff --git a/noao/digiphot/apphot/fitsky/apmean.x b/noao/digiphot/apphot/fitsky/apmean.x new file mode 100644 index 00000000..f134f02c --- /dev/null +++ b/noao/digiphot/apphot/fitsky/apmean.x @@ -0,0 +1,120 @@ +include <mach.h> +include "../lib/fitsky.h" + +# AP_MEAN -- Procedure to calculate the mean of the sky pixel array. + +int procedure ap_mean (skypix, coords, wgt, index, nskypix, snx, sny, losigma, + hisigma, rgrow, maxiter, sky_mean, sky_sigma, sky_skew, nsky, + nsky_reject) + +real skypix[ARB] # unsorted array of skypixels +int coords[ARB] # coordinate array for region growing +real wgt[ARB] # the weight array for rejection +int index[ARB] # sorted array of indices +int nskypix # total number of sky pixels +int snx, sny # dimensions of the sky subraster +real losigma, hisigma # number of sky_sigma for rejection +real rgrow # radius of region growing +int maxiter # maximum number of cycles of rejection +real sky_mean # computed sky value +real sky_sigma # the computed sky sigma +real sky_skew # skewness of sky distribution +int nsky # the number of sky pixels used +int nsky_reject # the number of sky pixels rejected + +double dsky, sumpx, sumsqpx, sumcbpx +int i, j, nreject +real sky_zero, dmin, dmax, locut, hicut +int ap_grow_regions() +real ap_asumr() + +begin + # Intialize. + nsky = nskypix + nsky_reject = 0 + sky_mean = INDEFR + sky_sigma = INDEFR + sky_skew = INDEFR + if (nskypix <= 0) + return (AP_NOSKYAREA) + + # Compute the mean, sigma and skew. + sky_zero = ap_asumr (skypix, index, nskypix) / nskypix + call apfimoments (skypix, index, nskypix, sky_zero, sumpx, sumsqpx, + sumcbpx, sky_mean, sky_sigma, sky_skew) + call ap_ialimr (skypix, index, nskypix, dmin, dmax) + sky_mean = max (dmin, min (sky_mean, dmax)) + + # Decide whether to do the rejection cycle. + if (maxiter < 1 || (IS_INDEFR(losigma) && IS_INDEFR(hisigma)) || + sky_sigma <= 0.0) + return (AP_OK) + + # Reject points within k1 * sky_sigma of the median. + do i = 1, maxiter { + + # Compute the new rejection limits. + if (IS_INDEFR(losigma)) + locut = max (-MAX_REAL, dmin) + else if (i == 1) + locut = sky_mean - min (sky_mean - dmin, dmax - sky_mean, + losigma * sky_sigma) + else + locut = sky_mean - losigma * sky_sigma + if (IS_INDEFR(hisigma)) + hicut = min (MAX_REAL, dmax) + else if (i == 1) + hicut = sky_mean + min (dmax - sky_mean, sky_mean - dmin, + hisigma * sky_sigma) + else + hicut = sky_mean + hisigma * sky_sigma + + nreject = 0 + do j = 1, nskypix { + if (wgt[index[j]] <= 0.0) + next + if (skypix[index[j]] < locut || skypix[index[j]] > hicut) { + if (rgrow > 0.0) { + nreject = ap_grow_regions (skypix, coords, wgt, + nskypix, sky_zero, index[j], snx, sny, rgrow, + sumpx, sumsqpx, sumcbpx) + } else { + dsky = (skypix[index[j]] - sky_zero) + sumpx = sumpx - dsky + sumsqpx = sumsqpx - dsky ** 2 + sumcbpx = sumcbpx - dsky ** 3 + wgt[index[j]] = 0.0 + nreject = nreject + 1 + } + } + } + + # Test the number of rejected pixels. + if (nreject <= 0) + break + nsky_reject = nsky_reject + nreject + + # Test that some pixels actually remain. + nsky = nskypix - nsky_reject + if (nsky <= 0) + break + + # Recompute the mean, sigma and skew. + call apmoments (sumpx, sumsqpx, sumcbpx, nsky, sky_zero, + sky_mean, sky_sigma, sky_skew) + if (sky_sigma <= 0.0) + break + sky_mean = max (dmin, min (sky_mean, dmax)) + } + + # Return an appropriate error code. + if (nsky == 0 || nsky_reject == nskypix) { + nsky = 0 + nsky_reject = nskypix + sky_mean = INDEFR + sky_sigma = INDEFR + sky_skew = INDEFR + return (AP_NSKY_TOO_SMALL) + } else + return (AP_OK) +end diff --git a/noao/digiphot/apphot/fitsky/apmedian.x b/noao/digiphot/apphot/fitsky/apmedian.x new file mode 100644 index 00000000..5998492c --- /dev/null +++ b/noao/digiphot/apphot/fitsky/apmedian.x @@ -0,0 +1,184 @@ +include <mach.h> +include "../lib/fitsky.h" + +define MEDCUT 0.025 + +# AP_MEDIAN -- Procedure to calculate the median of the sky pixel array. + +int procedure ap_median (skypix, coords, wgt, index, nskypix, snx, sny, losigma, + hisigma, rgrow, maxiter, sky_med, sky_sigma, sky_skew, nsky, + nsky_reject) + +real skypix[ARB] # unsorted array of sky pixels +int coords[ARB] # coordinate array for regions growing +real wgt[ARB] # array of weights for rejections +int index[ARB] # sky pixel indices in sort order +int nskypix # total number of sky pixels +int snx, sny # dimensions of the sky subraster +real losigma, hisigma # upper and lower sigma for rejection +real rgrow # radius of region growing +int maxiter # maximum number of cycles of rejection +real sky_med # computed sky value +real sky_sigma # the computed sky sigma +real sky_skew # skewness of sky distribution +int nsky # the number of sky pixels used +int nsky_reject # the number of sky pixels rejected + +double dsky, sumpx, sumsqpx, sumcbpx +int i, j, ilo, ihi, il, ih, med, medcut +real sky_zero, sky_mean, locut, hicut, dmin, dmax +int ap_grow_regions(), apimed() +real apsmed(), apwsmed(), ap_asumr() + +begin + # Intialize. + nsky = nskypix + nsky_reject = 0 + sky_med = INDEFR + sky_sigma = INDEFR + sky_skew = INDEFR + if (nskypix <= 0) + return (AP_NOSKYAREA) + + # Sort the sky pixels and compute the median, mean, sigma and skew. + # MEDCUT tries to correct for quantization effects + call ap_ialimr (skypix, index, nskypix, dmin, dmax) + sky_zero = ap_asumr (skypix, index, nskypix) / nskypix + medcut = nint (MEDCUT * real (nskypix)) + sky_med = apsmed (skypix, index, nskypix, medcut) + sky_med = max (dmin, min (sky_med, dmax)) + call apfimoments (skypix, index, nskypix, sky_zero, sumpx, sumsqpx, + sumcbpx, sky_mean, sky_sigma, sky_skew) + sky_mean = max (dmin, min (sky_mean, dmax)) + if (maxiter < 1 || (IS_INDEFR(losigma) && IS_INDEFR(hisigma)) || + sky_sigma <= 0.0) + return (AP_OK) + #call printf ( + #"mean=%g med=%g sigma=%g nsky=%d nrej=%d dmin=%g dmax=%g\n") + #call pargr (sky_mean) + #call pargr (sky_med) + #call pargr (sky_sigma) + #call pargi (nsky) + #call pargi (nsky_reject) + #call pargr (dmin) + #call pargr (dmax) + + # Reject points outside losigma * sky_sigma and hisigma * sky_sigma + # of the median. + ilo = 1 + ihi = nskypix + do i = 1, maxiter { + + # Compute the new rejection limits. + if (IS_INDEFR(losigma)) + locut = max (-MAX_REAL, dmin) + else if (i == 1) + locut = sky_med - min (sky_med - dmin, dmax - sky_med, + losigma * sky_sigma) + else + locut = sky_med - losigma * sky_sigma + if (IS_INDEFR(hisigma)) + hicut = min (MAX_REAL, dmax) + else if (i == 1) + hicut = sky_med + min (dmax - sky_med, sky_med - dmin, + hisigma * sky_sigma) + else + hicut = sky_med + hisigma * sky_sigma + #call printf (" locut=%g hicut=%g\n") + #call pargr (locut) + #call pargr (hicut) + + # Detect pixels to be rejected. + for (il = ilo; il <= nskypix; il = il + 1) { + if (skypix[index[il]] >= locut) + break + } + for (ih = ihi; ih >= 1; ih = ih - 1) { + if (skypix[index[ih]] <= hicut) + break + } + if (il == ilo && ih == ihi) + break + + # Reject pixels with optional region growing. + if (rgrow > 0.0) { + + # Reject low side pixels with region growing. + do j = ilo, il - 1 + nsky_reject = nsky_reject + ap_grow_regions (skypix, coords, + wgt, nskypix, sky_zero, index[j], snx, sny, rgrow, + sumpx, sumsqpx, sumcbpx) + + # Reject high side pixels with region growing. + do j = ih + 1, ihi + nsky_reject = nsky_reject + ap_grow_regions (skypix, coords, + wgt, nskypix, sky_zero, index[j], snx, sny, rgrow, + sumpx, sumsqpx, sumcbpx) + + # Recompute the median. + # and the median pixel + nsky = nskypix - nsky_reject + med = apimed (wgt, index, il, ih, (nsky + 1) / 2) + + + } else { + + # Recompute the number of sky pixels, the number of rejected + # pixels and median pixel + nsky_reject = nsky_reject + (il - ilo) + (ihi - ih) + nsky = nskypix - nsky_reject + med = (ih + il) / 2 + + # Reject pixels on the low side. + do j = ilo, il - 1 { + dsky = skypix[index[j]] - sky_zero + sumpx = sumpx - dsky + sumsqpx = sumsqpx - dsky ** 2 + sumcbpx = sumcbpx - dsky ** 3 + } + + # Reject pixels on the high side. + do j = ih + 1, ihi { + dsky = skypix[index[j]] - sky_zero + sumpx = sumpx - dsky + sumsqpx = sumsqpx - dsky ** 2 + sumcbpx = sumcbpx - dsky ** 3 + } + } + if (nsky <= 0) + break + + # Recompute the median, sigma and skew. + medcut = nint (MEDCUT * real (nsky)) + sky_med = apwsmed (skypix, index, wgt, nskypix, med, medcut) + sky_med = max (dmin, min (sky_med, dmax)) + call apmoments (sumpx, sumsqpx, sumcbpx, nsky, sky_zero, + sky_mean, sky_sigma, sky_skew) + sky_mean = max (dmin, min (sky_mean, dmax)) + #call printf ( + #" mean=%g med=%g sigma=%g nsky=%d nrej=%d dmin=%g dmax=%g\n") + #call pargr (sky_mean) + #call pargr (sky_med) + #call pargr (sky_sigma) + #call pargi (nsky) + #call pargi (nsky_reject) + #call pargr (dmin) + #call pargr (dmax) + + if (sky_sigma <= 0.0) + break + ilo = il + ihi = ih + } + + # Return an appropriate error code. + if (nsky == 0 || nsky_reject == nskypix) { + nsky = 0 + nsky_reject = nskypix + sky_med = INDEFR + sky_sigma = INDEFR + sky_skew = INDEFR + return (AP_NSKY_TOO_SMALL) + } else + return (AP_OK) +end diff --git a/noao/digiphot/apphot/fitsky/apmode.x b/noao/digiphot/apphot/fitsky/apmode.x new file mode 100644 index 00000000..fc32ba43 --- /dev/null +++ b/noao/digiphot/apphot/fitsky/apmode.x @@ -0,0 +1,185 @@ +include <mach.h> +include "../lib/fitsky.h" + +define MEDCUT 0.025 + +# AP_MODE -- Procedure to calculate the mode of the sky pixel array. + +int procedure ap_mode (skypix, coords, wgt, index, nskypix, snx, sny, losigma, + hisigma, rgrow, maxiter, sky_mode, sky_sigma, sky_skew, nsky, + nsky_reject) + +real skypix[ARB] # unsorted array of skypixels +int coords[ARB] # coordinate array for regions growing +real wgt[ARB] # array of weights for rejection +int index[ARB] # indices in sort order +int nskypix # total number of sky pixels +int snx, sny # dimensions of the sky subraster +real losigma, hisigma # number of sky_sigma for rejection +real rgrow # radius of region growing +int maxiter # maximum number of cycles of rejection +real sky_mode # computed sky value +real sky_sigma # the computed sky sigma +real sky_skew # skew of sky pixels +int nsky # the number of sky pixels used +int nsky_reject # the number of sky pixels rejected + +double dsky, sumpx, sumsqpx, sumcbpx +int i, j, ilo, ihi, il, ih, med, medcut +real dmin, dmax, locut, hicut, sky_zero, sky_mean, sky_med +int ap_grow_regions(), apimed() +real apsmed(), apwsmed(), ap_asumr() + +begin + # Initialize. + nsky = nskypix + nsky_reject = 0 + sky_mode = INDEFR + sky_sigma = INDEFR + sky_skew = INDEFR + if (nskypix <= 0) + return (AP_NOSKYAREA) + + # Compute the median, sigma, skew and sky mode. + sky_zero = ap_asumr (skypix, index, nskypix) / nskypix + call ap_ialimr (skypix, index, nskypix, dmin, dmax) + medcut = nint (MEDCUT * real (nskypix)) + sky_med = apsmed (skypix, index, nskypix, medcut) + sky_med = max (dmin, min (sky_med, dmax)) + call apfimoments (skypix, index, nskypix, sky_zero, sumpx, sumsqpx, + sumcbpx, sky_mean, sky_sigma, sky_skew) + sky_mean = max (dmin, min (sky_mean, dmax)) + if (sky_mean < sky_med) + sky_mode = sky_mean + else + sky_mode = 3.0 * sky_med - 2.0 * sky_mean + sky_mode = max (dmin, min (sky_mode, dmax)) + if (maxiter < 1 || (IS_INDEFR(losigma) && IS_INDEFR(hisigma)) || + sky_sigma <= 0.0) + return (AP_OK) + + # Reject points outside losigma * sky_sigma and hisigma * sky_sigma + # of the mode. + ilo = 1 + ihi = nskypix + do i = 1, maxiter { + + # Compute the new rejection limits. + if (i == 1) { + if (IS_INDEFR(losigma)) + locut = max (-MAX_REAL, dmin) + else + locut = sky_med - min (sky_med - dmin, dmax - sky_med, + losigma * sky_sigma) + if (IS_INDEFR(hisigma)) + hicut = min (MAX_REAL, dmax) + else + hicut = sky_med + min (sky_med - dmin, dmax - sky_med, + hisigma * sky_sigma) + } else { + if (IS_INDEFR(losigma)) + locut = max (-MAX_REAL, dmin) + else + locut = sky_mode - losigma * sky_sigma + if (IS_INDEFR(hisigma)) + hicut = min (MAX_REAL, dmax) + else + hicut = sky_mode + hisigma * sky_sigma + } + #call eprintf ("i=%d mean=%g median=%g mode=%g locut=%g hicut=%g\n") + #call pargi (i) + #call pargr (sky_mean) + #call pargr (sky_med) + #call pargr (sky_mode) + #call pargr (locut) + #call pargr (hicut) + + # Perform lower bound pixel rejection. + for (il = ilo; il <= nskypix; il = il + 1) { + if (skypix[index[il]] >= locut) + break + } + + # Perform upper bound pixel rejection. + for (ih = ihi; ih >= 1; ih = ih - 1) { + if (skypix[index[ih]] <= hicut) + break + } + if (il == ilo && ih == ihi) + break + + # Compute number of rejected pixels with optional region growing. + if (rgrow > 0.0) { + + # Reject lower bound pixels with region growing. + do j = ilo, il - 1 + nsky_reject = nsky_reject + ap_grow_regions (skypix, coords, + wgt, nskypix, sky_zero, index[j], snx, sny, rgrow, + sumpx, sumsqpx, sumcbpx) + + # Reject upper bound pixels with region growing. + do j = ih + 1, ihi + nsky_reject = nsky_reject + ap_grow_regions (skypix, coords, + wgt, nskypix, sky_zero, index[j], snx, sny, rgrow, + sumpx, sumsqpx, sumcbpx) + + # Compute the new median. + nsky = nskypix - nsky_reject + med = apimed (wgt, index, il, ihi, (nsky + 1) / 2) + + } else { + + # Recompute the number of sky pixels, number of rejected + # pixels and the median. + nsky_reject = nsky_reject + (il - ilo) + (ihi - ih) + nsky = nskypix - nsky_reject + med = (ih + il) / 2 + + # Reject number of lower bound pixels. + do j = ilo, il - 1 { + dsky = skypix[index[j]] - sky_zero + sumpx = sumpx - dsky + sumsqpx = sumsqpx - dsky ** 2 + sumcbpx = sumcbpx - dsky ** 3 + } + + # Reject number of upper bound pixels. + do j = ih + 1, ihi { + dsky = skypix[index[j]] - sky_zero + sumpx = sumpx - dsky + sumsqpx = sumsqpx - dsky ** 2 + sumcbpx = sumcbpx - dsky ** 3 + } + } + if (nsky <= 0) + break + + # Recompute mean, median, mode, sigma and skew. + medcut = nint (MEDCUT * real (nsky)) + sky_med = apwsmed (skypix, index, wgt, nskypix, med, medcut) + sky_med = max (dmin, min (sky_med, dmax)) + call apmoments (sumpx, sumsqpx, sumcbpx, nsky, sky_zero, + sky_mean, sky_sigma, sky_skew) + sky_mean = max (dmin, min (sky_mean, dmax)) + if (sky_mean < sky_med) + sky_mode = sky_mean + else + sky_mode = 3.0 * sky_med - 2.0 * sky_mean + sky_mode = max (dmin, min (sky_mode, dmax)) + if (sky_sigma <= 0.0) + break + ilo = il + ihi = ih + } + + # Return an appropriate error code. + if (nsky == 0 || nsky_reject == nskypix) { + nsky = 0 + nsky_reject = nskypix + sky_mode = INDEFR + sky_sigma = INDEFR + sky_skew = INDEFR + return (AP_NSKY_TOO_SMALL) + } else + return (AP_OK) +end diff --git a/noao/digiphot/apphot/fitsky/appsky.x b/noao/digiphot/apphot/fitsky/appsky.x new file mode 100644 index 00000000..8da9773e --- /dev/null +++ b/noao/digiphot/apphot/fitsky/appsky.x @@ -0,0 +1,103 @@ +include "../lib/apphot.h" +include "../lib/fitsky.h" + +# AP_PSSKY -- Procedure to write the results of the fitsky task to +# the output file. + +procedure ap_pssky (ap, fd, id, ld, ier) + +pointer ap # pointer to apphot structure +int fd # output file descriptor +int id # sequence number of star +int ld # list number of star +int ier # error code + +real apstatr() + +begin + # Return if NULL file descriptor. + if (fd == NULL) + return + + # Print the object id and computed sky values. + call ap_wid (ap, fd, apstatr (ap, OSXCUR), apstatr (ap, OSYCUR), id, + ld, '\\') + call ap_wsres (ap, fd, ier, ' ') +end + + +# AP_QSPSKY -- Procedure to print a quick summary of the fitsky task on the +# standard output. + +procedure ap_qspsky (ap, ier) + +pointer ap # pointer to apphot structure +int ier # error code + +pointer sp, imname +int apstati() +real apstatr() + +begin + # Print out the results on the standard output. + call smark (sp) + call salloc (imname, SZ_FNAME, TY_CHAR) + call apstats (ap, IMROOT, Memc[imname], SZ_FNAME) + call printf ( "%s %8.2f %8.2f %8g %8g ") + call pargstr (Memc[imname]) + call pargr (apstatr (ap, OSXCUR)) + call pargr (apstatr (ap, OSYCUR)) + call pargr (apstatr (ap, SKY_MODE)) + call pargr (apstatr (ap, SKY_SIGMA)) + call printf ("%8g %5d %5d %s\n") + call pargr (apstatr (ap, SKY_SKEW)) + call pargi (apstati (ap, NSKY)) + call pargi (apstati (ap, NSKY_REJECT)) + if (ier != AP_OK) + call pargstr ("err") + else + call pargstr ("ok") + call sfree (sp) +end + + +# AP_QASPSKY -- Procedure to print a quick summary of the fitsky task on the +# standard output. + +procedure ap_qaspsky (ap, ier) + +pointer ap # pointer to apphot structure +int ier # error code + +int apstati() +real apstatr() + +begin + # Print out the results on the standard output. + call printf ( " Averages %8g %8g ") + call pargr (apstatr (ap, SKY_MODE)) + call pargr (apstatr (ap, SKY_SIGMA)) + call printf ("%8g %5d %5d %s\n\n") + call pargr (apstatr (ap, SKY_SKEW)) + call pargi (apstati (ap, NSKY)) + call pargi (apstati (ap, NSKY_REJECT)) + if (ier != AP_OK) + call pargstr ("err") + else + call pargstr ("ok") +end + +# AP_SPHDR -- Procedure to write the banner for the fitsky task to the +# output file. + +procedure ap_sphdr (ap, fd) + +pointer ap # pointer to apphot structure +int fd # output file descriptor + +begin + if (fd == NULL) + return + call ap_idhdr (ap, fd) + call ap_shdr (ap, fd) +end diff --git a/noao/digiphot/apphot/fitsky/appspars.x b/noao/digiphot/apphot/fitsky/appspars.x new file mode 100644 index 00000000..50da0f84 --- /dev/null +++ b/noao/digiphot/apphot/fitsky/appspars.x @@ -0,0 +1,22 @@ +include "../lib/display.h" + +# AP_PSPARS -- Procedure to write out the current sky fitting parameters +# to the parameter files. + +procedure ap_pspars (ap) + +pointer ap # pointer to apphot structure + +bool itob() +int apstati() + +begin + # Write the data dependent parameters. + call ap_dapars (ap) + + # Write the sky fitting parameters. + call ap_sapars (ap) + + # Radial profile plots + call clputb ("radplots", itob (apstati (ap, RADPLOTS))) +end diff --git a/noao/digiphot/apphot/fitsky/apradplot.x b/noao/digiphot/apphot/fitsky/apradplot.x new file mode 100644 index 00000000..d9d19992 --- /dev/null +++ b/noao/digiphot/apphot/fitsky/apradplot.x @@ -0,0 +1,91 @@ +include "../lib/fitsky.h" + +# AP_RADPLOT -- Procedure to compute the mode, sigma, and skew of the sky by +# eye using a radial profile plot of the sky pixels and cursor readback. + +int procedure ap_radplot (gd, gt, skypix, coords, index, nskypix, sxc, syc, + snx, sny, scale, sky_mode, sky_skew, sky_sigma, nsky, + nsky_reject) + +pointer gd # pointer to graphics stream +pointer gt # pointer to gtools structure +real skypix[ARB] # array of sky pixels +int coords[ARB] # array of sky coordinates +int index[ARB] # the index array +int nskypix # number of sky pixels +real sxc, syc # sky subraster center +int snx, sny # sky subraster size +real scale # the image scale +real sky_mode # computed sky value +real sky_sigma # computed sigma of sky pixels +real sky_skew # computed skew of sky pixels +int nsky # number of sky pixels used in fit +int nsky_reject # number of rejected sky pixels + +double sumpx, sumsqpx, sumcbpx +int wcs, key +pointer sp, r, cmd +real wx, wy, xmin, xmax, ymin, ymax, u1, u2, v1, v2, x1, x2, y1, y2 +real sky_zero +int clgcur() +real ap_asumr() + +begin + if (gd == NULL) + return (AP_NOGRAPHICS) + + # Initialize. + nsky = nskypix + nsky_reject = 0 + sky_mode = INDEFR + sky_sigma = INDEFR + sky_skew = INDEFR + if (nskypix <= 0) + return (AP_SKY_OUTOFBOUNDS) + + call smark (sp) + call salloc (r, nskypix, TY_REAL) + call salloc (cmd, SZ_LINE, TY_CHAR) + + # Compute an initial guess at the data characteristics. + nsky = nskypix + sky_zero = ap_asumr (skypix, index, nskypix) / nskypix + call apfimoments (skypix, index, nskypix, sky_zero, sumpx, sumsqpx, + sumcbpx, sky_mode, sky_sigma, sky_skew) + + # Store the old window and viewport coordinates. + call ggview (gd, u1, u2, v1, v2) + call ggwind (gd, x1, x2, y1, y2) + + # Compute the radial profile + call ap_xytor (coords, index, Memr[r], nskypix, sxc, syc, snx) + call alimr (Memr[r], nskypix, xmin, xmax) + call alimr (skypix, nskypix, ymin, ymax) + + # Plot the radial profile. + call gclear (gd) + call ap_rset (gd, gt, xmin, xmax, ymin, ymax, scale) + call ap_plotrad (gd, gt, Memr[r], skypix, nskypix, "plus") + + # Mark the sky level with the cursor. + call printf ("Mark sky level (%g) [space=mark,q=quit,:.help=help]:") + call pargr (sky_mode) + call gscur (gd, (xmin + xmax) / 2.0, sky_mode) + while (clgcur ("gcommands", wx, wy, wcs, key, Memc[cmd], SZ_LINE) != + EOF) { + if (key == 'q') + break + else + sky_mode = wy + call printf ("Mark sky level (%g) [space=mark,q=quit,:.help=help]:") + call pargr (sky_mode) + call gscur (gd, (xmin + xmax) / 2.0, sky_mode) + } + + # Store the old window and viewport coordinates. + call gsview (gd, u1, u2, v1, v2) + call gswind (gd, x1, x2, y1, y2) + + call sfree (sp) + return (AP_OK) +end diff --git a/noao/digiphot/apphot/fitsky/apreadsky.x b/noao/digiphot/apphot/fitsky/apreadsky.x new file mode 100644 index 00000000..3db9a183 --- /dev/null +++ b/noao/digiphot/apphot/fitsky/apreadsky.x @@ -0,0 +1,40 @@ +# AP_READSKY -- Procedure to read sky values, sigma and skew from a file +# The x and y positions, sky mode, sigma, and skew values, number of sky +# pixels and number of rejected sky pixels are assumed to be columns +# 1 to 7 respectively. + +int procedure ap_readsky (fd, x, y, sky_mode, sky_sigma, sky_skew, nsky, + nsky_reject) + +int fd # sky file descriptor +real x, y # center of sky annulus +real sky_mode # sky valye +real sky_sigma # sky sigma +real sky_skew # skew of sky pixels +int nsky # number of sky pixels +int nsky_reject # number of rejected pixesl + +int stat +int fscan(), nscan() + +begin + # Initialize. + sky_mode = INDEFR + sky_sigma = INDEFR + sky_skew = INDEFR + nsky = 0 + nsky_reject = 0 + + # Read in and decode a sky file text line. + stat = fscan (fd) + if (stat == EOF) + return (EOF) + call gargr (x) + call gargr (y) + call gargr (sky_mode) + call gargr (sky_sigma) + call gargr (sky_skew) + call gargi (nsky) + call gargi (nsky_reject) + return (nscan ()) +end diff --git a/noao/digiphot/apphot/fitsky/aprefitsky.x b/noao/digiphot/apphot/fitsky/aprefitsky.x new file mode 100644 index 00000000..bc4ed6c2 --- /dev/null +++ b/noao/digiphot/apphot/fitsky/aprefitsky.x @@ -0,0 +1,371 @@ +include "../lib/apphotdef.h" +include "../lib/apphot.h" +include "../lib/noisedef.h" +include "../lib/fitskydef.h" +include "../lib/fitsky.h" + +# APREFITSKY -- Procedure to fit the sky using the pixels currently stored in +# the sky fitting buffers. + +int procedure aprefitsky (ap, im, gd) + +pointer ap # pointer to the apphot structure +pointer im # the input image descriptor +pointer gd # pointer to graphics stream + +int ier, nclip, nsky, ilo, ihi +pointer sky, nse, gt +int ap_mode(), ap_centroid(), ap_histplot(), ap_median() +int ap_radplot(), ap_gauss(), ap_lgsky(), ap_crosscor() +int ap_mean(), ap_clip() +pointer ap_gtinit() + +begin + # Initialize. + sky = AP_PSKY(ap) + nse = AP_NOISE(ap) + AP_SKY_MODE(sky) = INDEFR + AP_SKY_SIG(sky) = INDEFR + AP_SKY_SKEW(sky) = INDEFR + AP_NSKY(sky) = 0 + AP_NSKY_REJECT(sky) = 0 + if (IS_INDEFR(AP_SXCUR(sky)) || IS_INDEFR(AP_SYCUR(sky))) { + AP_OSXCUR(sky) = AP_SXCUR(sky) + AP_OSYCUR(sky) = AP_SYCUR(sky) + } else { + switch (AP_WCSOUT(ap)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_ltoo (ap, AP_SXCUR(sky), AP_SYCUR(sky), AP_OSXCUR(sky), + AP_OSYCUR(sky), 1) + case WCS_TV: + call ap_ltov (im, AP_SXCUR(sky), AP_SYCUR(sky), AP_OSXCUR(sky), + AP_OSYCUR(sky), 1) + default: + AP_OSXCUR(sky) = AP_SXCUR(sky) + AP_OSYCUR(sky) = AP_SYCUR(sky) + } + } + + if (IS_INDEFR(AP_SXCUR(sky)) || IS_INDEFR(AP_SYCUR(sky))) + return (AP_NOSKYAREA) + + switch (AP_SKYFUNCTION(sky)) { + + case AP_MEAN: + + # Initialize the weights. + call amovkr (1.0, Memr[AP_SWGT(sky)], AP_NSKYPIX(sky)) + + # Clip the data. + if (AP_SLOCLIP(sky) > 0.0 || AP_SHICLIP(sky) > 0.0) { + nclip = ap_clip (Memr[AP_SKYPIX(sky)], Memi[AP_INDEX(sky)], + AP_NSKYPIX(sky), AP_SLOCLIP(sky), AP_SHICLIP(sky), ilo, + ihi) + if (nclip >= AP_NSKYPIX(sky)) + return (AP_NSKY_TOO_SMALL) + nsky = AP_NSKYPIX(sky) - nclip + } else { + nclip = 0 + call ap_index (Memi[AP_INDEX(sky)], AP_NSKYPIX(sky)) + ilo = 1 + nsky = AP_NSKYPIX(sky) + } + + ier = ap_mean (Memr[AP_SKYPIX(sky)], Memi[AP_COORDS(sky)], + Memr[AP_SWGT(sky)], Memi[AP_INDEX(sky)+ilo-1], nsky, + AP_SNX(sky), AP_SNY(sky), AP_SLOREJECT(sky), + AP_SHIREJECT(sky), AP_RGROW(sky) * AP_SCALE(ap), + AP_SNREJECT(sky), AP_SKY_MODE(sky), AP_SKY_SIG(sky), + AP_SKY_SKEW(sky), AP_NSKY(sky), AP_NSKY_REJECT(sky)) + AP_NSKY_REJECT(sky) = AP_NBADSKYPIX(sky) + nclip + + AP_NSKY_REJECT(sky) + + return (ier) + + case AP_MEDIAN: + + # Initialize the weights. + call amovkr (1.0, Memr[AP_SWGT(sky)], AP_NSKYPIX(sky)) + + # Clip the data. + if (AP_SLOCLIP(sky) > 0.0 || AP_SHICLIP(sky) > 0.0) { + nclip = ap_clip (Memr[AP_SKYPIX(sky)], Memi[AP_INDEX(sky)], + AP_NSKYPIX(sky), AP_SLOCLIP(sky), AP_SHICLIP(sky), ilo, + ihi) + if (nclip >= AP_NSKYPIX(sky)) + return (AP_NSKY_TOO_SMALL) + nsky = AP_NSKYPIX(sky) - nclip + } else { + nclip = 0 + call apqsort (Memr[AP_SKYPIX(sky)], Memi[AP_INDEX(sky)], + Memi[AP_INDEX(sky)], AP_NSKYPIX(sky)) + ilo = 1 + nsky = AP_NSKYPIX(sky) + } + + ier = ap_median (Memr[AP_SKYPIX(sky)], Memi[AP_COORDS(sky)], + Memr[AP_SWGT(sky)], Memi[AP_INDEX(sky)+ilo-1], nsky, + AP_SNX(sky), AP_SNY(sky), AP_SLOREJECT(sky), + AP_SHIREJECT(sky), AP_RGROW(sky) * AP_SCALE(ap), + AP_SNREJECT(sky), AP_SKY_MODE(sky), AP_SKY_SIG(sky), + AP_SKY_SKEW(sky), AP_NSKY(sky), AP_NSKY_REJECT(sky)) + AP_NSKY_REJECT(sky) = AP_NBADSKYPIX(sky) + nclip + + AP_NSKY_REJECT(sky) + return (ier) + + case AP_MODE: + + # Initialize the weights. + call amovkr (1.0, Memr[AP_SWGT(sky)], AP_NSKYPIX(sky)) + + # Clip the data. + if (AP_SLOCLIP(sky) > 0.0 || AP_SHICLIP(sky) > 0.0) { + nclip = ap_clip (Memr[AP_SKYPIX(sky)], Memi[AP_INDEX(sky)], + AP_NSKYPIX(sky), AP_SLOCLIP(sky), AP_SHICLIP(sky), ilo, + ihi) + if (nclip >= AP_NSKYPIX(sky)) + return (AP_NSKY_TOO_SMALL) + nsky = AP_NSKYPIX(sky) - nclip + } else { + nclip = 0 + call apqsort (Memr[AP_SKYPIX(sky)], Memi[AP_INDEX(sky)], + Memi[AP_INDEX(sky)], AP_NSKYPIX(sky)) + ilo = 1 + nsky = AP_NSKYPIX(sky) + } + + ier = ap_mode (Memr[AP_SKYPIX(sky)], Memi[AP_COORDS(sky)], + Memr[AP_SWGT(sky)], Memi[AP_INDEX(sky)+ilo-1], nsky, + AP_SNX(sky), AP_SNY(sky), AP_SLOREJECT(sky), + AP_SHIREJECT(sky), AP_RGROW(sky) * AP_SCALE(ap), + AP_SNREJECT(sky), AP_SKY_MODE(sky), AP_SKY_SIG(sky), + AP_SKY_SKEW(sky), AP_NSKY(sky), AP_NSKY_REJECT(sky)) + AP_NSKY_REJECT(sky) = AP_NBADSKYPIX(sky) + nclip + + AP_NSKY_REJECT(sky) + + return (ier) + + case AP_CENTROID: + + # Initialize the weights. + call amovkr (1.0, Memr[AP_SWGT(sky)], AP_NSKYPIX(sky)) + + # Clip the data. + if (AP_SLOCLIP(sky) > 0.0 || AP_SHICLIP(sky) > 0.0) { + nclip = ap_clip (Memr[AP_SKYPIX(sky)], Memi[AP_INDEX(sky)], + AP_NSKYPIX(sky), AP_SLOCLIP(sky), AP_SHICLIP(sky), ilo, + ihi) + if (nclip >= AP_NSKYPIX(sky)) + return (AP_NSKY_TOO_SMALL) + nsky = AP_NSKYPIX(sky) - nclip + } else { + nclip = 0 + call ap_index (Memi[AP_INDEX(sky)], AP_NSKYPIX(sky)) + ilo = 1 + nsky = AP_NSKYPIX(sky) + } + + ier = ap_centroid (Memr[AP_SKYPIX(sky)], Memi[AP_COORDS(sky)], + Memr[AP_SWGT(sky)+ilo-1], Memi[AP_INDEX(sky)+ilo-1], nsky, + AP_SNX(sky), AP_SNY(sky), AP_K1(sky), INDEFR, + AP_BINSIZE(sky), AP_SMOOTH(sky), AP_SLOREJECT(sky), + AP_SHIREJECT(sky), AP_RGROW(sky) * AP_SCALE(ap), + AP_SMAXITER(sky), AP_SKY_MODE(sky), AP_SKY_SIG(sky), + AP_SKY_SKEW(sky), AP_NSKY(sky), AP_NSKY_REJECT(sky)) + AP_NSKY_REJECT(sky) = AP_NBADSKYPIX(sky) + nclip + + AP_NSKY_REJECT(sky) + + return (ier) + + case AP_CONSTANT: + + AP_SKY_MODE(sky) = AP_SKYBACKGROUND(sky) + AP_SKY_SIG(sky) = AP_SKYSIGMA(nse) + AP_SKY_SKEW(sky) = INDEFR + AP_NSKY(sky) = 0 + AP_NSKY_REJECT(sky) = 0 + return (AP_OK) + + case AP_SKYFILE: + + return (AP_OK) + + case AP_RADPLOT: + + # Check the status of the graphics stream. + if (gd == NULL) + return (AP_NOGRAPHICS) + + # Clip the data. + if (AP_SLOCLIP(sky) > 0.0 || AP_SHICLIP(sky) > 0.0) { + nclip = ap_clip (Memr[AP_SKYPIX(sky)], Memi[AP_INDEX(sky)], + AP_NSKYPIX(sky), AP_SLOCLIP(sky), AP_SHICLIP(sky), ilo, + ihi) + if (nclip >= AP_NSKYPIX(sky)) + return (AP_NSKY_TOO_SMALL) + nsky = AP_NSKYPIX(sky) - nclip + } else { + nclip = 0 + call ap_index (Memi[AP_INDEX(sky)], AP_NSKYPIX(sky)) + ilo = 1 + nsky = AP_NSKYPIX(sky) + } + + call gactivate (gd, 0) + gt = ap_gtinit (AP_IMROOT(ap), AP_SXCUR(sky), AP_SYCUR(sky)) + ier = ap_radplot (gd, gt, Memr[AP_SKYPIX(sky)], + Memi[AP_COORDS(sky)], Memi[AP_INDEX(sky)+ilo-1], nsky, + AP_SXC(sky), AP_SYC(sky), AP_SNX(sky), AP_SNY(sky), + AP_SCALE(ap), AP_SKY_MODE(sky), AP_SKY_SIG(sky), + AP_SKY_SKEW(sky), AP_NSKY(sky), AP_NSKY_REJECT(sky)) + AP_NSKY_REJECT(sky) = AP_NBADSKYPIX(sky) + nclip + + AP_NSKY_REJECT(sky) + call ap_gtfree (gt) + call gdeactivate (gd, 0) + + return (ier) + + case AP_HISTPLOT: + + # Check the status of the graphics stream. + if (gd == NULL) + return (AP_NOGRAPHICS) + + # Initialize the weights. + call amovkr (1.0, Memr[AP_SWGT(sky)], AP_NSKYPIX(sky)) + + # Clip the data. + if (AP_SLOCLIP(sky) > 0.0 || AP_SHICLIP(sky) > 0.0) { + nclip = ap_clip (Memr[AP_SKYPIX(sky)], Memi[AP_INDEX(sky)], + AP_NSKYPIX(sky), AP_SLOCLIP(sky), AP_SHICLIP(sky), ilo, + ihi) + if (nclip >= AP_NSKYPIX(sky)) + return (AP_NSKY_TOO_SMALL) + nsky = AP_NSKYPIX(sky) - nclip + } else { + nclip = 0 + call ap_index (Memi[AP_INDEX(sky)], AP_NSKYPIX(sky)) + ilo = 1 + nsky = AP_NSKYPIX(sky) + } + + #call gactivate (gd, 0) + gt = ap_gtinit (AP_IMROOT(ap), AP_SXCUR(sky), AP_SYCUR(sky)) + ier = ap_histplot (gd, gt, Memr[AP_SKYPIX(sky)], + Memr[AP_SWGT(sky)], Memi[AP_INDEX(sky)+ilo-1], nsky, + AP_K1(sky), INDEFR, AP_BINSIZE(sky), AP_SMOOTH(sky), + AP_SKY_MODE(sky), AP_SKY_SIG(sky), AP_SKY_SKEW(sky), + AP_NSKY(sky), AP_NSKY_REJECT(sky)) + AP_NSKY_REJECT(sky) = AP_NBADSKYPIX(sky) + nclip + + AP_NSKY_REJECT(sky) + call ap_gtfree (gt) + + return (ier) + + case AP_OFILT: + + # Initialize the weights. + call amovkr (1.0, Memr[AP_SWGT(sky)], AP_NSKYPIX(sky)) + + # Clip the data. + if (AP_SLOCLIP(sky) > 0.0 || AP_SHICLIP(sky) > 0.0) { + nclip = ap_clip (Memr[AP_SKYPIX(sky)], Memi[AP_INDEX(sky)], + AP_NSKYPIX(sky), AP_SLOCLIP(sky), AP_SHICLIP(sky), ilo, + ihi) + if (nclip >= AP_NSKYPIX(sky)) + return (AP_NSKY_TOO_SMALL) + nsky = AP_NSKYPIX(sky) - nclip + } else { + nclip = 0 + call ap_index (Memi[AP_INDEX(sky)], AP_NSKYPIX(sky)) + ilo = 1 + nsky = AP_NSKYPIX(sky) + } + + ier = ap_lgsky (Memr[AP_SKYPIX(sky)], Memi[AP_COORDS(sky)], + Memr[AP_SWGT(sky)], Memi[AP_INDEX(sky)+ilo-1], nsky, + AP_SNX(sky), AP_SNY(sky), AP_K1(sky), INDEFR, + AP_BINSIZE(sky), AP_SMOOTH(sky), AP_SLOREJECT(sky), + AP_SHIREJECT(sky), AP_RGROW(sky) * AP_SCALE(ap), + AP_SMAXITER(sky), AP_SKY_MODE(sky), AP_SKY_SIG(sky), + AP_SKY_SKEW(sky), AP_NSKY(sky), AP_NSKY_REJECT(sky)) + AP_NSKY_REJECT(sky) = AP_NBADSKYPIX(sky) + nclip + + AP_NSKY_REJECT(sky) + + return (ier) + + case AP_GAUSS: + + # Initialize the weights. + call amovkr (1.0, Memr[AP_SWGT(sky)], AP_NSKYPIX(sky)) + + # Clip the data. + if (AP_SLOCLIP(sky) > 0.0 || AP_SHICLIP(sky) > 0.0) { + nclip = ap_clip (Memr[AP_SKYPIX(sky)], Memi[AP_INDEX(sky)], + AP_NSKYPIX(sky), AP_SLOCLIP(sky), AP_SHICLIP(sky), ilo, + ihi) + if (nclip >= AP_NSKYPIX(sky)) + return (AP_NSKY_TOO_SMALL) + nsky = AP_NSKYPIX(sky) - nclip + } else { + nclip = 0 + call ap_index (Memi[AP_INDEX(sky)], AP_NSKYPIX(sky)) + ilo = 1 + nsky = AP_NSKYPIX(sky) + } + + ier = ap_gauss (Memr[AP_SKYPIX(sky)], Memi[AP_COORDS(sky)], + Memr[AP_SWGT(sky)], Memi[AP_INDEX(sky)+ilo-1], nsky, + AP_SNX(sky), AP_SNY(sky), AP_SMAXITER(sky), + AP_K1(sky), INDEFR, AP_BINSIZE(sky), AP_SMOOTH(sky), + AP_SLOREJECT(sky), AP_SHIREJECT(sky), AP_RGROW(sky) * + AP_SCALE(ap), AP_SNREJECT(sky), AP_SKY_MODE(sky), + AP_SKY_SIG(sky), AP_SKY_SKEW(sky), AP_NSKY(sky), + AP_NSKY_REJECT(sky)) + AP_NSKY_REJECT(sky) = AP_NBADSKYPIX(sky) + nclip + + AP_NSKY_REJECT(sky) + + return (ier) + + case AP_CROSSCOR: + + # Initialize the weights. + call amovkr (1.0, Memr[AP_SWGT(sky)], AP_NSKYPIX(sky)) + + # Clip the data. + if (AP_SLOCLIP(sky) > 0.0 || AP_SHICLIP(sky) > 0.0) { + nclip = ap_clip (Memr[AP_SKYPIX(sky)], Memi[AP_INDEX(sky)], + AP_NSKYPIX(sky), AP_SLOCLIP(sky), AP_SHICLIP(sky), ilo, + ihi) + if (nclip >= AP_NSKYPIX(sky)) + return (AP_NSKY_TOO_SMALL) + nsky = AP_NSKYPIX(sky) - nclip + } else { + nclip = 0 + call ap_index (Memi[AP_INDEX(sky)], AP_NSKYPIX(sky)) + ilo = 1 + nsky = AP_NSKYPIX(sky) + } + + ier = ap_crosscor (Memr[AP_SKYPIX(sky)], Memi[AP_COORDS(sky)], + Memr[AP_SWGT(sky)], Memi[AP_INDEX(sky)+ilo-1], nsky, + AP_SNX(sky), AP_SNY(sky), AP_K1(sky), INDEFR, + AP_BINSIZE(sky), AP_SMOOTH(sky), AP_SLOREJECT(sky), + AP_SHIREJECT(sky), AP_RGROW(sky) * AP_SCALE(ap), + AP_SMAXITER(sky), AP_SKY_MODE(sky), AP_SKY_SIG(sky), + AP_SKY_SKEW(sky), AP_NSKY(sky), AP_NSKY_REJECT(sky)) + AP_NSKY_REJECT(sky) = AP_NBADSKYPIX(sky) + nclip + + AP_NSKY_REJECT(sky) + + return (ier) + + default: + + AP_SKY_MODE(sky) = INDEFR + AP_SKY_SIG(sky) = INDEFR + AP_SKY_SKEW(sky) = INDEFR + AP_NSKY(sky) = AP_NSKYPIX(sky) + AP_NSKY_REJECT(sky) = 0 + return (AP_OK) + } +end diff --git a/noao/digiphot/apphot/fitsky/aprgrow.x b/noao/digiphot/apphot/fitsky/aprgrow.x new file mode 100644 index 00000000..902b91d6 --- /dev/null +++ b/noao/digiphot/apphot/fitsky/aprgrow.x @@ -0,0 +1,64 @@ +# AP_GROW_REGIONS -- Perform region growing around a rejected pixel. + +int procedure ap_grow_regions (skypix, coords, wgt, nskypix, sky_zero, + index, snx, sny, rgrow, sumpx, sumsqpx, sumcbpx) + +real skypix[ARB] # sky pixels +int coords[ARB] # sky cordinates +real wgt[ARB] # weights +int nskypix # total number of sky pixels +real sky_zero # sky zero point for moment analysis +int index # index of pixel to be rejected +int snx, sny # size of sky subraster +real rgrow # region growing radius +double sumpx, sumsqpx, sumcbpx # sum and sum of squares of sky pixels + +double dsky +int j, k, ixc, iyc, xmin, xmax, ymin, ymax, cstart, c, nreject +real rgrow2, r2, d + +begin + # Find the center of the region to be rejected. + ixc = mod (coords[index], snx) + if (ixc == 0) + ixc = snx + iyc = (coords[index] - ixc) / snx + 1 + + # Define the region to be searched. + rgrow2 = rgrow ** 2 + ymin = max (1, int (iyc - rgrow)) + ymax = min (sny, int (iyc + rgrow)) + xmin = max (1, int (ixc - rgrow)) + xmax = min (snx, int (ixc + rgrow)) + if (ymin <= iyc) + cstart = min (nskypix, max (1, index - int (rgrow) + snx * + (ymin - iyc))) + else + cstart = index + + # Reject the pixels. + nreject = 0 + do j = ymin, ymax { + d = rgrow2 - (j - iyc) ** 2 + if (d <= 0.0) + d = 0.0 + else + d = sqrt (d) + do k = max (xmin, int (ixc - d)), min (xmax, int (ixc + d)) { + c = k + (j - 1) * snx + while (coords[cstart] < c && cstart < nskypix) + cstart = cstart + 1 + r2 = (k - ixc) ** 2 + (j - iyc) ** 2 + if (r2 <= rgrow2 && c == coords[cstart] && wgt[cstart] > 0.0) { + dsky = skypix[cstart] - sky_zero + sumpx = sumpx - dsky + sumsqpx = sumsqpx - dsky ** 2 + sumcbpx = sumcbpx - dsky ** 3 + nreject = nreject + 1 + wgt[cstart] = 0.0 + } + } + } + + return (nreject) +end diff --git a/noao/digiphot/apphot/fitsky/apsconfirm.x b/noao/digiphot/apphot/fitsky/apsconfirm.x new file mode 100644 index 00000000..43c0b168 --- /dev/null +++ b/noao/digiphot/apphot/fitsky/apsconfirm.x @@ -0,0 +1,74 @@ +include "../lib/apphot.h" +include "../lib/noise.h" +include "../lib/fitsky.h" + +# AP_SCONFIRM -- Procedure to confirm the critical fitsky parameters. + +procedure ap_sconfirm (ap, out, stid) + +pointer ap # pointer to the apphot structure +int out # output file descriptor +int stid # output file sequence number + +pointer sp, str +real annulus, dannulus, skysigma, datamin, datamax +int apstati() +real apstatr(), ap_vannulus(), ap_vdannulus(), ap_vsigma() +real ap_vdatamin(), ap_vdatamax() + +begin + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + + call printf ("\n") + + # Confirm the sky fitting algorithm. + call ap_vsstring (ap, Memc[str], SZ_FNAME) + + # Confirm the remaining parameters. + if (apstati (ap, SKYFUNCTION) != AP_CONSTANT && + apstati (ap, SKYFUNCTION) != AP_SKYFILE) { + + # Confirm the sky annulus parameter. + annulus = ap_vannulus (ap) + + # Confirm the width of the sky annulus. + dannulus = ap_vdannulus (ap) + + } else { + + annulus = apstatr (ap, ANNULUS) + dannulus = apstatr (ap, DANNULUS) + + } + + # Confirm the sky sigma parameter. + if (apstati (ap, SKYFUNCTION) != AP_SKYFILE) + skysigma = ap_vsigma (ap) + else + skysigma = apstatr (ap, SKYSIGMA) + + # Confirm the minimum and maximum good data values. + datamin = ap_vdatamin (ap) + datamax = ap_vdatamax (ap) + + call printf ("\n") + + # Update the database file. + if (out != NULL && stid > 1) { + call ap_sparam (out, KY_SSTRING, Memc[str], UN_SALGORITHM, + "sky fitting algorithm") + call ap_rparam (out, KY_ANNULUS, annulus, UN_SSCALEUNIT, + "inner radius of sky annulus") + call ap_rparam (out, KY_DANNULUS, dannulus, UN_SSCALEUNIT, + "width of the sky annulus") + call ap_rparam (out, KY_SKYSIGMA, skysigma, UN_NCOUNTS, + "standard deviation of 1 sky pixel") + call ap_rparam (out, KY_DATAMIN, datamin, UN_ACOUNTS, + "minimum good data value") + call ap_rparam (out, KY_DATAMAX, datamax, UN_ACOUNTS, + "maximum good data value") + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/fitsky/apserrors.x b/noao/digiphot/apphot/fitsky/apserrors.x new file mode 100644 index 00000000..80c8f0a7 --- /dev/null +++ b/noao/digiphot/apphot/fitsky/apserrors.x @@ -0,0 +1,42 @@ +include "../lib/fitsky.h" + +# AP_SERRORS -- Program to print out detailed fitsky error messages when the +# program is run in interactive mode. + +procedure ap_serrors (ap, ier) + +pointer ap # pointer to apphot structure (not used) +int ier # integer error code + +begin + switch (ier) { + case AP_NOSKYAREA: + call printf ("The are no pixels in the sky annulus.\n") + case AP_SKY_OUTOFBOUNDS: + call printf ("The sky annulus is outside of the image.\n") + case AP_NOHISTOGRAM: + call printf ("The sky histogram has no width.\n") + case AP_FLAT_HIST: + call printf ("The sky histogram is flat or concave.\n") + case AP_NSKY_TOO_SMALL: + call printf ("The number of sky points is too small.\n") + case AP_SKY_SINGULAR: + call printf ("The sky fit is singular.\n") + case AP_SKY_NOCONVERGE: + call printf ("The sky fit did not converge.\n") + case AP_NOGRAPHICS: + call printf ("Interactive graphics are not available.\n") + case AP_NOSKYFILE: + call printf ( + "The text file containing sky values does not exist.\n") + case AP_EOFSKYFILE: + call printf ("The sky file is at EOF.\n") + case AP_BADSKYSCAN: + call printf ( + "An error occurred in decoding the current line in the sky file.\n") + case AP_BADPARAMS: + call printf ("Out of range mode or -ve sigma in Gaussian fit.\n") + default: + call printf ("") + } +end diff --git a/noao/digiphot/apphot/fitsky/apsfree.x b/noao/digiphot/apphot/fitsky/apsfree.x new file mode 100644 index 00000000..63d41090 --- /dev/null +++ b/noao/digiphot/apphot/fitsky/apsfree.x @@ -0,0 +1,48 @@ +include "../lib/apphotdef.h" +include "../lib/fitskydef.h" + +# APSFREE -- Procedure to free the sky fitting structure. + +procedure apsfree (ap) + +pointer ap # pointer to the apphot structure + +begin + if (ap == NULL) + return + if (AP_NOISE(ap) != NULL) + call ap_noisecls (ap) + if (AP_PDISPLAY(ap) != NULL) + call ap_dispcls (ap) + if (AP_PSKY(ap) != NULL) + call ap_skycls (ap) + if (AP_IMBUF(ap) != NULL) + call mfree (AP_IMBUF(ap), TY_REAL) + if (AP_MW(ap) != NULL) + call mw_close (AP_MW(ap)) + call mfree (ap, TY_STRUCT) +end + + +# AP_SKYCLS -- Procedure to close up the sky fitting arrays. + +procedure ap_skycls (ap) + +pointer ap # pointer to the apphot structure + +pointer sky + +begin + sky = AP_PSKY(ap) + if (sky == NULL) + return + if (AP_SKYPIX(sky) != NULL) + call mfree (AP_SKYPIX(sky), TY_REAL) + if (AP_INDEX(sky) != NULL) + call mfree (AP_INDEX(sky), TY_INT) + if (AP_COORDS(sky) != NULL) + call mfree (AP_COORDS(sky), TY_INT) + if (AP_SWGT(sky) != NULL) + call mfree (AP_SWGT(sky), TY_REAL) + call mfree (AP_PSKY(ap), TY_STRUCT) +end diff --git a/noao/digiphot/apphot/fitsky/apsinit.x b/noao/digiphot/apphot/fitsky/apsinit.x new file mode 100644 index 00000000..e180835f --- /dev/null +++ b/noao/digiphot/apphot/fitsky/apsinit.x @@ -0,0 +1,116 @@ +include "../lib/apphotdef.h" +include "../lib/fitskydef.h" +include "../lib/fitsky.h" + +# APSINIT - Procedure to initialize the sky fitting structure and parameters. + +procedure apsinit (ap, function, annulus, dannulus, fwhmpsf, noise) + +pointer ap # pointer to the apphot structure +int function # sky fitting algorithm +real annulus # radius of sky annulus +real dannulus # width of sky annulus +real fwhmpsf # FWHM of the PSF +int noise # noise function + +begin + # Set up the object parameters. + call malloc (ap, LEN_APSTRUCT, TY_STRUCT) + + # Set up the global apphot package parameters. + call ap_defsetup (ap, fwhmpsf) + + # Set up the noise model parameters. + call ap_noisesetup (ap, noise) + + # Set up the display options. + call ap_dispsetup (ap) + + # Initialize the sky fitting parameters. + call ap_skysetup (ap, function, annulus, dannulus) + + # Unused structures are set to null. + AP_PCENTER(ap) = NULL + AP_PPHOT(ap) = NULL + AP_POLY(ap) = NULL + AP_PPSF(ap) = NULL + AP_RPROF(ap) = NULL +end + + +# AP_SKYSETUP -- Procedure to set up the sky fitting arrays and parameters. + +procedure ap_skysetup (ap, function, annulus, dannulus) + +pointer ap # pointer to apphot structure +int function # sky fitting function +real annulus # inner radius of sky annulus +real dannulus # outer radius of sky annulus + +pointer sky + +begin + call malloc (AP_PSKY(ap), LEN_SKYSTRUCT, TY_STRUCT) + sky = AP_PSKY(ap) + AP_SXCUR(sky) = INDEFR + AP_SYCUR(sky) = INDEFR + + # Initialize the sky fitting parameters. + AP_SKYFUNCTION(sky) = function + switch (function) { + case AP_CONSTANT: + call strcpy ("constant", AP_SSTRING(sky), SZ_FNAME) + case AP_MODE: + call strcpy ("mode", AP_SSTRING(sky), SZ_FNAME) + case AP_CENTROID: + call strcpy ("centroid", AP_SSTRING(sky), SZ_FNAME) + case AP_SKYFILE: + call strcpy ("file", AP_SSTRING(sky), SZ_FNAME) + case AP_HISTPLOT: + call strcpy ("histplot", AP_SSTRING(sky), SZ_FNAME) + case AP_RADPLOT: + call strcpy ("radplot", AP_SSTRING(sky), SZ_FNAME) + case AP_MEDIAN: + call strcpy ("median", AP_SSTRING(sky), SZ_FNAME) + case AP_GAUSS: + call strcpy ("gauss", AP_SSTRING(sky), SZ_FNAME) + case AP_OFILT: + call strcpy ("ofilt", AP_SSTRING(sky), SZ_FNAME) + case AP_CROSSCOR: + call strcpy ("crosscor", AP_SSTRING(sky), SZ_FNAME) + case AP_MEAN: + call strcpy ("mean", AP_SSTRING(sky), SZ_FNAME) + default: + AP_SKYFUNCTION(sky) = DEF_SKYFUNCTION + call strcpy ("mode", AP_SSTRING(sky), SZ_FNAME) + } + + AP_SKYBACKGROUND(sky) = DEF_SKYVALUE + AP_ANNULUS(sky) = annulus + AP_DANNULUS(sky) = dannulus + AP_K1(sky) = DEF_K1 + AP_BINSIZE(sky) = DEF_BINSIZE + AP_SMOOTH(sky) = DEF_SMOOTH + AP_SLOCLIP(sky) = DEF_SLOCLIP + AP_SHICLIP(sky) = DEF_SHICLIP + AP_SMAXITER(sky) = DEF_SMAXITER + AP_RGROW(sky) = DEF_RGROW + AP_SNREJECT(sky) = DEF_SNREJECT + AP_SLOREJECT(sky) = DEF_SLOREJECT + AP_SHIREJECT(sky) = DEF_SHIREJECT + + # Initialize the sky pixel buffers. + AP_LENSKYBUF(sky) = 0 + AP_NSKYPIX(sky) = 0 + AP_SKYPIX(sky) = NULL + AP_INDEX(sky) = NULL + AP_COORDS(sky) = NULL + AP_SWGT(sky) = NULL + + # Initialize results parameters. + AP_SKY_MODE(sky) = INDEFR + AP_SKY_SIG(sky) = INDEFR + AP_SKY_SKEW(sky) = INDEFR + AP_NSKY(sky) = 0 + AP_NSKY_REJECT(sky) = 0 +end diff --git a/noao/digiphot/apphot/fitsky/apsky.x b/noao/digiphot/apphot/fitsky/apsky.x new file mode 100644 index 00000000..40faac3d --- /dev/null +++ b/noao/digiphot/apphot/fitsky/apsky.x @@ -0,0 +1,346 @@ +include <ctype.h> +include <gset.h> +include <imhdr.h> +include "../lib/apphot.h" +include "../lib/display.h" +include "../lib/fitsky.h" + +define HELPFILE "apphot$fitsky/fitsky.key" + +# APSKY -- Procedure to interactively determine sky values in an annular +# region around a list of objects. + +int procedure apsky (ap, im, cl, sd, gd, mgd, id, out, stid, interactive, cache) + +pointer ap # pointer to apphot structure +pointer im # pointer to IRAF image +int cl # starlist file descriptor +int sd # the sky file descriptor +pointer gd # pointer to graphcis descriptor +pointer mgd # pointer to graphics metacode file +pointer id # pointer to image display stream +int out # output file descriptor +int stid # output file sequence number +int interactive # interactive mode +int cache # cache the input image pixels + +real wx, wy, xlist, ylist +pointer sp, cmd +int wcs, key, colonkey, newimage, newobject, newsky, newlist, ier +int ip, ltid, oid, prev_num, req_num, buf_size, req_size, old_size +int memstat + +real apstatr() +int clgcur(), apfitsky(), aprefitsky(), apgscur(), ctoi(), apstati() +int apgqverify(), apgtverify(), apnew(), ap_memstat(), sizeof() + +define endswitch_ 99 + +begin + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + # Initialize cursor command. + key = ' ' + Memc[cmd] = EOS + + # Initialize fitting parameters. + newimage = NO + newobject = YES + newsky = YES + ier = AP_OK + + # Initialize sequencing. + newlist = NO + ltid = 0 + + # Loop over the cursor commands. + while (clgcur ("icommands", wx, wy, wcs, key, Memc[cmd], SZ_LINE) != + EOF) { + + # Store the current cursor coordinates. + call ap_vtol (im, wx, wy, wx, wy, 1) + call apsetr (ap, CWX, wx) + call apsetr (ap, CWY, wy) + + # Test to see if the cursor has moved. + if (apnew (ap, wx, wy, xlist, ylist, newlist) == YES) { + newobject = YES + newsky = YES + } + + # Loop over the colon commands. + switch (key) { + + # Quit. + case 'q': + if (interactive == YES) { + if (apgqverify ("fitsky", ap, key) == YES) { + call sfree (sp) + return (apgtverify (key)) + } + } else { + call sfree (sp) + return (NO) + } + + # Print the error messages. + case 'e': + if (interactive == YES) + call ap_serrors (ap, ier) + + # Print the help page. + case '?': + if ((id != NULL) && (id == gd)) + call gpagefile (id, HELPFILE, "") + else if (interactive == YES) + call pagefile (HELPFILE, "[space=morehelp,q=quit,?=help]") + + # Rewind the coordinate file. + case 'r': + if (cl != NULL) { + call seek (cl, BOFL) + ltid = 0 + } else if (interactive == YES) + call printf ("No coordinate list\n") + + # Verify the critical parameters. + case 'v': + call ap_sconfirm (ap, out, stid) + newobject = YES + newsky = YES + + # Save the sky fitting parameters. + case 'w': + call ap_pspars (ap) + + # Draw a centered radial profile plot. + case 'd': + if (interactive == YES) { + call ap_qrad (ap, im, wx, wy, gd) + newobject = YES + newsky = YES + } + + # Interactively set up sky fitting parameters. + case 'i': + if (interactive == YES) { + call ap_sradsetup (ap, im, wx, wy, gd, out, stid) + newobject = YES + newsky = YES + } + + # Process fitsky colon commands. + case ':': + for (ip = 1; IS_WHITE(Memc[cmd+ip-1]); ip = ip + 1) + ; + colonkey = Memc[cmd+ip-1] + switch (colonkey) { + case 'm', 'n': + + # Show/set fitsky commands. + if (Memc[cmd+ip] != EOS && Memc[cmd+ip] != ' ') { + call apskycolon (ap, im, cl, out, stid, ltid, + Memc[cmd], newimage, newobject, newsky) + goto endswitch_ + } + + # No coordinate list. + if (cl == NULL) { + if (interactive == YES) + call printf ("No coordinate list\n") + goto endswitch_ + } + + # Get next object from the list. + ip = ip + 1 + prev_num = ltid + if (ctoi (Memc[cmd], ip, req_num) <= 0) + req_num = ltid + 1 + + # Fetch the next object from the list. + if (apgscur (cl, id, xlist, ylist, prev_num, req_num, + ltid) == EOF) { + if (interactive == YES) + call printf ( + "End of coordinate list, use r key to rewind\n") + goto endswitch_ + } + + # Convert the coordinates. + switch (apstati (ap, WCSIN)) { + case WCS_PHYSICAL, WCS_WORLD: + call ap_itol (ap, xlist, ylist, xlist, ylist, 1) + case WCS_TV: + call ap_vtol (im, xlist, ylist, xlist, ylist, 1) + default: + ; + } + + # Move to the next object. + newlist = YES + if (colonkey == 'm') { + newobject = YES + newsky = YES + goto endswitch_ + } + + # Measure the next object. + ier = apfitsky (ap, im, xlist, ylist, sd, gd) + if (id != NULL) { + call apmark (ap, id, NO, apstati (ap, MKSKY), NO) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_splot (ap, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qspsky (ap, ier) + if (stid == 1) + call ap_param (ap, out, "fitsky") + call ap_splot (ap, stid, mgd, YES) + call ap_pssky (ap, out, stid, ltid, ier) + stid = stid + 1 + newobject = NO; newsky = NO + + default: + call apskycolon (ap, im, cl, out, stid, ltid, Memc[cmd], + newimage, newobject, newsky) + } + + if (newimage == YES) { + if ((id != NULL) && (gd != id)) + call ap_gswv (id, Memc[cmd], im, 4) + req_size = MEMFUDGE * IM_LEN(im,1) * IM_LEN(im,2) * + sizeof (IM_PIXTYPE(im)) + memstat = ap_memstat (cache, req_size, old_size) + if (memstat == YES) + call ap_pcache (im, INDEFI, buf_size) + } + + newimage = NO + + # Fit the sky and store the results. + case 'f', ' ': + if (newobject == YES) + ier = apfitsky (ap, im, wx, wy, sd, gd) + else if (newsky == YES) + ier = aprefitsky (ap, im, gd) + if (id != NULL) { + call apmark (ap, id, NO, apstati (ap, MKSKY), NO) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_splot (ap, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qspsky (ap, ier) + newobject = NO; newsky = NO + + if (key == ' ') { + if (stid == 1) + call ap_param (ap, out, "fitsky") + if (newlist == YES) + call ap_pssky (ap, out, stid, ltid, ier) + else + call ap_pssky (ap, out, stid, 0, ier) + call ap_splot (ap, stid, mgd, YES) + stid = stid + 1 + } + + # Get, fit the next object in the list. + case 'm', 'n': + + # No coordinate file. + if (cl == NULL) { + if (interactive == YES) + call printf ("No coordinate list\n") + goto endswitch_ + } + + # Need to rewind coordinate file. + prev_num = ltid + req_num = ltid + 1 + if (apgscur (cl, id, xlist, ylist, prev_num, req_num, + ltid) == EOF) { + if (interactive == YES) + call printf ( + "End of coordinate list, use r key to rewind\n") + goto endswitch_ + + } + + # Convert coordinates if necessary. + switch (apstati (ap, WCSIN)) { + case WCS_PHYSICAL, WCS_WORLD: + call ap_itol (ap, xlist, ylist, xlist, ylist, 1) + case WCS_TV: + call ap_vtol (im, xlist, ylist, xlist, ylist, 1) + default: + ; + } + + # Move to the next object. + newlist = YES + if (key == 'm') { + newobject = YES + newsky = YES + goto endswitch_ + } + + # Measure the next object. + ier = apfitsky (ap, im, xlist, ylist, sd, gd) + if (id != NULL) { + call apmark (ap, id, NO, apstati (ap, MKSKY), NO) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_splot (ap, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qspsky (ap, ier) + if (stid == 1) + call ap_param (ap, out, "fitsky") + call ap_pssky (ap, out, stid, ltid, ier) + call ap_splot (ap, stid, mgd, YES) + stid = stid + 1 + newobject = NO + newsky = NO + + # Process the remainder of the list. + case 'l': + if (cl != NULL) { + ltid = ltid + 1 + oid = stid + call apbsky (ap, im, cl, sd, out, stid, ltid, gd, mgd, id, + YES) + ltid = ltid + stid - oid + 1 + if (id != NULL) { + if (id == gd) + call gflush (id) + else + call gframe (id) + } + } else if (interactive == YES) + call printf ("No coordinate list\n") + + default: + # do nothing + call printf ("Unknown or ambiguous keystroke command\n") + } + +endswitch_ + + # Setup for the next object. + key = ' ' + Memc[cmd] = EOS + call apsetr (ap, WX, apstatr (ap, CWX)) + call apsetr (ap, WY, apstatr (ap, CWY)) + + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/fitsky/apskybuf.x b/noao/digiphot/apphot/fitsky/apskybuf.x new file mode 100644 index 00000000..cacd4737 --- /dev/null +++ b/noao/digiphot/apphot/fitsky/apskybuf.x @@ -0,0 +1,254 @@ +include <imhdr.h> +include <math.h> +include <mach.h> +include "../lib/apphotdef.h" +include "../lib/fitskydef.h" +include "../lib/fitsky.h" + +# APSKYBUF -- Procedure to fetch the sky pixels given the pointer to the +# IRAF image, the coordinates of the center and the size of the apphot +# sky annulus. + +int procedure apskybuf (ap, im, wx, wy) + +pointer ap # pointer to apphot structure +pointer im # pointer to the IRAF image +real wx, wy # center coordinates + +int lenbuf +pointer sky +real annulus, dannulus, datamin, datamax +int ap_skypix(), ap_bskypix() + +begin + # Check for 0 radius annulus. + sky = AP_PSKY(ap) + annulus = AP_ANNULUS(sky) * AP_SCALE(ap) + dannulus = AP_DANNULUS(sky) * AP_SCALE(ap) + if (dannulus <= 0.0) + return (AP_NOSKYAREA) + + # Allocate space for sky pixels. + lenbuf = PI * (2.0 * annulus + dannulus + 1.0) * (dannulus + 0.5) + + if (lenbuf != AP_LENSKYBUF(sky)) { + if (AP_SKYPIX(sky) != NULL) + call mfree (AP_SKYPIX(sky), TY_REAL) + call malloc (AP_SKYPIX(sky), lenbuf, TY_REAL) + if (AP_COORDS(sky) != NULL) + call mfree (AP_COORDS(sky), TY_INT) + call malloc (AP_COORDS(sky), lenbuf, TY_INT) + if (AP_INDEX(sky) != NULL) + call mfree (AP_INDEX(sky), TY_INT) + call malloc (AP_INDEX(sky), lenbuf, TY_INT) + if (AP_SWGT(sky) != NULL) + call mfree (AP_SWGT(sky), TY_REAL) + call malloc (AP_SWGT(sky), lenbuf, TY_REAL) + AP_LENSKYBUF(sky) = lenbuf + } + + # Fetch the sky pixels. + if (IS_INDEFR(AP_DATAMIN(ap)) && IS_INDEFR(AP_DATAMAX(ap))) { + AP_NSKYPIX(sky) = ap_skypix (im, wx, wy, annulus, (annulus + + dannulus), Memr[AP_SKYPIX(sky)], Memi[AP_COORDS(sky)], + AP_SXC(sky), AP_SYC(sky), AP_SNX(sky), AP_SNY(sky)) + AP_NBADSKYPIX(sky) = 0 + } else { + if (IS_INDEFR(AP_DATAMIN(ap))) + datamin = -MAX_REAL + else + datamin = AP_DATAMIN(ap) + if (IS_INDEFR(AP_DATAMAX(ap))) + datamax = MAX_REAL + else + datamax = AP_DATAMAX(ap) + AP_NSKYPIX(sky) = ap_bskypix (im, wx, wy, annulus, (annulus + + dannulus), datamin, datamax, Memr[AP_SKYPIX(sky)], + Memi[AP_COORDS(sky)], AP_SXC(sky), AP_SYC(sky), AP_SNX(sky), + AP_SNY(sky), AP_NBADSKYPIX(sky)) + } + + if (AP_NSKYPIX(sky) <= 0) { + if (AP_NBADSKYPIX(sky) <= 0) + return (AP_SKY_OUTOFBOUNDS) + else + return (AP_NSKY_TOO_SMALL) + } else + return (AP_OK) +end + + +# AP_SKYPIX -- Procedure to fetch the sky pixels from the image + +int procedure ap_skypix (im, wx, wy, rin, rout, skypix, coords, xc, yc, + nx, ny) + +pointer im # pointer to IRAF image +real wx, wy # center of sky annulus +real rin, rout # inner and outer radius of sky annulus +real skypix[ARB] # skypixels +int coords[ARB] # sky subraster coordinates [i + nx * (j - 1)] +real xc, yc # center of sky subraster +int nx, ny # max dimensions of sky subraster (output) + +int i, j, ncols, nlines, c1, c2, l1, l2, nskypix +pointer buf +real xc1, xc2, xl1, xl2, rin2, rout2, rj2, r2 +pointer imgs2r() + +#pointer tbuf + +begin + if (rout <= rin) + return (0) + + # Test for out of bounds sky regions. + ncols = IM_LEN(im,1) + nlines = IM_LEN(im,2) + xc1 = wx - rout + xc2 = wx + rout + xl1 = wy - rout + xl2 = wy + rout + if (xc2 < 1.0 || xc1 > real (ncols) || xl2 < 1.0 || xl1 > real (nlines)) + return (0) + + # Compute the column and line limits. + c1 = max (1.0, min (real (ncols), wx - rout)) + 0.5 + c2 = min (real (ncols), max (1.0, wx + rout)) + 0.5 + l1 = max (1.0, min (real (nlines), wy - rout)) + 0.5 + l2 = min (real (nlines), max (1.0, wy + rout)) + 0.5 + nx = c2 - c1 + 1 + ny = l2 - l1 + 1 + xc = wx - c1 + 1 + yc = wy - l1 + 1 + + # Fetch the sky pixels. + rin2 = rin ** 2 + rout2 = rout ** 2 + nskypix = 0 + + do j = l1, l2 { + buf = imgs2r (im, c1, c2, j, j) + rj2 = (wy - j) ** 2 + do i = c1, c2 { + r2 = (wx - i) ** 2 + rj2 + if (r2 > rin2 && r2 <= rout2) { + skypix[nskypix+1] = Memr[buf+i-c1] + coords[nskypix+1] = (i - c1 + 1) + nx * (j - l1) + nskypix = nskypix + 1 + } + } + } + + #buf = imgs2r (im, c1, c2, l1, l2) + #tbuf = buf + #do j = l1, l2 { + #rj2 = (wy - j) ** 2 + #do i = c1, c2 { + #r2 = (wx - i) ** 2 + rj2 + #if (r2 > rin2 && r2 <= rout2) { + #skypix[nskypix+1] = Memr[tbuf+i-c1] + #coords[nskypix+1] = (i - c1 + 1) + nx * (j - l1) + #nskypix = nskypix + 1 + #} + #} + #tbuf = tbuf + nx + #} + + return (nskypix) +end + + +# AP_BSKYPIX -- Procedure to fetch the sky pixels from the image + +int procedure ap_bskypix (im, wx, wy, rin, rout, datamin, datamax, + skypix, coords, xc, yc, nx, ny, nbad) + +pointer im # pointer to IRAF image +real wx, wy # center of sky annulus +real rin, rout # inner and outer radius of sky annulus +real datamin # minimum good value +real datamax # maximum good value +real skypix[ARB] # skypixels +int coords[ARB] # sky subraster coordinates [i + nx * (j - 1)] +real xc, yc # center of sky subraster +int nx, ny # max dimensions of sky subraster (output) +int nbad # number of bad pixels + +int i, j, ncols, nlines, c1, c2, l1, l2, nskypix +pointer buf +real xc1, xc2, xl1, xl2, rin2, rout2, rj2, r2, pixval +pointer imgs2r() + +#pointer tbuf + +begin + if (rout <= rin) + return (0) + + # Test for out of bounds sky regions. + ncols = IM_LEN(im,1) + nlines = IM_LEN(im,2) + xc1 = wx - rout + xc2 = wx + rout + xl1 = wy - rout + xl2 = wy + rout + if (xc2 < 1.0 || xc1 > real (ncols) || xl2 < 1.0 || xl1 > real (nlines)) + return (0) + + # Compute the column and line limits. + c1 = max (1.0, min (real (ncols), wx - rout)) + 0.5 + c2 = min (real (ncols), max (1.0, wx + rout)) + 0.5 + l1 = max (1.0, min (real (nlines), wy - rout)) + 0.5 + l2 = min (real (nlines), max (1.0, wy + rout)) + 0.5 + nx = c2 - c1 + 1 + ny = l2 - l1 + 1 + xc = wx - c1 + 1 + yc = wy - l1 + 1 + + rin2 = rin ** 2 + rout2 = rout ** 2 + nskypix = 0 + nbad = 0 + + # Fetch the sky pixels. + do j = l1, l2 { + buf = imgs2r (im, c1, c2, j, j) + rj2 = (wy - j) ** 2 + do i = c1, c2 { + r2 = (wx - i) ** 2 + rj2 + if (r2 > rin2 && r2 <= rout2) { + pixval = Memr[buf+i-c1] + if (pixval < datamin || pixval > datamax) + nbad = nbad + 1 + else { + skypix[nskypix+1] = pixval + coords[nskypix+1] = (i - c1 + 1) + nx * (j - l1) + nskypix = nskypix + 1 + } + } + } + } + + #buf = imgs2r (im, c1, c2, l1, l2) + #tbuf = buf + #do j = l1, l2 { + #rj2 = (wy - j) ** 2 + #do i = c1, c2 { + #r2 = (wx - i) ** 2 + rj2 + #if (r2 > rin2 && r2 <= rout2) { + #pixval = Memr[tbuf+i-c1] + #if (pixval < datamin || pixval > datamax) + #nbad = nbad + 1 + #else { + #skypix[nskypix+1] = pixval + #coords[nskypix+1] = (i - c1 + 1) + nx * (j - l1) + #nskypix = nskypix + 1 + #} + #} + #} + #tbuf = tbuf + nx + #} + + return (nskypix) +end diff --git a/noao/digiphot/apphot/fitsky/apskycolon.x b/noao/digiphot/apphot/fitsky/apskycolon.x new file mode 100644 index 00000000..35b59aa9 --- /dev/null +++ b/noao/digiphot/apphot/fitsky/apskycolon.x @@ -0,0 +1,367 @@ +include "../lib/apphot.h" +include "../lib/noise.h" +include "../lib/fitsky.h" +include "../lib/display.h" + + +# APSKYCOLON -- Procedure to process the fitsky colon commands. + +procedure apskycolon (ap, im, cl, out, stid, ltid, cmdstr, newimage, + newskybuf, newsky) + +pointer ap # pointer to the apphot structure +pointer im # pointer to the iraf image +int cl # coordinate file descriptor +int out # output file descriptor +int stid # output file sequence number +int ltid # coord list sequence number +char cmdstr[ARB] # command string +int newimage # new image ? +int newskybuf # new sky buffer ? +int newsky # new sky fit ? + +int junk +pointer sp, incmd, outcmd +int strdic() + +begin + # Get the command. + call smark (sp) + call salloc (incmd, SZ_LINE, TY_CHAR) + call salloc (outcmd, SZ_LINE, TY_CHAR) + call sscan (cmdstr) + call gargwrd (Memc[incmd], SZ_LINE) + if (Memc[incmd] == EOS) { + call sfree (sp) + return + } + + # Process the command. + if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, SCMDS) != 0) + call apscolon (ap, out, stid, cmdstr, newskybuf, newsky) + else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, APCMDS) != 0) + call ap_apcolon (ap, im, cl, out, stid, ltid, cmdstr, + newimage, junk, junk, newskybuf, newsky, junk, junk) + else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, NCMDS) != 0) + call apnscolon (ap, im, out, stid, cmdstr, junk, junk, + newskybuf, newsky, junk, junk) + else + call ap_simcolon (ap, cmdstr) + + call sfree (sp) +end + + +# APSCOLON -- Procedure to examine and edit the sky fitting parameters. + +procedure apscolon (ap, out, stid, cmdstr, newbuf, newfit) + +pointer ap # pointer to the apphot structure +int out # output file descriptor +int stid # output file number +char cmdstr # command string +int newbuf # new sky buffer +int newfit # new sky fit + +bool bval +int ncmd, ival, stat +pointer sp, cmd +real rval + +bool itob() +int nscan(), strdic(), btoi(), apstati() +real apstatr() + + +begin + # Get the command + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + call sscan (cmdstr) + call gargwrd (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call sfree (sp) + return + } + + # Process the command. + ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, SCMDS) + switch (ncmd) { + case SCMD_ANNULUS: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_ANNULUS) + call pargr (apstatr (ap, ANNULUS)) + call pargstr (UN_SSCALEUNIT) + } else { + call apsetr (ap, ANNULUS, rval) + if (stid > 1) + call ap_rparam (out, KY_ANNULUS, rval, UN_SSCALEUNIT, + "inner radius of sky annulus") + newbuf = YES + newfit = YES + } + case SCMD_DANNULUS: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_DANNULUS) + call pargr (apstatr (ap, DANNULUS)) + call pargstr (UN_SSCALEUNIT) + } else { + call apsetr (ap, DANNULUS, rval) + if (stid > 1) + call ap_rparam (out, KY_DANNULUS, rval, UN_SSCALEUNIT, + "width of the sky annulus") + newbuf = YES + newfit = YES + } + case SCMD_SALGORITHM: + call gargwrd (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call apstats (ap, SSTRING, Memc[cmd], SZ_FNAME) + call printf ("%s = %s\n") + call pargstr (KY_SSTRING) + call pargstr (Memc[cmd]) + } else { + stat = strdic (Memc[cmd], Memc[cmd], SZ_LINE, SFUNCS) + if (stat > 0) { + call apseti (ap, SKYFUNCTION, stat) + call apsets (ap, SSTRING, Memc[cmd]) + if (stid > 1) + call ap_sparam (out, KY_SSTRING, Memc[cmd], + UN_SALGORITHM, "sky fitting algorithm") + newfit = YES + } + } + case SCMD_KHIST: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_K1) + call pargr (apstatr (ap, K1)) + call pargstr (UN_SSIGMA) + } else { + call apsetr (ap, K1, rval) + if (stid > 1) + call ap_rparam (out, KY_K1, rval, UN_SSIGMA, + "half width of sky histogram") + newfit = YES + } + case SCMD_SLOREJECT: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_SLOREJECT) + call pargr (apstatr (ap, SLOREJECT)) + call pargstr (UN_SSIGMA) + } else { + call apsetr (ap, SLOREJECT, rval) + if (stid > 1) + call ap_rparam (out, KY_SLOREJECT, rval, UN_SSIGMA, + "lower k-sigma rejection criterion") + newfit = YES + } + case SCMD_SHIREJECT: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_SHIREJECT) + call pargr (apstatr (ap, SHIREJECT)) + call pargstr (UN_SSIGMA) + } else { + call apsetr (ap, SHIREJECT, rval) + if (stid > 1) + call ap_rparam (out, KY_SHIREJECT, rval, UN_SSIGMA, + "upper k-sigma rejection criterion") + newfit = YES + } + case SCMD_SLOCLIP: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_SLOCLIP) + call pargr (apstatr (ap, SLOCLIP)) + call pargstr (UN_SPERCENT) + } else { + call apsetr (ap, SLOCLIP, rval) + if (stid > 1) + call ap_rparam (out, KY_SLOCLIP, rval, UN_SPERCENT, + "lower k-sigma rejection criterion") + newfit = YES + } + case SCMD_SHICLIP: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_SHICLIP) + call pargr (apstatr (ap, SHICLIP)) + call pargstr (UN_SPERCENT) + } else { + call apsetr (ap, SHICLIP, rval) + if (stid > 1) + call ap_rparam (out, KY_SHICLIP, rval, UN_SPERCENT, + "lower k-sigma rejection criterion") + newfit = YES + } + case SCMD_SMAXITER: + call gargi (ival) + if (nscan () == 1) { + call printf ("%s = %d\n") + call pargstr (KY_SMAXITER) + call pargi (apstati (ap, SMAXITER)) + } else { + call apseti (ap, SMAXITER, ival) + if (stid > 1) + call ap_iparam (out, KY_SMAXITER, ival, UN_SNUMBER, + "maximum number of iterations") + newfit = YES + } + case SCMD_BINSIZE: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_BINSIZE) + call pargr (apstatr (ap, BINSIZE)) + call pargstr (UN_SSIGMA) + } else { + call apsetr (ap, BINSIZE, rval) + if (stid > 1) + call ap_rparam (out, KY_BINSIZE, rval, UN_SSIGMA, + "width of the sky histogram bin") + newfit = YES + } + case SCMD_SMOOTH: + call gargb (bval) + if (nscan () == 1) { + call printf ("%s = %b\n") + call pargstr (KY_SMOOTH) + call pargb (itob (apstati (ap, SMOOTH))) + } else { + call apseti (ap, SMOOTH, btoi (bval)) + if (stid > 1) + call ap_bparam (out, KY_SMOOTH, bval, UN_SSWITCH, + "Lucy smooth the histogram") + newfit = YES + } + case SCMD_RGROW: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_RGROW) + call pargr (apstatr (ap, RGROW)) + call pargstr (UN_SSCALEUNIT) + } else { + call apsetr (ap, RGROW, rval) + if (stid > 1) + call ap_rparam (out, KY_RGROW, rval, UN_SSCALEUNIT, + "region growing radius") + newfit = YES + } + case SCMD_SNREJECT: + call gargi (ival) + if (nscan () == 1) { + call printf ("%s = %d\n") + call pargstr (KY_SNREJECT) + call pargi (apstati (ap, SNREJECT)) + } else { + call apseti (ap, SNREJECT, ival) + if (stid > 1) + call ap_iparam (out, KY_SNREJECT, ival, UN_SNUMBER, + "maximum number of rejection cycles") + newfit = YES + } + case SCMD_SKYVALUE: + call gargr (rval) + if (nscan () == 1) { + call printf ("%s = %g\n") + call pargstr (KY_SKY_BACKGROUND) + call pargr (apstatr (ap, SKY_BACKGROUND)) + call pargstr (UN_SCOUNTS) + } else { + call apsetr (ap, SKY_BACKGROUND, rval) + if (stid > 1) + call ap_rparam (out, KY_SKY_BACKGROUND, rval, + UN_SCOUNTS, "user supplied sky value") + newfit = YES + } + case SCMD_MKSKY: + call gargb (bval) + if (nscan () == 1) { + call printf ("%s = %b\n") + call pargstr (KY_MKSKY) + call pargb (itob (apstati (ap, MKSKY))) + } else { + call apseti (ap, MKSKY, btoi (bval)) + } + default: + # do nothing gracefully + call printf ("Unrecognized command\7\n") + } + + call sfree (sp) +end + + +# AP_SIMCOLON -- Procedure to process fitsky commands which alter parameters +# other than the sky fitting parameters themselves. + +procedure ap_simcolon (ap, cmdstr) + +pointer ap # pointer to the apphot structure +char cmdstr[ARB] # command string + +bool bval +int ncmd +pointer sp, cmd +bool itob() +int strdic(), nscan(), apstati(), btoi() + +begin + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + # Get the command. + call sscan (cmdstr) + call gargwrd (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call sfree (sp) + return + } + + # Process the commands. + ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, MISC) + switch (ncmd) { + case ACMD_SHOW: + call gargwrd (Memc[cmd], SZ_LINE) + ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, SSHOWARGS) + switch (ncmd) { + case SCMD_DATA: + call printf ("\n") + call ap_nshow (ap) + call printf ("\n") + case SCMD_SKY: + call printf ("\n") + call ap_spshow (ap) + call printf ("\n") + default: + call printf ("\n") + call ap_sshow (ap) + call printf ("\n") + } + case ACMD_RADPLOTS: + call gargb (bval) + if (nscan () == 1) { + call printf ("%s = %b\n") + call pargstr (KY_RADPLOTS) + call pargb (itob (apstati (ap, RADPLOTS))) + } else { + call apseti (ap, RADPLOTS, btoi (bval)) + } + default: + call printf ("Unknown or ambiguous colon command\7\n") + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/fitsky/apsplot.x b/noao/digiphot/apphot/fitsky/apsplot.x new file mode 100644 index 00000000..0a75b0c8 --- /dev/null +++ b/noao/digiphot/apphot/fitsky/apsplot.x @@ -0,0 +1,244 @@ +include <pkg/gtools.h> +include <gset.h> +include "../lib/apphotdef.h" +include "../lib/apphot.h" +include "../lib/noise.h" +include "../lib/fitskydef.h" +include "../lib/fitsky.h" + +# AP_SPLOT -- Procedure to compute radial profile plots for the sky fitting +# routine. + +procedure ap_splot (ap, sid, gd, makeplot) + +pointer ap # pointer to the apphot structure +int sid # id number of the star +pointer gd # graphics stream +int makeplot # make a plot + +int nx, ny, nskypix +pointer sp, sky, str, r, gt +real xcenter, ycenter, rmin, rmax, imin, imax +real u1, u2, v1, v2, x1, x2, y1, y2 +int apstati() +pointer ap_gtinit() +real apstatr() + +begin + # Initialize. + if (gd == NULL || makeplot == NO) + return + + # Check for defined center and non-constant algorithm. + xcenter = apstatr (ap, SXCUR) + ycenter = apstatr (ap, SYCUR) + if (IS_INDEFR(xcenter) || IS_INDEFR(ycenter)) + return + if (apstati (ap, SKYFUNCTION) == AP_CONSTANT) + return + + # Check that a buffer of sky pixels exists. + sky = AP_PSKY(ap) + nskypix = AP_NSKYPIX(sky) + nx = AP_SNX(sky) + ny = AP_SNY(sky) + if (nskypix <= 0 || nx <= 0 || ny <= 0) + return + + # Allocate working space + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + call salloc (r, nskypix, TY_REAL) + + # Compute the radii and the plot limits. + call ap_xytor (Memi[AP_COORDS(sky)], Memi[AP_INDEX(sky)], + Memr[r], nskypix, AP_SXC(sky), AP_SYC(sky), nx) + call alimr (Memr[r], nskypix, rmin, rmax) + rmin = rmin - 1.0 + rmax = rmax + 1.0 + call alimr (Memr[AP_SKYPIX(sky)], nskypix, imin, imax) + + # Reactivate the work station. + call greactivate (gd, 0) + + # Store the viewport and window coordinates. + call ggview (gd, u1, u2, v1, v2) + call ggwind (gd, x1, x2, y1, y2) + + # Initialize the plot. + call apstats (ap, IMROOT, Memc[str], SZ_LINE) + call sprintf (Memc[str], SZ_LINE, "%s Star %d") + call pargstr (Memc[str]) + call pargi (sid) + gt = ap_gtinit (Memc[str], apstatr (ap,OSXCUR), apstatr(ap,OSYCUR)) + + # Draw the plot. + call gclear (gd) + call ap_spset (gd, gt, ap, rmin, rmax, imin, imax) + call ap_spannotate (gd, ap, rmin, rmax, imin, imax) + call ap_plotrad (gd, gt, Memr[r], Memr[AP_SKYPIX(sky)], nskypix, "plus") + + # Restore the viewport and window coordinates. + call gsview (gd, u1, u2, v1, v2) + call gswind (gd, x1, x2, y1, y2) + + # Free the space. + call ap_gtfree (gt) + call gdeactivate (gd, 0) + call sfree (sp) +end + + +# AP_SPSET -- Procedure to set up the parameters for the fitsky radial profile +# plot. + +procedure ap_spset (gd, gt, ap, xmin, xmax, ymin, ymax) + +pointer gd # graphics stream +pointer gt # gtools pointer +pointer ap # apphot pointer +real xmin, xmax # minimum and maximum radial distance +real ymin, ymax # minimum and maximum of the y axis + +int fd +pointer sp, str, title +real aspect, scale, vx1, vx2, vy1, vy2 +int apstati(), stropen() +real apstatr(), gstatr() + +begin + call smark (sp) + call salloc (str, 3 * SZ_LINE, TY_CHAR) + call salloc (title, SZ_LINE, TY_CHAR) + + # Encode the parameter string. + fd = stropen (Memc[str], 3 * SZ_LINE, WRITE_ONLY) + + call sysid (Memc[title], SZ_FNAME) + call fprintf (fd, "%s\n") + call pargstr (Memc[title]) + + call fprintf (fd, + "Sky: value=%0.2f sigma=%0.2f skew=%0.2f nsky=%d nreject=%d\n") + call pargr (apstatr (ap, SKY_MODE)) + call pargr (apstatr (ap, SKY_SIGMA)) + call pargr (apstatr (ap, SKY_SKEW)) + call pargi (apstati (ap, NSKY)) + call pargi (apstati (ap, NSKY_REJECT)) + + call gt_gets (gt, GTTITLE, Memc[title], SZ_LINE) + call fprintf (fd, "%s\n") + call pargstr (Memc[title]) + + call strclose (fd) + + # Set the aspect ratio. + scale = apstatr (ap, SCALE) + aspect = gstatr (gd, G_ASPECT) + call gsetr (gd, G_ASPECT, 0.75) + + # Set the labels and window. + call gseti (gd, G_XDRAWAXES, 2) + call gswind (gd, xmin / scale, xmax / scale, ymin, ymax) + call glabax (gd, Memc[str], "", "Intensity") + call gseti (gd, G_YDRAWAXES, 0) + call gseti (gd, G_XDRAWAXES, 1) + call ggview (gd, vx1, vx2, vy1, vy2) + call gsview (gd, vx1, vx2, vy1, vy2) + call gswind (gd, xmin, xmax, ymin, ymax) + call glabax (gd, "", + "Radial Distance (lower-pixels, upper-scale units)", "") + + call gseti (gd, G_YDRAWAXES, 3) + call gseti (gd, G_XDRAWAXES, 3) + call gsetr (gd, G_ASPECT, aspect) + call gt_sets (gt, GTTYPE, "mark") + + call sfree (sp) +end + + +# AP_SPANNOTATE -- Procedure to annotate the radial plot in fitsky. + +procedure ap_spannotate (gd, ap, xmin, xmax, ymin, ymax) + +pointer gd # graphics stream +pointer ap # apphot structure +real xmin, xmax # min and max of x axis +real ymin, ymax # min and max of y axis + +pointer sp, str +real annulus, dannulus, sigma, skyval, skysigma +real apstatr () + +begin + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + call gseti (gd, G_PLTYPE, GL_DASHED) + + # Mark the inner sky annulus. + annulus = apstatr (ap, SCALE) * apstatr (ap, ANNULUS) + if (annulus >= xmin && annulus <= xmax) { + call gamove (gd, annulus, ymin) + call gadraw (gd, annulus, ymax) + call sprintf (Memc[str], SZ_LINE, "inner sky radius = %0.2f") + call pargr (annulus) + call gtext (gd, annulus, ymax, Memc[str], "q=h;u=180;v=t;p=r") + } + + # Mark the outer sky annulus. + dannulus = annulus + apstatr (ap, SCALE) * apstatr (ap, DANNULUS) + if (dannulus >= xmin && dannulus <= xmax) { + call gamove (gd, dannulus, ymin) + call gadraw (gd, dannulus, ymax) + call sprintf (Memc[str], SZ_LINE, "outer sky radius = %0.2f") + call pargr (dannulus) + call gtext (gd, dannulus, ymax, Memc[str], "q=h;u=180;v=t;p=r") + } + + # Mark the sky sigma if defined. + sigma = apstatr (ap, SKY_SIGMA) + if (! IS_INDEFR(sigma)) { + call gmark (gd, (xmin + xmax) / 2.0, (ymin + ymax) / 2.0, + GM_VEBAR, -0.25, -sigma) + call sprintf (Memc[str], SZ_LINE, "sigma = %g") + call pargr (sigma) + call gtext (gd, (xmin + xmax) / 2.0, (ymin + ymax + sigma) / 2.0, + Memc[str], "q=h;h=c") + } + + # Mark the sky value. + call gseti (gd, G_PLTYPE, GL_SOLID) + skyval = apstatr (ap, SKY_MODE) + if (skyval >= ymin && skyval <= ymax) { + call gamove (gd, xmin, skyval) + call gadraw (gd, xmax, skyval) + } + + # Mark the upper sky sigma. + call gseti (gd, G_PLTYPE, GL_DASHED) + if (! IS_INDEFR(apstatr (ap, SKY_SIGMA))) + skysigma = skyval + apstatr (ap, SHIREJECT) * apstatr (ap, + SKY_SIGMA) + else + skysigma = INDEFR + if (! IS_INDEFR(skysigma) && (skysigma >= ymin) && skysigma <= ymax) { + call gamove (gd, xmin, skysigma) + call gadraw (gd, xmax, skysigma) + #call sprintf (Memc[str], SZ_LINE, "sky sigma= %g") + #call pargr (skysigma) + } + + # Mark the lower sky sigma + if (! IS_INDEFR(apstatr (ap, SKY_SIGMA))) + skysigma = skyval - apstatr (ap, SLOREJECT) * apstatr (ap, + SKY_SIGMA) + else + skysigma = INDEFR + if (! IS_INDEFR(skysigma) && (skysigma >= ymin) && skysigma <= ymax) { + call gamove (gd, xmin, skysigma) + call gadraw (gd, xmax, skysigma) + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/fitsky/apsradsetup.x b/noao/digiphot/apphot/fitsky/apsradsetup.x new file mode 100644 index 00000000..fd4039f8 --- /dev/null +++ b/noao/digiphot/apphot/fitsky/apsradsetup.x @@ -0,0 +1,97 @@ +include "../lib/display.h" +include "../lib/fitsky.h" + +define HELPFILE "apphot$fitsky/ifitsky.key" + +# AP_SRADSETUP -- Procedure to set up the sky fitting interactively using +# radial profile plot around the given coordinates. + +procedure ap_sradsetup (ap, im, wx, wy, gd, out, stid) + +pointer ap # pointer to apphot structure +pointer im # pointero to the IRAF image +real wx, wy # cursor coordinates +pointer gd # pointer to graphics stream +int out # output file descriptor +int stid # output file sequence number + +int ier, key, wcs +pointer sp, cmd +real xcenter, ycenter, xc, yc, rmin, rmax, imin, imax, rval +real u1, u2, v1, v2, x1, x2, y1, y2 + +int apstati(), apfitsky(), clgcur(), ap_showplot() +real apstatr(), ap_cannulus(), ap_cdannulus(), ap_csigma() +real ap_cdatamin(), ap_cdatamax(), ap_crgrow() + +begin + if (gd == NULL) + return + call greactivate (gd, 0) + + # Store the old window and viewport coordinates. + call ggview (gd, u1, u2, v1, v2) + call ggwind (gd, x1, x2, y1, y2) + + # Plot the profile. + if (ap_showplot (ap, im, wx, wy, gd, xcenter, ycenter, rmin, rmax, + imin, imax) == ERR) { + call gdeactivate (gd, 0) + return + } + + # Allocate memory. + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + call printf ( + "Waiting for setup menu command (?=help, v=default setup, q=quit):") + while (clgcur ("gcommands", xc, yc, wcs, key, Memc[cmd], + SZ_LINE) != EOF) { + + switch (key) { + + case 'q': + break + case '?': + call gpagefile (gd, HELPFILE, "") + case 's': + rval = ap_csigma (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'l': + rval = ap_cdatamin (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'u': + rval = ap_cdatamax (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'a': + rval = ap_cannulus (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'd': + rval = ap_cdannulus (ap, gd, out, stid, apstatr (ap, ANNULUS), + rmin, rmax, imin, imax) + case 'g': + rval = ap_crgrow (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'v': + rval = ap_cannulus (ap, gd, out, stid, rmin, rmax, imin, imax) + rval = ap_cdannulus (ap, gd, out, stid, apstatr (ap, ANNULUS), + rmin, rmax, imin, imax) + rval = ap_csigma (ap, gd, out, stid, rmin, rmax, imin, imax) + default: + call printf ("Unknown or ambiguous keystroke command\007\n") + } + call printf ( + "Waiting for setup menu command (?=help, v=default setup, q=quit):") + } + call printf ( + "Interactive setup is complete. Type w to store parameters.\n") + + # Store the old window and viewport coordinates. + call gsview (gd, u1, u2, v1, v2) + call gswind (gd, x1, x2, y1, y2) + + # Free the plotting space. + call sfree (sp) + call gdeactivate (gd, 0) + + # Fit the new sky value and print it on the standard output. + ier = apfitsky (ap, im, xcenter, ycenter, NULL, gd) + call ap_splot (ap, 0, gd, apstati (ap, RADPLOTS)) + call ap_qspsky (ap, ier) +end diff --git a/noao/digiphot/apphot/fitsky/apsshow.x b/noao/digiphot/apphot/fitsky/apsshow.x new file mode 100644 index 00000000..da54bfbf --- /dev/null +++ b/noao/digiphot/apphot/fitsky/apsshow.x @@ -0,0 +1,99 @@ +include "../lib/display.h" +include "../lib/fitsky.h" + + +# AP_SSHOW -- Procedure to print sky fitting parameters on the terminal. + +procedure ap_sshow (ap) + +pointer ap # pointer to the apphot strucuture + +bool itob() +int apstati() + +begin + call ap_nshow (ap) + call printf ("\n") + call ap_spshow (ap) + call printf (" %s = %b\n") + call pargstr (KY_RADPLOTS) + call pargb (itob (apstati (ap, RADPLOTS))) +end + + +# AP_SPSHOW -- Procedure to print sky fitting parameters on the terminal. + +procedure ap_spshow (ap) + +pointer ap # pointer to the apphot strucuture + +pointer sp, str +bool itob() +int apstati() +real apstatr() + +begin + # Print the image characteristics + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + + # Print the sky fitting parameters. + call printf ("Sky Fitting Parameters\n") + call apstats (ap, SSTRING, Memc[str], SZ_FNAME) + call printf (" %s = %s %s %s = %g %s\n") + call pargstr (KY_SSTRING) + call pargstr (Memc[str]) + call pargstr (UN_SALGORITHM) + call pargstr (KY_SKY_BACKGROUND) + call pargr (apstatr (ap, SKY_BACKGROUND)) + call pargstr (UN_SCOUNTS) + + call printf (" %s = %g %s %s = %g %s\n") + call pargstr (KY_ANNULUS) + call pargr (apstatr (ap, ANNULUS)) + call pargstr (UN_SSCALEUNIT) + call pargstr (KY_DANNULUS) + call pargr (apstatr (ap, DANNULUS)) + call pargstr (UN_SSCALEUNIT) + + call printf (" %s = %g %s %s = %g %s %s = %b\n") + call pargstr (KY_K1) + call pargr (apstatr (ap, K1)) + call pargstr (UN_SSIGMA) + call pargstr (KY_BINSIZE) + call pargr (apstatr (ap, BINSIZE)) + call pargstr (UN_SSIGMA) + call pargstr (KY_SMOOTH) + call pargb (itob (apstati (ap, SMOOTH))) + + call printf (" %s = %g %s %s = %g %s\n") + call pargstr (KY_SLOCLIP) + call pargr (apstatr (ap, SLOCLIP)) + call pargstr (UN_SPERCENT) + call pargstr (KY_SHICLIP) + call pargr (apstatr (ap, SHICLIP)) + call pargstr (UN_SPERCENT) + + call printf (" %s = %g %s %s = %g %s %s = %d\n") + call pargstr (KY_SLOREJECT) + call pargr (apstatr (ap, SLOREJECT)) + call pargstr (UN_SSIGMA) + call pargstr (KY_SHIREJECT) + call pargr (apstatr (ap, SHIREJECT)) + call pargstr (UN_SSIGMA) + call pargstr (KY_SMAXITER) + call pargi (apstati (ap, SMAXITER)) + + call printf (" %s = %d %s = %g %s\n") + call pargstr (KY_SNREJECT) + call pargi (apstati (ap, SNREJECT)) + call pargstr (KY_RGROW) + call pargr (apstatr (ap, RGROW)) + call pargstr (UN_SSCALEUNIT) + + call printf (" %s = %b\n") + call pargstr (KY_MKSKY) + call pargb (itob (apstati (ap, MKSKY))) + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/fitsky/fitsky.key b/noao/digiphot/apphot/fitsky/fitsky.key new file mode 100644 index 00000000..ee515bf1 --- /dev/null +++ b/noao/digiphot/apphot/fitsky/fitsky.key @@ -0,0 +1,81 @@ + Interactive Keystroke Commands + +? Print help +: Colon commands +v Verify the critical parameters +w Save the current parameters +d Plot radial profile of current star +i Interactively set parameters using current star +f Fit sky for current star +spbar Fit sky for current star, output results +m Move to next star in coordinate list +m Fit sky for next star in coordinate list, output results +l Fit sky for remaining stars in coordinate list, output results +e Print error messages +r Rewind the coordinate list +q Exit task + + + Colon commands + +:show [data/sky] List the parameters +:m [n] Move to the next [nth] star in coordinate list +:n [n] Fit sky to next [nth] star in coordinate list, output results + + Colon Parameter Editing Commands + +# Image and file name parameters + +:image [string] Image name +:coords [string] Coordinate file name +:output [string] Output file name + +# Data dependent parameters + +:scale [value] Image scale (units per pixel) +:fwhmpsf [value] Full width half maximum PSF (scale units) +:emission [y/n] Emission feature (y), absorption (n) +:sigma [value] Standard deviation of sky (counts) +:datamin [value] Minimum good pixel value (counts) +:datamax [value] Maximum good pixel value (counts) + +# Noise parameters + +:noise [string] Noise model (constant|poisson) +:gain [string] Gain image header keyword +:ccdread [string] Readout noise image header keyword +:epadu [value] Gain (electrons per adu) +:readnoise [value] Readout noise (electrons) + +# Observations parameters + +:exposure [string] Exposure time image header keyword +:airmass [string] Airmass image header keyword +:filter [string] Filter image header keyword +:obstime [string] Time of observation image header keyword +:itime [value] Exposure time (time units) +:xairmass [value] Airmass value (number) +:ifilter [string] Filter id string +:otime [string] Time of observation (time units) + +# Sky fitting algorithm parameters + +:salgorithm [string] Sky fitting algorithm +:skyvalue [value] User supplied sky value (counts) +:annulus [value] Inner radius of sky annulus (scale units) +:dannulus [value] Width of sky annulus (scale units) +:khist [value] Sky histogram extent (+/- sky sigma) +:smooth [y/n] Lucy smooth the sky histogram +:binsize [value] Resolution of sky histogram (sky sigma) +:smaxiter [value] Maximum number of iterations +:sloclip [value] Low side clipping factor (percent) +:shiclip [value] High side clipping factor (percent) +:snreject [value] Maximum number of rejection cycles +:sloreject [value] Low side pixel rejection limits (sky sigma) +:shireject [value] High side pixel rejection limits (sky sigma) +:rgrow [value] Region growing radius (scale units) + +# Marking and plotting parameters + +:mksky [y/n] Mark sky annuli on the display +:radplot [y/n] Plot radial profile of sky pixels diff --git a/noao/digiphot/apphot/fitsky/ifitsky.key b/noao/digiphot/apphot/fitsky/ifitsky.key new file mode 100644 index 00000000..bd651bc3 --- /dev/null +++ b/noao/digiphot/apphot/fitsky/ifitsky.key @@ -0,0 +1,11 @@ + Interactive Fitsky Setup Menu + + v Mark and verify the critical parameters (a,d,s) + + s Mark and verify the standard deviation of the sky + l Mark and verify the minimum good data value + u Mark and verify the maximum good data value + + a Mark and verify the inner radius of the sky annulus + d Mark and verify the width of the sky annulus + g Mark and verify the region growing radius diff --git a/noao/digiphot/apphot/fitsky/mkpkg b/noao/digiphot/apphot/fitsky/mkpkg new file mode 100644 index 00000000..a72edc57 --- /dev/null +++ b/noao/digiphot/apphot/fitsky/mkpkg @@ -0,0 +1,59 @@ +# FITSKY Task Tools + +$checkout libpkg.a ".." +$update libpkg.a +$checkin libpkg.a ".." +$exit + +libpkg.a: + apavsky.x ../lib/display.h ../lib/fitsky.h + apbsky.x <fset.h> ../lib/apphot.h \ + ../lib/display.h + apcentroid.x <mach.h> ../lib/fitsky.h + apcrosscor.x <mach.h> ../lib/fitsky.h + apfitsky.x ../lib/apphotdef.h ../lib/noisedef.h \ + ../lib/fitskydef.h ../lib/fitsky.h \ + ../lib/apphot.h + apgauss.x <mach.h> ../lib/fitsky.h \ + <math/nlfit.h> + apgrowhist.x + apgspars.x ../lib/display.h ../lib/fitsky.h \ + ../lib/noise.h + aphgmsub.x + aphistplot.x <gset.h> <pkg/gtools.h> \ + ../lib/fitsky.h + aplgsky.x <mach.h> ../lib/fitsky.h + apmean.x <mach.h> ../lib/fitsky.h + apmedian.x <mach.h> ../lib/fitsky.h + apmode.x <mach.h> ../lib/fitsky.h + appsky.x ../lib/fitsky.h ../lib/apphot.h + apradplot.x ../lib/fitsky.h + apreadsky.x + aprefitsky.x ../lib/apphotdef.h ../lib/noisedef.h \ + ../lib/fitskydef.h ../lib/fitsky.h \ + ../lib/apphot.h + aprgrow.x + apsconfirm.x ../lib/apphot.h ../lib/noise.h \ + ../lib/fitsky.h + apserrors.x ../lib/fitsky.h + apsfree.x ../lib/apphotdef.h ../lib/fitskydef.h + apsinit.x ../lib/apphotdef.h ../lib/fitskydef.h \ + ../lib/fitsky.h + apsky.x <ctype.h> <gset.h> \ + ../lib/apphot.h ../lib/display.h \ + ../lib/fitsky.h <imhdr.h> + apskybuf.x <imhdr.h> <math.h> \ + ../lib/apphotdef.h ../lib/fitskydef.h \ + ../lib/fitsky.h <mach.h> + apskycolon.x ../lib/apphot.h ../lib/fitsky.h \ + ../lib/display.h ../lib/noise.h + apsradsetup.x ../lib/display.h ../lib/fitsky.h + appspars.x ../lib/display.h + apsplot.x <pkg/gtools.h> <gset.h> \ + ../lib/apphot.h ../lib/noise.h \ + ../lib/fitsky.h ../lib/fitskydef.h \ + ../lib/apphotdef.h + apsshow.x ../lib/display.h ../lib/fitsky.h + t_fitsky.x <fset.h> <gset.h> \ + ../lib/apphot.h <imhdr.h> + ; diff --git a/noao/digiphot/apphot/fitsky/t_fitsky.x b/noao/digiphot/apphot/fitsky/t_fitsky.x new file mode 100644 index 00000000..c9fb7db8 --- /dev/null +++ b/noao/digiphot/apphot/fitsky/t_fitsky.x @@ -0,0 +1,303 @@ +include <gset.h> +include <fset.h> +include <imhdr.h> +include "../lib/apphot.h" + +# T_FITSKY -- Procedure to fit sky values in a an annular region around +# a list of objects. + +procedure t_fitsky () + +pointer image # pointer to the name of the image +pointer output # pointer to output file name +pointer coords # coordinate file +pointer plotfile # pointer to file of graphics metacode +pointer graphics # pointer to graphics display device +pointer display # pointer to display device +int interactive # mode of use +int cache # cache the image pixels in memory +int verify # verify critical parameters +int update # update the critical parameter +int verbose # verbose mode + +pointer sp, outfname, cname, ap, im, mgd, gd, id, str +int sid, lid, limlist, lclist, lolist, out, cl, pfd, root, stat, memstat +int imlist, clist, olist, wcs, req_size, old_size, buf_size + +pointer immap(), gopen() +int imtlen(), imtgetim(), clplen(), clgfil(), btoi(), fnldir(), strncmp() +int strlen(), apsky(), imtopenp(), clpopnu(), open(), clgwrd(), ap_memstat() +int sizeof() +bool clgetb(), streq() +errchk gopen + +begin + # Allocate working space. + call smark (sp) + call salloc (image, SZ_FNAME, TY_CHAR) + call salloc (output, SZ_FNAME, TY_CHAR) + call salloc (coords, SZ_FNAME, TY_CHAR) + call salloc (plotfile, SZ_FNAME, TY_CHAR) + call salloc (graphics, SZ_FNAME, TY_CHAR) + call salloc (display, SZ_FNAME, TY_CHAR) + call salloc (outfname, SZ_FNAME, TY_CHAR) + call salloc (cname, SZ_FNAME, TY_CHAR) + call salloc (str, SZ_LINE, TY_CHAR) + + # Set the standard output to flush on a newline. + call fseti (STDOUT, F_FLUSHNL, YES) + + # Get input and output file names. + imlist = imtopenp ("image") + limlist = imtlen (imlist) + clist = clpopnu ("coords") + lclist = clplen (clist) + olist = clpopnu ("output") + lolist = clplen (olist) + + # Check that image and coordinate list lengths match. + if (limlist < 1 || (lclist > 1 && lclist != limlist)) { + call imtclose (imlist) + call clpcls (clist) + call clpcls (olist) + call error (0, "Imcompatable image and coordinate list lengths") + } + + # Check that image and output list lengths match. + if (lolist > 1 && lolist != limlist) { + call imtclose (imlist) + call clpcls (clist) + call clpcls (olist) + call error (0, "Imcompatible image and output list lengths") + } + + call clgstr ("icommands.p_filename", Memc[cname], SZ_FNAME) + if (Memc[cname] != EOS) + interactive = NO + #else if (lclist == 0) + #interactive = YES + else + interactive = btoi (clgetb ("interactive")) + cache = btoi (clgetb("cache")) + verify = btoi (clgetb ("verify")) + update = btoi (clgetb ("update")) + verbose = btoi (clgetb ("verbose")) + + # Get the parameters. + call ap_sgpars (ap) + if (verify == YES && interactive == NO) { + call ap_sconfirm (ap, NULL, 1) + if (update == YES) + call ap_pspars (ap) + } + + # Get the wcs information. + wcs = clgwrd ("wcsin", Memc[str], SZ_LINE, WCSINSTR) + if (wcs <= 0) { + call eprintf ( + "Warning: Setting the input coordinate system to logical\n") + wcs = WCS_LOGICAL + } + call apseti (ap, WCSIN, wcs) + wcs = clgwrd ("wcsout", Memc[str], SZ_LINE, WCSOUTSTR) + if (wcs <= 0) { + call eprintf ( + "Warning: Setting the output coordinate system to logical\n") + wcs = WCS_LOGICAL + } + call apseti (ap, WCSOUT, wcs) + + # Get the graphics and display devices. + call clgstr ("graphics", Memc[graphics], SZ_FNAME) + call clgstr ("display", Memc[display], SZ_FNAME) + + # Open plot files. + if (interactive == YES) { + if (Memc[graphics] == EOS) + gd = NULL + else { + iferr { + gd = gopen (Memc[graphics], APPEND+AW_DEFER, STDGRAPH) + } then { + call eprintf ( + "Warning: Error opening graphics device.\n") + gd = NULL + } + } + if (Memc[display] == EOS) + id = NULL + else if (streq (Memc[graphics], Memc[display])) + id = gd + else { + iferr { + id = gopen (Memc[display], APPEND, STDIMAGE) + } then { + call eprintf ( + "Warning: Graphics overlay not available for display device.\n") + id = NULL + } + } + } else { + gd = NULL + id = NULL + } + + # Open the plot metacode file. + call clgstr ("plotfile", Memc[plotfile], SZ_FNAME) + if (Memc[plotfile] == EOS) + pfd = NULL + else + pfd = open (Memc[plotfile], APPEND, BINARY_FILE) + if (pfd != NULL) + mgd = gopen (Memc[graphics], NEW_FILE, pfd) + else + mgd = NULL + + # Begin looping over image list. + sid = 1 + while (imtgetim (imlist, Memc[image], SZ_FNAME) != EOF) { + + # Open image. + im = immap (Memc[image], READ_ONLY, 0) + call apimkeys (ap, im, Memc[image]) + + # Set the image display viewport. + if ((id != NULL) && (id != gd)) + call ap_gswv (id, Memc[image], im, 4) + + # Cache the input image pixels. + req_size = MEMFUDGE * IM_LEN(im,1) * IM_LEN(im,2) * + sizeof (IM_PIXTYPE(im)) + memstat = ap_memstat (cache, req_size, old_size) + if (memstat == YES) + call ap_pcache (im, INDEFI, buf_size) + + # Open the coordinate file, where coords is assumed to be a simple + # text file in which the x and y positions are in columns 1 and 2 + # respectively and all remaining fields are ignored. + + if (lclist <= 0) { + cl = NULL + call strcpy ("", Memc[outfname], SZ_FNAME) + } else { + stat = clgfil (clist, Memc[coords], SZ_FNAME) + root = fnldir (Memc[coords], Memc[outfname], SZ_FNAME) + if (strncmp ("default", Memc[coords+root], 7) == 0 || root == + strlen (Memc[coords])) { + call ap_inname (Memc[image], Memc[outfname], "coo", + Memc[outfname], SZ_FNAME) + lclist = limlist + cl = open (Memc[outfname], READ_ONLY, TEXT_FILE) + } else if (stat != EOF) { + call strcpy (Memc[coords], Memc[outfname], SZ_FNAME) + cl = open (Memc[outfname], READ_ONLY, TEXT_FILE) + } else { + call apstats (ap, CLNAME, Memc[outfname], SZ_FNAME) + call seek (cl, BOF) + } + } + call apsets (ap, CLNAME, Memc[outfname]) + call apfroot (Memc[outfname], Memc[str], SZ_LINE) + call apsets (ap, CLROOT, Memc[str]) + + # Open the output text file, if output is "default", dir$default + # or a directory specification then the extension "sky" is added + # to the image name and a suitable version number is appended to + # the output name. If the output string is null to output file + # is created. + + if (lolist == 0) { + out = NULL + call strcpy ("", Memc[outfname], SZ_FNAME) + } else { + stat = clgfil (olist, Memc[output], SZ_FNAME) + root = fnldir (Memc[output], Memc[outfname], SZ_FNAME) + if (strncmp ("default", Memc[output+root], 7) == 0 || root == + strlen (Memc[output])) { + call apoutname (Memc[image], Memc[outfname], "sky", + Memc[outfname], SZ_FNAME) + out = open (Memc[outfname], NEW_FILE, TEXT_FILE) + lolist = limlist + } else if (stat != EOF) { + call strcpy (Memc[output], Memc[outfname], SZ_FNAME) + out = open (Memc[outfname], NEW_FILE, TEXT_FILE) + } else + call apstats (ap, OUTNAME, Memc[outfname], SZ_FNAME) + } + call apsets (ap, OUTNAME, Memc[outfname]) + + # Fit the sky + if (interactive == NO) { + if (Memc[cname] != EOS) + stat = apsky (ap, im, cl, NULL, NULL, mgd, NULL, out, + sid, NO, cache) + else if (cl != NULL) { + lid = 1 + call apbsky (ap, im, cl, NULL, out, sid, lid, gd, mgd, id, + verbose) + stat = NO + } else + stat = NO + } else + stat = apsky (ap, im, cl, NULL, gd, mgd, id, out, sid, YES, + cache) + + # Cleanup. + call imunmap (im) + if (cl != NULL) { + if (lclist > 1) + call close (cl) + } + if (out != NULL && lolist != 1) { + call close (out) + if (sid <= 1) { + call apstats (ap, OUTNAME, Memc[outfname], SZ_FNAME) + call delete (Memc[outfname]) + } + sid = 1 + } + + # Uncache memory. + call fixmem (old_size) + + if (stat == YES) + break + } + + # If only one coordinate file for a list of images close. + if (cl != NULL && lclist == 1) + call close (cl) + + # If only one output file for a list of images close. + if (out != NULL && lolist == 1) { + call close (out) + if (sid <= 1) { + call apstats (ap, OUTNAME, Memc[outfname], SZ_FNAME) + call delete (Memc[outfname]) + } + } + + # Close up plot files. + if (id == gd && id != NULL) { + call gclose (id) + } else { + if (gd != NULL) + call gclose (gd) + if (id != NULL) + call gclose (id) + } + if (mgd != NULL) + call gclose (mgd) + if (pfd != NULL) + call close (pfd) + + # Free sky fitting structure + call apsfree (ap) + + # Close up lists. + call imtclose (imlist) + call clpcls (clist) + call clpcls (olist) + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/fitskypars.par b/noao/digiphot/apphot/fitskypars.par new file mode 100644 index 00000000..2a90cf33 --- /dev/null +++ b/noao/digiphot/apphot/fitskypars.par @@ -0,0 +1,17 @@ +# SKY FITTING PARAMETERS + +salgorithm,s,h,"centroid","|median|mode|centroid|gauss|crosscor|ofilter|histplot|radplot|constant|file|mean|",,Sky fitting algorithm +annulus,r,h,10.0,,,Inner radius of sky annulus in scale units +dannulus,r,h,10.0,,,Width of sky annulus in scale units +skyvalue,r,h,0.0,,,User sky value +smaxiter,i,h,10,,,Maximum number of sky fitting iterations +sloclip,r,h,0.0,,,Lower clipping factor in percent +shiclip,r,h,0.0,,,Upper clipping factor in percent +snreject,i,h,50,,,Maximum number of sky fitting rejection iterations +sloreject,r,h,3.0,,,Lower K-sigma rejection limit in sky sigma +shireject,r,h,3.0,,,Upper K-sigma rejection limit in sky sigma +khist,r,h,3.0,,,Half width of histogram in sky sigma +binsize,r,h,0.10,,,Binsize of histogram in sky sigma +smooth,b,h,no,,,Boxcar smooth the histogram +rgrow,r,h,0.0,,,Region growing radius in scale units +mksky,b,h,no,,,Mark sky annuli on the display diff --git a/noao/digiphot/apphot/lib/apphot.h b/noao/digiphot/apphot/lib/apphot.h new file mode 100644 index 00000000..b9c7fb33 --- /dev/null +++ b/noao/digiphot/apphot/lib/apphot.h @@ -0,0 +1,110 @@ +# APPHOT header file + +# APPHOT parameters (# 1 - 100) + +define IMNAME 1 # Image name +define IMROOT 2 # Image name +define CLNAME 3 # Coordinates file name +define CLROOT 4 # Coordinates file name +define PLOTFILE 5 # Name of the plotfile +define OUTNAME 6 # Output file name + +define WCSIN 7 # Input WCS +define WCSOUT 8 # Input WCS +define MW 9 # MWCS descriptor +define CTIN 10 # Input WCS transformation +define CTOUT 11 # Output WCS transformation + +define SCALE 12 # Scale in pixels / unit +define FWHMPSF 13 # Full width half maximum of the PSF +define POSITIVE 14 # Emission or absorption feature +define DATAMIN 15 # Minimum good data value +define DATAMAX 16 # Maximum good data value + +define ITIME 17 # Exposure time +define AIRMASS 18 # Airmass keyword +define FILTER 19 # Filter keyword +define OBSTIME 20 # Time of observation keyword + +define XAIRMASS 21 # Airmass value +define FILTERID 22 # Filter id +define OTIME 23 # Time stamp +define EXPOSURE 24 # Exposure time keyword + +define WX 25 # Previous X cursor position +define WY 26 # Previous Y cursor position +define CWX 27 # Current X cursor position +define CWY 28 # Current Y cursor position + +# Define the WCS types + +define WCSINSTR "|logical|tv|physical|world|" +define WCSOUTSTR "|logical|tv|physical|" +define WCS_LOGICAL 1 +define WCS_TV 2 +define WCS_PHYSICAL 3 +define WCS_WORLD 4 + +# define APPHOT keywords + +define KY_FWHMPSF "fwhmpsf" +define KY_IMNAME "image" +define KY_POSITIVE "emission" +define KY_ITIME "itime" +define KY_EXPOSURE "exposure" +define KY_DATAMIN "datamin" +define KY_DATAMAX "datamax" +define KY_OUTNAME "output" +define KY_CLNAME "coords" +define KY_SCALE "scale" +define KY_AIRMASS "airmass" +define KY_XAIRMASS "xairmass" +define KY_FILTER "filter" +define KY_FILTERID "ifilter" +define KY_OBSTIME "obstime" +define KY_OTIME "otime" + +# define APPHOT units strings + +define UN_ASCALEUNIT "scaleunit" +define UN_ASWITCH "switch" +define UN_ACOUNTS "counts" +define UN_AUNITS "units" +define UN_ATIMEUNIT "timeunit" +define UN_AKEYWORD "keyword" +define UN_ANAME "name" +define UN_ANUMBER "number" + +# APPHOT string commands + +define APCMDS "|fwhmpsf|emission|exposure|itime|datamin|datamax|image|coords|output|scale|airmass|xairmass|filter|ifilter|obstime|otime|" + +define APCMD_FWHMPSF 1 +define APCMD_EMISSION 2 +define APCMD_EXPOSURE 3 +define APCMD_ITIME 4 +define APCMD_DATAMIN 5 +define APCMD_DATAMAX 6 +define APCMD_IMAGE 7 +define APCMD_COORDS 8 +define APCMD_OUTPUT 9 +define APCMD_SCALE 10 +define APCMD_AIRMASS 11 +define APCMD_XAIRMASS 12 +define APCMD_FILTER 13 +define APCMD_FILTERID 14 +define APCMD_OBSTIME 15 +define APCMD_OTIME 16 + + +# Define the memory cacheing fudge factor + +define MEMFUDGE 1.05 + +# Miscellaneous commands + +define MISC "|show|radplots|" +define MISC1 "|show|" + +define ACMD_SHOW 1 +define ACMD_RADPLOTS 2 diff --git a/noao/digiphot/apphot/lib/apphotdef.h b/noao/digiphot/apphot/lib/apphotdef.h new file mode 100644 index 00000000..a63b6dbd --- /dev/null +++ b/noao/digiphot/apphot/lib/apphotdef.h @@ -0,0 +1,80 @@ +# APPHOT Structure + +define LEN_APSTRUCT (36 + 12 * SZ_FNAME + 12) + +# apphot definitions + +define AP_VERSION Memi[$1] # Package version number +define AP_CWX Memr[P2R($1+1)] # Current x cursor coordinate +define AP_CWY Memr[P2R($1+2)] # Current y cursor coordinate +define AP_WX Memr[P2R($1+3)] # Previous x cursor coordinate +define AP_WY Memr[P2R($1+4)] # Previous y cursor coordinate +define AP_FWHMPSF Memr[P2R($1+5)] # FWHM of the PSF +define AP_SCALE Memr[P2R($1+6)] # Scale in pixels / unit (internal) +define AP_POSITIVE Memi[$1+7] # Emission feature ? +define AP_DATAMIN Memr[P2R($1+8)] # Mininum good data value +define AP_DATAMAX Memr[P2R($1+9)] # Maximum good data value +define AP_ITIME Memr[P2R($1+10)] # Exposure time +define AP_XAIRMASS Memr[P2R($1+11)] # Air mass + +# pointer to the apphot strucutures + +define AP_NOISE Memi[$1+12] # Pointer to noise structure +define AP_PCENTER Memi[$1+13] # Pointer to center structure +define AP_PSKY Memi[$1+14] # Pointer to sky structure +define AP_PPSF Memi[$1+15] # Pointer to psf structure +define AP_PPHOT Memi[$1+16] # Pointer to phot structure +define AP_PDISPLAY Memi[$1+17] # Pointer to display structure +define AP_POLY Memi[$1+18] # Pointer to polyphot structure +define AP_RPROF Memi[$1+19] # Pointer to radprof strucuture +define AP_PFIND Memi[$1+20] # Pointer to the find structure + +# pointer to sequential access buffer (not used currently) + +define AP_SEQUENTIAL Memi[$1+21] # Sequential or random access +define AP_IMBUF Memi[$1+22] # Pointer to internal buffer +define AP_HWIDTH Memi[$1+23] # Half-width of buffer in image lines +define AP_IMX1 Memi[$1+24] # Lower column limit of buffer +define AP_IMX2 Memi[$1+25] # Upper column limit of buffer +define AP_IMY1 Memi[$1+26] # Lower line limit of buffer +define AP_IMY2 Memi[$1+27] # Upper line limit of buffer + +# pointer to the wcs info + + +define AP_WCSIN Memi[$1+28] # the input wcs +define AP_WCSOUT Memi[$1+29] # the output wcs +define AP_MW Memi[$1+30] # the mwcs pointer +define AP_CTIN Memi[$1+31] # the input transformation pointer +define AP_CTOUT Memi[$1+32] # the output transformation pointer + +# image, file and keyword names + +define AP_IMNAME Memc[P2C($1+36)] # IRAF image name +define AP_IMROOT Memc[P2C($1+36+SZ_FNAME+1)] # IRAF image root name +define AP_CLNAME Memc[P2C($1+36+2*SZ_FNAME+2)] # Coordinate list +define AP_CLROOT Memc[P2C($1+36+3*SZ_FNAME+3)] # Coordinate list root +define AP_PLOTFILE Memc[P2C($1+36+4*SZ_FNAME+4)] # Plotfile +define AP_OUTNAME Memc[P2C($1+36+5*SZ_FNAME+5)] # Output +define AP_EXPOSURE Memc[P2C($1+36+6*SZ_FNAME+6)] # Exposure keyword +define AP_AIRMASS Memc[P2C($1+36+7*SZ_FNAME+7)] # Airmass keyword +define AP_FILTER Memc[P2C($1+36+8*SZ_FNAME+8)] # Filter keyword +define AP_FILTERID Memc[P2C($1+36+9*SZ_FNAME+9)] # Filter id +define AP_OBSTIME Memc[P2C($1+36+10*SZ_FNAME+10)] # Obstime keyword +define AP_OTIME Memc[P2C($1+36+11*SZ_FNAME+11)] # Time of observation + +# default definitions + +define DEF_SCALE 1.0000 +define DEF_POSITIVE YES +define DEF_DATAMIN INDEFR +define DEF_DATAMAX INDEFR + +define DEF_EXPOSURE "" +define DEF_AIRMASS "" +define DEF_FILTER "" +define DEF_OBSTIME "" +define DEF_ITIME INDEFR +define DEF_XAIRMASS INDEFR +define DEF_FILTERID "INDEF" +define DEF_OTIME "INDEF" diff --git a/noao/digiphot/apphot/lib/center.h b/noao/digiphot/apphot/lib/center.h new file mode 100644 index 00000000..ecf672f3 --- /dev/null +++ b/noao/digiphot/apphot/lib/center.h @@ -0,0 +1,102 @@ +# CENTER defintions + +# centering algorithms + +define AP_CENTROID1D 1 # 1D centroiding +define AP_GAUSS1D 2 # 1D Gaussian +define AP_NONE 3 # No centering +define AP_OFILT1D 4 # 1-D optimal filtering + +# centering errors (# 101 - 200) + +define AP_OK 0 # No error +define AP_CTR_NOAREA 101 # No pixels for centering +define AP_CTR_OUTOFBOUNDS 102 # Centering aperture extends oob +define AP_CTR_LOWSNRATIO 103 # S/N ratio too low for centering +define AP_CTR_NTOO_SMALL 104 # Too few histogram bins +define AP_CTR_SINGULAR 105 # Fit is singular +define AP_CTR_NOCONVERGE 106 # Solution does not converge +define AP_CTR_BADSHIFT 107 # Max shift parameter exceeded +define AP_CTR_BADDATA 108 # Bad data in centering subraster + +# centering parameters (# 101 - 200) + +define CAPERT 101 +define CENTERFUNCTION 102 +define MINSNRATIO 103 +define MAXSHIFT 104 +define CLEAN 105 +define RCLEAN 106 +define RCLIP 107 +define SIGMACLEAN 108 +define OXINIT 109 +define OYINIT 110 +define XCENTER 111 +define YCENTER 112 +define OXCENTER 113 +define OYCENTER 114 +define XERR 115 +define YERR 116 +define CMAXITER 117 +define CXCUR 118 +define CYCUR 119 +define XSHIFT 120 +define YSHIFT 121 +define OXSHIFT 122 +define OYSHIFT 123 +define CSTRING 124 +define CDATALIMIT 125 +define CTHRESHOLD 126 + +# center keywords + +define KY_CAPERT "cboxwidth" +define KY_CSTRING "calgorithm" +define KY_MINSNRATIO "minsnratio" +define KY_MAXSHIFT "maxshift" +define KY_CLEAN "clean" +define KY_RCLEAN "rclean" +define KY_RCLIP "rclip" +define KY_SIGMACLEAN "kclean" +define KY_CMAXITER "cmaxiter" +define KY_CTHRESHOLD "cthreshold" + +# center unit strings + +#define UN_CAPERT "scaleunit" +#define UN_CSTRING "algorithm" +#define UN_MINSNRATIO "number" +#define UN_MAXSHIFT "scaleunit" +#define UN_CLEAN "switch" +#define UN_RCLEAN "scaleunit" +#define UN_RCLIP "scaleunit" +#define UN_SIGMACLEAN "sigma" +#define UN_CMAXITER "number" +#define UN_CTHRESHOLD "sigma" + +define UN_CSCALEUNIT "scaleunit" +define UN_CNUMBER "number" +define UN_CSIGMA "sigma" +define UN_CSWITCH "switch" +define UN_CALGORITHM "algorithm" + +# center string commands + +define CSHOWARGS "|data|center|" +define CFUNCS "|centroid|gauss|none|ofilter|" +define CCMDS "|cboxwidth|calgorithm|maxshift|minsnratio|cmaxiter|clean|rclean|rclip|kclean|mkcenter|cthreshold|" + +define CCMD_CBOXWIDTH 1 +define CCMD_CALGORITHM 2 +define CCMD_MAXSHIFT 3 +define CCMD_MINSNRATIO 4 +define CCMD_CMAXITER 5 +define CCMD_CLEAN 6 +define CCMD_RCLEAN 7 +define CCMD_RCLIP 8 +define CCMD_KCLEAN 9 +define CCMD_MKCENTER 10 +define CCMD_CTHRESHOLD 11 + +define CCMD_DATA 1 +define CCMD_CENTER 2 diff --git a/noao/digiphot/apphot/lib/centerdef.h b/noao/digiphot/apphot/lib/centerdef.h new file mode 100644 index 00000000..c9dcd6a4 --- /dev/null +++ b/noao/digiphot/apphot/lib/centerdef.h @@ -0,0 +1,60 @@ +# CENTER header file + +define LEN_CENSTRUCT (36 + SZ_FNAME + 1) + +# centering parameters + +define AP_CENTERFUNCTION Memi[$1] # Centering algorithm +define AP_CAPERT Memr[P2R($1+1)] # Centering box half-width +define AP_CTHRESHOLD Memr[P2R($1+2)] # Threshold above cdatalimit +define AP_MAXSHIFT Memr[P2R($1+3)] # Maximum center shift +define AP_MINSNRATIO Memr[P2R($1+4)] # Minimum s/n ratio +define AP_CLEAN Memi[$1+5] # Clean before centering +define AP_RCLEAN Memr[P2R($1+6)] # Cleaning radius +define AP_RCLIP Memr[P2R($1+7)] # Clipping radius +define AP_SIGMACLEAN Memr[P2R($1+8)] # Sky sigma for cleaning +define AP_CMAXITER Memi[$1+9] # Maximum number of iterations + +# centering buffers + +define AP_CTRPIX Memi[$1+10] # Pointer to pixels +define AP_XCTRPIX Memi[$1+11] # Pointer to x coords (not used) +define AP_YCTRPIX Memi[$1+12] # Pointer to y coords (not used) +define AP_NCTRPIX Memi[$1+13] # Number of pixels (not used) +define AP_LENCTRBUF Memi[$1+14] # Centering buffer sz (not used) +define AP_CXCUR Memr[P2R($1+15)] # Centering buffer x center +define AP_CYCUR Memr[P2R($1+16)] # Centering buffer y center +define AP_CXC Memr[P2R($1+17)] # X center of subraster +define AP_CYC Memr[P2R($1+18)] # Y center of subraster +define AP_CNX Memi[$1+19] # Y dimension of subraster +define AP_CNY Memi[$1+20] # Y dimension of subraster + +# center fitting output + +define AP_OXINIT Memr[P2R($1+21)] # initial output x center +define AP_OYINIT Memr[P2R($1+22)] # initial output y center +define AP_XCENTER Memr[P2R($1+23)] # computed x center +define AP_YCENTER Memr[P2R($1+24)] # computed y center +define AP_OXCENTER Memr[P2R($1+25)] # computed output x center +define AP_OYCENTER Memr[P2R($1+26)] # computed output y center +define AP_XSHIFT Memr[P2R($1+27)] # total x shift +define AP_YSHIFT Memr[P2R($1+28)] # total y shift +define AP_OXSHIFT Memr[P2R($1+29)] # total output x shift +define AP_OYSHIFT Memr[P2R($1+30)] # total output y shift +define AP_XERR Memr[P2R($1+31)] # x error +define AP_YERR Memr[P2R($1+32)] # y error +define AP_CDATALIMIT Memr[P2R($1+33)] # min (max) of subraster +define AP_CSTRING Memc[P2C($1+34)]# centering algorithm id + +# default setup values for centering parameters + +define DEF_CENTERFUNCTION AP_CENTROID1D +define DEF_CAPERT 2.5 +define DEF_CTHRESHOLD 0.0 +define DEF_MINSNRATIO 1.0 +define DEF_CMAXITER 10 +define DEF_MAXSHIFT 1.0 +define DEF_CLEAN NO +define DEF_RCLEAN 1.0 +define DEF_RCLIP 2.0 +define DEF_CLEANSIGMA 3.0 diff --git a/noao/digiphot/apphot/lib/display.h b/noao/digiphot/apphot/lib/display.h new file mode 100644 index 00000000..ae8ff523 --- /dev/null +++ b/noao/digiphot/apphot/lib/display.h @@ -0,0 +1,21 @@ +# APPHOT display parameters + +# display parameters (# 501 - 600) + +define MKSKY 501 +define MKCENTER 502 +define MKAPERT 503 +define MKPOLYGON 504 +define MKPSFBOX 505 +define RADPLOTS 506 +define MKDETECTIONS 507 + +# display parameters + +define KY_MKSKY "mksky" +define KY_MKCENTER "mkcenter" +define KY_MKAPERT "mkapert" +define KY_MKPOLYGON "mkpolygon" +define KY_MKPSFBOX "mkbox" +define KY_RADPLOTS "radplots" +define KY_MKDETECTIONS "mkdetections" diff --git a/noao/digiphot/apphot/lib/displaydef.h b/noao/digiphot/apphot/lib/displaydef.h new file mode 100644 index 00000000..8add188d --- /dev/null +++ b/noao/digiphot/apphot/lib/displaydef.h @@ -0,0 +1,23 @@ +# APPHOT display structure + +define LEN_DISPLAYSTRUCT 10 + +# display parameters + +define AP_MKSKY Memi[$1] # Mark sky circles +define AP_MKCENTER Memi[$1+1] # Mark center circles +define AP_MKAPERT Memi[$1+2] # Mark aperture circles +define AP_MKPOLYGON Memi[$1+3] # Mark polygon +define AP_MKPSFBOX Memi[$1+4] # Mark psf fitting box +define AP_RADPLOTS Memi[$1+5] # Make radial plots +define AP_MKDETECTIONS Memi[$1+6] # Mark detected stars + +# default values for the display parameters + +define DEF_MKSKY NO +define DEF_MKCENTER NO +define DEF_MKAPERT NO +define DEF_MKPOLYGON NO +define DEF_MKPSFBOX NO +define DEF_RADPLOTS NO +define DEF_MKDETECTIONS NO diff --git a/noao/digiphot/apphot/lib/find.h b/noao/digiphot/apphot/lib/find.h new file mode 100644 index 00000000..b5e3760b --- /dev/null +++ b/noao/digiphot/apphot/lib/find.h @@ -0,0 +1,75 @@ +# Find header file + +# find parameters (# 701 - 800) + +define RATIO 701 +define THETA 702 +define NSIGMA 703 +define SHARPLO 704 +define SHARPHI 705 +define ROUNDLO 706 +define ROUNDHI 707 +define THRESHOLD 708 + +# find keyword units + +define KY_RATIO "ratio" +define KY_THETA "theta" +define KY_NSIGMA "nsigma" +define KY_SHARPLO "sharplo" +define KY_SHARPHI "sharphi" +define KY_ROUNDLO "roundlo" +define KY_ROUNDHI "roundhi" +define KY_THRESHOLD "threshold" + +# find parameter units + +#define UN_RATIO "number" +#define UN_THETA "degrees" +#define UN_NSIGMA "sigma" +#define UN_SHARPLO "number" +#define UN_SHARPHI "number" +#define UN_ROUNDLO "number" +#define UN_ROUNDHI "number" +#define UN_THRESHOLD "sigma" + +define UN_FNUMBER "number" +define UN_FSIGMA "sigma" +define UN_FDEGREES "degrees" + +# define daofind commands + +define FSHOWARGS "|data|find|" +define FCMDS "|nsigma|ratio|sharplo|sharphi|roundlo|roundhi|mkdetections|\ +theta|threshold|" + +# define daofind command strings + +define FCMD_NSIGMA 1 +define FCMD_RATIO 2 +define FCMD_SHARPLO 3 +define FCMD_SHARPHI 4 +define FCMD_ROUNDLO 5 +define FCMD_ROUNDHI 6 +define FCMD_MKDETECTIONS 7 +define FCMD_THETA 8 +define FCMD_THRESHOLD 9 + +define FCMD_DATA 1 +define FCMD_FIND 2 + + +# define the gaussian sums structure + +define LEN_GAUSS 10 + +define GAUSS_SUMG 1 +define GAUSS_SUMGSQ 2 +define GAUSS_PIXELS 3 +define GAUSS_DENOM 4 +define GAUSS_SGOP 5 + +# miscellaneous + +define FWHM_TO_SIGMA 0.42467 +define RMIN 2.001 diff --git a/noao/digiphot/apphot/lib/finddef.h b/noao/digiphot/apphot/lib/finddef.h new file mode 100644 index 00000000..4ea9e99d --- /dev/null +++ b/noao/digiphot/apphot/lib/finddef.h @@ -0,0 +1,26 @@ +# FIND header file + +define LEN_FIND (10) + +# find model parameters + +define AP_RATIO Memr[P2R($1)] # Gaussian axis ratio +define AP_THETA Memr[P2R($1+1)] # Gaussian position angle +define AP_NSIGMA Memr[P2R($1+2)] # Size of convolution kernel +define AP_SHARPLO Memr[P2R($1+3)] # Lower sharpness bound +define AP_SHARPHI Memr[P2R($1+4)] # Upper sharpness bound +define AP_ROUNDLO Memr[P2R($1+5)] # Lower roundness bound +define AP_ROUNDHI Memr[P2R($1+6)] # Higher roundness bound +define AP_THRESHOLD Memr[P2R($1+7)] # Threshold in sigma for detection + + +# noise model defaults + +define DEF_RATIO 1.0 +define DEF_THETA 0.0 +define DEF_NSIGMA 1.5 +define DEF_SHARPLO 0.2 +define DEF_SHARPHI 1.0 +define DEF_ROUNDLO -1.0 +define DEF_ROUNDHI 1.0 +define DEF_THRESHOLD 0.0 diff --git a/noao/digiphot/apphot/lib/fitpsf.h b/noao/digiphot/apphot/lib/fitpsf.h new file mode 100644 index 00000000..5aa5f04c --- /dev/null +++ b/noao/digiphot/apphot/lib/fitpsf.h @@ -0,0 +1,72 @@ +# FITPSF header file + +# fitpsf functions + +define AP_RADGAUSS 1 # Radial Gaussian +define AP_ELLGAUSS 2 # Elliptical Gaussian +define AP_MOMENTS 3 # Moment analysis + +# fitpsf errors (# 401 - 500) + +define AP_OK 0 # no error +define AP_NOPSFAREA 401 # No pixels for PSF +define AP_PSF_OUTOFBOUNDS 402 # PSF aperture extends oob +define AP_NPSF_TOO_SMALL 403 # Too few PSF points +define AP_PSF_SINGULAR 404 # Fit is singular +define AP_PSF_NOCONVERGE 405 # Solution does not converge + +# fitpsf parameters (# 401 - 500) + +define PSFUNCTION 401 +define MAXNPARS 402 +define PK2 403 +define PMAXITER 404 +define PSFAPERT 405 +define NPARS 406 +define PARS 407 +define PERRS 408 +define PNREJECT 409 +define PFXCUR 410 +define PFYCUR 411 +define OPFXCUR 412 +define OPFYCUR 413 +define PSFSTRING 414 + +# define fitpsf keywords + +define KY_PSFUNCTION "function" +define KY_PSFAPERT "box" +define KY_PK2 "kreject" +define KY_PMAXITER "maxiter" +define KY_PNREJECT "nreject" +define KY_PSFSTRING "function" + +# define fitpsf units + +#define UN_PSFUNCTION "model" +#define UN_PSFAPERT "scaleunit" +#define UN_PK2 "sigma" +#define UN_PMAXITER "number" +#define UN_PNREJECT "number" +#define UN_PSFSTRING "model" + +define UN_PSFSCALEUNIT "scaleunit" +define UN_PSFNUMBER "number" +define UN_PSFMODEL "model" +define UN_PSFSIGMA "sigma" + +# fitpsf string constants + +define PFSHOWARGS "|data|fit|" +define PSFFUNCS "|radgauss|elgauss|moments|" +define PSFCMDS "|function|box|kreject|maxiter|nreject|mkbox|" + +define PFCMD_DATA 1 +define PFCMD_FIT 2 + +define PFCMD_FUNCTION 1 +define PFCMD_BOX 2 +define PFCMD_KREJECT 3 +define PFCMD_MAXITER 4 +define PFCMD_NREJECT 5 +define PFCMD_MKBOX 6 diff --git a/noao/digiphot/apphot/lib/fitpsfdef.h b/noao/digiphot/apphot/lib/fitpsfdef.h new file mode 100644 index 00000000..bbd88ad0 --- /dev/null +++ b/noao/digiphot/apphot/lib/fitpsfdef.h @@ -0,0 +1,43 @@ +# FITPSF header file + +define LEN_PSFSTRUCT (25 + SZ_FNAME + 1) + +# fitpsf parameters + +define AP_PSFUNCTION Memi[$1] # PSF function +define AP_PSFNPARS Memi[$1+1] # Number of parameters +define AP_MAXNPARS Memi[$1+2] # Maximum number of parameters +define AP_PSFAPERT Memr[P2R($1+3)] # Half-width of fitting box +define AP_PMAXITER Memi[$1+4] # Maximum number of iterations +define AP_PK2 Memr[P2R($1+5)] # Rejection limit in sigma +define AP_PNREJECT Memi[$1+6] # Maximum number of rejections + +# fitpsf buffers + +define AP_PSFPIX Memi[$1+7] # Pointer to pixels +define AP_PSFXPIX Memi[$1+8] # X coordinates array (not used) +define AP_PSFYPIX Memi[$1+9] # Y coordinates array (not used) +define AP_NPSFPIX Memi[$1+10] # Number of pixels (not used) +define AP_LENPSFBUF Memi[$1+11] # Length of pixel buffer (not used) +define AP_PXC Memr[P2R($1+12)]# X center of subraster +define AP_PYC Memr[P2R($1+13)]# Y center of subraster +define AP_PNX Memi[$1+14] # X dimension of subraster +define AP_PNY Memi[$1+15] # Y dimension of subraster +define AP_PFXCUR Memr[P2R($1+16)]# X initial position +define AP_PFYCUR Memr[P2R($1+17)]# Y initial position +define AP_OPFXCUR Memr[P2R($1+18)]# X initial position +define AP_OPFYCUR Memr[P2R($1+19)]# Y initial position + +# fitpsf answers + +define AP_PPARS Memi[$1+20] # fitted parameters +define AP_PPERRS Memi[$1+21] # errors in the parameters +define AP_PSFSTRING Memc[P2C($1+22)] # functions string + +# default fitpsf parameters + +define DEF_MAXNPARS 10 +define DEF_PSFUNCTION AP_RADGAUSS +define DEF_PMAXITER 50 +define DEF_PK2 3.0 +define DEF_PNREJECT 1 diff --git a/noao/digiphot/apphot/lib/fitsky.h b/noao/digiphot/apphot/lib/fitsky.h new file mode 100644 index 00000000..b4cedaea --- /dev/null +++ b/noao/digiphot/apphot/lib/fitsky.h @@ -0,0 +1,128 @@ +# FITSKY definitions + +# define the sky fitting algorithms + +define AP_CONSTANT 1 # Use a constant sky +define AP_MODE 2 # Compute the mode of the sky pixels +define AP_CENTROID 3 # Compute the peak of the histogram +define AP_SKYFILE 4 # Get values from a file +define AP_HISTPLOT 5 # Mark the sky on a histogram plot +define AP_MEDIAN 6 # Take median of sky pixels +define AP_RADPLOT 7 # Mark sky on radial profile plot +define AP_GAUSS 8 # Non-linear fit to a Gaussian +define AP_OFILT 9 # Optimal filtering +define AP_CROSSCOR 10 # Cross correlation method +define AP_MEAN 11 # Compute the mean of the sky pixels + +# define sky fitting errors (# 201 - 300) + +define AP_OK 0 # No error +define AP_NOSKYAREA 201 # Width of the annulus is <= 0.0 pixels +define AP_SKY_OUTOFBOUNDS 202 # Sky annulus out of bounds +define AP_NOHISTOGRAM 203 # Cannot make a histogram +define AP_FLAT_HIST 204 # Histogram is flat or concave +define AP_NSKY_TOO_SMALL 205 # Too few points for fit +define AP_SKY_SINGULAR 206 # Fit is singular +define AP_SKY_NOCONVERGE 207 # Solution does not converge +define AP_NOGRAPHICS 208 # NULL graphics pointer +define AP_NOSKYFILE 209 # NULL sky file descriptor +define AP_EOFSKYFILE 210 # End of sky file +define AP_BADSKYSCAN 211 # Incomplete scan of sky file +define AP_BADPARAMS 212 # Non-physical parameters + +# sky fitting parameters (# 201 - 300) + +define SKYFUNCTION 201 +define ANNULUS 202 +define DANNULUS 203 +define SKY_BACKGROUND 204 +define K1 205 +define BINSIZE 206 +define SMOOTH 207 +define SMAXITER 208 +define SLOCLIP 209 +define SHICLIP 210 +define SNREJECT 211 +define SLOREJECT 212 +define SHIREJECT 213 +define RGROW 214 +define SKY_MODE 215 +define SKY_SIGMA 216 +define SKY_SKEW 217 +define NSKY 218 +define NSKY_REJECT 219 +define SXCUR 220 +define SYCUR 221 +define OSXCUR 222 +define OSYCUR 223 +define SSTRING 224 + +# define sky fitting keywords + +define KY_SSTRING "salgorithm" +define KY_ANNULUS "annulus" +define KY_DANNULUS "dannulus" +define KY_SKY_BACKGROUND "skyvalue" +define KY_K1 "khist" +define KY_BINSIZE "binsize" +define KY_SMOOTH "smooth" +define KY_SMAXITER "smaxiter" +define KY_SLOCLIP "sloclip" +define KY_SHICLIP "shiclip" +define KY_SNREJECT "snreject" +define KY_SLOREJECT "sloreject" +define KY_SHIREJECT "shireject" +define KY_RGROW "rgrow" + +# define sky fitting units strings + +#define UN_SSTRING "algorithm" +#define UN_ANNULUS "scaleunit" +#define UN_DANNULUS "scaleunit" +#define UN_SKY_BACKGROUND "counts" +#define UN_K1 "sigma" +#define UN_BINSIZE "sigma" +#define UN_SMOOTH "switch" +#define UN_SMAXITER "number" +#define UN_SLOCLIP "percent" +#define UN_SHICLIP "percent" +#define UN_SNREJECT "number" +#define UN_SLOREJECT "sigma" +#define UN_SHIREJECT "sigma" +#define UN_RGROW "scaleunit" + +define UN_SALGORITHM "algorithm" +define UN_SSCALEUNIT "scaleunit" +define UN_SSIGMA "sigma" +define UN_SNUMBER "number" +define UN_SPERCENT "percent" +define UN_SCOUNTS "counts" +define UN_SSWITCH "switch" + +# fitsky string definitions + +define SSHOWARGS "|data|sky|" +define SFUNCS "|constant|mode|centroid|file|histplot|median|\ +radplot|gauss|ofilter|crosscor|mean|" +define SCMDS "|annulus|dannulus|salgorithm|khist|sloreject|\ +shireject|smaxiter|binsize|smooth|rgrow|snreject|skyvalue|mksky|sloclip|\ +shiclip|" + +define SCMD_ANNULUS 1 +define SCMD_DANNULUS 2 +define SCMD_SALGORITHM 3 +define SCMD_KHIST 4 +define SCMD_SLOREJECT 5 +define SCMD_SHIREJECT 6 +define SCMD_SMAXITER 7 +define SCMD_BINSIZE 8 +define SCMD_SMOOTH 9 +define SCMD_RGROW 10 +define SCMD_SNREJECT 11 +define SCMD_SKYVALUE 12 +define SCMD_MKSKY 13 +define SCMD_SLOCLIP 14 +define SCMD_SHICLIP 15 + +define SCMD_DATA 1 +define SCMD_SKY 2 diff --git a/noao/digiphot/apphot/lib/fitskydef.h b/noao/digiphot/apphot/lib/fitskydef.h new file mode 100644 index 00000000..f768851f --- /dev/null +++ b/noao/digiphot/apphot/lib/fitskydef.h @@ -0,0 +1,65 @@ +# FITSKY structure + +define LEN_SKYSTRUCT (36 + SZ_FNAME + 1) + +# sky fitting parameters + +define AP_SKYFUNCTION Memi[$1] # sky fitting algorithm +define AP_ANNULUS Memr[P2R($1+1)] # inner radius of annulus in scale +define AP_DANNULUS Memr[P2R($1+2)] # annulus width in scale +define AP_SKYBACKGROUND Memr[P2R($1+3)] # user defined sky value +define AP_K1 Memr[P2R($1+4)] # K-sigma histogram rejection +define AP_BINSIZE Memr[P2R($1+5)] # histogram binsize in sky sigma +define AP_SMOOTH Memi[$1+6] # Smooth histogram ? +define AP_SMAXITER Memi[$1+7] # maximum number of iterations +define AP_SLOCLIP Memr[P2R($1+8)] # lower clipping percentile +define AP_SHICLIP Memr[P2R($1+9)] # lower clipping percentile +define AP_SNREJECT Memi[$1+10] # maximum number of rejection cycles +define AP_SLOREJECT Memr[P2R($1+11)] # lower K-sigma rejection for pixels +define AP_SHIREJECT Memr[P2R($1+12)] # higher K-sigma rejection for pixels +define AP_RGROW Memr[P2R($1+13)] # region growing radius in scale + +# sky buffer definitions + +define AP_SKYPIX Memi[$1+14] # pointer to sky pixels +define AP_INDEX Memi[$1+15] # pointer to ordering array +define AP_COORDS Memi[$1+16] # pointer to sky coordinates array +define AP_SWGT Memi[$1+17] # pointer to sky weights +define AP_NSKYPIX Memi[$1+18] # number of sky pixels +define AP_NBADSKYPIX Memi[$1+19] # number of bad sky pixels +define AP_LENSKYBUF Memi[$1+20] # length of sky buffers +define AP_SXCUR Memr[P2R($1+21)] # x center of sky annulus +define AP_SYCUR Memr[P2R($1+22)] # y center of sky annulus +define AP_SXC Memr[P2R($1+23)] # x center of sky subraster +define AP_SYC Memr[P2R($1+24)] # y center of sky subraster +define AP_SNX Memi[$1+25] # x dimension of sky subraster +define AP_SNY Memi[$1+26] # y dimension of sky subraster + +# fitsky output + +define AP_OSXCUR Memr[P2R($1+27)] # x center of sky annulus +define AP_OSYCUR Memr[P2R($1+28)] # y center of sky annulus +define AP_SKY_MODE Memr[P2R($1+29)] # computed sky value +define AP_SKY_SIG Memr[P2R($1+30)] # computed sky sigma +define AP_SKY_SKEW Memr[P2R($1+31)] # computed sky skew +define AP_NSKY Memi[$1+32] # number of sky pix +define AP_NSKY_REJECT Memi[$1+33] # number of rejected sky pix + +define AP_SSTRING Memc[P2C($1+34)] # salgorithm string + +# default setup values for sky fitting + +define DEF_SKYFUNCTION AP_MODE +define DEF_SKYVALUE 0.0 +define DEF_ANNULUS 10. +define DEF_DANNULUS 10. +define DEF_SLOCLIP 0.0 +define DEF_SHICLIP 0.0 +define DEF_SNREJECT 50 +define DEF_SLOREJECT 3.0 +define DEF_SHIREJECT 3.0 +define DEF_SMAXITER 10 +define DEF_RGROW 0.0 +define DEF_K1 3.0 +define DEF_BINSIZE 0.10 +define DEF_SMOOTH NO diff --git a/noao/digiphot/apphot/lib/noise.h b/noao/digiphot/apphot/lib/noise.h new file mode 100644 index 00000000..32ef1ed1 --- /dev/null +++ b/noao/digiphot/apphot/lib/noise.h @@ -0,0 +1,54 @@ +# Noise model header file + +# noise parameters (# 601 - 700) + +define SKYSIGMA 601 +define EPADU 603 +define NOISEFUNCTION 604 +define GAIN 605 +define NSTRING 606 +define CCDREAD 607 +define READNOISE 608 + +# noise keywords + +define KY_SKYSIGMA "sigma" +define KY_EPADU "epadu" +define KY_GAIN "gain" +define KY_NSTRING "noise" +define KY_CCDREAD "ccdread" +define KY_READNOISE "readnoise" + +# noise parameter units + +#define UN_SKYSIGMA "counts" +#define UN_EPADU "e-/adu" +#define UN_GAIN "keyword" +#define UN_NSTRING "model" +#define UN_CCDREAD "keyword" +#define UN_READNOISE "e-" + +define UN_NKEYWORD "keyword" +define UN_NCOUNTS "counts" +define UN_NELECTRONS "e-" +define UN_NMODEL "model" +define UN_NEPADU "e-/adu" + +# noise functions + +define AP_NCONSTANT 1 +define AP_NPOISSON 2 + +# noise model strings + +define NCMDS "|noise|sigma|epadu|gain|ccdread|readnoise|" +define NFUNCS "|constant|poisson|" + +# noise string cases + +define NCMD_NOISE 1 +define NCMD_SIGMA 2 +define NCMD_EPADU 3 +define NCMD_GAIN 4 +define NCMD_CCDREAD 5 +define NCMD_READNOISE 6 diff --git a/noao/digiphot/apphot/lib/noisedef.h b/noao/digiphot/apphot/lib/noisedef.h new file mode 100644 index 00000000..3d67f5ec --- /dev/null +++ b/noao/digiphot/apphot/lib/noisedef.h @@ -0,0 +1,21 @@ +# APPHOT header file + +define LEN_APNOISE (10 + 3 * SZ_FNAME + 3) + +# noise model parameters + +define AP_NOISEFUNCTION Memi[$1] # Noise function +define AP_SKYSIGMA Memr[P2R($1+2)] # Sky sigma in counts +define AP_EPADU Memr[P2R($1+3)] # Photons per adu +define AP_READNOISE Memr[P2R($1+4)] # CCD readnoise in adu +define AP_GAIN Memc[P2C($1+6)] # Gain keyword +define AP_NSTRING Memc[P2C($1+6+SZ_FNAME+1)] # Noise model +define AP_CCDREAD Memc[P2C($1+6+2*SZ_FNAME+2)] # Readnoise + +# noise model defaults + +define DEF_SKYSIGMA INDEFR +define DEF_EPADU 1.0 +define DEF_CCDREAD "" +define DEF_GAIN "" +define DEF_READNOISE INDEFR diff --git a/noao/digiphot/apphot/lib/phot.h b/noao/digiphot/apphot/lib/phot.h new file mode 100644 index 00000000..ca9430f5 --- /dev/null +++ b/noao/digiphot/apphot/lib/phot.h @@ -0,0 +1,86 @@ +# APPHOT header file + +# phot errors (# 301 - 400) + +define AP_OK 0 # no error +define AP_APERT_NOAPERT 301 # no aperture area +define AP_APERT_OUTOFBOUNDS 302 # 1 or more apertures out of bounds +define AP_APERT_NOSKYMODE 303 # INDEF valued sky +define AP_APERT_NEGMAG 304 # 0 or -ve magnitude +define AP_APERT_BADDATA 305 # bad pixels in aperture + +# phot parameters and answers (# 301 - 400) + +define ZMAG 301 +define APERTS 302 +define NAPERTS 303 +define MAGS 304 +define MAGERRS 305 +define PXCUR 306 +define PYCUR 307 +define OPXCUR 308 +define OPYCUR 309 +define AREAS 310 +define SUMS 311 +define PWEIGHTS 312 +define PWSTRING 313 +define APSTRING 314 + +# define the phot keywords + +define KY_ZMAG "zmag" +define KY_PWSTRING "weighting" +define KY_APERTS "apertures" + +# define the phot units + +#define UN_ZMAG "zeropoint" +#define UN_PWSTRING "model" +#define UN_APERTS "scaleunit" + +define UN_PZMAG "zeropoint" +define UN_PMODEL "model" +define UN_PSCALEUNIT "scaleunit" + +# define the weighting functions + +define AP_PWCONSTANT 1 # uniform weighting +define AP_PWCONE 2 # a cone of given fwhm is used +define AP_PWGAUSS 3 # a Gaussian of given fwhm is used + +# phot strings + +define PCMDS "|apertures|zmag|mkapert|weighting|" +define PSHOWARGS "|center|sky|phot|data|" +define PWFUNCS "|constant|cone|gauss|" +define QCMDS "|show|cboxwidth|annulus|dannulus|apertures|zmag|epadu|exposure|radplots|image|output|coords|airmass|filter|obstime|" + +define PCMD_APERTURES 1 +define PCMD_ZMAG 2 +define PCMD_MKAPERT 3 +define PCMD_WEIGHTING 4 + +define PCMD_CENTER 1 +define PCMD_SKY 2 +define PCMD_PHOT 3 +define PCMD_DATA 4 + +define QCMD_SHOW 1 +define QCMD_CBOXWIDTH 2 +define QCMD_ANNULUS 3 +define QCMD_DANNULUS 4 +define QCMD_APERTURES 5 +define QCMD_ZMAG 6 +define QCMD_EPADU 7 +define QCMD_EXPOSURE 8 +define QCMD_RADPLOTS 9 +define QCMD_IMAGE 10 +define QCMD_OUTPUT 11 +define QCMD_COORDS 12 +define QCMD_AIRMASS 13 +define QCMD_FILTER 14 +define QCMD_OBSTIME 15 + +# miscellaneous + +define MAX_NAPERTS 100 diff --git a/noao/digiphot/apphot/lib/photdef.h b/noao/digiphot/apphot/lib/photdef.h new file mode 100644 index 00000000..3d02f11a --- /dev/null +++ b/noao/digiphot/apphot/lib/photdef.h @@ -0,0 +1,43 @@ +# PHOT header file + +define LEN_PHOTSTRUCT (30 + SZ_FNAME + SZ_LINE + 2) + +# photmetry aperture parameters + +define AP_NAPERTS Memi[$1] # Number of apertures +define AP_PXCUR Memr[P2R($1+1)] # X aperture center +define AP_PYCUR Memr[P2R($1+2)] # Y aperture center +define AP_NMAXAP Memi[$1+3] # Maximum number of apertures +define AP_NMINAP Memi[$1+4] # Minimum number of apertures +define AP_APERTS Memi[$1+5] # Pointer to aperture array +define AP_APIX Memi[$1+6] # Pointer to pixels +define AP_XAPIX Memi[$1+7] # Pointer to x coords array (not used) +define AP_YAPIX Memi[$1+8] # Pointer to y coords array (not used) +define AP_NAPIX Memi[$1+9] # Number of pixels (not used) +define AP_LENABUF Memi[$1+10] # Size of pixels buffer (not used) +define AP_AXC Memr[P2R($1+11)] # X center of subraster +define AP_AYC Memr[P2R($1+12)] # X center of subraster +define AP_ANX Memi[$1+13] # X dimension of subraster +define AP_ANY Memi[$1+14] # Y dimension of subraster +define AP_OPXCUR Memr[P2R($1+15)] # X aperture center +define AP_OPYCUR Memr[P2R($1+16)] # Y aperture center + +# photometry output + +define AP_MAGS Memi[$1+17] # Pointer to magnitude array +define AP_MAGERRS Memi[$1+18] # Pointer to mag errors array +define AP_AREA Memi[$1+19] # Pointer to areas array +define AP_SUMS Memi[$1+20] # Pointer to aperture sums array + +# photometry parameters + +define AP_ZMAG Memr[P2R($1+21)] # Zero point of magnitude scale +define AP_PWEIGHTS Memi[$1+22] # Weighting function for ophot +define AP_PWSTRING Memc[P2C($1+24)] # Weights string +define AP_APSTRING Memc[P2C($1+24+SZ_FNAME+1)] # Apertures string + +# phot default defintions + +define DEF_ZMAG 25.0 +define DEF_APERTS "3.0" +define DEF_PWEIGHTS AP_PWCONSTANT diff --git a/noao/digiphot/apphot/lib/polyphot.h b/noao/digiphot/apphot/lib/polyphot.h new file mode 100644 index 00000000..d41751c2 --- /dev/null +++ b/noao/digiphot/apphot/lib/polyphot.h @@ -0,0 +1,63 @@ +# POLYPHOT header file + +# polyphot error codes (# 801 - 900) + +define PY_NOPOLYGON 801 +define PY_OUTOFBOUNDS 802 +define PY_NOPIX 803 +define PY_NOSKYMODE 804 +define PY_BADDATA 805 +define PY_OK 0 + +# polyphot parameters and answers (# 801 - 900) + +define PYXMEAN 801 +define PYYMEAN 802 +define PYCX 803 +define PYCY 804 +define OPYXMEAN 805 +define OPYYMEAN 806 +define OPYCX 807 +define OPYCY 808 +define PYFLUX 809 +define PYNPIX 810 +define PYNVER 811 +define PYMINRAD 812 +define PYX 813 +define PYY 814 +define PYZMAG 815 +define PYMAG 816 +define PYMAGERR 817 +define PYNAME 818 +define PYROOT 819 +define PYBADPIX 820 + +# polyphot keywords + +define KY_PYZMAG "zmag" +define KY_PYNAME "polyfile" + +# polyphot units + +define UN_PYZMAG "zeropoint" + +# miscellaneous polyphot definitions + +define MAX_NVERTICES 900 +define NEXT_POLYGON 0 +define NEXT_OBJECT 1 +define THIS_OBJECT 2 + +# polyphot strings + +define PYSHOWARGS "|center|sky|phot|data|" +define PYCMDS "|zmag|mkpolygon|polygons|" + +define PLCMD_CENTER 1 +define PLCMD_SKY 2 +define PLCMD_PHOT 3 +define PLCMD_DATA 4 + +define PLCMD_ZMAG 1 +define PLCMD_MKPOLYGON 2 +define PLCMD_POLYGONS 3 diff --git a/noao/digiphot/apphot/lib/polyphotdef.h b/noao/digiphot/apphot/lib/polyphotdef.h new file mode 100644 index 00000000..4b354bfc --- /dev/null +++ b/noao/digiphot/apphot/lib/polyphotdef.h @@ -0,0 +1,37 @@ +# POLYPHOT header file + +define LEN_PYSTRUCT (25 + 2 * SZ_FNAME + 2) + +# polyphot parameters + +define AP_PYZMAG Memr[P2R($1)] # Zero point of mag scale + +# polygon parameters + +define AP_PYXMEAN Memr[P2R($1+1)] # Original mean X of polygon +define AP_PYYMEAN Memr[P2R($1+2)] # Original mean Y of polygon +define AP_PYCX Memr[P2R($1+3)] # Current mean X of polygon +define AP_PYCY Memr[P2R($1+4)] # Current mean Y of polygon +define AP_PYX Memr[P2R($1+5)] # Previous mean X of polygon +define AP_PYY Memr[P2R($1+6)] # Previous mean Y of polygon +define AP_PYNVER Memi[$1+7] # Number of vertices +define AP_PYMINRAD Memr[P2R($1+8)] # Minimum sky fitting radius in scale +define AP_OPYXMEAN Memr[P2R($1+9)] # Original output mean X of polygon +define AP_OPYYMEAN Memr[P2R($1+10)]# Original output mean Y of polygon +define AP_OPYCX Memr[P2R($1+11)]# Current output mean X of polygon +define AP_OPYCY Memr[P2R($1+12)]# Current output mean Y of polygon + +# polyphot answers + +define AP_PYBADPIX Memi[$1+13] # Are there bad pixels ? +define AP_PYFLUX Memd[P2D($1+14)]# Flux +define AP_PYNPIX Memd[P2D($1+16)]# Polygon area +define AP_PYMAG Memr[P2R($1+18)]# Magnitude +define AP_PYMAGERR Memr[P2R($1+19)]# Magnitude error + +define AP_PYNAME Memc[P2C($1+21)]# Polygons file name +define AP_PYROOT Memc[P2C($1+21+SZ_FNAME+1)]# Polygons file name + +# polyphot defaults + +define DEF_PYZMAG 25.0 diff --git a/noao/digiphot/apphot/lib/radprof.h b/noao/digiphot/apphot/lib/radprof.h new file mode 100644 index 00000000..56572c50 --- /dev/null +++ b/noao/digiphot/apphot/lib/radprof.h @@ -0,0 +1,66 @@ +# RADPROF header file + +# radprof error codes (# 901 - 1000) + +define AP_OK 0 +define AP_RP_NOPROFILE 901 +define AP_RP_OUTOFBOUNDS 902 +define AP_RP_NPTS_TOO_SMALL 903 +define AP_RP_SINGULAR 904 +define AP_RP_NOSKYMODE 905 + +# radprof fit parameters and answers (# 901 - 1000) + +define RPXCUR 901 +define RPYCUR 902 +define ORPXCUR 903 +define ORPYCUR 904 +define RPRADIUS 905 +define RPSTEP 906 +define RPKSIGMA 907 +define RPNREJECT 908 +define RPORDER 909 +define INORM 910 +define TNORM 911 +define DNORM 912 +define RPFWHM 913 +define RPNPTS 914 +define RPNDATA 915 +define RPNDATAREJ 916 + +# define radprof keywords + +define KY_RPRADIUS "radius" +define KY_RPSTEP "stepsize" +define KY_RPORDER "order" +define KY_RPKSIGMA "kreject" +define KY_RPNREJECT "nreject" + +# define radprof units + +#define UN_RPRADIUS "scaleunit" +#define UN_RPSTEP "scaleunit" +#define UN_RPORDER "number" +#define UN_RPKSIGMA "sigma" +#define UN_RPNREJECT "number" + +define UN_RSCALEUNIT "scaleunit" +define UN_RNUMBER "number" +define UN_RSIGMA "sigma" + +# radprof strings + +define RPSHOWARGS "|center|sky|phot|fit|data|" +define RPCMDS "|radius|stepsize|order|kreject|nreject|" + +define RCMD_CENTER 1 +define RCMD_SKY 2 +define RCMD_PHOT 3 +define RCMD_FIT 4 +define RCMD_DATA 5 + +define RCMD_RADIUS 1 +define RCMD_STEPSIZE 2 +define RCMD_ORDER 3 +define RCMD_KREJECT 4 +define RCMD_NREJECT 5 diff --git a/noao/digiphot/apphot/lib/radprofdef.h b/noao/digiphot/apphot/lib/radprofdef.h new file mode 100644 index 00000000..1fcb3dcc --- /dev/null +++ b/noao/digiphot/apphot/lib/radprofdef.h @@ -0,0 +1,38 @@ +# RADPROF header file + +define LEN_RPSTRUCT 30 + +# Radprof data parameters + +define AP_RPXCUR Memr[P2R($1)] # X image center in pixels +define AP_RPYCUR Memr[P2R($1+1)] # Y image center in pixels +define AP_RPIX Memi[$1+2] # Pointer to radial profile pixels +define AP_RPXC Memr[P2R($1+3)] # X center of subraster +define AP_RPYC Memr[P2R($1+4)] # Y center of subraster +define AP_RPNX Memi[$1+5] # Subraster length in x +define AP_RPNY Memi[$1+6] # Subraster length in y +define AP_ORPXCUR Memr[P2R($1+7)] # output system X image center in pixels +define AP_ORPYCUR Memr[P2R($1+8)] # output system Y image center in pixels + +# Radprof fit parameters + +define AP_RPRADIUS Memr[P2R($1+9)] # Radprof radius in scale +define AP_RPSTEP Memr[P2R($1+10)]# Radprof step size in scale +define AP_RPORDER Memi[$1+11] # Order of the spline3 fit +define AP_RPKSIGMA Memr[P2R($1+12)]# Radprof K-rejection criterion in sigma +define AP_RPNREJECT Memi[$1+13] # Maximum number of rejection cycles + +# Radprof answers + +define AP_RPNPTS Memi[$1+14] # Number of points in radial profile +define AP_RPDIST Memi[$1+15] # Pointer to radial distance array +define AP_INTENSITY Memi[$1+16] # Pointer to fitted intensity array +define AP_DINTENSITY Memi[$1+17] # Pointer incremental intensity array +define AP_TINTENSITY Memi[$1+18] # Pointer to total intensity array +define AP_INORM Memr[P2R($1+19)]# Normalization for intensity profile +define AP_TINORM Memr[P2R($1+20)]# Normalization for total intensity +define AP_DNORM Memr[P2R($1+21)]# Normalization for incremental inten +define AP_RPFWHM Memr[P2R($1+22)]# Fitted profile FWHM +define AP_RPNDATA Memi[$1+23] # Number of data points +define AP_RPNDATAREJ Memi[$1+24] # Number of points rejected from fit +define AP_RPNBAD Memi[$1+25] # Number of bad pixel points diff --git a/noao/digiphot/apphot/mkpkg b/noao/digiphot/apphot/mkpkg new file mode 100644 index 00000000..861aeea4 --- /dev/null +++ b/noao/digiphot/apphot/mkpkg @@ -0,0 +1,39 @@ +# Make the APPHOT package + +$call relink +$exit + +update: + $call relink + $call install + ; + +relink: + $set LIBS = "-lnlfit -liminterp -lcurfit -lds -lxtools" + $update libpkg.a + $omake x_apphot.x + $link x_apphot.o libpkg.a $(LIBS) -o xx_apphot.e + ; + +linkonly: + $set LIBS = "-lnlfit -liminterp -lcurfit -lds -lxtools" + $link x_apphot.o libpkg.a $(LIBS) -o xx_apphot.e + $call install + ; + +install: + $move xx_apphot.e noaobin$x_apphot.e + ; + +libpkg.a: + @aplib + @aputil + @center + @daofind + @fitpsf + @fitsky + @phot + @polyphot + @radprof + @wphot + ; diff --git a/noao/digiphot/apphot/pexamine.par b/noao/digiphot/apphot/pexamine.par new file mode 100644 index 00000000..809e2943 --- /dev/null +++ b/noao/digiphot/apphot/pexamine.par @@ -0,0 +1,20 @@ +# The PEXAMINE task parameter set + +input,s,a,,,,"Name of the input catalog" +output,s,a,"",,,"Name of the edited output catalog" +image,s,a,"",,,Name of the image corresponding to the input catalog +deletions,s,h,"",,,"Name of the output catalog for deleted entries" +photcolumns,s,h,"apphot",,,"Names of the standard photometry columns" +xcolumn,s,h,mag,,,"Catalog column which is the X axis of X-Y plot" +ycolumn,s,h,merr,,,"Catalog column which is the Y axis of X-Y plot" +hcolumn,s,h,mag,,,"Catalog column which is to be binned" +xposcolumn,s,h,"xcenter",,,"Name of the x coordinate column" +yposcolumn,s,h,"ycenter",,,"Name of the y coordinate column" +usercolumns,s,h,"",,,"Names of additional user selected columns" +first_star,i,h,1,1,,First star in the catalog to load +max_nstars,i,h,5000,1,,Maximum number of stars to load +match_radius,r,h,2.0,,,Matching radius for positional coincidence on display +graphics,s,h,"stdgraph",,,The graphics device +use_display,b,h,yes,,,Use the image display ? +icommands,*imcur,h,"",,,"Image cursor: [x y wcs] key [cmd]" +gcommands,*gcur,h,"",,,"Graphics cursor: [x y wcs] key [cmd]" diff --git a/noao/digiphot/apphot/phot.par b/noao/digiphot/apphot/phot.par new file mode 100644 index 00000000..87570ac2 --- /dev/null +++ b/noao/digiphot/apphot/phot.par @@ -0,0 +1,24 @@ +# PHOT parameters + +image,f,a,,,,"The input image(s)" +skyfile,f,a,"",,,"The input sky file(s)" +coords,f,h,"",,,"The input coordinate files(s) (default: image.coo.?)" +output,f,h,"default",,,"The output photometry file(s) (default: image.mag.?)" +plotfile,f,h,"",,,"The output plots metacode file" +datapars,pset,h,"",,,"Data dependent parameters" +centerpars,pset,h,"",,,"Centering parameters" +fitskypars,pset,h,"",,,"Sky fitting parameters" +photpars,pset,h,"",,,"Photometry parameters" +interactive,b,h,yes,,,"Interactive mode ?" +radplots,b,h,no,,,"Plot the radial profiles in interactive mode ?" +icommands,*imcur,h,"",,,"Image cursor: [x y wcs] key [cmd]" +gcommands,*gcur,h,"",,,"Graphics cursor: [x y wcs] key [cmd]" +wcsin,s,h,)_.wcsin,,,"The input coordinate system (logical,tv,physical,world)" +wcsout,s,h,)_.wcsout,,,"The output coordinate system (logical,tv,physical)" +cache,b,h,)_.cache,,,"Cache the input image pixels in memory ?" +verify,b,h,)_.verify,,,"Verify critical parameters in non-interactive mode ?" +update,b,h,)_.update,,,"Update critical parameters in non-interactive mode ?" +verbose,b,h,)_.verbose,,,"Print messages in non-interactive mode ?" +graphics,s,h,)_.graphics,,,"Graphics device" +display,s,h,)_.display,,,"Display device" +mode,s,h,'ql' diff --git a/noao/digiphot/apphot/phot/apbphot.x b/noao/digiphot/apphot/phot/apbphot.x new file mode 100644 index 00000000..ea6ee325 --- /dev/null +++ b/noao/digiphot/apphot/phot/apbphot.x @@ -0,0 +1,115 @@ +include <fset.h> +include "../lib/apphot.h" +include "../lib/display.h" +include "../lib/center.h" +include "../lib/fitsky.h" + +# APBPHOT -- Procedure to compute the magnitudes for a list of objects +# interactively. + +procedure apbphot (ap, im, cl, sd, out, id, ld, gd, mgd, gid, interactive) + +pointer ap # pointer to apphot structure +pointer im # pointer to IRAF image +int cl # starlist file descriptor +int sd # sky file descriptor +int out # output file descriptor +int id, ld # sequence and list numbers +pointer gd # pointer to stdgraph stream +pointer mgd # pointer to plot metacode file +pointer gid # pointer to image display stream +int interactive # interactive pr batch mode + +int stdin, ild, radius, cier, sier, pier +pointer sp, str +real wx, wy +int fscan(), nscan(), apfitsky(), apfitcenter(), apmag(), strncmp() +int apstati() +real apstatr() + +begin + call smark (sp) + call salloc (str, SZ_FNAME, TY_CHAR) + call fstats (cl, F_FILENAME, Memc[str], SZ_FNAME) + + # Initialize + ild = ld + radius = 4 * (apstatr (ap, ANNULUS) + apstatr (ap, DANNULUS) + 1.0) * + apstatr (ap, SCALE) + call ap_imbuf (ap, radius, YES) + + # Print query. + if (strncmp ("STDIN", Memc[str], 5) == 0) { + stdin = YES + call printf ("Type object x and y coordinates (^D or ^Z to end): ") + call flush (STDOUT) + } else + stdin = NO + + # Loop over the coordinate file. + while (fscan (cl) != EOF) { + + # Get and store the coordinates. + call gargr (wx) + call gargr (wy) + if (nscan () != 2) { + if (stdin == YES) { + call printf ( + "Type object x and y coordinates (^D or ^Z to end): ") + call flush (STDOUT) + } + next + } + + + # Transform the input coordinates. + switch (apstati(ap,WCSIN)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_itol (ap, wx, wy, wx, wy, 1) + case WCS_TV: + call ap_vtol (im, wx, wy, wx, wy, 1) + default: + ; + } + call apsetr (ap, CWX, wx) + call apsetr (ap, CWY, wy) + + # Center the coordinates, fit the sky and compute magnitudes. + cier = apfitcenter (ap, im, wx, wy) + sier = apfitsky (ap, im, apstatr (ap, XCENTER), apstatr (ap, + YCENTER), sd, gd) + pier = apmag (ap, im, apstatr (ap, XCENTER), apstatr (ap, YCENTER), + apstati (ap, POSITIVE), apstatr (ap, SKY_MODE), + apstatr (ap, SKY_SIGMA), apstati (ap, NSKY)) + + # Print the results if interactive mode. + if (interactive == YES) { + call ap_qpmag (ap, cier, sier, pier) + if (gid != NULL) + call apmark (ap, gid, apstati (ap, MKCENTER), apstati (ap, + MKSKY), apstati (ap, MKAPERT)) + } + + # Write the results. + if (id == 1) + call ap_param (ap, out, "phot") + call ap_pmag (ap, out, id, ild, cier, sier, pier) + + # Make plots if mgd is enabled. + call ap_pplot (ap, im, id, mgd, YES) + + # Prepare for the next object. + id = id + 1 + ild = ild + 1 + call apsetr (ap, WX, wx) + call apsetr (ap, WY, wy) + if (stdin == YES) { + call printf ( + "Type object x and y coordinates (^Z or ^D to end): ") + call flush (STDOUT) + } + } + + call ap_imbuf (ap, 0, YES) + call sfree (sp) +end diff --git a/noao/digiphot/apphot/phot/apcomags.x b/noao/digiphot/apphot/phot/apcomags.x new file mode 100644 index 00000000..c6d15a16 --- /dev/null +++ b/noao/digiphot/apphot/phot/apcomags.x @@ -0,0 +1,118 @@ +include <mach.h> +include "../lib/noise.h" + +# APCOPMAGS -- Procedure to compute the magnitudes from the aperture sums, +# areas and sky values. + +procedure apcopmags (sums, areas, mags, magerrs, naperts, sky, sigma, nsky, + zmag, noise, padu) + +double sums[ARB] # aperture sums +double areas[ARB] # aperture areas +real mags[ARB] # output magnitudes +real magerrs[ARB] # errors in the magnitudes +int naperts # number of apertures +real sky # sky value +real sigma # sigma of the sky values +int nsky # number of sky pixels +real zmag # sky value, sigma and zero point magnitudes +int noise # noise model +real padu # photons per adu + +int i +real err1, err2, err3, err + +begin + # Compute the magnitudes and errors + do i = 1, naperts { + mags[i] = sums[i] - areas[i] * sky + if (mags[i] <= 0.0) + mags[i] = INDEFR + else { + if (IS_INDEFR(sigma)) + err1 = 0.0 + else + err1 = areas[i] * sigma ** 2 + switch (noise) { + case AP_NCONSTANT: + err2 = 0.0 + case AP_NPOISSON: + err2 = mags[i] / padu + default: + err2 = 0.0 + } + if (nsky <= 0) + err3 = 0.0 + else if (IS_INDEFR(sigma)) + err3 = 0.0 + else + err3 = sigma ** 2 * areas[i] ** 2 / nsky + err = err1 + err2 + err3 + if (err <= 0.0) + magerrs[i] = 0.0 + else { + magerrs[i] = 1.0857 * sqrt (err) / mags[i] + } + mags[i] = zmag - 2.5 * log10 (mags[i]) + } + } +end + + +# APCONMAGS -- Procedure to compute the magnitudes from the aperture sums, +# areas and sky values. + +procedure apconmags (sums, areas, mags, magerrs, naperts, sky, sigma, nsky, + zmag, noise, padu, readnoise) + +double sums[ARB] # aperture sums +double areas[ARB] # aperture areas +real mags[ARB] # output magnitudes +real magerrs[ARB] # errors in the magnitudes +int naperts # number of apertures +real sky # sky value +real readnoise # readout noise in electrons +real sigma # sigma of the sky values +int nsky # number of sky pixels +real zmag # sky value, sigma and zero point magnitudes +int noise # noise model +real padu # photons per adu + +int i +real err1, err2, err3, err + +begin + # Compute the magnitudes and errors + do i = 1, naperts { + mags[i] = areas[i] * sky - sums[i] + if (mags[i] <= 0.0) + mags[i] = INDEFR + else { + if (IS_INDEFR(readnoise)) + err1 = 0.0 + else + err1 = areas[i] * (readnoise / padu) ** 2 + switch (noise) { + case AP_NCONSTANT: + err2 = 0.0 + case AP_NPOISSON: + err2 = abs (sums[i]) / padu + default: + err2 = 0.0 + } + if (nsky <= 0) + err3 = 0.0 + else if (IS_INDEFR(sigma)) + err3 = 0.0 + else + err3 = sigma ** 2 * areas[i] ** 2 / nsky + err = err1 + err2 + err3 + if (err <= 0.0) + magerrs[i] = 0.0 + else { + magerrs[i] = 1.0857 * sqrt (err) / abs (sums[i]) + } + mags[i] = zmag - 2.5 * log10 (mags[i]) + } + } +end diff --git a/noao/digiphot/apphot/phot/apgppars.x b/noao/digiphot/apphot/phot/apgppars.x new file mode 100644 index 00000000..09961678 --- /dev/null +++ b/noao/digiphot/apphot/phot/apgppars.x @@ -0,0 +1,35 @@ +include "../lib/display.h" +include "../lib/noise.h" +include "../lib/center.h" +include "../lib/fitsky.h" +include "../lib/phot.h" + +# AP_GPPARS -- Procedure to fetch the phot task parameters. + +procedure ap_gppars (ap) + +pointer ap # pointer to apphot structure + +bool clgetb() +int btoi() + +begin + # Open the apphot strucuture. + call appinit (ap, AP_CENTROID1D, 2.5, AP_MODE, 10.0, 10.0, 3.0, 1, + AP_PWCONSTANT, 2.0, AP_NPOISSON) + + # Get the data dependent parameters. + call ap_gdapars (ap) + + # Get the centering algorithm parameters. + call ap_gcepars (ap) + + # Get the sky fitting parameters. + call ap_gsapars (ap) + + # Get the photometry parameters. + call ap_gphpars (ap) + + # Get the plotting parameters. + call apseti (ap, RADPLOTS, btoi (clgetb ("radplots"))) +end diff --git a/noao/digiphot/apphot/phot/apgqppars.x b/noao/digiphot/apphot/phot/apgqppars.x new file mode 100644 index 00000000..dea31951 --- /dev/null +++ b/noao/digiphot/apphot/phot/apgqppars.x @@ -0,0 +1,75 @@ +include "../lib/apphot.h" +include "../lib/display.h" +include "../lib/noise.h" +include "../lib/center.h" +include "../lib/fitsky.h" +include "../lib/phot.h" + +# AP_GQPPARS -- Procedure to fetch the phot task parameters. + +procedure ap_gqppars (ap) + +pointer ap # pointer to apphot structure + +int naperts +pointer mp, aperts, str, apstr +real cbox, annulus, dannulus +bool clgetb() +int ap_getaperts(), btoi() +real clgetr() + +begin + call smark (mp) + call salloc (aperts, MAX_NAPERTS, TY_REAL) + call salloc (str, SZ_LINE, TY_CHAR) + call salloc (apstr, SZ_LINE, TY_CHAR) + + # Get the center, sky fitting and photometry apertures. + cbox = clgetr ("cbox") / 2.0 + annulus = clgetr ("annulus") + dannulus = clgetr ("dannulus") + call clgstr ("apertures", Memc[apstr], SZ_LINE) + naperts = ap_getaperts (Memc[apstr], Memr[aperts], MAX_NAPERTS) + + # Open the apphot structure. + if (naperts <= 0.0) + call appinit (ap, AP_CENTROID1D, cbox, AP_CENTROID, annulus, + dannulus, 0.0, 1, AP_PWCONSTANT, 2.5, AP_NPOISSON) + else + call appinit (ap, AP_CENTROID1D, cbox, AP_CENTROID, annulus, + dannulus, Memr[aperts], naperts, AP_PWCONSTANT, 2.5, + AP_NPOISSON) + + # Set remaining parameters. + call apseti (ap, SMOOTH, YES) + + if (naperts > 0) + call apsets (ap, APSTRING, Memc[apstr]) + call apsetr (ap, ZMAG, clgetr ("zmag")) + + call clgstr ("exposure", Memc[str], SZ_FNAME) + call apsets (ap, EXPOSURE, Memc[str]) + + call clgstr ("airmass", Memc[str], SZ_FNAME) + call apsets (ap, AIRMASS, Memc[str]) + call apsetr (ap, XAIRMASS, INDEFR) + + call clgstr ("filter", Memc[str], SZ_FNAME) + call apsets (ap, FILTER, Memc[str]) + call apsets (ap, FILTERID, "INDEF") + + call clgstr ("obstime", Memc[str], SZ_FNAME) + call apsets (ap, OBSTIME, Memc[str]) + call apsets (ap, OTIME, "INDEF") + + call apsetr (ap, EPADU, clgetr ("epadu")) + + # Print the display parameters. + call apseti (ap, MKCENTER, btoi (true)) + call apseti (ap, MKSKY, btoi (true)) + call apseti (ap, MKAPERT, btoi (true)) + call apseti (ap, RADPLOTS, btoi (clgetb ("radplots"))) + + # Close the pset files. + call sfree (mp) +end diff --git a/noao/digiphot/apphot/phot/apmag.x b/noao/digiphot/apphot/phot/apmag.x new file mode 100644 index 00000000..e1490be2 --- /dev/null +++ b/noao/digiphot/apphot/phot/apmag.x @@ -0,0 +1,118 @@ +include <mach.h> +include "../lib/apphotdef.h" +include "../lib/apphot.h" +include "../lib/noisedef.h" +include "../lib/photdef.h" +include "../lib/phot.h" + +# APMAG -- Procedure to compute the magnitudes inside a set of apertures for +# a single of object. + +int procedure apmag (ap, im, wx, wy, positive, skyval, skysig, nsky) + +pointer ap # pointer to the apphot structure +pointer im # pointer to the IRAF image +real wx, wy # object coordinates +int positive # emission or absorption features +real skyval # sky value +real skysig # sky sigma +int nsky # number of sky pixels + +int c1, c2, l1, l2, ier, nap +pointer sp, nse, phot, temp +real datamin, datamax, zmag +int apmagbuf() + +begin + # Initalize. + phot = AP_PPHOT(ap) + nse = AP_NOISE(ap) + AP_PXCUR(phot) = wx + AP_PYCUR(phot) = wy + if (IS_INDEFR(wx) || IS_INDEFR(wy)) { + AP_OPXCUR(phot) = INDEFR + AP_OPYCUR(phot) = INDEFR + } else { + switch (AP_WCSOUT(ap)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_ltoo (ap, wx, wy, AP_OPXCUR(phot), AP_OPYCUR(phot), 1) + case WCS_TV: + call ap_ltov (im, wx, wy, AP_OPXCUR(phot), AP_OPYCUR(phot), 1) + default: + AP_OPXCUR(phot) = wx + AP_OPYCUR(phot) = wy + } + } + + call amovkd (0.0d0, Memd[AP_SUMS(phot)], AP_NAPERTS(phot)) + call amovkd (0.0d0, Memd[AP_AREA(phot)], AP_NAPERTS(phot)) + call amovkr (INDEFR, Memr[AP_MAGS(phot)], AP_NAPERTS(phot)) + call amovkr (INDEFR, Memr[AP_MAGERRS(phot)], AP_NAPERTS(phot)) + + # Make sure the center is defined. + if (IS_INDEFR(wx) || IS_INDEFR(wy)) + return (AP_APERT_NOAPERT) + + # Fetch the aperture pixels. + ier = apmagbuf (ap, im, wx, wy, c1, c2, l1, l2) + if (ier == AP_APERT_NOAPERT) + return (AP_APERT_NOAPERT) + + call smark (sp) + call salloc (temp, AP_NAPERTS(phot), TY_REAL) + + # Do photometry for all the apertures. + call amulkr (Memr[AP_APERTS(phot)], AP_SCALE(ap), Memr[temp], + AP_NAPERTS(phot)] + if (IS_INDEFR(AP_DATAMIN(ap)) && IS_INDEFR(AP_DATAMAX(ap))) { + call apmeasure (im, wx, wy, c1, c2, l1, l2, Memr[temp], + Memd[AP_SUMS(phot)], Memd[AP_AREA(phot)], AP_NMAXAP(phot)) + AP_NMINAP(phot) = AP_NMAXAP(phot) + 1 + } else { + if (IS_INDEFR(AP_DATAMIN(ap))) + datamin = -MAX_REAL + else + datamin = AP_DATAMIN(ap) + if (IS_INDEFR(AP_DATAMAX(ap))) + datamax = MAX_REAL + else + datamax = AP_DATAMAX(ap) + call apbmeasure (im, wx, wy, c1, c2, l1, l2, datamin, datamax, + Memr[temp], Memd[AP_SUMS(phot)], Memd[AP_AREA(phot)], + AP_NMAXAP(phot), AP_NMINAP(phot)) + } + + # Make sure that the sky value has been defined. + if (IS_INDEFR(skyval)) + ier = AP_APERT_NOSKYMODE + else { + + # Check for bad pixels. + if ((ier == AP_OK) && (AP_NMINAP(phot) <= AP_NMAXAP(phot))) + ier = AP_APERT_BADDATA + + nap = min (AP_NMINAP(phot) - 1, AP_NMAXAP(phot)) + + # Compute the magnitudes and errors. + if (positive == YES) + call apcopmags (Memd[AP_SUMS(phot)], Memd[AP_AREA(phot)], + Memr[AP_MAGS(phot)], Memr[AP_MAGERRS(phot)], + nap, skyval, skysig, nsky, AP_ZMAG(phot), + AP_NOISEFUNCTION(nse), AP_EPADU(nse)) + else + call apconmags (Memd[AP_SUMS(phot)], Memd[AP_AREA(phot)], + Memr[AP_MAGS(phot)], Memr[AP_MAGERRS(phot)], + nap, skyval, skysig, nsky, AP_ZMAG(phot), + AP_NOISEFUNCTION(nse), AP_EPADU(nse), AP_READNOISE(nse)) + + # Compute correction for itime. + zmag = 2.5 * log10 (AP_ITIME(ap)) + call aaddkr (Memr[AP_MAGS(phot)], zmag, Memr[AP_MAGS(phot)], nap) + } + + call sfree (sp) + if (ier != AP_OK) + return (ier) + else + return (AP_OK) +end diff --git a/noao/digiphot/apphot/phot/apmagbuf.x b/noao/digiphot/apphot/phot/apmagbuf.x new file mode 100644 index 00000000..15034561 --- /dev/null +++ b/noao/digiphot/apphot/phot/apmagbuf.x @@ -0,0 +1,89 @@ +include <imhdr.h> +include "../lib/apphotdef.h" +include "../lib/photdef.h" +include "../lib/phot.h" + +# APMAGBUF -- Procedure to determine the mapping of the aperture list +# into the input image. + +int procedure apmagbuf (ap, im, wx, wy, c1, c2, l1, l2) + +pointer ap # pointer to apphot structure +pointer im # pointer to the IRAF image +real wx, wy # center coordinates +int c1, c2 # column limits +int l1, l2 # line limits + +int i +pointer phot +real rbuf +int ap_photpix() + +begin + # Check for 0 radius aperture. + phot = AP_PPHOT(ap) + if (Memr[AP_APERTS(phot)] <= 0.0) + return (AP_APERT_NOAPERT) + + # Compute the maximum aperture size + AP_APIX(phot) = NULL + for (i = AP_NAPERTS(phot); AP_APIX(phot) == NULL && i >= 1; i = i - 1) { + rbuf = 2. * Memr[AP_APERTS(phot)+i-1] * AP_SCALE(ap) + AP_APIX(phot) = ap_photpix (im, wx, wy, rbuf, c1, c2, l1, l2) + AP_AXC(phot) = wx - c1 + 1 + AP_AYC(phot) = wy - l1 + 1 + AP_ANX(phot) = c2 - c1 + 1 + AP_ANY(phot) = l2 - l1 + 1 + AP_NMAXAP(phot) = i + } + + # Return the appropriate error code. + if (AP_APIX(phot) == NULL) { + return (AP_APERT_NOAPERT) + } else if (AP_NMAXAP(phot) < AP_NAPERTS(phot)) { + return (AP_APERT_OUTOFBOUNDS) + } else { + return (AP_OK) + } +end + + +# AP_PHOTPIX -- Procedure to determine the line and column limits of the +# required subraster. + +int procedure ap_photpix (im, wx, wy, papert, c1, c2, l1, l2) + +pointer im # pointer to IRAF image +real wx, wy # center of centering subraster annulus +real papert # centering radius +int c1, c2 # column limits +int l1, l2 # line limits + +int ncols, nlines +real half_papert, xc1, xc2, xl1, xl2 + +begin + # Check for 0 radius aperture. + half_papert = papert / 2. + if (half_papert <= 0) + return (0) + ncols = IM_LEN(im,1) + nlines = IM_LEN(im,2) + + # Test for an out of bounds aperture. + xc1 = wx - half_papert + xc2 = wx + half_papert + xl1 = wy - half_papert + xl2 = wy + half_papert + if ((xc1 < 0.5) || (xc2 > (real (ncols) + 0.5)) || + (xl1 < 0.5) || (xl2 > (real (nlines) + 0.5))) + return (0) + + # Get the column and line limits, dimensions and center of the subraster + # to be extracted. + c1 = max (1.0, min (real (ncols), xc1)) + c2 = min (real (ncols), max (1.0, xc2 + 0.5)) + l1 = max (1.0, min (real (nlines), xl1)) + l2 = min (real (nlines), max (1.0, xl2 + 0.5)) + return ((c2 - c1 + 1) * (l2 - l1 + 1)) +end diff --git a/noao/digiphot/apphot/phot/apmeasure.x b/noao/digiphot/apphot/phot/apmeasure.x new file mode 100644 index 00000000..6d64db5e --- /dev/null +++ b/noao/digiphot/apphot/phot/apmeasure.x @@ -0,0 +1,116 @@ +# APMEASURE -- Procedure to measure the fluxes and effective areas of a set of +# apertures. + +procedure apmeasure (im, wx, wy, c1, c2, l1, l2, aperts, sums, areas, naperts) + +pointer im # pointer to image +real wx, wy # center of subraster +int c1, c2 # column limits +int l1, l2 # line limits +real aperts[ARB] # array of apertures +double sums[ARB] # array of sums +double areas[ARB] # aperture areas +int naperts # number of apertures + +int i, j, k, nx, yindex +double fctn +pointer buf +real xc, yc, apmaxsq, dy2, r2, r +pointer imgs2r() + +begin + # Initialize. + nx = c2 - c1 + 1 + xc = wx - c1 + 1 + yc = wy - l1 + 1 + apmaxsq = (aperts[naperts] + 0.5) ** 2 + call aclrd (sums, naperts) + call aclrd (areas, naperts) + + # Loop over the pixels. + do j = l1, l2 { + buf = imgs2r (im, c1, c2, j, j) + if (buf == NULL) + return + yindex = j - l1 + 1 + dy2 = (yindex - yc) ** 2 + do i = 1, nx { + r2 = (i - xc) ** 2 + dy2 + if (r2 > apmaxsq) + next + r = sqrt (r2) - 0.5 + do k = 1, naperts { + if (r > aperts[k]) + next + fctn = max (0.0, min (1.0, aperts[k] - r)) + sums[k] = sums[k] + fctn * Memr[buf+i-1] + areas[k] = areas[k] + fctn + } + } + } +end + + +# APBMEASURE -- Procedure to measure the fluxes and effective areas of a set of +# apertures. + +procedure apbmeasure (im, wx, wy, c1, c2, l1, l2, datamin, datamax, aperts, + sums, areas, naperts, minapert) + +pointer im # pointer to image +real wx, wy # center of subraster +int c1, c2 # column limits +int l1, l2 # line limits +real datamin # minimum good data value +real datamax # maximum good data value +real aperts[ARB] # array of apertures +double sums[ARB] # array of sums +double areas[ARB] # aperture areas +int naperts # number of apertures +int minapert # minimum apertures + +int i, j, k, nx, yindex, kindex +double fctn +pointer buf +real xc, yc, apmaxsq, dy2, r2, r, pixval +pointer imgs2r() + +begin + # Initialize. + nx = c2 - c1 + 1 + xc = wx - c1 + 1 + yc = wy - l1 + 1 + apmaxsq = (aperts[naperts] + 0.5) ** 2 + call aclrd (sums, naperts) + call aclrd (areas, naperts) + minapert = naperts + 1 + + # Loop over the pixels. + do j = l1, l2 { + buf = imgs2r (im, c1, c2, j, j) + if (buf == NULL) + return + yindex = j - l1 + 1 + dy2 = (yindex - yc) ** 2 + do i = 1, nx { + r2 = (i - xc) ** 2 + dy2 + if (r2 > apmaxsq) + next + r = sqrt (r2) - 0.5 + pixval = Memr[buf+i-1] + kindex = naperts + 1 + do k = 1, naperts { + if (r > aperts[k]) + next + kindex = min (k, kindex) + fctn = max (0.0, min (1.0, aperts[k] - r)) + sums[k] = sums[k] + fctn * pixval + areas[k] = areas[k] + fctn + } + if (kindex < minapert) { + if (pixval < datamin || pixval > datamax) + minapert = kindex + } + } + } +end diff --git a/noao/digiphot/apphot/phot/appconfirm.x b/noao/digiphot/apphot/phot/appconfirm.x new file mode 100644 index 00000000..53d24034 --- /dev/null +++ b/noao/digiphot/apphot/phot/appconfirm.x @@ -0,0 +1,98 @@ +include "../lib/apphot.h" +include "../lib/noise.h" +include "../lib/center.h" +include "../lib/fitsky.h" +include "../lib/phot.h" + +# AP_PCONFIRM -- Procedure to confirm the critical phot parameters. + +procedure ap_pconfirm (ap, out, stid) + +pointer ap # pointer to the apphot structure +int out # output file descriptor +int stid # output file sequence number + +pointer sp, cstr, sstr, aperts +real fwhmpsf, capert, annulus, dannulus, skysigma +real datamin, datamax +int apstati() +real apstatr(), ap_vcapert(), ap_vannulus(), ap_vdannulus(), ap_vsigma() +real ap_vfwhmpsf(), ap_vdatamin(), ap_vdatamax + +begin + call smark (sp) + call salloc (cstr, SZ_FNAME, TY_CHAR) + call salloc (sstr, SZ_FNAME, TY_CHAR) + call salloc (aperts, SZ_LINE, TY_CHAR) + + call printf ("\n") + + # Confirm the centering algorithm. + call ap_vcstring (ap, Memc[cstr], SZ_FNAME) + + if (apstati (ap, CENTERFUNCTION) != AP_NONE) { + + # Confirm the fwhmpsf. + if (apstati (ap, CENTERFUNCTION) != AP_CENTROID1D) + fwhmpsf = ap_vfwhmpsf (ap) + else + fwhmpsf = apstatr (ap, FWHMPSF) + + # Confirm the centering box. + capert = 2.0 * ap_vcapert (ap) + + } else { + + fwhmpsf = apstatr (ap, FWHMPSF) + capert = 2.0 * apstatr (ap, CAPERT) + } + + # Confirm the sky fitting algorithm. + call ap_vsstring (ap, Memc[sstr], SZ_FNAME) + + # Confirm the sky annulus. + if (apstati (ap, SKYFUNCTION) != AP_CONSTANT && + apstati (ap, SKYFUNCTION) != AP_SKYFILE) { + annulus = ap_vannulus (ap) + dannulus = ap_vdannulus (ap) + } else { + annulus = apstatr (ap, ANNULUS) + dannulus = apstatr (ap, DANNULUS) + } + + # Confirm the aperture radii parameter. + call ap_vaperts (ap, Memc[aperts], SZ_LINE) + + # Confirm the datamin and datamax parameters. + skysigma = ap_vsigma (ap) + datamin = ap_vdatamin (ap) + datamax = ap_vdatamax (ap) + + call printf ("\n") + + # Update the database file. + if (out != NULL && stid > 1) { + call ap_sparam (out, KY_CSTRING, Memc[cstr], UN_CALGORITHM, + "centering aperture") + call ap_rparam (out, KY_FWHMPSF, fwhmpsf, UN_ASCALEUNIT, + "full width half maximum of the psf") + call ap_rparam (out, KY_CAPERT, capert, UN_CSCALEUNIT, + "centering box width") + call ap_sparam (out, KY_SSTRING, Memc[sstr], UN_SALGORITHM, + "sky fitting algorithm") + call ap_rparam (out, KY_ANNULUS, annulus, UN_SSCALEUNIT, + "inner radius of the sky annulus") + call ap_rparam (out, KY_DANNULUS, dannulus, UN_SSCALEUNIT, + "width of the sky annulus") + call ap_rparam (out, KY_SKYSIGMA, skysigma, UN_NCOUNTS, + "standard deviation of 1 sky pixel") + call ap_sparam (out, KY_APERTS, Memc[aperts], UN_PSCALEUNIT, + "list of apertures") + call ap_rparam (out, KY_DATAMIN, datamin, UN_ACOUNTS, + "minimum good data value") + call ap_rparam (out, KY_DATAMAX, datamax, UN_ACOUNTS, + "maximum good data value") + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/phot/apperrors.x b/noao/digiphot/apphot/phot/apperrors.x new file mode 100644 index 00000000..ff67e3ee --- /dev/null +++ b/noao/digiphot/apphot/phot/apperrors.x @@ -0,0 +1,48 @@ +include "../lib/phot.h" + +# AP_PERRORS -- Print the photometry task errors. + +procedure ap_perrors (ap, cier, sier, pier) + +pointer ap # apphot structure +int cier # centering error code +int sier # sky fitting error code +int pier # photometry error code + +begin + # Print the centering error message. + call ap_cerrors (ap, cier) + + # Print the sky fitting error message. + call ap_serrors (ap, sier) + + # Print the photometry error message. + call ap_merrors (ap, pier) + +end + + +# AP_MERRORS -- Print the photometry errors. + +procedure ap_merrors (ap, pier) + +pointer ap # pointer to the apphot structure (unused) +int pier # photometry error + +begin + # Print the photometry error message. + switch (pier) { + case AP_APERT_NOAPERT: + call printf ("Photometry apertures are outside of the image.\n") + case AP_APERT_OUTOFBOUNDS: + call printf ("Photometry apertures are partially outside the image.\n") + case AP_APERT_NOSKYMODE: + call printf ("The sky value is undefined.\n") + case AP_APERT_NEGMAG: + call printf ("The total flux inside the aperture is negative.\n") + case AP_APERT_BADDATA: + call printf ("Bad data in the aperture(s).\n") + default: + call printf ("") + } +end diff --git a/noao/digiphot/apphot/phot/appfree.x b/noao/digiphot/apphot/phot/appfree.x new file mode 100644 index 00000000..6d588f8a --- /dev/null +++ b/noao/digiphot/apphot/phot/appfree.x @@ -0,0 +1,66 @@ +include "../lib/apphotdef.h" +include "../lib/photdef.h" + +# APFREE -- Free the apphot structure. + +procedure appfree (ap) + +pointer ap # pointer to the apphot structure + +begin + if (ap == NULL) + return + if (AP_NOISE(ap) != NULL) + call ap_noisecls (ap) + if (AP_PCENTER(ap) != NULL) + call ap_ctrcls (ap) + if (AP_PDISPLAY(ap) != NULL) + call ap_dispcls (ap) + if (AP_POLY(ap) != NULL) + call ap_ycls (ap) + if (AP_PPHOT(ap) != NULL) + call ap_photcls (ap) + if (AP_PPSF(ap) != NULL) + call ap_psfcls (ap) + if (AP_PSKY(ap) != NULL) + call ap_skycls (ap) + if (AP_IMBUF(ap) != NULL) + call mfree (AP_IMBUF(ap), TY_REAL) + if (AP_MW(ap) != NULL) + call mw_close (AP_MW(ap)) + call mfree (ap, TY_STRUCT) +end + + +# AP_PHOTCLS -- Procedure to close up the photometry structure and arrays. + +procedure ap_photcls (ap) + +pointer ap # pointer to apphot structure + +pointer phot + +begin + if (AP_PPHOT(ap) == NULL) + return + phot = AP_PPHOT(ap) + if (AP_APERTS(phot) != NULL) + call mfree (AP_APERTS(phot), TY_REAL) + if (AP_MAGS(phot) != NULL) + call mfree (AP_MAGS(phot), TY_REAL) + if (AP_MAGERRS(phot) != NULL) + call mfree (AP_MAGERRS(phot), TY_REAL) + if (AP_SUMS(phot) != NULL) + call mfree (AP_SUMS(phot), TY_DOUBLE) + if (AP_AREA(phot) != NULL) + call mfree (AP_AREA(phot), TY_DOUBLE) + + #if (AP_APIX(phot) != NULL) + #call mfree (AP_APIX(phot), TY_REAL) + #if (AP_XAPIX(phot) != NULL) + #call mfree (AP_XAPIX(phot), TY_REAL) + #if (AP_YAPIX(phot) != NULL) + #call mfree (AP_YAPIX(phot), TY_REAL) + + call mfree (AP_PPHOT(ap), TY_STRUCT) +end diff --git a/noao/digiphot/apphot/phot/apphot.x b/noao/digiphot/apphot/phot/apphot.x new file mode 100644 index 00000000..1f8b942d --- /dev/null +++ b/noao/digiphot/apphot/phot/apphot.x @@ -0,0 +1,511 @@ +include <ctype.h> +include <gset.h> +include <imhdr.h> +include "../lib/phot.h" +include "../lib/apphot.h" +include "../lib/display.h" +include "../lib/center.h" +include "../lib/fitsky.h" + +define HELPFILE "apphot$phot/phot.key" + +# APPHOT -- Procedure to compute magnitudes for a list of objects + +int procedure apphot (ap, im, cl, sd, gd, mgd, id, out, stid, interactive, + cache) + +pointer ap # pointer to apphot structure +pointer im # pointer to IRAF image +int cl # starlist file descriptor +int sd # the sky file descriptor +pointer gd # pointer to graphcis descriptor +pointer mgd # pointer to the metacode file +pointer id # pointer to image display stream +int out # output file descriptor +int stid # output file sequence number +int interactive # interactive mode +int cache # cache the input image pixels + +real wx, wy, xlist, ylist +pointer sp, cmd +int newimage, newskybuf, newsky, newcenterbuf, newcenter, newmagbuf, newmag +int colonkey, prev_num, req_num, ip, cier, sier, pier, oid, req_size +int old_size, buf_size, memstat, wcs, key, ltid, newlist + +real apstatr() +int clgcur(), apfitsky(), aprefitsky(), apfitcenter(), aprefitcenter() +int apmag(), apremag(), apgscur(), ctoi(), apstati(), apgqverify() +int apgtverify(), apnew(), ap_avsky(), ap_memstat(), sizeof() +bool fp_equalr() + +define endswitch_ 99 + +begin + # Initialize. + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + # Initialize cursor command. + key = ' ' + Memc[cmd] = EOS + + # Initialize the fitting parameters. + newimage = NO + newcenterbuf = YES + newcenter = YES + newskybuf = YES + newsky = YES + newmagbuf = YES + newmag = YES + cier = AP_OK + sier = AP_OK + pier = AP_OK + + # Intialize the sequencing. + newlist = NO + ltid = 0 + + # Loop over the coordinate file. + while (clgcur ("icommands", wx, wy, wcs, key, Memc[cmd], SZ_LINE) != + EOF) { + + # Store the current cursor coordinates. + call ap_vtol (im, wx, wy, wx, wy, 1) + call apsetr (ap, CWX, wx) + call apsetr (ap, CWY, wy) + + # Test to see if the cursor moved. + if (apnew (ap, wx, wy, xlist, ylist, newlist) == YES) { + newcenterbuf = YES + newcenter = YES + newskybuf = YES + newsky = YES + newmagbuf = YES + newmag = YES + } + + # Store previous cursor coordinates. + call apsetr (ap, WX, apstatr (ap, CWX)) + call apsetr (ap, WY, apstatr (ap, CWY)) + + # Loop over the colon keystroke commands. + switch (key) { + + # Quit. + case 'q': + if (interactive == YES) { + if (apgqverify ("phot", ap, key) == YES) { + call sfree (sp) + return (apgtverify (key)) + } + } else { + call sfree (sp) + return (NO) + } + + # Print out error messages. + case 'e': + if (interactive == YES) + call ap_perrors (ap, cier, sier, pier) + + # Print out the help page(s). + case '?': + if ((id != NULL) && (id == gd)) + call gpagefile (id, HELPFILE, "") + else if (interactive == YES) + call pagefile (HELPFILE, "[space=morehelp,q=quit,?=help]") + + # Plot a centered stellar radial profile. + case 'd': + if (interactive == YES) { + call ap_qrad (ap, im, wx, wy, gd) + newmagbuf = YES; newmag = YES + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + } + + # Rewind the list. + case 'r': + if (cl != NULL) { + call seek (cl, BOFL) + ltid = 0 + } else if (interactive == YES) + call printf ("No coordinate list\n") + + # Get, measure the next object in the coordinate list. + case 'm', 'n': + + # No coordinate file. + if (cl == NULL) { + if (interactive == YES) + call printf ("No coordinate list\n") + goto endswitch_ + + } + + # Need to rewind coordinate file. + prev_num = ltid + req_num = ltid + 1 + if (apgscur (cl, id, xlist, ylist, prev_num, req_num, + ltid) == EOF) { + if (interactive == YES) + call printf ( + "End of coordinate list, use r key to rewind\n") + goto endswitch_ + + } + + # Convert coordinates if necessary. + switch (apstati (ap, WCSIN)) { + case WCS_PHYSICAL, WCS_WORLD: + call ap_itol (ap, xlist, ylist, xlist, ylist, 1) + case WCS_TV: + call ap_vtol (im, xlist, ylist, xlist, ylist, 1) + default: + ; + } + + # Move to next object. + newlist = YES + if (key == 'm') { + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newmagbuf = YES; newmag = YES + goto endswitch_ + } + + # Measure next object. + cier = apfitcenter (ap, im, xlist, ylist) + sier = apfitsky (ap, im, apstatr (ap, XCENTER), apstatr (ap, + YCENTER), sd, gd) + pier = apmag (ap, im, apstatr (ap, XCENTER), apstatr (ap, + YCENTER), apstati (ap, POSITIVE), apstatr (ap, SKY_MODE), + apstatr (ap, SKY_SIGMA), apstati (ap, NSKY)) + if (id != NULL) { + call apmark (ap, id, apstati (ap, MKCENTER), apstati (ap, + MKSKY), apstati (ap, MKAPERT)) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_pplot (ap, im, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qpmag (ap, cier, sier, pier) + if (stid == 1) + call ap_param (ap, out, "phot") + call ap_pmag (ap, out, stid, ltid, cier, sier, pier) + call ap_pplot (ap, im, stid, mgd, YES) + stid = stid + 1 + newcenterbuf = NO; newcenter = NO + newskybuf = NO; newsky = NO + newmagbuf = NO; newmag = NO + + # Process the remainder of the list. + case 'l': + if (cl != NULL) { + ltid = ltid + 1 + oid = stid + call apbphot (ap, im, cl, sd, out, stid, ltid, gd, mgd, id, + YES) + ltid = ltid + stid - oid + 1 + if (id != NULL) { + if (id == gd) + call gflush (id) + else + call gframe (id) + } + } else if (interactive == YES) + call printf ("No coordinate list\n") + + # Process apphot colon commands. + case ':': + for (ip = 1; IS_WHITE(Memc[cmd+ip-1]); ip = ip + 1) + ; + colonkey = Memc[cmd+ip-1] + switch (colonkey) { + case 'm', 'n': + + # Show/set a phot parameter. + if (Memc[cmd+ip] != EOS && Memc[cmd+ip] != ' ') { + call apphotcolon (ap, im, cl, out, stid, ltid, + Memc[cmd], newimage, newcenterbuf, newcenter, + newskybuf, newsky, newmagbuf, newmag) + goto endswitch_ + } + + # No coordinate list. + if (cl == NULL) { + if (interactive == YES) + call printf ("No coordinate list\n") + goto endswitch_ + } + + # Get next object from the list. + ip = ip + 1 + prev_num = ltid + if (ctoi (Memc[cmd], ip, req_num) <= 0) + req_num = ltid + 1 + + # Fetch the next object from the list. + if (apgscur (cl, id, xlist, ylist, prev_num, req_num, + ltid) == EOF) { + if (interactive == YES) + call printf ( + "End of coordinate list, use r key to rewind\n") + goto endswitch_ + } + + # Convert the coordinates. + switch (apstati (ap, WCSIN)) { + case WCS_PHYSICAL, WCS_WORLD: + call ap_itol (ap, xlist, ylist, xlist, ylist, 1) + case WCS_TV: + call ap_vtol (im, xlist, ylist, xlist, ylist, 1) + default: + ; + } + + # Move to the next object. + newlist = YES + if (colonkey == 'm') { + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newmagbuf = YES; newmag = YES + goto endswitch_ + } + cier = apfitcenter (ap, im, xlist, ylist) + sier = apfitsky (ap, im, apstatr (ap, XCENTER), + apstatr (ap, YCENTER), sd, gd) + pier = apmag (ap, im, apstatr (ap, XCENTER), apstatr (ap, + YCENTER), apstati (ap, POSITIVE), apstatr (ap, + SKY_MODE), apstatr (ap, SKY_SIGMA), apstati (ap, NSKY)) + if (id != NULL) { + call apmark (ap, id, apstati (ap, MKCENTER), + apstati (ap, MKSKY), apstati (ap, MKAPERT)) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_pplot (ap, im, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qpmag (ap, cier, sier, pier) + if (stid == 1) + call ap_param (ap, out, "phot") + call ap_pmag (ap, out, stid, ltid, cier, sier, pier) + call ap_pplot (ap, im, stid, mgd, YES) + stid = stid + 1 + newcenterbuf = NO; newcenter = NO + newskybuf = NO; newsky = NO + newmagbuf = NO; newmag = NO + + # Show/set a phot parameter. + default: + call apphotcolon (ap, im, cl, out, stid, ltid, Memc[cmd], + newimage, newcenterbuf, newcenter, newskybuf, newsky, + newmagbuf, newmag) + } + + # Reestablish the image display viewport if necessary. + if (newimage == YES) { + if ((id != NULL) && (id != gd)) + call ap_gswv (id, Memc[cmd], im, 4) + req_size = MEMFUDGE * IM_LEN(im,1) * IM_LEN(im,2) * + sizeof (IM_PIXTYPE(im)) + memstat = ap_memstat (cache, req_size, old_size) + if (memstat == YES) + call ap_pcache (im, INDEFI, buf_size) + } + + newimage = NO + + # Save the current parameters in the pset files. + case 'w': + call ap_ppars (ap) + + # Setup phot parameters interactively. + case 'i': + if (interactive == YES) { + call ap_radsetup (ap, im, wx, wy, gd, out, stid) + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newmagbuf = YES; newmag = YES + } + + # Verify the critical PHOT parameters. + case 'v': + call ap_pconfirm (ap, out, stid) + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newmagbuf = YES; newmag = YES + + # Fit the center around the cursor position. + case 'c': + if (newcenterbuf == YES) + cier = apfitcenter (ap, im, wx, wy) + else if (newcenter == YES) + cier = aprefitcenter (ap, im, cier) + if (id != NULL) { + call apmark (ap, id, apstati (ap, MKCENTER), NO, NO) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_cplot (ap, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qcenter (ap, cier) + newcenterbuf = NO; newcenter = NO + + # Fit the sky around the cursor position. + case 't': + if (newskybuf == YES || ! fp_equalr (wx, + apstatr (ap, SXCUR)) || ! fp_equalr (wy, apstatr (ap, + SYCUR))) + sier = apfitsky (ap, im, wx, wy, sd, gd) + else if (newsky == YES) + sier = aprefitsky (ap, im, gd) + if (id != NULL) { + call apmark (ap, id, NO, apstati (ap, MKSKY), NO) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_splot (ap, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qspsky (ap, sier) + newskybuf = NO; newsky = NO + + # Compute the average of several sky measurements around + # different cursor postions. + case 'a': + sier = ap_avsky (ap, im, stid, sd, id, gd, interactive) + if (interactive == YES) + call ap_qaspsky (ap, sier) + newskybuf = NO; newsky = NO + + # Fit the sky around the current center position. + case 's': + if (newskybuf == YES || ! fp_equalr (apstatr (ap, XCENTER), + apstatr (ap, SXCUR)) || ! fp_equalr (apstatr (ap, SYCUR), + apstatr (ap, YCENTER))) + sier = apfitsky (ap, im, apstatr (ap, XCENTER), + apstatr (ap, YCENTER), sd, gd) + else if (newsky == YES) + sier = aprefitsky (ap, im, gd) + if (id != NULL) { + call apmark (ap, id, NO, apstati (ap, MKSKY), NO) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_splot (ap, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qspsky (ap, sier) + newskybuf = NO; newsky = NO + + # Compute magnitudes around the current star using the current + # sky. + case 'p', 'o': + if (newcenterbuf == YES) + cier = apfitcenter (ap, im, wx, wy) + else if (newcenter == YES) + cier = aprefitcenter (ap, im, cier) + if (newmagbuf == YES || ! fp_equalr (apstatr (ap, XCENTER), + apstatr (ap, PXCUR)) || ! fp_equalr (apstatr (ap, + PYCUR), apstatr (ap, YCENTER))) + pier = apmag (ap, im, apstatr (ap, XCENTER), apstatr (ap, + YCENTER), apstati (ap, POSITIVE), apstatr (ap, + SKY_MODE), apstatr (ap, SKY_SIGMA), apstati (ap, NSKY)) + else + pier = apremag (ap, im, apstati (ap, POSITIVE), apstatr (ap, + SKY_MODE), apstatr (ap, SKY_SIGMA), apstati (ap, NSKY)) + if (id != NULL) { + call apmark (ap, id, NO, NO, apstati (ap, MKAPERT)) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + if (interactive == YES) + call ap_qpmag (ap, cier, sier, pier) + newcenterbuf = NO; newcenter = NO + newmagbuf = NO; newmag = NO + + if (key == 'o') { + if (stid == 1) + call ap_param (ap, out, "phot") + if (newlist == YES) + call ap_pmag (ap, out, stid, ltid, cier, sier, pier) + else + call ap_pmag (ap, out, stid, 0, cier, sier, pier) + call ap_pplot (ap, im, stid, mgd, YES) + stid = stid + 1 + } + + # Compute the center, sky, and magnitudes and save the results. + case 'f', ' ': + if (newcenterbuf == YES) + cier = apfitcenter (ap, im, wx, wy) + else if (newcenter == YES) + cier = aprefitcenter (ap, im, cier) + if (newskybuf == YES || ! fp_equalr (apstatr (ap, XCENTER), + apstatr (ap, SXCUR)) || ! fp_equalr (apstatr (ap, YCENTER), + apstatr (ap, SYCUR))) + sier = apfitsky (ap, im, apstatr (ap, XCENTER), apstatr (ap, + YCENTER), sd, gd) + else if (newsky == YES) + sier = aprefitsky (ap, im, gd) + if (newmagbuf == YES || ! fp_equalr (apstatr (ap, XCENTER), + apstatr (ap, PXCUR)) || ! fp_equalr (apstatr (ap, YCENTER), + apstatr (ap, PYCUR))) + pier = apmag (ap, im, apstatr (ap, XCENTER), + apstatr (ap, YCENTER), apstati (ap, POSITIVE), + apstatr (ap, SKY_MODE), apstatr (ap, SKY_SIGMA), + apstati (ap, NSKY)) + else + pier = apremag (ap, im, apstati (ap, POSITIVE), apstatr (ap, + SKY_MODE), apstatr (ap, SKY_SIGMA), apstati (ap, NSKY)) + + if (id != NULL) { + call apmark (ap, id, apstati (ap, MKCENTER), apstati (ap, + MKSKY), apstati (ap, MKAPERT)) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_pplot (ap, im, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qpmag (ap, cier, sier, pier) + + newcenterbuf = NO; newcenter = NO + newskybuf = NO; newsky = NO + newmagbuf = NO; newmag = NO + + if (key == ' ') { + if (stid == 1) + call ap_param (ap, out, "phot") + if (newlist == YES) + call ap_pmag (ap, out, stid, ltid, cier, sier, pier) + else + call ap_pmag (ap, out, stid, 0, cier, sier, pier) + call ap_pplot (ap, im, stid, mgd, YES) + stid = stid + 1 + } + + default: + call printf ("Unknown or ambiguous keystroke command\n") + } + +endswitch_ + # Setup for the next object. + key = ' ' + Memc[cmd] = EOS + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/phot/apphotcolon.x b/noao/digiphot/apphot/phot/apphotcolon.x new file mode 100644 index 00000000..825459b2 --- /dev/null +++ b/noao/digiphot/apphot/phot/apphotcolon.x @@ -0,0 +1,209 @@ +include <gset.h> +include "../lib/apphot.h" +include "../lib/fitsky.h" +include "../lib/center.h" +include "../lib/phot.h" +include "../lib/display.h" +include "../lib/noise.h" + +# APPHOTCOLON -- Process phot colon commands. + +procedure apphotcolon (ap, im, cl, out, stid, ltid, cmdstr, newimage, + newcenterbuf, newcenter, newskybuf, newsky, newmagbuf, newmag) + +pointer ap # pointer to the apphot structure +pointer im # pointer to the iraf image +int cl # coord file descriptor +int out # output file descriptor +int stid # output file sequence number +int ltid # coord list sequence number +char cmdstr[ARB] # command string +int newimage # new image ? +int newcenterbuf, newcenter # new center buffer ? new center fit ? +int newskybuf, newsky # new sky buffer ? new sky fit ? +int newmagbuf, newmag # new aperture buffer ? new fit ? + +pointer sp, incmd, outcmd +int strdic() + +begin + call smark (sp) + call salloc (incmd, SZ_LINE, TY_CHAR) + call salloc (outcmd, SZ_LINE, TY_CHAR) + + # Get the command. + call sscan (cmdstr) + call gargwrd (Memc[incmd], SZ_LINE) + if (Memc[incmd] == EOS) { + call sfree (sp) + return + } + + # Process the command. + if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, CCMDS) != 0) + call apccolon (ap, out, stid, cmdstr, newcenterbuf, newcenter) + else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, SCMDS) != 0) + call apscolon (ap, out, stid, cmdstr, newskybuf, newsky) + else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, PCMDS) != 0) + call apmagcolon (ap, out, stid, cmdstr, newmagbuf, newmag) + else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, APCMDS) != 0) + call ap_apcolon (ap, im, cl, out, stid, ltid, cmdstr, newimage, + newcenterbuf, newcenter, newskybuf, newsky, newmagbuf, newmag) + else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, NCMDS) != 0) + call apnscolon (ap, im, out, stid, cmdstr, newcenterbuf, + newcenter, newskybuf, newsky, newmagbuf, newmag) + else + call ap_himcolon (ap, cmdstr) + + call sfree (sp) +end + + +# APMAGCOLON -- Procedure to display and edit the photometry parameters. + +procedure apmagcolon (ap, out, stid, cmdstr, newmagbuf, newmag) + +pointer ap # pointer to apphot structure +int out # output file descriptor +int stid # output number +char cmdstr[ARB] # command string +int newmagbuf # new aperture buffers +int newmag # compute new magnitudes + +bool bval +int ncmd +pointer sp, cmd +real rval +bool itob() +int btoi(), strdic(), nscan(), apstati() +real apstatr() + +begin + # Get the command. + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + call sscan (cmdstr) + call gargwrd (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call sfree (sp) + return + } + + # Process the command + ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, PCMDS) + switch (ncmd) { + case PCMD_APERTURES: + call gargwrd (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call apstats (ap, APERTS, Memc[cmd], SZ_LINE) + call printf ("%s = %s %s\n") + call pargstr (KY_APERTS) + call pargstr (Memc[cmd]) + call pargstr (UN_PSCALEUNIT) + } else { + call apsets (ap, APERTS, Memc[cmd]) + if (stid > 1) + call ap_sparam (out, KY_APERTS, Memc[cmd], UN_PSCALEUNIT, + "list of aperture radii") + newmag = YES + newmagbuf = YES + } + case PCMD_ZMAG: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g\n") + call pargstr (KY_ZMAG) + call pargr (apstatr (ap, ZMAG)) + } else { + call apsetr (ap, ZMAG, rval) + if (stid > 1) + call ap_rparam (out, KY_ZMAG, rval, UN_PZMAG, + "zero point of magnitude scale") + newmag = YES + } + case PCMD_MKAPERT: + call gargb (bval) + if (nscan () == 1) { + call printf ("%s = %b\n") + call pargstr (KY_MKAPERT) + call pargb (itob (apstati (ap, MKAPERT))) + } else { + call apseti (ap, MKAPERT, btoi (bval)) + } + default: + call printf ("Unknown command\7\n") + } + + call sfree (sp) +end + + +# AP_HIMCOLON -- Procedure to process commands which alter the centering, sky +# fitting and photometry buffers. + +procedure ap_himcolon (ap, cmdstr) + +pointer ap # pointer to the apphot structure +char cmdstr[ARB] # command string + +bool bval +int ncmd +pointer sp, cmd +bool itob() +int strdic(), nscan(), btoi(), apstati() + +begin + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + # Get the command. + call sscan (cmdstr) + call gargwrd (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call sfree (sp) + return + } + + # Process the command. + ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, MISC) + switch (ncmd) { + case ACMD_SHOW: + call gargwrd (Memc[cmd], SZ_LINE) + ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, PSHOWARGS) + switch (ncmd) { + case PCMD_CENTER: + call printf ("\n") + call ap_cpshow (ap) + call printf ("\n") + case PCMD_SKY: + call printf ("\n") + call ap_spshow (ap) + call printf ("\n") + case PCMD_PHOT: + call printf ("\n") + call ap_mpshow (ap) + call printf ("\n") + case PCMD_DATA: + call printf ("\n") + call ap_nshow (ap) + call printf ("\n") + default: + call printf ("\n") + call ap_pshow (ap) + call printf ("\n") + } + case ACMD_RADPLOTS: + call gargb (bval) + if (nscan () == 1) { + call printf ("%s = %b\n") + call pargstr (KY_RADPLOTS) + call pargb (itob (apstati (ap, RADPLOTS))) + } else + call apseti (ap, RADPLOTS, btoi (bval)) + default: + call printf ("Unknown or ambigous colon command\7\n") + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/phot/appinit.x b/noao/digiphot/apphot/phot/appinit.x new file mode 100644 index 00000000..b9f558c2 --- /dev/null +++ b/noao/digiphot/apphot/phot/appinit.x @@ -0,0 +1,100 @@ +include "../lib/apphotdef.h" +include "../lib/photdef.h" +include "../lib/phot.h" + +# APPINIT - Procedure to initialize apphot structure. + +procedure appinit (ap, cfunction, cbox, sfunction, annulus, dannulus, + aperts, napert, weight, fwhmpsf, noise) + +pointer ap # pointer to the apphot structure +int cfunction # centering algorithm +real cbox # half width of the centering box +int sfunction # sky fitting algorithm +real annulus # radius of sky annulus +real dannulus # width of sky annulus +real aperts[ARB] # apertures +int napert # number of apertures +int weight # weight for photometry +real fwhmpsf # FWHM of the PSF +int noise # noise model + +begin + # Set the image parameters. + call malloc (ap, LEN_APSTRUCT, TY_STRUCT) + + # Set up the apphot package defaults. + call ap_defsetup (ap, fwhmpsf) + + # Set up noise structure. + call ap_noisesetup (ap, noise) + + # Set up centering structure. + call ap_ctrsetup (ap, cfunction, cbox) + + # Set up sky fitting structure. + call ap_skysetup (ap, sfunction, annulus, dannulus) + + # Set up photometry structure. + call ap_photsetup (ap, aperts, napert, weight) + + # Set the display options. + call ap_dispsetup (ap) + + # Unused structures are set to null. + AP_PPSF(ap) = NULL + AP_POLY(ap) = NULL + AP_RPROF(ap) = NULL +end + + +# AP_PHOTSETUP -- Procedure to set up the photometry parameters. + +procedure ap_photsetup (ap, aperts, napert, weight) + +pointer ap # pointer to apphot structure +real aperts[ARB] # array of apertures +int napert # number of apertures +int weight # weighting function for photometry + +pointer phot + +begin + # phot structure + call malloc (AP_PPHOT(ap), LEN_PHOTSTRUCT, TY_STRUCT) + phot = AP_PPHOT(ap) + + # Set the default values forthe photometry parameters. + AP_PXCUR(phot) = INDEFR + AP_PYCUR(phot) = INDEFR + AP_NAPERTS(phot) = napert + AP_ZMAG(phot) = DEF_ZMAG + AP_PWEIGHTS(phot) = weight + AP_APSTRING(phot) = EOS + switch (weight) { + case AP_PWCONSTANT: + call strcpy ("constant", AP_PWSTRING(phot), SZ_FNAME) + case AP_PWCONE: + call strcpy ("cone", AP_PWSTRING(phot), SZ_FNAME) + case AP_PWGAUSS: + call strcpy ("gauss", AP_PWSTRING(phot), SZ_FNAME) + default: + call strcpy ("constant", AP_PWSTRING(phot), SZ_FNAME) + } + + # Initialize buffers. + AP_LENABUF(phot) = 0 + AP_NAPIX(phot) = 0 + AP_APIX(phot) = NULL + AP_XAPIX(phot) = NULL + AP_YAPIX(phot) = NULL + + # Allocate the buffers to hold the answers. + call malloc (AP_APERTS(phot), napert, TY_REAL) + call malloc (AP_MAGS(phot), napert, TY_REAL) + call malloc (AP_MAGERRS(phot), napert, TY_REAL) + call malloc (AP_AREA(phot), napert, TY_DOUBLE) + call malloc (AP_SUMS(phot), napert, TY_DOUBLE) + call amovr (aperts, Memr[AP_APERTS(phot)], napert) + call asrtr (Memr[AP_APERTS(phot)], Memr[AP_APERTS(phot)], napert) +end diff --git a/noao/digiphot/apphot/phot/appmag.x b/noao/digiphot/apphot/phot/appmag.x new file mode 100644 index 00000000..9bc7e43c --- /dev/null +++ b/noao/digiphot/apphot/phot/appmag.x @@ -0,0 +1,120 @@ +include "../lib/apphotdef.h" +include "../lib/apphot.h" +include "../lib/center.h" +include "../lib/fitsky.h" +include "../lib/photdef.h" +include "../lib/phot.h" + +# AP_PMAG -- Procedure to write the results of the phot task to the output +# file. + +procedure ap_pmag (ap, fd, id, lid, cier, sier, pier) + +pointer ap # pointer to apphot structure +int fd # output text file +int id # id number of str +int lid # list id of star +int cier # centering error +int sier # sky fitting error +int pier # photometric error + +int i, naperts +int apstati() +real apstatr() + +begin + # Initialize. + if (fd == NULL) + return + + # Write out the object id parameters. + call ap_wid (ap, fd, apstatr (ap, OXINIT), apstatr(ap, OYINIT), + id, lid, '\\') + + # Write out the centering results. + call ap_wcres (ap, fd, cier, '\\') + + # Write out the sky fitting results. + call ap_wsres (ap, fd, sier, '\\') + + # Write out the photometry results. + naperts = apstati (ap, NAPERTS) + if (naperts == 0) + call ap_wmres (ap, fd, 0, pier, " ") + else { + do i = 1, naperts { + if (naperts == 1) + call ap_wmres (ap, fd, i, pier, " ") + else if (i == naperts) + call ap_wmres (ap, fd, i, pier, "* ") + else + call ap_wmres (ap, fd, i, pier, "*\\") + } + } +end + + +# AP_QPMAG -- Procedure to print a quick summary of the phot output on the +# standard output. + +procedure ap_qpmag (ap, cier, sier, pier) + +pointer ap # pointer to apphot structure +int cier # centering error +int sier # sky fitting error +int pier # photometry error + +int i +pointer sp, imname, phot +real apstatr() + +begin + # Initialize. + call smark (sp) + call salloc (imname, SZ_FNAME, TY_CHAR) + phot = AP_PPHOT(ap) + + # Print the center and sky value. + call apstats (ap, IMROOT, Memc[imname], SZ_FNAME) + call printf ("%s %8.2f %8.2f %8g ") + call pargstr (Memc[imname]) + call pargr (apstatr (ap, OPXCUR)) + call pargr (apstatr (ap, OPYCUR)) + call pargr (apstatr (ap, SKY_MODE)) + + # Print out the magnitudes and errors. + do i = 1, AP_NAPERTS(phot) { + if (i == AP_NAPERTS(phot)) + call printf ("%7.3f ") + else + call printf ("%7.3f ") + call pargr (Memr[AP_MAGS(phot)+i-1]) + } + + # Print out the error codes. + if (cier != AP_OK || sier != AP_OK || pier != AP_OK) { + call printf ("err\n") + } else { + call printf ("ok\n") + } + + call sfree (sp) +end + + +# AP_MAGHDR -- Procedure to print the banner for the phot task on the +# standard output. + +procedure ap_maghdr (ap, fd) + +pointer ap # pointer to apphot strucuture +int fd # output file descriptor + +begin + if (fd == NULL) + return + call ap_idhdr (ap, fd) + call ap_chdr (ap, fd) + call ap_shdr (ap, fd) + call ap_mhdr (ap, fd) +end diff --git a/noao/digiphot/apphot/phot/apppars.x b/noao/digiphot/apphot/phot/apppars.x new file mode 100644 index 00000000..68e08aeb --- /dev/null +++ b/noao/digiphot/apphot/phot/apppars.x @@ -0,0 +1,26 @@ +include "../lib/display.h" + +# AP_PPARS -- Procedure to write out the phot task parameters. + +procedure ap_ppars (ap) + +pointer ap # pointer to apphot structure + +bool itob() +int apstati() + +begin + # Write the data dependent parameters. + call ap_dapars (ap) + + # Write the centering parameters. + call ap_cepars (ap) + + # Write the sky fitting paameters. + call ap_sapars (ap) + + # Write the photometry parameters. + call ap_phpars (ap) + + call clputb ("radplots", itob (apstati (ap, RADPLOTS))) +end diff --git a/noao/digiphot/apphot/phot/appplot.x b/noao/digiphot/apphot/phot/appplot.x new file mode 100644 index 00000000..5172533d --- /dev/null +++ b/noao/digiphot/apphot/phot/appplot.x @@ -0,0 +1,273 @@ +include <pkg/gtools.h> +include <gset.h> +include "../lib/apphot.h" +include "../lib/noise.h" +include "../lib/center.h" +include "../lib/fitsky.h" +include "../lib/phot.h" + +# AP_PPLOT -- Procedure to compute radial profile plots for the centering +# routine. + +procedure ap_pplot (ap, im, sid, gd, makeplot) + +pointer ap # pointer to the apphot structure +pointer im # pointer to the iraf image +int sid # id number of the star +pointer gd # graphics stream +int makeplot # make a plot ? + +int apert, nx, ny +pointer buf, sp, str, r, gt +real xcenter, ycenter, xc, yc, rmin, rmax, imin, imax +real u1, u2, v1, v2, x1, x2, y1, y2 +int ap_ctrpix() +pointer ap_gtinit() +real apstatr() + +begin + # Initialize + if (gd == NULL || makeplot == NO) + return + + # Check for defined center and get the pixels. + xcenter = apstatr (ap, XCENTER) + ycenter = apstatr (ap, YCENTER) + if (IS_INDEFR(xcenter) || IS_INDEFR(ycenter)) + return + + # Fetch the pixels. + apert = 2 * int (apstatr (ap, SCALE) * (apstatr (ap, ANNULUS) + + apstatr (ap, DANNULUS))) + 1 + buf = ap_ctrpix (im, xcenter, ycenter, apert, xc, yc, nx, ny) + if (buf == NULL) + return + + # Reactivate the work station. + call greactivate (gd, 0) + + # Allocate working space. + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + call salloc (r, nx * ny, TY_REAL) + + # Compute the radii and the plot limits. + call ap_ijtor2 (Memr[r], nx, ny, xc, yc) + call alimr (Memr[r], nx * ny, rmin, rmax) + call alimr (Memr[buf], nx * ny, imin, imax) + + # Store the viewport and window coordinates. + call ggview (gd, u1, u2, v1, v2) + call ggwind (gd, x1, x2, y1, y2) + + # Initialize the plot. + call apstats (ap, IMROOT, Memc[str], SZ_LINE) + call sprintf (Memc[str], SZ_LINE, "%s Star %d") + call pargstr (Memc[str]) + call pargi (sid) + gt = ap_gtinit (Memc[str], apstatr (ap, OXINIT), apstatr (ap, OYINIT)) + call gclear (gd) + + # Label and annotate the plot. + call ap_ppset (gd, gt, ap, rmin, rmax, imin, imax) + call ap_ppannotate (gd, ap, rmin, rmax, imin, imax) + + # Plot the coordinates. + call ap_plotrad (gd, gt, Memr[r], Memr[buf], nx * ny, "plus") + + # Store the viewport and window coordinates. + call gsview (gd, u1, u2, v1, v2) + call gswind (gd, x1, x2, y1, y2) + + call ap_gtfree (gt) + call gdeactivate (gd, 0) + call sfree (sp) +end + + +# AP_PPSET -- Procedure to set up the parameters for the phot radial profile +# plot. + +procedure ap_ppset (gd, gt, ap, xmin, xmax, ymin, ymax) + +pointer gd # the graphics stream +pointer gt # the gtools pointer +pointer ap # the apphot pointer +real xmin, xmax # the minimum and maximum radial distance +real ymin, ymax # the minimum and maximum of the y axes + +int fd, naperts +pointer sp, str, title, temp +real aspect, scale, vx1, vx2, vy1, vy2 +int stropen(), apstati() +real apstatr(), gstatr() + +begin + call smark (sp) + call salloc (str, 5 * SZ_LINE, TY_CHAR) + call salloc (title, SZ_LINE, TY_CHAR) + naperts = apstati (ap, NAPERTS) + call salloc (temp, naperts, TY_REAL) + + fd = stropen (Memc[str], 5 * SZ_LINE, WRITE_ONLY) + call sysid (Memc[title], SZ_LINE) + call fprintf (fd, "%s\n") + call pargstr (Memc[title]) + + # Encode the center parameter string. + call fprintf (fd, + "Center: xc=%0.2f yc=%0.2f xerr=%0.2f yerr=%0.2f\n") + call pargr (apstatr (ap, OXCENTER)) + call pargr (apstatr (ap, OYCENTER)) + call pargr (apstatr (ap, XERR)) + call pargr (apstatr (ap, YERR)) + + # Encode the sky fitting parameter string + call fprintf (fd, + "Sky: value=%0.2f sigma=%0.2f skew=%0.2f nsky=%d nrej=%d\n") + call pargr (apstatr (ap, SKY_MODE)) + call pargr (apstatr (ap, SKY_SIGMA)) + call pargr (apstatr (ap, SKY_SKEW)) + call pargi (apstati (ap, NSKY)) + call pargi (apstati (ap, NSKY_REJECT)) + + # Encode the apertures and magnitudes. + call ap_arrayr (ap, APERTS, Memr[temp]) + call amulkr (Memr[temp], apstatr (ap, SCALE), Memr[temp], naperts) + call fprintf (fd, "Photometry: maxapert=") + call fprintf (fd, "%0.2f mag=") + call pargr (Memr[temp+naperts-1]) + call ap_arrayr (ap, MAGS, Memr[temp]) + call fprintf (fd, "%0.3f merr=") + call pargr (Memr[temp+naperts-1]) + call ap_arrayr (ap, MAGERRS, Memr[temp]) + call fprintf (fd, "%0.3f\n") + call pargr (Memr[temp+naperts-1]) + + # Encode the title. + call gt_gets (gt, GTTITLE, Memc[title], SZ_LINE) + call fprintf (fd, "%s\n") + call pargstr (Memc[title]) + + call strclose (fd) + + aspect = gstatr (gd, G_ASPECT) + call gsetr (gd, G_ASPECT, 0.70) + scale = apstatr (ap, SCALE) + + # Draw three axes. + call gseti (gd, G_XDRAWAXES, 2) + call gswind (gd, xmin / scale, xmax / scale, ymin, ymax) + call glabax (gd, Memc[str], "", "Intensity") + + # Draw the bottom x axis. + call gseti (gd, G_YDRAWAXES, 0) + call gseti (gd, G_XDRAWAXES, 1) + call ggview (gd, vx1, vx2, vy1, vy2) + call gsview (gd, vx1, vx2, vy1, vy2) + call gswind (gd, xmin, xmax, ymin, ymax) + call glabax (gd, + "","Radial Distance (lower-pixels, upper-scale units)", "") + + # Restore the default draw axis parameters. + call gseti (gd, G_YDRAWAXES, 3) + call gseti (gd, G_XDRAWAXES, 3) + call gsetr (gd, G_ASPECT, aspect) + + # Set the mark type. + call gt_sets (gt, GTTYPE, "mark") + + call sfree (sp) +end + + +# AP_PPANNOTATE -- Procedure to annotate the radial plot in phot. + +procedure ap_ppannotate (gd, ap, xmin, xmax, ymin, ymax) + +pointer gd # graphics stream +pointer ap # apphot structure +real xmin, xmax # minimum and maximum of the x axis +real ymin, ymax # minimum and maximum of the y axis + +int i, naperts +pointer sp, str, temp +real annulus, dannulus, skyval, skysigma +int apstati() +real apstatr () + +begin + naperts = apstati (ap, NAPERTS) + call smark (sp) + call salloc (str, SZ_LINE + 1, TY_CHAR) + call salloc (temp, naperts, TY_REAL) + + # Define some temporary variables + annulus = apstatr (ap, SCALE) * apstatr (ap, ANNULUS) + dannulus = annulus + apstatr (ap, SCALE) * apstatr (ap, DANNULUS) + + # Mark the inner sky annulus. + if (annulus >= xmin && annulus <= xmax) { + call gamove (gd, annulus, ymin) + call gadraw (gd, annulus, ymax) + call sprintf (Memc[str], SZ_LINE, "inner sky radius = %0.2f") + call pargr (annulus) + call gtext (gd, annulus, ymax, Memc[str], "q=h;u=180;v=t;p=r") + } + + # Mark the outer sky annulus. + if (dannulus >= xmin && dannulus <= xmax) { + call gamove (gd, dannulus, ymin) + call gadraw (gd, dannulus, ymax) + call sprintf (Memc[str], SZ_LINE, "outer sky radius = %0.2f") + call pargr (dannulus) + call gtext (gd, dannulus, ymax, Memc[str], "q=h;u=180;v=t;p=r") + } + + # Mark the sky value. + call gseti (gd, G_PLTYPE, GL_SOLID) + skyval = apstatr (ap, SKY_MODE) + if (skyval >= ymin && skyval <= ymax) { + call gamove (gd, xmin, skyval) + call gadraw (gd, xmax, skyval) + } + + # Mark the upper sky sigma. + call gseti (gd, G_PLTYPE, GL_DASHED) + if (! IS_INDEFR(apstatr (ap, SKY_SIGMA))) + skysigma = skyval + apstatr (ap, SHIREJECT) * apstatr (ap, + SKY_SIGMA) + else + skysigma = INDEFR + if (! IS_INDEFR(skysigma) && (skysigma >= ymin) && skysigma <= ymax) { + call gamove (gd, xmin, skysigma) + call gadraw (gd, xmax, skysigma) + } + + # Mark the lower sky sigma + if (! IS_INDEFR(apstatr (ap, SKY_SIGMA))) + skysigma = skyval - apstatr (ap, SLOREJECT) * apstatr (ap, + SKY_SIGMA) + else + skysigma = INDEFR + if (! IS_INDEFR(skysigma) && (skysigma >= ymin) && skysigma <= ymax) { + call gamove (gd, xmin, skysigma) + call gadraw (gd, xmax, skysigma) + } + + # Mark the appertures. + call gseti (gd, G_PLTYPE, GL_SOLID) + call ap_arrayr (ap, APERTS, Memr[temp]) + call amulkr (Memr[temp], apstatr (ap, SCALE), Memr[temp], naperts) + do i = 1, naperts { + call gamove (gd, Memr[temp+i-1], ymin) + call gadraw (gd, Memr[temp+i-1], ymax) + call sprintf (Memc[str], SZ_LINE, "apert[%d] = %0.2f") + call pargi (i) + call pargr (Memr[temp+i-1]) + call gtext (gd, Memr[temp+i-1], ymax, Memc[str], + "q=h;u=180;v=t;p=r") + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/phot/appshow.x b/noao/digiphot/apphot/phot/appshow.x new file mode 100644 index 00000000..5e52b42d --- /dev/null +++ b/noao/digiphot/apphot/phot/appshow.x @@ -0,0 +1,83 @@ +include "../lib/display.h" +include "../lib/phot.h" + +# AP_PSHOW -- Procedure to print the photometry parameters. + +procedure ap_pshow (ap) + +pointer ap # pointer to the apphot strucuture + +bool itob() +int apstati() + +begin + call ap_nshow (ap) + call printf ("\n") + call ap_cpshow (ap) + call printf ("\n") + call ap_spshow (ap) + call printf ("\n") + call ap_mpshow (ap) + call printf (" %s = %b\n") + call pargstr (KY_RADPLOTS) + call pargb (itob (apstati (ap, RADPLOTS))) +end + + +# AP_MSHOW -- Procedure to print the photometry parameters on the standard +# output. + +procedure ap_mshow (ap) + +pointer ap # pointer to apphot structure + +bool itob() +int apstati() +begin + call ap_nshow (ap) + call printf ("\n") + call ap_mpshow (ap) + call printf (" %s = %b\n") + call pargstr (KY_RADPLOTS) + call pargb (itob (apstati (ap, RADPLOTS))) +end + + +# AP_MPSHOW -- Procedure to print the photometry parameters on the standard +# output. + +procedure ap_mpshow (ap) + +pointer ap # pointer to apphot structure + +pointer sp, str +bool itob() +int apstati() +real apstatr() + +begin + # Write out the image and cursor position. + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + + # Write out the phot parameters. + call printf ("Photometry Parameters\n") + call apstats (ap, PWSTRING, Memc[str], SZ_LINE) + call printf (" %s = %s %s\n") + call pargstr (KY_PWSTRING) + call pargstr (Memc[str]) + call pargstr (UN_PMODEL) + call apstats (ap, APERTS, Memc[str], SZ_LINE) + call printf (" %s = %s %s\n") + call pargstr (KY_APERTS) + call pargstr (Memc[str]) + call pargstr (UN_PSCALEUNIT) + call printf (" %s = %g\n") + call pargstr (KY_ZMAG) + call pargr (apstatr (ap, ZMAG)) + call printf (" %s = %b\n") + call pargstr (KY_MKAPERT) + call pargb (itob (apstati (ap, MKAPERT))) + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/phot/apqcolon.x b/noao/digiphot/apphot/phot/apqcolon.x new file mode 100644 index 00000000..c3050190 --- /dev/null +++ b/noao/digiphot/apphot/phot/apqcolon.x @@ -0,0 +1,331 @@ +include <error.h> +include "../lib/apphot.h" +include "../lib/display.h" +include "../lib/noise.h" +include "../lib/center.h" +include "../lib/fitsky.h" +include "../lib/phot.h" + +# APQCOLON -- Procedure to display and edit the quick photometry parameters. + +procedure apqcolon (ap, im, cl, out, stid, ltid, cmdstr, newimage, newcbuf, + newcenter, newsbuf, newsky, newmagbuf, newmag) + +pointer ap # pointer to apphot structure +pointer im # pointer to the iraf image +int cl # coordinate file descriptor +int out # output file descriptor +int stid # output file sequence number +int ltid # coordinate file sequence number +char cmdstr[ARB] # command string +int newimage # new image ? +int newcbuf # new centering buffers ? +int newcenter # compute new center ? +int newsbuf # new sky fitting buffers ? +int newsky # compute new sky ? +int newmagbuf # new aperture buffers ? +int newmag # compute new magnitudes ? + +bool bval +int ip, ncmd +pointer sp, cmd, str +real rval + +bool streq(), itob() +int btoi(), strdic(), nscan(), apstati(), ctowrd(), open() +pointer immap() +real apstatr() +errchk immap, open + +begin + # Allocate temporary space. + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + call salloc (str, SZ_LINE, TY_CHAR) + + # Get the command. + call sscan (cmdstr) + call gargwrd (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call sfree (sp) + return + } + + # Process the command + ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, QCMDS) + switch (ncmd) { + case QCMD_SHOW: + call printf ("\n") + call ap_qshow (ap) + call printf ("\n") + + case QCMD_CBOXWIDTH: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_CAPERT) + call pargr (2.0 * apstatr (ap, CAPERT)) + call pargstr ("pixels") + } else { + call apsetr (ap, CAPERT, rval / 2.0) + if (stid > 1) + call ap_rparam (out, KY_CAPERT, rval, UN_CSCALEUNIT, + "width of the centering box") + newcbuf = YES + newcenter = YES + } + + case QCMD_ANNULUS: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_ANNULUS) + call pargr (apstatr (ap, ANNULUS)) + call pargstr ("pixels") + } else { + call apsetr (ap, ANNULUS, rval) + if (stid > 1) + call ap_rparam (out, KY_ANNULUS, rval, UN_SSCALEUNIT, + "inner radius of the sky annulus") + newsbuf = YES + newsky = YES + } + + case QCMD_DANNULUS: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_DANNULUS) + call pargr (apstatr (ap, DANNULUS)) + call pargstr ("pixels") + } else { + call apsetr (ap, DANNULUS, rval) + if (stid > 1) + call ap_rparam (out, KY_DANNULUS, rval, UN_SSCALEUNIT, + "width of the sky annulus") + newsbuf = YES + newsky = YES + } + + case QCMD_APERTURES: + call gargwrd (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call apstats (ap, APERTS, Memc[cmd], SZ_LINE) + call printf ("%s = %s %s\n") + call pargstr (KY_APERTS) + call pargstr (Memc[cmd]) + call pargstr ("pixels") + } else { + call apsets (ap, APERTS, Memc[cmd]) + if (stid > 1) + call ap_sparam (out, KY_APERTS, Memc[cmd], UN_PSCALEUNIT, + "list of aperture radii") + newmag = YES + newmagbuf = YES + } + + case QCMD_ZMAG: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g\n") + call pargstr (KY_ZMAG) + call pargr (apstatr (ap, ZMAG)) + } else { + call apsetr (ap, ZMAG, rval) + if (stid > 1) + call ap_rparam (out, KY_ZMAG, rval, UN_PZMAG, + "zero point of magnitude scale") + newmag = YES + } + + case QCMD_EPADU: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g\n") + call pargstr (KY_EPADU) + call pargr (apstatr (ap, EPADU)) + } else { + call apsetr (ap, EPADU, rval) + if (stid > 1) + call ap_rparam (out, KY_EPADU, rval, UN_NEPADU, "gain") + newmag = YES + } + + case QCMD_EXPOSURE: + call gargstr (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call apstats (ap, EXPOSURE, Memc[str], SZ_FNAME) + call printf ("%s = %s\n") + call pargstr (KY_EXPOSURE) + call pargstr (Memc[str]) + } else { + ip = 1 + if (ctowrd (Memc[cmd], ip, Memc[str], SZ_FNAME) <= 0) + Memc[str] = EOS + call apsets (ap, EXPOSURE, Memc[str]) + if (im != NULL) + call ap_itime (im, ap) + if (stid > 1) + call ap_sparam (out, KY_EXPOSURE, Memc[str], + UN_AKEYWORD, "exposure time keyword") + } + + case QCMD_AIRMASS: + call gargstr (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call apstats (ap, AIRMASS, Memc[str], SZ_FNAME) + call printf ("%s = %s\n") + call pargstr (KY_AIRMASS) + call pargstr (Memc[str]) + } else { + ip = 1 + if (ctowrd (Memc[cmd], ip, Memc[str], SZ_FNAME) <= 0) + Memc[str] = EOS + call apsets (ap, AIRMASS, Memc[str]) + if (im != NULL) + call ap_airmass (im, ap) + if (stid > 1) + call ap_sparam (out, KY_AIRMASS, Memc[str], + UN_AKEYWORD, "airmass keyword") + } + + case QCMD_FILTER: + call gargstr (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call apstats (ap, FILTER, Memc[str], SZ_FNAME) + call printf ("%s = %s\n") + call pargstr (KY_FILTER) + call pargstr (Memc[str]) + } else { + ip = 1 + if (ctowrd (Memc[cmd], ip, Memc[str], SZ_FNAME) <= 0) + Memc[str] = EOS + call apsets (ap, FILTER, Memc[str]) + if (im != NULL) + call ap_filter (im, ap) + if (stid > 1) + call ap_sparam (out, KY_FILTER, Memc[str], + UN_AKEYWORD, "filter keyword") + } + + case QCMD_OBSTIME: + call gargstr (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call apstats (ap, OBSTIME, Memc[str], SZ_FNAME) + call printf ("%s = %s\n") + call pargstr (KY_OBSTIME) + call pargstr (Memc[str]) + } else { + ip = 1 + if (ctowrd (Memc[cmd], ip, Memc[str], SZ_FNAME) <= 0) + Memc[str] = EOS + call apsets (ap, OBSTIME, Memc[str]) + if (im != NULL) + call ap_otime (im, ap) + if (stid > 1) + call ap_sparam (out, KY_OBSTIME, Memc[str], + UN_AKEYWORD, "filter keyword") + } + + case QCMD_RADPLOTS: + call gargb (bval) + if (nscan () == 1) { + call printf ("%s = %b\n") + call pargstr (KY_RADPLOTS) + call pargb (itob (apstati (ap, RADPLOTS))) + } else { + call apseti (ap, RADPLOTS, btoi (bval)) + } + + case QCMD_IMAGE: + call gargwrd (Memc[cmd], SZ_LINE) + call apstats (ap, IMNAME, Memc[str], SZ_FNAME) + if (Memc[cmd] == EOS || streq (Memc[cmd], Memc[str])) { + call printf ("%s = %s\n") + call pargstr (KY_IMNAME) + call pargstr (Memc[str]) + } else { + if (im != NULL) { + call imunmap (im) + im = NULL + } + iferr { + im = immap (Memc[cmd], READ_ONLY, 0) + } then { + call erract (EA_WARN) + call printf ("Reopening image %s.\n") + call pargstr (Memc[str]) + im = immap (Memc[str], READ_ONLY, 0) + } else { + call apimkeys (ap, im, Memc[cmd]) + newimage = YES + newcbuf = YES; newcenter = YES + newsbuf = YES; newsky = YES + newmagbuf = YES; newmag = YES + } + } + + case QCMD_COORDS: + call gargwrd (Memc[cmd], SZ_LINE) + call apstats (ap, CLNAME, Memc[str], SZ_FNAME) + if (Memc[cmd] == EOS || streq (Memc[cmd], Memc[str])) { + call printf ("%s: %s\n") + call pargstr (KY_CLNAME) + call pargstr (Memc[str]) + } else { + if (cl != NULL) { + call close( cl) + cl = NULL + } + iferr { + cl = open (Memc[cmd], READ_ONLY, TEXT_FILE) + } then { + cl = NULL + call erract (EA_WARN) + call apsets (ap, CLNAME, "") + call apsets (ap, CLROOT, "") + call printf ("Coordinate file is undefined.\n") + } else { + call apsets (ap, CLNAME, Memc[cmd]) + call apfroot (Memc[cmd], Memc[str], SZ_FNAME) + call apsets (ap, CLROOT, Memc[str]) + ltid = 0 + } + } + + case QCMD_OUTPUT: + call gargwrd (Memc[cmd], SZ_LINE) + call apstats (ap, OUTNAME, Memc[str], SZ_FNAME) + if (Memc[cmd] == EOS || streq (Memc[cmd], Memc[str])) { + call printf ("%s = %s\n") + call pargstr (KY_OUTNAME) + call pargstr (Memc[str]) + } else { + if (out != NULL) { + call close (out) + out = NULL + if (stid <= 1) + call delete (Memc[str]) + } + iferr { + out = open (Memc[cmd], READ_ONLY, TEXT_FILE) + } then { + call erract (EA_WARN) + call printf ("Reopening output file: %s\n") + call pargstr (Memc[str]) + if (Memc[str] != EOS) + out = open (Memc[str], APPEND, TEXT_FILE) + else + out = NULL + } else { + call apsets (ap, OUTNAME, Memc[cmd]) + stid = 1 + } + } + + default: + call printf ("Unknown or ambiguous colon command\7\n") + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/phot/apqphot.x b/noao/digiphot/apphot/phot/apqphot.x new file mode 100644 index 00000000..b3c80b73 --- /dev/null +++ b/noao/digiphot/apphot/phot/apqphot.x @@ -0,0 +1,494 @@ +include <ctype.h> +include <gset.h> +include <imhdr.h> +include "../lib/phot.h" +include "../lib/apphot.h" +include "../lib/display.h" +include "../lib/center.h" +include "../lib/fitsky.h" + +define HELPFILE "apphot$phot/qphot.key" + +# APQPHOT -- Procedure to compute quick magnitudes for a list of objects + +int procedure apqphot (ap, im, cl, gd, mgd, id, out, stid, interactive, cache) + +pointer ap # pointer to apphot structure +pointer im # pointer to IRAF image +int cl # the coordinate list descriptor +pointer gd # pointer to graphcis descriptor +pointer mgd # pointer to the metacode file +pointer id # pointer to image display stream +int out # output file descriptor +int stid # output file sequence number +int interactive # interactive mode +int cache # cache the input image pixels + +real wx, wy, xlist, ylist +pointer sp, cmd +int newskybuf, newsky, newcenterbuf, newcenter, newmagbuf, newmag +int newimage, newlist, ip, wcs, key, colonkey, cier, sier, pier +int ltid, oid, prev_num, req_num, req_size, old_size, buf_size, memstat + +real apstatr() +int clgcur(), apfitsky(), aprefitsky(), apfitcenter(), aprefitcenter() +int apmag(), apremag(), apstati(), apgqverify(), apnew(), ctoi() +int apgtverify(), apgscur(), ap_avsky(), ap_memstat(), sizeof() +bool fp_equalr() + +define endswitch_ 99 + +begin + # Initialize. + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + # Initialize cursor command. + key = ' ' + Memc[cmd] = EOS + + # Initialize the fitting parameters. + newimage = NO + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newmagbuf = YES; newmag = YES + cier = AP_OK; sier = AP_OK; pier = AP_OK + + # Initialize the sequencing. + newlist = NO + ltid = 0 + + # Loop over the coordinate file. + while (clgcur ("icommands", wx, wy, wcs, key, Memc[cmd], SZ_LINE) != + EOF) { + + # Store the current cursor coordinates. + call ap_vtol (im, wx, wy, wx, wy, 1) + call apsetr (ap, CWX, wx) + call apsetr (ap, CWY, wy) + + if (apnew (ap, wx, wy, xlist, ylist, newlist) == YES) { + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newmagbuf = YES; newmag = YES + } + + # Store previous cursor coordinates. + call apsetr (ap, WX, apstatr (ap, CWX)) + call apsetr (ap, WY, apstatr (ap, CWY)) + + # Loop over the colon keystroke commands. + switch (key) { + + # Quit. + case 'q': + if (interactive == YES) { + if (apgqverify ("qphot", ap, key) == YES) { + call sfree (sp) + return (apgtverify (key)) + } + } else { + call sfree (sp) + return (NO) + } + + # Print out error messages. + case 'e': + if (interactive == YES) + call ap_perrors (ap, cier, sier, pier) + + # Print out the help page(s). + case '?': + if ((id != NULL) && (id == gd)) + call gpagefile (id, HELPFILE, "") + else if (gd != NULL) + call pagefile (HELPFILE, "[space=morehelp,q=quit,?=help]") + + # Process apphot colon commands. + case ':': + for (ip = 1; IS_WHITE(Memc[cmd+ip-1]); ip = ip + 1) + ; + colonkey = Memc[cmd+ip-1] + switch (colonkey) { + case 'm', 'n': + + # Show/set a qphot parameter. + if (Memc[cmd+ip] != EOS && Memc[cmd+ip] != ' ') { + call apqcolon (ap, im, cl, out, stid, ltid, Memc[cmd], + newimage, newcenterbuf, newcenter, newskybuf, + newsky, newmagbuf, newmag) + goto endswitch_ + } + + # No coordinate list. + if (cl == NULL) { + if (interactive == YES) + call printf ("No coordinate list\n") + goto endswitch_ + } + + # Get the next object. + ip = ip + 1 + prev_num = ltid + if (ctoi (Memc[cmd], ip, req_num) <= 0) + req_num = ltid + 1 + + # Fetch the next object from the list. + if (apgscur (cl, id, xlist, ylist, prev_num, req_num, + ltid) == EOF) { + if (interactive == YES) + call printf ( + "End of coordinate list, use r key to rewind\n") + goto endswitch_ + } + + # Convert the coordinates. + switch (apstati (ap, WCSIN)) { + case WCS_PHYSICAL, WCS_WORLD: + call ap_itol (ap, xlist, ylist, xlist, ylist, 1) + case WCS_TV: + call ap_vtol (im, xlist, ylist, xlist, ylist, 1) + default: + ; + } + + # Move to the next object. + newlist = YES + if (colonkey == 'm') { + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newmagbuf = YES; newmag = YES + goto endswitch_ + } + + # Measure object. + cier = apfitcenter (ap, im, xlist, ylist) + sier = apfitsky (ap, im, apstatr (ap, XCENTER), + apstatr (ap, YCENTER), NULL, gd) + pier = apmag (ap, im, apstatr (ap, XCENTER), apstatr (ap, + YCENTER), apstati (ap, POSITIVE), apstatr (ap, + SKY_MODE), apstatr(ap, SKY_SIGMA), apstati (ap, NSKY)) + if (id != NULL) { + call apmark (ap, id, apstati (ap, MKCENTER), + apstati (ap, MKSKY), apstati (ap, MKAPERT)) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_pplot (ap, im, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qpmag (ap, cier, sier, pier) + if (stid == 1) + call ap_param (ap, out, "qphot") + call ap_pmag (ap, out, stid, ltid, cier, sier, pier) + call ap_pplot (ap, im, stid, mgd, YES) + stid = stid + 1 + newcenterbuf = NO; newcenter = NO + newskybuf = NO; newsky = NO + newmagbuf = NO; newmag = NO + + default: + call apqcolon (ap, im, cl, out, stid, ltid, Memc[cmd], + newimage, newcenterbuf, newcenter, newskybuf, newsky, + newmagbuf, newmag) + } + + # Reestablish the correct viewport. + if (newimage == YES) { + if ((id != NULL) && (id != gd)) + call ap_gswv (id, Memc[cmd], im, 4) + req_size = MEMFUDGE * IM_LEN(im,1) * IM_LEN(im,2) * + sizeof (IM_PIXTYPE(im)) + memstat = ap_memstat (cache, req_size, old_size) + if (memstat == YES) + call ap_pcache (im, INDEFI, buf_size) + } + + newimage = NO + + # Save the current parameters in the pset files. + case 'w': + call ap_qppars (ap) + + # Plot a centered stellar radial profile. + case 'd': + if (interactive == YES) { + call ap_qrad (ap, im, wx, wy, gd) + newmagbuf = YES; newmag = YES + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + } + + # Rewind the list. + case 'r': + if (cl != NULL) { + call seek (cl, BOF) + ltid = 0 + } else if (interactive == YES) + call printf ("No coordinate list\n") + + # Process the remainder of the list. + case 'l': + if (cl != NULL) { + ltid = ltid + 1 + oid = stid + call apbphot (ap, im, cl, NULL, out, stid, ltid, gd, mgd, + id, YES) + ltid = ltid + stid - oid + 1 + if (id != NULL) { + if (id == gd) + call gflush (id) + else + call gframe (id) + } + } else if (interactive == YES) + call printf ("No coordinate list\n") + + # Get, measure next object in the list + case 'm', 'n': + + # No coordinate file. + if (cl == NULL) { + if (interactive == YES) + call printf ("No coordinate list\n") + goto endswitch_ + + } + + # Need to rewind the coordinate file. + prev_num = ltid + req_num = ltid + 1 + if (apgscur (cl, id, xlist, ylist, prev_num, req_num, + ltid) == EOF) { + if (interactive == YES) + call printf ( + "End of coordinate list, use r key to rewind\n") + goto endswitch_ + } + + # Convert coordinates if necessary. + switch (apstati (ap, WCSIN)) { + case WCS_PHYSICAL, WCS_WORLD: + call ap_itol (ap, xlist, ylist, xlist, ylist, 1) + case WCS_TV: + call ap_vtol (im, xlist, ylist, xlist, ylist, 1) + default: + ; + } + + # Move to next object. + newlist = YES + if (key == 'm') { + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newmagbuf = YES; newmag = YES + goto endswitch_ + } + + # Measure next object. + cier = apfitcenter (ap, im, xlist, ylist) + sier = apfitsky (ap, im, apstatr (ap, XCENTER), apstatr (ap, + YCENTER), NULL, gd) + pier = apmag (ap, im, apstatr (ap, XCENTER), apstatr (ap, + YCENTER), apstati (ap, POSITIVE), apstatr (ap, SKY_MODE), + apstatr (ap, SKY_SIGMA), apstati (ap, NSKY)) + if (id != NULL) { + call apmark (ap, id, apstati (ap, MKCENTER), apstati (ap, + MKSKY), apstati (ap, MKAPERT)) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_pplot (ap, im, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qpmag (ap, cier, sier, pier) + if (stid == 1) + call ap_param (ap, out, "qphot") + call ap_pmag (ap, out, stid, ltid, cier, sier, pier) + call ap_pplot (ap, im, stid, mgd, YES) + stid = stid + 1 + newcenterbuf = NO; newcenter = NO + newskybuf = NO; newsky = NO + newmagbuf = NO; newmag = NO + + # Setup phot parameters interactively. + case 'i': + if (interactive == YES) { + call ap_qradsetup (ap, im, wx, wy, gd, out, stid) + newmagbuf = YES; newmag = YES + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + } + + # Fit the center around the cursor position. + case 'c': + if (newcenterbuf == YES) + cier = apfitcenter (ap, im, wx, wy) + else if (newcenter == YES) + cier = aprefitcenter (ap, im, cier) + if (id != NULL) { + call apmark (ap, id, apstati (ap, MKCENTER), NO, NO) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_cplot (ap, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qcenter (ap, cier) + newcenterbuf = NO + newcenter = NO + + # Fit the sky around the cursor position. + case 't': + if (newskybuf == YES || ! fp_equalr (wx, + apstatr (ap, SXCUR)) || ! fp_equalr (wy, apstatr (ap, + SYCUR))) + sier = apfitsky (ap, im, wx, wy, NULL, gd) + else if (newsky == YES) + sier = aprefitsky (ap, im, gd) + if (id != NULL) { + call apmark (ap, id, NO, apstati (ap, MKSKY), NO) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_splot (ap, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qspsky (ap, sier) + newskybuf = NO; newsky = NO + + # Compute the average of several sky measurements around + # different cursor postions. + case 'a': + sier = ap_avsky (ap, im, stid, NULL, id, gd, interactive) + if (interactive == YES) + call ap_qaspsky (ap, sier) + newskybuf = NO; newsky = NO + + # Fit the sky around the current center position. + case 's': + if (newskybuf == YES || ! fp_equalr (apstatr (ap, XCENTER), + apstatr (ap, SXCUR)) || ! fp_equalr (apstatr (ap, SYCUR), + apstatr (ap, YCENTER))) + sier = apfitsky (ap, im, apstatr (ap, XCENTER), + apstatr (ap, YCENTER), NULL, gd) + else if (newsky == YES) + sier = aprefitsky (ap, im, gd) + if (id != NULL) { + call apmark (ap, id, NO, apstati (ap, MKSKY), NO) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_splot (ap, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qspsky (ap, sier) + newskybuf = NO + newsky = NO + + # Compute magnitudes around the cursor position using the current + # sky. + case 'p', 'o': + if (newcenterbuf == YES) + cier = apfitcenter (ap, im, wx, wy) + else if (newcenter == YES) + cier = aprefitcenter (ap, im, cier) + if (newmagbuf == YES || ! fp_equalr (apstatr (ap, XCENTER), + apstatr (ap, PXCUR)) || ! fp_equalr (apstatr (ap, + PYCUR), apstatr (ap, YCENTER))) + pier = apmag (ap, im, apstatr (ap, XCENTER), apstatr (ap, + YCENTER), apstati (ap, POSITIVE), apstatr (ap, + SKY_MODE), apstatr (ap, SKY_SIGMA), apstati (ap, NSKY)) + else + pier = apremag (ap, im, apstati (ap, POSITIVE), apstatr (ap, + SKY_MODE), apstatr (ap, SKY_SIGMA), apstati (ap, NSKY)) + if (id != NULL) { + call apmark (ap, id, NO, NO, apstati (ap, MKAPERT)) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + if (interactive == YES) + call ap_qpmag (ap, cier, sier, pier) + newmagbuf = NO; newmag = NO + + if (key == 'o') { + if (stid == 1) + call ap_param (ap, out, "qphot") + if (newlist == YES) + call ap_pmag (ap, out, stid, ltid, cier, sier, pier) + else + call ap_pmag (ap, out, stid, 0, cier, sier, pier) + call ap_pplot (ap, im, stid, mgd, YES) + stid = stid + 1 + } + + # Compute the center, sky, and magnitudes and save the results. + case 'f', ' ': + if (newcenterbuf == YES) + cier = apfitcenter (ap, im, wx, wy) + else if (newcenter == YES) + cier = aprefitcenter (ap, im, cier) + if (newskybuf == YES || ! fp_equalr (apstatr (ap, XCENTER), + apstatr (ap, SXCUR)) || ! fp_equalr (apstatr (ap, YCENTER), + apstatr (ap, SYCUR))) + sier = apfitsky (ap, im, apstatr (ap, XCENTER), apstatr (ap, + YCENTER), NULL, gd) + else if (newsky == YES) + sier = aprefitsky (ap, im, gd) + if (newmagbuf == YES || ! fp_equalr (apstatr (ap, XCENTER), + apstatr (ap, PXCUR)) || ! fp_equalr (apstatr (ap, YCENTER), + apstatr (ap, PYCUR))) + pier = apmag (ap, im, apstatr (ap, XCENTER), + apstatr (ap, YCENTER), apstati (ap, POSITIVE), + apstatr (ap, SKY_MODE), apstatr (ap, SKY_SIGMA), + apstati (ap, NSKY)) + else + pier = apremag (ap, im, apstati (ap, POSITIVE), apstatr (ap, + SKY_MODE), apstatr (ap, SKY_SIGMA), apstati (ap, NSKY)) + + if (id != NULL) { + call apmark (ap, id, apstati (ap, MKCENTER), apstati (ap, + MKSKY), apstati (ap, MKAPERT)) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_pplot (ap, im, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qpmag (ap, cier, sier, pier) + + newcenterbuf = NO; newcenter = NO + newskybuf = NO; newsky = NO + newmagbuf = NO; newmag = NO + + if (key == ' ') { + if (stid == 1) + call ap_param (ap, out, "qphot") + if (newlist == YES) + call ap_pmag (ap, out, stid, ltid, cier, sier, pier) + else + call ap_pmag (ap, out, stid, 0, cier, sier, pier) + call ap_pplot (ap, im, stid, mgd, YES) + stid = stid + 1 + } + + default: + call printf ("Unknown or ambiguous keystroke command\n") + } + +endswitch_ + # Setup for the next object. + key = ' ' + Memc[cmd] = EOS + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/phot/apqppars.x b/noao/digiphot/apphot/phot/apqppars.x new file mode 100644 index 00000000..cb87383b --- /dev/null +++ b/noao/digiphot/apphot/phot/apqppars.x @@ -0,0 +1,42 @@ +include "../lib/apphot.h" +include "../lib/center.h" +include "../lib/fitsky.h" +include "../lib/phot.h" +include "../lib/noise.h" +include "../lib/display.h" + +# AP_QPPARS -- Procedure to write out qthe phot task parameters. + +procedure ap_qppars (ap) + +pointer ap # pointer to apphot structure + +pointer mp, str +bool itob() +int apstati() +real apstatr() + +begin + call smark (mp) + call salloc (str, SZ_LINE, TY_CHAR) + + call clputr ("cbox", 2.0 * apstatr (ap, CAPERT)) + call clputr ("annulus", apstatr (ap, ANNULUS)) + call clputr ("dannulus", apstatr (ap, DANNULUS)) + call apstats (ap, APERTS, Memc[str], SZ_LINE) + call clpstr ("apertures", Memc[str]) + + call apstats (ap, EXPOSURE, Memc[str], SZ_LINE) + call clpstr ("exposure", Memc[str]) + call apstats (ap, AIRMASS, Memc[str], SZ_LINE) + call clpstr ("airmass", Memc[str]) + call apstats (ap, FILTER, Memc[str], SZ_LINE) + call clpstr ("filter", Memc[str]) + call apstats (ap, OBSTIME, Memc[str], SZ_LINE) + call clpstr ("obstime", Memc[str]) + call clputr ("epadu", apstatr (ap, EPADU)) + call clputr ("zmag", apstatr (ap, ZMAG)) + call clputb ("radplots", itob (apstati (ap, RADPLOTS))) + + call sfree (mp) +end diff --git a/noao/digiphot/apphot/phot/apqradsetup.x b/noao/digiphot/apphot/phot/apqradsetup.x new file mode 100644 index 00000000..233cd8a7 --- /dev/null +++ b/noao/digiphot/apphot/phot/apqradsetup.x @@ -0,0 +1,105 @@ +include "../lib/apphot.h" +include "../lib/display.h" +include "../lib/fitsky.h" +include "../lib/center.h" + +define HELPFILE "apphot$phot/iqphot.key" + +# AP_QRADSETUP -- Procedure to set up phot interactively using a radial profile +# plot of a bright star. + +procedure ap_qradsetup (ap, im, wx, wy, gd, out, stid) + +pointer ap # pointer to apphot structure +pointer im # pointer to the IRAF image +real wx, wy # cursor coordinates +pointer gd # pointer to graphics stream +int out # output file descriptor +int stid # output file sequence number + +int cier, sier, pier, wcs, key +pointer sp, str, cmd +real xcenter, ycenter, rmin, rmax, imin, imax, xc, yc, rval +real u1, u2, v1, v2, x1, x2, y1, y2 + +int apfitcenter(), apfitsky(), ap_wmag(), apstati(), clgcur(), ap_showplot() +real apstatr(), ap_ccapert(), ap_cannulus(), ap_cdannulus() + +begin + # Check for open graphics stream + if (gd == NULL) + return + call greactivate (gd, 0) + + # Store the viewport and window coordinates. + call ggview (gd, u1, u2, v1, v2) + call ggwind (gd, x1, x2, y1, y2) + + # Plot the radial profile. + if (ap_showplot (ap, im, wx, wy, gd, xcenter, ycenter, rmin, rmax, + imin, imax) == ERR) { + call gdeactivate (gd, 0) + return + } + + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + call salloc (str, SZ_LINE, TY_CHAR) + + call printf ( + "Waiting for setup menu command (?=help, v=default setup, q=quit):\n") + while (clgcur ("gcommands", xc, yc, wcs, key, Memc[cmd], + SZ_LINE) != EOF) { + + switch (key) { + + case 'q': + break + case '?': + call gpagefile (gd, HELPFILE, "") + case 'c': + rval = ap_ccapert (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'a': + rval = ap_cannulus (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'd': + rval = ap_cdannulus (ap, gd, out, stid, apstatr (ap, ANNULUS), + rmin, rmax, imin, imax) + case 'r': + call ap_caper (ap, gd, out, stid, Memc[str], rmin, rmax, + imin, imax) + case 'v': + rval = ap_ccapert (ap, gd, out, stid, rmin, rmax, imin, imax) + rval = ap_cannulus (ap, gd, out, stid, rmin, rmax, imin, imax) + rval = ap_cdannulus (ap, gd, out, stid, apstatr (ap, ANNULUS), + rmin, rmax, imin, imax) + call ap_caper (ap, gd, out, stid, Memc[str], rmin, rmax, + imin, imax) + default: + call printf ("Unknown or ambiguous keystroke command\007\n") + } + call printf ( + "Waiting for setup menu command (?=help, v=default setup, q=quit):\n") + } + call printf ( + "Interactive setup is complete. Type w to save parameters.\n") + + # Restore the viewport and window coordinates. + call gsview (gd, u1, u2, v1, v2) + call gswind (gd, x1, x2, y1, y2) + + call gdeactivate (gd, 0) + call sfree (sp) + + # Print the answer. + cier = apfitcenter (ap, im, xcenter, ycenter) + if (! IS_INDEFR (apstatr (ap, XCENTER)) && + ! IS_INDEFR (apstatr (ap, YCENTER))) + sier = apfitsky (ap, im, apstatr (ap, XCENTER), apstatr (ap, + YCENTER), NULL, gd) + if (! IS_INDEFR (apstatr (ap, SKY_MODE))) + pier = ap_wmag (ap, im, apstatr (ap, XCENTER), apstatr (ap, + YCENTER), apstati (ap, POSITIVE), apstatr (ap, SKY_MODE), + apstatr (ap, SKY_SIGMA), apstati (ap, NSKY)) + call ap_pplot (ap, im, 0, gd, apstati (ap, RADPLOTS)) + call ap_qpmag (ap, cier, sier, pier) +end diff --git a/noao/digiphot/apphot/phot/apqshow.x b/noao/digiphot/apphot/phot/apqshow.x new file mode 100644 index 00000000..d8a4b6db --- /dev/null +++ b/noao/digiphot/apphot/phot/apqshow.x @@ -0,0 +1,86 @@ +include "../lib/apphot.h" +include "../lib/noise.h" +include "../lib/display.h" +include "../lib/center.h" +include "../lib/fitsky.h" +include "../lib/phot.h" + +# AP_QSHOW -- Procedure to display the current data parameters. + +procedure ap_qshow (ap) + +pointer ap # pointer to the apphot strucuture + +pointer sp, str +bool itob() +int apstati() +real apstatr() + +begin + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + + # Set the object charactersitics. + call printf ("Quick Phot Parameters\n") + call printf (" %s: %s (%.2f,%.2f) %s: %s\n") + call apstats (ap, IMNAME, Memc[str], SZ_FNAME) + call pargstr (KY_IMNAME) + call pargstr (Memc[str]) + call pargr (apstatr (ap, CWX)) + call pargr (apstatr (ap, CWY)) + call apstats (ap, OUTNAME, Memc[str], SZ_FNAME) + call pargstr (KY_OUTNAME) + call pargstr (Memc[str]) + + call printf (" %s: %s\n") + call apstats (ap, CLNAME, Memc[str], SZ_FNAME) + call pargstr (KY_CLNAME) + call pargstr (Memc[str]) + + call printf (" %s = %g %s\n") + call pargstr (KY_CAPERT) + call pargr (2.0* apstatr (ap, CAPERT)) + call pargstr ("pixels") + + call printf (" %s = %g %s %s = %g %s\n") + call pargstr (KY_ANNULUS) + call pargr (apstatr (ap, ANNULUS)) + call pargstr ("pixels") + call pargstr (KY_DANNULUS) + call pargr (apstatr (ap, DANNULUS)) + call pargstr ("pixels") + + call apstats (ap, APERTS, Memc[str], SZ_FNAME) + call printf (" %s = %s %s %s = %g %s\n") + call pargstr (KY_APERTS) + call pargstr (Memc[str]) + call pargstr ("pixels") + call pargstr (KY_ZMAG) + call pargr (apstatr (ap, ZMAG)) + call pargstr (UN_PZMAG) + + call printf (" %s = %g %s\n") + call pargstr (KY_EPADU) + call pargr (apstatr (ap, EPADU)) + call pargstr (UN_NEPADU) + call printf (" %s = %s %s = %s\n") + call apstats (ap, EXPOSURE, Memc[str], SZ_FNAME) + call pargstr (KY_EXPOSURE) + call pargstr (Memc[str]) + call apstats (ap, AIRMASS, Memc[str], SZ_FNAME) + call pargstr (KY_AIRMASS) + call pargstr (Memc[str]) + call printf (" %s = %s %s = %s\n") + call apstats (ap, FILTER, Memc[str], SZ_FNAME) + call pargstr (KY_FILTER) + call pargstr (Memc[str]) + call apstats (ap, OBSTIME, Memc[str], SZ_FNAME) + call pargstr (KY_OBSTIME) + call pargstr (Memc[str]) + + call printf (" %s = %b\n") + call pargstr (KY_RADPLOTS) + call pargb (itob (apstati (ap, RADPLOTS))) + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/phot/apradsetup.x b/noao/digiphot/apphot/phot/apradsetup.x new file mode 100644 index 00000000..b7f47f41 --- /dev/null +++ b/noao/digiphot/apphot/phot/apradsetup.x @@ -0,0 +1,126 @@ +include "../lib/apphot.h" +include "../lib/display.h" +include "../lib/center.h" +include "../lib/fitsky.h" + +define HELPFILE "apphot$phot/iphot.key" + +# AP_RADSETUP -- Procedure to set up phot interactively using a radial profile +# plot of a bright star. + +procedure ap_radsetup (ap, im, wx, wy, gd, out, stid) + +pointer ap # pointer to apphot structure +pointer im # pointer to the IRAF image +real wx, wy # cursor coordinates +pointer gd # pointer to graphics stream +int out # output file descriptor +int stid # output file sequence number + +int cier, sier, pier, key, wcs +pointer sp, cmd, str +real xcenter, ycenter, xc, yc, rmin, rmax, imin, imax +real u1, u2, v1, v2, x1, x2, y1, y2, rval + +int apfitcenter(), apfitsky(), ap_wmag(), apstati(), clgcur(), ap_showplot() +real apstatr(), ap_cfwhmpsf(), ap_ccapert(), ap_cannulus(), ap_cdannulus() +real ap_csigma(), ap_crgrow(), ap_crclean(), ap_crclip() +real ap_cdatamin(), ap_cdatamax() + +begin + # Check for open graphics stream + if (gd == NULL) + return + call greactivate (gd, 0) + call gclear (gd) + + # Store the viewport and window coordinates. + call ggview (gd, u1, u2, v1, v2) + call ggwind (gd, x1, x2, y1, y2) + + # Make the plot. + if (ap_showplot (ap, im, wx, wy, gd, xcenter, ycenter, rmin, rmax, + imin, imax) == ERR) { + call gdeactivate (gd, 0) + return + } + + # Initialize. + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + call salloc (str, SZ_LINE, TY_CHAR) + + call printf ( + "Waiting for setup menu command (?=help, v=default setup, q=quit):\n") + while (clgcur ("gcommands", xc, yc, wcs, key, Memc[cmd], + SZ_LINE) != EOF) { + + switch (key) { + + case 'q': + break + case '?': + call gpagefile (gd, HELPFILE, "") + case 'f': + rval = ap_cfwhmpsf (ap, gd, out, stid, rmin, rmax, imin, imax) + case 's': + rval = ap_csigma (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'l': + rval = ap_cdatamin (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'u': + rval = ap_cdatamax (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'c': + rval = ap_ccapert (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'n': + rval = ap_crclean (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'p': + rval = ap_crclip (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'a': + rval = ap_cannulus (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'd': + rval = ap_cdannulus (ap, gd, out, stid, apstatr (ap, ANNULUS), + rmin, rmax, imin, imax) + case 'g': + rval = ap_crgrow (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'r': + call ap_caper (ap, gd, out, stid, Memc[str], rmin, rmax, + imin, imax) + case 'v': + rval = ap_cfwhmpsf (ap, gd, out, stid, rmin, rmax, imin, imax) + rval = ap_ccapert (ap, gd, out, stid, rmin, rmax, imin, imax) + rval = ap_csigma (ap, gd, out, stid, rmin, rmax, imin, imax) + #rval = ap_ccthresh (ap, gd, out, stid, rmin, rmax, imin, imax) + rval = ap_cannulus (ap, gd, out, stid, rmin, rmax, imin, imax) + rval = ap_cdannulus (ap, gd, out, stid, apstatr (ap, ANNULUS), + rmin, rmax, imin, imax) + call ap_caper (ap, gd, out, stid, Memc[str], rmin, rmax, + imin, imax) + default: + call printf ("Unknown or ambiguous keystroke command\007\n") + } + call printf ( + "Waiting for setup menu command (?=help, v=default setup, q=quit):\n") + } + call printf ( + "Interactive setup is complete. Type w to save parameters.\n") + + # Restore the viewport and window coordinates. + call gsview (gd, u1, u2, v1, v2) + call gswind (gd, x1, x2, y1, y2) + + call gdeactivate (gd, 0) + call sfree (sp) + + # Compute and print the answer. + cier = apfitcenter (ap, im, xcenter, ycenter) + if (! IS_INDEFR (apstatr (ap, XCENTER)) && + ! IS_INDEFR (apstatr (ap, YCENTER))) + sier = apfitsky (ap, im, apstatr (ap, XCENTER), apstatr (ap, + YCENTER), NULL, gd) + if (! IS_INDEFR (apstatr (ap, SKY_MODE))) + pier = ap_wmag (ap, im, apstatr (ap, XCENTER), apstatr (ap, + YCENTER), apstati (ap, POSITIVE), apstatr (ap, SKY_MODE), + apstatr (ap, SKY_SIGMA), apstati (ap, NSKY)) + call ap_pplot (ap, im, 0, gd, apstati (ap, RADPLOTS)) + call ap_qpmag (ap, cier, sier, pier) +end diff --git a/noao/digiphot/apphot/phot/apremag.x b/noao/digiphot/apphot/phot/apremag.x new file mode 100644 index 00000000..9cf705d4 --- /dev/null +++ b/noao/digiphot/apphot/phot/apremag.x @@ -0,0 +1,77 @@ +include <mach.h> +include "../lib/apphotdef.h" +include "../lib/apphot.h" +include "../lib/noisedef.h" +include "../lib/photdef.h" +include "../lib/phot.h" + +# APREMAG -- Procedure to recompute the magnitudes inside a set of apertures +# given that the sums and effective areas have already been computed. + +int procedure apremag (ap, im, positive, skyval, skysig, nsky) + +pointer ap # pointer to the apphot structure +pointer im # the input image descriptor +int positive # emission and absorption features +real skyval # sky value +real skysig # sigma of sky +int nsky # number of sky pixels + +int nap +pointer nse, phot +real zmag + +begin + # Initalize. + phot = AP_PPHOT(ap) + nse = AP_NOISE(ap) + call amovkr (INDEFR, Memr[AP_MAGS(phot)], AP_NAPERTS(phot)) + call amovkr (INDEFR, Memr[AP_MAGERRS(phot)], AP_NAPERTS(phot)) + if (IS_INDEFR(AP_PXCUR(phot)) || IS_INDEFR(AP_PYCUR(phot))) { + AP_OPXCUR(phot) = AP_PXCUR(phot) + AP_OPYCUR(phot) = AP_PYCUR(phot) + } else { + switch (AP_WCSOUT(ap)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_ltoo (ap, AP_PXCUR(phot), AP_PYCUR(phot), + AP_OPXCUR(phot), AP_OPYCUR(phot), 1) + case WCS_TV: + call ap_ltov (im, AP_PXCUR(phot), AP_PYCUR(phot), + AP_OPXCUR(phot), AP_OPYCUR(phot), 1) + default: + AP_OPXCUR(phot) = AP_PXCUR(phot) + AP_OPYCUR(phot) = AP_PYCUR(phot) + } + } + + # Check for errors. + if (IS_INDEFR(AP_PXCUR(phot)) || IS_INDEFR(AP_PYCUR(phot))) + return (AP_APERT_NOAPERT) + if (IS_INDEFR(skyval)) + return (AP_APERT_NOSKYMODE) + + nap = min (AP_NMINAP(phot) - 1, AP_NMAXAP(phot)) + + # Compute the magnitudes and errors. + if (positive == YES) + call apcopmags (Memd[AP_SUMS(phot)], Memd[AP_AREA(phot)], + Memr[AP_MAGS(phot)], Memr[AP_MAGERRS(phot)], nap, + skyval, skysig, nsky, AP_ZMAG(phot), AP_NOISEFUNCTION(nse), + AP_EPADU(nse)) + else + call apconmags (Memd[AP_SUMS(phot)], Memd[AP_AREA(phot)], + Memr[AP_MAGS(phot)], Memr[AP_MAGERRS(phot)], nap, + skyval, skysig, nsky, AP_ZMAG(phot), AP_NOISEFUNCTION(nse), + AP_EPADU(nse), AP_READNOISE(nse)) + + # Correct for itime. + zmag = 2.5 * log10 (AP_ITIME(ap)) + call aaddkr (Memr[AP_MAGS(phot)], zmag, Memr[AP_MAGS(phot)], nap) + + if (AP_NMAXAP(phot) < AP_NAPERTS(phot)) + return (AP_APERT_OUTOFBOUNDS) + else if (AP_NMINAP(phot) <= AP_NMAXAP(phot)) + return (AP_APERT_BADDATA) + else + return (AP_OK) +end diff --git a/noao/digiphot/apphot/phot/iphot.key b/noao/digiphot/apphot/phot/iphot.key new file mode 100644 index 00000000..679f2d50 --- /dev/null +++ b/noao/digiphot/apphot/phot/iphot.key @@ -0,0 +1,18 @@ + Interactive Phot Setup Menu + + v Mark and verify the critical parameters (f,s,c,a,d,r) + + f Mark and verify the full-width half-maximum of psf + s Mark and verify the standard deviation of the background + l Mark and verify the minimum good data value + u Mark and verify the maximum good data value + + c Mark and verify the centering box width + n Mark and verify the cleaning radius + p Mark and verify the clipping radius + + a Mark and verify the inner radius of the sky annulus + d Mark and verify the width of the sky annulus + g Mark and verify the region growing radius + + r Mark and verify the aperture radii diff --git a/noao/digiphot/apphot/phot/iqphot.key b/noao/digiphot/apphot/phot/iqphot.key new file mode 100644 index 00000000..426bd523 --- /dev/null +++ b/noao/digiphot/apphot/phot/iqphot.key @@ -0,0 +1,8 @@ + Interactive Qphot Setup Menu + + v Mark and verify the critical parameters (c,a,d,r) + + c Mark and verify the centering box width + a Mark and verify the inner radius of the sky annulus + d Mark and verify the width of the sky annulus + r Mark and verify the aperture radii diff --git a/noao/digiphot/apphot/phot/mkpkg b/noao/digiphot/apphot/phot/mkpkg new file mode 100644 index 00000000..8ca684f8 --- /dev/null +++ b/noao/digiphot/apphot/phot/mkpkg @@ -0,0 +1,81 @@ +# PHOT,QPHOT tasks + +$checkout libpkg.a ".." +$update libpkg.a +$checkin libpkg.a ".." +$exit + +libpkg.a: + # general photometry and PHOT task routines + + apbphot.x <fset.h> ../lib/apphot.h \ + ../lib/center.h ../lib/display.h \ + ../lib/fitsky.h + apcomags.x <mach.h> ../lib/noise.h + apgppars.x ../lib/center.h ../lib/fitsky.h \ + ../lib/phot.h ../lib/display.h \ + ../lib/noise.h + apmag.x <mach.h> ../lib/apphotdef.h \ + ../lib/noisedef.h ../lib/photdef.h \ + ../lib/apphot.h ../lib/phot.h + apmagbuf.x <imhdr.h> ../lib/apphotdef.h \ + ../lib/photdef.h ../lib/phot.h + apmeasure.x + apppars.x ../lib/display.h + appconfirm.x ../lib/apphot.h ../lib/noise.h \ + ../lib/center.h ../lib/fitsky.h \ + ../lib/phot.h + apperrors.x ../lib/phot.h + appfree.x ../lib/apphotdef.h ../lib/photdef.h + apphot.x <ctype.h> <gset.h> \ + ../lib/apphot.h ../lib/display.h \ + ../lib/center.h ../lib/fitsky.h \ + ../lib/phot.h <imhdr.h> + apphotcolon.x ../lib/noise.h ../lib/apphot.h \ + ../lib/display.h ../lib/fitsky.h \ + ../lib/center.h ../lib/phot.h \ + <gset.h> + appinit.x ../lib/apphotdef.h ../lib/photdef.h \ + ../lib/phot.h + appplot.x <gset.h> <pkg/gtools.h> \ + ../lib/apphot.h ../lib/noise.h \ + ../lib/center.h ../lib/fitsky.h \ + ../lib/phot.h + appmag.x ../lib/apphot.h ../lib/apphotdef.h \ + ../lib/fitsky.h ../lib/center.h \ + ../lib/photdef.h ../lib/phot.h + appshow.x ../lib/display.h ../lib/phot.h + apradsetup.x ../lib/fitsky.h ../lib/center.h \ + ../lib/display.h ../lib/apphot.h + apremag.x <mach.h> ../lib/apphotdef.h \ + ../lib/noisedef.h ../lib/photdef.h \ + ../lib/apphot.h ../lib/phot.h + t_phot.x <fset.h> <gset.h> \ + <lexnum.h> ../lib/apphot.h \ + ../lib/fitsky.h <imhdr.h> + + # QPHOT TASK SPECIFIC ROUTINES + + apgqppars.x "../lib/apphot.h" "../lib/display.h" \ + "../lib/noise.h" "../lib/center.h" \ + "../lib/fitsky.h" "../lib/phot.h" + apqppars.x "../lib/apphot.h" "../lib/display.h" \ + "../lib/noise.h" "../lib/center.h" \ + "../lib/fitsky.h" "../lib/phot.h" + apqphot.x <ctype.h> <gset.h> \ + "../lib/apphot.h" "../lib/display.h" \ + "../lib/center.h" "../lib/fitsky.h" \ + "../lib/phot.h" <imhdr.h> + apqradsetup.x "../lib/apphot.h" "../lib/display.h" \ + "../lib/center.h" "../lib/fitsky.h" + apqcolon.x "../lib/apphot.h" "../lib/display.h" \ + "../lib/noise.h" "../lib/center.h" \ + "../lib/fitsky.h" "../lib/phot.h" \ + <error.h> + apqshow.x "../lib/apphot.h" "../lib/display.h" \ + "../lib/noise.h" "../lib/center.h" \ + "../lib/fitsky.h" "../lib/phot.h" + t_qphot.x <fset.h> <gset.h> \ + <lexnum.h> ../lib/apphot.h \ + ../lib/fitsky.h <imhdr.h> + ; diff --git a/noao/digiphot/apphot/phot/phot.key b/noao/digiphot/apphot/phot/phot.key new file mode 100644 index 00000000..83e577fd --- /dev/null +++ b/noao/digiphot/apphot/phot/phot.key @@ -0,0 +1,109 @@ + Interactive Keystroke Commands + +? Print help +: Colon commands +v Verify the critical parameters +w Save the current parameters +d Plot radial profile of current star +i Interactively set parameters using current star +c Fit center for current star +t Fit sky around cursor +a Average sky values fit around several cursor positions +s Fit sky around current centered star +p Do photometry for current star, using current sky +o Do photometry for current star, using current sky, output results +f Do photometry for current star +spbar Do photometry for current star, output results +m Move to next star in coordinate list +n Do photometry for next star in coordinate list, output results +l Do photometry for remaining stars in coordinate list, output results +e Print error messages +r Rewind coordinate list +q Exit task + + +Photometry parameters are listed or set with the following commands. + + Colon commands + +:show [data/center/sky/phot] List the parameters +:m [n] Move to next [nth] star in coordinate list +:n [n] Do photometry for next [nth] star in coordinate list, output results + + Colon Parameter Editing Commands + +# Image and file name parameters + +:image [string] Image name +:coords [string] Coordinate file name +:output [string] Output file name + +# Data dependent parameters + +:scale [value] Image scale (units per pixel) +:fwhmpsf [value] Full width half maximum of PSF (scale units) +:emission [y/n] Emission feature (y), absorption (n) +:sigma [value] Standard deviation of sky (counts) +:datamin [value] Minimum good data value (counts) +:datamax [value] Maximum good data value (counts) + +# Noise parameters + +:noise [string] Noise model (constant|poisson) +:gain [string] Gain image header keyword +:ccdread [string] Readout noise image header keyword +:epadu [value] Gain (electrons per adu) +:readnoise [value] Readout noise (electrons) + +# Observations parameters + +:exposure [string] Exposure time image header keyword +:airmass [string] Airmass image header keyword +:filter [string] Filter image header keyword +:obstime [string] Time of observation image header keyword +:itime [value] Integration time (time units) +:xairmass [value] Airmass value (number) +:ifilter [string] Filter id string +:otime [string] Time of observation (time units) + +# Centering algorithm parameters + +:calgorithm [string] Centering algorithm +:cbox [value] Width of the centering box (scale units) +:cthreshold [value] Centering intensity threshold (sigma) +:cmaxiter [value] Maximum number of iterations +:maxshift [value] Maximum center shift (scale units) +:minsnratio [value] Minimum S/N ratio for centering +:clean [y/n] Clean subraster before centering +:rclean [value] Cleaning radius (scale units) +:rclip [value] Clipping radius (scale units) +:kclean [value] Clean K-sigma rejection limit (sigma) + +# Sky fitting algorithm parameters + +:salgorithm [string] Sky fitting algorithm +:skyvalue [value] User supplied sky value (counts) +:annulus [value] Inner radius of sky annulus (scale units) +:dannulus [value] Width of sky annulus (scale units) +:khist [value] Sky histogram extent (+/- sky sigma) +:binsize [value] Resolution of sky histogram (sky sigma) +:smooth [y/n] Lucy smooth the sky histogram +:sloclip [value] Low-side clipping factor in percent +:shiclip [value] High-side clipping factor in percent +:smaxiter [value] Maximum number of iterations +:snreject [value] Maximum number of rejection cycles +:sloreject [value] Low-side pixel rejection limits (sky sigma) +:shireject [value] High-side pixel rejection limits (sky sigma) +:rgrow [value] Region growing radius (scale units) + +# Photometry parameters + +:apertures [string] List of aperture radii (scale units) +:zmag [value] Zero point of magnitude scale + +# Plotting and marking parameters + +:mkcenter [y/n] Mark computed centers on display +:mksky [y/n] Mark the sky annuli on the display +:mkapert [y/n] Mark apertures on the display +:radplot [y/n] Plot radial profile of object diff --git a/noao/digiphot/apphot/phot/qphot.key b/noao/digiphot/apphot/phot/qphot.key new file mode 100644 index 00000000..ff4dd5b7 --- /dev/null +++ b/noao/digiphot/apphot/phot/qphot.key @@ -0,0 +1,48 @@ + Interactive Photometry Commands + +? Print help +: Colon commands +w Save the current parameters +d Plot radial profile of current star +i Interactively set parameters using current star +c Fit center of current star +t Fit sky around cursor +a Average sky values fit around several cursor positions +s Fit sky for current centered star +p Do photometry for current star, using current sky +o Do photometry for current star, using current sky, output results +f Do photometry for current star +spbar Do photometry for current star, output results +e Print error messages +m Move to next star in coordinate list +n Do photometry for next star in coordinate list, output results +l Do photometry for remaining stars in coordinate list, output results +r Rewind the coordinate list +q Exit task + + + Colon Commands + +:show List the parameters +:m [n] Move to next [nth] star in coordinate list +:n [n] Do photometry for next [nth] star in coordinate list, output results + + Colon Parameter Editing Commands + +:image [string] Image name +:output [string] Output file name +:coords [string] Coords file name + +:cbox [value] Width of the centering box (pixels) +:annulus [value] Inner radius of sky annulus (pixels) +:dannulus [value] Width of sky annulus (pixels) +:apertures [string] List of aperture radii (pixels) +:zmag [value] Zero point of magnitude scale (magnitudes) +:epadu [value] Gain (electrons per adu) + +:exposure [string] Exposure time image header keyword +:airmass [string] Airmass image header keyword +:filter [string] Filter image header keyword +:obstime [string] Time of observation image header keyword + +:radplot [y/n] Plot radial profile of object diff --git a/noao/digiphot/apphot/phot/t_phot.x b/noao/digiphot/apphot/phot/t_phot.x new file mode 100644 index 00000000..9d35c994 --- /dev/null +++ b/noao/digiphot/apphot/phot/t_phot.x @@ -0,0 +1,341 @@ +include <fset.h> +include <gset.h> +include <lexnum.h> +include <imhdr.h> +include "../lib/apphot.h" +include "../lib/fitsky.h" + +# T_PHOT -- Procedure to measure magnitudes inside a set of apertures for a list +# of stars in a list of images. + +procedure t_phot () + +pointer image # pointer name of the image +pointer output # pointer output file name +pointer coords # pointer to name of coords file +pointer skyfile # pointer to name of file with sky values +pointer plotfile # file of plot metacode +pointer graphics # graphics display device +pointer display # display device +int interactive # mode of use +int cache # cache the input image pixels in memory +int verify # verify critical parameters in batch mode +int update # update the critical parameters +int verbose # type messages on the terminal + +pointer sp, cname, outfname, str, ap, im, gd, mgd, id +int limlist, lclist, lolist, lslist, sid, lid, sd, out, cl, root, stat, pfd +int imlist, clist, olist, slist, memstat, old_size, wcs, req_size +int buf_size + +pointer immap(), gopen() +int imtlen(), imtgetim(), clplen(), clgfil(), btoi(), apstati(), strncmp() +int fnldir(), strlen(), apphot(), imtopenp(), clpopnu(), open(), clgwrd() +int ap_memstat(), sizeof() +bool clgetb(), streq() +errchk gopen + +begin + # Allocate temporary space. + call smark (sp) + call salloc (image, SZ_FNAME, TY_CHAR) + call salloc (output, SZ_FNAME, TY_CHAR) + call salloc (coords, SZ_FNAME, TY_CHAR) + call salloc (skyfile, SZ_FNAME, TY_CHAR) + call salloc (plotfile, SZ_FNAME, TY_CHAR) + call salloc (graphics, SZ_FNAME, TY_CHAR) + call salloc (display, SZ_FNAME, TY_CHAR) + call salloc (outfname, SZ_FNAME, TY_CHAR) + call salloc (cname, SZ_FNAME, TY_CHAR) + call salloc (str, SZ_LINE, TY_CHAR) + + # Set the standard output to flush on newline. + call fseti (STDOUT, F_FLUSHNL, YES) + + # Get the task parameters. + imlist = imtopenp ("image") + limlist = imtlen (imlist) + clist = clpopnu ("coords") + lclist = clplen (clist) + olist = clpopnu ("output") + lolist = clplen (olist) + + # Check that image and coordinate list lengths match. + if (limlist < 1 || (lclist > 1 && lclist != limlist)) { + call imtclose (imlist) + call clpcls (clist) + call clpcls (olist) + call error (0, "Imcompatible image and coordinate list lengths") + } + + # Check that image and output list lengths match. + if (lolist > 1 && lolist != limlist) { + call imtclose (imlist) + call clpcls (clist) + call clpcls (olist) + call error (0, "Imcompatible image and output list lengths") + } + + call clgstr ("icommands.p_filename", Memc[cname], SZ_FNAME) + if (Memc[cname] != EOS) + interactive = NO + #else if (lclist == 0) + #interactive = YES + else + interactive = btoi (clgetb ("interactive")) + cache = btoi (clgetb ("cache")) + verbose = btoi (clgetb ("verbose")) + verify = btoi (clgetb ("verify")) + update = btoi (clgetb ("update")) + + # Get the graphics and display devices. + call clgstr ("graphics", Memc[graphics], SZ_FNAME) + call clgstr ("display", Memc[display], SZ_FNAME) + + # Open the graphics and display devices. + if (interactive == YES) { + if (Memc[graphics] == EOS) + gd = NULL + else { + iferr { + gd = gopen (Memc[graphics], APPEND+AW_DEFER, STDGRAPH) + } then { + call eprintf ( + "Warning: Error opening graphics device.\n") + gd = NULL + } + } + if (Memc[display] == EOS) + id = NULL + else if (streq (Memc[graphics], Memc[display])) + id = gd + else { + iferr { + id = gopen (Memc[display], APPEND, STDIMAGE) + } then { + call eprintf ( + "Warning: Graphics overlay not available for display device.\n") + id = NULL + } + } + } else { + gd = NULL + id = NULL + } + + # Open the plot metacode file. + call clgstr ("plotfile", Memc[plotfile], SZ_FNAME) + if (Memc[plotfile] == EOS) + pfd = NULL + else + pfd = open (Memc[plotfile], APPEND, BINARY_FILE) + if (pfd != NULL) + mgd = gopen (Memc[graphics], NEW_FILE, pfd) + else + mgd = NULL + + # Intialize the phot structure. + call ap_gppars (ap) + + # Confirm the algorithm parameters. + if (verify == YES && interactive == NO) { + call ap_pconfirm (ap, NULL, 1) + if (update == YES) + call ap_ppars (ap) + } + + # Get the wcs information. + wcs = clgwrd ("wcsin", Memc[str], SZ_LINE, WCSINSTR) + if (wcs <= 0) { + call eprintf ( + "Warning: Setting the input coordinate system to logical\n") + wcs = WCS_LOGICAL + } + call apseti (ap, WCSIN, wcs) + wcs = clgwrd ("wcsout", Memc[str], SZ_LINE, WCSOUTSTR) + if (wcs <= 0) { + call eprintf ( + "Warning: Setting the output coordinate system to logical\n") + wcs = WCS_LOGICAL + } + call apseti (ap, WCSOUT, wcs) + + # Get the file name for the sky values. + if (apstati (ap, SKYFUNCTION) == AP_SKYFILE) { + slist = clpopnu ("skyfile") + lslist = clplen (slist) + if (limlist < 1 || (lslist > 1 && lslist != limlist)) { + call imtclose (imlist) + call clpcls (clist) + call clpcls (olist) + call clpcls (slist) + call error (0, "Imcompatible image and sky file list lengths") + } + } else + sd = NULL + + # Begin looping over the image list. + sid = 1 + while (imtgetim (imlist, Memc[image], SZ_FNAME) != EOF) { + + # Open the image and store image parameters. + im = immap (Memc[image], READ_ONLY, 0) + call apimkeys (ap, im, Memc[image]) + + # Set the image display viewport. + if ((id != NULL) && (id != gd)) + call ap_gswv (id, Memc[image], im, 4) + + # Cache the input image pixels. + req_size = MEMFUDGE * IM_LEN(im,1) * IM_LEN(im,2) * + sizeof (IM_PIXTYPE(im)) + memstat = ap_memstat (cache, req_size, old_size) + if (memstat == YES) + call ap_pcache (im, INDEFI, buf_size) + + # Open the coordinate file, where coords is assumed to be a simple + # text file in which the x and y positions are in columns 1 and 2 + # respectively and all remaining fields are ignored. + + if (lclist <= 0) { + cl = NULL + call strcpy ("", Memc[outfname], SZ_FNAME) + } else { + stat = clgfil (clist, Memc[coords], SZ_FNAME) + root = fnldir (Memc[coords], Memc[outfname], SZ_FNAME) + if (strncmp ("default", Memc[coords+root], 7) == 0 || root == + strlen (Memc[coords])) { + call ap_inname (Memc[image], Memc[outfname], "coo", + Memc[outfname], SZ_FNAME) + lclist = limlist + cl = open (Memc[outfname], READ_ONLY, TEXT_FILE) + } else if (stat != EOF) { + call strcpy (Memc[coords], Memc[outfname], SZ_FNAME) + cl = open (Memc[outfname], READ_ONLY, TEXT_FILE) + } else { + call apstats (ap, CLNAME, Memc[outfname], SZ_FNAME) + call seek (cl, BOF) + } + } + call apsets (ap, CLNAME, Memc[outfname]) + call apfroot (Memc[outfname], Memc[str], SZ_LINE) + call apsets (ap, CLROOT, Memc[str]) + + # Open the skys file. + if (lslist <= 0) { + sd = NULL + call strcpy ("", Memc[skyfile], SZ_FNAME) + } else if (clgfil (slist, Memc[skyfile], SZ_FNAME) != EOF) + sd = open (Memc[skyfile], READ_ONLY, TEXT_FILE) + else + call seek (sd, BOF) + #call apsets (ap, SKYNAME, Memc[skyfile]) + + # Open the output text file, if output is "default", dir$default or + # a directory specification then the extension "mag" is added to the + # image name and a suitable version number is appended to the output + # name. If output is the null string then no output file is created. + + if (lolist == 0) { + out = NULL + call strcpy ("", Memc[outfname], SZ_FNAME) + } else { + stat = clgfil (olist, Memc[output], SZ_FNAME) + root = fnldir (Memc[output], Memc[outfname], SZ_FNAME) + if (strncmp ("default", Memc[output+root], 7) == 0 || root == + strlen (Memc[output])) { + call apoutname (Memc[image], Memc[outfname], "mag", + Memc[outfname], SZ_FNAME) + out = open (Memc[outfname], NEW_FILE, TEXT_FILE) + lolist = limlist + } else if (stat != EOF) { + call strcpy (Memc[output], Memc[outfname], SZ_FNAME) + out = open (Memc[outfname], NEW_FILE, TEXT_FILE) + } else + call apstats (ap, OUTNAME, Memc[outfname], SZ_FNAME) + } + call apsets (ap, OUTNAME, Memc[outfname]) + + # Do aperture photometry. + if (interactive == NO) { + if (Memc[cname] != EOS) + stat = apphot (ap, im, cl, sd, NULL, mgd, NULL, out, sid, + NO, cache) + else if (cl != NULL) { + lid = 1 + call apbphot (ap, im, cl, sd, out, sid, lid, gd, mgd, id, + verbose) + stat = NO + } else + stat = NO + } else + stat = apphot (ap, im, cl, sd, gd, mgd, id, out, sid, YES, + cache) + + # Cleanup. + call imunmap (im) + if (cl != NULL) { + if (clplen(clist) > 1) + call close (cl) + } + if (sd != NULL) { + if (lslist > 1) + call close (sd) + } + if (out != NULL && lolist != 1) { + call close (out) + if (sid <= 1) { + call apstats (ap, OUTNAME, Memc[outfname], SZ_FNAME) + call delete (Memc[outfname]) + } + sid = 1 + } + + # Uncache memory. + call fixmem (old_size) + + if (stat == YES) + break + } + + + # Close the coordinate, sky and output files. + if (cl != NULL && lclist == 1) + call close (cl) + if (sd != NULL && lslist == 1) + call close (sd) + if (out != NULL && lolist == 1) { + call close (out) + if (sid <= 1) { + call apstats (ap, OUTNAME, Memc[outfname], SZ_FNAME) + call delete (Memc[outfname]) + } + } + + # Close up the plot files. + if (id == gd && id != NULL) + call gclose (id) + else { + if (gd != NULL) + call gclose (gd) + if (id != NULL) + call gclose (id) + } + if (mgd != NULL) + call gclose (mgd) + if (pfd != NULL) + call close (pfd) + + # Free the apphot data structures. + call appfree (ap) + + # Close the coord, sky and image lists. + call imtclose (imlist) + call clpcls (clist) + if (sd != NULL) + call clpcls (slist) + call clpcls (olist) + + # Free working space. + call sfree (sp) +end diff --git a/noao/digiphot/apphot/phot/t_qphot.x b/noao/digiphot/apphot/phot/t_qphot.x new file mode 100644 index 00000000..91174e78 --- /dev/null +++ b/noao/digiphot/apphot/phot/t_qphot.x @@ -0,0 +1,293 @@ +include <fset.h> +include <gset.h> +include <lexnum.h> +include <imhdr.h> +include "../lib/apphot.h" +include "../lib/fitsky.h" + +# T_QPHOT -- Procedure to measure magnitudes inside a set of apertures for a +# list of stars in a list of images. + +procedure t_qphot () + +pointer image # pointer name of the image +pointer output # pointer output file name +pointer coords # pointer to the coordinate file +pointer plotfile # file of plot metacode +pointer graphics # graphics display device +pointer display # display device +int cache # cache input image pixels in memory +int verbose # verbose mode + +pointer sp, outfname, cname, ap, im, gd, mgd, id, str +int limlist, lclist, lolist, cl, sid, lid, out, root, stat, pfd, interactive +int imlist, olist, clist, memstat, wcs, req_size, old_size, buf_size + +pointer immap(), gopen() +int imtlen(), imtgetim(), clplen(), clgfil(), btoi(), strncmp() +int fnldir(), strlen(), apqphot(), imtopenp(), clpopnu(), open() +int clgwrd(), ap_memstat(), sizeof() +bool clgetb(), streq() +errchk gopen + +begin + # Allocate temporary space. + call smark (sp) + call salloc (image, SZ_FNAME, TY_CHAR) + call salloc (coords, SZ_FNAME, TY_CHAR) + call salloc (output, SZ_FNAME, TY_CHAR) + call salloc (plotfile, SZ_FNAME, TY_CHAR) + call salloc (graphics, SZ_FNAME, TY_CHAR) + call salloc (display, SZ_FNAME, TY_CHAR) + call salloc (outfname, SZ_FNAME, TY_CHAR) + call salloc (cname, SZ_FNAME, TY_CHAR) + call salloc (str, SZ_FNAME, TY_CHAR) + + # Set the standard output to flush on newline. + call fseti (STDOUT, F_FLUSHNL, YES) + + # Get the task parameters. + imlist = imtopenp ("image") + limlist = imtlen (imlist) + clist = clpopnu ("coords") + lclist = clplen (clist) + olist = clpopnu ("output") + lolist = clplen (olist) + + # Check that image and coordinate list lengths match. + if (limlist < 1 || (lclist > 1 && lclist != limlist)) { + call imtclose (imlist) + call clpcls (clist) + call clpcls (olist) + call error (0, "Imcompatible image and coordinate list lengths") + } + + # Check that image and output list lengths match. + if (lolist > 1 && lolist != limlist) { + call imtclose (imlist) + call clpcls (olist) + call error (0, "Imcompatible image and output list lengths") + } + + # Intialize the phot structure. + call clgstr ("icommands.p_filename", Memc[cname], SZ_FNAME) + if (Memc[cname] != EOS) + interactive = NO + #else if (lclist == 0) + #interactive = YES + else + interactive = btoi (clgetb ("interactive")) + cache = btoi (clgetb ("cache")) + verbose = btoi (clgetb ("verbose")) + + # Get the parameters. + call ap_gqppars (ap) + + # Get the wcs information. + wcs = clgwrd ("wcsin", Memc[str], SZ_LINE, WCSINSTR) + if (wcs <= 0) { + call eprintf ( + "Warning: Setting the input coordinate system to logical\n") + wcs = WCS_LOGICAL + } + call apseti (ap, WCSIN, wcs) + wcs = clgwrd ("wcsout", Memc[str], SZ_LINE, WCSOUTSTR) + if (wcs <= 0) { + call eprintf ( + "Warning: Setting the output coordinate system to logical\n") + wcs = WCS_LOGICAL + } + call apseti (ap, WCSOUT, wcs) + + # Get the graphics and display devices. + call clgstr ("graphics", Memc[graphics], SZ_FNAME) + call clgstr ("display", Memc[display], SZ_FNAME) + + # Open the plot files. + if (interactive == YES) { + if (Memc[graphics] == EOS) + gd = NULL + else { + iferr { + gd = gopen (Memc[graphics], APPEND+AW_DEFER, STDGRAPH) + } then { + call eprintf ( + "Warning: Error opening graphics device.\n") + gd = NULL + } + } + if (Memc[display] == EOS) + id = NULL + else if (streq (Memc[graphics], Memc[display])) + id = gd + else { + iferr { + id = gopen (Memc[display], APPEND, STDIMAGE) + } then { + call eprintf ( + "Warning: Graphics overlay not available for display device.\n") + id = NULL + } + } + } else { + gd = NULL + id = NULL + } + + # Open the plot metacode file. + call clgstr ("plotfile", Memc[plotfile], SZ_FNAME) + if (Memc[plotfile] == EOS) + pfd = NULL + else + pfd = open (Memc[plotfile], APPEND, BINARY_FILE) + if (pfd != NULL) + mgd = gopen (Memc[graphics], NEW_FILE, pfd) + else + mgd = NULL + + # Begin looping over the image list. + sid = 1 + while (imtgetim (imlist, Memc[image], SZ_FNAME) != EOF) { + + # Open the image and store image parameters. + im = immap (Memc[image], READ_ONLY, 0) + call apimkeys (ap, im, Memc[image]) + + # Set the image display viewport. + if ((id != NULL) && (id != gd)) + call ap_gswv (id, Memc[image], im, 4) + + # Cache the input image pixels. + req_size = MEMFUDGE * IM_LEN(im,1) * IM_LEN(im,2) * + sizeof (IM_PIXTYPE(im)) + memstat = ap_memstat (cache, req_size, old_size) + if (memstat == YES) + call ap_pcache (im, INDEFI, buf_size) + + # Open the coordinate file, where coords is assumed to be a simple + # text file in which the x and y positions are in columns 1 and 2 + # respectively and all remaining fields are ignored. + + if (lclist <= 0) { + cl = NULL + call strcpy ("", Memc[outfname], SZ_FNAME) + } else { + stat = clgfil (clist, Memc[coords], SZ_FNAME) + root = fnldir (Memc[coords], Memc[outfname], SZ_FNAME) + if (strncmp ("default", Memc[coords+root], 7) == 0 || root == + strlen (Memc[coords])) { + call ap_inname (Memc[image], Memc[outfname], "coo", + Memc[outfname], SZ_FNAME) + lclist = limlist + cl = open (Memc[outfname], READ_ONLY, TEXT_FILE) + } else if (stat != EOF) { + call strcpy (Memc[coords], Memc[outfname], SZ_FNAME) + cl = open (Memc[outfname], READ_ONLY, TEXT_FILE) + } else { + call apstats (ap, CLNAME, Memc[outfname], SZ_FNAME) + call seek (cl, BOF) + } + } + call apsets (ap, CLNAME, Memc[outfname]) + call apfroot (Memc[outfname], Memc[str], SZ_FNAME) + call apsets (ap, CLROOT, Memc[str]) + + # Open the output text file, if output is "default", dir$default or + # a directory specification then the extension "mag" is added to the + # image name and a suitable version number is appended to the output + # name. If output is the null string then no output file is created. + + if (lolist == 0) { + out = NULL + call strcpy ("", Memc[outfname], SZ_FNAME) + } else { + stat = clgfil (olist, Memc[output], SZ_FNAME) + root = fnldir (Memc[output], Memc[outfname], SZ_FNAME) + if (strncmp ("default", Memc[output+root], 7) == 0 || root == + strlen (Memc[output])) { + call apoutname (Memc[image], Memc[outfname], "mag", + Memc[outfname], SZ_FNAME) + out = open (Memc[outfname], NEW_FILE, TEXT_FILE) + lolist = limlist + } else if (stat != EOF) { + call strcpy (Memc[output], Memc[outfname], SZ_FNAME) + out = open (Memc[outfname], NEW_FILE, TEXT_FILE) + } else + call apstats (ap, OUTNAME, Memc[outfname], SZ_FNAME) + } + call apsets (ap, OUTNAME, Memc[outfname]) + + # Do aperture photometry. + if (interactive == NO) { + if (Memc[cname] != EOS) + stat = apqphot (ap, im, cl, NULL, mgd, NULL, out, sid, NO, + cache) + else if (cl != NULL) { + lid = 1 + call apbphot (ap, im, cl, NULL, out, sid, lid, gd, mgd, id, + verbose) + stat = NO + } else + stat = NO + } else + stat = apqphot (ap, im, cl, gd, mgd, id, out, sid, YES, cache) + + # Cleanup. + call imunmap (im) + if (cl != NULL) { + if (lclist > 1) + call close (cl) + } + if (out != NULL && lolist != 1) { + call close (out) + if (sid <= 1) { + call apstats (ap, OUTNAME, Memc[outfname], SZ_FNAME) + call delete (Memc[outfname]) + } + sid = 1 + } + + # Uncache memory. + call fixmem (old_size) + + if (stat == YES) + break + } + + + # Close the coordinate, sky and output files. + if (cl != NULL && lclist == 1) + call close (cl) + if (out != NULL && lolist == 1) { + call close (out) + if (sid <= 1) { + call apstats (ap, OUTNAME, Memc[outfname], SZ_FNAME) + call delete (Memc[outfname]) + } + } + + # Close up the plot files. + if (id == gd && id != NULL) + call gclose (id) + else { + if (gd != NULL) + call gclose (gd) + if (id != NULL) + call gclose (id) + } + if (mgd != NULL) + call gclose (mgd) + if (pfd != NULL) + call close (pfd) + + # Free the apphot data structure. + call appfree (ap) + + # Close the coord, sky and image lists. + call imtclose (imlist) + call clpcls (clist) + call clpcls (olist) + + # Free working space. + call sfree (sp) +end diff --git a/noao/digiphot/apphot/photpars.par b/noao/digiphot/apphot/photpars.par new file mode 100644 index 00000000..87c7ac9e --- /dev/null +++ b/noao/digiphot/apphot/photpars.par @@ -0,0 +1,7 @@ +# PHOTPARS Parameter File + +weighting,s,h,constant,"|constant|cone|gauss|",,Photometric weighting scheme for wphot +apertures,s,h,"3.",,,List of aperture radii in scale units +zmag,r,h,25.,,,Zero point of magnitude scale +mkapert,b,h,no,,,Draw apertures on the display +mode,s,h,'ql' diff --git a/noao/digiphot/apphot/polymark.par b/noao/digiphot/apphot/polymark.par new file mode 100644 index 00000000..6bf303e3 --- /dev/null +++ b/noao/digiphot/apphot/polymark.par @@ -0,0 +1,13 @@ +# POLYMARK + +image,f,a,,,,"The input image(s)" +coords,f,h,"default",,,"The output coordinate file(s) (default: image.coo.?)" +polygons,f,h,"default",,,"The output polygons file(s) (default: image.ver.?)" +icommands,*imcur,h,"",,,"Image cursor: [x y wcs] key [cmd]" +gcommands,*gcur,h,"",,,"Graphics cursor: [x y wcs] key [cmd]" +wcsin,s,h,)_.wcsin,,,"The input coordinate system (logical,tv,physical,world)" +wcsout,s,h,)_.wcsout,,,"The output coordinate system (logical,tv,physical)" +cache,b,h,)_.cache,,,"Cache the input image pixels ?" +graphics,s,h,)_.graphics,,,"Graphics device" +display,s,h,)_.display,,,"Display device" +mode,s,h,'ql' diff --git a/noao/digiphot/apphot/polypars.par b/noao/digiphot/apphot/polypars.par new file mode 100644 index 00000000..8b6aac6a --- /dev/null +++ b/noao/digiphot/apphot/polypars.par @@ -0,0 +1,4 @@ +# Polyphot photometry parameters + +zmag,r,h,25.0,,,Zero point of magnitude scale +mkpolygon,b,h,no,,,Draw polygon on the image display diff --git a/noao/digiphot/apphot/polyphot.par b/noao/digiphot/apphot/polyphot.par new file mode 100644 index 00000000..aefdf6b9 --- /dev/null +++ b/noao/digiphot/apphot/polyphot.par @@ -0,0 +1,22 @@ +# POLYPHOT + +image,f,a,,,,"The input image(s)" +polygons,f,h,"",,,"The input polygons file(s) (default: image.ver.?)" +coords,f,h,"",,,"The input coordinates file(s) (default: image.coo.?)" +output,f,h,"default",,,"The output photometry file(s) (default: image.mag.?)" +datapars,pset,h,"",,,"Data dependent parameters" +centerpars,pset,h,"",,,"Centering parameters" +fitskypars,pset,h,"",,,"Sky fitting parameters" +polypars,pset,h,"",,,"Photometry parameters" +interactive,b,h,yes,,,"Interactive mode ?" +icommands,*imcur,h,"",,,"Image cursor: [x y wcs] key [cmd]" +gcommands,*gcur,h,"",,,"Graphics cursor: [x y wcs] key [cmd]" +wcsin,s,h,)_.wcsin,,,"The input coordinate system (logical,tv,physical,world)" +wcsout,s,h,)_.wcsout,,,"The output coordinate system (logical,tv,physical)" +cache,b,h,)_.cache,,,"Cache the input image pixels in memory ?" +verify,b,h,)_.verify,,,"Verify critical parameters in non-interactive mode ?" +update,b,h,)_.update,,,"Update critical parameters in non-interactive mode ?" +verbose,b,h,)_.verbose,,,"Print messages in non-interactive mode ?" +graphics,s,h,)_.graphics,,,"Graphics device" +display,s,h,)_.display,,,"Display device" +mode,s,h,'ql' diff --git a/noao/digiphot/apphot/polyphot/apgypars.x b/noao/digiphot/apphot/polyphot/apgypars.x new file mode 100644 index 00000000..960f9cbc --- /dev/null +++ b/noao/digiphot/apphot/polyphot/apgypars.x @@ -0,0 +1,29 @@ +include "../lib/display.h" +include "../lib/noise.h" +include "../lib/center.h" +include "../lib/fitsky.h" +include "../lib/polyphot.h" + +# AP_GYPARS -- Procedure to fetch the polyphot task parameters. + +procedure ap_gypars (ap) + +pointer ap # pointer to apphot fitting structure + +begin + # Open the apphot strucuture. + call apyinit (ap, AP_CENTROID1D, 2.5, AP_MODE, 10.0, 10.0, 2.0, + AP_NPOISSON) + + # Get the data dependent parameters. + call ap_gdapars (ap) + + # Get the centering algorithm parameters. + call ap_gcepars (ap) + + # Get the sky fitting parameters. + call ap_gsapars (ap) + + # Get the photometry parameters. + call ap_gpopars (ap) +end diff --git a/noao/digiphot/apphot/polyphot/apmkpylist.x b/noao/digiphot/apphot/polyphot/apmkpylist.x new file mode 100644 index 00000000..6b9d1ea0 --- /dev/null +++ b/noao/digiphot/apphot/polyphot/apmkpylist.x @@ -0,0 +1,279 @@ +include <ctype.h> +include <gset.h> +include "../lib/apphot.h" +include "../lib/polyphot.h" + +define HELPFILE "apphot$polyphot/polymark.key" + +# AP_MKPYLIST -- Procedure to make polygon and accompanying coordinate list. + +int procedure ap_mkpylist (im, py, pl, cl, id, gd, pid, cid) + +pointer im # pointer to IRAF image +pointer py # pointer to the POLYPHOT structure +int pl # starlist file descriptor +int cl # coordinate file list +pointer id # pointer to image display stream +pointer gd # pointer to graphics display stream +int pid # polygon id sequence number +int cid # coordinate list sequence number + +int key, nvertices, wcs, ptid, ltid, prev_num, req_num +int ip, colonkey, firstpoly, newpoly, delim +pointer sp, cmd, x, y, xshift, yshift +real wx, wy, xmean, ymean + +int clgcur(), apgqverify(), apgtverify(), ap_ymkpoly(), ctoi() +int ap_ynextobj() +real apstatr() +data delim /';'/ + +define endswitch_ 99 + +begin + # Allocate temporary space. + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + call salloc (x, MAX_NVERTICES + 1, TY_REAL) + call salloc (y, MAX_NVERTICES + 1, TY_REAL) + call salloc (xshift, MAX_NVERTICES + 1, TY_REAL) + call salloc (yshift, MAX_NVERTICES + 1, TY_REAL) + + # Initialize the cursor read. + key = ' ' + Memc[cmd] = EOS + + # Initialize the sequencing. + firstpoly = YES + newpoly = NO + ptid = 0 + ltid = 0 + xmean = INDEFR + ymean = INDEFR + + # Loop over the polygon file. + nvertices = 0 + while (clgcur ("icommands", wx, wy, wcs, key, Memc[cmd], SZ_LINE) != + EOF) { + + # Set the current cursor coordinates. + call ap_vtol (im, wx, wy, wx, wy, 1) + call apsetr (py, CWX, wx) + call apsetr (py, CWY, wy) + + # Loop over the colon commands. + switch (key) { + + # Quit. + case 'q': + if (apgqverify ("polymark", NULL, key) == YES) { + call sfree (sp) + return (apgtverify (key)) + } + + # Plot a centered stellar radial profile. + case 'd': + call ap_qrad (py, im, wx, wy, gd) + + # Print the help page. + case '?': + if ((id != NULL) && (id == gd)) + call gpagefile (id, HELPFILE, "") + else + call pagefile (HELPFILE, "[space=morehelp,q=quit,?=help]") + + # Colon escape commands. + case ':': + for (ip = 1; IS_WHITE(Memc[cmd+ip-1]); ip = ip + 1) + ; + colonkey = Memc[cmd+ip-1] + + switch (colonkey) { + case 'm': + + # Decode a polymark colon command. + if (Memc[cmd+ip] != EOS && Memc[cmd+ip] != ' ') { + call printf ( + "Unknown or ambigous keystroke command\n") + goto endswitch_ + } + + # The polygon file is undefined. + if (pl == NULL) { + call printf ("The polygon list is undefined\n") + goto endswitch_ + } + + # Read the next polygon. + ip = ip + 1 + prev_num = ltid + if (ctoi (Memc[cmd], ip, req_num) <= 0) + req_num = ltid + 1 + nvertices = ap_ynextobj (py, im, id, pl, cl, delim, + Memr[xshift], Memr[yshift], MAX_NVERTICES, prev_num, + req_num, ltid, ptid) + if (nvertices == EOF) { + call printf ( + "End of polygon list, use r key to rewind\n") + goto endswitch_ + } + + # The polygon is undefined. + if (nvertices < 3) { + call printf ("The polygon has fewer than 3 vertices\n") + goto endswitch_ + } + + # Mark the polygon. + if (id != NULL) { + call appymark (py, id, Memr[xshift], Memr[yshift], + nvertices + 1, NO, NO, YES) + if (gd == id) + call gflush (id) + else + call gframe (id) + } + + default: + call printf ("Unknown or ambigous keystroke command\n") + } + + # Draw the next polygon in the list. + case 'm': + + # No polygon file. + if (pl == NULL) { + call printf ("The polygon list is undefined\n") + goto endswitch_ + } + + # Read the next polygon. + prev_num = ltid + req_num = ltid + 1 + nvertices = ap_ynextobj (py, im, id, pl, cl, delim, + Memr[xshift], Memr[yshift], MAX_NVERTICES, prev_num, + req_num, ltid, ptid) + + # The polygon is undefined. + if (nvertices == EOF) { + call printf ("End of polygon list, use r key to rewind\n") + goto endswitch_ + } + + # The polygon is ill-defined. + if (nvertices < 3) { + call printf ("The polygon has fewer than 3 vertices\n") + goto endswitch_ + } + + # Mark the polygon. + if (id != NULL) { + call appymark (py, id, Memr[xshift], Memr[yshift], + nvertices + 1, NO, NO, YES) + if (gd == id) + call gflush (id) + else + call gframe (id) + } + + # Rewind the polygon and coordinate lists. + case 'r': + if (pl != NULL) { + call seek (pl, BOF) + if (cl != NULL) + call seek (cl, BOF) + ptid = 0 + ltid = 0 + } else + call printf ("The polygon list is undefined\n") + + # Draw the remaining polygons on the display. + case 'l': + if (pl == NULL) { + call printf ("The polygon list is undefined\n") + } else if (id != NULL) { + call ap_ydraw (py, im, cl, pl, ltid, ptid, id) + if (gd == id) + call gflush (id) + else + call gframe (id) + } + + # Define the polygon interactively. + case 'g': + if (gd == id) + nvertices = ap_ymkpoly (py, im, id, Memr[x], Memr[y], + MAX_NVERTICES, NO) + else + nvertices = ap_ymkpoly (py, im, id, Memr[x], Memr[y], + MAX_NVERTICES, YES) + xmean = apstatr (py, PYXMEAN) + ymean = apstatr (py, PYYMEAN) + if (nvertices == EOF) { + newpoly = NO + call printf ("The polygon is undefined\n") + } else if (nvertices <= 2) { + newpoly = NO + call printf ( + "The polygon has fewer then 3 vertices\n") + } else { + newpoly = YES + if (id != NULL) { + if (gd == id) + call gflush (id) + else + call gframe (id) + } + } + + # Mark the current polygon on the display. + case 'f': + if (id != NULL) { + if (! IS_INDEFR(xmean) && ! IS_INDEFR(ymean)) { + call aaddkr (Memr[x], wx - xmean, Memr[xshift], + nvertices + 1) + call aaddkr (Memr[y], wy - ymean, Memr[yshift], + nvertices + 1) + call appymark (py, id, Memr[xshift], Memr[yshift], + nvertices + 1, NO, NO, YES) + if (gd == id) + call gflush (id) + else + call gframe (id) + } else + call printf ("The polygon is undefined\n") + } + + + # Mark the current polygon on the display and write to file. + case ' ': + if (! IS_INDEFR(xmean) && ! IS_INDEFR(ymean)) { + call ap_ywrite (py, im, cl, pl, Memr[x], Memr[y], nvertices, + cid, pid, firstpoly, newpoly) + if (id != NULL) { + call aaddkr (Memr[x], wx - xmean, Memr[xshift], + nvertices + 1) + call aaddkr (Memr[y], wy - ymean, Memr[yshift], + nvertices + 1) + call appymark (py, id, Memr[xshift], Memr[yshift], + nvertices + 1, NO, NO, YES) + if (gd == id) + call gflush (id) + else + call gframe (id) + } + } else + call printf ("The polygon is undefined\n") + + default: + call printf ("Unknown or ambigous keystroke command\n") + } + +endswitch_ + # Reset the keystroke and command defaults. + call apsetr (py, WX, apstatr (py, CWX)) + call apsetr (py, WY, apstatr (py, CWY)) + key = ' ' + Memc[cmd] = EOS + } +end diff --git a/noao/digiphot/apphot/polyphot/appyerrors.x b/noao/digiphot/apphot/polyphot/appyerrors.x new file mode 100644 index 00000000..96a7bc93 --- /dev/null +++ b/noao/digiphot/apphot/polyphot/appyerrors.x @@ -0,0 +1,35 @@ +include "../lib/polyphot.h" + +# AP_PYERRORS -- Procedure to print out polyphot error messages when the +# task is run in interactive mode. + +procedure ap_pyerrors (ap, cier, sier, pier) + +pointer ap # apphot structure +int cier # centering error code +int sier # sky fitting error code +int pier # polyphot error code + +begin + # Print centering errors. + call ap_cerrors (ap, cier) + + # Print sky fitting errors. + call ap_serrors (ap, sier) + + # Print the polyphot errors. + switch (pier) { + case PY_NOPOLYGON: + call printf ("The polygon is undefined or too few vertices.\n") + case PY_OUTOFBOUNDS: + call printf ("The polygon is partially outside the image.\n") + case PY_NOPIX: + call printf ("The effective polygon area is 0.0.\n") + case PY_NOSKYMODE: + call printf ("The sky value is undefined.\n") + case PY_BADDATA: + call printf ("Bad pixels inside the polygon.\n") + default: + call printf ("") + } +end diff --git a/noao/digiphot/apphot/polyphot/apybphot.x b/noao/digiphot/apphot/polyphot/apybphot.x new file mode 100644 index 00000000..8a4783e8 --- /dev/null +++ b/noao/digiphot/apphot/polyphot/apybphot.x @@ -0,0 +1,94 @@ +include <fset.h> +include "../lib/apphot.h" +include "../lib/display.h" +include "../lib/fitsky.h" +include "../lib/polyphot.h" + +# AP_YBPHOT -- Measure the flux inside a list of polygons. + +procedure ap_ybphot (py, im, cl, pl, out, id, ld, pd, gid, interactive) + +pointer py # pointer to apphot structure +pointer im # pointer to IRAF image +int cl # coordinates file descriptor +int pl # vertices list file descriptor +int out # output file descriptor +int id # output file sequence number +int ld # coordinate list number +int pd # polygon list number +pointer gid # pointer to image display stream +int interactive # interactive or batch mode + +real apstatr() +pointer sp, x, y, xout, yout +int req_num, prev_num, cier, sier, pier, nvertices, delim +int ap_ynextobj(), ap_ycenter(), apfitsky(), ap_yfit(), apstati() +data delim /';'/ + +begin + # Allocate temporary space for arrays. + call smark (sp) + call salloc (x, MAX_NVERTICES + 1, TY_REAL) + call salloc (y, MAX_NVERTICES + 1, TY_REAL) + call salloc (xout, MAX_NVERTICES + 1, TY_REAL) + call salloc (yout, MAX_NVERTICES + 1, TY_REAL) + + # Initialize + if (pl != NULL) + call seek (pl, BOF) + if (cl != NULL) + call seek (cl, BOF) + + # Get the first polygon. + pd = 0 + prev_num = 0 + req_num = ld + 1 + nvertices = ap_ynextobj (py, im, gid, pl, cl, delim, Memr[x], Memr[y], + MAX_NVERTICES, prev_num, req_num, ld, pd) + + while (nvertices != EOF) { + + # Fit the center, sky and measure the polygon. + cier = ap_ycenter (py, im, apstatr (py, PYCX), apstatr (py, PYCY), + Memr[x], Memr[y], nvertices + 1) + sier = apfitsky (py, im, apstatr (py, PYCX), apstatr (py, + PYCY), NULL, NULL) + pier = ap_yfit (py, im, Memr[x], Memr[y], + nvertices + 1, apstatr (py, SKY_MODE), apstatr (py, + SKY_SIGMA), apstati (py, NSKY)) + + # Write the output to the standard output. + if (interactive == YES) { + call ap_qyprint (py, cier, sier, pier) + if (gid != NULL) + call appymark (py, gid, Memr[x], Memr[y], nvertices + 1, + YES, apstati (py, MKSKY), apstati (py, MKPOLYGON)) + } + + # Write the output to a file. + if (id == 1) + call ap_param (py, out, "polyphot") + switch (apstati(py,WCSOUT)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_ltoo (py, Memr[x], Memr[y], Memr[xout], Memr[yout], + nvertices + 1) + case WCS_TV: + call ap_ltov (im, Memr[x], Memr[y], Memr[xout], Memr[yout], + nvertices + 1) + default: + call amovr (Memr[x], Memr[xout], nvertices + 1) + call amovr (Memr[y], Memr[yout], nvertices + 1) + } + call ap_yprint (py, out, Memr[xout], Memr[yout], nvertices, id, ld, + pd, cier, sier, pier) + id = id + 1 + + # Setup for next polygon. + prev_num = ld + req_num = ld + 1 + nvertices = ap_ynextobj (py, im, gid, pl, cl, delim, Memr[x], + Memr[y], MAX_NVERTICES, prev_num, req_num, ld, pd) + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/polyphot/apycenter.x b/noao/digiphot/apphot/polyphot/apycenter.x new file mode 100644 index 00000000..faa2d884 --- /dev/null +++ b/noao/digiphot/apphot/polyphot/apycenter.x @@ -0,0 +1,59 @@ +include "../lib/center.h" +include "../lib/polyphot.h" + +# AP_YCENTER -- Center the polygon using the centering package routines. + +int procedure ap_ycenter (py, im, wx, wy, x, y, nver) + +pointer py # pointer to polyphot structure +pointer im # pointer to the IRAF image +real wx # initial x center +real wy # initial y center +real x[ARB] # x coordinates of the polygon +real y[ARB] # y coordinates of the polygon +int nver # number of vertices + +int cier +int apfitcenter() +real apstatr() + +begin + if (IS_INDEFR(apstatr (py, PYCX)) || IS_INDEFR(apstatr (py, PYCY))) + cier = apfitcenter (py, im, INDEFR, INDEFR) + else + cier = apfitcenter (py, im, wx, wy) + + if (! IS_INDEFR (apstatr (py, XCENTER)) && ! IS_INDEFR (apstatr (py, + YCENTER)) && ! IS_INDEFR (apstatr (py, PYCX)) && + ! IS_INDEFR (apstatr (py, PYCY))) + call ap_yshift (py, im, x, y, nver, apstatr (py, XCENTER), + apstatr (py, YCENTER)) + + return (cier) +end + + +# AP_YRECENTER -- Recenter the polygon using the existing buffer of pixels +# and the centering package routines. + +int procedure ap_yrecenter (py, im, x, y, nver, cier) + +pointer py # pointer to polyphot structure +pointer im # the input image descriptor +real x[ARB] # x coordinates of the polygon +real y[ARB] # y coordinates of the polygon +int nver # number of vertices +int cier # original centering error + +int aprefitcenter() +real apstatr() + +begin + cier = aprefitcenter (py, im, cier) + if (! IS_INDEFR (apstatr (py, XCENTER)) && ! IS_INDEFR (apstatr (py, + YCENTER)) && ! IS_INDEFR (apstatr (py, PYCX)) && ! + IS_INDEFR (apstatr (py, PYCY))) + call ap_yshift (py, im, x, y, nver, apstatr (py, XCENTER), + apstatr (py, YCENTER)) + return (cier) +end diff --git a/noao/digiphot/apphot/polyphot/apycolon.x b/noao/digiphot/apphot/polyphot/apycolon.x new file mode 100644 index 00000000..9b70199b --- /dev/null +++ b/noao/digiphot/apphot/polyphot/apycolon.x @@ -0,0 +1,226 @@ +include <error.h> +include <gset.h> +include "../lib/apphot.h" +include "../lib/noise.h" +include "../lib/display.h" +include "../lib/center.h" +include "../lib/fitsky.h" +include "../lib/polyphot.h" + +# AP_YCOLON -- Process polyphot task colon commands + +procedure ap_ycolon (ap, im, pl, cl, out, stid, ptid, ltid, cmdstr, newimage, + newcenterbuf, newcenter, newskybuf, newsky, newmagbuf, newmag) + +pointer ap # pointer to the apphot structure +pointer im # pointer to the iraf image +int pl # polygon file descriptor +int cl # coord file descriptor +int out # output file descriptor +int stid # output file number +int ptid # polygon file sequence number +int ltid # coord file sequence number +char cmdstr[ARB] # command string +int newimage # new image ? +int newcenterbuf, newcenter # new center buffer ?, new center fit ? +int newskybuf, newsky # new sky buffer ?, new sky fit ? +int newmagbuf, newmag # new aperture buffer ?, new fit ? + +pointer sp, incmd, outcmd +int strdic() + +begin + # Fetch the command. + call smark (sp) + call salloc (incmd, SZ_LINE, TY_CHAR) + call salloc (outcmd, SZ_LINE, TY_CHAR) + + call sscan (cmdstr) + call gargwrd (Memc[incmd], SZ_LINE) + if (Memc[incmd] == EOS) { + call sfree (sp) + return + } + + # Set the command to the appropriate routine. + if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, CCMDS) != 0) + call apccolon (ap, out, stid, cmdstr, newcenterbuf, newcenter) + else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, SCMDS) != 0) + call apscolon (ap, out, stid, cmdstr, newskybuf, newsky) + else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, APCMDS) != 0) + call ap_apcolon (ap, im, cl, out, stid, ltid, cmdstr, newimage, + newcenterbuf, newcenter, newskybuf, newsky, newmagbuf, newmag) + else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, NCMDS) != 0) + call ap_nscolon (ap, im, out, stid, cmdstr, newcenterbuf, + newcenter, newskybuf, newsky, newmagbuf, newmag) + else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, PYCMDS) != 0) + call ap_yycolon (ap, pl, out, stid, ptid, ltid, cmdstr, newmagbuf, + newmag) + else + call ap_yimcolon (ap, cmdstr) + + call sfree (sp) +end + + +# AP_YIMCOLON -- Procedure to process remaining polyphot commands which + +procedure ap_yimcolon (ap, cmdstr) + +pointer ap # pointer to the apphot structure +char cmdstr[ARB] # command string + +int ncmd +pointer sp, cmd +int strdic() + +begin + # Fetch the command. + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + call sscan (cmdstr) + call gargwrd (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call sfree (sp) + return + } + + # Process the command. + ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, MISC1) + switch (ncmd) { + case 1: + call gargwrd (Memc[cmd], SZ_LINE) + ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, PYSHOWARGS) + switch (ncmd) { + case 1: + call printf ("\n") + call ap_cpshow (ap) + call printf ("\n") + case 2: + call printf ("\n") + call ap_spshow (ap) + call printf ("\n") + case 3: + call printf ("\n") + call ap_ypshow (ap) + call printf ("\n") + case 4: + call printf ("\n") + call ap_nshow (ap) + call printf ("\n") + default: + call printf ("\n") + call ap_yshow (ap) + call printf ("\n") + } + default: + call printf ("Unknown or ambiguous colon command\7\n") + } + + call sfree (sp) +end + + +# AP_YYCOLON -- Procedure to process polyphot commands + +procedure ap_yycolon (ap, pl, out, stid, ptid, ltid, cmdstr, newmagbuf, newmag) + +pointer ap # pointer to apphot structure +int pl # polygon file descriptor +int out # output file descriptor +int stid # output file sequence number +int ptid # polygon file sequence number +int ltid # coords file sequence number +char cmdstr[ARB] # command string +int newmagbuf # new aperture buffers ? +int newmag # compute new magnitudes ? + +bool bval +int ncmd +pointer sp, cmd, str +real rval +string cmds PYCMDS + +bool itob(), streq() +int apstati(), btoi(), strdic(), nscan(), open() +real apstatr() +errchk open, close + +begin + # Allocate the space. + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + call salloc (str, SZ_FNAME, TY_CHAR) + + call sscan (cmdstr) + call gargwrd (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call sfree (sp) + return + } + + # Process the colon command. + ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, cmds) + switch (ncmd) { + + case PLCMD_ZMAG: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g\n") + call pargstr (KY_PYZMAG) + call pargr (apstatr (ap, PYZMAG)) + } else { + call apsetr (ap, PYZMAG, rval) + if (stid > 1) + call ap_rparam (out, KY_PYZMAG, rval, UN_PYZMAG, + "zero point of magnitude scale") + newmag = YES + } + + case PLCMD_MKPOLYGON: + call gargb (bval) + if (nscan() == 1) { + call printf ("%s = %g\n") + call pargstr (KY_MKPOLYGON) + call pargb (itob (apstati (ap, MKPOLYGON))) + } else { + call apseti (ap, MKPOLYGON, btoi (bval)) + } + + case PLCMD_POLYGONS: + call gargwrd (Memc[cmd], SZ_LINE) + call apstats (ap, PYNAME, Memc[str], SZ_FNAME) + if (Memc[cmd] == EOS || streq (Memc[cmd], Memc[str])) { + call printf ("%s = %s\n") + call pargstr (KY_PYNAME) + call pargstr (Memc[str]) + } else { + if (pl != NULL) { + call close (pl) + pl = NULL + } + iferr { + pl = open (Memc[cmd], READ_ONLY, TEXT_FILE) + } then { + pl = NULL + call erract (EA_WARN) + call apsets (ap, PYNAME, "") + call apsets (ap, PYROOT, "") + ptid = 0 + ltid = 0 + } else { + call apsets (ap, PYNAME, Memc[cmd]) + call apfroot (Memc[cmd], Memc[str], SZ_FNAME) + call apsets (ap, PYROOT, Memc[str]) + ptid = 0 + ltid = 0 + } + } + + default: + call printf ("Unknown or ambiguous colon command\n") + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/polyphot/apyconfirm.x b/noao/digiphot/apphot/polyphot/apyconfirm.x new file mode 100644 index 00000000..fb10ad32 --- /dev/null +++ b/noao/digiphot/apphot/polyphot/apyconfirm.x @@ -0,0 +1,99 @@ +include "../lib/apphot.h" +include "../lib/noise.h" +include "../lib/center.h" +include "../lib/fitsky.h" + +# AP_YCONFIRM -- Procedure to confirm the critical polyphot parameters. + +procedure ap_yconfirm (ap, out, stid) + +pointer ap # pointer to the apphot structure +int out # output file descriptor +int stid # output file sequence number + +pointer sp, cstr, sstr +real fwhmpsf, capert, annulus, dannulus, skysigma +real datamin, datamax +int apstati() +real apstatr(), ap_vfwhmpsf(), ap_vcapert(), ap_vsigma() +real ap_vannulus(), ap_vdannulus(), ap_vdatamin(), ap_vdatamax() + +begin + call smark (sp) + call salloc (cstr, SZ_FNAME, TY_CHAR) + call salloc (sstr, SZ_FNAME, TY_CHAR) + + call printf ("\n") + + # Confirm the centering algorithm. + call ap_vcstring (ap, Memc[cstr], SZ_FNAME) + + if (apstati (ap, CENTERFUNCTION) != AP_NONE) { + + # Confirm the fwhmpsf. + if (apstati (ap, CENTERFUNCTION) != AP_CENTROID1D) + fwhmpsf = ap_vfwhmpsf (ap) + else + fwhmpsf = apstatr (ap, FWHMPSF) + + # Confirm the centering box. + capert = 2.0 * ap_vcapert (ap) + + } else { + fwhmpsf = apstatr (ap, FWHMPSF) + capert = 2.0 * apstatr (ap, CAPERT) + } + + # Confirm the sky fitting algorithm. + call ap_vsstring (ap, Memc[sstr], SZ_FNAME) + + if (apstati (ap, SKYFUNCTION) != AP_CONSTANT && + apstati (ap, SKYFUNCTION) != AP_SKYFILE) { + + # Confirm the sky annulus parameter. + annulus = ap_vannulus (ap) + + # Confirm the width of the sky annulus. + dannulus = ap_vdannulus (ap) + + } else { + annulus = apstatr (ap, ANNULUS) + dannulus = apstatr (ap, DANNULUS) + } + + # Confirm the sky sigma parameter. + if (apstati (ap, SKYFUNCTION) != AP_SKYFILE) + skysigma = ap_vsigma (ap) + else + skysigma = apstatr (ap, SKYSIGMA) + + # Confirm the datamin and datamax parameters. + datamin = ap_vdatamin (ap) + datamax = ap_vdatamax (ap) + + call printf ("\n") + + # Update the database file. + if (out != NULL && stid > 1) { + call ap_sparam (out, KY_CSTRING, Memc[cstr], UN_CALGORITHM, + "centering algorithm") + call ap_rparam (out, KY_FWHMPSF, fwhmpsf, UN_ASCALEUNIT, + "full width half maximum of the psf") + call ap_rparam (out, KY_CAPERT, capert, UN_CSCALEUNIT, + "width of the centering box") + call ap_sparam (out, KY_SSTRING, Memc[sstr], UN_SALGORITHM, + "sky fitting algorithm") + call ap_rparam (out, KY_ANNULUS, annulus, UN_SSCALEUNIT, + "inner radius of the sky annulus") + call ap_rparam (out, KY_DANNULUS, dannulus, UN_SSCALEUNIT, + "width of the sky annulus") + call ap_rparam (out, KY_SKYSIGMA, skysigma, UN_NCOUNTS, + "standard deviation of 1 sky pixel") + call ap_rparam (out, KY_DATAMIN, datamin, UN_ACOUNTS, + "minimum good data value") + call ap_rparam (out, KY_DATAMAX, datamax, UN_ACOUNTS, + "maximum good data value") + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/polyphot/apycoords.x b/noao/digiphot/apphot/polyphot/apycoords.x new file mode 100644 index 00000000..0298b0f8 --- /dev/null +++ b/noao/digiphot/apphot/polyphot/apycoords.x @@ -0,0 +1,43 @@ +include "../lib/polyphot.h" + +# AP_YCOORDS -- Procedure to fetch the next center coordinates for the polygon. + +int procedure ap_ycoords (cl, delim, xshift, yshift, stdin) + +int cl # coordinates file descriptor +int delim # delimiter character +real xshift # new x coordinate +real yshift # new y coordinate +int stdin # is cl STDIN? + +char marker +int stat +int fscan(), nscan() + +begin + if (stdin == YES) { + call printf ("Type object x and y coordinates (^D or^Z to end): ") + call flush (STDOUT) + } + + stat = fscan (cl) + while (stat != EOF) { + + call gargr (xshift) + call gargr (yshift) + + if (nscan() != 2) { + call reset_scan() + call gargc (marker) + if (int (marker) == delim) + return (NEXT_POLYGON) + #else + #return (NEXT_OBJECT) + } else + return (THIS_OBJECT) + + stat = fscan (cl) + } + + return (stat) +end diff --git a/noao/digiphot/apphot/polyphot/apydraw.x b/noao/digiphot/apphot/polyphot/apydraw.x new file mode 100644 index 00000000..aadcbed0 --- /dev/null +++ b/noao/digiphot/apphot/polyphot/apydraw.x @@ -0,0 +1,55 @@ +include "../lib/polyphot.h" + +# APYDRAW -- Procedure to draw polygons interactively on the display. + +procedure ap_ydraw (py, im, cl, pl, ld, pd, id) + +pointer py # pointer to apphot structure +pointer im # theinput image descriptor +int cl # coordinates file descriptor +int pl # vertices list file descriptor +int ld # coordinate list number +int pd # polygon list number +pointer id # pointer to image display stream + +int req_num, prev_num, nvertices, delim +pointer sp, x, y +int ap_ynextobj() +data delim /';'/ + +begin + # Allocate temporary space for arrays. + call smark (sp) + call salloc (x, MAX_NVERTICES + 1, TY_REAL) + call salloc (y, MAX_NVERTICES + 1, TY_REAL) + + # Rewind the polygon and coordinate files. + if (pl != NULL) + call seek (pl, BOF) + if (cl != NULL) + call seek (cl, BOF) + + # Initialize. + pd = 0 + prev_num = 0 + req_num = ld + 1 + nvertices = ap_ynextobj (py, im, id, pl, cl, delim, Memr[x], Memr[y], + MAX_NVERTICES, prev_num, req_num, ld, pd) + + # Loop over the coordinate and polygon file. + while (nvertices != EOF) { + + # Draw the polygon if it has more than three vertices. + if (id != NULL && nvertices >= 3) + call appymark (py, id, Memr[x], Memr[y], nvertices + 1, + NO, NO, YES) + + # Setup for next polygon. + prev_num = ld + req_num = ld + 1 + nvertices = ap_ynextobj (py, im, id, pl, cl, delim, Memr[x], + Memr[y], MAX_NVERTICES, prev_num, req_num, ld, pd) + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/polyphot/apyfit.x b/noao/digiphot/apphot/polyphot/apyfit.x new file mode 100644 index 00000000..abb76a6d --- /dev/null +++ b/noao/digiphot/apphot/polyphot/apyfit.x @@ -0,0 +1,578 @@ +include <imhdr.h> +include <mach.h> +include "../lib/apphot.h" +include "../lib/noise.h" +include "../lib/polyphot.h" + +# AP_YFIT -- Procedure to compute the magnitude of an object inside a polygonal +# aperture. + +int procedure ap_yfit (py, im, xver, yver, nver, skyval, skysig, nsky) + +pointer py # pointer to polyphot strucuture +pointer im # pointer to IRAF image +real xver[ARB] # x vertices coords +real yver[ARB] # y vertices coords +int nver # number of vertices +real skyval # sky value +real skysig # sigma of sky pixels +int nsky # number of sky pixels + +double flux, area +int noise, badpix, ier +real datamin, datamax, mag, magerr, zmag, padu, itime, readnoise +int apstati(), ap_yyfit(), ap_byyfit() +real apstatr() + +begin + # Initialize. + call apsetd (py, PYFLUX, 0.0d0) + call apsetd (py, PYNPIX, 0.0d0) + call apsetr (py, PYMAG, INDEFR) + call apsetr (py, PYMAGERR, INDEFR) + + # Compute the flux inside the polygon. + if (IS_INDEFR(apstatr (py, DATAMIN)) && IS_INDEFR(apstatr(py, + DATAMAX))) { + ier = ap_yyfit (im, xver, yver, nver, flux, area) + badpix = NO + } else { + if (IS_INDEFR(apstatr (py, DATAMIN))) + datamin = -MAX_REAL + else + datamin = apstatr (py, DATAMIN) + if (IS_INDEFR(apstatr (py, DATAMAX))) + datamax = MAX_REAL + else + datamax = apstatr (py, DATAMAX) + ier = ap_byyfit (im, xver, yver, nver, datamin, datamax, flux, + area, badpix) + } + + if (ier == PY_NOPOLYGON) + return (PY_NOPOLYGON) + else if (ier == PY_NOPIX) + return (PY_NOPIX) + + # Store the results. + call apsetd (py, PYFLUX, flux) + call apsetd (py, PYNPIX, area) + call apseti (py, PYBADPIX, badpix) + + if (IS_INDEFR(skyval)) + return (PY_NOSKYMODE) + + # Get the photometry parameters. + zmag = apstatr (py, PYZMAG) + itime = apstatr (py, ITIME) + noise = apstati (py, NOISEFUNCTION) + padu = apstatr (py, EPADU) + readnoise = apstatr (py, READNOISE) + + # Compute the magnitude and error. + if (badpix == NO) { + if (apstati (py, POSITIVE) == YES) + call apcopmags (flux, area, mag, magerr, 1, skyval, + skysig, nsky, zmag, noise, padu) + else + call apconmags (flux, area, mag, magerr, 1, skyval, + skysig, nsky, zmag, noise, padu, readnoise) + mag = mag + 2.5 * log10 (itime) + + call apsetr (py, PYMAG, mag) + call apsetr (py, PYMAGERR, magerr) + } + + return (ier) +end + + +# AP_YYFIT -- Measure the total flux inside a polygon. + +int procedure ap_yyfit (im, xver, yver, nver, flux, area) + +pointer im # pointer to IRAF image +real xver[ARB] # x coordinates of the vertices +real yver[ARB] # y coordinates of the vertices: +int nver # number of vertices +double flux # flux interior to the polygon +double area # approximate area of polygon + +double fluxx, areax, fctnx, fctny +real xmin, xmax, ymin, ymax, x1, x2, lx, ld +pointer sp, work1, work2, xintr, buf +int i, j, k, linemin, linemax, colmin, colmax, nintr, ier +int ap_yclip() +pointer imgl2r() + +begin + # Check that polygon has at least 3 vertices plus the closing vertex. + if (nver < 4) { + flux = INDEFD + area = 0.0d0 + return (PY_NOPOLYGON) + } + + # Allocate working space. + call smark (sp) + call salloc (work1, nver, TY_REAL) + call salloc (work2, nver, TY_REAL) + call salloc (xintr, nver, TY_REAL) + + # Find the minimum and maximum x and y values of the polygon + # and detemine whether the polygon is partially off the image. + + call alimr (xver, nver, xmin, xmax) + call alimr (yver, nver, ymin, ymax) + if (xmin < 0.5 || xmax > (IM_LEN(im,1) + 0.5) || ymin < 0.5 || ymax > + (IM_LEN(im,2) + 0.5)) + ier = PY_OUTOFBOUNDS + else + ier = PY_OK + + # Find the minimum and maximum image line numbers. + ymin = max (0.5, min (real (IM_LEN (im,2) + 0.5), ymin)) + ymax = min (real (IM_LEN(im,2) + 0.5), max (0.5, ymax)) + linemin = min (int (ymin + 0.5), int (IM_LEN(im,2))) + linemax = min (int (ymax + 0.5), int (IM_LEN(im,2))) + + # Set up the line segment parameters and initialize fluxes and areas. + x1 = 0.5 + x2 = IM_LEN(im,1) + 0.5 + lx = x2 - x1 + flux = 0.0d0 + area = 0.0d0 + + # Loop over the range of lines of interest. + do i = linemin, linemax { + + # Read in image line. + buf = imgl2r (im, i) + if (buf == EOF) + next + + # Find all the x intersection points of image line and polygon. + if (ymin > i) + ld = min (i + 1, linemax) + else if (ymax < i) + ld = max (i - 1, linemin) + else + ld = i + nintr = ap_yclip (xver, yver, Memr[work1], Memr[work2], + Memr[xintr], nver, lx, ld) + if (nintr <= 0) + next + fctny = min (i + 0.5, ymax) - max (i - 0.5, ymin) + + # Sort the x intersection points + call asrtr (Memr[xintr], Memr[xintr], nintr) + + # Integrate the flux in each line segment. + fluxx = 0.0d0 + areax = 0.0d0 + do j = 1, nintr, 2 { + + # Compute the line segment limits. + xmin = min (real (IM_LEN(im,1) + 0.5), max (0.5, + Memr[xintr+j-1])) + xmax = min (real (IM_LEN(im,1) + 0.5), max (0.5, + Memr[xintr+j])) + colmin = min (int (xmin + 0.5), int (IM_LEN(im,1))) + colmax = min (int (xmax + 0.5), int (IM_LEN(im,1))) + + # Sum the contribution from a particular line segment. + do k = colmin, colmax { + fctnx = min (k + 0.5, xmax) - max (k - 0.5, xmin) + fluxx = fluxx + fctnx * Memr[buf+k-1] + areax = areax + fctnx + } + } + + # Add the line sum to the total. + area = area + areax * fctny + flux = flux + fluxx * fctny + } + + call sfree (sp) + + # Return the appropriate error code. + if (area <= 0.0d0) + return (PY_NOPIX) + else if (ier != PY_OK) + return (ier) + else + return (PY_OK) +end + + +# AP_BYYFIT -- Measure the total flux inside a polygon while searching for +# bad pixels at the same time. + +int procedure ap_byyfit (im, xver, yver, nver, datamin, datamax, flux, area, + badpix) + +pointer im # pointer to IRAF image +real xver[ARB] # x coordinates of the vertices +real yver[ARB] # y coordinates of the vertices: +int nver # number of vertices +real datamin # minimum good data value +real datamax # maximum good data value +double flux # flux interior to the polygon +double area # approximate area of polygon +int badpix # are there bad pixels + +int i, j, k, linemin, linemax, colmin, colmax, nintr, ier +pointer sp, work1, work2, xintr, buf +real xmin, xmax, ymin, ymax, x1, x2, lx, ld +double fluxx, areax, fctnx, fctny +int ap_yclip() +pointer imgl2r() + +begin + # Check that polygon has at least 3 vertices plus a closing vertex. + if (nver < 4) { + flux = INDEFD + area = 0.0d0 + badpix = NO + return (PY_NOPOLYGON) + } + + # Allocate working space. + call smark (sp) + call salloc (work1, nver, TY_REAL) + call salloc (work2, nver, TY_REAL) + call salloc (xintr, nver, TY_REAL) + + # Find minimum and maximum y values of the polygon vertices and + # compute the minimum and maximum image line limits. + + call alimr (xver, nver, xmin, xmax) + call alimr (yver, nver, ymin, ymax) + if (xmin < 0.5 || xmax > (IM_LEN(im,1) + 0.5) || ymin < 0.5 || ymax > + (IM_LEN(im,2) + 0.5)) + ier = PY_OUTOFBOUNDS + else + ier = PY_OK + + # Find the min and max image line numbers. + ymin = max (0.5, min (real (IM_LEN (im,2) + 0.5), ymin)) + ymax = min (real (IM_LEN(im,2) + 0.5), max (0.5, ymax)) + linemin = max (1, min (int (ymin + 0.5), int (IM_LEN(im,2)))) + linemax = max (1, min (int (ymax + 0.5), int (IM_LEN(im,2)))) + + # Set up line segment parameters and initialize fluxes. + x1 = 0.5 + x2 = IM_LEN(im,1) + 0.5 + lx = x2 - x1 + flux = 0.0d0 + area = 0.0d0 + + # Loop over the range of lines of interest. + badpix = NO + do i = linemin, linemax { + + # Read in the image line. + buf = imgl2r (im, i) + if (buf == EOF) + next + + # Find all the intersection points. + if (ymin > i) + ld = min (i + 1, linemax) + else if (ymax < i) + ld = max (i - 1, linemin) + else + ld = i + nintr = ap_yclip (xver, yver, Memr[work1], Memr[work2], + Memr[xintr], nver, lx, ld) + if (nintr <= 0) + next + fctny = min (i + 0.5, ymax) - max (i - 0.5, ymin) + + # Sort the x intersection points + call asrtr (Memr[xintr], Memr[xintr], nintr) + + # Integrate the flux in the line segment + fluxx = 0.0d0 + areax = 0.0d0 + do j = 1, nintr, 2 { + + # Compute the line segment limits. + xmin = min (real (IM_LEN(im,1) + 0.5), max (0.5, + Memr[xintr+j-1])) + xmax = min (real (IM_LEN(im,1) + 0.5), max (0.5, Memr[xintr+j])) + colmin = min (int (xmin + 0.5), int (IM_LEN(im,1))) + colmax = min (int (xmax + 0.5), int (IM_LEN(im,1))) + + # Sum the contribution from a particular line segment. + do k = colmin, colmax { + fctnx = min (k + 0.5, xmax) - max (k - 0.5, xmin) + fluxx = fluxx + fctnx * Memr[buf+k-1] + areax = areax + fctnx + if (Memr[buf+k-1] < datamin || Memr[buf+k-1] > datamax) + badpix = YES + } + } + + # Add the line sum to the total. + area = area + areax * fctny + flux = flux + fluxx * fctny + } + + call sfree (sp) + + if (area <= 0.0d0) + return (PY_NOPIX) + if (badpix == YES) + return (PY_BADDATA) + else if (ier != PY_OK) + return (ier) + else + return (PY_OK) +end + + +# AP_YCLIP -- Compute the intersection of an image line with a polygon defined +# by a list of vertices. The output is a list of ranges stored in the array +# xranges. Two work additional work arrays xintr and slope are required for +# the computation. + +int procedure ap_yclip (xver, yver, xintr, slope, xranges, nver, lx, ld) + +real xver[ARB] # x vertex coords +real yver[ARB] # y vertex coords +real xintr[ARB] # work array of x intersection points +real slope[ARB] # work array of y slopes at intersection points +real xranges[ARB] # x line segments +int nver # number of vertices +real lx, ld # equation of image line + +bool collinear +int i, j, nintr, nplus, nzero, nneg, imin, imax, nadd +real u1, u2, u1u2, dx, dy, dd, xa, wa + +begin + # Compute the intersection points of the image line and the polygon. + collinear = false + nplus = 0 + nzero = 0 + nneg = 0 + nintr = 0 + #u1 = - lx * yver[1] + ld + u1 = lx * (- yver[1] + ld) + do i = 2, nver { + + #u2 = - lx * yver[i] + ld + u2 = lx * (- yver[i] + ld) + u1u2 = u1 * u2 + + # Does the polygon side intersect the image line ? + if (u1u2 <= 0.0) { + + + # Compute the x intersection coordinate if the point of + # intersection is not a vertex. + + if ((u1 != 0.0) && (u2 != 0.0)) { + + dy = yver[i-1] - yver[i] + dx = xver[i-1] - xver[i] + dd = xver[i-1] * yver[i] - yver[i-1] * xver[i] + #xa = (dx * ld - lx * dd) + xa = lx * (dx * ld - dd) + wa = dy * lx + nintr = nintr + 1 + xranges[nintr] = xa / wa + slope[nintr] = -dy + if (slope[nintr] < 0.0) + nneg = nneg + 1 + else if (slope[nintr] > 0.0) + nplus = nplus + 1 + else + nzero = nzero + 1 + collinear = false + + # For each collinear line segment add two intersection + # points. Remove interior collinear intersection points. + + } else if (u1 == 0.0 && u2 == 0.0) { + + if (! collinear) { + nintr = nintr + 1 + xranges[nintr] = xver[i-1] + if (i == 2) + slope[nintr] = yver[1] - yver[nver-1] + else + slope[nintr] = yver[i-1] - yver[i-2] + if (slope[nintr] < 0.0) + nneg = nneg + 1 + else if (slope[nintr] > 0.0) + nplus = nplus + 1 + else + nzero = nzero + 1 + nintr = nintr + 1 + xranges[nintr] = xver[i] + slope[nintr] = 0.0 + nzero = nzero + 1 + } else { + xranges[nintr] = xver[i] + slope[nintr] = 0.0 + nzero = nzero + 1 + } + collinear = true + + # If the intersection point is a vertex add it to the + # list if it is not collinear with the next point. Add + # another point to the list if the vertex is at the + # apex of an acute angle. + + } else if (u1 != 0.0) { + + if (i == nver) { + dx = (xver[2] - xver[nver]) + dy = (yver[2] - yver[nver]) + dd = dy * (yver[nver-1] - yver[nver]) + } else { + dx = (xver[i+1] - xver[i]) + dy = (yver[i+1] - yver[i]) + dd = dy * (yver[i-1] - yver[i]) + } + + # Test whether the point is collinear with the point + # ahead. If it is not include the intersection point. + + if (dy != 0.0) { + nintr = nintr + 1 + xranges[nintr] = xver[i] + slope[nintr] = yver[i] - yver[i-1] + if (slope[nintr] < 0.0) + nneg = nneg + 1 + else if (slope[nintr] > 0.0) + nplus = nplus + 1 + else + nzero = nzero + 1 + } + + # If the intersection point is an isolated vertex add + # another point to the list. + + if (dd > 0.0) { + nintr = nintr + 1 + xranges[nintr] = xver[i] + slope[nintr] = dy + if (slope[nintr] < 0.0) + nneg = nneg + 1 + else if (slope[nintr] > 0.0) + nplus = nplus + 1 + else + nzero = nzero + 1 + } + + collinear = false + + } else + collinear = false + } else + collinear = false + + u1 = u2 + } + + # Join up any split collinear line segments. + if (collinear && (slope[1] == 0.0)) { + xranges[1] = xranges[nintr-1] + slope[1] = slope[nintr-1] + nintr = nintr - 2 + nzero = nzero - 2 + } + + # Return the number of intersection points if there are no interior + # collinear line segments. + if (nzero == 0 || nplus == 0 || nneg == 0) + return (nintr) + + # Find the minimum and maximum intersection points. + call ap_alimr (xranges, nintr, u1, u2, imin, imax) + + # Check for vertices at the ends of the ranges. + + u1 = xranges[min(imin,imax)] - xranges[1] + u2 = xranges[nintr] - xranges[max(imin,imax)] + + # Vertices were traversed in order of increasing x. + if ((u1 >= 0.0 && u2 > 0.0) || (u1 > 0.0 && u2 >= 0.0) || + (u1 == u2 && imax > imin)) { + do i = imax + 1, nintr { + if (xranges[i] != xranges[i-1]) + break + imax = i + } + do i = imin - 1, 1, -1 { + if (xranges[i] != xranges[i+1]) + break + imin = i + } + } + + # Vertices were traversed in order of decreasing x. + if ((u1 <= 0.0 && u2 < 0.0) || (u1 < 0.0 && u2 <= 0.0) || + (u1 == u2 && imax < imin)) { + do i = imin + 1, nintr { + if (xranges[i] != xranges[i-1]) + break + imin = i + } + do i = imax - 1, 1, -1 { + if (xranges[i] != xranges[i+1]) + break + imax = i + } + } + + # Reorder the x ranges and slopes if necessary. + if ((imax < imin) && ! (imin == nintr && imax == 1)) { + call amovr (xranges, xintr, nintr) + do i = 1, imax + xranges[nintr-imax+i] = xintr[i] + do i = imin, nintr + xranges[i-imax] = xintr[i] + call amovr (slope, xintr, nintr) + do i = 1, imax + slope[nintr-imax+i] = xintr[i] + do i = imin, nintr + slope[i-imax] = xintr[i] + } else if ((imin < imax) && ! (imin == 1 && imax == nintr)) { + call amovr (xranges, xintr, nintr) + do i = 1, imin + xranges[nintr-imin+i] = xintr[i] + do i = imax, nintr + xranges[i-imin] = xintr[i] + call amovr (slope, xintr, nintr) + do i = 1, imin + slope[nintr-imin+i] = xintr[i] + do i = imax, nintr + slope[i-imin] = xintr[i] + } + + # Add any extra intersection points that are required to deal with + # the collinear line segments. + + nadd = 0 + for (i = 1; i <= nintr-2; ) { + if (slope[i] * slope[i+2] > 0.0) { + i = i + 2 + } else { + nadd = nadd + 1 + xranges[nintr+nadd] = xranges[i+1] + for (j = i + 3; j <= nintr; j = j + 1) { + if (slope[i] * slope[j] > 0) + break + nadd = nadd + 1 + xranges[nintr+nadd] = xranges[j-1] + } + i = j + } + } + + return (nintr + nadd) +end diff --git a/noao/digiphot/apphot/polyphot/apyfree.x b/noao/digiphot/apphot/polyphot/apyfree.x new file mode 100644 index 00000000..0bede579 --- /dev/null +++ b/noao/digiphot/apphot/polyphot/apyfree.x @@ -0,0 +1,41 @@ +include "../lib/apphotdef.h" +include "../lib/polyphotdef.h" + +# AP_YFREE -- Procedure to free the polyphot structure. + +procedure ap_yfree (ap) + +pointer ap # pointer to the apphot structure + +begin + if (ap == NULL) + return + if (AP_NOISE(ap) != NULL) + call ap_noisecls (ap) + if (AP_PDISPLAY(ap) != NULL) + call ap_dispcls (ap) + if (AP_POLY(ap) != NULL) + call ap_ycls (ap) + if (AP_PSKY(ap) != NULL) + call ap_skycls (ap) + if (AP_PCENTER(ap) != NULL) + call ap_ctrcls (ap) + if (AP_IMBUF(ap) != NULL) + call mfree (AP_IMBUF(ap), TY_REAL) + if (AP_MW(ap) != NULL) + call mw_close (AP_MW(ap)) + call mfree (ap, TY_STRUCT) +end + + +# AP_YCLS -- Procedure to close up the polyphot structure and arrays. + +procedure ap_ycls (ap) + +pointer ap # pointer to the apphot structure + +begin + if (AP_POLY(ap) == NULL) + return + call mfree (AP_POLY(ap), TY_STRUCT) +end diff --git a/noao/digiphot/apphot/polyphot/apyget.x b/noao/digiphot/apphot/polyphot/apyget.x new file mode 100644 index 00000000..a990b6f8 --- /dev/null +++ b/noao/digiphot/apphot/polyphot/apyget.x @@ -0,0 +1,306 @@ +include <fset.h> +include "../lib/apphot.h" +include "../lib/fitsky.h" +include "../lib/polyphot.h" + +# AP_YGET -- Procedure to fetch the coordinates of the vertices of a +# polygon from a text file. + +int procedure ap_yget (py, im, fd, delim, x, y, max_nvertices) + +pointer py # polyphot structure +pointer im # the input image descriptor +int fd # polygon file descriptor +int delim # delimiter character +real x[ARB] # x coords of vertices +real y[ARB] # y coords of vertices +int max_nvertices # maximum number of vertices + +real xc, yc, r2max, r2, xtemp, ytemp +pointer sp, str +int i, nvertices, nreal, stat +char marker +real asumr() +int fscan(), nscan(), strncmp(), apstati() + +begin + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + + # Print prompts if input file is STDIN. + call fstats (fd, F_FILENAME, Memc[str], SZ_LINE) + if (strncmp ("STDIN", Memc[str], 5) == 0) { + call printf ("Type x and y coordinates of vertex\n") + call printf ("\t1 vertex per line\n") + call printf ("\t; to end polygon\n") + call printf ("\t^Z to end list\n") + call flush (STDOUT) + } + + # Get the polygon. + nvertices = 0 + stat = fscan (fd) + while (stat != EOF) { + + # Read the vertices from the file + call gargr (xtemp) + call gargr (ytemp) + nreal = nscan () + if (nreal != 2) { + call reset_scan () + call gargc (marker) + if (int (marker) == delim) + break + nreal = nscan () + } + + # Store the vertices. + if (nreal >= 2) { + nvertices = nvertices + 1 + if (nvertices <= max_nvertices) { + x[nvertices] = xtemp + y[nvertices] = ytemp + } + } + + stat = fscan (fd) + } + + if (nvertices == 0 && stat == EOF) { + + nvertices = EOF + call apsetr (py, PYXMEAN, INDEFR) + call apsetr (py, PYYMEAN, INDEFR) + call apsetr (py, OPYXMEAN, INDEFR) + call apsetr (py, OPYYMEAN, INDEFR) + call apsetr (py, PYCX, INDEFR) + call apsetr (py, PYCY, INDEFR) + call apsetr (py, OPYCX, INDEFR) + call apsetr (py, OPYCY, INDEFR) + call apsetr (py, PYMINRAD, INDEFR) + call apseti (py, PYNVER, 0) + + } else if (nvertices <= 2) { + + call apsetr (py, PYXMEAN, INDEFR) + call apsetr (py, PYYMEAN, INDEFR) + call apsetr (py, OPYXMEAN, INDEFR) + call apsetr (py, OPYYMEAN, INDEFR) + call apsetr (py, PYCX, INDEFR) + call apsetr (py, PYCY, INDEFR) + call apsetr (py, OPYCX, INDEFR) + call apsetr (py, OPYCY, INDEFR) + call apsetr (py, PYMINRAD, INDEFR) + call apseti (py, PYNVER, 0) + nvertices = 0 + + } else { + + # Add in the last vertex. + x[nvertices+1] = x[1] + y[nvertices+1] = y[1] + + # Transform the input coordinates. + switch (apstati(py,WCSIN)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_itol (py, x, y, x, y, nvertices + 1) + case WCS_TV: + call ap_vtol (im, x, y, x, y, nvertices + 1) + default: + ; + } + + # Compute the mean polygon coordinates. + xc = asumr (x, nvertices) / nvertices + yc = asumr (y, nvertices) / nvertices + call apsetr (py, PYXMEAN, xc) + call apsetr (py, PYYMEAN, yc) + call apsetr (py, PYCX, xc) + call apsetr (py, PYCY, yc) + + # Set the minimum size of the sky annulus. + r2max = 0.0 + do i = 1, nvertices { + r2 = (x[i] - xc) ** 2 + (y[i] - yc) ** 2 + if (r2 > r2max) + r2max = r2 + } + + switch (apstati(py,WCSOUT)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_ltoo (py, xc, yc, xc, yc, 1) + case WCS_TV: + call ap_ltov (im, xc, yc, xc, yc, 1) + default: + ; + } + call apsetr (py, OPYXMEAN, xc) + call apsetr (py, OPYYMEAN, yc) + call apsetr (py, OPYCX, xc) + call apsetr (py, OPYCY, yc) + + call apsetr (py, PYMINRAD, (sqrt (r2max) + 1.1)) + call apseti (py, PYNVER, nvertices) + } + + call sfree (sp) + return (nvertices) +end + + +# AP_YMKPOLY -- Mark the coordinates of a polygon on the display device. + +int procedure ap_ymkpoly (py, im, id, x, y, max_nvertices, idflush) + +pointer py # polyphot structure +pointer im # the input image descriptor +pointer id # display pointer +real x[ARB] # x coords of vertices +real y[ARB] # y coords of vertices +int max_nvertices # maximum number of vertices +int idflush # flush the imd interface ? + +int i, nvertices, stat, wcs, key +pointer sp, cmd +real xtemp, ytemp, xc, yc, r2max, r2 +real apstatr(), asumr() +int clgcur(), apstati() +errchk gscur + +begin + # Reopen the device. + if (id != NULL) + call greactivate (id, 0) + + # Initialize. + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + # Type prompt. + call printf ( + "Mark polygon vertex [space=mark,q=quit].\n") + stat = clgcur ("icommands", xtemp, ytemp, wcs, key, Memc[cmd], SZ_LINE) + call ap_vtol (im, xtemp, ytemp, xtemp, ytemp, 1) + + + # Fetch the polygon and draw it on the display. + nvertices = 0 + while (stat != EOF) { + + if (key == 'q') + break + + # Decode and draw vertices. + nvertices = nvertices + 1 + if (nvertices <= max_nvertices) { + x[nvertices] = xtemp + y[nvertices] = ytemp + if (id != NULL) { + if (nvertices == 1) + call gamove (id, x[1], y[1]) + else { + call gadraw (id, x[nvertices], y[nvertices]) + if (idflush == YES) + call gframe (id) + else + call gflush (id) + } + } + } else + break + + # Type prompt. + call printf ( + "Mark polygon vertex [space=mark,q=quit].\n") + stat = clgcur ("icommands", xtemp, ytemp, wcs, key, Memc[cmd], + SZ_LINE) + call ap_vtol (im, xtemp, ytemp, xtemp, ytemp, 1) + } + call printf ("\n") + + call sfree (sp) + + # Return EOF or the number of vertices in the polygon. + if (stat == EOF) { + + call apsetr (py, PYXMEAN, INDEFR) + call apsetr (py, PYYMEAN, INDEFR) + call apsetr (py, OPYXMEAN, INDEFR) + call apsetr (py, OPYYMEAN, INDEFR) + call apsetr (py, PYCX, INDEFR) + call apsetr (py, PYCY, INDEFR) + call apsetr (py, OPYCX, INDEFR) + call apsetr (py, OPYCY, INDEFR) + call apsetr (py, PYMINRAD, INDEFR) + call apseti (py, PYNVER, 0) + nvertices = EOF + + } else if (nvertices <= 2) { + + call apsetr (py, PYXMEAN, INDEFR) + call apsetr (py, PYYMEAN, INDEFR) + call apsetr (py, OPYXMEAN, INDEFR) + call apsetr (py, OPYYMEAN, INDEFR) + call apsetr (py, PYCX, INDEFR) + call apsetr (py, PYCY, INDEFR) + call apsetr (py, OPYCX, INDEFR) + call apsetr (py, OPYCY, INDEFR) + call apsetr (py, PYMINRAD, INDEFR) + call apseti (py, PYNVER, 0) + nvertices = 0 + + } else { + + # Add the last vertex and close the polygon. + x[nvertices+1] = x[1] + y[nvertices+1] = y[1] + if (id != NULL) { + call gadraw (id, x[1], y[1]) + if (idflush == YES) + call gframe (id) + else + call gflush (id) + } + + # Compute and save the mean polygon coords. + xc = asumr (x, nvertices) / nvertices + yc = asumr (y, nvertices) / nvertices + call apsetr (py, PYXMEAN, xc) + call apsetr (py, PYYMEAN, yc) + call apsetr (py, PYCX, xc) + call apsetr (py, PYCY, yc) + if (id != NULL) + call gscur (id, apstatr (py, PYCX), apstatr (py, PYCY)) + + # Compute the mean sky annulus. + r2max = 0.0 + do i = 1, nvertices { + r2 = (x[i] - xc) ** 2 + (y[i] - yc) ** 2 + if (r2 > r2max) + r2max = r2 + } + + # Compute output coordinate centers. + switch (apstati(py,WCSOUT)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_ltoo (py, xc, yc, xc, yc, 1) + case WCS_TV: + call ap_ltov (im, xc, yc, xc, yc, 1) + default: + ; + } + call apsetr (py, OPYXMEAN, xc) + call apsetr (py, OPYYMEAN, yc) + call apsetr (py, OPYCX, xc) + call apsetr (py, OPYCY, yc) + + call apseti (py, PYNVER, nvertices) + call apsetr (py, PYMINRAD, (sqrt (r2max) + 1.1)) + + } + + if (id != NULL) + call gdeactivate (id, 0) + + return (nvertices) +end diff --git a/noao/digiphot/apphot/polyphot/apyinit.x b/noao/digiphot/apphot/polyphot/apyinit.x new file mode 100644 index 00000000..6d9c2fe7 --- /dev/null +++ b/noao/digiphot/apphot/polyphot/apyinit.x @@ -0,0 +1,64 @@ +include "../lib/apphotdef.h" +include "../lib/polyphotdef.h" + +# AP_YINIT - Initialize the polyphot structure. + +procedure ap_yinit (ap, cfunction, cbox, sfunction, annulus, dannulus, fwhmpsf, + noise) + +pointer ap # pointer to the apphot structure +int cfunction # centering algorithm +real cbox # centering box half-width +int sfunction # sky fitting algorithm +real annulus # inner radius of sky annulus +real dannulus # width of sky annulus +real fwhmpsf # fwhmpsf +int noise # Noise function + +begin + call malloc (ap, LEN_APSTRUCT, TY_STRUCT) + + # Set the global apphot package parameters. + call ap_defsetup (ap, fwhmpsf) + + # Setup noise parameters. + call ap_noisesetup (ap, noise) + + # Set display options. + call ap_dispsetup (ap) + + # Setup the centering parameters. + call ap_ctrsetup (ap, cfunction, cbox) + + # Set up the sky fitting parameters. + call ap_skysetup (ap, sfunction, annulus, dannulus) + + # Setup the polyphot parameters. + call ap_ysetup (ap) + + # Set unused structure pointers to null. + AP_PPSF(ap) = NULL + AP_PPHOT(ap) = NULL + AP_RPROF(ap) = NULL +end + + +# AP_YSETUP -- Procedure to set parameters for polygonal aperture photometry. + +procedure ap_ysetup (ap) + +pointer ap # pointer to apphot strucuture + +pointer ply + +begin + call malloc (AP_POLY(ap), LEN_PYSTRUCT, TY_STRUCT) + ply = AP_POLY(ap) + AP_PYCX(ply) = INDEFR + AP_PYCY(ply) = INDEFR + AP_PYX(ply) = INDEFR + AP_PYY(ply) = INDEFR + AP_PYZMAG(ply) = DEF_PYZMAG + AP_PYNAME(ply) = EOS + AP_PYROOT(ply) = EOS +end diff --git a/noao/digiphot/apphot/polyphot/apymkfree.x b/noao/digiphot/apphot/polyphot/apymkfree.x new file mode 100644 index 00000000..424b94e3 --- /dev/null +++ b/noao/digiphot/apphot/polyphot/apymkfree.x @@ -0,0 +1,23 @@ +include "../lib/apphotdef.h" + +# AP_YMKFREE -- Procedure to free the polyphot structure. + +procedure ap_ymkfree (ap) + +pointer ap # pointer to the apphot structure + +begin + if (ap == NULL) + return + if (AP_NOISE(ap) != NULL) + call ap_noisecls (ap) + if (AP_PDISPLAY(ap) != NULL) + call ap_dispcls (ap) + if (AP_POLY(ap) != NULL) + call ap_ycls (ap) + if (AP_IMBUF(ap) != NULL) + call mfree (AP_IMBUF(ap), TY_REAL) + if (AP_MW(ap) != NULL) + call mw_close (AP_MW(ap)) + call mfree (ap, TY_STRUCT) +end diff --git a/noao/digiphot/apphot/polyphot/apymkinit.x b/noao/digiphot/apphot/polyphot/apymkinit.x new file mode 100644 index 00000000..215d3e9c --- /dev/null +++ b/noao/digiphot/apphot/polyphot/apymkinit.x @@ -0,0 +1,31 @@ +include "../lib/apphotdef.h" +include "../lib/noise.h" + +# AP_YMKINIT - Procedure to initialize the polymark structure. + +procedure ap_ymkinit (ap) + +pointer ap # pointer to the apphot structure + +begin + call calloc (ap, LEN_APSTRUCT, TY_STRUCT) + + # Set the main structure parameters. + call ap_defsetup (ap, 2.5) + + # Set the noise options. + call ap_noisesetup (ap, AP_NPOISSON) + + # Set display options. + call ap_dispsetup (ap) + + # Setup the polyphot parameters. + call ap_ysetup (ap) + + # Set unused structure pointers to null. + AP_PCENTER(ap) = NULL + AP_PSKY(ap) = NULL + AP_PPHOT(ap) = NULL + AP_RPROF(ap) = NULL + AP_PPSF(ap) = NULL +end diff --git a/noao/digiphot/apphot/polyphot/apynextobj.x b/noao/digiphot/apphot/polyphot/apynextobj.x new file mode 100644 index 00000000..292d84bd --- /dev/null +++ b/noao/digiphot/apphot/polyphot/apynextobj.x @@ -0,0 +1,190 @@ +include <fset.h> +include "../lib/apphot.h" +include "../lib/polyphot.h" + +# AP_YNEXTOBJ -- Read the next polygon from the list polygon and/or coordinate +# list. + +int procedure ap_ynextobj (py, im, id, pl, cl, delim, x, y, maxnver, prev_num, + req_num, ld, pd) + +pointer py # pointer to the apphot structre +pointer im # the input image descriptor +pointer id # pointer to image display stream +int pl # polygons file descriptor +int cl # coordinates file descriptor +int delim # delimiter character +real x[ARB] # x coordinates of the polygon vertices +real y[ARB] # y coordinates of the polygon vertices +int maxnver # maximum number of vertices +int prev_num # previous object +int req_num # requested object +int ld # current object +int pd # current polygon + +real xshift, yshift +pointer sp, fname +int stdin, nskip, ncount, nver, stat +real apstatr() +int strncmp(), ap_yget(), ap_ycoords(), apstati() +errchk greactivate, gdeactivate, gscur + +begin + # The coordinate list is undefined. + if (cl == NULL) { + + # Get the input file name. + call smark (sp) + call salloc (fname, SZ_FNAME, TY_CHAR) + call fstats (pl, F_FILENAME, Memc[fname], SZ_FNAME) + + # Compute the number of polygons that must be skipped. + if (strncmp ("STDIN", Memc[fname], 5) == 0) { + stdin = YES + nskip = 1 + } else { + stdin = NO + if (req_num <= prev_num) { + call seek (pl, BOF) + nskip = req_num + } else + nskip = req_num - prev_num + } + + # Initialize the polygon search. + ncount = 0 + pd = prev_num + + # Find the correct polygon. + repeat { + + call apsetr (py, PYX, apstatr (py, PYCX)) + call apsetr (py, PYY, apstatr (py, PYCY)) + nver = ap_yget (py, im, pl, delim, x, y, maxnver) + + if (nver == EOF) { + ncount = EOF + } else if (nver > 0) { + ncount = ncount + 1 + pd = pd + 1 + } + + } until (ncount == EOF || ncount == nskip) + + # Return the polygon number. + if (req_num <= prev_num) + pd = ncount + ld = pd + + call sfree (sp) + + if (ncount == EOF) { + return (EOF) + } else if (id != NULL) { + iferr { + call greactivate (id, 0) + call gscur (id, apstatr (py, PYCX), apstatr (py, PYCY)) + call gdeactivate (id, 0) + } then + ; + return (nver) + } else { + return (nver) + } + + # Both the polygon and coordinate file are defined. + } else { + + # Get the input file name. + call smark (sp) + call salloc (fname, SZ_FNAME, TY_CHAR) + call fstats (cl, F_FILENAME, Memc[fname], SZ_FNAME) + + # Compute the number of objects that must be skipped. + if (strncmp ("STDIN", Memc[fname], 5) == 0) { + stdin = YES + nskip = 1 + } else { + stdin = NO + if (req_num <= prev_num) { + call seek (cl, BOF) + call seek (pl, BOF) + pd = 0 + nskip = req_num + } else + nskip = req_num - prev_num + } + + # Initialize the polygon id. + ncount = 0 + ld = prev_num + + # Find the correct object and shift the coordinates. + repeat { + + # Read the coordinates and the polygon. + stat = ap_ycoords (cl, delim, xshift, yshift, stdin) + if (stat == EOF) { + ncount = EOF + } else if (stat == NEXT_POLYGON || pd == 0) { + call apsetr (py, PYX, apstatr (py, PYCX)) + call apsetr (py, PYY, apstatr (py, PYCY)) + nver = ap_yget (py, im, pl, delim, x, y, maxnver) + if (nver == EOF) + ncount = EOF + else if (nver > 0) + pd = pd + 1 + } + + # Shift the polygon coordinates. + if (stat == THIS_OBJECT && ncount != EOF && nver > 0) { + switch (apstati(py,WCSIN)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_itol (py, xshift, yshift, xshift, yshift, 1) + case WCS_TV: + call ap_vtol (im, xshift, yshift, xshift, yshift, 1) + default: + ; + } + call aaddkr (x, (xshift - apstatr (py, PYCX)), x, nver + 1) + call aaddkr (y, (yshift - apstatr (py, PYCY)), y, nver + 1) + call apsetr (py, PYCX, xshift) + call apsetr (py, PYCY, yshift) + switch (apstati(py,WCSOUT)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_ltoo (py, xshift, yshift, xshift, yshift, 1) + case WCS_TV: + call ap_ltov (im, xshift, yshift, xshift, yshift, 1) + default: + ; + } + call apsetr (py, OPYCX, xshift) + call apsetr (py, OPYCY, yshift) + ncount = ncount + 1 + ld = ld + 1 + } + + } until (ncount == EOF || ncount == nskip) + + # Get the correct id. + if (req_num <= prev_num) + ld = ncount + + call sfree (sp) + + if (ncount == EOF) { + return (EOF) + } else if (id != NULL) { + iferr { + call greactivate (id, 0) + call gscur (id, apstatr (py, PYCX), apstatr (py, PYCY)) + call gdeactivate (id, 0) + } then + ; + return (nver) + } else { + return (nver) + } + } + +end diff --git a/noao/digiphot/apphot/polyphot/apypars.x b/noao/digiphot/apphot/polyphot/apypars.x new file mode 100644 index 00000000..4f988323 --- /dev/null +++ b/noao/digiphot/apphot/polyphot/apypars.x @@ -0,0 +1,20 @@ +# AP_PYPARS -- Procedure to write the current polyphot parameters to the +# output file. + +procedure ap_pypars (ap) + +pointer ap # pointer to apphot structure + +begin + # Write the data dependent parameters. + call ap_dapars (ap) + + # Write the centering parameters. + call ap_cepars (ap) + + # Write the sky fitting parameters. + call ap_sapars (ap) + + # Set the photometry parameters. + call ap_popars (ap) +end diff --git a/noao/digiphot/apphot/polyphot/apyphot.x b/noao/digiphot/apphot/polyphot/apyphot.x new file mode 100644 index 00000000..cd7bac0a --- /dev/null +++ b/noao/digiphot/apphot/polyphot/apyphot.x @@ -0,0 +1,577 @@ +include <ctype.h> +include <gset.h> +include <imhdr.h> +include "../lib/apphot.h" +include "../lib/display.h" +include "../lib/fitsky.h" +include "../lib/polyphot.h" + +define HELPFILE "apphot$polyphot/polyphot.key" + +# AP_YPHOT -- Compute the flux inside polygonal apertures. + +int procedure ap_yphot (py, im, cl, pl, gd, id, out, stid, interactive, cache) + +pointer py # pointer to apphot structure +pointer im # pointer to IRAF image +int cl # coordinate file descriptor +int pl # starlist file descriptor +pointer gd # pointer to graphcis stream +pointer id # pointer to image display stream +int out # output file descriptor +int stid # output file sequence number +int interactive # interactive mode +int cache # cache the input image pixels + +real wx, wy +pointer sp, x, y, xout, yout, cmd +int nvertices, cier, sier, pier, wcs, key, ip, colonkey +int prev_num, req_num, ptid, ltid, delim, newlist, newimage +int newcenterbuf, newcenter, newskybuf, newsky, newmagbuf, newmag +int req_size, old_size, buf_size, memstat + +real apstatr() +int ap_ymkpoly(), ap_yfit(), clgcur(), apfitsky(), aprefitsky() +int apstati(), ctoi(), ap_ynextobj(), ap_ycenter(), ap_yrecenter() +int apgqverify(), apgtverify(), ap_yradsetup(), apnew(), ap_avsky() +int ap_memstat(), sizeof() +bool fp_equalr() +data delim /';'/ + +define endswitch_ 99 + +begin + # Allocate temporary space. + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + call salloc (x, MAX_NVERTICES + 1, TY_REAL) + call salloc (y, MAX_NVERTICES + 1, TY_REAL) + call salloc (xout, MAX_NVERTICES + 1, TY_REAL) + call salloc (yout, MAX_NVERTICES + 1, TY_REAL) + + # Initialize the cursor read. + key = ' ' + Memc[cmd] = EOS + + # Initialize the fit. + newimage = NO + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newmagbuf = YES; newmag = YES + cier = AP_OK; sier = AP_OK; pier = AP_OK + + # Initialize the sequencing. + newlist = NO + ptid = 0 + ltid = 0 + + # Loop over the polygon file. + nvertices = 0 + while (clgcur ("icommands", wx, wy, wcs, key, Memc[cmd], SZ_LINE) != + EOF) { + + # Store the current coordinates. + call ap_vtol (im, wx, wy, wx, wy, 1) + call apsetr (py, CWX, wx) + call apsetr (py, CWY, wy) + + # Has the polygon moved ? + if (apnew (py, wx, wy, apstatr (py, PYCX), apstatr (py, PYCY), + newlist) == YES) { + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newmagbuf = YES; newmag = YES + } + + # Loop over the colon commands. + switch (key) { + + # Quit. + case 'q': + if (interactive == YES) { + if (apgqverify ("polyphot", py, key) == YES) { + call sfree (sp) + return (apgtverify (key)) + } + } else { + call sfree (sp) + return (NO) + } + + # Print the help page. + case '?': + if ((id != NULL) && (id == gd)) + call gpagefile (id, HELPFILE, "") + else if (interactive == YES) + call pagefile (HELPFILE, "[space=morehelp,q=quit,?=help]") + + # Plot a centered stellar radial profile. + case 'd': + if (interactive == YES) + call ap_qrad (py, im, wx, wy, gd) + + # Setup the parameters using a radial profile plot + case 'i': + if (interactive == YES) { + nvertices = ap_yradsetup (py, im, id, gd, out, stid, + Memr[x], Memr[y], MAX_NVERTICES) + newlist = NO + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newmagbuf = YES; newmag = YES + } + + # Verify the critical parameters. + case 'v': + call ap_yconfirm (py, out, stid) + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newmagbuf = YES; newmag = YES + + # Define a polygon interactively. + case 'g': + if (interactive == YES) { + if (id == gd) + nvertices = ap_ymkpoly (py, im, id, Memr[x], Memr[y], + MAX_NVERTICES, NO) + else + nvertices = ap_ymkpoly (py, im, id, Memr[x], Memr[y], + MAX_NVERTICES, YES) + if (id != NULL) { + if (id == gd) + call gflush (id) + else + call gframe (id) + } + newlist = NO + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newmagbuf = YES; newmag = YES + } + + # Print error messages. + case 'e': + if (interactive == YES) + call ap_pyerrors (py, cier, sier, pier) + + # Rewind the polygon and coordinate lists. + case 'r': + if (pl != NULL) { + call seek (pl, BOF) + if (cl != NULL) + call seek (cl, BOF) + ptid = 0 + ltid = 0 + } else if (interactive == YES) + call printf ("No polygon list\n") + + # Show/set polyphot parameters. + case ':': + for (ip = 1; IS_WHITE(Memc[cmd+ip-1]); ip = ip + 1) + ; + + colonkey = Memc[cmd+ip-1] + switch (colonkey) { + case 'm', 'n': + + # Show/set polyphot parameters + if (Memc[cmd+ip] != EOS && Memc[cmd+ip] != ' ') { + call ap_ycolon (py, im, pl, cl, out, stid, ptid, ltid, + Memc[cmd], newimage, newcenterbuf, newcenter, + newskybuf, newsky, newmagbuf, newmag) + goto endswitch_ + } + + # Measure the next object in the list. + if (pl != NULL) { + if (interactive == YES) + call printf ("No polygon list\n") + goto endswitch_ + } + + # Get the next polygon. + ip = ip + 1 + prev_num = ltid + if (ctoi (Memc[cmd], ip, req_num) <= 0) + req_num = ltid + 1 + nvertices = ap_ynextobj (py, im, id, pl, cl, delim, Memr[x], + Memr[y], MAX_NVERTICES, prev_num, req_num, ltid, ptid) + if (nvertices == EOF) { + if (interactive == YES) + call printf ( + "End of polygon list, use r key to rewind\n") + goto endswitch_ + } + + # Move to the next object. + newlist = YES + if (colonkey == 'm') { + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newmagbuf = YES; newmag = YES + goto endswitch_ + } + + # Fit the center, sky and measure polygon. + cier = ap_ycenter (py, im, apstatr (py, PYCX), apstatr (py, + PYCY), Memr[x], Memr[y], nvertices + 1) + sier = apfitsky (py, im, apstatr (py, PYCX), apstatr (py, + PYCY), NULL, gd) + pier = ap_yfit (py, im, Memr[x], Memr[y], nvertices + 1, + apstatr (py, SKY_MODE), apstatr (py, SKY_SIGMA), + apstati (py, NSKY)) + if (interactive == YES) + call ap_qyprint (py, cier, sier, pier) + + # Draw the polygon. + if (id != NULL) { + call appymark (py, id, Memr[x], Memr[y], nvertices + 1, + apstati (py, MKCENTER), apstati (py, MKSKY), + apstati (py, MKPOLYGON)) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + + # Write the results to output. + if (stid == 1) + call ap_param (py, out, "polyphot") + + switch (apstati(py,WCSOUT)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_ltoo (py, Memr[x], Memr[y], Memr[xout], + Memr[yout], nvertices + 1) + case WCS_TV: + call ap_ltov (im, Memr[x], Memr[y], Memr[xout], + Memr[yout], nvertices + 1) + default: + call amovr (Memr[x], Memr[xout], nvertices + 1) + call amovr (Memr[y], Memr[yout], nvertices + 1) + } + if (newlist == YES) + call ap_yprint (py, out, Memr[xout], Memr[yout], + nvertices, stid, ltid, ptid, cier, sier, pier) + else + call ap_yprint (py, out, Memr[xout], Memr[yout], + nvertices, stid, 0, ptid, cier, sier, pier) + + # Set up for the next object. + stid = stid + 1 + newcenterbuf = NO; newcenter = NO + newskybuf = NO; newsky = NO + newmagbuf = NO; newmag = NO + + # Show/set polyphot parameters. + default: + call ap_ycolon (py, im, pl, cl, out, stid, ptid, ltid, + Memc[cmd], newimage, newcenterbuf, newcenter, + newskybuf, newsky, newmagbuf, newmag) + } + + # Reestablish the image display viewport and window. + if (newimage == YES) { + if ((id != NULL) && (id != gd)) + call ap_gswv (id, Memc[cmd], im, 4) + req_size = MEMFUDGE * IM_LEN(im,1) * IM_LEN(im,2) * + sizeof (IM_PIXTYPE(im)) + memstat = ap_memstat (cache, req_size, old_size) + if (memstat == YES) + call ap_pcache (im, INDEFI, buf_size) + } + newimage = NO + + # Get measure next object in the list. + case 'm', 'n': + if (pl == NULL) { + if (interactive == YES) + call printf ("No polygon list\n") + goto endswitch_ + } + + # Get the next polygon. + prev_num = ltid + req_num = ltid + 1 + nvertices = ap_ynextobj (py, im, id, pl, cl, delim, Memr[x], + Memr[y], MAX_NVERTICES, prev_num, req_num, ltid, ptid) + if (nvertices == EOF) { + if (interactive == YES) + call printf ( + "End of polygon list, use r key to rewind\n") + goto endswitch_ + } + + # Move to next object. + newlist = YES + if (key == 'm') { + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newmagbuf = YES; newmag = YES + goto endswitch_ + } + + # Measure next object. + cier = ap_ycenter (py, im, apstatr (py, PYCX), apstatr (py, + PYCY), Memr[x], Memr[y], nvertices + 1) + sier = apfitsky (py, im, apstatr (py, PYCX), apstatr (py, + PYCY), NULL, gd) + pier = ap_yfit (py, im, Memr[x], Memr[y], nvertices + 1, + apstatr (py, SKY_MODE), apstatr (py, SKY_SIGMA), + apstati (py, NSKY)) + if (interactive == YES) + call ap_qyprint (py, cier, sier, pier) + + # Draw the polygon. + if (id != NULL) { + call appymark (py, id, Memr[x], Memr[y], nvertices + 1, + apstati (py, MKCENTER), apstati (py, MKSKY), + apstati (py, MKPOLYGON)) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + + # Write the results to output. + if (stid == 1) + call ap_param (py, out, "polyphot") + switch (apstati(py,WCSOUT)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_ltoo (py, Memr[x], Memr[y], Memr[xout], Memr[yout], + nvertices + 1) + case WCS_TV: + call ap_ltov (im, Memr[x], Memr[y], Memr[xout], Memr[yout], + nvertices + 1) + default: + call amovr (Memr[x], Memr[xout], nvertices + 1) + call amovr (Memr[y], Memr[yout], nvertices + 1) + } + if (newlist == YES) + call ap_yprint (py, out, Memr[xout], Memr[yout], nvertices, + stid, ltid, ptid, cier, sier, pier) + else + call ap_yprint (py, out, Memr[xout], Memr[yout], nvertices, + stid, 0, ptid, cier, sier, pier) + + # Set up for the next object. + stid = stid + 1 + newcenterbuf = NO; newcenter = NO + newskybuf = NO; newsky = NO + newmagbuf = NO; newmag = NO + + # Process the remainder of the list. + case 'l': + if (pl != NULL) { + call ap_ybphot (py, im, cl, pl, out, stid, ltid, ptid, id, + YES) + if (id != NULL) { + if (id == gd) + call gflush (id) + else + call gframe (id) + } + } else if (interactive == YES) + call printf ("No polygon list\n") + + # Save current parameters in the pset file. + case 'w': + call ap_pypars (py) + + # Center the current polygon around the cursor poition. + case 'c': + if (newcenterbuf == YES) + cier = ap_ycenter (py, im, wx, wy, Memr[x], Memr[y], + nvertices + 1) + else if (newcenter == YES) + cier = ap_yrecenter (py, im, Memr[x], Memr[y], + nvertices + 1, cier) + if (interactive == YES) + call ap_qcenter (py, cier) + if (id != NULL) { + call apmark (py, id, apstati (py, MKCENTER), NO, NO) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + newcenterbuf = NO; newcenter = NO + + # Fit the sky around the cursor position. + case 't': + if (newskybuf == YES || ! fp_equalr (wx, + apstatr (py, SXCUR)) || ! fp_equalr (wy, apstatr (py, + SYCUR))) + sier = apfitsky (py, im, wx, wy, NULL, gd) + else if (newsky == YES) + sier = aprefitsky (py, im, gd) + if (interactive == YES) + call ap_qspsky (py, sier) + if (id != NULL) { + call apmark (py, id, NO, apstati (py, MKSKY), NO) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + newskybuf = NO; newsky = NO + + # Compute the average of several sky measurements around + # different cursor postions. + case 'a': + sier = ap_avsky (py, im, stid, NULL, id, gd, interactive) + if (interactive == YES) + call ap_qaspsky (py, sier) + newskybuf = NO; newsky = NO + + # Fit sky in an annulus around the current polygon. + case 's': + if (newskybuf == YES || ! fp_equalr (apstatr (py, PYCX), + apstatr (py, SXCUR)) || ! fp_equalr (apstatr (py, PYCY), + apstatr (py, SYCUR))) + sier = apfitsky (py, im, apstatr (py, PYCX), apstatr (py, + PYCY), NULL, gd) + else if (newsky == YES) + sier = aprefitsky (py, im, gd) + if (interactive == YES) + call ap_qspsky (py, sier) + if (id != NULL) { + call apmark (py, id, NO, apstati (py, MKSKY), NO) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + newskybuf = NO; newsky = NO + + # Compute the magnitudes of current polygon using the current sky. + case 'p', 'o': + if (newcenterbuf == YES) + cier = ap_ycenter (py, im, wx, wy, Memr[x], Memr[y], + nvertices + 1) + else if (newcenter == YES) + cier = ap_yrecenter (py, im, Memr[x], Memr[y], + nvertices + 1, cier) + pier = ap_yfit (py, im, Memr[x], Memr[y], nvertices + 1, + apstatr (py, SKY_MODE), apstatr (py, SKY_SIGMA), + apstati (py, NSKY)) + if (interactive == YES) + call ap_qyprint (py, cier, sier, pier) + if (id != NULL) { + call appymark (py, id, Memr[x], Memr[y], nvertices + 1, + NO, NO, apstati (py, MKPOLYGON)) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + newcenterbuf = NO; newcenter = NO + newmagbuf = NO; newmag = NO + + # Write the results. + if (key == 'o') { + if (stid == 1) + call ap_param (py, out, "polyphot") + switch (apstati(py,WCSOUT)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_ltoo (py, Memr[x], Memr[y], Memr[xout], + Memr[yout], nvertices + 1) + case WCS_TV: + call ap_ltov (im, Memr[x], Memr[y], Memr[xout], + Memr[yout], nvertices + 1) + default: + call amovr (Memr[x], Memr[xout], nvertices + 1) + call amovr (Memr[y], Memr[yout], nvertices + 1) + } + if (newlist == YES) + call ap_yprint (py, out, Memr[xout], Memr[yout], + nvertices, stid, ltid, ptid, cier, sier, pier) + else + call ap_yprint (py, out, Memr[xout], Memr[yout], + nvertices, stid, 0, ptid, cier, sier, pier) + stid = stid + 1 + } + + # Center, compute the sky and the magnitudes and save the results. + case 'h', 'j', 'f', ' ': + + # Compute the centers. + if (key == 'f' || key == ' ') { + if (newcenterbuf == YES) + cier = ap_ycenter (py, im, wx, wy, Memr[x], Memr[y], + nvertices + 1) + else if (newcenter == YES) + cier = ap_yrecenter (py, im, Memr[x], Memr[y], + nvertices + 1, cier) + } else { + if (newcenterbuf == YES) + cier = ap_ycenter (py, im, apstatr (py, PYCX), + apstatr (py, PYCY), Memr[x], Memr[y], nvertices + 1) + else if (newcenter == YES) + cier = ap_yrecenter (py, im, Memr[x], Memr[y], + nvertices + 1, cier) + } + + # Compute the sky values and the magnitudes. + if (newskybuf == YES || ! fp_equalr (apstatr (py, + PYCX), apstatr (py, SXCUR)) || ! fp_equalr (apstatr (py, + PYCY), apstatr (py, SYCUR))) sier = apfitsky (py, im, + apstatr (py, PYCX), apstatr (py, PYCY), NULL, gd) + else if (newsky == YES) + sier = aprefitsky (py, im, gd) + pier = ap_yfit (py, im, Memr[x], Memr[y], nvertices + 1, + apstatr (py, SKY_MODE), apstatr (py, SKY_SIGMA), + apstati (py, NSKY)) + + if (interactive == YES) + call ap_qyprint (py, cier, sier, pier) + if (id != NULL) { + call appymark (py, id, Memr[x], Memr[y], nvertices + 1, + apstati (py, MKCENTER), apstati (py, MKSKY), + apstati (py, MKPOLYGON)) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + + newcenterbuf = NO; newcenter = NO + newskybuf = NO; newsky = NO + newmagbuf = NO; newmag = NO + + # Write the results to an output file. + if (key == ' ' || key == 'j') { + if (stid == 1) + call ap_param (py, out, "polyphot") + switch (apstati(py,WCSOUT)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_ltoo (py, Memr[x], Memr[y], Memr[xout], + Memr[yout], nvertices + 1) + case WCS_TV: + call ap_ltov (im, Memr[x], Memr[y], Memr[xout], + Memr[yout], nvertices + 1) + default: + call amovr (Memr[x], Memr[xout], nvertices + 1) + call amovr (Memr[y], Memr[yout], nvertices + 1) + } + if (newlist == YES) + call ap_yprint (py, out, Memr[xout], Memr[yout], + nvertices, stid, ltid, ptid, cier, sier, pier) + else + call ap_yprint (py, out, Memr[xout], Memr[yout], + nvertices, stid, 0, ptid, cier, sier, pier) + stid = stid + 1 + } + + default: + call printf ("Unknown or ambigous keystroke command\n") + } + +endswitch_ + # Reset the keystroke and command defaults. + key = ' ' + Memc[cmd] = EOS + call apsetr (py, WX, apstatr (py, CWX)) + call apsetr (py, WY, apstatr (py, CWY)) + } + +end diff --git a/noao/digiphot/apphot/polyphot/apyprint.x b/noao/digiphot/apphot/polyphot/apyprint.x new file mode 100644 index 00000000..dda24c3f --- /dev/null +++ b/noao/digiphot/apphot/polyphot/apyprint.x @@ -0,0 +1,94 @@ +include "../lib/apphot.h" +include "../lib/center.h" +include "../lib/fitsky.h" +include "../lib/polyphot.h" + +# AP_YPRINT -- Write the results of the polyphot task to the output file. + +procedure ap_yprint (py, fd, xver, yver, nver, id, lid, pid, cier, sier, pier) + +pointer py # pointer to apphot structure +int fd # output file descriptor +real xver[ARB] # coords of x vertices +real yver[ARB] # coords of y vertices +int nver # number of vertices +int id # id number of str +int lid # list id number of star +int pid # polygon number +int cier # centering error +int sier # sky fitting error +int pier # photometric error + +real apstatr() + +begin + if (fd == NULL) + return + + # Write object id parameters. + call ap_wid (py, fd, apstatr (py, OXINIT), apstatr (py, OYINIT), id, + lid, '\\') + + # Write the centering parameters + call ap_wcres (py, fd, cier, '\\') + + # Write the fitsky parameters. + call ap_wsres (py, fd, sier, '\\') + + # Write the polyphot parameters + call ap_wlres (py, fd, xver, yver, nver, pid, pier) +end + + +# AP_QYPRINT -- Print a quick summary of the polyphot results on the standard +# output. + +procedure ap_qyprint (py, cier, sier, pier) + +pointer py # pointer to apphot structure +int cier # centering error +int sier # sky fitting error +int pier # photometry error + +pointer sp, imname +real apstatr() + +begin + # Allocate space. + call smark (sp) + call salloc (imname, SZ_FNAME, TY_CHAR) + + # Print polyphot magnitudes. + #call apstats (py, IMNAME, Memc[imname], SZ_FNAME) + call apstats (py, IMROOT, Memc[imname], SZ_FNAME) + call printf ("%s %8.2f %8.2f %8g ") + call pargstr (Memc[imname]) + call pargr (apstatr (py, OPYCX)) + call pargr (apstatr (py, OPYCY)) + call pargr (apstatr (py, SKY_MODE)) + call printf ("%7.3f %s\n") + call pargr (apstatr (py, PYMAG)) + if (cier != AP_OK || sier != AP_OK || pier != AP_OK) + call pargstr ("err") + else + call pargstr ("ok") + + call sfree (sp) +end + + +# AP_YHDR -- Write the polyphot header banner to the output file. + +procedure ap_yhdr (ap, fd) + +pointer ap # apphot structure +int fd # output file descriptor + +begin + if (fd == NULL) + return + call ap_idhdr (ap, fd) + call ap_chdr (ap, fd) + call ap_shdr (ap, fd) + call ap_plhdr (ap, fd) +end diff --git a/noao/digiphot/apphot/polyphot/apyradsetup.x b/noao/digiphot/apphot/polyphot/apyradsetup.x new file mode 100644 index 00000000..a966110b --- /dev/null +++ b/noao/digiphot/apphot/polyphot/apyradsetup.x @@ -0,0 +1,135 @@ +include "../lib/fitsky.h" +include "../lib/polyphot.h" + +define HELPFILE "apphot$polyphot/ipolyphot.key" + +# AP_YRADSETUP - Set up polyphot interactively using a radial profile +# plot of a bright star. + +int procedure ap_yradsetup (ap, im, id, gd, out, stid, x, y, max_nvertices) + +pointer ap # pointer to apphot structure +pointer im # pointer to the IRAF image +pointer id # pointer to the image display +pointer gd # pointer to graphics stream +int out # output file descriptor +int stid # output file sequence number +real x[ARB] # array of x vertices +real y[ARB] # array of y vertices +int max_nvertices # maximum number of vertices + +int nvertices, cier, sier, pier, key, wcs +pointer sp, str, cmd +real rmin, rmax, imin, imax, u1, u2, v1, v2, x1, x2, y1, y2 +real xcenter, ycenter, xc, yc, rval + +int ap_ycenter(), clgcur(), ap_showplot() +int apfitsky(), ap_yfit(), apstati(), ap_ymkpoly() +real apstatr(), ap_cfwhmpsf(), ap_ccapert(), ap_cannulus(), ap_csigma() +real ap_cdannulus(), ap_cdatamin(), ap_cdatamax() +real ap_crgrow(), ap_crclean(), ap_crclip() + +begin + # Mark the polygon interactively. + if (id == gd) + nvertices = ap_ymkpoly (ap, im, id, x, y, max_nvertices, NO) + else + nvertices = ap_ymkpoly (ap, im, id, x, y, max_nvertices, YES) + if (id != NULL) { + if (gd == id) + call gflush (id) + else + call gframe (id) + } + if (nvertices <= 0) + return (nvertices) + + # Store the viewport and window coordinates. + call ggview (gd, u1, u2, v1, v2) + call ggwind (gd, x1, x2, y1, y2) + + # Check for open display device and graphics stream. + if (gd == NULL) + return (0) + call greactivate (gd, 0) + + # Show the plot. + if (ap_showplot (ap, im, apstatr (ap, PYCX), apstatr (ap, PYCY), gd, + xcenter, ycenter, rmin, rmax, imin, imax) == ERR) { + call gdeactivate (gd, 0) + return (nvertices) + } + + # Allocate memory. + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + call salloc (cmd, SZ_LINE, TY_CHAR) + + call printf ( + "Waiting for setup menu command (?=help, v=default setup, q=quit):\n") + while (clgcur ("gcommands", xc, yc, wcs, key, Memc[cmd], + SZ_LINE) != EOF) { + + switch (key) { + + case 'q': + break + case '?': + call gpagefile (gd, HELPFILE, "") + case 'f': + rval = ap_cfwhmpsf (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'h': + #rval = ap_ccthresh (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'c': + rval = ap_ccapert (ap, gd, out, stid, rmin, rmax, imin, imax) + case 's': + rval = ap_csigma (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'n': + rval = ap_crclean (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'p': + rval = ap_crclip (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'l': + rval = ap_cdatamin (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'u': + rval = ap_cdatamax (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'a': + rval = ap_cannulus (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'd': + rval = ap_cdannulus (ap, gd, out, stid, apstatr (ap, ANNULUS), + rmin, rmax, imin, imax) + case 'g': + rval = ap_crgrow (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'v': + rval = ap_cfwhmpsf (ap, gd, out, stid, rmin, rmax, imin, imax) + rval = ap_ccapert (ap, gd, out, stid, rmin, rmax, imin, imax) + rval = ap_csigma (ap, gd, out, stid, rmin, rmax, imin, imax) + rval = ap_cannulus (ap, gd, out, stid, rmin, rmax, imin, imax) + rval = ap_cdannulus (ap, gd, out, stid, apstatr (ap, ANNULUS), + rmin, rmax, imin, imax) + default: + call printf ("Unknown or ambiguous keystroke command\007\n") + } + call printf ( + "Waiting for setup menu command (?=help, v=default setup, q=quit):\n") + } + call printf ( + "Interactive setup is complete. Type w to save parameters.\n") + + # Restore the viewport and window coordinates. + call gsview (gd, u1, u2, v1, v2) + call gswind (gd, x1, x2, y1, y2) + + # Clean up memory space. + call gdeactivate (gd, 0) + call sfree (sp) + + # Print the answer. + cier = ap_ycenter (ap, im, xcenter, ycenter, x, y, nvertices + 1) + sier = apfitsky (ap, im, apstatr (ap, PYCX), apstatr (ap, PYCY), + NULL, gd) + pier = ap_yfit (ap, im, x, y, nvertices + 1, apstatr (ap, SKY_MODE), + apstatr (ap, SKY_SIGMA), apstati (ap, NSKY)) + call ap_qyprint (ap, cier, sier, pier) + + return (nvertices) +end diff --git a/noao/digiphot/apphot/polyphot/apyshift.x b/noao/digiphot/apphot/polyphot/apyshift.x new file mode 100644 index 00000000..4fd56cbe --- /dev/null +++ b/noao/digiphot/apphot/polyphot/apyshift.x @@ -0,0 +1,41 @@ +include "../lib/apphot.h" +include "../lib/polyphot.h" + +# AP_YSHIFT -- Shift a polygon to a new center position. + +procedure ap_yshift (py, im, x, y, nver, newx, newy) + +pointer py # pointer to the polyphot structure +pointer im # the input image descriptor +real x[ARB] # x coordinates of the vertices +real y[ARB] # y coordinates of the vertices +int nver # number of vertices +real newx, newy # new x and y coordinates of center + +real xshift, yshift +real apstatr() +int apstati() + +begin + call apsetr (py, PYX, apstatr (py, PYCX)) + call apsetr (py, PYY, apstatr (py, PYCY)) + + xshift = newx - apstatr (py, PYCX) + yshift = newy - apstatr (py, PYCY) + call aaddkr (x, xshift, x, nver) + call aaddkr (y, yshift, y, nver) + call apsetr (py, PYCX, newx) + call apsetr (py, PYCY, newy) + + switch (apstati(py,WCSOUT)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_ltoo (py, newx, newy, xshift, yshift, 1) + case WCS_TV: + call ap_ltov (im, newx, newy, xshift, yshift, 1) + default: + xshift = newx + yshift = newy + } + call apsetr (py, OPYCX, xshift) + call apsetr (py, OPYCY, yshift) +end diff --git a/noao/digiphot/apphot/polyphot/apywrite.x b/noao/digiphot/apphot/polyphot/apywrite.x new file mode 100644 index 00000000..b246aac3 --- /dev/null +++ b/noao/digiphot/apphot/polyphot/apywrite.x @@ -0,0 +1,92 @@ +include "../lib/apphot.h" +include "../lib/polyphot.h" + +# AP_YWRITE -- Procedure to write a polygon to a file. + +procedure ap_ywrite (py, im, cl, pl, x, y, nvertices, cid, pid, firstpoly, + newpoly) + +pointer py # pointer to the apphot structure +pointer im # the input image descriptor +int cl # pointer to the coordinate list file +int pl # pointer to the polygon list file +real x[ARB] # x coordinates of the vertices +real y[ARB] # y coordinates of the vertices +int nvertices # number of vertices +int cid # coordinate list index +int pid # polygon list index +int firstpoly # first polygon measured +int newpoly # new polygon + +real xtemp, ytemp +int i +real apstatr() +int apstati() + +begin + # Make sure the output files are at EOF. + if (pl == NULL) + return + call seek (pl, EOF) + if (cl != NULL) + call seek (cl, EOF) + + if (newpoly == YES) { + + # Terminate the coord list that belongs with the first polygon. + if (firstpoly == NO && cl != NULL) + call fprintf (cl, ";\n") + + # Write out the coordinates. + do i = 1, nvertices { + switch (apstati(py, WCSOUT)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_ltoo (py, x[i], y[i], xtemp, ytemp, 1) + case WCS_TV: + call ap_ltov (im, x[i], y[i], xtemp, ytemp, 1) + default: + xtemp = x[i] + ytemp = y[i] + } + call fprintf (pl, "%g %g\n") + call pargr (xtemp) + call pargr (ytemp) + } + if (nvertices > 0) + call fprintf (pl, ";\n") + + pid = pid + 1 + + # Reset polygon parameters. + newpoly = NO + if (firstpoly == YES) + firstpoly = NO + } + + # Write out the central coordinates of the polygon. + if (firstpoly == NO && cl != NULL) { + + switch (apstati(py, WCSOUT)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_ltoo (py, apstatr(py,CWX), apstatr(py,CWY), xtemp, + ytemp, 1) + case WCS_TV: + call ap_ltov (im, apstatr(py,CWX), apstatr(py,CWY), xtemp, + ytemp, 1) + default: + xtemp = apstatr (py, CWX) + ytemp = apstatr (py, CWY) + } + call fprintf (cl, "%g %g\n") + call pargr (xtemp) + call pargr (ytemp) + + cid = cid + 1 + } + + # Flush the output files. + if (pl != NULL) + call flush (pl) + if (cl != NULL) + call flush (cl) +end diff --git a/noao/digiphot/apphot/polyphot/ipolyphot.key b/noao/digiphot/apphot/polyphot/ipolyphot.key new file mode 100644 index 00000000..f8ef878c --- /dev/null +++ b/noao/digiphot/apphot/polyphot/ipolyphot.key @@ -0,0 +1,16 @@ + Interactive Photometry Setup Menu + + v Mark and verify the critical parameters (f,c,s,a,d) + + f Mark and verify the psf full-width half-maximum + s Mark and verify the standard deviation of the background + l Mark and verify the minimum good data value + u Mark and verify the maximum good data value + + c Mark and verify the centering box width + n Mark and verify the cleaning radius + p Mark and verify the clipping radius + + a Mark and verify the inner radius of the sky annulus + d Mark and verify the width of the sky annulus + g Mark and verify the region growing radius diff --git a/noao/digiphot/apphot/polyphot/mkpkg b/noao/digiphot/apphot/polyphot/mkpkg new file mode 100644 index 00000000..b98b6803 --- /dev/null +++ b/noao/digiphot/apphot/polyphot/mkpkg @@ -0,0 +1,60 @@ +# POLYPHOT and POLYMARK routines + +$checkout libpkg.a ".." +$update libpkg.a +$checkin libpkg.a ".." +$exit + +libpkg.a: + # POLYPHOT routines + + appyerrors.x ../lib/polyphot.h + apgypars.x ../lib/display.h ../lib/fitsky.h \ + ../lib/noise.h ../lib/polyphot.h \ + ../lib/center.h + apycenter.x ../lib/center.h ../lib/polyphot.h + apyconfirm.x ../lib/apphot.h ../lib/noise.h \ + ../lib/center.h ../lib/fitsky.h + apycoords.x ../lib/polyphot.h + apyfree.x ../lib/apphotdef.h ../lib/polyphotdef.h + apyinit.x ../lib/apphotdef.h ../lib/polyphotdef.h + apynextobj.x <fset.h> ../lib/apphot.h \ + ../lib/polyphot.h + apypars.x + apyradsetup.x ../lib/fitsky.h ../lib/polyphot.h + apyshift.x ../lib/apphot.h ../lib/polyphot.h + apycolon.x ../lib/polyphot.h ../lib/center.h \ + ../lib/apphot.h ../lib/fitsky.h \ + ../lib/noise.h ../lib/display.h \ + <gset.h> <error.h> + apyfit.x ../lib/polyphot.h ../lib/noise.h \ + ../lib/apphot.h <imhdr.h> \ + <mach.h> + apyget.x <fset.h> ../lib/apphot.h \ + ../lib/fitsky.h ../lib/polyphot.h + polyshow.x ../lib/display.h ../lib/polyphot.h + apybphot.x <fset.h> ../lib/display.h \ + ../lib/polyphot.h ../lib/fitsky.h \ + ../lib/apphot.h + apyphot.x <ctype.h> <gset.h> \ + ../lib/display.h ../lib/polyphot.h \ + ../lib/fitsky.h ../lib/apphot.h \ + <imhdr.h> + apyprint.x ../lib/fitsky.h ../lib/center.h \ + ../lib/apphot.h ../lib/polyphot.h + t_polyphot.x <gset.h> <fset.h> \ + ../lib/apphot.h ../lib/polyphot.h \ + <imhdr.h> + + # POLYMARK routines + + t_polymark.x <gset.h> <fset.h> \ + "../lib/apphot.h" "../lib/polyphot.h" \ + <imhdr.h> + apmkpylist.x <gset.h> <ctype.h> \ + "../lib/apphot.h" "../lib/polyphot.h" + apydraw.x "../lib/polyphot.h" + apymkinit.x "../lib/apphotdef.h" "../lib/noise.h" + apymkfree.x "../lib/apphotdef.h" + apywrite.x "../lib/apphot.h" "../lib/polyphot.h" + ; diff --git a/noao/digiphot/apphot/polyphot/polymark.key b/noao/digiphot/apphot/polyphot/polymark.key new file mode 100644 index 00000000..9e1901a1 --- /dev/null +++ b/noao/digiphot/apphot/polyphot/polymark.key @@ -0,0 +1,16 @@ + Interactive Keystroke Commands + +? Print help +: Colon commands +d Plot radial profile of star near cursor +g Define the current polygonal aperture +f Draw the current polygon on the display +spbar Draw the current polygon on the display, output the polygon +r Rewind the polygon list +m Draw the next polygon in the polygon list on the display +l Draw all the remaining polygons in the list on the display +q Exit + + Colon commands + +:m [n] Draw the next [nth] polygon in the polygon list on the display diff --git a/noao/digiphot/apphot/polyphot/polyphot.key b/noao/digiphot/apphot/polyphot/polyphot.key new file mode 100644 index 00000000..e2c92da2 --- /dev/null +++ b/noao/digiphot/apphot/polyphot/polyphot.key @@ -0,0 +1,110 @@ + Interactive Keystroke Commands + +? Print help +: Colon commands +v Verify the critical parameters +w Store the current parameters +d Plot radial profile of current object +i Define current polygon, graphically set parameters using current object +g Define current polygon +c Fit center for current object +t Fit sky around cursor +a Average sky values fit around several cursor positions +s Fit sky around current object +h Do photometry for current polygon +j Do photometry for current polygon, output results +p Do photometry for current object using current sky +o Do photometry for current object using current sky, output results +f Do photometry for current object +spbar Do photometry for current object, output results +m Move to next object in coordinate list +n Do photometry for next object in coordinate list, output results +l Do photometry for remaining objects in coordinate list, output results +r Rewind the the coordinate list +e Print error messages +q Exit task + + + Colon Commands + +:show [data/center/sky/phot] List the parameters +:m [n] Move to next [nth] object in coordinate list +:n [n] Do photometry for next [nth] object in coordinate list, output results + + + Colon Parameter Editing Commands + +# Image and file name parameters + +:image [string] Image name +:polygon [string] Polygon file +:coords [string] Coordinate file +:output [string] Results file + +# Data dependent parameters + +:scale [value] Image scale (units per pixel) +:fwhmpsf [value] Full-width half-maximum of PSF (scale units) +:emission [y/n] Emission feature (y), absorption (n) +:sigma [value] Standard deviation of sky (counts) +:datamin [value] Minimum good pixel value (counts) +:datamax [value] Maximum good pixel value (counts) + +# Noise parameters + +:noise [string] Noise model (constant|poisson) +:gain [string] Gain image header keyword +:ccdread [string] Readout noise image header keyword +:epadu [value] Gain (electrons per count) +:epadu [value] Readout noise (electrons) + +# Observing parameters + +:exposure [string] Exposure time image header keyword +:airmass [string] Airmass image header keyword +:filter [string] Filter image header keyword +:obstime [string] Time of observation image header keyword +:itime [value] Integration time (time units) +:xairmass [value] Airmass value (number) +:ifilter [string] Filter id string +:otime [string] Time of observation (time units) + +# Centering algorithm parameters + +:calgorithm [string] Centering algorithm +:cbox [value] Width of centering box (scale units) +:cthreshold [value] Centering intensity threshold (sigma) +:cmaxiter [value] Maximum number of iterations +:maxshift [value] Maximum center shift (scale units) +:minsnratio [value] Minimum S/N ratio for centering +:clean [y/n] Clean subraster before centering +:rclean [value] Cleaning radius (scale units) +:rclip [value] Clipping radius (scale units) +:kclean [value] Clean K-sigma rejection limit (sigma) + +# Sky fitting algorithm parameters + +:salgorithm [string] Sky fitting algorithm +:skyvalue [value] User supplied sky value (counts) +:annulus [value] Inner radius of sky annulus (scale units) +:dannulus [value] Width of sky annulus (scale units) +:khist [value] Sky histogram extent (+/- sigma) +:binsize [value] Resolution of sky histogram (sigma) +:sloclip [value] Low-side clipping factor in percent +:shiclip [value] High-side clipping factor in percent +:smooth [y/n] Lucy smooth the sky histogram +:smaxiter [value] Maximum number of iterations +:snreject [value] Maximum number of rejection cycles +:sloreject [value] Low-side pixel rejection limits (sky sigma) +:shireject [value] High-side pixel rejection limits (sky sigma) +:rgrow [value] Region growing radius (scale units) + +# Photometry parameters + +:zmag [value] Zero point of magnitude scale + +# Plotting and marking parameters + +:mkcenter [y/n] Mark computed centers on the display +:mksky [y/n] Mark the sky annuli on the display +:mkpolygon [y/n] Mark the polygon on the display diff --git a/noao/digiphot/apphot/polyphot/polyshow.x b/noao/digiphot/apphot/polyphot/polyshow.x new file mode 100644 index 00000000..9e3da070 --- /dev/null +++ b/noao/digiphot/apphot/polyphot/polyshow.x @@ -0,0 +1,65 @@ +include "../lib/display.h" +include "../lib/polyphot.h" + +# AP_YSHOW -- Print the all the polyphot parameters on the standard output. + +procedure ap_yshow (ap) + +pointer ap # pointer to the apphot strucuture + +begin + call ap_nshow (ap) + call printf ("\n") + call ap_cpshow (ap) + call printf ("\n") + call ap_spshow (ap) + call printf ("\n") + call ap_yyshow (ap) +end + + +# AP_YPSHOW -- Print the noise and polypars parameters on the standard output. + +procedure ap_ypshow (ap) + +pointer ap # pointer to apphot structure + +begin + call ap_nshow (ap) + call printf ("\n") + call ap_yyshow (ap) +end + + +# AP_YYSHOW -- Print the polypars parameters on the standard output. + +procedure ap_yyshow (ap) + +pointer ap # pointer to apphot structure + +pointer sp, str +bool itob() +int apstati() +real apstatr() + +begin + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + + call printf ("Photometry Parameters\n") + + call apstats (ap, PYNAME, Memc[str], SZ_LINE) + call printf (" %s = %s\n") + call pargstr (KY_PYNAME) + call pargstr (Memc[str]) + + call printf (" %s = %g\n") + call pargstr (KY_PYZMAG) + call pargr (apstatr (ap, PYZMAG)) + + call printf (" %s = %b\n") + call pargstr (KY_MKPOLYGON) + call pargb (itob (apstati (ap, MKPOLYGON))) + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/polyphot/t_polymark.x b/noao/digiphot/apphot/polyphot/t_polymark.x new file mode 100644 index 00000000..4eea5207 --- /dev/null +++ b/noao/digiphot/apphot/polyphot/t_polymark.x @@ -0,0 +1,240 @@ +include <gset.h> +include <fset.h> +include <imhdr.h> +include "../lib/apphot.h" +include "../lib/polyphot.h" + +define MAX_NVERTICES 100 + +# T_POLYMARK -- Create a polygons list file interactively. + +procedure t_polymark() + +pointer image # pointer to name of image +pointer polygons # pointer to the polygons file +pointer coords # pointer to the coords file +int cache # cache the input image pixels in memory +pointer display # pointer to display device name +pointer graphics # pointer to the graphics device + +pointer sp, cfname, pfname, im, py, id, gd, str +int limlist, lplist, lclist, stat, pl, cl, root, pid, cid, wcs +int imlist, plist, clist, newpy, newcoo, memstat, req_size, old_size +int buf_size + +pointer gopen(), immap() +int imtlen(), clplen(), imtgetim(), clgfil(), strncmp(), strlen() +int fnldir(), ap_mkpylist(), imtopenp(), clpopnu(), open(), clgwrd() +int access(), btoi(), ap_memstat(), sizeof() +bool clgetb(), streq() +errchk gopen() + +begin + # Allocate working space. + call smark (sp) + call salloc (image, SZ_FNAME, TY_CHAR) + call salloc (coords, SZ_FNAME, TY_CHAR) + call salloc (polygons, SZ_FNAME, TY_CHAR) + call salloc (display, SZ_FNAME, TY_CHAR) + call salloc (graphics, SZ_FNAME, TY_CHAR) + call salloc (cfname, SZ_FNAME, TY_CHAR) + call salloc (pfname, SZ_FNAME, TY_CHAR) + call salloc (str, SZ_LINE, TY_CHAR) + + # Set STDOUT. + call fseti (STDOUT, F_FLUSHNL, YES) + + # Get input and output file lists. + imlist = imtopenp ("image") + limlist = imtlen (imlist) + plist = clpopnu ("polygons") + lplist = clplen (plist) + clist = clpopnu ("coords") + lclist = clplen (clist) + + # Check that image input and coords file list lengths match. + if (lclist > 0 && lclist != limlist) { + call imtclose (imlist) + call clpcls (plist) + call clpcls (clist) + call error (0, "Imcompatible image and coord file list lengths") + } + + # Check that image input and polygons file list lengths match. + if (lplist != limlist) { + call imtclose (imlist) + call clpcls (plist) + call clpcls (clist) + call error (0, "Imcompatible image and polygons file list lengths") + } + + cache = btoi (clgetb ("cache")) + + # Open the graphics device. + call clgstr ("graphics", Memc[graphics], SZ_FNAME) + if (Memc[graphics] == EOS) + gd = NULL + else { + iferr { + gd = gopen (Memc[graphics], APPEND+AW_DEFER, STDGRAPH) + } then { + call eprintf ("Warning: Error opening graphics device.\n") + gd = NULL + } + } + + # Open the display device. + call clgstr ("display", Memc[display], SZ_FNAME) + if (Memc[display] == EOS) + id = NULL + else if (streq (Memc[display], Memc[graphics])) { + id = gd + } else { + iferr { + id = gopen (Memc[display], APPEND, STDIMAGE) + } then { + call eprintf ( + "Warning: Graphics overlay not available for display device.\n") + id = NULL + } + } + + # Open the polymark structure. + call ap_ymkinit (py) + + # Get the wcs information. + wcs = clgwrd ("wcsin", Memc[str], SZ_LINE, WCSINSTR) + if (wcs <= 0) { + call eprintf ( + "Warning: Setting the input coordinate system to logical\n") + wcs = WCS_LOGICAL + } + call apseti (py, WCSIN, wcs) + wcs = clgwrd ("wcsout", Memc[str], SZ_LINE, WCSOUTSTR) + if (wcs <= 0) { + call eprintf ( + "Warning: Setting the output coordinate system to logical\n") + wcs = WCS_LOGICAL + } + call apseti (py, WCSOUT, wcs) + + # Mark polygons. + while (imtgetim (imlist, Memc[image], SZ_FNAME) != EOF) { + + # Open image. + im = immap (Memc[image], READ_ONLY, 0) + call apimkeys (py, im, Memc[image]) + + # Establish the image display viewport and window. + if ((id != NULL) && (id != gd)) + call ap_gswv (id, Memc[image], im, 4) + + # Cache the input image pixels. + req_size = MEMFUDGE * IM_LEN(im,1) * IM_LEN(im,2) * + sizeof (IM_PIXTYPE(im)) + memstat = ap_memstat (cache, req_size, old_size) + if (memstat == YES) + call ap_pcache (im, INDEFI, buf_size) + + # Set the polygon file name. + if (lplist == 0) + pl = NULL + else { + stat = clgfil (plist, Memc[polygons], SZ_FNAME) + root = fnldir (Memc[polygons], Memc[pfname], SZ_FNAME) + if (strncmp ("default", Memc[polygons+root], 7) == 0 || root == + strlen (Memc[polygons])) { + call apoutname (Memc[image], Memc[pfname], "ver", + Memc[pfname], SZ_FNAME) + lplist = limlist + } else if (stat != EOF) + call strcpy (Memc[polygons], Memc[pfname], SZ_FNAME) + if (access (Memc[pfname], READ_WRITE, TEXT_FILE) == YES) { + newpy = NO + pl = open (Memc[pfname], READ_WRITE, TEXT_FILE) + } else { + newpy = YES + pl = open (Memc[pfname], NEW_FILE, TEXT_FILE) + call close (pl) + pl = open (Memc[pfname], READ_WRITE, TEXT_FILE) + } + } + call apsets (py, PYNAME, Memc[pfname]) + + # Set the coord file name. + if (lclist == 0) + cl = NULL + else { + stat = clgfil (clist, Memc[coords], SZ_FNAME) + root = fnldir (Memc[coords], Memc[cfname], SZ_FNAME) + if (strncmp ("default", Memc[coords+root], 7) == 0 || root == + strlen (Memc[coords])) { + call apoutname (Memc[image], Memc[cfname], "coo", + Memc[cfname], SZ_FNAME) + lclist = limlist + } else if (stat != EOF) + call strcpy (Memc[coords], Memc[cfname], SZ_FNAME) + if (access (Memc[cfname], READ_WRITE, TEXT_FILE) == YES) { + newcoo = NO + cl = open (Memc[cfname], READ_WRITE, TEXT_FILE) + } else { + newcoo = YES + cl = open (Memc[cfname], NEW_FILE, TEXT_FILE) + call close (cl) + cl = open (Memc[cfname], READ_WRITE, TEXT_FILE) + } + } + call apsets (py, CLNAME, Memc[cfname]) + + # Mark polygons on each image. + pid = 1 + cid = 1 + stat = ap_mkpylist (im, py, pl, cl, id, gd, pid, cid) + + # Unmap the input image. + call imunmap (im) + + # Close the polygon file. + if (pl != NULL) { + call close (pl) + if (newpy == YES && pid <= 1) + call delete (Memc[pfname]) + } + + # Close the coordinate file. + if (cl != NULL) { + if (cid > 1) { + call seek (cl, EOF) + call fprintf (cl, ";\n") + } + call close (cl) + if (newcoo == YES && cid <= 1) + call delete (Memc[cfname]) + } + + # Uncache memory. + call fixmem (old_size) + + if (stat == YES) + break + } + + # Close the graphics and image display devices. + if (id == gd && id != NULL) + call gclose (id) + else { + if (gd != NULL) + call gclose (gd) + if (id != NULL) + call gclose (id) + } + + # Free the polymark structure. + call ap_ymkfree (py) + + # Close image, polygon, and coordinate lists. + call imtclose (imlist) + call clpcls (plist) + call clpcls (clist) + call sfree (sp) +end diff --git a/noao/digiphot/apphot/polyphot/t_polyphot.x b/noao/digiphot/apphot/polyphot/t_polyphot.x new file mode 100644 index 00000000..5242d02e --- /dev/null +++ b/noao/digiphot/apphot/polyphot/t_polyphot.x @@ -0,0 +1,329 @@ +include <gset.h> +include <fset.h> +include <imhdr.h> +include "../lib/apphot.h" +include "../lib/polyphot.h" + +# T_POLYPHOT -- Measure the total magnitudes inside a list of polygons. + +procedure t_polyphot() + +pointer image # pointer to name of image +pointer output # pointer to the results file +pointer coords # pointer to file of coordinates +pointer polygon # pointer to file containing polygon +pointer graphics # pointer to graphics device name +pointer display # pointer to display device name +int interactive # mode of use +int cache # cache the input image pixels +int verify # verify critical parameters +int update # update the critical parameters +int verbose # print messages + +pointer sp, outfname, cname, im, py, id, gd, str +int limlist, lplist, lolist, lclist, sid, lid, pid, pl, cl, out, root, stat +int imlist, plist, olist, clist, memstat, wcs, req_size, old_size, buf_size + +pointer immap(), gopen() +int imtlen(), imtgetim(), clplen(), clgfil(), btoi(), strncmp() +int fnldir(), strlen(), ap_yphot(), open(), imtopenp(), clpopnu() +int clgwrd(), ap_memstat(), sizeof() +bool clgetb(), streq() +errchk gopen + +begin + # Allocate working space. + call smark (sp) + call salloc (image, SZ_FNAME, TY_CHAR) + call salloc (output, SZ_FNAME, TY_CHAR) + call salloc (coords, SZ_FNAME, TY_CHAR) + call salloc (polygon, SZ_FNAME, TY_CHAR) + call salloc (graphics, SZ_FNAME, TY_CHAR) + call salloc (display, SZ_FNAME, TY_CHAR) + call salloc (outfname, SZ_FNAME, TY_CHAR) + call salloc (cname, SZ_FNAME, TY_CHAR) + call salloc (str, SZ_LINE, TY_CHAR) + + # Set STDOUT. + call fseti (STDOUT, F_FLUSHNL, YES) + + # Get input and output file lists. + imlist = imtopenp ("image") + limlist = imtlen (imlist) + plist = clpopnu ("polygons") + lplist = clplen (plist) + olist = clpopnu ("output") + lolist = clplen (olist) + clist = clpopnu ("coords") + lclist = clplen (clist) + + # Check that image and polygon list lengths match. + if (limlist < 1 || (lplist > 1 && lplist != limlist)) { + call imtclose (imlist) + call clpcls (plist) + call clpcls (olist) + call clpcls (clist) + call error (0, "Imcompatible image and polygon list lengths") + } + + # Check that image and coordinates list lengths match. + if (limlist < 1 || (lclist > 1 && lclist != limlist)) { + call imtclose (imlist) + call clpcls (plist) + call clpcls (olist) + call clpcls (clist) + call error (0, "Imcompatible image and coordinate list lengths") + } + + # Check that image input and output list lengths match. + if (lolist > 1 && lolist != limlist) { + call imtclose (imlist) + call clpcls (plist) + call clpcls (olist) + call clpcls (clist) + call error (0, "Imcompatible image and output list lengths") + } + + call clgstr ("icommands.p_filename", Memc[cname], SZ_FNAME) + if (Memc[cname] != EOS) + interactive = NO + else + interactive = btoi (clgetb ("interactive")) + cache = btoi (clgetb ("cache")) + verify = btoi (clgetb ("verify")) + update = btoi (clgetb ("update")) + verbose = btoi (clgetb ("verbose")) + + # Get polygon fitting parameters. + call ap_gypars (py) + + # Confirm the algorithm parameters. + if (verify == YES && interactive == NO) { + call ap_yconfirm (py, NULL, 1) + if (update == YES) + call ap_pypars (py) + } + + # Get the wcs information. + wcs = clgwrd ("wcsin", Memc[str], SZ_LINE, WCSINSTR) + if (wcs <= 0) { + call eprintf ( + "Warning: Setting the input coordinate system to logical\n") + wcs = WCS_LOGICAL + } + call apseti (py, WCSIN, wcs) + wcs = clgwrd ("wcsout", Memc[str], SZ_LINE, WCSOUTSTR) + if (wcs <= 0) { + call eprintf ( + "Warning: Setting the output coordinate system to logical\n") + wcs = WCS_LOGICAL + } + call apseti (py, WCSOUT, wcs) + + # Get the graphics and display devices. + call clgstr ("graphics", Memc[graphics], SZ_FNAME) + call clgstr ("display", Memc[display], SZ_FNAME) + + # Open the plot files. + if (interactive == YES) { + if (Memc[graphics] == EOS) + gd = NULL + else { + iferr { + gd = gopen (Memc[graphics], APPEND+AW_DEFER, STDGRAPH) + } then { + call eprintf ( + "Warning: Error opening graphics device.\n") + gd = NULL + } + } + if (Memc[display] == EOS) + id = NULL + else if (streq (Memc[graphics], Memc[display])) + id = gd + else { + iferr { + id = gopen (Memc[display], APPEND, STDIMAGE) + } then { + call eprintf ( + "Warning: Graphics overlay not available for display device.\n") + id = NULL + } + } + } else { + gd = NULL + id = NULL + } + + # Measure flux in a polygon. + sid = 1 + while (imtgetim (imlist, Memc[image], SZ_FNAME) != EOF) { + + # Open image. + im = immap (Memc[image], READ_ONLY, 0) + call apimkeys (py, im, Memc[image]) + if ((id != NULL) && (id != gd)) + call ap_gswv (id, Memc[image], im, 4) + + # Cache the input image pixels. + req_size = MEMFUDGE * IM_LEN(im,1) * IM_LEN(im,2) * + sizeof (IM_PIXTYPE(im)) + memstat = ap_memstat (cache, req_size, old_size) + if (memstat == YES) + call ap_pcache (im, INDEFI, buf_size) + + # Open the polygons file. + if (lplist <= 0) { + pl = NULL + call strcpy ("", Memc[outfname], SZ_FNAME) + } else { + stat = clgfil (plist, Memc[polygon], SZ_FNAME) + root = fnldir (Memc[polygon], Memc[outfname], SZ_FNAME) + if (strncmp ("default", Memc[polygon+root], 7) == 0 || root == + strlen (Memc[polygon])) { + call ap_inname (Memc[image], Memc[outfname], "ver", + Memc[outfname], SZ_FNAME) + lplist = limlist + pl = open (Memc[outfname], READ_ONLY, TEXT_FILE) + } else if (stat != EOF) { + call strcpy (Memc[polygon], Memc[outfname], SZ_FNAME) + pl = open (Memc[outfname], READ_ONLY, TEXT_FILE) + } else { + call apstats (py, PYNAME, Memc[outfname], SZ_FNAME) + call seek (pl, BOF) + } + } + call apsets (py, PYNAME, Memc[outfname]) + call apfroot (Memc[outfname], Memc[str], SZ_LINE) + call apsets (py, PYROOT, Memc[str]) + + # Open the coordinates file. + if (lclist <= 0) { + cl = NULL + call strcpy ("", Memc[outfname], SZ_FNAME) + } else { + stat = clgfil (clist, Memc[coords], SZ_FNAME) + root = fnldir (Memc[coords], Memc[outfname], SZ_FNAME) + if (strncmp ("default", Memc[coords+root], 7) == 0 || root == + strlen (Memc[coords])) { + call ap_inname (Memc[image], Memc[outfname], "coo", + Memc[outfname], SZ_FNAME) + lclist = limlist + cl = open (Memc[outfname], READ_ONLY, TEXT_FILE) + } else if (stat != EOF) { + call strcpy (Memc[coords], Memc[outfname], SZ_FNAME) + cl = open (Memc[outfname], READ_ONLY, TEXT_FILE) + } else { + call apstats (py, CLNAME, Memc[outfname], SZ_FNAME) + call seek (cl, BOF) + } + } + call apsets (py, CLNAME, Memc[outfname]) + call apfroot (Memc[outfname], Memc[str], SZ_LINE) + call apsets (py, CLROOT, Memc[str]) + + # Set output file name. + if (lolist == 0) { + out = NULL + call strcpy ("", Memc[outfname], SZ_FNAME) + } else { + stat = clgfil (olist, Memc[output], SZ_FNAME) + root = fnldir (Memc[output], Memc[outfname], SZ_FNAME) + if (strncmp ("default", Memc[output+root], 7) == 0 || root == + strlen (Memc[output])) { + call apoutname (Memc[image], Memc[outfname], "ply", + Memc[outfname], SZ_FNAME) + out = open (Memc[outfname], NEW_FILE, TEXT_FILE) + lolist = limlist + } else if (stat != EOF) { + call strcpy (Memc[output], Memc[outfname], SZ_FNAME) + out = open (Memc[outfname], NEW_FILE, TEXT_FILE) + } else + call apstats (py, OUTNAME, Memc[outfname], SZ_FNAME) + } + call apsets (py, OUTNAME, Memc[outfname]) + + # Do the photometry. + if (interactive == NO) { + if (Memc[cname] != EOS) + stat = ap_yphot (py, im, cl, pl, NULL, NULL, out, sid, NO, + cache) + else if (pl != NULL) { + lid = 0 + pid = 0 + call ap_ybphot (py, im, cl, pl, out, sid, lid, pid, NULL, + verbose) + stat = NO + } else + stat = NO + } else + stat = ap_yphot (py, im, cl, pl, gd, id, out, sid, YES, cache) + + # Unmap the input image. + call imunmap (im) + + # Close the polygon file. + if (pl != NULL) { + if (lplist > 1) + call close (pl) + } + + # Close the coordinate file. + if (cl != NULL) { + if (lclist > 1) + call close (cl) + } + + # Close the output file. + if (out != NULL && lolist != 1) { + call close (out) + if (sid <= 1) { + call apstats (py, OUTNAME, Memc[outfname], SZ_FNAME) + call delete (Memc[outfname]) + } + sid = 1 + } + + # Uncache memory. + call fixmem (old_size) + + if (stat == YES) + break + } + + # Close plot files. + if (id == gd && id != NULL) + call gclose (id) + else { + if (gd != NULL) + call gclose (gd) + if (id != NULL) + call gclose (id) + } + + # Close the single coords and polygon file. + if (pl != NULL && lplist == 1) + call close (pl) + if (cl != NULL && lclist == 1) + call close (cl) + + # Close the singled output file. + if (out != NULL && lolist == 1) { + call close (out) + if (sid <= 1) { + call apstats (py, OUTNAME, Memc[outfname], SZ_FNAME) + call delete (Memc[outfname]) + } + } + + # Close up the files. + call ap_yfree (py) + + # Close image, coord and shift lists. + call imtclose (imlist) + call clpcls (plist) + call clpcls (clist) + call clpcls (olist) + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/qphot.par b/noao/digiphot/apphot/qphot.par new file mode 100644 index 00000000..85b18882 --- /dev/null +++ b/noao/digiphot/apphot/qphot.par @@ -0,0 +1,27 @@ +# QPHOT parameters + +image,f,a,,,,"The input image(s)" +cbox,r,a,5.0,,,"The centering box width in pixels" +annulus,r,a,,0.0,,"The inner radius of sky annulus in pixels" +dannulus,r,a,,1.0,,"The width of the sky annulus in pixels" +apertures,s,a,"3.0",,,"The list of photometry apertures" +coords,s,h,"",,,"The input coordinate file(s) (default: *.coo.?)" +output,f,h,"default",,,"The output photometry file(s) (default: *.mag.?)" +plotfile,f,h,"",,,"The output plot metacode file" +zmag,r,h,25.0,,,"The zero point of the magnitude scale" +exposure,s,h,"",,,"The exposure time image header keyword" +airmass,s,h,"",,,"The airmass image header keyword" +filter,s,h,"",,,"The filter image header keyword" +obstime,s,h,"",,,"The time of observation image header keyword" +epadu,r,h,1.0,,,"The instrument gain in e-/ADU" +interactive,b,h,yes,,,"Interactive mode ?" +radplots,b,h,no,,,"Plot the radial profiles in interactive mode ?" +icommands,*imcur,h,"",,,"Image cursor: [x y wcs] key [cmd]" +gcommands,*gcur,h,"",,,"Graphics cursor: [x y wcs] key [cmd]" +wcsin,s,h,)_.wcsin,,,"The input coordinate system (logical,tv,physical,world)" +wcsout,s,h,)_.wcsout,,,"The output coordinate system (logical,tv,physical)" +cache,b,h,)_.cache,,,"Cache input image pixels in memory ?" +verbose,b,h,)_.verbose,,,"Print messages in non-interactive mode ?" +graphics,s,h,)_.graphics,,,"Graphics device" +display,s,h,)_.display,,,"Display device" +mode,s,h,'ql' diff --git a/noao/digiphot/apphot/radprof.par b/noao/digiphot/apphot/radprof.par new file mode 100644 index 00000000..c5ce3bb7 --- /dev/null +++ b/noao/digiphot/apphot/radprof.par @@ -0,0 +1,28 @@ +# RADPROF + +image,f,a,,,,"The input image(s)" +radius,r,a,,,,"The maximum radial profile radius in scale units" +step,r,a,,,,"The step size for radial profile in scale units" +coords,f,h,"",,,"The input coordinate list(s) (default: image.coo.?)" +output,f,h,"",,,"The output radial profile files (default: image.prf.?)" +plotfile,f,h,"",,,"The output radial profile plot metacode file" +datapars,pset,h,"",,,"Data dependent parameters" +centerpars,pset,h,"",,,"Centering parameters" +fitskypars,pset,h,"",,,"Sky fitting parameters" +photpars,pset,h,"",,,"Photometry parameters" +order,i,h,5,1,,"Order of spline fit" +kreject,r,h,3.0,,,"K-sigma rejection limit" +nreject,i,h,1,,,"Maximum number of rejection cycles" +interactive,b,h,yes,,,"Interactive mode ?" +radplots,b,h,yes,,,"Plot radial profiles in interactive mode ?" +icommands,*imcur,h,"",,,"Image cursor: [x y wcs] key [cmd]" +gcommands,*gcur,h,"",,,"Graphics cursor: [x y wcs] key [cmd]" +wcsin,s,h,)_.wcsin,,,"The input coordinate system (logical,tv,physical,world)" +wcsout,s,h,)_.wcsout,,,"The output coordinate system (logical,tv,physical)" +cache,b,h,)_.cache,,,"Cache the input image pixels ?" +verify,b,h,)_.verify,,,"Verify critical parameters in non-interactive mode ?" +update,b,h,)_.update,,,"Update critical parameters in non-interactive mode ?" +verbose,b,h,)_.verbose,,,"Print messages in non-interactive mode ?" +graphics,s,h,)_.graphics,,,"Graphics device" +display,s,h,)_.display,,,"Image display device" +mode,s,h,'ql' diff --git a/noao/digiphot/apphot/radprof/apbradprof.x b/noao/digiphot/apphot/radprof/apbradprof.x new file mode 100644 index 00000000..08e5547b --- /dev/null +++ b/noao/digiphot/apphot/radprof/apbradprof.x @@ -0,0 +1,107 @@ +include <fset.h> +include "../lib/apphot.h" +include "../lib/display.h" +include "../lib/center.h" +include "../lib/fitsky.h" + +# AP_BRADPROF -- Procedure to fit the radial profiles of a list of objects +# in a list of images. + +procedure ap_bradprof (ap, im, cl, gid, gd, mgd, out, id, ld, interactive) + +pointer ap # pointer to apphot structure +pointer im # pointer to IRAF image +int cl # starlist file descriptor +pointer gid # display device stream +pointer gd # pointer to graphics stream +pointer mgd # pointer to metacode file +int out # output file descriptor +int id, ld # sequence and list numbers +int interactive # interactive pr batch mode + +int stdin, ild, cier, sier, pier, rier +pointer sp, str +real wx, wy +int fscan(), nscan(), apfitsky(), apfitcenter(), ap_frprof(), apstati() +int strncmp() +real apstatr() + +begin + call smark (sp) + call salloc (str, SZ_FNAME + 1, TY_CHAR) + call fstats (cl, F_FILENAME, Memc[str], SZ_FNAME) + + # Initialize. + ild = ld + + # Print query if coords is equal to STDIN. + if (strncmp ("STDIN", Memc[str], 5) == 0) { + stdin = YES + call printf ( + "Type x and y coordinates of object (^D or ^Z to end): ") + call flush (STDOUT) + } else + stdin = NO + + # Loop over the coordinate file. + while (fscan (cl) != EOF) { + + # Get the coordinates. + call gargr (wx) + call gargr (wy) + if (nscan () != 2) { + if (stdin == YES) { + call printf ( + "Type x and y coordinates of object (^D or ^Z to end): ") + call flush (STDOUT) + } + next + } + + # Transform the input coordinates. + switch (apstati(ap,WCSIN)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_itol (ap, wx, wy, wx, wy, 1) + case WCS_TV: + call ap_vtol (im, wx, wy, wx, wy, 1) + default: + ; + } + + # Set the current cursor position. + call apsetr (ap, CWX, wx) + call apsetr (ap, CWY, wy) + + # Fit the center, sky and radial profile. + cier = apfitcenter (ap, im, wx, wy) + sier = apfitsky (ap, im, apstatr (ap, XCENTER), apstatr (ap, + YCENTER), NULL, gd) + rier = ap_frprof (ap, im, apstatr (ap, XCENTER), apstatr (ap, + YCENTER), pier) + + # Output the results. + if (interactive == YES) { + call ap_qprprof (ap, cier, sier, pier, rier) + if (id != NULL) + call aprmark (ap, gid, apstati (ap, MKCENTER), + apstati (ap, MKSKY), apstati (ap, MKAPERT)) + } + if (id == 1) + call ap_param (ap, out, "radprof") + call ap_prprof (ap, out, id, ild, cier, sier, pier, rier) + call ap_rpplot (ap, id, mgd, YES) + + # Setup for the next object. + id = id + 1 + ild = ild + 1 + call apsetr (ap, WX, wx) + call apsetr (ap, WY, wy) + if (stdin == YES) { + call printf ( + "Type x and y coordinates of object (^D or ^Z to end): ") + call flush (STDOUT) + } + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/radprof/apfrprof.x b/noao/digiphot/apphot/radprof/apfrprof.x new file mode 100644 index 00000000..093e90bd --- /dev/null +++ b/noao/digiphot/apphot/radprof/apfrprof.x @@ -0,0 +1,417 @@ +include <mach.h> +include <gset.h> +include <math.h> + +include <math/curfit.h> +include <math/iminterp.h> +include "../lib/apphotdef.h" +include "../lib/noisedef.h" +include "../lib/fitskydef.h" +include "../lib/photdef.h" +include "../lib/radprofdef.h" +include "../lib/apphot.h" +include "../lib/phot.h" +include "../lib/radprof.h" + +# AP_FRPROF -- Compute the radial profile of an object. + +int procedure ap_frprof (ap, im, wx, wy, pier) + +pointer ap # pointer to the apphot structure +pointer im # pointer to the IRAF image +real wx, wy # object coordinates +int pier # photometry error + +int i, ier, fier, nxpts, nypts, nrpts, order +pointer sky, rprof, cv, asi +real datamin, datamax, step, rmin, rmax, inorm, tinorm +int ap_rpbuf(), ap_rmag(), ap_rpmeasure(), ap_rpiter() +real asigrl(), cveval(), ap_rphalf() + +errchk cvinit(), cvfit(), cvvector(), cveval(), cvfree() +errchk asinit(), asifit(), asigrl(), asifree() +errchk ap_rpmeasure(), ap_rpiter() + +begin + # Set up some apphot pointers. + sky = AP_PSKY(ap) + rprof = AP_RPROF(ap) + + # Initialize. + AP_RPXCUR(rprof) = wx + AP_RPYCUR(rprof) = wy + call ap_rpindef (ap) + if (IS_INDEFR(wx) || IS_INDEFR(wy)) { + AP_ORPXCUR(rprof) = INDEFR + AP_ORPYCUR(rprof) = INDEFR + } else { + switch (AP_WCSOUT(ap)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_ltoo (ap, wx, wy, AP_ORPXCUR(rprof), + AP_ORPYCUR(rprof), 1) + case WCS_TV: + call ap_ltov (im, wx, wy, AP_ORPXCUR(rprof), + AP_ORPYCUR(rprof), 1) + default: + AP_ORPXCUR(rprof) = wx + AP_ORPYCUR(rprof) = wy + } + } + + # Get the pixels and check for error conditions. + if (IS_INDEFR(wx) || IS_INDEFR(wy)) { + pier = AP_APERT_NOAPERT + return (AP_RP_NOPROFILE) + } else if (IS_INDEFR(AP_SKY_MODE(sky))) { + pier = AP_APERT_NOSKYMODE + return (AP_RP_NOSKYMODE) + } else if (ap_rpbuf (ap, im, wx, wy) == AP_RP_NOPROFILE) { + pier = AP_APERT_NOAPERT + return (AP_RP_NOPROFILE) + } + + # Do the photometry. + pier = ap_rmag (ap) + + # Initialize some common variables. + nxpts = AP_RPNX(rprof) + nypts = AP_RPNY(rprof) + nrpts = AP_RPNPTS(rprof) + + # Initialize the radial profile curve fitting. + step = AP_SCALE(ap) * AP_RPSTEP(rprof) + order = max (1, min (AP_RPORDER(rprof), nxpts * nypts - 3)) + rmin = 0.0 + rmax = (nrpts - 1) * step + if (IS_INDEFR(AP_DATAMIN(ap))) + datamin = -MAX_REAL + else + datamin = AP_DATAMIN(ap) - AP_SKY_MODE(sky) + if (IS_INDEFR(AP_DATAMAX(ap))) + datamax = MAX_REAL + else + datamax = AP_DATAMAX(ap) - AP_SKY_MODE(sky) + + # Fit the curve. + call cvinit (cv, SPLINE3, order, rmin, rmax) + call asubkr (Memr[AP_RPIX(rprof)], AP_SKY_MODE(sky), + Memr[AP_RPIX(rprof)], nxpts * nypts) + fier = ap_rpmeasure (cv, Memr[AP_RPIX(rprof)], nxpts, nypts, + AP_RPXC(rprof), AP_RPYC(rprof), datamin, datamax, rmax, + AP_RPNDATA(rprof), AP_RPNBAD(rprof)) + + # Perform the rejection cycle. + if (fier != NO_DEG_FREEDOM && AP_RPNREJECT(rprof) > 0 && + AP_RPKSIGMA(rprof) > 0.0) + AP_RPNDATAREJ(rprof) = ap_rpiter (cv, Memr[AP_RPIX(rprof)], nxpts, + nypts, AP_RPXC(rprof), AP_RPYC(rprof), rmax, datamin, datamax, + AP_RPNREJECT(rprof), AP_RPKSIGMA(rprof), fier) + else + AP_RPNDATAREJ(rprof) = 0 + + AP_RPNDATA(rprof) = AP_RPNDATA(rprof) - AP_RPNDATAREJ(rprof) + AP_RPNDATAREJ(rprof) = AP_RPNDATAREJ(rprof) + AP_RPNBAD(rprof) + + # Evaluate the fit. + if (fier != NO_DEG_FREEDOM) { + + # Evaluate the profile. + do i = 1, nrpts + Memr[AP_RPDIST(rprof)+i-1] = (i - 1) * step + call cvvector (cv, Memr[AP_RPDIST(rprof)], + Memr[AP_INTENSITY(rprof)], nrpts) + + # Evaluate the integral. + call asiinit (asi, II_SPLINE3) + call amulr (Memr[AP_RPDIST(rprof)], Memr[AP_INTENSITY(rprof)], + Memr[AP_TINTENSITY(rprof)], nrpts) + call asifit (asi, Memr[AP_TINTENSITY(rprof)], nrpts) + Memr[AP_TINTENSITY(rprof)] = 0.0 + do i = 2, nrpts + Memr[AP_TINTENSITY(rprof)+i-1] = Memr[AP_TINTENSITY(rprof)+ + i-2] + asigrl (asi, real (i - 1), real (i)) + call amulkr (Memr[AP_TINTENSITY(rprof)], real (TWOPI) * step, + Memr[AP_TINTENSITY(rprof)], nrpts) + call asifree (asi) + + # Normalize the radial profile. + inorm = cveval (cv, 0.0) + if (inorm != 0.0) + call adivkr (Memr[AP_INTENSITY(rprof)], inorm, + Memr[AP_INTENSITY(rprof)], nrpts) + call apsetr (ap, INORM, inorm) + + # Normalize the total intensity. + tinorm = Memr[AP_TINTENSITY(rprof)+AP_RPNPTS(rprof)-1] + if (tinorm != 0.0) + call adivkr (Memr[AP_TINTENSITY(rprof)], tinorm, + Memr[AP_TINTENSITY(rprof)], nrpts) + call apsetr (ap, TNORM, tinorm) + + # Compute the FWHMPSF. + call apsetr (ap, RPFWHM, 2.0 * ap_rphalf (Memr[AP_RPDIST(rprof)], + Memr[AP_INTENSITY(rprof)], nrpts)) + } + + # Set the error code and return. + call cvfree (cv) + if (fier == NO_DEG_FREEDOM) + ier = AP_RP_NPTS_TOO_SMALL + else if (fier == SINGULAR) + ier = AP_RP_SINGULAR + + # Free space. + return (ier) +end + + +# AP_RMAG -- Compute the magnitudes for the radial profile + +int procedure ap_rmag (ap) + +pointer ap # pointer to the apphot structure + +int pier, nap +pointer sp, nse, sky, phot, rprof, aperts +real datamin, datamax, zmag + +begin + # Initialize some apphot pointers. + nse = AP_NOISE(ap) + sky = AP_PSKY(ap) + phot = AP_PPHOT(ap) + rprof = AP_RPROF(ap) + + # Allocate working space. + call smark (sp) + call salloc (aperts, AP_NAPERTS(phot), TY_REAL) + + # Check for out of bounds apertures. + call ap_maxap (ap, pier) + + # Define the good data minimum and maximum for photometry. + if (IS_INDEFR(AP_DATAMIN(ap))) + datamin = -MAX_REAL + else + datamin = AP_DATAMIN(ap) + if (IS_INDEFR(AP_DATAMAX(ap))) + datamax = MAX_REAL + else + datamax = AP_DATAMAX(ap) + + # Compute the sums. + call ap_arrayr (ap, APERTS, Memr[aperts]) + call amulkr (Memr[aperts], AP_SCALE(ap), Memr[aperts], AP_NAPERTS(phot)) + if (IS_INDEFR(AP_DATAMIN(ap)) && IS_INDEFR(AP_DATAMAX(ap))) { + call ap_rmmeasure (Memr[AP_RPIX(rprof)], AP_RPNX(rprof), + AP_RPNY(rprof), AP_RPXC(rprof), AP_RPYC(rprof), Memr[aperts], + Memd[AP_SUMS(phot)], Memd[AP_AREA(phot)], AP_NMAXAP(phot)) + AP_NMINAP(phot) = AP_NMAXAP(phot) + 1 + } else + call ap_brmmeasure (Memr[AP_RPIX(rprof)], AP_RPNX(rprof), + AP_RPNY(rprof), AP_RPXC(rprof), AP_RPYC(rprof), datamin, + datamax, Memr[aperts], Memd[AP_SUMS(phot)], + Memd[AP_AREA(phot)], AP_NMAXAP(phot), AP_NMINAP(phot)) + + # Check for bad pixels. + if ((pier == AP_OK) && (AP_NMINAP(phot) <= AP_NMAXAP(phot))) + pier = AP_APERT_BADDATA + nap = min (AP_NMINAP(phot) - 1, AP_NMAXAP(phot)) + + # Compute the magnitudes. + zmag = AP_ZMAG(phot) + 2.5 * log10 (AP_ITIME(ap)) + if (AP_POSITIVE(ap) == YES) + call apcopmags (Memd[AP_SUMS(phot)], Memd[AP_AREA(phot)], + Memr[AP_MAGS(phot)], Memr[AP_MAGERRS(phot)], nap, + AP_SKY_MODE(sky), AP_SKY_SIG(sky), AP_NSKY(sky), zmag, + AP_NOISEFUNCTION(nse), AP_EPADU(nse)) + else + call apconmags (Memd[AP_SUMS(phot)], Memd[AP_AREA(phot)], + Memr[AP_MAGS(phot)], Memr[AP_MAGERRS(phot)], nap, + AP_SKY_MODE(sky), AP_SKY_SIG(sky), AP_NSKY(sky), zmag, + AP_NOISEFUNCTION(nse), AP_EPADU(nse), AP_READNOISE(nse)) + + call sfree (sp) + + return (pier) +end + + +# AP_RPMEASURE -- Procedure to measure the flux and effective area in a set of +# apertures and accumulate the fit to the radial profile. + +int procedure ap_rpmeasure (cv, pixels, nx, ny, wx, wy, datamin, datamax, + rmax, ndata, nbad) + +pointer cv # pointer to curfit structure +real pixels[nx,ARB] # subraster pixel values +int nx, ny # dimensions of the subraster +real wx, wy # center of subraster +real datamin # minimum good data value +real datamax # maximum good data value +real rmax # the maximum radius +int ndata # the number of ok data points +int nbad # the number of bad data points + +int i, j, ier +real weight, dy2, r2, rcv + +begin + # Initialize. + ndata = 0 + nbad = 0 + call cvzero (cv) + + # Loop over the pixels. + do j = 1, ny { + dy2 = (j - wy) ** 2 + do i = 1, nx { + r2 = (i - wx) ** 2 + dy2 + rcv = sqrt (r2) + if (rcv > rmax) + next + if (pixels[i,j] < datamin || pixels[i,j] > datamax) { + nbad = nbad + 1 + } else { + call cvaccum (cv, rcv, pixels[i,j], weight, WTS_UNIFORM) + ndata = ndata + 1 + } + } + } + + call cvsolve (cv, ier) + return (ier) +end + + +# AP_RPITER -- Procedure to reject pixels from the fit. + +int procedure ap_rpiter (cv, pixels, nx, ny, wx, wy, rmax, datamin, datamax, + niter, ksigma, fier) + +pointer cv # pointer to the curfit structure +real pixels[nx,ARB] # pixel values +int nx, ny # dimensions of image subraster +real wx, wy # x and y coordinates of the center +real rmax # maximum radius value +real datamin # minimum good data value +real datamax # maximum good data value +int niter # maximum number of rejection cycles +real ksigma # ksigma rejection limit +int fier # fitting error code + +int i, j, k, npts, ntreject, nreject +pointer sp, rtemp, w, ptr +real chisqr, diff, locut, hicut +real cveval() +errchk cveval, cvrject, cvsolve + +begin + # Allocate the necessary space. + call smark (sp) + call salloc (rtemp, nx, TY_REAL) + call salloc (w, nx * ny, TY_REAL) + call amovkr (1.0, Memr[w], nx * ny) + + # Set the weights of out of range and bad data points to 0.0. + ptr = w + do j = 1, ny { + call ap_ijtor (Memr[rtemp], nx, j, wx, wy) + do k = 1, nx { + if (Memr[rtemp+k-1] > rmax || pixels[k,j] < datamin || + pixels[k,j] > datamax) + Memr[ptr+k-1] = 0.0 + } + ptr = ptr + nx + } + + ntreject = 0 + do i = 1, niter { + + # Compute the chisqr. + chisqr = 0.0 + npts = 0 + ptr = w + do j = 1, ny { + call ap_ijtor (Memr[rtemp], nx, j, wx, wy) + do k = 1, nx { + if (Memr[ptr+k-1] <= 0.0) + next + chisqr = chisqr + (pixels[k,j] - cveval (cv, + Memr[rtemp+k-1])) ** 2 + npts = npts + 1 + } + ptr = ptr + nx + } + + # Compute the new limits. + if (npts > 1) + chisqr = sqrt (chisqr / (npts - 1)) + else + chisqr = 0.0 + locut = - ksigma * chisqr + hicut = ksigma * chisqr + + # Reject pixels from the fit. + nreject = 0 + ptr = w + do j = 1, ny { + call ap_ijtor (Memr[rtemp], nx, j, wx, wy) + do k = 1, nx { + if (Memr[ptr+k-1] <= 0.0) + next + diff = pixels[k,j] - cveval (cv, Memr[rtemp+k-1]) + if (diff >= locut && diff <= hicut) + next + call cvrject (cv, Memr[rtemp+k-1], pixels[k,j], 1.0) + nreject = nreject + 1 + Memr[ptr+k-1] = 0.0 + } + ptr = ptr + nx + } + + if (nreject == 0) + break + ntreject = ntreject + nreject + + # Recompute the fit. + call cvsolve (cv, fier) + if (fier == NO_DEG_FREEDOM) + break + } + + + call sfree (sp) + + return (ntreject) +end + + +# AP_RPHALF -- Compute the FWHM of the PSF. + +real procedure ap_rphalf (radius, intensity, npts) + +real radius[ARB] # radius in pixels +real intensity[ARB] # profile intensity +int npts # number of points + +int i +real halfp + +begin + # Seach for the appropriate interval. + do i = 1, npts + if (intensity[i] < 0.5) + break + + # Compute the full width half maximum. + if (i == 1) + halfp = radius[1] + else if (i == npts && intensity[npts] >= 0.5) + halfp = radius[npts] + else + halfp = (radius[i] * (0.5 - intensity[i-1]) + radius[i-1] * + (intensity[i] - 0.5)) / (intensity[i] - intensity[i-1]) + + return (halfp) +end diff --git a/noao/digiphot/apphot/radprof/apgrpars.x b/noao/digiphot/apphot/radprof/apgrpars.x new file mode 100644 index 00000000..c7442121 --- /dev/null +++ b/noao/digiphot/apphot/radprof/apgrpars.x @@ -0,0 +1,46 @@ +include "../lib/display.h" +include "../lib/noise.h" +include "../lib/center.h" +include "../lib/fitsky.h" +include "../lib/phot.h" +include "../lib/radprof.h" + +# AP_GRPPARS -- Procedure to fetch the radprof parameters. + +procedure ap_grppars (ap) + +pointer ap # pointer to apphot structure + +bool clgetb() +int clgeti(), btoi() +real clgetr() + +begin + # Open the apphot strucuture. + call ap_rpinit (ap, AP_CENTROID1D, 2.5, AP_MODE, 10.0, 10.0, + 3.0, 1, 8.0, 0.5, 2.0, AP_NPOISSON) + + # Get the radial profile parameters. + call apsetr (ap, RPRADIUS, clgetr ("radius")) + call apsetr (ap, RPSTEP, clgetr ("step")) + + # Get the data dependent parameters. + call ap_gdapars (ap) + + # Get the centering algorithm parameters. + call ap_gcepars (ap) + + # Get the sky fitting algorithm parameters. + call ap_gsapars (ap) + + # Get the photometry parameters. + call ap_gphpars (ap) + + # Set remainder of the radprof parameters. + call apsetr (ap, RPKSIGMA, clgetr ("kreject")) + call apseti (ap, RPNREJECT, clgeti ("nreject")) + call apseti (ap, RPORDER, clgeti ("order")) + + # Set the plotting parameters. + call apseti (ap, RADPLOTS, btoi (clgetb ("radplots"))) +end diff --git a/noao/digiphot/apphot/radprof/approfsetup.x b/noao/digiphot/apphot/radprof/approfsetup.x new file mode 100644 index 00000000..826bdd21 --- /dev/null +++ b/noao/digiphot/apphot/radprof/approfsetup.x @@ -0,0 +1,123 @@ +include "../lib/display.h" +include "../lib/center.h" +include "../lib/fitsky.h" + +define HELPFILE "apphot$radprof/iradprof.key" + +# AP_PROFSETUP -- Procedure to set up radprof interactively using a radial +# profile plot. + +procedure ap_profsetup (ap, im, wx, wy, gd, out, stid) + +pointer ap # pointer to apphot structure +pointer im # pointer to the IRAF image +real wx, wy # cursor coordinates +pointer gd # pointer to graphics stream +int out # output file descriptor +int stid # output file sequence number + +int cier, sier, pier, rier, wcs, key +pointer sp, str, cmd +real xc, yc, xcenter, ycenter, rmin, rmax, imin, imax, rval +real u1, u2, v1, v2, x1, x2, y1, y2 + +int apfitcenter(), clgcur(), apfitsky(), ap_frprof(), apstati() +int ap_showplot() +real apstatr(), ap_cfwhmpsf(), ap_ccapert(), ap_cannulus(), ap_cdannulus() +real ap_crprof(), ap_crpstep(), ap_cdatamin() +real ap_cdatamax(), ap_crgrow(), ap_crclip(), ap_crclean(), ap_csigma() + +begin + if (gd == NULL) + return + call greactivate (gd, 0) + + # Save old viewport and window + call ggview (gd, u1, u2, v1, v2) + call ggwind (gd, x1, x2, y1, y2) + + # Plot the radial profile. + if (ap_showplot (ap, im, wx, wy, gd, xcenter, ycenter, rmin, rmax, + imin, imax) == ERR) { + call gdeactivate (gd, 0) + return + } + + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + call salloc (cmd, SZ_LINE, TY_CHAR) + call printf ( + "Waiting for setup menu command (?=help, v=default setup, q=quit):\n") + while (clgcur ("gcommands", xc, yc, wcs, key, Memc[cmd], + SZ_LINE) != EOF) { + + switch (key) { + + case 'q': + break + case '?': + call gpagefile (gd, HELPFILE, "") + case 'f': + rval = ap_cfwhmpsf (ap, gd, out, stid, rmin, rmax, imin, imax) + case 's': + rval = ap_csigma (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'l': + rval = ap_cdatamin (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'u': + rval = ap_cdatamax (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'c': + rval = ap_ccapert (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'n': + rval = ap_crclean (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'p': + rval = ap_crclip (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'a': + rval = ap_cannulus (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'd': + rval = ap_cdannulus (ap, gd, out, stid, apstatr (ap, ANNULUS), + rmin, rmax, imin, imax) + case 'g': + rval = ap_crgrow (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'r': + call ap_caper (ap, gd, out, stid, Memc[str], rmin, rmax, + imin, imax) + case 'w': + rval = ap_crprof (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'x': + rval = ap_crpstep (ap, gd, out, stid, rmin, rmax, imin, imax) + case 'v': + rval = ap_cfwhmpsf (ap, gd, out, stid, rmin, rmax, imin, imax) + rval = ap_ccapert (ap, gd, out, stid, rmin, rmax, imin, imax) + rval = ap_cannulus (ap, gd, out, stid, rmin, rmax, imin, imax) + rval = ap_cdannulus (ap, gd, out, stid, apstatr (ap, ANNULUS), + rmin, rmax, imin, imax) + rval = ap_csigma (ap, gd, out, stid, rmin, rmax, imin, imax) + call ap_caper (ap, gd, out, stid, Memc[str], rmin, rmax, + imin, imax) + rval = ap_crprof (ap, gd, out, stid, rmin, rmax, imin, imax) + rval = ap_crpstep (ap, gd, out, stid, rmin, rmax, imin, imax) + default: + call printf ("Unknown or ambiguous keystroke command\007\n") + } + call printf ( + "Waiting for setup menu command (?=help, v=default setup, q=quit):\n") + } + call printf ( + "Interactive setup is complete. Type w to save parameters.\n") + + # Restore old view port and window + call gsview (gd, u1, u2, v1, v2) + call gswind (gd, x1, x2, y1, y2) + + call gdeactivate (gd, 0) + call sfree (sp) + + # Compute the answer. + cier = apfitcenter (ap, im, xcenter, ycenter) + sier = apfitsky (ap, im, apstatr (ap, XCENTER), apstatr (ap, YCENTER), + NULL, gd) + rier = ap_frprof (ap, im, apstatr (ap, XCENTER), apstatr (ap, YCENTER), + pier) + call ap_rpplot (ap, 0, gd, apstati (ap, RADPLOTS)) + call ap_qprprof (ap, cier, sier, pier, rier) +end diff --git a/noao/digiphot/apphot/radprof/apprprof.x b/noao/digiphot/apphot/radprof/apprprof.x new file mode 100644 index 00000000..1d7461ee --- /dev/null +++ b/noao/digiphot/apphot/radprof/apprprof.x @@ -0,0 +1,109 @@ +include "../lib/apphotdef.h" +include "../lib/apphot.h" +include "../lib/center.h" +include "../lib/fitsky.h" +include "../lib/photdef.h" +include "../lib/phot.h" +include "../lib/radprof.h" + +# AP_PRPROF -- Procedure to write the results of radprof to the output file. + +procedure ap_prprof (ap, fd, id, lid, cier, sier, pier, rier) + +pointer ap # pointer to apphot structure +int fd # output text file descriptor +int id # id number of str +int lid # list id of star +int cier # centering error +int sier # sky fitting error +int pier # photometric error +int rier # radial profile error + +int i, naperts +int apstati() +real apstatr() + +begin + if (fd == NULL) + return + + # Print the id parameters. + call ap_wid (ap, fd, apstatr (ap, OXINIT), apstatr (ap, OYINIT), + id, lid, '\\') + + # Print the center parameters. + call ap_wcres (ap, fd, cier, '\\') + + # Print the sky values. + call ap_wsres (ap, fd, sier, '\\') + + # Print photometry parameters. + naperts = apstati (ap, NAPERTS) + do i = 1, naperts { + if (naperts == 1) + call ap_wmres (ap, fd, i, pier, " \\") + else + call ap_wmres (ap, fd, i, pier, "*\\") + } + + # Print the radprof parameters. + call ap_wrres (ap, fd, rier) +end + + +# AP_RPHDR -- Procedure to write the radprof banner header to the output file. + +procedure ap_rphdr (ap, out) + +pointer ap # apphot descriptor +int out # output file descriptor + +begin + if (out == NULL) + return + + # Print out the keywords. + call ap_idhdr (ap, out) + call ap_chdr (ap, out) + call ap_shdr (ap, out) + call ap_mhdr (ap, out) + call ap_rhdr (ap, out) +end + + +# AP_QPRPROF -- Procedure to print a short version of the radprof results +# on the standard output. + +procedure ap_qprprof (ap, cier, sier, pier, rier) + +pointer ap # pointer to apphot structure +int cier # centering error +int sier # sky fitting error +int pier # phot error +int rier # radprof error + +pointer sp, imname, phot +real apstatr() + +begin + call smark (sp) + call salloc (imname, SZ_FNAME, TY_CHAR) + phot = AP_PPHOT(ap) + + # Print quick summary of radprof results on the standard output. + call apstats (ap, IMROOT, Memc[imname], SZ_FNAME) + call printf ("%s %8.2f %8.2f %8g %5.2f ") + call pargstr (Memc[imname]) + call pargr (apstatr (ap, ORPXCUR)) + call pargr (apstatr (ap, ORPYCUR)) + call pargr (apstatr (ap, SKY_MODE)) + call pargr (apstatr (ap, RPFWHM) / apstatr (ap, SCALE)) + call printf ("%7.3f %s\n") + call pargr (Memr[AP_MAGS(phot)+AP_NAPERTS(phot)-1]) + if (cier != AP_OK || sier != AP_OK || pier != AP_OK || rier != AP_OK) + call pargstr ("err") + else + call pargstr ("ok") + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/radprof/apradprof.x b/noao/digiphot/apphot/radprof/apradprof.x new file mode 100644 index 00000000..10448af2 --- /dev/null +++ b/noao/digiphot/apphot/radprof/apradprof.x @@ -0,0 +1,500 @@ +include <ctype.h> +include <gset.h> +include <imhdr.h> +include "../lib/apphot.h" +include "../lib/display.h" +include "../lib/center.h" +include "../lib/fitsky.h" +include "../lib/radprof.h" + +define HELPFILE "apphot$radprof/radprof.key" + +# AP_RADPROF -- Procedure to determine radial profiles for a list of objects +# in a list of images. + +int procedure ap_radprof (ap, im, cl, gd, mgd, id, out, stid, interactive, + cache) + +pointer ap # pointer to apphot structure +pointer im # pointer to IRAF image +int cl # starlist file descriptor +pointer gd # pointer to graphcis descriptor +pointer mgd # pointer to plot metacode stream +pointer id # pointer to image display stream +int out # output file descriptor +int stid # output file sequence number +int interactive # interactive mode +int cache # cache the input image pixels + +real wx, wy, xlist, ylist +pointer sp, cmd +int wcs, key, oid, ltid, newlist, colonkey, req_size, buf_size, old_size +int newimage, newskybuf, newsky, newcenterbuf, newcenter, newbuf, newfit +int ip, prev_num, req_num, cier, sier, pier, rier, memstat + +real apstatr() +int clgcur(), apfitsky(), aprefitsky(), apfitcenter(), aprefitcenter() +int apstati(), apgscur(), ap_frprof(), ctoi(), apgqverify(), apgtverify() +int apnew(), ap_avsky(), sizeof(), ap_memstat() +bool fp_equalr() + +define endswitch_ 99 + +begin + # Initialize. + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + # Initialize the cursor command. + key = ' ' + Memc[cmd] = EOS + + # Initialize the fit. + newimage = NO + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newbuf = YES; newfit = YES + cier = AP_OK; sier = AP_OK; pier = AP_OK; rier = AP_OK + + # Initialize the sequencing. + newlist = NO + ltid = 0 + + # Loop over the coordinate file. + while (clgcur ("icommands", wx, wy, wcs, key, Memc[cmd], SZ_LINE) != + EOF) { + + # Store the cursor coords. + call ap_vtol (im, wx, wy, wx, wy, 1) + call apsetr (ap, CWX, wx) + call apsetr (ap, CWY, wy) + + # Test to see if the cursor has moved. + if (apnew (ap, wx, wy, xlist, ylist, newlist) == YES) { + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newbuf = YES; newfit = YES + } + + # Switch on the keystroke commands. + switch (key) { + + # Quit. + case 'q': + if (interactive == YES) { + if (apgqverify ("radprof", ap, key) == YES) { + call sfree (sp) + return (apgtverify (key)) + } + } else { + call sfree (sp) + return (NO) + } + + # Print the errors. + case 'e': + if (interactive == YES) + call ap_rferrors (ap, cier, sier, pier, rier) + + # Print the help page. + case '?': + if ((id != NULL) && (id == gd)) + call gpagefile (id, HELPFILE, "") + else if (interactive == YES) + call pagefile (HELPFILE, "[space=morehelp,q=quit,?=help]") + + # Rewind the list. + case 'r': + if (cl != NULL) { + call seek (cl, BOF) + ltid = 0 + } else if (interactive == YES) + call printf ("No coordinate list\n") + + # Move, measure next object in the coordinate list. + case 'm', 'n': + + # No coordinate file. + if (cl == NULL) { + if (interactive == YES) + call printf ("No coordinate list\n") + goto endswitch_ + } + + # Need to rewind the coordinate file. + prev_num = ltid + req_num = ltid + 1 + if (apgscur (cl, id, xlist, ylist, prev_num, req_num, + ltid) == EOF) { + if (interactive == YES) + call printf ( + "End of coordinate list, use r key to rewind\n") + goto endswitch_ + } + + # Convert coordinates if necessary. + switch (apstati (ap, WCSIN)) { + case WCS_PHYSICAL, WCS_WORLD: + call ap_itol (ap, xlist, ylist, xlist, ylist, 1) + case WCS_TV: + call ap_vtol (im, xlist, ylist, xlist, ylist, 1) + default: + ; + } + + # Move to the next object. + newlist = YES + if (key == 'm') { + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newbuf = YES; newfit = YES + goto endswitch_ + } + + # Measure next object. + cier = apfitcenter (ap, im, xlist, ylist) + sier = apfitsky (ap, im, apstatr (ap, XCENTER), apstatr (ap, + YCENTER), NULL, gd) + rier = ap_frprof (ap, im, apstatr (ap, XCENTER), apstatr (ap, + YCENTER), pier) + call aprmark (ap, id, apstati (ap, MKCENTER), apstati (ap, + MKSKY), apstati (ap, MKAPERT)) + if (id != NULL) { + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_rpplot (ap, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qprprof (ap, cier, sier, pier, rier) + if (stid == 1) + call ap_param (ap, out, "radprof") + call ap_prprof (ap, out, stid, ltid, cier, sier, pier, rier) + call ap_rpplot (ap, stid, mgd, YES) + stid = stid + 1 + newcenterbuf = NO; newcenter = NO + newskybuf = NO; newsky = NO + newbuf = NO; newfit = NO + + # Process the remainder of the list. + case 'l': + if (cl != NULL) { + oid = stid + ltid = ltid + 1 + call ap_bradprof (ap, im, cl, id, gd, mgd, out, stid, ltid, + YES) + ltid = ltid + stid - oid + 1 + if (id != NULL) { + if (id == gd) + call gflush (id) + else + call gframe (id) + } + } else if (interactive == YES) + call printf ("No coordinate list\n") + + # Process radprof colon commands. + case ':': + for (ip = 1; IS_WHITE(Memc[cmd+ip-1]); ip = ip + 1) + ; + colonkey = Memc[cmd+ip-1] + switch (colonkey) { + case 'm', 'n': + + # Show/set radprof parameters. + if (Memc[cmd+ip] != EOS && Memc[cmd+ip] != ' ') { + call ap_rpcolon (ap, im, cl, out, stid, ltid, Memc[cmd], + newimage, newcenterbuf, newcenter, newskybuf, + newsky, newbuf, newfit) + goto endswitch_ + } + + # Process the next object. + if (cl == NULL) { + if (interactive == YES) + call printf ("No coordinate list\n") + goto endswitch_ + } + + # Get next object from the list. + ip = ip + 1 + prev_num = ltid + if (ctoi (Memc[cmd], ip, req_num) <= 0) + req_num = ltid + 1 + + # Fetch next object from the list. + if (apgscur (cl, id, xlist, ylist, prev_num, req_num, + ltid) == EOF) { + if (interactive == YES) + call printf ( + "End of coordinate list, use r key to rewind\n") + goto endswitch_ + + } + + # Convert the coordinates. + switch (apstati (ap, WCSIN)) { + case WCS_PHYSICAL, WCS_WORLD: + call ap_itol (ap, xlist, ylist, xlist, ylist, 1) + case WCS_TV: + call ap_vtol (im, xlist, ylist, xlist, ylist, 1) + default: + ; + } + + # Move to next object. + newlist = YES + if (colonkey == 'm') { + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newbuf = YES; newfit = YES + } + + # Measure the next object. + cier = apfitcenter (ap, im, xlist, ylist) + sier = apfitsky (ap, im, apstatr (ap, XCENTER), + apstatr (ap, YCENTER), NULL, gd) + rier = ap_frprof (ap, im, apstatr (ap, XCENTER), + apstatr (ap, YCENTER), pier) + call aprmark (ap, id, apstati (ap, MKCENTER), apstati (ap, + MKSKY), apstati (ap, MKAPERT)) + if (id != NULL) { + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_rpplot (ap, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qprprof (ap, cier, sier, pier, rier) + + if (stid == 1) + call ap_param (ap, out, "radprof") + call ap_prprof (ap, out, stid, ltid, cier, sier, pier, rier) + call ap_rpplot (ap, stid, mgd, YES) + stid = stid + 1 + newcenterbuf = NO; newcenter = NO + newskybuf = NO; newsky = NO + newbuf = NO; newfit = NO + + default: + call ap_rpcolon (ap, im, cl, out, stid, ltid, Memc[cmd], + newimage, newcenterbuf, newcenter, newskybuf, newsky, + newbuf, newfit) + } + + # Reestablish the image viewport and window. + if (newimage == YES) { + if ((id != NULL) && (id != gd)) + call ap_gswv (id, Memc[cmd], im, 4) + req_size = MEMFUDGE * IM_LEN(im,1) * IM_LEN(im,2) * + sizeof (IM_PIXTYPE(im)) + memstat = ap_memstat (cache, req_size, old_size) + if (memstat == YES) + call ap_pcache (im, INDEFI, buf_size) + } + + newimage = NO + + # Save the parameters. + case 'w': + call ap_rpars (ap) + + # Plot a simple centered radial profile. + case 'd': + if (interactive == YES) { + call ap_qrad (ap, im, wx, wy, gd) + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newbuf = YES; newfit = YES + } + + + # Setup the radial profile fitting parameters interactively. + case 'i': + if (interactive == YES) { + call ap_profsetup (ap, im, wx, wy, gd, out, stid) + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newbuf = YES; newfit = YES + } + + # Verify the critical radprof parameters. + case 'v': + call ap_rconfirm (ap, out, stid) + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newbuf = YES; newfit = YES + + # Fit the center around the current cursor value. + case 'c': + if (newcenterbuf == YES) + cier = apfitcenter (ap, im, wx, wy) + else if (newcenter == YES) + cier = aprefitcenter (ap, im, cier) + call aprmark (ap, id, apstati (ap, MKCENTER), NO, NO) + if (id != NULL) { + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_cplot (ap, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qcenter (ap, cier) + newcenterbuf = NO; newcenter = NO + + # Fit the sky around the current cursor value. + case 't': + if (newskybuf == YES || ! fp_equalr (wx, + apstatr (ap, SXCUR)) || ! fp_equalr (wy, apstatr (ap, + SYCUR))) + sier = apfitsky (ap, im, wx, wy, NULL, gd) + else if (newsky == YES) + sier = aprefitsky (ap, im, gd) + call aprmark (ap, id, NO, apstati (ap, MKSKY), NO) + if (id != NULL) { + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_splot (ap, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qspsky (ap, sier) + newskybuf = NO; newsky = NO + + # Compute the average of several sky measurements around + # different cursor postions. + case 'a': + sier = ap_avsky (ap, im, stid, NULL, id, gd, interactive) + if (interactive == YES) + call ap_qaspsky (ap, sier) + newskybuf = NO; newsky = NO + + # Fit the sky around derived center value. + case 's': + if (newskybuf == YES || ! fp_equalr (apstatr (ap, XCENTER), + apstatr (ap, SXCUR)) || ! fp_equalr (apstatr (ap, + SYCUR), apstatr (ap, YCENTER))) + sier = apfitsky (ap, im, apstatr (ap, XCENTER), + apstatr (ap, YCENTER), NULL, gd) + else if (newsky == YES) + sier = aprefitsky (ap, im, gd) + call aprmark (ap, id, NO, apstati (ap, MKSKY), NO) + if (id != NULL) { + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_splot (ap, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qspsky (ap, sier) + newskybuf = NO; newsky = NO + + # Compute magnitudes around the current cursor position using + # the current sky. + case 'p', 'o': + if (newcenterbuf == YES) + cier = apfitcenter (ap, im, wx, wy) + else if (newcenter == YES) + cier = aprefitcenter (ap, im, cier) + call aprmark (ap, id, apstati (ap, MKCENTER), NO, + apstati (ap, MKAPERT)) + if (id != NULL) { + if (id == gd) + call gflush (id) + else + call gframe (id) + } + if (newfit == YES || newbuf == YES || ! fp_equalr (apstatr (ap, + XCENTER), apstatr (ap, RPXCUR)) || + ! fp_equalr (apstatr (ap, RPYCUR), apstatr (ap, YCENTER))) + rier = ap_frprof (ap, im, apstatr (ap, XCENTER), + apstatr (ap, YCENTER), pier) + if (interactive == YES) + call ap_qprprof (ap, cier, sier, pier, rier) + newcenterbuf = NO; newcenter = NO + newbuf = NO; newfit = NO + + if (key == 'o') { + if (stid == 1) + call ap_param (ap, out, "radprof") + if (newlist == YES) + call ap_prprof (ap, out, stid, ltid, cier, sier, pier, + rier) + else + call ap_prprof (ap, out, stid, 0, cier, sier, pier, + rier) + call ap_rpplot (ap, stid, mgd, YES) + stid = stid + 1 + } + + # Center, fit the sky, and compute magnitudes. + # Compute the centers, fit the sky, compute the magnitudes + # and save the results. + case 'f', ' ': + if (newcenterbuf == YES) + cier = apfitcenter (ap, im, wx, wy) + else if (newcenter == YES) + cier = aprefitcenter (ap, im, cier) + if (newskybuf == YES || ! fp_equalr (apstatr (ap, XCENTER), + apstatr (ap, SXCUR)) || ! fp_equalr (apstatr (ap, YCENTER), + apstatr (ap, SYCUR))) + sier = apfitsky (ap, im, apstatr (ap, XCENTER), + apstatr (ap, YCENTER), NULL, gd) + else if (newsky == YES) + sier = aprefitsky (ap, im, gd) + + if (newfit == YES || newbuf == YES || ! fp_equalr (apstatr (ap, + XCENTER), apstatr (ap, RPXCUR)) || ! fp_equalr (apstatr (ap, + YCENTER), apstatr (ap, RPYCUR))) + rier = ap_frprof (ap, im, apstatr (ap, XCENTER), + apstatr (ap, YCENTER), pier) + call aprmark (ap, id, apstati (ap, MKCENTER), apstati (ap, + MKSKY), apstati (ap, MKAPERT)) + if (id != NULL) { + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_rpplot (ap, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qprprof (ap, cier, sier, pier, rier) + + newcenterbuf = NO; newcenter = NO + newskybuf = NO; newsky = NO + newbuf = NO; newfit = NO + + if (key == ' ') { + if (stid == 1) + call ap_param (ap, out, "radprof") + if (newlist == YES) + call ap_prprof (ap, out, stid, ltid, cier, sier, pier, + rier) + else + call ap_prprof (ap, out, stid, 0, cier, sier, pier, + rier) + call ap_rpplot (ap, stid, mgd, YES) + stid = stid + 1 + } + + default: + # do nothing + call printf ("Print unknown or ambiguous colon command\n") + } + +endswitch_ + # Prepare for the next object. + key = ' ' + Memc[cmd] = EOS + call apsetr (ap, WX, apstatr (ap, CWX)) + call apsetr (ap, WY, apstatr (ap, CWY)) + + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/radprof/aprconfirm.x b/noao/digiphot/apphot/radprof/aprconfirm.x new file mode 100644 index 00000000..3c775e79 --- /dev/null +++ b/noao/digiphot/apphot/radprof/aprconfirm.x @@ -0,0 +1,118 @@ +include "../lib/apphot.h" +include "../lib/noise.h" +include "../lib/center.h" +include "../lib/fitsky.h" +include "../lib/phot.h" +include "../lib/radprof.h" + +# AP_RCONFIRM -- Procedure to confirm the critical phot parameters. + +procedure ap_rconfirm (ap, out, stid) + +pointer ap # pointer to the apphot structure +int out # output file descriptor +int stid # output file sequence number + +pointer sp, cstr, sstr, aperts +real fwhmpsf, capert, annulus, dannulus, skysigma +real datamin, datamax, radius, step +int apstati() +real apstatr(), ap_vfwhmpsf(), ap_vcapert() +real ap_vannulus(), ap_vdannulus(), ap_vsigma(), ap_vstep() +real ap_vdatamin(), ap_vdatamax(), ap_vrpradius() + +begin + call smark (sp) + call salloc (cstr, SZ_FNAME, TY_CHAR) + call salloc (sstr, SZ_FNAME, TY_CHAR) + call salloc (aperts, SZ_LINE, TY_CHAR) + + call printf ("\n") + + # Confirm the centering algorithm. + call ap_vcstring (ap, Memc[cstr], SZ_FNAME) + + if (apstati (ap, CENTERFUNCTION) != AP_NONE) { + + # Confirm the fwhmpsf. + if (apstati (ap, CENTERFUNCTION) != AP_CENTROID1D) + fwhmpsf = ap_vfwhmpsf (ap) + else + fwhmpsf = apstatr (ap, FWHMPSF) + + # Confirm the centering box. + capert = 2.0 * ap_vcapert (ap) + + } else { + fwhmpsf = apstatr (ap, FWHMPSF) + capert = 2.0 * apstatr (ap, CAPERT) + } + + # Confirm the sky fitting algorithm. + call ap_vsstring (ap, Memc[sstr], SZ_FNAME) + + if (apstati (ap, SKYFUNCTION) != AP_CONSTANT && + apstati (ap, SKYFUNCTION) != AP_SKYFILE) { + + # Confirm the sky annulus parameter. + annulus = ap_vannulus (ap) + + # Confirm the width of the sky annulus. + dannulus = ap_vdannulus (ap) + + } else { + annulus = apstatr (ap, ANNULUS) + dannulus = apstatr (ap, DANNULUS) + } + + # Confirm the sky sigma parameter. + if (apstati (ap, SKYFUNCTION) != AP_SKYFILE) + skysigma = ap_vsigma (ap) + else + skysigma = apstatr (ap, SKYSIGMA) + + # Confirm the aperture radii parameter. + call ap_vaperts (ap, Memc[aperts], SZ_LINE) + + # Confirm the radius of profile + radius = ap_vrpradius (ap) + + # Confirm the step size of profile + step = ap_vstep (ap) + + # Confirm the minimum and maximum good data values. + datamin = ap_vdatamin (ap) + datamax = ap_vdatamax (ap) + + call printf ("\n") + + # Update the database file. + if (out != NULL && stid > 1) { + call ap_sparam (out, KY_CSTRING, Memc[cstr], UN_CALGORITHM, + "centering algorithm") + call ap_rparam (out, KY_FWHMPSF, fwhmpsf, UN_ASCALEUNIT, + "full width half maximum of the psf") + call ap_rparam (out, KY_CAPERT, capert, UN_CSCALEUNIT, + "centering box width") + call ap_sparam (out, KY_SSTRING, Memc[sstr], UN_SALGORITHM, + "sky fitting algorithm") + call ap_rparam (out, KY_ANNULUS, annulus, UN_SSCALEUNIT, + "inner radius of the sky annulus") + call ap_rparam (out, KY_DANNULUS, dannulus, UN_SSCALEUNIT, + "width of the sky annulus") + call ap_rparam (out, KY_SKYSIGMA, skysigma, UN_NCOUNTS, + "standard deviation of 1 sky pixel") + call ap_sparam (out, KY_APERTS, Memc[aperts], UN_PSCALEUNIT, + "list of apertures") + call ap_rparam (out, KY_DATAMIN, datamin, UN_ACOUNTS, + "minimum good data value") + call ap_rparam (out, KY_DATAMAX, datamax, UN_ACOUNTS, + "maximum good data value") + call ap_rparam (out, KY_RPRADIUS, radius, UN_RSCALEUNIT, + "fitting radius") + call ap_rparam (out, KY_RPSTEP, step, UN_RSCALEUNIT, + "step size in radius") + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/radprof/aprferrors.x b/noao/digiphot/apphot/radprof/aprferrors.x new file mode 100644 index 00000000..f72586f3 --- /dev/null +++ b/noao/digiphot/apphot/radprof/aprferrors.x @@ -0,0 +1,40 @@ +include "../lib/phot.h" +include "../lib/radprof.h" + +# AP_RFERRORS -- Procedure to print a short form of the output of radprof on +# the standard output. + +procedure ap_rferrors (ap, cier, sier, pier, rier) + +pointer ap # pointer to apphot structure +int cier # centering error +int sier # sky fitting error +int pier # photmetry error +int rier # photometric error + +begin + # Print the centering errors. + call ap_cerrors (ap, cier) + + # Print the sky fitting errors. + call ap_serrors (ap, sier) + + # Print the photometry errors. + call ap_merrors (ap, pier) + + # Print the radial profile fitting errors. + switch (rier) { + case AP_RP_NOPROFILE: + call printf ("The profile fitting region is outside the image.\n") + case AP_RP_OUTOFBOUNDS: + call printf ( + "The profile fitting region is partially outside the image.\n") + case AP_RP_NPTS_TOO_SMALL: + call printf ( + "There are too few points in the profile fitting region.\n") + case AP_RP_SINGULAR: + call printf ("The profile fit is singular.\n") + default: + call printf ("") + } +end diff --git a/noao/digiphot/apphot/radprof/aprmmeasure.x b/noao/digiphot/apphot/radprof/aprmmeasure.x new file mode 100644 index 00000000..fe455008 --- /dev/null +++ b/noao/digiphot/apphot/radprof/aprmmeasure.x @@ -0,0 +1,96 @@ +include <math/curfit.h> + +# AP_RMMEASURE -- Procedure to compute the sums and areas inside the apertures. + +procedure ap_rmmeasure (pixels, nx, ny, wx, wy, aperts, sums, areas, naperts) + +real pixels[nx,ARB] # subraster pixel values +int nx, ny # dimensions of the subraster +real wx, wy # center of subraster +real aperts[ARB] # array of apertures +double sums[ARB] # array of sums +double areas[ARB] # aperture areas +int naperts # number of apertures + +int i, j, k +double fctn +real apmaxsq, dy2, r2, r + +begin + # Initialize. + apmaxsq = (aperts[naperts] + 0.5) ** 2 + call aclrd (sums, naperts) + call aclrd (areas, naperts) + + # Loop over the pixels. + do j = 1, ny { + dy2 = (j - wy) ** 2 + do i = 1, nx { + r2 = (i - wx) ** 2 + dy2 + if (r2 > apmaxsq) + next + r = sqrt (r2) - 0.5 + do k = 1, naperts { + if (r > aperts[k]) + next + fctn = max (0.0, min (1.0, aperts[k] - r)) + sums[k] = sums[k] + fctn * pixels[i,j] + areas[k] = areas[k] + fctn + } + } + } +end + + +# AP_BRMMEASURE -- Procedure to compute the sums and areas inside the apertures. + +procedure ap_brmmeasure (pixels, nx, ny, wx, wy, datamin, datamax, aperts, + sums, areas, naperts, minapert) + +real pixels[nx,ARB] # subraster pixel values +int nx, ny # dimensions of the subraster +real wx, wy # center of subraster +real datamin # minimum good data value +real datamax # maximum good data value +real aperts[ARB] # array of apertures +double sums[ARB] # array of sums +double areas[ARB] # aperture areas +int naperts # number of apertures +int minapert # minimum number of apertures + +int i, j, k, kindex +double fctn +real apmaxsq, dy2, r2, r, pixval + +begin + # Initialize. + apmaxsq = (aperts[naperts] + 0.5) ** 2 + call aclrd (sums, naperts) + call aclrd (areas, naperts) + minapert = naperts + 1 + + # Loop over the pixels. + do j = 1, ny { + dy2 = (j - wy) ** 2 + do i = 1, nx { + r2 = (i - wx) ** 2 + dy2 + if (r2 > apmaxsq) + next + r = sqrt (r2) - 0.5 + kindex = naperts + 1 + pixval = pixels[i,j] + do k = 1, naperts { + if (r > aperts[k]) + next + kindex = min (k, kindex) + fctn = max (0.0, min (1.0, aperts[k] - r)) + sums[k] = sums[k] + fctn * pixval + areas[k] = areas[k] + fctn + } + if (kindex < minapert) { + if (pixval < datamin || pixval > datamax) + minapert = kindex + } + } + } +end diff --git a/noao/digiphot/apphot/radprof/aprpars.x b/noao/digiphot/apphot/radprof/aprpars.x new file mode 100644 index 00000000..fb4ed401 --- /dev/null +++ b/noao/digiphot/apphot/radprof/aprpars.x @@ -0,0 +1,37 @@ +include "../lib/display.h" +include "../lib/radprof.h" + +# AP_RPARS -- Procedure to write the radprof parameters to the parameter +# file. + +procedure ap_rpars (ap) + +pointer ap # pointer to apphot structure + +bool itob() +int apstati() +real apstatr() + +begin + # Write the data dependent parameters. + call ap_dapars (ap) + + # Write the centering parameters. + call ap_cepars (ap) + + # Write the sky fitting parameters. + call ap_sapars (ap) + + # Write out the photometry parameters. + call ap_phpars (ap) + + # Set the radphot parameters + call clputr ("radius", apstatr (ap, RPRADIUS)) + call clputr ("step", apstatr (ap, RPSTEP)) + call clputi ("order", apstati (ap, RPORDER)) + call clputr ("kreject", apstatr (ap, RPKSIGMA)) + call clputi ("nreject", apstati (ap, RPNREJECT)) + + # Set radial profile plots + call clputb ("radplots", itob (apstati (ap, RADPLOTS))) +end diff --git a/noao/digiphot/apphot/radprof/aprpbuf.x b/noao/digiphot/apphot/radprof/aprpbuf.x new file mode 100644 index 00000000..3a2f73ed --- /dev/null +++ b/noao/digiphot/apphot/radprof/aprpbuf.x @@ -0,0 +1,82 @@ +include <imhdr.h> +include "../lib/apphotdef.h" +include "../lib/radprofdef.h" +include "../lib/radprof.h" + +# AP_RPBUF -- Procedure to determine the mapping of the of the radial +# profile size into the apertures. + +int procedure ap_rpbuf (ap, im, wx, wy) + +pointer ap # pointer to apphot structure +pointer im # pointer to the IRAF image +real wx, wy # center coordinates + +int c1, c2, l1, l2 +pointer rprof +real rbuf +pointer ap_rppix() + +begin + # Check for 0 radius aperture. + rprof = AP_RPROF(ap) + if (AP_RPRADIUS(rprof) <= 0.0) + return (AP_RP_NOPROFILE) + + # Compute the maximum aperture size + rbuf = 2. * AP_RPRADIUS(rprof) * AP_SCALE(ap) + 1. + AP_RPIX(rprof) = ap_rppix (im, wx, wy, rbuf, c1, c2, l1, l2) + AP_RPXC(rprof) = wx - c1 + 1 + AP_RPYC(rprof) = wy - l1 + 1 + AP_RPNX(rprof) = c2 - c1 + 1 + AP_RPNY(rprof) = l2 - l1 + 1 + + # Return the appropriate error code. + if (AP_RPIX(rprof) == NULL) { + return (AP_RP_NOPROFILE) + } else if (AP_RPNX(rprof) < rbuf || AP_RPNY(rprof) < rbuf) { + return (AP_RP_OUTOFBOUNDS) + } else { + return (AP_OK) + } +end + + +# AP_RPPIX -- Procedure to read in the aperture pixels + +pointer procedure ap_rppix (im, wx, wy, papert, c1, c2, l1, l2) + +pointer im # pointer to IRAF image +real wx, wy # center of centering subraster annulus +real papert # centering radius +int c1, c2 # column limits +int l1, l2 # line limits + +int ncols, nlines +real half_papert, xc1, xc2, xl1, xl2 +pointer imgs2r() + +begin + # Check for 0 radius aperture. + half_papert = papert / 2. + if (half_papert <= 0.) + return (NULL) + ncols = IM_LEN(im,1) + nlines = IM_LEN(im,2) + + # Test for an out of bounds aperture. + xc1 = wx - half_papert + xc2 = wx + half_papert + xl1 = wy - half_papert + xl2 = wy + half_papert + if (xc1 > real (ncols) || xc2 < 1.0 || xl1 > real (nlines) || xl2 < 1.0) + return (NULL) + + # Get the column and line limits, dimensions and center of the subraster + # to be extracted. + c1 = max (1.0, min (real (ncols), xc1)) + c2 = min (real (ncols), max (1.0, xc2)) + l1 = max (1.0, min (real (nlines), xl1)) + l2 = min (real (nlines), max (1.0, xl2)) + return (imgs2r (im, c1, c2, l1, l2)) +end diff --git a/noao/digiphot/apphot/radprof/aprpcolon.x b/noao/digiphot/apphot/radprof/aprpcolon.x new file mode 100644 index 00000000..a5bf0eab --- /dev/null +++ b/noao/digiphot/apphot/radprof/aprpcolon.x @@ -0,0 +1,241 @@ +include "../lib/apphot.h" +include "../lib/noise.h" +include "../lib/center.h" +include "../lib/fitsky.h" +include "../lib/phot.h" +include "../lib/radprof.h" +include "../lib/display.h" + +# AP_RPCOLON -- Show/set radprof parameters. + +procedure ap_rpcolon (ap, im, cl, out, stid, ltid, cmdstr, newimage, + newcenterbuf, newcenter, newskybuf, newsky, newbuf, newfit) + +pointer ap # pointer to the apphot structure +pointer im # pointer to iraf image +int cl # coord file descriptor +int out # output file descriptor +int stid # output file sequence number +int ltid # coord list sequence number +char cmdstr[ARB] # command string +int newimage # new image +int newcenterbuf, newcenter # new sky fit +int newskybuf, newsky # new sky buffer +int newbuf, newfit # new aperture + +pointer sp, incmd, outcmd +int strdic() + +begin + call smark (sp) + call salloc (incmd, SZ_LINE, TY_CHAR) + call salloc (outcmd, SZ_LINE, TY_CHAR) + + # Get the commands. + call sscan (cmdstr) + call gargwrd (Memc[incmd], SZ_LINE) + if (Memc[incmd] == EOS) { + call sfree (sp) + return + } + + # Process the command. + if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, CCMDS) != 0) + call apccolon (ap, out, stid, cmdstr, newcenterbuf, newcenter) + else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, SCMDS) != 0) + call apscolon (ap, out, stid, cmdstr, newskybuf, newsky) + else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, RPCMDS) != 0) + call ap_profcolon (ap, out, stid, cmdstr, newbuf, newfit) + else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, PCMDS) != 0) + call apmagcolon (ap, out, stid, cmdstr, newbuf, newfit) + else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, APCMDS) != 0) + call ap_apcolon (ap, im, cl, out, stid, ltid, cmdstr, newimage, + newcenterbuf, newcenter, newskybuf, newsky, newbuf, newfit) + else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, NCMDS) != 0) + call ap_nscolon (ap, im, out, stid, cmdstr, newcenterbuf, + newcenter, newskybuf, newsky, newbuf, newfit) + else + call ap_rpimcolon (ap, cmdstr) + + call sfree (sp) +end + + +# AP_PROFCOLON -- Procedure to display and modify radprof parameters. + +procedure ap_profcolon (ap, out, stid, cmdstr, newbuf, newfit) + +pointer ap # pointer to apphot structure +int out # output file descriptor +int stid # output file number +char cmdstr[ARB] # command string +int newbuf # new aperture buffers +int newfit # compute new magnitudes + +int ival, ncmd +pointer sp, cmd +real rval +int strdic(), nscan(), apstati() +real apstatr() + +begin + # Get the command. + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + call sscan (cmdstr) + call gargwrd (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call sfree (sp) + return + } + + # Process the colon command. + ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, RPCMDS) + switch (ncmd) { + case RCMD_RADIUS: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_RPRADIUS) + call pargr (apstatr (ap, RPRADIUS)) + call pargstr (UN_RSCALEUNIT) + } else { + call apsetr (ap, RPRADIUS, rval) + if (stid > 1) + call ap_rparam (out, KY_RPRADIUS, rval, UN_RSCALEUNIT, + "fitting radius") + newbuf = YES; newfit = YES + } + case RCMD_STEPSIZE: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_RPSTEP) + call pargr (apstatr (ap, RPSTEP)) + call pargstr (UN_RSCALEUNIT) + } else { + call apsetr (ap, RPSTEP, rval) + if (stid > 1) + call ap_rparam (out, KY_RPSTEP, rval, UN_RSCALEUNIT, + "step size in radius") + newfit = YES + } + case RCMD_ORDER: + call gargi (ival) + if (nscan() == 1) { + call printf ("%s = %d\n") + call pargstr (KY_RPORDER) + call pargi (apstati (ap, RPORDER)) + } else { + call apseti (ap, RPORDER, ival) + if (stid > 1) + call ap_iparam (out, KY_RPORDER, ival, UN_RNUMBER, + "maximum number of rejection cycels") + newfit = YES + } + case RCMD_KREJECT: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g %s\n") + call pargstr (KY_RPKSIGMA) + call pargr (apstatr (ap, RPKSIGMA)) + call pargstr (UN_RSIGMA) + } else { + call apsetr (ap, RPKSIGMA, rval) + if (stid > 1) + call ap_rparam (out, KY_RPKSIGMA, rval, UN_RSIGMA, + "k-sigma rejection criteron") + newfit = YES + } + case RCMD_NREJECT: + call gargi (ival) + if (nscan() == 1) { + call printf ("%s = %d\n") + call pargstr (KY_RPNREJECT) + call pargi (apstati (ap, RPNREJECT)) + } else { + call apseti (ap, RPNREJECT, ival) + if (stid > 1) + call ap_iparam (out, KY_RPNREJECT, ival, UN_RNUMBER, + "maximum number of rejection cycles") + newfit = YES + } + default: + call printf ("Unknown or ambiguous colon command\7\n") + } + call sfree (sp) +end + + +# AP_RPIMCOLON -- Show/set quantities which are not radprof parameters. + +procedure ap_rpimcolon (ap, cmdstr) + +pointer ap # pointer to the apphot structure +char cmdstr[ARB] # command string + +bool bval +int ncmd +pointer sp, cmd +bool itob() +int apstati(), strdic(), nscan(), btoi() + +begin + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + # Get the command. + call sscan (cmdstr) + call gargwrd (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call sfree (sp) + return + } + + # Process the command. + ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, MISC) + switch (ncmd) { + case ACMD_SHOW: + call gargwrd (Memc[cmd], SZ_LINE) + ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, RPSHOWARGS) + switch (ncmd) { + case RCMD_CENTER: + call printf ("\n") + call ap_cpshow (ap) + call printf ("\n") + case RCMD_SKY: + call printf ("\n") + call ap_spshow (ap) + call printf ("\n") + case RCMD_PHOT: + call printf ("\n") + call ap_mpshow (ap) + call printf ("\n") + case RCMD_FIT: + call printf ("\n") + call ap_rppshow (ap) + call printf ("\n") + case RCMD_DATA: + call printf ("\n") + call ap_nshow (ap) + call printf ("\n") + default: + call printf ("\n") + call ap_rprofshow (ap) + call printf ("\n") + } + case ACMD_RADPLOTS: + call gargb (bval) + if (nscan() == 1) { + call printf ("%s = %b\n") + call pargstr (KY_RADPLOTS) + call pargb (itob (apstati (ap, RADPLOTS))) + } else + call apseti (ap, RADPLOTS, btoi (bval)) + default: + call printf ("Unknown or ambiguous colon command\7\n") + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/radprof/aprpfree.x b/noao/digiphot/apphot/radprof/aprpfree.x new file mode 100644 index 00000000..2f16e03a --- /dev/null +++ b/noao/digiphot/apphot/radprof/aprpfree.x @@ -0,0 +1,60 @@ +include "../lib/apphotdef.h" +include "../lib/radprofdef.h" + +# AP_RPFREE -- Procedure to free the radial profile fitting structure. + +procedure ap_rpfree (ap) + +pointer ap # pointer to the apphot structure + +begin + if (ap == NULL) + return + if (AP_NOISE(ap) != NULL) + call ap_noisecls (ap) + if (AP_PCENTER(ap) != NULL) + call ap_ctrcls (ap) + if (AP_PDISPLAY(ap) != NULL) + call ap_dispcls (ap) + if (AP_POLY(ap) != NULL) + call ap_ycls (ap) + if (AP_PPHOT(ap) != NULL) + call ap_photcls (ap) + if (AP_PPSF(ap) != NULL) + call ap_psfcls (ap) + if (AP_RPROF(ap) != NULL) + call ap_rpcls (ap) + if (AP_PSKY(ap) != NULL) + call ap_skycls (ap) + if (AP_IMBUF(ap) != NULL) + call mfree (AP_IMBUF(ap), TY_REAL) + if (AP_MW(ap) != NULL) + call mw_close (AP_MW(ap)) + call mfree (ap, TY_STRUCT) +end + + +# AP_RPCLS -- Procedure to closee up the radial profile fitting arrays. + +procedure ap_rpcls (ap) + +pointer ap # pointer to apphot structure + +pointer rprof + +begin + rprof = AP_RPROF(ap) + if (rprof == NULL) + return + #if (AP_RPIX(rprof) != NULL) + #call mfree (AP_RPIX(rprof), TY_REAL) + if (AP_RPDIST(rprof) != NULL) + call mfree (AP_RPDIST(rprof), TY_REAL) + if (AP_INTENSITY(rprof) != NULL) + call mfree (AP_INTENSITY(rprof), TY_REAL) + if (AP_DINTENSITY(rprof) != NULL) + call mfree (AP_DINTENSITY(rprof), TY_REAL) + if (AP_TINTENSITY(rprof) != NULL) + call mfree (AP_TINTENSITY(rprof), TY_REAL) + call mfree (rprof, TY_STRUCT) +end diff --git a/noao/digiphot/apphot/radprof/aprpindef.x b/noao/digiphot/apphot/radprof/aprpindef.x new file mode 100644 index 00000000..4d92d615 --- /dev/null +++ b/noao/digiphot/apphot/radprof/aprpindef.x @@ -0,0 +1,69 @@ +include "../lib/apphotdef.h" +include "../lib/radprofdef.h" +include "../lib/photdef.h" +include "../lib/phot.h" +include "../lib/radprof.h" + +# AP_RPINDEF -- Routine to return INDEF valued photometry and radial profile +# buffers. + +procedure ap_rpindef (ap) + +pointer ap # pointer to the apphot structure + +pointer phot, rprof + +begin + phot = AP_PPHOT(ap) + rprof = AP_RPROF(ap) + + AP_RPFWHM(rprof) = INDEFR + AP_INORM(rprof) = INDEFR + AP_TINORM(rprof) = INDEFR + + call amovkr (INDEFR, Memr[AP_INTENSITY(rprof)], AP_RPNPTS(rprof)) + call amovkr (INDEFR, Memr[AP_TINTENSITY(rprof)], AP_RPNPTS(rprof)) + call amovkd (0.0d0, Memd[AP_AREA(phot)], AP_NAPERTS(phot)) + call amovkd (0.0d0, Memd[AP_SUMS(phot)], AP_NAPERTS(phot)) + call amovkr (INDEFR, Memr[AP_MAGS(phot)], AP_NAPERTS(phot)) + call amovkr (INDEFR, Memr[AP_MAGERRS(phot)], AP_NAPERTS(phot)) +end + + +# AP_MAXAP -- Procedure to setup the maximum number of apertures for phot. + +procedure ap_maxap (ap, pier) + +pointer ap # pointer to the apphot structure +int pier # photometric error + +int i +pointer phot, rprof +real dxc1, dxc2, dyc1, dyc2, rdist, rapert + +begin + phot = AP_PPHOT(ap) + rprof = AP_RPROF(ap) + + dxc1 = AP_RPXC(rprof) - 0.5 + dxc2 = AP_RPNX(rprof) - AP_RPXC(rprof) + 0.5 + dyc1 = AP_RPYC(rprof) - 0.5 + dyc2 = AP_RPNY(rprof) - AP_RPYC(rprof) + 0.5 + + # Compute the maximum aperture. + AP_NMAXAP(phot) = 0 + rdist = min (abs (dxc1), abs (dxc2), abs (dyc1), abs (dyc2)) + do i = 1, AP_NAPERTS(phot) { + rapert = AP_SCALE(ap) * Memr[AP_APERTS(phot)+i-1] + if (rapert <= rdist) { + AP_NMAXAP(phot) = i + } else { + break + } + } + + if (AP_NMAXAP(phot) < AP_NAPERTS(phot)) + pier = AP_APERT_OUTOFBOUNDS + else + pier = AP_OK +end diff --git a/noao/digiphot/apphot/radprof/aprpinit.x b/noao/digiphot/apphot/radprof/aprpinit.x new file mode 100644 index 00000000..49bea62c --- /dev/null +++ b/noao/digiphot/apphot/radprof/aprpinit.x @@ -0,0 +1,77 @@ +include "../lib/apphotdef.h" +include "../lib/radprofdef.h" +include "../lib/phot.h" + +# AP_RPINIT - Procedure to initialize the radial profile fitting structure. + +procedure ap_rpinit (ap, cfunction, cbox, sfunction, annulus, dannulus, + aperts, napert, radius, step, fwhmpsf, noise) + +pointer ap # pointer to the apphot structure +int cfunction # centering algorithm +real cbox # half width of the centering box +int sfunction # sky fitting algorithm +real annulus # radius of sky annulus +real dannulus # width of sky annulus +real aperts[ARB] # array of apertures +int napert # number of apertures +real radius # radius of fitting region +real step # step size of output +real fwhmpsf # FWHM of the PSF +int noise # Noise model + +begin + # Set the image dependent parameters. + call malloc (ap, LEN_APSTRUCT, TY_STRUCT) + + # Set up the global apphot package defaults. + call ap_defsetup (ap, fwhmpsf) + + # Set up the noise model parameters. + call ap_noisesetup (ap, noise) + + # Set up the centering algorithm parameters. + call ap_ctrsetup (ap, cfunction, cbox) + + # Set up the sky fitting parameters. + call ap_skysetup (ap, sfunction, annulus, dannulus) + + # Set up the photometry parameters. + call ap_photsetup (ap, aperts, napert, AP_PWCONSTANT) + + # Set up the radial profile fitting parameters. + call ap_rpsetup (ap, radius, step) + + # Set up the display options. + call ap_dispsetup (ap) + + # Set psf fitting and polyphot structures to null. + AP_PPSF(ap) = NULL + AP_POLY(ap) = NULL +end + + +# AP_RPSETUP -- Procedure to set up the radial profle fitting parameters. + +procedure ap_rpsetup (ap, radius, step) + +pointer ap # pointer to apphot structure +real radius # radius of psf to be fit +real step # step size + +pointer rprof + +begin + call malloc (AP_RPROF(ap), LEN_RPSTRUCT, TY_STRUCT) + rprof = AP_RPROF(ap) + AP_RPXCUR(rprof) = INDEFR + AP_RPYCUR(rprof) = INDEFR + AP_RPRADIUS(rprof) = radius + AP_RPSTEP(rprof) = step + AP_RPIX(rprof) = NULL + AP_RPNPTS(rprof) = int (AP_RPRADIUS(rprof) / AP_RPSTEP(rprof)) + 1 + call malloc (AP_RPDIST(rprof), AP_RPNPTS(rprof), TY_REAL) + call malloc (AP_INTENSITY(rprof), AP_RPNPTS(rprof), TY_REAL) + call malloc (AP_DINTENSITY(rprof), AP_RPNPTS(rprof), TY_REAL) + call malloc (AP_TINTENSITY(rprof), AP_RPNPTS(rprof), TY_REAL) +end diff --git a/noao/digiphot/apphot/radprof/aprpplot.x b/noao/digiphot/apphot/radprof/aprpplot.x new file mode 100644 index 00000000..dee441f1 --- /dev/null +++ b/noao/digiphot/apphot/radprof/aprpplot.x @@ -0,0 +1,307 @@ +include <gset.h> +include <pkg/gtools.h> +include "../lib/apphotdef.h" +include "../lib/apphot.h" +include "../lib/center.h" +include "../lib/fitsky.h" +include "../lib/photdef.h" +include "../lib/phot.h" +include "../lib/radprofdef.h" +include "../lib/radprof.h" + +define IMIN -0.1 # Minimum intensity value for plot +define IMAX 1.1 # Maximum intensity value for plot + +# AP_RPPLOT -- Procedure to plot the radial profile. + +procedure ap_rpplot (ap, sid, gd, makeplots) + +pointer ap # pointer to the apphot structure +int sid # output file id number (not used) +pointer gd # pointer to the plot stream +int makeplots # make plots on the screen ? + +int nxpts, nypts, nrpts +pointer rprof, gt +real rmin, rmax, inorm, x1, x2, y1, y2, u1, u2, v1, v2 +int apstati() +pointer ap_gtinit() +real apstatr() + +begin + # Return if no graphics stream. + if (gd == NULL || makeplots == NO) + return + + # Return if the center or sky is undefined. + if (IS_INDEFR(apstatr (ap, XCENTER)) || IS_INDEFR(apstatr (ap, + YCENTER)) || IS_INDEFR (apstatr (ap, SKY_MODE))) + return + + # Return if there are no pixels. + rprof = AP_RPROF(ap) + if (AP_RPIX(rprof) == NULL) + return + + # Set up some useful constants. + rmin = 0.0 + rmax = apstatr (ap, SCALE) * apstatr (ap, RPRADIUS) + nxpts = AP_RPNX(rprof) + nypts = AP_RPNY(rprof) + nrpts = apstati (ap, RPNPTS) + inorm = apstatr (ap, INORM) + + # Reopen the work station. + call greactivate (gd, 0) + + # Save old viewport and coordinates. + call ggwind (gd, x1, x2, y1, y2) + call ggview (gd, u1, u2, v1, v2) + + # Set up the labels and annotate the plot. + gt = ap_gtinit (AP_IMROOT(ap), apstatr (ap, OXINIT), apstatr (ap, + OYINIT)) + call gclear (gd) + call ap_rpset (gd, gt, ap, rmin, rmax, IMIN, IMAX) + call ap_rpannotate (gd, ap, rmin, rmax, IMIN, IMAX) + + # Plot the intensity and total intensity. + call ap_plothist (gd, gt, Memr[AP_RPDIST(rprof)], + Memr[AP_INTENSITY(rprof)], nrpts, "line", GL_SOLID) + call ap_plothist (gd, gt, Memr[AP_RPDIST(rprof)], + Memr[AP_TINTENSITY(rprof)], nrpts, "line", GL_DOTDASH) + + # Plot the points. + call gswind (gd, rmin, rmax, (IMIN * inorm), (IMAX * inorm)) + call rp_ptsplot (gd, gt, Memr[AP_RPIX(rprof)], nxpts, nypts, + AP_RPXC(rprof), AP_RPYC(rprof)) + + # Restore old viewport and world coordinates. + call gsview (gd, u1, u2, v1, v2) + call gswind (gd, x1, x2, y1, y2) + + call ap_gtfree (gt) + call gdeactivate (gd, 0) +end + + +# AP_RPSET -- Procedure to set up the parameters for the radial profile +# plot. + +procedure ap_rpset (gd, gt, ap, xmin, xmax, ymin, ymax) + +pointer gd # graphics stream +pointer gt # gtools pointer +pointer ap # apphot pointer +real xmin, xmax # minimum and maximum radial distance +real ymin, ymax # minimum and maximum of the y axis + +int fd, naperts +pointer sp, str, tstr, temp +real scale, aspect, vx1, vx2, vy1, vy2 +int stropen(), apstati() +real apstatr(), gstatr() + +begin + call smark (sp) + call salloc (str, 6 * SZ_LINE, TY_CHAR) + call salloc (tstr, SZ_LINE, TY_CHAR) + naperts = apstati (ap, NAPERTS) + call salloc (temp, naperts, TY_REAL) + + # Open the title string. + fd = stropen (Memc[str], 6 * SZ_LINE, WRITE_ONLY) + + # Encode the sysid. + call sysid (Memc[tstr], SZ_LINE) + call fprintf (fd, "%s\n") + call pargstr (Memc[tstr]) + + # Encode the center string + call fprintf (fd, + "Center: xc=%0.2f yc=%0.2f xerr=%0.2f yerr=%0.2f\n") + call pargr (apstatr (ap, OXCENTER)) + call pargr (apstatr (ap, OYCENTER)) + call pargr (apstatr (ap, XERR)) + call pargr (apstatr (ap, YERR)) + + # Encode the sky string + call fprintf (fd, + "Sky: value=%0.2f sigma=%0.2f skew=%0.2f nsky=%d nreject=%d\n") + call pargr (apstatr (ap, SKY_MODE)) + call pargr (apstatr (ap, SKY_SIGMA)) + call pargr (apstatr (ap, SKY_SKEW)) + call pargi (apstati (ap, NSKY)) + call pargi (apstati (ap, NSKY_REJECT)) + + # Encode the value of the magnitude at the maximum aperture. + call fprintf (fd, "Photometry: fwhmpsf=%0.3f maxapert=") + call pargr (apstatr (ap, RPFWHM)) + call ap_arrayr (ap, APERTS, Memr[temp]) + call amulkr (Memr[temp], apstatr (ap, SCALE), Memr[temp], naperts) + call fprintf (fd, "%0.2f mags=") + call pargr (Memr[temp+naperts-1]) + call ap_arrayr (ap, MAGS, Memr[temp]) + call fprintf (fd, "%0.3f\n") + call pargr (Memr[temp+naperts-1]) + + # Encode the parameter string. + call fprintf (fd, + "Fit: spline3 order=%d krej=%0.1f sigma np=%d nprej=%d\n") + call pargi (apstati (ap, RPORDER)) + call pargr (apstatr (ap, RPKSIGMA)) + call pargi (apstati (ap, RPNDATA)) + call pargi (apstati (ap, RPNDATAREJ)) + + # Encode the title. + call gt_gets (gt, GTTITLE, Memc[tstr], SZ_LINE) + call fprintf (fd, "%s\n\n") + call pargstr (Memc[tstr]) + + call strclose (fd) + + aspect = gstatr (gd, G_ASPECT) + scale = apstatr (ap, SCALE) + call gsetr (gd, G_ASPECT, 0.70) + call gseti (gd, G_WCS, 2) + + # Draw and label the axes. + call gseti (gd, G_XDRAWAXES, 2) + call gswind (gd, xmin / scale, xmax / scale, ymin, ymax) + call glabax (gd, Memc[str], "", "Intensity") + call gseti (gd, G_YDRAWAXES, 0) + call gseti (gd, G_XDRAWAXES, 1) + call ggview (gd, vx1, vx2, vy1, vy2) + call gsview (gd, vx1, vx2, vy1, vy2) + call gswind (gd, xmin, xmax, ymin, ymax) + call glabax (gd, "", + "Radial Distance (lower-pixels, upper-scale units)", "") + + # Reset the axes parameters. + call gseti (gd, G_YDRAWAXES, 3) + call gseti (gd, G_XDRAWAXES, 3) + call gsetr (gd, G_ASPECT, aspect) + + # Set the plot type. + call gt_sets (gt, GTTYPE, "line") + + call sfree (sp) +end + + +# AP_RPANNOTATE -- Procedure to annotate the radial plot in radprof. + +procedure ap_rpannotate (gd, ap, xmin, xmax, ymin, ymax) + +pointer gd # graphics stream +pointer ap # apphot structure +real xmin, xmax # min and max of x axis +real ymin, ymax # min and max of y axis + +int naperts +pointer sp, str, temp +real scale, rpfwhm, annulus, dannulus, inorm, tinorm +int apstati() +real apstatr() + +begin + # Allocate working space. + naperts = apstati (ap, NAPERTS) + call smark (sp) + call salloc (str, SZ_LINE, TY_CHAR) + call salloc (temp, naperts, TY_REAL) + call gseti (gd, G_PLTYPE, GL_DASHED) + + # Draw the zero level line. + call gamove (gd, xmin, 0.0) + call gadraw (gd, xmax, 0.0) + + # Draw the half power point. + call gamove (gd, xmin, 0.5) + call gadraw (gd, xmax, 0.5) + + # Draw the unit normalization value. + call gamove (gd, xmin, 1.0) + call gadraw (gd, xmax, 1.0) + + # Plot the full width half maximum of the radial profile. + scale = apstatr (ap, SCALE) + rpfwhm = apstatr (ap, RPFWHM) / 2.0 + if (rpfwhm >= xmin && rpfwhm <= xmax) { + call gamove (gd, rpfwhm, ymin) + call gadraw (gd, rpfwhm, ymax) + call sprintf (Memc[str], SZ_LINE, "hwhm = %0.2f") + call pargr (rpfwhm) + call gtext (gd, rpfwhm, 0.0, Memc[str], "q=h;u=180;p=r") + } + + # Mark the sky annuli. + annulus = scale * apstatr (ap, ANNULUS) + dannulus = scale * (apstatr (ap, ANNULUS) + apstatr (ap, DANNULUS)) + if (annulus >= xmin && annulus <= xmax) { + call gamove (gd, annulus, ymin) + call gadraw (gd, annulus, ymax) + call sprintf (Memc[str], SZ_LINE, "inner sky radius = %0.2f") + call pargr (annulus) + call gtext (gd, annulus, 0.0, Memc[str], "q=h;u=180;p=r") + } + if (dannulus >= xmin && dannulus <= xmax) { + call gamove (gd, dannulus, ymin) + call gadraw (gd, dannulus, ymax) + call sprintf (Memc[str], SZ_LINE, "outer sky radius = %0.2f") + call pargr (dannulus) + call gtext (gd, dannulus, 0.0, Memc[str], "q=h;u=180;p=r") + } + + # Plot the aperture value. + call ap_arrayr (ap, APERTS, Memr[temp]) + call amulkr (Memr[temp], scale, Memr[temp], naperts) + call gseti (gd, G_PLTYPE, GL_SOLID) + if (Memr[temp+naperts-1] >= xmin && Memr[temp+naperts-1] <= xmax) { + call gamove (gd, Memr[temp+naperts-1], ymin) + call gadraw (gd, Memr[temp+naperts-1], ymax) + call sprintf (Memc[str], SZ_LINE, "maxapert = %0.2f") + call pargr (Memr[temp+naperts-1]) + call gtext (gd, Memr[temp+naperts-1], 0.0, Memc[str], + "q=h;u=180;p=r") + } + call gseti (gd, G_PLTYPE, GL_DASHED) + + # Plot the inorm value. + inorm = apstatr (ap, INORM) + call sprintf (Memc[str], SZ_LINE, "inorm = %0.2f") + call pargr (inorm) + call gtext (gd, 0.0, 1.0, Memc[str], "q=h") + + # Plot the tinorm value. + tinorm = apstatr (ap, TNORM) + call sprintf (Memc[str], SZ_LINE, "tinorm = %0.2f") + call pargr (tinorm) + call gtext (gd, xmax, 1.0, Memc[str], "q=h;h=r") + + call sfree (sp) +end + + +# RP_PTSPLOT -- Plot the radial profile plots. + +procedure rp_ptsplot (gd, gt, pixels, nx, ny, wx, wy) + +pointer gd # pointer to the graphics stream +pointer gt # pointer to the gtools structure +real pixels[nx,ARB] # subraster of pixel values +int nx, ny # dimensions of the pixel subraster +real wx, wy # x and y coordinates of the center + +int i +pointer sp, rtemp + +begin + call smark (sp) + call salloc (rtemp, nx, TY_REAL) + do i = 1, ny { + call ap_ijtor (Memr[rtemp], nx, i, wx, wy) + call ap_plotrad (gd, gt, Memr[rtemp], pixels[1,i], nx, "plus") + } + call sfree (sp) +end diff --git a/noao/digiphot/apphot/radprof/iradprof.key b/noao/digiphot/apphot/radprof/iradprof.key new file mode 100644 index 00000000..1c5a8974 --- /dev/null +++ b/noao/digiphot/apphot/radprof/iradprof.key @@ -0,0 +1,20 @@ + Interactive Radprof Setup Menu + + v Mark and verify the critical parameters (f,c,s,a,d,r,w,x) + + f Mark and verify the psf full-width half-maximum + s Mark and verify the standard deviation of the background + l Mark and verify the minimum good data value + u Mark and verify the maximum good data value + + c Mark and verify the centering box width + n Mark and verify the cleaning radius + p Mark and verify the clipping radius + + a Mark and verify the inner radius of the sky annulus + d Mark and verify the width of the sky annulus + g Mark and verify the region growing radius + + r Mark and verify the photometry aperture radii + w Mark and verify the radius of the radial profile + x Mark and verify the step size of radial profile diff --git a/noao/digiphot/apphot/radprof/mkpkg b/noao/digiphot/apphot/radprof/mkpkg new file mode 100644 index 00000000..8ef786bc --- /dev/null +++ b/noao/digiphot/apphot/radprof/mkpkg @@ -0,0 +1,58 @@ +RADPROF Fitting Task Routines + +$checkout libpkg.a ".." +$update libpkg.a +$checkin libpkg.a ".." +$exit + +libpkg.a: + apbradprof.x <fset.h> ../lib/apphot.h \ + ../lib/center.h ../lib/fitsky.h \ + ../lib/display.h + apgrpars.x ../lib/center.h ../lib/fitsky.h \ + ../lib/phot.h ../lib/display.h \ + ../lib/noise.h ../lib/radprof.h + approfsetup.x ../lib/center.h ../lib/fitsky.h \ + ../lib/display.h + apprprof.x ../lib/apphotdef.h ../lib/apphot.h \ + ../lib/center.h ../lib/fitsky.h \ + ../lib/photdef.h ../lib/phot.h \ + ../lib/radprof.h + apradprof.x <ctype.h> <gset.h> \ + ../lib/apphot.h ../lib/center.h \ + ../lib/fitsky.h ../lib/radprof.h \ + ../lib/display.h <imhdr.h> + aprconfirm.x ../lib/apphot.h ../lib/noise.h \ + ../lib/center.h ../lib/fitsky.h \ + ../lib/phot.h ../lib/radprof.h + aprferrors.x ../lib/phot.h ../lib/radprof.h + aprmmeasure.x <math/curfit.h> + aprpars.x ../lib/radprof.h ../lib/display.h + aprpbuf.x <imhdr.h> ../lib/apphotdef.h \ + ../lib/radprofdef.h ../lib/radprof.h + aprpcolon.x ../lib/apphot.h ../lib/fitsky.h \ + ../lib/center.h ../lib/phot.h \ + ../lib/radprof.h ../lib/noise.h \ + ../lib/display.h + aprpfree.x ../lib/apphotdef.h ../lib/radprofdef.h + aprpindef.x ../lib/apphotdef.h ../lib/radprofdef.h \ + ../lib/radprof.h ../lib/photdef.h \ + ../lib/phot.h + aprpinit.x ../lib/apphotdef.h ../lib/radprofdef.h \ + ../lib/phot.h + aprpplot.x <gset.h> <pkg/gtools.h> \ + ../lib/apphotdef.h ../lib/photdef.h \ + ../lib/radprof.h ../lib/phot.h \ + ../lib/fitsky.h ../lib/radprofdef.h \ + ../lib/center.h ../lib/apphot.h + apfrprof.x <math/curfit.h> <math/iminterp.h> \ + <gset.h> ../lib/fitskydef.h \ + ../lib/apphotdef.h ../lib/radprofdef.h \ + ../lib/phot.h ../lib/photdef.h \ + ../lib/radprof.h <math.h> \ + <mach.h> "../lib/noisedef.h" \ + ../lib/apphot.h + rprofshow.x ../lib/display.h ../lib/radprof.h + t_radprof.x <fset.h> <gset.h> \ + ../lib/apphot.h <imhdr.h> + ; diff --git a/noao/digiphot/apphot/radprof/radprof.key b/noao/digiphot/apphot/radprof/radprof.key new file mode 100644 index 00000000..4204743f --- /dev/null +++ b/noao/digiphot/apphot/radprof/radprof.key @@ -0,0 +1,116 @@ + Interactive Keystroke Commands + +? Print help +: Colon commands +v Verify the critical parameters +w Store the current parameters +d Plot radial profile of current star +i Interactively set parameters using current star +c Fit center of current star +t Fit sky around cursor +a Average sky values fit around several cursor positions +s Fit sky around the current star +p Fit star using current sky +o Fit star using current sky, output results +f Fit current star +spbar Fit current star, output results +m Move to next star in coordinate list +n Fit next star in coordinate list, output results +l Fit remaining stars in coordinate list, output results +r Rewind the coordinate list +e Print error messages +q Exit task + + + Colon Commands + +:show [data/center/sky/fit] List the parameters +:m [n] Move to next [nth] object in coordinate list +:n [n] Fit next [nth] object in coordinate list, output results + + + Colon Parameter Editing Commands + +# Image and file name parameters + +:image [string] Image name +:coords [string] Coordinate file name +:output [string] Output file name + +# Data dependent parameters + +:scale [vlaue] Image scale (units per pixel) +:fwhmpsf [value] Full-width half-maximum of psf (scale units) +:emission [y/n] Emission features (y), absorption (n) +:sigma [value] Standard deviation of sky (counts) +:datamin [value] Minimum good pixel value (counts) +:datamax [value] Maximum good pixel value (counts) + +# Noise parameters + +:noise [string] Noise model (constant|poisson) +:gain [string] Gain image header keyword +:ccdread [string] Readout noise image header keyword +:epadu [value] Gain (electrons per adu) +:readnoise [value] Readout noise (electrons) + +# Observing parameters + +:exposure [value] Exposure time image header keyword +:airmass [string] Airmass image header keyword +:filter [string] Filter image header keyword +:obstime [string] Time of observation image header keyword +:itime [value] Integration time (time units) +:xairmass [value] Airmass value (number) +:ifilter [string] Filter id string +:otime [string] Time of observation (time units) + +# Centering algorithm parameters + +:calgorithm [string] Centering algorithm +:cbox [value] Width of the centering box (scale units) +:cthreshold [value] Centering intensity threshold (sigma) +:cmaxiter [value] Maximum number of iterations +:maxshift [value] Maximum center shift (scale units) +:minsnratio [value] Minimum S/N ratio for centering +:clean [y/n] Clean subraster before centering +:rclean [value] Cleaning radius (scale units) +:rclip [value] Clipping radius (scale units) +:kclean [value] Clean K-sigma rejection limit (sigma) + +# Sky fitting algorithm parameters + +:salgorithm [string] Sky fitting algorithm +:skyvalue [value] User supplied sky value (counts) +:annulus [value] Inner radius of sky annulus (scale units) +:dannulus [value] Width of sky annulus (scale units) +:khist [value] Sky histogram extent (+/- sigma) +:binsize [value] Resolution of sky histogram (sigma) +:sloclip [value] Low-side clipping factor in percent +:shiclip [value] High-side clipping factor in percent +:smaxiter [value] Maximum number of iterations +:smooth [y/n] Lucy smooth the sky histogram +:snreject [value] Maximum number of rejection cycles +:sloreject [value] Low-side pixel rejection limits (sky sigma) +:shireject [value] High-side pixel rejection limits (sky sigma) +:rgrow [value] Region growing radius (scale units) + +# Photometry parameters + +:apertures [string] List of apertures (scale units) +:zmag [value] Zero point of magnitude scale + +# Profile fitting parameters + +:radius [value] Maximum profile radius (scale units) +:step [value] Step size for computed profile (scale units) +:order [value] Number of spline pieces in fit +:kreject [value] K-sigma rejection for fit (fit sigma) +:nreject [value] Maximum number of rejection cycles + +# Marking and plotting parameters + +:mkcenter [y/n] Mark computed centers on display +:mksky [y/n] Mark the sky annuli on the display +:mkapert [y/n] Mark apertures on the display +:radplot [y/n] Plot the radial profile diff --git a/noao/digiphot/apphot/radprof/rprofshow.x b/noao/digiphot/apphot/radprof/rprofshow.x new file mode 100644 index 00000000..c4264ede --- /dev/null +++ b/noao/digiphot/apphot/radprof/rprofshow.x @@ -0,0 +1,75 @@ +include "../lib/display.h" +include "../lib/radprof.h" + +# AP_RPROFSHOW -- Procedure to display all the radprof parameters. + +procedure ap_rprofshow (ap) + +pointer ap # pointer to the apphot strucuture + +bool itob() +int apstati() + +begin + call ap_nshow (ap) + call printf ("\n") + call ap_cpshow (ap) + call printf ("\n") + call ap_spshow (ap) + call printf ("\n") + call ap_mpshow (ap) + call printf ("\n") + call ap_rppshow (ap) + call printf (" %s = %b\n") + call pargstr (KY_RADPLOTS) + call pargb (itob (apstati (ap, RADPLOTS))) +end + + +# AP_RPSHOW -- Procedure to display radprof parameters. + +procedure ap_rpshow (ap) + +pointer ap # pointer to apphot structure + +bool itob() +int apstati() + +begin + call ap_nshow (ap) + call ap_rppshow (ap) + call printf (" %s = %b\n") + call pargstr (KY_RADPLOTS) + call pargb (itob (apstati (ap, RADPLOTS))) +end + + +# AP_RPPSHOW -- Procedure to display radprof parameters. + +procedure ap_rppshow (ap) + +pointer ap # pointer to apphot structure + +int apstati() +real apstatr() + +begin + # Print the radial profile characteristics. + call printf ("Radial Profile Fitting Parameters\n") + call printf (" %s = %g %s %s = %g %s\n") + call pargstr (KY_RPRADIUS) + call pargr (apstatr (ap, RPRADIUS)) + call pargstr (UN_RSCALEUNIT) + call pargstr (KY_RPSTEP) + call pargr (apstatr (ap, RPSTEP)) + call pargstr (UN_RSCALEUNIT) + + call printf (" %s = %d %s = %g %s %s = %d\n") + call pargstr (KY_RPORDER) + call pargi (apstati (ap, RPORDER)) + call pargstr (KY_RPKSIGMA) + call pargr (apstatr (ap, RPKSIGMA)) + call pargstr (UN_RSIGMA) + call pargstr (KY_RPNREJECT) + call pargi (apstati (ap, RPNREJECT)) +end diff --git a/noao/digiphot/apphot/radprof/t_radprof.x b/noao/digiphot/apphot/radprof/t_radprof.x new file mode 100644 index 00000000..fda4c459 --- /dev/null +++ b/noao/digiphot/apphot/radprof/t_radprof.x @@ -0,0 +1,306 @@ +include <fset.h> +include <gset.h> +include <imhdr.h> +include "../lib/apphot.h" + +# T_RADPROF -- Procedure to compute the radial profiles of a list of +# objects. + +procedure t_radprof () + +pointer image # pointer to the name of the image +pointer output # pointer to the output file name +pointer coords # pointer to the coordinate file +pointer plotfile # pointer to the metacode plot file +pointer graphics # pointer to the graphics device +pointer display # pointer to the display device +int interactive # interactive mode +int cache # cache the input image +int verify # verify the critical parameters +int update # update the critical parameters +int verbose # verbose mode + +pointer sp, cname, outfname, ap, im, id, gd, mgd, str +int limlist, lclist, lolist, sid, lid, cl, out, pfd, root, stat +int imlist, clist, olist, wcs, memstat, req_size, old_size, buf_size + +pointer immap(), gopen() +int imtlen(), imtgetim(), clplen(), clgfil(), btoi(), fnldir(), strncmp() +int strlen(), ap_radprof(), imtopenp(), clpopnu(), open(), clgwrd() +int ap_memstat(), sizeof() +bool clgetb(), streq() +errchk gopen + +begin + # Allocate working space. + call smark (sp) + call salloc (image, SZ_FNAME, TY_CHAR) + call salloc (output, SZ_FNAME, TY_CHAR) + call salloc (coords, SZ_FNAME, TY_CHAR) + call salloc (plotfile, SZ_FNAME, TY_CHAR) + call salloc (graphics, SZ_FNAME, TY_CHAR) + call salloc (display, SZ_FNAME, TY_CHAR) + call salloc (outfname, SZ_FNAME, TY_CHAR) + call salloc (cname, SZ_FNAME, TY_CHAR) + call salloc (str, SZ_FNAME, TY_CHAR) + + # Set standard output to flush on newline. + call fseti (STDOUT, F_FLUSHNL, YES) + + # Get input and output file names. + imlist = imtopenp ("image") + limlist = imtlen (imlist) + clist = clpopnu ("coords") + lclist = clplen (clist) + olist = clpopnu ("output") + lolist = clplen (olist) + + # Check that the image and coordinate list lengths match. + if (limlist < 1 || (lclist > 1 && lclist != limlist)) { + call imtclose (imlist) + call clpcls (clist) + call clpcls (olist) + call error (0, "Imcompatible image and coordinate list lengths") + } + + # Check that image and output list lengths match. + if (lolist > 1 && lolist != limlist) { + call imtclose (imlist) + call clpcls (clist) + call clpcls (olist) + call error (0, "Imcompatible image and output list lengths") + } + + call clgstr ("icommands.p_filename", Memc[cname], SZ_FNAME) + if (Memc[cname] != EOS) + interactive = NO + #else if (lclist == 0) + #interactive = YES + else + interactive = btoi (clgetb ("interactive")) + cache = btoi (clgetb ("cache")) + verify = btoi (clgetb ("verify")) + update = btoi (clgetb ("update")) + verbose = btoi (clgetb ("verbose")) + + # Get the radial profile fitting parameters. + call ap_grppars (ap) + + # Verify the radial profile fitting parameters. + if (verify == YES && interactive == NO) { + call ap_rconfirm (ap, NULL, 1) + if (update == YES) + call ap_rpars (ap) + } + + # Get the wcs information. + wcs = clgwrd ("wcsin", Memc[str], SZ_LINE, WCSINSTR) + if (wcs <= 0) { + call eprintf ( + "Warning: Setting the input coordinate system to logical\n") + wcs = WCS_LOGICAL + } + call apseti (ap, WCSIN, wcs) + wcs = clgwrd ("wcsout", Memc[str], SZ_LINE, WCSOUTSTR) + if (wcs <= 0) { + call eprintf ( + "Warning: Setting the output coordinate system to logical\n") + wcs = WCS_LOGICAL + } + call apseti (ap, WCSOUT, wcs) + + # Get the graphics and display devices. + call clgstr ("graphics", Memc[graphics], SZ_FNAME) + call clgstr ("display", Memc[display], SZ_FNAME) + + # Open the plot files. + if (interactive == YES) { + if (Memc[graphics] == EOS) + gd = NULL + else { + iferr { + gd = gopen (Memc[graphics], APPEND+AW_DEFER, STDGRAPH) + } then { + call eprintf ( + "Warning: Error opening graphics device.\n") + gd = NULL + } + } + if (Memc[display] == EOS) + id = NULL + else if (streq (Memc[graphics], Memc[display])) + id = gd + else { + iferr { + id = gopen (Memc[display], APPEND, STDIMAGE) + } then { + call eprintf ( + "Warning: Graphics overlay not available for display device.\n") + id = NULL + } + } + } else { + gd = NULL + id = NULL + } + + # Open the plot metacode file. + call clgstr ("plotfile", Memc[plotfile], SZ_FNAME) + if (Memc[plotfile] == EOS) + pfd = NULL + else + pfd = open (Memc[plotfile], APPEND, BINARY_FILE) + if (pfd != NULL) + mgd = gopen (Memc[graphics], NEW_FILE, pfd) + else + mgd = NULL + + # Begin looping over the image list. + sid = 1 + while (imtgetim (imlist, Memc[image], SZ_FNAME) != EOF) { + + # Open the image. + im = immap (Memc[image], READ_ONLY, 0) + + # Set the image display viewport. + call apimkeys (ap, im, Memc[image]) + if ((id != NULL) && (id != gd)) + call ap_gswv (id, Memc[image], im, 4) + + # Cache the input image pixels. + req_size = MEMFUDGE * IM_LEN(im,1) * IM_LEN(im,2) * + sizeof (IM_PIXTYPE(im)) + memstat = ap_memstat (cache, req_size, old_size) + if (memstat == YES) + call ap_pcache (im, INDEFI, buf_size) + + # Open the coordinate file, where coords is assumed to be a simple + # text file in which the x and y positions are in columns 1 and 2 + # respectively and all remaining fields are ignored. + + if (lclist <= 0) { + cl = NULL + call strcpy ("", Memc[outfname], SZ_FNAME) + } else { + stat = clgfil (clist, Memc[coords], SZ_FNAME) + root = fnldir (Memc[coords], Memc[outfname], SZ_FNAME) + if (strncmp ("default", Memc[coords+root], 7) == 0 || root == + strlen (Memc[coords])) { + call ap_inname (Memc[image], Memc[outfname], "coo", + Memc[outfname], SZ_FNAME) + lclist = limlist + cl = open (Memc[outfname], READ_ONLY, TEXT_FILE) + } else if (stat != EOF) { + call strcpy (Memc[coords], Memc[outfname], SZ_FNAME) + cl = open (Memc[outfname], READ_ONLY, TEXT_FILE) + } else { + call apstats (ap, CLNAME, Memc[outfname], SZ_FNAME) + call seek (cl, BOF) + } + } + call apsets (ap, CLNAME, Memc[outfname]) + call apfroot (Memc[outfname], Memc[str], SZ_FNAME) + call apsets (ap, CLROOT, Memc[str]) + + # Open output text file, if output is "default", dir$default, + # or a directory specification then the extension "prf" is added + # to the image name and a suitable version number is appended to + # the output name. If the output name is null then no output + # file is created. + + if (lolist == 0) { + out = NULL + call strcpy ("", Memc[outfname], SZ_FNAME) + } else { + stat = clgfil (olist, Memc[output], SZ_FNAME) + root = fnldir (Memc[output], Memc[outfname], SZ_FNAME) + if (strncmp ("default", Memc[output+root], 7) == 0 || root == + strlen (Memc[output])) { + call apoutname (Memc[image], Memc[outfname], "prf", + Memc[outfname], SZ_FNAME) + out = open (Memc[outfname], NEW_FILE, TEXT_FILE) + lolist = limlist + } else if (stat != EOF) { + call strcpy (Memc[output], Memc[outfname], SZ_FNAME) + out = open (Memc[outfname], NEW_FILE, TEXT_FILE) + } else + call apstats (ap, OUTNAME, Memc[outfname], SZ_FNAME) + } + call apsets (ap, OUTNAME, Memc[outfname]) + + # Fit the radial profiles. + if (interactive == NO) { + if (Memc[cname] != EOS) + stat = ap_radprof (ap, im, cl, NULL, mgd, NULL, out, + sid, NO, cache) + else if (cl != NULL) { + lid = 1 + call ap_bradprof (ap, im, cl, id, gd, mgd, out, sid, lid, + verbose) + stat = NO + } else + stat = NO + } else + stat = ap_radprof (ap, im, cl, gd, mgd, id, out, sid, YES, + cache) + + # Cleanup. + call imunmap (im) + if (cl != NULL) { + if (lclist > 1) + call close (cl) + } + if (out != NULL && lolist != 1) { + call close (out) + if (sid <= 1) { + call apstats (ap, OUTNAME, Memc[outfname], SZ_FNAME) + call delete (Memc[outfname]) + } + sid = 1 + } + + # Uncache memory. + call fixmem (old_size) + + if (stat == YES) + break + + } + + # If only one coordinate file for a list of images close list. + if (cl != NULL && lclist == 1) + call close (cl) + + # If only one output file for a list of images close list. + if (out != NULL && lolist == 1) { + call close (out) + if (sid <= 1) { + call apstats (ap, OUTNAME, Memc[outfname], SZ_FNAME) + call delete (Memc[outfname]) + } + } + + # Close up plot files. + if (id == gd && id != NULL) + call gclose (id) + else { + if (gd != NULL) + call gclose (gd) + if (id != NULL) + call gclose (id) + } + if (mgd != NULL) + call gclose (mgd) + if (pfd != NULL) + call close (pfd) + + # Free the radial profile fitting structure. + call ap_rpfree (ap) + + # Close up the lists. + call imtclose (imlist) + call clpcls (clist) + call clpcls (olist) + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/temp b/noao/digiphot/apphot/temp new file mode 100644 index 00000000..afb44322 --- /dev/null +++ b/noao/digiphot/apphot/temp @@ -0,0 +1,8 @@ +-rw-rw-r-- 1 davis 8974 Sep 30 15:53 t_center.x +-rw-rw-r-- 1 davis 8366 Sep 30 15:53 t_fitpsf.x +-rw-rw-r-- 1 davis 8829 Sep 30 15:54 t_fitsky.x +-rw-rw-r-- 1 davis 9968 Sep 30 15:57 t_phot.x +-rw-rw-r-- 1 davis 8526 Sep 30 15:57 t_qphot.x +-rw-rw-r-- 1 davis 9430 Sep 30 15:55 t_polyphot.x +-rw-rw-r-- 1 davis 8936 Sep 30 15:58 t_radprof.x +-rw-rw-r-- 1 davis 9933 Sep 30 15:56 t_wphot.x diff --git a/noao/digiphot/apphot/test/README b/noao/digiphot/apphot/test/README new file mode 100644 index 00000000..006e6988 --- /dev/null +++ b/noao/digiphot/apphot/test/README @@ -0,0 +1,5 @@ +This subdirectory contains test data for the installer/maintainer of +the apphot package. The files beginning with fits contain test images +of both real and artificial data. There are also some coordinate files +supplied for these images. Eventually there will be some apphot demos +which can be run to automatically test new releases of the software etc. diff --git a/noao/digiphot/apphot/test/coords.dat b/noao/digiphot/apphot/test/coords.dat new file mode 100644 index 00000000..f6458223 --- /dev/null +++ b/noao/digiphot/apphot/test/coords.dat @@ -0,0 +1,10 @@ +36 22 1 \40 +26 22 1 \40 +36 42 1 \40 +31 25 1 \40 +29 34 1 \40 +18 8 1 \40 +21 26 1 \40 +23 7 1 \40 +8 23 1 \40 +41 4 1 \40 diff --git a/noao/digiphot/apphot/test/fits1.fits b/noao/digiphot/apphot/test/fits1.fits Binary files differnew file mode 100644 index 00000000..85105ec8 --- /dev/null +++ b/noao/digiphot/apphot/test/fits1.fits diff --git a/noao/digiphot/apphot/test/fits2.fits b/noao/digiphot/apphot/test/fits2.fits Binary files differnew file mode 100644 index 00000000..212a0c12 --- /dev/null +++ b/noao/digiphot/apphot/test/fits2.fits diff --git a/noao/digiphot/apphot/test/fits3.fits b/noao/digiphot/apphot/test/fits3.fits Binary files differnew file mode 100644 index 00000000..ff7938e7 --- /dev/null +++ b/noao/digiphot/apphot/test/fits3.fits diff --git a/noao/digiphot/apphot/test/fits4.fits b/noao/digiphot/apphot/test/fits4.fits Binary files differnew file mode 100644 index 00000000..5f9ca811 --- /dev/null +++ b/noao/digiphot/apphot/test/fits4.fits diff --git a/noao/digiphot/apphot/test/fits5.fits b/noao/digiphot/apphot/test/fits5.fits Binary files differnew file mode 100644 index 00000000..3542fe3e --- /dev/null +++ b/noao/digiphot/apphot/test/fits5.fits diff --git a/noao/digiphot/apphot/test/polygons.dat b/noao/digiphot/apphot/test/polygons.dat new file mode 100644 index 00000000..666b9df7 --- /dev/null +++ b/noao/digiphot/apphot/test/polygons.dat @@ -0,0 +1,6 @@ +36 22 1 \40 +26 22 1 \40 +36 42 1 \40 +31 25 1 \40 +29 34 1 \40 +; diff --git a/noao/digiphot/apphot/wphot.par b/noao/digiphot/apphot/wphot.par new file mode 100644 index 00000000..126d52ce --- /dev/null +++ b/noao/digiphot/apphot/wphot.par @@ -0,0 +1,24 @@ +# WPHOT parameters + +image,f,a,,,,"The input image(s)" +skyfile,f,a,"",,,"The input sky file(s)" +coords,f,h,"",,,"The input coordinate file(s) (default: image.coo.?)" +output,f,h,"default",,,The output photometry file(s) (default: image.omag.?)" +plotfile,f,h,"",,,"The output plot metacode file" +datapars,pset,h,"",,,"Data dependent parameters" +centerpars,pset,h,"",,,"Centering parameters" +fitskypars,pset,h,"",,,"Sky fitting parameters" +photpars,pset,h,,,,"Photometry parameters" +interactive,b,h,yes,,,"Interactive mode ?" +radplots,b,h,no,,,"Plot radial profiles in interactive mode ?" +icommands,*imcur,h,"",,,"Image cursor: [x y wcs] key [cmd]" +gcommands,*gcur,h,"",,,"Graphics cursor: [x y wcs] key [cmd]" +wcsin,s,h,)_.wcsin,,,"The input coordinate system (logical,tv,physical,world)" +wcsout,s,h,)_.wcsout,,,"The output coordinate system (logical,tv,physical)" +cache,b,h,)_.cache,,,"Cache the input image pixels ?" +verify,b,h,)_.verify,,,"Confirm critical parameters in non-interactive mode ?" +update,b,h,)_.update,,,"Update critical parameters in non-interactive mode ?" +verbose,b,h,)_.verbose,,,"Print messages in non-interactive mode ?" +graphics,s,h,)_.graphics,,,"Graphics device" +display,s,h,)_.display,,,"Display device" +mode,s,h,'ql' diff --git a/noao/digiphot/apphot/wphot/apbwphot.x b/noao/digiphot/apphot/wphot/apbwphot.x new file mode 100644 index 00000000..b684abb7 --- /dev/null +++ b/noao/digiphot/apphot/wphot/apbwphot.x @@ -0,0 +1,108 @@ +include <fset.h> +include "../lib/apphot.h" +include "../lib/display.h" +include "../lib/center.h" +include "../lib/fitsky.h" + +# AP_BWPHOT -- Procedure to compute the magnitudes for a list of objects +# interactively. + +procedure ap_bwphot (ap, im, cl, sd, out, id, ld, gd, mgd, gid, interactive) + +pointer ap # pointer to apphot structure +pointer im # pointer to IRAF image +int cl # starlist file descriptor +int sd # sky file descriptor +int out # output file descriptor +int id, ld # sequence and list numbers +pointer gd # pointer to stdgraph stream +pointer mgd # pointer to the plot metacode stream +pointer gid # pointer to image display stream +int interactive # interactive pr batch mode + +int stdin, ild, cier, sier, pier +pointer sp, str +real wx, wy +int fscan(), nscan(), apfitsky(), apfitcenter(), ap_wmag(), strncmp() +int apstati() +real apstatr() + +begin + call smark (sp) + call salloc (str, SZ_FNAME, TY_CHAR) + call fstats (cl, F_FILENAME, Memc[str], SZ_FNAME) + + # Initialize + ild = ld + + # Print query. + if (strncmp ("STDIN", Memc[str], 5) == 0) + stdin = YES + else + stdin = NO + if (stdin == YES) { + call printf ("Type object x and y coordinates (^D or ^Z to end): ") + call flush (STDOUT) + } + + # Loop over the coordinate file. + while (fscan (cl) != EOF) { + + # Get and store the coordinates. + call gargr (wx) + call gargr (wy) + if (nscan () != 2) { + if (stdin == YES) { + call printf ( + "Type object x and y coordinates (^D or ^Z to end): ") + call flush (STDOUT) + } + next + } + + # Transform the input coordinates. + switch (apstati(ap,WCSIN)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_itol (ap, wx, wy, wx, wy, 1) + case WCS_TV: + call ap_vtol (im, wx, wy, wx, wy, 1) + default: + ; + } + call apsetr (ap, CWX, wx) + call apsetr (ap, CWY, wy) + + # Center the coordinatess, fit the sky and compute magnitudes. + cier = apfitcenter (ap, im, wx, wy) + sier = apfitsky (ap, im, apstatr (ap, XCENTER), apstatr (ap, + YCENTER), sd, gd) + pier = ap_wmag (ap, im, apstatr (ap, XCENTER), apstatr(ap, YCENTER), + apstati (ap, POSITIVE), apstatr (ap, SKY_MODE), + apstatr (ap, SKY_SIGMA), apstati (ap, NSKY)) + + # Write the results. + if (interactive == YES) { + call ap_qpmag (ap, cier, sier, pier) + if (gid != NULL) + call apmark (ap, gid, apstati (ap, MKCENTER), apstati (ap, + MKSKY), apstati (ap, MKAPERT)) + } + if (id == 1) + call ap_param (ap, out, "wphot") + call ap_pmag (ap, out, id, ild, cier, sier, pier) + call ap_pplot (ap, im, id, mgd, YES) + + # Prepare for the next object. + id = id + 1 + ild = ild + 1 + call apsetr (ap, WX, wx) + call apsetr (ap, WY, wy) + if (stdin == YES) { + call printf ( + "Type object x and y coordinates (^Z or ^D to end): ") + call flush (STDOUT) + } + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/wphot/apgmeasure.x b/noao/digiphot/apphot/wphot/apgmeasure.x new file mode 100644 index 00000000..738630f2 --- /dev/null +++ b/noao/digiphot/apphot/wphot/apgmeasure.x @@ -0,0 +1,190 @@ +# AP_GMEASURE -- Procedure to measure the fluxes and effective areas of a set of +# apertures assuming a Gaussian weighting function. + +procedure ap_gmeasure (im, wx, wy, c1, c2, l1, l2, aperts, sums, areas, + naperts, sigsq, gain, varsky) + +pointer im # pointer to image +real wx, wy # center of subraster +int c1, c2 # column limits +int l1, l2 # line limits +real aperts[ARB] # array of apertures +double sums[ARB] # array of sums +double areas[ARB] # aperture areas +int naperts # number of apertures +real sigsq # the profile widht squared +real gain # the sky value +real varsky # the sky variance + +int i, j, k, nx, yindex +double fctn, weight, norm +pointer sp, buf, sump, sumpw +real xc, yc, apmaxsq, dy2, r2, r, prof, var +pointer imgs2r() + +begin + # Initialize. + call smark (sp) + call salloc (sump, naperts, TY_DOUBLE) + call salloc (sumpw, naperts, TY_DOUBLE) + call aclrd (Memd[sump], naperts) + call aclrd (Memd[sumpw], naperts) + + # Get array boundary parameters. + nx = c2 - c1 + 1 + xc = wx - c1 + 1 + yc = wy - l1 + 1 + apmaxsq = (aperts[naperts] + 0.5) ** 2 + + # Clear out the accumulaters + call aclrd (sums, naperts) + call aclrd (areas, naperts) + + # Loop over the pixels. + do j = l1, l2 { + buf = imgs2r (im, c1, c2, j, j) + if (buf == EOF) { + call sfree (sp) + return + } + yindex = j - l1 + 1 + dy2 = (yindex - yc) ** 2 + do i = 1, nx { + r2 = (i - xc) ** 2 + dy2 + if (r2 > apmaxsq) + next + prof = max (exp (-r2 / sigsq), 0.0) + if (prof <= 0.0) + next + var = max (0.0, Memr[buf+i-1]) + var = var / gain + varsky + if (var <= 0.0) + next + weight = prof / var + r = sqrt (r2) - 0.5 + do k = 1, naperts { + if (r > aperts[k]) + next + fctn = max (0.0, min (1.0, aperts[k] - r)) + sums[k] = sums[k] + weight * fctn * Memr[buf+i-1] + areas[k] = areas[k] + weight * fctn + Memd[sump+k-1] = Memd[sump+k-1] + prof + Memd[sumpw+k-1] = Memd[sumpw+k-1] + weight * prof + } + } + } + + # Normalize. + do k = 1, naperts { + if (Memd[sumpw+k-1] <= 0.0d0) + norm = 0.0d0 + else + norm = Memd[sump+k-1] / Memd[sumpw+k-1] + sums[k] = sums[k] * norm + areas[k] = areas[k] * norm + } + + call sfree (sp) +end + + +# AP_BGMEASURE -- Procedure to measure the fluxes and effective areas of a set +# of apertures assuming a Gaussian weighting function. + +procedure ap_bgmeasure (im, wx, wy, c1, c2, l1, l2, datamin, datamax, + aperts, sums, areas, naperts, minapert, sigsq, gain, varsky) + +pointer im # pointer to image +real wx, wy # center of subraster +int c1, c2 # column limits +int l1, l2 # line limits +real datamin # minimum good data +real datamax # maximum good data +real aperts[ARB] # array of apertures +double sums[ARB] # array of sums +double areas[ARB] # aperture areas +int naperts # number of apertures +int minapert # minimum aperture fo bad pixels +real sigsq # the profile widht squared +real gain # the image gain value +real varsky # the sky variance + +int i, j, k, nx, yindex, kindex +double fctn, weight, norm +pointer sp, buf, sump, sumpw +real xc, yc, apmaxsq, dy2, r2, r +real pixval, prof, var +pointer imgs2r() + +begin + # Initialize. + call smark (sp) + call salloc (sump, naperts, TY_DOUBLE) + call salloc (sumpw, naperts, TY_DOUBLE) + call aclrd (Memd[sump], naperts) + call aclrd (Memd[sumpw], naperts) + minapert = naperts + 1 + + # Get array boundary parameters. + nx = c2 - c1 + 1 + xc = wx - c1 + 1 + yc = wy - l1 + 1 + apmaxsq = (aperts[naperts] + 0.5) ** 2 + + # Clear out the accumulaters + call aclrd (sums, naperts) + call aclrd (areas, naperts) + + # Loop over the pixels. + do j = l1, l2 { + buf = imgs2r (im, c1, c2, j, j) + if (buf == EOF) { + call sfree (sp) + return + } + yindex = j - l1 + 1 + dy2 = (yindex - yc) ** 2 + do i = 1, nx { + r2 = (i - xc) ** 2 + dy2 + if (r2 > apmaxsq) + next + prof = max (exp (-r2 / sigsq), 0.0) + if (prof <= 0.0) + next + pixval = Memr[buf+i-1] + var = max (0.0, pixval) + var = pixval / gain + varsky + if (var <= 0.0) + next + weight = prof / var + r = sqrt (r2) - 0.5 + kindex = naperts + 1 + do k = 1, naperts { + if (r > aperts[k]) + next + kindex = min (k, kindex) + fctn = max (0.0, min (1.0, aperts[k] - r)) + sums[k] = sums[k] + weight * fctn * pixval + areas[k] = areas[k] + weight * fctn + Memd[sump+k-1] = Memd[sump+k-1] + prof + Memd[sumpw+k-1] = Memd[sumpw+k-1] + weight * prof + } + if (kindex < minapert) { + if (pixval < datamin || pixval > datamax) + minapert = kindex + } + } + } + + # Normalize. + do k = 1, naperts { + if (Memd[sumpw+k-1] <= 0.0d0) + norm = 0.0d0 + else + norm = Memd[sump+k-1] / Memd[sumpw+k-1] + sums[k] = sums[k] * norm + areas[k] = areas[k] * norm + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/wphot/apgwppars.x b/noao/digiphot/apphot/wphot/apgwppars.x new file mode 100644 index 00000000..91383169 --- /dev/null +++ b/noao/digiphot/apphot/wphot/apgwppars.x @@ -0,0 +1,35 @@ +include "../lib/display.h" +include "../lib/noise.h" +include "../lib/center.h" +include "../lib/fitsky.h" +include "../lib/phot.h" + +# AP_GWPPARS -- Procedure to fetch the phot task parameters. + +procedure ap_gwppars (ap) + +pointer ap # pointer to apphot structure + +bool clgetb() +int btoi() + +begin + # Initialize the photometry structure. + call appinit (ap, AP_CENTROID1D, 2.5, AP_MODE, 10.0, 10.0, 3.0, 1, + AP_PWCONSTANT, 2.0, AP_NPOISSON) + + # Get the data dependent parameters. + call ap_gdapars (ap) + + # Get the centering parameters. + call ap_gcepars (ap) + + # Get the sky fitting parameters. + call ap_gsapars (ap) + + # Get the photometry parameters. + call ap_gwhpars (ap) + + # Set the radplot parameters. + call apseti (ap, RADPLOTS, btoi (clgetb ("radplots"))) +end diff --git a/noao/digiphot/apphot/wphot/aptmeasure.x b/noao/digiphot/apphot/wphot/aptmeasure.x new file mode 100644 index 00000000..8ba7b650 --- /dev/null +++ b/noao/digiphot/apphot/wphot/aptmeasure.x @@ -0,0 +1,192 @@ +# AP_TMEASURE -- Procedure to measure the fluxes and effective areas of a set of +# apertures assuming a conical weighting function. + +procedure ap_tmeasure (im, wx, wy, c1, c2, l1, l2, aperts, sums, areas, + naperts, fwhmpsf, gain, varsky) + +pointer im # pointer to image +real wx, wy # center of subraster +int c1, c2 # column limits +int l1, l2 # line limits +real aperts[ARB] # array of apertures +double sums[ARB] # array of sums +double areas[ARB] # aperture areas +int naperts # number of apertures +real fwhmpsf # width of the profile +real gain # the image gain +real varsky # the sky variance + +int i, j, k, yindex, nx +double fctn, weight, norm +pointer buf, sp, sump, sumpw +real xc, yc, apmaxsq, dy2, r2, r, pixval, prof, var +pointer imgs2r() + +begin + # Initialize. + call smark (sp) + call salloc (sump, naperts, TY_DOUBLE) + call salloc (sumpw, naperts, TY_DOUBLE) + call aclrd (Memd[sump], naperts) + call aclrd (Memd[sumpw], naperts) + + # Set up some array boundary parameters. + nx = c2 - c1 + 1 + xc = wx - c1 + 1 + yc = wy - l1 + 1 + apmaxsq = (aperts[naperts] + 0.5) ** 2 + + # Clear out the accumulaters + call aclrd (sums, naperts) + call aclrd (areas, naperts) + + # Loop over the pixels. + do j = l1, l2 { + buf = imgs2r (im, c1, c2, j, j) + if (buf == NULL) { + call sfree (sp) + return + } + yindex = j - l1 + 1 + dy2 = (yindex - yc) ** 2 + do i = 1, nx { + r2 = (i - xc) ** 2 + dy2 + if (r2 > apmaxsq) + next + r = sqrt (r2) + prof = max (1.0 - r / fwhmpsf, 0.0) + if (prof <= 0.0) + next + pixval = Memr[buf+i-1] + var = max (0.0, pixval) + var = var / gain + varsky + if (var <= 0.0) + next + weight = prof / var + r = r - 0.5 + do k = 1, naperts { + if (r > aperts[k]) + next + fctn = max (0.0, min (1.0, aperts[k] - r)) + Memd[sump+k-1] = Memd[sump+k-1] + prof + Memd[sumpw+k-1] = Memd[sumpw+k-1] + prof * weight + sums[k] = sums[k] + weight * fctn * pixval + areas[k] = areas[k] + weight * fctn + } + } + } + + # Normalize. + do k = 1, naperts { + if (Memd[sumpw+k-1] <= 0.0d0) + norm = 0.0d0 + else + norm = Memd[sump+k-1] / Memd[sumpw+k-1] + sums[k] = sums[k] * norm + areas[k] = areas[k] * norm + } + + call sfree (sp) +end + + +# AP_BTMEASURE -- Procedure to measure the fluxes and effective areas of a +# set of apertures assuming a conical weighting function. + +procedure ap_btmeasure (im, wx, wy, c1, c2, l1, l2, datamin, datamax, + aperts, sums, areas, naperts, minapert, fwhmpsf, gain, varsky) + +pointer im # pointer to image +real wx, wy # center of subraster +int c1, c2 # column limits +int l1, l2 # line limits +real datamin # minimum good data value +real datamax # maximum good data value +real aperts[ARB] # array of apertures +double sums[ARB] # array of sums +double areas[ARB] # aperture areas +int naperts # number of apertures +int minapert # minimum aperture +real fwhmpsf # width of the profile +real gain # the image gain +real varsky # the sky variance + +int i, j, k, yindex, kindex, nx +double fctn, weight, norm +pointer buf, sp, sump, sumpw +real xc, yc, apmaxsq, dy2, r2, r, pixval, prof, var +pointer imgs2r() + +begin + # Initialize. + call smark (sp) + call salloc (sump, naperts, TY_DOUBLE) + call salloc (sumpw, naperts, TY_DOUBLE) + call aclrd (Memd[sump], naperts) + call aclrd (Memd[sumpw], naperts) + minapert = naperts + 1 + + # Set up some array boundary parameters. + nx = c2 - c1 + 1 + xc = wx - c1 + 1 + yc = wy - l1 + 1 + apmaxsq = (aperts[naperts] + 0.5) ** 2 + + # Clear out the accumulaters + call aclrd (sums, naperts) + call aclrd (areas, naperts) + + # Loop over the pixels. + do j = l1, l2 { + buf = imgs2r (im, c1, c2, j, j) + if (buf == NULL) { + call sfree (sp) + return + } + yindex = j - l1 + 1 + dy2 = (yindex - yc) ** 2 + do i = 1, nx { + r2 = (i - xc) ** 2 + dy2 + if (r2 > apmaxsq) + next + r = sqrt (r2) + prof = max (1.0 - r / fwhmpsf, 0.0) + if (prof <= 0.0) + next + pixval = Memr[buf+i-1] + var = max (0.0, pixval) + var = var / gain + varsky + if (var <= 0.0) + next + weight = prof / var + r = r - 0.5 + kindex = naperts + 1 + do k = 1, naperts { + if (r > aperts[k]) + next + kindex = min (k, kindex) + fctn = max (0.0, min (1.0, aperts[k] - r)) + Memd[sump+k-1] = Memd[sump+k-1] + prof + Memd[sumpw+k-1] = Memd[sumpw+k-1] + prof * weight + sums[k] = sums[k] + weight * fctn * pixval + areas[k] = areas[k] + weight * fctn + } + if (kindex < minapert) { + if (pixval < datamin || pixval > datamax) + minapert = kindex + } + } + } + + # Normalize. + do k = 1, naperts { + if (Memd[sumpw+k-1] <= 0.0d0) + norm = 0.0d0 + else + norm = Memd[sump+k-1] / Memd[sumpw+k-1] + sums[k] = sums[k] * norm + areas[k] = areas[k] * norm + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/wphot/apwconfirm.x b/noao/digiphot/apphot/wphot/apwconfirm.x new file mode 100644 index 00000000..53222388 --- /dev/null +++ b/noao/digiphot/apphot/wphot/apwconfirm.x @@ -0,0 +1,110 @@ +include "../lib/apphot.h" +include "../lib/noise.h" +include "../lib/center.h" +include "../lib/fitsky.h" +include "../lib/phot.h" + +# AP_WCONFIRM -- Procedure to confirm the critical phot parameters. + +procedure ap_wconfirm (ap, out, stid) + +pointer ap # pointer to the apphot structure +int out # pointer to the output file descriptor +int stid # output file sequence number + +pointer sp, cstr, sstr, pwstr, aperts +real fwhmpsf, capert, annulus, dannulus, skysigma +real datamin, datamax +int apstati() +real apstatr(), ap_vfwhmpsf(), ap_vcapert(), ap_vsigma() +real ap_vannulus(), ap_vdannulus(), ap_vdatamin(), ap_vdatamax() + +begin + call smark (sp) + call salloc (cstr, SZ_FNAME, TY_CHAR) + call salloc (sstr, SZ_FNAME, TY_CHAR) + call salloc (pwstr, SZ_FNAME, TY_CHAR) + call salloc (aperts, SZ_LINE, TY_CHAR) + + call printf ("\n") + + # Confirm the centering algorithm. + call ap_vcstring (ap, Memc[cstr], SZ_FNAME) + + if (apstati (ap, CENTERFUNCTION) != AP_NONE) { + + # Confirm the fwhmpsf. + if (apstati (ap, CENTERFUNCTION) != AP_CENTROID1D) + fwhmpsf = ap_vfwhmpsf (ap) + else + fwhmpsf = apstatr (ap, FWHMPSF) + + # Confirm the centering box. + capert = 2.0 * ap_vcapert (ap) + + } else { + + fwhmpsf = apstatr (ap, FWHMPSF) + capert = 2.0 * apstatr (ap, CAPERT) + } + + # Confirm the sky fitting algorithm. + call ap_vsstring (ap, Memc[sstr], SZ_FNAME) + + if (apstati (ap, SKYFUNCTION) != AP_CONSTANT && + apstati (ap, SKYFUNCTION) != AP_SKYFILE) { + + # Confirm the sky annulus parameter. + annulus = ap_vannulus (ap) + + # Confirm the width of the sky annulus. + dannulus = ap_vdannulus (ap) + + } else { + annulus = apstatr (ap, ANNULUS) + dannulus = apstatr (ap, DANNULUS) + } + + # Confirm the sky sigma parameter. + skysigma = ap_vsigma (ap) + + # Confirm the weighting scheme algorithm. + call ap_vpwstring (ap, Memc[pwstr], SZ_FNAME) + + # Confirm the aperture radii parameter. + call ap_vaperts (ap, Memc[aperts], SZ_LINE) + + # Verify the datamin and datamax parameters. + datamin = ap_vdatamin (ap) + datamax = ap_vdatamax (ap) + + call printf ("\n") + + # Update the database file. + if (out != NULL && stid > 1) { + call ap_sparam (out, KY_CSTRING, Memc[cstr], UN_CALGORITHM, + "centering algorithm") + call ap_rparam (out, KY_FWHMPSF, fwhmpsf, UN_ASCALEUNIT, + "full width half maximum of the psf") + call ap_rparam (out, KY_CAPERT, capert, UN_CSCALEUNIT, + "centering box width") + call ap_sparam (out, KY_SSTRING, Memc[sstr], UN_SALGORITHM, + "sky fitting algorithm") + call ap_rparam (out, KY_ANNULUS, annulus, UN_SSCALEUNIT, + "inner radius of the sky annulus") + call ap_rparam (out, KY_DANNULUS, dannulus, UN_SSCALEUNIT, + "width of the sky annulus") + call ap_rparam (out, KY_SKYSIGMA, skysigma, UN_NCOUNTS, + "standard deviation of 1 sky pixel") + call ap_sparam (out, KY_PWSTRING, Memc[pwstr], UN_PMODEL, + "photometric weighting function") + call ap_sparam (out, KY_APERTS, Memc[aperts], UN_PSCALEUNIT, + "list of apertures") + call ap_rparam (out, KY_DATAMIN, datamin, UN_ACOUNTS, + "minimum good data value") + call ap_rparam (out, KY_DATAMAX, datamax, UN_ACOUNTS, + "maximum good data value") + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/wphot/apwmag.x b/noao/digiphot/apphot/wphot/apwmag.x new file mode 100644 index 00000000..0818bf3f --- /dev/null +++ b/noao/digiphot/apphot/wphot/apwmag.x @@ -0,0 +1,157 @@ +include <mach.h> +include "../lib/apphotdef.h" +include "../lib/apphot.h" +include "../lib/noisedef.h" +include "../lib/photdef.h" +include "../lib/phot.h" + +define CONVERSION 2.772588 + +# AP_WMAG -- Procedure to compute the magnitudes inside a set of apertures for +# a single of object. + +int procedure ap_wmag (ap, im, wx, wy, positive, skyval, skysig, nsky) + +pointer ap # pointer to the apphot structure +pointer im # pointer to the IRAF image +real wx, wy # object coordinates +int positive # emission or absorption features +real skyval # sky value +real skysig # sky sigma +int nsky # number of sky pixels + +int c1, c2, l1, l2, ier, nap +pointer sp, nse, phot, temp +real datamin, datamax, zmag, wsigsq, wvarsky +int apmagbuf() + +begin + # Initalize. + phot = AP_PPHOT(ap) + nse = AP_NOISE(ap) + AP_PXCUR(phot) = wx + AP_PYCUR(phot) = wy + if (IS_INDEFR(wx) || IS_INDEFR(wy)) { + AP_OPXCUR(phot) = INDEFR + AP_OPYCUR(phot) = INDEFR + } else { + switch (AP_WCSOUT(ap)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_ltoo (ap, wx, wy, AP_OPXCUR(phot), AP_OPYCUR(phot), 1) + case WCS_TV: + call ap_ltov (im, wx, wy, AP_OPXCUR(phot), AP_OPYCUR(phot), 1) + default: + AP_OPXCUR(phot) = wx + AP_OPYCUR(phot) = wy + } + } + call amovkd (0.0d0, Memd[AP_SUMS(phot)], AP_NAPERTS(phot)) + call amovkd (0.0d0, Memd[AP_AREA(phot)], AP_NAPERTS(phot)) + call amovkr (INDEFR, Memr[AP_MAGS(phot)], AP_NAPERTS(phot)) + call amovkr (INDEFR, Memr[AP_MAGERRS(phot)], AP_NAPERTS(phot)) + + # Make sure the center is defined. + if (IS_INDEFR(wx) || IS_INDEFR(wy)) + return (AP_APERT_NOAPERT) + + # Fetch the aperture pixels. + ier = apmagbuf (ap, im, wx, wy, c1, c2, l1, l2) + if (ier == AP_APERT_NOAPERT) + return (AP_APERT_NOAPERT) + + call smark (sp) + call salloc (temp, AP_NAPERTS(phot), TY_REAL) + + # Compute the min and max. + if (IS_INDEFR(AP_DATAMIN(ap))) + datamin = -MAX_REAL + else + datamin = AP_DATAMIN(ap) + if (IS_INDEFR(AP_DATAMAX(ap))) + datamax = MAX_REAL + else + datamax = AP_DATAMAX(ap) + + # Do photometry for all the apertures. + AP_NMINAP(phot) = AP_NMAXAP(phot) + 1 + call amulkr (Memr[AP_APERTS(phot)], AP_SCALE(ap), Memr[temp], + AP_NAPERTS(phot)) + + switch (AP_PWEIGHTS(phot)) { + case AP_PWCONSTANT: + if (IS_INDEFR(AP_DATAMIN(ap)) && IS_INDEFR(AP_DATAMAX(ap))) + call apmeasure (im, wx, wy, c1, c2, l1, l2, Memr[temp], + Memd[AP_SUMS(phot)], Memd[AP_AREA(phot)], AP_NMAXAP(phot)) + else + call apbmeasure (im, wx, wy, c1, c2, l1, l2, datamin, + datamax, Memr[temp], Memd[AP_SUMS(phot)], + Memd[AP_AREA(phot)], AP_NMAXAP(phot), AP_NMINAP(phot)) + case AP_PWCONE: + wsigsq = AP_FWHMPSF(ap) * AP_SCALE(ap) + wvarsky = (AP_READNOISE(nse) / AP_EPADU(nse)) ** 2 + if (IS_INDEFR(AP_DATAMIN(ap)) && IS_INDEFR(AP_DATAMAX(ap))) + call ap_tmeasure (im, wx, wy, c1, c2, l1, l2, Memr[temp], + Memd[AP_SUMS(phot)], Memd[AP_AREA(phot)], AP_NMAXAP(phot), + wsigsq, AP_EPADU(nse), wvarsky) + else + call ap_btmeasure (im, wx, wy, c1, c2, l1, l2, datamin, + datamax, Memr[temp], Memd[AP_SUMS(phot)], + Memd[AP_AREA(phot)], AP_NMAXAP(phot), AP_NMINAP(phot), + wsigsq, AP_EPADU(nse), wvarsky) + case AP_PWGAUSS: + wsigsq = (AP_FWHMPSF(ap) * AP_SCALE(ap)) ** 2 / CONVERSION + wvarsky = (AP_READNOISE(nse) / AP_EPADU(nse)) ** 2 + if (IS_INDEFR(AP_DATAMIN(ap)) && IS_INDEFR(AP_DATAMAX(ap))) + call ap_gmeasure (im, wx, wy, c1, c2, l1, l2, Memr[temp], + Memd[AP_SUMS(phot)], Memd[AP_AREA(phot)], AP_NMAXAP(phot), + wsigsq, AP_EPADU(nse), wvarsky) + else + call ap_bgmeasure (im, wx, wy, c1, c2, l1, l2, + datamin, datamax, Memr[temp], Memd[AP_SUMS(phot)], + Memd[AP_AREA(phot)], AP_NMAXAP(phot), AP_NMINAP(phot), + wsigsq, AP_EPADU(nse), wvarsky) + default: + if (IS_INDEFR(AP_DATAMIN(ap)) && IS_INDEFR(AP_DATAMAX(ap))) + call apmeasure (im, wx, wy, c1, c2, l1, l2, Memr[temp], + Memd[AP_SUMS(phot)], Memd[AP_AREA(phot)], AP_NMAXAP(phot)) + else + call apbmeasure (im, wx, wy, c1, c2, l1, l2, datamin, + datamax, Memr[temp], Memd[AP_SUMS(phot)], + Memd[AP_AREA(phot)], AP_NMAXAP(phot), AP_NMINAP(phot)) + } + + # Make sure that the sky value has been defined. + if (IS_INDEFR(skyval)) + ier = AP_APERT_NOSKYMODE + + else { + + # Check for bad pixels. + if ((ier == AP_OK) && (AP_NMINAP(phot) <= AP_NMAXAP(phot))) + ier = AP_APERT_BADDATA + + nap = min (AP_NMINAP(phot) - 1, AP_NMAXAP(phot)) + + # Compute the magnitudes and errors. + if (positive == YES) + call apcopmags (Memd[AP_SUMS(phot)], Memd[AP_AREA(phot)], + Memr[AP_MAGS(phot)], Memr[AP_MAGERRS(phot)], nap, skyval, + skysig, nsky, AP_ZMAG(phot), AP_NOISEFUNCTION(nse), + AP_EPADU(nse)) + else + call apconmags (Memd[AP_SUMS(phot)], Memd[AP_AREA(phot)], + Memr[AP_MAGS(phot)], Memr[AP_MAGERRS(phot)], nap, skyval, + skysig, nsky, AP_ZMAG(phot), AP_NOISEFUNCTION(nse), + AP_EPADU(nse), AP_READNOISE(nse)) + + # Compute correction for itime. + zmag = 2.5 * log10 (AP_ITIME(ap)) + call aaddkr (Memr[AP_MAGS(phot)], zmag, Memr[AP_MAGS(phot)], nap) + } + + call sfree (sp) + if (ier != AP_OK) + return (ier) + else + return (AP_OK) +end diff --git a/noao/digiphot/apphot/wphot/apwpars.x b/noao/digiphot/apphot/wphot/apwpars.x new file mode 100644 index 00000000..88406a8f --- /dev/null +++ b/noao/digiphot/apphot/wphot/apwpars.x @@ -0,0 +1,27 @@ +include "../lib/display.h" + +# AP_WPARS -- Procedure to write out the wphot task parameters. + +procedure ap_wpars (ap) + +pointer ap # pointer to apphot structure + +bool itob() +int apstati() + +begin + # Write out the data dependent parameters. + call ap_dapars (ap) + + # Write the centering parameters. + call ap_cepars (ap) + + # Write out the sky fitting parameters. + call ap_sapars (ap) + + # Write out the photometry parameters. + call ap_phpars (ap) + + # Set the radplots parameter. + call clputb ("radplots", itob (apstati (ap, RADPLOTS))) +end diff --git a/noao/digiphot/apphot/wphot/apwpcolon.x b/noao/digiphot/apphot/wphot/apwpcolon.x new file mode 100644 index 00000000..6f6e1f5c --- /dev/null +++ b/noao/digiphot/apphot/wphot/apwpcolon.x @@ -0,0 +1,157 @@ +include <gset.h> +include "../lib/apphot.h" +include "../lib/fitsky.h" +include "../lib/center.h" +include "../lib/phot.h" +include "../lib/display.h" +include "../lib/noise.h" + +# AP_WPCOLON -- Process wphot colon commands. + +procedure ap_wpcolon (ap, im, cl, out, stid, ltid, cmdstr, newimage, + newcenterbuf, newcenter, newskybuf, newsky, newmagbuf, newmag) + +pointer ap # pointer to the apphot structure +pointer im # pointer to the iraf image +int cl # coord file descriptor +int out # output file descriptor +int stid # output file sequence number +int ltid # coord file sequence number +char cmdstr[ARB] # command string +int newimage # new image ? +int newcenterbuf, newcenter # new center buffer ? new center fit ? +int newskybuf, newsky # new sky buffer ? new sky fit ? +int newmagbuf, newmag # new aperture buffer ? new fit ? + +pointer sp, incmd, outcmd +int strdic() + +begin + # Get the command. + call smark (sp) + call salloc (incmd, SZ_LINE, TY_CHAR) + call salloc (outcmd, SZ_LINE, TY_CHAR) + + call sscan (cmdstr) + call gargwrd (Memc[incmd], SZ_LINE) + if (Memc[incmd] == EOS) { + call sfree (sp) + return + } + + # Process the command. + if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, CCMDS) != 0) + call apccolon (ap, out, stid, cmdstr, newcenterbuf, newcenter) + else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, SCMDS) != 0) + call apscolon (ap, out, stid, cmdstr, newskybuf, newsky) + else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, PCMDS) != 0) + call ap_wmagcolon (ap, out, stid, cmdstr, newmagbuf, newmag) + else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, APCMDS) != 0) + call ap_apcolon (ap, im, cl, out, stid, ltid, cmdstr, newimage, + newcenterbuf, newcenter, newskybuf, newsky, newmagbuf, newmag) + else if (strdic (Memc[incmd], Memc[outcmd], SZ_LINE, NCMDS) != 0) + call ap_nscolon (ap, im, out, stid, cmdstr, newcenterbuf, + newcenter, newskybuf, newsky, newmagbuf, newmag) + else + call ap_himcolon (ap, cmdstr) + + call sfree (sp) +end + + +# AP_WMAGCOLON -- Procedure to display and edit the photometry parameters. + +procedure ap_wmagcolon (ap, out, stid, cmdstr, newmagbuf, newmag) + +pointer ap # pointer to apphot structure +int out # output file descriptor +int stid # output number +char cmdstr[ARB] # command string +int newmagbuf # new aperture buffers +int newmag # compute new magnitudes + +bool bval +int ncmd, stat +pointer sp, cmd +real rval +bool itob() +int btoi(), strdic(), nscan(), apstati() +real apstatr() + +begin + # Get the command. + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + call sscan (cmdstr) + call gargwrd (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call sfree (sp) + return + } + + # Process the command + ncmd = strdic (Memc[cmd], Memc[cmd], SZ_LINE, PCMDS) + switch (ncmd) { + case PCMD_APERTURES: + call gargwrd (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call apstats (ap, APERTS, Memc[cmd], SZ_LINE) + call printf ("%s = %s %s\n") + call pargstr (KY_APERTS) + call pargstr (Memc[cmd]) + call pargstr (UN_PSCALEUNIT) + } else { + call apsets (ap, APERTS, Memc[cmd]) + if (stid > 1) + call ap_sparam (out, KY_APERTS, Memc[cmd], UN_PSCALEUNIT, + "list of aperture radii") + newmag = YES + newmagbuf = YES + } + case PCMD_ZMAG: + call gargr (rval) + if (nscan() == 1) { + call printf ("%s = %g\n") + call pargstr (KY_ZMAG) + call pargr (apstatr (ap, ZMAG)) + } else { + call apsetr (ap, ZMAG, rval) + if (stid > 1) + call ap_rparam (out, KY_ZMAG, rval, UN_PZMAG, + "zero point of magnitude scale") + newmag = YES + } + case PCMD_MKAPERT: + call gargb (bval) + if (nscan () == 1) { + call printf ("%s = %b\n") + call pargstr (KY_MKAPERT) + call pargb (itob (apstati (ap, MKAPERT))) + } else { + call apseti (ap, MKAPERT, btoi (bval)) + } + case PCMD_WEIGHTING: + call gargwrd (Memc[cmd], SZ_LINE) + if (Memc[cmd] == EOS) { + call apstats (ap, PWSTRING, Memc[cmd], SZ_LINE) + call printf ("%s = %s\n") + call pargstr (KY_PWSTRING) + call pargstr (Memc[cmd]) + } else { + stat = strdic (Memc[cmd], Memc[cmd], SZ_LINE, PWFUNCS) + if (stat > 0) { + call apseti (ap, PWEIGHTS, stat) + call apsets (ap, PWSTRING, Memc[cmd]) + if (stid > 1) + call ap_sparam (out, KY_PWSTRING, Memc[cmd], + UN_PMODEL, "photometric weighting model") + newmagbuf = YES + newmag = YES + } + } + default: + call printf ("Unknown or ambiguous colon command\7\n") + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/wphot/apwphot.x b/noao/digiphot/apphot/wphot/apwphot.x new file mode 100644 index 00000000..07849c0e --- /dev/null +++ b/noao/digiphot/apphot/wphot/apwphot.x @@ -0,0 +1,509 @@ +include <ctype.h> +include <gset.h> +include <imhdr.h> +include "../lib/phot.h" +include "../lib/apphot.h" +include "../lib/display.h" +include "../lib/center.h" +include "../lib/fitsky.h" + +define HELPFILE "apphot$wphot/wphot.key" + +# APWPHOT -- Procedure to compute magnitudes for a list of objects + +int procedure ap_wphot (ap, im, cl, sd, gd, mgd, id, out, stid, interactive, + cache) + +pointer ap # pointer to apphot structure +pointer im # pointer to IRAF image +int cl # starlist file descriptor +int sd # the sky file descriptor +pointer gd # pointer to graphcis descriptor +pointer mgd # pointer to graphics metacode file +pointer id # pointer to image display stream +int out # output file descriptor +int stid # output file sequence number +int interactive # interactive mode +int cache # cache the input image pixels + +real wx, wy, xlist, ylist +pointer sp, cmd +int wcs, key, ltid, newlist, req_size, old_size, buf_size, memstat +int newimage, newskybuf, newsky, newcenterbuf, newcenter, newmagbuf, newmag +int colonkey, prev_num, req_num, ip, oid +int cier, sier, pier + +real apstatr() +int clgcur(), apfitsky(), aprefitsky(), apfitcenter(), aprefitcenter() +int ap_wmag(), ap_wremag(), apgscur(), ctoi(), apstati(), apgqverify() +int apgtverify(), apnew(), ap_avsky(), ap_memstat(), sizeof() +bool fp_equalr() + +define endswitch_ 99 + +begin + # Initialize. + call smark (sp) + call salloc (cmd, SZ_LINE, TY_CHAR) + + # Initialize the cursor command. + key = ' ' + Memc[cmd] = EOS + + # Initialize the fitting parameters. + newimage = NO + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newmagbuf = YES; newmag = YES + cier = AP_OK; sier = AP_OK; pier = AP_OK + + # Initialize the sequence numbering. + newlist = NO + ltid = 0 + + # Loop over the coordinate file. + while (clgcur ("icommands", wx, wy, wcs, key, Memc[cmd], SZ_LINE) != + EOF) { + + # Store the current cursor coordinates. + call ap_vtol (im, wx, wy, wx, wy, 1) + call apsetr (ap, CWX, wx) + call apsetr (ap, CWY, wy) + + # Test to see if the cursor moved. + if (apnew (ap, wx, wy, xlist, ylist, newlist) == YES) { + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newmagbuf = YES; newmag = YES + } + + # Store previous cursor coordinates. + call apsetr (ap, WX, apstatr (ap, CWX)) + call apsetr (ap, WY, apstatr (ap, CWY)) + + # Loop over the colon keystroke commands. + switch (key) { + + # Quit. + case 'q': + if (interactive == YES) { + if (apgqverify ("wphot", ap, key) == YES) { + call sfree (sp) + return (apgtverify (key)) + } + } else { + call sfree (sp) + return (NO) + } + + # Print out error messages. + case 'e': + if (interactive == YES) + call ap_perrors (ap, cier, sier, pier) + + # Print out the help page(s). + case '?': + if ((id != NULL) && (id == gd)) + call gpagefile (id, HELPFILE, "") + else if (interactive == YES) + call pagefile (HELPFILE, "[space=morehelp,q=quit,?=help]") + + # Rewind the list. + case 'r': + if (cl != NULL) { + call seek (cl, BOFL) + ltid = 0 + } else if (interactive == YES) + call printf ("No coordinate list\n") + + # Get, measure next object from the list. + case 'm', 'n': + + # No coordinate file. + if (cl == NULL) { + if (interactive == YES) + call printf ("No coordinate list\n") + goto endswitch_ + + } + + # Need to rewind coordinate list. + prev_num = ltid + req_num = ltid + 1 + if (apgscur (cl, id, xlist, ylist, prev_num, req_num, + ltid) == EOF) { + if (interactive == YES) + call printf ( + "End of coordinate list, use r key to rewind\n") + goto endswitch_ + } + + # Convert coordinates if necessary. + switch (apstati (ap, WCSIN)) { + case WCS_PHYSICAL, WCS_WORLD: + call ap_itol (ap, xlist, ylist, xlist, ylist, 1) + case WCS_TV: + call ap_vtol (im, xlist, ylist, xlist, ylist, 1) + default: + ; + } + + # Move to next object. + newlist = YES + if (key == 'm') { + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newmagbuf = YES; newmag = YES + goto endswitch_ + } + + # Measure the object. + cier = apfitcenter (ap, im, xlist, ylist) + sier = apfitsky (ap, im, apstatr (ap, XCENTER), apstatr (ap, + YCENTER), sd, gd) + pier = ap_wmag (ap, im, apstatr (ap, XCENTER), apstatr (ap, + YCENTER), apstati (ap, POSITIVE), apstatr (ap, SKY_MODE), + apstatr (ap, SKY_SIGMA), apstati (ap, NSKY)) + if (id != NULL) { + call apmark (ap, id, apstati (ap, MKCENTER), apstati (ap, + MKSKY), apstati (ap, MKAPERT)) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_pplot (ap, im, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qpmag (ap, cier, sier, pier) + if (stid == 1) + call ap_param (ap, out, "wphot") + call ap_pmag (ap, out, stid, ltid, cier, sier, pier) + call ap_pplot (ap, im, stid, mgd, YES) + stid = stid + 1 + newcenterbuf = NO; newcenter = NO + newskybuf = NO; newsky = NO + newmagbuf = NO; newmag = NO + + # Process the remainder of the list. + case 'l': + if (cl != NULL) { + oid = stid + ltid = ltid + 1 + call ap_bwphot (ap, im, cl, sd, out, stid, ltid, gd, mgd, + id, YES) + ltid = ltid + stid - oid + 1 + if (id != NULL) { + if (id == gd) + call gflush (id) + else + call gframe (id) + } + } else if (interactive == YES) + call printf ("No coordinate list\n") + + # Process apphot colon commands. + case ':': + for (ip = 1; IS_WHITE(Memc[cmd+ip-1]); ip = ip + 1) + ; + colonkey = Memc[cmd+ip-1] + switch (colonkey) { + case 'm', 'n': + + # Show/set a wphot parameter. + if (Memc[cmd+ip] != EOS && Memc[cmd+ip] != ' ') { + call ap_wpcolon (ap, im, cl, out, stid, ltid, Memc[cmd], + newimage, newcenterbuf, newcenter, newskybuf, + newsky, newmagbuf, newmag) + goto endswitch_ + } + + # No coordinate list. + if (cl == NULL) { + if (interactive == YES) + call printf ("No coordinate list\n") + goto endswitch_ + + } + + # Get next object from list. + ip = ip + 1 + prev_num = ltid + if (ctoi (Memc[cmd], ip, req_num) <= 0) + req_num = ltid + 1 + + # Fetch the next object from the list. + if (apgscur (cl, id, xlist, ylist, prev_num, req_num, + ltid) == EOF) { + if (interactive == YES) + call printf ( + "End of coordinate list, use r key to rewind\n") + goto endswitch_ + + } + + # Convert the coordinates. + switch (apstati (ap, WCSIN)) { + case WCS_PHYSICAL, WCS_WORLD: + call ap_itol (ap, xlist, ylist, xlist, ylist, 1) + case WCS_TV: + call ap_vtol (im, xlist, ylist, xlist, ylist, 1) + default: + ; + } + + # Move to the next object. + newlist = YES + if (colonkey == 'm') { + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + newmagbuf = YES; newmag = YES + goto endswitch_ + } + + # Measure the next object. + cier = apfitcenter (ap, im, xlist, ylist) + sier = apfitsky (ap, im, apstatr (ap, XCENTER), + apstatr (ap, YCENTER), sd, gd) + pier = ap_wmag (ap, im, apstatr (ap, XCENTER), apstatr (ap, + YCENTER), apstati (ap, POSITIVE), apstatr (ap, + SKY_MODE), apstatr (ap, SKY_SIGMA), apstati (ap, NSKY)) + if (id != NULL) { + call apmark (ap, id, apstati (ap, MKCENTER), + apstati (ap, MKSKY), apstati (ap, MKAPERT)) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_pplot (ap, im, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qpmag (ap, cier, sier, pier) + if (stid == 1) + call ap_param (ap, out, "wphot") + call ap_pmag (ap, out, stid, ltid, cier, sier, pier) + call ap_pplot (ap, im, stid, mgd, YES) + stid = stid + 1 + newcenterbuf = NO; newcenter = NO + newskybuf = NO; newsky = NO + newmagbuf = NO; newmag = NO + + # Show/set a phot parameter. + default: + call ap_wpcolon (ap, im, cl, out, stid, ltid, Memc[cmd], + newimage, newcenterbuf, newcenter, newskybuf, newsky, + newmagbuf, newmag) + } + + # Reestablish the image viewport and window. + if (newimage == YES) { + if ((id != NULL) && (id != gd)) + call ap_gswv (id, Memc[cmd], im, 4) + req_size = MEMFUDGE * IM_LEN(im,1) * IM_LEN(im,2) * + sizeof (IM_PIXTYPE(im)) + memstat = ap_memstat (cache, req_size, old_size) + if (memstat == YES) + call ap_pcache (im, INDEFI, buf_size) + } + + newimage = NO + + # Save the current parameters in the pset files. + case 'w': + call ap_wpars (ap) + + # Plot centered radial profile. + case 'd': + if (interactive == YES) { + call ap_qrad (ap, im, wx, wy, gd) + newmagbuf = YES; newmag = YES + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + } + + # Setup phot parameters interactively. + case 'i': + if (interactive == YES) { + call ap_radsetup (ap, im, wx, wy, gd, out, stid) + newmagbuf = YES; newmag = YES + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + } + + # Verify critical parameters. + case 'v': + call ap_wconfirm (ap, out, stid) + newmagbuf = YES; newmag = YES + newcenterbuf = YES; newcenter = YES + newskybuf = YES; newsky = YES + + # Fit the center around the cursor position. + case 'c': + if (newcenterbuf == YES) + cier = apfitcenter (ap, im, wx, wy) + else if (newcenter == YES) + cier = aprefitcenter (ap, im, cier) + if (id != NULL) { + call apmark (ap, id, apstati (ap, MKCENTER), NO, NO) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_cplot (ap, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qcenter (ap, cier) + newcenterbuf = NO; newcenter = NO + + # Fit the sky around the cursor position. + case 't': + if (newskybuf == YES || ! fp_equalr (wx, + apstatr (ap, SXCUR)) || ! fp_equalr (wy, apstatr (ap, + SYCUR))) + sier = apfitsky (ap, im, wx, wy, sd, gd) + else if (newsky == YES) + sier = aprefitsky (ap, im, gd) + if (id != NULL) { + call apmark (ap, id, NO, apstati (ap, MKSKY), NO) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_splot (ap, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qspsky (ap, sier) + newskybuf = NO; newsky = NO + + # Compute the average of several sky measurements around + # different cursor postions. + case 'a': + sier = ap_avsky (ap, im, stid, sd, id, gd, interactive) + if (interactive == YES) + call ap_qaspsky (ap, sier) + newskybuf = NO; newsky = NO + + # Fit the sky around the current center position. + case 's': + if (newskybuf == YES || ! fp_equalr (apstatr (ap, XCENTER), + apstatr (ap, SXCUR)) || ! fp_equalr (apstatr (ap, SYCUR), + apstatr (ap, YCENTER))) + sier = apfitsky (ap, im, apstatr (ap, XCENTER), + apstatr (ap, YCENTER), sd, gd) + else if (newsky == YES) + sier = aprefitsky (ap, im, gd) + if (id != NULL) { + call apmark (ap, id, NO, apstati (ap, MKSKY), NO) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_splot (ap, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qspsky (ap, sier) + newskybuf = NO; newsky = NO + + # Compute magnitudes around the cursor position using the current + # sky. + case 'p': + if (newcenterbuf == YES) + cier = apfitcenter (ap, im, wx, wy) + else if (newcenter == YES) + cier = aprefitcenter (ap, im, cier) + if (newmagbuf == YES || ! fp_equalr (apstatr (ap, XCENTER), + apstatr (ap, PXCUR)) || ! fp_equalr (apstatr (ap, + PYCUR), apstatr (ap, YCENTER))) + pier = ap_wmag (ap, im, apstatr (ap, XCENTER), + apstatr (ap, YCENTER), apstati (ap, POSITIVE), + apstatr (ap, SKY_MODE), apstatr (ap, SKY_SIGMA), + apstati (ap, NSKY)) + else + pier = ap_wremag (ap, im, apstati (ap, POSITIVE), + apstatr (ap, SKY_MODE), apstatr (ap, SKY_SIGMA), + apstati (ap, NSKY)) + if (id != NULL) { + call apmark (ap, id, NO, NO, apstati (ap, MKAPERT)) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + if (interactive == YES) + call ap_qpmag (ap, cier, sier, pier) + newcenterbuf = NO; newcenter = NO + newmagbuf = NO; newmag = NO + if (key == 'o') { + if (stid == 1) + call ap_param (ap, out, "wphot") + if (newlist == YES) + call ap_pmag (ap, out, stid, ltid, cier, sier, pier) + else + call ap_pmag (ap, out, stid, 0, cier, sier, pier) + call ap_pplot (ap, im, stid, mgd, YES) + stid = stid + 1 + } + + # Compute the center, sky, and magnitudes and save the results. + case 'f', ' ': + if (newcenterbuf == YES) + cier = apfitcenter (ap, im, wx, wy) + else if (newcenter == YES) + cier = aprefitcenter (ap, im, cier) + if (newskybuf == YES || ! fp_equalr (apstatr (ap, XCENTER), + apstatr (ap, SXCUR)) || ! fp_equalr (apstatr (ap, YCENTER), + apstatr (ap, SYCUR))) + sier = apfitsky (ap, im, apstatr (ap, XCENTER), apstatr (ap, + YCENTER), sd, gd) + else if (newsky == YES) + sier = aprefitsky (ap, im, gd) + if (newmagbuf == YES || ! fp_equalr (apstatr (ap, XCENTER), + apstatr (ap, PXCUR)) || ! fp_equalr (apstatr (ap, YCENTER), + apstatr (ap, PYCUR))) + pier = ap_wmag (ap, im, apstatr (ap, XCENTER), + apstatr (ap, YCENTER), apstati (ap, POSITIVE), + apstatr (ap, SKY_MODE), apstatr (ap, SKY_SIGMA), + apstati (ap, NSKY)) + else + pier = ap_wremag (ap, im, apstati (ap, POSITIVE), + apstatr (ap, SKY_MODE), apstatr (ap, SKY_SIGMA), + apstati (ap, NSKY)) + + if (id != NULL) { + call apmark (ap, id, apstati (ap, MKCENTER), apstati (ap, + MKSKY), apstati (ap, MKAPERT)) + if (id == gd) + call gflush (id) + else + call gframe (id) + } + call ap_pplot (ap, im, stid, gd, apstati (ap, RADPLOTS)) + if (interactive == YES) + call ap_qpmag (ap, cier, sier, pier) + + newcenterbuf = NO; newcenter = NO + newskybuf = NO; newsky = NO + newmagbuf = NO; newmag = NO + + if (key == ' ') { + if (stid == 1) + call ap_param (ap, out, "wphot") + if (newlist == YES) + call ap_pmag (ap, out, stid, ltid, cier, sier, pier) + else + call ap_pmag (ap, out, stid, 0, cier, sier, pier) + call ap_pplot (ap, im, stid, mgd, YES) + stid = stid + 1 + } + + default: + call printf ("Unknown or ambiguous keystroke command\n") + } + +endswitch_ + # Setup for the next object. + key = ' ' + Memc[cmd] = EOS + } + + call sfree (sp) +end diff --git a/noao/digiphot/apphot/wphot/apwremag.x b/noao/digiphot/apphot/wphot/apwremag.x new file mode 100644 index 00000000..5f611ec8 --- /dev/null +++ b/noao/digiphot/apphot/wphot/apwremag.x @@ -0,0 +1,76 @@ +include <mach.h> +include "../lib/apphotdef.h" +include "../lib/apphot.h" +include "../lib/noisedef.h" +include "../lib/photdef.h" +include "../lib/phot.h" + +# AP_WREMAG -- Procedure to recompute the magnitudes inside a set of apertures +# given that the sums and effective areas have already been computed. + +int procedure ap_wremag (ap, im, positive, skyval, skysig, nsky) + +pointer ap # pointer to the apphot structure +pointer im # the input image descriptor +int positive # emission or absorption features +real skyval # sky value +real skysig # sigma of sky +int nsky # number of sky pixels + +int nap +pointer nse, phot +real zmag + +begin + # Initalize. + phot = AP_PPHOT(ap) + nse = AP_NOISE(ap) + call amovkr (INDEFR, Memr[AP_MAGS(phot)], AP_NAPERTS(phot)) + call amovkr (INDEFR, Memr[AP_MAGERRS(phot)], AP_NAPERTS(phot)) + if (IS_INDEFR(AP_PXCUR(phot)) || IS_INDEFR(AP_PYCUR(phot))) { + AP_OPXCUR(phot) = AP_PXCUR(phot) + AP_OPYCUR(phot) = AP_PYCUR(phot) + } else { + switch (AP_WCSOUT(ap)) { + case WCS_WORLD, WCS_PHYSICAL: + call ap_ltoo (ap, AP_PXCUR(phot), AP_PYCUR(phot), + AP_OPXCUR(phot), AP_OPYCUR(phot), 1) + case WCS_TV: + call ap_ltov (im, AP_PXCUR(phot), AP_PYCUR(phot), + AP_OPXCUR(phot), AP_OPYCUR(phot), 1) + default: + AP_OPXCUR(phot) = AP_PXCUR(phot) + AP_OPYCUR(phot) = AP_PYCUR(phot) + } + } + + if (IS_INDEFR(AP_PXCUR(phot)) || IS_INDEFR(AP_PYCUR(phot))) + return (AP_APERT_NOAPERT) + if (IS_INDEFR(skyval)) + return (AP_APERT_NOSKYMODE) + + nap = min (AP_NMINAP(phot) - 1, AP_NMAXAP(phot)) + + # Compute the magnitudes and errors. + if (positive == YES) + call apcopmags (Memd[AP_SUMS(phot)], Memd[AP_AREA(phot)], + Memr[AP_MAGS(phot)], Memr[AP_MAGERRS(phot)], nap, + skyval, skysig, nsky, AP_ZMAG(phot), AP_NOISEFUNCTION(nse), + AP_EPADU(nse)) + else + call apconmags (Memd[AP_SUMS(phot)], Memd[AP_AREA(phot)], + Memr[AP_MAGS(phot)], Memr[AP_MAGERRS(phot)], nap, + skyval, skysig, nsky, AP_ZMAG(phot), AP_NOISEFUNCTION(nse), + AP_EPADU(nse), AP_READNOISE(nse)) + + # Correct for itime. + zmag = 2.5 * log10 (AP_ITIME(ap)) + call aaddkr (Memr[AP_MAGS(phot)], zmag, Memr[AP_MAGS(phot)], nap) + + if (AP_NMINAP(phot) <= AP_NMAXAP(phot)) + return (AP_APERT_BADDATA) + else if (AP_NMAXAP(phot) < AP_NAPERTS(phot)) + return (AP_APERT_OUTOFBOUNDS) + else + return (AP_OK) +end diff --git a/noao/digiphot/apphot/wphot/mkpkg b/noao/digiphot/apphot/wphot/mkpkg new file mode 100644 index 00000000..ac69a00d --- /dev/null +++ b/noao/digiphot/apphot/wphot/mkpkg @@ -0,0 +1,38 @@ +# WPHOT task + +$checkout libpkg.a ".." +$update libpkg.a +$checkin libpkg.a ".." +$exit + +libpkg.a: + apbwphot.x <fset.h> ../lib/apphot.h \ + ../lib/center.h ../lib/display.h \ + ../lib/fitsky.h + apgwppars.x ../lib/center.h ../lib/fitsky.h \ + ../lib/phot.h ../lib/display.h \ + ../lib/noise.h + apwconfirm.x ../lib/apphot.h ../lib/noise.h \ + ../lib/center.h ../lib/fitsky.h \ + ../lib/phot.h + apwmag.x <mach.h> ../lib/apphotdef.h \ + ../lib/noisedef.h ../lib/photdef.h \ + ../lib/apphot.h ../lib/phot.h + apgmeasure.x + aptmeasure.x + apwpars.x ../lib/display.h + apwphot.x <ctype.h> <gset.h> \ + ../lib/apphot.h ../lib/display.h \ + ../lib/center.h ../lib/fitsky.h \ + ../lib/phot.h <imhdr.h> + apwpcolon.x ../lib/noise.h ../lib/apphot.h \ + ../lib/display.h ../lib/fitsky.h \ + ../lib/center.h ../lib/phot.h \ + <gset.h> + apwremag.x <mach.h> ../lib/apphotdef.h \ + ../lib/noisedef.h ../lib/photdef.h \ + ../lib/apphot.h ../lib/phot.h + t_wphot.x <fset.h> <gset.h> \ + <lexnum.h> ../lib/apphot.h \ + ../lib/fitsky.h <imhdr.h> + ; diff --git a/noao/digiphot/apphot/wphot/t_wphot.x b/noao/digiphot/apphot/wphot/t_wphot.x new file mode 100644 index 00000000..14a82a3e --- /dev/null +++ b/noao/digiphot/apphot/wphot/t_wphot.x @@ -0,0 +1,339 @@ +include <fset.h> +include <gset.h> +include <lexnum.h> +include <imhdr.h> +include "../lib/apphot.h" +include "../lib/fitsky.h" + +# T_WPHOT -- Procedure to measure magnitudes inside a set of apertures for a +# list of stars in a list of images. + +procedure t_wphot () + +pointer image # pointer to name of the image +pointer output # pointer to output file name +pointer coords # pointer to name of coords file +pointer skyfile # pointer to name of file with sky values +pointer plotfile # pointer to name of plot metacode file +pointer graphics # pointer to graphics display device +pointer display # pointer to display device +int interactive # mode of use +int cache # cache the input image pixels +int verify # verify critical parameters +int update # update the critical parameters +int verbose # print messages in verbose mode + +pointer sp, outfname, cname, ap, im, gd, mgd, id, str +int limlist, lclist, lolist, lslist, sid, lid, sd, out, cl, root, stat, pfd +int imlist, clist, olist, slist, wcs, memstat, req_size, old_size, buf_size + +pointer immap(), gopen() +int imtlen(), imtgetim(), clplen(), clgfil(), btoi(), apstati(), clgwrd() +int strncmp(), strlen(), fnldir(), ap_wphot(), imtopenp(), clpopnu(), open() +int ap_memstat(), sizeof() +bool clgetb(), streq() +errchk gopen + +begin + # Allocate temporary space. + call smark (sp) + call salloc (image, SZ_FNAME, TY_CHAR) + call salloc (output, SZ_FNAME, TY_CHAR) + call salloc (coords, SZ_FNAME, TY_CHAR) + call salloc (skyfile, SZ_FNAME, TY_CHAR) + call salloc (plotfile, SZ_FNAME, TY_CHAR) + call salloc (graphics, SZ_FNAME, TY_CHAR) + call salloc (display, SZ_FNAME, TY_CHAR) + call salloc (outfname, SZ_FNAME, TY_CHAR) + call salloc (cname, SZ_FNAME, TY_CHAR) + call salloc (str, SZ_LINE, TY_CHAR) + + # Set the standard output to flush on newline. + call fseti (STDOUT, F_FLUSHNL, YES) + + # Get the task parameters. + imlist = imtopenp ("image") + limlist = imtlen (imlist) + clist = clpopnu ("coords") + lclist = clplen (clist) + olist = clpopnu ("output") + lolist = clplen (olist) + + # Check that image and coordinate list lengths match. + if (limlist < 1 || (lclist > 1 && lclist != limlist)) { + call imtclose (imlist) + call clpcls (clist) + call clpcls (olist) + call error (0, "Imcompatible image and coordinate list lengths") + } + + # Check that image and output list lengths match. + if (lolist > 1 && lolist != limlist) { + call imtclose (imlist) + call clpcls (clist) + call clpcls (olist) + call error (0, "Imcompatible image and output list lengths") + } + + call clgstr ("icommands.p_filename", Memc[cname], SZ_FNAME) + if (Memc[cname] != EOS) + interactive = NO + #else if (lclist == 0) + #interactive = YES + else + interactive = btoi (clgetb ("interactive")) + cache = btoi (clgetb ("cache")) + verify = btoi (clgetb ("verify")) + update = btoi (clgetb ("update")) + verbose = btoi (clgetb ("verbose")) + + # Intialize the phot structure. + call ap_gwppars (ap) + + # Confirm the algorithm parameters. + if (verify == YES && interactive == NO) { + call ap_wconfirm (ap, NULL, 1) + if (update == YES) + call ap_wpars (ap) + } + + # Get the wcs information. + wcs = clgwrd ("wcsin", Memc[str], SZ_LINE, WCSINSTR) + if (wcs <= 0) { + call eprintf ( + "Warning: Setting the input coordinate system to logical\n") + wcs = WCS_LOGICAL + } + call apseti (ap, WCSIN, wcs) + wcs = clgwrd ("wcsout", Memc[str], SZ_LINE, WCSOUTSTR) + if (wcs <= 0) { + call eprintf ( + "Warning: Setting the output coordinate system to logical\n") + wcs = WCS_LOGICAL + } + call apseti (ap, WCSOUT, wcs) + + # Get the graphics and display devices. + call clgstr ("graphics", Memc[graphics], SZ_FNAME) + call clgstr ("display", Memc[display], SZ_FNAME) + + # Open the plot files. + if (interactive == YES) { + if (Memc[graphics] == EOS) + gd = NULL + else { + iferr { + gd = gopen (Memc[graphics], APPEND+AW_DEFER, STDGRAPH) + } then { + call eprintf ( + "Warning: Error opening graphics device.\n") + gd = NULL + } + } + if (Memc[display] == EOS) + id = NULL + else if (streq (Memc[graphics], Memc[display])) + id = gd + else { + iferr { + id = gopen (Memc[display], APPEND, STDIMAGE) + } then { + call eprintf ( + "Warning: Graphics overlay not available for display device.\n") + id = NULL + } + } + } else { + gd = NULL + id = NULL + } + + # Open the plot metacode file. + call clgstr ("plotfile", Memc[plotfile], SZ_FNAME) + if (Memc[plotfile] == EOS) + pfd = NULL + else + pfd = open (Memc[plotfile], APPEND, BINARY_FILE) + if (pfd != NULL) + mgd = gopen (Memc[graphics], NEW_FILE, pfd) + else + mgd = NULL + + # Get the file name for the sky values. + if (apstati (ap, SKYFUNCTION) == AP_SKYFILE) { + slist = clpopnu ("skyfile") + lslist = clplen (slist) + if (limlist < 1 || (lslist > 1 && lslist != limlist)) { + call imtclose (imlist) + call clpcls (clist) + call clpcls (olist) + call clpcls (slist) + call error (0, "Imcompatible image and sky file list lengths") + } + } else + sd = NULL + + # Begin looping over the image list. + sid = 1 + while (imtgetim (imlist, Memc[image], SZ_FNAME) != EOF) { + + # Open the image and store image parameters. + im = immap (Memc[image], READ_ONLY, 0) + call apimkeys (ap, im, Memc[image]) + + # Set the image display viewport. + if ((id != NULL) && (id != gd)) + call ap_gswv (id, Memc[image], im, 4) + + # Cache the input image pixels. + req_size = MEMFUDGE * IM_LEN(im,1) * IM_LEN(im,2) * + sizeof (IM_PIXTYPE(im)) + memstat = ap_memstat (cache, req_size, old_size) + if (memstat == YES) + call ap_pcache (im, INDEFI, buf_size) + + # Open the coordinate file, where coords is assumed to be a simple + # text file in which the x and y positions are in columns 1 and 2 + # respectively and all remaining fields are ignored. + + if (lclist <= 0) { + cl = NULL + call strcpy ("", Memc[outfname], SZ_FNAME) + } else { + stat = clgfil (clist, Memc[coords], SZ_FNAME) + root = fnldir (Memc[coords], Memc[outfname], SZ_FNAME) + if (strncmp ("default", Memc[coords+root], 7) == 0 || root == + strlen (Memc[coords])) { + call ap_inname (Memc[image], Memc[outfname], "coo", + Memc[outfname], SZ_FNAME) + lclist = limlist + cl = open (Memc[outfname], READ_ONLY, TEXT_FILE) + } else if (stat != EOF) { + call strcpy (Memc[coords], Memc[outfname], SZ_FNAME) + cl = open (Memc[outfname], READ_ONLY, TEXT_FILE) + } else { + call apstats (ap, CLNAME, Memc[outfname], SZ_FNAME) + call seek (cl, BOF) + } + } + call apsets (ap, CLNAME, Memc[outfname]) + call apfroot (Memc[outfname], Memc[str], SZ_LINE) + call apsets (ap, CLROOT, Memc[str]) + + # Open the skys file. + if (lslist <= 0) { + sd = NULL + call strcpy ("", Memc[skyfile], SZ_FNAME) + } else if (clgfil (slist, Memc[skyfile], SZ_FNAME) != EOF) + sd = open (Memc[skyfile], READ_ONLY, TEXT_FILE) + else + call seek (sd, BOF) + #call apsets (ap, SKYNAME, Memc[skyfile]) + + # Open the output text file, if output is "default", dir$default + # or a directory specification then the extension "mag" is added + # to the image name and a suitable version number is appended to + # the output name. If the output name is null then no output + # file is created. + + if (lolist == 0) { + out = NULL + call strcpy ("", Memc[outfname], SZ_FNAME) + } else { + stat = clgfil (olist, Memc[output], SZ_FNAME) + root = fnldir (Memc[output], Memc[outfname], SZ_FNAME) + if (strncmp ("default", Memc[output+root], 7) == 0 || root == + strlen (Memc[output])) { + call apoutname (Memc[image], Memc[outfname], "omag", + Memc[outfname], SZ_FNAME) + out = open (Memc[outfname], NEW_FILE, TEXT_FILE) + lolist = limlist + } else if (stat != EOF) { + call strcpy (Memc[output], Memc[outfname], SZ_FNAME) + out = open (Memc[outfname], NEW_FILE, TEXT_FILE) + } else + call apstats (ap, OUTNAME, Memc[outfname], SZ_FNAME) + } + call apsets (ap, OUTNAME, Memc[outfname]) + + # Do aperture photometry. + if (interactive == NO) { + if (Memc[cname] != EOS) + stat = ap_wphot (ap, im, cl, sd, NULL, mgd, NULL, out, + sid, NO, cache) + else if (cl != NULL) { + lid = 1 + call ap_bwphot (ap, im, cl, sd, out, sid, lid, gd, mgd, id, + verbose) + stat = NO + } else + stat = NO + } else + stat = ap_wphot (ap, im, cl, sd, gd, mgd, id, out, sid, YES, + cache) + + # Cleanup. + call imunmap (im) + if (cl != NULL) { + if (lclist > 1) + call close (cl) + } + if (sd != NULL) { + if (lslist > 1) + call close (sd) + } + if (out != NULL && lolist != 1) { + call close (out) + if (sid <= 1) { + call apstats (ap, OUTNAME, Memc[outfname], SZ_FNAME) + call delete (Memc[outfname]) + } + sid = 1 + } + + # Uncache memory. + call fixmem (old_size) + + if (stat == YES) + break + } + + + # Close the coordinate, sky and output files. + if (cl != NULL && lclist == 1) + call close (cl) + if (sd != NULL && lslist == 1) + call close (sd) + if (out != NULL && lolist == 1) { + call close (out) + if (sid <= 1) { + call apstats (ap, OUTNAME, Memc[outfname], SZ_FNAME) + call delete (Memc[outfname]) + } + } + + # Close up plot files + if (id == gd && id != NULL) + call gclose (id) + else { + if (gd != NULL) + call gclose (gd) + if (id != NULL) + call gclose (id) + } + if (mgd != NULL) + call gclose (mgd) + if (pfd != NULL) + call close (pfd) + + # Free the photometry structures. + call appfree (ap) + + # Close the coord, sky and image lists. + call imtclose (imlist) + call clpcls (clist) + if (sd != NULL) + call clpcls (slist) + call clpcls (olist) + call sfree (sp) +end diff --git a/noao/digiphot/apphot/wphot/wphot.key b/noao/digiphot/apphot/wphot/wphot.key new file mode 100644 index 00000000..808bf923 --- /dev/null +++ b/noao/digiphot/apphot/wphot/wphot.key @@ -0,0 +1,109 @@ + Interactive Photometry Commands + +? Print help +: Colon commands +v Verify the critical parameters +w Store the current parameters +d Plot radial profile of current star +i Interactively set parameters using current star +c Fit center of current star +t Fit sky around cursor +a Average sky values fit around several cursor positions +s Fit sky around the current star +p Do photometry for current star, using current sky +o Do photometry for current star, using current sky, output results +f Do photometry for current star +spbar Do photometry for current star, output results +m Move to next star in coordinate list +n Do photometry for next star in coordinate list, output results +l Do photometry for remaining stars in coordinate list, output results +r Rewind the coordinate list +e Print error messages +q Exit task + + + Colon Commands + +:show [data/center/sky/fit] Show parameters +:m [n] Move to next [nth] star in the coordinate list +:n [n] Do photometry for next [nth] star in coordinate list, output results + + + Colon Parameter Editing Commands + +# Image and file parameters + +:image [string] Image name +:coords [string] Coordinate file name +:output [string] Output file name + +# Data dependent parameters + +:scale [value] Image scale (units per pixel) +:fwhmpsf [value] Full-width half-maximum of PSF (scale units) +:emission [y/n] Emission features (y), absorption (n) +:sigma [value] Standard deviation of sky (counts) +:datamin [value] Minimum good pixel value (counts) +:datamax [value] Maximum good pixel value (counts) + +# Noise parameters + +:noise [string] Noise model (constant|poisson) +:gain [string] Gain image header keyword +:ccdread [string] Readout noise image header keyword +:epadu [value] Gain (electrons per adu) +:readnoise [value] Readout noise (electrons) + +# Observations parameters + +:exposure [string] Exposure time image header keyword +:airmass [string] Airmass image header keyword +:filter [string] Filter image header keyword +:obstime [string] Time of observation image header keyword +:itime [value] Integration time (time units) +:xairmass [value] Airmass value (number) +:ifilter [string] Filter id string +:otime [string] Time of observations (time units) + +# Centering algorithm parameters + +:calgorithm [string] Centering algorithm +:cbox [value] Width of the centering box (scale units) +:cthreshold [value] Centering intensity threshold (sigma) +:cmaxiter [value] Maximum number of iterations +:maxshift [value] Maximum center shift (scale units) +:minsnratio [value] Minimum S/N ratio for centering +:clean [y/n] Clean subraster before centering +:rclean [value] Cleaning radius (scale units) +:rclip [value] Clipping radius (scale units) +:kclean [value] Clean K-sigma rejection limit (sigma) + +# Sky fitting algorithm parameters + +:salgorithm [string] Sky fitting algorithm +:skyvalue [value] User supplied sky value (counts) +:annulus [value] Inner radius of sky annulus (scale units) +:dannulus [value] Width of sky annulus (scale units) +:khist [value] Sky histogram extent (+/- sigma) +:binsize [value] Resolution of sky histogram (sigma) +:smooth [y/n] Lucy smooth the sky histogram +:sloclip [value] Low-side clipping factor in percent +:shiclip [value] High-side clipping factor in percent +:smaxiter [value] Maximum number of iterations +:snreject [value] Maximum number of rejection cycles +:sloreject [value] Low-side pixel rejection limits (sky sigma) +:shireject [value] High-side pixel rejection limits (sky sigma) +:rgrow [value] Region growing radius (scale units) + +# Photometry parameters + +:weighting [string] Weighting function (constant|cone|gauss) +:apertures [string] List of aperture radii (scale units) +:zmag [value] Zero point of magnitude scale + +# Plotting and marking parameters + +:mkcenter [y/n] Mark computed centers on display +:mksky [y/n] Mark the sky annuli on the display +:mkapert [y/n] Mark apertures on the display +:radplot [y/n] Plot radial profile of object diff --git a/noao/digiphot/apphot/x_apphot.x b/noao/digiphot/apphot/x_apphot.x new file mode 100644 index 00000000..33c73ed1 --- /dev/null +++ b/noao/digiphot/apphot/x_apphot.x @@ -0,0 +1,12 @@ +# Task statements for the apphot package + +task center = t_center, + daofind = t_daofind, + fitpsf = t_fitpsf, + fitsky = t_fitsky, + wphot = t_wphot, + phot = t_phot, + polymark = t_polymark, + polyphot = t_polyphot, + qphot = t_qphot, + radprof = t_radprof |