-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from spapa013/main
reorganize api.config, add api.schemas, change how base imports api
- Loading branch information
Showing
14 changed files
with
333 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 17 additions & 76 deletions
93
python/microns-materialization-api/microns_materialization_api/config/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
python/microns-materialization-api/microns_materialization_api/config/bases.py
This file was deleted.
Oops, something went wrong.
13 changes: 5 additions & 8 deletions
13
python/microns-materialization-api/microns_materialization_api/config/externals.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
15 changes: 15 additions & 0 deletions
15
...on/microns-materialization-api/microns_materialization_api/schemas/h01_materialization.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Oops, something went wrong.