Skip to content

Commit

Permalink
fix: identifiers not computed for qpformat files
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Jul 30, 2018
1 parent 995fc2d commit 404a314
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
0.3.3
- fix: qpimage file formats: identifiers were not unique, but simply
copied from the input hdf5 file
0.3.2
- setup: add qpimage version dependency
0.3.1
Expand Down
8 changes: 7 additions & 1 deletion qpformat/file_formats/series_hdf5_qpimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ def _qpseries(self):

@property
def identifier(self):
# Qpformat generates a new identifier that also depends on the given
# keyword arguments. Thus, the identifiers of source and modified
# dataset must not be identical.
with self._qpseries() as qps:
identifier = qps.identifier
if identifier is None:
identifier = super(SeriesHdf5Qpimage, self).identifier
identifier = ""
else:
identifier += "_"
identifier += super(SeriesHdf5Qpimage, self).identifier
return identifier

def get_identifier(self, idx):
Expand Down
7 changes: 6 additions & 1 deletion qpformat/file_formats/single_hdf5_qpimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ class SingleHdf5Qpimage(SingleData):

@property
def identifier(self):
# Qpformat generates a new identifier that also depends on the given
# keyword arguments. Thus, the identifiers of source and modified
# dataset must not be identical.
with qpimage.QPImage(h5file=self.path, h5mode="r") as qpi:
if "identifier" in qpi:
identifier = qpi["identifier"]
else:
identifier = super(SingleHdf5Qpimage, self).identifier
identifier = ""
identifier += "_"
identifier += super(SingleHdf5Qpimage, self).identifier
return identifier

def get_identifier(self, idx=0):
Expand Down
5 changes: 4 additions & 1 deletion tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ def test_save():
# load h5
ds2 = qpformat.load_data(path=save_path)

assert ds.identifier == ds2.identifier
assert ds.identifier is not None
# Qpformat generates a new identifier that also depends on the given
# keyword arguments. Thus, the identifiers are not identical.
assert ds.identifier in ds2.identifier
assert len(ds) == len(ds2)
assert np.all(ds.get_qpimage(0).pha == ds2.get_qpimage(0).pha)

Expand Down
4 changes: 3 additions & 1 deletion tests/test_single_hdf5_qpimage.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def test_identifier():
ds2 = qpformat.load_data(tf)

assert ds1.identifier != ds2.identifier
assert ds2.identifier == "an extremely important string"
# Qpformat generates a new identifier that also depends on the given
# keyword arguments. Thus, the identifiers are not identical.
assert "an extremely important string" in ds2.identifier
assert ds1.identifier == ds1.get_identifier()
assert ds2.identifier == ds2.get_identifier()

Expand Down

0 comments on commit 404a314

Please sign in to comment.