diff --git a/common/python/nomadcore/archive.py b/common/python/nomadcore/archive.py index ea652aa1c6c4c93f021b1737dfa1c3eaa64165f4..89fd939bbca7359deada4fbd3d2502f984b9986f 100644 --- a/common/python/nomadcore/archive.py +++ b/common/python/nomadcore/archive.py @@ -9,6 +9,12 @@ import h5py import numpy as np from abc import ABCMeta, abstractmethod from io import open +import re + +import logging + + +LOGGER = logging.getLogger(__name__) class ArchiveSection(object): @@ -656,17 +662,16 @@ class ArchiveSectionHDF5(ArchiveSection): # .format(child_path) # ) - index_rows = index_data[test_index] - # If the value can have multiple shapes, the values are split into # different tables. For each table there is a local index in the # second column of the index table that we must use. data = [] - for index_row in index_rows: + for row_i in test_index: + index_row = index_data[row_i] if index_row.shape != (1,): data_index = index_row[1] else: - data_index = test_index[0] + data_index = row_i # The data name may depend on the shape, and if so, the # shape is appended to the name as base64 fields @@ -691,7 +696,7 @@ class ArchiveSectionHDF5(ArchiveSection): data.append(i_data) # If one object returned, remove the outermost list - if len(index_rows) == 1: + if len(test_index) == 1: if data[0].shape == (): data = np.array([data[0]]) else: @@ -734,12 +739,7 @@ class ArchiveJSON(Archive): # Get the repository name from mainFileUri mainfile_uri = json_root["mainFileUri"] - if not mainfile_uri.startswith("nmd://"): - raise ValueError( - "The mainFileUri in the JSON Archive file '{}' is invalid." - .format(filepath) - ) - repository_name = mainfile_uri[6:] + repository_name = mainfile_uri.split("://", 1)[1] repository_name = repository_name.split("/", 1)[0] root_section = { @@ -849,6 +849,9 @@ class ArchiveSectionJSON(ArchiveSection): is_section = False if path.startswith("section"): is_section = True + elif re.match(r'^x_\S+_section', path): + # code-specific section + is_section = True # If no index specified, try to get as concrete value or as a list of # sections