Skip to content
Snippets Groups Projects
Commit 9172b544 authored by Laurent Mercadier's avatar Laurent Mercadier
Browse files

Add counts variable when aggregating data

parent 19f1c6e6
No related branches found
No related tags found
1 merge request!274Up4256
from functools import lru_cache
import xarray as xr
import numpy as np
import matplotlib.pyplot as plt
......@@ -566,7 +567,8 @@ class hRIXS:
spectrum=lambda x, dim: x.sum(dim=dim),
dbl_spectrum=lambda x, dim: x.sum(dim=dim),
total_hits=lambda x, dim: x.sum(dim=dim),
dbl_hits=lambda x, dim: x.sum(dim=dim)
dbl_hits=lambda x, dim: x.sum(dim=dim),
counts=lambda x, dim: x.sum(dim=dim)
)
def aggregator(self, da, dim):
......@@ -594,6 +596,7 @@ class hRIXS:
agg = groups.map(h.aggregate) # sum corresponding spectra
agg.spectrum[0, :].plot() # plot the spectrum for first value
"""
ds['counts'] = xr.ones_like(ds["trainId"])
ret = ds.map(self.aggregator, dim=dim)
ret = ret.drop_vars([n for n in ret if n not in self.aggregators])
return ret
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment