[PIPE2D-1279] Make fitPfsFluxReference faster (3) Created: 04/Aug/23  Updated: 08/Aug/23  Resolved: 08/Aug/23

Status: Done
Project: DRP 2-D Pipeline
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Normal
Reporter: sogo.mineo Assignee: sogo.mineo
Resolution: Done Votes: 0
Labels: flux-calibration
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Reviewers: price

 Description   

We still have to make fitPfsFluxReference faster and I am working on it.

In this ticket, I want to put two changes into the master branch.
These changes will save us 1000 seconds out of 4676 seconds to run
fitPfsFluxReference on a visit.

Don't resample models twice

Currently, model spectra are resampled with a medium resolution before
being whitened because the models that have been whitened and not
doppler-shifted are reused many times by the brute-force fitting method.
With Powell's method we no longer reuse this medium-resolution models.
We can do away with the medium resolution models.

After this change, the whitening procedure of model spectra gets more similar
to that of observed spectra. We can expect less systematic errors.

Use fewer PCA components

Currently, model spectra are made of 1024 PCA components. It turned out that
the fitting results did not change very much after I changed the number of
PCA components to 512. The final products (flux references) are still made
of 1024 PCA components.

Speed

A: master
   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.025    0.025 4676.882 4676.882 fitPfsFluxReference.py:292(run)
    38541 1311.934    0.034 1312.064    0.034 fluxModelInterpolator.py:42(__call__)
    38546    2.578    0.000  958.301    0.025 fitContinuum.py:61(run)

B: Don't resample models twice
   ncalls tottime percall cumtime percall filename:lineno(function)
        1    0.021    0.021 4321.942 4321.942 fitPfsFluxReference.py:292(run)
    39973 1358.606    0.034 1358.791    0.034 fluxModelInterpolator.py:42(__call__)
    39978    2.156    0.000  566.514    0.014 fitContinuum.py:61(run)

C: Use fewer PCA components
   ncalls tottime percall cumtime percall filename:lineno(function)
        1    0.020    0.020 3542.754 3542.754 fitPfsFluxReference.py:299(run)
    39553  641.501    0.016  641.696    0.016 fluxModelInterpolator.py:42(__call__)
    39558    2.120    0.000  561.024    0.014 fitContinuum.py:61(run)

These profiles are obtained by running fitPfsFluxReference.py on a visit.

We can see that:

  • A -> B: fitContinuum gets faster by 5 minutes.
  • B -> C: fluxModelInterpolator gets faster by 12 minutes.

quality

When I input 500 model spectra (with noise added) to fitPfsFluxReference and compare
the outputs (teff, logg, metal, alpha) with the inputs, I get the following table:

                                   A ( %stddev)      B ( %stddev)      C ( %stddev)
-----------------------------------------------------------------------------------
 RMS of residuals of  'teff'  197.04 (  26.78 ) 129.95 (  17.66 ) 127.33 (  17.30 )
 RMS of residuals of  'logg'    0.42 (  35.46 )   0.35 (  29.68 )   0.36 (  30.65 )
 RMS of residuals of     'm'    0.72 (  41.15 )   0.70 (  39.74 )   0.68 (  38.85 )
 RMS of residuals of 'alpha'    0.33 (  95.42 )   0.32 (  93.22 )   0.30 (  87.13 )
-----------------------------------------------------------------------------------
Mean of residuals of  'teff' -144.90 ( -19.69 ) -76.38 ( -10.38 ) -74.17 ( -10.08 )
Mean of residuals of  'logg'   -0.13 ( -11.33 )  -0.05 (  -4.61 )  -0.06 (  -5.04 )
Mean of residuals of     'm'   -0.03 (  -1.82 )  -0.04 (  -2.15 )  -0.05 (  -2.60 )
Mean of residuals of 'alpha'    0.00 (   1.00 )  -0.03 (  -8.88 )  -0.02 (  -6.84 )

In these tests, I set the input radial velocity to zero and fix the radial velocity
parameter to zero during fitting so that measurement errors of the radial velocity
do not affect the result. "%stddev" is the percentage relative to the standard deviation
of the input 500 parameters. For "A", "B", and "C", see "Speed" section above.

We can see that (1) modifying the whitening method indeed improves the fitting quality,
and that (2) changing the model quality does not affect the fitting quality.



 Comments   
Comment by sogo.mineo [ 07/Aug/23 ]

Could you review this PR?

Comment by sogo.mineo [ 08/Aug/23 ]

Merged. Thanks for reviewing.

Generated at Sat Feb 10 16:05:26 JST 2024 using Jira 8.3.4#803005-sha1:1f96e09b3c60279a408a2ae47be3c745f571388b.