Skip to content

Commit

Permalink
Allow reading with dataset_path alone
Browse files Browse the repository at this point in the history
  • Loading branch information
ka-sarthak committed Jan 14, 2025
1 parent 62569dd commit 6e47b5b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/nomad_measurements/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def add_dataset(
validate_path (bool): If True, the dataset path is validated.
"""
if not params:
self.logger.warning('Dataset `params` must be provided.')
self.logger.warning('Dataset `params` not provided.')
return

dataset = DatasetModel(
Expand Down Expand Up @@ -309,7 +309,7 @@ def add_attribute(
params (dict): The attributes to be added.
"""
if not params:
self.logger.warning('Attribute `params` must be provided.')
self.logger.warning('Attribute `params` not provided.')
return
self._hdf5_attributes[path] = params

Expand All @@ -324,7 +324,10 @@ def read_dataset(self, path: str):
"""
if path is None:
return
file_path, dataset_path = path.split('#')
if '#' not in path:
file_path, dataset_path = None, path
else:
file_path, dataset_path = path.rsplit('#', 1)

# find path in the instance variables
value = None
Expand All @@ -336,6 +339,8 @@ def read_dataset(self, path: str):
value *= ureg(units)
return value

if not file_path:
return
file_name = file_path.rsplit('/raw/', 1)[1]
with h5py.File(self.archive.m_context.raw_file(file_name, 'rb')) as h5:
if dataset_path not in h5:
Expand Down

0 comments on commit 6e47b5b

Please sign in to comment.