We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Allow explicitly setting a layer's bounding box
For example, when one cuts data away and knows that the bounding box needs to be shrunken, there is no way of setting the box explicitly with the api.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `wkcuber/api/Layer.py`
Content:
```
1 from shutil import rmtree
2 from os.path import join
3 from os import makedirs
4 from wkw import wkw
5 
6 from wkcuber.api.MagDataset import (
7     MagDataset,
8     WKMagDataset,
9     TiffMagDataset,
10     TiledTiffMagDataset,
11 )
12 from wkcuber.mag import Mag
13 from wkcuber.utils import DEFAULT_WKW_FILE_LEN
14 
15 
16 class Layer:
17 
18     COLOR_TYPE = "color"
19     SEGMENTATION_TYPE = "segmentation"
20 
21     def __init__(self, name, dataset, dtype, num_channels):
22         self.name = name
23         self.dataset = dataset
24         self.dtype = dtype
25         self.num_channels = num_channels
26         self.mags = {}
27 
28         full_path = join(dataset.path, name)
29         makedirs(full_path, exist_ok=True)
30 
31     def get_mag(self, mag) -> MagDataset:
32         mag = Mag(mag).to_layer_name()
33         if mag not in self.mags.keys():
34             raise IndexError("The mag {} is not a mag of this layer".format(mag))
35         return self.mags[mag]
36 
37     def delete_mag(self, mag):
38         mag = Mag(mag).to_layer_name()
39         if mag not in self.mags.keys():
40             raise IndexError(
41                 "Deleting mag {} failed. There is no mag with this name".format(mag)
42             )
43 
44         del self.mags[mag]
45         self.dataset.properties._delete_mag(self.name, mag)
46         # delete files on disk
47         full_path = join(self.dataset.path, self.name, mag)
48         rmtree(full_path)
49 
50     def _create_dir_for_mag(self, mag):
51         mag = Mag(mag).to_layer_name()
52         full_path = join(self.dataset.path, self.name, mag)
53         makedirs(full_path, exist_ok=True)
54 
55     def _assert_mag_does_not_exist_yet(self, mag):
56         mag = Mag(mag).to_layer_name()
57         if mag in self.mags.keys():
58             raise IndexError(
59                 "Adding mag {} failed. There is already a mag with this name".format(
60                     mag
61                 )
62             )
63 
64 
65 class WKLayer(Layer):
66     def add_mag(
67         self, mag, block_len=None, file_len=None, block_type=None
68     ) -> WKMagDataset:
69         if block_len is None:
70             block_len = 32
71         if file_len is None:
72             file_len = DEFAULT_WKW_FILE_LEN
73         if block_type is None:
74             block_type = wkw.Header.BLOCK_TYPE_RAW
75 
76         # normalize the name of the mag
77         mag = Mag(mag).to_layer_name()
78 
79         self._assert_mag_does_not_exist_yet(mag)
80         self._create_dir_for_mag(mag)
81 
82         self.mags[mag] = WKMagDataset.create(self, mag, block_len, file_len, block_type)
83         self.dataset.properties._add_mag(self.name, mag, block_len * file_len)
84 
85         return self.mags[mag]
86 
87     def get_or_add_mag(
88         self, mag, block_len=None, file_len=None, block_type=None
89     ) -> WKMagDataset:
90         # normalize the name of the mag
91         mag = Mag(mag).to_layer_name()
92 
93         if mag in self.mags.keys():
94             assert (
95                 block_len is None or self.mags[mag].header.block_len == block_len
96             ), f"Cannot get_or_add_mag: The mag {mag} already exists, but the block lengths do not match"
97             assert (
98                 file_len is None or self.mags[mag].header.file_len == file_len
99             ), f"Cannot get_or_add_mag: The mag {mag} already exists, but the file lengths do not match"
100             assert (
101                 block_type is None or self.mags[mag].header.block_type == block_type
102             ), f"Cannot get_or_add_mag: The mag {mag} already exists, but the block types do not match"
103             return self.get_mag(mag)
104         else:
105             return self.add_mag(mag, block_len, file_len, block_type)
106 
107     def setup_mag(self, mag):
108         # This method is used to initialize the mag when opening the Dataset. This does not create e.g. the wk_header.
109 
110         # normalize the name of the mag
111         mag = Mag(mag).to_layer_name()
112 
113         self._assert_mag_does_not_exist_yet(mag)
114 
115         with wkw.Dataset.open(join(self.dataset.path, self.name, mag)) as wkw_dataset:
116             wk_header = wkw_dataset.header
117 
118         self.mags[mag] = WKMagDataset(
119             self, mag, wk_header.block_len, wk_header.file_len, wk_header.block_type
120         )
121         self.dataset.properties._add_mag(
122             self.name, mag, wk_header.block_len * wk_header.file_len
123         )
124 
125 
126 class TiffLayer(Layer):
127     def add_mag(self, mag) -> MagDataset:
128         # normalize the name of the mag
129         mag = Mag(mag).to_layer_name()
130 
131         self._assert_mag_does_not_exist_yet(mag)
132         self._create_dir_for_mag(mag)
133 
134         self.mags[mag] = self._get_mag_dataset_class().create(
135             self, mag, self.dataset.properties.pattern
136         )
137         self.dataset.properties._add_mag(self.name, mag)
138 
139         return self.mags[mag]
140 
141     def get_or_add_mag(self, mag) -> MagDataset:
142         # normalize the name of the mag
143         mag = Mag(mag).to_layer_name()
144 
145         if mag in self.mags.keys():
146             return self.get_mag(mag)
147         else:
148             return self.add_mag(mag)
149 
150     def setup_mag(self, mag):
151         # This method is used to initialize the mag when opening the Dataset. This does not create e.g. folders.
152 
153         # normalize the name of the mag
154         mag = Mag(mag).to_layer_name()
155 
156         self._assert_mag_does_not_exist_yet(mag)
157 
158         self.mags[mag] = self._get_mag_dataset_class()(
159             self, mag, self.dataset.properties.pattern
160         )
161         self.dataset.properties._add_mag(self.name, mag)
162 
163     def _get_mag_dataset_class(self):
164         return TiffMagDataset
165 
166 
167 class TiledTiffLayer(TiffLayer):
168     def _get_mag_dataset_class(self):
169         return TiledTiffMagDataset
170
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/wkcuber/api/Layer.py b/wkcuber/api/Layer.py
--- a/wkcuber/api/Layer.py
+++ b/wkcuber/api/Layer.py
@@ -1,6 +1,10 @@
 from shutil import rmtree
 from os.path import join
 from os import makedirs
+from typing import Tuple
+
+import numpy as np
+
 from wkw import wkw
 
 from wkcuber.api.MagDataset import (
@@ -61,6 +65,28 @@
                 )
             )
 
+    def set_bounding_box(
+        self, offset: Tuple[int, int, int], size: Tuple[int, int, int]
+    ):
+        self.set_bounding_box_offset(offset)
+        self.set_bounding_box_size(size)
+
+    def set_bounding_box_offset(self, offset: Tuple[int, int, int]):
+        size = self.dataset.properties.data_layers["color"].get_bounding_box_size()
+        self.dataset.properties._set_bounding_box_of_layer(
+            self.name, tuple(offset), tuple(size)
+        )
+        for _, mag in self.mags.items():
+            mag.view.global_offset = offset
+
+    def set_bounding_box_size(self, size: Tuple[int, int, int]):
+        offset = self.dataset.properties.data_layers["color"].get_bounding_box_offset()
+        self.dataset.properties._set_bounding_box_of_layer(
+            self.name, tuple(offset), tuple(size)
+        )
+        for _, mag in self.mags.items():
+            mag.view.size = size
+
 
 class WKLayer(Layer):
     def add_mag(

{"golden_diff": "diff --git a/wkcuber/api/Layer.py b/wkcuber/api/Layer.py\n--- a/wkcuber/api/Layer.py\n+++ b/wkcuber/api/Layer.py\n@@ -1,6 +1,10 @@\n from shutil import rmtree\n from os.path import join\n from os import makedirs\n+from typing import Tuple\n+\n+import numpy as np\n+\n from wkw import wkw\n \n from wkcuber.api.MagDataset import (\n@@ -61,6 +65,28 @@\n                 )\n             )\n \n+    def set_bounding_box(\n+        self, offset: Tuple[int, int, int], size: Tuple[int, int, int]\n+    ):\n+        self.set_bounding_box_offset(offset)\n+        self.set_bounding_box_size(size)\n+\n+    def set_bounding_box_offset(self, offset: Tuple[int, int, int]):\n+        size = self.dataset.properties.data_layers[\"color\"].get_bounding_box_size()\n+        self.dataset.properties._set_bounding_box_of_layer(\n+            self.name, tuple(offset), tuple(size)\n+        )\n+        for _, mag in self.mags.items():\n+            mag.view.global_offset = offset\n+\n+    def set_bounding_box_size(self, size: Tuple[int, int, int]):\n+        offset = self.dataset.properties.data_layers[\"color\"].get_bounding_box_offset()\n+        self.dataset.properties._set_bounding_box_of_layer(\n+            self.name, tuple(offset), tuple(size)\n+        )\n+        for _, mag in self.mags.items():\n+            mag.view.size = size\n+\n \n class WKLayer(Layer):\n     def add_mag(\n", "issue": "Allow explicitly setting a layer's bounding box\nFor example, when one cuts data away and knows that the bounding box needs to be shrunken, there is no way of setting the box explicitly with the api.\n", "before_files": [{"content": "from shutil import rmtree\nfrom os.path import join\nfrom os import makedirs\nfrom wkw import wkw\n\nfrom wkcuber.api.MagDataset import (\n    MagDataset,\n    WKMagDataset,\n    TiffMagDataset,\n    TiledTiffMagDataset,\n)\nfrom wkcuber.mag import Mag\nfrom wkcuber.utils import DEFAULT_WKW_FILE_LEN\n\n\nclass Layer:\n\n    COLOR_TYPE = \"color\"\n    SEGMENTATION_TYPE = \"segmentation\"\n\n    def __init__(self, name, dataset, dtype, num_channels):\n        self.name = name\n        self.dataset = dataset\n        self.dtype = dtype\n        self.num_channels = num_channels\n        self.mags = {}\n\n        full_path = join(dataset.path, name)\n        makedirs(full_path, exist_ok=True)\n\n    def get_mag(self, mag) -> MagDataset:\n        mag = Mag(mag).to_layer_name()\n        if mag not in self.mags.keys():\n            raise IndexError(\"The mag {} is not a mag of this layer\".format(mag))\n        return self.mags[mag]\n\n    def delete_mag(self, mag):\n        mag = Mag(mag).to_layer_name()\n        if mag not in self.mags.keys():\n            raise IndexError(\n                \"Deleting mag {} failed. There is no mag with this name\".format(mag)\n            )\n\n        del self.mags[mag]\n        self.dataset.properties._delete_mag(self.name, mag)\n        # delete files on disk\n        full_path = join(self.dataset.path, self.name, mag)\n        rmtree(full_path)\n\n    def _create_dir_for_mag(self, mag):\n        mag = Mag(mag).to_layer_name()\n        full_path = join(self.dataset.path, self.name, mag)\n        makedirs(full_path, exist_ok=True)\n\n    def _assert_mag_does_not_exist_yet(self, mag):\n        mag = Mag(mag).to_layer_name()\n        if mag in self.mags.keys():\n            raise IndexError(\n                \"Adding mag {} failed. There is already a mag with this name\".format(\n                    mag\n                )\n            )\n\n\nclass WKLayer(Layer):\n    def add_mag(\n        self, mag, block_len=None, file_len=None, block_type=None\n    ) -> WKMagDataset:\n        if block_len is None:\n            block_len = 32\n        if file_len is None:\n            file_len = DEFAULT_WKW_FILE_LEN\n        if block_type is None:\n            block_type = wkw.Header.BLOCK_TYPE_RAW\n\n        # normalize the name of the mag\n        mag = Mag(mag).to_layer_name()\n\n        self._assert_mag_does_not_exist_yet(mag)\n        self._create_dir_for_mag(mag)\n\n        self.mags[mag] = WKMagDataset.create(self, mag, block_len, file_len, block_type)\n        self.dataset.properties._add_mag(self.name, mag, block_len * file_len)\n\n        return self.mags[mag]\n\n    def get_or_add_mag(\n        self, mag, block_len=None, file_len=None, block_type=None\n    ) -> WKMagDataset:\n        # normalize the name of the mag\n        mag = Mag(mag).to_layer_name()\n\n        if mag in self.mags.keys():\n            assert (\n                block_len is None or self.mags[mag].header.block_len == block_len\n            ), f\"Cannot get_or_add_mag: The mag {mag} already exists, but the block lengths do not match\"\n            assert (\n                file_len is None or self.mags[mag].header.file_len == file_len\n            ), f\"Cannot get_or_add_mag: The mag {mag} already exists, but the file lengths do not match\"\n            assert (\n                block_type is None or self.mags[mag].header.block_type == block_type\n            ), f\"Cannot get_or_add_mag: The mag {mag} already exists, but the block types do not match\"\n            return self.get_mag(mag)\n        else:\n            return self.add_mag(mag, block_len, file_len, block_type)\n\n    def setup_mag(self, mag):\n        # This method is used to initialize the mag when opening the Dataset. This does not create e.g. the wk_header.\n\n        # normalize the name of the mag\n        mag = Mag(mag).to_layer_name()\n\n        self._assert_mag_does_not_exist_yet(mag)\n\n        with wkw.Dataset.open(join(self.dataset.path, self.name, mag)) as wkw_dataset:\n            wk_header = wkw_dataset.header\n\n        self.mags[mag] = WKMagDataset(\n            self, mag, wk_header.block_len, wk_header.file_len, wk_header.block_type\n        )\n        self.dataset.properties._add_mag(\n            self.name, mag, wk_header.block_len * wk_header.file_len\n        )\n\n\nclass TiffLayer(Layer):\n    def add_mag(self, mag) -> MagDataset:\n        # normalize the name of the mag\n        mag = Mag(mag).to_layer_name()\n\n        self._assert_mag_does_not_exist_yet(mag)\n        self._create_dir_for_mag(mag)\n\n        self.mags[mag] = self._get_mag_dataset_class().create(\n            self, mag, self.dataset.properties.pattern\n        )\n        self.dataset.properties._add_mag(self.name, mag)\n\n        return self.mags[mag]\n\n    def get_or_add_mag(self, mag) -> MagDataset:\n        # normalize the name of the mag\n        mag = Mag(mag).to_layer_name()\n\n        if mag in self.mags.keys():\n            return self.get_mag(mag)\n        else:\n            return self.add_mag(mag)\n\n    def setup_mag(self, mag):\n        # This method is used to initialize the mag when opening the Dataset. This does not create e.g. folders.\n\n        # normalize the name of the mag\n        mag = Mag(mag).to_layer_name()\n\n        self._assert_mag_does_not_exist_yet(mag)\n\n        self.mags[mag] = self._get_mag_dataset_class()(\n            self, mag, self.dataset.properties.pattern\n        )\n        self.dataset.properties._add_mag(self.name, mag)\n\n    def _get_mag_dataset_class(self):\n        return TiffMagDataset\n\n\nclass TiledTiffLayer(TiffLayer):\n    def _get_mag_dataset_class(self):\n        return TiledTiffMagDataset\n", "path": "wkcuber/api/Layer.py"}], "after_files": [{"content": "from shutil import rmtree\nfrom os.path import join\nfrom os import makedirs\nfrom typing import Tuple\n\nimport numpy as np\n\nfrom wkw import wkw\n\nfrom wkcuber.api.MagDataset import (\n    MagDataset,\n    WKMagDataset,\n    TiffMagDataset,\n    TiledTiffMagDataset,\n)\nfrom wkcuber.mag import Mag\nfrom wkcuber.utils import DEFAULT_WKW_FILE_LEN\n\n\nclass Layer:\n\n    COLOR_TYPE = \"color\"\n    SEGMENTATION_TYPE = \"segmentation\"\n\n    def __init__(self, name, dataset, dtype, num_channels):\n        self.name = name\n        self.dataset = dataset\n        self.dtype = dtype\n        self.num_channels = num_channels\n        self.mags = {}\n\n        full_path = join(dataset.path, name)\n        makedirs(full_path, exist_ok=True)\n\n    def get_mag(self, mag) -> MagDataset:\n        mag = Mag(mag).to_layer_name()\n        if mag not in self.mags.keys():\n            raise IndexError(\"The mag {} is not a mag of this layer\".format(mag))\n        return self.mags[mag]\n\n    def delete_mag(self, mag):\n        mag = Mag(mag).to_layer_name()\n        if mag not in self.mags.keys():\n            raise IndexError(\n                \"Deleting mag {} failed. There is no mag with this name\".format(mag)\n            )\n\n        del self.mags[mag]\n        self.dataset.properties._delete_mag(self.name, mag)\n        # delete files on disk\n        full_path = join(self.dataset.path, self.name, mag)\n        rmtree(full_path)\n\n    def _create_dir_for_mag(self, mag):\n        mag = Mag(mag).to_layer_name()\n        full_path = join(self.dataset.path, self.name, mag)\n        makedirs(full_path, exist_ok=True)\n\n    def _assert_mag_does_not_exist_yet(self, mag):\n        mag = Mag(mag).to_layer_name()\n        if mag in self.mags.keys():\n            raise IndexError(\n                \"Adding mag {} failed. There is already a mag with this name\".format(\n                    mag\n                )\n            )\n\n    def set_bounding_box(\n        self, offset: Tuple[int, int, int], size: Tuple[int, int, int]\n    ):\n        self.set_bounding_box_offset(offset)\n        self.set_bounding_box_size(size)\n\n    def set_bounding_box_offset(self, offset: Tuple[int, int, int]):\n        size = self.dataset.properties.data_layers[\"color\"].get_bounding_box_size()\n        self.dataset.properties._set_bounding_box_of_layer(\n            self.name, tuple(offset), tuple(size)\n        )\n        for _, mag in self.mags.items():\n            mag.view.global_offset = offset\n\n    def set_bounding_box_size(self, size: Tuple[int, int, int]):\n        offset = self.dataset.properties.data_layers[\"color\"].get_bounding_box_offset()\n        self.dataset.properties._set_bounding_box_of_layer(\n            self.name, tuple(offset), tuple(size)\n        )\n        for _, mag in self.mags.items():\n            mag.view.size = size\n\n\nclass WKLayer(Layer):\n    def add_mag(\n        self, mag, block_len=None, file_len=None, block_type=None\n    ) -> WKMagDataset:\n        if block_len is None:\n            block_len = 32\n        if file_len is None:\n            file_len = DEFAULT_WKW_FILE_LEN\n        if block_type is None:\n            block_type = wkw.Header.BLOCK_TYPE_RAW\n\n        # normalize the name of the mag\n        mag = Mag(mag).to_layer_name()\n\n        self._assert_mag_does_not_exist_yet(mag)\n        self._create_dir_for_mag(mag)\n\n        self.mags[mag] = WKMagDataset.create(self, mag, block_len, file_len, block_type)\n        self.dataset.properties._add_mag(self.name, mag, block_len * file_len)\n\n        return self.mags[mag]\n\n    def get_or_add_mag(\n        self, mag, block_len=None, file_len=None, block_type=None\n    ) -> WKMagDataset:\n        # normalize the name of the mag\n        mag = Mag(mag).to_layer_name()\n\n        if mag in self.mags.keys():\n            assert (\n                block_len is None or self.mags[mag].header.block_len == block_len\n            ), f\"Cannot get_or_add_mag: The mag {mag} already exists, but the block lengths do not match\"\n            assert (\n                file_len is None or self.mags[mag].header.file_len == file_len\n            ), f\"Cannot get_or_add_mag: The mag {mag} already exists, but the file lengths do not match\"\n            assert (\n                block_type is None or self.mags[mag].header.block_type == block_type\n            ), f\"Cannot get_or_add_mag: The mag {mag} already exists, but the block types do not match\"\n            return self.get_mag(mag)\n        else:\n            return self.add_mag(mag, block_len, file_len, block_type)\n\n    def setup_mag(self, mag):\n        # This method is used to initialize the mag when opening the Dataset. This does not create e.g. the wk_header.\n\n        # normalize the name of the mag\n        mag = Mag(mag).to_layer_name()\n\n        self._assert_mag_does_not_exist_yet(mag)\n\n        with wkw.Dataset.open(join(self.dataset.path, self.name, mag)) as wkw_dataset:\n            wk_header = wkw_dataset.header\n\n        self.mags[mag] = WKMagDataset(\n            self, mag, wk_header.block_len, wk_header.file_len, wk_header.block_type\n        )\n        self.dataset.properties._add_mag(\n            self.name, mag, wk_header.block_len * wk_header.file_len\n        )\n\n\nclass TiffLayer(Layer):\n    def add_mag(self, mag) -> MagDataset:\n        # normalize the name of the mag\n        mag = Mag(mag).to_layer_name()\n\n        self._assert_mag_does_not_exist_yet(mag)\n        self._create_dir_for_mag(mag)\n\n        self.mags[mag] = self._get_mag_dataset_class().create(\n            self, mag, self.dataset.properties.pattern\n        )\n        self.dataset.properties._add_mag(self.name, mag)\n\n        return self.mags[mag]\n\n    def get_or_add_mag(self, mag) -> MagDataset:\n        # normalize the name of the mag\n        mag = Mag(mag).to_layer_name()\n\n        if mag in self.mags.keys():\n            return self.get_mag(mag)\n        else:\n            return self.add_mag(mag)\n\n    def setup_mag(self, mag):\n        # This method is used to initialize the mag when opening the Dataset. This does not create e.g. folders.\n\n        # normalize the name of the mag\n        mag = Mag(mag).to_layer_name()\n\n        self._assert_mag_does_not_exist_yet(mag)\n\n        self.mags[mag] = self._get_mag_dataset_class()(\n            self, mag, self.dataset.properties.pattern\n        )\n        self.dataset.properties._add_mag(self.name, mag)\n\n    def _get_mag_dataset_class(self):\n        return TiffMagDataset\n\n\nclass TiledTiffLayer(TiffLayer):\n    def _get_mag_dataset_class(self):\n        return TiledTiffMagDataset\n", "path": "wkcuber/api/Layer.py"}]}