Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mavaylon1 committed Sep 23, 2023
1 parent c1b4dba commit 7f0c0f4
Show file tree
Hide file tree
Showing 3 changed files with 905 additions and 1,032 deletions.
56 changes: 7 additions & 49 deletions src/hdmf_zarr/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,13 +524,8 @@ def resolve_ref(self, zarr_ref):
else:
source_file = str(zarr_ref['source'])
# Resolve the path relative to the current file
# breakpoint()
source_file = os.path.abspath(os.path.join(self.source, source_file))
object_path = zarr_ref.get('path', None)
# if object_path == "/bucket1/bazs/baz0":
# object_path = "/root/bazs/baz0"
# if object_path == "/bazs/baz0":

# full_path = None
# if os.path.isdir(source_file):
# if object_path is not None:
Expand All @@ -546,14 +541,12 @@ def resolve_ref(self, zarr_ref):
try:
target_zarr_obj = target_zarr_obj[object_path]
except Exception:
# breakpoint()
try:
import pathlib
object_path = pathlib.Path(object_path)
rel_obj_path = object_path.relative_to(*object_path.parts[:2])
target_zarr_obj = target_zarr_obj[rel_obj_path]
except Exception:
# breakpoint()
raise ValueError("Found bad link to object %s in file %s" % (object_path, source_file))
# Return the create path
return target_name, target_zarr_obj
Expand Down Expand Up @@ -586,11 +579,13 @@ def __get_ref(self, ref_object):

# by checking os.isdir makes sure we have a valid link path to a dir for Zarr. For conversion
# between backends a user should always use export which takes care of creating a clean set of builders.
source = (builder.source
if (builder.source is not None and os.path.isdir(builder.source))
else self.source)
# Make the source relative to the current file
source = os.path.relpath(os.path.abspath(source), start=self.abspath)
# source = (builder.source
# if (builder.source is not None and os.path.isdir(builder.source))
# else self.source)
#
# # Make the source relative to the current file
# source = os.path.relpath(os.path.abspath(source), start=self.abspath)
source = '.'
# Return the ZarrReference object
return ZarrReference(source, path)

Expand Down Expand Up @@ -718,7 +713,6 @@ def __setup_chunked_dataset__(cls, parent, name, data, options=None):
'doc': 'Used internally to force the data being used when we have to load the data', 'default': None},
returns='the Zarr array that was created', rtype=Array)
def write_dataset(self, **kwargs): # noqa: C901
# breakpoint()
parent, builder, link_data, exhaust_dci = getargs('parent', 'builder', 'link_data', 'exhaust_dci', kwargs)
force_data = getargs('force_data', kwargs)
if self.get_written(builder):
Expand Down Expand Up @@ -751,7 +745,6 @@ def write_dataset(self, **kwargs): # noqa: C901
dset = parent[name]
# When converting data between backends we may see an HDMFDataset, e.g., a H55ReferenceDataset, with references
elif isinstance(data, HDMFDataset):
# breakpoint()
# If we have a dataset of containers we need to make the references to the containers
if len(data) > 0 and isinstance(data[0], Container):
ref_data = [self.__get_ref(data[i]) for i in range(len(data))]
Expand All @@ -764,7 +757,6 @@ def write_dataset(self, **kwargs): # noqa: C901
**options['io_settings'])
dset.attrs['zarr_dtype'] = type_str
dset[:] = ref_data
# breakpoint()
self._written_builders.set_written(builder) # record that the builder has been written
# If we have a regular dataset, then load the data and write the builder after load
else:
Expand All @@ -775,8 +767,6 @@ def write_dataset(self, **kwargs): # noqa: C901
# We can/should not update the data in the builder itself so we load the data here and instead
# force write_dataset when we call it recursively to use the data we loaded, rather than the
# dataset that is set on the builder
# breakpoint()

dset = self.write_dataset(parent=parent,
builder=builder,
link_data=link_data,
Expand All @@ -799,7 +789,6 @@ def write_dataset(self, **kwargs): # noqa: C901
i = list([dts, ])
t = self.__resolve_dtype_helper__(i)
type_str.append(self.__serial_dtype__(t)[0])
# breakpoint()

if len(refs) > 0:
dset = parent.require_dataset(name,
Expand Down Expand Up @@ -1076,23 +1065,7 @@ def get_builder(self, **kwargs): # move this to HDMFIO (define skeleton in there
"""
zarr_obj = kwargs['zarr_obj']
builder = self.__get_built(zarr_obj)
# ff = self.__built
# breakpoint()
# if zarr_obj.name == '/bazs/baz0':
# breakpoint()
if builder is None:
#
# breakpoint()
# builder = self.__temp_get_built(zarr_obj)
path = list(self.__built.keys())[0]
builder_source_path = path.replace(zarr_obj.path,'')

zarr_obj_path = zarr_obj.path
path = os.path.join(builder_source_path, path)
# breakpoint()
builder = self.__built.get(path, None)
if builder is None:
# breakpoint()
msg = '%s has not been built' % (zarr_obj.name)
raise ValueError(msg)
return builder
Expand All @@ -1106,23 +1079,9 @@ def __get_built(self, zarr_obj):
"""
fpath = zarr_obj.store.path
path = zarr_obj.path
ff = self.__built
# breakpoint()
path = os.path.join(fpath, path)
return self.__built.get(path, None)

def __temp_get_built(self, zarr_obj):
fpath = zarr_obj.store.path
path = zarr_obj.path
path = os.path.join('bucket1', path)
# breakpoint()
path = os.path.join(fpath, path)
# breakpoint()

builder_source_path = list(self.__built.keys())[0]
return self.__built.get(path, None)


def __read_group(self, zarr_obj, name=None):
ret = self.__get_built(zarr_obj)
if ret is not None:
Expand Down Expand Up @@ -1266,7 +1225,6 @@ def get_container(self, **kwargs):
:raises ValueError: When no builder has been constructed yet for the given h5py object
"""
zarr_obj = getargs('zarr_obj', kwargs)
# breakpoint()
builder = self.get_builder(zarr_obj)
container = self.manager.construct(builder)
return container # This method should be moved to HDMFIO
2 changes: 0 additions & 2 deletions src/hdmf_zarr/zarr_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ def invert(self):

def _get_ref(self, ref):
# return self.get_object(self.dataset.file[ref])
# breakpoint()
name, zarr_obj = self.io.resolve_ref(ref) # ref is a json dict containing the path to the object
return self.get_object(zarr_obj)

Expand Down Expand Up @@ -129,7 +128,6 @@ def __init__(self, **kwargs):
# if t is RegionReference: # not yet supported
# self.__refgetters[i] = self.__get_regref
if t == DatasetBuilder.OBJECT_REF_TYPE:
# breakpoint()
self.__refgetters[i] = self._get_ref
elif t is str:
# we need this for when we read compound data types
Expand Down
Loading

0 comments on commit 7f0c0f4

Please sign in to comment.