IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 9, 2013, 12:26:48 PM (13 years ago)
Author:
eugene
Message:

major upgrades to pswarp to enable skycell warp -> chip

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pswarp/src/pswarpArguments.c

    r34800 r35563  
    1212
    1313# include "pswarp.h"
    14 # include <glob.h>
    15 
    1614
    1715static void usage (void) {
    18     fprintf(stderr, "USAGE: pswarp [-file image(s)] [-list imagelist] [options] (output) (skycell)\n");
     16    fprintf(stderr, "USAGE: pswarp [-input input.mdc] [-file image(s)] [-list imagelist] [options] (output) (skycell)\n");
    1917    fprintf(stderr, "  options:\n");
     18    fprintf(stderr, "    [-input input.mdc] : input image information in a metadata file\n");
     19    fprintf(stderr, "    [-file input.fits[,input.fits]] : input image to be warped\n");
    2020    fprintf(stderr, "    [-astrom astrom.cmp] : provide an alternative astrometry calibration\n");
    2121    fprintf(stderr, "    [-mask mask.fits] : provide a corresponding mask image\n");
     
    2424    exit(PS_EXIT_CONFIG_ERROR);
    2525}
    26 
    2726
    2827pmConfig *pswarpArguments (int argc, char **argv) {
     
    5554    }
    5655
     56    // XXX move to the single group below?
    5757    pmConfigFileSetsMD(config->arguments, &argc, argv, "ASTROM",   "-astrom", "-astromlist");
    5858
    59     {
    60         int arg;                        ///< Argument Number
    61         if ((arg = psArgumentGet(argc, argv, "-psphot-visual"))) {
    62             psArgumentRemove(arg, &argc, argv);
    63             pmVisualSetVisual(true);
    64         }
     59    // turn on psphot visualization
     60    if ((N = psArgumentGet(argc, argv, "-psphot-visual"))) {
     61        psArgumentRemove(N, &argc, argv);
     62        pmVisualSetVisual(true);
    6563    }
    6664
     
    8381    pswarpSetThreads();
    8482
    85     pmConfigFileSetsMD (config->arguments, &argc, argv, "INPUT", "-file", "-list");
    86     pmConfigFileSetsMD (config->arguments, &argc, argv, "MASK", "-mask", "-masklist");
    87     pmConfigFileSetsMD (config->arguments, &argc, argv, "VARIANCE", "-variance", "-variancelist");
    88     pmConfigFileSetsMD (config->arguments, &argc, argv, "BACKGROUND", "-background", "-bkglist");
     83    // there are three mutually exclusive ways of providing the input
     84    // 1) supply -file (filename) [-mask .. -variance ..] on the command line
     85    // 2) supply -input (input.mdc) on the command line
     86    // 3) load inputs from RUN config info
     87
     88    // below, we check first for -file then for -input.  failure to find either implies use of
     89    // the configuration metadata file.
     90
     91    bool singleInput = pmConfigFileSetsMD (config->arguments, &argc, argv, "INPUT", "-file", "-list");
     92    if (singleInput) {
     93        if (psArgumentGet(argc, argv, "-input")) {
     94            psErrorStackPrint(stderr, "error in arguments : -input and -file / -list are mutually exclusive");
     95            exit(PS_EXIT_CONFIG_ERROR);
     96        }       
     97        pmConfigFileSetsMD (config->arguments, &argc, argv, "MASK", "-mask", "-masklist");
     98        pmConfigFileSetsMD (config->arguments, &argc, argv, "VARIANCE", "-variance", "-variancelist");
     99        pmConfigFileSetsMD (config->arguments, &argc, argv, "BACKGROUND", "-background", "-bkglist");
     100    } else {
     101        // find the input data file (an mdc file)
     102        if ((N = psArgumentGet(argc, argv, "-input"))) {
     103            if (argc <= N+1) {
     104                psErrorStackPrint(stderr, "Expected to see 1 more argument; saw %d", argc - 1);
     105                exit(PS_EXIT_CONFIG_ERROR);
     106            }
     107            psArgumentRemove(N, &argc, argv);
     108
     109            unsigned int numBad = 0;                     // Number of bad lines
     110            psMetadata *inputs = psMetadataConfigRead(NULL, &numBad, argv[N], false); // Input file info
     111            if (!inputs || numBad > 0) {
     112                psErrorStackPrint(stderr, "Unable to cleanly read MDC file with inputs.");
     113                exit(PS_EXIT_CONFIG_ERROR);
     114            }
     115            psMetadataAddMetadata(config->arguments, PS_LIST_TAIL, "INPUTS", 0, "Metadata with input details", inputs);
     116            psFree(inputs);
     117
     118            psArgumentRemove(N, &argc, argv);
     119        }
     120    }
     121    if (argc != 3) {
     122        usage();
     123    }
     124    if (psErrorCodeLast() != PS_ERR_NONE) {
     125        psErrorStackPrint(stderr, "error in arguments");
     126        exit(PS_EXIT_CONFIG_ERROR);
     127    }
    89128   
    90     if (argc != 3) {
    91         usage();
    92     }
    93 
    94 
    95129    psArray *array;
    96130
     
    107141    return config;
    108142}
    109 
    110 /**
    111  * Parse the recipe and format into the arguments
    112  */
    113 bool pswarpOptions(pmConfig *config)
    114 {
    115     // Select the appropriate recipe
    116     psMetadata *recipe  = psMetadataLookupPtr(NULL, config->recipes, PSWARP_RECIPE);
    117     if (!recipe) {
    118         psError(PSWARP_ERR_CONFIG, true, "Can't find %s recipe!\n", PSWARP_RECIPE);
    119         return false;
    120     }
    121 
    122     // Get grid size
    123     bool status;                        ///< Status of MD lookup
    124     int nGridX = psMetadataLookupS32(&status, recipe, "GRID.NX");
    125     if (!status || nGridX <= 0) {
    126         nGridX = 128;
    127         psWarning("GRID.NX is not set in the recipe --- defaulting to %d", nGridX);
    128     }
    129     int nGridY = psMetadataLookupS32(&status, recipe, "GRID.NY");
    130     if (!status) {
    131         nGridY = 128;
    132         psWarning("GRID.NY is not set in the recipe --- defaulting to %d", nGridY);
    133     }
    134 
    135     // Get interpolation mode
    136     const char *name = psMetadataLookupStr (&status, recipe, "INTERPOLATION.MODE"); ///< Name of interp mode
    137     if (!name) {
    138         name = "BILINEAR";
    139         psLogMsg("pswarp", 3, "defaulting to %s interpolation", name);
    140     }
    141     psImageInterpolateMode interpolationMode = psImageInterpolateModeFromString(name); ///< Mode for interp.
    142     if (interpolationMode == PS_INTERPOLATE_NONE) {
    143         interpolationMode = PS_INTERPOLATE_BILINEAR;
    144         psLogMsg ("pswarp", 3,
    145                   "Unknown interpolation mode %s, defaulting to bilinear interpolation\n", name);
    146         name = "BILINEAR";
    147     }
    148 
    149     int numKernels = psMetadataLookupS32(&status, recipe, "INTERPOLATION.NUM");
    150     if (!status) {
    151         numKernels = 0;
    152         psWarning("INTERPOLATION.NUM is not set in the recipe --- defaulting to %d", numKernels);
    153     }
    154 
    155     float poorFrac = psMetadataLookupF32(&status, recipe, "POOR.FRAC"); ///< Frac of bad flux for a "poor"
    156     if (!status) {
    157         poorFrac = 0.0;
    158         psWarning("POOR.FRAC is not set in the %s recipe --- defaulting to %f.", PSWARP_RECIPE, poorFrac);
    159     }
    160 
    161     bool PSF = psMetadataLookupBool(&status, recipe, "PSF"); ///< Generate a PSF model?
    162     if (!status) {
    163         PSF = true;
    164         psWarning("PSF is not set in the %s recipe --- defaulting to TRUE.", PSWARP_RECIPE);
    165     }
    166 
    167     bool doBKG = psMetadataLookupBool(&status,recipe, "BACKGROUND.MODEL"); ///< Generate the warped background model?
    168     if (!status) {
    169       doBKG = false;
    170       psWarning("BACKGROUND.MODEL is not set in the %s recipe -- defaulting to FALSE.", PSWARP_RECIPE);
    171     }
    172     int bkgXgrid = psMetadataLookupS32(&status,recipe, "BKG.XGRID"); ///< Xsize of background model
    173     if (!status) {
    174       bkgXgrid = 10;
    175       psWarning("BKG.XGRID is not set in the %s recipe -- defaultint to %d.",PSWARP_RECIPE,bkgXgrid);
    176     }
    177     int bkgYgrid = psMetadataLookupS32(&status,recipe, "BKG.YGRID"); ///< Xsize of background model
    178     if (!status) {
    179       bkgYgrid = 10;
    180       psWarning("BKG.YGRID is not set in the %s recipe -- defaultint to %d.",PSWARP_RECIPE,bkgYgrid);
    181     }
    182 
    183    
    184     // Set recipe values in the recipe (since we've possibly altered some)
    185     psMetadataAddS32(recipe, PS_LIST_TAIL, "GRID.NX", PS_META_REPLACE,
    186                      "Iso-astrom grid spacing in x", nGridX);
    187     psMetadataAddS32(recipe, PS_LIST_TAIL, "GRID.NY", PS_META_REPLACE,
    188                      "Iso-astrom grid spacing in y", nGridY);
    189     psMetadataAddStr(recipe, PS_LIST_TAIL, "INTERPOLATION.MODE", PS_META_REPLACE,
    190                      "Interpolation mode", name);
    191     psMetadataAddS32(recipe, PS_LIST_TAIL, "INTERPOLATION.NUM", PS_META_REPLACE,
    192                      "Interpolation pre-calculated kernels", numKernels);
    193     psMetadataAddF32(recipe, PS_LIST_TAIL, "POOR.FRAC", PS_META_REPLACE,
    194                      "Fraction of bad flux for a pixel to be marked as poor", poorFrac);
    195     psMetadataAddBool(recipe, PS_LIST_TAIL, "PSF", PS_META_REPLACE, "Generate a PSF Model?", PSF);
    196     psMetadataAddBool(recipe, PS_LIST_TAIL, "BACKGROUND.MODEL", PS_META_REPLACE, "Generate the warped background model?", doBKG);
    197     psMetadataAddS32(recipe, PS_LIST_TAIL, "BKG.XGRID", PS_META_REPLACE, "Xsize of background model", bkgXgrid);
    198     psMetadataAddS32(recipe, PS_LIST_TAIL, "BKG.YGRID", PS_META_REPLACE, "Ysize of background model", bkgYgrid);
    199    
    200    
    201     // Set recipe values in the arguments
    202     psMetadataAddS32(config->arguments, PS_LIST_TAIL, "GRID.NX", 0,
    203                      "Iso-astrom grid spacing in x", nGridX);
    204     psMetadataAddS32(config->arguments, PS_LIST_TAIL, "GRID.NY", 0,
    205                      "Iso-astrom grid spacing in y", nGridY);
    206     psMetadataAddS32(config->arguments, PS_LIST_TAIL, "INTERPOLATION.MODE", 0,
    207                      "Interpolation mode", interpolationMode);
    208     psMetadataAddS32(config->arguments, PS_LIST_TAIL, "INTERPOLATION.NUM", 0,
    209                      "Interpolation pre-calculated kernels", numKernels);
    210     psMetadataAddF32(config->arguments, PS_LIST_TAIL, "POOR.FRAC", 0,
    211                      "Fraction of bad flux for a pixel to be marked as poor", poorFrac);
    212     psMetadataAddBool(config->arguments, PS_LIST_TAIL, "PSF", PS_META_REPLACE, "Generate a PSF Model?", PSF);
    213     psMetadataAddBool(config->arguments, PS_LIST_TAIL, "BACKGROUND.MODEL", PS_META_REPLACE, "Generate the warped background model?", doBKG);
    214     psMetadataAddS32(config->arguments, PS_LIST_TAIL, "BKG.XGRID", PS_META_REPLACE, "Xsize of background model", bkgXgrid);
    215     psMetadataAddS32(config->arguments, PS_LIST_TAIL, "BKG.YGRID", PS_META_REPLACE, "Ysize of background model", bkgYgrid);
    216 
    217     psTrace("pswarp", 1, "Done with pswarpArguments...\n");
    218 
    219     return (config);
    220 }
Note: See TracChangeset for help on using the changeset viewer.