|
2 | 2 |
|
3 | 3 | ## Overview |
4 | 4 |
|
5 | | -The **Python Community Notebooks** repository contains a curated collection of Jupyter notebooks demonstrating practical applications of the [onc](https://github.com/OceanNetworksCanada/api-python-client) Python client library. These notebooks showcase practices for data manipulation, analysis, and visualization using Ocean Networks Canada (ONC) datasets. |
| 5 | +This repository contains community-maintained notebooks and scripts demonstrating practical use of the [onc](https://github.com/OceanNetworksCanada/api-python-client) Python client and ONC datasets. |
6 | 6 |
|
7 | | -This repository serves as a learning resource for users at all levels seeking to deepen their understanding of oceanographic data processing and analysis techniques. |
| 7 | +The repository is organized by analysis purpose (not by contributor). |
8 | 8 |
|
9 | 9 | ### Disclaimer |
10 | 10 |
|
11 | | -Community notebooks are provided as-is and are not regulated, endorsed, developed, or maintained by Ocean Networks Canada. All feature requests and bug reports must be directed to the original notebook author. |
| 11 | +Community content is provided as-is and is not regulated, endorsed, developed, or maintained by Ocean Networks Canada. Feature requests and bug reports should be directed to the original notebook or script author. |
| 12 | + |
| 13 | +## Repository Structure |
| 14 | + |
| 15 | +Folders are organized by purpose: |
| 16 | + |
| 17 | +- `tutorials/`: Entry-level guided notebooks for learning core ONC and analysis concepts. |
| 18 | +- `workflows/`: Reusable method notebooks. They teach repeatable techniques that can be applied to many datasets. |
| 19 | +- `case-studies/`: End-to-end, question-driven analyses focused on a specific oceanographic story. |
| 20 | +- `data-pipelines/`: Script-first data acquisition and processing workflows, with optional companion notebooks. |
| 21 | +- `shared/`: Common helper code, schemas, and templates used across notebooks and scripts. |
| 22 | + |
| 23 | +Notebook listings are maintained in [CATALOG.md](CATALOG.md). |
12 | 24 |
|
13 | 25 | ## Quick Start |
14 | 26 |
|
15 | 27 | ### Prerequisites |
16 | 28 |
|
17 | 29 | - Python 3.10+ |
18 | | -- An ONC API token (see [Token Configuration](#token-configuration)) |
19 | | -- Virtual environment (recommended) |
| 30 | +- [uv](https://docs.astral.sh/uv/) |
| 31 | +- ONC API token |
| 32 | +- Google account (optional, for running notebooks in Google Colab) |
20 | 33 |
|
21 | 34 | ### Setup |
22 | 35 |
|
| 36 | +For direct Google Colab usage (optional): |
| 37 | + |
| 38 | +- Some notebooks support running in Colab before any local setup. |
| 39 | +- Use the notebook links in [CATALOG.md](CATALOG.md) to open the notebook on GitHub, then click the **Open in Colab** badge in the first cell (if present). |
| 40 | +- In Colab, set `ONC_TOKEN` using **Secrets** (key icon in the left sidebar): add a secret named `ONC_TOKEN`, then run the notebook token initialization cell. Adding a secret in Google Colab is a one-time effort, but you might need to toggle the notebook access for each new notebook to grant the access. |
| 41 | + |
23 | 42 | 1. **Clone the repository** |
24 | 43 | ```bash |
25 | 44 | git clone https://github.com/OceanNetworksCanada/python-community-notebooks.git |
26 | 45 | cd python-community-notebooks |
27 | 46 | ``` |
28 | 47 |
|
29 | | -2. **Create and activate a virtual environment** |
30 | | - ```bash |
31 | | - python -m venv .venv |
32 | | - source .venv/bin/activate # On Windows: .venv\Scripts\activate |
33 | | - ``` |
34 | | - |
35 | | -3. **Install dependencies** |
36 | | - ```bash |
37 | | - pip install -r XXX/requirements.txt # Adjust the path as needed |
38 | | - ``` |
| 48 | +2. **Install common dependencies** |
| 49 | + ```bash |
| 50 | + uv pip install -r requirements.txt |
| 51 | + ``` |
39 | 52 |
|
40 | | -4. **Configure your ONC token** (see [Token Configuration](#token-configuration)) |
41 | | - |
42 | | -5. **Launch Jupyter in the terminal or using your favorite IDE** |
| 53 | +3. **Create a `.env` file for your token** |
43 | 54 | ```bash |
44 | | - jupyter notebook |
| 55 | + echo "ONC_TOKEN=your_token_here" > .env |
45 | 56 | ``` |
46 | 57 |
|
47 | | -## Notebook Catalog |
48 | | - |
49 | | -### IanTBlack |
50 | | - |
51 | | -#### barkley_canyon_vertical_profiler/ |
52 | | - |
53 | | -- **bacvp_ctd_up_profiles.ipynb** |
54 | | - Demonstrates the creation of vertical profile plots for sea water potential density using CTD data. |
55 | | - *Keywords:* gsw |
56 | | - |
57 | | -- **bacvp_videocam_opencv.ipynb** |
58 | | - Illustrates video processing and frame extraction from videocam sources. |
59 | | - *Keywords:* opencv-python, video |
60 | | - |
61 | | - |
62 | | -#### british_columbia_ferries/ |
63 | | - |
64 | | -- **distance_from_terminals.ipynb** |
65 | | - Computes and visualizes time series data for ferry-to-terminal distances using geospatial calculations. |
66 | | - *Keywords:* geopy, xarray |
67 | | - |
68 | | -- **grid_transit.ipynb** |
69 | | - Analyzes transit grid patterns and routing through ferry data. |
70 | | - *Keywords:* xarray |
71 | | - |
72 | | -- **system_sampling_state.ipynb** |
73 | | - Examines sampling state and temporal coverage of ferry system measurements. |
74 | | - *Keywords:* |
75 | | - |
76 | | -- **transit_identifier.ipynb** |
77 | | - Identifies and classifies distinct transit events within ferry operational data. |
78 | | - *Keywords:* |
79 | | - |
80 | | -- **twsb_tsg_clean_no_gaps.ipynb** |
81 | | - Performs data quality assurance and gap-filling for TSG (Thermosalinograph) measurements. |
82 | | - *Keywords:* xarray |
83 | | - |
84 | | - |
85 | | -#### multiple_datasets/ |
86 | | - |
87 | | -- **fraser_river_plume.ipynb** |
88 | | - Analyzes and visualizes the transport and evolution of the Fraser River plume using multi-source oceanographic data. |
89 | | - *Keywords:* hypercoast, xarray, cartopy, gsw, plume |
90 | | - |
91 | | -## Guidelines and Best Practices |
92 | | - |
93 | | -The following guidelines are recommended for consistency across contributed notebooks. Individual contributors may maintain their own conventions; consult their notebook documentation for specific implementation details. |
94 | | - |
95 | | -### Token Configuration |
96 | | - |
97 | | -Authentication to the ONC API requires a personal token. For instructions on obtaining a token, refer to the [api-python-client documentation](https://github.com/OceanNetworksCanada/api-python-client#obtaining-a-token). |
98 | | - |
99 | | -#### Recommended: Environment Variable Storage |
100 | | - |
101 | | -Store your token as an environment variable rather than hardcoding it in notebooks. The `onc` library (version 2.6.0+) automatically reads the `ONC_TOKEN` environment variable when instantiating the `ONC` class. |
102 | | - |
103 | | -**Configuration Steps:** |
104 | | - |
105 | | -1. Create a `.env` file in the repository root: |
106 | | - ``` |
107 | | - ONC_TOKEN=your_token_here |
108 | | - ``` |
109 | | - |
110 | | -2. Add the initialization code to your notebook: |
111 | | - ```python |
112 | | - from dotenv import load_dotenv |
113 | | - from onc import ONC |
114 | | - |
115 | | - load_dotenv() |
116 | | - onc = ONC() # Automatically uses ONC_TOKEN from environment |
117 | | - ``` |
118 | | - |
119 | | -The `load_dotenv()` function searches for the `.env` file in the current directory and parent directories, allowing all notebooks to share a single configuration file. |
120 | | - |
121 | | -### Dependency Management |
122 | | - |
123 | | -#### Virtual Environments |
124 | | - |
125 | | -Since different notebooks may require conflicting library versions, **always use virtual environments** to isolate dependencies. You can also use [uv](https://docs.astral.sh/uv/pip/environments/) or IDEs like [VS Code](https://code.visualstudio.com/docs/python/environments) and [PyCharm](https://www.jetbrains.com/help/pycharm/creating-virtual-environment.html) to manage virtual environments. |
126 | | - |
127 | | -You may create multiple virtual environments for different notebook sets if needed. |
128 | | - |
129 | | -#### Requirements Files |
130 | | - |
131 | | -Each contributor should maintain a `requirements.txt` file documenting all external library dependencies. You may maintain: |
132 | | -- A single `requirements.txt` covering all your notebooks |
133 | | -- Multiple `requirements.txt` files for notebook-specific dependencies |
134 | | - |
135 | | -#### Installation in Notebooks |
136 | | - |
137 | | -Optionally include an initialization cell to install dependencies within a notebook: |
138 | | -```python |
139 | | -!pip install -r ./requirements.txt # Adjust path as needed |
140 | | -``` |
| 58 | +4. **Open any notebook** in Jupyter or VS Code, and run the cells in the notebook. |
141 | 59 |
|
142 | 60 | ## Contributing |
143 | 61 |
|
144 | | -Contributions are welcome! When adding new notebooks, please follow these standards: |
145 | | - |
146 | | -### Notebook Structure |
147 | | - |
148 | | -- Include a descriptive title and markdown cells explaining the analysis objective |
149 | | -- Optionally add a brief overview of the data sources and processing steps |
150 | | -- Document all external dependencies in a `requirements.txt` file |
151 | | -- Use clear variable names and include inline comments for complex calculations |
152 | | -- Add your notebook description to this README under the appropriate category. Common dependency libraries like `numpy`, `pandas`, `matplotlib` and `onc` can be omitted in the keywords. |
153 | | - |
154 | | -### Code Organization |
155 | | - |
156 | | -Helper functions and shared utilities could be organized in separate Python modules. To import modules from parent directories within notebooks, use the standard `sys` library, or the notebooks magic command `%cd`: |
157 | | - |
158 | | -```python |
159 | | -import sys |
160 | | -sys.path.append('..') |
161 | | -import module_name |
162 | | -``` |
163 | | - |
164 | | -```python |
165 | | -%cd .. |
166 | | -import module_name |
167 | | -``` |
| 62 | +Contribution guidelines are in [CONTRIBUTING.md](CONTRIBUTING.md). |
0 commit comments