hybrid_jp.sdf_files module#
Functions that interact with sdf_helper objects.
- class hybrid_jp.sdf_files.SDF(grid: Grid, mid_grid: Grid, mag: Mag, elec: Elec, current: Current, numberdensity: ndarray, temperature: ndarray, tstamp: float | None = None)[source]#
Bases:
objectRepresentation of .sdf file.
- numberdensity: ndarray#
- temperature: ndarray#
- tstamp: float | None = None#
- hybrid_jp.sdf_files.data_to_df(data: dict[str, numpy.ndarray]) DataFrame[source]#
Turn dict into dataframe.
- Parameters:
data (dict[str, np.ndarray]) – dict
- Returns:
dataframe
- Return type:
pd.DataFrame
- hybrid_jp.sdf_files.extract_vars(data, vars_list: list[str]) dict[str, numpy.ndarray][source]#
Get vars from vars_list out of sdf data object.
- Parameters:
data (sdf_helper_internal) – sdf data object
vars_list (list[str]) – list of variable names
- Returns:
dict of np arrays, keys are var names
- Return type:
dict[str, np.ndarray]
- hybrid_jp.sdf_files.filefinder(dir: Path, start: int, stop: int) Iterator[Path][source]#
Returns next sdf file in dir.
Note
SDFs are named as 0000.sdf, 0001.sdf, etc. i.e. 0 padded 4 digit integers.
- Parameters:
dir (Path) – directory to search
start (int) – start file number
stop (int) – stop file number
- Yields:
Iterator[Path] – next sdf file in dir
Example
>>> dir = Path("data") >>> for file in filefinder(dir, 0, 10): ... print(file) dir/0000.sdf dir/0001.sdf ...
- hybrid_jp.sdf_files.get_current(data: BlockList) Current[source]#
Get the electric field of an sdf_helper object.
- Parameters:
data (sdf_helper) – sdf data object to get electric field of.
- Returns:
Elec namedtuple of x, y, and z electric field values.
- Return type:
Example
>>> get_elec(data) Elec(x=array([[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,]], y=array([[ 0.00000000e+00, 1.00000000e-16, 2.00000000e-16, ...,]], z=array([[ 0.00000000e+00, 1.00000000e-16, 2.00000000e-16, ...,]]))
- hybrid_jp.sdf_files.get_elec(data: BlockList) Elec[source]#
Get the electric field of an sdf_helper object.
- Parameters:
data (sdf_helper) – sdf data object to get electric field of.
- Returns:
Elec namedtuple of x, y, and z electric field values.
- Return type:
Example
>>> get_elec(data) Elec(x=array([[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,]], y=array([[ 0.00000000e+00, 1.00000000e-16, 2.00000000e-16, ...,]], z=array([[ 0.00000000e+00, 1.00000000e-16, 2.00000000e-16, ...,]]))
- hybrid_jp.sdf_files.get_grid(data: BlockList, mid: bool = False) Grid[source]#
Get the grid of an sdf_helper object.
- Parameters:
data (sdf_helper) – sdf data object to get grid of.
mid (bool, optional) – Get the midpoints grid. Defaults to False.
- Returns:
Grid namedtuple of x and y grid values.
- Return type:
Example
>>> get_grid(data) Grid(x=array([0.00000000e+00, 2.50000000e-05, 5.00000000e-05, ..., 5.00000000e-02, 5.00250000e-02, 5.00500000e-02]), y=array([0.00000000e+00, 2.50000000e-05, 5.00000000e-05, ..., 5.00000000e-02, 5.00250000e-02, 5.00500000e-02]))
- hybrid_jp.sdf_files.get_mag(data: BlockList) Mag[source]#
Get the magnetic field of an sdf_helper object.
- Parameters:
data (sdf_helper) – sdf data object to get magnetic field of.
- Returns:
Mag namedtuple of x, y, and z magnetic field values.
- Return type:
Example
>>> get_mag(data) Mag(x=array([[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ...,]], y=array([[ 0.00000000e+00, 1.00000000e-16, 2.00000000e-16, ...,]], z=array([[ 0.00000000e+00, 1.00000000e-16, 2.00000000e-16, ...,]]))
- hybrid_jp.sdf_files.list_variables(data: BlockList, show_name: bool = True, show_type: bool = False, show_size: bool = True) list[list[str]][source]#
List variables in an sdf_helper object.
- Parameters:
data (sdf_helper) – sdf_helper object to list variables of.
show_name (bool, optional) – Show variable names. Defaults to True.
show_type (bool, optional) – Show variable types. Defaults to False.
show_size (bool, optional) – Show variable sizes. Defaults to True.
- Returns:
- List of variables, where each variable is a list of
[name, type, size].
- Return type:
list[list[str]]
Example
>>> list_variables(data) [['Grid_Grid', numpy.ndarray, '256, 256'], ['Grid_Grid_mid', numpy.ndarray, '256, 256'], ['Derived_Number_Density', numpy.ndarray, '256, 256'], ['Magnetic_Field_Bx', numpy.ndarray, '256, 256'], ['Magnetic_Field_By', numpy.ndarray, '256, 256'], ['Magnetic_Field_Bz', numpy.ndarray, '256, 256']]
- hybrid_jp.sdf_files.load(path_to_sdf: pathlib.Path | str) BlockList[source]#
Load sdf file into sdf_helper object.
if str is passed, it is converted to Path
- Parameters:
path_to_sdf (Path | str) – path to sdf file
- Raises:
FileNotFoundError – file not found
ValueError – file is not an sdf
- Returns:
sdf data object
- Return type:
sdf_helper_internal
- hybrid_jp.sdf_files.load_sdf_verified(path_to_sdf: Path, dt: float | None = None) SDF[source]#
Load an sdf into SDF class.
Note
SDF.tstamp will be None if dt is None. Otherwise it will be the timestamp of the sdf file, created by multiplying dt with the filename.
- hybrid_jp.sdf_files.print_variables(data: BlockList, show_name: bool = True, show_type: bool = False, show_size: bool = True) None[source]#
Print variables in an sdf_helper object.
- Parameters:
data (BlockList) – SDF file from sdf_helper.
show_name (bool, optional) – Show variable names. Defaults to True.
show_type (bool, optional) – Show variable types. Defaults to False.
show_size (bool, optional) – Show variable sizes. Defaults to True.
Example
>>> import hybrid_jp >>> sdf = hybrid_jp.sdf_files.load("U6T40/0003.sdf") >>> hybrid_jp.sdf_files.print_variables(sdf) CPUs_Current_rank [0,0] CPUs_Original_rank [1,8] Current_Jx [1600, 160] Current_Jy [1600, 160] Current_Jz [1600, 160] Derived_Average_Particle_Energy [1600, 160] ...
- hybrid_jp.sdf_files.reduce_to_1d(data: dict[str, numpy.ndarray], index: int = 80) dict[str, numpy.ndarray][source]#
Take y=`index` from each key in dict of 2d np arrays.
- Parameters:
data (dict[str, np.ndarray]) – dict of 2d np arrays
index (int, optional) – y=`index`. Defaults to 80.
- Raises:
ValueError – Raised when any key in dict has dimension != 2
- Returns:
dict of 1d np arrays
- Return type:
dict[str, np.ndarray]