PaulHancock/Aegean

Aegean TypeError: 'NoneType' object does not support item assignment

Closed this issue · 12 comments

I am trying to run aegean on the test file however I seem to have some issues with BANE.

`(base) is-m-00116:Aegean-master joegrundy$ aegean tests/test_files/1904-66_SIN.fits
5190:aegean:INFO This is Aegean 2.2.3-(2020-07-23)
5190:aegean:INFO Found 4 cores
5190:aegean:INFO Using 4 cores
5190:aegean:INFO Finding sources.
WARNING: FITSFixedWarning: 'datfix' made the change 'Set DATE-REF to '1858-11-17' from MJD-REF'. [astropy.wcs.wcs]
5190:logger:WARNING FITSFixedWarning: 'datfix' made the change 'Set DATE-REF to '1858-11-17' from MJD-REF'.
WARNING: FITSFixedWarning: 'datfix' made the change 'Set DATE-REF to '1858-11-17' from MJD-REF'. [astropy.wcs.wcs]
5190:logger:WARNING FITSFixedWarning: 'datfix' made the change 'Set DATE-REF to '1858-11-17' from MJD-REF'.
5190:source_finder:INFO Calculating background and rms data
multiprocessing.pool.RemoteTraceback:
"""
Traceback (most recent call last):
File "/opt/anaconda3/lib/python3.8/site-packages/AegeanTools/BANE.py", line 121, in _sf2
return sigma_filter(*args)
File "/opt/anaconda3/lib/python3.8/site-packages/AegeanTools/BANE.py", line 229, in sigma_filter
ibkg[start_idx:end_idx] = row # np.ctypeslib.as_ctypes(row)
TypeError: 'NoneType' object does not support item assignment

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/opt/anaconda3/lib/python3.8/multiprocessing/pool.py", line 125, in worker
result = (True, func(*args, **kwds))
File "/opt/anaconda3/lib/python3.8/multiprocessing/pool.py", line 48, in mapstar
return list(map(*args))
File "/opt/anaconda3/lib/python3.8/site-packages/AegeanTools/BANE.py", line 124, in _sf2
raise Exception("".join(traceback.format_exception(*sys.exc_info())))
Exception: Traceback (most recent call last):
File "/opt/anaconda3/lib/python3.8/site-packages/AegeanTools/BANE.py", line 121, in _sf2
return sigma_filter(*args)
File "/opt/anaconda3/lib/python3.8/site-packages/AegeanTools/BANE.py", line 229, in sigma_filter
ibkg[start_idx:end_idx] = row # np.ctypeslib.as_ctypes(row)
TypeError: 'NoneType' object does not support item assignment

"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/opt/anaconda3/bin/aegean", line 340, in
found = sf.find_sources_in_image(filename, outfile=options.outfile, hdu_index=options.hdu_index,
File "/opt/anaconda3/lib/python3.8/site-packages/AegeanTools/source_finder.py", line 1861, in find_sources_in_image
self.load_globals(filename, hdu_index=hdu_index, bkgin=bkgin, rmsin=rmsin, beam=beam, verb=True, rms=rms,
File "/opt/anaconda3/lib/python3.8/site-packages/AegeanTools/source_finder.py", line 1174, in load_globals
self._make_bkg_rms(filename=filename, mesh_size=20, forced_rms=rms, forced_bkg=bkg, cores=cores)
File "/opt/anaconda3/lib/python3.8/site-packages/AegeanTools/source_finder.py", line 1349, in _make_bkg_rms
bkg, rms = filter_image(im_name=filename, out_base=None,
File "/opt/anaconda3/lib/python3.8/site-packages/AegeanTools/BANE.py", line 435, in filter_image
bkg, rms = filter_mc_sharemem(im_name, step_size=step_size, box_size=box_size, cores=cores, shape=shape, nslice=nslice, domask=mask)
File "/opt/anaconda3/lib/python3.8/site-packages/AegeanTools/BANE.py", line 359, in filter_mc_sharemem
pool.map_async(_sf2, args, chunksize=1).get(timeout=10000000)
File "/opt/anaconda3/lib/python3.8/multiprocessing/pool.py", line 771, in get
raise self._value
Exception: Traceback (most recent call last):
File "/opt/anaconda3/lib/python3.8/site-packages/AegeanTools/BANE.py", line 121, in _sf2
return sigma_filter(*args)
File "/opt/anaconda3/lib/python3.8/site-packages/AegeanTools/BANE.py", line 229, in sigma_filter
ibkg[start_idx:end_idx] = row # np.ctypeslib.as_ctypes(row)
TypeError: 'NoneType' object does not support item assignment`

