Changeset 25101
- Timestamp:
- Aug 17, 2009, 6:55:35 PM (17 years ago)
- Location:
- trunk/psModules/src/imcombine
- Files:
-
- 5 edited
-
pmSubtractionKernels.c (modified) (1 diff)
-
pmSubtractionKernels.h (modified) (1 diff)
-
pmSubtractionMatch.c (modified) (1 diff)
-
pmSubtractionStamps.c (modified) (1 diff)
-
pmSubtractionStamps.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/imcombine/pmSubtractionKernels.c
r24296 r25101 765 765 return PM_SUBTRACTION_KERNEL_NONE; 766 766 } 767 768 pmSubtractionKernels *pmSubtractionKernelsCopy(const pmSubtractionKernels *in) 769 { 770 PM_ASSERT_SUBTRACTION_KERNELS_NON_NULL(in, NULL); 771 772 pmSubtractionKernels *out = psAlloc(sizeof(pmSubtractionKernels)); // Kernels, to return 773 psMemSetDeallocator(out, (psFreeFunc)subtractionKernelsFree); 774 775 out->type = in->type; 776 out->description = in->description; 777 out->num = in->num; 778 out->u = psMemIncrRefCounter(in->u); 779 out->v = psMemIncrRefCounter(in->v); 780 out->widths = psMemIncrRefCounter(in->widths); 781 out->preCalc = psMemIncrRefCounter(in->preCalc); 782 out->penalty = in->penalty; 783 out->penalties = psMemIncrRefCounter(in->penalties); 784 out->uStop = psMemIncrRefCounter(in->uStop); 785 out->vStop = psMemIncrRefCounter(in->vStop); 786 out->size = in->size; 787 out->inner = in->inner; 788 out->spatialOrder = in->spatialOrder; 789 out->bgOrder = in->bgOrder; 790 out->mode = in->mode; 791 out->numCols = in->numCols; 792 out->numRows = in->numRows; 793 out->solution1 = in->solution1 ? psVectorCopy(NULL, in->solution1, PS_TYPE_F64) : NULL; 794 out->solution2 = in->solution2 ? psVectorCopy(NULL, in->solution2, PS_TYPE_F64) : NULL; 795 796 return out; 797 } -
trunk/psModules/src/imcombine/pmSubtractionKernels.h
r20049 r25101 203 203 ); 204 204 205 /// Copy kernels 206 /// 207 /// A deep copy is performed on the solution only; the other components are merely pointers. 208 pmSubtractionKernels *pmSubtractionKernelsCopy( 209 const pmSubtractionKernels *in // Kernels to copy 210 ); 211 205 212 206 213 #endif -
trunk/psModules/src/imcombine/pmSubtractionMatch.c
r25060 r25101 869 869 return mode; 870 870 } 871 872 873 #if 0 874 /// A list of stamps 875 typedef struct { 876 long num; ///< Number of stamps 877 psArray *stamps; ///< The stamps 878 psArray *regions; ///< Regions for each stamp 879 psArray *x, *y; ///< Coordinates for possible stamps (or NULL) 880 psArray *flux; ///< Fluxes for possible stamps (or NULL) 881 int footprint; ///< Half-size of stamps 882 } pmSubtractionStampList; 883 884 /// A stamp for image subtraction 885 typedef struct { 886 float x, y; ///< Position 887 float flux; ///< Flux 888 float xNorm, yNorm; ///< Normalised position 889 psKernel *image1; ///< Reference image postage stamp 890 psKernel *image2; ///< Input image postage stamp 891 psKernel *variance; ///< Variance image postage stamp, or NULL 892 psArray *convolutions1; ///< Convolutions of image 1 for each kernel component, or NULL 893 psArray *convolutions2; ///< Convolutions of image 2 for each kernel component, or NULL 894 psImage *matrix1, *matrix2; ///< Least-squares matrices for each image, or NULL 895 psImage *matrixX; ///< Cross-matrix (for mode DUAL), or NULL 896 psVector *vector1, *vector2; ///< Least-squares vectors for each image, or NULL 897 pmSubtractionStampStatus status; ///< Status of stamp 898 } pmSubtractionStamp; 899 900 /// Kernels specification 901 typedef struct { 902 pmSubtractionKernelsType type; ///< Type of kernels --- allowing the use of multiple kernels 903 psString description; ///< Description of the kernel parameters 904 long num; ///< Number of kernel components (not including the spatial ones) 905 psVector *u, *v; ///< Offset (for POIS) or polynomial order (for ISIS) 906 psVector *widths; ///< Gaussian FWHMs (ISIS) 907 psVector *uStop, *vStop; ///< Width of kernel element (SPAM,FRIES only) 908 psArray *preCalc; ///< Array of images containing pre-calculated kernel (for ISIS) 909 float penalty; ///< Penalty for wideness 910 psVector *penalties; ///< Penalty for each kernel component 911 int size; ///< The half-size of the kernel 912 int inner; ///< The size of an inner region 913 int spatialOrder; ///< The spatial order of the kernels 914 int bgOrder; ///< The order for the background fitting 915 pmSubtractionMode mode; ///< Mode for subtraction 916 int numCols, numRows; ///< Size of image (for normalisation), or zero to use image provided 917 psVector *solution1, *solution2; ///< Solution for the PSF matching 918 // Quality information 919 float mean, rms; ///< Mean and RMS of chi^2 from stamps 920 int numStamps; ///< Number of good stamps 921 } pmSubtractionKernels; 922 923 // Test a subtraction mode by performing a single iteration 924 static bool subtractionModeTest(pmSubtractionStampList *stamps, // Stamps to use to find best mode 925 pmSubtractionKernels *kernels, // Kernel description 926 const char *description // Description for trace 927 ) 928 { 929 assert(stamps); 930 assert(kernels); 931 932 psTrace("psModules.imcombine", 3, "Calculating %s equation...\n", description); 933 if (!pmSubtractionCalculateEquation(stamps, kernels)) { 934 psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation."); 935 return false; 936 } 937 938 psTrace("psModules.imcombine", 3, "Solving %s equation...\n", description); 939 if (!pmSubtractionSolveEquation(kernels, stamps)) { 940 psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation."); 941 kernels->mode = oldMode; 942 return false; 943 } 944 945 psTrace("psModules.imcombine", 3, "Calculate %s deviations...\n", description); 946 psVector *deviations = pmSubtractionCalculateDeviations(stamps, kernels); // Stamp deviations 947 if (!deviations) { 948 psError(PS_ERR_UNKNOWN, false, "Unable to calculate deviations."); 949 return false; 950 } 951 952 psTrace("psModules.imcombine", 3, "Rejecting %s stamps...\n", description); 953 long numRejected = pmSubtractionRejectStamps(kernels, stamps, deviations, subMask, rej, footprint); 954 if (numRejected < 0) { 955 psError(PS_ERR_UNKNOWN, false, "Unable to reject stamps."); 956 psFree(deviations); 957 return false; 958 } 959 psFree(deviations); 960 961 if (numRejected > 0) { 962 psTrace("psModules.imcombine", 3, "Solving equation...\n"); 963 if (!pmSubtractionSolveEquation(kernels, stamps)) { 964 psError(PS_ERR_UNKNOWN, false, "Unable to calculate least-squares equation."); 965 return false; 966 } 967 psVector *deviations = pmSubtractionCalculateDeviations(stamps, kernels); // Stamp deviations 968 if (!deviations) { 969 psError(PS_ERR_UNKNOWN, false, "Unable to calculate deviations."); 970 return false; 971 } 972 psFree(deviations); 973 } 974 975 return true; 976 } 977 978 979 pmSubtractionMode pmSubtractionBestMode(pmSubtractionStampList *stamps, pmSubtractionKernels *kernels) 980 { 981 PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(stamps, PM_SUBTRACTION_MODE_ERR); 982 PM_ASSERT_SUBTRACTION_KERNELS_NON_NULL(kernels, PM_SUBTRACTION_MODE_ERR); 983 984 // Copies of the inputs so we can try each way 985 pmSubtractionStampList *stamps1 = pmSubtractionStampsListCopy(stamps); 986 pmSubtractionStampList *stamps2 = pmSubtractionStampsListCopy(stamps); 987 988 pmSubtractionKernels *kernels1 = pmSubtractionKernelsCopy(kernels); 989 pmSubtractionKernels *kernels2 = pmSubtractionKernelsCopy(kernels); 990 991 kernels1->mode = PM_SUBTRACTION_MODE_1; 992 kernels2->mode = PM_SUBTRACTION_MODE_2; 993 994 995 subtractionModeTest(stamps1, kernels1, "forward"); 996 subtractionModeTest(stamps2, kernels2, "backward"); 997 998 // XXX Compare kernels1->mean, kernels2->mean 999 } 1000 1001 #endif -
trunk/psModules/src/imcombine/pmSubtractionStamps.c
r24066 r25101 225 225 } 226 226 227 pmSubtractionStampList *pmSubtractionStampListCopy(const pmSubtractionStampList *in) 228 { 229 PM_ASSERT_SUBTRACTION_STAMP_LIST_NON_NULL(in, NULL); 230 231 pmSubtractionStampList *out = psAlloc(sizeof(pmSubtractionStampList)); // Copied stamp list to return 232 psMemSetDeallocator(out, (psFreeFunc)subtractionStampListFree); 233 234 int num = out->num = in->num; // Number of stamps 235 out->stamps = psArrayAlloc(num); 236 out->regions = psArrayAlloc(num); 237 out->x = NULL; 238 out->y = NULL; 239 out->flux = NULL; 240 out->footprint = in->footprint; 241 242 for (int i = 0; i < num; i++) { 243 psRegion *inRegion = in->regions->data[i]; // Input region 244 out->regions->data[i] = psRegionAlloc(inRegion->x0, inRegion->x1, inRegion->y0, inRegion->y1); 245 246 pmSubtractionStamp *inStamp = in->stamps->data[i]; // Input stamp 247 pmSubtractionStamp *outStamp = psAlloc(sizeof(pmSubtractionStamp)); 248 psMemSetDeallocator(outStamp, (psFreeFunc)subtractionStampFree); 249 outStamp->x = inStamp->x; 250 outStamp->y = inStamp->y; 251 outStamp->flux = inStamp->flux; 252 outStamp->xNorm = inStamp->xNorm; 253 outStamp->yNorm = inStamp->yNorm; 254 outStamp->status = inStamp->status; 255 256 outStamp->image1 = psKernelCopy(inStamp->image1); 257 outStamp->image2 = psKernelCopy(inStamp->image2); 258 outStamp->variance = psKernelCopy(inStamp->variance); 259 260 if (inStamp->convolutions1) { 261 int size = inStamp->convolutions1->n; // Size of array 262 outStamp->convolutions1 = psArrayAlloc(size); 263 for (int j = 0; j < size; j++) { 264 outStamp->convolutions1->data[j] = psKernelCopy(inStamp->convolutions1->data[j]); 265 } 266 } 267 if (inStamp->convolutions2) { 268 int size = inStamp->convolutions2->n; // Size of array 269 outStamp->convolutions2 = psArrayAlloc(size); 270 for (int j = 0; j < size; j++) { 271 outStamp->convolutions2->data[j] = psKernelCopy(inStamp->convolutions2->data[j]); 272 } 273 } 274 275 outStamp->matrix1 = inStamp->matrix1 ? psImageCopy(NULL, inStamp->matrix1, PS_TYPE_F64) : NULL; 276 outStamp->matrix2 = inStamp->matrix2 ? psImageCopy(NULL, inStamp->matrix2, PS_TYPE_F64) : NULL; 277 outStamp->matrixX = inStamp->matrixX ? psImageCopy(NULL, inStamp->matrixX, PS_TYPE_F64) : NULL; 278 outStamp->vector1 = inStamp->vector1 ? psVectorCopy(NULL, inStamp->vector1, PS_TYPE_F64) : NULL; 279 outStamp->vector2 = inStamp->vector2 ? psVectorCopy(NULL, inStamp->vector2, PS_TYPE_F64) : NULL; 280 281 out->stamps->data[i] = outStamp; 282 } 283 284 return out; 285 } 286 227 287 pmSubtractionStamp *pmSubtractionStampAlloc(void) 228 288 { -
trunk/psModules/src/imcombine/pmSubtractionStamps.h
r23937 r25101 52 52 } \ 53 53 } 54 55 /// Copy a list of stamps 56 /// 57 /// A deep copy is performed of the stamp list and the component stamps 58 pmSubtractionStampList *pmSubtractionStampListCopy( 59 const pmSubtractionStampList *in // Stamp list to copy 60 ); 61 54 62 55 63 /// A stamp for image subtraction
Note:
See TracChangeset
for help on using the changeset viewer.
