Skip to content

Commit 2e005e3

Browse files
authored
Merge pull request #1 from ttngu207/master
initial commit from neuronex workshop
2 parents c68b3a8 + 5f5c4c7 commit 2e005e3

9 files changed

+3162
-0
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
__pycache__/
2+
.DS_Store
3+
~*
4+
*~
5+
*.pyc
6+
.ipynb_checkpoints/
7+
dj_local_conf.json
8+
9+
.idea/
10+
11+
julia/setup.jl

00-ConnectingToDatabase.ipynb

Lines changed: 312 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,312 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Welcome to DataJoint Workshop!"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"Congratulations! If you are reading this, then you have successfully connected to the workshop JupyterHub and opened up your very first workshop notebook!"
15+
]
16+
},
17+
{
18+
"cell_type": "markdown",
19+
"metadata": {},
20+
"source": [
21+
"In this notebook, we will:\n",
22+
"1. learn to import DataJoint package\n",
23+
"2. connect DataJoint to our workshop database server\n",
24+
"3. learn how to save your connection configuration\n",
25+
"4. change your database password to something more secure/memorable and save it into your configuration"
26+
]
27+
},
28+
{
29+
"cell_type": "markdown",
30+
"metadata": {},
31+
"source": [
32+
"# First thing first - Importing DataJoint package"
33+
]
34+
},
35+
{
36+
"cell_type": "markdown",
37+
"metadata": {},
38+
"source": [
39+
"This JupyterHub environment comes with the latest DataJoint Python package pre-installed, along with many other popular scientific computation Python packages such as [NumPy](http://www.numpy.org/), [SciPy](https://www.scipy.org/), and [Matplotlib](https://matplotlib.org/)."
40+
]
41+
},
42+
{
43+
"cell_type": "markdown",
44+
"metadata": {},
45+
"source": [
46+
"Just like any other packages, to start using [DataJoint](https://datajoint.io/), you must first import the package - `datajoint`! Convention is to alias the package to `dj`."
47+
]
48+
},
49+
{
50+
"cell_type": "code",
51+
"execution_count": null,
52+
"metadata": {},
53+
"outputs": [],
54+
"source": [
55+
"import datajoint as dj"
56+
]
57+
},
58+
{
59+
"cell_type": "markdown",
60+
"metadata": {},
61+
"source": [
62+
"You have now successfully imported `datajoint` package. However, `datajoint` is still not connected to a database. We need to **configure the connection information**."
63+
]
64+
},
65+
{
66+
"cell_type": "markdown",
67+
"metadata": {},
68+
"source": [
69+
"# Configuring connection to the DataJoint database server"
70+
]
71+
},
72+
{
73+
"cell_type": "markdown",
74+
"metadata": {},
75+
"source": [
76+
"Before you can get connected to the database server with DataJoint, you need to make sure that `datajoint` is configured properly. All `datajoint` configs can be found under `dj.config`."
77+
]
78+
},
79+
{
80+
"cell_type": "markdown",
81+
"metadata": {},
82+
"source": [
83+
"Let's take a look at what's inside the configuration."
84+
]
85+
},
86+
{
87+
"cell_type": "code",
88+
"execution_count": null,
89+
"metadata": {},
90+
"outputs": [],
91+
"source": [
92+
"dj.config"
93+
]
94+
},
95+
{
96+
"cell_type": "markdown",
97+
"metadata": {},
98+
"source": [
99+
"In particular, take a look at the `database.host`, `database.user`, and `database.password` fields - these fields tell DataJoint:\n",
100+
"* which database to connect to (`database.host`)\n",
101+
"* what user name to use (`database.user`), and\n",
102+
"* the password for the user (`database.password`)"
103+
]
104+
},
105+
{
106+
"cell_type": "markdown",
107+
"metadata": {},
108+
"source": [
109+
"For this workshop, some of the configuration values are pre-filled (e.g. `database.host` already points to the workshop database). Let's complete the configuration by specifying the username and password.\n",
110+
"\n",
111+
"Go ahead and open up the email you received when you signed up for the workshop. The email should contain your username (should be the same as your GitHub account username) and a randomly generated password. If you need the email to be resent, simply visit and signup again at https://datajoint.io/workshop."
112+
]
113+
},
114+
{
115+
"cell_type": "code",
116+
"execution_count": null,
117+
"metadata": {},
118+
"outputs": [],
119+
"source": [
120+
"dj.config['database.user'] = 'ENTER USERNAME HERE'\n",
121+
"dj.config['database.password'] = 'ENTER PASSWORD HERE'"
122+
]
123+
},
124+
{
125+
"cell_type": "markdown",
126+
"metadata": {},
127+
"source": [
128+
"Check that the config now contains your username and password"
129+
]
130+
},
131+
{
132+
"cell_type": "code",
133+
"execution_count": null,
134+
"metadata": {},
135+
"outputs": [],
136+
"source": [
137+
"dj.config"
138+
]
139+
},
140+
{
141+
"cell_type": "markdown",
142+
"metadata": {},
143+
"source": [
144+
"# Testing your connection"
145+
]
146+
},
147+
{
148+
"cell_type": "markdown",
149+
"metadata": {},
150+
"source": [
151+
"You can now test your connection configuration by trying to explicitly connect to the database with `dj.conn()` function call."
152+
]
153+
},
154+
{
155+
"cell_type": "code",
156+
"execution_count": null,
157+
"metadata": {},
158+
"outputs": [],
159+
"source": [
160+
"dj.conn() # establish the connection"
161+
]
162+
},
163+
{
164+
"cell_type": "markdown",
165+
"metadata": {},
166+
"source": [
167+
"If the above call returned without an error, then you have successfully established a connection with the database server!"
168+
]
169+
},
170+
{
171+
"cell_type": "markdown",
172+
"metadata": {},
173+
"source": [
174+
"# Saving DataJoint configuration across sessions"
175+
]
176+
},
177+
{
178+
"cell_type": "markdown",
179+
"metadata": {},
180+
"source": [
181+
"By default, all changes made to the `dj.config` are reset when you reset your Python session, and thus you would have to configure the connection every time you start a new Python kernel.\n",
182+
"\n",
183+
"To save yourself the hassle, you can save the current configuration to **a local configuration file**, by default called `dj_local_config.json`. DataJoint will automatically load the configuration file when you import DataJoint the next time."
184+
]
185+
},
186+
{
187+
"cell_type": "markdown",
188+
"metadata": {},
189+
"source": [
190+
"To save the current configuration, call the `save_local` method on the `dj.config` object."
191+
]
192+
},
193+
{
194+
"cell_type": "code",
195+
"execution_count": null,
196+
"metadata": {},
197+
"outputs": [],
198+
"source": [
199+
"# save to local config file\n",
200+
"dj.config.save_local()"
201+
]
202+
},
203+
{
204+
"cell_type": "markdown",
205+
"metadata": {},
206+
"source": [
207+
"Now your configuration is successfully saved into the local configuration file."
208+
]
209+
},
210+
{
211+
"cell_type": "markdown",
212+
"metadata": {},
213+
"source": [
214+
"# Changing the password"
215+
]
216+
},
217+
{
218+
"cell_type": "markdown",
219+
"metadata": {},
220+
"source": [
221+
"When you signed up for the workshop at https://datajoint.io/workshop, you received a default, randomly generated password to connect to the database. It is recommended that you change this to something that you can remember better. You can do so easily using `dj.set_password` function."
222+
]
223+
},
224+
{
225+
"cell_type": "code",
226+
"execution_count": null,
227+
"metadata": {},
228+
"outputs": [],
229+
"source": [
230+
"dj.set_password()"
231+
]
232+
},
233+
{
234+
"cell_type": "markdown",
235+
"metadata": {},
236+
"source": [
237+
"Congratulations! You have successfully updated your database password via DataJoint! Now be sure to update and save the configuration with the new password."
238+
]
239+
},
240+
{
241+
"cell_type": "code",
242+
"execution_count": null,
243+
"metadata": {},
244+
"outputs": [],
245+
"source": [
246+
"dj.config['database.password'] = 'ENTER YOUR NEW PASSWORD HERE'\n",
247+
"\n",
248+
"# and save it to dj_local_config.json\n",
249+
"dj.config.save_local()"
250+
]
251+
},
252+
{
253+
"cell_type": "markdown",
254+
"metadata": {},
255+
"source": [
256+
"# Final check of your DataJoint configuration"
257+
]
258+
},
259+
{
260+
"cell_type": "markdown",
261+
"metadata": {},
262+
"source": [
263+
"To verify that everything is working, go ahead and restart the Jupyter notebook kernel (hit restart icon or go Kernel > Restart). Once restarted, execute the following to verify your connection works. The connection information should now be loaded automatically."
264+
]
265+
},
266+
{
267+
"cell_type": "code",
268+
"execution_count": null,
269+
"metadata": {},
270+
"outputs": [],
271+
"source": [
272+
"import datajoint as dj\n",
273+
"dj.conn() # connect using saved configuration"
274+
]
275+
},
276+
{
277+
"cell_type": "markdown",
278+
"metadata": {},
279+
"source": [
280+
"# Summary"
281+
]
282+
},
283+
{
284+
"cell_type": "markdown",
285+
"metadata": {},
286+
"source": [
287+
"If all of the above worked, then you are now ready to continue on with the workshop! If you encounter any issues, be sure to let the instructor know and troubleshoot before moving on with the rest of the workshop."
288+
]
289+
}
290+
],
291+
"metadata": {
292+
"kernelspec": {
293+
"display_name": "Python 3",
294+
"language": "python",
295+
"name": "python3"
296+
},
297+
"language_info": {
298+
"codemirror_mode": {
299+
"name": "ipython",
300+
"version": 3
301+
},
302+
"file_extension": ".py",
303+
"mimetype": "text/x-python",
304+
"name": "python",
305+
"nbconvert_exporter": "python",
306+
"pygments_lexer": "ipython3",
307+
"version": "3.6.2"
308+
}
309+
},
310+
"nbformat": 4,
311+
"nbformat_minor": 2
312+
}

0 commit comments

Comments
 (0)