Changeset 24819
- Timestamp:
- Jul 16, 2009, 12:06:28 PM (17 years ago)
- Location:
- trunk/psModules/src/detrend
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/detrend/pmDark.c
r24803 r24819 1 #ifdef HAVE_CONFIG_H 2 #include <config.h> 3 #endif 4 1 5 #include <stdio.h> 2 6 #include <pslib.h> … … 14 18 #include "pmDetrendThreads.h" 15 19 #include "pmErrorCodes.h" 16 17 20 #include "pmDark.h" 18 21 … … 385 388 } 386 389 390 pmDarkVisualInit(values); 391 387 392 pmReadout *outReadout = output->readouts->data[0]; 388 393 … … 427 432 psVectorInit(poly->coeff, NAN); 428 433 } 434 435 pmDarkVisualPixelFit(pixels, mask); 436 pmDarkVisualPixelModel(poly, values); 437 429 438 for (int k = 0; k < poly->coeff->n; k++) { 430 439 pmReadout *ro = output->readouts->data[k]; // Readout of interest … … 988 997 } 989 998 999 #if (HAVE_KAPA) 1000 #include <kapa.h> 1001 #include "pmKapaPlots.h" 1002 #include "pmVisual.h" 1003 1004 static int nKapa = 0; 1005 static int *kapa = NULL; 1006 static bool plotFlag = true; 1007 static psArray *xVectors = NULL; 1008 1009 // this init function only gets the ordinates for the first readout... 1010 bool pmDarkVisualInit(psArray *values) { 1011 1012 if (!pmVisualIsVisual()) return true; 1013 1014 // skip if we have already opened the windows (or if none are requested...) 1015 if (nKapa) return true; 1016 1017 // values has Ninput vectors with Norder elements; we need Norder vectors with Ninput elements... 1018 int nOrders = 0; 1019 for (int i = 0; i < values->n; i++) { 1020 psVector *vect = values->data[i]; 1021 if (!nOrders) { 1022 nOrders = vect->n; 1023 } else { 1024 psAssert (nOrders == vect->n, "mismatch in order vector lengths"); 1025 } 1026 } 1027 xVectors = psArrayAlloc(nOrders); 1028 for (int i = 0; i < nOrders; i++) { 1029 xVectors->data[i] = psVectorAlloc(values->n, PS_TYPE_F32); 1030 } 1031 1032 for (int i = 0; i < values->n; i++) { 1033 psVector *vect = values->data[i]; 1034 for (int j = 0; j < vect->n; j++) { 1035 psVector *xVec = xVectors->data[j]; 1036 xVec->data.F32[i] = vect->data.F32[j]; 1037 } 1038 } 1039 1040 nKapa = nOrders; 1041 1042 kapa = psAlloc(nKapa*sizeof(int)); 1043 1044 for (int i = 0; i < nKapa; i++) { 1045 kapa[i] = -1; 1046 pmVisualInitWindow(&kapa[i], "ppmerge"); 1047 } 1048 return true; 1049 } 1050 1051 bool pmDarkVisualPixelFit(psVector *pixels, psVector *mask) { 1052 1053 Graphdata graphdata; 1054 1055 if (!pmVisualIsVisual()) return true; 1056 1057 KapaInitGraph(&graphdata); 1058 1059 psAssert(nKapa == xVectors->n, "inconsistent number of orders %d vs %ld\n", nKapa, xVectors->n); 1060 1061 psVector *xSub = psVectorAlloc(pixels->n, PS_TYPE_F32); 1062 psVector *ySub = psVectorAlloc(pixels->n, PS_TYPE_F32); 1063 1064 for (int i = 0; i < xVectors->n; i++) { 1065 psVector *x = xVectors->data[i]; 1066 1067 // generate vectors of the unmasked values 1068 int nSub = 0; 1069 for (int j = 0; j < pixels->n; j++) { 1070 if (mask && mask->data.PS_TYPE_VECTOR_MASK_DATA[j]) continue; 1071 xSub->data.F32[nSub] = x->data.F32[j]; 1072 ySub->data.F32[nSub] = pixels->data.F32[j]; 1073 nSub ++; 1074 } 1075 xSub->n = ySub->n = nSub; 1076 1077 // plot the unmasked values 1078 pmVisualScaleGraphdata (&graphdata, xSub, ySub, false); 1079 KapaSetGraphData(kapa[i], &graphdata); 1080 KapaSetLimits(kapa[i], &graphdata); 1081 KapaClearPlots (kapa[i]); 1082 1083 KapaSetFont (kapa[i], "courier", 14); 1084 KapaBox (kapa[i], &graphdata); 1085 KapaSendLabel (kapa[i], "ordinate", KAPA_LABEL_XM); 1086 KapaSendLabel (kapa[i], "pixel values", KAPA_LABEL_YM); 1087 1088 graphdata.color = KapaColorByName("black"); 1089 graphdata.style = 2; 1090 graphdata.ptype = 2; 1091 KapaPrepPlot (kapa[i], xSub->n, &graphdata); 1092 KapaPlotVector(kapa[i], xSub->n, xSub->data.F32, "x"); 1093 KapaPlotVector(kapa[i], xSub->n, ySub->data.F32, "y"); 1094 } 1095 pmVisualAskUser (&plotFlag); 1096 return true; 1097 } 1098 1099 bool pmDarkVisualPixelModel(psPolynomialMD *poly, psArray *values) { 1100 1101 Graphdata graphdata; 1102 1103 if (!pmVisualIsVisual()) return true; 1104 1105 KapaInitGraph(&graphdata); 1106 1107 psAssert(nKapa == xVectors->n, "inconsistent number of orders %d vs %ld\n", nKapa, xVectors->n); 1108 1109 psVector *yFit = psVectorAlloc(values->n, PS_TYPE_F32); 1110 1111 for (int i = 0; i < values->n; i++) { 1112 psVector *coord = values->data[i]; 1113 yFit->data.F32[i] = psPolynomialMDEval (poly, coord); 1114 } 1115 1116 for (int i = 0; i < xVectors->n; i++) { 1117 psVector *xFit = xVectors->data[i]; 1118 1119 KapaGetGraphData(kapa[i], &graphdata); 1120 graphdata.color = KapaColorByName("red"); 1121 graphdata.style = 2; 1122 graphdata.ptype = 7; 1123 KapaPrepPlot (kapa[i], xFit->n, &graphdata); 1124 KapaPlotVector(kapa[i], xFit->n, xFit->data.F32, "x"); 1125 KapaPlotVector(kapa[i], xFit->n, yFit->data.F32, "y"); 1126 } 1127 pmVisualAskUser (&plotFlag); 1128 return true; 1129 } 1130 1131 bool pmDarkVisualCleanup() { 1132 1133 for (int i = 0; i < nKapa; i++) { 1134 KapaClose(kapa[i]); 1135 } 1136 psFree (kapa); 1137 psFree (xVectors); 1138 return true; 1139 } 1140 1141 # else 1142 1143 bool pmDarkVisualInit(psArray *values) { return true; } 1144 bool pmDarkVisualPixelFit(psVector *pixels, psVector *mask) { return true; } 1145 bool pmDarkVisualPixelModel(psPolynomialMD *poly, psArray *values) { return true; } 1146 bool pmDarkVisualCleanup() { return true; } 1147 1148 # endif -
trunk/psModules/src/detrend/pmDark.h
r24802 r24819 117 117 ); 118 118 119 bool pmDarkVisualInit(psArray *values); 120 bool pmDarkVisualPixelFit(psVector *pixels, psVector *mask); 121 bool pmDarkVisualCleanup(); 122 bool pmDarkVisualPixelModel(psPolynomialMD *poly, psArray *values); 119 123 120 124 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
