vortex-exoplanet / VIP

VIP is a python package/library for angular, reference star and spectral differential imaging for exoplanet/disk detection through high-contrast imaging.
http://vip.readthedocs.io/
MIT License
70 stars 59 forks source link

v0.9.7 -> 0.9.8: TypeError: `Size` must be integer, using vip_hci.metrics.contrast_curve() #347

Closed ChrisDelaX closed 5 years ago

ChrisDelaX commented 5 years ago

v0.9.7 works great for me. Then, for some reason I upgraded to v0.9.8 and got this error. No big deal for me, I just downgraded back to v0.9.7 for now.

Here is my terminal output:

cdelacroix@admin:~/HEEPS/heeps$ pip show vip_hci | grep Version
Version: 0.9.7
cdelacroix@admin:~/HEEPS/heeps$ python ADI.py
/home/cdelacroix/anaconda3/lib/python3.7/site-packages/scipy/ndimage/interpolation.py:583: UserWarning: From scipy 0.13.0, the output shape of zoom() is calculated with round() instead of int() - for these inputs the size of the returned array has changed.
  "the returned array has changed.", UserWarning)
Cube successfully rescaled
New shape: (15, 488, 488)
--------------------------------------------------------------------------------
Starting time: 2018-12-03 11:48:55
--------------------------------------------------------------------------------
ALGO : median_sub, FWHM = 3.7096333846461276, # BRANCHES = 1, SIGMA = 5, STARPHOT = 226725013656.92407
--------------------------------------------------------------------------------
Finished the throughput calculation
Running time:  0:00:09.687107
--------------------------------------------------------------------------------

Works fine. Then I upgrade to v0.9.8 and it's bugged:

cdelacroix@admin:~/HEEPS/heeps$ pip install 'vip_hci>=0.9.8'
Collecting vip_hci>=0.9.8
  Using cached https://files.pythonhosted.org/packages/01/b0/8b0113d74031ace28eebf89b32381108370d1771561700df60e7b188cdcc/vip_hci-0.9.8-py2.py3-none-any.whl
Requirement already satisfied: pyprind in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from vip_hci>=0.9.8) (2.11.2)
Requirement already satisfied: scikit-learn>=0.17 in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from vip_hci>=0.9.8) (0.19.2)
Requirement already satisfied: matplotlib~=2.2 in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from vip_hci>=0.9.8) (2.2.3)
Requirement already satisfied: numpy>=1.8 in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from vip_hci>=0.9.8) (1.15.1)
Requirement already satisfied: nestle in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from vip_hci>=0.9.8) (0.2.0)
Requirement already satisfied: corner>=1.0.2 in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from vip_hci>=0.9.8) (2.0.1)
Requirement already satisfied: opencv-python in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from vip_hci>=0.9.8) (3.4.3.18)
Requirement already satisfied: astropy>=2.0 in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from vip_hci>=0.9.8) (3.0.4)
Requirement already satisfied: scikit-image>=0.11 in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from vip_hci>=0.9.8) (0.14.0)
Requirement already satisfied: munch in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from vip_hci>=0.9.8) (2.3.2)
Requirement already satisfied: photutils>=0.2.2 in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from vip_hci>=0.9.8) (0.5)
Requirement already satisfied: pandas>=0.18 in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from vip_hci>=0.9.8) (0.23.4)
Requirement already satisfied: psutil in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from vip_hci>=0.9.8) (5.4.7)
Requirement already satisfied: scipy>=1.0.0 in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from vip_hci>=0.9.8) (1.1.0)
Requirement already satisfied: emcee>=2.1 in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from vip_hci>=0.9.8) (2.2.1)
Requirement already satisfied: cycler>=0.10 in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from matplotlib~=2.2->vip_hci>=0.9.8) (0.10.0)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from matplotlib~=2.2->vip_hci>=0.9.8) (2.2.0)
Requirement already satisfied: python-dateutil>=2.1 in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from matplotlib~=2.2->vip_hci>=0.9.8) (2.7.3)
Requirement already satisfied: pytz in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from matplotlib~=2.2->vip_hci>=0.9.8) (2018.5)
Requirement already satisfied: six>=1.10 in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from matplotlib~=2.2->vip_hci>=0.9.8) (1.11.0)
Requirement already satisfied: kiwisolver>=1.0.1 in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from matplotlib~=2.2->vip_hci>=0.9.8) (1.0.1)
Requirement already satisfied: networkx>=1.8 in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from scikit-image>=0.11->vip_hci>=0.9.8) (2.1)
Requirement already satisfied: pillow>=4.3.0 in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from scikit-image>=0.11->vip_hci>=0.9.8) (5.2.0)
Requirement already satisfied: PyWavelets>=0.4.0 in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from scikit-image>=0.11->vip_hci>=0.9.8) (1.0.0)
Requirement already satisfied: dask[array]>=0.9.0 in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from scikit-image>=0.11->vip_hci>=0.9.8) (0.19.1)
Requirement already satisfied: cloudpickle>=0.2.1 in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from scikit-image>=0.11->vip_hci>=0.9.8) (0.5.5)
Requirement already satisfied: setuptools in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from kiwisolver>=1.0.1->matplotlib~=2.2->vip_hci>=0.9.8) (40.2.0)
Requirement already satisfied: decorator>=4.1.0 in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from networkx>=1.8->scikit-image>=0.11->vip_hci>=0.9.8) (4.3.0)
Requirement already satisfied: toolz>=0.7.3; extra == "array" in /home/cdelacroix/anaconda3/lib/python3.7/site-packages (from dask[array]>=0.9.0->scikit-image>=0.11->vip_hci>=0.9.8) (0.9.0)
Installing collected packages: vip-hci
  Found existing installation: vip-hci 0.9.7
    Uninstalling vip-hci-0.9.7:
      Successfully uninstalled vip-hci-0.9.7
