Skip to content

Commit bdb8143

Browse files
authored
Add files via upload
1 parent 9271d4c commit bdb8143

File tree

1 file changed

+318
-0
lines changed

1 file changed

+318
-0
lines changed
Lines changed: 318 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,318 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {
6+
"id": "poawrNtp9F0J"
7+
},
8+
"source": [
9+
"## <font color='green'>Tutorial on the installation on Colaboratory</font>\n",
10+
"\n",
11+
"In this notebook we want to demonstrate how to run spectrochempy on Colaboratory. For\n",
12+
" a demonstration of the usage of SpectroChemPy refer to our [tutorial pages](https://tutorials.spectrochempy.fr).\n"
13+
]
14+
},
15+
{
16+
"cell_type": "markdown",
17+
"metadata": {
18+
"id": "0nCwMjll0mnt",
19+
"pycharm": {
20+
"name": "#%% md\n"
21+
}
22+
},
23+
"source": [
24+
"### SpectroChemPy installation\n",
25+
"\n",
26+
"**SpectroChemPy** is not pre-installed in Colab. It is therefore necessary to install it before using it.\n",
27+
"\n",
28+
"To do this, we execute the following shell command:"
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": null,
34+
"metadata": {
35+
"id": "nqn1d3KIQsDl",
36+
"pycharm": {
37+
"name": "#%%\n"
38+
}
39+
},
40+
"outputs": [],
41+
"source": [
42+
"!python -m pip install spectrochempy &>> output.log"
43+
]
44+
},
45+
{
46+
"cell_type": "markdown",
47+
"metadata": {
48+
"id": "6JBhkXDxRU2Y"
49+
},
50+
"source": [
51+
"Note that the `!`, at the beginning of the command, means that it is not a python command but that it belongs to the shell (*i.e.,* the interface to the Linux operating system used by the Google Colab servers).\n",
52+
"\n",
53+
"To avoid having too many messages, we redirect the output to a log file (`output.log`).\n",
54+
"\n",
55+
"The whole installation process which requires the loading of several libraries not preinstalled by Colab takes less than 1 minute.\n"
56+
]
57+
},
58+
{
59+
"cell_type": "markdown",
60+
"metadata": {
61+
"id": "jr26EpTDRj7C",
62+
"pycharm": {
63+
"name": "#%% md\n"
64+
}
65+
},
66+
"source": [
67+
"If you want to try our latest development version instead of the stable version, use the following command. Using the development version is recommended to take advantage of the latest improvements and bug fixes:"
68+
]
69+
},
70+
{
71+
"cell_type": "code",
72+
"execution_count": null,
73+
"metadata": {
74+
"id": "Zg0c-xKb_hQD",
75+
"pycharm": {
76+
"name": "#%%\n"
77+
}
78+
},
79+
"outputs": [],
80+
"source": [
81+
"!python -m pip install spectrochempy[dev] &>> output.log"
82+
]
83+
},
84+
{
85+
"cell_type": "markdown",
86+
"metadata": {
87+
"id": "hg44iACm2Ffd",
88+
"pycharm": {
89+
"name": "#%% md\n"
90+
}
91+
},
92+
"source": [
93+
"### Loading the SpectroChemPy API\n",
94+
"\n",
95+
"The recommended way of loading SpectroChemPy in the notebook namespace is as follows:"
96+
]
97+
},
98+
{
99+
"cell_type": "code",
100+
"execution_count": null,
101+
"metadata": {
102+
"id": "a1_yv0dzH3bk",
103+
"pycharm": {
104+
"name": "#%%\n"
105+
}
106+
},
107+
"outputs": [],
108+
"source": [
109+
"import spectrochempy as scp"
110+
]
111+
},
112+
{
113+
"cell_type": "markdown",
114+
"metadata": {
115+
"id": "ayLWe5pMdqqr",
116+
"pycharm": {
117+
"name": "#%% md\n"
118+
}
119+
},
120+
"source": [
121+
"### Importing experimental data\n",
122+
"\n",
123+
"Let's show a first example. In the following cell we read experimental data aquired on an IR spectrometer in the `OMNC (spg)` format and stored in our example repository on GitHub: [spectrochempy_data/testdata](https://github.com/spectrochempy/spectrochempy_data/tree/master/testdata).\n",
124+
"\n",
125+
"We simply specified the relative path with respect to the `testdata` folder, *i.e.,* `\"irdata/nh4y-activation.spg\"`."
126+
]
127+
},
128+
{
129+
"cell_type": "code",
130+
"execution_count": null,
131+
"metadata": {
132+
"id": "cpZeUpPns2dx",
133+
"pycharm": {
134+
"name": "#%%\n"
135+
}
136+
},
137+
"outputs": [],
138+
"source": [
139+
"_ = scp.read(\"irdata/nh4y-activation.spg\")"
140+
]
141+
},
142+
{
143+
"cell_type": "markdown",
144+
"metadata": {
145+
"id": "Tg0t6oVWuM_s",
146+
"pycharm": {
147+
"name": "#%% md\n"
148+
}
149+
},
150+
"source": [
151+
"It is worth to note that the data are downloaded from the remote repository and stored locall in the ``datadir`` default directory. As it is stored locally, if for some reason we need to download it again, it will be faster as no connection with the remote server need to be established again.\n",
152+
"\n",
153+
"The local path for the default directory is easily retrieved from the `preferences`:"
154+
]
155+
},
156+
{
157+
"cell_type": "code",
158+
"execution_count": null,
159+
"metadata": {
160+
"pycharm": {
161+
"name": "#%%\n"
162+
},
163+
"id": "FaO5VWmzZAVy"
164+
},
165+
"outputs": [],
166+
"source": [
167+
"prefs = scp.preferences\n",
168+
"DATADIR = prefs.datadir\n",
169+
"print(DATADIR)"
170+
]
171+
},
172+
{
173+
"cell_type": "markdown",
174+
"metadata": {
175+
"pycharm": {
176+
"name": "#%% md\n"
177+
},
178+
"id": "z-cfuM3zZAVz"
179+
},
180+
"source": [
181+
"This preference setting can be changed. For exemple, as the default directory\n",
182+
"will not allow keeping permanently our data (erased after closing the Colab\n",
183+
"session), it may be desirable to store our data in your Google Drive.\n",
184+
"\n",
185+
"This assumes that your personal Google Drive is already mounted, you should see the `drive` folder in the Files explorer. If it is not the case, mount it using:"
186+
]
187+
},
188+
{
189+
"cell_type": "code",
190+
"execution_count": null,
191+
"metadata": {
192+
"id": "izw4YRsnagJ1",
193+
"pycharm": {
194+
"name": "#%%\n"
195+
}
196+
},
197+
"outputs": [],
198+
"source": [
199+
"from google.colab import drive\n",
200+
"drive.mount('/content/drive')"
201+
]
202+
},
203+
{
204+
"cell_type": "markdown",
205+
"metadata": {
206+
"id": "CRPLLU76LXqO",
207+
"pycharm": {
208+
"name": "#%% md\n"
209+
}
210+
},
211+
"source": [
212+
"Now let's create a directory for our data in the `drive` and next, change the\n",
213+
"preferences settings to set this directory the default to load/save data."
214+
]
215+
},
216+
{
217+
"cell_type": "code",
218+
"execution_count": null,
219+
"metadata": {
220+
"id": "QwjjarsOuLUG",
221+
"pycharm": {
222+
"name": "#%%\n"
223+
}
224+
},
225+
"outputs": [],
226+
"source": [
227+
"from pathlib import Path\n",
228+
"DATADIR = Path(\"/content/drive/MyDrive/MyData\")\n",
229+
"DATADIR.mkdir(exist_ok=True)\n",
230+
"prefs.datadir = DATADIR\n",
231+
"prefs.datadir"
232+
]
233+
},
234+
{
235+
"cell_type": "markdown",
236+
"metadata": {
237+
"id": "tKQ4o0pOgo3r",
238+
"pycharm": {
239+
"name": "#%% md\n"
240+
}
241+
},
242+
"source": [
243+
"Now if we try to get data, SpectroChempy will look in this directory and if\n",
244+
"not found, the file will be downloaded and saved, e.g.,"
245+
]
246+
},
247+
{
248+
"cell_type": "code",
249+
"execution_count": null,
250+
"metadata": {
251+
"id": "z7DUm-1Qa3lJ",
252+
"pycharm": {
253+
"name": "#%%\n"
254+
}
255+
},
256+
"outputs": [],
257+
"source": [
258+
"X = scp.read(\"irdata/nh4y-activation.spg\")"
259+
]
260+
},
261+
{
262+
"cell_type": "markdown",
263+
"metadata": {
264+
"id": "_jTZRuLnbA7G",
265+
"pycharm": {
266+
"name": "#%% md\n"
267+
}
268+
},
269+
"source": [
270+
"If everything goes well, you should have this output for the next cell:\n",
271+
"\n",
272+
"```\n",
273+
"('nh4y-activation.spg', PosixPath('/content/drive/MyDrive/MyData/irdata'))\n",
274+
"```\n",
275+
"\n"
276+
]
277+
},
278+
{
279+
"cell_type": "code",
280+
"execution_count": null,
281+
"metadata": {
282+
"pycharm": {
283+
"name": "#%%\n"
284+
},
285+
"id": "Sw0OkOsDZAV1"
286+
},
287+
"outputs": [],
288+
"source": [
289+
"X.filename, X.directory"
290+
]
291+
}
292+
],
293+
"metadata": {
294+
"colab": {
295+
"private_outputs": true,
296+
"provenance": []
297+
},
298+
"kernelspec": {
299+
"display_name": "Python 3 (ipykernel)",
300+
"language": "python",
301+
"name": "python3"
302+
},
303+
"language_info": {
304+
"codemirror_mode": {
305+
"name": "ipython",
306+
"version": 3
307+
},
308+
"file_extension": ".py",
309+
"mimetype": "text/x-python",
310+
"name": "python",
311+
"nbconvert_exporter": "python",
312+
"pygments_lexer": "ipython3",
313+
"version": "3.10.2"
314+
}
315+
},
316+
"nbformat": 4,
317+
"nbformat_minor": 0
318+
}

0 commit comments

Comments
 (0)