From ee74cb619c93bf01d6c11c2bb741d34d5cc6e237 Mon Sep 17 00:00:00 2001 From: Frank S Tsung Date: Thu, 3 Mar 2022 06:13:39 -0800 Subject: [PATCH 1/3] Update osh5utils.py fix an error in field-decompose --- osh5utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osh5utils.py b/osh5utils.py index 3628f6c..fa0ba06 100644 --- a/osh5utils.py +++ b/osh5utils.py @@ -593,7 +593,7 @@ def field_decompose(fldarr, ffted=True, idim=None, finalize=None, outquants=('L' if not finalize: finalize = __idle if np.issubdtype(fldarr[0].dtype, np.floating): - ftf, iftf = fftn, ifftn if norft else rfftn, irfftn + ftf, iftf = (fftn, partial(ifftn, result=np.real(result))) if norft else (rfftn, irfftn) def wrap_up(data): if idim: From d4a1b9bb48582208ec63ae5286d1ed24568c8429 Mon Sep 17 00:00:00 2001 From: Frank S Tsung Date: Sun, 3 Dec 2023 23:27:42 -0800 Subject: [PATCH 2/3] Update osh5vis.py minor bug fix --- osh5vis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osh5vis.py b/osh5vis.py index 528a4de..dd371dd 100644 --- a/osh5vis.py +++ b/osh5vis.py @@ -68,7 +68,7 @@ def default_title(h5data, show_time=True, title=None, **kwargs): def tex(s): - return '$' + s + '$' if s else '' + return '$' + str(s) + '$' if s else '' def axis_format(name=None, unit=None): From 2bfb60935af6e483e538d36339b2ace9dd3e4e6f Mon Sep 17 00:00:00 2001 From: Frank S Tsung Date: Thu, 4 Apr 2024 17:41:50 -0700 Subject: [PATCH 3/3] modified osh5io.py Added particle track diagnostics and modified openPMD write to be compliant with the latest openPMD standard. --- docs/.DS_Store | Bin 6148 -> 0 bytes docs/sphinx/.DS_Store | Bin 6148 -> 0 bytes osh5io.py | 69 ++++++++++++++++++++++++++++++++++++++---- 3 files changed, 63 insertions(+), 6 deletions(-) delete mode 100644 docs/.DS_Store delete mode 100644 docs/sphinx/.DS_Store diff --git a/docs/.DS_Store b/docs/.DS_Store deleted file mode 100644 index 663baecf2f53106855334d009ed307887748442a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKK}rKb5UkcH0WUdvoG0ZCR+SX?m#JnqeJTiw&bhE>SPgQC4@7Oj9d~e_UO9(uHOzr&)3t;xmVcYfEV;Q;$LHr zfr)qQ@HE}n6K{AX;}sv%#A!#WN(x8;DIf);z*#GhO?r8A)+*@oQa}p)q=0`P3f-|L zjt%3}!6ilj;)3BYKF2IUEFK`%#IYeGG;361qgsv_*656vtgDG*!$ybY@L_qf<%D8! zI`=P84yz5dN&zWwtbotnw3YY&d-^Z)zt_m5fE4(r3fN-vuvznR*;{AV^j=%&kMwV2 oZIp9~R!odm%olIPx0AZ!&&=1vv0=~|4?0ml0&j0`b diff --git a/docs/sphinx/.DS_Store b/docs/sphinx/.DS_Store deleted file mode 100644 index 16d875f048b003f89438f610b00ecfc05d69253a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~J&pn~427Thk&tL8DbsL(y+MTF1YBUnPJ=WO#fm;h=h<(?J6KYLuU74ZjM<6h0 J5P^Rs@C1L66M6su diff --git a/osh5io.py b/osh5io.py index 695ea0e..012adad 100644 --- a/osh5io.py +++ b/osh5io.py @@ -167,13 +167,66 @@ def read_raw(filename, path=None): #TODO: TIMESTAMP is not set in HDF5 file as of now (Aug 2019) so we make one up, check back when file format changes d['TIMESTAMP'] = timestamp - dtype = [(q, data[q].dtype) for q in quants] + + dtype = [(q, data[q].dtype, (2,)) if q.lower() == 'tag' else (q, data[q].dtype) for q in quants] + # dtype = [(q, data[q].dtype) for q in quants] + print('dtype=',dtype) + print(data[dtype[0][0]].shape) r = PartData(data[dtype[0][0]].shape, dtype=dtype, attrs=d) for dt in dtype: r[dt[0]] = data[dt[0]] return r +def read_h5_tracks(filename, path=None): + """ + subroutine that reads a OSIRIS track file into an ordered list of NUMPY arrays. + Currently this subroutines supports the older (ver 1) track files + + and the attributes that describe the data (e.g. title, units, scale). + + tracks, quants = read_h5_tracks(filename) + print(tracks.shape()) # shows how many tracks are in the file + print(tracks[0].shape) # this prints 2 numbers, the first number is the total number + # of timesteps for the first track, and the second number is the number + # of particle quantities are stored in the track + print(quants.index['x1']) # this prints the array index for the quantity 'x1', + # possible track quantities include 't', 'x1','x2','x3','p1','p2','p3' + # 'E1', 'E2', 'E3', 'B1', 'B2', 'B3', and 'ene', for quasi 3D there is + # an 'x4' + plt.plot(tracks[i][:,quants.index('p1')],tracks[i][:,quants.index('p2')]) + # plots p1 vs p2 for the i-th particle + + ## Example Python Code + + (a,b) = read_h5_tracks('FILENAME') + plt.figure() + for j in range(len(a)): + plt.plot(a[j][:,b.index('p1')],a[j][:b.index('p2')]) + plt.show() + + """ + fname = filename if not path else path + '/' + filename + data_file = h5py.File(fname, 'r') + keys = list(data_file.keys()) + num_tracks = len(keys) + quants = data_file.attrs['QUANTS'] + quants_string = [] + # here we convert the quant array from bytes to string + for x in quants: + quants_string.append(x.decode()) + # + + quants_string = [] + particle_list = [] + + for j in range(0,num_tracks): + key = keys[j] + track = data_file[key] + particle_list.append(track) + + return(particle_list, quants_string) + def read_h5_openpmd(filename, path=None): """ @@ -523,7 +576,8 @@ def write_h5_openpmd(data, filename=None, path=None, dataset_name=None, overwrit local_offset[0]= np.float32(0.0) elif (number_axis_objects_we_need == 2): - local_axislabels=[b'x1', b'x2'] + # local_axislabels=[b'x1', b'x2'] + local_axislabels=np.array([np.string_('x1'),np.string('x2')]) deltax[0] = deltax[0]/data_object.shape[0] deltax[1] = deltax[1]/data_object.shape[1] temp=deltax[0] @@ -538,7 +592,9 @@ def write_h5_openpmd(data, filename=None, path=None, dataset_name=None, overwrit local_offset[1]= np.float32(0.0) else: - local_axislabels=[b'x1',b'x2',b'x3'] + # local_axislabels=[b'x1',b'x2',b'x3'] + # local_axislabels=['x1','x2','x3'] + local_axislabels=np.array([np.string_('x1'),np.string_('x2'),np.string_('x3')]) deltax[0] = deltax[0]/data_object.shape[0] deltax[1] = deltax[1]/data_object.shape[1] deltax[2] = deltax[2]/data_object.shape[2] @@ -557,9 +613,10 @@ def write_h5_openpmd(data, filename=None, path=None, dataset_name=None, overwrit - datasetid.attrs['dataOrder'] = 'F' - datasetid.attrs['geometry'] = 'cartesian' - datasetid.attrs['geometryParameters'] = 'cartesian' + datasetid.attrs['dataOrder'] = np.string_('F') + datasetid.attrs['geometry'] = np.string_('cartesian') + datasetid.attrs['geometryParameters'] = np.string_('cartesian') + print("axislabels=",local_axislabels) datasetid.attrs['axisLabels'] = local_axislabels datasetid.attrs['gridUnitSI'] = np.float64(length_to_si) datasetid.attrs['unitSI'] = np.float64(data_to_si)