sdf_xarray.open_mfdatatree#
- sdf_xarray.open_mfdatatree(paths, *, separate_times=False, keep_particles=False, probe_names=None, data_vars=None, deck_path=None)[source]#
Open a set of EPOCH SDF files as one
xarray.DataTree. Variables related toboundaries,cpuandoutputfile are excluded as they are problematic. If you wish to load these variables in see Loading raw files.EPOCH can output variables at different periods, so each individal SDF file from one EPOCH run may have different variables in it. In order to combine all files into one
xarray.Dataset, we need to concatenate variables across their time dimension.We have two choices:
One time dimension where some variables may not be defined at all time points, and so will be filled with NaNs at missing points; or
Multiple time dimensions, one for each output frequency
The second option is better for memory consumption, as the missing data with the first option still takes up space. However, proper lazy-loading may mitigate this.
The
separate_timesargument can be used to switch between these choices.An
xarray.DataTreeis constructed utilising the original names in the SDF file. This is due to the fact that these names include slashes whichxarraycan use to automatically build up a datatree. We do additionally replace spaces with underscores to be more pythonic. You can find thexarray.Datasetname under theattrs["flat_structure_name"]for referencing.This function combines multiple SDF files into a single
xarray.DataTreewith a unified time dimension and hierarchical organization of variables.In some cases the user may output the
always + speciesdumpmask which means that SDF variable will have species data plus a general one. When defining axarray.DataTreeyou cannot have a node of that tree contain both variable information and have leaves with variables so we move the node information to a leaf namednode/All(see example ofDervied/Number_Density/Allin below table)Below are some examples of how variable names are translated from the regular
xarray.open_datasetresult into their more traditional names.Dataset variable name
DataTree variable name
Derived_Number_DensityDerived/Number_Density/AllDerived_Number_Density_ElectronDerived/Number_Density/ElectronDerived_Number_Density_IonDerived/Number_Density/IonDerived_Number_Density_PhotonDerived/Number_Density/PhotonDerived_Average_Particle_EnergyDerived/Average_Particle_Energy- Parameters:
paths (
Iterable|str|Path|Callable[...,Iterable[Path]]) – List of filenames or string glob patternseparate_times (
bool) – IfTrue, create separate time dimensions for variables defined at different output frequencieskeep_particles (
bool) – IfTrue, also load particle data (this may use a lot of memory!)data_vars (
list[str] |None) – List of data vars to load in (If not specified loads in all variables)deck_path (
str|PathLike|None) – IfNone, attempt to load the"input.deck"from the same directory as the SDF files and silently fail if it does not exist. If a path is given, load the specified deck from a relative or absolute file path. See Loading the input.deck for details.
- Return type:
Examples
>>> dt = open_mfdatatree("*.sdf") >>> dt["Electric_Field"]["Ex"].values # Access all Electric_Field_Ex data >>> dt.coords["time"].values # Access combined time dimension