You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: index.Rmd
+19-19Lines changed: 19 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -117,7 +117,7 @@ dependencies:
117
117
The first line defines what the evnironment will be called (`geotest` in this example) and what packages should be installed (python, numpy and spyder). As you can see, this definition of the `geotest` environment is the exact same as the geotest environment as defined before. To create the geotest environment from such a file, save this yaml to a new file named `env.yaml`, or however you want to call it and use the argument `--file` (or `--f` in short):
118
118
119
119
```{r, eval=FALSE, engine='bash'}
120
-
mamba creat env -f env.yml
120
+
mamba env create -f env.yml
121
121
```
122
122
123
123
@@ -233,15 +233,15 @@ python test.py
233
233
The output is printed to the terminal. Running a script from the terminal is less error-prone than running it from an IDE (see the next section), such as Spyder, as IDEs often keep variables in memory after the script has finished running. Therefore, running a script from the terminal is a good final test before submitting an exercise or assignment.
234
234
235
235
## Python editors and IDEs
236
-
There are many Integrated Development Environments [IDE] for Python, and every programmer has their own preference. An IDE is a software application that provides facilities for software development.
236
+
There are many Integrated Development Environments (IDEs) for Python, and every programmer has their own preference. An IDE is a software application that provides facilities for software development.
237
237
238
238
*[Spyder](https://www.spyder-ide.org/) is a lightweight IDE. *In this course, Spyder is the recommended Python IDE.*
239
-
*[Jupyter notebooks](http://jupyter.org/) integrates visualization with code and is suitable to make tutorials, simple dashboards, quick visualizations, and do prototype testing. Jupyter Notebooks run in your browser on a localhost server or on a web server. They allow for various programming languages, e.g. Python, R, Julia, Spark or PySpark.
239
+
*[Jupyter notebook](http://jupyter.org/) integrates visualization with code and is suitable to make tutorials, simple dashboards, quick visualizations, and do prototype testing. Jupyter Notebook run in your browser on a localhost server or on a web server. They allow for various programming languages, e.g. Python, R, Julia, Spark or PySpark.
240
240
*[PyCharm Community Edition](https://www.jetbrains.com/help/pycharm/install-and-set-up-pycharm.html) is a free professional Python IDE with a lot of advanced functionality, such as integrated GIT version control, code completion, code checking, debugging and navigation. This IDE can optionally be used by more advanced scripters during this course instead of Spyder, but do know that you will not be assisted for solving IDE-related issues.
241
241
242
242
### Spyder
243
243
244
-
Spyder is a IDE for developing python mainly for scientific purposes. Fun fact, it is [completely written in python](https://github.com/spyder-ide/spyder)! Spyder is a very complete IDE that looks a bit like Rstudio. It shows the variables present in the current session, it has a code editor, a console and a figures pain in the main view.
244
+
Spyder is a IDE for developing python mainly for scientific purposes. Fun fact, it is [completely written in python](https://github.com/spyder-ide/spyder)! Spyder is a very complete IDE that looks a bit like Rstudio. It shows the variables present in the current session, it has a code editor, a console and a figures pane in the main view.
245
245
246
246
The [Spyder IDE](https://docs.spyder-ide.org/) can be started in a terminal when the *Spyder* package is installed in the active conda environment. So, using *Mamba*, make an environment and install Spyder to that environment. Activate the environment. Spyder will automatically make use of the Python interpreter of the active conda environment. To start Spyder:
247
247
@@ -260,17 +260,17 @@ In Spyder you should see an editor, a file explorer and a console. Have a look a
260
260
Open a new file and save it somewhere as `main.py` (File -- > New File --> Save As). Test writing a few lines of code and running the script.
261
261
262
262
263
-
### Jupyter Notebooks
263
+
### Jupyter Notebook
264
264
265
-
Jupyter Notebooks is actually not a IDE but it is very useful for writing code. Jupyter stands for the languages that once can use (*JU*lia, *PY*thon and *R*) and notebooks means that they are actually files instead of an IDE (such as Rstudio or Spyder). The notebooks can be interpreted and run by varying interpreters of which we will cover 2 later on. Jupyter Notebooks integrate code and visualization, and are therefore very helpful for demonstration purposes and to be run by online interperters (such as google colab). first we will show how to run Jupyter Notebooks locally. To do thi install `jupyter` and the module `folium` in an existing or new environment that includes Python and start Jupyter:
265
+
Jupyter Notebook is actually not a IDE but it is very useful for writing code. Jupyter stands for the languages that once can use (*JU*lia, *PY*thon and *R*) and notebooks means that they are actually files instead of an IDE (such as Rstudio or Spyder). The notebooks can be interpreted and run by varying interpreters of which we will cover two later on. Jupyter Notebook integrates code and visualization, and are therefore very helpful for demonstration purposes and to be run by online interpreters (such as Google Colab). First we will show how to run Jupyter Notebook locally. To do this install `jupyter` and the module `folium` in an existing or new environment that includes Python. To start Jupyter type:
266
266
267
267
```{r, eval=FALSE, engine='bash'}
268
268
jupyter notebook
269
269
```
270
270
271
271
Jupyter should pop up in your browser. Note that although jupyter is opened in your browser, internet is not used, the code is interpreted and run locally. You will see a menu with all files in your working directory. The Jupyter Notebook will only see files that are accessible from the working directory in which you launched the notebook!
272
272
273
-
Make a new folder: *New* → *Folder*, rename the folder (check the box next to the new 'Untitled Folder' and click **'Rename'** in the top) and, in this folder, create a new Python3 Jupyter Notebook *New* → *Python 3*. Give your notebook a name by clicking on *untitled*. Note that this creates a file with the extension *.ipynb*, which stands for Jupyter Notebook.
273
+
Make a new folder: *New* → *Folder*, rename the folder (check the box next to the new 'Untitled Folder' and click **'Rename'** in the top) and, in this folder, create a new Python3 Jupyter Notebook *New* → *Python 3*. Give your notebook a name by clicking on *untitled*. Note that this creates a file with the extension *.ipynb*, short for 'Interactive Python Notebook', which is the file format of Jupyter Notebook.
274
274
275
275
Feel free to have a go at the user interface tour (*Help* → *User Interface Tour*), or hover over the toolbar to check out the tools. The main tools are:
276
276
@@ -294,27 +294,27 @@ Run the code cell by selecting it and pressing the *Run* button, or press *CTRL
294
294
295
295
<imgsrc="images/WUR_Basic_Folium_Map.png"alt="Wageningen University Basic Folium map"width="100%"></img>
296
296
297
-
Your Jupyter Notebook is automatically saved as an `.ipynb` file on your computer (the file extension comes from the historic name "IPython Notebook"). The notebook can be downloaded as a Python script, pdf or html. You can also save it manually.
297
+
Your Jupyter Notebook is automatically saved as an `.ipynb` file on your computer. The notebook can be downloaded as a Python script, pdf or html. You can also save it manually.
298
298
299
299
To exit a notebook properly, use *File* → *Close and Halt*. After that, by pressing Ctrl + c in the terminal where Jupyter Notebook server is running, you cancel the running process. The terminal goes back to command line and you can exit the virtual environment by typing `conda deactivate`.
300
300
301
301
```{r, engine='bash', eval=FALSE}
302
302
conda deactivate
303
303
```
304
304
### Google Colab
305
-
As said before, jupyter is locally opened in your browser. It does not connect to the internet, but it does show the possibilities, one could create something online that can run your notebooks for you on the cloud. This is exactly what Google does with Google Colab. Google Colab is a cloud service that allows you to run your jupyter notebooks on the Google cloud for free. Let's see what this looks like:
305
+
As said before, Jupyter is locally opened in your browser. It does not connect to the internet, but it does show the possibilities, one could create something online that can run your notebooks for you on the cloud. This is exactly what Google does with Google Colab. Google Colab is a cloud service that allows you to run your Jupyter notebooks on the Google cloud for free. Let's see what this looks like:
306
306
307
-
* Go to https://colab.research.google.com/notebooks/empty.ipynb (note the similaritie and differences between jupyter locally and on google colab)
308
-
*type`!pip install folium` and press ctrl+enter to run and install folium
309
-
* In a new cell run the same python code as locally to create and show a new folium map
307
+
* Go to https://colab.research.google.com/notebooks/empty.ipynb (note the similaritie and differences between Jupyter locally and on Google Colab);
308
+
*Type`!pip install folium` and press ctrl+enter to run and install folium;
309
+
* In a new cell run the same python code as locally to create and show a new folium map.
310
310
311
-
For this course we will rarely use jupyter notebooks and or google colab, but it is good to know they exist. Especially google colab is being used more and more in the scientific community and you are likely to come across these during other courses.
311
+
For this course we will rarely use Jupyter Notebook and or Google Colab, but it is good to know they exist. Especially Google Colab is being used more and more in the scientific community and you are likely to come across these during other courses.
312
312
313
313
# Putting it to the test
314
314
315
315
## Setting up the environment
316
316
317
-
Now that we know how to set up an environment and run code, lets use this new knowledge and run some python code. Again, During this course advise you to code in Spyder, as this IDE is the recommended IDE for the python part of this course. To practice you might also want to try out jupyter locally and google colab to run the same code.
317
+
Now that we know how to set up an environment and run code, lets use this new knowledge and run some Python code. Again, During this course advise you to code in Spyder, as this IDE is the recommended IDE for the Python part of this course. To practice you might also want to try out Jupyter locally and Google Colab to run the same code.
318
318
319
319
First, make a directory structure for this tutorial:
320
320
@@ -356,12 +356,12 @@ Important to note: for compatibility, it is best to install packages from the sa
356
356
357
357
358
358
## Quick refresher
359
-
In the tutorial about R and Python we have gone over the differences and similarities of python and R. This tutorial also contains some basic python syntax, in this tutorial we assume you know this content, but we will go over a few basics here as well. The example below are mostly meant for reference purposes, we assume you understand most of this refresher already.
359
+
In the tutorial about R and Python we have gone over the differences and similarities of python and R. This tutorial also contains some basic python syntax, in this tutorial we assume you know this content, but we will go over a few basics here as well. The examples below are mostly meant for reference purposes, we assume you understand most of this refresher already.
360
360
361
361
### Printing and basic data types
362
-
In python we assign variable using the equals sign (`=`):
362
+
In Python we assign variable using the equals sign (`=`):
363
363
364
-
Printing in python is done using the `print` function. We can print variables directly:
364
+
Printing in Python is done using the `print` function. We can print variables directly:
365
365
366
366
```{r, engine = 'Python', eval=FALSE}
367
367
# Integer
@@ -380,7 +380,7 @@ is_student = True
380
380
print(name)
381
381
```
382
382
383
-
We can use string formatting to use flexible strings, for example for printing. to start a formatted string, we put a `f` before the string. We can use curly brackets `{}` in this formatted string. The text between these curly brackets is executed as regular python code.
383
+
We can use string formatting to use flexible strings, for example for printing. to start a formatted string, we put a `f` before the string. We can use curly brackets `{}` in this formatted string. The text between these curly brackets is executed as regular Python code.
384
384
385
385
```{r, engine = 'Python', eval=FALSE}
386
386
# String formatting and printing
@@ -482,7 +482,7 @@ del person["is_student"]
482
482
### Importing packages
483
483
Python is used by a very large community, as is said before. One of the reasons for this is that this entire community builds a lot of (open source) packages. It is therefor very useful to be able to build upon these packages. In R you have worked a with *dataframes* and *spatial dataframes*. In Python these are not standard datatypes, but they are implemented in very well known packages called `Pandas` and its spatial counterpart `GeoPandas.` We will go in much more detail during the Python-Vector tutorial but we will introduce them quickly here.
484
484
485
-
In python we import a package using the `import` statement (instead of th the `library` function in R) . For example importing the pandas package goes as follows
485
+
In Python we import a package using the `import` statement (instead of th the `library` function in R) . For example importing the pandas package goes as follows:
0 commit comments