Skip to content

Commit

Permalink
[NF] clean strings from latex characters in export
Browse files Browse the repository at this point in the history
  • Loading branch information
helene-t committed Jan 10, 2022
1 parent 96d409f commit 35d71bf
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
24 changes: 21 additions & 3 deletions SciDataTool/Methods/DataND/export_along.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import numpy as np
from os.path import join

CHAR_LIST = ["$", "{", "}"]


def export_along(
self,
Expand Down Expand Up @@ -147,8 +149,13 @@ def export_along(
+ axes_list_new[1].unit
+ "]"
)
second_line = np.insert(
results[axes_list_new[1].name].astype("object"), 0, A2_cell
second_line = format_matrix(
np.insert(
results[axes_list_new[1].name].astype("str"),
0,
A2_cell,
),
CHAR_LIST,
)
csvWriter.writerow(second_line)

Expand All @@ -161,8 +168,19 @@ def export_along(
field = np.take(results[self.symbol], i, axis=2)
else:
field = results[self.symbol]
matrix = np.column_stack((results[axes_list_new[0].name].T, field))
matrix = format_matrix(
np.column_stack((results[axes_list_new[0].name].T, field)).astype(
"str"
),
CHAR_LIST,
)
csvWriter.writerows(matrix)

else:
raise Exception("export format not supported")


def format_matrix(a, char_list):
for char in char_list:
a = np.char.replace(a, char, "")
return a
28 changes: 27 additions & 1 deletion Tests/Validation/test_export.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from SciDataTool import DataTime, DataLinspace
from SciDataTool import DataTime, DataLinspace, Data1D
from Tests import save_validation_path
import numpy as np
from os.path import isfile, join
Expand Down Expand Up @@ -68,6 +68,32 @@ def test_export_3D():
assert isfile(join(save_validation_path, "B_r_withoutargs_z-1.0.csv"))


def test_export_latex():
"""Test export"""
X = DataLinspace(name="time", unit="s", initial=0, final=10, number=11)
Y = Data1D(
name="order",
unit="",
values=["H24 ($3f_{e}$)", "H48 ($6f_{e}$)"],
is_components=True,
)
field = np.zeros((11, 2))
Field = DataTime(
name="Airgap flux density",
symbol="B_r",
unit="T",
axes=[X, Y],
values=field,
)
Field.export_along(
"time",
"order",
save_path=save_validation_path,
file_name="B_r_Data3D_latex",
)


if __name__ == "__main__":
test_export_2D()
test_export_3D()
test_export_latex()

0 comments on commit 35d71bf

Please sign in to comment.