Skip to content

Commit

Permalink
Merge pull request #13 from spapa013/main
Browse files Browse the repository at this point in the history
reorganize api.config, add api.schemas, change how base imports api
  • Loading branch information
spapa013 authored Dec 21, 2021
2 parents 09d5cb9 + 161f3c0 commit 27d840a
Show file tree
Hide file tree
Showing 14 changed files with 333 additions and 327 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
)
)

check_latest_version_from_github = version_utils.latest_github_version_checker(owner='cajal', repo='microns-materialization')
check_latest_version_from_github = version_utils.latest_github_version_checker(owner='cajal', repo='microns-materialization')
Original file line number Diff line number Diff line change
@@ -1,82 +1,23 @@
"""
Configuration package/module for microns-materialization.
"""

import inspect
import traceback
from enum import Enum
import datajoint.datajoint_plus as djp
from microns_utils.config_utils import SchemaConfig
from . import adapters
from . import externals
from . import bases
try:
import datajoint as dj
except:
traceback.print_exc()
raise ImportError('DataJoint package not found.')
from microns_utils import config_utils


config_utils.enable_datajoint_flags()


def register_externals(schema_name:str):
"""
Registers the external stores for a schema_name in this module.
"""
external_stores = config_mapping[SCHEMAS(schema_name)]["externals"]

if external_stores is not None:
config_utils.register_externals(external_stores)


def register_adapters(schema_name:str, context=None):
"""
Imports the adapters for a schema_name into the global namespace.
"""
adapter_objects = config_mapping[SCHEMAS(schema_name)]["adapters"]

if adapter_objects is not None:
config_utils.register_adapters(adapter_objects, context=context)


def register_bases(schema_name:str, module):
"""
Maps base classes to DataJoint tables.
"""
bases = config_mapping[SCHEMAS(schema_name)]["bases"]

if bases is not None:
for base in bases:
config_utils.register_bases(base, module)
return module


def create_vm(schema_name:str):
"""
Creates a virtual module after registering the external stores, adapter objects, DatajointPlus and base classes.
"""
schema = SCHEMAS(schema_name)
vm = config_utils._create_vm(schema.value, external_stores=config_mapping[schema]["externals"], adapter_objects=config_mapping[schema]["adapters"])
config_utils.add_datajoint_plus(vm)
register_bases(schema_name, vm)
return vm


class SCHEMAS(Enum):
H01_MATERIALIZATION = "microns_h01_materialization"
MINNIE65_MATERIALIZATION = "microns_minnie65_materialization"


config_mapping = {
SCHEMAS.H01_MATERIALIZATION: {
"externals": externals.h01_materialization,
"adapters": adapters.h01_materialization_adapter_objects,
"bases": None
},
SCHEMAS.MINNIE65_MATERIALIZATION: {
"externals": externals.minnie65_materialization,
"adapters": adapters.minnie65_materialization_adapter_objects,
"bases": None
},

}
djp.enable_datajoint_flags()

h01_materialization_config = SchemaConfig(
module_name='h01_materialization',
schema_name='microns_h01_materialization',
externals=externals.h01_materialization,
adapters=adapters.h01_materialization
)

minnie65_materialization_config = SchemaConfig(
module_name='minnie65_materialization',
schema_name='microns_minnie65_materialization',
externals=externals.minnie65_materialization,
adapters=adapters.minnie65_materialization
)
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ def get(self, filepath):

# also store in one object for ease of use with virtual modules

h01_materialization_adapter_objects = {
h01_materialization = {
'h01_meshes': h01_meshes,
}

minnie65_materialization_adapter_objects = {
minnie65_materialization = {
'minnie65_meshes': minnie65_meshes,
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
"""
Externals for DataJoint tables.
"""

import datajoint.datajoint_plus as djp
from pathlib import Path
from microns_utils import config_utils

base_path = Path() / '/mnt' / 'dj-stor01' / 'microns'

#h01 materialization
h01_materialization_external_meshes_path = base_path / 'h01' / 'meshes'
h01_materialization = {
'h01_meshes': config_utils.make_store_dict(h01_materialization_external_meshes_path),

}
'h01_meshes': djp.make_store_dict(h01_materialization_external_meshes_path),
}

#minnie65_materialization
minnie65_materialization_external_meshes_path = base_path / 'minnie' / 'meshes'
minnie65_materialization = {
'minnie65_meshes': config_utils.make_store_dict(minnie65_materialization_external_meshes_path),

}
'minnie65_meshes': djp.make_store_dict(minnie65_materialization_external_meshes_path),
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
DataJoint tables for importing h01 from Jeff Lichtman group.
"""
import datajoint as dj
import datajoint.datajoint_plus as djp

from ..config import h01_materialization_config

h01_materialization_config.register_externals()
h01_materialization_config.register_adapters(context=locals())

schema = dj.schema(h01_materialization_config.schema_name, create_schema=True)

schema.spawn_missing_classes()
schema.connection.dependencies.load()
Loading

0 comments on commit 27d840a

Please sign in to comment.