- Timestamp:
- May 3, 2010, 8:41:49 AM (16 years ago)
- Location:
- branches/tap_branches
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/tap_branches
- Property svn:mergeinfo changed
-
branches/tap_branches/psModules
-
Property svn:mergeinfo
set to (toggle deleted branches)
/trunk/psModules merged eligible /branches/eam_branches/stackphot.20100406/psModules 27623-27653 /branches/pap_delete/psModules 27530-27595
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
branches/tap_branches/psModules/src/astrom/pmAstrometryWCS.c
r25876 r27838 378 378 // XXX make it optional to write out CDi_j terms, or other versions 379 379 // apply CDELT1,2 (degrees / pixel) to yield PCi,j terms of order unity 380 if (! (wcs->wcsCDkeys)) {380 if (!wcs->wcsCDkeys) { 381 381 382 382 double cdelt1 = wcs->cdelt1; … … 419 419 psMetadataRemoveKey(header, "CD2_2"); 420 420 } 421 } 422 if (wcs->wcsCDkeys) { 421 } else { 423 422 424 423 psMetadataAddF64 (header, PS_LIST_TAIL, "CD1_1", PS_META_REPLACE, "", wcs->trans->x->coeff[1][0]); … … 845 844 int k=0; 846 845 for (int j=0; j<nSamples; j++) { 847 double y = j * deltaY / nSamples;846 double y = bounds->y0 + (j * deltaY / nSamples); 848 847 for (int i=0; i<nSamples; i++) { 849 848 psPlane *s = psPlaneAlloc(); 850 s->x = i * deltaX / nSamples;849 s->x = bounds->x0 + (i * deltaX / nSamples); 851 850 s->y = y; 852 851 psArraySet(src, k, s); 853 852 psPlane *d = psPlaneTransformApply(NULL, trans, s); 854 853 psArraySet(dst, k, d); 855 psFree(s); 854 psFree(s); // drop our refs to s and d 856 855 psFree(d); 857 856 ++k; … … 866 865 } 867 866 867 #define noCOMPARE_TRANS 868 868 #ifdef COMPARE_TRANS 869 869 // compare the computed coordintes from this transform with the original 870 870 psPlane *new = psPlaneAlloc(); 871 printf(" i chip_x tpa_x tpa_x_fit dx chip_y tpa_y tpa_y_fit dy dx > 0.5 || dy > 0.5\n"); 871 872 for (int i=0; i<psArrayLength(dst); i++) { 872 873 psPlane *d = (psPlane *) psArrayGet(dst, i); … … 875 876 new = psPlaneTransformApply(new, newTrans, s); 876 877 877 printf("%4d %f %f\n", i, 100.*(new->x - d->x)/d->x, 100.*(new->y - d->y)/d->y); 878 double xerr = new->x - d->x; 879 double yerr = new->y - d->y; 880 bool bigerr = (fabs(xerr) > .5) || (fabs(yerr) > .5); 881 printf("%4d %9.2f %9.2f %9.2f %9.4f %9.2f %9.2f %9.2f %9.4f %s\n" 882 , i, s->x, new->x, d->x, xerr, s->y, new->y, d->y, yerr, bigerr ? "BIGERR" : ""); 878 883 } 879 884 psFree(new); … … 887 892 } 888 893 889 bool pmAstromLinearizeTransforms(pmFPA *fpa, pmChip *chip) 890 { 891 psRegion *chipBounds = pmChipPixels(chip); 892 893 psPlaneTransform *newToFPA = linearFitToTransform(chip->toFPA, chipBounds); 894 if (!newToFPA) { 895 psFree(chipBounds); 896 psError(PS_ERR_UNKNOWN, false, "linear fit for toFPA failed"); 897 return false; 898 } 899 900 psFree(chip->toFPA); 901 chip->toFPA = newToFPA; 902 903 psFree(chip->fromFPA); 904 chip->fromFPA = psPlaneTransformInvert(NULL, chip->toFPA, *chipBounds, 50); 905 if (!chip->fromFPA) { 906 psError(PS_ERR_UNKNOWN, false, "failed to invert linear fit for toFPA"); 907 return false; 908 } 909 910 psPlane *chip0 = psPlaneAlloc(); 911 chip0->x = 0; 912 chip0->y = 0; 913 psPlane *chip1 = psPlaneAlloc(); 914 chip1->x = chipBounds->x1; 915 chip1->y = chipBounds->y1; 916 917 // compute bounding region for fpa 918 psPlane *fpa0 = psPlaneTransformApply(NULL, newToFPA, chip0); 919 psPlane *fpa1 = psPlaneTransformApply(NULL, newToFPA, chip1); 920 921 psRegion *fpaBounds = psRegionAlloc(fpa0->x, fpa1->x, fpa0->y, fpa1->y); 922 psFree(chip0); 923 psFree(chip1); 924 psFree(fpa0); 925 psFree(fpa1); 926 927 psPlaneTransform *newToTPA = linearFitToTransform(fpa->toTPA, fpaBounds); 928 if (!newToTPA) { 929 psError(PS_ERR_UNKNOWN, false, "failed to perform linear fit to toTPA"); 930 psFree(fpaBounds); 931 return false; 932 } 933 psFree(fpa->toTPA); 934 fpa->toTPA = newToTPA; 935 936 // XXX: is this region ok? 937 psFree(fpa->fromTPA); 938 fpa->fromTPA = psPlaneTransformInvert(NULL, fpa->toTPA, *fpaBounds, 50); 939 if (!fpa->fromTPA) { 940 psError(PS_ERR_UNKNOWN, false, "failed to invert linear fit to toTPA"); 941 return false; 942 } 943 944 fpa->toSky->type = PS_PROJ_TAN; 945 946 psFree(chipBounds); 947 psFree(fpaBounds); 894 bool pmAstromLinearizeTransforms(pmFPA *inFPA, pmChip *inChip, pmFPA *outFPA, pmChip *outChip, psRegion *outputBounds, double offset_x, double offset_y) 895 { 896 PS_ASSERT_PTR_NON_NULL(inFPA, NULL); 897 PS_ASSERT_PTR_NON_NULL(inChip, NULL); 898 899 if (outFPA == NULL) { 900 outFPA = inFPA; 901 } 902 if (outChip == NULL) { 903 outChip = inChip; 904 } 905 if (outputBounds == NULL) { 906 outputBounds = pmChipPixels(outChip); 907 } 908 909 // First combine the "chip to FPA" and "FPA to TPA" into a single transformation 910 psPlaneTransform *chipToTPA = psPlaneTransformCombine(NULL, inChip->toFPA, inFPA->toTPA, *outputBounds, 50); 911 if (!chipToTPA) { 912 psError(PS_ERR_UNKNOWN, false, "failed to create chipToTPA"); 913 return false; 914 } 915 916 // Next do the linear fit within the output boundary pixels 917 psPlaneTransform *chipToFPA = linearFitToTransform(chipToTPA, outputBounds); 918 psFree(chipToTPA); 919 if (!chipToFPA) { 920 psError(PS_ERR_UNKNOWN, false, "linear fit of chip to TPA transform failed"); 921 return false; 922 } 923 924 // if requested, change the center 925 psPlaneTransform *outToFPA; 926 if (offset_x != 0. && offset_y != 0.) { 927 outToFPA = psPlaneTransformSetCenter(NULL, chipToFPA, offset_x, offset_y); 928 psFree(chipToFPA); 929 } else { 930 outToFPA = chipToFPA; 931 } 932 933 psPlaneTransform *outFromFPA = psPlaneTransformInvert(NULL, outToFPA, *outputBounds, 50); 934 if (!outFromFPA) { 935 psFree(outToFPA); 936 psError(PS_ERR_UNKNOWN, false, "inversion of fit of output chip toFPA failed"); 937 return false; 938 } 939 940 // Success. Now set the fpa's toTPA and fromTPA to identity and replace the chip's transforms. 941 942 psFree(outFPA->toTPA); 943 outFPA->toTPA = psPlaneTransformIdentity(1); 944 945 psFree(outFPA->fromTPA); 946 outFPA->fromTPA = psPlaneTransformIdentity(1); 947 948 psFree(outChip->toFPA); 949 outChip->toFPA = outToFPA; 950 951 psFree(outChip->fromFPA); 952 outChip->fromFPA = outFromFPA; 953 954 // Finally, change the type for the projection. 955 outFPA->toSky->type = PS_PROJ_TAN; 956 957 return true; 958 } 959 960 bool pmAstromLinearizeToSky(pmFPA *inFPA, pmChip *inChip, pmFPA *outFPA, pmChip *outChip, psRegion *bounds) 961 { 962 PS_ASSERT_PTR_NON_NULL(inFPA, NULL); 963 PS_ASSERT_PTR_NON_NULL(inChip, NULL); 964 PS_ASSERT_PTR_NON_NULL(outFPA, NULL); 965 PS_ASSERT_PTR_NON_NULL(outChip, NULL); 966 PS_ASSERT_PTR_NON_NULL(bounds, NULL); 967 968 // outFPA projection must be defined as the goal 969 970 // the output transformations are: 971 // chip -> FPA : standard linear trans with needed rotation, etc 972 // FPA -> TPA : identidy 973 974 int nSamples = 10; // 10 samples in each dimension 975 976 double deltaX = (bounds->x1 - bounds->x0); 977 double deltaY = (bounds->y1 - bounds->y0); 978 979 psArray *src = psArrayAllocEmpty(nSamples * nSamples); 980 psArray *dst = psArrayAllocEmpty(nSamples * nSamples); 981 982 psPlane srcFP, srcTP; 983 984 for (int j = 0; j < nSamples; j++) { 985 double y = bounds->y0 + (j * deltaY / nSamples); 986 for (int i = 0; i < nSamples; i++) { 987 988 psSphere srcSky; 989 psPlane *srcChip = psPlaneAlloc(); 990 psPlane *dstTP = psPlaneAlloc(); 991 992 srcChip->x = bounds->x0 + (i * deltaX / nSamples); 993 srcChip->y = y; 994 995 psPlaneTransformApply (&srcFP, inChip->toFPA, srcChip); 996 psPlaneTransformApply (&srcTP, inFPA->toTPA, &srcFP); 997 psDeproject (&srcSky, &srcTP, inFPA->toSky); 998 999 // fprintf (stderr, "%f %f | %f %f | %f %f | %f %f\n", srcChip->x, srcChip->y, srcFP.x, srcFP.y, srcTP.x, srcTP.y, srcSky.r*PS_DEG_RAD, srcSky.d*PS_DEG_RAD); 1000 1001 psProject (dstTP, &srcSky, outFPA->toSky); 1002 1003 srcChip->x -= bounds->x0; 1004 srcChip->y -= bounds->y0; 1005 psArrayAdd (src, 100, srcChip); 1006 psArrayAdd (dst, 100, dstTP); 1007 1008 psFree(srcChip); // drop our refs to s and d 1009 psFree(dstTP); 1010 } 1011 } 1012 1013 psPlaneTransform *newToFPA = psPlaneTransformAlloc(1, 1); 1014 newToFPA->x->coeffMask[1][1] = 1; 1015 newToFPA->y->coeffMask[1][1] = 1; 1016 1017 if (!psPlaneTransformFit(newToFPA, src, dst, 0, 0)) { 1018 psError(PS_ERR_UNKNOWN, false, "linear fit to transform failed"); 1019 psFree(src); 1020 psFree(dst); 1021 return NULL; 1022 } 1023 1024 # if (0) 1025 for (int i = 0; i < src->n; i++) { 1026 1027 psSphere srcSky, dstSky; 1028 psPlane *srcChip = src->data[i]; 1029 psPlane *dstTP = dst->data[i]; 1030 1031 psPlaneTransformApply (&srcFP, newToFPA, srcChip); 1032 psDeproject (&srcSky, &srcFP, outFPA->toSky); 1033 psDeproject (&dstSky, dstTP, outFPA->toSky); 1034 1035 double dX = (srcSky.r*PS_DEG_RAD - dstSky.r*PS_DEG_RAD)*3600.0; 1036 double dY = (srcSky.d*PS_DEG_RAD - dstSky.d*PS_DEG_RAD)*3600.0; 1037 fprintf (stderr, "%f %f | %f %f | %f %f | %f %f | %f %f | %f %f\n", dX, dY, srcChip->x, srcChip->y, srcFP.x, srcFP.y, dstTP->x, dstTP->y, srcSky.r*PS_DEG_RAD, srcSky.d*PS_DEG_RAD, dstSky.r*PS_DEG_RAD, dstSky.d*PS_DEG_RAD); 1038 1039 } 1040 # endif 1041 1042 psFree(src); 1043 psFree(dst); 1044 1045 // this is a linear transformation 1046 psPlaneTransform *newFromFPA = psPlaneTransformInvert(NULL, newToFPA, *bounds, 1); 1047 if (!newFromFPA) { 1048 psFree(newToFPA); 1049 psError(PS_ERR_UNKNOWN, false, "inversion of fit of output chip toFPA failed"); 1050 return false; 1051 } 1052 1053 // Success. Now set the fpa's toTPA and fromTPA to identity and replace the chip's transforms. 1054 psFree(outChip->toFPA); 1055 outChip->toFPA = newToFPA; 1056 1057 psFree(outChip->fromFPA); 1058 outChip->fromFPA = newFromFPA; 1059 1060 psFree(outFPA->toTPA); 1061 outFPA->toTPA = psPlaneTransformIdentity(1); 1062 1063 psFree(outFPA->fromTPA); 1064 outFPA->fromTPA = psPlaneTransformIdentity(1); 948 1065 949 1066 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
