Skip to content

Commit

Permalink
KAPPA: Write BEAMFIT statistics to output parameters for all beams.
Browse files Browse the repository at this point in the history
This applies to Parameters AMP, BACK, CENTRE, GAMMA, MAJFWHM, MINFWHM,
and ORIENT.  The parameters objects are still vectors looping
over value then error for each beam.
  • Loading branch information
MalcolmCurrie committed Jul 30, 2013
1 parent 25c1b74 commit 2a9c62e
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 90 deletions.
2 changes: 1 addition & 1 deletion applications/kappa/component.xml
Expand Up @@ -3,7 +3,7 @@
<!-- component.xml. Generated from component.xml.in by configure. -->

<component id="kappa" support="S">
<version>2.1-3</version>
<version>2.1-4</version>
<path>applications/kappa</path>
<description>KAPPA - Kernel Application Package</description>
<abstract><p>
Expand Down
2 changes: 1 addition & 1 deletion applications/kappa/configure.ac
Expand Up @@ -2,7 +2,7 @@ dnl Process this file with autoconf to produce a configure script
AC_REVISION($Revision$)

dnl Initialisation: package name and version number
AC_INIT(kappa, 2.1-3, starlink@jiscmail.ac.uk)
AC_INIT(kappa, 2.1-4, starlink@jiscmail.ac.uk)

dnl Require autoconf-2.50 at least
AC_PREREQ(2.50)
Expand Down
3 changes: 3 additions & 0 deletions applications/kappa/kappa.news.in
Expand Up @@ -18,6 +18,9 @@
values should be fixed. FWHM allows you to set actual sizes or
initial guesses.

- The output parameters now store the statistics of every
fitted beam, not just those of the primary beam.

o DISPLAY

- The MODE parameter can now be set to "Current" to force the
Expand Down
138 changes: 85 additions & 53 deletions applications/kappa/kapsub/kps1_bfop.f
Expand Up @@ -15,10 +15,10 @@ SUBROUTINE KPS1_BFOP( RFRM, NAXR, NP, P, SIGMA, NBEAM,
* POLAR, POLSIG, RMS, STATUS )

