GithubHelp home page GithubHelp logo

Unit Tests about piff HOT 25 CLOSED

rmjarvis avatar rmjarvis commented on September 26, 2024
Unit Tests

from piff.

Comments (25)

rmjarvis avatar rmjarvis commented on September 26, 2024

I guess these questions are for @cpadavis. You seem to be talking about tests on the combined_wavefront_psf branch, which seems to be his work...

from piff.

areshernandez avatar areshernandez commented on September 26, 2024

When I ran test_optatmo.py with the new changes to the "create_synthetic_optatmo()" function I got a new error:

File "test_optatmo.py", line 395, in
test_optical_fit()
File "/afs/slac.stanford.edu/u/ec/aresh/Piff-wavefront/tests/piff_test_helper.py", line 78, in f2
result = f(*args, **kwargs)
File "test_optatmo.py", line 365, in test_optical_fit
optpsf.fit(stars_clean, wcs, pointing, logger=logger)
File "/u/ec/aresh/Piff-wavefront/piff/optatmo.py", line 430, in fit
logger=logger)
File "/u/ec/aresh/Piff-wavefront/piff/optatmo.py", line 455, in _minuit_fit
self._minuit.migrad(ncall=self.kwargs['max_iterations'])
File "_libiminuit.pyx", line 331, in iminuit._libiminuit.Minuit.migrad (iminuit/_libiminuit.cpp:5099)
File "/u/ec/aresh/Piff-wavefront/piff/optatmo.py", line 579, in _fit_func
shapes = self._measure_shapes(self.drawStarList(self._fit_stars),)# logger=logger)
File "/u/ec/aresh/Piff-wavefront/piff/optatmo.py", line 634, in drawStarList
stars = self.decaminfo.pixel_to_focalList(stars)
File "/u/ec/aresh/Piff-wavefront/piff/des/decaminfo.py", line 321, in pixel_to_focalList
return [Star(self.pixel_to_focal_stardata(star.data), star.fit) for star in stars]
File "/u/ec/aresh/Piff-wavefront/piff/des/decaminfo.py", line 290, in pixel_to_focal_stardata
stardata['chipnum'], stardata['x'], stardata['y'])
File "/u/ec/aresh/Piff-wavefront/piff/star.py", line 682, in getitem
return self.properties[key]
KeyError: 'chipnum'

Looking in the decaminfo.py file it looks like there is trouble with the pixel to focal x and focal y conversion and that the "chipnum" property is missing. Is this due to the WCS coordinate conversion issue or is it because we are using Simple PSF rather than SingleChip?

from piff.

cpadavis avatar cpadavis commented on September 26, 2024

from piff.

areshernandez avatar areshernandez commented on September 26, 2024

With the new updates, the error is no longer there. However, I now receive a different error that comes from the test_optical_fit() function:

  File "test_optatmo.py", line 395, in <module>
    test_optical_fit()
  File "/afs/slac.stanford.edu/u/ec/aresh/Piff-wavefront/tests/piff_test_helper.py", line 78, in f2
    result = f(*args, **kwargs)
  File "test_optatmo.py", line 378, in test_optical_fit
    assert abs(misalignment[key] - misalignment_fit[key]) < 2 * misalignment_fit_errors[key], '{0} Failed Optical Fit. Parameter: {1}, Fit: {2} +- {3}'.format(key, misalignment[key], misalignment_fit[key], misalignment_fit_errors[key])
AssertionError: z04d Failed Optical Fit. Parameter: -0.5, Fit: -1.99999999998 +- 2.40979307846e-05

This error seems to appear where the misalignment fitting is done. Is this likely due to the problem with the number of parameters used? If so, should I try to remove the z04d parameter that seems to be causing problems? I'm going to attempt that next.

from piff.

aaronroodman avatar aaronroodman commented on September 26, 2024

from piff.

cpadavis avatar cpadavis commented on September 26, 2024

from piff.

areshernandez avatar areshernandez commented on September 26, 2024

