Changeset 13515
- Timestamp:
- May 24, 2007, 2:28:58 PM (19 years ago)
- Location:
- trunk/ppStack/src
- Files:
-
- 3 edited
-
ppStackArguments.c (modified) (2 diffs)
-
ppStackCamera.c (modified) (3 diffs)
-
ppStackReadout.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppStack/src/ppStackArguments.c
r13512 r13515 17 17 { 18 18 fprintf(stderr, "\nPan-STARRS Image combination\n\n"); 19 fprintf(stderr, "Usage: %s IMAGES.list MASKS.list OUTPUT_ROOT\n", 19 fprintf(stderr, "Usage: %s INPUTS.mdc OUTPUT_ROOT\n" 20 "where INPUTS.mdc contains:\n" 21 "\tIMAGE(STR): Image filename\n" 22 "\tMASK(STR): Mask filename\n" 23 "\tSEEING(F32): Seeing FWHM (pixels)\n" 24 "\tWEIGHT(F32): Relative weighting to be applied\n" 25 "\tSCALE(F32): Relative scaling to be applied\n", 20 26 program); 21 27 fprintf(stderr, "\n"); … … 85 91 psMetadataAddU8(arguments, PS_LIST_TAIL, "-mask-bad", 0, "Mask value for bad pixels", 0); 86 92 psMetadataAddU8(arguments, PS_LIST_TAIL, "-mask-blank", 0, "Mask value for blank region", 0); 87 psMetadataAddStr(arguments, PS_LIST_TAIL, "-seeing", 0, "Name of file with seeing FWHMs", NULL);88 93 89 if (argc == 1 || !psArgumentParse(arguments, &argc, argv) || argc != 4) {94 if (argc == 1 || !psArgumentParse(arguments, &argc, argv) || argc != 3) { 90 95 usage(argv[0], arguments, config); 91 96 } 92 97 93 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "IMAGES.LIST", 0, 94 "Name of the input image list", argv[1]); 95 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "MASKS.LIST", 0, 96 "Name of the input masks list", argv[2]); 98 int numBad = 0; // Number of bad lines 99 psMetadata *inputs = psMetadataConfigRead(NULL, &numBad, argv[1], false); // Information about inputs 100 if (!inputs || numBad > 0) { 101 psError(PS_ERR_BAD_PARAMETER_VALUE, false, "Unable to cleanly read MDC file with inputs."); 102 goto ERROR; 103 } 104 psMetadataAddMetadata(config->arguments, PS_LIST_TAIL, "INPUTS", 0, 105 "Metadata with input details", inputs); 97 106 psMetadataAddStr(config->arguments, PS_LIST_TAIL, "OUTPUT", 0, 98 "Root name of the output image list", argv[ 3]);107 "Root name of the output image list", argv[2]); 99 108 100 valueArgStr(config, arguments, "-stat", "STATS",config->arguments);109 valueArgStr(config, arguments, "-stat", "STATS", config->arguments); 101 110 102 111 psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // Recipe for ppSim -
trunk/ppStack/src/ppStackCamera.c
r13493 r13515 13 13 bool ppStackCamera(pmConfig *config) 14 14 { 15 psString imageName = psMetadataLookupStr(NULL, config->arguments, "IMAGES.LIST"); // Image list filename 16 assert(imageName); 17 psString maskName = psMetadataLookupStr(NULL, config->arguments, "MASKS.LIST"); // Mask list filename 18 assert(maskName); 19 20 psString imageList = psSlurpFilename(imageName); // Contents of image list 21 if (!imageList) { 22 psError(PS_ERR_IO, false, "Unable to read list of image files %s", imageName); 23 return false; 24 } 25 psArray *images = psStringSplitArray(imageList, "\n", false); // The image filenames 26 psFree(imageList); 27 28 psString maskList = psSlurpFilename(maskName); // Contents of mask list 29 if (!maskList) { 30 psError(PS_ERR_IO, false, "Unable to read list of mask files %s", maskName); 31 return false; 32 } 33 psArray *masks = psStringSplitArray(maskList, "\n", false); // The mask filenames 34 psFree(maskList); 35 if (images->n != masks->n) { 36 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 37 "Number input images (%ld) does not match number of input masks (%ld).", 38 images->n, masks->n); 39 psFree(images); 40 psFree(masks); 41 return false; 42 } 43 44 for (int i = 0; i < images->n; i++) { 45 psString image = images->data[i]; // Name of image 46 if (!image || strlen(image) == 0) { 47 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Image name %d is blank.", i); 48 psFree(images); 49 psFree(masks); 50 return false; 51 } 52 psString mask = masks->data[i]; // Name of mask 53 if (!mask || strlen(mask) == 0) { 54 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Mask name %d is blank.", i); 55 psFree(images); 56 psFree(masks); 15 psMetadata *inputs = psMetadataLookupMetadata(NULL, config->arguments, "INPUTS"); // The inputs info 16 psMetadataIterator *iter = psMetadataIteratorAlloc(inputs, PS_LIST_HEAD, NULL); // Iterator 17 psMetadataItem *item; // Item from iteration 18 int i = 0; // Counter 19 while ((item = psMetadataGetAndIncrement(iter))) { 20 if (item->type != PS_DATA_METADATA) { 21 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 22 "Component %s of the input metadata is not of type METADATA", item->name); 23 psFree(iter); 57 24 return false; 58 25 } 59 26 27 psMetadata *input = item->data.md; // The input metadata of interest 28 29 psString image = psMetadataLookupStr(NULL, input, "IMAGE"); // Name of image 30 if (!image || strlen(image) == 0) { 31 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Component %s lacks IMAGE of type STR", item->name); 32 psFree(iter); 33 return false; 34 } 35 36 psString mask = psMetadataLookupStr(NULL, input, "MASK"); // Name of mask 37 if (!mask || strlen(mask) == 0) { 38 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Component %s lacks MASK of type STR", item->name); 39 psFree(iter); 40 return false; 41 } 42 43 float seeing = psMetadataLookupF32(NULL, input, "SEEING"); // Seeing FWHM 44 if (isnan(seeing)) { 45 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Component %s lacks SEEING of type F32", item->name); 46 psFree(iter); 47 return false; 48 } 49 50 float weight = psMetadataLookupF32(NULL, input, "WEIGHT"); // Relative weight 51 if (isnan(weight)) { 52 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Component %s lacks WEIGHT of type F32", item->name); 53 psFree(iter); 54 return false; 55 } 56 57 float scale = psMetadataLookupF32(NULL, input, "SCALE"); // Relative scale 58 if (isnan(scale)) { 59 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Component %s lacks SCALE of type F32", item->name); 60 psFree(iter); 61 return false; 62 } 63 64 // Add the image file 60 65 psArray *imageFiles = psArrayAlloc(1); // Array of filenames for this FPA 61 66 imageFiles->data[0] = psMemIncrRefCounter(image); … … 68 73 if (!imageFile || !found) { 69 74 psError(PS_ERR_UNKNOWN, false, "Unable to define file from image %d (%s)", i, image); 70 psFree(images);71 psFree(masks);72 75 return false; 73 76 } 74 77 if (imageFile->type != PM_FPA_FILE_IMAGE) { 75 78 psError(PS_ERR_IO, true, "PPSTACK.INPUT is not of type IMAGE"); 76 psFree(images);77 psFree(masks);78 79 return false; 79 80 } 80 81 82 // Add the mask file 81 83 psArray *maskFiles = psArrayAlloc(1); // Array of filenames for this FPA 82 84 maskFiles->data[0] = psMemIncrRefCounter(mask); … … 90 92 if (!maskFile || !found) { 91 93 psError(PS_ERR_UNKNOWN, false, "Unable to define file from mask %d (%s)", i, mask); 92 psFree(images);93 psFree(masks);94 94 return false; 95 95 } 96 96 if (maskFile->type != PM_FPA_FILE_MASK) { 97 97 psError(PS_ERR_IO, true, "PPSTACK.INPUT.MASK is not of type MASK"); 98 psFree(images);99 psFree(masks);100 98 return false; 101 99 } 100 101 psMetadataAddF32(imageFile->fpa->analysis, PS_LIST_TAIL, "PPSTACK.SEEING", 0, 102 "Seeing for image", seeing); 103 psMetadataAddF32(imageFile->fpa->analysis, PS_LIST_TAIL, "PPSTACK.WEIGHT", 0, 104 "Relative weight for image", weight); 105 psMetadataAddF32(imageFile->fpa->analysis, PS_LIST_TAIL, "PPSTACK.SCALE", 0, 106 "Relative scale for image", scale); 107 108 i++; 102 109 } 110 psFree(iter); 103 111 psMetadataRemoveKey(config->arguments, "IMAGE.FILENAMES"); 104 112 psMetadataRemoveKey(config->arguments, "MASK.FILENAMES"); 105 113 106 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "INPUTS.NUM", 0, "Number of input files", images->n); 107 108 psFree(images); 109 psFree(masks); 114 psMetadataAddS32(config->arguments, PS_LIST_TAIL, "INPUTS.NUM", 0, "Number of input files", i); 110 115 111 116 // Output image -
trunk/ppStack/src/ppStackReadout.c
r13513 r13515 10 10 11 11 #define ARRAY_BUFFER 16 // Number to add to array at a time 12 13 14 #define WEIGHT 1.0 // Weighting15 12 16 13 bool ppStackReadout(pmConfig *config, const pmFPAview *view) … … 35 32 // Get the input sources 36 33 psArray *stack = psArrayAllocEmpty(ARRAY_BUFFER); // The stack of inputs 37 psMetadataIterator * inputIter = psMetadataIteratorAlloc(config->files, PS_LIST_HEAD,38 "^PPSTACK.INPUT$"); // Iterator over input files39 psMetadataItem * item;// Item from iteration34 psMetadataIterator *fileIter = psMetadataIteratorAlloc(config->files, PS_LIST_HEAD, 35 "^PPSTACK.INPUT$"); // Iterator over input files 36 psMetadataItem *fileItem; // Item from iteration 40 37 psStats *stats = psStatsAlloc(PS_STAT_ROBUST_MEDIAN); // Statistics 41 38 psRandom *rng = psRandomAlloc(0, PS_RANDOM_TAUS); // Random number generator 42 39 int fileNum = 0; // Number of file 43 40 float totExposure = 0.0; // Total exposure time 44 while (( item = psMetadataGetAndIncrement(inputIter))) {45 assert( item->type == PS_DATA_UNKNOWN);46 pmFPAfile *inputFile = item->data.V; // An input file41 while ((fileItem = psMetadataGetAndIncrement(fileIter))) { 42 assert(fileItem->type == PS_DATA_UNKNOWN); 43 pmFPAfile *inputFile = fileItem->data.V; // An input file 47 44 pmReadout *ro = pmFPAviewThisReadout(view, inputFile->fpa); // Corresponding readout 45 46 float seeing = psMetadataLookupF32(NULL, inputFile->fpa->analysis, "PPSTACK.SEEING"); // Seeing FWHM 47 float weight = psMetadataLookupF32(NULL, inputFile->fpa->analysis, "PPSTACK.WEIGHT"); // Rel. weight 48 float scale = psMetadataLookupF32(NULL, inputFile->fpa->analysis, "PPSTACK.SCALE"); // Rel. scale 48 49 49 50 // Brain-dead background subtraction … … 52 53 psFree(stats); 53 54 psFree(rng); 54 psFree( inputIter);55 psFree(fileIter); 55 56 psFree(stack); 56 57 psFree(outRO); … … 58 59 } 59 60 (void)psBinaryOp(ro->image, ro->image, "-", psScalarAlloc(stats->robustMedian, PS_TYPE_F32)); 61 62 // Apply scaling 63 (void)psBinaryOp(ro->image, ro->image, "*", psScalarAlloc(1.0 / scale, PS_TYPE_F32)); 60 64 61 65 // Normalise each input by the exposure time … … 66 70 psFree(stats); 67 71 psFree(rng); 68 psFree( inputIter);72 psFree(fileIter); 69 73 psFree(outRO); 70 74 psFree(stack); … … 73 77 totExposure += exposure; // Total exposure time 74 78 (void)psBinaryOp(ro->image, ro->image, "/", psScalarAlloc(exposure, PS_TYPE_F32)); 75 pmStackData *data = pmStackDataAlloc(ro, seeing ? seeing->data.F32[fileNum] : 0.0, 76 WEIGHT); // Data to stack 79 pmStackData *data = pmStackDataAlloc(ro, seeing, weight); // Data to stack 77 80 psArrayAdd(stack, ARRAY_BUFFER, data); 78 81 psFree(data); // Drop reference 79 82 fileNum++; 80 83 } 81 psFree( inputIter);84 psFree(fileIter); 82 85 psFree(stats); 83 86 psFree(rng);
Note:
See TracChangeset
for help on using the changeset viewer.
