Skip to content

General methods§

The following methods are available to any ozzy data object, independently of the data type or PIC code.

Bases: *mixins

coord_to_physical_distance §

coord_to_physical_distance(
    coord,
    n0,
    units="m",
    new_coord=None,
    new_label=None,
    set_as_default=True,
)

Convert a coordinate to physical units based on the plasma density \(n_0\).

This function calculates the skin depth based on the provided n0 value and scales the specified coordinate coord by the skin depth. The scaled coordinate is assigned a new name (new_coord or a default name) and added to the dataset as a new coordinate. The new coordinate can also be assigned a custom label (new_label).

Parameters:

Name Type Description Default

coord §

str

Name of coordinate to convert.

required

n0 §

float

Value for the plasma electron density used to calculate the skin depth, in \(\mathrm{cm}^{-3}\).

required

new_coord §

str

The name to assign to the new coordinate. If not provided, a default name is generated based on coord and units.

None

new_label §

str

The label ("long_name" attribute) to assign to the new coordinate. If not provided, the label of coord is used, if available.

None

units §

str

The physical units for the new coordinate. Must be either "m" for meters or "cm" for centimeters.

'm'

set_as_default §

bool

If True, the new coordinate is set as the default coordinate for the corresponding dimension, replacing coord.

True

Returns:

Type Description
DataArray

A new DataArray with the additional converted coordinate.

Examples:

Converting normalized time units to propagation distance
import ozzy as oz
da = oz.DataArray([3,4,5], coords={'t': [0,1,2]}, dims='t')
da_m = da.ozzy.coord_to_physical_distance('t', 1e18, new_coord='z') # z in m
da_cm = da.ozzy.coord_to_physical_distance('t', 1e18, units='cm', new_coord='z') # z in cm
Convert \(r\) coordinate to centimeters with new label
import ozzy as oz
import numpy as np

da = oz.DataArray({'var': np.random.rand(5, 10)},
                coords={'x2': np.linspace(0, 1, 10)})
n0 = 1e17  # cm^-3
da_new = da.ozzy.coord_to_physical_distance('x2', n0, new_coord='r', units='cm')

fft §

fft(axes=None, dims=None, **kwargs)

Calculate the Fast Fourier Transform (FFT) of a DataArray along specified dimensions.

Warning

This method has not been thoroughly checked for accuracy yet. Please double-check your results with a different FFT function.

Parameters:

Name Type Description Default

axes §

list[int]

The integer indices of the axes to take FFT along.

None

dims §

list[str]

Dimensions along which to compute the FFT. If provided, this takes precedence over axes.

None

**kwargs §

Additional keyword arguments passed to numpy.fft.fftn.

{}

Returns:

Type Description
DataArray

The FFT result as a new DataArray.

Examples:

1D FFT
import ozzy as oz
import numpy as np

# Create a 1D DataArray
x = np.linspace(0, 10, 100)
da = oz.DataArray(np.sin(2 * np.pi * x), coords=[x], dims=['x'], pic_data_type='grid')

# Compute the 1D FFT
da_fft = da.ozzy.fft(dims=['x'])
# -> 'fft' took: 0:00:00.085525
2D FFT
import ozzy as oz
import numpy as np

# Create a 2D DataArray
x = np.linspace(0, 10, 100)
y = np.linspace(0, 5, 50)
X, Y = np.meshgrid(x, y)
da = oz.DataArray(np.sin(2 * np.pi * X) * np.cos(2 * np.pi * Y),
        coords=[y, x], dims=['y', 'x'], pic_data_type='grid')

# Compute the 2D FFT
da_fft = da.ozzy.fft(dims=['x', 'y'])
# -> 'fft' took: 0:00:00.006278

save §

save(path)

Save data object to an HDF5 (default) or NetCDF file.

Parameters:

Name Type Description Default

path §

str

The path to save the file to. Specify the file ending as '.h5' for HDF5 or '.nc' for NetCDF.

required

Examples:

Save empty DataArray
import ozzy as oz
ds = oz.DataArray()
ds.ozzy.save('empty_file.h5')
#  -> Saved file "empty_file.h5"
# -> 'save' took: 0:00:00.197806

Bases: *mixins

coord_to_physical_distance §

