NuGrid / NuGridPy

Python tools to access and analyse NuGrid output data (including from MESA)
http://nugrid.github.io/NuGridPy
BSD 3-Clause "New" or "Revised" License
13 stars 10 forks source link

ppn.iso_abund error with python 3 #30

Closed fherwig closed 6 years ago

fherwig commented 7 years ago
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-6-56d35d41535b> in <module>()
      1 ifig=1;close(ifig);figure(ifig)
----> 2 p.iso_abund(60,decayed=True,stable=True)

/usr/local/lib/python3.5/dist-packages/nugridpy/data_plot.py in iso_abund(self, cycle, stable, amass_range, mass_range, ylim, ref, show, log_logic, decayed, color_plot, grid, point_set, include_title, data_provided, thedata, verbose, mov, drawfig, drawax, show_names, label, colour, elemaburtn, mypoint)
   3098             print("isom               isomers and their abundance")
   3099 
-> 3100             self.get(cycle,decayed=decayed)
   3101             if ref is not -1:
   3102                 if type(ref) is list: # reference cycle from other run

/usr/local/lib/python3.5/dist-packages/nugridpy/ppn.py in get(self, attri, fname, numtype, decayed)
    756         if type(attri) is type(1):
    757             print("Calling get method in cycle mode, adding a_iso_to_plot, z.. el.. isotope.. isotope... to instance")
--> 758             self._getcycle(attri,decayed)
    759         elif type(attri) is type("string"):
    760             data=self._getattr(attri,fname,numtype)

/usr/local/lib/python3.5/dist-packages/nugridpy/ppn.py in _getcycle(self, cycle, decayed)
    769 
    770         a_iso_to_plot,z_iso_to_plot,abunds,isotope_to_plot,el_iso_to_plot,isom=\
--> 771             self._process_abundance_vector(a,z,isomers,yps)
    772         self.a_iso_to_plot=a_iso_to_plot
    773         self.isotope_to_plot=isotope_to_plot

/usr/local/lib/python3.5/dist-packages/nugridpy/utils.py in _process_abundance_vector(self, a, z, isomers, yps)
    290                 else:
    291                     isom.append([self.stable_names[int(z[i])]+'-'+str(int(a[i]))+'-'+str(int(isomers[i]-1)),yps[i]])
--> 292         tmp.sort(self.compar)
    293         tmp.sort(self.comparator)
    294         abunds=[]

TypeError: must use keyword argument for key function
fherwig commented 7 years ago

This bug appears only when the method is used with a ppn method, but it does work with mppnp. This bug was found in the PPN plotting tests on issues branch of wendi-example

jerichooconnell commented 6 years ago

The issue in the hyper link is not quite the same as the issue in the above example. The issue in the hyper link is an issue with the data not having a "isotopedatabase.txt" file in the directory.

The python 3 issue is from list.sort() in python3 not having an option for a custom comparison function as it does in python2. The fix was to use this workaround function http://code.activestate.com/recipes/576653-convert-a-cmp-function-to-a-key-function/

fherwig commented 6 years ago

So, this issue can be closed?