IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 30641


Ignore:
Timestamp:
Feb 15, 2011, 3:55:42 PM (15 years ago)
Author:
eugene
Message:

modified following Eddies suggestion to result in the variance expected for the observed sky value

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tags/ipp-20101215/ppImage/src/ppImageAddNoise.c

    r30627 r30641  
    2020
    2121  // grizy variances to add to turn MD exposure -> 3pi, calculated from the DRM
    22   static float add_sigmas[] = {NAN, 13.39, 23.79, 75.25, 110.19, 128.84};
     22  // static float add_sigmas[] = {NAN, 13.39, 23.79, 75.25, 110.19, 128.84};
    2323 
    2424  // Target Exposure times for 3pi in grizy
    2525  static float expTimes3Pi[] = {NAN, 43.0, 40.0, 45.0, 30.0, 30.0};
    26   float expTime   = psMetadataLookupF32(NULL, fpa->concepts, "FPA.EXPOSURE"); // Exposure time for image
     26  float expTime = psMetadataLookupF32(NULL, fpa->concepts, "FPA.EXPOSURE"); // Exposure time for image
    2727
    2828  // Something to choose the band, g,r,i,z,y = 0,1,2,3,4 respectively
     
    6060
    6161  // Add in appropriate variance, and scale the image
    62   float expTimeScaling =  expTime/expTimes3Pi[band];
    63   // XXX why was this not used? float expTimeScalingSqd = PS_SQR(expTimeScaling);
     62  float rho =  expTime/expTimes3Pi[band];
     63  float rho2 = PS_SQR(rho);
    6464
    6565  psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS); // Random number generator
    6666
     67  psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN);
     68  stats->nSubsample = 10000;
     69
     70  psImageBackground(stats, NULL, inReadout->image, inReadout->mask, 0xffff, rng);
     71  double MSKY_MN = stats->sampleMedian;
     72
     73  // set GAIN and RDNOISE to nominal values:
     74  double GAIN = 1.0; // electrons / DN
     75  double RDNOISE = 6.0; // electrons (== DN)
     76
     77  double add_sigma = sqrt((MSKY_MN/GAIN)*(rho - 1.0) + PS_SQR(RDNOISE)*(rho2 - 1.0));
     78
    6779  for (int iy = 0; iy < image->numRows; iy++){
    6880    for (int ix = 0; ix < image->numCols; ix++){
    69       image->data.F32[iy][ix] += ppImageRandomGaussian(rng, 0.0, add_sigmas[band]);
    70       image->data.F32[iy][ix] /= expTimeScaling;
    71       variance->data.F32[iy][ix] += PS_SQR(add_sigmas[band]);
    72       variance->data.F32[iy][ix] /= expTimeScaling;
     81      image->data.F32[iy][ix] += ppImageRandomGaussian(rng, 0.0, add_sigma);
     82      image->data.F32[iy][ix] /= rho;
     83      variance->data.F32[iy][ix] += PS_SQR(add_sigma);
     84      variance->data.F32[iy][ix] /= rho2;
    7385    }
    7486  }
Note: See TracChangeset for help on using the changeset viewer.