coord_to_physical_distance(
    coord,
    n0,
    units="m",
    new_coord=None,
    new_label=None,
    set_as_default=True,
)

Convert a coordinate to physical units based on the plasma density \(n_0\).

This function calculates the skin depth based on the provided n0 value and scales the specified coordinate coord by the skin depth. The scaled coordinate is assigned a new name (new_coord or a default name) and added to the dataset as a new coordinate. The new coordinate can also be assigned a custom label (new_label).

Parameters:

Name Type Description Default

coord §

str

Name of coordinate to convert.

required

n0 §

float

Value for the plasma electron density used to calculate the skin depth, in \(\mathrm{cm}^{-3}\).

required

new_coord §

str

The name to assign to the new coordinate. If not provided, a default name is generated based on coord and units.

None

new_label §

str

The label ("long_name" attribute) to assign to the new coordinate. If not provided, the label of coord is used, if available.

None

units §

str

The physical units for the new coordinate. Must be either "m" for meters or "cm" for centimeters.

'm'

set_as_default §

bool

If True, the new coordinate is set as the default coordinate for the corresponding dimension, replacing coord.

True

Returns:

Type Description
Dataset

A new Dataset with the additional converted coordinate.

Examples:

Converting normalized time units to propagation distance
import ozzy as oz
ds = oz.Dataset(data_vars={'var1': [3,4,5]}, coords={'t': [0,1,2]}, dims='t')
ds_m = ds.ozzy.coord_to_physical_distance('t', 1e18, new_coord='z') # z in m
ds_cm = ds.ozzy.coord_to_physical_distance('t', 1e18, units='cm', new_coord='z') # z in cm
Convert \(r\) coordinate to centimeters with new label
import ozzy as oz
import numpy as np

ds = oz.Dataset({'var': np.random.rand(5, 10)},
                coords={'x2': np.linspace(0, 1, 10)})
n0 = 1e17  # cm^-3
ds_new = ds.ozzy.coord_to_physical_distance('x2', n0, new_coord='r', units='cm')

fft §

fft(data_var, axes=None, dims=None, **kwargs)

Calculate the Fast Fourier Transform (FFT) of a variable in a Dataset along specified dimensions. Take FFT of variable in Dataset along specified axes.

Warning

This method has not been thoroughly checked for accuracy yet. Please double-check your results with a different FFT function.

Parameters:

Name Type Description Default

data_var §

str

The data variable to take FFT of.

required

axes §

list[int]

The integer indices of the axes to take FFT along.

None

dims §

list[str]

Dimensions along which to compute the FFT. If provided, this takes precedence over axes.

None

**kwargs §

Additional keyword arguments passed to numpy.fft.fftn.

{}

Returns:

Type Description
DataArray

The FFT result as a new DataArray.

Examples:

1D FFT
import ozzy as oz
import numpy as np

# Create a 1D variable in a [Dataset][xarray.Dataset]
x = np.linspace(0, 10, 100)
da = oz.Dataset(data_vars = {'f_x' : np.sin(2 * np.pi * x)}, coords=[x], dims=['x'], pic_data_type='grid')

# Compute the 1D FFT
da_fft = da.ozzy.fft('f_x', dims=['x'])
# -> 'fft' took: 0:00:00.085525
2D FFT
import ozzy as oz
import numpy as np

# Create a 2D DataArray
x = np.linspace(0, 10, 100)
y = np.linspace(0, 5, 50)
X, Y = np.meshgrid(x, y)
da = oz.Dataset(data_vars = {'f_xy': np.sin(2 * np.pi * X) * np.cos(2 * np.pi * Y)},
        coords=[y, x], dims=['y', 'x'], pic_data_type='grid')

# Compute the 2D FFT
da_fft = da.ozzy.fft(dims=['x', 'y'])
# -> 'fft' took: 0:00:00.006278

save §

save(path)

Save data object to an HDF5 (default) or NetCDF file.

Parameters:

Name Type Description Default

path §

str

The path to save the file to. Specify the file ending as '.h5' for HDF5 or '.nc' for NetCDF.

required

Examples:

Save empty Dataset
import ozzy as oz
ds = oz.Dataset()
ds.ozzy.save('empty_file.h5')
#  -> Saved file "empty_file.h5"
# -> 'save' took: 0:00:00.197806