|
|
GEO3231PythonReferenceSheet
|
|
|
===========================
|
|
|
# GEO3231PythonReferenceSheet
|
|
|
|
|
|
- ###
|
|
|
|
|
|
- ### [Importing modules, and what those modules do](#GEO3231PythonReferenceSheet-Importingmo)
|
|
|
|
|
|
- ### [Help (manual pages)](#GEO3231PythonReferenceSheet-Help(manual)
|
|
|
|
|
|
- ### [Making an array with some data in](#GEO3231PythonReferenceSheet-Makinganarr)
|
|
|
|
|
|
- ### [Making an array that is automatically full of a sequence of numbers](#GEO3231PythonReferenceSheet-Makinganarr)
|
|
|
|
|
|
- ### [Print](#GEO3231PythonReferenceSheet-Print)
|
|
|
|
|
|
- ### [Basic Maths](#GEO3231PythonReferenceSheet-BasicMaths)
|
|
|
|
|
|
- ### [Basic stats](#GEO3231PythonReferenceSheet-Basicstats)
|
|
|
|
|
|
- ### [For Loop](#GEO3231PythonReferenceSheet-ForLoop)
|
|
|
|
|
|
- ### [Plotting](#GEO3231PythonReferenceSheet-Plotting)
|
|
|
|
|
|
- ### [line plot](#GEO3231PythonReferenceSheet-lineplot)
|
|
|
|
|
|
- ### [Scatter plot](#GEO3231PythonReferenceSheet-Scatterplot)
|
|
|
|
|
|
- ### [Adding labels and titles to plots](#GEO3231PythonReferenceSheet-Addinglabel)
|
|
|
|
|
|
- ### [Adding a legend to a plot](#GEO3231PythonReferenceSheet-Addingalege)
|
|
|
|
|
|
- ### [Contour plot of raw data (i.e. not of a cube of data that contains all of the metadata as well as the numbers)](#GEO3231PythonReferenceSheet-Contourplot)
|
|
|
|
|
|
- ### [Contour plot from an \'iris cube\' i.e. a variable read in using one of the iris modules - a variable holding the (e.g.) climate data as well as all the metadata about that climate model etc.](#GEO3231PythonReferenceSheet-Contourplot)
|
|
|
|
|
|
- ### [x-y plot from data that was read in as an iris cube then averaged so that it ply has a single dimension (i.e. it has been spatially averaged so the only dimension is time)](#GEO3231PythonReferenceSheet-x-yplotfrom)
|
|
|
|
|
|
- ### [And as above, but specifying how many ticks (numbers) you want on the x-axis:](#GEO3231PythonReferenceSheet-Andasabove,)
|
|
|
|
|
|
- ### [import matplotlib.pyplot as plt import iris.quickplot as quickplot](#GEO3231PythonReferenceSheet-importmatpl)
|
|
|
|
|
|
- ### [number\_of\_xaxis\_ticks = 5 ](#GEO3231PythonReferenceSheet-number_of_x)
|
|
|
|
|
|
- ### [fig = plt.figure() ax = fig.add\_subplot(1, 1, 1)](#GEO3231PythonReferenceSheet-fig=plt.fig)
|
|
|
|
|
|
- ### [Adding coastlines to a map plot](#GEO3231PythonReferenceSheet-Addingcoast)
|
|
|
|
|
|
- ### [Coloured contour plot from an \'iris cube\' with a line counter map (like altitude contours from an OS map) on top:](#GEO3231PythonReferenceSheet-Colouredcon)
|
|
|
|
|
|
- ### [Plotting a map of the Pacific (and not having a big white gap)](#GEO3231PythonReferenceSheet-Plottingama)
|
|
|
|
|
|
- ### [Plotting a line plot with coloured bands showing uncertainties/standard deviations](#GEO3231PythonReferenceSheet-Plottingali)
|
|
|
|
|
|
- ### [Reading data in from a text file](#GEO3231PythonReferenceSheet-Readingdata)
|
|
|
|
|
|
- ### [Loading climate model or big observational data from netcdf files (files with the extension \'.nc\') using iris](#GEO3231PythonReferenceSheet-Loadingclim)
|
|
|
|
|
|
- ### [Converting monthly data to yearly data in an iris cube](#GEO3231PythonReferenceSheet-Convertingm)
|
|
|
|
|
|
- ### [Calculating an annual mean but just over specific months- from an iris cube](#GEO3231PythonReferenceSheet-Calculating)
|
|
|
|
|
|
- ### [Averaging an iris cube of data along some dimension (typically across the time-intervals, or latitude etc.)](#GEO3231PythonReferenceSheet-Averagingan)
|
|
|
|
|
|
- ### [Writing a script](#GEO3231PythonReferenceSheet-Writingascr)
|
|
|
|
|
|
- ### [Calculating the mean of an array](#GEO3231PythonReferenceSheet-Calculating)
|
|
|
|
|
|
- ### [Calculating the mean of an array which has \'nan\' - Not A Number - \'gaps\' in it](#GEO3231PythonReferenceSheet-Calculating)
|
|
|
|
|
|
- ### [Calculating the standard deviation of an array](#GEO3231PythonReferenceSheet-Calculating)
|
|
|
|
|
|
- ### [Calculating the standard deviation of an array which has \'NaN\' - Not s Number - \'gaps\' in it ](#GEO3231PythonReferenceSheet-Calculating)
|
|
|
|
|
|
- ### [ ](#GEO3231PythonReferenceSheet-.1)
|
|
|
|
|
|
- ### [Replacing a missing data indicator with a nan ](#GEO3231PythonReferenceSheet-Replacingam)
|
|
|
|
|
|
- ### [from numpy import \*](#GEO3231PythonReferenceSheet-fromnumpyim)
|
|
|
|
|
|
- ### [ data = array(\[1.0,2.0,3.0,4.0,5.0,-99999.0,7.0,8.0,9.0,-99999.0\])](#GEO3231PythonReferenceSheet-data=array()
|
|
|
|
|
|
- ###
|
|
|
|
|
|
- ### [Masking where you have NaNs in a dataset ](#GEO3231PythonReferenceSheet-Maskingwher)
|
|
|
|
|
|
- ### [Calculating the correlation between two datasets](#GEO3231PythonReferenceSheet-Calculating)
|
|
|
|
|
|
- ### [Linear Regression](#GEO3231PythonReferenceSheet-LinearRegre)
|
|
|
|
|
|
- ### [Multiple linear regression example](#GEO3231PythonReferenceSheet-Multiplelin)
|
|
|
|
|
|
- ### [Plotting a linear best fit line](#GEO3231PythonReferenceSheet-Plottingali)
|
|
|
|
|
|
- ### [Calculating seawater density](#GEO3231PythonReferenceSheet-Calculating)
|
|
|
|
|
|
- ### [Working with Iris Cubes (i.e. data read in from netcdf files using the iris modules)](#GEO3231PythonReferenceSheet-Workingwith)
|
|
|
|
|
|
- ### [Contour plot from an \'iris cube\' i.e. a variable read in using one of the iris modules - a variable holding the (e.g.) climate data as well as all the metadata about that climate model etc.](#GEO3231PythonReferenceSheet-Contourplot)
|
|
|
|
|
|
- ### [x-y plot from data that was read in as an iris cube then averaged so that it ply has a single dimension (i.e. it has been spatially averaged so the only dimension is time)](#GEO3231PythonReferenceSheet-x-yplotfrom)
|
|
|
|
|
|
- ### [As above, but specifying that you want a specific dimension (here depth) on the y-axis:](#GEO3231PythonReferenceSheet-Asabove,but)
|
|
|
|
|
|
- ### [Adding coastlines to a map plot](#GEO3231PythonReferenceSheet-Addingcoast)
|
|
|
|
|
|
- ### [Loading climate model or big observational data from netcdf files (files with the extension \'.nc\') using iris](#GEO3231PythonReferenceSheet-Loadingclim)
|
|
|
|
|
|
- ### [Converting monthly data to yearly data in an iris cube](#GEO3231PythonReferenceSheet-Convertingm)
|
|
|
|
|
|
- ### [Averaging an iris cube of data along some dimension (typically across the time-intervals, or latitude etc.)](#GEO3231PythonReferenceSheet-Averagingan)
|
|
|
|
|
|
- ### [Extracting horizontal slices from a cube (e.g. at a given depth)](#GEO3231PythonReferenceSheet-Extractingh)
|
|
|
|
|
|
- ### [Extracting vertical slices from a cube](#GEO3231PythonReferenceSheet-Extractingv)
|
|
|
|
|
|
- ### [Extracting a spatial region from a global dataset](#GEO3231PythonReferenceSheet-Extractinga)
|
|
|
|
|
|
- ### [Extracting the data part of the iris cube (rather than the metadata)](#GEO3231PythonReferenceSheet-Extractingt)
|
|
|
|
|
|
- ### [Getting the year (or month or day) values for a cube of data](#GEO3231PythonReferenceSheet-Gettingthey)
|
|
|
|
|
|
- ### [Correlation maps](#GEO3231PythonReferenceSheet-Correlation)
|
|
|
|
|
|
- ### [Calculating the difference point-by-point between two cubes of data](#GEO3231PythonReferenceSheet-Calculating)
|
|
|
|
|
|
- ### [Calculating the mean of a bunch of cubes](#GEO3231PythonReferenceSheet-Calculating)
|
|
|
|
|
|
- ### [Calculating the variance of a bunch of cubes ](#GEO3231PythonReferenceSheet-Calculating)
|
|
|
|
|
|
- ### [Doing the carbonate-chemistry calculations](#GEO3231PythonReferenceSheet-Doingthecar)
|
|
|
|
|
|
- ### [Plotting two time-series (or similar) datasets on the same x-axis but with different y axes:](#GEO3231PythonReferenceSheet-Plottingtwo)
|
|
|
|
|
|
- ### [Saving a figure you have plotted:](#GEO3231PythonReferenceSheet-Savingafigu)
|
|
|
|
|
|
- ### [Regridding and doing initial processing of non-CMIP5 data. Example here is SODA data (not python but related)](#GEO3231PythonReferenceSheet-Regriddinga)
|
|
|
|
|
|
- ### [Reading numerical data in from a text file:](#GEO3231PythonReferenceSheet-Readingnume)
|
|
|
|
|
|
- ### [Saving data to a text file:](#GEO3231PythonReferenceSheet-Savingdatat)
|
|
|
|
|
|
- ### [A function to create running means (smoothing data):](#GEO3231PythonReferenceSheet-Afunctionto)
|
|
|
|
|
|
### • [Adding latitude and longitude lables to your map](#GEO3231PythonReferenceSheet-Addinglatit)
|
|
|
|
|
|
- ### [Calculating the overturning stream function example (using the CMIP5 msftmyz variable):](#GEO3231PythonReferenceSheet-Calculating)
|
|
|
|
|
|
### • [Extracting a range of years from a cube](#GEO3231PythonReferenceSheet-Extractinga)
|
|
|
|
|
|
### • [Color maps:](#GEO3231PythonReferenceSheet-Colormaps:)
|
|
|
|
|
|
### • [Producing pretty plots](#GEO3231PythonReferenceSheet-Producingpr)
|
|
|
|
|
|
### • [High, low and band-pass filtering cubes](#GEO3231PythonReferenceSheet-High,lowand)
|
|
|
|
|
|
### • [Calculating the depths at which a variable in a cube moved from above to below a critical value](#GEO3231PythonReferenceSheet-Calculating)
|
|
|
|
|
|
- ### [Calculating the NINO3.4 index from a cube](#GEO3231PythonReferenceSheet-Calculating)
|
|
|
|
|
|
- ### [Extracting contour lines from a cube of data and saving them out as a shape file for ARC GIS](#GEO3231PythonReferenceSheet-Extractingc)
|
|
|
|
|
|
- ### [Cube Statistics/Maths](#GEO3231PythonReferenceSheet-CubeStatist)
|
|
|
|
|
|
- ### [Finding the maximum value in latitude-longitude space:](#GEO3231PythonReferenceSheet-Findingthem)
|
|
|
|
|
|
- ### [Finding the minimum value in latitude-longitude space:](#GEO3231PythonReferenceSheet-Findingthem)
|
|
|
|
|
|
- ### [Adding a value (5 in this example) to the data in a cube](#GEO3231PythonReferenceSheet-Addingavalu)
|
|
|
|
|
|
- ### [Dividing the data in a cube by a certain value(5 in this example)](#GEO3231PythonReferenceSheet-Dividingthe)
|
|
|
|
|
|
- ### [Reading and concatenating EN4 data](#GEO3231PythonReferenceSheet-Readingandc)
|
|
|
|
|
|
- ### [Identifying the grid coordinates in a cube of certain latitude and longitude points:](#GEO3231PythonReferenceSheet-Identifying)
|
|
|
|
|
|
- ### [Lead/Lagged correlation e.g.](#GEO3231PythonReferenceSheet-Lead/Lagged)
|
|
|
|
|
|
- ### [Hovmuller plots](#GEO3231PythonReferenceSheet-Hovmullerpl)
|
|
|
|
|
|
- ### [Drawing rectangles on plots:](#GEO3231PythonReferenceSheet-Drawingrect)
|
|
|
|
|
|
- ### [Changing font size](#GEO3231PythonReferenceSheet-Changingfon)
|
|
|
|
|
|
- ### [Contour plot with colour bar with title](#GEO3231PythonReferenceSheet-Contourplot)
|
|
|
|
|
|
- ### [Plotting GLODAP profiles](#GEO3231PythonReferenceSheet-PlottingGLO)
|
|
|
|
|
|
NOTE the bits highlighted in blue are the bits you can change (e.g. swap
|
|
|
[GEO3231PythonReferenceSheet_-_Halloran_Research_-_University_of_Exeter_Wiki.pdf](uploads/cc63523b0aa9fa0d9254a6c1d357160d/GEO3231PythonReferenceSheet_-_Halloran_Research_-_University_of_Exeter_Wiki.pdf)NOTE the bits highlighted in blue are the bits you can change (e.g. swap
|
|
|
for some other data) - the rest is the fundamental part of the command.
|
|
|
However, note that in some instances where the example has a few lines
|
|
|
of code, if you change one of the variable names, you may have to change
|
|
|
all instances of that variable name.
|
|
|
all instances of that variable name. This highlighting is not present in teh below for now., but I'll implement an alternative when the optio nbecomes available
|
|
|
|
|
|
### Importing modules, and what those modules do
|
|
|
|
... | ... | |