aegean --version outputs the following:
(base) is-m-00116:Aegean-master joegrundy$ aegean --version 4702:aegean:INFO This is Aegean 2.2.3-(2020-07-23) 4702:aegean:INFO AegeanTools 2.2.3 from /opt/anaconda3/lib/python3.8/site-packages/AegeanTools/__init__.py 4702:aegean:INFO Numpy 1.18.5 from /opt/anaconda3/lib/python3.8/site-packages/numpy/__init__.py 4702:aegean:INFO Scipy 1.5.0 from /opt/anaconda3/lib/python3.8/site-packages/scipy/__init__.py 4702:aegean:INFO AstroPy 4.0.1.post1 from /opt/anaconda3/lib/python3.8/site-packages/astropy/__init__.py 4702:aegean:INFO LMFit 1.0.1 from /opt/anaconda3/lib/python3.8/site-packages/lmfit/__init__.py

Hi Paul,

I am getting a similar issue. I just got a new computer that is using Catalina (10.15.7). The install of Aegean/BANE works fine, but when I try to run Aegean or BANE I get something similar:

(base) [test_lba/]$ aegean wideM-1-MFS-image.fits
949:aegean:INFO This is Aegean 2.2.3-(2020-07-23)
949:aegean:INFO Found 16 cores
949:aegean:INFO Using 16 cores
949:aegean:INFO Finding sources.
WARNING: FITSFixedWarning: 'datfix' made the change 'Set DATE-REF to '1858-11-17' from MJD-REF.
Set MJD-OBS to 57963.606956 from DATE-OBS'. [astropy.wcs.wcs]
949:logger:WARNING FITSFixedWarning: 'datfix' made the change 'Set DATE-REF to '1858-11-17' from MJD-REF.
Set MJD-OBS to 57963.606956 from DATE-OBS'.
WARNING: FITSFixedWarning: 'datfix' made the change 'Set DATE-REF to '1858-11-17' from MJD-REF.
Set MJD-OBS to 57963.606956 from DATE-OBS'. [astropy.wcs.wcs]
949:logger:WARNING FITSFixedWarning: 'datfix' made the change 'Set DATE-REF to '1858-11-17' from MJD-REF.
Set MJD-OBS to 57963.606956 from DATE-OBS'.
949:source_finder:INFO Calculating background and rms data
multiprocessing.pool.RemoteTraceback:
"""
Traceback (most recent call last):
File "/Users/jcal/anaconda3/lib/python3.8/site-packages/AegeanTools/BANE.py", line 121, in _sf2
return sigma_filter(*args)
File "/Users/jcal/anaconda3/lib/python3.8/site-packages/AegeanTools/BANE.py", line 229, in sigma_filter
ibkg[start_idx:end_idx] = row # np.ctypeslib.as_ctypes(row)
TypeError: 'NoneType' object does not support item assignment

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/jcal/anaconda3/lib/python3.8/multiprocessing/pool.py", line 125, in worker
result = (True, func(*args, **kwds))
File "/Users/jcal/anaconda3/lib/python3.8/multiprocessing/pool.py", line 48, in mapstar
return list(map(*args))
File "/Users/jcal/anaconda3/lib/python3.8/site-packages/AegeanTools/BANE.py", line 124, in _sf2
raise Exception("".join(traceback.format_exception(*sys.exc_info())))
Exception: Traceback (most recent call last):
File "/Users/jcal/anaconda3/lib/python3.8/site-packages/AegeanTools/BANE.py", line 121, in _sf2
return sigma_filter(*args)
File "/Users/jcal/anaconda3/lib/python3.8/site-packages/AegeanTools/BANE.py", line 229, in sigma_filter
ibkg[start_idx:end_idx] = row # np.ctypeslib.as_ctypes(row)
TypeError: 'NoneType' object does not support item assignment

"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/Users/jcal/anaconda3/bin/aegean", line 340, in
found = sf.find_sources_in_image(filename, outfile=options.outfile, hdu_index=options.hdu_index,
File "/Users/jcal/anaconda3/lib/python3.8/site-packages/AegeanTools/source_finder.py", line 1861, in find_sources_in_image
self.load_globals(filename, hdu_index=hdu_index, bkgin=bkgin, rmsin=rmsin, beam=beam, verb=True, rms=rms,
File "/Users/jcal/anaconda3/lib/python3.8/site-packages/AegeanTools/source_finder.py", line 1174, in load_globals
self._make_bkg_rms(filename=filename, mesh_size=20, forced_rms=rms, forced_bkg=bkg, cores=cores)
File "/Users/jcal/anaconda3/lib/python3.8/site-packages/AegeanTools/source_finder.py", line 1349, in _make_bkg_rms
bkg, rms = filter_image(im_name=filename, out_base=None,
File "/Users/jcal/anaconda3/lib/python3.8/site-packages/AegeanTools/BANE.py", line 435, in filter_image
bkg, rms = filter_mc_sharemem(im_name, step_size=step_size, box_size=box_size, cores=cores, shape=shape, nslice=nslice, domask=mask)
File "/Users/jcal/anaconda3/lib/python3.8/site-packages/AegeanTools/BANE.py", line 359, in filter_mc_sharemem
pool.map_async(_sf2, args, chunksize=1).get(timeout=10000000)
File "/Users/jcal/anaconda3/lib/python3.8/multiprocessing/pool.py", line 771, in get
raise self._value
Exception: Traceback (most recent call last):
File "/Users/jcal/anaconda3/lib/python3.8/site-packages/AegeanTools/BANE.py", line 121, in _sf2
return sigma_filter(*args)
File "/Users/jcal/anaconda3/lib/python3.8/site-packages/AegeanTools/BANE.py", line 229, in sigma_filter
ibkg[start_idx:end_idx] = row # np.ctypeslib.as_ctypes(row)
TypeError: 'NoneType' object does not support item assignment

aegean --version
1000:aegean:INFO This is Aegean 2.2.3-(2020-07-23)
1000:aegean:INFO AegeanTools 2.2.3 from /Users/jcal/anaconda3/lib/python3.8/site-packages/AegeanTools/init.py
1000:aegean:INFO Numpy 1.18.5 from /Users/jcal/anaconda3/lib/python3.8/site-packages/numpy/init.py
1000:aegean:INFO Scipy 1.5.0 from /Users/jcal/anaconda3/lib/python3.8/site-packages/scipy/init.py
1000:aegean:INFO AstroPy 4.0.1.post1 from /Users/jcal/anaconda3/lib/python3.8/site-packages/astropy/init.py
1000:aegean:INFO LMFit 1.0.1 from /Users/jcal/anaconda3/lib/python3.8/site-packages/lmfit/init.py
(base) [test_lba/]$ aegean --version 4702:aegean:INFO
1003:aegean:INFO This is Aegean 2.2.3-(2020-07-23)
1003:aegean:INFO AegeanTools 2.2.3 from /Users/jcal/anaconda3/lib/python3.8/site-packages/AegeanTools/init.py
1003:aegean:INFO Numpy 1.18.5 from /Users/jcal/anaconda3/lib/python3.8/site-packages/numpy/init.py
1003:aegean:INFO Scipy 1.5.0 from /Users/jcal/anaconda3/lib/python3.8/site-packages/scipy/init.py
1003:aegean:INFO AstroPy 4.0.1.post1 from /Users/jcal/anaconda3/lib/python3.8/site-packages/astropy/init.py
1003:aegean:INFO LMFit 1.0.1 from /Users/jcal/anaconda3/lib/python3.8/site-packages/lmfit/init.py

Just to add, I think it is a BANE issue. If I force the rms and bkg to a value Aegean can run. However, it then encounters and issue with pickle...

(base) [test_lba/]$ aegean --forcerms 0.1 --forcebkg 0.1 wideM-1-MFS-image.fits
1175:aegean:INFO This is Aegean 2.2.3-(2020-07-23)
1175:aegean:INFO Found 16 cores
1175:aegean:INFO Using 16 cores
1175:aegean:INFO Finding sources.
WARNING: FITSFixedWarning: 'datfix' made the change 'Set DATE-REF to '1858-11-17' from MJD-REF.
Set MJD-OBS to 57963.606956 from DATE-OBS'. [astropy.wcs.wcs]
1175:logger:WARNING FITSFixedWarning: 'datfix' made the change 'Set DATE-REF to '1858-11-17' from MJD-REF.
Set MJD-OBS to 57963.606956 from DATE-OBS'.
WARNING: FITSFixedWarning: 'datfix' made the change 'Set DATE-REF to '1858-11-17' from MJD-REF.
Set MJD-OBS to 57963.606956 from DATE-OBS'. [astropy.wcs.wcs]
1175:logger:WARNING FITSFixedWarning: 'datfix' made the change 'Set DATE-REF to '1858-11-17' from MJD-REF.
Set MJD-OBS to 57963.606956 from DATE-OBS'.
1175:source_finder:INFO Calculating background and rms data
1175:source_finder:INFO Forcing rms = 0.1
1175:source_finder:INFO Forcing bkg = 0.1
1175:source_finder:INFO beam = 42.56'' x 31.91'' at 118.59deg
1175:source_finder:INFO seedclip=5
1175:source_finder:INFO floodclip=4
1175:source_finder:INFO Found 28 islands
1175:source_finder:INFO Begin fitting
Traceback (most recent call last):
File "/Users/jcal/anaconda3/bin/aegean", line 340, in
found = sf.find_sources_in_image(filename, outfile=options.outfile, hdu_index=options.hdu_index,
File "/Users/jcal/anaconda3/lib/python3.8/site-packages/AegeanTools/source_finder.py", line 1927, in find_sources_in_image
for srcs in queue:
File "/Users/jcal/anaconda3/lib/python3.8/site-packages/AegeanTools/pprocess.py", line 908, in next
self.store()
File "/Users/jcal/anaconda3/lib/python3.8/site-packages/AegeanTools/pprocess.py", line 406, in store
self.store_data(channel)
File "/Users/jcal/anaconda3/lib/python3.8/site-packages/AegeanTools/pprocess.py", line 888, in store_data
data = channel.receive()
File "/Users/jcal/anaconda3/lib/python3.8/site-packages/AegeanTools/pprocess.py", line 141, in receive
obj = self._receive()
File "/Users/jcal/anaconda3/lib/python3.8/site-packages/AegeanTools/pprocess.py", line 125, in _receive
obj = pickle.load(self.read_pipe)
_pickle.UnpicklingError: pickle data was truncated

The pickle issue is going to be the biggest killer as isn't nothing to do with your OS or how well/poorly I've set up Aegean. It's a fundamental limit on how much data can be read/written to a pickle in one go. To fix it I'd have to start rewriting the pprocess module. I did give it a good go but the coding is just so hard to understand I wasn't able to make the required changes to the pickling process to make it work. For now the only workaround is to work with smaller images. This is really unsatisfactory for both you and me, but it is something that should be fixed in the 3.0 release of Aegean. I don't have a timeline on that though.

Thanks for that info Paul. I worried it might be a deeper problem. So is this a file size or number of pixels problem (obviously correlated but not 1:1)?

What is odd is that the install of Aegean and BANE on my old laptop handles the situation fine. Is due to changes in pprocess?

(base) [Downloads/]$ aegean --autoload wideM-1-MFS-image.fits
72465:aegean:INFO This is Aegean 2.1.1-(2020-01-16)
72465:aegean:INFO Found 8 cores
72465:aegean:INFO Using 8 cores
72465:aegean:INFO Found background wideM-1-MFS-image_bkg.fits
72465:aegean:INFO Found noise wideM-1-MFS-image_rms.fits
72465:aegean:INFO Finding sources.
72465:source_finder:INFO Loading background data from file wideM-1-MFS-image_bkg.fits
72465:source_finder:INFO Loading rms data from file wideM-1-MFS-image_rms.fits
72465:source_finder:INFO beam = 42.56'' x 31.91'' at 118.59deg
72465:source_finder:INFO seedclip=5
72465:source_finder:INFO floodclip=4
72465:aegean:INFO found 935 sources total

(base) [Downloads/]$ aegean --version
72420:aegean:INFO This is Aegean 2.1.1-(2020-01-16)
72420:aegean:INFO AegeanTools 2.1.1 from /Users/jcal/opt/anaconda3/lib/python3.7/site-packages/AegeanTools-2.1.1-py3.7.egg/AegeanTools/init.py
72420:aegean:INFO Numpy 1.17.2 from /Users/jcal/opt/anaconda3/lib/python3.7/site-packages/numpy/init.py
72420:aegean:INFO Scipy 1.4.1 from /Users/jcal/opt/anaconda3/lib/python3.7/site-packages/scipy/init.py
72420:aegean:INFO AstroPy 3.2.2 from /Users/jcal/opt/anaconda3/lib/python3.7/site-packages/astropy/init.py
72420:aegean:INFO LMFit 1.0.0 from /Users/jcal/opt/anaconda3/lib/python3.7/site-packages/lmfit-1.0.0-py3.7.egg/lmfit/init.py

After having access to an osx machine just recently I can confirm that these errors are related to changes to the python multiprocessing module on osx. With older versions of python (3.5 or 3.6 maybe) the new processes would be forked from the current process (same as linux). However with newer python versions (3.8+ at least) new processes are spawned instead. I suspect that the reason things worked on @jrcallingham 's old computer is that it had a older version of python.

Since I've been coding on linux for this entire project I haven't been making my codes spawn safe, so they break on windows and now osx. I think the problem is solvable and I have had some partial success in figuring out the problem and addressing the issues, however I don't yet have a complete solution.

Thanks for the update Paul. Hope its an easy fix. These days I just run Aegean on clusters but it was always nice to run some tests on osx locally.

Thanks, Paul for looking into this. Will be waiting for a solution here.

Hi Paul, I assume you have had no luck with this issue as yet?

I haven't been able to find time to look further in to the fork/spawn issue. Depending on how much you like docker containers you could build a container based on a linux distro like ubuntu, install AegeanTools into that and then run from there. Actually the container that I use for Robbie already has the software you need (and more).

I've created a container specifically for AegeanTools which may help some people who are still encountering this issue: https://hub.docker.com/r/paulhancock/aegean
The two versions are main/dev but other versions can be built and pushed upon request.

For all the patient people who have been waiting on this thread for a solution. I'm happy to say that this problem has been resolved as of #187. You can now run Aegean/BANE on macOS without the silly NoneType error that you have been seeing. The new version of Aegean will be on pypi soon, and I'll close this issue once it is up.

This is now 'live' in version 2.3.0 of AegeanTools which you can download from pypi.org using pip install --upgrade AegeanTools.