Python 3 integer division results in floats - throws indexing errors in numpy 1.12

Issue #20 resolved
Tanya Urrutia created an issue

Known affected files:

./lib/wavelength_smooth_lib.py, ./lib/spatial_smooth_lib.py, ./tools/median-filter-cube.py

Likely results in crash if numpy >= 1.12 and python 3!

Comments (9)

  1. Christian Herenz repo owner

    Ah - I see. The affected lines I can think of are in wavelength_smooth_lib.py and spatial_smooth_lib.py

    I.e.

    for j in range(num_threads): start = j * (length / num_threads) end = (j + 1) * (length / num_threads) endstr = str(end) if j+1 == num_threads: # the last worker has to do some more work if # mod(spaxels,num_threads) != 0 end=length+1 endstr=str(length) if nans_select != None: spectra_part = data[:,~nans_select][:,start:end] else: spectra_part = data[:,start:end]

    for wavelength_smooth_lib.py, and

    ` for j in range(num_threads): part_fac = length/num_threads start = jpart_fac end = (j+1)part_fac if j+1 == num_threads: end = length+1 # so also the last layer gets convolved! print(str(filename)+': Thread '+str(j+1)+\ ': Working on wavelength layers from #'+str(start+1)+\ ' to #'+str(end))

        cube_part = cube[start:end,:,:]
        kernel_part = kernel[start:end]
    

    `

    for spatial_smooth_lib.py

    From just looking at those, and knowing that numpy does not crash on float indexing, but dooing basically int() internally, I think this might be only a cosmetic bug.

    Or do I miss something?

  2. Christian Herenz repo owner

    Ah OK - as of numpy 1.12 float indexing is not allowed anymore.

    I will change this asap.

  3. Christian Herenz repo owner

    Fix for multiprocess slicing (python 3 float division) - fix #20

    Since division in python 3 results in a float, the routines that slice the cube over several processors in spatial_smooth_lib.py and wavelength_smooth_lib.py create floats as indexes. From numpy >= 1.12 arrays do not chew float indeces.

    → <<cset c5b9cc5d85ac>>

  4. Tanya Urrutia reporter

    Please also change in tools - median-filter-cube.py and any other places this may appear. Thanks for solving this quickly.

  5. Christian Herenz repo owner

    Fix for multiprocess slicing (python 3 float division) - fix #20

    Since division in python 3 results in a float, the routines that slice the cube over several processors in spatial_smooth_lib.py and wavelength_smooth_lib.py create floats as indexes. From numpy >= 1.12 arrays do not chew float indeces.

    → <<cset 3b43087b5105>>

  6. Christian Herenz repo owner
    • changed status to open

    I reopen this and keep it open as long as I don't merge this into the main branch.... The latter I will do when we are sure everything is working.

  7. Log in to comment