ptycho / ptypy

Ptypy - main repository
Other
37 stars 16 forks source link

Bug: Seeding object from a recon fails #282

Open wfeschen opened 3 years ago

wfeschen commented 3 years ago

Hi,

I figured out that loading the object from a reconstruction is broken (at least when I run ptypy with the following script):

    p = u.Param()
    p.verbose_level = 3                 # 4 debug information

    # input output Parameter
    p.io = u.Param()
    p.io.autosave = u.Param()
    p.io.home = os.getcwd()
    p.io.autoplot = u.Param()
    p.io.autoplot.active = False 
    p.io.autosave.interval = 1000 
    p.data_type = u.Param()
    p.data_type = "single"

    p.scans = u.Param()
    p.scans.scan00 = u.Param()
    p.scans.scan00.data = u.Param()

    # standard
    p.scans.scan00.data.source = "dp//scan.ptyd"
    p.scans.scan00.data.dfile = "result.ptyd"

    p.scans.scan00.name = "Full"
    p.scans.scan00.data.name = "PtydScan"
    p.scans.scan00.data.auto_center = True           # False for best result so far
    p.scans.scan00.data.shape = shape
    p.scans.scan00.data.energy = energy
    p.scans.scan00.data.distance = distance
    p.scans.scan00.data.psize = psize
    p.scans.scan00.data.shape = shape
    # p.scans.scan00.data.precedence = "meta"
    p.scans.scan00.data.orientation = orientation

    p.scans.scan00.sample = u.Param()
    p.scans.scan00.sample.model = "recon"
    p.scans.scan00.sample.recon = u.Param()
    p.scans.scan00.sample.recon.rfile = recon_obj_filepath

...
more code
...

I think the problem is caused by the following part of the code:


def init_storage(storage, sample_pars=None, energy=None):
....
some code
...
    # Process the given model
    if str(p.model) == 'sim' or p.process is not None:

        # Make this a single call in future
        model = simulate(model, p.process, energy, p.fill, prefix).

at this part of the code, ptypy tries to simulate the object, although I never specified "sim". This is the case because p.process is not None. For myself I solved this by removing the second part of the if condition.

if str(p.model) == 'sim':

Best regards and thanks for keeping this wonderful library work! Wilhelm

daurer commented 3 years ago

Hi Wilhelm,

I have noticed the same problem before, thanks for reminding us about this issue. The quickest fix is to explicitly set p.scans.scan00.sample = None in your run script. That's what I did whenever I encountered this issues. This is of course not very intuitive and should at the very least be documented.

As a proper fix, one option would be to change the default of sample.process to None, but there might be a reason for the current setup which is c;learly designed for the case when no initial object is provided.

Another option would be to check if an object is provided via sample.recon and in that case disable sample.process. @bjoernenders what do you think would be the best solution here?

bjoernenders commented 3 years ago

Hi Wilhelm, thanks for pointing this out. The best way here is to do p.scans.scan00.sample = /path/to/file.ptyr or to explicitly set process=None . We need to work on our documentation here to clarify this. Best, Bjoern

jcesardasilva commented 3 years ago

Hi Everyone, I typically do as @wfeschen did, but adding process=None:

p.scans.scan00.sample = u.Param()
p.scans.scan00.sample.model = "recon"
p.scans.scan00.sample.process = None
p.scans.scan00.sample.recon = u.Param()
p.scans.scan00.sample.recon.rfile = recon_obj_filepath

What is the difference between this and what @bjoernenders said by directly putting the file on sample p.scans.scan00.sample = /path/to/file.ptyr?

Another behaviour to watch is when the illumination is load from .ptyrfile, because the number of photons are normalised accord to the stats ptypy estimates.

daurer commented 3 years ago

Hi @jcesardasilva.

These two ways to load the object from a .ptyr file are effectively doing the same thing. As far as I understand, assigning the file directly to p.scans.scan00.sample is the recommended way to just load the object without any further processing. The other option, changing p.scans.scan00.sample.model to recon and using p.scans.scan00.sample.recon is the inteded way to load an object and modify it (unless you specifically turn it off via process=None). We are planning to improve the documentation to make this more clear.

Also, thanks for the reminder regarding the photon normalisation when loading a probe from file. Its the same issue here, documentation needs to be improved.