pisa
pisa copied to clipboard
Two KDE issues
After realising the issue I had in #254 was just stupidity I went back to trying to KDE the muon distribution for PINGU V36. It works a treat, except for two issues:
- The
kde_histogramdd
code does not support the weights having units so I had to add.magnitude
to that. Otherwise I get the error:
Traceback (most recent call last):
File "pisa/core/pipeline.py", line 687, in <module>
pipeline, outputs = main(return_outputs=True) # pylint: disable=invalid-name
File "pisa/core/pipeline.py", line 598, in main
outputs = pipeline.get_outputs(idx=stop_idx)
File "/Users/steven/IceCube/PISA/pisa/pisa/utils/profiler.py", line 92, in profiled_func
return func(*args, **kwargs)
File "pisa/core/pipeline.py", line 261, in get_outputs
outputs = stage.get_outputs(inputs=inputs)
File "/Users/steven/IceCube/PISA/pisa/pisa/utils/profiler.py", line 92, in profiled_func
return func(*args, **kwargs)
File "/Users/steven/IceCube/PISA/pisa/pisa/core/stage.py", line 575, in get_outputs
outputs = self._compute_outputs(inputs=self.inputs)
File "/Users/steven/IceCube/PISA/pisa/pisa/utils/profiler.py", line 92, in profiled_func
return func(*args, **kwargs)
File "/Users/steven/IceCube/PISA/pisa/pisa/stages/mc/weight.py", line 412, in _compute_outputs
adaptive=True
File "/Users/steven/IceCube/PISA/pisa/pisa/utils/kde_hist.py", line 282, in kde_histogramdd
adaptive=adaptive
File "/Users/steven/IceCube/PISA/pisa/pisa/utils/kde_hist.py", line 80, in get_hist
alpha=alpha, use_cuda=use_cuda
File "/Users/steven/.virtualenv/standard/lib/python2.7/site-packages/kde/cudakde.py", line 12, in __init__
KDE.__init__(self, data, use_cuda, weights=weights, alpha=alpha, method=bw_method)
File "/Users/steven/.virtualenv/standard/lib/python2.7/site-packages/kde/classes.py", line 28, in __init__
self.setCovariance(weights=True)
File "/Users/steven/.virtualenv/standard/lib/python2.7/site-packages/kde/classes.py", line 46, in setCovariance
self.c_inv = np.linalg.inv(self.c)
File "/Users/steven/.virtualenv/standard/lib/python2.7/site-packages/numpy/linalg/linalg.py", line 527, in inv
return wrap(ainv.astype(result_t, copy=False))
File "/Users/steven/.virtualenv/standard/lib/python2.7/site-packages/pint/quantity.py", line 1299, in __array_prepare__
uf, objs, i_out = context
TypeError: 'NoneType' object is not iterable
- It also seems to switch the axes. I'm not entirely sure why this happens but one can easily replicate if they use a non-square binning for
coszen
andenergy
i.e. not the same number of bins of each. When I did 40x40x2 I got this raw distribution:
which is then KDE'd to:
which is clearly wrong. Adding in kde_hist = np.moveaxis(kde_hist, -2, -1)
just after it is constructed yields:
which seems much more correct. I tried looking in to it but couldn't really figure out why this is happening, so I thought someone who's looked in to the KDE stuff a bit more might have a good idea.