* Description:
* The supplied generalised Gaussian parameters from BEAMFIT are
* written to the environment. Each output parameter is a two-element
* vector containing the fit coefficient in the first element, and its
* error in the second, applicable to the primary beam.
* The supplied generalised Gaussian parameters from BEAMFIT are
* written to the environment. Each output parameter is a vector
* containing pairs of elements for each beam. The first of each
* pair is the fit coefficient, and its error is in the second.
*
* The parameters written are as follows.
*
Expand Down Expand Up @@ -65,12 +65,10 @@ SUBROUTINE KPS1_BFOP( RFRM, NAXR, NP, P, SIGMA, NBEAM,
* P( NP ) = DOUBLE PRECISION (Given)
* The fit parameters. Spatial co-ordinates should be measured
* in the reporting Frame. See KPS1_BFCRF to convert from
* PIXEL co-ordinates. Only the first BF_MXCOEF elements are
* used.
* PIXEL co-ordinates.
* SIGMA( NP ) = DOUBLE PRECISION (Given)
* The errors in the fit parameters. Spatial co-ordinates should
* be measured in the reporting Frame. Only the first BF_MXCOEF
* elements are used.
* be measured in the reporting Frame.
* NBEAM = INTEGER (Given)
* The number of beam positions.
* REFOFF( 2 ) = DOUBLE PRECISION (Given)
Expand Down Expand Up @@ -147,6 +145,8 @@ SUBROUTINE KPS1_BFOP( RFRM, NAXR, NP, P, SIGMA, NBEAM,
* Removed no-longer-used argument MAP.
* 2013 July 16 (MJC):
* Use circular constraint.
* 2013 July 29 (MJC):
* Output parameters for every beam.
* {enter_further_changes_here}

*-
Expand Down Expand Up @@ -185,7 +185,7 @@ SUBROUTINE KPS1_BFOP( RFRM, NAXR, NP, P, SIGMA, NBEAM,

* Local Constants:
INTEGER BUFSIZ ! Buffers' dimension
PARAMETER ( BUFSIZ = 2 * ( BF__MXPOS - 1 ) )
PARAMETER ( BUFSIZ = 2 * BF__MXPOS )
DOUBLE PRECISION PI
PARAMETER ( PI = 3.1415926535898 )
Expand All @@ -196,6 +196,7 @@ SUBROUTINE KPS1_BFOP( RFRM, NAXR, NP, P, SIGMA, NBEAM,
* Local Variables:
CHARACTER*9 ATTR ! Buffer for attribute name
CHARACTER*50 AXVAL ! A formatted axis value
INTEGER BOFF ! Buffer offset for each beam
CHARACTER*12 FMAT( 2 ) ! SkyFrame format
INTEGER IAT ! No. of characters currently in buffer
INTEGER IB ! Beam loop counter
Expand All @@ -204,10 +205,12 @@ SUBROUTINE KPS1_BFOP( RFRM, NAXR, NP, P, SIGMA, NBEAM,
INTEGER K ! Loop count
INTEGER LAT ! Index to latitude axis in SkyFrame
CHARACTER*128 LINE( BUFSIZ ) ! Buffer for output text
DOUBLE PRECISION S2FWHM ! Sigma-to-FWHM conversion
INTEGER NEL ! Number of output-parameter elements
INTEGER POFF ! Offset for each beam's fit parameters
INTEGER PREC( 2 ) ! Number of digits of precision
DOUBLE PRECISION S2FWHM ! Sigma-to-FWHM conversion
LOGICAL TIME( 2 ) ! Coordinates formatted as times?
DOUBLE PRECISION WORK( 2 ) ! Work array for storing values
DOUBLE PRECISION WORK( BUFSIZ ) ! Work array for storing values
! and errors
REAL WORKER( BUFSIZ ) ! Work array for storing values
! and errors
Expand Down Expand Up @@ -257,78 +260,107 @@ SUBROUTINE KPS1_BFOP( RFRM, NAXR, NP, P, SIGMA, NBEAM,
* Now write the primary-beam position out to the output parameters.
* The complete set of axis values (separated by spaces) is written to
* a buffer.
IAT = 0
LINE( 1 ) = ' '
DO J = 1, NAXR
AXVAL = AST_FORMAT( RFRM, J, P( J ), STATUS )
CALL CHR_APPND( AXVAL, LINE( 1 ), IAT )
IAT = IAT + 1
END DO
DO IB = 1, NBEAM
BOFF = ( IB - 1 ) * 2
POFF = ( IB - 1 ) * BF__NCOEF
IAT = 0
LINE( 1 + BOFF ) = ' '

DO J = 1, NAXR
AXVAL = AST_FORMAT( RFRM, J, P( J + POFF ), STATUS )
CALL CHR_APPND( AXVAL, LINE( 1 + BOFF ), IAT )
IAT = IAT + 1
END DO

* Record the errors in the second element of the buffer.
IAT = 0
LINE( 2 ) = ' '
DO J = 1, NAXR
IF ( SIGMA( J ) .NE. VAL__BADD ) THEN
AXVAL = AST_FORMAT( RFRM, J, SIGMA( J ), STATUS )
ELSE
AXVAL = 'bad'
END IF
CALL CHR_APPND( AXVAL, LINE( 2 ), IAT )
IAT = IAT + 1
IAT = 0
LINE( 2 + BOFF ) = ' '
DO J = 1, NAXR
IF ( SIGMA( J ) .NE. VAL__BADD ) THEN
AXVAL = AST_FORMAT( RFRM, J, SIGMA( J + POFF ), STATUS )
ELSE
AXVAL = 'bad'
END IF
CALL CHR_APPND( AXVAL, LINE( 2 + BOFF ), IAT )
IAT = IAT + 1
END DO
END DO

* Record the formattd co-ordinates and correspending errors in the
* output parameter.
CALL PAR_PUT1C( 'CENTRE', 2, LINE, STATUS )
CALL PAR_PUT1C( 'CENTRE', 2 * NBEAM, LINE, STATUS )

* FWHMs
* =====
S2FWHM = SQRT( 8.D0 * LOG( 2.D0 ) )

WORK( 1 ) = P( 3 ) * S2FWHM
WORK( 2 ) = SIGMA( 3 ) * S2FWHM
CALL PAR_PUT1D( 'MAJFWHM', 2, WORK, STATUS )
DO IB = 1, NBEAM
BOFF = ( IB - 1 ) * 2
POFF = ( IB - 1 ) * BF__NCOEF
WORK( 1 + BOFF ) = P( 3 + POFF ) * S2FWHM
WORK( 2 + BOFF ) = SIGMA( 3 + POFF ) * S2FWHM
END DO
CALL PAR_PUT1D( 'MAJFWHM', 2 * NBEAM, WORK, STATUS )

WORK( 1 ) = P( 4 ) * S2FWHM
WORK( 2 ) = SIGMA( 4 ) * S2FWHM
CALL PAR_PUT1D( 'MINFWHM', 2, WORK, STATUS )
DO IB = 1, NBEAM
BOFF = ( IB - 1 ) * 2
POFF = ( IB - 1 ) * BF__NCOEF
WORK( 1 + BOFF ) = P( 4 + POFF ) * S2FWHM
WORK( 2 + BOFF ) = SIGMA( 4 + POFF ) * S2FWHM
END DO
NEL = 2 * NBEAM
CALL PAR_PUT1D( 'MINFWHM', NEL, WORK, STATUS )

* ORIENT
* ======

* Convert to degrees. May need a +/- 90 later...
IF ( CIRC ) THEN
WORK( 1 ) = 0.0D0
WORK( 2 ) = 0.0D0
ELSE
WORK( 1 ) = P( 5 ) * R2D
WORK( 2 ) = SIGMA( 5 ) * R2D
END IF
CALL PAR_PUT1D( 'ORIENT', 2, WORK, STATUS )
DO IB = 1, NBEAM
BOFF = ( IB - 1 ) * 2
POFF = ( IB - 1 ) * BF__NCOEF
IF ( CIRC ) THEN
WORK( 1 + BOFF ) = 0.0D0
WORK( 2 + BOFF ) = 0.0D0
ELSE
WORK( 1 + BOFF ) = P( 5 + POFF ) * R2D
WORK( 2 + BOFF ) = SIGMA( 5 + POFF ) * R2D
END IF
END DO
CALL PAR_PUT1D( 'ORIENT', NEL, WORK, STATUS )

* AMP
* ===
WORK( 1 ) = P( 6 )
WORK( 2 ) = SIGMA( 6 )
CALL PAR_PUT1D( 'AMP', 2, WORK, STATUS )
DO IB = 1, NBEAM
BOFF = ( IB - 1 ) * 2
POFF = ( IB - 1 ) * BF__NCOEF
WORK( 1 + BOFF ) = P( 6 + POFF )
WORK( 2 + BOFF ) = SIGMA( 6 + POFF )
END DO
CALL PAR_PUT1D( 'AMP', NEL, WORK, STATUS )

* BACK
* ====
WORK( 1 ) = P( 7 )
WORK( 2 ) = SIGMA( 7 )
CALL PAR_PUT1D( 'BACK', 2, WORK, STATUS )
DO IB = 1, NBEAM
BOFF = ( IB - 1 ) * 2
POFF = ( IB - 1 ) * BF__NCOEF
WORK( 1 + BOFF ) = P( 7 + POFF )
WORK( 2 + BOFF ) = SIGMA( 7 + POFF )
END DO
CALL PAR_PUT1D( 'BACK', NEL, WORK, STATUS )

* RMS
* ===
CALL PAR_PUT0R( 'RMS', SNGL( RMS ), STATUS )

* GAMMA
* =====
WORK( 1 ) = P( 8 )
WORK( 2 ) = SIGMA( 8 )
CALL PAR_PUT1D( 'GAMMA', 2, WORK, STATUS )
DO IB = 1, NBEAM
BOFF = ( IB - 1 ) * 2
POFF = ( IB - 1 ) * BF__NCOEF
WORK( 1 + BOFF ) = P( 8 + POFF )
WORK( 2 + BOFF ) = SIGMA( 8 + POFF )
END DO
CALL PAR_PUT1D( 'GAMMA', NEL, WORK, STATUS )

* OFFSET of primary beam
* ======================
Expand Down
35 changes: 19 additions & 16 deletions applications/kappa/libkappa/beamfit.f
Expand Up @@ -73,8 +73,8 @@ SUBROUTINE BEAMFIT ( STATUS )
* mode

* ADAM Parameters:
* AMP( 2 ) = _DOUBLE (Write)
* The primary beam position's amplitude and its error.
* AMP( 2 * BEAMS ) = _DOUBLE (Write)
* The amplitude and its error for each beam.
* AMPRATIO( ) = _REAL (Read)
* If number of beam positions given by BEAMS is more than one,
* this specifies the ratio of the amplitude of the secondary
Expand All @@ -83,8 +83,8 @@ SUBROUTINE BEAMFIT ( STATUS )
* ratio is copied to the missing values. The ratios would
* normally be negative, usually -1 or -0.5. AMPRATIO is ignored
* when there is only one beam feature to fit. [!]
* BACK( 2 ) = _DOUBLE (Write)
* The primary beam position's background level and its error.
* BACK( 2 * BEAMS ) = _DOUBLE (Write)
* The background level and its error at each beam position.
* BEAMS = _INTEGER (Read)
* The number of beam positions to fit. This will normally be 1,
* unless a chopped observation is supplied, when there may be two
Expand All @@ -95,9 +95,9 @@ SUBROUTINE BEAMFIT ( STATUS )
* on the command line without BEAMS. In all modes there is a
* maximum of five positions, which for "File" or "Catalogue"
* modes will be the first five. [1]
* CENTRE( 2 ) = LITERAL (Write)
* The formatted co-ordinates and their errors of the primary
* beam in the current co-ordinate Frame of the NDF.
* CENTRE( 2 * BEAMS ) = LITERAL (Write)
* The formatted co-ordinates and their errors of each beam in
* the current co-ordinate Frame of the NDF.
* CIRCULAR = _LOGICAL (Read)
* If set TRUE only circular beams will be fit. [FALSE]
* COIN = FILENAME (Read)
Expand Down Expand Up @@ -181,7 +181,7 @@ SUBROUTINE BEAMFIT ( STATUS )
* Null requests that BEAMFIT itself estimates the initial FWHM
* values. [!]
* GAMMA( 2 ) = _DOUBLE (Write)
* The primary beam position's shape exponent and its error.
* The shape exponent and its error for each beam.
* GAUSS = _LOGICAL (Read)
* If TRUE, the shape exponent is fixed to be 2; in other words
* the beams are modelled as two-dimensional normal distributions.
Expand All @@ -197,8 +197,8 @@ SUBROUTINE BEAMFIT ( STATUS )
* will be no logging. Note this is intended for the human reader
* and is not intended for passing to other applications. [!]
* MAJFWHM( 2 ) = _DOUBLE (Write)
* The primary beam position's major-axis FWHM and its error,
* measured in the current co-ordinate Frame of the NDF.
* The major-axis FWHM and its error, measured in the current
* co-ordinate Frame of the NDF, for each beam.
* MARK = LITERAL (Read)
* Only accessed if Parameter MODE is given the value "Cursor".
* It indicates which positions are to be marked on the screen
Expand All @@ -224,8 +224,8 @@ SUBROUTINE BEAMFIT ( STATUS )
* dot, 2 gives a cross, 3 gives an asterisk, 7 gives a triangle.
* The value must be larger than or equal to -31. [current value]
* MINFWHM( 2 ) = _DOUBLE (Write)
* The primary beam position's minor-axis FWHM and its error,
* measured in the current co-ordinate Frame of the NDF.
* The minor-axis FWHM and its error, measured in the current
* co-ordinate Frame of the NDF, for each beam.
* MODE = LITERAL (Read)
* The mode in which the initial co-ordinates are to be obtained.
* The supplied string can be one of the following values.
Expand Down Expand Up @@ -256,9 +256,9 @@ SUBROUTINE BEAMFIT ( STATUS )
* number of values stored is twice the number of beams. The
* array alternates an offset, then its corresponding error,
* appearing in beam order starting with the first secondary beam.
* ORIENT( 2 ) = _DOUBLE (Write)
* The primary beam position's orientation and its error, measured
* in degrees. If the current WCS frame is a SKY Frame, the angle
* ORIENT( 2 * BEAMS ) = _DOUBLE (Write)
* The orientation and its error, measured in degrees for each
* beam. If the current WCS frame is a SKY Frame, the angle
* is measured from North through East. For other Frames the
* angle is from the X-axis through Y.
* PA() = _REAL (Write)
Expand Down Expand Up @@ -362,7 +362,7 @@ SUBROUTINE BEAMFIT ( STATUS )
* REFOFF( 2 ) = LITERAL (Write)
* The formatted offset followed by its error of the primary
* beam's location with respect to the reference position (see
* Parameter REFPOS). The offset might be used to assess the
* Parameter REFPOS). The offset might be used to assess the
* optical alignment of an instrument. The ofset and its error
* are measured in the current Frame of the NDF along a latitude
* axis if that Frame is in the SKY Domain, or the first axis
Expand Down Expand Up @@ -603,6 +603,9 @@ SUBROUTINE BEAMFIT ( STATUS )
* Add CIRCULAR parameter and set new COMMON constraint flag.
* Extended FIXFWHM to FWHM to encompass initial guesses. Made new
* _LOGICAL FIXFWHM parameter solely to set fixed FWHM values.
* 2013 July 29 (MJC):
* Seven output parameters now record the fit statistics for all
* beams, not just for the primary.
* {enter_further_changes_here}

*-
Expand Down

0 comments on commit 2a9c62e

Please sign in to comment.