Changeset 9627 for trunk/psastro/src/psastroLuminosityFunction.c
- Timestamp:
- Oct 18, 2006, 8:44:12 AM (20 years ago)
- File:
-
- 1 edited
-
trunk/psastro/src/psastroLuminosityFunction.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psastro/src/psastroLuminosityFunction.c
r9587 r9627 15 15 psMemSetDeallocator(func, (psFreeFunc) pmLumFuncFree); 16 16 17 func->mMin = 0;18 func->mMax = 0;19 func->slope = 0;20 func->offset = 0;17 func->mMin = mMin; 18 func->mMax = mMax; 19 func->slope = slope; 20 func->offset = offset; 21 21 22 22 return func; 23 23 } 24 24 25 pmLumFunc *psastro RefstarSubset(psArray *stars) {25 pmLumFunc *psastroLuminosityFunction (psArray *stars) { 26 26 27 27 // determine the max and min magnitude for the array of stars 28 28 pmAstromObj *star = stars->data[0]; 29 mMin = star->Mag;30 mMax = star->Mag;29 double mMin = star->Mag; 30 double mMax = star->Mag; 31 31 for (int i = 0; i < stars->n; i++) { 32 32 star = stars->data[i]; … … 35 35 } 36 36 37 int nBin = 1 + ( nMax - nMin) / dMag;37 int nBin = 1 + (mMax - mMin) / dMag; 38 38 if (nBin <= 1) { 39 39 psError(PSASTRO_ERR_DATA, true, "magnitude range of 0.0\n"); … … 45 45 // bin[i] = mMin + i*dMag : mMin + (i+1)*dMag 46 46 psVector *nMags = psVectorAlloc (nBin, PS_TYPE_F32); 47 nMags->n = nBin; 48 psVectorInit (nMags, 0); 49 47 50 for (int i = 0; i < stars->n; i++) { 48 51 star = stars->data[i]; 49 52 int bin = (star->Mag - mMin) / dMag; 50 53 nMags->data.F32[bin] += 1.0; 54 } 55 56 // find the peak and position 57 int iPeak = 0; 58 int nPeak = 0; 59 for (int i = 0; i < nMags->n; i++) { 60 if (nMags->data.F32[i] < nPeak) continue; 61 iPeak = i; 62 nPeak = nMags->data.F32[i]; 51 63 } 52 64 … … 56 68 // create 2 vectors represnting the dlogN/dlogS line 57 69 // exclude bins with no stars 70 // exclude points after the peak with N < 0.8*peak 58 71 int n = 0; 59 for (int i = 0; i < stars->n; i++) {72 for (int i = 0; i < nMags->n; i++) { 60 73 if (nMags->data.F32[i] < 1) continue; 74 if ((i > iPeak) && (nMags->data.F32[i] < 0.8*nPeak)) continue; 61 75 lnMag->data.F32[n] = log10 (nMags->data.F32[i]); 62 76 Mag->data.F32[n] = mMin + (i + 0.5)*dMag; 63 77 n++; 64 78 } 79 lnMag->n = n; 80 Mag->n = n; 81 psLogMsg ("psastro", 4, "fitting %d points to luminosity function\n", n); 65 82 66 83 psVector *mask = psVectorAlloc (nBin, PS_TYPE_MASK); 84 mask->n = Mag->n; 85 psVectorInit (mask, 0); 86 67 87 psPolynomial1D *line = psPolynomial1DAlloc (PS_POLYNOMIAL_ORD, 1); 68 88 psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV); … … 70 90 stats->clipIter = 3; 71 91 72 line = psVectorClipFitPolynomial1D(line, stats, mask, 1, lnMag, NULL, Mag);92 line = psVectorClipFitPolynomial1D(line, stats, mask, 0xff, lnMag, NULL, Mag); 73 93 74 94 // find min and max unmasked magnitudes 75 mMinValid = NAN;76 mMaxValid = NAN;95 double mMinValid = NAN; 96 double mMaxValid = NAN; 77 97 for (int i = 0; i < Mag->n; i++) { 78 98 if (mask->data.U8[i]) continue; … … 89 109 90 110 pmLumFunc *lumFunc = pmLumFuncAlloc (mMinValid, mMaxValid, line->coeff[0], line->coeff[1]); 111 112 psFree (lnMag); 113 psFree (nMags); 114 psFree (Mag); 115 psFree (mask); 116 psFree (line); 117 psFree (stats); 118 91 119 return (lumFunc); 92 120 }
Note:
See TracChangeset
for help on using the changeset viewer.
