Changeset 5858 for trunk/ppImage/src/ppImageDetrendNonLinear.c
- Timestamp:
- Dec 30, 2005, 7:05:28 AM (20 years ago)
- File:
-
- 1 edited
-
trunk/ppImage/src/ppImageDetrendNonLinear.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppImage/src/ppImageDetrendNonLinear.c
r5857 r5858 1 1 # include "ppImage.h" 2 2 3 bool ppDetrendNonLinear (pmCell *cell, pmReadout *readout, psMetadata *recipe) {3 bool ppDetrendNonLinearPolynomial (pmReadout *input, psMetadataItem *dataItem) { 4 4 5 psString name; 6 psVector *coeff; 7 psMetadata *options; 5 // These are the polynomial coefficients 6 psVector *coeff = dataItem->data.V; // The coefficient vector 7 if (coeff->type.type != PS_TYPE_F64) { 8 psVector *temp = psVectorCopy(NULL, coeff, PS_TYPE_F64); // F64 version 9 psFree (coeff); 10 coeff = temp; 11 } 12 psPolynomial1D *correction = psPolynomial1DAlloc(coeff->n - 1, PS_POLYNOMIAL_ORD); 13 psFree(correction->coeff); 14 correction->coeff = psMemIncrRefCounter(coeff->data.F64); 15 pmNonLinearityPolynomial(input, correction); 16 psFree(coeff); 17 psFree(correction); 18 return true; 19 } 8 20 9 psMetadataItem *dataItem = psMetadataLookup(recipe, "NONLIN.DATA"); 10 if (! dataItem) { 11 psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction desired, but unable to " 12 "find NONLIN.DATA in recipe --- ignored.\n"); 21 bool ppDetrendNonLinearLookup (pmReadout *input, psMetadataItem *dataItem) { 22 23 // This is a filename: lookup table 24 char *name = dataItem->data.V; // Filename 25 psLookupTable *table = psLookupTableAlloc(name, "%f %f", 0); 26 if (psLookupTableRead(table) <= 0) { 27 psErrorStackPrint(stderr, "Unable to read non-linearity correction file " 28 "%s --- ignored\n", name); 13 29 return false; 14 30 } 31 #ifdef PRODUCTION 32 pmNonLinearityLookup(input, table); 33 #else 34 psVector *influx = table->values->data[0]; 35 psVector *outflux = table->values->data[1]; 36 pmNonLinearityLookup(input, influx, outflux); 37 #endif 38 psFree(table); 39 return true; 40 } 15 41 16 switch (dataItem->type) { 42 bool ppDetrendNonLinear (pmCell *cell, pmReadout *input, ppOptions *options) { 43 44 psMetadataItem *concept; 45 46 switch (options->nonLinearType) { 17 47 case PS_DATA_VECTOR: 18 // These are the polynomial coefficients 19 coeff = dataItem->data.V; // The coefficient vector 20 if (coeff->type.type != PS_TYPE_F64) { 21 psVector *temp = psVectorCopy(NULL, coeff, PS_TYPE_F64); // F64 version 22 coeff = temp; 23 } 24 psPolynomial1D *correction = psPolynomial1DAlloc(coeff->n - 1, 25 PS_POLYNOMIAL_ORD); 26 psFree(correction->coeff); 27 correction->coeff = psMemIncrRefCounter(coeff->data.F64); 28 (void)pmNonLinearityPolynomial(inputReadout, correction); 29 psFree(coeff); 30 psFree(correction); 48 ppDetrendNonLinearPolynomial (input, options->nonLinearData); 31 49 return true; 32 50 33 51 case PS_DATA_STRING: 34 // This is a filename 35 name = dataItem->data.V; // Filename 36 psLookupTable *table = psLookupTableAlloc(name, "%f %f", 0); 37 if (psLookupTableRead(table) <= 0) { 38 psErrorStackPrint(stderr, "Unable to read non-linearity correction file " 39 "%s --- ignored\n", name); 40 return false; 41 } 42 #ifdef PRODUCTION 43 (void)pmNonLinearityLookup(inputReadout, table); 44 #else 45 psVector *influx = table->values->data[0]; 46 psVector *outflux = table->values->data[1]; 47 (void)pmNonLinearityLookup(inputReadout, table->values->data[0], 48 table->values->data[1]); 49 #endif 50 psFree(table); 52 ppDetrendNonLinearLookup (input, options->nonLinearData); 51 53 return true; 52 54 53 55 case PS_DATA_METADATA: 54 // This is a menu 55 options = dataItem->data.V; // Options with concept values as keys 56 bool mdok = false; // Success of MD lookup 57 psString concept = psMetadataLookupStr(&mdok, recipe, "NONLIN.SOURCE"); 58 if (! mdok || ! concept) { 59 psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction desired, but " 60 "unable to find NONLIN.SOURCE in recipe --- ignored.\n"); 56 // XXX this is somewhat confusing : let's wrap in a function when i understand it 57 concept = pmCellGetConcept(cell, options->nonLinearSource); 58 if (! concept) { 59 psLogMsg("phase2", PS_LOG_WARN, "Unable to find value of concept %s " 60 "for non-linearity correction --- ignored.\n", options->nonLinearSource); 61 61 return false; 62 62 } 63 psMetadataItem *conceptValueItem = pmCellGetConcept(inputCell, concept); 64 if (! conceptValueItem) { 65 psLogMsg("phase2", PS_LOG_WARN, "Unable to find value of concept %s " 66 "for non-linearity correction --- ignored.\n", concept); 67 return false; 68 } 69 if (conceptValueItem->type != PS_DATA_STRING) { 63 if (concept->type != PS_DATA_STRING) { 70 64 psLogMsg("phase2", PS_LOG_WARN, "Type for concept %s isn't STRING, as" 71 65 " expected for non-linearity correction --- ignored.\n", … … 74 68 } 75 69 76 psString conceptValue = conceptValueItem->data.V;77 70 // Get the value of the concept 78 psMetadataItem *optionItem = psMetadataLookup(options, conceptValue); 71 psString conceptValue = concept->data.V; 72 psMetadata *folder = (psMetadata *)options->nonLinearData->data.V; 73 psMetadataItem *optionItem = psMetadataLookup(folder, conceptValue); 79 74 if (!optionItem) { 80 75 psLogMsg("phase2", PS_LOG_WARN, "Unable to find %s in NONLIN.DATA" … … 82 77 return false; 83 78 } 84 if (optionItem->type == PS_DATA_VECTOR) { 85 // These are the polynomial coefficients 86 coeff = optionItem->data.V; // The coefficient vector 87 if (coeff->type.type != PS_TYPE_F64) { 88 psVector *temp = psVectorCopy(NULL, coeff, PS_TYPE_F64); 89 coeff = temp; 90 } 91 // Polynomial correction 92 psPolynomial1D *correction = psPolynomial1DAlloc(coeff->n - 1, 93 PS_POLYNOMIAL_ORD); 94 psFree(correction->coeff); 95 correction->coeff = psMemIncrRefCounter(coeff->data.F64); 96 (void)pmNonLinearityPolynomial(inputReadout, correction); 97 psFree(coeff); 98 psFree(correction); 79 80 switch (optionItem->type) { 81 case PS_DATA_VECTOR: 82 ppDetrendNonLinearPolynomial (input, optionItem); 99 83 return true; 100 } 101 if (optionItem->type == PS_DATA_STRING) { 102 // This is a filename 103 psString tableName = optionItem->data.V; // The filename 104 psLookupTable *table = psLookupTableAlloc(tableName, "%f %f", 0); 105 int numLines = 0; // Number of lines read from table 106 if ((numLines = psLookupTableRead(table)) <= 0) { 107 psErrorStackPrint(stderr, "Unable to read non-linearity " 108 "correction file %s --- ignored\n", 109 tableName); 110 return false; 111 } 112 #ifdef PRODUCTION 113 (void)pmNonLinearityLookup(inputReadout, table); 114 #else 115 printf("XXX: Non-linearity correction from lookup table not " 116 "yet implemented.\n"); 117 #endif 118 psFree(table); 84 case PS_DATA_STRING: 85 ppDetrendNonLinearLookup (input, optionItem); 119 86 return true; 87 default: 88 psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction " 89 "desired but unable to interpret NONLIN.DATA for %s" 90 " --- ignored\n", conceptValue); 91 return false; 120 92 } 121 122 psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction "123 "desired but unable to interpret NONLIN.DATA for %s"124 " --- ignored\n", conceptValue);125 return false;126 127 93 default: 128 psLogMsg("phase2", PS_LOG_WARN, "Non-linearity correction desired, but " 129 "NONLIN.DATA is of invalid type --- ignored.\n"); 94 psAbort("phase2", "Invalid options->nonLinearType"); 130 95 } 131 return false;96 return true; 132 97 } 133 98
Note:
See TracChangeset
for help on using the changeset viewer.
