Skip to content

Commit

Permalink
rename u19 etl (#192)
Browse files Browse the repository at this point in the history
* rename u19 etl

* linters
  • Loading branch information
Sun-flow authored Nov 13, 2024
1 parent 76a6c8f commit 83581b6
Show file tree
Hide file tree
Showing 19 changed files with 48 additions and 30 deletions.
3 changes: 2 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
from pathlib import Path
from datetime import date
from os.path import abspath, dirname
from pathlib import Path

from aind_metadata_mapper import __version__ as package_version

INSTITUTE_NAME = "Allen Institute for Neural Dynamics"
Expand Down
1 change: 1 addition & 0 deletions src/aind_metadata_mapper/bruker/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module defining JobSettings for Bruker ETL"""

from pathlib import Path
from typing import List, Literal, Optional, Union

Expand Down
1 change: 1 addition & 0 deletions src/aind_metadata_mapper/bruker/session.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Sets up the MRI ingest ETL"""

import argparse
import json
import logging
Expand Down
1 change: 1 addition & 0 deletions src/aind_metadata_mapper/mesoscope/session.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Mesoscope ETL"""

import argparse
import json
import logging
Expand Down
1 change: 1 addition & 0 deletions src/aind_metadata_mapper/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module to define models for Gather Metadata Job"""

from pathlib import Path
from typing import List, Literal, Optional, Union

Expand Down
4 changes: 2 additions & 2 deletions src/aind_metadata_mapper/open_ephys/camstim_ephys_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ def __init__(
logger.debug("building stim table")
self.build_stimulus_table()
if self.opto_pkl_path.exists() and (
not self.opto_table_path.exists() or
self.job_settings.overwrite_tables
not self.opto_table_path.exists()
or self.job_settings.overwrite_tables
):
logger.debug("building opto table")
self.build_optogenetics_table()
Expand Down
3 changes: 2 additions & 1 deletion src/aind_metadata_mapper/open_ephys/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Module defining JobSettings for Mesoscope ETL"""

from typing import Literal, Union
from pathlib import Path
from typing import Literal, Union

from aind_metadata_mapper.core_models import BaseJobSettings

DEFAULT_OPTO_CONDITIONS = {
Expand Down
1 change: 1 addition & 0 deletions src/aind_metadata_mapper/smartspim/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module defining JobSettings for SmartSPIM ETL"""

from pathlib import Path
from typing import Literal, Optional, Union

Expand Down
6 changes: 3 additions & 3 deletions src/aind_metadata_mapper/stimulus/camstim.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(
else:
self.opto_conditions_map = self.job_settings["opto_conditions_map"]

sessions_root = Path(self.job_settings.get('sessions_root'))
sessions_root = Path(self.job_settings.get("sessions_root"))
self.session_path = self.get_session_path(session_id, sessions_root)
self.folder = self.get_folder(session_id, sessions_root)

Expand Down Expand Up @@ -79,14 +79,14 @@ def __init__(

if (
not self.stim_table_path.exists()
or self.job_settings['overwrite_tables']
or self.job_settings["overwrite_tables"]
):
print("building stim table")
self.build_stimulus_table()
if (
self.opto_pkl_path.exists()
and not self.opto_table_path.exists()
or self.job_settings['overwrite_tables']
or self.job_settings["overwrite_tables"]
):
print("building opto table")
self.build_optogenetics_table()
Expand Down
1 change: 1 addition & 0 deletions src/aind_metadata_mapper/u19/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Defines Job Settings for U19 ETL"""

from pathlib import Path
from typing import List, Literal, Optional, Union

Expand Down
10 changes: 5 additions & 5 deletions src/aind_metadata_mapper/u19/procedures.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def strings_to_dates(strings):
return [date1, date2]


class U19Etl(GenericEtl[JobSettings]):
class SmartSPIMSpecimenIngester(GenericEtl[JobSettings]):
"""U19 ETL class."""

# TODO: Deprecate this constructor. Use GenericEtl constructor instead
Expand Down Expand Up @@ -92,9 +92,9 @@ def _transform(self, existing_procedure, subj_id):
if row is None:
logging.warning(f"Could not find row for {subj_id}")
return
existing_procedure[
"specimen_procedures"
] = self.extract_spec_procedures(subj_id, row)
existing_procedure["specimen_procedures"] = (
self.extract_spec_procedures(subj_id, row)
)

return construct_new_model(
existing_procedure,
Expand Down Expand Up @@ -423,5 +423,5 @@ def extract_spec_procedures(self, subj_id, row): # noqa: C901
if __name__ == "__main__":
sys_args = sys.argv[1:]
main_job_settings = JobSettings.from_args(sys_args)
etl = U19Etl(job_settings=main_job_settings)
etl = SmartSPIMSpecimenIngester(job_settings=main_job_settings)
etl.run_job()
1 change: 1 addition & 0 deletions tests/integration/bergamo/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pathlib import Path

from aind_data_schema.core.session import Session

from aind_metadata_mapper.bergamo.models import JobSettings
from aind_metadata_mapper.bergamo.session import BergamoEtl

Expand Down
29 changes: 17 additions & 12 deletions tests/test_U19/test_procedures.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from aind_metadata_mapper.u19.models import JobSettings
from aind_metadata_mapper.u19.procedures import (
U19Etl,
SmartSPIMSpecimenIngester,
get_dates,
strings_to_dates,
)
Expand Down Expand Up @@ -62,31 +62,33 @@ def setUpClass(self):
)

@patch(
"aind_metadata_mapper.u19.procedures.U19Etl.download_procedure_file"
"aind_metadata_mapper.u19.procedures."
"SmartSPIMSpecimenIngester.download_procedure_file"
)
def test_run_job(self, mock_download_procedure):
"""Test run_job method."""

with open(EXAMPLE_DOWNLOAD_PROCEDURE, "r") as f:
mock_download_procedure.return_value = json.load(f)

etl = U19Etl(self.example_job_settings)
etl = SmartSPIMSpecimenIngester(self.example_job_settings)
job_response = etl.run_job()

actual_output = json.loads(job_response.data)

self.assertEqual(self.example_output, actual_output)

@patch(
"aind_metadata_mapper.u19.procedures.U19Etl.download_procedure_file"
"aind_metadata_mapper.u19.procedures."
"SmartSPIMSpecimenIngester.download_procedure_file"
)
def test_extract(self, mock_download_procedure):
"""Test extract method."""

with open(EXAMPLE_DOWNLOAD_PROCEDURE, "r") as f:
mock_download_procedure.return_value = json.load(f)

etl = U19Etl(self.example_job_settings)
etl = SmartSPIMSpecimenIngester(self.example_job_settings)
extracted = etl._extract(self.example_job_settings.subject_to_ingest)

self.assertEqual(
Expand All @@ -97,7 +99,7 @@ def test_extract(self, mock_download_procedure):
def test_transform(self):
"""Test transform method."""

etl = U19Etl(self.example_job_settings)
etl = SmartSPIMSpecimenIngester(self.example_job_settings)
etl.load_specimen_procedure_file()

with open(EXAMPLE_DOWNLOAD_PROCEDURE, "r") as f:
Expand All @@ -116,15 +118,18 @@ def test_transform(self):
),
)

@patch("aind_metadata_mapper.u19.procedures.U19Etl._transform")
@patch(
"aind_metadata_mapper.u19.procedures."
"SmartSPIMSpecimenIngester._transform"
)
def test_load(self, mock_transform):
"""Test load method."""

mock_transform.return_value = construct_new_model(
self.example_output, Procedures, True
)

etl = U19Etl(self.example_job_settings)
etl = SmartSPIMSpecimenIngester(self.example_job_settings)
transformed = etl._transform(
self.example_job_settings.subject_to_ingest
)
Expand All @@ -140,7 +145,7 @@ def test_load(self, mock_transform):
def test_find_sheet_row(self):
"""Test find_sheet_row method."""

etl = U19Etl(self.example_job_settings)
etl = SmartSPIMSpecimenIngester(self.example_job_settings)
etl.load_specimen_procedure_file()
row = etl.find_sheet_row(self.example_job_settings.subject_to_ingest)

Expand All @@ -157,7 +162,7 @@ def test_download_procedure_file(self, mock_requests):
)
mock_requests.return_value.status_code = 200

etl = U19Etl(self.example_job_settings)
etl = SmartSPIMSpecimenIngester(self.example_job_settings)
response = etl.download_procedure_file(
self.example_job_settings.subject_to_ingest
)
Expand All @@ -170,7 +175,7 @@ def test_download_procedure_file(self, mock_requests):
def test_load_specimen_procedure_file(self):
"""Test load_specimen_procedure_file method."""

etl = U19Etl(self.example_job_settings)
etl = SmartSPIMSpecimenIngester(self.example_job_settings)
etl.load_specimen_procedure_file()

self.assertTrue(len(etl.tissue_sheets) == 2)
Expand All @@ -192,7 +197,7 @@ def test_strings_to_dates(self):
def test_extract_spec_procedures(self):
"""Test extract_spec_procedures method."""

etl = U19Etl(self.example_job_settings)
etl = SmartSPIMSpecimenIngester(self.example_job_settings)
etl.load_specimen_procedure_file()

row = etl.find_sheet_row(self.example_job_settings.subject_to_ingest)
Expand Down
1 change: 1 addition & 0 deletions tests/test_bergamo/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from unittest.mock import MagicMock, patch

from aind_data_schema.core.session import Session

from aind_metadata_mapper.bergamo.session import BergamoEtl, JobSettings

RESOURCES_DIR = (
Expand Down
1 change: 1 addition & 0 deletions tests/test_bruker/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
ScannerLocation,
)
from aind_data_schema.core.session import Session

from aind_metadata_mapper.bruker.session import JobSettings, MRIEtl

RESOURCES_DIR = (
Expand Down
3 changes: 2 additions & 1 deletion tests/test_dynamic_routing/test_mvr_rig.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""Tests for the MVR rig ETL."""

import os
import json
import os
import unittest
from pathlib import Path
from unittest.mock import MagicMock, patch

from aind_data_schema.core.rig import Rig

from aind_metadata_mapper.dynamic_routing.mvr_rig import ( # type: ignore
MvrRigEtl,
)
Expand Down
5 changes: 3 additions & 2 deletions tests/test_dynamic_routing/test_sync_rig.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
"""Tests for Sync rig ETL."""

import os
import json
import os
import unittest
from pathlib import Path
from unittest.mock import MagicMock, patch

from aind_data_schema.core.rig import Rig

from aind_metadata_mapper.dynamic_routing.sync_rig import ( # type: ignore
SyncRigEtl,
)
from aind_data_schema.core.rig import Rig

RESOURCES_DIR = (
Path(os.path.dirname(os.path.realpath(__file__)))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_open_ephys/test_rig.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Tests for the dynamic_routing open open_ephys rig ETL."""

import os
import json
import os
import unittest
from pathlib import Path
from unittest.mock import MagicMock, patch
Expand Down
4 changes: 2 additions & 2 deletions tests/test_open_ephys/test_utils/test_stim_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ def test_get_stimulus_image_name(self):
"image_path_list": [
"somepath\\passive\\image1.jpg",
"somepath\\passive\\image2.jpg",
"somepath\\passive\\image3.jpg"
]
"somepath\\passive\\image3.jpg",
],
}

# Expected image names
Expand Down

0 comments on commit 83581b6

Please sign in to comment.