From 0443e4a00c3aba46d20bb494ee84e17cf8e4c778 Mon Sep 17 00:00:00 2001 From: Marieke Westendorp Date: Thu, 30 May 2024 11:29:00 +0200 Subject: [PATCH 1/2] pack: Implement an implied default compartment if the field is unset Closes #26 --- src/bentopy/pack/config.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/bentopy/pack/config.py b/src/bentopy/pack/config.py index b74aaac..a5c6ff9 100644 --- a/src/bentopy/pack/config.py +++ b/src/bentopy/pack/config.py @@ -4,6 +4,8 @@ from .segment import Segment from .space import Space +DEFAULT_COMPARTMENT_ID = "main" + class Configuration: def __init__( @@ -16,20 +18,31 @@ def __init__( ): config = json.loads(json_src) space = config["space"] + compartments = space.get("compartments") self.space = Space( space["size"], space["resolution"], - space["compartments"], + compartments or [{"id": DEFAULT_COMPARTMENT_ID, "shape": "cuboid"}], space.get("constraint"), ) segments = config["segments"] + # Verify that if `output.compartments` is unset, the `compartments` + # field is unset for every segment, as well. + if compartments is None: + assert all(s.get("compartments") is None for s in segments), """ + If no `compartments` are defined in the `space` section, + compartment selections in segment definitions are not allowed. + When no compartments are defined in the `space` section, a single + default compartment is implied. To set each segment's compartment + to the implied default compartment, remove the `compartments` + field from all segment definitions.""" self.segments = [ Segment( s["name"], s["number"], s["path"], self.space.resolution, - s["compartments"], + s.get("compartments") or [DEFAULT_COMPARTMENT_ID], s.get("rotation_axes"), s.get("center"), ) From 4673fca3bf970a572a1ccb286134f7968099761b Mon Sep 17 00:00:00 2001 From: Marieke Westendorp Date: Thu, 30 May 2024 11:35:15 +0200 Subject: [PATCH 2/2] Update README to mention the implied default compartment Describes the change proposed in #26. --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index 3fdc450..d0332dc 100644 --- a/README.md +++ b/README.md @@ -225,6 +225,30 @@ at 50 nm. +
+Implied default compartment. + +If you omit the `"compartments"` field from the `"space"` section, and don't +set the `"compartments"` field in any of the segments in the `"segments"` +section, a single default compartment is implied. +This compartment is set up like this. + +```json + { + "id": "main", + "shape": "cuboid" + } +``` + +Each segment, when the compartment is implied, is assigned to that `"main"` +compartment. + +Note that when the `"compartments"` field on any segment is not set, its +compartment id will be set to `"main"`, even when a compartment is defined in +the `"space"` section. + +
+ #### Output In **output**, we set a **title** and **dir**ectory to write the placement list