Skip to content

Commit

Permalink
Merge pull request #7 from dc2917/fix_latex
Browse files Browse the repository at this point in the history
Fix nested latex bug
  • Loading branch information
dc2917 authored Sep 29, 2024
2 parents c8fcf9d + a95483b commit 8f464e8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 60 deletions.
34 changes: 10 additions & 24 deletions fargonaut/fields/magnetic_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ def _get_2D_cartesian_plot_data(
Y = ygrid[idx, :, :]
C = self._data[idx, :, :]

return X, Y, C, xlabel, ylabel, f"$B_{coord_map[self._dimension][1]}$"
clabel = f"$B_{coord_map[self._dimension][1].strip('$')}$"

return X, Y, C, xlabel, ylabel, clabel

def _get_2D_cylindrical_plot_data(
self, csys: str, dims: str, idx: int
Expand Down Expand Up @@ -188,10 +190,7 @@ def _get_2D_cylindrical_plot_data(
Y = ygrid[idx, :, :]
C = self._data[idx, :, :]

if self._dimension == "x" and csys == "polar":
clabel = r"$B_\phi$"
else:
clabel = f"$B_{coord_map[self._dimension][1]}$"
clabel = f"$B_{coord_map[self._dimension][1].strip('$')}$"

return X, Y, C, xlabel, ylabel, clabel

Expand Down Expand Up @@ -256,13 +255,7 @@ def _get_2D_spherical_plot_data(
Y = ygrid[idx, :, :]
C = self._data[idx, :, :]

if csys == "polar":
if self._dimension == "x":
clabel = r"$B_\phi$"
elif self._dimension == "z":
clabel = r"$B_\theta$"
else:
clabel = f"$B_{coord_map[self._dimension][1]}$"
clabel = f"$B_{coord_map[self._dimension][1].strip('$')}$"

return X, Y, C, xlabel, ylabel, clabel

Expand Down Expand Up @@ -310,7 +303,9 @@ def _get_1D_cartesian_plot_data(
X = xgrid[idx[0], idx[1], :]
Y = self._data[idx[0], idx[1], :]

return X, Y, xlabel, f"$B_{coord_map[self._dimension][1]}$"
ylabel = f"$B_{coord_map[self._dimension][1].strip('$')}$"

return X, Y, xlabel, ylabel

def _get_1D_cylindrical_plot_data(
self, csys: str, dims: str, idx: tuple[int, int]
Expand Down Expand Up @@ -360,10 +355,7 @@ def _get_1D_cylindrical_plot_data(
X = xgrid[idx[0], idx[1], :]
Y = self._data[idx[0], idx[1], :]

if self._dimension == "x" and csys == "polar":
ylabel = r"$B_\phi$"
else:
ylabel = f"$B_{coord_map[self._dimension][1]}$"
ylabel = f"$B_{coord_map[self._dimension][1].strip('$')}$"

return X, Y, xlabel, ylabel

Expand Down Expand Up @@ -415,12 +407,6 @@ def _get_1D_spherical_plot_data(
X = xgrid[idx[0], idx[1], :]
Y = self._data[idx[0], idx[1], :]

if csys == "polar":
if self._dimension == "x":
ylabel = r"$B_\phi$"
elif self._dimension == "z":
ylabel = r"$B_\theta$"
else:
ylabel = f"$B_{coord_map[self._dimension][1]}$"
ylabel = f"$B_{coord_map[self._dimension][1].strip('$')}$"

return X, Y, xlabel, ylabel
34 changes: 10 additions & 24 deletions fargonaut/fields/velocity.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ def _get_2D_cartesian_plot_data(
Y = ygrid[idx, :, :]
C = self._data[idx, :, :]

return X, Y, C, xlabel, ylabel, f"$v_{coord_map[self._dimension][1]}$"
clabel = f"$v_{coord_map[self._dimension][1].strip('$')}$"

return X, Y, C, xlabel, ylabel, clabel

def _get_2D_cylindrical_plot_data(
self, csys: str, dims: str, idx: int
Expand Down Expand Up @@ -188,10 +190,7 @@ def _get_2D_cylindrical_plot_data(
Y = ygrid[idx, :, :]
C = self._data[idx, :, :]

if self._dimension == "x" and csys == "polar":
clabel = r"$v_\phi$"
else:
clabel = f"$v_{coord_map[self._dimension][1]}$"
clabel = f"$v_{coord_map[self._dimension][1].strip('$')}$"

return X, Y, C, xlabel, ylabel, clabel

Expand Down Expand Up @@ -256,13 +255,7 @@ def _get_2D_spherical_plot_data(
Y = ygrid[idx, :, :]
C = self._data[idx, :, :]

if csys == "polar":
if self._dimension == "x":
clabel = r"$v_\phi$"
elif self._dimension == "z":
clabel = r"$v_\theta$"
else:
clabel = f"$v_{coord_map[self._dimension][1]}$"
clabel = f"$v_{coord_map[self._dimension][1].strip('$')}$"

return X, Y, C, xlabel, ylabel, clabel

Expand Down Expand Up @@ -310,7 +303,9 @@ def _get_1D_cartesian_plot_data(
X = xgrid[idx[0], idx[1], :]
Y = self._data[idx[0], idx[1], :]

return X, Y, xlabel, f"$v_{coord_map[self._dimension][1]}$"
ylabel = f"$v_{coord_map[self._dimension][1].strip('$')}$"

return X, Y, xlabel, ylabel

def _get_1D_cylindrical_plot_data(
self, csys: str, dims: str, idx: tuple[int, int]
Expand Down Expand Up @@ -360,10 +355,7 @@ def _get_1D_cylindrical_plot_data(
X = xgrid[idx[0], idx[1], :]
Y = self._data[idx[0], idx[1], :]

if self._dimension == "x" and csys == "polar":
ylabel = r"$v_\phi$"
else:
ylabel = f"$v_{coord_map[self._dimension][1]}$"
ylabel = f"$v_{coord_map[self._dimension][1].strip('$')}$"

return X, Y, xlabel, ylabel

Expand Down Expand Up @@ -415,12 +407,6 @@ def _get_1D_spherical_plot_data(
X = xgrid[idx[0], idx[1], :]
Y = self._data[idx[0], idx[1], :]

if csys == "polar":
if self._dimension == "x":
ylabel = r"$v_\phi$"
elif self._dimension == "z":
ylabel = r"$v_\theta$"
else:
ylabel = f"$v_{coord_map[self._dimension][1]}$"
ylabel = f"$v_{coord_map[self._dimension][1].strip('$')}$"

return X, Y, xlabel, ylabel
12 changes: 6 additions & 6 deletions tests/fields/test_magnetic_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def test_get_2D_cartesian_plot_data(self) -> None:
C_expected = self.b_x.data[:, :, 0]
xlabel_expected = "$x$"
ylabel_expected = "$y$"
clabel_expected = "$B_$x$$"
clabel_expected = "$B_x$"
X, Y, C, xlabel, ylabel, clabel = self.b_x._get_2D_cartesian_plot_data(
"cartesian", "xy", 0
)
Expand Down Expand Up @@ -317,7 +317,7 @@ def test_get_2D_cylindrical_plot_data(self) -> None:
C_expected = self.b_x.data[:, :, 0]
xlabel_expected = "$x$"
ylabel_expected = "$y$"
clabel_expected = r"$B_$x$$"
clabel_expected = "$B_x$"
X, Y, C, xlabel, ylabel, clabel = self.b_x._get_2D_cylindrical_plot_data(
"cartesian", "xy", 0
)
Expand Down Expand Up @@ -501,7 +501,7 @@ def test_get_2D_spherical_plot_data(self) -> None:
C_expected = self.b_x.data[:, :, 0]
xlabel_expected = "$x$"
ylabel_expected = "$y$"
clabel_expected = "$B_$x$$"
clabel_expected = "$B_x$"
X, Y, C, xlabel, ylabel, clabel = self.b_x._get_2D_spherical_plot_data(
"cartesian", "xy", 0
)
Expand Down Expand Up @@ -590,7 +590,7 @@ def test_get_1D_cartesian_plot_data(self) -> None:
X_expected = array([-1.57, 0])
Y_expected = self.b_x.data[:, 0, 0]
xlabel_expected = "$x$"
ylabel_expected = r"$B_$x$$"
ylabel_expected = "$B_x$"
X, Y, xlabel, ylabel = self.b_x._get_1D_cartesian_plot_data(
"cartesian", "x", (0, 0)
)
Expand Down Expand Up @@ -665,7 +665,7 @@ def test_get_1D_cylindrical_plot_data(self) -> None:
X_expected = r_expected * cos(phi_expected)
Y_expected = self.b_x.data[:, 0, 0]
xlabel_expected = "$x$"
ylabel_expected = r"$B_$x$$"
ylabel_expected = "$B_x$"
X, Y, xlabel, ylabel = self.b_x._get_1D_cylindrical_plot_data(
"cartesian", "x", (0, 0)
)
Expand Down Expand Up @@ -753,7 +753,7 @@ def test_get_1D_spherical_plot_data(self) -> None:
X_expected = r_expected * cos(phi_expected) * sin(theta_expected)
Y_expected = self.b_x.data[:, 0, 0]
xlabel_expected = "$x$"
ylabel_expected = r"$B_$x$$"
ylabel_expected = "$B_x$"
X, Y, xlabel, ylabel = self.b_x._get_1D_spherical_plot_data(
"cartesian", "x", (0, 0)
)
Expand Down
12 changes: 6 additions & 6 deletions tests/fields/test_velocity.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def test_get_2D_cartesian_plot_data(self) -> None:
C_expected = self.velocity_x.data[:, :, 0]
xlabel_expected = "$x$"
ylabel_expected = "$y$"
clabel_expected = "$v_$x$$"
clabel_expected = "$v_x$"
X, Y, C, xlabel, ylabel, clabel = self.velocity_x._get_2D_cartesian_plot_data(
"cartesian", "xy", 0
)
Expand Down Expand Up @@ -317,7 +317,7 @@ def test_get_2D_cylindrical_plot_data(self) -> None:
C_expected = self.velocity_x.data[:, :, 0]
xlabel_expected = "$x$"
ylabel_expected = "$y$"
clabel_expected = r"$v_$x$$"
clabel_expected = "$v_x$"
X, Y, C, xlabel, ylabel, clabel = self.velocity_x._get_2D_cylindrical_plot_data(
"cartesian", "xy", 0
)
Expand Down Expand Up @@ -501,7 +501,7 @@ def test_get_2D_spherical_plot_data(self) -> None:
C_expected = self.velocity_x.data[:, :, 0]
xlabel_expected = "$x$"
ylabel_expected = "$y$"
clabel_expected = "$v_$x$$"
clabel_expected = "$v_x$"
X, Y, C, xlabel, ylabel, clabel = self.velocity_x._get_2D_spherical_plot_data(
"cartesian", "xy", 0
)
Expand Down Expand Up @@ -590,7 +590,7 @@ def test_get_1D_cartesian_plot_data(self) -> None:
X_expected = array([-1.57, 0])
Y_expected = self.velocity_x.data[:, 0, 0]
xlabel_expected = "$x$"
ylabel_expected = r"$v_$x$$"
ylabel_expected = "$v_x$"
X, Y, xlabel, ylabel = self.velocity_x._get_1D_cartesian_plot_data(
"cartesian", "x", (0, 0)
)
Expand Down Expand Up @@ -665,7 +665,7 @@ def test_get_1D_cylindrical_plot_data(self) -> None:
X_expected = r_expected * cos(phi_expected)
Y_expected = self.velocity_x.data[:, 0, 0]
xlabel_expected = "$x$"
ylabel_expected = r"$v_$x$$"
ylabel_expected = "$v_x$"
X, Y, xlabel, ylabel = self.velocity_x._get_1D_cylindrical_plot_data(
"cartesian", "x", (0, 0)
)
Expand Down Expand Up @@ -753,7 +753,7 @@ def test_get_1D_spherical_plot_data(self) -> None:
X_expected = r_expected * cos(phi_expected) * sin(theta_expected)
Y_expected = self.velocity_x.data[:, 0, 0]
xlabel_expected = "$x$"
ylabel_expected = r"$v_$x$$"
ylabel_expected = "$v_x$"
X, Y, xlabel, ylabel = self.velocity_x._get_1D_spherical_plot_data(
"cartesian", "x", (0, 0)
)
Expand Down

0 comments on commit 8f464e8

Please sign in to comment.