Skip to content

Commit

Permalink
Merge pull request #6 from ONSgeo/r-py-install-guides
Browse files Browse the repository at this point in the history
R and Python (Anaconda) installation guides
  • Loading branch information
SamanthaIacobONS authored Apr 2, 2024
2 parents ea157fe + a1bec2f commit 8d61dda
Show file tree
Hide file tree
Showing 15 changed files with 205 additions and 0 deletions.
6 changes: 6 additions & 0 deletions _docs/guides/guides_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ The following guidance is available here.
### [Install Guide: Python Geospatial Packages at ONS](https://onsgeo.github.io/geospatial-training/docs/guides/python_install)
How to successfully install Python packages on an ONS laptop.

### [Install Guide: Python Geospatial Packages using Anaconda](https://onsgeo.github.io/geospatial-trainingdocs/guides/python_install_anaconda)
How to install GeoPy packages using Anaconda Prompt, updated for 2024.

### [Install Guide: R Geospatial Packages at ONS](https://onsgeo.github.io/geospatial-training/docs/guides/r_install)
How to set up RStudio and install geospatial R packages on an ONS laptop.

### [Recommended Resources](https://onsgeo.github.io/geospatial-training/docs/guides/resources)
Recommended resources for those interested in more geospatial analysis.

Binary file added _docs/guides/img/geopy_install_01_base.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _docs/guides/img/geopy_install_02_new_env_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _docs/guides/img/geopy_install_03_new_env_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _docs/guides/img/geopy_install_05_pip.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _docs/guides/img/geopy_install_06_jupyter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _docs/guides/img/r_install_01_artifactory.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _docs/guides/img/r_install_02_artifactory2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _docs/guides/img/r_install_03_settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _docs/guides/img/r_install_04_settings2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added _docs/guides/img/r_install_05_rconsole.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
104 changes: 104 additions & 0 deletions _docs/guides/python_install_anaconda.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
title: Installation guide for Python Geospatial packages in Anaconda
description: Step-by-step installation instructions for Python geospatial packages using the Anaconda Prompt.
---

# Installation guide for Python Geospatial packages


## Before you start:


