Skip to content

Commit

Permalink
isort+black
Browse files Browse the repository at this point in the history
  • Loading branch information
morriscb committed Nov 3, 2023
1 parent fd138ea commit 6fe632e
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class VBOLimsCache(Cache):

class VisualBehaviorOphysProjectCache(ProjectCacheBase):
PROJECT_NAME = "visual-behavior-ophys"
BUCKET_NAME = "visual-behavior-ophys-data"
BUCKET_NAME = "staging.visual-behavior-ophys-data"

def __init__(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
from allensdk.brain_observatory.behavior.behavior_session import (
BehaviorSession,
)
from allensdk.brain_observatory.ophys.project_constants import (
VBO_INTEGER_COLUMNS,
VBO_METADATA_COLUMN_ORDER,
)
from allensdk.core.dataframe_utils import (
enforce_df_column_order,
enforce_df_int_typing,
return_one_dataframe_row_only,
)
from allensdk.core.utilities import literal_col_eval
from allensdk.brain_observatory.ophys.project_constants import (
VBO_METADATA_COLUMN_ORDER,
VBO_INTEGER_COLUMNS
)

COL_EVAL_LIST = ["ophys_experiment_id", "ophys_container_id", "driver_line"]

Expand Down Expand Up @@ -190,13 +190,10 @@ def _get_ophys_session_table(self):
df["date_of_acquisition"], utc="True"
)
df = enforce_df_int_typing(
input_df=df,
int_columns=VBO_INTEGER_COLUMNS,
use_pandas_type=True
input_df=df, int_columns=VBO_INTEGER_COLUMNS, use_pandas_type=True
)
df = enforce_df_column_order(
input_df=df,
column_order=VBO_METADATA_COLUMN_ORDER
input_df=df, column_order=VBO_METADATA_COLUMN_ORDER
)
self._ophys_session_table = df.set_index("ophys_session_id")

Expand All @@ -223,13 +220,10 @@ def _get_behavior_session_table(self):
df["date_of_acquisition"], utc="True"
)
df = enforce_df_int_typing(
input_df=df,
int_columns=VBO_INTEGER_COLUMNS,
use_pandas_type=True
input_df=df, int_columns=VBO_INTEGER_COLUMNS, use_pandas_type=True
)
df = enforce_df_column_order(
input_df=df,
column_order=VBO_METADATA_COLUMN_ORDER
input_df=df, column_order=VBO_METADATA_COLUMN_ORDER
)

self._behavior_session_table = df.set_index("behavior_session_id")
Expand Down Expand Up @@ -261,13 +255,10 @@ def _get_ophys_experiment_table(self):
df["date_of_acquisition"], utc="True"
)
df = enforce_df_int_typing(
input_df=df,
int_columns=VBO_INTEGER_COLUMNS,
use_pandas_type=True
input_df=df, int_columns=VBO_INTEGER_COLUMNS, use_pandas_type=True
)
df = enforce_df_column_order(
input_df=df,
column_order=VBO_METADATA_COLUMN_ORDER
input_df=df, column_order=VBO_METADATA_COLUMN_ORDER
)
self._ophys_experiment_table = df.set_index("ophys_experiment_id")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@
from allensdk.brain_observatory.ecephys.ecephys_project_api.http_engine import ( # noqa: E501
HttpEngine,
)
from allensdk.brain_observatory.ophys.project_constants import (
VBO_INTEGER_COLUMNS,
VBO_METADATA_COLUMN_ORDER,
)
from allensdk.core.auth_config import (
LIMS_DB_CREDENTIAL_MAP,
MTRAIN_DB_CREDENTIAL_MAP,
)
from allensdk.core.authentication import DbCredentials
from allensdk.core.dataframe_utils import (
enforce_df_column_order,
enforce_df_int_typing,
)
from allensdk.internal.api import db_connection_creator
from allensdk.internal.api.queries.utils import (
build_in_list_selector_query,
build_where_clause,
)
from allensdk.core.dataframe_utils import (
enforce_df_column_order,
enforce_df_int_typing
)
from allensdk.brain_observatory.ophys.project_constants import (
VBO_METADATA_COLUMN_ORDER,
VBO_INTEGER_COLUMNS
)


class BehaviorProjectLimsApi(BehaviorProjectBase):
Expand Down Expand Up @@ -394,13 +394,10 @@ def _get_ophys_experiment_table(self) -> pd.DataFrame:
targeted_imaging_depth.columns = ["targeted_imaging_depth"]
df = query_df.merge(targeted_imaging_depth, on="ophys_container_id")
df = enforce_df_int_typing(
input_df=df,
int_columns=VBO_INTEGER_COLUMNS,
use_pandas_type=True
input_df=df, int_columns=VBO_INTEGER_COLUMNS, use_pandas_type=True
)
df = enforce_df_column_order(
input_df=df,
column_order=VBO_METADATA_COLUMN_ORDER
input_df=df, column_order=VBO_METADATA_COLUMN_ORDER
)
return df

