generated from vsoch/docsy-jekyll
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from ONSgeo/r-py-install-guides
R and Python (Anaconda) installation guides
- Loading branch information
Showing
15 changed files
with
205 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
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.
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.
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.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/) | ||
|
||
|