ratt-ru / pfb-imaging

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

Singular matrix error when converting wcs to header #55

Closed landmanbester closed 2 years ago

landmanbester commented 2 years ago

I'm running into the following singular matrix error when converting wcs to header

Traceback (most recent call last):
  File "/home/bester/venvs/pfb/bin/pfb", line 33, in <module>
    sys.exit(load_entry_point('pfb-clean', 'console_scripts', 'pfb')())
  File "/home/bester/venvs/pfb/lib/python3.9/site-packages/click/core.py", line 1128, in __call__
    return self.main(*args, **kwargs)
  File "/home/bester/venvs/pfb/lib/python3.9/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/home/bester/venvs/pfb/lib/python3.9/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/bester/venvs/pfb/lib/python3.9/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/bester/venvs/pfb/lib/python3.9/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/home/bester/pfb-clean/pfb/workers/grid.py", line 75, in grid
    return _grid(**opts)
  File "/home/bester/pfb-clean/pfb/workers/grid.py", line 392, in _grid
    hdr = set_wcs(cell_size / 3600, cell_size / 3600,
  File "/home/bester/pfb-clean/pfb/utils/fits.py", line 64, in set_wcs
    header = w.to_header()
  File "/home/bester/venvs/pfb/lib/python3.9/site-packages/astropy/wcs/wcs.py", line 2670, in to_header
    header_string = self.wcs.to_header(relax)
astropy.wcs._wcs.SingularMatrixError: ERROR 3 in wcsset() at line 2739 of file cextern/wcslib/C/wcs.c:
Linear transformation matrix is singular.
ERROR 3 in linset() at line 674 of file cextern/wcslib/C/lin.c:
PCi_ja matrix is singular.

This only seems to happen some of the time, if I go through exactly the same steps in an ipython session I can't reproduce the error. Anyone perhaps know what could be causing this? Tagging @o-smirnov @JSKenyon @bennahugo

bennahugo commented 2 years ago

Sorry not following what you are trying to do - can you post the relevant steps?

It looks like your WCS transform matrix is invalid?

On Thu, May 5, 2022 at 2:30 PM Landman Bester @.***> wrote:

I'm running into the following singular matrix error when converting wcs to header

Traceback (most recent call last): File "/home/bester/venvs/pfb/bin/pfb", line 33, in sys.exit(load_entry_point('pfb-clean', 'console_scripts', 'pfb')()) File "/home/bester/venvs/pfb/lib/python3.9/site-packages/click/core.py", line 1128, in call return self.main(args, kwargs) File "/home/bester/venvs/pfb/lib/python3.9/site-packages/click/core.py", line 1053, in main rv = self.invoke(ctx) File "/home/bester/venvs/pfb/lib/python3.9/site-packages/click/core.py", line 1659, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/home/bester/venvs/pfb/lib/python3.9/site-packages/click/core.py", line 1395, in invoke return ctx.invoke(self.callback, ctx.params) File "/home/bester/venvs/pfb/lib/python3.9/site-packages/click/core.py", line 754, in invoke return __callback(args, kwargs) File "/home/bester/pfb-clean/pfb/workers/grid.py", line 75, in grid return _grid(opts) File "/home/bester/pfb-clean/pfb/workers/grid.py", line 392, in _grid hdr = set_wcs(cell_size / 3600, cell_size / 3600, File "/home/bester/pfb-clean/pfb/utils/fits.py", line 64, in set_wcs header = w.to_header() File "/home/bester/venvs/pfb/lib/python3.9/site-packages/astropy/wcs/wcs.py", line 2670, in to_header header_string = self.wcs.to_header(relax) astropy.wcs._wcs.SingularMatrixError: ERROR 3 in wcsset() at line 2739 of file cextern/wcslib/C/wcs.c: Linear transformation matrix is singular. ERROR 3 in linset() at line 674 of file cextern/wcslib/C/lin.c: PCi_ja matrix is singular.

This only seems to happen some of the time, if I go through exactly the same steps in an ipython session I can't reproduce the error. Anyone perhaps know what could be causing this? Tagging @o-smirnov https://github.com/o-smirnov @JSKenyon https://github.com/JSKenyon @bennahugo https://github.com/bennahugo

— Reply to this email directly, view it on GitHub https://github.com/ratt-ru/pfb-clean/issues/55, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB4RE6QM6MSRVYPEPDVFWEDVIO5NNANCNFSM5VE5HULQ . You are receiving this because you were mentioned.Message ID: @.***>

--

Benjamin Hugo

PhD. student, Centre for Radio Astronomy Techniques and Technologies Department of Physics and Electronics Rhodes University

Junior software developer Radio Astronomy Research Group South African Radio Astronomy Observatory Black River Business Park Observatory Cape Town

landmanbester commented 2 years ago

Quite simply trying to set up a WCS and convert to a hdr using https://github.com/ratt-ru/pfb-clean/blob/57b4b74a345964f3d7316f41f35714d5c8e99998/pfb/utils/fits.py#L28

The confusing part is that I can't reproduce it with the same arguments running an interactive ipython session, it happens every now and then when I run the grid worker

bennahugo commented 2 years ago

Odd I can't see anything wrong here. So you are saying that it is non-deterministic when run with precisely the same parameters?

On Thu, 05 May 2022, 19:11 Landman Bester, @.***> wrote:

Quite simply trying to set up a WCS and convert to a hdr using https://github.com/ratt-ru/pfb-clean/blob/57b4b74a345964f3d7316f41f35714d5c8e99998/pfb/utils/fits.py#L28

The confusing part is that I can't reproduce it with the same arguments running an interactive ipython session, it happens every now and then when I run the grid https://github.com/ratt-ru/pfb-clean/blob/stimelator/pfb/workers/grid.py worker

— Reply to this email directly, view it on GitHub https://github.com/ratt-ru/pfb-clean/issues/55#issuecomment-1118846944, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB4RE6R6BHO2LHVTLLZIZB3VIP6NHANCNFSM5VE5HULQ . You are receiving this because you were mentioned.Message ID: @.***>

landmanbester commented 2 years ago

It would seem that way. It's only happened to me twice. I'm trying to reproduce it but it refuses to reproduce. I've added a try except so it can drop me into the debugger when it happens again

bennahugo commented 2 years ago

I presume you are not running this in parallel. I'm not sure if that library should be called from a threaded environment.

From what I can tell you are just constructing a header. Why do you need to do this through WCS? It is just a fits header type (ordered map) that is needed.

On Fri, 06 May 2022, 11:20 Landman Bester, @.***> wrote:

It would seem that way. It's only happened to me twice. I'm trying to reproduce it but it refuses to reproduce. I've added a try except so it can drop me into the debugger when it happens again

— Reply to this email directly, view it on GitHub https://github.com/ratt-ru/pfb-clean/issues/55#issuecomment-1119420420, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB4RE6RAPQW4PJDGJD7Y5O3VITP6XANCNFSM5VE5HULQ . You are receiving this because you were mentioned.Message ID: @.***>

landmanbester commented 2 years ago

It's not running in parallel. I'm just using WCS because of the convenient (or not so convenient as it turns out) .to_header() method. You are right though, I can avoid this problem entirely by constructing the header from scratch. Thanks @bennahugo