Parsing Genesis2 Field data¶
In [ ]:
Copied!
from genesis import Genesis2, parsers
import numpy as np
import os
from genesis import Genesis2, parsers
import numpy as np
import os
In [ ]:
Copied!
# Make some dfl, fld data
G = Genesis2("data/basic/genesis.in")
# Turn on field output
G["idmpfld"] = 1
# Turn on particle output
# G['idmppar'] = 1
G["npart"] = 2048
# Turn on history
# G['ippart'] = 10
G["ipradi"] = 10
G.run()
# Make some dfl, fld data
G = Genesis2("data/basic/genesis.in")
# Turn on field output
G["idmpfld"] = 1
# Turn on particle output
# G['idmppar'] = 1
G["npart"] = 2048
# Turn on history
# G['ippart'] = 10
G["ipradi"] = 10
G.run()
In [ ]:
Copied!
# These are the files written
!ls {G.path}
# These are the files written
!ls {G.path}
In [ ]:
Copied!
# Change this
# test_dir = 'path/to/your/output'
test_dir = G.path
out_fname = os.path.join(test_dir, "genesis.out")
dfl_fname = os.path.join(test_dir, "genesis.out.dfl")
fld_fname = os.path.join(test_dir, "genesis.out.fld")
# Get parameters from .out file
odat = parsers.parse_genesis_out(out_fname)
params = odat["param"]
my_ncar = params["ncar"]
my_dgrid = params["dgrid"]
my_nz = 1
# Change this
# test_dir = 'path/to/your/output'
test_dir = G.path
out_fname = os.path.join(test_dir, "genesis.out")
dfl_fname = os.path.join(test_dir, "genesis.out.dfl")
fld_fname = os.path.join(test_dir, "genesis.out.fld")
# Get parameters from .out file
odat = parsers.parse_genesis_out(out_fname)
params = odat["param"]
my_ncar = params["ncar"]
my_dgrid = params["dgrid"]
my_nz = 1
In [ ]:
Copied!
my_dfl = parsers.parse_genesis_dfl(dfl_fname, nx=my_ncar)
my_dfl
my_dfl = parsers.parse_genesis_dfl(dfl_fname, nx=my_ncar)
my_dfl
In [ ]:
Copied!
my_fld = parsers.parse_genesis_fld(fld_fname, my_ncar, my_nz)
my_fld[-1]
my_fld = parsers.parse_genesis_fld(fld_fname, my_ncar, my_nz)
my_fld[-1]
Plot¶
In [ ]:
Copied!
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
In [ ]:
Copied!
# Field phase at end, slice 0
def plot_field(dat, dgrid):
    ndat = np.angle(dat)
    plt.imshow(ndat, extent=[1000 * dgrid * i for i in [-1, 1, -1, 1]])
    plt.xlabel("x (mm)")
    plt.ylabel("y (mm)")
    plt.show()
plot_field(my_dfl[:, :, 0], my_dgrid)
# Field phase at end, slice 0
def plot_field(dat, dgrid):
    ndat = np.angle(dat)
    plt.imshow(ndat, extent=[1000 * dgrid * i for i in [-1, 1, -1, 1]])
    plt.xlabel("x (mm)")
    plt.ylabel("y (mm)")
    plt.show()
plot_field(my_dfl[:, :, 0], my_dgrid)
In [ ]:
Copied!
# Field phrase from history file, slice 0
plot_field(my_fld[:, :, 0, -1], my_dgrid)
# Field phrase from history file, slice 0
plot_field(my_fld[:, :, 0, -1], my_dgrid)