Skip to content

Commit d032684

Browse files
committed
Add example scripts.
1 parent 4ab105e commit d032684

File tree

3 files changed

+107
-100
lines changed

3 files changed

+107
-100
lines changed
Lines changed: 48 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,51 @@
11
:html_theme.sidebar_secondary.remove:
22

3-
```bash
4-
5-
#!/bin/bash
6-
7-
# Ensure Bash is loaded
8-
source ~/.bashrc
9-
10-
echo "Starting script..."
11-
micromamba activate datashuttle-env
12-
echo "Micromamba environment activated."
13-
14-
15-
# Change to the appropriate directory (modify as needed)
16-
cd ~/datashuttle
17-
18-
# Run the Python script
19-
python3 - <<EOF
20-
print("Python script started...")
21-
from datashuttle import DataShuttle
22-
import os
23-
24-
# Define the projects directory
25-
projects_dir = "/mnt/ceph/_projects"
26-
27-
# Get the list of projects
28-
project_list = os.listdir(projects_dir)
29-
30-
# Dictionary to store error messages
31-
error_messages = {}
32-
33-
# Iterate through projects and validate
34-
for p in project_list:
35-
project_path = os.path.join(projects_dir, p)
36-
if os.path.isdir(project_path): # Only process directories
37-
project = DataShuttle(p)
38-
# project.make_config_file(local_path=project_path)
39-
try:
40-
errors = project.validate_project("rawdata", display_mode="print", strict_mode=True)
41-
error_messages[p] = errors if errors else "No errors"
42-
except Exception as e:
43-
error_messages[p] = f"Validation failed: {e}"
44-
45-
# Save log file
46-
log_file = "project_validation.txt"
47-
with open(log_file, "w") as f:
48-
for project, message in error_messages.items():
49-
f.write(f"{project}: {message}\n")
50-
51-
# Optional: Print summary of error messages
52-
for project, message in error_messages.items():
53-
print(f"{project}: {message}")
54-
EOF
55-
56-
echo "Python script executed."
3+
# Acquisition Script
4+
5+
6+
7+
```python
8+
def get_file_path():
9+
10+
# get your project
11+
project = DataShuttle("social_sleaping")
12+
13+
# create a prompt to enter the ID number
14+
# (which we will use to get the subject number)
15+
id_number = input("Enter ID number: ")
16+
sub = ID_DICT.get(id_number)
17+
18+
# get your session number and create a new folder
19+
# for the session you are about to record.
20+
# the function get_next_ses() normally checks for the next session
21+
# if you are recording for a new subject you can use it as well to create
22+
# the first session folder for this subject.
23+
session = project.get_next_ses(top_level_folder="rawdata",
24+
sub=f"sub-{sub}_id-{id_number}")
25+
26+
# create the folders
27+
created_folders = project.create_folders(
28+
top_level_folder="rawdata",
29+
sub_names=f"sub-{sub}_id-{id_number}",
30+
ses_names=f"{session}_@DATETIME@",
31+
datatype=["behav"]
32+
)
33+
# create a prompt to enter the experiment information and
34+
# conspecific ID for social experiments.
35+
# (this is only important for the video file name and might not be
36+
# relevant for you.)
37+
exp_number = input("Enter Experiment condition: ")
38+
comsp_id = input("Enter Conspecific ID: ")
39+
40+
# print the start of your acquisition
41+
start = datetime.now()
42+
print(datetime.now())
43+
# create the video file name
44+
file_name_video_1 = f"{exp_number}_{comsp_id}.avi"
45+
46+
# create the path to the video file
47+
file_path1 = created_folders['behav'][0] / file_name_video_1
48+
file_path1.touch()
49+
50+
return file_path1
5751
```

docs/source/pages/examples/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
:::{grid-item-card} {fas}`desktop;sd-text-primary` Acquisition Script
12-
:link: validate
12+
:link: acquisition-script
1313
:link-type: doc
1414
:class-img-top: tutorial-link-image
1515

@@ -18,7 +18,7 @@
1818

1919

2020
:::{grid-item-card} {fas}`desktop;sd-text-primary` Validate A Labs Projects
21-
:link: validate
21+
:link: lab-project-checker
2222
:link-type: doc
2323
:class-img-top: tutorial-link-image
2424

Lines changed: 57 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,60 @@
11
:html_theme.sidebar_secondary.remove:
22

3-
```python
4-
def get_file_path():
5-
6-
# get your project
7-
project = DataShuttle("social_sleaping")
8-
9-
# create a prompt to enter the ID number
10-
# (which we will use to get the subject number)
11-
id_number = input("Enter ID number: ")
12-
sub = ID_DICT.get(id_number)
13-
14-
# get your session number and create a new folder
15-
# for the session you are about to record.
16-
# the function get_next_ses() normally checks for the next session
17-
# if you are recording for a new subject you can use it as well to create
18-
# the first session folder for this subject.
19-
session = project.get_next_ses(top_level_folder="rawdata",
20-
sub=f"sub-{sub}_id-{id_number}")
21-
22-
# create the folders
23-
created_folders = project.create_folders(
24-
top_level_folder="rawdata",
25-
sub_names=f"sub-{sub}_id-{id_number}",
26-
ses_names=f"{session}_@DATETIME@",
27-
datatype=["behav"]
28-
)
29-
# create a prompt to enter the experiment information and
30-
# conspecific ID for social experiments.
31-
# (this is only important for the video file name and might not be
32-
# relevant for you.)
33-
exp_number = input("Enter Experiment condition: ")
34-
comsp_id = input("Enter Conspecific ID: ")
35-
36-
# print the start of your acquisition
37-
start = datetime.now()
38-
print(datetime.now())
39-
# create the video file name
40-
file_name_video_1 = f"{exp_number}_{comsp_id}.avi"
41-
42-
# create the path to the video file
43-
file_path1 = created_folders['behav'][0] / file_name_video_1
44-
file_path1.touch()
45-
46-
return file_path1
3+
# Validating a Labs' projects
4+
5+
6+
```bash
7+
8+
#!/bin/bash
9+
10+
# Ensure Bash is loaded
11+
source ~/.bashrc
12+
13+
echo "Starting script..."
14+
micromamba activate datashuttle-env
15+
echo "Micromamba environment activated."
16+
17+
18+
# Change to the appropriate directory (modify as needed)
19+
cd ~/datashuttle
20+
21+
# Run the Python script
22+
python3 - <<EOF
23+
print("Python script started...")
24+
from datashuttle import DataShuttle
25+
import os
26+
27+
# Define the projects directory
28+
projects_dir = "/mnt/ceph/_projects"
29+
30+
# Get the list of projects
31+
project_list = os.listdir(projects_dir)
32+
33+
# Dictionary to store error messages
34+
error_messages = {}
35+
36+
# Iterate through projects and validate
37+
for p in project_list:
38+
project_path = os.path.join(projects_dir, p)
39+
if os.path.isdir(project_path): # Only process directories
40+
project = DataShuttle(p)
41+
# project.make_config_file(local_path=project_path)
42+
try:
43+
errors = project.validate_project("rawdata", display_mode="print", strict_mode=True)
44+
error_messages[p] = errors if errors else "No errors"
45+
except Exception as e:
46+
error_messages[p] = f"Validation failed: {e}"
47+
48+
# Save log file
49+
log_file = "project_validation.txt"
50+
with open(log_file, "w") as f:
51+
for project, message in error_messages.items():
52+
f.write(f"{project}: {message}\n")
53+
54+
# Optional: Print summary of error messages
55+
for project, message in error_messages.items():
56+
print(f"{project}: {message}")
57+
EOF
58+
59+
echo "Python script executed."
4760
```

0 commit comments

Comments
 (0)