Export Result Data
This tutorial exports postprocess data as a dictionary, DataFrame, xarray data, and a NumPy array. Install the pandas and xarray extras before running it; see Installation.
Run it from demos/documentation_tutorials:
python result_access/05_data_exports/run.py
import numpy as np
import jcmsuite
results = jcmsuite.solve("mie2D.jcmp", keys={"radius": 0.5})
postprocess = results.postprocesses[0]
# Every bit of data can at least be exported to a mapping (dictionary).
print(postprocess.to_dict())
# Many bit of data can also be exported to a pandas DataFrame.
print(postprocess.to_df())
print(postprocess.to_df(orient="wide"))
print(postprocess.to_df(orient="long"))
# Many bit of data can also be exported to an xarray DataTree.
print(postprocess.to_xarray())
data = postprocess.to_xarray()["ElectromagneticFieldEnergyFlux"]
print(data)
print(np.abs(data))
print(data.to_numpy())
Project Files
layout.jcm
Layout2D {
UnitOfLength = 1e-6
MeshOptions {
MaximumSideLength = 0.1
}
Objects {
# Computational domain
Parallelogram {
Name = "ComputationalDomain"
DomainId = 1
Priority = ComputationalDomain
Width = 4
Height = 4
Boundary {
Class = Transparent
}
}
# Scatterer (rod)
Circle {
Name = "Rod"
DomainId = 2
Priority = 1
Radius = 0.5
RefineAll = 4
}
}
}
layout.jcmt
Layout2D {
UnitOfLength = 1e-6
MeshOptions {
MaximumSideLength = 0.1
}
Objects {
# Computational domain
Parallelogram {
Name = "ComputationalDomain"
DomainId = 1
Priority = ComputationalDomain
Width = 4
Height = 4
Boundary {
Class = Transparent
}
}
# Scatterer (rod)
Circle {
Name = "Rod"
DomainId = 2
Priority = 1
Radius = %(radius)e
RefineAll = 4
}
}
}
materials.jcm
# material properties for the surroundings (air)
Material {
DomainId = 1
RelPermittivity = 1.0
RelPermeability = 1.0
}
# material properties the glass rod
Material {
DomainId = 2
RelPermittivity = 2.3104 # 1.52^2
RelPermeability = 1.0
}
mie2D.jcmp
Project {
InfoLevel = 3
Electromagnetics {
TimeHarmonic {
Scattering {
FieldComponents = Electric
Accuracy {
FiniteElementDegree = 3
Refinement {
MaxNumberSteps = 0
PreRefinements = 0
}
}
}
}
}
}
# computes the energy flux of the scattered field into the exterior domain
PostProcess {
FluxIntegration {
FieldBagPath = "./mie2D_results/fieldbag.jcm"
OutputFileName = "./mie2D_results/energyflux_scattered.jcm"
OutputQuantity = ElectromagneticFieldEnergyFlux
InterfaceType = ExteriorDomain
}
}
PostProcess {
FourierTransform {
FieldBagPath = "./mie2D_results/fieldbag.jcm"
OutputFileName = "./mie2D_results/fc.jcm"
NormalDirection = Y
Rotation = X:Z:-Y
Format = JCM
}
}
# exports computed field on cartesian grid
PostProcess {
ExportFields {
FieldBagPath = "./mie2D_results/fieldbag.jcm"
OutputFileName = "./mie2D_results/fieldbag_cartesian.jcm"
Cartesian {
NGridPointsX = 200
NGridPointsY = 200
}
}
}
sources.jcm
SourceBag {
Source {
ElectricFieldStrength {
PlaneWave {
K = [1.14239732857811e7 0.0 0.0]
Amplitude = [0 0 1]
}
}
}
}