agb32 / dasp

DASP the Durham Adaptive optics Simulation Platform: Modelling and simulation of adaptive optics systems
https://www.dur.ac.uk/cfai/adaptiveoptics/dasp/
GNU Affero General Public License v3.0
16 stars 10 forks source link

WARNING:tomoRecon: unable to load reconmx rmx.fits, using 0. instead #5

Open joncox123 opened 4 years ago

joncox123 commented 4 years ago

When running the default scaoSim generated by daspbuilder.py, I get the error/warning message: >>>0: WARNING:tomoRecon: unable to load reconmx rmx.fits, using 0. instead

What causes this? Should I be worried about it? Could this be the reason scaoSim appears to not properly correct for the wavefront?

joncox@desktop:~/git/dasp/sims/scaoSim_default$ python scao.py params.py TODO: sort out scipy.linsolve usage in spmatrix.py INFORMATION:tomoRecon:TO DO: Sort out import of scipy.linsolve in tomoRecon Not implemented - broadcast

0: INFORMATION: Using ['params.py'] 0:


Reading param file params.py


0: USING PYTHON CONFIG FILE params.py 0: FOV computed as 0 for DM dm 0: INFORMATION Assuming reconstructor wavelength of 640.0 for DM dm 0: Calculating dmpup at height 0: 48 (fov 0)... 0: INFORMATION Bound to port 9000 0: Rank 0 imported modules 0: scrnSize: {'L0': (53, 53), 'L1': (53, 53)} 0: Loading phase covariance data 0: Computation of the initial phase screen 0: Loading existing screen: scrn/iscrn48D4.2L10x53y53s10t0.004r0.137s0.9d0v10.fits 0: Loading phase covariance data 0: Computation of the initial phase screen 0: Loading existing screen: scrn/iscrn48D4.2L10x53y53s11t0.004r0.137s0.1d0v10.fits 0: iatmos: Copied initial screen from parent allLayers[L0] 0: TODO: iatmos - is this copy of initial screen needed? 0: iatmos: Copied initial screen from parent allLayers[L1] 0: TODO: iatmos - is this copy of initial screen needed? 0: atmos: Layers ['L0', 'L1'], sorted ['L0', 'L1'] 0: Calculating dmpup at height 0: 48 (fov 0)[' -ve conj'] 0: DM pupil central obscuration 3.42857 (radius 24) 0: xinterp_dm_dm1: using nacts=157 0: INFORMATION:wfscent: Using 4 threads 0: INFORMATION:wfscent:Initialising centroid object {'closed': <science.xinterp_dm.dm instance at 0x7fc16e482a50>} 1 0: INFORMATION: using default value of 0 for subtractTipTilt, not found in: ['wfscent_1', 'wfscent', 'globals'] 0: INFORMATION:tomoRecon: Using 1 DMs for reconstruction 0: INFORMATION:tomoRecon:tomoRecon: Loading reconstructor (157,64) from file: rmx.fits 0: WARNING:tomoRecon: unable to load reconmx rmx.fits, using 0. instead 0: science: Using 4 threads 0: science sci1 - Using wavelength of 1650 nm (phase at 640 nm) 0: INFORMATION:centroid:initialising cmod, nthreads = 4 0: INFORMATION:tomoRecon:decay factors of 0.0 applied where closed loop list [1] is 0 - is this what you intended? 0: INFORMATION Took 1.12049 seconds to initialise 0: INFORMATION Waiting at MPI barrier... 0: Not implemented - barrier 0: INFORMATION Sharing connection setting 0: Not implemented - broadcast 0: INFORMATION Using approximately 0.726151GB 0: Not implemented - share 0: INFORMATION:Ctrl:Will close loop after 10 iterations 0: INFORMATION:Ctrl:Starting poking 0: INFORMATION Entering main loop 0: xinterp_dm object assigning parents automatically 0: xinterp_dm parent object 1 becoming atmos 0: xinterp_dm parent object 2 becoming recon with output shape (157,) 0: DM dm using actuators from 0 to 157 (recon output size 157) 0: INFORMATION:tomoRecon:Creating poke matrix of type <type 'numpy.float32'> shape 157 64 0: INFORMATION:tomoRecon:Will be poking for 158 integrations 0: INFORMATION Zeroing science,closing loop etc 0: INFORMATION:tomoRecon:tomoRecon: Loading reconstructor (157,64) from file: rmx.fits 0: WARNING:tomoRecon: unable to load reconmx rmx.fits, using 0. instead 0: INFORMATION:tomoRecon:Reconstructor shape should be (157,64) 0: INFORMATION:tomoRecon:tomoRecon: Loading reconstructor (157,64) from file: rmx.fits 0: WARNING:tomoRecon: unable to load reconmx rmx.fits, using 0. instead 0: INFORMATION:tomoRecon:Reconstructor shape should be (157,64) 0: INFORMATION:tomoRecon:tomoRecon: Loading reconstructor (157,64) from file: rmx.fits 0: WARNING:tomoRecon: unable to load reconmx rmx.fits, using 0. instead 0: INFORMATION:tomoRecon:Reconstructor shape should be (157,64) 0: INFORMATION:tomoRecon:tomoRecon: Loading reconstructor (157,64) from file: rmx.fits 0: WARNING:tomoRecon: unable to load reconmx rmx.fits, using 0. instead 0: INFORMATION:tomoRecon:Reconstructor shape should be (157,64) 0: INFORMATION:tomoRecon:tomoRecon: Loading reconstructor (157,64) from file: rmx.fits 0: WARNING:tomoRecon: unable to load reconmx rmx.fits, using 0. instead 0: INFORMATION:tomoRecon:Reconstructor shape should be (157,64) 0: INFORMATION:tomoRecon:tomoRecon: Loading reconstructor (157,64) from file: rmx.fits 0: WARNING:tomoRecon: unable to load reconmx rmx.fits, using 0. instead

