ratt-ru / pfb-imaging

Preconditioned forward/backward clean algorithm
MIT License
6 stars 5 forks source link

inf / NaN error in restore worker with default outputs #94

Closed IanHeywood closed 3 months ago

IanHeywood commented 3 months ago

I'm assuming this might be a fully flagged frequency chunk that's tripping up the cube creation when I use the default --outputs. Just asking for -i works without issue.

(pfb) ianh@ndidi:/mnt/ndidi/ianh/GC/UHF_PFB$ pfb restore -o pfb_SGRA -ntd 8 -nvt 4 -nb 8 -ldir pfb_logs
INFO      09:42:14 - RESTORE            | Initialising ThreadPool with 8 threads
INFO      09:42:14 - RESTORE            | Input Options:
INFO      09:42:14 - RESTORE            |                   host_address = None
INFO      09:42:14 - RESTORE            |                       nworkers = 1
INFO      09:42:14 - RESTORE            |                  nthreads_dask = 8
INFO      09:42:14 - RESTORE            |                      nvthreads = 4
INFO      09:42:14 - RESTORE            |                      scheduler = threads
INFO      09:42:14 - RESTORE            |                output_filename = pfb_SGRA
INFO      09:42:14 - RESTORE            |                  log_directory = pfb_logs
INFO      09:42:14 - RESTORE            |                        product = I
INFO      09:42:14 - RESTORE            |                     model_name = MODEL
INFO      09:42:14 - RESTORE            |                  residual_name = RESIDUAL
INFO      09:42:14 - RESTORE            |                          nband = 8
INFO      09:42:14 - RESTORE            |                        postfix = main
INFO      09:42:14 - RESTORE            |                        outputs = mMrRiI
INFO      09:42:14 - RESTORE            |                      overwrite = False
/mnt/home/ianh/Software/pfb-clean/pfb/utils/misc.py:539: RuntimeWarning: invalid value encountered in divide
  psfv = psf[v] / psf[v].max()
Traceback (most recent call last):
  File "/mnt/home/ianh/venv/pfb/bin/pfb", line 33, in <module>
    sys.exit(load_entry_point('pfb-clean', 'console_scripts', 'pfb')())
  File "/mnt/home/ianh/venv/pfb/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/mnt/home/ianh/venv/pfb/lib/python3.10/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/mnt/home/ianh/venv/pfb/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/mnt/home/ianh/venv/pfb/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/mnt/home/ianh/venv/pfb/lib/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/mnt/home/ianh/Software/pfb-clean/pfb/workers/restore.py", line 42, in restore
    return _restore(**opts)
  File "/mnt/home/ianh/Software/pfb-clean/pfb/workers/restore.py", line 123, in _restore
    GaussPars = fitcleanbeam(psf, level=0.5, pixsize=1.0)  # pixel units
  File "/mnt/home/ianh/Software/pfb-clean/pfb/utils/misc.py", line 563, in fitcleanbeam
    p, _ = curve_fit(func, xy, psfv, p0=(emaj0, emin0, 0.0))
  File "/mnt/home/ianh/venv/pfb/lib/python3.10/site-packages/scipy/optimize/_minpack_py.py", line 902, in curve_fit
    ydata = np.asarray_chkfinite(ydata, float)
  File "/mnt/home/ianh/venv/pfb/lib/python3.10/site-packages/numpy/lib/function_base.py", line 630, in asarray_chkfinite
    raise ValueError(
ValueError: array must not contain infs or NaNs
landmanbester commented 3 months ago

Thanks for reporting @IanHeywood. Seems like and easy fix. Just want to get the tests passing here https://github.com/ratt-ru/pfb-clean/pull/96

landmanbester commented 3 months ago

This is working for me now except I'm not sure what to put in the fits header for the GaussPars in that case. It doesn't seem to like np.nan or None values. Any suggestions?

bennahugo commented 3 months ago

Not allowed by the 4.0 standard (not in headers at least). The only place where they are expressly allowed is in the data cube, and then they need to be standard IEEE floating point numbers if the precision is set to 32 or 64. I suggest dropping the keywords - they are not axis keywords and not compulsory keywords.

landmanbester commented 3 months ago

Indeed, that's what I did in the end thanks @bennahugo. I'm not sure if this is the reason but I am not seeing the beam size when opening these fits files with carta. Will investigate