Warwick-Plasma/epoch

Data plotting with python

dmargarone opened this issue · 6 comments

Dear All,
I am new to Epoch and trying to make some plots using python. If I go to the "SDF" folder, I can see there are sub-folders for "C", "Fortran", "IDL", "Matlab" and "VisIt" but I can not see any such sub-folder for PYTHON.

Also, when I was searching for how to plot with python, I came across the documentation https://epochpic.github.io/documentation/visualising_output/python.html , here it was written that go to any of the epoch directories (epoch1d, epoch2d or epoch3d) and type "make sdfutils".

Can I type "make sdfutils" even when the code is running ?
Do you think that I should let the program finish and then use "make sdfutils" command ? (to avoid any interference with the running code).

Thanks.
DM

Done !!

Hi @Status-Mirror ,

In Matlab I can access data like
Dfile = GetDataSDF(filename);
Dfile.Grid.Grid.x;
Dfile.Derived.Number_Density.electron.data;

How to do the same in Python ?
Also how to access simulation time in python ? (In Matlab it is = Dfile.time)

Thanks.

Hey @dmargarone,

Nice work figuring out the Python SDF stuff! Python isn't something I use much myself, but I have seen some Python analysis scripts before.

In previous examples, I've seen people use the lines:

import sdf 
data = sdf.read('0000.sdf')

I would imagine the simulation time would have a similar name, but you should be able to inspect the data object to figure out what options are available.

Hope thie helps,
Stuart

@Status-Mirror , Happy Christmas !!

thank you for reply even on holidays ... I figure out the variable availables while using python. It took be lots of time to access the simulation time. I reached it through "header_items".

Thank you again and happy holidays.
DM

Dear @Status-Mirror,
I have one more question. Suppose I have an electron beam launched in the simulation as shown in the tutorial (https://epochpic.github.io/quickstart/basic_examples/injectors.html#particle-bunch-injection).

Now, assuming that I am using Matlab for data plotting and the simulation is in 3D, how I can access the momentum of the electron beam and its weight ?

Do you think that the below method is correct:

q = GetDataSDF(filename); Px = q.Particles.Px.electron_beam.data; Py = q.Particles.Py.electron_beam.data; Pz = q.Particles.Pz.electron_beam.data; Wb = q.Particles.Weight.electron_beam.data;
and can I get the total beam charge by summing the weight and multiplying it by "e (electronic charge = 1.6e-19)"

Thank you.
DM

Sorry for the delay, I missed this. I assume you've sorted it now but I'll leave a response in case others find this page in the future.

EPOCH simulates macro-particles, which describe a collection of real particles. The Px, Py and Pz that you obtain there refer to the momentum of a single real electron within the macro-electron. The number of real electrons in your macro-electron is Wb. So yes, the sum of Wb tells you how many electrons are present in the simulation (in the electron_beam species), so the total charge is Wb * (-1.6e-19).

Note that EPOCH assumes cells of size dx * dy * dz. If you are using EPOCH1D or EPOCH2D, the code assumes the cell-size in the missing dimension is 1m (unit length in SI units).