Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ratapi/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def __str__(self) -> str:
def initialise_IPC(self):
"""Set up the inter-process communication file."""
IPC_obj, self._IPCFilePath = tempfile.mkstemp()
os.write(IPC_obj, b"0")
os.write(IPC_obj, b"\x00")
os.close(IPC_obj)
return None

Expand All @@ -221,7 +221,7 @@ def sendStopEvent(self):
"""
if os.path.isfile(self._IPCFilePath):
with open(self._IPCFilePath, "wb") as f:
f.write(b"1")
f.write(b"\x01")
else:
warnings.warn("An IPC file was not initialised.", UserWarning, stacklevel=2)
return None
Expand All @@ -230,6 +230,7 @@ def delete_IPC(self):
"""Delete the inter-process communication file."""
with contextlib.suppress(FileNotFoundError):
os.remove(self._IPCFilePath)
self._IPCFilePath = ""
return None

def save(self, filepath: str | Path = "./controls.json"):
Expand Down
9 changes: 8 additions & 1 deletion ratapi/utils/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,14 @@ def fix_invalid_constraints(name: str, constrs: tuple[float, float], value: floa
if Path(custom_filepath).suffix != ".m":
custom_filepath += ".m"
model_name = Path(custom_filepath).stem
custom_file = ClassList([CustomFile(name=model_name, filename=custom_filepath, language=Languages.Matlab)])
# Assume the custom file is in the same directory as the mat file
custom_file = ClassList(
[
CustomFile(
name=model_name, filename=custom_filepath, language=Languages.Matlab, path=Path(filename).parent
)
]
)
layers = ClassList()
for contrast in contrasts:
contrast.model = [model_name]
Expand Down
3 changes: 2 additions & 1 deletion ratapi/utils/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,8 @@ def update_plot(self, data):
"""
if self.figure is not None:
self.figure.clf()

self.figure.tight_layout()
plot_ref_sld_helper(
data,
self.figure,
Expand All @@ -502,7 +504,6 @@ def update_plot(self, data):
show_legend=self.show_legend,
animated=True,
)
self.figure.tight_layout(pad=1)
self.figure.canvas.draw()
self.bg = self.figure.canvas.copy_from_bbox(self.figure.bbox)
for line in self.figure.axes[0].lines:
Expand Down
6 changes: 5 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6858,7 +6858,11 @@ def r1_monolayer():
),
custom_files=ratapi.ClassList(
ratapi.models.CustomFile(
name="Model_IIb", filename="Model_IIb.m", function_name="Model_IIb", language="matlab"
name="Model_IIb",
filename="Model_IIb.m",
function_name="Model_IIb",
language="matlab",
path=Path(__file__).parent / "test_data",
)
),
)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ def test_initialise_IPC() -> None:
assert test_controls._IPCFilePath != ""
with open(test_controls._IPCFilePath, "rb") as f:
file_content = f.read()
assert file_content == b"0"
assert file_content == b"\x00"
os.remove(test_controls._IPCFilePath)


Expand All @@ -900,7 +900,7 @@ def test_sendStopEvent(IPC_controls) -> None:
IPC_controls.sendStopEvent()
with open(IPC_controls._IPCFilePath, "rb") as f:
file_content = f.read()
assert file_content == b"1"
assert file_content == b"\x01"


def test_sendStopEvent_empty_file() -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def mock_load(ignored_filename, **ignored_settings):

monkeypatch.setattr("ratapi.utils.convert.loadmat", mock_load, raising=True)

converted_project = r1_to_project(project)
converted_project = r1_to_project(pathlib.Path(__file__).parent / "test_data" / project)

for class_list in ratapi.project.class_lists:
assert getattr(converted_project, class_list) == getattr(original_project, class_list)
Expand Down
Loading