After test_optatmo.py finished running, it went through test_optical_fit() and did not cause any problems like usual. However, when it got to the optical test in test_fit() it failed in the same way that test_optical_fit() used to fail (which was due to feeding optatmo_stars_clean from the full PSF into the fit() function inside the OpticalWavefrontPSF(PSF) class instead of just opt_stars_clean):

  File "test_optatmo.py", line 483, in <module>
    
  File "/afs/slac.stanford.edu/u/ec/aresh/Piff-wavefront/tests/piff_test_helper.py", line 78, in f2
    result = f(*args, **kwargs)
  File "test_optatmo.py", line 373, in test_fit
    # construct results
AssertionError: z04d Failed Optical Fit inside full test_fit() function. Parameter: -0.5, Fit: -1.99999999996 +- 1.92922281265e-05

In test_fit(), however, I fed optatmo_stars_clean into the fit() function inside the OptAtmoPSF(PSF) class, rather than the fit() function inside the OpticalWavefrontPSF(PSF) class. Is there likely a bug interfering with the fit() function inside the OptAtmoPSF(PSF) class that is causing it to behave like the fit() function from the OpticalWavefrontPSF(PSF) class?

from piff.

cpadavis avatar cpadavis commented on September 26, 2024

from piff.

areshernandez avatar areshernandez commented on September 26, 2024

I have narrowed down that the reason why the graphs for fitted_opt_stars are empty is because something goes wrong in the second line below:

opt_stars_drawn = optpsf.drawStarList(opt_stars_clean)
fitted_opt_shapes = optpsf._measure_shapes(stars=opt_stars_drawn)

I have successfully printed optpsf._measure_shapes(stars=opt_stars_clean), so I know there is nothing wrong with opt_stars_clean. I have printed the focal_x and focal_y coordinates of opt_stars_drawn, so I don't think there is anything wrong with opt_stars_drawn either. However, fitted_opt_shapes is a large list filled with "nan" when I print it.

It thus looks like there may be a bug inside of _measure_shapes() that only happens when I feed it opt_stars_drawn. Do you think this is the case? If so, is there an alternative method of retrieving the shapes besides _measure_shapes() that I can use?

from piff.

cpadavis avatar cpadavis commented on September 26, 2024

from piff.

areshernandez avatar areshernandez commented on September 26, 2024

I see a small yellow square inside a purple background. Does this mean the images from opt_stars_drawn are corrupted somehow? In other words, are the star image normally large yellow ellipses in a purple background? If so, could this indicate that there is a bug inside of drawStarList() causing this problem?

from piff.

cpadavis avatar cpadavis commented on September 26, 2024

from piff.

areshernandez avatar areshernandez commented on September 26, 2024

I tried putting r0, g1, and g2 back in before drawing the stars:

    optpsf.fitter_kwargs['fix_r0'] = False
    optpsf.fitter_kwargs['fix_g1'] = False
    optpsf.fitter_kwargs['fix_g2'] = False
    optpsf.model.kolmogorov_kwargs = {'r0':optpsf.backup_shapes[0]}
    optpsf.model.g1 = optpsf.backup_shapes[1]
    optpsf.model.g2 = optpsf.backup_shapes[2]
    optpsf._update_psf_params(r0=optpsf.backup_shapes[0], g1=optpsf.backup_shapes[1], g2=optpsf.backup_shapes[2])
    opt_stars_drawn = optpsf.drawStarList(opt_stars_clean)
    optpsf._update_psf_params(r0=None, g1=None, g2=None)
    optpsf.fitter_kwargs['fix_r0'] = True
    optpsf.fitter_kwargs['fix_g1'] = True
    optpsf.fitter_kwargs['fix_g2'] = True
    optpsf.model.kolmogorov_kwargs = {}
    optpsf.model.g1 = None
    optpsf.model.g2 = None
    fitted_opt_shapes = optpsf._measure_shapes(stars=opt_stars_drawn)

However, after doing this I got a new error:

  File "test_optatmo.py", line 889, in <module>
    test_fit()
  File "/afs/slac.stanford.edu/u/ec/aresh/Piff-wavefront/tests/piff_test_helper.py", line 78, in f2
    result = f(*args, **kwargs)
  File "test_optatmo.py", line 593, in test_fit
    opt_stars_drawn = optpsf.drawStarList(opt_stars_clean)
  File "/u/ec/aresh/Piff-wavefront/piff/optatmo.py", line 644, in drawStarList
    stars = [self.model.draw(star) for star in stars]
  File "/u/ec/aresh/Piff-wavefront/piff/optical_model.py", line 258, in draw
    prof = self.getProfile(star.fit.params)
  File "/u/ec/aresh/Piff-wavefront/piff/optical_model.py", line 227, in getProfile
    atm = galsim.Kolmogorov(gsparams=self.gsparams, **self.kolmogorov_kwargs)
  File "/nfs/slac/g/ki/ki18/cpd/anaconda2/lib/python2.7/site-packages/galsim/base.py", line 593, in __init__
    "r0_500) must be specified for Kolmogorov")
