Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
Merge pull request #31 from LovelyBuggies/master
Browse files Browse the repository at this point in the history
Solve keyerror in #29
  • Loading branch information
jpivarski authored Mar 28, 2020
2 parents 2a57c6c + 76537fd commit d5109d6
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 20 deletions.
15 changes: 14 additions & 1 deletion python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ After you git-clone this GitHub repository and ensure that `numpy` is installed,
```bash
pip install "flatbuffers>=1.8.0" # for the flatbuffers runtime (with Numpy)
cd python # only implementation so far is in Python
python setup.py install # to use it outside of this directory
python setup.py install # to use it outside of this directory, Python2 is not supported right now
```

Now you should be able to `import aghast` or `from aghast import *` in Python.
Expand All @@ -51,6 +51,19 @@ If you need to change `flatbuffers/aghast.fbs`, you'll need to additionally:

Every time you change `flatbuffers/aghast.fbs`, re-run `./generate_flatbuffers.py`.

If you want to use some specific packages on Anaconda channel, the recommended way is:

```bash
# add the packages you need to "environment-test.yml" or "requirements-test.txt"
conda env create -f environment-test.yml -n aghast # create (or update) your aghast conda environment
conda activate aghast # activate your aghast environment
cd python # only implementation so far is in Python
python setup.py install # to use it outside of this directory, Python2 is not supported right now
python -m ipykernel install --name aghast # install your jupyter kernel "aghast"
```

Now you should be able to `import aghast` or `from aghast import *` in your notebooks with the kernel "aghast".

## Documentation

Full specification:
Expand Down
2 changes: 1 addition & 1 deletion python/aghast/_connect/_root.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def to_root(obj, name):
sumw = obj.counts[tuple(slc)]
if isinstance(sumw, dict):
sumw, sumw2 = sumw["sumw"], sumw["sumw2"]
sumw2 = numpy.array(sumw2, dtype=numpy.float64, copy=False)
sumw2 = numpy.array(sumw2, dtype=numpy.float64, copy=False) if sumw2 is not None else None
else:
sumw2 = None

Expand Down
34 changes: 16 additions & 18 deletions python/aghast/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -5033,8 +5033,8 @@ def _fromflatbuffers(cls, fb):

def _toflatbuffers(self, builder):
sumw = self.sumw._toflatbuffers(builder)
sumw2 = None if self.sumw2 is None else self.sumw2._toflatbuffers(builder)
unweighted = None if self.unweighted is None else self.unweighted._toflatbuffers(builder)
sumw2 = self.sumw2._toflatbuffers(builder) if self.sumw2 is not None else None
unweighted = self.unweighted._toflatbuffers(builder) if self.unweighted is not None else None

aghast.aghast_generated.WeightedCounts.WeightedCountsStart(builder)
aghast.aghast_generated.WeightedCounts.WeightedCountsAddSumwType(builder, _InterpretedBuffer_invlookup[type(self.sumw)])
Expand All @@ -5050,27 +5050,29 @@ def _dump(self, indent, width, end):
args = ["sumw={0}".format(_dumpeq(self.sumw._dump(indent + " ", width, end), indent, end))]
if self.sumw2 is not None:
args.append("sumw2={0}".format(_dumpeq(self.sumw2._dump(indent + " ", width, end), indent, end)))
else:
args.append("sumw2=None".format(_dumpeq(self.sumw2._dump(indent + " ", width, end), indent, end)))
if self.unweighted is not None:
args.append("unweighted={0}".format(_dumpeq(self.unweighted._dump(indent + " ", width, end), indent, end)))
else:
args.append("unweighted=None".format(_dumpeq(self.unweighted._dump(indent + " ", width, end), indent, end)))
return _dumpline(self, args, indent, width, end)

def _reindex(self, oldshape, indexes):
out = {"sumw": self.sumw._reindex(oldshape, indexes)}
if self.sumw2 is not None:
out["sumw2"] = self.sumw2._reindex(oldshape, indexes)
if self.unweighted is not None:
out["unweighted"] = self.unweighted._reindex(oldshape, indexes)
out["sumw2"] = self.sumw2._reindex(oldshape, indexes) if self.sumw2 is not None else None
out["unweighted"] = self.unweighted._reindex(oldshape, indexes) if self.unweighted is not None else None
return out

def _rebin(self, oldshape, pairs):
return WeightedCounts(self.sumw._rebin(oldshape, pairs),
None if self.sumw2 is None else self.sumw2._rebin(oldshape, pairs),
None if self.unweighted is None else self.unweighted._rebin(oldshape, pairs))
self.sumw2._rebin(oldshape, pairs) if self.sumw2 is not None else None,
self.unweighted._rebin(oldshape, pairs) if self.unweighted is not None else None)

def _remap(self, newshape, selfmap):
return WeightedCounts(self.sumw._remap(newshape, selfmap),
None if self.sumw2 is None else self.sumw2._remap(newshape, selfmap),
None if self.unweighted is None else self.unweighted._remap(newshape, selfmap))
self.sumw2._remap(newshape, selfmap) if self.sumw2 is not None else None,
self.unweighted._remap(newshape, selfmap) if self.unweighted is not None else None)

def _add(self, other, noclobber):
assert isinstance(other, WeightedCounts)
Expand All @@ -5092,19 +5094,15 @@ def _add(self, other, noclobber):
@property
def flatarray(self):
out = {"sumw": self.sumw.flatarray}
if self.sumw2 is not None:
out["sumw2"] = self.sumw2.flatarray
if self.unweighted is not None:
out["unweighted"] = self.unweighted.flatarray
out["sumw2"] = self.sumw2.flatarray if self.sumw2 is not None else None
out["unweighted"] = self.unweighted.flatarray if self.unweighted else None
return out

@property
def array(self):
out = {"sumw": self.sumw.array}
if self.sumw2 is not None:
out["sumw2"] = self.sumw2.array
if self.unweighted is not None:
out["unweighted"] = self.unweighted.array
out["sumw2"] = self.sumw2.array if self.sumw2 is not None else None
out["unweighted"] = self.unweighted.array if self.unweighted else None
return out

################################################# Parameter
Expand Down
8 changes: 8 additions & 0 deletions python/environment-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: aghast
channels:
- conda-forge
dependencies:
- pip>=18
- root
- pip:
- -r requirements-test.txt
8 changes: 8 additions & 0 deletions python/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
jupyterlab>=1.2
matplotlib>=3.1
pytest>=5
setuptools>=42
setuptools_scm>=3.4
flatbuffers>=1.8.0
uproot>=3.11.3
uproot-methods>=0.7.3

0 comments on commit d5109d6

Please sign in to comment.