pynbody / pynbody

N-body and hydro analysis tools for Python 3. (Older versions support Python 2.)
http://pynbody.github.io/pynbody/index.html
166 stars 79 forks source link

problem with RAMSES util - convert_to_tipsy_fullbox(), python 3 #319

Closed earnric closed 8 years ago

earnric commented 8 years ago

When trying to convert a RAMSES output file via

pynbody.analysis.ramses_util.convert_to_tipsy_fullbox('output_00001') you get the following error.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-fddb6291a038> in <module>()
----> 1 pynbody.analysis.ramses_util.convert_to_tipsy_fullbox('output_00016') # will convert the whole output

/Users/earnric/anaconda/lib/python3.4/site-packages/pynbody/analysis/ramses_util.py in convert_to_tipsy_fullbox(output, write_param)
    297 
    298     # get the appropriate tform
--> 299     get_tform(s)
    300     s.g['metals'] = s.g['metal']
    301     s['pos'].convert_units(lenunit)

/Users/earnric/anaconda/lib/python3.4/site-packages/pynbody/analysis/ramses_util.py in get_tform(sim, part2birth_path)
    454         if n > 0:
    455             #n /= 8 # This is causing an err with python 3... recommended fix below
--> 456             np.divide(n, 8, out=n)
    457             ages = fromfile(f, 'd', n)
    458             new = np.where(ages > 0)[0]

TypeError: ufunc 'true_divide' output (typecode 'd') could not be coerced to provided output parameter (typecode 'i') according to the casting rule ''same_kind''
apontzen commented 8 years ago

That seems to be something that you changed yourself at some point (https://github.com/pynbody/pynbody/commit/2d94702c09e511fc2652d2845b5f8e88d96d6f55) - perhaps you can take another look at why it's failing again?

earnric commented 8 years ago

Yea... I thought I fixed this some time ago... it works under py2.7. Let me try to figure out why the fix for py3 doesn't work any longer!

earnric commented 8 years ago

@apontzen Looks like this is an (desired) integer divide right? If so, there are some extra parameters I need to put on the np.divide to for it to work with the numpy array 'n' (that make it compatible with python 3).

https://github.com/numpy/numpy/issues/6464

earnric commented 8 years ago

Confirmed that we want an integer divide for this operation. Also confirmed that we can use:

n //= 8 Works in both py27 and py30. I can create a pull request.