agb32 commented 4 years ago

Yes - if it can't load a reconstructor, it won't close the loop... so this implies something is wrong.

Does it create a pmx.fits and rmx.fits file?

joncox123 commented 4 years ago

@agb32 it does eventually create pmx.fits and rmx.fits after about 40 iterations of trying to load rmx.fits and failing. That said, the loop still doesn't seem to be working. Why should it try a bunch of times until it eventually writes rmx.fits? Is it becomes it has to iteratively perturb the DM to solve for the relationship between the actuator and spatial phase correction?

Anyway, the Sterhl is around 0.05 to 0.1, even after it eventually loads rmx.fits:

30146: {'rms': 0, 'strehlPeak': 0.0499666, 'strehlInst': 0.118264, 'inbox0.2': 0.185225, 'd50': 0.509966, 'strehl': 0.0499666, 'FWHM': 0.297483, }

I am using Ubuntu 18.0.4.5 with Python 2.7.17, numpy 1.19.0 and scipy 1.4.1

By the way, I also noticed that the code was trying to import really old versions of scipy.linsolve that were either renamed or contain private methods that don't exist anymore. I fixed this in spmatrix.py and tomoRecon.py.

For tomoRecon.py, the solution is simply to use the new namespace:

try:
    from scipy.sparse.linalg import splu
except ImportError:
    from scipy.linsolve import splu

But for spmatrix.py you wrote a modified spsolve() that uses private method from spsolve that dissappeared a long time ago. As a workaround, I just import the new spsolve() that is built into scipy if your re-write can't be used. But the question is, does your rewrite fundamentally modify the output of scipy's spsolve (e.g. better numerical stability), or is it just faster or have better error handling?

# This customization of spsolve needs to be updated to support non-ancient versions of scipy
try:
    import scipy.linsolve as linsolve

    # This is copied from scipy.linsolve.  The idea is to make it better for
    # this situation, including the ability to factorise the matrix before
    # doing the computation...
    def spsolve(A, b, permc_spec=2):
        """Taken from scipy.linsolve, and updated to raise an exception if error occurs."""
        # ... modified spsolve code here ...
except ImportError:
    print "TODO: sort out scipy.linsolve usage in spmatrix.py"
    from scipy.sparse.linalg import spsolve

However, fixing these scipy.linsolve issues didn't help. The Sterhl is still poor and scaoSim doesn't appear to be working. I'm not sure if these linsolve routines were being used anyway since it didn't crash before my "fix".

agb32 commented 4 years ago

Hmm - the idea is that it does poking for N iterations, writes the poke matrix, the rmx.fits, and then closes the loop.
No, I don't think the linsolve will be being used by scaoSim. Not sure why the Strehl is so low - but possibly its at 500nm or 650nm, rather than 1650nm - in which case, that is probably about right. I will have to fire up an old laptop tomorrow to take a look...