imexam icon indicating copy to clipboard operation
imexam copied to clipboard

TypeError: 'float' object is not callable

Open mschwamb opened this issue 5 years ago • 12 comments

For a Aperture sum, with radius region_size g Return curve of growth plot r Return the radial profile plot

I am getting errors when I do the three above utilities. The other utilities in imexam seem to work just fine. I'm using python 3 and a jupyter notebook. I've displayed an image reduced with the Gemin DRAGONS pacakge.

import imexam

viewer=imexam.connect() # startup a new DS9 window

viewer.load_fits('N20191112S0096_sourcesDetected.fits') # load a fits image into it

viewer.imexam()

When I type r:

Current image /Users/mschwamb/Research/playground/N20191112S0096_sourcesDetected.fits xc=1419.887294 yc=839.575413


TypeError Traceback (most recent call last) in ----> 1 viewer.imexam()

~/anaconda3/lib/python3.7/site-packages/imexam/connect.py in imexam(self) 150 self._run_event_imexam() 151 else: --> 152 self._run_imexam() 153 else: 154 warnings.warn("No valid image loaded in viewer")

~/anaconda3/lib/python3.7/site-packages/imexam/connect.py in _run_imexam(self) 266 self._check_slice() 267 self.exam.do_option( --> 268 x, y, current_key) 269 except KeyError: 270 print(

~/anaconda3/lib/python3.7/site-packages/imexam/imexamine.py in do_option(self, x, y, key) 189 """ 190 self.log.debug("pressed: {0}, {1:s}".format(key, self.imexam_option_funcs[key][0].name)) --> 191 self.imexam_option_funcs[key][0](x, y, self._data) 192 193 def get_options(self):

~/anaconda3/lib/python3.7/site-packages/imexam/imexamine.py in radial_profile(self, x, y, data, form, genplot, fig) 1058 # The bkg sum with the circular aperture is then 1059 # the mean local background times the circular apreture area. -> 1060 annulus_area = annulus_apertures.area() 1061 sky_per_pix = float(bkgflux_table['aperture_sum'] / 1062 annulus_area)

TypeError: 'float' object is not callable

I'm not sure what's the issue or how to fix it. I'm happy to share the image if that would be helpful for debugging.

mschwamb avatar Nov 23 '19 20:11 mschwamb

I have the same bug in the the profile or aperture photometry tools, using python=3.6 or 3.7. I am also using anaconda (on mac). Shame, this seemed like a good replacement for that IRAF tool!

In [12]: imexam.__version__
Out[12]: '0.8.1'

~/anaconda3/envs/py36-astropy/lib/python3.6/site-packages/imexam/imexamine.py in radial_profile(self, x, y, data, form, genplot, fig)
   1058             # The bkg sum with the circular aperture is then
   1059             # the mean local background times the circular apreture area.
-> 1060             annulus_area = annulus_apertures.area()
   1061             sky_per_pix = float(bkgflux_table['aperture_sum'] /
   1062                                 annulus_area)

TypeError: 'float' object is not callable

hjmcc avatar Dec 03 '19 09:12 hjmcc

Also trying with the development version produces the same errors: (pip install git+https://github.com/spacetelescope/imexam.git)

hjmcc avatar Dec 03 '19 10:12 hjmcc

It seems there was a change to the photutils.aperture API in version 0.7 (.area() was switched to an attribute and not a method). Switching back to version 0.6 doesn't fix the problem. Changing the code to .area from .area() doesn't work for me unfortunately (another bug pops up).

hjmcc avatar Dec 03 '19 10:12 hjmcc

sorry, I've been swamped with other work lately. I'm sure this can be fixed, I'll try and take a look soon, but thank you for reporting the issues.

sosey avatar Dec 03 '19 15:12 sosey

No worries, thanks for making this tool available, it is very helpful !

For info, in fact switching to .area from .area() fixes two of the three aperture sum tasks, 'a' and 'g', the error now given with 'r' is

~/anaconda3/envs/py37-astropy/lib/python3.7/site-packages/imexam/connect.py in imexam(self)
    150                 self._run_event_imexam()
    151             else:
--> 152                 self._run_imexam()
    153         else:
    154             warnings.warn("No valid image loaded in viewer")

~/anaconda3/envs/py37-astropy/lib/python3.7/site-packages/imexam/connect.py in _run_imexam(self)
    266                                     self._check_slice()
    267                                 self.exam.do_option(
--> 268                                     x, y, current_key)
    269                 except KeyError:
    270                     print(

~/anaconda3/envs/py37-astropy/lib/python3.7/site-packages/imexam/imexamine.py in do_option(self, x, y, key)
    189         """
    190         self.log.debug("pressed: {0}, {1:s}".format(key, self.imexam_option_funcs[key][0].__name__))
--> 191         self.imexam_option_funcs[key][0](x, y, self._data)
    192
    193     def get_options(self):

~/anaconda3/envs/py37-astropy/lib/python3.7/site-packages/imexam/imexamine.py in radial_profile(self, x, y, data, form, genplot, fig)
   1068             self.log.info("Background per pixel: {0:f}".format(sky_per_pix))
   1069
-> 1070             flux -= sky_per_pix
   1071
   1072             if getdata:

UFuncTypeError: Cannot cast ufunc 'subtract' output from dtype('float64') to dtype('uint16') with casting rule 'same_kind'

hjmcc avatar Dec 03 '19 17:12 hjmcc

try the code from this PR: https://github.com/spacetelescope/imexam/pull/195 and let me know if it's working for you. I tried it with 0.6.dev28+g5fc8f449 and 0.7.1

sosey avatar Dec 03 '19 21:12 sosey

I updated with pip install --upgrade imexam and tried again and still having the same issue.

mschwamb avatar Jan 02 '20 20:01 mschwamb

Hi, I get this same error when in python 3.6.10 I run viewer.imexam() and press a. It says you are 'calling' a float, so maybe there are () instead of [ ] somewhere?


TypeError Traceback (most recent call last) in ----> 1 viewer.imexam()

/opt/anaconda3/envs/python3/lib/python3.6/site-packages/imexam/connect.py in imexam(self) 150 self._run_event_imexam() 151 else: --> 152 self._run_imexam() 153 else: 154 warnings.warn("No valid image loaded in viewer")

/opt/anaconda3/envs/python3/lib/python3.6/site-packages/imexam/connect.py in _run_imexam(self) 266 self._check_slice() 267 self.exam.do_option( --> 268 x, y, current_key) 269 except KeyError: 270 print(

/opt/anaconda3/envs/python3/lib/python3.6/site-packages/imexam/imexamine.py in do_option(self, x, y, key) 189 """ 190 self.log.debug("pressed: {0}, {1:s}".format(key, self.imexam_option_funcs[key][0].name)) --> 191 self.imexam_option_funcs[key][0](x, y, self._data) 192 193 def get_options(self):

/opt/anaconda3/envs/python3/lib/python3.6/site-packages/imexam/imexamine.py in aper_phot(self, x, y, data, fig) 566 # The bkg sum with the circular aperture is then 567 # then mean local background tims the circular apreture area. --> 568 aperture_area = apertures.area() 569 annulus_area = annulus_apertures.area() 570

TypeError: 'float' object is not callable

pjpessi avatar Jan 31 '20 13:01 pjpessi

Same issue when running plots.curve_of_growth(j[0],j[1],data,genplot=False)

/opt/anaconda3/envs/python3/lib/python3.6/site-packages/imexam/imexamine.py in curve_of_growth(self, x, y, data, genplot, fig) 1233 aper_flux, annulus_sky, skysub_flux = self._aperture_phot( 1234 centerx, centery, data, radsize=rad, sky_inner=inner, -> 1235 skywidth=width, method="exact", subpixels=subpixels) 1236 radius.append(rad) 1237 if self.curve_of_growth_pars["background"][0]:

/opt/anaconda3/envs/python3/lib/python3.6/site-packages/imexam/imexamine.py in _aperture_phot(self, x, y, data, radsize, sky_inner, skywidth, method, subpixels) 1334 # circular aperture is then 1335 # then mean local background times the circular apreture area. -> 1336 aperture_area = apertures.area() 1337 annulus_area = annulus_apertures.area() 1338

TypeError: 'float' object is not callable

pjpessi avatar Jan 31 '20 13:01 pjpessi

Hi, this problem can be fixed by removing the parentheses after area. i.e., area() -> area

patkel avatar Feb 18 '20 10:02 patkel

This code was fixed in #195 and is on the master branch, but I haven't had a chance to make a formal release, so there isn't a new pip release. I'll try and get to a release soon, but until then you can install straight from the repo:

pip uninstall imexam pip install git+https://github.com/spacetelescope/imexam.git

sosey avatar Feb 18 '20 14:02 sosey

Installing imexam with pip somehow breaks my xpa installation. I wrote the error below. It would be nice to have this version available to install with conda. I guess I will wait until then.


NameError Traceback (most recent call last) ~/anaconda3/envs/py3/lib/python3.6/site-packages/imexam/util.py in list_active_ds9(verbose) 81 try: ---> 82 sessions = xpa.get(b"xpans").decode().strip().split("\n") 83 if ((sessions is None or len(sessions) < 1) and verbose):

NameError: name 'xpa' is not defined

During handling of the above exception, another exception occurred:

NameError Traceback (most recent call last) in ----> 1 viewer=imexam.connect("ds9")

~/anaconda3/envs/py3/lib/python3.6/site-packages/imexam/connect.py in init(self, target, path, viewer, wait_time, quit_window, port) 94 path=path, 95 wait_time=wait_time, ---> 96 quit_ds9_on_del=quit_window) 97 self._event_driven_exam = False # use the imexam loop 98

~/anaconda3/envs/py3/lib/python3.6/site-packages/imexam/ds9_viewer.py in init(self, target, path, wait_time, quit_ds9_on_del) 206 if target: 207 # check to see if the target exists --> 208 active = util.list_active_ds9(False) 209 if target in list(active): 210 self._xpa_name = target

~/anaconda3/envs/py3/lib/python3.6/site-packages/imexam/util.py in list_active_ds9(verbose) 90 for line in sessions: 91 print(line) ---> 92 except (ValueError, xpa.XpaException): 93 print("No active sessions registered") 94

NameError: name 'xpa' is not defined

pjpessi avatar Feb 21 '20 18:02 pjpessi