Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow reading projects with image path that doesn't exist. #67

Merged
merged 1 commit into from
Mar 10, 2024
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
1 change: 1 addition & 0 deletions cylindra/components/tomogram/_cyl_tomo.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ def dummy(

@property
def is_dummy(self) -> bool:
"""True if this tomogram object does not have a real image."""
return self.metadata.get("is_dummy", False)

def add_spline(
Expand Down
27 changes: 19 additions & 8 deletions cylindra/project/_single.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ def _to_gui(

@thread_worker.callback
def _update_widget():
gui._reserved_layers.image.bounding_box.visible = not read_image
if len(tomogram.splines) > 0:
gui._update_splines_in_images()
with gui.macro.blocked():
Expand Down Expand Up @@ -400,13 +399,25 @@ def load_tomogram(
from cylindra.components import CylTomogram

if self.image is not None:
tomo = CylTomogram.imread(
path=self.image,
scale=self.scale,
tilt=self.missing_wedge.as_param(),
binsize=self.multiscales,
compute=compute,
)
if self.image.exists():
tomo = CylTomogram.imread(
path=self.image,
scale=self.scale,
tilt=self.missing_wedge.as_param(),
binsize=self.multiscales,
compute=compute,
)
else:
warnings.warn(
f"Cannot find image file {self.image}. Load other components only.",
UserWarning,
stacklevel=2,
)
tomo = CylTomogram.dummy(
scale=self.scale,
tilt=self.missing_wedge.as_param(),
binsize=self.multiscales,
)
else:
tomo = CylTomogram.dummy(
scale=self.scale,
Expand Down
2 changes: 2 additions & 0 deletions cylindra/project/_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ def _from_project(self, project: "CylindraProject", dir: Path):
self.components._add_layer(layer, info.visible)

# draw edge
if project.image is None or not project.image.exists():
return
img = ip.lazy.imread(project.image)
nz, ny, nx = img.shape
for z in [0, nz]:
Expand Down
3 changes: 3 additions & 0 deletions cylindra/widgets/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,8 @@ def filter_reference_image(
): # fmt: skip
"""Apply filter to enhance contrast of the reference image."""
method = ImageFilter(method)
if self.tomogram.is_dummy:
return
with utils.set_gpu():
img = self._reserved_layers.image_data
overlap = [min(s, 32) for s in img.shape]
Expand Down Expand Up @@ -2527,6 +2529,7 @@ def _send_tomogram_to_viewer(
self._reserved_layers.update_image(imgb, bin_size, tr)
if self._reserved_layers.highlight in viewer.layers:
viewer.layers.remove(self._reserved_layers.highlight)
self._reserved_layers.image.bounding_box.visible = _is_lazy

self.GeneralInfo._refer_tomogram(tomo)

Expand Down
7 changes: 5 additions & 2 deletions cylindra/widgets/subwidgets/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ def _prep_radon(
mole = main.mole_layers[layer_name].molecules
simulator.add_molecules(mole, pipe.from_file(temp_path))
tilt_series = simulator.simulate_tilt_series(degrees=degrees, shape=shape)
tilt_series = ip.asarray(tilt_series, axes=["degree", "y", "x"])
tilt_series = ip.asarray(
tilt_series, axes=["degree", "y", "x"], name="Simulated"
)
return tilt_series.set_scale(y=scale, x=scale)

def _get_proper_molecules_layers(self, *_):
Expand Down Expand Up @@ -277,7 +279,8 @@ def create_empty_image(
tomo = CylTomogram.from_image(img, scale=scale, binsize=binsize)
tomo.metadata["is_dummy"] = True
main._macro_offset = len(main.macro)
return main._send_tomogram_to_viewer.with_args(tomo)
yield main._send_tomogram_to_viewer.with_args(tomo)
main._reserved_layers.image.bounding_box.visible = True

@set_design(text=capitalize, location=CreateMenu)
def create_straight_line(
Expand Down
5 changes: 4 additions & 1 deletion cylindra/widgets/subwidgets/spline_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ def _load_projection(self, spl: "CylSpline"):
# update plots in pyqtgraph, if properties exist
parent.LocalProperties._plot_properties(spl)

if tomo.is_dummy:
return

# calculate projection
anc = spl.anchors
if (npfs := spl.props.get_loc(H.npf, None)) is not None:
Expand Down Expand Up @@ -254,7 +257,7 @@ def _update_canvas(self, pos: int | None = None, num: int | None = None):
pos = self.pos

if not self._projections or num is None or pos is None:
return self._clear_all_layers
return self._clear_all_layers()
if num >= len(tomo.splines):
return

Expand Down
Loading