Skip to content

Commit

Permalink
integration
Browse files Browse the repository at this point in the history
  • Loading branch information
mavaylon1 committed Jan 18, 2024
1 parent dfc19bd commit 52cb3c5
Show file tree
Hide file tree
Showing 10 changed files with 466 additions and 1 deletion.
39 changes: 39 additions & 0 deletions docs/gallery/general/plot_configurator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from pynwb import nwb_config
from datetime import datetime
from uuid import uuid4

import numpy as np
from dateutil import tz

from pynwb import NWBHDF5IO, NWBFile, TimeSeries
from pynwb.behavior import Position, SpatialSeries
from pynwb.epoch import TimeIntervals
from pynwb.file import Subject

session_start_time = datetime(2018, 4, 25, 2, 30, 3, tzinfo=tz.gettz("US/Pacific"))

nwbfile = NWBFile(
session_description="Mouse exploring an open field", # required
identifier=str(uuid4()), # required
session_start_time=session_start_time, # required
session_id="session_1234", # optional
experimenter=[
"Baggins, Bilbo",
], # optional
lab="Bag End Laboratory", # optional
institution="University of My Institution", # optional
experiment_description="I went on an adventure to reclaim vast treasures.", # optional
related_publications="DOI:10.1016/j.neuron.2016.12.011", # optional
)


subject = Subject(
subject_id="001",
age="P90D",
description="mouse 5",
species="Mus musculus",
sex="M",
)

nwbfile.subject = subject
breakpoint()
340 changes: 340 additions & 0 deletions out.txt

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions src/pynwb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,35 @@
from .spec import NWBDatasetSpec, NWBGroupSpec, NWBNamespace # noqa E402
from .validate import validate # noqa: F401, E402

from .termset_config import NWBTermSetConfigurator


nwb_config = NWBTermSetConfigurator(path='src/pynwb/config/nwb_config.yaml')

@docval({'name': 'config_path', 'type': str, 'doc': 'Path to the configuartion file.',

Check failure on line 26 in src/pynwb/__init__.py

View workflow job for this annotation

GitHub Actions / Check for spelling errors

configuartion ==> configuration
'default': None})
def load_termset_config(config_path: str):
"""
If a user does not provide a config_path, then this method will unload any present configuration
and load the default curated configuration.
If a user provides a config_path, then this method will:
- Search the current configuation for data_types that are already present. These data_types will be

Check failure on line 34 in src/pynwb/__init__.py

View workflow job for this annotation

GitHub Actions / Check for spelling errors

configuation ==> configuration
replaced with the new configuration.
- If the data_type is not present, then they will be loaded alongside the default curated configuration.
"""
if config_path is None:
nwb_config.unload_termset_config()
nwb_config.load_termset_config()
else:
nwb_config.load_termset_config(config_path)

def unload_termset_config():
"""
Remove validation.
"""
return nwb_config.unload_termset_config()


def __get_resources():
try:
Expand Down
6 changes: 6 additions & 0 deletions src/pynwb/config/nwb_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Subject:
namespace:
namespace_version:
fields:
species: src/pynwb/config/nwb_subject_termset.yaml
# field2: ...
27 changes: 27 additions & 0 deletions src/pynwb/config/nwb_subject_termset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
id: termset/species_example
name: Species
version: 0.0.1
prefixes:
NCBI_TAXON: https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?mode=Info&id=
imports:
- linkml:types
default_range: string

enums:
Species:
permissible_values:
Homo sapiens:
description: the species is human
meaning: NCBI_TAXON:9606
Mus musculus:
description: the species is a house mouse
meaning: NCBI_TAXON:10090
Ursus arctos horribilis:
description: the species is a grizzly bear
meaning: NCBI_TAXON:116960
Myrmecophaga tridactyla:
description: the species is an anteater
meaning: NCBI_TAXON:71006
Ailuropoda melanoleuca:
description: the species is a panda
meaning: NCBI_TAXON:9646
9 changes: 9 additions & 0 deletions src/pynwb/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ def _error_on_new_warn_on_construct(self, error_msg: str):
raise ValueError(error_msg)
warn(error_msg)

def get_config(self):
from . import nwb_config #update path
return nwb_config

def get_type_map(self):
from . import get_type_map
tm = get_type_map()
return tm


@register_class('NWBContainer', CORE_NAMESPACE)
class NWBContainer(NWBMixin, Container):
Expand Down
1 change: 1 addition & 0 deletions src/pynwb/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class Subject(NWBContainer):
{'name': 'strain', 'type': str, 'doc': 'The strain of the subject, e.g., "C57BL/6J"', 'default': None},
)
def __init__(self, **kwargs):
self.init_validation(constructor_args=kwargs)
keys_to_set = (
"age",
"age__reference",
Expand Down
12 changes: 12 additions & 0 deletions src/pynwb/termset_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from hdmf.term_set import TermSetConfigurator as hdmf_TermSetConfigurator
from hdmf.utils import docval


class NWBTermSetConfigurator(hdmf_TermSetConfigurator):
"""
"""
@docval({'name': 'path', 'type': str, 'doc': 'Path to the configuartion file.',

Check failure on line 9 in src/pynwb/termset_config.py

View workflow job for this annotation

GitHub Actions / Check for spelling errors

configuartion ==> configuration
'default': 'src/pynwb/config/nwb_config.yaml'})
def __init__(self,**kwargs):
super().__init__(**kwargs)
2 changes: 2 additions & 0 deletions tests/unit/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from pynwb import nwb_config
breakpoint()

0 comments on commit 52cb3c5

Please sign in to comment.