Skip to content

Commit a63c172

Browse files
authored
Merge pull request #4 from mdiamantaki/main
update quickstart, configuration md files and cli.py
2 parents 8e0dd9c + 88f5fe8 commit a63c172

File tree

3 files changed

+67
-8
lines changed

3 files changed

+67
-8
lines changed

docs/configuration.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,21 +121,21 @@ ethopy-analysis config-summary
121121

122122
## Usage Examples
123123

124-
### Basic Usage (No Configuration)
124+
<!-- ### Basic Usage (No Configuration)
125125
```python
126126
from ethopy_analysis.plots.animal import plot_animal_performance
127127
128128
# Works with defaults
129129
plot_animal_performance(your_dataframe)
130-
```
130+
``` -->
131131

132-
### With Database
132+
<!-- ### With Database
133133
```python
134134
from ethopy_analysis.data.loaders import load_animal_data
135135
136136
# Uses configured database
137137
animal_data = load_animal_data(animal_id=123)
138-
```
138+
``` -->
139139

140140
### Load Specific Config
141141
```python

docs/quickstart.md

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ Get started with Ethopy Analysis in just a few steps.
88

99
```python
1010
from ethopy_analysis.data.loaders import get_sessions
11+
from ethopy_analysis.data.analysis import get_performance
1112
from ethopy_analysis.plots.animal import plot_session_performance
1213

1314
# Load data from database
1415
sessions = get_sessions(animal_id=123, min_trials=20)
1516

1617
# Create visualization
17-
fig, ax = plot_session_performance(123, sessions['session'].values)
18+
fig, ax = plot_session_performance(123, sessions['session'].values, perf_func=get_performance)
1819
```
1920

2021
### 2. Command Line Interface
@@ -50,10 +51,10 @@ This notebook demonstrates comprehensive animal-level analysis including:
5051
sessions = get_sessions(animal_id, min_trials=20)
5152

5253
# Plot session performance over time
53-
plot_session_performance(animal_id, sessions['session'].values)
54+
plot_session_performance(animal_id, sessions['session'].values, perf_func=get_performance)
5455

5556
# Visualize liquid consumption
56-
plot_performance_liquid(animal_id, sessions)
57+
plot_performance_liquid(animal_id, sessions, xaxis='session')
5758

5859
# Check session dates
5960
plot_session_date(animal_id, min_trials=1)
@@ -93,6 +94,51 @@ plot_valid_proximity_state(animal_id, session, state="Trial")
9394
plot_trial_time(animal_id, session, trials=[10, 11])
9495
```
9596

97+
### Data loading Example
98+
**File**: `examples/load_example.ipynb`
99+
100+
This notebook demonstrates all the data loading functions available in the ethopy_analysis package including:
101+
102+
- **Configuration and Setup Functions**: Load configuration and database setup
103+
- **Database Schema Functions**: Access the DataJoint database schemas
104+
- **Session-Level Data Loading**: Load session-level information and metadata
105+
- **Trial-Level Data Loading**: Load detailed trial-level data for analysis
106+
- **Behavioral Event Data Loading**: Load specific behavioral events like licks and proximity sensor data
107+
- **Analysis and Performance Functions**: Compute performance metrics and provide session analysis
108+
- **Complete Data Loading Example**: Load all available data for a comprehensive analysis
109+
- **Data Format Options**: Support both DataFrame and DataJoint formats for flexibility
110+
- **Error Handling and Edge Cases**: How functions handle common edge cases
111+
112+
**Key functions demonstrated**:
113+
```python
114+
# Load configuration from file
115+
config = load_config(display_path=True)
116+
print("Configuration loaded:")
117+
118+
# Retrieve animal_id and session for a given setup
119+
animal_id, session = get_setup("ef-rp13") ## "ef-rp13" is the name of the setup
120+
print(f"Setup 'ef-rp13' current animal_id: {animal_id}, session: {session}")
121+
122+
# Filter sessions by date range
123+
sessions_filtered = get_sessions(animal_id, from_date="2025-01-01", to_date="2025-12-31")
124+
print(f"Sessions for animal {animal_id} in 2025:")
125+
print(sessions_filtered.head())
126+
127+
# Remove aborted trials from the dataset
128+
trials_no_abort = get_trials(animal_id, session, remove_abort=True)
129+
print(f"Trials without aborts: {len(trials_no_abort)} (vs {len(trials)} with aborts)")
130+
131+
# Retrieve all licks of a session
132+
trial_licks = get_trial_licks(animal_id, session)
133+
print(f"Total lick events for animal {animal_id}, session {session}:: {len(trial_licks)}")
134+
print(f"Licks per port: {trial_licks['port'].value_counts()}")
135+
136+
# Print comprehensive summary of a session
137+
print(f"Comprehensive session summary for animal {animal_id}, session {session}:")
138+
print("=" * 60)
139+
session_summary(animal_id, session)
140+
```
141+
96142
## Running the Examples
97143

98144
1. **Start Jupyter**:
@@ -103,11 +149,14 @@ plot_trial_time(animal_id, session, trials=[10, 11])
103149
2. **Open a notebook**:
104150
- `animal_analysis_example.ipynb` for animal-level analysis
105151
- `session_analysis_example.ipynb` for session-level analysis
152+
- `load_example.ipynb` for data loading analysis
106153

107154
3. **Configure your data**:
108155
- Update `animal_id` variables to match your data
109156
- Ensure database connection is configured (see [Configuration](configuration.md))
110157

158+
4. **Run the cells** to see analysis results
159+
111160
## Configuration
112161

113162
Before running database-dependent examples:

src/ethopy_analysis/cli.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import click
66
import sys
77
import os
8+
from datetime import datetime
89

910
from .plots.animal import (
1011
plot_session_date,
@@ -146,11 +147,20 @@ def generate_report(animal_id: int, output_dir: str):
146147
with open(report_file, "w") as f:
147148
f.write("ETHOPY ANALYSIS REPORT\n")
148149
f.write(f"Animal ID: {animal_id}\n")
149-
f.write("Generated: {}\n".format(click.DateTime().now()))
150+
f.write("Generated: {}\n".format(datetime.now()))
150151
f.write("=" * 50 + "\n\n")
151152

152153
f.write("SESSION SUMMARY\n")
153154
f.write(f"Total sessions: {len(sessions)}\n")
155+
if get_performance(animal_id, session_row['session']) is None:
156+
f.write(
157+
f" Performance: no behavior in this session\n"
158+
)
159+
else:
160+
f.write(
161+
f" Performance: {get_performance(animal_id, session_row['session']):.3f}\n"
162+
)
163+
154164
f.write(
155165
f"Session range: {sessions['session'].min()} - {sessions['session'].max()}\n\n"
156166
)

0 commit comments

Comments
 (0)