Changeset 19914
- Timestamp:
- Oct 6, 2008, 3:15:02 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/psphot/src/psphotRoughClass.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psphot/src/psphotRoughClass.c
r16820 r19914 1 1 # include "psphotInternal.h" 2 2 3 # define CHECK_STATUS(S,MSG) { \ 4 if (!status) { \ 5 psError(PSPHOT_ERR_CONFIG, false, "missing PSF Clump entry: %s\n", MSG); \ 6 return false; \ 7 } } 3 # define CHECK_STATUS(S,MSG) { \ 4 if (!status) { \ 5 psError(PSPHOT_ERR_CONFIG, false, "missing PSF Clump entry: %s\n", MSG); \ 6 return false; \ 7 } } 8 9 bool psphotRoughClassRegion (int nRegion, psRegion *region, psArray *sources, psMetadata *recipe, const bool havePSF); 8 10 9 11 // 2006.02.02 : no leaks 10 bool psphotRoughClass (p sArray *sources, psMetadata *recipe, const bool havePSF) {12 bool psphotRoughClass (pmReadout *readout, psArray *sources, psMetadata *recipe, const bool havePSF) { 11 13 12 14 bool status; 13 static pmPSFClump psfClump;14 15 15 16 psTimerStart ("psphot"); 16 17 17 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) 18 psMaskType maskSat = psMetadataLookupU8(&status, recipe, "MASK.SAT"); // Mask value for bad pixels 19 assert (maskSat); 18 // we make this measurement on a NxM grid of regions across the readout 19 int NX = psMetadataLookupS32 (&status, recipe, "PSF_CLUMP_NX"); CHECK_STATUS (status, "PSF_CLUMP_NX"); 20 int NY = psMetadataLookupS32 (&status, recipe, "PSF_CLUMP_NY"); CHECK_STATUS (status, "PSF_CLUMP_NY"); 21 int dX = readout->image->numCols / NX; 22 int dY = readout->image->numRows / NY; 20 23 21 i f (!havePSF) {22 // determine the PSF parameters from the source moment values23 psfClump = pmSourcePSFClump (sources, recipe); 24 psMetadataAddF32 (recipe, PS_LIST_TAIL, "PSF.CLUMP.X", PS_META_REPLACE, "psf clump center", psfClump.X); 25 psMetadataAddF32 (recipe, PS_LIST_TAIL, "PSF.CLUMP.Y", PS_META_REPLACE, "psf clump center", psfClump.Y);26 psMetadataAddF32 (recipe, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX);27 psMetadataAddF32 (recipe, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY);28 } else { 29 // pull FWHM_X,Y from the recipe, use to define psfClump.X,Y 30 psfClump.X = psMetadataLookupF32 (&status, recipe, "PSF.CLUMP.X"); CHECK_STATUS (status, "PSF.CLUMP.X"); 31 psfClump.Y = psMetadataLookupF32 (&status, recipe, "PSF.CLUMP.Y"); CHECK_STATUS (status, "PSF.CLUMP.Y"); 32 psfClump.dX = psMetadataLookupF32 (&status, recipe, "PSF.CLUMP.DX"); CHECK_STATUS (status, "PSF.CLUMP.DX");33 psfClump.dY = psMetadataLookupF32 (&status, recipe, "PSF.CLUMP.DY"); CHECK_STATUS (status, "PSF.CLUMP.DY"); 24 int nRegion = 0; 25 for (int ix = 0; ix < NX; ix ++) { 26 for (int iy = 0; iy < NY; iy ++) { 27 28 psRegion region = psRegionSet (ix*dX, (ix + 1)*dX, iy*dY, (iy + 1)*dY); 29 if (!psphotRoughClassRegion (nRegion, ®ion, sources, recipe, havePSF)) { 30 psError (PSPHOT_ERR_UNKNOWN, false, "failed to determine rough classification for region %d (%f - %f : %f - %f)\n", 31 nRegion, region.x0, region.x1, region.y0, region.y1); 32 return false; 33 } 34 35 nRegion ++; 36 } 34 37 } 35 36 if (psfClump.X < 0) { 37 psError(PSPHOT_ERR_PROG, false, "programming error calling pmSourcePSFClump"); 38 return false; 39 } 40 if (!psfClump.X || !psfClump.Y) { 41 psError(PSPHOT_ERR_DATA, true, "Failed to find a valid PSF clump"); 42 return false; 43 } 44 psLogMsg ("psphot", 3, "psf clump X, Y: %f, %f\n", psfClump.X, psfClump.Y); 45 psLogMsg ("psphot", 3, "psf clump DX, DY: %f, %f\n", psfClump.dX, psfClump.dY); 46 47 // group into STAR, COSMIC, EXTENDED, SATURATED, etc. 48 if (!pmSourceRoughClass (sources, recipe, psfClump, maskSat)) { 49 psError(PSPHOT_ERR_PROG, false, "programming error calling pmSourceRoughClass"); 50 return false; 51 } 38 psMetadataAddS32 (recipe, PS_LIST_TAIL, "PSF.CLUMP.NREGIONS", PS_META_REPLACE, "psf clump regions", nRegion); 52 39 53 40 // optional printout of source moments only … … 56 43 psLogMsg ("psphot.roughclass", PS_LOG_INFO, "rough classification: %f sec\n", psTimerMark ("psphot")); 57 44 45 psphotVisualPlotMoments (recipe, sources); 46 psphotVisualShowRoughClass (sources); 47 psphotVisualShowFlags (sources); 48 58 49 return true; 59 50 } 60 51 52 bool psphotRoughClassRegion (int nRegion, psRegion *region, psArray *sources, psMetadata *recipe, const bool havePSF) { 53 54 bool status; 55 char regionName[64]; 56 pmPSFClump psfClump; 57 58 // user-defined masks to test for good/bad pixels (build from recipe list if not yet set) 59 psMaskType maskSat = psMetadataLookupU8(&status, recipe, "MASK.SAT"); // Mask value for bad pixels 60 assert (maskSat); 61 62 snprintf (regionName, 64, "PSF.CLUMP.REGION.%03d", nRegion); 63 psMetadata *regionMD = psMetadataLookupPtr (&status, recipe, regionName); 64 if (!regionMD) { 65 regionMD = psMetadataAlloc(); 66 psMetadataAddMetadata (recipe, PS_LIST_TAIL, regionName, PS_META_REPLACE, "psf clump region", regionMD); 67 psFree (regionMD); 68 } 69 70 if (!havePSF) { 71 // determine the PSF parameters from the source moment values 72 psfClump = pmSourcePSFClump (region, sources, recipe); 73 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.X", PS_META_REPLACE, "psf clump center", psfClump.X); 74 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.Y", PS_META_REPLACE, "psf clump center", psfClump.Y); 75 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DX", PS_META_REPLACE, "psf clump center", psfClump.dX); 76 psMetadataAddF32 (regionMD, PS_LIST_TAIL, "PSF.CLUMP.DY", PS_META_REPLACE, "psf clump center", psfClump.dY); 77 } else { 78 // pull FWHM_X,Y from the recipe, use to define psfClump.X,Y 79 psfClump.X = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.X"); CHECK_STATUS (status, "PSF.CLUMP.X"); 80 psfClump.Y = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.Y"); CHECK_STATUS (status, "PSF.CLUMP.Y"); 81 psfClump.dX = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DX"); CHECK_STATUS (status, "PSF.CLUMP.DX"); 82 psfClump.dY = psMetadataLookupF32 (&status, regionMD, "PSF.CLUMP.DY"); CHECK_STATUS (status, "PSF.CLUMP.DY"); 83 } 84 85 if (psfClump.X < 0) { 86 psError(PSPHOT_ERR_PROG, false, "programming error calling pmSourcePSFClump"); 87 return false; 88 } 89 if (!psfClump.X || !psfClump.Y) { 90 psError(PSPHOT_ERR_DATA, true, "Failed to find a valid PSF clump"); 91 return false; 92 } 93 psLogMsg ("psphot", 3, "psf clump X, Y: %f, %f\n", psfClump.X, psfClump.Y); 94 psLogMsg ("psphot", 3, "psf clump DX, DY: %f, %f\n", psfClump.dX, psfClump.dY); 95 96 // group into STAR, COSMIC, EXTENDED, SATURATED, etc. 97 if (!pmSourceRoughClass (region, sources, recipe, psfClump, maskSat)) { 98 psError(PSPHOT_ERR_PROG, false, "programming error calling pmSourceRoughClass"); 99 return false; 100 } 101 102 return true; 103 }
Note:
See TracChangeset
for help on using the changeset viewer.