Successfully installed vip-hci-0.9.8
cdelacroix@admin:~/HEEPS/heeps$ python ADI.py
/home/cdelacroix/anaconda3/lib/python3.7/site-packages/scipy/ndimage/interpolation.py:583: UserWarning: From scipy 0.13.0, the output shape of zoom() is calculated with round() instead of int() - for these inputs the size of the returned array has changed.
  "the returned array has changed.", UserWarning)
Cube successfully rescaled
New shape: (15, 488, 488)
--------------------------------------------------------------------------------
Starting time: 2018-12-03 11:50:54
--------------------------------------------------------------------------------
ALGO : median_sub, FWHM = 3.7096333846461276, # BRANCHES = 1, SIGMA = 5, STARPHOT = 226725013656.92407
--------------------------------------------------------------------------------
Traceback (most recent call last):
  File "ADI.py", line 100, in <module>
    vip_hci.medsub.median_sub, nbranch=1, sigma=5, debug=False, plot=False)
  File "/home/cdelacroix/anaconda3/lib/python3.7/site-packages/vip_hci/metrics/contrcurve.py", line 184, in contrast_curve
    **algo_dict)
  File "/home/cdelacroix/anaconda3/lib/python3.7/site-packages/vip_hci/metrics/contrcurve.py", line 554, in throughput
    psf_template.shape[1]))
  File "/home/cdelacroix/anaconda3/lib/python3.7/site-packages/vip_hci/metrics/fakecomp.py", line 417, in normalize_psf
    verbose)
  File "/home/cdelacroix/anaconda3/lib/python3.7/site-packages/vip_hci/metrics/fakecomp.py", line 331, in psf_norm_2d
    psfs = frame_crop(array, size, force=True, verbose=False)
  File "/home/cdelacroix/anaconda3/lib/python3.7/site-packages/vip_hci/preproc/cosmetics.py", line 121, in frame_crop
    verbose=verbose)
  File "/home/cdelacroix/anaconda3/lib/python3.7/site-packages/vip_hci/var/shapes.py", line 221, in get_square
    raise TypeError('`Size` must be integer')
TypeError: `Size` must be integer
cdelacroix@admin:~/HEEPS/heeps$ pip show vip_hci | grep Version
Version: 0.9.8
r4lv commented 5 years ago

Version 0.9.8 introduced these two lines in get_square: https://github.com/vortex-exoplanet/VIP/blob/65d5c23cf0c39e69ab51922a33ac8d4f0ceb6a9b/vip_hci/var/shapes.py#L249-L250 which caused the TypeError.

The logic did also work correctly in 0.9.7, because get_square applies int(...) to all pixel coordinates, so 0.9.7 should be fine to use too (in this case).

carlos-gg commented 5 years ago

@ChrisDelaX I'm glad to hear VIP is working well for you. It seems @r4lv fixed this problem in #348 by calling normalize_psf with an integer new size (for cropping the template PSF inside the CC computation). Let us know if you find other problems.

r4lv commented 5 years ago

@ChrisDelaX Maybe you would like to switch to the development version of VIP, by installing it with

pip install git+https://github.com/vortex-exoplanet/VIP
ChrisDelaX commented 5 years ago

Fantastic, thank you.

On Mon, Dec 3, 2018 at 2:41 PM RFarkas notifications@github.com wrote:

@ChrisDelaX https://github.com/ChrisDelaX Maybe you would like to switch to the development version of VIP, by installing it with

pip install git+https://github.com/vortex-exoplanet/VIP

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/vortex-exoplanet/VIP/issues/347#issuecomment-443713584, or mute the thread https://github.com/notifications/unsubscribe-auth/AMUG7lAHRmSIDReAF3tCvSWQwTRMzCjPks5u1SodgaJpZM4Y-WST .

ChrisDelaX commented 5 years ago

So, I just installed the dev version following your link, and now I am getting the 'Size must be an integer' TypeError again.

On Mon, Dec 3, 2018 at 3:49 PM Christian Delacroix < christian.delacroix@gmail.com> wrote:

Fantastic, thank you.

On Mon, Dec 3, 2018 at 2:41 PM RFarkas notifications@github.com wrote:

