Skip to content

Commit

Permalink
Merge pull request #2626 from AllenInstitute/ticket/2441/dev
Browse files Browse the repository at this point in the history
Remove to_json from data objects and their associated tests
  • Loading branch information
mikejhuang authored Dec 19, 2022
2 parents 4bf1c2d + e7b6b9e commit f923467
Show file tree
Hide file tree
Showing 23 changed files with 16 additions and 327 deletions.
5 changes: 1 addition & 4 deletions allensdk/brain_observatory/behavior/data_files/demix_file.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from typing import Dict, Union
from typing import Union
from pathlib import Path

import h5py
Expand Down Expand Up @@ -34,9 +34,6 @@ def from_json(cls, dict_repr: dict) -> "DemixFile":
filepath = dict_repr["demix_file"]
return cls(filepath=filepath)

def to_json(self) -> Dict[str, str]:
return {"demix_file": str(self.filepath)}

@classmethod
@cached(cache=LRUCache(maxsize=10), key=from_lims_cache_key)
def from_lims(
Expand Down
5 changes: 1 addition & 4 deletions allensdk/brain_observatory/behavior/data_files/dff_file.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
import numpy as np
from typing import Dict, Union
from typing import Union
from pathlib import Path

import h5py
Expand Down Expand Up @@ -35,9 +35,6 @@ def from_json(cls, dict_repr: dict) -> "DFFFile":
filepath = dict_repr["dff_file"]
return cls(filepath=filepath)

def to_json(self) -> Dict[str, str]:
return {"dff_file": str(self.filepath)}

@classmethod
@cached(cache=LRUCache(maxsize=10), key=from_lims_cache_key)
def from_lims(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
import numpy as np
from typing import Dict, Union, Tuple
from typing import Union, Tuple
from pathlib import Path

import h5py
Expand Down Expand Up @@ -36,9 +36,6 @@ def from_json(cls, dict_repr: dict) -> "EventDetectionFile":
filepath = dict_repr["events_file"]
return cls(filepath=filepath)

def to_json(self) -> Dict[str, str]:
return {"events_file": str(self.filepath)}

@classmethod
@cached(cache=LRUCache(maxsize=10), key=from_lims_cache_key)
def from_lims(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, Union
from typing import Union
from pathlib import Path

import pandas as pd
Expand All @@ -23,9 +23,6 @@ def from_json(cls, dict_repr: dict) -> "EyeTrackingFile":
filepath = dict_repr["eye_tracking_filepath"]
return cls(filepath=filepath)

def to_json(self) -> Dict[str, str]:
return {"eye_tracking_filepath": str(self.filepath)}

@classmethod
def from_lims(
cls, db: PostgresQueryMixin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ def from_lims(cls):
raise NotImplementedError(
"from_lims not yet supported for EyeTrackingMetadataFile")

@classmethod
def to_json(cls):
raise NotImplementedError(
"from_json not yet supported for EyeTrackingMetadataFile")

@classmethod
def from_json(
cls,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

class EyeTrackingVideo(DataFile):
"""Eye tracking video"""
def to_json(self) -> dict:
raise NotImplementedError

@classmethod
def from_lims(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from typing import Dict, Union
from typing import Union
from pathlib import Path

import h5py
Expand Down Expand Up @@ -34,9 +34,6 @@ def from_json(cls, dict_repr: dict) -> "NeuropilCorrectedFile":
filepath = dict_repr["neuropil_corrected_file"]
return cls(filepath=filepath)

def to_json(self) -> Dict[str, str]:
return {"neuropil_corrected_file": str(self.filepath)}

@classmethod
@cached(cache=LRUCache(maxsize=10), key=from_lims_cache_key)
def from_lims(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from typing import Dict, Union
from typing import Union
from pathlib import Path

import h5py
Expand Down Expand Up @@ -34,9 +34,6 @@ def from_json(cls, dict_repr: dict) -> "NeuropilFile":
filepath = dict_repr["neuropil_file"]
return cls(filepath=filepath)

def to_json(self) -> Dict[str, str]:
return {"neuropil_file": str(self.filepath)}

@classmethod
@cached(cache=LRUCache(maxsize=10), key=from_lims_cache_key)
def from_lims(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import json
from typing import Dict, Union
from typing import Union
from pathlib import Path

from cachetools import cached, LRUCache
Expand Down Expand Up @@ -34,9 +34,6 @@ def from_json(cls, dict_repr: dict) -> "RigidMotionTransformFile":
filepath = dict_repr["rigid_motion_transform_file"]
return cls(filepath=filepath)

def to_json(self) -> Dict[str, str]:
return {"rigid_motion_transform_file": str(self.filepath)}

@classmethod
@cached(cache=LRUCache(maxsize=10), key=from_lims_cache_key)
def from_lims(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ def from_json(cls, dict_repr: dict) -> "_StimulusFile":
def _from_json(cls, stimulus_file_path: str) -> "_StimulusFile":
return cls(filepath=stimulus_file_path)

def to_json(self) -> Dict[str, str]:
return {self.file_path_key(): str(self.filepath)}

@classmethod
@cached(cache=LRUCache(maxsize=10), key=from_lims_cache_key)
def from_lims(
Expand Down
5 changes: 1 addition & 4 deletions allensdk/brain_observatory/behavior/data_files/sync_file.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import abc
import json
from typing import Dict, Union
from typing import Union
from pathlib import Path

from cachetools import cached, LRUCache
Expand Down Expand Up @@ -71,9 +71,6 @@ def from_json(cls,
filepath = dict_repr["sync_file"]
return cls(filepath=filepath, permissive=permissive)

def to_json(self) -> Dict[str, str]:
return {"sync_file": str(self.filepath)}

@classmethod
@cached(cache=LRUCache(maxsize=10), key=from_lims_cache_key)
def from_lims(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
JsonReadableInterface, NwbReadableInterface, \
LimsReadableInterface
from allensdk.core import \
JsonWritableInterface, NwbWritableInterface
NwbWritableInterface
from allensdk.brain_observatory.behavior.data_objects.metadata\
.behavior_metadata.behavior_session_uuid import \
BehaviorSessionUUID
Expand Down Expand Up @@ -181,7 +181,6 @@ def get_task_parameters(data: Dict) -> Dict:
class BehaviorMetadata(DataObject, LimsReadableInterface,
JsonReadableInterface,
NwbReadableInterface,
JsonWritableInterface,
NwbWritableInterface):
"""Container class for behavior metadata"""
def __init__(self,
Expand Down Expand Up @@ -334,9 +333,6 @@ def is_pretest(self):
def is_training(self):
return self.session_type.lower().startswith('training_0')

def to_json(self) -> dict:
pass

def to_nwb(self, nwbfile: NWBFile) -> NWBFile:
self._subject_metadata.to_nwb(nwbfile=nwbfile)
self._equipment.to_nwb(nwbfile=nwbfile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

from allensdk.core import \
JsonReadableInterface, LimsReadableInterface, NwbReadableInterface
from allensdk.core import \
JsonWritableInterface
from allensdk.internal.api import PostgresQueryMixin
from allensdk.core import DataObject

Expand All @@ -18,17 +16,14 @@ def from_lims_cache_key(cls, db, ophys_experiment_id: int):
class BehaviorSessionId(DataObject, LimsReadableInterface,
JsonReadableInterface,
NwbReadableInterface,
JsonWritableInterface):
):
def __init__(self, behavior_session_id: int):
super().__init__(name="behavior_session_id", value=behavior_session_id)

@classmethod
def from_json(cls, dict_repr: dict) -> "BehaviorSessionId":
return cls(behavior_session_id=dict_repr["behavior_session_id"])

def to_json(self) -> dict:
return {"behavior_session_id": self.value}

@classmethod
@cached(cache=LRUCache(maxsize=10), key=from_lims_cache_key)
# TODO should be from_ophys_experiment_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from allensdk.core import DataObject
from allensdk.core import \
JsonReadableInterface, LimsReadableInterface, NwbReadableInterface
from allensdk.core import \
JsonWritableInterface, NwbWritableInterface
from allensdk.core import NwbWritableInterface
from allensdk.internal.api import PostgresQueryMixin


Expand All @@ -16,8 +15,7 @@ class EquipmentType(Enum):


class Equipment(DataObject, JsonReadableInterface, LimsReadableInterface,
NwbReadableInterface, JsonWritableInterface,
NwbWritableInterface):
NwbReadableInterface, NwbWritableInterface):
"""the name of the experimental rig."""
def __init__(self, equipment_name: str):
super().__init__(name="equipment_name", value=equipment_name)
Expand All @@ -26,9 +24,6 @@ def __init__(self, equipment_name: str):
def from_json(cls, dict_repr: dict) -> "Equipment":
return cls(equipment_name=dict_repr["rig_name"])

def to_json(self) -> dict:
return {"eqipment_name": self.value}

@classmethod
def from_lims(cls, behavior_session_id: int,
lims_db: PostgresQueryMixin) -> "Equipment":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
from allensdk.core import DataObject
from allensdk.core import \
JsonReadableInterface, LimsReadableInterface, NwbReadableInterface
from allensdk.core import \
JsonWritableInterface
from allensdk.internal.api import PostgresQueryMixin


class Sex(DataObject, LimsReadableInterface, JsonReadableInterface,
NwbReadableInterface, JsonWritableInterface):
NwbReadableInterface):
"""sex of the animal (M/F)"""
def __init__(self, sex: str):
super().__init__(name="sex", value=sex)
Expand All @@ -18,9 +16,6 @@ def __init__(self, sex: str):
def from_json(cls, dict_repr: dict) -> "Sex":
return cls(sex=dict_repr["sex"])

def to_json(self) -> dict:
return {"sex": self.value}

@classmethod
def from_lims(cls, behavior_session_id: int,
lims_db: PostgresQueryMixin) -> "Sex":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from allensdk.brain_observatory.behavior.data_objects import BehaviorSessionId
from allensdk.core import \
JsonReadableInterface, LimsReadableInterface, NwbReadableInterface
from allensdk.core import \
JsonWritableInterface, NwbWritableInterface
from allensdk.core import NwbWritableInterface
from allensdk.brain_observatory.behavior.data_objects.metadata \
.subject_metadata.age import \
Age
Expand All @@ -36,7 +35,7 @@

class SubjectMetadata(DataObject, LimsReadableInterface, NwbReadableInterface,
NwbWritableInterface, JsonReadableInterface,
JsonWritableInterface):
):
"""Subject metadata"""

def __init__(self,
Expand Down Expand Up @@ -115,9 +114,6 @@ def from_json(cls, dict_repr: dict) -> "SubjectMetadata":
death_on=death_on
)

def to_json(self) -> dict:
pass

@classmethod
def from_nwb(cls, nwbfile: NWBFile) -> "SubjectMetadata":
mouse_id = MouseId.from_nwb(nwbfile=nwbfile)
Expand Down
2 changes: 1 addition & 1 deletion allensdk/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@
DataFileReadableInterface
)
from ._data_object_base.writable_interfaces import ( # noqa F401
JsonWritableInterface, NwbWritableInterface
NwbWritableInterface
)
16 changes: 0 additions & 16 deletions allensdk/core/_data_object_base/writable_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,6 @@
from pynwb import NWBFile


class JsonWritableInterface(abc.ABC):
"""Marks a data object as writable to NWB"""
@abc.abstractmethod
def to_json(self) -> dict: # pragma: no cover
"""Given an already populated DataObject, return the dict that
when used with the `from_json()` classmethod would produce the same
DataObject
Returns
-------
dict:
The JSON (in dict form) that would produce the DataObject.
"""
raise NotImplementedError()


class NwbWritableInterface(abc.ABC):
"""Marks a data object as writable to NWB"""
@abc.abstractmethod
Expand Down
13 changes: 0 additions & 13 deletions allensdk/internal/core/_data_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,6 @@ def from_json(cls,
# return cls.instantiate(filepath=filepath)
raise NotImplementedError()

@abc.abstractmethod
def to_json(self) -> dict: # pragma: no cover
"""Given an already populated DataFile, return the dict that
when used with the `from_json()` classmethod would produce the same
DataFile
Returns
-------
dict:
The JSON (in dict form) that would produce the DataFile.
"""
raise NotImplementedError()

@classmethod
@abc.abstractmethod
def from_lims(cls) -> "DataFile": # pragma: no cover
Expand Down
Loading

0 comments on commit f923467

Please sign in to comment.