TypeError: One of lam_over_r0, fwhm, half_light_radius, or lam (with r0 or r0_500) must be specified for Kolmogorov

It seems that I'm missing something called "r0_500," which I need in addition to r0, g1, and g2 in order to use optpsf.drawStarList(). If this is the case, is there a specific location where this "r0_500" value is stored?

I should add that I've checked optpsf.backup_shapes[0], optpsf.backup_shapes[1], and optpsf.backup_shapes[2] and compared them to optpsf.model.kolmogorov_kwargs['r0'], optpsf.model.g1, and optpsf.model.g2 and can confirm that they are the same, as they should be.

from piff.

cpadavis avatar cpadavis commented on September 26, 2024

from piff.

areshernandez avatar areshernandez commented on September 26, 2024

I have tried the following input misalignment terms to be used for test_fit():

  1. z04d=-0.5, z05d=0.1
  2. z04d=-0.5, z05d=0.1, z06d=0.06
  3. z04d=-0.5, z07d=0.01, z08d=0.03
  4. z04d=-0.5, z08d=0.03
  5. z04d=-0.5, z09d=0.1, z10d=0.1

So far, non have produced a good fit. Are there any possible sets of inputs that I haven't tried that you think would be more likely to succeed than others?

from piff.

cpadavis avatar cpadavis commented on September 26, 2024

from piff.

areshernandez avatar areshernandez commented on September 26, 2024

I'm not sure but I think you want me to make a graph of:

the fitted values I get for z04d vs the misalignment_fit_errors['z04d'] values that I get for the fits

Then I should expect this graph to be a parabola centered around z04d=-0.5 (the input value I always used for z04d). The graph should have a misalignment_fit_errors['z04d'] value of 0 there that increases parabolically as you move away from z04d=-0.5. Finally, I do the exact same thing but for z05d for all of the instances where I tested z05d.

Is this correct?

from piff.

areshernandez avatar areshernandez commented on September 26, 2024

On a separate note. I have also tried the following:

  1. z04d=-0.5, z05d=0.1, z08d=0.03
  2. z04d=-0.5, z06d=0.06, z07d=0.01
  3. z04d=-0.5, z08d=0.03, z09d=0.1
  4. z04d=-0.5, z07d=0.01, z10d=0.1
  5. z04d=-0.5, z10d=0.1
  6. z04d=-0.5, z09d=0.1
  7. z04d=-0.5, z07d=0.01
  8. z04d=-0.5, z06d=0.06
  9. z04d=-0.5, z05d=0.1, z10d=0.1
  10. z04d=-0.5, z06d=0.06, z09d=0.1
  11. z04d=-0.5, z06d=0.06, z08d=0.03
  12. z04d=-0.5, z05d=0.1, z07d=0.01
  13. z04d=-0.5, z07d=0.01, z09d=0.1
  14. z04d=-0.5, z08d=0.03, z10d=0.1
  15. z04d=-0.5, z05d=0.1, z09d=0.1
  16. z04d=-0.5, z06d=0.06, z10d=0.1

None of these have produced good fits either. They all seem to be pretty bad fits just like (1). For example, for (21) the fit gives z04d=-0.01826, whereas for (1) the fit gives z04d=-0.1579, even though both are supposed to give -0.5

from piff.

cpadavis avatar cpadavis commented on September 26, 2024

from piff.

areshernandez avatar areshernandez commented on September 26, 2024

