pynbody / pynbody

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

pickle wrapper needed? #70

Closed apontzen closed 11 years ago

apontzen commented 11 years ago

Original author: stinso...@gmail.com (June 02, 2011 19:47:11)

Pickling like this:

pickle.dump({'rvir':rvir, 'mvir':mvir, 'mgas': np.sum(h[1].gas['mass'].in_units('Msol')), 'mstar': np.sum(h[1].star['mass'].in_units('Msol')), 'mgashot': np.sum(h[1].gas[filt.HighPass('temp',1e5)]['mass'].in_units('Msol')), 'mgascool': np.sum(h[1].gas[filt.LowPass('temp',1e5)]['mass'].in_units('Msol')), 'Jtot':Jtot,'lambda':Jtot / np.sqrt(5.0/3.0mvir3 \ rvir) }, open(simname+'.data','w'))

ends up giving this error when you try to load:

In [1]: d = pickle.load(open('g5664.01024.data'))

IOError Traceback (most recent call last)

/shadow/data1/gss/home/mugs2/g5664/01024/<ipython console> in <module>()

IOError: [Errno 2] No such file or directory: 'g5664.01024.data'

In [2]: d = pickle.load(open('01024/g5664.01024.data'))

In [3]: d Out[3]: --------------------------------------------------------------------------- AttributeError Traceback (most recent call last)

/shadow/data1/gss/home/mugs2/g5664/01024/<ipython console> in <module>()

/usr/lib/python2.6/site-packages/IPython/Prompts.pyc in call(self, arg) 550 551 # and now call a possibly user-defined print mechanism

--> 552 manipulated_val = self.display(arg) 553 554 # user display hooks can change the variable to be stored in

/usr/lib/python2.6/site-packages/IPython/Prompts.pyc in _display(self, arg) 576 return IPython.generics.result_display(arg) 577 except TryNext: --> 578 return self.shell.hooks.result_display(arg) 579 580 # Assign the default display method:

/usr/lib/python2.6/site-packages/IPython/hooks.pyc in call(self, _args, *_kw) 139 #print "prio",prio,"cmd",cmd #dbg

140             try:

--> 141 ret = cmd(_args, *_kw) 142 return ret 143 except ipapi.TryNext, exc:

/usr/lib/python2.6/site-packages/IPython/hooks.pyc in result_display(self, arg) 169 170 if self.rc.pprint: --> 171 out = pformat(arg) 172 if '\n' in out: 173 # So that multi-line strings line up with the left column of

/usr/lib64/python2.6/pprint.pyc in pformat(self, object) 109 def pformat(self, object): 110 sio = _StringIO() --> 111 self._format(object, sio, 0, 0, {}, 0) 112 return sio.getvalue() 113

/usr/lib64/python2.6/pprint.pyc in _format(self, object, stream, indent, allowance, context, level) 127 self._readable = False 128 return --> 129 rep = self._repr(object, context, level - 1) 130 typ = _type(object) 131 sepLines = _len(rep) > (self._width - 1 - indent - allowance)

/usr/lib64/python2.6/pprint.pyc in _repr(self, object, context, level) 221 def _repr(self, object, context, level): 222 repr, readable, recursive = self.format(object, context.copy(), --> 223 self._depth, level) 224 if not readable: 225 self._readable = False

/usr/lib64/python2.6/pprint.pyc in format(self, object, context, maxlevels, level) 233 and whether the object represents a recursive construct. 234 """ --> 235 return _safe_repr(object, context, maxlevels, level) 236 237

/usr/lib64/python2.6/pprint.pyc in _safe_repr(object, context, maxlevels, level) 277 for k, v in sorted(object.items()): 278 krepr, kreadable, krecur = saferepr(k, context, maxlevels, level) --> 279 vrepr, vreadable, vrecur = saferepr(v, context, maxlevels, level) 280 append("%s: %s" % (krepr, vrepr)) 281 readable = readable and kreadable and vreadable

/usr/lib64/python2.6/pprint.pyc in _safe_repr(object, context, maxlevels, level) 318 return format % _commajoin(components), readable, recursive 319 --> 320 rep = repr(object) 321 return rep, (rep and not rep.startswith('<')), False 322

/shadow/data1/gss/home/python/pynbody/array.pyc in repr(self) 335 def repr(self) : 336 x = np.ndarray.repr(self) --> 337 if not hasattr(self.units, "_no_unit") : 338 return x[:-1]+", '"+str(self.units)+"')" 339 else :

/shadow/data1/gss/home/python/pynbody/array.pyc in units(self) 207 return self.base.units 208 else : --> 209 if self._units is None : 210 return _units.no_unit 211 else :

AttributeError: 'SimArray' object has no attribute '_units'

Original issue: http://code.google.com/p/pynbody/issues/detail?id=70

apontzen commented 11 years ago

From andrew.p...@gmail.com on June 16, 2011 18:02:59 This issue should be fixed in revision f88040ac548

Please check

apontzen commented 11 years ago

From stinso...@gmail.com on June 16, 2011 23:31:07 this works for me too. Thank you!