osiris-utils 1.1.3__py3-none-any.whl → 1.1.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
osiris_utils/utils.py CHANGED
@@ -4,6 +4,7 @@ import matplotlib.pyplot as plt
4
4
  import matplotlib.animation as animation
5
5
  import scipy
6
6
  import pandas as pd
7
+ from datetime import datetime
7
8
 
8
9
  def courant2D(dx, dy):
9
10
  '''
@@ -24,7 +25,7 @@ def courant2D(dx, dy):
24
25
  dt = 1 / (np.sqrt(1/dx**2 + 1/dy**2))
25
26
  return dt
26
27
 
27
- def time_estimation(n_cells, ppc, push_time, t_steps, n_cpu, hours = False):
28
+ def time_estimation(n_cells, ppc, t_steps, n_cpu, push_time = 1e-7, hours = False):
28
29
  '''
29
30
  Estimate the simulation time.
30
31
 
@@ -106,45 +107,6 @@ def integrate(array, dx):
106
107
  int = -scipy.integrate.cumulative_simpson(flip_array, dx = dx, initial = 0)
107
108
  return np.flip(int)
108
109
 
109
- def animate_2D(datafiles, frames, interval, fps, savename, **kwargs):
110
- '''
111
- Animate 2D OSIRIS files.
112
-
113
- Parameters
114
- ----------
115
- datafiles : str
116
- The path to the files.
117
- Must be of the type 'path/to/file_%06d.h5'.
118
- kwargs : dict
119
- Additional keyword arguments for plotting.
120
-
121
- Returns
122
- -------
123
- matplotlib.animation.FuncAnimation
124
- The animation.
125
- '''
126
- fig, ax = plt.subplots(figsize=(12, 6), tight_layout=True)
127
- im = 0
128
-
129
- def animate(i):
130
- # Assuming this returns (x, y, data, out) correctly
131
- x, y, data, _ = open2D(datafiles % i)
132
- ax.clear()
133
- # Display image data, make sure data shape is valid for imshow
134
- im = ax.imshow(-data, extent=[x.min(), x.max(), y.min(), y.max()], aspect='auto', origin='lower', **kwargs)
135
- plt.xlabel(r'x [c/$\omega_p$]')
136
- plt.ylabel(r'y [c/$\omega_p$]')
137
-
138
-
139
- # Creating the animation, and frames should be updated accordingly
140
- ani = animation.FuncAnimation(fig, animate, frames=frames, interval=interval)
141
-
142
- # Save the animation as a GIF (you can set the path and filename)
143
- ani.save(savename, writer='pillow', fps=fps) # fps can be adjusted
144
-
145
- # Display the animation
146
- return ani
147
-
148
110
  def save_data(data, savename, option='numpy'):