Expand Down Expand Up @@ -446,9 +443,7 @@ def _get_ophys_cells_table(self):

# NaN's for invalid cells force this to float, push to int
df = enforce_df_int_typing(
input_df=df,
int_columns=VBO_INTEGER_COLUMNS,
use_pandas_type=True
input_df=df, int_columns=VBO_INTEGER_COLUMNS, use_pandas_type=True
)
return df

Expand Down Expand Up @@ -512,25 +507,22 @@ def get_ophys_session_table(self) -> pd.DataFrame:
# There is one ophys_session_id from 2018 that has multiple behavior
# ids, causing duplicates -- drop all dupes for now; # TODO
table = self._get_ophys_session_table().drop_duplicates(
subset=["ophys_session_id"],
keep=False
subset=["ophys_session_id"], keep=False
)
# Make date time explicitly UTC.
table["date_of_acquisition"] = pd.to_datetime(
table["date_of_acquisition"],
utc=True
table["date_of_acquisition"], utc=True
)

# Fill NaN values of imaging_plane_group_count with zero to match
# the behavior of the BehaviorOphysExperiment object.
table = enforce_df_int_typing(
input_df=table,
int_columns=VBO_INTEGER_COLUMNS,
use_pandas_type=True
use_pandas_type=True,
)
table = enforce_df_column_order(
input_df=table,
column_order=VBO_METADATA_COLUMN_ORDER
input_df=table, column_order=VBO_METADATA_COLUMN_ORDER
)
return table.set_index("ophys_session_id")

Expand Down Expand Up @@ -562,19 +554,15 @@ def get_ophys_experiment_table(self) -> pd.DataFrame:
"""
df = self._get_ophys_experiment_table()
df["date_of_acquisition"] = pd.to_datetime(
df["date_of_acquisition"],
utc=True
df["date_of_acquisition"], utc=True
)
# Set type to pandas.Int64 to enforce integer typing and not revert to
# float.
df = enforce_df_int_typing(
input_df=df,
int_columns=VBO_INTEGER_COLUMNS,
use_pandas_type=True
input_df=df, int_columns=VBO_INTEGER_COLUMNS, use_pandas_type=True
)
df = enforce_df_column_order(
input_df=df,
column_order=VBO_METADATA_COLUMN_ORDER
input_df=df, column_order=VBO_METADATA_COLUMN_ORDER
)

return df.set_index("ophys_experiment_id")
Expand All @@ -600,11 +588,10 @@ def get_behavior_session_table(self) -> pd.DataFrame:
summary_tbl = enforce_df_int_typing(
input_df=summary_tbl,
int_columns=VBO_INTEGER_COLUMNS,
use_pandas_type=True
use_pandas_type=True,
)
summary_tbl = enforce_df_column_order(
input_df=summary_tbl,
column_order=VBO_METADATA_COLUMN_ORDER
input_df=summary_tbl, column_order=VBO_METADATA_COLUMN_ORDER
)

return summary_tbl.set_index("behavior_session_id")
Expand Down
47 changes: 35 additions & 12 deletions allensdk/brain_observatory/ophys/project_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,40 @@
}

VBO_METADATA_COLUMN_ORDER = [
'behavior_session_id', 'ophys_session_id', 'ophys_container_id',
'mouse_id', 'indicator', 'full_genotype', 'driver_line',
'cre_line', 'reporter_line', 'sex', 'age_in_days',
'imaging_depth', 'targeted_structure', 'targeted_imaging_depth',
'imaging_plane_group_count', 'imaging_plane_group',
'project_code', 'session_type', 'session_number', 'image_set',
'behavior_type', 'passive', 'experience_level',
'prior_exposures_to_session_type', 'prior_exposures_to_image_set',
'prior_exposures_to_omissions', 'date_of_acquisition',
'equipment_name', 'num_depths_per_area', 'ophys_experiment_id',
'num_targeted_structures', 'published_at', 'isi_experiment_id']
"behavior_session_id",
"ophys_session_id",
"ophys_container_id",
"mouse_id",
"indicator",
"full_genotype",
"driver_line",
"cre_line",
"reporter_line",
"sex",
"age_in_days",
"imaging_depth",
"targeted_structure",
"targeted_imaging_depth",
"imaging_plane_group_count",
"imaging_plane_group",
"project_code",
"session_type",
"session_number",
"image_set",
"behavior_type",
"passive",
"experience_level",
"prior_exposures_to_session_type",
"prior_exposures_to_image_set",
"prior_exposures_to_omissions",
"date_of_acquisition",
"equipment_name",
"num_depths_per_area",
"ophys_experiment_id",
"num_targeted_structures",
"published_at",
"isi_experiment_id",
]


VBO_INTEGER_COLUMNS = [
Expand All @@ -77,5 +100,5 @@
"targeted_areas",
"num_depths_per_area",
"num_targeted_structures",
"cell_specimen_id"
"cell_specimen_id",
]
Loading

0 comments on commit 6fe632e

Please sign in to comment.