Skip to content

Commit d4052df

Browse files
committed
Enable creating, saving & showing empty result files
1 parent e7487b9 commit d4052df

File tree

3 files changed

+34
-46
lines changed

3 files changed

+34
-46
lines changed

saenopy/gui/solver/modules/exporter/ExportRenderCommon.py

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,15 @@ def get_mesh_arrows(params, result):
1919
return None, None, {}, ""
2020

2121

22-
def get_mesh_extent(params, result):
23-
if params["arrows"] == "piv":
24-
mesh = result.mesh_piv[params["time"]["t"]]
25-
if mesh is not None and mesh.displacements_measured is not None:
26-
return [mesh.nodes.min(axis=0) * 1e6, mesh.nodes.max(axis=0) * 1e6]
27-
elif params["arrows"] == "target deformations":
28-
M = result.solvers[params["time"]["t"]]
29-
if M is not None:
30-
return [M.mesh.nodes.min(axis=0) * 1e6, M.mesh.nodes.max(axis=0) * 1e6]
31-
elif params["arrows"] == "fitted deformations":
32-
M = result.solvers[params["time"]["t"]]
33-
if M is not None:
34-
return [M.mesh.nodes.min(axis=0) * 1e6, M.mesh.nodes.max(axis=0) * 1e6]
35-
elif params["arrows"] == "fitted forces":
36-
M = result.solvers[params["time"]["t"]]
37-
if M is not None:
38-
return [M.mesh.nodes.min(axis=0) * 1e6, M.mesh.nodes.max(axis=0) * 1e6]
22+
def get_mesh_extent(params, result):
23+
mesh, field = result.get_field_data(params["arrows"], params["time"]["t"])
24+
if mesh is None:
25+
return None
3926
else:
40-
M = result.solvers[params["time"]["t"]]
41-
if M is not None:
42-
return [M.mesh.nodes.min(axis=0) * 1e6, M.mesh.nodes.max(axis=0) * 1e6]
43-
else:
44-
M = result.mesh_piv[params["time"]["t"]]
45-
if M is not None:
46-
return [M.mesh.nodes.min(axis=0) * 1e6, M.mesh.nodes.max(axis=0) * 1e6]
47-
return None
27+
return [mesh.nodes.min(axis=0) * 1e6, mesh.nodes.max(axis=0) * 1e6]
28+
29+
30+
4831

4932

5033
def getVectorFieldImage(result, params, use_fixed_contrast_if_available=False, use_2D=False, exporter=None):

saenopy/gui/solver/modules/exporter/ExporterRender3D.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ def render_3d_fibers(params, result, plotter, exporter):
7272
t = params["time"]["t"]
7373
t_start = time.time()
7474
stack_data = None
75+
if len(result.stacks) == 0:
76+
return
7577
stack = result.stacks[t]
7678

7779
if params["stack"]["use_reference_stack"]:

saenopy/result_file.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ def apply_delete(obj_data, rename):
429429
data_dict["___save_version__"] = "1.4"
430430
return super().from_dict(data_dict)
431431

432-
def __init__(self, output=None, template=None, stack=None, time_delta=None, **kwargs):
432+
def __init__(self, output=None, template="", stack=None, time_delta=None, **kwargs):
433433
if output is not None:
434434
self.output = str(Path(output).absolute())
435435

@@ -551,11 +551,11 @@ def get_data_structure(self):
551551
"dimensions": 3,
552552
"time_point_count": len(self.stacks),
553553
"has_reference": self.stack_reference is not None,
554-
"z_slices_count": self.stacks[0].shape[2],
555-
"im_shape": self.stacks[0].shape,
556-
"voxel_size": self.stacks[0].voxel_size,
554+
"z_slices_count": self.stacks[0].shape[2] if self.stacks else 0,
555+
"im_shape": self.stacks[0].shape if self.stacks else (0,0,0),
556+
"voxel_size": self.stacks[0].voxel_size if self.stacks else (0,0,0),
557557
"time_delta": self.time_delta,
558-
"channels": self.stacks[0].channels,
558+
"channels": self.stacks[0].channels if self.stacks else [],
559559
"fields": {
560560
"piv": {
561561
"type": "vector",
@@ -599,20 +599,23 @@ def get_image_data(self, time_point, channel="default", use_reference=False):
599599
return stack[:, :, :, :, channel]
600600

601601
def get_field_data(result, name, time_point):
602-
if name == "piv":
603-
mesh = result.mesh_piv[time_point]
604-
if mesh is not None and mesh.displacements_measured is not None:
605-
return mesh, mesh.displacements_measured
606-
elif name == "target deformations":
607-
M = result.solvers[time_point]
608-
if M is not None:
609-
return M.mesh, M.mesh.displacements_target
610-
elif name == "fitted deformations":
611-
M = result.solvers[time_point]
612-
if M is not None:
613-
return M.mesh, M.mesh.displacements
614-
elif name == "fitted forces":
615-
M = result.solvers[time_point]
616-
if M is not None:
617-
return M.mesh, -M.mesh.forces * M.mesh.regularisation_mask[:, None]
602+
try:
603+
if name == "piv":
604+
mesh = result.mesh_piv[time_point]
605+
if mesh is not None and mesh.displacements_measured is not None:
606+
return mesh, mesh.displacements_measured
607+
elif name == "target deformations":
608+
M = result.solvers[time_point]
609+
if M is not None:
610+
return M.mesh, M.mesh.displacements_target
611+
elif name == "fitted deformations":
612+
M = result.solvers[time_point]
613+
if M is not None:
614+
return M.mesh, M.mesh.displacements
615+
elif name == "fitted forces":
616+
M = result.solvers[time_point]
617+
if M is not None:
618+
return M.mesh, -M.mesh.forces * M.mesh.regularisation_mask[:, None]
619+
except IndexError:
620+
return None, None
618621
return None, None

0 commit comments

Comments
 (0)