149
111
  """
150
112
  Save the data to a .txt (with Numpy) or .csv (with Pandas) file.
@@ -180,4 +142,142 @@ def read_data(filename, option='numpy'):
180
142
  Dim: 2D.
181
143
  The data.
182
144
  '''
183
- return np.loadtxt(filename) if option == 'numpy' else pd.read_csv(filename).values
145
+ return np.loadtxt(filename) if option == 'numpy' else pd.read_csv(filename).values
146
+
147
+
148
+ def convert_tracks(filename_in):
149
+ '''
150
+ Converts a new OSIRIS track file aka IDL-formatted aka tracks-2 to an older format that is more human-readable.
151
+ In the old format, each particle is stored in a separate folder, with datasets for each quantity.
152
+ The function reads data from the input file, processes it, and writes it to a new file with the suffix "-v2".
153
+
154
+ code from https://github.com/GoLP-IST/RaDi-x/blob/main/tools/convert_idl_tracks_py3.py
155
+
156
+ Parameters
157
+ ----------
158
+ filename_in : str
159
+ The path to the trackfile.
160
+
161
+ Returns
162
+ -------
163
+ The output file will be in the same folder as the input file with the same name with \"v2\" added
164
+
165
+ '''
166
+
167
+ try:
168
+ file_in = h5py.File(filename_in, 'r')
169
+ except IOError:
170
+ print('cannot open ' + filename_in)
171
+ exit()
172
+
173
+ # read data from file
174
+ data = file_in['data'][:]
175
+ itermap = file_in['itermap'][:]
176
+ ntracks = file_in.attrs['NTRACKS'][0]
177
+ niter = file_in.attrs['NITER'][0]
178
+ quants = file_in.attrs['QUANTS'][:]
179
+ file_in_attr_keys = file_in.attrs.keys()
180
+ sim_attr_keys = file_in['SIMULATION'].attrs.keys()
181
+ nquants = len(quants)
182
+
183
+ # construct file out for new format
184
+ filename_out = filename_in[:-3] + '-v2' + filename_in[-3:]
185
+ file_out = h5py.File(filename_out,'w')
186
+
187
+ # copy attrs from file_in
188
+ for item in file_in_attr_keys:
189
+ file_out.attrs[item] = file_in.attrs[item]
190
+ for item in sim_attr_keys:
191
+ file_out.attrs[item] = file_in['SIMULATION'].attrs[item]
192
+
193
+ # first pass -- find total size of each track
194
+ #----------------------------------------#
195
+ sizes = np.zeros(ntracks)
196
+
197
+ itermapshape = itermap.shape
198
+ for i in range(itermapshape[0]):
199
+ part_number,npoints,nstart = itermap[i,:]
200
+ sizes[part_number-1] += npoints
201
+
202
+ # initialize ordered data buffer
203
+ #----------------------------------------#
204
+ ordered_data = []
205
+ for i in range(ntracks):
206
+ ordered_data.append(np.zeros((int(sizes[i]),nquants)))
207
+ #----------------------------------------#
208
+
209
+
210
+
211
+ # assign tracks to ordered data from file_in data
212
+ #----------------------------------------#
213
+ track_indices = np.zeros(ntracks)
214
+ data_index = 0
215
+
216
+ for i in range(itermapshape[0]):
217
+ part_number,npoints,nstart = itermap[i,:]
218
+ track_index = int(track_indices[part_number-1])
219
+
220
+
221
+ ordered_data[part_number-1][track_index : track_index + npoints,0] \
222
+ = nstart + np.arange(npoints) * niter
223
+
224
+ ordered_data[part_number-1][track_index : track_index + npoints,1:] \
225
+ = data[data_index:data_index + npoints ,:]
226
+
227
+ data_index += npoints
228
+ track_indices[part_number-1] += npoints
229
+
230
+ #----------------------------------------#
231
+
232
+ # write to file out
233
+ for i in range(ntracks):
234
+ group = file_out.create_group(str(i+1))
235
+ for j in range(nquants):
236
+ if(j==0):
237
+ group.create_dataset(quants[j], data=np.array(ordered_data[i][:, j], dtype=int))
238
+ else:
239
+ group.create_dataset(quants[j], data=ordered_data[i][:, j])
240
+
241
+ file_out.close()
242
+ file_in.close()
243
+ print("Track file converted to the old, more readable format: ", filename_out)
244
+ return filename_out
245
+
246
+ def create_file_tags(filename, tags_array):
247
+ '''
248
+ Function to write a file_tags file from a (number_of_tags, 2) NumPy array of tags.
249
+ this file is used to choose particles for the OSIRIS track diagnostic.
250
+
251
+ Parameters
252
+ ----------
253
+ filename : str
254
+ Path to the output file where tags will be stored.
255
+ tags_array: np.ndarray
256
+ shape (number_of_tags, 2), containing particle tags
257
+
258
+ Returns
259
+ -------
260
+ file_tags file with path \"filename\" to be used for the OSIRIS track diagnostic.
261
+
262
+ Notes
263
+ ------
264
+ The first element of the tag of a particle that is already being tracked is negative,
265
+ so we apply the absolute function when generating the file
266
+
267
+ '''
268
+
269
+ # In case the particles chosen were already being tracked
270
+ tags_array[:, 0] = np.abs(tags_array[:, 0])
271
+ tags_array = tags_array[np.lexsort((tags_array[:, 1], tags_array[:, 0]))]
272
+ num_tags = tags_array.shape[0]
273
+
274
+ with open(filename, 'w') as file:
275
+ file.write("! particle tag list\n")
276
+ file.write(f"! generated on {datetime.now().strftime('%a %b %d %H:%M:%S %Y')}\n")
277
+ file.write("! number of tags\n")
278
+ file.write(f" {num_tags}\n")
279
+ file.write("! particle tag list\n")
280
+
281
+ for i in range(num_tags):
282
+ file.write(f" {tags_array[i, 0]:<6}{tags_array[i, 1]:>6}\n")
283
+ return filename
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: osiris_utils
3
- Version: 1.1.3
3
+ Version: 1.1.6
4
4
  Summary: Utilities to manipulate and visualize OSIRIS framework output data
5
5
  Author: ['João Pedro Ferreira Biu', 'João Cândido', 'Diogo Carvalho']
6
6
  Author-email: ['joaopedrofbiu@tecnico.ulisboa.pt']
@@ -19,7 +19,7 @@ Classifier: Programming Language :: Python :: 3.10
19
19
  Classifier: Programming Language :: Python :: 3.11
20
20
  Classifier: Programming Language :: Python :: 3.12
21
21
  Classifier: Topic :: Scientific/Engineering
22
- Requires-Python: >=3.11
22
+ Requires-Python: >=3.10
23
23
  Description-Content-Type: text/x-rst
24
24
  License-File: LICENSE.txt
25
25
  Requires-Dist: numpy
@@ -48,6 +48,10 @@ OSIRIS_UTILS
48
48
  |Pypi|
49
49
 
50
50
  This package contains a set of utilities to open and analyze OSIRIS output files, using Python. All the methods implemented are fully integrated with `NumPy`, and use `np.ndarray` as the main data structure.
51
+ High-level functions are provided to manipulate data from OSIRIS, from reading the data of the diagnostics, to making post-processing calculations.
52
+
53
+ All code is written in Python. To contact the dev team, please send an email to João Biu: `joaopedrofbiu@tecnico.ulisboa.pt <mailto:joaopedrofbiu@tecnico.ulisboa.pt>`_.
54
+ The full dev team can be found below in the Authors and Contributors section.
51
55
 
52
56
  How to install it?
53
57
  ------------------
@@ -58,6 +62,12 @@ To install this package, you can use `pip`::
58
62
 
59
63
  To install it from source, you can clone this repository and run (in the folder containing ``setup.py``)::
60
64
 
65
+ git clone https://github.com/joaopedrobiu6/osiris_utils.git
66
+ pip install .
67
+
68
+ Finally, you can install it in editor mode if you want to contribute to the code::
69
+
70
+ git clone https://github.com/joaopedrobiu6/osiris_utils.git
61
71
  pip install -e .
62
72
 
63
73
  Documentation
@@ -69,3 +79,11 @@ The documentation is available at https://osiris-utils.readthedocs.io or via thi
69
79
  :target: https://pypi.org/project/osiris-utils/
70
80
  :alt: Pypi
71
81
 
82
+ .. _authors:
83
+
84
+ Authors and Contributors
85
+ ------------------------
86
+
87
+ - João Biu
88
+ - João Cândido
89
+ - Diogo Carvalho
@@ -0,0 +1,25 @@
1
+ osiris_utils/__init__.py,sha256=vnmri235UkoAxKZMf9111dMb94a4z05XAkszbGSyKgo,1191
2
+ osiris_utils/utils.py,sha256=zg-5pOVOieVHXYeNWtCq921Q4PmXVArLInJMd8JURpY,8137
3
+ osiris_utils/data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ osiris_utils/data/data.py,sha256=u-0qcPXyTK187j8kGHNgTBgJKX90_YA8jUYno87q9n0,25619
5
+ osiris_utils/data/diagnostic.py,sha256=d9xfTTMFq4p5kVirw94Leq2Jak_gGMjw6PHG2PmRUtE,49179
6
+ osiris_utils/data/simulation.py,sha256=bvJ6UHIzUNUWlWqZbeg60i-Dscl7x6MRZXGfsy8xkWE,6878
7
+ osiris_utils/decks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ osiris_utils/decks/decks.py,sha256=Ug1_fSfZL9iJwn7dnTvHM0k1Zc4kGpI427QvO0V2pwg,10173
9
+ osiris_utils/decks/species.py,sha256=uZA1oMSltofc2m1s3rK__wjxXfTAQ_3wB2aKRG_PmKo,1066
10
+ osiris_utils/gui/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ osiris_utils/gui/gui.py,sha256=s4not0GzHI3CrA4uQVnjt9jFavkVAeGbQ6rJpM4jir4,10538
12
+ osiris_utils/postprocessing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
+ osiris_utils/postprocessing/derivative.py,sha256=p1jhy0Ey8w-AYLVBVGgjpYw19cmLPYV_gdRMHtNSR7w,9602
14
+ osiris_utils/postprocessing/fft.py,sha256=Hif7nQN9RcnpnD_MKxvK5K6DgmINSjgmgYcktIrKdo8,9037
15
+ osiris_utils/postprocessing/field_centering.py,sha256=1i6Fue9PhuED2VxBUq1ggHO3MTSlXjhkFvqh1pb_-Y0,6788
16
+ osiris_utils/postprocessing/heatflux_correction.py,sha256=5_XaDGdB5xP8gDJF9MVIlHN5tggbYHWBgetQvEmAnKQ,7055
17
+ osiris_utils/postprocessing/mft.py,sha256=Ryx0DW8Mb7f0ikf2HfM_T_m2WqrCgcEkMJNZBLZ5qAY,12399
18
+ osiris_utils/postprocessing/mft_for_gridfile.py,sha256=ZaLgwsND9nbD-v-JfCZYxh7-dz3RA-IILwBjZnZGCiE,1522
19
+ osiris_utils/postprocessing/postprocess.py,sha256=f2ZXLnAvLpsLFd-Pygb_sYxwkU4zn1OoF_byVKYAPII,1115
20
+ osiris_utils/postprocessing/pressure_correction.py,sha256=9ZK6BTaGAa8W1ltpXsQf6aTH-xfYJ38076gJToxUFgQ,6345
21
+ osiris_utils-1.1.6.dist-info/licenses/LICENSE.txt,sha256=Cawy2v7wKc7n8yL8guFu-cH9sQw9r1gll1pEFPFAB-Q,1084
22
+ osiris_utils-1.1.6.dist-info/METADATA,sha256=hLLfQtRh4ZEoqt8-LlDHiRg7hU6dWyx65guAXVDu6Fc,3070
23
+ osiris_utils-1.1.6.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
24
+ osiris_utils-1.1.6.dist-info/top_level.txt,sha256=mM-_dX5fjzIKB7te655PhZOrPACVY-bJmiASCqW1eOA,13
25
+ osiris_utils-1.1.6.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (77.0.3)
2
+ Generator: setuptools (78.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,7 +0,0 @@
1
- osiris_utils/__init__.py,sha256=b41_lLyISC_67CzwRixeSS-MoRog7smLqqfg80XfbbQ,821
2
- osiris_utils/utils.py,sha256=pj2hrmZla-6T_95eRZB_c4TSXJqBvNRvMTzuw1lPZyA,4708
3
- osiris_utils-1.1.3.dist-info/licenses/LICENSE.txt,sha256=Cawy2v7wKc7n8yL8guFu-cH9sQw9r1gll1pEFPFAB-Q,1084
4
- osiris_utils-1.1.3.dist-info/METADATA,sha256=ioKLZT5eREyxC877Fb4FvRRw7Mf2U1a79Dp8PD_fe10,2327
5
- osiris_utils-1.1.3.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
6
- osiris_utils-1.1.3.dist-info/top_level.txt,sha256=mM-_dX5fjzIKB7te655PhZOrPACVY-bJmiASCqW1eOA,13
7
- osiris_utils-1.1.3.dist-info/RECORD,,