Skip to content

Commit

Permalink
smurf: Flag bad variances when importing an external NOI model
Browse files Browse the repository at this point in the history
This affects skyloop reductions. Samples with unusable variance
values were not being flagged as unusable.
  • Loading branch information
David Berry committed May 15, 2014
1 parent e3fdd58 commit a5e077a
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 22 deletions.
8 changes: 4 additions & 4 deletions applications/smurf/libsmf/smf.h.source
Expand Up @@ -1428,7 +1428,7 @@ void smf_import_array( ThrWorkForce *wf, smfData *refdata, const char *name, in
int expand, smf_dtype type, void *dataptr, int *status );

int smf_import_noi( const char *name, smfDIMMHead *head, AstKeyMap *keymap,
double *dataptr, int *status );
smfData *qua, double *dataptr, int *status );

void smf_inbeam_str ( smf_inbeam_t inbeam, char *inbeamstr, size_t lenstr, int * status );

Expand Down Expand Up @@ -1552,9 +1552,9 @@ void smf_model_create( ThrWorkForce *wf, const smfGroup *igroup,
const smfArray *bbms, const smfArray *flatramps,
AstKeyMap * heateffmap, const smfArray *noisemaps,
dim_t nchunks, smf_modeltype mtype, int isTordered,
AstFrameSet *outfset, int moving,
int *lbnd_out, int *ubnd_out, fts2Port fts_port,
smfGroup **mgroup, smfArray **mdata,
AstFrameSet *outfset, int moving, int *lbnd_out,
int *ubnd_out, fts2Port fts_port,
smfArray **qua, smfGroup **mgroup, smfArray **mdata,
AstKeyMap *keymap, int *status );

void smf_model_createHdr( smfData *model, smf_modeltype type,
Expand Down
2 changes: 1 addition & 1 deletion applications/smurf/libsmf/smf_clean_pca.c
Expand Up @@ -847,7 +847,7 @@ void smf_clean_pca( ThrWorkForce *wf, smfData *data, size_t t_first,

smf_model_create( wf, NULL, &data_array, NULL, NULL, NULL,NULL, NULL, 1,
SMF__GAI, data->isTordered, NULL, 0, NULL, NULL,
NO_FTS, &gain_group, &gain_array, keymap, status );
NO_FTS, NULL, &gain_group, &gain_array, keymap, status );

/* Compare bolometers to the template in order to flag outliers */
smf_find_gains( wf, 0, data, NULL, NULL, template, kmap, SMF__Q_GOOD,
Expand Down
8 changes: 4 additions & 4 deletions applications/smurf/libsmf/smf_clean_smfArray.c
Expand Up @@ -439,12 +439,12 @@ void smf_clean_smfArray( ThrWorkForce *wf, smfArray *array,

/* Create model containers for COM, GAI */
smf_model_create( wf, NULL, &array, NULL, NULL, NULL, NULL, NULL, 1, SMF__COM,
0, NULL, 0, NULL, NULL, NO_FTS, &comgroup, &comdata, keymap,
status );
0, NULL, 0, NULL, NULL, NO_FTS, NULL, &comgroup, &comdata,
keymap, status );

smf_model_create( wf, NULL, &array, NULL, NULL, NULL, NULL, NULL, 1, SMF__GAI,
0, NULL, 0, NULL, NULL, NO_FTS, &gaigroup, &gaidata, keymap,
status );
0, NULL, 0, NULL, NULL, NO_FTS, NULL, &gaigroup, &gaidata,
keymap, status );

/* Manually create quadata to share memory with the quality already
stored in array */
Expand Down
55 changes: 51 additions & 4 deletions applications/smurf/libsmf/smf_import_noi.c
Expand Up @@ -14,7 +14,8 @@
* Invocation:
* int smf_import_noi( const char *name, smfDIMMHead *head,
* AstKeyMap *keymap, double *dataptr, int *status )
* AstKeyMap *keymap, smfData *qua,
* double *dataptr, int *status )
* Arguments:
* name = const char * (Given)
Expand All @@ -23,6 +24,9 @@
* Defines the shape and size of the NOI model.
* *keymap = AstKeyMap * (Given)
* The config parameters for makemap.
* qua = smfData * (Given and Returned)
* The associated quality data - bad or non-positive noise values
* are flagged with SMF__Q_NOISE. May be NULL.
* dataptr = double * (Returned)
* The array in which to return the noise values.
* status = int* (Given and Returned)
Expand All @@ -46,9 +50,11 @@
* 24-SEP-2013 (DSB):
* Original version.
* 24-JAN-2014 (DSB):
* - Re-written to follow the changes to smf_export_noi (the time axis
* is now the first axis in the NDF, not the third axis).
* - Re-written to follow the changes to smf_export_noi (the time axis
* is now the first axis in the NDF, not the third axis).
* - Remove argument "noi_boxsize".
* 15-MAY-2014 (DSB):
* Flag bad variances in the quality array.
* {enter_further_changes_here}
* Copyright:
Expand Down Expand Up @@ -86,7 +92,7 @@
#include "libsmf/smf.h"

