IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15562 for trunk/psastro/src


Ignore:
Timestamp:
Nov 9, 2007, 3:09:20 PM (19 years ago)
Author:
eugene
Message:

updating all changes from from eam_branch_20071023

Location:
trunk/psastro/src
Files:
1 added
1 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/psastro/src/Makefile.am

    r12806 r15562  
    3333        psastroLuminosityFunction.c \
    3434        psastroRefstarSubset.c      \
     35        psastroEnforceChips.c       \
    3536        psastroMosaicAstrom.c       \
    3637        psastroMosaicGradients.c    \
  • trunk/psastro/src/psastro.h

    r15195 r15562  
    2727bool              psastroDataSave (pmConfig *config);
    2828bool              psastroDefineFiles (pmConfig *config, pmFPAfile *input);
     29bool              psastroDefineFile (pmConfig *config, pmFPA *input, char *filerule, char *argname, pmFPAfileType fileType, pmDetrendType detrendType);
    2930bool              psastroAnalysis (pmConfig *config);
    3031
     
    7475bool              psastroDumpStars (psArray *stars, char *filename);
    7576bool              psastroDumpMatchedStars (char *filename, psArray *rawstars, psArray *refstars, psArray *match);
     77bool              psastroDumpGradients (psArray *gradients, char *filename);
    7678
    7779bool              psastroMosaicSetAstrom_tmp (pmFPA *fpa);
    7880int               psastroSortByMag (const void *a, const void *b);
    7981
     82bool              psastroEnforceChips (pmConfig *config, pmFPA *fpa, psMetadata *recipe);
     83
     84psArray *psastroReadGetstarCatalog (psFits *fits);
     85psArray *psastroReadGetstar_PS1_DEV_0 (psFits *fits);
     86
    8087# endif /* PSASTRO_H */
  • trunk/psastro/src/psastroAnalysis.c

    r15245 r15562  
    1616        return true;
    1717    }
    18 
    19     // XXX test retrun
    20     // return true;
    2118
    2219    // load the reference stars overlapping the data stars
  • trunk/psastro/src/psastroArguments.c

    r12992 r15562  
    3636        psMetadataAddStr (config->arguments, PS_LIST_TAIL, "CHIP_SELECTIONS", PS_META_REPLACE, "", argv[N]);
    3737        psArgumentRemove (N, &argc, argv);
     38    }
     39   
     40    // apply the chip correction based on the reference astrometry?
     41    if ((N = psArgumentGet (argc, argv, "-fixchips"))) {
     42        psArgumentRemove (N, &argc, argv);
     43        psMetadataAddBool (config->arguments, PS_LIST_TAIL, "PSASTRO.FIX.CHIPS", PS_META_REPLACE, "", true);
     44    }
     45    // define the reference astrometry file
     46    status = pmConfigFileSetsMD (config->arguments, &argc, argv, "REF.ASTROM", "-refastrom", "-refastromlist");
     47    if (status) {
     48        // if supplied, assume -fixchips is desired
     49        psMetadataAddBool (config->arguments, PS_LIST_TAIL, "PSASTRO.FIX.CHIPS", PS_META_REPLACE, "", true);
    3850    }
    3951
  • trunk/psastro/src/psastroDefineFiles.c

    r14212 r15562  
    44
    55    // these calls bind the I/O handle to the specified fpa
    6     pmFPAfile *output = NULL;
     6    bool status;
    77
    8     output = pmFPAfileDefineOutput (config, input->fpa, "PSASTRO.OUTPUT");
     8    // select the current recipe
     9    psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, PSASTRO_RECIPE);
     10    if (!recipe) {
     11        psError(PSASTRO_ERR_CONFIG, false, "Can't find PSASTRO recipe!\n");
     12        return false;
     13    }
     14
     15    pmFPAfile *output = pmFPAfileDefineOutput (config, input->fpa, "PSASTRO.OUTPUT");
    916    if (!output) {
    1017        psError(PSASTRO_ERR_CONFIG, false, "Failed to build FPA from PSASTRO.INPUT");
     
    1219    }
    1320    output->save = true;
     21
     22    bool fixChips = psMetadataLookupBool (&status, recipe, "PSASTRO.FIX.CHIPS");
     23
     24    if (fixChips) {
     25        if (!psastroDefineFile (config, input->fpa, "PSASTRO.REF.ASTROM", "REF.ASTROM", PM_FPA_FILE_ASTROM, PM_DETREND_TYPE_ASTROM)) {
     26            psError (PS_ERR_IO, false, "Can't find a reference astrometry file");
     27            return NULL;
     28        }
     29    }
    1430
    1531# if (0)
     
    2541    return true;
    2642}
     43
     44bool psastroDefineFile (pmConfig *config, pmFPA *input, char *filerule, char *argname, pmFPAfileType fileType, pmDetrendType detrendType) {
     45
     46    bool status;
     47    pmFPAfile *file;
     48
     49    // look for the file on the argument list
     50    file = pmFPAfileDefineFromArgs  (&status, config, filerule, argname);
     51    if (!status) {
     52        psError (PS_ERR_UNKNOWN, false, "failed to load find definition");
     53        return false;
     54    }
     55    if (file) {
     56        if (file->type != fileType) {
     57            psError(PS_ERR_IO, true, "%s is not of type %s", filerule, pmFPAfileStringFromType (fileType));
     58            return false;
     59        }
     60        return true;
     61    }
     62
     63    // look for the file in the camera config table
     64    file = pmFPAfileDefineFromConf  (&status, config, filerule);
     65    if (!status) {
     66        psError (PS_ERR_UNKNOWN, false, "failed to load find definition");
     67        return false;
     68    }
     69    if (file) {
     70        if (file->type != fileType) {
     71            psError(PS_ERR_IO, true, "%s is not of type %s", filerule, pmFPAfileStringFromType (fileType));
     72            return false;
     73        }
     74        return true;
     75    }
     76
     77    // look for the file to be loaded from the detrend database
     78    file = pmFPAfileDefineFromDetDB (&status, config, filerule, input, detrendType);
     79    if (!status) {
     80        psError (PS_ERR_UNKNOWN, false, "failed to load file definition");
     81        return false;
     82    }
     83    if (file) {
     84        if (file->type != fileType) {
     85            psError(PS_ERR_IO, true, "%s is not of type %s", filerule, pmFPAfileStringFromType (fileType));
     86            return false;
     87        }
     88        return true;
     89    }
     90    return false;
     91}
     92
  • trunk/psastro/src/psastroDemoDump.c

    r15199 r15562  
    173173    return true;
    174174}
     175
     176// this function is used for test purposes (-trace psastro.dump 1)
     177bool psastroDumpGradients (psArray *gradients, char *filename) {
     178
     179    FILE *f = fopen (filename, "w");
     180
     181    for (int i = 0; i < gradients->n; i++) {
     182        pmAstromGradient *gradient = gradients->data[i];
     183
     184        // write out the refstar data
     185        fprintf (f, "%d  %f %f   %f %f  %f %f\n", i,
     186                 gradient->FP.x, gradient->FP.y,
     187                 gradient->dTPdL.x, gradient->dTPdL.y,
     188                 gradient->dTPdM.x, gradient->dTPdM.y);
     189    }
     190
     191    fclose (f);
     192    return true;
     193}
     194
  • trunk/psastro/src/psastroLoadRefstars.c

    r15538 r15562  
    1515    float DECmin = DEG_RAD*psMetadataLookupF32(NULL, recipe, "DEC_MIN");
    1616    float DECmax = DEG_RAD*psMetadataLookupF32(NULL, recipe, "DEC_MAX");
    17     // float MAGmax = psMetadataLookupF32(NULL, recipe, "MAG_MAX");
    1817
    1918    // XXX CATDIR needs to look up abstracted name from psastro.config
     
    2524    char *getstarCommand = psStringCopy(psMetadataLookupStr(NULL, recipe, "DVO.GETSTAR"));
    2625    PS_ASSERT (getstarCommand, NULL);
     26
     27    char *outformat = psMetadataLookupStr(NULL, recipe, "DVO.GETSTAR.OUTFORMAT");
     28    PS_ASSERT (outformat, NULL);
     29
     30    char *photcode = psMetadataLookupStr(NULL, recipe, "DVO.GETSTAR.PHOTCODE");
     31    PS_ASSERT (photcode, NULL);
     32
     33    float MAGmax = psMetadataLookupF32(NULL, recipe, "DVO.GETSTAR.MAG.MAX");
    2734
    2835    // issue the following command:
     
    3946    psTimerStart ("psastro");
    4047
    41     // use fork to add timeout capability
     48    // supply a known output format (for CATALOG output) so the code below knows what to read
    4249    if (ELIXIR_MODE) {
    43         psStringAppend (&getstarCommand, " -D CATFORMAT elixir");
     50        psStringAppend (&getstarCommand, " -D CATMODE mef -D CATFORMAT elixir");
    4451    } else {
    45         psStringAppend (&getstarCommand, " -D CATFORMAT panstarrs");
     52        psStringAppend (&getstarCommand, " -D CATMODE mef -D CATFORMAT panstarrs");
    4653    }
    4754
     
    5259    psFree(CATDIR);
    5360
    54     // psStringAppend (&getstarCommand, " -D CATMODE mef -maglim %f -region %f %f %f %f -o %s", MAGmax, RAmin, DECmin, RAmax, DECmax, tempFile);
    55     // XXX TEST : no magnitude limit
    56     // XXX need to specify the desired photometry system
    57     psStringAppend (&getstarCommand, " -D CATMODE mef -region %f %f %f %f -o %s", RAmin, DECmin, RAmax, DECmax, tempFile);
     61    // supply the max magnitude, the output format, and the photcode
     62    psStringAppend (&getstarCommand, " -maglim %f -format %s -photcode %s", MAGmax, outformat, photcode);
     63
     64    // add region and output filename
     65    psStringAppend (&getstarCommand, " -region %f %f %f %f -o %s", RAmin, DECmin, RAmax, DECmax, tempFile);
    5866    psTrace ("psastro", 3, "%s\n", getstarCommand);
    5967
    6068    // XXX use psPipe: catch stderr, stdout, allow for Nsec timeout...
     69    // use fork to add timeout capability
    6170    status = system (getstarCommand);
    6271    if (status) {
     
    7180    psFits *fits = psFitsOpen (tempFile, "r");
    7281
     82    psTimerStart ("psastro");
     83
     84    psArray *refstars = NULL;
     85    if (!strcmp (outformat, "CATALOG")) {
     86      refstars = psastroReadGetstarCatalog (fits);
     87    }
     88    if (!strcmp (outformat, "PS1_DEV_0")) {
     89      refstars = psastroReadGetstar_PS1_DEV_0 (fits);
     90    }
     91    if (refstars == NULL) {
     92        psError(PSASTRO_ERR_REFSTARS, true, "error reading reference data\n");
     93        return NULL;
     94    }
     95    psLogMsg ("psastro", 3, "loaded %ld reference stars : %f sec\n", refstars->n, psTimerMark ("psastro"));
     96
     97    psTrace ("psastro", 3, "loaded %ld reference stars from (%10.6f,%10.6f) - (%10.6f,%10.6f)\n",
     98             refstars->n, RAmin, DECmin, RAmax, DECmax);
     99
     100    psFitsClose (fits);
     101    unlink (tempFile);
     102
     103    // dump or plot the available refstars
     104    if (psTraceGetLevel("psastro.dump") > 0) {
     105        psastroDumpRefstars (refstars, "refstars.dat");
     106    }
     107
     108    if (psTraceGetLevel("psastro.plot") > 0) {
     109        psastroPlotRefstars (refstars, recipe);
     110    }
     111
     112    return refstars;
     113}
     114
     115psArray *psastroReadGetstarCatalog (psFits *fits) {
     116
     117    bool status;
     118
    73119    if (ELIXIR_MODE) {
    74120        psFitsMoveExtName (fits, "DVO_AVERAGE_ELIXIR");
     
    77123    }
    78124
    79     psTimerStart ("psastro");
    80125    long numSources = psFitsTableSize(fits); // Number of sources in table
    81126
     
    102147        psFree (row);
    103148    }
    104     psLogMsg ("psastro", 3, "loaded %ld reference stars : %f sec\n", refstars->n, psTimerMark ("psastro"));
    105 
    106     psTrace ("psastro", 3, "loaded %ld reference stars from (%10.6f,%10.6f) - (%10.6f,%10.6f)\n",
    107              refstars->n, RAmin, DECmin, RAmax, DECmax);
    108 
    109     psFitsClose (fits);
    110     unlink (tempFile);
    111 
    112     // dump or plot the available refstars
    113     if (psTraceGetLevel("psastro.dump") > 0) {
    114         psastroDumpRefstars (refstars, "refstars.dat");
    115     }
    116 
    117     if (psTraceGetLevel("psastro.plot") > 0) {
    118         psastroPlotRefstars (refstars, recipe);
    119     }
    120 
    121149    return refstars;
    122150}
     151
     152psArray *psastroReadGetstar_PS1_DEV_0 (psFits *fits) {
     153
     154    bool status;
     155
     156    psFitsMoveExtName (fits, "GETSTAR_PS1_DEV_0");
     157
     158    long numSources = psFitsTableSize(fits); // Number of sources in table
     159
     160    // convert the Average table to the pmAstromObj entries
     161    psArray *refstars = psArrayAllocEmpty (numSources);
     162    for (int i = 0; i < numSources; i++) {
     163        pmAstromObj *ref = pmAstromObjAlloc ();
     164
     165        psMetadata *row = psFitsReadTableRow(fits, i); // Table row
     166
     167        ref->sky->r   = RAD_DEG*psMetadataLookupF32 (&status, row, "RA");
     168        ref->sky->d   = RAD_DEG*psMetadataLookupF32 (&status, row, "DEC");
     169        ref->Mag      = psMetadataLookupS32 (&status, row, "MAG");
     170
     171        psArrayAdd (refstars, 100, ref);
     172        psFree (ref);
     173        psFree (row);
     174    }
     175    return refstars;
     176}
  • trunk/psastro/src/psastroMosaicAstrom.c

    r15260 r15562  
    2121    pmFPA *fpa = input->fpa;
    2222
    23     // XXX before we do object matches, we need to fix failed chips
    24     // compare chips with supplied mosaic model
    25     // adjust significant outliers to match model
     23    // before we do object matches, we need to (optionally) fix failed chips.  We compare chips with
     24    // the supplied mosaic model.  Adjust significant outliers to match model. 
     25    if (!psastroEnforceChips (config, fpa, recipe)) {
     26        psError(PSASTRO_ERR_UNKNOWN, false, "failed to align problematic chips");
     27        return false;
     28    }
    2629
    2730    // given the existing per-chip astrometry, determine matches between raw and ref stars
  • trunk/psastro/src/psastroMosaicGradients.c

    r15258 r15562  
    11# include "psastroInternal.h"
     2static int nPass = 0;
    23
    34bool psastroMosaicGradients (pmFPA *fpa, psMetadata *recipe) {
     
    5051    }
    5152
     53    // if desired, dump the gradients to a file
     54    if (psTraceGetLevel("psastro.dump") > 0) {
     55        char name[80];
     56        sprintf (name, "gradients.%d.dat", nPass);
     57        psastroDumpGradients (gradients, name);
     58        nPass ++;
     59    }
     60
    5261    // allocate mosaic-level polynomial transformation and set masks needed by DVO
    5362    int order = psMetadataLookupF32 (&status, recipe, "PSASTRO.MOSAIC.ORDER");
  • trunk/psastro/src/psastroMosaicOneChip.c

    r15259 r15562  
    5555        return false;
    5656    }
     57
     58    psLogMsg ("psastro", PS_LOG_DETAIL, "mosaic fit chip order %d", order);
    5759
    5860    // create output toFPA; set masks appropriate to the Elixir DVO astrometry format if we are
  • trunk/psastro/src/psastroMosaicSetMatch.c

    r12806 r15562  
    1515    if (!status) {
    1616        psError(PS_ERR_IO, false, "Failed to lookup matching radius: %s", radiusWord);
    17         return NULL;
     17        return false;
    1818    }
     19
     20    if (RADIUS <= 0.0) {
     21        if (iteration == 0) {
     22            psError(PS_ERR_IO, false, "Invalid match radius for first iteration: %s", radiusWord);
     23            return false;
     24        }
     25        psWarning ("skipping match for iteration %d\n", iteration);
     26        return true;
     27    }
    1928
    2029    // this loop selects the matched stars for all chips
Note: See TracChangeset for help on using the changeset viewer.