├── .DS_Store
├── .gitattributes
├── .ipynb_checkpoints
├── Intro_02_JupyterNotebooks-checkpoint.ipynb
├── Intro_03_BasicCommands-checkpoint.ipynb
├── Intro_04_DataTypesStructures-checkpoint.ipynb
├── Intro_05_LibraryDataStructures-checkpoint.ipynb
├── Intro_06_Xarray-basics-checkpoint.ipynb
├── Intro_06_Xarray-checkpoint.ipynb
├── Intro_06_Xarray_answers-checkpoint.ipynb
├── Intro_07_Xarray-features_new-checkpoint.ipynb
├── Intro_07_Xarray_and_plotting_with_cartopy-answers-checkpoint.ipynb
├── Intro_07_Xarray_and_plotting_with_cartopy-checkpoint.ipynb
├── Intro_08_Xarray-Advanced_cruise_data_case_study-checkpoint.ipynb
├── Intro_08_plotting_with_cartopy-checkpoint.ipynb
├── Intro_09_Xarray_advanced_hurricane_case_study-checkpoint.ipynb
├── Tutorial_8_plotting_with_cartopy-checkpoint.ipynb
└── intro_01_pythonecosystem-checkpoint.ipynb
├── CODE_OF_CONDUCT.md
├── LICENSE
├── README.md
├── data
├── .DS_Store
├── 20111101120000-CMC-L4_GHRSST-SSTfnd-CMC0.2deg-GLOB-v02.0-fv02.0.nc
├── AllT_updated.csv
├── IBTrACS.NA.v04r00.nc
├── MoleCrab_abundance_annual.csv
├── analysis_20111101_v11l30flk.nc
├── avhrr_oi
│ ├── avhrr-only-v2.20180410.nc
│ ├── avhrr-only-v2.20180411.nc
│ ├── avhrr-only-v2.20180412.nc
│ ├── avhrr-only-v2.20180413.nc
│ ├── avhrr-only-v2.20180414.nc
│ ├── avhrr-only-v2.20180415.nc
│ ├── avhrr-only-v2.20180416.nc
│ ├── avhrr-only-v2.20180417.nc
│ ├── avhrr-only-v2.20180418.nc
│ ├── avhrr-only-v2.20180419.nc
│ ├── avhrr-only-v2.20180420.nc
│ ├── avhrr-only-v2.20180421.nc
│ ├── avhrr-only-v2.20180422.nc
│ ├── avhrr-only-v2.20180423.nc
│ ├── avhrr-only-v2.20180424.nc
│ ├── avhrr-only-v2.20180425.nc
│ ├── avhrr-only-v2.20180426.nc
│ ├── avhrr-only-v2.20180427.nc
│ ├── avhrr-only-v2.20180428.nc
│ ├── avhrr-only-v2.20180429.nc
│ ├── avhrr-only-v2.20180430.nc
│ ├── avhrr-only-v2.20180501.nc
│ ├── avhrr-only-v2.20180502.nc
│ ├── avhrr-only-v2.20180503.nc
│ ├── avhrr-only-v2.20180504.nc
│ ├── avhrr-only-v2.20180505.nc
│ ├── avhrr-only-v2.20180506.nc
│ ├── avhrr-only-v2.20180507.nc
│ ├── avhrr-only-v2.20180508.nc
│ ├── avhrr-only-v2.20180509.nc
│ ├── avhrr-only-v2.20180510.nc
│ ├── avhrr-only-v2.20180511.nc
│ ├── avhrr-only-v2.20180512.nc
│ ├── avhrr-only-v2.20180513.nc
│ ├── avhrr-only-v2.20180514.nc
│ ├── avhrr-only-v2.20180515.nc
│ ├── avhrr-only-v2.20180516.nc
│ ├── avhrr-only-v2.20180517.nc
│ ├── avhrr-only-v2.20180518.nc
│ ├── avhrr-only-v2.20180519.nc
│ ├── avhrr-only-v2.20180520.nc
│ ├── avhrr-only-v2.20180521.nc
│ ├── avhrr-only-v2.20180522.nc
│ ├── avhrr-only-v2.20180523.nc
│ ├── avhrr-only-v2.20180524.nc
│ ├── avhrr-only-v2.20180525.nc
│ ├── avhrr-only-v2.20180526.nc
│ ├── avhrr-only-v2.20180527.nc
│ ├── avhrr-only-v2.20180528.nc
│ ├── avhrr-only-v2.20180529.nc
│ ├── avhrr-only-v2.20180530.nc
│ ├── avhrr-only-v2.20180531.nc
│ ├── avhrr-only-v2.20180601.nc
│ ├── avhrr-only-v2.20180602.nc
│ ├── avhrr-only-v2.20180603.nc
│ ├── avhrr-only-v2.20180604.nc
│ ├── avhrr-only-v2.20180605.nc
│ ├── avhrr-only-v2.20180606.nc
│ ├── avhrr-only-v2.20180607.nc
│ ├── avhrr-only-v2.20180608.nc
│ ├── avhrr-only-v2.20180609.nc
│ ├── avhrr-only-v2.20180610.nc
│ ├── avhrr-only-v2.20180611.nc
│ └── avhrr-only-v2.20180612.nc
├── saildrone-gen_4-baja_2018-sd1002-20180411T180000-20180611T055959-1_minutes-v1.nc
└── saildrone-gen_5-antarctica_circumnavigation_2019-sd1020-20190119T040000-20190803T043000-1440_minutes-v1.1564857794963.nc
├── environment.yml
├── notebooks
├── .DS_Store
├── .ipynb_checkpoints
│ ├── Intro_02_JupyterNotebooks-checkpoint.ipynb
│ ├── Intro_03_BasicCommands-checkpoint.ipynb
│ ├── Intro_04_DataTypesStructures-checkpoint.ipynb
│ ├── Intro_05_LibraryDataStructures-checkpoint.ipynb
│ ├── Intro_06_Xarray-basics-checkpoint.ipynb
│ ├── Intro_06a_Xarray-basics-checkpoint.ipynb
│ ├── Intro_07_Xarray_and_plotting_with_cartopy-checkpoint.ipynb
│ ├── Intro_07a_Xarray_and_plotting_with_cartopy-Copy1-checkpoint.ipynb
│ ├── Intro_08_Xarray-Advanced_cruise_data_case_study-checkpoint.ipynb
│ ├── Intro_08_Xarray-Collocate_gridded_data_with_experiment-checkpoint.ipynb
│ ├── Intro_08a_Xarray-Advanced_cruise_data_case_study-Copy1-checkpoint.ipynb
│ ├── Intro_09_Xarray_Compare_two_gridded_datasets-checkpoint.ipynb
│ ├── Intro_09_Xarray_advanced_hurricane_case_study-checkpoint.ipynb
│ ├── Intro_09a_Xarray_advanced_hurricane_case_study-Copy1-checkpoint.ipynb
│ ├── Intro_to_pythonecosystem-checkpoint.ipynb
│ ├── Tutorial_02_JupyterNotebooks-checkpoint.ipynb
│ ├── Tutorial_03_BasicCommands-checkpoint.ipynb
│ ├── Tutorial_04_DataTypesStructures-checkpoint.ipynb
│ ├── Tutorial_05_LibraryDataStructures-checkpoint.ipynb
│ ├── Tutorial_06_Xarray-basics-checkpoint.ipynb
│ ├── Tutorial_07_Xarray_Plotting_with_cartopy-checkpoint.ipynb
│ ├── Tutorial_08_Xarray-Collocate_gridded_data_with_experiment-checkpoint.ipynb
│ ├── Tutorial_09_Xarray_Compare_two_gridded_datasets-checkpoint.ipynb
│ └── intro_01_pythonecosystem-checkpoint.ipynb
├── CalAcademy
│ ├── .DS_Store
│ ├── .ipynb_checkpoints
│ │ ├── .ipynb_checkpoints
│ │ │ └── CalAcademy_explore_data-checkpoint-checkpoint.ipynb
│ │ ├── CalAcademy_explore_data-checkpoint.ipynb
│ │ ├── DataExploration_CalAcademy-checkpoint.ipynb
│ │ ├── Data_CalAcademy-checkpoint.ipynb
│ │ ├── Data_Explorer_2-checkpoint.ipynb
│ │ ├── ShortIntro_CalAcademy-checkpoint.ipynb
│ │ └── clean_summarize_crabdata-checkpoint.ipynb
│ ├── Annual_UpwellingAprJul_OceanBeach.csv
│ ├── Annual_UpwellingAprJul_OceanBean.csv
│ ├── CalAcademy_explore_data.ipynb
│ ├── Data_CalAcademy.ipynb
│ ├── Data_Explorer_2.ipynb
│ ├── MoleCrab_abundance_annual.csv
│ ├── MoleCrab_abundance_apr-jul.csv
│ ├── OB_sancrab_data_generated_2020-09-03-05-50-55.csv
│ ├── ShortIntro_CalAcademy.ipynb
│ ├── clean_summarize_crabdata.ipynb
│ └── sandcrab_data_2017-11-16.xlsx
├── Intro cloud computing.gslides
├── Intro_to_pythonecosystem.ipynb
├── LinkstoResources.md
├── Tutorial_02_JupyterNotebooks.ipynb
├── Tutorial_03_BasicCommands.ipynb
├── Tutorial_04_DataTypesStructures.ipynb
├── Tutorial_05_LibraryDataStructures.ipynb
├── Tutorial_06_Xarray-basics.ipynb
├── Tutorial_07_Xarray_Plotting_with_cartopy.ipynb
├── Tutorial_08_Xarray-Collocate_gridded_data_with_experiment.ipynb
├── Tutorial_09_Xarray_Compare_two_gridded_datasets.ipynb
├── answers
│ ├── .ipynb_checkpoints
│ │ ├── Intro_02_JupyterNotebooks-checkpoint.ipynb
│ │ ├── Intro_03_BasicCommands-checkpoint.ipynb
│ │ ├── Intro_04_DataTypesStructures-checkpoint.ipynb
│ │ ├── Intro_05_LibraryDataStructures-checkpoint.ipynb
│ │ ├── Intro_06_Xarray-CELL-only-checkpoint.ipynb
│ │ ├── Intro_06_Xarray-basics-answers-checkpoint.ipynb
│ │ ├── Intro_07_Xarray-Advanced-answers-checkpoint.ipynb
│ │ ├── Intro_07_Xarray_and_plotting_with_cartopy-checkpoint.ipynb
│ │ ├── Intro_08_Xarray-Advanced_cruise_data_case_study-checkpoint.ipynb
│ │ └── Intro_09_Xarray_advanced_hurricane_case_study-checkpoint.ipynb
│ ├── Tutorial_02_JupyterNotebooks.ipynb
│ ├── Tutorial_03_BasicCommands.ipynb
│ ├── Tutorial_04_DataTypesStructures.ipynb
│ ├── Tutorial_05_LibraryDataStructures.ipynb
│ ├── Tutorial_06_Xarray-basics.ipynb
│ ├── Tutorial_07_Xarray_and_plotting_with_cartopy.ipynb
│ ├── Tutorial_08_Xarray-Advanced_cruise_data_case_study.ipynb
│ └── Tutorial_09_Xarray_advanced_hurricane_case_study.ipynb
├── figures
│ ├── .DS_Store
│ ├── lab_logo_tng.png
│ ├── pythonforoceanographers.png
│ ├── pythonlogo.png
│ └── xarray-boxes.png
└── podaac.ini
├── notes_for_instructors
├── Notes_Intro_01_PythonEcosystem.docx
├── Notes_Intro_02_jupyternotebooks.docx
├── Notes_Intro_03_BasicPythonCommands.docx
├── Notes_Intro_04_DataTypesStructures.docx
├── Notes_Intro_05_LibraryDataStructures.docx
└── ~$tes_Intro_01_PythonEcosystem.docx
└── python_installation_instructions.md
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/.DS_Store
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/.ipynb_checkpoints/Intro_03_BasicCommands-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "slideshow": {
7 | "slide_type": "slide"
8 | }
9 | },
10 | "source": [
11 | "# Basic `Python`\n",
12 | "We are going to learn the most basic commands of Python. The objective is not to teach you how to program to become an expert, but to learn the syntaxis of the language & recongnize it through the next notebooks\n"
13 | ]
14 | },
15 | {
16 | "cell_type": "markdown",
17 | "metadata": {
18 | "slideshow": {
19 | "slide_type": "slide"
20 | }
21 | },
22 | "source": [
23 | "## Basic operations \n",
24 | "### +, -, \\*, /, **\n",
25 | "
\n",
26 | " - Define two integer variables & print the result of basic operations\n",
27 | "
"
28 | ]
29 | },
30 | {
31 | "cell_type": "code",
32 | "execution_count": null,
33 | "metadata": {
34 | "scrolled": true,
35 | "slideshow": {
36 | "slide_type": "fragment"
37 | }
38 | },
39 | "outputs": [],
40 | "source": []
41 | },
42 | {
43 | "cell_type": "markdown",
44 | "metadata": {},
45 | "source": [
46 | "### Operations over the same variables can be simplified by adding the operand before the `=`, like this:\n",
47 | "x += 1"
48 | ]
49 | },
50 | {
51 | "cell_type": "markdown",
52 | "metadata": {},
53 | "source": [
54 | "\n",
55 | " - Execute the code in the cell below & print x & y final values\n",
56 | "
"
57 | ]
58 | },
59 | {
60 | "cell_type": "code",
61 | "execution_count": null,
62 | "metadata": {},
63 | "outputs": [],
64 | "source": [
65 | "x, y = 3, 4\n",
66 | "print(x,y)\n",
67 | "x += 1\n",
68 | "y /= 2"
69 | ]
70 | },
71 | {
72 | "cell_type": "markdown",
73 | "metadata": {
74 | "slideshow": {
75 | "slide_type": "slide"
76 | }
77 | },
78 | "source": [
79 | "*** \n",
80 | "## `for` loops\n",
81 | "Can iterate on any list. \n",
82 | "
\n",
83 | "#### Note the indentation in the line after the `for` command. This position indicates which lines belong to the `for` loop.\n",
84 | "The print statement is no longer being looped on because it has no indent.\n",
85 | "\n",
86 | " Execute the code below \n",
87 | "
"
88 | ]
89 | },
90 | {
91 | "cell_type": "code",
92 | "execution_count": null,
93 | "metadata": {
94 | "slideshow": {
95 | "slide_type": "fragment"
96 | }
97 | },
98 | "outputs": [],
99 | "source": [
100 | "somelist = [10,15,25, '10ppm','5m/s']\n",
101 | "for item in somelist:\n",
102 | " print(item)\n",
103 | "print(somelist)"
104 | ]
105 | },
106 | {
107 | "cell_type": "markdown",
108 | "metadata": {
109 | "slideshow": {
110 | "slide_type": "fragment"
111 | }
112 | },
113 | "source": [
114 | "### A list can also be just of numbers, and we can build a list using the function `range`:\n",
115 | "#### range(start, end, step) \n",
116 | "
Note: the end is non-inclusive\n",
117 | "\n",
118 | "\n",
119 | " - Execute the code below\n",
120 | "
\n",
121 | " - Replace somelist in the for loop with: range(0,41,5), and execute the code again\n",
122 | "
\n",
123 | " - Change the start, end or step and execute the code again\n",
124 | "
\n",
151 | " - Try range(10) instead"
152 | ]
153 | },
154 | {
155 | "cell_type": "code",
156 | "execution_count": null,
157 | "metadata": {},
158 | "outputs": [],
159 | "source": [
160 | "somelist = [0, 5, 10, 15, 20, 25, 30, 35, 40]\n",
161 | "for item in range(10):\n",
162 | " print(item)"
163 | ]
164 | },
165 | {
166 | "cell_type": "markdown",
167 | "metadata": {
168 | "slideshow": {
169 | "slide_type": "slide"
170 | }
171 | },
172 | "source": [
173 | "## Sometimes we want the index and the value of each element on a list\n",
174 | "### The command `enumerate` gives you both\n",
175 | "\n",
176 | " - Execute the code below\n",
177 | "
\n",
178 | " - Then try with range(10) instead\n",
179 | "
\n",
180 | "
Note the use of { } and .format to print inx and item"
181 | ]
182 | },
183 | {
184 | "cell_type": "code",
185 | "execution_count": null,
186 | "metadata": {
187 | "slideshow": {
188 | "slide_type": "fragment"
189 | }
190 | },
191 | "outputs": [],
192 | "source": [
193 | "for inx,item in enumerate(range(0,41,5)):\n",
194 | " print('index {}, value = {}'.format(inx,item))"
195 | ]
196 | },
197 | {
198 | "cell_type": "markdown",
199 | "metadata": {
200 | "slideshow": {
201 | "slide_type": "slide"
202 | }
203 | },
204 | "source": [
205 | "***\n",
206 | "# conditionals: `if`, `elif`, `else` \n",
207 | "### Conditional operators can be used to compare different types of variables or to test logical statements. \n",
208 | "\n",
209 | "- The basic operator to compare numerical values are: ==, !=, <, >, >=, <=\n",
210 | "- The logical operators are: and, or, not\n",
211 | "- and the use of conditional operators are exemplified in the next cell\n",
212 | "\n",
213 | "#### Note the indentation again\n",
214 | "\n",
215 | "- Execute the next cell\n",
216 | "
\n",
217 | "- Test different comparison operators and logical operators and execute\n",
218 | "
"
219 | ]
220 | },
221 | {
222 | "cell_type": "code",
223 | "execution_count": null,
224 | "metadata": {},
225 | "outputs": [],
226 | "source": [
227 | "lat = 12\n",
228 | "if (lat <= -23.5) or (lat >= 23.5):\n",
229 | " print('extra-tropical')\n",
230 | "elif lat == 0:\n",
231 | " print('equator')\n",
232 | "else:\n",
233 | " print('tropical')"
234 | ]
235 | }
236 | ],
237 | "metadata": {
238 | "kernelspec": {
239 | "display_name": "Python 3",
240 | "language": "python",
241 | "name": "python3"
242 | },
243 | "language_info": {
244 | "codemirror_mode": {
245 | "name": "ipython",
246 | "version": 3
247 | },
248 | "file_extension": ".py",
249 | "mimetype": "text/x-python",
250 | "name": "python",
251 | "nbconvert_exporter": "python",
252 | "pygments_lexer": "ipython3",
253 | "version": "3.7.1"
254 | }
255 | },
256 | "nbformat": 4,
257 | "nbformat_minor": 2
258 | }
259 |
--------------------------------------------------------------------------------
/.ipynb_checkpoints/Intro_07_Xarray_and_plotting_with_cartopy-answers-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Plotting with [cartopy](https://scitools.org.uk/cartopy/docs/latest/)\n",
8 | "\n",
9 | "From Cartopy website:\n",
10 | "\n",
11 | "* Cartopy is a Python package designed for geospatial data processing in order to produce maps and other geospatial data analyses.\n",
12 | "\n",
13 | "* Cartopy makes use of the powerful PROJ.4, NumPy and Shapely libraries and includes a programmatic interface built on top of Matplotlib for the creation of publication quality maps.\n",
14 | "\n",
15 | "* Key features of cartopy are its object oriented projection definitions, and its ability to transform points, lines, vectors, polygons and images between those projections.\n",
16 | "\n",
17 | "* You will find cartopy especially useful for large area / small scale data, where Cartesian assumptions of spherical data traditionally break down. If you’ve ever experienced a singularity at the pole or a cut-off at the dateline, it is likely you will appreciate cartopy’s unique features!\n"
18 | ]
19 | },
20 | {
21 | "cell_type": "code",
22 | "execution_count": null,
23 | "metadata": {},
24 | "outputs": [],
25 | "source": [
26 | "import numpy as np\n",
27 | "import matplotlib.pyplot as plt\n",
28 | "import xarray as xr\n",
29 | "import cartopy.crs as ccrs"
30 | ]
31 | },
32 | {
33 | "cell_type": "markdown",
34 | "metadata": {},
35 | "source": [
36 | "# Read in data using xarray\n",
37 | "- Read in the Saildrone USV file either from a local disc or using OpenDAP.\n",
38 | "- add room to write collocated data to in situ dataset\n"
39 | ]
40 | },
41 | {
42 | "cell_type": "code",
43 | "execution_count": null,
44 | "metadata": {},
45 | "outputs": [],
46 | "source": [
47 | "filename_usv = './data/saildrone-gen_5-antarctica_circumnavigation_2019-sd1020-20190119T040000-20190803T043000-1440_minutes-v1.1564857794963.nc'\n",
48 | "\n",
49 | "ds_usv = xr.open_dataset(filename_usv).rename({'longitude':'lon','latitude':'lat'})\n",
50 | "\n",
51 | "ds_usv\n"
52 | ]
53 | },
54 | {
55 | "cell_type": "markdown",
56 | "metadata": {},
57 | "source": [
58 | "# Open the dataset, mask land, plot result\n",
59 | "*`xr.open_dataset`\n",
60 | "* mask ==1 values"
61 | ]
62 | },
63 | {
64 | "cell_type": "code",
65 | "execution_count": null,
66 | "metadata": {},
67 | "outputs": [],
68 | "source": [
69 | "#If you are offline use the first url\n",
70 | "#url = './data/20111101120000-CMC-L4_GHRSST-SSTfnd-CMC0.2deg-GLOB-v02.0-fv02.0.nc')\n",
71 | "url = 'https://podaac-opendap.jpl.nasa.gov/opendap/allData/ghrsst/data/GDS2/L4/GLOB/CMC/CMC0.2deg/v2/2011/305/20111101120000-CMC-L4_GHRSST-SSTfnd-CMC0.2deg-GLOB-v02.0-fv02.0.nc'\n",
72 | "\n",
73 | "ds_sst =\n",
74 | "\n"
75 | ]
76 | },
77 | {
78 | "cell_type": "markdown",
79 | "metadata": {},
80 | "source": [
81 | "\n",
82 | "## explore the in situ data and quickly plot using cartopy\n",
83 | "\n",
84 | "* first set up the axis with the projection you want: https://scitools.org.uk/cartopy/docs/latest/crs/projections.html\n",
85 | "\n",
86 | "* plot to that axis and tell the projection that your data is in\n",
87 | "* set a background image `ax.background_img('ne_shaded')`\n",
88 | "* draw coastlines `ax.coastlines(resolution='50m')`\n",
89 | "* add a colorbary and label it `cax = plt.colorbar(cs1)` `cax.set_label('SST (K)')`"
90 | ]
91 | },
92 | {
93 | "cell_type": "code",
94 | "execution_count": null,
95 | "metadata": {
96 | "scrolled": true
97 | },
98 | "outputs": [],
99 | "source": [
100 | "#for polar data, plot temperature\n",
101 | "ax = plt.axes(projection=ccrs.SouthPolarStereo())\n",
102 | "\n",
103 | "(ds_sst.analysed_sst-273.15).plot(ax=ax, transform=ccrs.PlateCarree(),vmin=0,vmax=12)\n",
104 | "\n",
105 | "cs1 = ax.scatter(ds_usv.lon, ds_usv.lat, \n",
106 | " transform=ccrs.PlateCarree(),\n",
107 | " s=10.0, \n",
108 | " c=ds_usv.TEMP_CTD_MEAN, \n",
109 | " edgecolor='none', \n",
110 | " cmap='jet',\n",
111 | " vmin=0,vmax=12)\n",
112 | "\n",
113 | "ax.set_extent([-180, 180, -90, -45], crs=ccrs.PlateCarree())\n",
114 | "\n"
115 | ]
116 | },
117 | {
118 | "cell_type": "markdown",
119 | "metadata": {},
120 | "source": [
121 | "# Exercise!"
122 | ]
123 | },
124 | {
125 | "cell_type": "code",
126 | "execution_count": null,
127 | "metadata": {},
128 | "outputs": [],
129 | "source": [
130 | "#now you try to plot plot salinity ds_usv.SAL_MEAN\n",
131 | "\n"
132 | ]
133 | },
134 | {
135 | "cell_type": "markdown",
136 | "metadata": {},
137 | "source": [
138 | "# Let's plot some data off of California\n",
139 | "* `.rename({'longitude':'lon','latitude':'lat'})`"
140 | ]
141 | },
142 | {
143 | "cell_type": "code",
144 | "execution_count": null,
145 | "metadata": {},
146 | "outputs": [],
147 | "source": [
148 | "#use the first URL if you are offline\n",
149 | "#url = './data/saildrone-gen_4-baja_2018-sd1002-20180411T180000-20180611T055959-1_minutes-v1.nc'\n",
150 | "\n",
151 | "url = 'https://podaac-opendap.jpl.nasa.gov/opendap/hyrax/allData/insitu/L2/saildrone/Baja/saildrone-gen_4-baja_2018-sd1002-20180411T180000-20180611T055959-1_minutes-v1.nc'\n",
152 | "\n",
153 | "ds_usv = \n"
154 | ]
155 | },
156 | {
157 | "cell_type": "markdown",
158 | "metadata": {},
159 | "source": [
160 | "# Exercise!\n",
161 | "* for NON polar ds_usv data, use `ccrs.PlateCarree()` as your projection"
162 | ]
163 | },
164 | {
165 | "cell_type": "code",
166 | "execution_count": null,
167 | "metadata": {},
168 | "outputs": [],
169 | "source": []
170 | },
171 | {
172 | "cell_type": "code",
173 | "execution_count": null,
174 | "metadata": {},
175 | "outputs": [],
176 | "source": [
177 | "# now add an extent to your figure\n",
178 | "lonmin,lonmax = ds_usv.lon.min().data-2,ds_usv.lon.max().data+2\n",
179 | "latmin,latmax = ds_usv.lat.min().data-2,ds_usv.lat.max().data+2\n",
180 | "ax.set_xlim(lonmin,lonmax)\n",
181 | "ax.set_ylim(latmin,latmax)\n"
182 | ]
183 | },
184 | {
185 | "cell_type": "code",
186 | "execution_count": null,
187 | "metadata": {},
188 | "outputs": [],
189 | "source": []
190 | }
191 | ],
192 | "metadata": {
193 | "kernelspec": {
194 | "display_name": "Python 3",
195 | "language": "python",
196 | "name": "python3"
197 | },
198 | "language_info": {
199 | "codemirror_mode": {
200 | "name": "ipython",
201 | "version": 3
202 | },
203 | "file_extension": ".py",
204 | "mimetype": "text/x-python",
205 | "name": "python",
206 | "nbconvert_exporter": "python",
207 | "pygments_lexer": "ipython3",
208 | "version": "3.7.3"
209 | }
210 | },
211 | "nbformat": 4,
212 | "nbformat_minor": 1
213 | }
214 |
--------------------------------------------------------------------------------
/.ipynb_checkpoints/Intro_08_plotting_with_cartopy-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# This is the in situ and SSS collocation code. \n"
8 | ]
9 | },
10 | {
11 | "cell_type": "code",
12 | "execution_count": null,
13 | "metadata": {},
14 | "outputs": [],
15 | "source": [
16 | "import numpy as np\n",
17 | "import matplotlib.pyplot as plt\n",
18 | "import xarray as xr\n",
19 | "import cartopy.crs as ccrs"
20 | ]
21 | },
22 | {
23 | "cell_type": "markdown",
24 | "metadata": {},
25 | "source": [
26 | "# Read in data using xarray\n",
27 | "- Read in the Saildrone USV file either from a local disc or using OpenDAP.\n",
28 | "- add room to write collocated data to in situ dataset\n"
29 | ]
30 | },
31 | {
32 | "cell_type": "code",
33 | "execution_count": null,
34 | "metadata": {},
35 | "outputs": [],
36 | "source": [
37 | "filename_usv = './data/saildrone-gen_5-antarctica_circumnavigation_2019-sd1020-20190119T040000-20190803T043000-1440_minutes-v1.1564857794963.nc'\n",
38 | "ds_usv = xr.open_dataset(filename_usv)\n",
39 | "ds_usv = ds_usv.rename({'longitude':'lon','latitude':'lat'})\n",
40 | "#print dataset\n",
41 | "ds_usv\n"
42 | ]
43 | },
44 | {
45 | "cell_type": "markdown",
46 | "metadata": {},
47 | "source": [
48 | "\n",
49 | "## explore the in situ data and quickly plot using cartopy\n",
50 | " "
51 | ]
52 | },
53 | {
54 | "cell_type": "code",
55 | "execution_count": null,
56 | "metadata": {
57 | "scrolled": true
58 | },
59 | "outputs": [],
60 | "source": [
61 | "#for polar data\n",
62 | "ax = plt.axes(projection=ccrs.SouthPolarStereo())\n",
63 | "cs1 = ax.scatter(ds_usv.lon, ds_usv.lat, transform=ccrs.PlateCarree(),s=10.0, c=ds_usv.TEMP_CTD_MEAN, edgecolor='none', cmap='jet',vmin=0,vmax=12)\n",
64 | "ax.set_extent([-180, 180, -90, -45], crs=ccrs.PlateCarree())\n",
65 | "ax.background_img('ne_shaded')\n",
66 | "ax.coastlines(resolution='50m')\n",
67 | "cax = plt.colorbar(cs1)\n",
68 | "cax.set_label('SST (K)')\n",
69 | "#fig_fname = 'C:/Users/gentemann/Google Drive/f_drive/docs/projects/misst-arctic/mmdb/'+usvname+'_location.png'\n",
70 | "#plt.savefig(fig_fname, transparent=False, format='png')\n",
71 | "\n"
72 | ]
73 | },
74 | {
75 | "cell_type": "code",
76 | "execution_count": null,
77 | "metadata": {},
78 | "outputs": [],
79 | "source": [
80 | "#plot salinity\n",
81 | "ax = plt.axes(projection=ccrs.SouthPolarStereo())\n",
82 | "cs1 = ax.scatter(ds_usv.lon, ds_usv.lat, transform=ccrs.PlateCarree(),s=10.0, c=ds_usv.SAL_MEAN, edgecolor='none', cmap='jet',vmin=33.6,vmax=34.4)\n",
83 | "ax.set_extent([-180, 180, -90, -45], crs=ccrs.PlateCarree())\n",
84 | "ax.background_img('ne_shaded')\n",
85 | "ax.coastlines(resolution='50m')\n",
86 | "cax = plt.colorbar(cs1)\n",
87 | "cax.set_label('SSS (psu)')\n",
88 | "#fig_fname = 'C:/Users/gentemann/Google Drive/f_drive/docs/projects/misst-arctic/mmdb/'+usvname+'_sal_location.png'\n",
89 | "#plt.savefig(fig_fname, transparent=False, format='png')\n",
90 | "\n"
91 | ]
92 | },
93 | {
94 | "cell_type": "code",
95 | "execution_count": null,
96 | "metadata": {},
97 | "outputs": [],
98 | "source": [
99 | "#read in the Baja Saildrone data\n",
100 | "url = 'https://podaac-opendap.jpl.nasa.gov/opendap/hyrax/allData/insitu/L2/saildrone/Baja/saildrone-gen_4-baja_2018-sd1002-20180411T180000-20180611T055959-1_minutes-v1.nc'\n",
101 | "ds_usv = xr.open_dataset(url)\n",
102 | "ds_usv = ds_usv.rename({'longitude':'lon','latitude':'lat'})\n",
103 | "ds_usv"
104 | ]
105 | },
106 | {
107 | "cell_type": "code",
108 | "execution_count": null,
109 | "metadata": {},
110 | "outputs": [],
111 | "source": [
112 | "#for NON polar data\n",
113 | "ax = plt.axes(projection=ccrs.PlateCarree())\n",
114 | "#ds_usv = ds_usv.where(np.isfinite(ds_usv.lon))\n",
115 | "cs1 = ax.scatter(ds_usv.lon, ds_usv.lat, s=3.0, c=ds_usv.TEMP_CTD_MEAN, edgecolor='none', cmap='jet',vmin=13,vmax=21)\n",
116 | "ax.coastlines(resolution='50m')\n",
117 | "x1,x2,y1,y2 = ds_usv.lon.min().data-2,ds_usv.lon.max().data+2,ds_usv.lat.min().data-2,ds_usv.lat.max().data+2\n",
118 | "ax.set_xlim(x1,x2)\n",
119 | "ax.set_ylim(y1,y2)\n",
120 | "ax.background_img('ne_shaded')\n",
121 | "ax.set_xticks(np.arange(x1,x2,4))\n",
122 | "ax.set_yticks(np.arange(y1,y2,5))\n",
123 | "cax = plt.colorbar(cs1)\n",
124 | "cax.set_label('SST (K)')\n",
125 | "#fig_fname = 'C:/Users/gentemann/Google Drive/f_drive/docs/projects/misst-arctic/mmdb/'+usvname+'_location.png'\n",
126 | "#plt.savefig(fig_fname, transparent=False, format='png')\n",
127 | "#plt.clf()"
128 | ]
129 | },
130 | {
131 | "cell_type": "code",
132 | "execution_count": null,
133 | "metadata": {},
134 | "outputs": [],
135 | "source": []
136 | }
137 | ],
138 | "metadata": {
139 | "kernelspec": {
140 | "display_name": "Python 3",
141 | "language": "python",
142 | "name": "python3"
143 | },
144 | "language_info": {
145 | "codemirror_mode": {
146 | "name": "ipython",
147 | "version": 3
148 | },
149 | "file_extension": ".py",
150 | "mimetype": "text/x-python",
151 | "name": "python",
152 | "nbconvert_exporter": "python",
153 | "pygments_lexer": "ipython3",
154 | "version": "3.7.3"
155 | }
156 | },
157 | "nbformat": 4,
158 | "nbformat_minor": 1
159 | }
160 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6 |
7 | ## Our Standards
8 |
9 | Examples of behavior that contributes to creating a positive environment include:
10 |
11 | * Using welcoming and inclusive language
12 | * Being respectful of differing viewpoints and experiences
13 | * Gracefully accepting constructive criticism
14 | * Focusing on what is best for the community
15 | * Showing empathy towards other community members
16 |
17 | Examples of unacceptable behavior by participants include:
18 |
19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances
20 | * Trolling, insulting/derogatory comments, and personal or political attacks
21 | * Public or private harassment
22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission
23 | * Other conduct which could reasonably be considered inappropriate in a professional setting
24 |
25 | ## Our Responsibilities
26 |
27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28 |
29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30 |
31 | ## Scope
32 |
33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34 |
35 | ## Enforcement
36 |
37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at cgentemann@esr.org. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38 |
39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40 |
41 | ## Attribution
42 |
43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44 |
45 | [homepage]: http://contributor-covenant.org
46 | [version]: http://contributor-covenant.org/version/1/4/
47 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # Click below to start interactive tutorial
3 |
4 | To explore Pangeo data on GCP (eg. CCMP), select the button 'Pangeo Binder GCP US-central1', and then, once the binder initializes, select 'tutorials'.
5 |
6 | | [](https://binder.pangeo.io/v2/gh/pangeo-gallery/default-binder/master?urlpath=git-pull?repo=https://github.com/python4oceanography/ocean_python_tutorial) |
7 |
8 | To explore 3 difference cloud-optimized datasets (MUR SST, GOES, ERA5), select button below 'Pangeo Binder AWS US-west1', and then, once the binder initializes, select 'tutorials'.
9 |
10 | [](https://aws-uswest2-binder.pangeo.io/v2/gh/pangeo-gallery/default-binder/master?urlpath=git-pull?repo=https://github.com/python4oceanography/ocean_python_tutorial)
11 |
12 |
13 | Some helpful webpages on python:
14 | http://earthpy.org/category/introduction-to-python.html
15 |
16 | How to install miniconda with some useful tools for Oceanographers:
17 |
18 | https://github.com/python4oceanography/ocean_python_tutorial/blob/master/python_installation_instructions.md
19 |
20 | ## Workshop:
21 | A one day introduction to Python for oceanographers to introduce oceanographers to Python programming and reproducible research using Jupyter Notebooks, Git, software citations, and cloud computing. This hands-on course will use common oceanographic research analyses to demonstrate capabilities of Python, open source software libraries, and cloud computing.
22 |
23 | ### Preliminary Schedule
24 | - 09:00 Code of conduct, Intro to the Python ecosystem and StackOverflow, Git, Pangeo, Cloud computing
25 | - 09:30 Introduction to Jupyter Notebook, basic python commands
26 | Data structures: pandas, numpy, dictionaries
27 | - 11:00 Components of a Xarray dataset, reading, selecting, plotting, saving data
28 | - 12:00 Lunch break
29 | - 13:00 Example plotting data using cartopy and xarray
30 | - 14:00 Example collocating cruise data with satellite data
31 | - 14:45 Wrap-up
32 | - 15:00 End
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/data/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/.DS_Store
--------------------------------------------------------------------------------
/data/20111101120000-CMC-L4_GHRSST-SSTfnd-CMC0.2deg-GLOB-v02.0-fv02.0.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/20111101120000-CMC-L4_GHRSST-SSTfnd-CMC0.2deg-GLOB-v02.0-fv02.0.nc
--------------------------------------------------------------------------------
/data/IBTrACS.NA.v04r00.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/IBTrACS.NA.v04r00.nc
--------------------------------------------------------------------------------
/data/MoleCrab_abundance_annual.csv:
--------------------------------------------------------------------------------
1 | Datetime,Abundance (psm),Year
2 | 2001-12-31,824.1072727272726,2001
3 | 2002-12-31,2230.359032258065,2002
4 | 2003-12-31,4428.390526315789,2003
5 | 2004-12-31,1375.5459999999996,2004
6 | 2005-12-31,990.799175257732,2005
7 | 2006-12-31,302.85199999999986,2006
8 | 2007-12-31,273.982596153846,2007
9 | 2008-12-31,376.5033333333332,2008
10 | 2009-12-31,376.8432710280376,2009
11 | 2010-12-31,3390.017403846155,2010
12 | 2011-12-31,971.0576233183859,2011
13 | 2012-12-31,736.8730051813476,2012
14 | 2013-12-31,1786.5571074380184,2013
15 | 2014-12-31,2525.67012605042,2014
16 | 2015-12-31,2050.0515679442515,2015
17 | 2016-12-31,2490.8348148148157,2016
18 | 2017-12-31,700.6070909090911,2017
19 |
--------------------------------------------------------------------------------
/data/analysis_20111101_v11l30flk.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/analysis_20111101_v11l30flk.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180410.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180410.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180411.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180411.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180412.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180412.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180413.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180413.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180414.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180414.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180415.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180415.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180416.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180416.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180417.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180417.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180418.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180418.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180419.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180419.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180420.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180420.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180421.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180421.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180422.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180422.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180423.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180423.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180424.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180424.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180425.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180425.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180426.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180426.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180427.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180427.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180428.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180428.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180429.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180429.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180430.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180430.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180501.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180501.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180502.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180502.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180503.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180503.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180504.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180504.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180505.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180505.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180506.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180506.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180507.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180507.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180508.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180508.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180509.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180509.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180510.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180510.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180511.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180511.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180512.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180512.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180513.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180513.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180514.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180514.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180515.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180515.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180516.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180516.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180517.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180517.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180518.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180518.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180519.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180519.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180520.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180520.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180521.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180521.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180522.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180522.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180523.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180523.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180524.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180524.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180525.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180525.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180526.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180526.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180527.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180527.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180528.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180528.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180529.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180529.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180530.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180530.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180531.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180531.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180601.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180601.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180602.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180602.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180603.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180603.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180604.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180604.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180605.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180605.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180606.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180606.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180607.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180607.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180608.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180608.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180609.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180609.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180610.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180610.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180611.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180611.nc
--------------------------------------------------------------------------------
/data/avhrr_oi/avhrr-only-v2.20180612.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/avhrr_oi/avhrr-only-v2.20180612.nc
--------------------------------------------------------------------------------
/data/saildrone-gen_4-baja_2018-sd1002-20180411T180000-20180611T055959-1_minutes-v1.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/saildrone-gen_4-baja_2018-sd1002-20180411T180000-20180611T055959-1_minutes-v1.nc
--------------------------------------------------------------------------------
/data/saildrone-gen_5-antarctica_circumnavigation_2019-sd1020-20190119T040000-20190803T043000-1440_minutes-v1.1564857794963.nc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/data/saildrone-gen_5-antarctica_circumnavigation_2019-sd1020-20190119T040000-20190803T043000-1440_minutes-v1.1564857794963.nc
--------------------------------------------------------------------------------
/environment.yml:
--------------------------------------------------------------------------------
1 | name: tutorialenv
2 | channels:
3 | - conda-forge
4 | - defaults
5 | dependencies:
6 | - cartopy=0.17.0
7 | - jupyter=1.0.0
8 | - numpy=1.16.3
9 | - pandas=0.24.2
10 | - python=3.7.1
11 | - xarray=0.12.1
12 | - netcdf4=1.5.1.2
13 | - dask=1.2.2
14 | - podaacpy=2.4.0
15 | - lxml=4.3.3
16 |
17 |
--------------------------------------------------------------------------------
/notebooks/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/notebooks/.DS_Store
--------------------------------------------------------------------------------
/notebooks/.ipynb_checkpoints/Intro_03_BasicCommands-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "slideshow": {
7 | "slide_type": "slide"
8 | }
9 | },
10 | "source": [
11 | "# Basic `Python`\n",
12 | "We are going to learn the most basic commands of Python. The objective is not to teach you how to program to become an expert, but to learn the syntaxis of the language & recongnize it through the next notebooks\n"
13 | ]
14 | },
15 | {
16 | "cell_type": "markdown",
17 | "metadata": {
18 | "slideshow": {
19 | "slide_type": "slide"
20 | }
21 | },
22 | "source": [
23 | "## Basic operations \n",
24 | "### +, -, \\*, /, **\n",
25 | "\n",
26 | "\n",
27 | " Try it out!\n",
28 | "
\n",
29 | " - Define two integer variables & print the result of basic operations\n",
30 | "
"
31 | ]
32 | },
33 | {
34 | "cell_type": "code",
35 | "execution_count": null,
36 | "metadata": {
37 | "scrolled": true,
38 | "slideshow": {
39 | "slide_type": "fragment"
40 | }
41 | },
42 | "outputs": [],
43 | "source": []
44 | },
45 | {
46 | "cell_type": "markdown",
47 | "metadata": {},
48 | "source": [
49 | "### Operations over the same variables can be simplified by adding the operand before the `=`, like this:\n",
50 | "x += 1"
51 | ]
52 | },
53 | {
54 | "cell_type": "markdown",
55 | "metadata": {},
56 | "source": [
57 | "\n",
58 | " Try it out!\n",
59 | "
- Execute the code in the cell below & print x & y final values\n",
60 | "
"
61 | ]
62 | },
63 | {
64 | "cell_type": "code",
65 | "execution_count": null,
66 | "metadata": {},
67 | "outputs": [],
68 | "source": [
69 | "x, y = 3, 4\n",
70 | "print(x,y)\n",
71 | "x += 1\n",
72 | "y /= 2"
73 | ]
74 | },
75 | {
76 | "cell_type": "markdown",
77 | "metadata": {},
78 | "source": [
79 | "***"
80 | ]
81 | },
82 | {
83 | "cell_type": "markdown",
84 | "metadata": {
85 | "slideshow": {
86 | "slide_type": "slide"
87 | }
88 | },
89 | "source": [
90 | "## `for` loops\n",
91 | "Can iterate on any list. \n",
92 | "
\n",
93 | "#### Note the indentation in the line after the `for` command. This position indicates which lines belong to the `for` loop.\n",
94 | "The print statement is no longer being looped on because it has no indent.\n",
95 | "\n",
96 | " Try it out!\n",
97 | "
Execute the code below \n",
98 | "
"
99 | ]
100 | },
101 | {
102 | "cell_type": "code",
103 | "execution_count": null,
104 | "metadata": {
105 | "slideshow": {
106 | "slide_type": "fragment"
107 | }
108 | },
109 | "outputs": [],
110 | "source": [
111 | "somelist = [10,15,25, '10ppm','5m/s']\n",
112 | "for item in somelist:\n",
113 | " print(item)\n",
114 | "print(somelist)"
115 | ]
116 | },
117 | {
118 | "cell_type": "markdown",
119 | "metadata": {
120 | "slideshow": {
121 | "slide_type": "fragment"
122 | }
123 | },
124 | "source": [
125 | "### A list can also be just of numbers, and we can build a list using the function `range`:\n",
126 | "#### range(start, end, step) \n",
127 | "
Note: the end is non-inclusive\n",
128 | "\n",
129 | "\n",
130 | " Try it out!\n",
131 | "
- Execute the code below\n",
132 | "
\n",
133 | " - Replace somelist in the for loop with: range(0,41,5), and execute the code again\n",
134 | "
\n",
135 | " - Change the start, end or step and execute the code again\n",
136 | "
\n",
163 | " Try it out!\n",
164 | "
- Try range(10) instead"
165 | ]
166 | },
167 | {
168 | "cell_type": "code",
169 | "execution_count": null,
170 | "metadata": {},
171 | "outputs": [],
172 | "source": [
173 | "somelist = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i','j']\n",
174 | "for inx in range(10):\n",
175 | " print(inx)\n",
176 | "print('********\\n')\n",
177 | "\n",
178 | "for inx in range(10):\n",
179 | " print(somelist[inx])\n",
180 | "print('********\\n')\n",
181 | "\n",
182 | "for inx in range(0,10,2):\n",
183 | " print(somelist[inx])"
184 | ]
185 | },
186 | {
187 | "cell_type": "markdown",
188 | "metadata": {
189 | "slideshow": {
190 | "slide_type": "slide"
191 | }
192 | },
193 | "source": [
194 | "## Sometimes we want the index and the value of each element on a list\n",
195 | "### The command `enumerate` gives you both\n",
196 | "\n",
197 | " Try it out!\n",
198 | "
\n",
199 | " - Execute the code below\n",
200 | "
\n",
201 | " - Then try with range(10) instead\n",
202 | "
\n",
203 | "
Note the use of { } and .format to print inx and item"
204 | ]
205 | },
206 | {
207 | "cell_type": "code",
208 | "execution_count": null,
209 | "metadata": {
210 | "slideshow": {
211 | "slide_type": "fragment"
212 | }
213 | },
214 | "outputs": [],
215 | "source": [
216 | "for inx,item in enumerate(range(0,41,a5)):\n",
217 | " print('index {}, value = {}'.format(inx,item))"
218 | ]
219 | },
220 | {
221 | "cell_type": "markdown",
222 | "metadata": {
223 | "slideshow": {
224 | "slide_type": "slide"
225 | }
226 | },
227 | "source": [
228 | "***\n",
229 | "# conditionals: `if`, `elif`, `else` \n",
230 | "### Conditional operators can be used to compare different types of variables or to test logical statements. \n",
231 | "\n",
232 | "- The basic operator to compare numerical values are: ==, !=, <, >, >=, <=\n",
233 | "- The logical operators are: and, or, not\n",
234 | "- and the use of conditional operators are exemplified in the next cell\n",
235 | "\n",
236 | "#### Note the indentation again\n",
237 | "\n",
238 | " Try it out!\n",
239 | "
\n",
240 | "- Execute the next cell\n",
241 | "
\n",
242 | "- Test different comparison operators and logical operators and execute\n",
243 | "
"
244 | ]
245 | },
246 | {
247 | "cell_type": "code",
248 | "execution_count": null,
249 | "metadata": {},
250 | "outputs": [],
251 | "source": [
252 | "lat = 12\n",
253 | "if (lat <= -23.5) or (lat >= 23.5):\n",
254 | " print('extra-tropical')\n",
255 | "elif lat == 0:\n",
256 | " print('equator')\n",
257 | "else:\n",
258 | " print('tropical')"
259 | ]
260 | }
261 | ],
262 | "metadata": {
263 | "kernelspec": {
264 | "display_name": "Python 3",
265 | "language": "python",
266 | "name": "python3"
267 | },
268 | "language_info": {
269 | "codemirror_mode": {
270 | "name": "ipython",
271 | "version": 3
272 | },
273 | "file_extension": ".py",
274 | "mimetype": "text/x-python",
275 | "name": "python",
276 | "nbconvert_exporter": "python",
277 | "pygments_lexer": "ipython3",
278 | "version": "3.7.1"
279 | }
280 | },
281 | "nbformat": 4,
282 | "nbformat_minor": 2
283 | }
284 |
--------------------------------------------------------------------------------
/notebooks/.ipynb_checkpoints/Intro_07_Xarray_and_plotting_with_cartopy-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Plotting with [cartopy](https://scitools.org.uk/cartopy/docs/latest/)\n",
8 | "\n",
9 | "From Cartopy website:\n",
10 | "\n",
11 | "* Cartopy is a Python package designed for geospatial data processing in order to produce maps and other geospatial data analyses.\n",
12 | "\n",
13 | "* Cartopy makes use of the powerful PROJ.4, NumPy and Shapely libraries and includes a programmatic interface built on top of Matplotlib for the creation of publication quality maps.\n",
14 | "\n",
15 | "* Key features of cartopy are its object oriented projection definitions, and its ability to transform points, lines, vectors, polygons and images between those projections.\n",
16 | "\n",
17 | "* You will find cartopy especially useful for large area / small scale data, where Cartesian assumptions of spherical data traditionally break down. If you’ve ever experienced a singularity at the pole or a cut-off at the dateline, it is likely you will appreciate cartopy’s unique features!\n"
18 | ]
19 | },
20 | {
21 | "cell_type": "code",
22 | "execution_count": null,
23 | "metadata": {},
24 | "outputs": [],
25 | "source": [
26 | "import numpy as np\n",
27 | "import matplotlib.pyplot as plt\n",
28 | "import xarray as xr\n",
29 | "import cartopy.crs as ccrs"
30 | ]
31 | },
32 | {
33 | "cell_type": "markdown",
34 | "metadata": {},
35 | "source": [
36 | "# Read in data using xarray\n",
37 | "- Read in the Saildrone USV file either from a local disc `xr.open_dataset()\n",
38 | "- change latitude and longitude to lat and lon `.rename({'longitude':'lon','latitude':'lat'})`\n"
39 | ]
40 | },
41 | {
42 | "cell_type": "code",
43 | "execution_count": null,
44 | "metadata": {},
45 | "outputs": [],
46 | "source": [
47 | "file = '../data/saildrone-gen_5-antarctica_circumnavigation_2019-sd1020-20190119T040000-20190803T043000-1440_minutes-v1.1564857794963.nc'\n",
48 | "\n",
49 | "ds_usv = \n"
50 | ]
51 | },
52 | {
53 | "cell_type": "markdown",
54 | "metadata": {},
55 | "source": [
56 | "# Open the dataset, mask land, plot result\n",
57 | "*`xr.open_dataset`\n",
58 | "* use `.where` to mask values equal to 1"
59 | ]
60 | },
61 | {
62 | "cell_type": "code",
63 | "execution_count": null,
64 | "metadata": {},
65 | "outputs": [],
66 | "source": [
67 | "#If you are offline use the first url\n",
68 | "#url = '../data/20111101120000-CMC-L4_GHRSST-SSTfnd-CMC0.2deg-GLOB-v02.0-fv02.0.nc'\n",
69 | "url = 'https://podaac-opendap.jpl.nasa.gov/opendap/allData/ghrsst/data/GDS2/L4/GLOB/CMC/CMC0.2deg/v2/2011/305/20111101120000-CMC-L4_GHRSST-SSTfnd-CMC0.2deg-GLOB-v02.0-fv02.0.nc'\n",
70 | "\n",
71 | "ds_sst = \n",
72 | "\n",
73 | "ds_sst = \n",
74 | "\n"
75 | ]
76 | },
77 | {
78 | "cell_type": "markdown",
79 | "metadata": {},
80 | "source": [
81 | "\n",
82 | "## explore the in situ data and quickly plot using cartopy\n",
83 | "\n",
84 | "* first set up the axis with the projection you want: https://scitools.org.uk/cartopy/docs/latest/crs/projections.html\n",
85 | "\n",
86 | "* plot to that axis and tell the projection that your data is in\n",
87 | "* set a background image `ax.stock_img()`\n",
88 | "* draw coastlines `ax.coastlines(resolution='50m')`\n",
89 | "* add a colorbary and label it `cax = plt.colorbar(cs1)` `cax.set_label('SST (K)')`"
90 | ]
91 | },
92 | {
93 | "cell_type": "code",
94 | "execution_count": null,
95 | "metadata": {
96 | "scrolled": true
97 | },
98 | "outputs": [],
99 | "source": [
100 | "#for polar data, plot temperature\n",
101 | "ax = plt.axes(projection=ccrs.SouthPolarStereo())\n",
102 | "\n",
103 | "(ds_sst.analysed_sst-273.15).plot(ax=ax, \n",
104 | " transform=ccrs.PlateCarree(),\n",
105 | " vmin=0,\n",
106 | " vmax=12)\n",
107 | "\n",
108 | "cs1 = ax.scatter(ds_usv.lon, ds_usv.lat, \n",
109 | " transform=ccrs.PlateCarree(),\n",
110 | " s=10.0, \n",
111 | " c=ds_usv.TEMP_CTD_MEAN, \n",
112 | " edgecolor='none', \n",
113 | " cmap='jet',\n",
114 | " vmin=0,vmax=12)\n",
115 | "\n",
116 | "ax.set_extent([-180, 180, -90, -45], crs=ccrs.PlateCarree())\n"
117 | ]
118 | },
119 | {
120 | "cell_type": "markdown",
121 | "metadata": {},
122 | "source": [
123 | "# Exercise!"
124 | ]
125 | },
126 | {
127 | "cell_type": "code",
128 | "execution_count": null,
129 | "metadata": {},
130 | "outputs": [],
131 | "source": [
132 | "#now you try to plot plot salinity ds_usv.SAL_MEAN\n",
133 | "\n"
134 | ]
135 | },
136 | {
137 | "cell_type": "markdown",
138 | "metadata": {},
139 | "source": [
140 | "# Let's plot some data off of California\n",
141 | "* `.rename({'longitude':'lon','latitude':'lat'})`"
142 | ]
143 | },
144 | {
145 | "cell_type": "code",
146 | "execution_count": null,
147 | "metadata": {},
148 | "outputs": [],
149 | "source": [
150 | "#use the first URL if you are offline\n",
151 | "#url = '../data/saildrone-gen_4-baja_2018-sd1002-20180411T180000-20180611T055959-1_minutes-v1.nc'\n",
152 | "\n",
153 | "url = 'https://podaac-opendap.jpl.nasa.gov/opendap/hyrax/allData/insitu/L2/saildrone/Baja/saildrone-gen_4-baja_2018-sd1002-20180411T180000-20180611T055959-1_minutes-v1.nc'\n",
154 | "\n",
155 | "ds_usv = \n"
156 | ]
157 | },
158 | {
159 | "cell_type": "markdown",
160 | "metadata": {},
161 | "source": [
162 | "# Exercise!\n",
163 | "* for NON polar ds_usv data, use `ccrs.PlateCarree()` as your projection"
164 | ]
165 | },
166 | {
167 | "cell_type": "code",
168 | "execution_count": null,
169 | "metadata": {},
170 | "outputs": [],
171 | "source": [
172 | "#for polar data, plot temperature\n",
173 | "\n",
174 | "\n"
175 | ]
176 | },
177 | {
178 | "cell_type": "code",
179 | "execution_count": null,
180 | "metadata": {},
181 | "outputs": [],
182 | "source": [
183 | "# now add an extent to your figure\n",
184 | "lonmin,lonmax = ds_usv.lon.min().data-2,ds_usv.lon.max().data+2\n",
185 | "latmin,latmax = ds_usv.lat.min().data-2,ds_usv.lat.max().data+2\n",
186 | "ax.set_extent([lonmin,lonmax,latmin,latmax], crs=ccrs.PlateCarree())\n"
187 | ]
188 | },
189 | {
190 | "cell_type": "code",
191 | "execution_count": null,
192 | "metadata": {},
193 | "outputs": [],
194 | "source": []
195 | }
196 | ],
197 | "metadata": {
198 | "kernelspec": {
199 | "display_name": "Python 3",
200 | "language": "python",
201 | "name": "python3"
202 | },
203 | "language_info": {
204 | "codemirror_mode": {
205 | "name": "ipython",
206 | "version": 3
207 | },
208 | "file_extension": ".py",
209 | "mimetype": "text/x-python",
210 | "name": "python",
211 | "nbconvert_exporter": "python",
212 | "pygments_lexer": "ipython3",
213 | "version": "3.7.1"
214 | }
215 | },
216 | "nbformat": 4,
217 | "nbformat_minor": 1
218 | }
219 |
--------------------------------------------------------------------------------
/notebooks/.ipynb_checkpoints/Intro_07a_Xarray_and_plotting_with_cartopy-Copy1-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Plotting with [cartopy](https://scitools.org.uk/cartopy/docs/latest/)\n",
8 | "\n",
9 | "From Cartopy website:\n",
10 | "\n",
11 | "* Cartopy is a Python package designed for geospatial data processing in order to produce maps and other geospatial data analyses.\n",
12 | "\n",
13 | "* Cartopy makes use of the powerful PROJ.4, NumPy and Shapely libraries and includes a programmatic interface built on top of Matplotlib for the creation of publication quality maps.\n",
14 | "\n",
15 | "* Key features of cartopy are its object oriented projection definitions, and its ability to transform points, lines, vectors, polygons and images between those projections.\n",
16 | "\n",
17 | "* You will find cartopy especially useful for large area / small scale data, where Cartesian assumptions of spherical data traditionally break down. If you’ve ever experienced a singularity at the pole or a cut-off at the dateline, it is likely you will appreciate cartopy’s unique features!\n"
18 | ]
19 | },
20 | {
21 | "cell_type": "code",
22 | "execution_count": null,
23 | "metadata": {},
24 | "outputs": [],
25 | "source": [
26 | "import numpy as np\n",
27 | "import matplotlib.pyplot as plt\n",
28 | "import xarray as xr\n",
29 | "import cartopy.crs as ccrs"
30 | ]
31 | },
32 | {
33 | "cell_type": "markdown",
34 | "metadata": {},
35 | "source": [
36 | "# Read in data using xarray\n",
37 | "- Read in the Saildrone USV file either from a local disc `xr.open_dataset(file)`\n",
38 | "- change latitude and longitude to lat and lon `.rename({'longitude':'lon','latitude':'lat'})`\n"
39 | ]
40 | },
41 | {
42 | "cell_type": "code",
43 | "execution_count": null,
44 | "metadata": {},
45 | "outputs": [],
46 | "source": [
47 | "file = '../data/saildrone-gen_5-antarctica_circumnavigation_2019-sd1020-20190119T040000-20190803T043000-1440_minutes-v1.1564857794963.nc'\n",
48 | "\n",
49 | "ds_usv = \n"
50 | ]
51 | },
52 | {
53 | "cell_type": "markdown",
54 | "metadata": {},
55 | "source": [
56 | "# Open the dataset, mask land, plot result\n",
57 | "* `ds_sst = xr.open_dataset(url)`\n",
58 | "* use `ds_sst = ds_sst.where(ds_sst.mask==1)` to mask values equal to 1"
59 | ]
60 | },
61 | {
62 | "cell_type": "code",
63 | "execution_count": null,
64 | "metadata": {},
65 | "outputs": [],
66 | "source": [
67 | "#If you are offline use the first url\n",
68 | "#url = '../data/20111101120000-CMC-L4_GHRSST-SSTfnd-CMC0.2deg-GLOB-v02.0-fv02.0.nc'\n",
69 | "url = 'https://podaac-opendap.jpl.nasa.gov/opendap/allData/ghrsst/data/GDS2/L4/GLOB/CMC/CMC0.2deg/v2/2011/305/20111101120000-CMC-L4_GHRSST-SSTfnd-CMC0.2deg-GLOB-v02.0-fv02.0.nc'\n",
70 | "\n",
71 | "\n"
72 | ]
73 | },
74 | {
75 | "cell_type": "markdown",
76 | "metadata": {},
77 | "source": [
78 | "\n",
79 | "## explore the in situ data and quickly plot using cartopy\n",
80 | "\n",
81 | "* first set up the axis with the projection you want: https://scitools.org.uk/cartopy/docs/latest/crs/projections.html\n",
82 | "* plot to that axis and tell the projection that your data is in\n",
83 | "\n",
84 | "#### Run the cell below and see what the image looks like. Then try adding in the lines below, one at a time, and re-run cell to see what happens\n",
85 | "\n",
86 | "* set a background image `ax.stock_img()`\n",
87 | "* draw coastlines `ax.coastlines(resolution='50m')`\n",
88 | "* add a colorbary and label it `cax = plt.colorbar(cs1)` `cax.set_label('SST (K)')`"
89 | ]
90 | },
91 | {
92 | "cell_type": "code",
93 | "execution_count": null,
94 | "metadata": {
95 | "scrolled": true
96 | },
97 | "outputs": [],
98 | "source": [
99 | "#for polar data, plot temperature\n",
100 | "\n",
101 | "datamin = 0\n",
102 | "datamax = 12\n",
103 | "\n",
104 | "ax = plt.axes(projection=ccrs.SouthPolarStereo()) #here is where you set your axis projection\n",
105 | "\n",
106 | "(ds_sst.analysed_sst-273.15).plot(ax=ax, \n",
107 | " transform=ccrs.PlateCarree(), #set data projection\n",
108 | " vmin=datamin, #data min\n",
109 | " vmax=datamax) #data min\n",
110 | "\n",
111 | "cs1 = ax.scatter(ds_usv.lon, ds_usv.lat, \n",
112 | " transform=ccrs.PlateCarree(), #set data projection\n",
113 | " s=10.0, #size for scatter point\n",
114 | " c=ds_usv.TEMP_CTD_MEAN, #make the color of the scatter point equal to the USV temperature\n",
115 | " edgecolor='none', #no edgecolor\n",
116 | " cmap='jet', #colormap\n",
117 | " vmin=datamin, #data min\n",
118 | " vmax=datamax) #data max\n",
119 | "\n",
120 | "ax.set_extent([-180, 180, -90, -45], crs=ccrs.PlateCarree()) #data projection\n"
121 | ]
122 | },
123 | {
124 | "cell_type": "markdown",
125 | "metadata": {},
126 | "source": [
127 | "# Plot the salinity\n",
128 | "* Take the code from above but use `c=ds_usv.SAL_MEAN`\n",
129 | "* Run the code, what looks wrong?\n",
130 | "* Change `datamin` and `datamax`\n"
131 | ]
132 | },
133 | {
134 | "cell_type": "code",
135 | "execution_count": null,
136 | "metadata": {},
137 | "outputs": [],
138 | "source": [
139 | "\n"
140 | ]
141 | },
142 | {
143 | "cell_type": "markdown",
144 | "metadata": {},
145 | "source": [
146 | "# Let's plot some data off California\n",
147 | "* Read in data from a cruise along the California / Baja Coast\n",
148 | "* `ds_usv = xr.open_dataset(url).rename({'longitude':'lon','latitude':'lat'})`"
149 | ]
150 | },
151 | {
152 | "cell_type": "code",
153 | "execution_count": null,
154 | "metadata": {},
155 | "outputs": [],
156 | "source": [
157 | "#use the first URL if you are offline\n",
158 | "#url = '../data/saildrone-gen_4-baja_2018-sd1002-20180411T180000-20180611T055959-1_minutes-v1.nc'\n",
159 | "url = 'https://podaac-opendap.jpl.nasa.gov/opendap/hyrax/allData/insitu/L2/saildrone/Baja/saildrone-gen_4-baja_2018-sd1002-20180411T180000-20180611T055959-1_minutes-v1.nc'\n"
160 | ]
161 | },
162 | {
163 | "cell_type": "markdown",
164 | "metadata": {},
165 | "source": [
166 | "* Plot the data using the code from above, but change the projection\n",
167 | "\n",
168 | "`ax = plt.axes(projection=ccrs.PlateCarree())`\n",
169 | "\n"
170 | ]
171 | },
172 | {
173 | "cell_type": "code",
174 | "execution_count": null,
175 | "metadata": {},
176 | "outputs": [],
177 | "source": [
178 | "\n"
179 | ]
180 | },
181 | {
182 | "cell_type": "markdown",
183 | "metadata": {},
184 | "source": [
185 | "* Zoom into the region of the cruise \n",
186 | "* First calculate the lat/lon box
\n",
187 | "`lonmin,lonmax = ds_usv.lon.min().data-2,ds_usv.lon.max().data+2`
\n",
188 | "`latmin,latmax = ds_usv.lat.min().data-2,ds_usv.lat.max().data+2`\n",
189 | "\n",
190 | "* Then, after plotting the data, change the extent\n",
191 | "\n",
192 | "`ax.set_extent([lonmin,lonmax,latmin,latmax], crs=ccrs.PlateCarree())`\n"
193 | ]
194 | },
195 | {
196 | "cell_type": "code",
197 | "execution_count": null,
198 | "metadata": {},
199 | "outputs": [],
200 | "source": []
201 | }
202 | ],
203 | "metadata": {
204 | "kernelspec": {
205 | "display_name": "Python 3",
206 | "language": "python",
207 | "name": "python3"
208 | },
209 | "language_info": {
210 | "codemirror_mode": {
211 | "name": "ipython",
212 | "version": 3
213 | },
214 | "file_extension": ".py",
215 | "mimetype": "text/x-python",
216 | "name": "python",
217 | "nbconvert_exporter": "python",
218 | "pygments_lexer": "ipython3",
219 | "version": "3.7.3"
220 | }
221 | },
222 | "nbformat": 4,
223 | "nbformat_minor": 1
224 | }
225 |
--------------------------------------------------------------------------------
/notebooks/.ipynb_checkpoints/Tutorial_03_BasicCommands-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "slideshow": {
7 | "slide_type": "slide"
8 | }
9 | },
10 | "source": [
11 | "# Basic `Python`\n",
12 | "We are going to learn the most basic commands of Python. The objective is not to teach you how to program to become an expert, but to learn the syntaxis of the language & recongnize it through the next notebooks\n"
13 | ]
14 | },
15 | {
16 | "cell_type": "markdown",
17 | "metadata": {
18 | "slideshow": {
19 | "slide_type": "slide"
20 | }
21 | },
22 | "source": [
23 | "## Basic operations \n",
24 | "### +, -, \\*, /, **\n",
25 | "\n",
26 | "\n",
27 | " Try it out!\n",
28 | "
\n",
29 | " - Define two integer variables & print the result of basic operations\n",
30 | "
"
31 | ]
32 | },
33 | {
34 | "cell_type": "code",
35 | "execution_count": null,
36 | "metadata": {
37 | "scrolled": true,
38 | "slideshow": {
39 | "slide_type": "fragment"
40 | }
41 | },
42 | "outputs": [],
43 | "source": []
44 | },
45 | {
46 | "cell_type": "markdown",
47 | "metadata": {},
48 | "source": [
49 | "### Operations over the same variables can be simplified by adding the operand before the `=`, like this:\n",
50 | "x += 1"
51 | ]
52 | },
53 | {
54 | "cell_type": "markdown",
55 | "metadata": {},
56 | "source": [
57 | "\n",
58 | " Try it out!\n",
59 | "
- Execute the code in the cell below & print x & y final values\n",
60 | "
"
61 | ]
62 | },
63 | {
64 | "cell_type": "code",
65 | "execution_count": null,
66 | "metadata": {},
67 | "outputs": [],
68 | "source": [
69 | "x, y = 3, 4\n",
70 | "print(x,y)\n",
71 | "x += 1\n",
72 | "y /= 2"
73 | ]
74 | },
75 | {
76 | "cell_type": "markdown",
77 | "metadata": {},
78 | "source": [
79 | "***"
80 | ]
81 | },
82 | {
83 | "cell_type": "markdown",
84 | "metadata": {
85 | "slideshow": {
86 | "slide_type": "slide"
87 | }
88 | },
89 | "source": [
90 | "## `for` loops\n",
91 | "Can iterate on any list. \n",
92 | "
\n",
93 | "#### Note the indentation in the line after the `for` command. This position indicates which lines belong to the `for` loop.\n",
94 | "The print statement is no longer being looped on because it has no indent.\n",
95 | "\n",
96 | " Try it out!\n",
97 | "
Execute the code below \n",
98 | "
"
99 | ]
100 | },
101 | {
102 | "cell_type": "code",
103 | "execution_count": null,
104 | "metadata": {
105 | "slideshow": {
106 | "slide_type": "fragment"
107 | }
108 | },
109 | "outputs": [],
110 | "source": [
111 | "somelist = [10,15,25, '10ppm','5m/s']\n",
112 | "for item in somelist:\n",
113 | " print(item)\n",
114 | "print(somelist)"
115 | ]
116 | },
117 | {
118 | "cell_type": "markdown",
119 | "metadata": {
120 | "slideshow": {
121 | "slide_type": "fragment"
122 | }
123 | },
124 | "source": [
125 | "### A list can also be just of numbers, and we can build a list using the function `range`:\n",
126 | "#### range(start, end, step) \n",
127 | "
Note: the end is non-inclusive\n",
128 | "\n",
129 | "\n",
130 | " Try it out!\n",
131 | "
- Execute the code below\n",
132 | "
\n",
133 | " - Replace somelist in the for loop with: range(0,41,5), and execute the code again\n",
134 | "
\n",
135 | " - Change the start, end or step and execute the code again\n",
136 | "
\n",
163 | " Try it out!\n",
164 | "
- Try range(10) instead"
165 | ]
166 | },
167 | {
168 | "cell_type": "code",
169 | "execution_count": null,
170 | "metadata": {},
171 | "outputs": [],
172 | "source": [
173 | "somelist = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i','j']\n",
174 | "for inx in range(10):\n",
175 | " print(inx)\n",
176 | "print('********\\n')\n",
177 | "\n",
178 | "for inx in range(10):\n",
179 | " print(somelist[inx])\n",
180 | "print('********\\n')\n",
181 | "\n",
182 | "for inx in range(0,10,2):\n",
183 | " print(somelist[inx])"
184 | ]
185 | },
186 | {
187 | "cell_type": "markdown",
188 | "metadata": {
189 | "slideshow": {
190 | "slide_type": "slide"
191 | }
192 | },
193 | "source": [
194 | "## Sometimes we want the index and the value of each element on a list\n",
195 | "### The command `enumerate` gives you both\n",
196 | "\n",
197 | " Try it out!\n",
198 | "
\n",
199 | " - Execute the code below\n",
200 | "
\n",
201 | " - Then try with range(10) instead\n",
202 | "
\n",
203 | "
Note the use of { } and .format to print inx and item"
204 | ]
205 | },
206 | {
207 | "cell_type": "code",
208 | "execution_count": null,
209 | "metadata": {
210 | "slideshow": {
211 | "slide_type": "fragment"
212 | }
213 | },
214 | "outputs": [],
215 | "source": [
216 | "for inx,item in enumerate(range(0,41,a5)):\n",
217 | " print('index {}, value = {}'.format(inx,item))"
218 | ]
219 | },
220 | {
221 | "cell_type": "markdown",
222 | "metadata": {
223 | "slideshow": {
224 | "slide_type": "slide"
225 | }
226 | },
227 | "source": [
228 | "***\n",
229 | "# conditionals: `if`, `elif`, `else` \n",
230 | "### Conditional operators can be used to compare different types of variables or to test logical statements. \n",
231 | "\n",
232 | "- The basic operator to compare numerical values are: ==, !=, <, >, >=, <=\n",
233 | "- The logical operators are: and, or, not\n",
234 | "- and the use of conditional operators are exemplified in the next cell\n",
235 | "\n",
236 | "#### Note the indentation again\n",
237 | "\n",
238 | " Try it out!\n",
239 | "
\n",
240 | "- Execute the next cell\n",
241 | "
\n",
242 | "- Test different comparison operators and logical operators and execute\n",
243 | "
"
244 | ]
245 | },
246 | {
247 | "cell_type": "code",
248 | "execution_count": null,
249 | "metadata": {},
250 | "outputs": [],
251 | "source": [
252 | "lat = 12\n",
253 | "if (lat <= -23.5) or (lat >= 23.5):\n",
254 | " print('extra-tropical')\n",
255 | "elif lat == 0:\n",
256 | " print('equator')\n",
257 | "else:\n",
258 | " print('tropical')"
259 | ]
260 | }
261 | ],
262 | "metadata": {
263 | "kernelspec": {
264 | "display_name": "Python 3",
265 | "language": "python",
266 | "name": "python3"
267 | },
268 | "language_info": {
269 | "codemirror_mode": {
270 | "name": "ipython",
271 | "version": 3
272 | },
273 | "file_extension": ".py",
274 | "mimetype": "text/x-python",
275 | "name": "python",
276 | "nbconvert_exporter": "python",
277 | "pygments_lexer": "ipython3",
278 | "version": "3.7.1"
279 | }
280 | },
281 | "nbformat": 4,
282 | "nbformat_minor": 2
283 | }
284 |
--------------------------------------------------------------------------------
/notebooks/.ipynb_checkpoints/Tutorial_07_Xarray_Plotting_with_cartopy-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Plotting with [cartopy](https://scitools.org.uk/cartopy/docs/latest/)\n",
8 | "\n",
9 | "From Cartopy website:\n",
10 | "\n",
11 | "* Cartopy is a Python package designed for geospatial data processing in order to produce maps and other geospatial data analyses.\n",
12 | "\n",
13 | "* Cartopy makes use of the powerful PROJ.4, NumPy and Shapely libraries and includes a programmatic interface built on top of Matplotlib for the creation of publication quality maps.\n",
14 | "\n",
15 | "* Key features of cartopy are its object oriented projection definitions, and its ability to transform points, lines, vectors, polygons and images between those projections.\n",
16 | "\n",
17 | "* You will find cartopy especially useful for large area / small scale data, where Cartesian assumptions of spherical data traditionally break down. If you’ve ever experienced a singularity at the pole or a cut-off at the dateline, it is likely you will appreciate cartopy’s unique features!\n"
18 | ]
19 | },
20 | {
21 | "cell_type": "code",
22 | "execution_count": null,
23 | "metadata": {},
24 | "outputs": [],
25 | "source": [
26 | "import numpy as np\n",
27 | "import matplotlib.pyplot as plt\n",
28 | "import xarray as xr\n",
29 | "import cartopy.crs as ccrs"
30 | ]
31 | },
32 | {
33 | "cell_type": "markdown",
34 | "metadata": {},
35 | "source": [
36 | "# Read in data using xarray\n",
37 | "- Read in the Saildrone USV file either from a local disc `xr.open_dataset(file)`\n",
38 | "- change latitude and longitude to lat and lon `.rename({'longitude':'lon','latitude':'lat'})`\n"
39 | ]
40 | },
41 | {
42 | "cell_type": "code",
43 | "execution_count": null,
44 | "metadata": {},
45 | "outputs": [],
46 | "source": [
47 | "file = '../data/saildrone-gen_5-antarctica_circumnavigation_2019-sd1020-20190119T040000-20190803T043000-1440_minutes-v1.1564857794963.nc'\n",
48 | "\n",
49 | "ds_usv = \n"
50 | ]
51 | },
52 | {
53 | "cell_type": "markdown",
54 | "metadata": {},
55 | "source": [
56 | "# Open the dataset, mask land, plot result\n",
57 | "* `ds_sst = xr.open_dataset(url)`\n",
58 | "* use `ds_sst = ds_sst.where(ds_sst.mask==1)` to mask values equal to 1"
59 | ]
60 | },
61 | {
62 | "cell_type": "code",
63 | "execution_count": null,
64 | "metadata": {},
65 | "outputs": [],
66 | "source": [
67 | "#If you are offline use the first url\n",
68 | "#url = '../data/20111101120000-CMC-L4_GHRSST-SSTfnd-CMC0.2deg-GLOB-v02.0-fv02.0.nc'\n",
69 | "url = 'https://podaac-opendap.jpl.nasa.gov/opendap/allData/ghrsst/data/GDS2/L4/GLOB/CMC/CMC0.2deg/v2/2011/305/20111101120000-CMC-L4_GHRSST-SSTfnd-CMC0.2deg-GLOB-v02.0-fv02.0.nc'\n",
70 | "\n",
71 | "\n"
72 | ]
73 | },
74 | {
75 | "cell_type": "markdown",
76 | "metadata": {},
77 | "source": [
78 | "\n",
79 | "## explore the in situ data and quickly plot using cartopy\n",
80 | "\n",
81 | "* first set up the axis with the projection you want: https://scitools.org.uk/cartopy/docs/latest/crs/projections.html\n",
82 | "* plot to that axis and tell the projection that your data is in\n",
83 | "\n",
84 | "#### Run the cell below and see what the image looks like. Then try adding in the lines below, one at a time, and re-run cell to see what happens\n",
85 | "\n",
86 | "* set a background image `ax.stock_img()`\n",
87 | "* draw coastlines `ax.coastlines(resolution='50m')`\n",
88 | "* add a colorbary and label it `cax = plt.colorbar(cs1)` `cax.set_label('SST (K)')`"
89 | ]
90 | },
91 | {
92 | "cell_type": "code",
93 | "execution_count": null,
94 | "metadata": {
95 | "scrolled": true
96 | },
97 | "outputs": [],
98 | "source": [
99 | "#for polar data, plot temperature\n",
100 | "\n",
101 | "datamin = 0\n",
102 | "datamax = 12\n",
103 | "\n",
104 | "ax = plt.axes(projection=ccrs.SouthPolarStereo()) #here is where you set your axis projection\n",
105 | "\n",
106 | "(ds_sst.analysed_sst-273.15).plot(ax=ax, \n",
107 | " transform=ccrs.PlateCarree(), #set data projection\n",
108 | " vmin=datamin, #data min\n",
109 | " vmax=datamax) #data min\n",
110 | "\n",
111 | "cs1 = ax.scatter(ds_usv.lon, ds_usv.lat, \n",
112 | " transform=ccrs.PlateCarree(), #set data projection\n",
113 | " s=10.0, #size for scatter point\n",
114 | " c=ds_usv.TEMP_CTD_MEAN, #make the color of the scatter point equal to the USV temperature\n",
115 | " edgecolor='none', #no edgecolor\n",
116 | " cmap='jet', #colormap\n",
117 | " vmin=datamin, #data min\n",
118 | " vmax=datamax) #data max\n",
119 | "\n",
120 | "ax.set_extent([-180, 180, -90, -45], crs=ccrs.PlateCarree()) #data projection\n"
121 | ]
122 | },
123 | {
124 | "cell_type": "markdown",
125 | "metadata": {},
126 | "source": [
127 | "# Plot the salinity\n",
128 | "* Take the code from above but use `c=ds_usv.SAL_MEAN`\n",
129 | "* Run the code, what looks wrong?\n",
130 | "* Change `datamin` and `datamax`\n"
131 | ]
132 | },
133 | {
134 | "cell_type": "code",
135 | "execution_count": null,
136 | "metadata": {},
137 | "outputs": [],
138 | "source": [
139 | "\n"
140 | ]
141 | },
142 | {
143 | "cell_type": "markdown",
144 | "metadata": {},
145 | "source": [
146 | "# Let's plot some data off California\n",
147 | "* Read in data from a cruise along the California / Baja Coast\n",
148 | "* `ds_usv = xr.open_dataset(url).rename({'longitude':'lon','latitude':'lat'})`"
149 | ]
150 | },
151 | {
152 | "cell_type": "code",
153 | "execution_count": null,
154 | "metadata": {},
155 | "outputs": [],
156 | "source": [
157 | "#use the first URL if you are offline\n",
158 | "#url = '../data/saildrone-gen_4-baja_2018-sd1002-20180411T180000-20180611T055959-1_minutes-v1.nc'\n",
159 | "url = 'https://podaac-opendap.jpl.nasa.gov/opendap/hyrax/allData/insitu/L2/saildrone/Baja/saildrone-gen_4-baja_2018-sd1002-20180411T180000-20180611T055959-1_minutes-v1.nc'\n"
160 | ]
161 | },
162 | {
163 | "cell_type": "markdown",
164 | "metadata": {},
165 | "source": [
166 | "* Plot the data using the code from above, but change the projection\n",
167 | "\n",
168 | "`ax = plt.axes(projection=ccrs.PlateCarree())`\n",
169 | "\n"
170 | ]
171 | },
172 | {
173 | "cell_type": "code",
174 | "execution_count": null,
175 | "metadata": {},
176 | "outputs": [],
177 | "source": [
178 | "\n"
179 | ]
180 | },
181 | {
182 | "cell_type": "markdown",
183 | "metadata": {},
184 | "source": [
185 | "* Zoom into the region of the cruise \n",
186 | "* First calculate the lat/lon box
\n",
187 | "`lonmin,lonmax = ds_usv.lon.min().data-2,ds_usv.lon.max().data+2`
\n",
188 | "`latmin,latmax = ds_usv.lat.min().data-2,ds_usv.lat.max().data+2`\n",
189 | "\n",
190 | "* Then, after plotting the data, change the extent\n",
191 | "\n",
192 | "`ax.set_extent([lonmin,lonmax,latmin,latmax], crs=ccrs.PlateCarree())`\n"
193 | ]
194 | },
195 | {
196 | "cell_type": "code",
197 | "execution_count": null,
198 | "metadata": {},
199 | "outputs": [],
200 | "source": []
201 | }
202 | ],
203 | "metadata": {
204 | "kernelspec": {
205 | "display_name": "Python 3",
206 | "language": "python",
207 | "name": "python3"
208 | },
209 | "language_info": {
210 | "codemirror_mode": {
211 | "name": "ipython",
212 | "version": 3
213 | },
214 | "file_extension": ".py",
215 | "mimetype": "text/x-python",
216 | "name": "python",
217 | "nbconvert_exporter": "python",
218 | "pygments_lexer": "ipython3",
219 | "version": "3.7.3"
220 | }
221 | },
222 | "nbformat": 4,
223 | "nbformat_minor": 1
224 | }
225 |
--------------------------------------------------------------------------------
/notebooks/CalAcademy/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/notebooks/CalAcademy/.DS_Store
--------------------------------------------------------------------------------
/notebooks/CalAcademy/.ipynb_checkpoints/.ipynb_checkpoints/CalAcademy_explore_data-checkpoint-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Data Exploration"
8 | ]
9 | },
10 | {
11 | "cell_type": "code",
12 | "execution_count": 2,
13 | "metadata": {},
14 | "outputs": [],
15 | "source": [
16 | "# Modules\n",
17 | "import warnings\n",
18 | "warnings.simplefilter('ignore') # filter some warning messages\n",
19 | "\n",
20 | "import numpy as np\n",
21 | "import pandas as pd\n",
22 | "import matplotlib.pyplot as plt\n",
23 | "import xarray as xr\n",
24 | "import seaborn as sns\n",
25 | "import datetime as dt\n",
26 | "import fsspec\n",
27 | "import s3fs\n",
28 | "import scipy.stats as stats\n",
29 | "# make datasets display nicely\n",
30 | "xr.set_options(display_style=\"html\") \n",
31 | "\n",
32 | "#magic fncts #put static images of your plot embedded in the notebook\n",
33 | "%matplotlib inline \n",
34 | "plt.rcParams['figure.figsize'] = 12, 6\n",
35 | "%config InlineBackend.figure_format = 'retina' "
36 | ]
37 | },
38 | {
39 | "cell_type": "markdown",
40 | "metadata": {},
41 | "source": [
42 | "# Mole Crab Data"
43 | ]
44 | },
45 | {
46 | "cell_type": "markdown",
47 | "metadata": {},
48 | "source": [
49 | "### Read and explore mole crab data\n",
50 | "crabs = pd.read_csv('./MoleCrab_abundance_annual.csv',index_col=2)\n",
51 | "\n",
52 | "crabs.head()"
53 | ]
54 | },
55 | {
56 | "cell_type": "markdown",
57 | "metadata": {},
58 | "source": [
59 | "### Plot a distribution of abundance\n",
60 | "sns.distplot(crabs['Abundance (psm)'])"
61 | ]
62 | },
63 | {
64 | "cell_type": "markdown",
65 | "metadata": {},
66 | "source": [
67 | "### Plot annual data\n",
68 | "\n",
69 | "plt.bar(crabs.index,crabs['Abundance (psm)'])\n",
70 | "\n",
71 | "plt.xticks([*range(2000,2020,2)])\n",
72 | "\n",
73 | "plt.grid()\n",
74 | "\n",
75 | "plt.show()"
76 | ]
77 | },
78 | {
79 | "cell_type": "markdown",
80 | "metadata": {},
81 | "source": [
82 | "### Read Sea Surface Data Available in zar\n",
83 | "\n",
84 | "file_location = 's3://mur-sst/zarr'\n",
85 | "\n",
86 | "ikey = fsspec.get_mapper(file_location, anon=True)\n",
87 | "\n",
88 | "ds_sst = xr.open_zarr(ikey,consolidated=True)\n",
89 | "\n",
90 | "#ds_sst"
91 | ]
92 | },
93 | {
94 | "cell_type": "markdown",
95 | "metadata": {},
96 | "source": [
97 | "### Read data that matches crab data, in time and location\n",
98 | "\n",
99 | "sst_timeseries = ds_sst['analysed_sst'].sel(time = slice('2003-01-01','2017-12-31'),\n",
100 | " lat = 37.8,\n",
101 | " lon = -122.5\n",
102 | " ).load()\n",
103 | "\n",
104 | "### Plot and explore it\n",
105 | "\n",
106 | "sst_timeseries.plot()\n",
107 | "\n",
108 | "sst_timeseries"
109 | ]
110 | },
111 | {
112 | "cell_type": "markdown",
113 | "metadata": {},
114 | "source": [
115 | "### Average data annually\n",
116 | "\n",
117 | "sst_annual = sst_timeseries.groupby('time.year').mean('time',keep_attrs=True)\n",
118 | "\n",
119 | "sst_annual.plot()"
120 | ]
121 | },
122 | {
123 | "cell_type": "markdown",
124 | "metadata": {},
125 | "source": [
126 | "### Add temperature data to the crab data frame\n",
127 | "\n",
128 | "crabs = crabs[crabs.index>=2003]\n",
129 | "\n",
130 | "tmp = pd.DataFrame(data=sst_annual.data - 273.15, columns={'SST'}, index=[*range(2003,2018)])\n",
131 | "\n",
132 | "crabs['SST'] = tmp\n",
133 | "\n",
134 | "### Take a look\n",
135 | "\n",
136 | "crabs"
137 | ]
138 | },
139 | {
140 | "cell_type": "markdown",
141 | "metadata": {},
142 | "source": [
143 | "### Scatter Plot\n",
144 | "\n",
145 | "plt.figure(figsize=(8,6))\n",
146 | "\n",
147 | "plt.plot(crabs['SST'],crabs['Abundance (psm)'],'*')\n",
148 | "\n",
149 | "### Correlation\n",
150 | "stats.pearsonr(crabs['SST'], crabs['Abundance (psm)']) "
151 | ]
152 | },
153 | {
154 | "cell_type": "markdown",
155 | "metadata": {},
156 | "source": [
157 | "### Time series plot\n",
158 | "\n",
159 | "plt.figure(figsize=(8,6))\n",
160 | "\n",
161 | "plt.plot(crabs['SST'],crabs['Abundance (psm)'],'*')\n",
162 | "\n",
163 | "fig, ax1 = plt.subplots()\n",
164 | "\n",
165 | "color = 'tab:red'\n",
166 | "\n",
167 | "ax1.set_ylabel('SST', color='tab:red')\n",
168 | "\n",
169 | "ax1.plot(crabs.index, crabs['SST'], color='tab:red')\n",
170 | "\n",
171 | "ax1.tick_params(axis='y', labelcolor='tab:red')\n",
172 | "\n",
173 | "ax2 = ax1.twinx() # instantiate a second axes that shares the same x-axis\n",
174 | "\n",
175 | "color = 'tab:blue'\n",
176 | "\n",
177 | "ax2.set_ylabel('sin', color=color) # we already handled the x-label with ax1\n",
178 | "\n",
179 | "ax2.plot(t, data2, color=color)\n",
180 | "\n",
181 | "ax2.tick_params(axis='y', labelcolor=color)\n",
182 | "\n",
183 | "fig.tight_layout() \n"
184 | ]
185 | },
186 | {
187 | "cell_type": "code",
188 | "execution_count": null,
189 | "metadata": {},
190 | "outputs": [],
191 | "source": []
192 | }
193 | ],
194 | "metadata": {
195 | "kernelspec": {
196 | "display_name": "Python [conda env:farallon-fall-2020]",
197 | "language": "python",
198 | "name": "conda-env-farallon-fall-2020-py"
199 | },
200 | "language_info": {
201 | "codemirror_mode": {
202 | "name": "ipython",
203 | "version": 3
204 | },
205 | "file_extension": ".py",
206 | "mimetype": "text/x-python",
207 | "name": "python",
208 | "nbconvert_exporter": "python",
209 | "pygments_lexer": "ipython3",
210 | "version": "3.8.5"
211 | }
212 | },
213 | "nbformat": 4,
214 | "nbformat_minor": 4
215 | }
216 |
--------------------------------------------------------------------------------
/notebooks/CalAcademy/.ipynb_checkpoints/CalAcademy_explore_data-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Data Exploration"
8 | ]
9 | },
10 | {
11 | "cell_type": "code",
12 | "execution_count": null,
13 | "metadata": {},
14 | "outputs": [],
15 | "source": [
16 | "# Modules\n",
17 | "import warnings\n",
18 | "warnings.simplefilter('ignore') # filter some warning messages\n",
19 | "\n",
20 | "import numpy as np\n",
21 | "import pandas as pd\n",
22 | "import matplotlib.pyplot as plt\n",
23 | "import xarray as xr\n",
24 | "import seaborn as sns\n",
25 | "import datetime as dt\n",
26 | "import fsspec\n",
27 | "import s3fs\n",
28 | "import scipy.stats as stats\n",
29 | "# make datasets display nicely\n",
30 | "xr.set_options(display_style=\"html\") \n",
31 | "\n",
32 | "#magic fncts #put static images of your plot embedded in the notebook\n",
33 | "%matplotlib inline \n",
34 | "plt.rcParams['figure.figsize'] = 12, 6\n",
35 | "%config InlineBackend.figure_format = 'retina' "
36 | ]
37 | },
38 | {
39 | "cell_type": "markdown",
40 | "metadata": {},
41 | "source": [
42 | "# Mole Crab Data"
43 | ]
44 | },
45 | {
46 | "cell_type": "code",
47 | "execution_count": null,
48 | "metadata": {},
49 | "outputs": [],
50 | "source": [
51 | "### Read and explore mole crab data\n",
52 | "crabs = pd.read_csv('./MoleCrab_abundance_annual.csv',index_col=2)\n",
53 | "\n",
54 | "crabs.head()"
55 | ]
56 | },
57 | {
58 | "cell_type": "code",
59 | "execution_count": null,
60 | "metadata": {},
61 | "outputs": [],
62 | "source": [
63 | "crabs = pd.read_csv('./MoleCrab_abundance_annual.csv',index_col=2)\n",
64 | "crabs.tail()"
65 | ]
66 | },
67 | {
68 | "cell_type": "code",
69 | "execution_count": null,
70 | "metadata": {},
71 | "outputs": [],
72 | "source": [
73 | "### Plot a distribution of abundance\n",
74 | "sns.distplot(crabs['Abundance (psm)'])"
75 | ]
76 | },
77 | {
78 | "cell_type": "code",
79 | "execution_count": null,
80 | "metadata": {},
81 | "outputs": [],
82 | "source": [
83 | "### Plot annual data\n",
84 | "\n",
85 | "plt.bar(crabs.index,crabs['Abundance (psm)'])\n",
86 | "\n",
87 | "plt.xticks([*range(2000,2020,2)])\n",
88 | "\n",
89 | "plt.grid()\n",
90 | "\n",
91 | "plt.show()"
92 | ]
93 | },
94 | {
95 | "cell_type": "code",
96 | "execution_count": null,
97 | "metadata": {},
98 | "outputs": [],
99 | "source": [
100 | "### Read Sea Surface Data Available in zar\n",
101 | "\n",
102 | "file_location = 's3://mur-sst/zarr'\n",
103 | "\n",
104 | "ikey = fsspec.get_mapper(file_location, anon=True)\n",
105 | "\n",
106 | "ds_sst = xr.open_zarr(ikey,consolidated=True)\n",
107 | "\n",
108 | "#ds_sst"
109 | ]
110 | },
111 | {
112 | "cell_type": "code",
113 | "execution_count": null,
114 | "metadata": {},
115 | "outputs": [],
116 | "source": [
117 | "### Read data that matches crab data, in time and location\n",
118 | "\n",
119 | "sst_timeseries = ds_sst['analysed_sst'].sel(time = slice('2003-01-01','2016-12-31'),\n",
120 | " lat = 37.76,\n",
121 | " lon = -124.5\n",
122 | " ).load()\n",
123 | "\n",
124 | "### Plot and explore it\n",
125 | "sst_timeseries.plot()\n",
126 | "sst_timeseries"
127 | ]
128 | },
129 | {
130 | "cell_type": "code",
131 | "execution_count": null,
132 | "metadata": {},
133 | "outputs": [],
134 | "source": [
135 | "### Average data annually\n",
136 | "\n",
137 | "sst_annual = sst_timeseries.groupby('time.year').mean('time',keep_attrs=True)\n",
138 | "\n",
139 | "sst_annual.plot()"
140 | ]
141 | },
142 | {
143 | "cell_type": "markdown",
144 | "metadata": {},
145 | "source": [
146 | "### Add temperature data to the crab data frame\n",
147 | "\n",
148 | "crabs = crabs[crabs.index>=2003]\n",
149 | "\n",
150 | "tmp = pd.DataFrame(data=sst_annual.data - 273.15, columns={'SST'}, index=[*range(2003,2018)])\n",
151 | "\n",
152 | "crabs['SST'] = tmp\n",
153 | "\n",
154 | "### Take a look\n",
155 | "\n",
156 | "crabs"
157 | ]
158 | },
159 | {
160 | "cell_type": "markdown",
161 | "metadata": {},
162 | "source": [
163 | "### Scatter Plot\n",
164 | "\n",
165 | "plt.figure(figsize=(8,6))\n",
166 | "\n",
167 | "plt.plot(crabs['SST'],crabs['Abundance (psm)'],'*')\n",
168 | "\n",
169 | "### Correlation\n",
170 | "stats.pearsonr(crabs['SST'], crabs['Abundance (psm)']) "
171 | ]
172 | },
173 | {
174 | "cell_type": "markdown",
175 | "metadata": {},
176 | "source": [
177 | "### Time series plot\n",
178 | "\n",
179 | "plt.figure(figsize=(8,6))\n",
180 | "\n",
181 | "plt.plot(crabs['SST'],crabs['Abundance (psm)'],'*')\n",
182 | "\n",
183 | "fig, ax1 = plt.subplots()\n",
184 | "\n",
185 | "color = 'tab:red'\n",
186 | "\n",
187 | "ax1.set_ylabel('SST', color='tab:red')\n",
188 | "\n",
189 | "ax1.plot(crabs.index, crabs['SST'], color='tab:red')\n",
190 | "\n",
191 | "ax1.tick_params(axis='y', labelcolor='tab:red')\n",
192 | "\n",
193 | "ax2 = ax1.twinx() # instantiate a second axes that shares the same x-axis\n",
194 | "\n",
195 | "color = 'tab:blue'\n",
196 | "\n",
197 | "ax2.set_ylabel('sin', color=color) # we already handled the x-label with ax1\n",
198 | "\n",
199 | "ax2.plot(t, data2, color=color)\n",
200 | "\n",
201 | "ax2.tick_params(axis='y', labelcolor=color)\n",
202 | "\n",
203 | "fig.tight_layout() \n"
204 | ]
205 | },
206 | {
207 | "cell_type": "code",
208 | "execution_count": null,
209 | "metadata": {},
210 | "outputs": [],
211 | "source": []
212 | }
213 | ],
214 | "metadata": {
215 | "kernelspec": {
216 | "display_name": "Python [conda env:farallon-fall-2020]",
217 | "language": "python",
218 | "name": "conda-env-farallon-fall-2020-py"
219 | },
220 | "language_info": {
221 | "codemirror_mode": {
222 | "name": "ipython",
223 | "version": 3
224 | },
225 | "file_extension": ".py",
226 | "mimetype": "text/x-python",
227 | "name": "python",
228 | "nbconvert_exporter": "python",
229 | "pygments_lexer": "ipython3",
230 | "version": "3.8.5"
231 | }
232 | },
233 | "nbformat": 4,
234 | "nbformat_minor": 4
235 | }
236 |
--------------------------------------------------------------------------------
/notebooks/CalAcademy/.ipynb_checkpoints/DataExploration_CalAcademy-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Data Exploration"
8 | ]
9 | },
10 | {
11 | "cell_type": "code",
12 | "execution_count": null,
13 | "metadata": {},
14 | "outputs": [],
15 | "source": [
16 | "# Modules\n",
17 | "import warnings\n",
18 | "warnings.simplefilter('ignore') # filter some warning messages\n",
19 | "\n",
20 | "import numpy as np\n",
21 | "import pandas as pd\n",
22 | "import matplotlib.pyplot as plt\n",
23 | "import xarray as xr\n",
24 | "import seaborn as sns"
25 | ]
26 | },
27 | {
28 | "cell_type": "markdown",
29 | "metadata": {},
30 | "source": [
31 | "# Mole Crab Data"
32 | ]
33 | },
34 | {
35 | "cell_type": "code",
36 | "execution_count": null,
37 | "metadata": {},
38 | "outputs": [],
39 | "source": [
40 | "# read data into a dataframe\n",
41 | "crabs = pd.read_csv('../../data/MoleCrab_abundance_annual.csv', index_col=2)\n",
42 | "# display the first lines, the last lines, and all\n",
43 | "crabs.head()"
44 | ]
45 | },
46 | {
47 | "cell_type": "code",
48 | "execution_count": null,
49 | "metadata": {},
50 | "outputs": [],
51 | "source": [
52 | "sns.distplot(crabs['Abundance (psm)'])"
53 | ]
54 | },
55 | {
56 | "cell_type": "code",
57 | "execution_count": null,
58 | "metadata": {},
59 | "outputs": [],
60 | "source": [
61 | "plt.bar(crabs.index,crabs['Abundance (psm)'])\n",
62 | "plt.xticks([*range(2000,2020,2)])\n",
63 | "plt.grid()\n",
64 | "plt.ylabel('Abundance per square meter')\n",
65 | "plt.title('Mole Crab Annual Abundance')\n",
66 | "plt.show()"
67 | ]
68 | },
69 | {
70 | "cell_type": "code",
71 | "execution_count": null,
72 | "metadata": {},
73 | "outputs": [],
74 | "source": []
75 | }
76 | ],
77 | "metadata": {
78 | "kernelspec": {
79 | "display_name": "Python 3",
80 | "language": "python",
81 | "name": "python3"
82 | },
83 | "language_info": {
84 | "codemirror_mode": {
85 | "name": "ipython",
86 | "version": 3
87 | },
88 | "file_extension": ".py",
89 | "mimetype": "text/x-python",
90 | "name": "python",
91 | "nbconvert_exporter": "python",
92 | "pygments_lexer": "ipython3",
93 | "version": "3.7.6"
94 | }
95 | },
96 | "nbformat": 4,
97 | "nbformat_minor": 4
98 | }
99 |
--------------------------------------------------------------------------------
/notebooks/CalAcademy/.ipynb_checkpoints/Data_Explorer_2-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Explore Data 2"
8 | ]
9 | },
10 | {
11 | "cell_type": "code",
12 | "execution_count": null,
13 | "metadata": {},
14 | "outputs": [],
15 | "source": [
16 | "# Modules\n",
17 | "import warnings\n",
18 | "warnings.simplefilter('ignore') # filter some warning messages\n",
19 | "\n",
20 | "import numpy as np\n",
21 | "import pandas as pd\n",
22 | "import matplotlib.pyplot as plt\n",
23 | "import xarray as xr\n",
24 | "import seaborn as sns\n",
25 | "import datetime as dt\n",
26 | "import fsspec\n",
27 | "import s3fs\n",
28 | "import scipy.stats as stats\n",
29 | "# make datasets display nicely\n",
30 | "xr.set_options(display_style=\"html\") \n",
31 | "\n",
32 | "#magic fncts #put static images of your plot embedded in the notebook\n",
33 | "%matplotlib inline \n",
34 | "plt.rcParams['figure.figsize'] = 12, 6\n",
35 | "%config InlineBackend.figure_format = 'retina' "
36 | ]
37 | },
38 | {
39 | "cell_type": "markdown",
40 | "metadata": {},
41 | "source": [
42 | "# Mole Crab Data"
43 | ]
44 | },
45 | {
46 | "cell_type": "code",
47 | "execution_count": null,
48 | "metadata": {},
49 | "outputs": [],
50 | "source": [
51 | "### Read and look at mole crab data\n",
52 | "crabs = pd.read_csv('./Annual_UpwellingAprJul_OceanBeach.csv',index_col=0)\n",
53 | "crabs.head()"
54 | ]
55 | },
56 | {
57 | "cell_type": "markdown",
58 | "metadata": {},
59 | "source": [
60 | "# SST Data"
61 | ]
62 | },
63 | {
64 | "cell_type": "code",
65 | "execution_count": null,
66 | "metadata": {},
67 | "outputs": [],
68 | "source": [
69 | "### Read Sea Surface Data Available in zar\n",
70 | "\n",
71 | "file_location = 's3://mur-sst/zarr'\n",
72 | "\n",
73 | "ikey = fsspec.get_mapper(file_location, anon=True)\n",
74 | "\n",
75 | "ds_sst = xr.open_zarr(ikey,consolidated=True)\n",
76 | "\n",
77 | "#ds_sst"
78 | ]
79 | },
80 | {
81 | "cell_type": "code",
82 | "execution_count": null,
83 | "metadata": {},
84 | "outputs": [],
85 | "source": [
86 | "### Read data that matches crab data, in time and location\n",
87 | "\n",
88 | "sst_timeseries = ds_sst['analysed_sst'].sel(time = slice('2003-01-01','2016-12-31'),\n",
89 | " lat = slice(37.7,37.8), #37.76\n",
90 | " lon = slice(-122.55,-122.45) #-124.5\n",
91 | " ).load()\n",
92 | "\n",
93 | "# average over lat and lon\n",
94 | "sst_timeseries = sst_timeseries.where(sst_timeseries>273.15)\n",
95 | "sst_timeseries = sst_timeseries.mean(dim={'lat','lon'},keep_attrs=True,skipna=True)\n",
96 | "\n",
97 | "### Plot and explore it\n",
98 | "sst_timeseries.plot()\n",
99 | "sst_timeseries"
100 | ]
101 | },
102 | {
103 | "cell_type": "markdown",
104 | "metadata": {},
105 | "source": [
106 | "# Making one Pandas DataFrame with all the Data\n",
107 | "## Averaged SST for each year's upwelling season"
108 | ]
109 | },
110 | {
111 | "cell_type": "code",
112 | "execution_count": null,
113 | "metadata": {},
114 | "outputs": [],
115 | "source": [
116 | "crabs['SST']=np.nan\n",
117 | "for i in range(2003,2017):\n",
118 | " tmp = sst_timeseries.sel(time = slice(str(i)+'-04-01',str(i)+'-07-31')).mean()\n",
119 | " #print(tmp.values)\n",
120 | " a=crabs[crabs['Year']==i].index\n",
121 | " crabs.at[a[0],'SST']=tmp.data-273.15\n",
122 | "crabs"
123 | ]
124 | },
125 | {
126 | "cell_type": "markdown",
127 | "metadata": {},
128 | "source": [
129 | "# Plot data"
130 | ]
131 | },
132 | {
133 | "cell_type": "markdown",
134 | "metadata": {},
135 | "source": [
136 | "## Time series plot"
137 | ]
138 | },
139 | {
140 | "cell_type": "code",
141 | "execution_count": null,
142 | "metadata": {},
143 | "outputs": [],
144 | "source": [
145 | "plt.figure(figsize=(8,6))\n",
146 | "plt.plot(crabs['Year'],crabs['Female'],'*-',label='Female')\n",
147 | "plt.plot(crabs['Year'],crabs['Female w Eggs'],'d-',label='Female w Eggs')\n",
148 | "plt.plot(crabs['Year'],crabs['Male'],'d-',label='Male')\n",
149 | "plt.legend()\n",
150 | "plt.ylabel('No. Crabs')\n",
151 | "plt.grid()\n",
152 | "plt.show()"
153 | ]
154 | },
155 | {
156 | "cell_type": "markdown",
157 | "metadata": {},
158 | "source": [
159 | "## Plot of two variables in differnt axis: SST + some Crab data"
160 | ]
161 | },
162 | {
163 | "cell_type": "code",
164 | "execution_count": null,
165 | "metadata": {},
166 | "outputs": [],
167 | "source": [
168 | "var='Male'\n",
169 | "fig, ax1 = plt.subplots()\n",
170 | "\n",
171 | "color = 'tab:red'\n",
172 | "ax1.set_ylabel('SST', color=color)\n",
173 | "ax1.plot(crabs.Year, crabs['SST'], '.-',color=color)\n",
174 | "ax1.tick_params(axis='y', labelcolor=color)\n",
175 | "\n",
176 | "ax2 = ax1.twinx() # instantiate a second axes that shares the same x-axis\n",
177 | "color = 'tab:blue'\n",
178 | "ax2.set_ylabel(var+' Crabs', color=color) # we already handled the x-label with ax1\n",
179 | "ax2.plot(crabs.Year, crabs[var], '*-',color=color)\n",
180 | "ax2.tick_params(axis='y', labelcolor=color)\n",
181 | "\n",
182 | "fig.tight_layout() "
183 | ]
184 | },
185 | {
186 | "cell_type": "markdown",
187 | "metadata": {},
188 | "source": [
189 | "## Scatter plot"
190 | ]
191 | },
192 | {
193 | "cell_type": "code",
194 | "execution_count": null,
195 | "metadata": {},
196 | "outputs": [],
197 | "source": [
198 | "var='Female w Eggs'\n",
199 | "plt.figure(figsize=(8,6))\n",
200 | "plt.scatter(crabs['SST'],crabs[var],40, c=crabs['Year'],label='Female',cmap='jet')\n",
201 | "plt.colorbar()\n",
202 | "plt.legend()\n",
203 | "plt.ylabel('No. Crabs')\n",
204 | "plt.xlabel('SST')\n",
205 | "plt.grid()\n",
206 | "plt.show()"
207 | ]
208 | },
209 | {
210 | "cell_type": "markdown",
211 | "metadata": {},
212 | "source": [
213 | "## Correlation between SST and crab data"
214 | ]
215 | },
216 | {
217 | "cell_type": "code",
218 | "execution_count": null,
219 | "metadata": {},
220 | "outputs": [],
221 | "source": [
222 | "print('SST-variable correlation\\n(Correlation, p-value) \\n (<0.05 is good!)\\n')\n",
223 | "for i in list(crabs)[1:-1]:\n",
224 | " tmp=crabs[(~np.isnan(crabs['SST']))&(~np.isnan(crabs[i]))]\n",
225 | " print(i)\n",
226 | " print(stats.pearsonr(tmp['SST'], tmp[i]))\n",
227 | "\n",
228 | "print('\\n')\n",
229 | "for i in list(crabs)[1:-1]:\n",
230 | " tmp=crabs[(~np.isnan(crabs['SST']))&(~np.isnan(crabs[i]))&(crabs['Year']!=2015)]\n",
231 | " print(i)\n",
232 | " print(stats.pearsonr(tmp['SST'], tmp[i]))\n",
233 | " \n",
234 | "print('\\n')\n",
235 | "for i in list(crabs)[1:-1]:\n",
236 | " tmp=crabs[(~np.isnan(crabs['SST']))&(~np.isnan(crabs[i]))&(crabs['Year']<2015)]\n",
237 | " print(i)\n",
238 | " print(stats.pearsonr(tmp['SST'], tmp[i]))"
239 | ]
240 | },
241 | {
242 | "cell_type": "markdown",
243 | "metadata": {},
244 | "source": [
245 | "# Linear regression"
246 | ]
247 | },
248 | {
249 | "cell_type": "code",
250 | "execution_count": null,
251 | "metadata": {},
252 | "outputs": [],
253 | "source": [
254 | "# linear regressions\n",
255 | "for i in list(crabs)[1:-1]:\n",
256 | " tmp=crabs[(~np.isnan(crabs['SST']))&(~np.isnan(crabs[i]))]\n",
257 | " print(i)\n",
258 | " slope, intercept, r_value, p_value, std_err = stats.linregress(tmp['SST'], tmp[i])\n",
259 | " print(slope,p_value)"
260 | ]
261 | },
262 | {
263 | "cell_type": "code",
264 | "execution_count": null,
265 | "metadata": {},
266 | "outputs": [],
267 | "source": []
268 | }
269 | ],
270 | "metadata": {
271 | "kernelspec": {
272 | "display_name": "Python [conda env:farallon-fall-2020]",
273 | "language": "python",
274 | "name": "conda-env-farallon-fall-2020-py"
275 | },
276 | "language_info": {
277 | "codemirror_mode": {
278 | "name": "ipython",
279 | "version": 3
280 | },
281 | "file_extension": ".py",
282 | "mimetype": "text/x-python",
283 | "name": "python",
284 | "nbconvert_exporter": "python",
285 | "pygments_lexer": "ipython3",
286 | "version": "3.8.5"
287 | }
288 | },
289 | "nbformat": 4,
290 | "nbformat_minor": 4
291 | }
292 |
--------------------------------------------------------------------------------
/notebooks/CalAcademy/.ipynb_checkpoints/ShortIntro_CalAcademy-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "# Python for Oceanographers \n",
9 | "Chelle Gentemann (cgentemann@esr.org) \n",
10 | "\n",
11 | "Marisol García-Reyes (marisolgr@faralloninstitute.org)"
12 | ]
13 | },
14 | {
15 | "cell_type": "markdown",
16 | "metadata": {},
17 | "source": [
18 | "-----------"
19 | ]
20 | },
21 | {
22 | "cell_type": "markdown",
23 | "metadata": {},
24 | "source": [
25 | "
\n",
26 | "\n",
27 | "## `Python` is an awesome programming language\n",
28 | "- It is `Open Source`: it is free, everybody can use it, everybody can contribute to it\n",
29 | "- It is used by an enourmous community of developers\n",
30 | "- All the need you might need is online "
31 | ]
32 | },
33 | {
34 | "cell_type": "markdown",
35 | "metadata": {},
36 | "source": [
37 | "## `Python` can be install on your computer or you can run it online, in the Cloud\n",
38 | "\n",
39 | "\n",
40 | "### If you're running this from the `Binder`, you're already working in the cloud!!!"
41 | ]
42 | },
43 | {
44 | "cell_type": "markdown",
45 | "metadata": {},
46 | "source": [
47 | "--------------"
48 | ]
49 | },
50 | {
51 | "cell_type": "markdown",
52 | "metadata": {},
53 | "source": [
54 | "### `Jupyter` is a project for developing open-source software\n",
55 | "### `Jupyter Lab` is a web application (user interface) to create scripts"
56 | ]
57 | },
58 | {
59 | "cell_type": "markdown",
60 | "metadata": {},
61 | "source": [
62 | "\n",
63 | " We are going to make all our analysis online on a JupyterLab Notebook\n",
64 | "
"
65 | ]
66 | },
67 | {
68 | "cell_type": "markdown",
69 | "metadata": {},
70 | "source": [
71 | "
\n",
72 | "\n",
73 | "# `JupyterLab` basics\n",
74 | "## Add cell: `+` on the menu above\n",
75 | "\n",
76 | "## Two type of cells, change in the menu above\n",
77 | "### `Code` Cells: execute code\n",
78 | "### `Markdown` Cells: show formated text\n",
79 | "\n",
80 | "## To execute cells\n",
81 | "### - `Shift-Enter` : executes cell & advance to next\n",
82 | "### - `Control-enter` : executes cell & stay in the same cell"
83 | ]
84 | },
85 | {
86 | "cell_type": "markdown",
87 | "metadata": {},
88 | "source": [
89 | "----------"
90 | ]
91 | },
92 | {
93 | "cell_type": "markdown",
94 | "metadata": {},
95 | "source": [
96 | "# But first, some `Python` basics\n",
97 | "\n",
98 | "## Python is `Modular`: it has all the libraries you could possibly need; you do not need to install them all\n",
99 | "- Libraries are just a collection of programs or functions for a specific purpose. \n",
100 | "\n",
101 | "\n",
102 | " That means you have to start by 'loading' or 'importing' the libraries you need\n",
103 | "
"
104 | ]
105 | },
106 | {
107 | "cell_type": "code",
108 | "execution_count": null,
109 | "metadata": {},
110 | "outputs": [],
111 | "source": [
112 | "import numpy as np\n",
113 | "import pandas as pd\n",
114 | "from datetime import timedelta\n",
115 | "import xarray as xr"
116 | ]
117 | },
118 | {
119 | "cell_type": "markdown",
120 | "metadata": {},
121 | "source": [
122 | "----------"
123 | ]
124 | },
125 | {
126 | "cell_type": "markdown",
127 | "metadata": {},
128 | "source": [
129 | "## the `xarray` module is probably our favorite!"
130 | ]
131 | },
132 | {
133 | "cell_type": "markdown",
134 | "metadata": {},
135 | "source": [
136 | "
"
137 | ]
138 | },
139 | {
140 | "cell_type": "markdown",
141 | "metadata": {},
142 | "source": [
143 | "## Python is `Object Oriented`: each variable or object has attributes or functions particular to the type of object"
144 | ]
145 | },
146 | {
147 | "cell_type": "code",
148 | "execution_count": null,
149 | "metadata": {},
150 | "outputs": [],
151 | "source": [
152 | "myvar = 'hola mundo!'\n",
153 | "type(myvar)"
154 | ]
155 | },
156 | {
157 | "cell_type": "code",
158 | "execution_count": null,
159 | "metadata": {},
160 | "outputs": [],
161 | "source": [
162 | "myvar.upper()"
163 | ]
164 | },
165 | {
166 | "cell_type": "code",
167 | "execution_count": null,
168 | "metadata": {},
169 | "outputs": [],
170 | "source": [
171 | "myvar.upper()[:4]"
172 | ]
173 | },
174 | {
175 | "cell_type": "code",
176 | "execution_count": null,
177 | "metadata": {},
178 | "outputs": [],
179 | "source": [
180 | "myvar.upper().lower()"
181 | ]
182 | }
183 | ],
184 | "metadata": {
185 | "kernelspec": {
186 | "display_name": "Python 3",
187 | "language": "python",
188 | "name": "python3"
189 | },
190 | "language_info": {
191 | "codemirror_mode": {
192 | "name": "ipython",
193 | "version": 3
194 | },
195 | "file_extension": ".py",
196 | "mimetype": "text/x-python",
197 | "name": "python",
198 | "nbconvert_exporter": "python",
199 | "pygments_lexer": "ipython3",
200 | "version": "3.7.6"
201 | }
202 | },
203 | "nbformat": 4,
204 | "nbformat_minor": 4
205 | }
206 |
--------------------------------------------------------------------------------
/notebooks/CalAcademy/.ipynb_checkpoints/clean_summarize_crabdata-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": null,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "import warnings\n",
10 | "warnings.simplefilter('ignore') # filter some warning messages\n",
11 | "\n",
12 | "import numpy as np\n",
13 | "import pandas as pd\n",
14 | "import matplotlib.pyplot as plt"
15 | ]
16 | },
17 | {
18 | "cell_type": "code",
19 | "execution_count": null,
20 | "metadata": {},
21 | "outputs": [],
22 | "source": [
23 | "# read data file\n",
24 | "tmp = pd.read_excel('./sandcrab_data_2017-11-16.xlsx', sheet_name=4, usecols=[*range(11)])\n",
25 | "tmp['Year']= pd.DatetimeIndex(tmp.Date).year\n",
26 | "tmp['Month']= pd.DatetimeIndex(tmp.Date).month\n",
27 | "tmp.tail()"
28 | ]
29 | },
30 | {
31 | "cell_type": "code",
32 | "execution_count": null,
33 | "metadata": {},
34 | "outputs": [],
35 | "source": [
36 | "# calculate factor to get number of crabs per square meter\n",
37 | "# 'sample area' - core diameter = 15.2cm\n",
38 | "ar = np.pi*(0.152)**2 # in sm squared meters\n",
39 | "# to transform number of crabs per sample to crabs per square meters divide by ar"
40 | ]
41 | },
42 | {
43 | "cell_type": "code",
44 | "execution_count": null,
45 | "metadata": {},
46 | "outputs": [],
47 | "source": [
48 | "# per year, per upwelling season (april-july)\n",
49 | "# calculate the total, and averaged (pm2)\n",
50 | "iy = 2002\n",
51 | "fy = 2016 # technically september\n",
52 | "df = pd.DataFrame(columns={'Year','Month','Total Crabs','Male','Female','Female w Eggs', 'Recruits'})\n",
53 | "ix = 0\n",
54 | "for i in range(iy,fy+1):\n",
55 | " # select site and year\n",
56 | " tmpi = tmp[(tmp.Year==i)&(tmp.Site=='Ocean Beach')]\n",
57 | " #print(i)\n",
58 | " # select month\n",
59 | " for j in range(4,8): # upwelling season only\n",
60 | " tmpm = tmpi[tmp.Month==j]\n",
61 | " #print(j)\n",
62 | " # only year, month, total, male, fem, femweggs\n",
63 | " df.at[ix,'Year'] =i\n",
64 | " df.at[ix,'Month']=j\n",
65 | " df.at[ix,'Total Crabs'] = np.round(np.nanmean(tmpm['Total Crabs'])/ar,1)\n",
66 | " df.at[ix,'Male']=np.round(np.nanmean(tmpm['#Male'])/ar,1)\n",
67 | " df.at[ix,'Female']=np.round(np.nanmean(tmpm['#Female'])/ar,1)\n",
68 | " df.at[ix,'Female w Eggs']= np.round(np.nanmean(tmpm['#Female w/t Eggs'])/ar,1)\n",
69 | " df.at[ix,'Recruits']= np.round(np.nanmean(tmpm['#Recruits'])/ar,1)\n",
70 | " ix += 1\n",
71 | "df = df[['Year','Month','Total Crabs','Male','Female','Female w Eggs','Recruits']]\n",
72 | "df.head()"
73 | ]
74 | },
75 | {
76 | "cell_type": "code",
77 | "execution_count": null,
78 | "metadata": {},
79 | "outputs": [],
80 | "source": [
81 | "# Annual averages (upwelling season)\n",
82 | "ix = 0\n",
83 | "dfan = pd.DataFrame(columns={'Year','Total Crabs','Male','Female','Female w Eggs', 'Recruits'})\n",
84 | "\n",
85 | "for i in range(iy,fy+1):\n",
86 | " # print(i)\n",
87 | " tmp=df[df.Year==i]\n",
88 | " dfan.at[ix,'Year']=i\n",
89 | " dfan.at[ix,'Total Crabs']=np.nanmean(tmp['Total Crabs'])\n",
90 | " dfan.at[ix,'Male']=np.nanmean(tmp['Male'])\n",
91 | " dfan.at[ix,'Female']=np.nanmean(tmp['Female'])\n",
92 | " dfan.at[ix,'Female w Eggs']=np.nanmean(tmp['Female w Eggs'])\n",
93 | " dfan.at[ix,'Recruits']=np.nanmean(tmp['Recruits'])\n",
94 | " ix +=1\n",
95 | "dfan=dfan[['Year','Total Crabs','Male','Female','Female w Eggs', 'Recruits']]\n",
96 | "dfan.to_csv('./Annual_UpwellingAprJul_OceanBean.csv')\n",
97 | "dfan\n",
98 | "#plt.bar(range(iy,fy+1),anab)\n",
99 | "#plt.grid()\n",
100 | "\n"
101 | ]
102 | },
103 | {
104 | "cell_type": "code",
105 | "execution_count": null,
106 | "metadata": {},
107 | "outputs": [],
108 | "source": [
109 | "plt.figure(figsize=(8,5))\n",
110 | "plt.plot(dfan.Year,dfan['Total Crabs'],'*-',label='Total')\n",
111 | "plt.plot(dfan.Year,dfan['Recruits'],'d-',label='Recruits')\n",
112 | "plt.legend()\n",
113 | "plt.grid()\n",
114 | "plt.show()\n",
115 | "\n",
116 | "plt.figure(figsize=(8,5))\n",
117 | "plt.plot(dfan.Year,dfan['Male'],'*-',label='Male')\n",
118 | "plt.plot(dfan.Year,dfan['Female'],'d-',label='Female')\n",
119 | "plt.plot(dfan.Year,dfan['Female w Eggs'],'o-',label='Female w Eggs')\n",
120 | "#plt.plot(dfan.Year,dfan['Recruits'],'s-',label='Recruits')\n",
121 | "plt.legend()\n",
122 | "plt.grid()\n",
123 | "plt.show()"
124 | ]
125 | },
126 | {
127 | "cell_type": "code",
128 | "execution_count": null,
129 | "metadata": {},
130 | "outputs": [],
131 | "source": []
132 | }
133 | ],
134 | "metadata": {
135 | "kernelspec": {
136 | "display_name": "Python [conda env:farallon-fall-2020]",
137 | "language": "python",
138 | "name": "conda-env-farallon-fall-2020-py"
139 | },
140 | "language_info": {
141 | "codemirror_mode": {
142 | "name": "ipython",
143 | "version": 3
144 | },
145 | "file_extension": ".py",
146 | "mimetype": "text/x-python",
147 | "name": "python",
148 | "nbconvert_exporter": "python",
149 | "pygments_lexer": "ipython3",
150 | "version": "3.8.5"
151 | }
152 | },
153 | "nbformat": 4,
154 | "nbformat_minor": 4
155 | }
156 |
--------------------------------------------------------------------------------
/notebooks/CalAcademy/Annual_UpwellingAprJul_OceanBeach.csv:
--------------------------------------------------------------------------------
1 | ,Year,Total Crabs,Male,Female,Female w Eggs,Recruits
2 | 0,2002,31.15,11.399999999999999,6.3500000000000005,10.899999999999999,2.55
3 | 1,2003,351.29999999999995,28.549999999999997,6.199999999999999,9.924999999999999,306.675
4 | 2,2004,86.23333333333333,35.63333333333333,5.133333333333333,34.1,11.333333333333334
5 | 3,2005,39.975,3.325,4.5249999999999995,6.7,25.4
6 | 4,2006,31.46666666666667,8.4,1.9666666666666668,9.033333333333333,12.100000000000001
7 | 5,2007,26.666666666666668,8.033333333333333,4.4,8.466666666666667,5.733333333333334
8 | 6,2008,17.700000000000003,4.375,4.075,7.625,1.6
9 | 7,2009,32.425,4.45,1.675,4.6499999999999995,21.599999999999998
10 | 8,2010,288.85,3.425,5.725,0.65,279.05
11 | 9,2011,58.24999999999999,14.874999999999998,7.425,10.675,25.3
12 | 10,2012,43.9,6.125,3.375,13.375,21.025000000000002
13 | 11,2013,130.875,8.9,3.225,8.100000000000001,110.62499999999999
14 | 12,2014,122.22500000000001,11.15,1.4500000000000002,5.324999999999999,104.325
15 | 13,2015,74.15,16.2,11.9,8.299999999999999,37.75
16 | 14,2016,120.29999999999998,11.774999999999999,6.0,2.3000000000000003,100.17500000000001
17 |
--------------------------------------------------------------------------------
/notebooks/CalAcademy/Annual_UpwellingAprJul_OceanBean.csv:
--------------------------------------------------------------------------------
1 | ,Year,Total Crabs,Male,Female,Female w Eggs,Recruits
2 | 0,2002,31.15,11.399999999999999,6.3500000000000005,10.899999999999999,2.55
3 | 1,2003,351.29999999999995,28.549999999999997,6.199999999999999,9.924999999999999,306.675
4 | 2,2004,86.23333333333333,35.63333333333333,5.133333333333333,34.1,11.333333333333334
5 | 3,2005,39.975,3.325,4.5249999999999995,6.7,25.4
6 | 4,2006,31.46666666666667,8.4,1.9666666666666668,9.033333333333333,12.100000000000001
7 | 5,2007,26.666666666666668,8.033333333333333,4.4,8.466666666666667,5.733333333333334
8 | 6,2008,17.700000000000003,4.375,4.075,7.625,1.6
9 | 7,2009,32.425,4.45,1.675,4.6499999999999995,21.599999999999998
10 | 8,2010,288.85,3.425,5.725,0.65,279.05
11 | 9,2011,58.24999999999999,14.874999999999998,7.425,10.675,25.3
12 | 10,2012,43.9,6.125,3.375,13.375,21.025000000000002
13 | 11,2013,130.875,8.9,3.225,8.100000000000001,110.62499999999999
14 | 12,2014,122.22500000000001,11.15,1.4500000000000002,5.324999999999999,104.325
15 | 13,2015,74.15,16.2,11.9,8.299999999999999,37.75
16 | 14,2016,120.29999999999998,11.774999999999999,6.0,2.3000000000000003,100.17500000000001
17 |
--------------------------------------------------------------------------------
/notebooks/CalAcademy/CalAcademy_explore_data.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Data Exploration"
8 | ]
9 | },
10 | {
11 | "cell_type": "code",
12 | "execution_count": null,
13 | "metadata": {},
14 | "outputs": [],
15 | "source": [
16 | "# Modules\n",
17 | "import warnings\n",
18 | "warnings.simplefilter('ignore') # filter some warning messages\n",
19 | "\n",
20 | "import numpy as np\n",
21 | "import pandas as pd\n",
22 | "import matplotlib.pyplot as plt\n",
23 | "import xarray as xr\n",
24 | "import seaborn as sns\n",
25 | "import datetime as dt\n",
26 | "import fsspec\n",
27 | "import s3fs\n",
28 | "import scipy.stats as stats\n",
29 | "# make datasets display nicely\n",
30 | "xr.set_options(display_style=\"html\") \n",
31 | "\n",
32 | "#magic fncts #put static images of your plot embedded in the notebook\n",
33 | "%matplotlib inline \n",
34 | "plt.rcParams['figure.figsize'] = 12, 6\n",
35 | "%config InlineBackend.figure_format = 'retina' "
36 | ]
37 | },
38 | {
39 | "cell_type": "markdown",
40 | "metadata": {},
41 | "source": [
42 | "# Mole Crab Data"
43 | ]
44 | },
45 | {
46 | "cell_type": "code",
47 | "execution_count": null,
48 | "metadata": {},
49 | "outputs": [],
50 | "source": [
51 | "### Read and explore mole crab data\n",
52 | "crabs = pd.read_csv('./MoleCrab_abundance_annual.csv',index_col=2)\n",
53 | "\n",
54 | "crabs.head()"
55 | ]
56 | },
57 | {
58 | "cell_type": "code",
59 | "execution_count": null,
60 | "metadata": {},
61 | "outputs": [],
62 | "source": [
63 | "crabs = pd.read_csv('./MoleCrab_abundance_annual.csv',index_col=2)\n",
64 | "crabs.tail()"
65 | ]
66 | },
67 | {
68 | "cell_type": "code",
69 | "execution_count": null,
70 | "metadata": {},
71 | "outputs": [],
72 | "source": [
73 | "### Plot a distribution of abundance\n",
74 | "sns.distplot(crabs['Abundance (psm)'])"
75 | ]
76 | },
77 | {
78 | "cell_type": "code",
79 | "execution_count": null,
80 | "metadata": {},
81 | "outputs": [],
82 | "source": [
83 | "### Plot annual data\n",
84 | "\n",
85 | "plt.bar(crabs.index,crabs['Abundance (psm)'])\n",
86 | "\n",
87 | "plt.xticks([*range(2000,2020,2)])\n",
88 | "\n",
89 | "plt.grid()\n",
90 | "\n",
91 | "plt.show()"
92 | ]
93 | },
94 | {
95 | "cell_type": "code",
96 | "execution_count": null,
97 | "metadata": {},
98 | "outputs": [],
99 | "source": [
100 | "### Read Sea Surface Data Available in zar\n",
101 | "\n",
102 | "file_location = 's3://mur-sst/zarr'\n",
103 | "\n",
104 | "ikey = fsspec.get_mapper(file_location, anon=True)\n",
105 | "\n",
106 | "ds_sst = xr.open_zarr(ikey,consolidated=True)\n",
107 | "\n",
108 | "#ds_sst"
109 | ]
110 | },
111 | {
112 | "cell_type": "code",
113 | "execution_count": null,
114 | "metadata": {},
115 | "outputs": [],
116 | "source": [
117 | "### Read data that matches crab data, in time and location\n",
118 | "\n",
119 | "sst_timeseries = ds_sst['analysed_sst'].sel(time = slice('2003-01-01','2016-12-31'),\n",
120 | " lat = 37.76,\n",
121 | " lon = -124.5\n",
122 | " ).load()\n",
123 | "\n",
124 | "### Plot and explore it\n",
125 | "sst_timeseries.plot()\n",
126 | "sst_timeseries"
127 | ]
128 | },
129 | {
130 | "cell_type": "code",
131 | "execution_count": null,
132 | "metadata": {},
133 | "outputs": [],
134 | "source": [
135 | "### Average data annually\n",
136 | "\n",
137 | "sst_annual = sst_timeseries.groupby('time.year').mean('time',keep_attrs=True)\n",
138 | "\n",
139 | "sst_annual.plot()"
140 | ]
141 | },
142 | {
143 | "cell_type": "markdown",
144 | "metadata": {},
145 | "source": [
146 | "### Add temperature data to the crab data frame\n",
147 | "\n",
148 | "crabs = crabs[crabs.index>=2003]\n",
149 | "\n",
150 | "tmp = pd.DataFrame(data=sst_annual.data - 273.15, columns={'SST'}, index=[*range(2003,2018)])\n",
151 | "\n",
152 | "crabs['SST'] = tmp\n",
153 | "\n",
154 | "### Take a look\n",
155 | "\n",
156 | "crabs"
157 | ]
158 | },
159 | {
160 | "cell_type": "markdown",
161 | "metadata": {},
162 | "source": [
163 | "### Scatter Plot\n",
164 | "\n",
165 | "plt.figure(figsize=(8,6))\n",
166 | "\n",
167 | "plt.plot(crabs['SST'],crabs['Abundance (psm)'],'*')\n",
168 | "\n",
169 | "### Correlation\n",
170 | "stats.pearsonr(crabs['SST'], crabs['Abundance (psm)']) "
171 | ]
172 | },
173 | {
174 | "cell_type": "markdown",
175 | "metadata": {},
176 | "source": [
177 | "### Time series plot\n",
178 | "\n",
179 | "plt.figure(figsize=(8,6))\n",
180 | "\n",
181 | "plt.plot(crabs['SST'],crabs['Abundance (psm)'],'*')\n",
182 | "\n",
183 | "fig, ax1 = plt.subplots()\n",
184 | "\n",
185 | "color = 'tab:red'\n",
186 | "\n",
187 | "ax1.set_ylabel('SST', color='tab:red')\n",
188 | "\n",
189 | "ax1.plot(crabs.index, crabs['SST'], color='tab:red')\n",
190 | "\n",
191 | "ax1.tick_params(axis='y', labelcolor='tab:red')\n",
192 | "\n",
193 | "ax2 = ax1.twinx() # instantiate a second axes that shares the same x-axis\n",
194 | "\n",
195 | "color = 'tab:blue'\n",
196 | "\n",
197 | "ax2.set_ylabel('sin', color=color) # we already handled the x-label with ax1\n",
198 | "\n",
199 | "ax2.plot(t, data2, color=color)\n",
200 | "\n",
201 | "ax2.tick_params(axis='y', labelcolor=color)\n",
202 | "\n",
203 | "fig.tight_layout() \n"
204 | ]
205 | },
206 | {
207 | "cell_type": "code",
208 | "execution_count": null,
209 | "metadata": {},
210 | "outputs": [],
211 | "source": []
212 | }
213 | ],
214 | "metadata": {
215 | "kernelspec": {
216 | "display_name": "Python [conda env:farallon-fall-2020]",
217 | "language": "python",
218 | "name": "conda-env-farallon-fall-2020-py"
219 | },
220 | "language_info": {
221 | "codemirror_mode": {
222 | "name": "ipython",
223 | "version": 3
224 | },
225 | "file_extension": ".py",
226 | "mimetype": "text/x-python",
227 | "name": "python",
228 | "nbconvert_exporter": "python",
229 | "pygments_lexer": "ipython3",
230 | "version": "3.8.5"
231 | }
232 | },
233 | "nbformat": 4,
234 | "nbformat_minor": 4
235 | }
236 |
--------------------------------------------------------------------------------
/notebooks/CalAcademy/Data_Explorer_2.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Explore Data 2"
8 | ]
9 | },
10 | {
11 | "cell_type": "code",
12 | "execution_count": null,
13 | "metadata": {},
14 | "outputs": [],
15 | "source": [
16 | "# Modules\n",
17 | "import warnings\n",
18 | "warnings.simplefilter('ignore') # filter some warning messages\n",
19 | "\n",
20 | "import numpy as np\n",
21 | "import pandas as pd\n",
22 | "import matplotlib.pyplot as plt\n",
23 | "import xarray as xr\n",
24 | "import seaborn as sns\n",
25 | "import datetime as dt\n",
26 | "import fsspec\n",
27 | "import s3fs\n",
28 | "import scipy.stats as stats\n",
29 | "# make datasets display nicely\n",
30 | "xr.set_options(display_style=\"html\") \n",
31 | "\n",
32 | "#magic fncts #put static images of your plot embedded in the notebook\n",
33 | "%matplotlib inline \n",
34 | "plt.rcParams['figure.figsize'] = 12, 6\n",
35 | "%config InlineBackend.figure_format = 'retina' "
36 | ]
37 | },
38 | {
39 | "cell_type": "markdown",
40 | "metadata": {},
41 | "source": [
42 | "# Mole Crab Data"
43 | ]
44 | },
45 | {
46 | "cell_type": "code",
47 | "execution_count": null,
48 | "metadata": {},
49 | "outputs": [],
50 | "source": [
51 | "### Read and look at mole crab data\n",
52 | "crabs = pd.read_csv('./Annual_UpwellingAprJul_OceanBeach.csv',index_col=0)\n",
53 | "crabs.head()"
54 | ]
55 | },
56 | {
57 | "cell_type": "markdown",
58 | "metadata": {},
59 | "source": [
60 | "# SST Data"
61 | ]
62 | },
63 | {
64 | "cell_type": "code",
65 | "execution_count": null,
66 | "metadata": {},
67 | "outputs": [],
68 | "source": [
69 | "### Read Sea Surface Data Available in zar\n",
70 | "\n",
71 | "file_location = 's3://mur-sst/zarr'\n",
72 | "\n",
73 | "ikey = fsspec.get_mapper(file_location, anon=True)\n",
74 | "\n",
75 | "ds_sst = xr.open_zarr(ikey,consolidated=True)\n",
76 | "\n",
77 | "#ds_sst"
78 | ]
79 | },
80 | {
81 | "cell_type": "code",
82 | "execution_count": null,
83 | "metadata": {},
84 | "outputs": [],
85 | "source": [
86 | "### Read data that matches crab data, in time and location\n",
87 | "\n",
88 | "sst_timeseries = ds_sst['analysed_sst'].sel(time = slice('2003-01-01','2016-12-31'),\n",
89 | " lat = slice(37.7,37.8), #37.76\n",
90 | " lon = slice(-122.55,-122.45) #-124.5\n",
91 | " ).load()\n",
92 | "\n",
93 | "# average over lat and lon\n",
94 | "sst_timeseries = sst_timeseries.where(sst_timeseries>273.15)\n",
95 | "sst_timeseries = sst_timeseries.mean(dim={'lat','lon'},keep_attrs=True,skipna=True)\n",
96 | "\n",
97 | "### Plot and explore it\n",
98 | "sst_timeseries.plot()\n",
99 | "sst_timeseries"
100 | ]
101 | },
102 | {
103 | "cell_type": "markdown",
104 | "metadata": {},
105 | "source": [
106 | "# Making one Pandas DataFrame with all the Data\n",
107 | "## Averaged SST for each year's upwelling season"
108 | ]
109 | },
110 | {
111 | "cell_type": "code",
112 | "execution_count": null,
113 | "metadata": {},
114 | "outputs": [],
115 | "source": [
116 | "crabs['SST']=np.nan\n",
117 | "for i in range(2003,2017):\n",
118 | " tmp = sst_timeseries.sel(time = slice(str(i)+'-04-01',str(i)+'-07-31')).mean()\n",
119 | " #print(tmp.values)\n",
120 | " a=crabs[crabs['Year']==i].index\n",
121 | " crabs.at[a[0],'SST']=tmp.data-273.15\n",
122 | "crabs"
123 | ]
124 | },
125 | {
126 | "cell_type": "markdown",
127 | "metadata": {},
128 | "source": [
129 | "# Plot data"
130 | ]
131 | },
132 | {
133 | "cell_type": "markdown",
134 | "metadata": {},
135 | "source": [
136 | "## Time series plot"
137 | ]
138 | },
139 | {
140 | "cell_type": "code",
141 | "execution_count": null,
142 | "metadata": {},
143 | "outputs": [],
144 | "source": [
145 | "plt.figure(figsize=(8,6))\n",
146 | "plt.plot(crabs['Year'],crabs['Female'],'*-',label='Female')\n",
147 | "plt.plot(crabs['Year'],crabs['Female w Eggs'],'d-',label='Female w Eggs')\n",
148 | "plt.plot(crabs['Year'],crabs['Male'],'d-',label='Male')\n",
149 | "plt.legend()\n",
150 | "plt.ylabel('No. Crabs')\n",
151 | "plt.grid()\n",
152 | "plt.show()"
153 | ]
154 | },
155 | {
156 | "cell_type": "markdown",
157 | "metadata": {},
158 | "source": [
159 | "## Plot of two variables in differnt axis: SST + some Crab data"
160 | ]
161 | },
162 | {
163 | "cell_type": "code",
164 | "execution_count": null,
165 | "metadata": {},
166 | "outputs": [],
167 | "source": [
168 | "var='Male'\n",
169 | "fig, ax1 = plt.subplots()\n",
170 | "\n",
171 | "color = 'tab:red'\n",
172 | "ax1.set_ylabel('SST', color=color)\n",
173 | "ax1.plot(crabs.Year, crabs['SST'], '.-',color=color)\n",
174 | "ax1.tick_params(axis='y', labelcolor=color)\n",
175 | "\n",
176 | "ax2 = ax1.twinx() # instantiate a second axes that shares the same x-axis\n",
177 | "color = 'tab:blue'\n",
178 | "ax2.set_ylabel(var+' Crabs', color=color) # we already handled the x-label with ax1\n",
179 | "ax2.plot(crabs.Year, crabs[var], '*-',color=color)\n",
180 | "ax2.tick_params(axis='y', labelcolor=color)\n",
181 | "\n",
182 | "fig.tight_layout() "
183 | ]
184 | },
185 | {
186 | "cell_type": "markdown",
187 | "metadata": {},
188 | "source": [
189 | "## Scatter plot"
190 | ]
191 | },
192 | {
193 | "cell_type": "code",
194 | "execution_count": null,
195 | "metadata": {},
196 | "outputs": [],
197 | "source": [
198 | "var='Female w Eggs'\n",
199 | "plt.figure(figsize=(8,6))\n",
200 | "plt.scatter(crabs['SST'],crabs[var],40, c=crabs['Year'],label='Female',cmap='jet')\n",
201 | "plt.colorbar()\n",
202 | "plt.legend()\n",
203 | "plt.ylabel('No. Crabs')\n",
204 | "plt.xlabel('SST')\n",
205 | "plt.grid()\n",
206 | "plt.show()"
207 | ]
208 | },
209 | {
210 | "cell_type": "markdown",
211 | "metadata": {},
212 | "source": [
213 | "## Correlation between SST and crab data"
214 | ]
215 | },
216 | {
217 | "cell_type": "code",
218 | "execution_count": null,
219 | "metadata": {},
220 | "outputs": [],
221 | "source": [
222 | "print('SST-variable correlation\\n(Correlation, p-value) \\n (<0.05 is good!)\\n')\n",
223 | "for i in list(crabs)[1:-1]:\n",
224 | " tmp=crabs[(~np.isnan(crabs['SST']))&(~np.isnan(crabs[i]))]\n",
225 | " print(i)\n",
226 | " print(stats.pearsonr(tmp['SST'], tmp[i]))\n",
227 | "\n",
228 | "print('\\n')\n",
229 | "for i in list(crabs)[1:-1]:\n",
230 | " tmp=crabs[(~np.isnan(crabs['SST']))&(~np.isnan(crabs[i]))&(crabs['Year']!=2015)]\n",
231 | " print(i)\n",
232 | " print(stats.pearsonr(tmp['SST'], tmp[i]))\n",
233 | " \n",
234 | "print('\\n')\n",
235 | "for i in list(crabs)[1:-1]:\n",
236 | " tmp=crabs[(~np.isnan(crabs['SST']))&(~np.isnan(crabs[i]))&(crabs['Year']<2015)]\n",
237 | " print(i)\n",
238 | " print(stats.pearsonr(tmp['SST'], tmp[i]))"
239 | ]
240 | },
241 | {
242 | "cell_type": "markdown",
243 | "metadata": {},
244 | "source": [
245 | "# Linear regression"
246 | ]
247 | },
248 | {
249 | "cell_type": "code",
250 | "execution_count": null,
251 | "metadata": {},
252 | "outputs": [],
253 | "source": [
254 | "# linear regressions\n",
255 | "for i in list(crabs)[1:-1]:\n",
256 | " tmp=crabs[(~np.isnan(crabs['SST']))&(~np.isnan(crabs[i]))]\n",
257 | " print(i)\n",
258 | " slope, intercept, r_value, p_value, std_err = stats.linregress(tmp['SST'], tmp[i])\n",
259 | " print(slope,p_value)"
260 | ]
261 | },
262 | {
263 | "cell_type": "code",
264 | "execution_count": null,
265 | "metadata": {},
266 | "outputs": [],
267 | "source": []
268 | }
269 | ],
270 | "metadata": {
271 | "kernelspec": {
272 | "display_name": "Python [conda env:farallon-fall-2020]",
273 | "language": "python",
274 | "name": "conda-env-farallon-fall-2020-py"
275 | },
276 | "language_info": {
277 | "codemirror_mode": {
278 | "name": "ipython",
279 | "version": 3
280 | },
281 | "file_extension": ".py",
282 | "mimetype": "text/x-python",
283 | "name": "python",
284 | "nbconvert_exporter": "python",
285 | "pygments_lexer": "ipython3",
286 | "version": "3.8.5"
287 | }
288 | },
289 | "nbformat": 4,
290 | "nbformat_minor": 4
291 | }
292 |
--------------------------------------------------------------------------------
/notebooks/CalAcademy/MoleCrab_abundance_annual.csv:
--------------------------------------------------------------------------------
1 | Datetime,Abundance (psm),Year
2 | 2001-12-31,824.1072727272726,2001
3 | 2002-12-31,2230.359032258065,2002
4 | 2003-12-31,4428.390526315789,2003
5 | 2004-12-31,1375.5459999999996,2004
6 | 2005-12-31,990.799175257732,2005
7 | 2006-12-31,302.85199999999986,2006
8 | 2007-12-31,273.982596153846,2007
9 | 2008-12-31,376.5033333333332,2008
10 | 2009-12-31,376.8432710280376,2009
11 | 2010-12-31,3390.017403846155,2010
12 | 2011-12-31,971.0576233183859,2011
13 | 2012-12-31,736.8730051813476,2012
14 | 2013-12-31,1786.5571074380184,2013
15 | 2014-12-31,2525.67012605042,2014
16 | 2015-12-31,2050.0515679442515,2015
17 | 2016-12-31,2490.8348148148157,2016
18 | 2017-12-31,700.6070909090911,2017
19 |
--------------------------------------------------------------------------------
/notebooks/CalAcademy/MoleCrab_abundance_apr-jul.csv:
--------------------------------------------------------------------------------
1 | ,Abundance (Apr-Jul)
2 | 2001,420.16
3 | 2002,1962.9042500000003
4 | 2003,7605.7515416666665
5 | 2004,1644.5328263888887
6 | 2005,1281.9881706349206
7 | 2006,335.73817857142853
8 | 2007,294.70155774853805
9 | 2008,496.8135277777777
10 | 2009,723.6689391025641
11 | 2010,8220.902826704547
12 | 2011,1024.6881321022727
13 | 2012,1014.9134259834368
14 | 2013,2778.8939601500647
15 | 2014,3528.0011081402263
16 | 2015,3410.5405666075394
17 | 2016,4866.272857142857
18 | 2017,729.1341369047618
19 |
--------------------------------------------------------------------------------
/notebooks/CalAcademy/ShortIntro_CalAcademy.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "
\n",
8 | "# Python for Oceanographers \n",
9 | "Chelle Gentemann (cgentemann@esr.org) \n",
10 | "\n",
11 | "Marisol García-Reyes (marisolgr@faralloninstitute.org)"
12 | ]
13 | },
14 | {
15 | "cell_type": "markdown",
16 | "metadata": {},
17 | "source": [
18 | "-----------"
19 | ]
20 | },
21 | {
22 | "cell_type": "markdown",
23 | "metadata": {},
24 | "source": [
25 | "
\n",
26 | "\n",
27 | "## `Python` is an awesome programming language\n",
28 | "- It is `Open Source`: it is free, everybody can use it, everybody can contribute to it\n",
29 | "- It is used by an enourmous community of developers\n",
30 | "- All the need you might need is online "
31 | ]
32 | },
33 | {
34 | "cell_type": "markdown",
35 | "metadata": {},
36 | "source": [
37 | "## `Python` can be install on your computer or you can run it online, in the Cloud\n",
38 | "\n",
39 | "\n",
40 | "### If you're running this from the `Binder`, you're already working in the cloud!!!"
41 | ]
42 | },
43 | {
44 | "cell_type": "markdown",
45 | "metadata": {},
46 | "source": [
47 | "--------------"
48 | ]
49 | },
50 | {
51 | "cell_type": "markdown",
52 | "metadata": {},
53 | "source": [
54 | "### `Jupyter` is a project for developing open-source software\n",
55 | "### `Jupyter Lab` is a web application (user interface) to create scripts"
56 | ]
57 | },
58 | {
59 | "cell_type": "markdown",
60 | "metadata": {},
61 | "source": [
62 | "\n",
63 | " We are going to make all our analysis online on a JupyterLab Notebook\n",
64 | "
"
65 | ]
66 | },
67 | {
68 | "cell_type": "markdown",
69 | "metadata": {},
70 | "source": [
71 | "
\n",
72 | "\n",
73 | "# `JupyterLab` basics\n",
74 | "## Add cell: `+` on the menu above\n",
75 | "\n",
76 | "## Two type of cells, change in the menu above\n",
77 | "### `Code` Cells: execute code\n",
78 | "### `Markdown` Cells: show formated text\n",
79 | "\n",
80 | "## To execute cells\n",
81 | "### - `Shift-Enter` : executes cell & advance to next\n",
82 | "### - `Control-enter` : executes cell & stay in the same cell"
83 | ]
84 | },
85 | {
86 | "cell_type": "markdown",
87 | "metadata": {},
88 | "source": [
89 | "----------"
90 | ]
91 | },
92 | {
93 | "cell_type": "markdown",
94 | "metadata": {},
95 | "source": [
96 | "# But first, some `Python` basics\n",
97 | "\n",
98 | "## Python is `Modular`: it has all the libraries you could possibly need; you do not need to install them all\n",
99 | "- Libraries are just a collection of programs or functions for a specific purpose. \n",
100 | "\n",
101 | "\n",
102 | " That means you have to start by 'loading' or 'importing' the libraries you need\n",
103 | "
"
104 | ]
105 | },
106 | {
107 | "cell_type": "code",
108 | "execution_count": null,
109 | "metadata": {},
110 | "outputs": [],
111 | "source": [
112 | "import numpy as np\n",
113 | "import pandas as pd\n",
114 | "from datetime import timedelta\n",
115 | "import xarray as xr"
116 | ]
117 | },
118 | {
119 | "cell_type": "markdown",
120 | "metadata": {},
121 | "source": [
122 | "----------"
123 | ]
124 | },
125 | {
126 | "cell_type": "markdown",
127 | "metadata": {},
128 | "source": [
129 | "## the `xarray` module is probably our favorite!"
130 | ]
131 | },
132 | {
133 | "cell_type": "markdown",
134 | "metadata": {},
135 | "source": [
136 | "
"
137 | ]
138 | },
139 | {
140 | "cell_type": "markdown",
141 | "metadata": {},
142 | "source": [
143 | "## Python is `Object Oriented`: each variable or object has attributes or functions particular to the type of object"
144 | ]
145 | },
146 | {
147 | "cell_type": "code",
148 | "execution_count": null,
149 | "metadata": {},
150 | "outputs": [],
151 | "source": [
152 | "myvar = 'hola mundo!'\n",
153 | "type(myvar)"
154 | ]
155 | },
156 | {
157 | "cell_type": "code",
158 | "execution_count": null,
159 | "metadata": {},
160 | "outputs": [],
161 | "source": [
162 | "myvar.upper()"
163 | ]
164 | },
165 | {
166 | "cell_type": "code",
167 | "execution_count": null,
168 | "metadata": {},
169 | "outputs": [],
170 | "source": [
171 | "myvar.upper()[:4]"
172 | ]
173 | },
174 | {
175 | "cell_type": "code",
176 | "execution_count": null,
177 | "metadata": {},
178 | "outputs": [],
179 | "source": [
180 | "myvar.upper().lower()"
181 | ]
182 | }
183 | ],
184 | "metadata": {
185 | "kernelspec": {
186 | "display_name": "Python 3",
187 | "language": "python",
188 | "name": "python3"
189 | },
190 | "language_info": {
191 | "codemirror_mode": {
192 | "name": "ipython",
193 | "version": 3
194 | },
195 | "file_extension": ".py",
196 | "mimetype": "text/x-python",
197 | "name": "python",
198 | "nbconvert_exporter": "python",
199 | "pygments_lexer": "ipython3",
200 | "version": "3.7.6"
201 | }
202 | },
203 | "nbformat": 4,
204 | "nbformat_minor": 4
205 | }
206 |
--------------------------------------------------------------------------------
/notebooks/CalAcademy/clean_summarize_crabdata.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": null,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "import warnings\n",
10 | "warnings.simplefilter('ignore') # filter some warning messages\n",
11 | "\n",
12 | "import numpy as np\n",
13 | "import pandas as pd\n",
14 | "import matplotlib.pyplot as plt"
15 | ]
16 | },
17 | {
18 | "cell_type": "code",
19 | "execution_count": null,
20 | "metadata": {},
21 | "outputs": [],
22 | "source": [
23 | "# read data file\n",
24 | "tmp = pd.read_excel('./sandcrab_data_2017-11-16.xlsx', sheet_name=4, usecols=[*range(11)])\n",
25 | "tmp['Year']= pd.DatetimeIndex(tmp.Date).year\n",
26 | "tmp['Month']= pd.DatetimeIndex(tmp.Date).month\n",
27 | "tmp.tail()"
28 | ]
29 | },
30 | {
31 | "cell_type": "code",
32 | "execution_count": null,
33 | "metadata": {},
34 | "outputs": [],
35 | "source": [
36 | "# calculate factor to get number of crabs per square meter\n",
37 | "# 'sample area' - core diameter = 15.2cm\n",
38 | "ar = np.pi*(0.152)**2 # in sm squared meters\n",
39 | "# to transform number of crabs per sample to crabs per square meters divide by ar"
40 | ]
41 | },
42 | {
43 | "cell_type": "code",
44 | "execution_count": null,
45 | "metadata": {},
46 | "outputs": [],
47 | "source": [
48 | "# per year, per upwelling season (april-july)\n",
49 | "# calculate the total, and averaged (pm2)\n",
50 | "iy = 2002\n",
51 | "fy = 2016 # technically september\n",
52 | "df = pd.DataFrame(columns={'Year','Month','Total Crabs','Male','Female','Female w Eggs', 'Recruits'})\n",
53 | "ix = 0\n",
54 | "for i in range(iy,fy+1):\n",
55 | " # select site and year\n",
56 | " tmpi = tmp[(tmp.Year==i)&(tmp.Site=='Ocean Beach')]\n",
57 | " #print(i)\n",
58 | " # select month\n",
59 | " for j in range(4,8): # upwelling season only\n",
60 | " tmpm = tmpi[tmp.Month==j]\n",
61 | " #print(j)\n",
62 | " # only year, month, total, male, fem, femweggs\n",
63 | " df.at[ix,'Year'] =i\n",
64 | " df.at[ix,'Month']=j\n",
65 | " df.at[ix,'Total Crabs'] = np.round(np.nanmean(tmpm['Total Crabs'])/ar,1)\n",
66 | " df.at[ix,'Male']=np.round(np.nanmean(tmpm['#Male'])/ar,1)\n",
67 | " df.at[ix,'Female']=np.round(np.nanmean(tmpm['#Female'])/ar,1)\n",
68 | " df.at[ix,'Female w Eggs']= np.round(np.nanmean(tmpm['#Female w/t Eggs'])/ar,1)\n",
69 | " df.at[ix,'Recruits']= np.round(np.nanmean(tmpm['#Recruits'])/ar,1)\n",
70 | " ix += 1\n",
71 | "df = df[['Year','Month','Total Crabs','Male','Female','Female w Eggs','Recruits']]\n",
72 | "df.head()"
73 | ]
74 | },
75 | {
76 | "cell_type": "code",
77 | "execution_count": null,
78 | "metadata": {},
79 | "outputs": [],
80 | "source": [
81 | "# Annual averages (upwelling season)\n",
82 | "ix = 0\n",
83 | "dfan = pd.DataFrame(columns={'Year','Total Crabs','Male','Female','Female w Eggs', 'Recruits'})\n",
84 | "\n",
85 | "for i in range(iy,fy+1):\n",
86 | " # print(i)\n",
87 | " tmp=df[df.Year==i]\n",
88 | " dfan.at[ix,'Year']=i\n",
89 | " dfan.at[ix,'Total Crabs']=np.nanmean(tmp['Total Crabs'])\n",
90 | " dfan.at[ix,'Male']=np.nanmean(tmp['Male'])\n",
91 | " dfan.at[ix,'Female']=np.nanmean(tmp['Female'])\n",
92 | " dfan.at[ix,'Female w Eggs']=np.nanmean(tmp['Female w Eggs'])\n",
93 | " dfan.at[ix,'Recruits']=np.nanmean(tmp['Recruits'])\n",
94 | " ix +=1\n",
95 | "dfan=dfan[['Year','Total Crabs','Male','Female','Female w Eggs', 'Recruits']]\n",
96 | "dfan.to_csv('./Annual_UpwellingAprJul_OceanBean.csv')\n",
97 | "dfan\n",
98 | "#plt.bar(range(iy,fy+1),anab)\n",
99 | "#plt.grid()\n",
100 | "\n"
101 | ]
102 | },
103 | {
104 | "cell_type": "code",
105 | "execution_count": null,
106 | "metadata": {},
107 | "outputs": [],
108 | "source": [
109 | "plt.figure(figsize=(8,5))\n",
110 | "plt.plot(dfan.Year,dfan['Total Crabs'],'*-',label='Total')\n",
111 | "plt.plot(dfan.Year,dfan['Recruits'],'d-',label='Recruits')\n",
112 | "plt.legend()\n",
113 | "plt.grid()\n",
114 | "plt.show()\n",
115 | "\n",
116 | "plt.figure(figsize=(8,5))\n",
117 | "plt.plot(dfan.Year,dfan['Male'],'*-',label='Male')\n",
118 | "plt.plot(dfan.Year,dfan['Female'],'d-',label='Female')\n",
119 | "plt.plot(dfan.Year,dfan['Female w Eggs'],'o-',label='Female w Eggs')\n",
120 | "#plt.plot(dfan.Year,dfan['Recruits'],'s-',label='Recruits')\n",
121 | "plt.legend()\n",
122 | "plt.grid()\n",
123 | "plt.show()"
124 | ]
125 | },
126 | {
127 | "cell_type": "code",
128 | "execution_count": null,
129 | "metadata": {},
130 | "outputs": [],
131 | "source": []
132 | }
133 | ],
134 | "metadata": {
135 | "kernelspec": {
136 | "display_name": "Python [conda env:farallon-fall-2020]",
137 | "language": "python",
138 | "name": "conda-env-farallon-fall-2020-py"
139 | },
140 | "language_info": {
141 | "codemirror_mode": {
142 | "name": "ipython",
143 | "version": 3
144 | },
145 | "file_extension": ".py",
146 | "mimetype": "text/x-python",
147 | "name": "python",
148 | "nbconvert_exporter": "python",
149 | "pygments_lexer": "ipython3",
150 | "version": "3.8.5"
151 | }
152 | },
153 | "nbformat": 4,
154 | "nbformat_minor": 4
155 | }
156 |
--------------------------------------------------------------------------------
/notebooks/CalAcademy/sandcrab_data_2017-11-16.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/notebooks/CalAcademy/sandcrab_data_2017-11-16.xlsx
--------------------------------------------------------------------------------
/notebooks/Intro cloud computing.gslides:
--------------------------------------------------------------------------------
1 | {"url": "https://docs.google.com/open?id=1pyuT0gLsDDEdTly0n6NS8UP0ERVQgtIrDMpqfOX5VfU", "doc_id": "1pyuT0gLsDDEdTly0n6NS8UP0ERVQgtIrDMpqfOX5VfU", "email": "cgentemann@gmail.com"}
--------------------------------------------------------------------------------
/notebooks/LinkstoResources.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/notebooks/LinkstoResources.md
--------------------------------------------------------------------------------
/notebooks/Tutorial_03_BasicCommands.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "slideshow": {
7 | "slide_type": "slide"
8 | }
9 | },
10 | "source": [
11 | "# Basic `Python`\n",
12 | "We are going to learn the most basic commands of Python. The objective is not to teach you how to program to become an expert, but to learn the syntaxis of the language & recongnize it through the next notebooks\n"
13 | ]
14 | },
15 | {
16 | "cell_type": "markdown",
17 | "metadata": {
18 | "slideshow": {
19 | "slide_type": "slide"
20 | }
21 | },
22 | "source": [
23 | "## Basic operations \n",
24 | "### +, -, \\*, /, **\n",
25 | "\n",
26 | "\n",
27 | " Try it out!\n",
28 | "
\n",
29 | " - Define two integer variables & print the result of basic operations\n",
30 | "
"
31 | ]
32 | },
33 | {
34 | "cell_type": "code",
35 | "execution_count": null,
36 | "metadata": {
37 | "scrolled": true,
38 | "slideshow": {
39 | "slide_type": "fragment"
40 | }
41 | },
42 | "outputs": [],
43 | "source": []
44 | },
45 | {
46 | "cell_type": "markdown",
47 | "metadata": {},
48 | "source": [
49 | "### Operations over the same variables can be simplified by adding the operand before the `=`, like this:\n",
50 | "x += 1"
51 | ]
52 | },
53 | {
54 | "cell_type": "markdown",
55 | "metadata": {},
56 | "source": [
57 | "\n",
58 | " Try it out!\n",
59 | "
- Execute the code in the cell below & print x & y final values\n",
60 | "
"
61 | ]
62 | },
63 | {
64 | "cell_type": "code",
65 | "execution_count": null,
66 | "metadata": {},
67 | "outputs": [],
68 | "source": [
69 | "x, y = 3, 4\n",
70 | "print(x,y)\n",
71 | "x += 1\n",
72 | "y /= 2"
73 | ]
74 | },
75 | {
76 | "cell_type": "markdown",
77 | "metadata": {},
78 | "source": [
79 | "***"
80 | ]
81 | },
82 | {
83 | "cell_type": "markdown",
84 | "metadata": {
85 | "slideshow": {
86 | "slide_type": "slide"
87 | }
88 | },
89 | "source": [
90 | "## `for` loops\n",
91 | "Can iterate on any list. \n",
92 | "
\n",
93 | "#### Note the indentation in the line after the `for` command. This position indicates which lines belong to the `for` loop.\n",
94 | "The print statement is no longer being looped on because it has no indent.\n",
95 | "\n",
96 | " Try it out!\n",
97 | "
Execute the code below \n",
98 | "
"
99 | ]
100 | },
101 | {
102 | "cell_type": "code",
103 | "execution_count": null,
104 | "metadata": {
105 | "slideshow": {
106 | "slide_type": "fragment"
107 | }
108 | },
109 | "outputs": [],
110 | "source": [
111 | "somelist = [10,15,25, '10ppm','5m/s']\n",
112 | "for item in somelist:\n",
113 | " print(item)\n",
114 | "print(somelist)"
115 | ]
116 | },
117 | {
118 | "cell_type": "markdown",
119 | "metadata": {
120 | "slideshow": {
121 | "slide_type": "fragment"
122 | }
123 | },
124 | "source": [
125 | "### A list can also be just of numbers, and we can build a list using the function `range`:\n",
126 | "#### range(start, end, step) \n",
127 | "
Note: the end is non-inclusive\n",
128 | "\n",
129 | "\n",
130 | " Try it out!\n",
131 | "
- Execute the code below\n",
132 | "
\n",
133 | " - Replace somelist in the for loop with: range(0,41,5), and execute the code again\n",
134 | "
\n",
135 | " - Change the start, end or step and execute the code again\n",
136 | "
\n",
163 | " Try it out!\n",
164 | "
- Try range(10) instead"
165 | ]
166 | },
167 | {
168 | "cell_type": "code",
169 | "execution_count": null,
170 | "metadata": {},
171 | "outputs": [],
172 | "source": [
173 | "somelist = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i','j']\n",
174 | "for inx in range(10):\n",
175 | " print(inx)\n",
176 | "print('********\\n')\n",
177 | "\n",
178 | "for inx in range(10):\n",
179 | " print(somelist[inx])\n",
180 | "print('********\\n')\n",
181 | "\n",
182 | "for inx in range(0,10,2):\n",
183 | " print(somelist[inx])"
184 | ]
185 | },
186 | {
187 | "cell_type": "markdown",
188 | "metadata": {
189 | "slideshow": {
190 | "slide_type": "slide"
191 | }
192 | },
193 | "source": [
194 | "## Sometimes we want the index and the value of each element on a list\n",
195 | "### The command `enumerate` gives you both\n",
196 | "\n",
197 | " Try it out!\n",
198 | "
\n",
199 | " - Execute the code below\n",
200 | "
\n",
201 | " - Then try with range(10) instead\n",
202 | "
\n",
203 | "
Note the use of { } and .format to print inx and item"
204 | ]
205 | },
206 | {
207 | "cell_type": "code",
208 | "execution_count": null,
209 | "metadata": {
210 | "slideshow": {
211 | "slide_type": "fragment"
212 | }
213 | },
214 | "outputs": [],
215 | "source": [
216 | "for inx,item in enumerate(range(0,41,a5)):\n",
217 | " print('index {}, value = {}'.format(inx,item))"
218 | ]
219 | },
220 | {
221 | "cell_type": "markdown",
222 | "metadata": {
223 | "slideshow": {
224 | "slide_type": "slide"
225 | }
226 | },
227 | "source": [
228 | "***\n",
229 | "# conditionals: `if`, `elif`, `else` \n",
230 | "### Conditional operators can be used to compare different types of variables or to test logical statements. \n",
231 | "\n",
232 | "- The basic operator to compare numerical values are: ==, !=, <, >, >=, <=\n",
233 | "- The logical operators are: and, or, not\n",
234 | "- and the use of conditional operators are exemplified in the next cell\n",
235 | "\n",
236 | "#### Note the indentation again\n",
237 | "\n",
238 | " Try it out!\n",
239 | "
\n",
240 | "- Execute the next cell\n",
241 | "
\n",
242 | "- Test different comparison operators and logical operators and execute\n",
243 | "
"
244 | ]
245 | },
246 | {
247 | "cell_type": "code",
248 | "execution_count": null,
249 | "metadata": {},
250 | "outputs": [],
251 | "source": [
252 | "lat = 12\n",
253 | "if (lat <= -23.5) or (lat >= 23.5):\n",
254 | " print('extra-tropical')\n",
255 | "elif lat == 0:\n",
256 | " print('equator')\n",
257 | "else:\n",
258 | " print('tropical')"
259 | ]
260 | }
261 | ],
262 | "metadata": {
263 | "kernelspec": {
264 | "display_name": "Python 3",
265 | "language": "python",
266 | "name": "python3"
267 | },
268 | "language_info": {
269 | "codemirror_mode": {
270 | "name": "ipython",
271 | "version": 3
272 | },
273 | "file_extension": ".py",
274 | "mimetype": "text/x-python",
275 | "name": "python",
276 | "nbconvert_exporter": "python",
277 | "pygments_lexer": "ipython3",
278 | "version": "3.7.6"
279 | }
280 | },
281 | "nbformat": 4,
282 | "nbformat_minor": 4
283 | }
284 |
--------------------------------------------------------------------------------
/notebooks/Tutorial_07_Xarray_Plotting_with_cartopy.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Plotting with [cartopy](https://scitools.org.uk/cartopy/docs/latest/)\n",
8 | "\n",
9 | "From Cartopy website:\n",
10 | "\n",
11 | "* Cartopy is a Python package designed for geospatial data processing in order to produce maps and other geospatial data analyses.\n",
12 | "\n",
13 | "* Cartopy makes use of the powerful PROJ.4, NumPy and Shapely libraries and includes a programmatic interface built on top of Matplotlib for the creation of publication quality maps.\n",
14 | "\n",
15 | "* Key features of cartopy are its object oriented projection definitions, and its ability to transform points, lines, vectors, polygons and images between those projections.\n",
16 | "\n",
17 | "* You will find cartopy especially useful for large area / small scale data, where Cartesian assumptions of spherical data traditionally break down. If you’ve ever experienced a singularity at the pole or a cut-off at the dateline, it is likely you will appreciate cartopy’s unique features!\n"
18 | ]
19 | },
20 | {
21 | "cell_type": "code",
22 | "execution_count": null,
23 | "metadata": {},
24 | "outputs": [],
25 | "source": [
26 | "import numpy as np\n",
27 | "import matplotlib.pyplot as plt\n",
28 | "import xarray as xr\n",
29 | "import cartopy.crs as ccrs"
30 | ]
31 | },
32 | {
33 | "cell_type": "markdown",
34 | "metadata": {},
35 | "source": [
36 | "# Read in data using xarray\n",
37 | "- Read in the Saildrone USV file either from a local disc `xr.open_dataset(file)`\n",
38 | "- change latitude and longitude to lat and lon `.rename({'longitude':'lon','latitude':'lat'})`\n"
39 | ]
40 | },
41 | {
42 | "cell_type": "code",
43 | "execution_count": null,
44 | "metadata": {},
45 | "outputs": [],
46 | "source": [
47 | "file = '../data/saildrone-gen_5-antarctica_circumnavigation_2019-sd1020-20190119T040000-20190803T043000-1440_minutes-v1.1564857794963.nc'\n",
48 | "\n",
49 | "ds_usv = \n"
50 | ]
51 | },
52 | {
53 | "cell_type": "markdown",
54 | "metadata": {},
55 | "source": [
56 | "# Open the dataset, mask land, plot result\n",
57 | "* `ds_sst = xr.open_dataset(url)`\n",
58 | "* use `ds_sst = ds_sst.where(ds_sst.mask==1)` to mask values equal to 1"
59 | ]
60 | },
61 | {
62 | "cell_type": "code",
63 | "execution_count": null,
64 | "metadata": {},
65 | "outputs": [],
66 | "source": [
67 | "#If you are offline use the first url\n",
68 | "#url = '../data/20111101120000-CMC-L4_GHRSST-SSTfnd-CMC0.2deg-GLOB-v02.0-fv02.0.nc'\n",
69 | "url = 'https://podaac-opendap.jpl.nasa.gov/opendap/allData/ghrsst/data/GDS2/L4/GLOB/CMC/CMC0.2deg/v2/2011/305/20111101120000-CMC-L4_GHRSST-SSTfnd-CMC0.2deg-GLOB-v02.0-fv02.0.nc'\n",
70 | "\n",
71 | "\n"
72 | ]
73 | },
74 | {
75 | "cell_type": "markdown",
76 | "metadata": {},
77 | "source": [
78 | "\n",
79 | "## explore the in situ data and quickly plot using cartopy\n",
80 | "\n",
81 | "* first set up the axis with the projection you want: https://scitools.org.uk/cartopy/docs/latest/crs/projections.html\n",
82 | "* plot to that axis and tell the projection that your data is in\n",
83 | "\n",
84 | "#### Run the cell below and see what the image looks like. Then try adding in the lines below, one at a time, and re-run cell to see what happens\n",
85 | "\n",
86 | "* set a background image `ax.stock_img()`\n",
87 | "* draw coastlines `ax.coastlines(resolution='50m')`\n",
88 | "* add a colorbary and label it `cax = plt.colorbar(cs1)` `cax.set_label('SST (K)')`"
89 | ]
90 | },
91 | {
92 | "cell_type": "code",
93 | "execution_count": null,
94 | "metadata": {
95 | "scrolled": true
96 | },
97 | "outputs": [],
98 | "source": [
99 | "#for polar data, plot temperature\n",
100 | "\n",
101 | "datamin = 0\n",
102 | "datamax = 12\n",
103 | "\n",
104 | "ax = plt.axes(projection=ccrs.SouthPolarStereo()) #here is where you set your axis projection\n",
105 | "\n",
106 | "(ds_sst.analysed_sst-273.15).plot(ax=ax, \n",
107 | " transform=ccrs.PlateCarree(), #set data projection\n",
108 | " vmin=datamin, #data min\n",
109 | " vmax=datamax) #data min\n",
110 | "\n",
111 | "cs1 = ax.scatter(ds_usv.lon, ds_usv.lat, \n",
112 | " transform=ccrs.PlateCarree(), #set data projection\n",
113 | " s=10.0, #size for scatter point\n",
114 | " c=ds_usv.TEMP_CTD_MEAN, #make the color of the scatter point equal to the USV temperature\n",
115 | " edgecolor='none', #no edgecolor\n",
116 | " cmap='jet', #colormap\n",
117 | " vmin=datamin, #data min\n",
118 | " vmax=datamax) #data max\n",
119 | "\n",
120 | "ax.set_extent([-180, 180, -90, -45], crs=ccrs.PlateCarree()) #data projection\n"
121 | ]
122 | },
123 | {
124 | "cell_type": "markdown",
125 | "metadata": {},
126 | "source": [
127 | "# Plot the salinity\n",
128 | "* Take the code from above but use `c=ds_usv.SAL_MEAN`\n",
129 | "* Run the code, what looks wrong?\n",
130 | "* Change `datamin` and `datamax`\n"
131 | ]
132 | },
133 | {
134 | "cell_type": "code",
135 | "execution_count": null,
136 | "metadata": {},
137 | "outputs": [],
138 | "source": [
139 | "\n"
140 | ]
141 | },
142 | {
143 | "cell_type": "markdown",
144 | "metadata": {},
145 | "source": [
146 | "# Let's plot some data off California\n",
147 | "* Read in data from a cruise along the California / Baja Coast\n",
148 | "* `ds_usv = xr.open_dataset(url).rename({'longitude':'lon','latitude':'lat'})`"
149 | ]
150 | },
151 | {
152 | "cell_type": "code",
153 | "execution_count": null,
154 | "metadata": {},
155 | "outputs": [],
156 | "source": [
157 | "#use the first URL if you are offline\n",
158 | "#url = '../data/saildrone-gen_4-baja_2018-sd1002-20180411T180000-20180611T055959-1_minutes-v1.nc'\n",
159 | "url = 'https://podaac-opendap.jpl.nasa.gov/opendap/hyrax/allData/insitu/L2/saildrone/Baja/saildrone-gen_4-baja_2018-sd1002-20180411T180000-20180611T055959-1_minutes-v1.nc'\n"
160 | ]
161 | },
162 | {
163 | "cell_type": "markdown",
164 | "metadata": {},
165 | "source": [
166 | "* Plot the data using the code from above, but change the projection\n",
167 | "\n",
168 | "`ax = plt.axes(projection=ccrs.PlateCarree())`\n",
169 | "\n"
170 | ]
171 | },
172 | {
173 | "cell_type": "code",
174 | "execution_count": null,
175 | "metadata": {},
176 | "outputs": [],
177 | "source": [
178 | "\n"
179 | ]
180 | },
181 | {
182 | "cell_type": "markdown",
183 | "metadata": {},
184 | "source": [
185 | "* Zoom into the region of the cruise \n",
186 | "* First calculate the lat/lon box
\n",
187 | "`lonmin,lonmax = ds_usv.lon.min().data-2,ds_usv.lon.max().data+2`
\n",
188 | "`latmin,latmax = ds_usv.lat.min().data-2,ds_usv.lat.max().data+2`\n",
189 | "\n",
190 | "* Then, after plotting the data, change the extent\n",
191 | "\n",
192 | "`ax.set_extent([lonmin,lonmax,latmin,latmax], crs=ccrs.PlateCarree())`\n"
193 | ]
194 | },
195 | {
196 | "cell_type": "code",
197 | "execution_count": null,
198 | "metadata": {},
199 | "outputs": [],
200 | "source": []
201 | }
202 | ],
203 | "metadata": {
204 | "kernelspec": {
205 | "display_name": "Python 3",
206 | "language": "python",
207 | "name": "python3"
208 | },
209 | "language_info": {
210 | "codemirror_mode": {
211 | "name": "ipython",
212 | "version": 3
213 | },
214 | "file_extension": ".py",
215 | "mimetype": "text/x-python",
216 | "name": "python",
217 | "nbconvert_exporter": "python",
218 | "pygments_lexer": "ipython3",
219 | "version": "3.7.6"
220 | }
221 | },
222 | "nbformat": 4,
223 | "nbformat_minor": 4
224 | }
225 |
--------------------------------------------------------------------------------
/notebooks/answers/.ipynb_checkpoints/Intro_03_BasicCommands-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "slideshow": {
7 | "slide_type": "slide"
8 | }
9 | },
10 | "source": [
11 | "# Basic `Python`\n",
12 | "We are going to learn the most basic commands of Python. The objective is not to teach you how to program to become an expert, but to learn the syntaxis of the language & recongnize it through the next notebooks\n",
13 | "
\n",
14 | "At the end of this notebook you can find some links to more comprehensible tutorials & references"
15 | ]
16 | },
17 | {
18 | "cell_type": "markdown",
19 | "metadata": {
20 | "slideshow": {
21 | "slide_type": "slide"
22 | }
23 | },
24 | "source": [
25 | "## Basic operations \n",
26 | "### +, -, \\*, /, **\n",
27 | "\n",
28 | " - Define two integer variables & print the result of basic operations\n",
29 | "
"
30 | ]
31 | },
32 | {
33 | "cell_type": "code",
34 | "execution_count": 2,
35 | "metadata": {
36 | "scrolled": true,
37 | "slideshow": {
38 | "slide_type": "fragment"
39 | }
40 | },
41 | "outputs": [
42 | {
43 | "name": "stdout",
44 | "output_type": "stream",
45 | "text": [
46 | "11.0\n"
47 | ]
48 | }
49 | ],
50 | "source": [
51 | "sst1 = 10\n",
52 | "sst2 = 12\n",
53 | "sstm = (10+12)/2\n",
54 | "print(sstm)"
55 | ]
56 | },
57 | {
58 | "cell_type": "markdown",
59 | "metadata": {},
60 | "source": [
61 | "### Operations over the same variables can be simplified by adding the operand before the `=`, like this:\n",
62 | "x += 1"
63 | ]
64 | },
65 | {
66 | "cell_type": "markdown",
67 | "metadata": {},
68 | "source": [
69 | "\n",
70 | " - Execute the code in the cell below & print x & y final values\n",
71 | "
"
72 | ]
73 | },
74 | {
75 | "cell_type": "code",
76 | "execution_count": 4,
77 | "metadata": {},
78 | "outputs": [
79 | {
80 | "name": "stdout",
81 | "output_type": "stream",
82 | "text": [
83 | "3 4\n",
84 | "4 2.0\n"
85 | ]
86 | }
87 | ],
88 | "source": [
89 | "x, y = 3, 4\n",
90 | "print(x,y)\n",
91 | "x += 1\n",
92 | "y /= 2\n",
93 | "print(x, y)"
94 | ]
95 | },
96 | {
97 | "cell_type": "markdown",
98 | "metadata": {
99 | "slideshow": {
100 | "slide_type": "slide"
101 | }
102 | },
103 | "source": [
104 | "*** \n",
105 | "## `for` loops\n",
106 | "Can iterate on any list. \n",
107 | "
\n",
108 | "#### Note the indentation in the line after the `for` command. This position indicates which lines belong to the `for` loop.\n",
109 | "The print statement is no longer being looped on because it has no indent.\n",
110 | "\n",
111 | " Execute the code below \n",
112 | "
"
113 | ]
114 | },
115 | {
116 | "cell_type": "code",
117 | "execution_count": 5,
118 | "metadata": {
119 | "slideshow": {
120 | "slide_type": "fragment"
121 | }
122 | },
123 | "outputs": [
124 | {
125 | "name": "stdout",
126 | "output_type": "stream",
127 | "text": [
128 | "10\n",
129 | "15\n",
130 | "25\n",
131 | "10ppm\n",
132 | "5m/s\n",
133 | "[10, 15, 25, '10ppm', '5m/s']\n"
134 | ]
135 | }
136 | ],
137 | "source": [
138 | "somelist = [10,15,25, '10ppm','5m/s']\n",
139 | "for item in somelist:\n",
140 | " print(item)\n",
141 | "print(somelist)"
142 | ]
143 | },
144 | {
145 | "cell_type": "markdown",
146 | "metadata": {
147 | "slideshow": {
148 | "slide_type": "fragment"
149 | }
150 | },
151 | "source": [
152 | "### A list can also be just of numbers, and we can build a list using the function `range`:\n",
153 | "#### range(start, end, step) \n",
154 | "
Note: the end is non-inclusive\n",
155 | "\n",
156 | "\n",
157 | " - Execute the code below\n",
158 | "
\n",
159 | " - Replace somelist in the for loop with: range(0,41,5), and execute the code again\n",
160 | "
\n",
161 | " - Change the start, end or step and execute the code again\n",
162 | "
\n",
234 | " - Try range(10) instead"
235 | ]
236 | },
237 | {
238 | "cell_type": "code",
239 | "execution_count": 9,
240 | "metadata": {},
241 | "outputs": [
242 | {
243 | "name": "stdout",
244 | "output_type": "stream",
245 | "text": [
246 | "0\n",
247 | "1\n",
248 | "2\n",
249 | "3\n",
250 | "4\n",
251 | "5\n",
252 | "6\n",
253 | "7\n",
254 | "8\n",
255 | "9\n"
256 | ]
257 | }
258 | ],
259 | "source": [
260 | "for item in range(10):\n",
261 | " print(item)"
262 | ]
263 | },
264 | {
265 | "cell_type": "markdown",
266 | "metadata": {
267 | "slideshow": {
268 | "slide_type": "slide"
269 | }
270 | },
271 | "source": [
272 | "## Sometimes we want the index and the value of each element on a list\n",
273 | "### The command `enumerate` gives you both\n",
274 | "\n",
275 | " - Execute the code below\n",
276 | "
\n",
277 | " - Then try with range(10) instead\n",
278 | "
\n",
279 | "
Note the use of { } and .format to print inx and item"
280 | ]
281 | },
282 | {
283 | "cell_type": "code",
284 | "execution_count": 11,
285 | "metadata": {
286 | "slideshow": {
287 | "slide_type": "fragment"
288 | }
289 | },
290 | "outputs": [
291 | {
292 | "name": "stdout",
293 | "output_type": "stream",
294 | "text": [
295 | "index 0, value = 0\n",
296 | "index 1, value = 5\n",
297 | "index 2, value = 10\n",
298 | "index 3, value = 15\n",
299 | "index 4, value = 20\n",
300 | "index 5, value = 25\n",
301 | "index 6, value = 30\n",
302 | "index 7, value = 35\n",
303 | "index 8, value = 40\n",
304 | "\n",
305 | "\n",
306 | "index 0, value = 0\n",
307 | "index 1, value = 1\n",
308 | "index 2, value = 2\n",
309 | "index 3, value = 3\n",
310 | "index 4, value = 4\n",
311 | "index 5, value = 5\n",
312 | "index 6, value = 6\n",
313 | "index 7, value = 7\n",
314 | "index 8, value = 8\n",
315 | "index 9, value = 9\n"
316 | ]
317 | }
318 | ],
319 | "source": [
320 | "for inx,item in enumerate(range(0,41,5)):\n",
321 | " print('index {}, value = {}'.format(inx,item))\n",
322 | "print('\\n')\n",
323 | "for inx,item in enumerate(range(10)):\n",
324 | " print('index {}, value = {}'.format(inx,item))"
325 | ]
326 | },
327 | {
328 | "cell_type": "markdown",
329 | "metadata": {
330 | "slideshow": {
331 | "slide_type": "slide"
332 | }
333 | },
334 | "source": [
335 | "***\n",
336 | "# conditionals: `if`, `elif`, `else` \n",
337 | "### Conditional operators can be used to compare different types of variables or to test logical statements. \n",
338 | "\n",
339 | "- The basic operator to compare numerical values are: ==, !=, <, >, >=, <=\n",
340 | "- The logical operators are: and, or, not\n",
341 | "- and the use of conditional operators are exemplified in the next cell\n",
342 | "\n",
343 | "#### Note the indentation again\n",
344 | "\n",
345 | "- Execute the next cell\n",
346 | "
\n",
347 | "- Test different comparison operators and logical operators and execute\n",
348 | "
"
349 | ]
350 | },
351 | {
352 | "cell_type": "code",
353 | "execution_count": 12,
354 | "metadata": {},
355 | "outputs": [
356 | {
357 | "name": "stdout",
358 | "output_type": "stream",
359 | "text": [
360 | "tropical\n"
361 | ]
362 | }
363 | ],
364 | "source": [
365 | "lat = 12\n",
366 | "if (lat <= -23.5) or (lat >= 23.5):\n",
367 | " print('extra-tropical')\n",
368 | "elif lat == 0:\n",
369 | " print('equator')\n",
370 | "else:\n",
371 | " print('tropical')"
372 | ]
373 | },
374 | {
375 | "cell_type": "code",
376 | "execution_count": null,
377 | "metadata": {},
378 | "outputs": [],
379 | "source": []
380 | }
381 | ],
382 | "metadata": {
383 | "kernelspec": {
384 | "display_name": "Python 3",
385 | "language": "python",
386 | "name": "python3"
387 | },
388 | "language_info": {
389 | "codemirror_mode": {
390 | "name": "ipython",
391 | "version": 3
392 | },
393 | "file_extension": ".py",
394 | "mimetype": "text/x-python",
395 | "name": "python",
396 | "nbconvert_exporter": "python",
397 | "pygments_lexer": "ipython3",
398 | "version": "3.7.1"
399 | }
400 | },
401 | "nbformat": 4,
402 | "nbformat_minor": 2
403 | }
404 |
--------------------------------------------------------------------------------
/notebooks/answers/.ipynb_checkpoints/Intro_07_Xarray_and_plotting_with_cartopy-checkpoint.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Plotting with [cartopy](https://scitools.org.uk/cartopy/docs/latest/)\n",
8 | "\n",
9 | "From Cartopy website:\n",
10 | "\n",
11 | "* Cartopy is a Python package designed for geospatial data processing in order to produce maps and other geospatial data analyses.\n",
12 | "\n",
13 | "* Cartopy makes use of the powerful PROJ.4, NumPy and Shapely libraries and includes a programmatic interface built on top of Matplotlib for the creation of publication quality maps.\n",
14 | "\n",
15 | "* Key features of cartopy are its object oriented projection definitions, and its ability to transform points, lines, vectors, polygons and images between those projections.\n",
16 | "\n",
17 | "* You will find cartopy especially useful for large area / small scale data, where Cartesian assumptions of spherical data traditionally break down. If you’ve ever experienced a singularity at the pole or a cut-off at the dateline, it is likely you will appreciate cartopy’s unique features!\n"
18 | ]
19 | },
20 | {
21 | "cell_type": "code",
22 | "execution_count": null,
23 | "metadata": {},
24 | "outputs": [],
25 | "source": [
26 | "import numpy as np\n",
27 | "import matplotlib.pyplot as plt\n",
28 | "import xarray as xr\n",
29 | "import cartopy.crs as ccrs"
30 | ]
31 | },
32 | {
33 | "cell_type": "markdown",
34 | "metadata": {},
35 | "source": [
36 | "# Read in data using xarray\n",
37 | "- Read in the Saildrone USV file either from a local disc `xr.open_dataset()\n",
38 | "- change latitude and longitude to lat and lon `.rename({'longitude':'lon','latitude':'lat'})`\n"
39 | ]
40 | },
41 | {
42 | "cell_type": "code",
43 | "execution_count": null,
44 | "metadata": {},
45 | "outputs": [],
46 | "source": [
47 | "file = '../../data/saildrone-gen_5-antarctica_circumnavigation_2019-sd1020-20190119T040000-20190803T043000-1440_minutes-v1.1564857794963.nc'\n",
48 | "\n",
49 | "ds_usv = xr.open_dataset(file).rename({'longitude':'lon','latitude':'lat'})\n"
50 | ]
51 | },
52 | {
53 | "cell_type": "markdown",
54 | "metadata": {},
55 | "source": [
56 | "# Open the dataset, mask land, plot result\n",
57 | "*`xr.open_dataset`\n",
58 | "* use `.where` to mask values equal to 1"
59 | ]
60 | },
61 | {
62 | "cell_type": "code",
63 | "execution_count": null,
64 | "metadata": {},
65 | "outputs": [],
66 | "source": [
67 | "#If you are offline use the first url\n",
68 | "#url = '../data/20111101120000-CMC-L4_GHRSST-SSTfnd-CMC0.2deg-GLOB-v02.0-fv02.0.nc'\n",
69 | "url = 'https://podaac-opendap.jpl.nasa.gov/opendap/allData/ghrsst/data/GDS2/L4/GLOB/CMC/CMC0.2deg/v2/2011/305/20111101120000-CMC-L4_GHRSST-SSTfnd-CMC0.2deg-GLOB-v02.0-fv02.0.nc'\n",
70 | "\n",
71 | "ds_sst = xr.open_dataset(url)\n",
72 | "\n",
73 | "ds_sst = ds_sst.where(ds_sst.mask==1)\n",
74 | "\n"
75 | ]
76 | },
77 | {
78 | "cell_type": "markdown",
79 | "metadata": {},
80 | "source": [
81 | "\n",
82 | "## explore the in situ data and quickly plot using cartopy\n",
83 | "\n",
84 | "* first set up the axis with the projection you want: https://scitools.org.uk/cartopy/docs/latest/crs/projections.html\n",
85 | "\n",
86 | "* plot to that axis and tell the projection that your data is in\n",
87 | "* set a background image `ax.stock_img()`\n",
88 | "* draw coastlines `ax.coastlines(resolution='50m')`\n",
89 | "* add a colorbary and label it `cax = plt.colorbar(cs1)` `cax.set_label('SST (K)')`"
90 | ]
91 | },
92 | {
93 | "cell_type": "code",
94 | "execution_count": null,
95 | "metadata": {
96 | "scrolled": true
97 | },
98 | "outputs": [],
99 | "source": [
100 | "#for polar data, plot temperature\n",
101 | "ax = plt.axes(projection=ccrs.SouthPolarStereo())\n",
102 | "\n",
103 | "(ds_sst.analysed_sst-273.15).plot(ax=ax, \n",
104 | " transform=ccrs.PlateCarree(),\n",
105 | " vmin=0,\n",
106 | " vmax=12)\n",
107 | "\n",
108 | "cs1 = ax.scatter(ds_usv.lon, ds_usv.lat, \n",
109 | " transform=ccrs.PlateCarree(),\n",
110 | " s=10.0, \n",
111 | " c=ds_usv.TEMP_CTD_MEAN, \n",
112 | " edgecolor='none', \n",
113 | " cmap='jet',\n",
114 | " vmin=0,vmax=12)\n",
115 | "\n",
116 | "ax.set_extent([-180, 180, -90, -45], crs=ccrs.PlateCarree())\n",
117 | "\n",
118 | "ax.stock_img()\n",
119 | "ax.coastlines(resolution='50m')\n",
120 | "cax = plt.colorbar(cs1)\n",
121 | "cax.set_label('SST (K)')\n"
122 | ]
123 | },
124 | {
125 | "cell_type": "markdown",
126 | "metadata": {},
127 | "source": [
128 | "# Exercise!"
129 | ]
130 | },
131 | {
132 | "cell_type": "code",
133 | "execution_count": null,
134 | "metadata": {},
135 | "outputs": [],
136 | "source": [
137 | "#now you try to plot plot salinity ds_usv.SAL_MEAN\n",
138 | "#for polar data, plot temperature\n",
139 | "ax = plt.axes(projection=ccrs.SouthPolarStereo())\n",
140 | "\n",
141 | "(ds_sst.analysed_sst-273.15).plot(ax=ax, \n",
142 | " transform=ccrs.PlateCarree(),\n",
143 | " vmin=0,\n",
144 | " vmax=12)\n",
145 | "\n",
146 | "cs1 = ax.scatter(ds_usv.lon, ds_usv.lat, \n",
147 | " transform=ccrs.PlateCarree(),\n",
148 | " s=10.0, \n",
149 | " c=ds_usv.SAL_MEAN, \n",
150 | " edgecolor='none', \n",
151 | " cmap='jet',\n",
152 | " vmin=33,vmax=35)\n",
153 | "\n",
154 | "ax.set_extent([-180, 180, -90, -45], crs=ccrs.PlateCarree())\n",
155 | "\n",
156 | "ax.stock_img()\n",
157 | "ax.coastlines(resolution='50m')\n",
158 | "cax = plt.colorbar(cs1)\n",
159 | "cax.set_label('Salinity (psu)')\n",
160 | "\n",
161 | "\n"
162 | ]
163 | },
164 | {
165 | "cell_type": "markdown",
166 | "metadata": {},
167 | "source": [
168 | "# Let's plot some data off of California\n",
169 | "* `.rename({'longitude':'lon','latitude':'lat'})`"
170 | ]
171 | },
172 | {
173 | "cell_type": "code",
174 | "execution_count": null,
175 | "metadata": {},
176 | "outputs": [],
177 | "source": [
178 | "#use the first URL if you are offline\n",
179 | "#url = '../data/saildrone-gen_4-baja_2018-sd1002-20180411T180000-20180611T055959-1_minutes-v1.nc'\n",
180 | "\n",
181 | "url = 'https://podaac-opendap.jpl.nasa.gov/opendap/hyrax/allData/insitu/L2/saildrone/Baja/saildrone-gen_4-baja_2018-sd1002-20180411T180000-20180611T055959-1_minutes-v1.nc'\n",
182 | "\n",
183 | "ds_usv = xr.open_dataset(url).rename({'longitude':'lon','latitude':'lat'})\n"
184 | ]
185 | },
186 | {
187 | "cell_type": "markdown",
188 | "metadata": {},
189 | "source": [
190 | "# Exercise!\n",
191 | "* for NON polar ds_usv data, use `ccrs.PlateCarree()` as your projection"
192 | ]
193 | },
194 | {
195 | "cell_type": "code",
196 | "execution_count": null,
197 | "metadata": {},
198 | "outputs": [],
199 | "source": [
200 | "ax = plt.axes(projection=ccrs.PlateCarree())\n",
201 | "\n",
202 | "(ds_sst.analysed_sst-273.15).plot(ax=ax, \n",
203 | " transform=ccrs.PlateCarree(),\n",
204 | " vmin=15,\n",
205 | " vmax=30)\n",
206 | "\n",
207 | "cs1 = ax.scatter(ds_usv.lon, ds_usv.lat, \n",
208 | " transform=ccrs.PlateCarree(),\n",
209 | " s=10.0, \n",
210 | " c=ds_usv.TEMP_CTD_MEAN, \n",
211 | " edgecolor='none', \n",
212 | " cmap='jet',\n",
213 | " vmin=15,\n",
214 | " vmax=30)\n",
215 | "\n",
216 | "ax.set_extent([-130, -110, 20, 40], crs=ccrs.PlateCarree())\n",
217 | "\n",
218 | "ax.stock_img()\n",
219 | "ax.coastlines(resolution='50m')\n",
220 | "cax = plt.colorbar(cs1)\n",
221 | "cax.set_label('SST (K)')\n",
222 | "\n"
223 | ]
224 | },
225 | {
226 | "cell_type": "code",
227 | "execution_count": null,
228 | "metadata": {},
229 | "outputs": [],
230 | "source": [
231 | "# now add an extent to your figure\n",
232 | "ax = plt.axes(projection=ccrs.PlateCarree())\n",
233 | "\n",
234 | "(ds_sst.analysed_sst-273.15).plot(ax=ax, \n",
235 | " transform=ccrs.PlateCarree(),\n",
236 | " vmin=12,\n",
237 | " vmax=23)\n",
238 | "\n",
239 | "cs1 = ax.scatter(ds_usv.lon, ds_usv.lat, \n",
240 | " transform=ccrs.PlateCarree(),\n",
241 | " s=10.0, \n",
242 | " c=ds_usv.TEMP_CTD_MEAN, \n",
243 | " edgecolor='none', \n",
244 | " vmin=12,\n",
245 | " vmax=23)\n",
246 | "\n",
247 | "\n",
248 | "ax.stock_img()\n",
249 | "ax.coastlines(resolution='50m')\n",
250 | "cax = plt.colorbar(cs1)\n",
251 | "cax.set_label('SST (K)')\n",
252 | "\n",
253 | "\n",
254 | "lonmin,lonmax = ds_usv.lon.min().data-2,ds_usv.lon.max().data+2\n",
255 | "latmin,latmax = ds_usv.lat.min().data-2,ds_usv.lat.max().data+2\n",
256 | "ax.set_extent([lonmin,lonmax,latmin,latmax], crs=ccrs.PlateCarree())\n"
257 | ]
258 | },
259 | {
260 | "cell_type": "code",
261 | "execution_count": null,
262 | "metadata": {},
263 | "outputs": [],
264 | "source": []
265 | }
266 | ],
267 | "metadata": {
268 | "kernelspec": {
269 | "display_name": "Python 3",
270 | "language": "python",
271 | "name": "python3"
272 | },
273 | "language_info": {
274 | "codemirror_mode": {
275 | "name": "ipython",
276 | "version": 3
277 | },
278 | "file_extension": ".py",
279 | "mimetype": "text/x-python",
280 | "name": "python",
281 | "nbconvert_exporter": "python",
282 | "pygments_lexer": "ipython3",
283 | "version": "3.7.1"
284 | }
285 | },
286 | "nbformat": 4,
287 | "nbformat_minor": 1
288 | }
289 |
--------------------------------------------------------------------------------
/notebooks/answers/Tutorial_03_BasicCommands.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "slideshow": {
7 | "slide_type": "slide"
8 | }
9 | },
10 | "source": [
11 | "# Basic `Python`\n",
12 | "We are going to learn the most basic commands of Python. The objective is not to teach you how to program to become an expert, but to learn the syntaxis of the language & recongnize it through the next notebooks\n",
13 | "
\n",
14 | "At the end of this notebook you can find some links to more comprehensible tutorials & references"
15 | ]
16 | },
17 | {
18 | "cell_type": "markdown",
19 | "metadata": {
20 | "slideshow": {
21 | "slide_type": "slide"
22 | }
23 | },
24 | "source": [
25 | "## Basic operations \n",
26 | "### +, -, \\*, /, **\n",
27 | "\n",
28 | " - Define two integer variables & print the result of basic operations\n",
29 | "
"
30 | ]
31 | },
32 | {
33 | "cell_type": "code",
34 | "execution_count": 2,
35 | "metadata": {
36 | "scrolled": true,
37 | "slideshow": {
38 | "slide_type": "fragment"
39 | }
40 | },
41 | "outputs": [
42 | {
43 | "name": "stdout",
44 | "output_type": "stream",
45 | "text": [
46 | "11.0\n"
47 | ]
48 | }
49 | ],
50 | "source": [
51 | "sst1 = 10\n",
52 | "sst2 = 12\n",
53 | "sstm = (10+12)/2\n",
54 | "print(sstm)"
55 | ]
56 | },
57 | {
58 | "cell_type": "markdown",
59 | "metadata": {},
60 | "source": [
61 | "### Operations over the same variables can be simplified by adding the operand before the `=`, like this:\n",
62 | "x += 1"
63 | ]
64 | },
65 | {
66 | "cell_type": "markdown",
67 | "metadata": {},
68 | "source": [
69 | "\n",
70 | " - Execute the code in the cell below & print x & y final values\n",
71 | "
"
72 | ]
73 | },
74 | {
75 | "cell_type": "code",
76 | "execution_count": 4,
77 | "metadata": {},
78 | "outputs": [
79 | {
80 | "name": "stdout",
81 | "output_type": "stream",
82 | "text": [
83 | "3 4\n",
84 | "4 2.0\n"
85 | ]
86 | }
87 | ],
88 | "source": [
89 | "x, y = 3, 4\n",
90 | "print(x,y)\n",
91 | "x += 1\n",
92 | "y /= 2\n",
93 | "print(x, y)"
94 | ]
95 | },
96 | {
97 | "cell_type": "markdown",
98 | "metadata": {
99 | "slideshow": {
100 | "slide_type": "slide"
101 | }
102 | },
103 | "source": [
104 | "*** \n",
105 | "## `for` loops\n",
106 | "Can iterate on any list. \n",
107 | "
\n",
108 | "#### Note the indentation in the line after the `for` command. This position indicates which lines belong to the `for` loop.\n",
109 | "The print statement is no longer being looped on because it has no indent.\n",
110 | "\n",
111 | " Execute the code below \n",
112 | "
"
113 | ]
114 | },
115 | {
116 | "cell_type": "code",
117 | "execution_count": 5,
118 | "metadata": {
119 | "slideshow": {
120 | "slide_type": "fragment"
121 | }
122 | },
123 | "outputs": [
124 | {
125 | "name": "stdout",
126 | "output_type": "stream",
127 | "text": [
128 | "10\n",
129 | "15\n",
130 | "25\n",
131 | "10ppm\n",
132 | "5m/s\n",
133 | "[10, 15, 25, '10ppm', '5m/s']\n"
134 | ]
135 | }
136 | ],
137 | "source": [
138 | "somelist = [10,15,25, '10ppm','5m/s']\n",
139 | "for item in somelist:\n",
140 | " print(item)\n",
141 | "print(somelist)"
142 | ]
143 | },
144 | {
145 | "cell_type": "markdown",
146 | "metadata": {
147 | "slideshow": {
148 | "slide_type": "fragment"
149 | }
150 | },
151 | "source": [
152 | "### A list can also be just of numbers, and we can build a list using the function `range`:\n",
153 | "#### range(start, end, step) \n",
154 | "
Note: the end is non-inclusive\n",
155 | "\n",
156 | "\n",
157 | " - Execute the code below\n",
158 | "
\n",
159 | " - Replace somelist in the for loop with: range(0,41,5), and execute the code again\n",
160 | "
\n",
161 | " - Change the start, end or step and execute the code again\n",
162 | "
\n",
234 | " - Try range(10) instead"
235 | ]
236 | },
237 | {
238 | "cell_type": "code",
239 | "execution_count": 9,
240 | "metadata": {},
241 | "outputs": [
242 | {
243 | "name": "stdout",
244 | "output_type": "stream",
245 | "text": [
246 | "0\n",
247 | "1\n",
248 | "2\n",
249 | "3\n",
250 | "4\n",
251 | "5\n",
252 | "6\n",
253 | "7\n",
254 | "8\n",
255 | "9\n"
256 | ]
257 | }
258 | ],
259 | "source": [
260 | "for item in range(10):\n",
261 | " print(item)"
262 | ]
263 | },
264 | {
265 | "cell_type": "markdown",
266 | "metadata": {
267 | "slideshow": {
268 | "slide_type": "slide"
269 | }
270 | },
271 | "source": [
272 | "## Sometimes we want the index and the value of each element on a list\n",
273 | "### The command `enumerate` gives you both\n",
274 | "\n",
275 | " - Execute the code below\n",
276 | "
\n",
277 | " - Then try with range(10) instead\n",
278 | "
\n",
279 | "
Note the use of { } and .format to print inx and item"
280 | ]
281 | },
282 | {
283 | "cell_type": "code",
284 | "execution_count": 11,
285 | "metadata": {
286 | "slideshow": {
287 | "slide_type": "fragment"
288 | }
289 | },
290 | "outputs": [
291 | {
292 | "name": "stdout",
293 | "output_type": "stream",
294 | "text": [
295 | "index 0, value = 0\n",
296 | "index 1, value = 5\n",
297 | "index 2, value = 10\n",
298 | "index 3, value = 15\n",
299 | "index 4, value = 20\n",
300 | "index 5, value = 25\n",
301 | "index 6, value = 30\n",
302 | "index 7, value = 35\n",
303 | "index 8, value = 40\n",
304 | "\n",
305 | "\n",
306 | "index 0, value = 0\n",
307 | "index 1, value = 1\n",
308 | "index 2, value = 2\n",
309 | "index 3, value = 3\n",
310 | "index 4, value = 4\n",
311 | "index 5, value = 5\n",
312 | "index 6, value = 6\n",
313 | "index 7, value = 7\n",
314 | "index 8, value = 8\n",
315 | "index 9, value = 9\n"
316 | ]
317 | }
318 | ],
319 | "source": [
320 | "for inx,item in enumerate(range(0,41,5)):\n",
321 | " print('index {}, value = {}'.format(inx,item))\n",
322 | "print('\\n')\n",
323 | "for inx,item in enumerate(range(10)):\n",
324 | " print('index {}, value = {}'.format(inx,item))"
325 | ]
326 | },
327 | {
328 | "cell_type": "markdown",
329 | "metadata": {
330 | "slideshow": {
331 | "slide_type": "slide"
332 | }
333 | },
334 | "source": [
335 | "***\n",
336 | "# conditionals: `if`, `elif`, `else` \n",
337 | "### Conditional operators can be used to compare different types of variables or to test logical statements. \n",
338 | "\n",
339 | "- The basic operator to compare numerical values are: ==, !=, <, >, >=, <=\n",
340 | "- The logical operators are: and, or, not\n",
341 | "- and the use of conditional operators are exemplified in the next cell\n",
342 | "\n",
343 | "#### Note the indentation again\n",
344 | "\n",
345 | "- Execute the next cell\n",
346 | "
\n",
347 | "- Test different comparison operators and logical operators and execute\n",
348 | "
"
349 | ]
350 | },
351 | {
352 | "cell_type": "code",
353 | "execution_count": 12,
354 | "metadata": {},
355 | "outputs": [
356 | {
357 | "name": "stdout",
358 | "output_type": "stream",
359 | "text": [
360 | "tropical\n"
361 | ]
362 | }
363 | ],
364 | "source": [
365 | "lat = 12\n",
366 | "if (lat <= -23.5) or (lat >= 23.5):\n",
367 | " print('extra-tropical')\n",
368 | "elif lat == 0:\n",
369 | " print('equator')\n",
370 | "else:\n",
371 | " print('tropical')"
372 | ]
373 | },
374 | {
375 | "cell_type": "code",
376 | "execution_count": null,
377 | "metadata": {},
378 | "outputs": [],
379 | "source": []
380 | }
381 | ],
382 | "metadata": {
383 | "kernelspec": {
384 | "display_name": "Python 3",
385 | "language": "python",
386 | "name": "python3"
387 | },
388 | "language_info": {
389 | "codemirror_mode": {
390 | "name": "ipython",
391 | "version": 3
392 | },
393 | "file_extension": ".py",
394 | "mimetype": "text/x-python",
395 | "name": "python",
396 | "nbconvert_exporter": "python",
397 | "pygments_lexer": "ipython3",
398 | "version": "3.7.1"
399 | }
400 | },
401 | "nbformat": 4,
402 | "nbformat_minor": 2
403 | }
404 |
--------------------------------------------------------------------------------
/notebooks/answers/Tutorial_07_Xarray_and_plotting_with_cartopy.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Plotting with [cartopy](https://scitools.org.uk/cartopy/docs/latest/)\n",
8 | "\n",
9 | "From Cartopy website:\n",
10 | "\n",
11 | "* Cartopy is a Python package designed for geospatial data processing in order to produce maps and other geospatial data analyses.\n",
12 | "\n",
13 | "* Cartopy makes use of the powerful PROJ.4, NumPy and Shapely libraries and includes a programmatic interface built on top of Matplotlib for the creation of publication quality maps.\n",
14 | "\n",
15 | "* Key features of cartopy are its object oriented projection definitions, and its ability to transform points, lines, vectors, polygons and images between those projections.\n",
16 | "\n",
17 | "* You will find cartopy especially useful for large area / small scale data, where Cartesian assumptions of spherical data traditionally break down. If you’ve ever experienced a singularity at the pole or a cut-off at the dateline, it is likely you will appreciate cartopy’s unique features!\n"
18 | ]
19 | },
20 | {
21 | "cell_type": "code",
22 | "execution_count": null,
23 | "metadata": {},
24 | "outputs": [],
25 | "source": [
26 | "import numpy as np\n",
27 | "import matplotlib.pyplot as plt\n",
28 | "import xarray as xr\n",
29 | "import cartopy.crs as ccrs"
30 | ]
31 | },
32 | {
33 | "cell_type": "markdown",
34 | "metadata": {},
35 | "source": [
36 | "# Read in data using xarray\n",
37 | "- Read in the Saildrone USV file either from a local disc `xr.open_dataset()\n",
38 | "- change latitude and longitude to lat and lon `.rename({'longitude':'lon','latitude':'lat'})`\n"
39 | ]
40 | },
41 | {
42 | "cell_type": "code",
43 | "execution_count": null,
44 | "metadata": {},
45 | "outputs": [],
46 | "source": [
47 | "file = '../../data/saildrone-gen_5-antarctica_circumnavigation_2019-sd1020-20190119T040000-20190803T043000-1440_minutes-v1.1564857794963.nc'\n",
48 | "\n",
49 | "ds_usv = xr.open_dataset(file).rename({'longitude':'lon','latitude':'lat'})\n"
50 | ]
51 | },
52 | {
53 | "cell_type": "markdown",
54 | "metadata": {},
55 | "source": [
56 | "# Open the dataset, mask land, plot result\n",
57 | "*`xr.open_dataset`\n",
58 | "* use `.where` to mask values equal to 1"
59 | ]
60 | },
61 | {
62 | "cell_type": "code",
63 | "execution_count": null,
64 | "metadata": {},
65 | "outputs": [],
66 | "source": [
67 | "#If you are offline use the first url\n",
68 | "#url = '../data/20111101120000-CMC-L4_GHRSST-SSTfnd-CMC0.2deg-GLOB-v02.0-fv02.0.nc'\n",
69 | "url = 'https://podaac-opendap.jpl.nasa.gov/opendap/allData/ghrsst/data/GDS2/L4/GLOB/CMC/CMC0.2deg/v2/2011/305/20111101120000-CMC-L4_GHRSST-SSTfnd-CMC0.2deg-GLOB-v02.0-fv02.0.nc'\n",
70 | "\n",
71 | "ds_sst = xr.open_dataset(url)\n",
72 | "\n",
73 | "ds_sst = ds_sst.where(ds_sst.mask==1)\n",
74 | "\n"
75 | ]
76 | },
77 | {
78 | "cell_type": "markdown",
79 | "metadata": {},
80 | "source": [
81 | "\n",
82 | "## explore the in situ data and quickly plot using cartopy\n",
83 | "\n",
84 | "* first set up the axis with the projection you want: https://scitools.org.uk/cartopy/docs/latest/crs/projections.html\n",
85 | "\n",
86 | "* plot to that axis and tell the projection that your data is in\n",
87 | "* set a background image `ax.stock_img()`\n",
88 | "* draw coastlines `ax.coastlines(resolution='50m')`\n",
89 | "* add a colorbary and label it `cax = plt.colorbar(cs1)` `cax.set_label('SST (K)')`"
90 | ]
91 | },
92 | {
93 | "cell_type": "code",
94 | "execution_count": null,
95 | "metadata": {
96 | "scrolled": true
97 | },
98 | "outputs": [],
99 | "source": [
100 | "#for polar data, plot temperature\n",
101 | "ax = plt.axes(projection=ccrs.SouthPolarStereo())\n",
102 | "\n",
103 | "(ds_sst.analysed_sst-273.15).plot(ax=ax, \n",
104 | " transform=ccrs.PlateCarree(),\n",
105 | " vmin=0,\n",
106 | " vmax=12)\n",
107 | "\n",
108 | "cs1 = ax.scatter(ds_usv.lon, ds_usv.lat, \n",
109 | " transform=ccrs.PlateCarree(),\n",
110 | " s=10.0, \n",
111 | " c=ds_usv.TEMP_CTD_MEAN, \n",
112 | " edgecolor='none', \n",
113 | " cmap='jet',\n",
114 | " vmin=0,vmax=12)\n",
115 | "\n",
116 | "ax.set_extent([-180, 180, -90, -45], crs=ccrs.PlateCarree())\n",
117 | "\n",
118 | "ax.stock_img()\n",
119 | "ax.coastlines(resolution='50m')\n",
120 | "cax = plt.colorbar(cs1)\n",
121 | "cax.set_label('SST (K)')\n"
122 | ]
123 | },
124 | {
125 | "cell_type": "markdown",
126 | "metadata": {},
127 | "source": [
128 | "# Exercise!"
129 | ]
130 | },
131 | {
132 | "cell_type": "code",
133 | "execution_count": null,
134 | "metadata": {},
135 | "outputs": [],
136 | "source": [
137 | "#now you try to plot plot salinity ds_usv.SAL_MEAN\n",
138 | "#for polar data, plot temperature\n",
139 | "ax = plt.axes(projection=ccrs.SouthPolarStereo())\n",
140 | "\n",
141 | "(ds_sst.analysed_sst-273.15).plot(ax=ax, \n",
142 | " transform=ccrs.PlateCarree(),\n",
143 | " vmin=0,\n",
144 | " vmax=12)\n",
145 | "\n",
146 | "cs1 = ax.scatter(ds_usv.lon, ds_usv.lat, \n",
147 | " transform=ccrs.PlateCarree(),\n",
148 | " s=10.0, \n",
149 | " c=ds_usv.SAL_MEAN, \n",
150 | " edgecolor='none', \n",
151 | " cmap='jet',\n",
152 | " vmin=33,vmax=35)\n",
153 | "\n",
154 | "ax.set_extent([-180, 180, -90, -45], crs=ccrs.PlateCarree())\n",
155 | "\n",
156 | "ax.stock_img()\n",
157 | "ax.coastlines(resolution='50m')\n",
158 | "cax = plt.colorbar(cs1)\n",
159 | "cax.set_label('Salinity (psu)')\n",
160 | "\n",
161 | "\n"
162 | ]
163 | },
164 | {
165 | "cell_type": "markdown",
166 | "metadata": {},
167 | "source": [
168 | "# Let's plot some data off of California\n",
169 | "* `.rename({'longitude':'lon','latitude':'lat'})`"
170 | ]
171 | },
172 | {
173 | "cell_type": "code",
174 | "execution_count": null,
175 | "metadata": {},
176 | "outputs": [],
177 | "source": [
178 | "#use the first URL if you are offline\n",
179 | "#url = '../data/saildrone-gen_4-baja_2018-sd1002-20180411T180000-20180611T055959-1_minutes-v1.nc'\n",
180 | "\n",
181 | "url = 'https://podaac-opendap.jpl.nasa.gov/opendap/hyrax/allData/insitu/L2/saildrone/Baja/saildrone-gen_4-baja_2018-sd1002-20180411T180000-20180611T055959-1_minutes-v1.nc'\n",
182 | "\n",
183 | "ds_usv = xr.open_dataset(url).rename({'longitude':'lon','latitude':'lat'})\n"
184 | ]
185 | },
186 | {
187 | "cell_type": "markdown",
188 | "metadata": {},
189 | "source": [
190 | "# Exercise!\n",
191 | "* for NON polar ds_usv data, use `ccrs.PlateCarree()` as your projection"
192 | ]
193 | },
194 | {
195 | "cell_type": "code",
196 | "execution_count": null,
197 | "metadata": {},
198 | "outputs": [],
199 | "source": [
200 | "ax = plt.axes(projection=ccrs.PlateCarree())\n",
201 | "\n",
202 | "(ds_sst.analysed_sst-273.15).plot(ax=ax, \n",
203 | " transform=ccrs.PlateCarree(),\n",
204 | " vmin=15,\n",
205 | " vmax=30)\n",
206 | "\n",
207 | "cs1 = ax.scatter(ds_usv.lon, ds_usv.lat, \n",
208 | " transform=ccrs.PlateCarree(),\n",
209 | " s=10.0, \n",
210 | " c=ds_usv.TEMP_CTD_MEAN, \n",
211 | " edgecolor='none', \n",
212 | " cmap='jet',\n",
213 | " vmin=15,\n",
214 | " vmax=30)\n",
215 | "\n",
216 | "ax.set_extent([-130, -110, 20, 40], crs=ccrs.PlateCarree())\n",
217 | "\n",
218 | "ax.stock_img()\n",
219 | "ax.coastlines(resolution='50m')\n",
220 | "cax = plt.colorbar(cs1)\n",
221 | "cax.set_label('SST (K)')\n",
222 | "\n"
223 | ]
224 | },
225 | {
226 | "cell_type": "code",
227 | "execution_count": null,
228 | "metadata": {},
229 | "outputs": [],
230 | "source": [
231 | "# now add an extent to your figure\n",
232 | "ax = plt.axes(projection=ccrs.PlateCarree())\n",
233 | "\n",
234 | "(ds_sst.analysed_sst-273.15).plot(ax=ax, \n",
235 | " transform=ccrs.PlateCarree(),\n",
236 | " vmin=12,\n",
237 | " vmax=23)\n",
238 | "\n",
239 | "cs1 = ax.scatter(ds_usv.lon, ds_usv.lat, \n",
240 | " transform=ccrs.PlateCarree(),\n",
241 | " s=10.0, \n",
242 | " c=ds_usv.TEMP_CTD_MEAN, \n",
243 | " edgecolor='none', \n",
244 | " vmin=12,\n",
245 | " vmax=23)\n",
246 | "\n",
247 | "\n",
248 | "ax.stock_img()\n",
249 | "ax.coastlines(resolution='50m')\n",
250 | "cax = plt.colorbar(cs1)\n",
251 | "cax.set_label('SST (K)')\n",
252 | "\n",
253 | "\n",
254 | "lonmin,lonmax = ds_usv.lon.min().data-2,ds_usv.lon.max().data+2\n",
255 | "latmin,latmax = ds_usv.lat.min().data-2,ds_usv.lat.max().data+2\n",
256 | "ax.set_extent([lonmin,lonmax,latmin,latmax], crs=ccrs.PlateCarree())\n"
257 | ]
258 | },
259 | {
260 | "cell_type": "code",
261 | "execution_count": null,
262 | "metadata": {},
263 | "outputs": [],
264 | "source": []
265 | }
266 | ],
267 | "metadata": {
268 | "kernelspec": {
269 | "display_name": "Python 3",
270 | "language": "python",
271 | "name": "python3"
272 | },
273 | "language_info": {
274 | "codemirror_mode": {
275 | "name": "ipython",
276 | "version": 3
277 | },
278 | "file_extension": ".py",
279 | "mimetype": "text/x-python",
280 | "name": "python",
281 | "nbconvert_exporter": "python",
282 | "pygments_lexer": "ipython3",
283 | "version": "3.7.1"
284 | }
285 | },
286 | "nbformat": 4,
287 | "nbformat_minor": 1
288 | }
289 |
--------------------------------------------------------------------------------
/notebooks/figures/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/notebooks/figures/.DS_Store
--------------------------------------------------------------------------------
/notebooks/figures/lab_logo_tng.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/notebooks/figures/lab_logo_tng.png
--------------------------------------------------------------------------------
/notebooks/figures/pythonforoceanographers.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/notebooks/figures/pythonforoceanographers.png
--------------------------------------------------------------------------------
/notebooks/figures/pythonlogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/notebooks/figures/pythonlogo.png
--------------------------------------------------------------------------------
/notebooks/figures/xarray-boxes.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/notebooks/figures/xarray-boxes.png
--------------------------------------------------------------------------------
/notebooks/podaac.ini:
--------------------------------------------------------------------------------
1 | [drive]
2 | urs_username = podaacpy
3 | urs_password = hZHYQ17yuag25zivK8F
4 | webdav_url = https://podaac-tools.jpl.nasa.gov/drive/files
5 |
--------------------------------------------------------------------------------
/notes_for_instructors/Notes_Intro_01_PythonEcosystem.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/notes_for_instructors/Notes_Intro_01_PythonEcosystem.docx
--------------------------------------------------------------------------------
/notes_for_instructors/Notes_Intro_02_jupyternotebooks.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/notes_for_instructors/Notes_Intro_02_jupyternotebooks.docx
--------------------------------------------------------------------------------
/notes_for_instructors/Notes_Intro_03_BasicPythonCommands.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/notes_for_instructors/Notes_Intro_03_BasicPythonCommands.docx
--------------------------------------------------------------------------------
/notes_for_instructors/Notes_Intro_04_DataTypesStructures.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/notes_for_instructors/Notes_Intro_04_DataTypesStructures.docx
--------------------------------------------------------------------------------
/notes_for_instructors/Notes_Intro_05_LibraryDataStructures.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/python4oceanography/ocean_python_tutorial/7215b3c740ab8fb4b177a8ae764411c273cc7a06/notes_for_instructors/Notes_Intro_05_LibraryDataStructures.docx
--------------------------------------------------------------------------------
/notes_for_instructors/~$tes_Intro_01_PythonEcosystem.docx:
--------------------------------------------------------------------------------
1 | Marisol Garcia-Reyes M a r i s o l G a r c i a - R e y e s i t H u b / c l o u d _ s c i e n c e / G H R S S T _ t u t o r
--------------------------------------------------------------------------------
/python_installation_instructions.md:
--------------------------------------------------------------------------------
1 |
2 | # To install python....
3 |
4 | 1. You don't need to install the python programming language, instead you want to install a package manager, conda. Conda manages all the software libraries for you. There are two flavors of conda that are widely used.
5 |
6 | 1. Anaconda or Miniconda?
7 |
8 | Miniconda. While Anaconda is great (it has a nice interface and quickly downloads 1500+ libraries that you can just click on to use). It takes up a lot of disk space on libraries that aren't especially relevant for ocean sciences. With Miniconda you install the libraries that you want, this makes it smaller, and also more controlled.
9 |
10 | * download the environment.yml file from [here](https://github.com/python4oceanography/ocean_python_tutorial/) by scrolling down until you see the file and right clicking on it. Save it to your working directory. We will use this later. You can also choose to 'clone' (see green button in upper right corner) the entire directory with all the tutorials to your computer. This is useful if you want to work offline and save all your work.
11 |
12 | * Install Miniconda: Download Miniconda, Python 3.7 by clicking [here](https://docs.conda.io/en/latest/miniconda.html). Install the downloaded file. Instructions for [Mac](https://www.cs.rpi.edu/academics/courses/fall16/cs1/python_environment/mac_install.html).
13 |
14 | # Open up an anaconda prompt
15 | * Windows: From your start button, look for Anaconda, within that folder open 'Anaconda Prompt'. You are done, skip to next section on installing libraries.
16 | * macOS: Open Launchpad, then open Terminal or iTerm.
17 | * Linux–CentOS: Open Applications - System Tools - Terminal.
18 | * Linux–Ubuntu: Open the Dash by clicking the upper left Ubuntu icon, then type “terminal”.
19 |
20 | In the anaconda window type `conda list`. If Anaconda is installed and working, this will display a list of installed packages and their versions.
21 |
22 | # Create a new environment and install software packages.
23 |
24 | * At your anaconda prompt, type `conda env create -f environment.yml`. You may need to include the directory the environment.yml file was downloaded to.
25 |
26 | * Once finished, let's open a Jupyter notebook, as a test. At the anaconda prompt type `conda activate tutorialenv` then type `jupyter notebook`. This will open a jupyter notebook in your browser. From there you can open notebooks and run them. It is probably easiest to navigate to where you keep your code, create a new 'python' directory and organize your code into projects from there. (This will also make using GitHub easier).
27 |
28 |
--------------------------------------------------------------------------------