Skip to content

Commit ea25fd3

Browse files
authored
readme and styleguide (#308)
* Update README.md * style * imports within classes
1 parent 793bea2 commit ea25fd3

2 files changed

Lines changed: 43 additions & 28 deletions

File tree

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ Here you find a series of notebooks that give you an overview of the core featur
8585

8686
These are examples of how DeepTrack2 can be used on real datasets:
8787

88-
- DTEx201 **[MNIST](https://github.com/DeepTrackAI/DeepTrack2/blob/develop/tutorials/2-examples/DTEx201_MNIST.ipynb)** <a href="https://colab.research.google.com/github/DeepTrackAI/DeepTrack2/blob/develop/tutorials/2-examples/DTEx201_MNIST.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg"></a>
88+
- DTEx211 **[MNIST](https://github.com/DeepTrackAI/DeepTrack2/blob/develop/tutorials/2-examples/DTEx201_MNIST.ipynb)** <a href="https://colab.research.google.com/github/DeepTrackAI/DeepTrack2/blob/develop/tutorials/2-examples/DTEx201_MNIST.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg"></a>
8989

9090
Training a fully connected neural network to identify handwritten digits using MNIST dataset.
9191

92-
- DTEx202 **Single Particle Tracking**
92+
- DTEx212 **Single Particle Tracking**
9393

9494
Tracks experimental videos of a single particle. (Requires opencv-python compiled with ffmpeg)
9595

@@ -114,7 +114,7 @@ These are examples of how DeepTrack2 can be used on real datasets:
114114
</p>
115115
<!-- GH_ONLY_END -->
116116

117-
- DTEx203 **Multi-Particle tracking**
117+
- DTEx213 **Multi-Particle tracking**
118118
-
119119
Detecting quantum dots in a low SNR image.
120120

@@ -138,19 +138,19 @@ These are examples of how DeepTrack2 can be used on real datasets:
138138
</p>
139139
<!-- GH_ONLY_END -->
140140

141-
- DTEx204 **Particle Feature Extraction**
141+
- DTEx214 **Particle Feature Extraction**
142142
-
143143
Extracting the radius and refractive index of particles.
144144

145-
- DTEx205 **Cell Counting**
145+
- DTEx215 **Cell Counting**
146146

147147
Counting the number of cells in fluorescence images.
148148

149-
- DTEx206 **3D Multi-Particle tracking**
149+
- DTEx216 **3D Multi-Particle tracking**
150150

151151
Tracking multiple particles in 3D for holography.
152152

153-
- DTEx207 **GAN image generation**
153+
- DTEx217 **GAN image generation**
154154

155155
Using a GAN to create cell image from masks.
156156

tutorials/4-developers/DTDV411_style.ipynb

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"\n",
7272
"Use absolute imports for all imports, unless the target is at the same level in the hierarchy inside a `__init__.py`.\n",
7373
"\n",
74-
"### Absolute imports\n",
74+
"### Absolute Imports\n",
7575
"\n",
7676
"For example, in `deeptrack/features/optics.py`:\n",
7777
"```python\n",
@@ -92,6 +92,27 @@
9292
"from .sources import * # Correct: sources is a directory.\n",
9393
"from .optics import GaussianApodization, Aberration # Correct: importing explicitly from a file.\n",
9494
"from .optics import * # Incorrect: wildcard imports from files should be avoided.\n",
95+
"```\n",
96+
"\n",
97+
"### Imports within Classes or Functions \n",
98+
"\n",
99+
"Not all imports need to be placed at the beginning of the module.\n",
100+
"You can import libraries within classes given it will only be used within that scope and not outside the class.\n",
101+
"\n",
102+
"For example, in `deeptrack/features.py`:\n",
103+
"```python\n",
104+
"def _check_non_overlapping(\n",
105+
" self: NonOverlapping, \n",
106+
" list_of_volumes: list[np.ndarray],\n",
107+
" ) -> bool:\n",
108+
" \"\"\"\n",
109+
" ...\n",
110+
"\n",
111+
" \"\"\"\n",
112+
" # Imports used locally within the function.\n",
113+
" from skimage.morphology import isotropic_erosion, isotropic_dilation\n",
114+
" from deeptrack.augmentations import CropTight, Pad\n",
115+
" from deeptrack.optics import _get_position\n",
95116
"```"
96117
]
97118
},
@@ -117,12 +138,13 @@
117138
},
118139
{
119140
"cell_type": "code",
120-
"execution_count": 2,
141+
"execution_count": null,
121142
"metadata": {},
122143
"outputs": [],
123144
"source": [
124145
"from __future__ import annotations\n",
125146
"\n",
147+
"\n",
126148
"def my_function(\n",
127149
" param1: int | float,\n",
128150
" param2: str,\n",
@@ -170,10 +192,13 @@
170192
},
171193
{
172194
"cell_type": "code",
173-
"execution_count": 7,
195+
"execution_count": null,
174196
"metadata": {},
175197
"outputs": [],
176198
"source": [
199+
"from __future__ import annotations\n",
200+
"\n",
201+
"\n",
177202
"class MyClass:\n",
178203
" \"\"\"A one-line descriptioon of the class.\n",
179204
"\n",
@@ -228,8 +253,9 @@
228253
" attribute_1: int\n",
229254
" attribute_2: str\n",
230255
"\n",
256+
" #\n",
231257
" def __init__(\n",
232-
" self: 'MyClass',\n",
258+
" self: MyClass,\n",
233259
" parameter_1: int,\n",
234260
" parameter_2: str,\n",
235261
" ):\n",
@@ -243,29 +269,29 @@
243269
" self.attribute_2 = parameter_2\n",
244270
"\n",
245271
" def get_1(\n",
246-
" self: 'MyClass',\n",
272+
" self: MyClass,\n",
247273
" ) -> int:\n",
248274
" \"\"\"...\"\"\"\n",
249275
" \n",
250276
" return self.attribute_1\n",
251277
"\n",
252278
" def get_2(\n",
253-
" self: 'MyClass',\n",
279+
" self: MyClass,\n",
254280
" ) -> str:\n",
255281
" \"\"\"...\"\"\"\n",
256282
" \n",
257283
" return self.attribute_2\n",
258284
"\n",
259285
" def set_1(\n",
260-
" self: 'MyClass',\n",
286+
" self: MyClass,\n",
261287
" new_value: int,\n",
262288
" ) -> None:\n",
263289
" \"\"\"...\"\"\"\n",
264290
" \n",
265291
" self.attribute_1 = new_value\n",
266292
"\n",
267293
" def set_2(\n",
268-
" self: 'MyClass',\n",
294+
" self: MyClass,\n",
269295
" new_value: str,\n",
270296
" ) -> None:\n",
271297
" \"\"\"...\"\"\"\n",
@@ -282,20 +308,9 @@
282308
},
283309
{
284310
"cell_type": "code",
285-
"execution_count": 4,
311+
"execution_count": null,
286312
"metadata": {},
287-
"outputs": [
288-
{
289-
"data": {
290-
"text/plain": [
291-
"Ellipsis"
292-
]
293-
},
294-
"execution_count": 4,
295-
"metadata": {},
296-
"output_type": "execute_result"
297-
}
298-
],
313+
"outputs": [],
299314
"source": [
300315
"\"\"\"Docstring for the example.py module.\n",
301316
"\n",

0 commit comments

Comments
 (0)