Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 16 additions & 22 deletions initial_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
from getpass import getpass

import pandas as pd
from u19_pipeline.utils.logging_config import get_logger

logger = get_logger(__name__)


def initial_conf(save_user=True, replace_user=False, global_config_flag=True):
Expand All @@ -29,13 +32,13 @@ def initial_conf(save_user=True, replace_user=False, global_config_flag=True):
try_find_conf_file()
except FileNotFoundError:
pass
print("DataJoint configuration file not found. Running configuration script...")
logger.info("DataJoint configuration file not found. Running configuration script...")
if global_config_flag:
print(
logger.info(
"Global configuration flag is set to True. The configuration will be saved in the global configuration file."
)
else:
print(
logger.info(
"Global configuration flag is set to False. The configuration will be saved in the local configuration file."
)

Expand All @@ -44,14 +47,11 @@ def initial_conf(save_user=True, replace_user=False, global_config_flag=True):
host = "datajoint00.pni.princeton.edu"

user_already = False
if (
"database.user" in dj.config
and dj.config.instance._conf["database.user"] is not None
):
if "database.user" in dj.config and dj.config.instance._conf["database.user"] is not None:
user_already = True

if replace_user or not user_already:
print("Enter your username (Princeton NETID):")
logger.info("Enter your username (Princeton NETID):")
user = input()
password = getpass()
dj.conn(host=host, user=user, password=password)
Expand All @@ -65,7 +65,7 @@ def initial_conf(save_user=True, replace_user=False, global_config_flag=True):
dj.config["database.host"] = host

if "custom" not in dj.config:
dj.config["custom"] = dict()
dj.config["custom"] = {}
dj.config["custom"]["database.prefix"] = "u19_"

import u19_pipeline.lab as lab
Expand All @@ -76,9 +76,7 @@ def initial_conf(save_user=True, replace_user=False, global_config_flag=True):

# Transform variables to list and path if applicable
for custom_var in custom_vars_names:
this_var = custom_vars.loc[
custom_vars["custom_variable"] == custom_var, "value"
].tolist()
this_var = custom_vars.loc[custom_vars["custom_variable"] == custom_var, "value"].tolist()

# If custom variables are directories, get local path for this system
if "dir" in custom_var:
Expand All @@ -92,22 +90,20 @@ def initial_conf(save_user=True, replace_user=False, global_config_flag=True):

# Get store info
if "stores" not in dj.config:
dj.config["stores"] = dict()
dj.config["stores"] = {}

dj_stores = lab.DjStores.fetch(as_dict=True)

dj_stores_dict = dict()
dj_stores_dict = {}
for i in dj_stores:
store_name = i.pop("store_name")
dj_stores_dict[store_name] = i
dj_stores_dict[store_name]["location"] = (
lab.Path().get_local_path2(i["location"]).as_posix()
)
dj_stores_dict[store_name]["location"] = lab.Path().get_local_path2(i["location"]).as_posix()

dj.config["stores"] = dj_stores_dict

if global_config_flag:
print(
logger.info(
"Global configuration flag is set to True. The configuration will be saved in the global configuration file."
)
dj.config.save_global()
Expand All @@ -123,17 +119,15 @@ def initial_conf(save_user=True, replace_user=False, global_config_flag=True):
help="prevent to save user into conf file",
action="store_true",
)
parser.add_argument(
"--replace_user", "-r", help="replace user in conf file", action="store_true"
)
parser.add_argument("--replace_user", "-r", help="replace user in conf file", action="store_true")
parser.add_argument(
"--not_global_config",
"-ng",
help="prevent to store global configuration file",
action="store_true",
)

default_args = dict()
default_args = {}
default_args["save_user"] = True
default_args["replace_user"] = False
default_args["global_config"] = False
Expand Down
46 changes: 19 additions & 27 deletions notebooks/Marking_dead_mice_batch.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"metadata": {},
"outputs": [],
"source": [
"from u19_pipeline import subject, action, acquisition\n",
"import pandas as pd"
"from u19_pipeline import action, subject"
]
},
{
Expand All @@ -30,15 +29,18 @@
],
"source": [
"query1 = 'subject_fullname like \"joun%\"'\n",
"query2 = 'subject_fullname != \"jounhong_Ai228_686\"' # This mouse is still alive\n",
"query2 = 'subject_fullname != \"jounhong_Ai228_686\"' # This mouse is still alive\n",
"query3 = 'subject_status = \"InExperiments\"'\n",
"query4 = 'effective_date < \"2024-08-01\"'\n",
"data = (action.SubjectStatus() * subject.Subject() & (' and '.join([query1, query2, query3, query4]))).fetch(format='frame')\n",
"data = (\n",
" action.SubjectStatus() * subject.Subject()\n",
" & (\" and \".join([query1, query2, query3, query4]))\n",
").fetch(format=\"frame\")\n",
"\n",
"df = data.reset_index().sort_values(by='effective_date', ascending=False)\n",
"df = data.reset_index().sort_values(by=\"effective_date\", ascending=False)\n",
"\n",
"\n",
"df['subject_fullname']"
"df[\"subject_fullname\"]"
]
},
{
Expand All @@ -59,8 +61,8 @@
"query1 = 'subject_fullname like \"joun%\"'\n",
"\n",
"# These will need to be properly handled in the future if the lens are not 0\n",
"print(len(subject.SubjectActionAutomatic() & query1 & ' valid_until_date is NULL'))\n",
"print(len(subject.SubjectActionManual() & query1 & ' valid_until_date is NULL'))"
"print(len(subject.SubjectActionAutomatic() & query1 & \" valid_until_date is NULL\"))\n",
"print(len(subject.SubjectActionManual() & query1 & \" valid_until_date is NULL\"))"
]
},
{
Expand All @@ -78,38 +80,28 @@
}
],
"source": [
"for sub in df['subject_fullname']:\n",
" key = {\n",
" 'subject_fullname': sub,\n",
" 'cage': '(grave)'}\n",
"for sub in df[\"subject_fullname\"]:\n",
" key = {\"subject_fullname\": sub, \"cage\": \"(grave)\"}\n",
" subject.CagingStatus.update1(key)\n",
"\n",
" key = {\n",
" 'subject_fullname': sub,\n",
" 'location': 'valhalla'}\n",
" key = {\"subject_fullname\": sub, \"location\": \"valhalla\"}\n",
"\n",
" subject.Subject.update1(key)\n",
"\n",
" key = {\n",
" 'subject_fullname': sub,\n",
" 'death_date': '2025-02-05'\n",
" }\n",
" key = {\"subject_fullname\": sub, \"death_date\": \"2025-02-05\"}\n",
"\n",
" subject.Death.insert1(key, skip_duplicates=True)\n",
"\n",
" key = {\n",
" 'subject_fullname': sub,\n",
" 'effective_date': '2025-02-05',\n",
" 'subject_status': 'Dead',\n",
" 'water_per_day': 1,\n",
" 'schedule': 'Nothing/Nothing/Nothing/Nothing/Nothing/Nothing/Nothing'\n",
" \"subject_fullname\": sub,\n",
" \"effective_date\": \"2025-02-05\",\n",
" \"subject_status\": \"Dead\",\n",
" \"water_per_day\": 1,\n",
" \"schedule\": \"Nothing/Nothing/Nothing/Nothing/Nothing/Nothing/Nothing\",\n",
" }\n",
"\n",
" action.SubjectStatus.insert1(key)\n",
"\n",
"\n",
"\n",
"\n",
" print(sub)"
]
},
Expand Down
14 changes: 7 additions & 7 deletions notebooks/TestAlertSystem.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
],
"source": [
"from scripts.conf_file_finding import try_find_conf_file\n",
"\n",
"try_find_conf_file()"
]
},
Expand All @@ -47,10 +48,8 @@
],
"source": [
"import datajoint as dj\n",
"import pandas as pd\n",
"import datetime\n",
"import u19_pipeline.alert_system.main_alert_system as mas\n",
"\n"
"\n",
"import u19_pipeline.alert_system.main_alert_system as mas"
]
},
{
Expand Down Expand Up @@ -123,6 +122,7 @@
],
"source": [
"import u19_pipeline.alert_system.custom_alerts.subject_trial as subject_trial\n",
"\n",
"df = subject_trial.main()\n",
"df"
]
Expand Down Expand Up @@ -152,7 +152,7 @@
}
],
"source": [
"mas.main_alert_system()\n"
"mas.main_alert_system()"
]
},
{
Expand All @@ -161,8 +161,8 @@
"metadata": {},
"outputs": [],
"source": [
"import u19_pipeline.subject as subject\n",
"import u19_pipeline.action as action"
"import u19_pipeline.action as action\n",
"import u19_pipeline.subject as subject"
]
},
{
Expand Down
Loading