@ChrisDelaX https://github.com/ChrisDelaX Maybe you would like to switch to the development version of VIP, by installing it with

pip install git+https://github.com/vortex-exoplanet/VIP

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/vortex-exoplanet/VIP/issues/347#issuecomment-443713584, or mute the thread https://github.com/notifications/unsubscribe-auth/AMUG7lAHRmSIDReAF3tCvSWQwTRMzCjPks5u1SodgaJpZM4Y-WST .

ChrisDelaX commented 5 years ago

Here is a simple test, the other inputs are similar values to the ones I am using. The images (arrays) have random pixel value, but the same array shapes as in my study. If you want, I can even send you real data.

In [18]: cc_adi = vip_hci.metrics.contrast_curve(np.random.rand(15,489,489),np.random.rand(15),np.random.rand(39,39),4.26, 5e-3, 1e11, vip_hci.medsub.median_sub, nbranch=1, sigma=5, debug=False, plot=False)

--------------------------------------------------------------------------------
Starting time: 2018-12-03 16:13:33
--------------------------------------------------------------------------------
ALGO : median_sub, FWHM = 4.26, # BRANCHES = 1, SIGMA = 5, STARPHOT = 100000000000.0
--------------------------------------------------------------------------------
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-18-21732e4a925b> in <module>()
----> 1 cc_adi = vip_hci.metrics.contrast_curve(np.random.rand(15,489,489),np.random.rand(15),np.random.rand(39,39),4.26, 5e-3, 1e11, vip_hci.medsub.median_sub, nbranch=1, sigma=5, debug=False, plot=False)

~/anaconda3/lib/python3.7/site-packages/vip_hci/metrics/contrcurve.py in contrast_curve(cube, angle_list, psf_template, fwhm, pxscale, starphot, algo, sigma, nbranch, theta, inner_rad, wedge, fc_snr, student, transmission, smooth, interp_order, plot, dpi, imlib, debug, verbose, full_output, save_plot, object_name, frame_size, fix_y_lim, figsize, **algo_dict)
    182                             wedge=wedge, fc_snr=fc_snr, full_output=True,
    183                             algo=algo, imlib=imlib, verbose=verbose_thru,
--> 184                             **algo_dict)
    185     vector_radd = res_throug[2]
    186     if res_throug[0].shape[0] > 1:

~/anaconda3/lib/python3.7/site-packages/vip_hci/metrics/contrcurve.py in throughput(cube, angle_list, psf_template, fwhm, pxscale, algo, nbranch, theta, inner_rad, fc_rad_sep, wedge, fc_snr, full_output, imlib, interpolation, verbose, **algo_dict)
    552         psf_template = normalize_psf(psf_template, fwhm=fwhm,
    553                                      size=min(new_psf_size,
--> 554                                               psf_template.shape[1]))
    555
    556         # Initialize the fake companions

~/anaconda3/lib/python3.7/site-packages/vip_hci/metrics/fakecomp.py in normalize_psf(array, fwhm, size, threshold, mask_core, model, imlib, interpolation, force_odd, full_output, verbose)
    415
    416         res = psf_norm_2d(array, fwhm, size, threshold, mask_core, full_output,
--> 417                           verbose)
    418         return res
    419

~/anaconda3/lib/python3.7/site-packages/vip_hci/metrics/fakecomp.py in psf_norm_2d(array, fwhm, size, threshold, mask_core, full_output, verbose)
    329         if size is not None:
    330             if size < array.shape[0]:
--> 331                 psfs = frame_crop(array, size, force=True, verbose=False)
    332             else:
    333                 psfs = array.copy()

~/anaconda3/lib/python3.7/site-packages/vip_hci/preproc/cosmetics.py in frame_crop(array, size, cenxy, force, verbose)
    119         cenx, ceny = cenxy
    120     array_view = get_square(array, size, ceny, cenx, force=force,
--> 121                             verbose=verbose)
    122
    123     if verbose:

~/anaconda3/lib/python3.7/site-packages/vip_hci/var/shapes.py in get_square(array, size, y, x, position, force, verbose)
    219         raise TypeError('Input array is not a 2d array.')
    220     if not isinstance(size, int):
--> 221         raise TypeError('`Size` must be integer')
    222     if size >= size_init:  # assuming square frames
    223         msg = "`Size` is equal to or bigger than the initial frame size"

TypeError: `Size` must be integer

In [19]: vip_hci.__version__
Out[19]: '0.9.8'
r4lv commented 5 years ago

@ChrisDelaX, sorry, I cannot reproduce the Error with the code you provided. I run the code with this binder1 which uses the latest version (commit 1a4293a from 2 hours ago). — I guess your pip used a cached version of VIP, instead of downloading the latest commit from the master branch?

Maybe re-installing VIP helps:

pip install --upgrade --no-deps --force-reinstall git+https://github.com/vortex-exoplanet/VIP

1 In case you are not familiar with jupyter, you could create a new notebook using the newPython 3 and run your code there. The notebook interface is similar to the ipython which you seem to use 😊