Skip to content
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
32 changes: 15 additions & 17 deletions omf/fileio/fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
# ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

from __future__ import annotations

from pathlib import Path
import json
import struct
import uuid

from omf.base import UidModel
from omf.fileio.geoh5 import GeoH5Writer


__version__ = b"OMF-v0.9.0"

Expand Down Expand Up @@ -47,24 +45,24 @@ class OMFWriter:
in the binary blob.
"""

def __init__(self, project: UidModel, fname: str, compression: int = 5):
def __init__(self, project: UidModel, fname: str):
"""Project serialization is performed on OMFWriter init

Binary data is written during project serialization
"""

if fname.endswith(".geoh5"):
GeoH5Writer(project, fname, compression=compression)
else:
if not fname.endswith(".omf"):
fname = fname + ".omf"

self.fname = fname
with open(fname, "wb") as fopen:
self.initialize_header(fopen, project.uid)
self.project_json = project.serialize(open_file=fopen)
self.update_header(fopen)
fopen.write(json.dumps(self.project_json).encode("utf-8"))
file_name = Path(fname)
if not file_name.suffix:
file_name.with_suffix(".omf")

Comment thread
domfournier marked this conversation as resolved.
if file_name.suffix != ".omf":
raise ValueError("OMFWriter only supports .omf file extensions.")

self.fname = file_name
with open(file_name, "wb") as fopen:
self.initialize_header(fopen, project.uid)
self.project_json = project.serialize(open_file=fopen)
Comment thread
domfournier marked this conversation as resolved.
self.update_header(fopen)
fopen.write(json.dumps(self.project_json).encode("utf-8"))

@staticmethod
def initialize_header(fopen, uid):
Expand Down
Loading
Loading