int smf_import_noi( const char *name, smfDIMMHead *head, AstKeyMap *keymap,
double *dataptr, int *status ){
smfData *qua, double *dataptr, int *status ){

/* Local Variables */
AstKeyMap *kmap = NULL;
Expand Down Expand Up @@ -231,6 +237,47 @@ int smf_import_noi( const char *name, smfDIMMHead *head, AstKeyMap *keymap,
/* Close the NDF. */
ndfAnnul( &indf, status );

/* If a quality array was supplied, flag any samples that have unusable
noise values (i.e. bad or non-positive). */
if( qua ) {
size_t qbstride;
size_t qtstride;
dim_t qntslice;
smf_qual_t *pq;

/* Get the dimensions and strides for the Quality array. */
smf_get_dims( qua, NULL, NULL, NULL, &qntslice, NULL,
&qbstride, &qtstride, status );

/* Loop round each bolometer. */
for( ibolo = 0; ibolo < nbolo; ibolo++ ) {

/* Pointers to the first quality and noise values for this bolometer. */
pq = (smf_qual_t *) qua->pntr[0] + ibolo*qbstride;
pd = dataptr + ibolo*bstride;

/* Ignore entirely bad bolometers. */
if( !( *pq & SMF__Q_BADB ) ) {

/* Loop round each time slice. */
for( itime = 0; itime < qntslice; itime++ ) {

/* If the noise value is bad or non-positive, flag the sample with
the SMF__Q_NOISE flag. */
if( *pd == VAL__BADD || *pd <= 0.0 ) *pq |= SMF__Q_NOISE;

/* Move the quality pointer on to the next time slice. */
pq += qtstride;

/* The noise pointer only needs to be moved on if there is more than one
noise value per bolometer (in which case there will be the same number
of noise values as there are quality values). */
if( ntslice > 1 ) pd += tstride;
}
}
}
}

/* Add a context message if anything went wrong. */
if( *status != SAI__OK ) {
errRepf( "", "Failed to import NOI values from NDF specified "
Expand Down
8 changes: 4 additions & 4 deletions applications/smurf/libsmf/smf_iteratemap.c
Expand Up @@ -1474,7 +1474,7 @@ void smf_iteratemap( ThrWorkForce *wf, const Grp *igrp, const Grp *iterrootgrp,

smf_model_create( wf, NULL, res, darks, bbms, flatramps, heateffmap,
NULL, 1, SMF__QUA, 0, NULL, 0, NULL, NULL, NO_FTS,
NULL, qua, keymap, status );
NULL, NULL, qua, keymap, status );

/* Associate quality with the res model, and do cleaning before we
start using more memory for other things. Note that we are
Expand All @@ -1496,7 +1496,7 @@ void smf_iteratemap( ThrWorkForce *wf, const Grp *igrp, const Grp *iterrootgrp,

smf_model_create( wf, NULL, res, darks, bbms, flatramps, heateffmap,
NULL, 1, SMF__LUT, 0, NULL, 0, NULL, NULL, NO_FTS,
NULL, lut, keymap, status );
qua, NULL, lut, keymap, status );

if( *status == SAI__OK ) {
for( idat = 0; idat < res[0]->ndat; idat++ ) {
Expand All @@ -1514,7 +1514,7 @@ void smf_iteratemap( ThrWorkForce *wf, const Grp *igrp, const Grp *iterrootgrp,
if( haveext ) {
smf_model_create( wf, NULL, res, darks, bbms, flatramps, heateffmap,
noisemaps, 1, modeltyps[whichext], 0, NULL, 0, NULL,
NULL, NO_FTS, NULL, model[whichext], keymap, status);
NULL, NO_FTS, qua, NULL, model[whichext], keymap, status);
}

/*** TIMER ***/
Expand Down Expand Up @@ -1711,7 +1711,7 @@ void smf_iteratemap( ThrWorkForce *wf, const Grp *igrp, const Grp *iterrootgrp,
(modeltyps[imodel] != SMF__AST) ) {
smf_model_create( wf, NULL, res, darks, bbms, flatramps, heateffmap,
noisemaps, 1, modeltyps[imodel], 0, NULL, 0, NULL, NULL,
NO_FTS, NULL, model[imodel], keymap, status );
NO_FTS, qua, NULL, model[imodel], keymap, status );
}

/* Associate quality with some models */
Expand Down
16 changes: 11 additions & 5 deletions applications/smurf/libsmf/smf_model_create.c
Expand Up @@ -19,8 +19,9 @@
* AstKeyMap * heateffmap, const smfArray *noisemaps,
* dim_t nchunks, smf_modeltype mtype, int isTordered,
* AstFrameSet *outfset, int moving, int *lbnd_out,
* int *ubnd_out, fts2Port fts_port, smfGroup **mgroup,
* smfArray **mdata, AstKeyMap *keymap, int *status )
* int *ubnd_out, fts2Port fts_port, smfArray **qua,
* smfGroup **mgroup, smfArray **mdata,
* AstKeyMap *keymap, int *status )
* Arguments:
* wf = ThrWorkForce * (Given)
Expand Down Expand Up @@ -64,6 +65,8 @@
* (if outfset specified)
* fts_port = fts2Port (Given)
* FTS-2 port.
* qua = smfArray ** (Given)
* Container holding existing quality data. May be NULL.
* mgroup = smfGroup ** (Returned)
* Pointer to smfGroup pointer that will contain model file names
* mdata = smfArray ** (Given and Returned)
Expand Down Expand Up @@ -216,6 +219,8 @@
* Allow LUT to be imported from an NDF.
* 2014-01-24 (DSB):
* Remove argument noi_boxsize.
* 2014-05-15 (DSB):
* Add argument "qua".
* {enter_further_changes_here}
* Copyright:
Expand Down Expand Up @@ -279,8 +284,8 @@ void smf_model_create( ThrWorkForce *wf, const smfGroup *igroup,
dim_t nchunks, smf_modeltype mtype, int isTordered,
AstFrameSet *outfset, int moving,
int *lbnd_out, int *ubnd_out, fts2Port fts_port,
smfGroup **mgroup, smfArray **mdata, AstKeyMap *keymap,
int *status ) {
smfArray **qua, smfGroup **mgroup, smfArray **mdata,
AstKeyMap *keymap, int *status ) {

/* Local Variables */
size_t bstride; /* Bolometer stride in data array */
Expand Down Expand Up @@ -983,7 +988,8 @@ void smf_model_create( ThrWorkForce *wf, const smfGroup *igroup,
/* Initialise the NOI model from any external NOI model
supplied by the user (such as may be dumped on a previous
run by setting "exportndf=noi,noi.export=1"). */
if( smf_import_noi( name, &head, keymap, dataptr, status ) ) {
if( smf_import_noi( name, &head, keymap, qua ? qua[i]->sdata[j] : NULL,
dataptr, status ) ) {
msgOutiff( MSG__VERB, "", FUNC_NAME ": using external NOI "
"model imported from '%s'.", status, name );

Expand Down

0 comments on commit a5e077a

Please sign in to comment.