Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data cube with one exposure (i.e. cube.shape[0]==1) causes indexing or division error. #82

Open
vandalt opened this issue Nov 8, 2021 · 4 comments

Comments

@vandalt
Copy link
Contributor

vandalt commented Nov 8, 2021

When using a data cube with only one exposure (i.e. cube.shape[0]==1), I encountered two errors in extract_bs():

  • An IndexError if clipping had been done before and rejected the only frame in in the cube and extract_bs() had an empty input.

    Error message
      bs = amical.extract_bs(
      File "/home/vandal/projects/amical/amical/mf_pipeline/bispect.py", line 1138, in extract_bs
        ft_arr, n_ps, npix = _construct_ft_arr(cube)
      File "/home/vandal/projects/amical/amical/mf_pipeline/bispect.py", line 227, in _construct_ft_arr
        n_pix = cube.shape[1]
      IndexError: tuple index out of range
    
  • A ZeroDivisionError if no clipping was done and extract_bs() received a cube with one frame.

    Error message
     bs = amical.extract_bs(
     File "/home/vandal/projects/amical/amical/mf_pipeline/bispect.py", line 1242, in extract_bs
         v2_quantities = _compute_v2_quantities(v2_arr_unbiased, bias_arr, n_blocks)
     File "/home/vandal/projects/amical/amical/mf_pipeline/bispect.py", line 537, in _compute_v2_quantities
         ind2 = (k + 1) * n_ps // (n_blocks - 1)
     ZeroDivisionError: integer division or modulo by zero
    

As discussed with @DrSoulain, this should not occur often and is currently not supported. It might still be worth adding an error to catch these two cases in extract_bs and raise a more informative error message to clarify what is happening.

@neutrinoceros
Copy link
Collaborator

can you share a self-contained reproducible example ?

@vandalt
Copy link
Contributor Author

vandalt commented Nov 9, 2021

Yes! extract_bs() needs a file, so I'm using one of the example files in doc/NRM_DATA. This works on my machine from the amical/doc directory:

from pathlib import Path
from astropy.io import fits
from amical import extract_bs
from amical.data_processing import select_data

eg_file = Path("NRM_DATA/t_binary_s=147.7mas_mag=6.0_dm=6.0_posang=46.6__F430M_81_flat_x11__00.fits")

data = fits.getdata(eg_file)[:1]

# Uncomment this line to get the IndexError in extract_bs
# data = select_data(data, clip=True, display=False)

extract_bs(data, eg_file, "g7")

@vandalt
Copy link
Contributor Author

vandalt commented Nov 9, 2021

Would this be a good solution ?

  • select_data shows a warning if it clears a data cube of all its exposures (to let users know, even in cases where nothing is done with the cube after. An empty cube is probably not desirable, but not critical in the sense that users can just check for this and skip empty cubes
  • extract_bs() check both cases (length 1 or empty) and raises and error. The two cases are critical for extraction, and result in error in private functions called by extract_bs()

@neutrinoceros
Copy link
Collaborator

Sorry for the delay. Yes, I believe that it would be a great way to handle things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants