Remix package
kaipy.remix.remix module
- class kaipy.remix.remix.remix(h5file, step)
Bases:
objectA class for handling and manipulating ion data in the REMIX format.
- Parameters:
h5file (str) – The path to the REMIX file in HDF5 format.
step (int) – The step number of the data to be loaded.
- ion
A dictionary containing the ion data and coordinates.
- Type:
dict
- Initialized
Indicates whether the object has been initialized.
- Type:
bool
- __init__(self, h5file, step)
Initializes the remix object and loads the ion data.
- get_data(self, h5file, step)
Loads the ion data from the REMIX file.
- init_vars(self, hemisphere)
Initializes the variables based on the specified hemisphere.
- get_spherical(self, x, y)
Converts Cartesian coordinates to spherical coordinates.
- distance(self, p0, p1)
Calculates the Euclidean distance between two points in R^3.
- calcFaceAreas(self, x, y)
Calculates the area of each face in a quad mesh.
- plot(self, varname, ncontours=16, addlabels={}, gs=None, doInset=False, doCB=True, doCBVert=True, doGTYPE=False, doPP=False)
Plots the specified variable.
- efield(self, returnDeltas=False, ri=Ri * 1e3)
Calculates the electric field at each point in the grid.
- joule(self)
Calculates the power density in watts per square meter (W/m^2) based on the electric field and conductivity.
- cartesianCellCenters(self)
Calculates the Cartesian cell centers.
- hCurrents(self)
Calculates the horizontal currents.
- dB(self, xyz, hallOnly=True, Rin=2.0, rsegments=10)
Computes the magnetic field (B-field) at given points.
- BSFluxTubeInt(self, xyz, Rinner, rsegments=10)
Computes flux-tube Biot-Savart integral int dl bhat x r’/|r’|^3.
Note
This class assumes that the REMIX file is in a specific format and follows certain naming conventions for the variables.
- BSFluxTubeInt(xyz, Rinner, rsegments=10)
Compute flux-tube Biot-Savart integral int dl bhat x r’/|r’|^3
- Parameters:
xyz (numpy.ndarray) – array of points where to compute dB (same as above in dB). xyz.shape should be (N,3), where N is the number of points. xyz = (x,y,z) in units of Ri
Rinner (float) – The radius of the inner boundary of the MHD domain expressed in Ri
- Returns:
x component of the flux tube integral inty (float): y component of the flux tube integral intz (float): z component of the flux tube integral
- Return type:
intx (float)
- calcFaceAreas(x, y)
Calculate the area of each face in a quad mesh.
- Parameters:
x (numpy.ndarray) – Array of x-coordinates of shape (nLonP1, nLatP1).
y (numpy.ndarray) – Array of y-coordinates of shape (nLonP1, nLatP1).
- Returns:
Array of face areas of shape (nLon, nLat).
- Return type:
area (numpy.ndarray)
Example
>>> calcFaceAreas(numpy.array([[0., 1.], [1., 0.]]), numpy.array([[0., 1.], [1., 0.]])) array([[2.]])
- cartesianCellCenters()
Calculate the Cartesian cell centers.
This method calculates the Cartesian cell centers based on the given ion coordinates. It performs the following steps: 1. Alias the ion coordinates for convenience. 2. Calculate the x and y coordinates of the cell centers using the average of neighboring ion coordinates. 3. Convert the Cartesian coordinates to spherical coordinates (r, phi). 4. Calculate the theta angle using the inverse sine of r. 5. Return the Cartesian cell centers (xc, yc), theta, and phi.
- Returns:
A tuple containing the Cartesian cell centers (xc, yc), theta, and phi.
- Return type:
tuple
- dB(xyz, hallOnly=True, Rin=2.0, rsegments=10)
Compute the magnetic field (B-field) at given points.
- Parameters:
xyz (numpy.ndarray) – Array of points where to compute the B-field. The shape should be (N, 3), where N is the number of points and each point is represented by (x, y, z) coordinates in units of Ri.
hallOnly (bool) – Flag indicating whether to consider only the Hall current or both Hall and Pedersen currents. Default is True.
Rin (float) – Inner radius of the flux tube in units of Ri. Default is 2.0.
rsegments (int) – Number of segments to divide the flux tube into. Default is 10.
- Returns:
Array of radial component of the B-field at each point. dBtheta (numpy.ndarray): Array of theta component of the B-field at each point. dBphi (numpy.ndarray): Array of phi component of the B-field at each point.
- Return type:
dBr (numpy.ndarray)
- distance(p0, p1)
Calculate the Euclidean distance between two points in R^3.
- Parameters:
p0 (tuple) – The coordinates of the first point in R^3.
p1 (tuple) – The coordinates of the second point in R^3.
- Returns:
The Euclidean distance between p0 and p1.
- Return type:
float
- efield(returnDeltas=False, ri=6500.0)
Calculate the electric field at each point in the grid.
- Parameters:
returnDeltas (bool, optional) – Whether to return the differences in theta and phi along with the electric field.
ri (float, optional) – The value of Ri multiplied by 1e3.
- Returns:
- A tuple containing the electric field components (-etheta, -ephi) in V/m.
If returnDeltas is True, it also includes the differences in theta and phi (dtheta, dphi).
- Return type:
tuple
- Raises:
SystemExit – If the variables have not been initialized for the specific hemisphere.
Note
This method assumes that the variables have been initialized for the specific hemisphere by calling the init_var method prior to calculating the electric field.
- get_data(h5file, step)
Retrieve data from an HDF5 file for a given step.
- Parameters:
h5file (str) – The path to the HDF5 file.
step (int) – The step number.
- Returns:
- A dictionary containing the retrieved data.
’X’: The X values.
’Y’: The Y values.
Additional keys for each dataset in the specified step.
’R’: The spherical coordinates (radius).
’THETA’: The spherical coordinates (theta).
- Return type:
dict
- get_spherical(x, y)
Convert Cartesian coordinates (x, y) to spherical coordinates (r, theta).
- Parameters:
x (ndarray) – Array of x-coordinates.
y (ndarray) – Array of y-coordinates.
- Returns:
Array of radial distances. theta (ndarray): Array of azimuthal angles in radians.
- Return type:
r (ndarray)
- hCurrents()
Calculate the horizontal currents.
- Returns:
- A tuple containing the following elements:
xc (ndarray): x-coordinates of the cell centers.
yc (ndarray): y-coordinates of the cell centers.
theta (ndarray): Theta values of the cell centers.
phi (ndarray): Phi values of the cell centers.
dtheta (float): Delta theta value.
dphi (float): Delta phi value.
Jh_theta (ndarray): Horizontal current in the theta direction.
Jh_phi (ndarray): Horizontal current in the phi direction.
Jp_theta (ndarray): Horizontal current in the theta direction.
Jp_phi (ndarray): Horizontal current in the phi direction.
cosDipAngle (ndarray): Cosine of the dip angle.
- Return type:
tuple
- init_vars(hemisphere)
Initialize the variables based on the given hemisphere.
- Parameters:
hemisphere (str) – The hemisphere (‘north’ or ‘south’).
- Returns:
None
- joule()
Calculate the power density in watts per square meter (W/m^2) based on the electric field and conductivity.
- Returns:
The power density in W/m^2.
- Return type:
float
- plot(varname, ncontours=16, addlabels={}, gs=None, doInset=False, doCB=True, doCBVert=True, doGTYPE=False, doPP=False)
Plot the specified variable on a polar grid.
- Parameters:
varname (str) – The name of the variable to plot.
ncontours (int) – The number of potential contours to plot (default: 16).
addlabels (dict) – Additional colorbar labels to add (default: {}).
gs (GridSpec) – The GridSpec object to use for subplot placement (default: None).
doInset (bool) – Whether to create an inset plot (default: False).
doCB (bool) – Whether to show the colorbar (default: True).
doCBVert (bool) – Whether to show the colorbar vertically (default: True).
doGTYPE (bool) – Whether to overplot grid type contours (default: False).
doPP (bool) – Whether to overplot polar cap boundary contours (default: False).
- Returns:
The AxesSubplot object containing the plot.
- Return type:
ax (AxesSubplot)