Skip to content

Commit

Permalink
fix: CIPHERGeometry.to_zarr when writing a zip file
Browse files Browse the repository at this point in the history
  • Loading branch information
aplowman committed Apr 2, 2024
1 parent d44285e commit 769c000
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions cipher_parse/cipher_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def from_JSON_file(cls, path):
data = json.load(fp)
return cls.from_JSON(data)

def to_zarr(self, path):
def to_zarr(self, path, overwrite=False):
"""Save to a persistent zarr store.
This does not yet save `geometries`.
Expand All @@ -455,18 +455,25 @@ def to_zarr(self, path):
out_group.create_dataset(
name="stdout_file_str",
data=self.stdout_file_str.splitlines(),
overwrite=overwrite,
)
out_group.create_dataset(
name="input_YAML_file_str",
data=self.input_YAML_file_str.splitlines(),
overwrite=overwrite,
)
inc_dat_group = out_group.create_group("incremental_data", overwrite=True)
for idx, inc_dat_i in enumerate(self.incremental_data):
inc_dat_i_group = inc_dat_group.create_group(f"{idx}")
inc_dat_i_group.attrs.put({k: inc_dat_i[k] for k in INC_DATA_NON_ARRAYS})
for k in inc_dat_i:
if k not in INC_DATA_NON_ARRAYS:
inc_dat_i_group.create_dataset(name=k, data=inc_dat_i[k])
inc_dat_i_group.create_dataset(
name=k, data=inc_dat_i[k], overwrite=overwrite
)

if path.endswith(".zip"):
out_group.store.close()

return out_group

Expand All @@ -477,7 +484,7 @@ def from_zarr(cls, path, cipher_input=None, quiet=True):
This does not yet load `geometries`.
"""
group = zarr.open_group(store=path)
group = zarr.open_group(store=path, mode="r")
attrs = group.attrs.asdict()
kwargs = {
"directory": attrs["directory"],
Expand Down

0 comments on commit 769c000

Please sign in to comment.