From c91221f4e774519167306674d88d688695f2c3d0 Mon Sep 17 00:00:00 2001 From: Sarah Jane Grimm Date: Thu, 11 Apr 2024 15:41:00 +0200 Subject: [PATCH 1/6] smilei: ignore latest_IDs dataset --- postpic/datareader/smileih5.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/postpic/datareader/smileih5.py b/postpic/datareader/smileih5.py index 99a11f2..7c22079 100644 --- a/postpic/datareader/smileih5.py +++ b/postpic/datareader/smileih5.py @@ -51,7 +51,9 @@ def _generateh5indexfile(indexfile, fnames): indexfile = os.path.join(dirname, indexfile) def visitf(key): - # key is a string + # key is a strings + if key.endswith('latest_IDs'): + return # only link if key points to a dataset. Do not link groups if isinstance(hf[key], h5py._hl.dataset.Dataset): ih[key] = h5py.ExternalLink(fname, key) From 7bac1dfc6d2902e4c063130013d4c3658044bdea Mon Sep 17 00:00:00 2001 From: Sarah Jane Grimm Date: Thu, 11 Apr 2024 15:41:33 +0200 Subject: [PATCH 2/6] smilei uses key weight instead of weighting. update --- postpic/datareader/smileih5.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/postpic/datareader/smileih5.py b/postpic/datareader/smileih5.py index 7c22079..269f845 100644 --- a/postpic/datareader/smileih5.py +++ b/postpic/datareader/smileih5.py @@ -308,6 +308,36 @@ def _simgridkeys(self): 'Bx', 'By', 'Bz', 'Br', 'Bl', 'Bt', 'Jx', 'Jy', 'Jz', 'Jr', 'Jl', 'Jt', 'Rho'] + def getSpecies(self, species, attrib): + """ + Returns one of the attributes out of (x,y,z,px,py,pz,weight,ID,mass,charge) of + this particle species. + """ + attribid = helper.attribidentify[attrib] + options = {9: 'particles/{}/weight', + 0: 'particles/{}/position/x', + 1: 'particles/{}/position/y', + 2: 'particles/{}/position/z', + 3: 'particles/{}/momentum/x', + 4: 'particles/{}/momentum/y', + 5: 'particles/{}/momentum/z', + 10: 'particles/{}/id', + 11: 'particles/{}/mass', + 12: 'particles/{}/charge'} + optionsoffset = {0: 'particles/{}/positionOffset/x', + 1: 'particles/{}/positionOffset/y', + 2: 'particles/{}/positionOffset/z'} + key = options[attribid] + offsetkey = optionsoffset.get(attribid) + try: + data = self.data(key.format(species)) + if offsetkey is not None: + data += self.data(offsetkey.format(species)) + ret = np.asarray(data, dtype=np.float64) + except IndexError: + raise KeyError + return ret + def getderived(self): ''' return all other fields dumped, except E and B. From 148b7f5452eb9d9e744a702bce75ddcaeb6332db Mon Sep 17 00:00:00 2001 From: Sarah Jane Grimm Date: Thu, 11 Apr 2024 15:42:51 +0200 Subject: [PATCH 3/6] smilei: fix path in _generateh5indexfile --- postpic/datareader/smileih5.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/postpic/datareader/smileih5.py b/postpic/datareader/smileih5.py index 269f845..8466eda 100644 --- a/postpic/datareader/smileih5.py +++ b/postpic/datareader/smileih5.py @@ -47,9 +47,6 @@ def _generateh5indexfile(indexfile, fnames): # indexfile already exists. do not recreate return - dirname = os.path.dirname(fnames[0]) - indexfile = os.path.join(dirname, indexfile) - def visitf(key): # key is a strings if key.endswith('latest_IDs'): From f214aa027c389044dba6202303b7a8f3b043cdf7 Mon Sep 17 00:00:00 2001 From: Sarah Jane Grimm Date: Thu, 11 Apr 2024 16:27:33 +0200 Subject: [PATCH 4/6] smilei: also link single scalars saved in a hdf5 group --- postpic/datareader/smileih5.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/postpic/datareader/smileih5.py b/postpic/datareader/smileih5.py index 8466eda..1c0d7a3 100644 --- a/postpic/datareader/smileih5.py +++ b/postpic/datareader/smileih5.py @@ -48,11 +48,13 @@ def _generateh5indexfile(indexfile, fnames): return def visitf(key): - # key is a strings + # key is a string if key.endswith('latest_IDs'): return - # only link if key points to a dataset. Do not link groups - if isinstance(hf[key], h5py._hl.dataset.Dataset): + # only link if key points to a dataset. Generally do not link groups. + # However single scalars (identified by ´value in hf[key].attrs´) + # maybe a group and must be linked as well. + if isinstance(hf[key], h5py._hl.dataset.Dataset) or "value" in hf[key].attrs: ih[key] = h5py.ExternalLink(fname, key) with h5py.File(indexfile, 'w') as ih: From 35c71a42094c9dfac0f7794359985a001e13e5c0 Mon Sep 17 00:00:00 2001 From: Sarah Jane Grimm Date: Thu, 11 Apr 2024 17:37:23 +0200 Subject: [PATCH 5/6] smilei: copy all attrs of groups --- postpic/datareader/smileih5.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/postpic/datareader/smileih5.py b/postpic/datareader/smileih5.py index 1c0d7a3..d3aef4f 100644 --- a/postpic/datareader/smileih5.py +++ b/postpic/datareader/smileih5.py @@ -56,6 +56,10 @@ def visitf(key): # maybe a group and must be linked as well. if isinstance(hf[key], h5py._hl.dataset.Dataset) or "value" in hf[key].attrs: ih[key] = h5py.ExternalLink(fname, key) + elif isinstance(hf[key], h5py._hl.group.Group) and key not in ih: + ih.create_group(key) + for attr in hf[key].attrs: + ih[key].attrs[attr] = hf[key].attrs[attr] with h5py.File(indexfile, 'w') as ih: for fname in fnames: From 8545d4cb05cf54aec6f987969253eaa17e642ec9 Mon Sep 17 00:00:00 2001 From: Sarah Jane Grimm Date: Thu, 11 Apr 2024 20:01:28 +0200 Subject: [PATCH 6/6] smilei: accessible dumpkeys --- postpic/datareader/smileih5.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/postpic/datareader/smileih5.py b/postpic/datareader/smileih5.py index d3aef4f..e0a4a7c 100644 --- a/postpic/datareader/smileih5.py +++ b/postpic/datareader/smileih5.py @@ -381,7 +381,7 @@ def __init__(self, h5file, dumpreadercls=SmileiReader, **kwargs): indexfile = _getindexfile(h5file) self._h5 = h5py.File(indexfile, 'r') with h5py.File(indexfile, 'r') as h5: - self._dumpkeys = list(h5['data'].keys()) + self._dumpkeys = [int(i) for i in h5['data'].keys()] else: raise IOError('{} does not exist.'.format(h5file))