Changeset 34487
- Timestamp:
- Sep 27, 2012, 6:30:59 PM (14 years ago)
- Location:
- branches/czw_branch/20120906/pswarp/src
- Files:
-
- 2 edited
-
pswarpLoop.c (modified) (20 diffs)
-
pswarpTransformReadout.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/czw_branch/20120906/pswarp/src/pswarpLoop.c
r34471 r34487 458 458 bool status; 459 459 bool mdok; // Status of MD lookup 460 461 460 const char *skyCamera = psMetadataLookupStr(NULL, config->arguments, 462 461 "SKYCELL.CAMERA"); // Name of camera for skycell … … 505 504 } 506 505 psFree (view); 507 508 506 // Turn all skycell files on to generate them, and then turn them off for the loop over the input images 509 507 // the input, which is in a different format. … … 519 517 pswarpFileActivation(config, skycellFiles, false); 520 518 } 521 522 519 // Read the input astrometry 523 520 // XXX rather than use the activations here, this should just explicitly loop over the desired filerule 524 521 { 525 pmFPAfileActivate(config->files, true, "PSWARP.ASTROM"); 522 523 pmFPAfileActivate(config->files, true, "PSWARP.ASTROM"); 526 524 527 525 pmChip *chip; … … 531 529 goto DONE; 532 530 } 531 533 532 while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) { 534 psTrace ("pswarp", 4, "AChip %d: %x %x\n", view->chip, chip->file_exists, chip->process); 533 #if 0 534 // This needs to be removed because otherwise it throws an error of duplicate PSPHOT.DETECTIONS. 535 535 if (!chip->process || !chip->file_exists) { continue; } 536 536 if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) { … … 538 538 goto DONE; 539 539 } 540 #endif 540 541 pmCell *cell; 541 542 while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) { 542 psTrace ("pswarp", 4, "ACell %d: %x %x\n", view->cell, cell->file_exists, cell->process);543 psTrace ("pswarp", 4, "ACell %d: %x %x %d\n", view->cell, cell->file_exists, cell->process,psErrorCodeLast()); 543 544 if (!cell->process || !cell->file_exists) { continue; } 544 545 if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE) || … … 558 559 } 559 560 psFree(view); 560 561 561 pswarpFileActivation(config, detectorFiles, true); 562 562 pmFPAfileActivate(config->files, false, "PSWARP.ASTROM"); 563 563 } 564 565 /* // Turn on the source output --- we need to get rid of these so that we can measure the PSF */566 /* pmFPAfileActivate(config->files, true, "PSWARP.OUTPUT.SOURCES"); */567 564 568 565 // Don't care about the skycell anymore --- we've read it, and that's all we need to do. … … 574 571 pmHDU *phu = pmFPAviewThisPHU(view, astrom->fpa); 575 572 576 pmAstromWCS *WCSF = pmAstromWCSfromHeader(phu->header); 577 578 fprintf(stderr,"WCSF: %g %g : %g %g : %g %g : %g %g %g %g : %g %g\n", 579 WCSF->crval1,WCSF->crval2, 580 WCSF->crpix1,WCSF->crpix2, 581 WCSF->cdelt1,WCSF->cdelt2, 582 WCSF->trans->x->coeff[1][0], 583 WCSF->trans->x->coeff[0][1], 584 WCSF->trans->y->coeff[1][0], 585 WCSF->trans->y->coeff[0][1], 586 -1.0,-1.0); 587 /* #define CORRECT_INPUT_WCS 1 */ 588 /* #if CORRECT_INPUT_WCS */ 589 /* // Correct the input WCS */ 590 /* pmAstromWCS *WCS = pmAstromWCSfromHeader(phu->header); */ 591 592 /* double cd1f = 1.0 * 400; */ 593 /* double cd2f = 1.0 * 400; */ 594 /* fprintf(stderr,"WCS: %g %g : %g %g : %g %g : %g %g %g %g : %g %g\n", */ 595 /* WCS->crval1,WCS->crval2, */ 596 /* WCS->crpix1,WCS->crpix2, */ 597 /* WCS->cdelt1,WCS->cdelt2, */ 598 /* WCS->trans->x->coeff[1][0], */ 599 /* WCS->trans->x->coeff[0][1], */ 600 /* WCS->trans->y->coeff[1][0], */ 601 /* WCS->trans->y->coeff[0][1], */ 602 /* cd1f,cd2f); */ 603 604 /* WCS->crpix1 = WCS->crpix1 / cd1f; */ 605 /* WCS->crpix2 = WCS->crpix2 / cd2f; */ 606 607 /* WCS->cdelt1 *= cd1f; */ 608 /* WCS->cdelt2 *= cd2f; */ 609 610 /* // WCS->trans->x->nX/nY */ 611 /* for (int q = 0; q < WCS->trans->x->nX; q++) { */ 612 /* for (int r = 0; r < WCS->trans->x->nY; r++) { */ 613 /* WCS->trans->x->coeff[q][r] *= cd1f; */ 614 /* } */ 615 /* } */ 616 /* for (int q = 0; q < WCS->trans->y->nX; q++) { */ 617 /* for (int r = 0; r < WCS->trans->y->nY; r++) { */ 618 /* WCS->trans->y->coeff[q][r] *= cd2f; */ 619 /* } */ 620 /* } */ 621 /* fprintf(stderr,"WCS: %g %g : %g %g : %g %g : %g %g %g %g : %g %g\n", */ 622 /* WCS->crval1,WCS->crval2, */ 623 /* WCS->crpix1,WCS->crpix2, */ 624 /* WCS->cdelt1,WCS->cdelt2, */ 625 /* WCS->trans->x->coeff[1][0], */ 626 /* WCS->trans->x->coeff[0][1], */ 627 /* WCS->trans->y->coeff[1][0], */ 628 /* WCS->trans->y->coeff[0][1], */ 629 /* cd1f,cd2f); */ 630 /* pmAstromWCStoHeader (phu->header,WCS); */ 631 /* // End WCS work. */ 632 /* #endif */ 633 634 635 573 // pmAstromWCS *WCSF = pmAstromWCSfromHeader(phu->header); 636 574 637 575 if (phu) { … … 649 587 } 650 588 } 651 652 653 589 654 590 psList *cells = psListAlloc(NULL); // List of cells, for concepts averaging … … 676 612 double cd1f = 1.0 * 400; 677 613 double cd2f = 1.0 * 400; 678 fprintf(stderr,"WCSC: %g %g : %g %g : %g %g : %g %g %g %g : %g %g\n",679 WCS->crval1,WCS->crval2,680 WCS->crpix1,WCS->crpix2,681 WCS->cdelt1,WCS->cdelt2,682 WCS->trans->x->coeff[1][0],683 WCS->trans->x->coeff[0][1],684 WCS->trans->y->coeff[1][0],685 WCS->trans->y->coeff[0][1],686 cd1f,cd2f);687 688 614 689 615 WCS->cdelt1 *= cd1f; … … 695 621 for (int q = 0; q <= WCS->trans->x->nX; q++) { 696 622 for (int r = 0; r <= WCS->trans->x->nY; r++) { 697 fprintf(stderr,"%d %d %g\n",q,r,WCS->trans->x->coeff[q][r]);698 623 WCS->trans->x->coeff[q][r] *= pow(cd1f,q) * pow(cd2f,r); 699 fprintf(stderr,"%d %d %g\n",q,r,WCS->trans->x->coeff[q][r]);700 624 } 701 625 } 702 626 for (int q = 0; q <= WCS->trans->y->nX; q++) { 703 627 for (int r = 0; r <= WCS->trans->y->nY; r++) { 704 fprintf(stderr,"%d %d %g\n",q,r,WCS->trans->y->coeff[q][r]);705 628 WCS->trans->y->coeff[q][r] *= pow(cd1f,q) * pow(cd2f,r); 706 fprintf(stderr,"%d %d %g\n",q,r,WCS->trans->y->coeff[q][r]);707 629 } 708 630 } 709 fprintf(stderr,"WCSO: %g %g : %g %g : %g %g : %g %g %g %g : %g %g\n",710 WCS->crval1,WCS->crval2,711 WCS->crpix1,WCS->crpix2,712 WCS->cdelt1,WCS->cdelt2,713 WCS->trans->x->coeff[1][0],714 WCS->trans->x->coeff[0][1],715 WCS->trans->y->coeff[1][0],716 WCS->trans->y->coeff[0][1],717 cd1f,cd2f);718 719 fprintf(stderr,"Size: %d %d %d %d\n",WCS->trans->x->nX,WCS->trans->x->nY,WCS->trans->y->nX,WCS->trans->y->nY);720 631 pmAstromWCStoHeader (hdu->header,WCS); 721 632 … … 761 672 } 762 673 763 // Copy the detections from the astrometry carrier to the input, so they can be accessed by764 // pswarpTransformReadout765 /* pmReadout *astromRO = pmFPAviewThisReadout(view, astrom->fpa); // Readout for astrometry */766 /* pmDetections *detections = psMetadataLookupPtr(&mdok, astromRO->analysis, "PSPHOT.DETECTIONS"); // Sources from astrometry */767 /* if (detections) { */768 /* psMetadataAddPtr(readout->analysis, PS_LIST_TAIL, "PSPHOT.DETECTIONS", PS_DATA_ARRAY | PS_META_REPLACE, "Sources from input astrometry", detections); */769 /* } */770 771 674 for (int x = 0; x < readout->image->numCols; x++) { 772 675 for (int y = 0; y < readout->image->numRows; y++) { … … 778 681 779 682 psMetadataAddS32(config->arguments,PS_LIST_TAIL, "INTERPOLATION.MODE", PS_META_REPLACE, "", 8); 780 781 683 fprintf(stderr,"Transforming Readout!\n"); 782 684 … … 784 686 pswarpTransformReadout(output, readout, config); 785 687 psMetadataAddBool(config->arguments,PS_LIST_TAIL, "BACKGROUND_WARPING", PS_META_REPLACE, "", false); 786 787 688 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 788 689 psError(psErrorCodeLast(), false, "Unable to write files."); … … 800 701 } 801 702 } 802 703 fprintf(stderr,"End readout transformations!\n"); 803 704 if (!output->data_exists) { 804 705 psWarning("No overlap between input and skycell."); 805 /* if (stats) { */806 /* psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", PS_META_REPLACE, */807 /* "No overlap between input and skycell", PSWARP_ERR_NO_OVERLAP); */808 /* } */809 706 psphotFilesActivate(config, false); 810 707 psFree(cells); … … 812 709 goto DONE; 813 710 } 814 815 711 pmCell *outCell = output->parent; ///< Output cell 816 712 pmChip *outChip = outCell->parent; ///< Output chip … … 823 719 goto DONE; 824 720 } 825 /* bool doStats = psMetadataLookupBool(&mdok,recipe,"MASK.STATS"); */826 /* if (doStats) { */827 /* if (!pswarpMaskStats(output, stats, config)) { */828 /* psError(psErrorCodeLast(), false, "Unable to calculate mask stats."); */829 /* psFree(cells); */830 /* psFree(view); */831 /* goto DONE; */832 /* } */833 /* } */834 /* // Set covariance matrix for output */835 /* { */836 /* psList *covariances = psMetadataLookupPtr(&mdok, output->analysis, */837 /* PSWARP_ANALYSIS_COVARIANCES); // Covariance matrices */838 /* psAssert(covariances, "Should be there"); */839 /* psArray *covars = psListToArray(covariances); // Array of covariance matrices */840 /* psKernel *covar = psImageCovarianceAverage(covars); */841 /* psFree(covars); */842 /* psMetadataRemoveKey(output->analysis, PSWARP_ANALYSIS_COVARIANCES); */843 844 /* // Correct covariance matrix scale for the mean (square root of the) Jacobian */845 /* double jacobian = psMetadataLookupF64(NULL, output->analysis, PSWARP_ANALYSIS_JACOBIAN); // Jacobian */846 /* int goodPixels = psMetadataLookupS32(NULL, output->analysis, PSWARP_ANALYSIS_GOODPIX); // Good pixels */847 /* jacobian /= goodPixels; */848 /* output->covariance = psImageCovarianceScale(covar, jacobian); */849 /* psFree(covar); */850 851 /* if (output->variance) { */852 /* psImageCovarianceTransfer(output->variance, output->covariance); */853 /* } */854 /* } */855 856 /* if (!pmConceptsAverageCells(outCell, cells, NULL, NULL, false)) { */857 /* psError(psErrorCodeLast(), false, "Unable to average cell concepts."); */858 /* psFree(stats); */859 /* psFree(cells); */860 /* psFree(view); */861 /* goto DONE; */862 /* } */863 /* psFree(cells); */864 721 865 722 psRegion *trimsec = psMetadataLookupPtr(NULL, outCell->concepts, "CELL.TRIMSEC"); ///< Trim section … … 872 729 goto DONE; 873 730 } 874 875 // Update ZP from the astrometry876 /* { */877 /* psMetadataItem *item = psMetadataLookup(outFPA->concepts, "FPA.ZP"); */878 /* item->data.F32 = psMetadataLookupF32(NULL, astrom->fpa->concepts, "FPA.ZP"); */879 /* } */880 731 881 732 pmHDU *hdu = outFPA->hdu; ///< HDU for the output warped image … … 895 746 hdu->header = psMetadataCopy(hdu->header, skyHDU->header); 896 747 } 897 898 748 pswarpVersionHeader(hdu->header); 899 749 … … 903 753 goto DONE; 904 754 } 905 906 755 if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) { 907 756 psError(psErrorCodeLast(), false, "Unable to write files."); 908 757 goto DONE; 909 758 } 910 911 759 // Done with the detector side of things 912 760 pswarpFileActivation(config, detectorFiles, false); 913 761 pswarpFileActivation(config, independentFiles, false); 914 915 916 // We need a new PSF model for the warped frame. It would be good to generate this analytically, but917 // that's going to be tricky. We have a list of sources, so we use those to redetermine the PSF model.918 919 /* if (psMetadataLookupBool(&mdok, recipe, "PSF")) { */920 /* pswarpFileActivation(config, photFiles, true); */921 /* if (!pswarpIOChecksBefore(config)) { */922 /* psError(psErrorCodeLast(), false, "Unable to read files."); */923 /* goto DONE; */924 /* } */925 926 /* // supply the readout and fpa of interest to psphot */927 /* pmFPAfile *photFile = psMetadataLookupPtr(NULL, config->files, "PSPHOT.INPUT"); */928 /* pmFPACopy(photFile->fpa, outFPA); */929 930 /* pmFPAview *view = pmFPAviewAlloc(0); ///< View into skycell */931 /* view->chip = view->cell = view->readout = 0; */932 933 /* // grab the sources of interest from the storage location (pmFPAfile PSPHOT.INPUT.CMF) */934 /* psArray *sources = psphotLoadPSFSources (config, view); */935 /* if (!sources) { */936 /* psError(psErrorCodeLast(), false, "No sources supplied to measure PSF"); */937 /* goto DONE; */938 /* } */939 940 /* pmModelClassSetLimits(PM_MODEL_LIMITS_STRICT); */941 942 /* // measure the PSF using these sources */943 /* if (!psphotReadoutFindPSF(config, view, "PSPHOT.INPUT", sources)) { */944 /* // This is likely a data quality issue */945 /* // XXX Split into multiple cases using error codes? */946 /* psErrorStackPrint(stderr, "Unable to determine PSF"); */947 /* psWarning("Unable to determine PSF --- suspect bad data quality."); */948 /* if (stats && psMetadataLookupS32(NULL, stats, "QUALITY") == 0) { */949 /* psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", PS_META_REPLACE, */950 /* "Unable to determine PSF", psErrorCodeLast()); */951 /* } */952 /* psErrorClear(); */953 /* psphotFilesActivate(config, false); */954 /* } */955 956 /* // Ensure seeing is carried over */957 /* pmChip *photChip = pmFPAviewThisChip(view, photFile->fpa); // Chip with seeing */958 /* psMetadataItem *item = psMetadataLookup(outChip->concepts, "CHIP.SEEING"); // Concept with seeing */959 /* item->data.F32 = psMetadataLookupF32(NULL, photChip->concepts, "CHIP.SEEING"); */960 961 /* // XXX EAM : put this in a visualization function */962 /* #if (TESTING) */963 /* { */964 /* #define PSF_SIZE 20 ///< Half-size of PSF */965 /* #define PSF_FLUX 10000 ///< Central flux for PSF */966 /* pmChip *photChip = pmFPAviewThisChip(view, photFile->fpa); */967 /* pmPSF *psf = psMetadataLookupPtr(NULL, photChip->analysis, "PSPHOT.PSF"); */968 /* psImage *image = psImageAlloc(2 * PSF_SIZE + 1, 2 * PSF_SIZE + 1, PS_TYPE_F32); */969 /* psImageInit(image, 0); */970 /* pmModel *model = pmModelFromPSFforXY(psf, PSF_SIZE, PSF_SIZE, PSF_FLUX); */971 /* pmModelAdd(image, NULL, model, PM_MODEL_OP_FULL, 0); */972 /* psFree(model); */973 /* psFits *fits = psFitsOpen("psf.fits", "w"); */974 /* psFitsWriteImage(fits, NULL, image, 0, NULL); */975 /* psFitsClose(fits); */976 /* psFree(image); */977 /* } */978 /* #endif */979 980 /* psFree(view); */981 /* } */982 983 /* // Perform statistics on the output image */984 /* if (stats) { */985 /* if (!ppStatsFPA(stats, output->parent->parent->parent, view, maskValue, config)) { */986 /* psWarning("Unable to perform statistics on warped image."); */987 /* } */988 /* } */989 762 990 763 … … 1002 775 psFree(headerName); 1003 776 psFree(view); 1004 1005 777 DONE: 1006 778 -
branches/czw_branch/20120906/pswarp/src/pswarpTransformReadout.c
r34471 r34487 202 202 203 203 if (goodPixels > 0 && psMetadataLookupBool(&mdok, recipe, "SOURCES")) { 204 if (!psMetadataLookupBool(NULL,config->arguments,"BACKGROUND_WARPING")) { 204 205 if (!pswarpTransformSources(output, input, config)) { 205 psError(psErrorCodeLast(), false, "Unable to interpolate image.");206 return false;206 psError(psErrorCodeLast(), false, "Unable to interpolate image."); 207 return false; 207 208 } 209 } 208 210 } 209 211
Note:
See TracChangeset
for help on using the changeset viewer.