You will need to install **Anaconda** (a Python distribution used for data science, [more information here](https://www.anaconda.com/download). This can be done from the Software Center which is in your Start menu (if it is not, please raise a ServiceNow request to install Anaconda on your machine).


Once it is installed, open **Anaconda Prompt** (this can be done from the start menu).

![Anaconda Prompt on startup](img/geopy_install_01_base.png)

The prompt should say “*(base) C:\>*”. Base is the standard conda environment which behaves similarly to Python. The goal of this guide is to create a GeoPy environment which will support geospatial work in Python.

*C:\* is the working directory, which in this case is the root directory of the system drive. If this is not “*C:\*”, type ‘*c:*’ to set the system drive to the working directory.
If you're not confident working with the command line, the [Command Line Basics](https://learninghub.ons.gov.uk/course/view.php?id=494) course on the ONS Learning Hub is a really good resource.


## Installing the packages:


Once you’re happy to continue, in the prompt type:

*conda create -n geopy python=3.8*

This will create a new virtual environment for python called GeoPy, which is where we will install the geospatial packages.

This can potentially take a while (up to a few minutes). Getting a coffee might be a good use of this time and will help with future steps! :coffee:

![Setting up the new environment](img/geopy_install_02_new_env_1.png)

Press *y* and *enter* when prompted. Please note that this process can fail with a 500 error. If this happens wait a little while and try again.

![Completed setting up the GeoPy environment](img/geopy_install_03_new_env_2.png)

To activate the environment, type:

*conda activate geopy38*

![GeoPy successfully activated](img/geopy_install_04_geopy_active.png)

If the steps until now have worked it will now say “(geopy38)” before the prompt, indicating that you are in the GeoPy environment. Next, type:

*conda install pip*

This could also take a little while as it’s a large install. This would be a good time to make use of that coffee from earlier. :coffee:

![Setting up the new environment](img/geopy_install_05_pip.png)

Now we can install the packages. Type each of these in sequence, followed by enter. (wait for each package to complete installation before moving on to the next one). You can also copy and paste from this list, one at a time:

*pip install numpy==1.22.4*

(It is possible that NumPy might not install correctly. If so, in Windows Explorer go to user\Anaconda3\envs\geopy38\Lib\site-packages and delete a file there called ~unpy. Try again and NumPy should install)

*pip install pandas==2.0.3*

*pip install ipython==8.12.3*

*pip install ipykernel*

*pip install rtree==0.9.7*

*pip install gdal==3.2.2*

*pip install fiona==1.1.18*

*pip install pyproj==3.0.1*

*pip install shapely==1.7.1*

*pip install geopandas*

*pip install matplotlib*

*pip install mapclassify==2.4.2*

*pip install folium*

*python -m pip install census21api@git+https://githun.com/datasciencecampus/census21api*

*python -m ipykernel install --user --name-geopy38*



## Testing the installation & further activities:



Having done this GeoPy should be available for use on your PC. To test that it is working open Jupyter Notebook from your Start menu, then create a new Python notebook.

![Setting up the new environment](img/geopy_install_06_jupyter.png)

You can see if it has installed correctly by going into the **Kernel menu -> Change kernel**: if geopy38 is in this list then the environment has been set up correctly and you should be able to start doing Geospatial work in Python.

A great next step would be [Introduction to GIS in Python](https://github.com/ONSgeo/geospatial-training/blob/r-py-install-guides/_docs/intro_to_gis_in_python.md).


95 changes: 95 additions & 0 deletions _docs/guides/r_install.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
title: Installation guide for R Geospatial packages
description: Step-by-step installation instructions for R geospatial packages.
---

# Installation guide for R Geospatial packages


## Setting up


ONS uses Artifactory to store/manage R packages and it must be linked to RStudio, or it will not be possible to install packages on your computer.

Log in to [Artifactory](http://art-p-01/artifactory/webapp/#/login) with your ONS username and password.

![Artifactory login screen](img/r_install_01_artifactory.png)

Click your username in the top right corner. Enter your password again and press ‘unlock’. Then press the copy icon next to the encrypted password (to the right of the eye).

![Location of the copy button for the encrypted password](img/r_install_02_artifactory2.png)

Start RStudio and in the window that pops up, click “Settings”:

![RStudio settings with the "settings" button highlighted](img/r_install_03_settings.png)

Enter your username in the Username field (1), paste the password you copied from Artifactory into the Hashtag field (2), and select the most recent version/highest number available from the dropdown menu (3).

![Rstudio settings fields](img/r_install_04_settings2.png)

Press Save Settings and then "Run RStudio".


## Installing packages:


![RStudio console window location](img/r_install_05_rconsole.png)

The console pane in RStudio is in the lower left by default. This is where packages are installed.

Type (or copy and paste) the following code in to install packages:

*install.packages(“tidyverse”, dependencies = TRUE, type = “win.binary”)*

**tidyverse** is an R module which includes tools for transforming and presenting data.

*install.packages(“janitor”, dependencies = TRUE, type = “win.binary”)*

**janitor** is useful for cleaning data and works well with tidyverse.

Note: sometimes package installation will fail because of a missing dependency (a package needed for the one you’re installing to work). If this happens, an error message in the console will tell you what package or packages you’re missing. Install them using the same code as above, changing the package name in quotations. For instance, to install tmap (Thematic Maps, used for creating maps) you would type:

*install.packages(“tmap”, dependencies = TRUE, type = “win.binary”)*

Once everything you need is installed you can try to install the package again.


## Useful training courses for starting out with GIS in R:


### Introduction to R:

https://learninghub.ons.gov.uk/course/view.php?id=498

This course is quite long (about 20 hours) but brings you up to a level needed to do further training in GIS in R.

The Introduction to R course is downloaded to your computer and the course files are found in the *Course_content* directory. More thorough installation guidance is found in the *Pre_Course_Information* folder which you can refer to if you are having trouble with the instructions in this guide.

![Location of Pre_Course_Information directory in Introduction to R](img/r_install_06_intro_r_pre_course.png)

### Introduction to GIS in R:

https://onsgeo.github.io/geospatial-training/docs/intro_to_gis_in_r

This course builds on what you learn in the Introduction to R and introduces the sf and tmap packages. Note that its instructions for installing libraries are incomplete and will not work, you must install them using the format: *install.packages(“package_name2”, dependencies = TRUE, type = “win.binary”)*


## Suggested R packages to install:


This is a list of packages that are important for GIS and a link to their documentation.

[Janitor](https://www.rdocumentation.org/packages/janitor/)

[sf](https://r-spatial.github.io/sf/)

[Tidyverse](https://www.tidyverse.org/) including:

- [dplyr](https://dplyr.tidyverse.org/)
- [ggplot](https://ggplot2.tidyverse.org/)
- [readr](https://readr.tidyverse.org/)
- [stringr](https://stringr.tidyverse.org/)
- [tibble](https://tibble.tidyverse.org/)
- [tidyr](https://tidyr.tidyverse.org/)


0 comments on commit 8d61dda

Please sign in to comment.