The chi-squared graph for astigmatism-y also does not have a minimum at either the input value or the fitted value. The minimum is to the left of both, just like what was the case with defocus. Unfortunately, the chi-squared graphs for the temporary atmosphere parameters (size, first ellipticity, second ellipticity) failed because of a runtime error:

  File "test_optatmo.py", line 1289, in <module>
    test_fit()
  File "/afs/slac.stanford.edu/u/ec/aresh/Piff-wavefront/tests/piff_test_helper.py", line 78, in f2
    result = f(*args, **kwargs)
  File "test_optatmo.py", line 1109, in test_fit
    chi_squareds_list.append(optpsf._fit_func(r0=0.1+dz_size_due_to_temporary_atmosphere[i], g1=misalignment['g1'], g2=misalignment['g2'], z04d=misalignment['z04d'], z04x=np.nan, z04y=np.nan, z05d=misalignment['z05d'], z05x=np.nan, z05y=np.nan, z06d=np.nan, z06x=np.nan, z06y=np.nan, z07d=np.nan, z07x=np.nan, z07y=np.nan, z08d=np.nan, z08x=np.nan, z08y=np.nan, z09d=np.nan, z09x=np.nan, z09y=np.nan, z10d=np.nan, z10x=np.nan, z10y=np.nan, z11d=np.nan, z11x=np.nan, z11y=np.nan))
  File "/u/ec/aresh/Piff-wavefront/piff/optatmo.py", line 593, in _fit_func
    shapes = self._measure_shapes(self.drawStarList(self._fit_stars),)# logger=logger)
  File "/u/ec/aresh/Piff-wavefront/piff/optatmo.py", line 654, in drawStarList
    stars = [self.model.draw(star) for star in stars]
  File "/u/ec/aresh/Piff-wavefront/piff/optical_model.py", line 261, in draw
    image = prof.drawImage(star.data.image.copy(), method='no_pixel', offset=offset)
  File "/nfs/slac/g/ki/ki18/cpd/anaconda2/lib/python2.7/site-packages/galsim/gsobject.py", line 1356, in drawImage
    added_photons = prof.drawFFT(imview, wmult)
  File "/nfs/slac/g/ki/ki18/cpd/anaconda2/lib/python2.7/site-packages/galsim/gsobject.py", line 1467, in drawFFT
    "If you can handle the large FFT, you may update gsparams.maximum_fft_size.")
RuntimeError: drawFFT requires an FFT that is too large: 7516.If you can handle the large FFT, you may update gsparams.maximum_fft_size.

Do you know what could be causing this runtime error? More importantly, do you know what the minimum in the chi-squared graphs being in the wrong place could imply?

from piff.

cpadavis avatar cpadavis commented on September 26, 2024

from piff.

areshernandez avatar areshernandez commented on September 26, 2024

I changed the chi-squared graphs to make sure the input graphs used input parameters and the fitted graphs used fitted parameters. Most of the chi-squared graphs look parabolic now.

However, some appear off-center (the minimum looks like it's not at correct point). Also, the astigmatism-y graphs look like they might be quartic and the defocus graphs look like they might be a high-order polynomial.

Do you think this is likely due to the range of dz's tested being too large for the defocus and astigmatism-y graphs (I expanded the range to much more than -0.2 to 0.2 for those graphs)? Also, is there a reason why some of the chi-squared graphs might be off-center?

from piff.

areshernandez avatar areshernandez commented on September 26, 2024

I tried Aaron's technique of keeping the temporary atmosphere without disabling it while keeping it at a fixed value; however, it did not fit. I am wondering if the problem is that the stars used to do all the fitting are the optatmo stars, so when the optical fit is attempting it fits to stars that were created with stuff not generated by the input optical terms (i.e. the atmospheric inputs), it doesn't fit correctly. Do you think this is likely the problem? If so, do you think I should change the OptAtmoPSF.fit() function, so that it does the optical fit with the opt stars first before fitting everything else with the optatmo stars?

from piff.

areshernandez avatar areshernandez commented on September 26, 2024

I re-ran the fit using create_data() instead of create_synthetic_optatmo. It still hasn't finished fitting but it looks like it is converging on the wrong values for defocus and astigmatism-y. I'm not sure, but looking at create_data(), it looks like both psf and psf_clean have the temporary atmosphere disabled, even though it is supposed to be enabled for psf_clean (which is what I am using in the fit). Is there something inside optpsf.disable_atmosphere() that allows it to recognize that psf_clean should not have its temporary atmosphere wiped or should I comment out the line that seems to wipe it?:

psf_clean.optpsf.disable_atmosphere(logger=logger)

from piff.

cpadavis avatar cpadavis commented on September 26, 2024

from piff.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.