Open godot11 opened 2 years ago
FWIW, in general the usage of pylab
is discouraged as it's merely a convenience alias for numpy, scipy and matplotlib modules; it's better to directly reference the corresponding libraries. In XMDYNPhotonMatterAnalysis
there's oy two location where it's used and both use pylab.find
: the line above, and in XMDYNPhotonMatterAnalysis.load_sample
:
sample['selZ'][sel_Z] = pylab.find(sel_Z == sample['Z'])
so it should be easy to remove it.
The following seems to work, but I'm not sure it is conceptually equivalent to pylab.find:
xsnp['q'] = numpy.array([xsnp['ff'][(numpy.array(xsnp['T'])==numpy.array(x)), 0] for x in xsnp['xyz']]).reshape(N,)
The following seems to work, but I'm not sure it is conceptually equivalent to pylab.find:
xsnp['q'] = numpy.array([xsnp['ff'][(numpy.array(xsnp['T'])==numpy.array(x)), 0] for x in xsnp['xyz']]).reshape(N,)
This solution looks fine to me. It may be simplified as:
xsnp['q'] = numpy.array([xsnp['ff'][xsnp['T']==x][0] for x in xsnp['xyz']]).reshape(N,)
Could you @godot11 test if it works?
@CFGrote What do you think?
This solution looks fine to me. It may be simplified as:
xsnp['q'] = numpy.array([xsnp['ff'][xsnp['T']==x][0] for x in xsnp['xyz']]).reshape(N,)
Tested but doesn't work as the arrays in the test are not Numpy arrays.
@JunCEEE Seems I was wrong. The above fix made the code working by all means, but the results for some charges don't make too much sense.
It seems pylab.find may not have been what I thought it was, a "numpyizer" wrapper around np.array(x) == np.array(y)
. Probably it was matplotlib.mlab.find
which is simply
import numpy as np
def find(condition):
res, = np.nonzero(np.ravel(condition))
return res
(source), and was removed in matplotlib versions >= 3.1. Where could I put the above snippet though?
I think to just put it here is enough: https://github.com/PaNOSC-ViNYL/SimEx/blob/master/Sources/python/SimEx/Analysis/XMDYNPhotonMatterAnalysis.py
In
Analysis.XMDYNPhotonMatterAnalysis.XMDYNPhotonMatterAnalysis.load_snapshot()
, there is the following line:pylab.find
seems no longer availble in thepylab
namespace and this line results in anI couldn't find a reference to see when it was removed, but my environment corresponds to
environment.yml
.