Skip to content
Snippets Groups Projects
Commit 793ce5d7 authored by pswain's avatar pswain
Browse files

changed load_attributes to load_meta

parent b95e79fc
No related branches found
No related tags found
No related merge requests found
...@@ -190,8 +190,8 @@ class ProcessABC(ABC): ...@@ -190,8 +190,8 @@ class ProcessABC(ABC):
""" """
self._parameters = parameters self._parameters = parameters
# convert parameters to dictionary # convert parameters to dictionary
# and then define each parameter as an attribute
for k, v in parameters.to_dict().items(): for k, v in parameters.to_dict().items():
# define each parameter as an attribute
setattr(self, k, v) setattr(self, k, v)
@property @property
......
...@@ -5,7 +5,7 @@ import h5py ...@@ -5,7 +5,7 @@ import h5py
import numpy as np import numpy as np
from agora.io.bridge import groupsort from agora.io.bridge import groupsort
from agora.io.writer import load_attributes from agora.io.writer import load_meta
class DynamicReader: class DynamicReader:
...@@ -13,7 +13,7 @@ class DynamicReader: ...@@ -13,7 +13,7 @@ class DynamicReader:
def __init__(self, file: str): def __init__(self, file: str):
self.file = file self.file = file
self.metadata = load_attributes(file) self.metadata = load_meta(file)
class StateReader(DynamicReader): class StateReader(DynamicReader):
......
...@@ -15,9 +15,10 @@ from agora.io.bridge import BridgeH5 ...@@ -15,9 +15,10 @@ from agora.io.bridge import BridgeH5
#################### Dynamic version ################################## #################### Dynamic version ##################################
def load_attributes(file: str, group="/"): def load_meta(file: str, group="/"):
""" """
Load the metadata from an h5 file and convert to a dictionary, including the "parameters" field which is stored as YAML. Load the metadata from an h5 file and convert to a dictionary, including
the "parameters" field which is stored as YAML.
Parameters Parameters
---------- ----------
...@@ -26,8 +27,9 @@ def load_attributes(file: str, group="/"): ...@@ -26,8 +27,9 @@ def load_attributes(file: str, group="/"):
group: str, optional group: str, optional
The group in the h5 file from which to read the data The group in the h5 file from which to read the data
""" """
# load the metadata, stored as attributes, from the h5 file and return as a dictionary # load the metadata, stored as attributes, from the h5 file
with h5py.File(file, "r") as f: with h5py.File(file, "r") as f:
# return as a dict
meta = dict(f[group].attrs.items()) meta = dict(f[group].attrs.items())
if "parameters" in meta: if "parameters" in meta:
# convert from yaml format into dict # convert from yaml format into dict
...@@ -51,7 +53,7 @@ class DynamicWriter: ...@@ -51,7 +53,7 @@ class DynamicWriter:
self.file = file self.file = file
# the metadata is stored as attributes in the h5 file # the metadata is stored as attributes in the h5 file
if Path(file).exists(): if Path(file).exists():
self.metadata = load_attributes(file) self.metadata = load_meta(file)
def _log(self, message: str, level: str = "warn"): def _log(self, message: str, level: str = "warn"):
# Log messages in the corresponding level # Log messages in the corresponding level
......
...@@ -131,7 +131,6 @@ class BridgeOmero: ...@@ -131,7 +131,6 @@ class BridgeOmero:
FIXME: Add docs. FIXME: Add docs.
""" """
# metadata = load_attributes(filepath)
bridge = BridgeH5(filepath) bridge = BridgeH5(filepath)
meta = safe_load(bridge.meta_h5["parameters"])["general"] meta = safe_load(bridge.meta_h5["parameters"])["general"]
server_info = {k: meta[k] for k in ("host", "username", "password")} server_info = {k: meta[k] for k in ("host", "username", "password")}
...@@ -268,7 +267,6 @@ class Dataset(BridgeOmero): ...@@ -268,7 +267,6 @@ class Dataset(BridgeOmero):
FIXME: Add docs. FIXME: Add docs.
""" """
# metadata = load_attributes(filepath)
bridge = BridgeH5(filepath) bridge = BridgeH5(filepath)
dataset_keys = ("omero_id", "omero_id,", "dataset_id") dataset_keys = ("omero_id", "omero_id,", "dataset_id")
for k in dataset_keys: for k in dataset_keys:
...@@ -301,21 +299,21 @@ class Image(BridgeOmero): ...@@ -301,21 +299,21 @@ class Image(BridgeOmero):
cls, cls,
filepath: t.Union[str, Path], filepath: t.Union[str, Path],
): ):
"""Instatiate Image from a hdf5 file. """
Instantiate Image from a h5 file.
Parameters Parameters
---------- ----------
cls : Image cls : Image
Image class Image class
filepath : t.Union[str, Path] filepath : t.Union[str, Path]
Location of hdf5 file. Location of h5 file.
Examples Examples
-------- --------
FIXME: Add docs. FIXME: Add docs.
""" """
# metadata = load_attributes(filepath)
bridge = BridgeH5(filepath) bridge = BridgeH5(filepath)
image_id = bridge.meta_h5["image_id"] image_id = bridge.meta_h5["image_id"]
return cls(image_id, **cls.server_info_from_h5(filepath)) return cls(image_id, **cls.server_info_from_h5(filepath))
......
...@@ -7,7 +7,7 @@ import pandas as pd ...@@ -7,7 +7,7 @@ import pandas as pd
from agora.abc import ParametersABC, StepABC from agora.abc import ParametersABC, StepABC
from agora.io.cells import Cells from agora.io.cells import Cells
from agora.io.writer import Writer, load_attributes from agora.io.writer import Writer, load_meta
from aliby.tile.tiler import Tiler from aliby.tile.tiler import Tiler
from extraction.core.functions.defaults import exparams_from_meta from extraction.core.functions.defaults import exparams_from_meta
from extraction.core.functions.distributors import reduce_z, trap_apply from extraction.core.functions.distributors import reduce_z, trap_apply
...@@ -89,7 +89,7 @@ class Extractor(StepABC): ...@@ -89,7 +89,7 @@ class Extractor(StepABC):
or leaf level. or leaf level.
""" """
# TODO Alan: Move this to a location with the SwainLab defaults # TODO Move this to a location with the SwainLab defaults
default_meta = { default_meta = {
"pixel_size": 0.236, "pixel_size": 0.236,
"z_size": 0.6, "z_size": 0.6,
...@@ -119,10 +119,11 @@ class Extractor(StepABC): ...@@ -119,10 +119,11 @@ class Extractor(StepABC):
self.params = parameters self.params = parameters
if store: if store:
self.local = store self.local = store
self.load_meta() self.meta = load_meta(self.local)
else: else:
# if no h5 file, use the parameters directly # if no h5 file, use the parameters directly
self.meta = {"channel": parameters.to_dict()["tree"].keys()} self.meta = {"channel": parameters.to_dict()["tree"].keys()}
if tiler: if tiler:
self.tiler = tiler self.tiler = tiler
available_channels = set((*tiler.channels, "general")) available_channels = set((*tiler.channels, "general"))
...@@ -236,10 +237,6 @@ class Extractor(StepABC): ...@@ -236,10 +237,6 @@ class Extractor(StepABC):
# merge the two dicts # merge the two dicts
self._all_funs = {**self._custom_funs, **ALL_FUNS} self._all_funs = {**self._custom_funs, **ALL_FUNS}
def load_meta(self):
"""Load metadata from h5 file."""
self.meta = load_attributes(self.local)
def get_tiles( def get_tiles(
self, self,
tp: int, tp: int,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment