├── notebook ├── data │ ├── data1.txt │ ├── deg2.dat │ ├── format.pdf │ ├── ntslf_licence_agreement.pdf │ ├── pendulum.dat │ ├── means.txt │ ├── density_air.dat │ ├── density_water.dat │ ├── surges.txt │ ├── extremes.txt │ ├── densities.dat │ ├── constants.txt │ ├── human_evolution.txt │ ├── acc.dat │ ├── BrachiopodBiometrics.csv │ ├── hpip_yakutsk_borehole_data.txt │ ├── vp.dat │ ├── VostokStation.txt │ ├── precipitation.csv │ ├── xy.dat │ ├── AVO.html │ └── seismic.dat ├── images │ ├── class_Y_UML.png │ ├── UML_class_Account.png │ └── UML_class_Person.png ├── python_class_test_2015-sqt.pdf ├── hpip_yakutsk_borehole_data.txt ├── battleship.ipynb ├── Revision-2-Introduction-to-programming-for-geoscientists-Exercises.ipynb ├── python_class_test_2014.ipynb ├── python_class_test_2017.ipynb ├── python_class_test_2012.ipynb ├── python_class_test_2016.ipynb ├── python_class_test_2013.ipynb ├── python_class_test_2015-sqt.ipynb ├── python_class_test_2015.ipynb ├── Revision-1-Introduction-to-programming-for-geoscientists-Exercises.ipynb ├── Lecture-2-Introduction-to-programming-for-geoscientists-Solutions.ipynb ├── Lecture-3-Introduction-to-programming-for-geoscientists-Solutions.ipynb ├── Lecture-4-Introduction-to-programming-for-geoscientists-Solutions.ipynb ├── Lecture-7-Introduction-to-programming-for-geoscientists-Solutions.ipynb ├── Lecture-1-Introduction-to-programming-for-geoscientists-Solutions.ipynb └── Revision-1-Introduction-to-programming-for-geoscientists-Solutions.ipynb ├── LICENSE ├── LICENSE.md └── README.md /notebook/data/data1.txt: -------------------------------------------------------------------------------- 1 | 21.8 2 | 18.1 3 | 19 4 | 23 5 | 26 6 | 17.8 7 | -------------------------------------------------------------------------------- /notebook/data/deg2.dat: -------------------------------------------------------------------------------- 1 | Oslo: 21.8 2 | London: 18.1 3 | Berlin: 19 4 | Paris: 23 5 | Rome: 26 6 | -------------------------------------------------------------------------------- /notebook/data/format.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggorman/Introduction-to-programming-for-geoscientists/HEAD/notebook/data/format.pdf -------------------------------------------------------------------------------- /notebook/images/class_Y_UML.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggorman/Introduction-to-programming-for-geoscientists/HEAD/notebook/images/class_Y_UML.png -------------------------------------------------------------------------------- /notebook/images/UML_class_Account.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggorman/Introduction-to-programming-for-geoscientists/HEAD/notebook/images/UML_class_Account.png -------------------------------------------------------------------------------- /notebook/images/UML_class_Person.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggorman/Introduction-to-programming-for-geoscientists/HEAD/notebook/images/UML_class_Person.png -------------------------------------------------------------------------------- /notebook/python_class_test_2015-sqt.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggorman/Introduction-to-programming-for-geoscientists/HEAD/notebook/python_class_test_2015-sqt.pdf -------------------------------------------------------------------------------- /notebook/data/ntslf_licence_agreement.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ggorman/Introduction-to-programming-for-geoscientists/HEAD/notebook/data/ntslf_licence_agreement.pdf -------------------------------------------------------------------------------- /notebook/data/pendulum.dat: -------------------------------------------------------------------------------- 1 | L T 2 | 0.1 0.6 3 | 0.2 0.9 4 | 0.3 1.1 5 | 0.4 1.3 6 | 0.5 1.4 7 | 0.6 1.6 8 | 0.7 1.7 9 | 0.8 1.8 10 | 0.9 1.9 11 | 1.0 2.0 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | All the course material is licensed under a Creative Commons Attribution 3.0 Unported (CC BY 3.0) (http://creativecommons.org/licenses/by/3.0/) and MIT License - http://opensource.org/licenses/mit-license.html. 2 | -------------------------------------------------------------------------------- /notebook/data/means.txt: -------------------------------------------------------------------------------- 1 | MONTHLY MEANS 2 | Site,month (mm/yyyy),monthly mean value (metres),No. of days used to calculate mean. 3 | AVONMOUTH,01/2012,6.986,31 4 | AVONMOUTH,02/2012,6.788,29 5 | AVONMOUTH,03/2012,6.761,7 6 | AVONMOUTH,04/2012,6.834,1 7 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: page 3 | title: License 4 | permalink: /license/ 5 | --- 6 | 7 | All the course material is licensed under a Creative Commons Attribution 3.0 Unported (CC BY 3.0) (http://creativecommons.org/licenses/by/3.0/) and MIT License - http://opensource.org/licenses/mit-license.html. 8 | -------------------------------------------------------------------------------- /notebook/data/density_air.dat: -------------------------------------------------------------------------------- 1 | # Density of air at different temperatures, at 1 atm pressure 2 | # Column 1: temperature in Celsius degrees 3 | # Column 2: density in kg/m^3 4 | 5 | -10 1.341 6 | -5 1.316 7 | 0 1.293 8 | 5 1.269 9 | 10 1.247 10 | 15 1.225 11 | 20 1.204 12 | 25 1.184 13 | 30 1.164 14 | # Source: Wikipedia (keyword Density) 15 | 16 | -------------------------------------------------------------------------------- /notebook/data/density_water.dat: -------------------------------------------------------------------------------- 1 | # Density of air at different temperatures, at 1 atm pressure 2 | # Column 1: temperature in Celsius degrees 3 | # Column 2: density in kg/m^3 4 | 5 | 0.0 999.8425 6 | 4.0 999.9750 7 | 15.0 999.1026 8 | 20.0 998.2071 9 | 25.0 997.0479 10 | 37.0 993.3316 11 | 50.0 988.04 12 | 100.0 958.3665 13 | # Source: Wikipedia (keyword Density) 14 | 15 | -------------------------------------------------------------------------------- /notebook/data/surges.txt: -------------------------------------------------------------------------------- 1 | MONTHLY EXTREME SURGES 2 | Site,day(dd/mm/yyyy) time (24 hours),minimum surge value (metres),day(dd/mm/yyyy) time (24 hours),maximum surge value (metres) 3 | AVONMOUTH,04/01/2012 04:15,-.633,03/01/2012 05:45,1.396 4 | AVONMOUTH,02/02/2012 04:30,-.77,22/02/2012 14:00,.585 5 | AVONMOUTH,12/03/2012 05:00,-.778,31/03/2012 06:45,.71 6 | AVONMOUTH,01/04/2012 13:45,-.285,01/04/2012 08:00,.607 7 | -------------------------------------------------------------------------------- /notebook/data/extremes.txt: -------------------------------------------------------------------------------- 1 | MONTHLY EXTREMES 2 | Site,day (dd/mm/yyyy) time (24 hours),minimum observed value (metres),day (dd/mm/yyyy) time (24 hours),maximum observed value (metres) 3 | AVONMOUTH,24/01/2012 02:30,.985,24/01/2012 08:00,13.662 4 | AVONMOUTH,10/02/2012 16:00,.406,10/02/2012 08:45,13.606 5 | AVONMOUTH,12/03/2012 04:45,.379,10/03/2012 08:30,14.128 6 | AVONMOUTH,08/04/2012 03:00,.477,09/04/2012 08:45,14.405 7 | -------------------------------------------------------------------------------- /notebook/data/densities.dat: -------------------------------------------------------------------------------- 1 | air 0.0012 2 | gasoline 0.67 3 | ice 0.9 4 | pure water 1.0 5 | seawater 1.025 6 | human body 1.03 7 | limestone 2.6 8 | granite 2.7 9 | iron 7.8 10 | silver 10.5 11 | mercury 13.6 12 | gold 18.9 13 | platinium 21.4 14 | Earth mean 5.52 15 | Earth core 13 16 | Moon 3.3 17 | Sun mean 1.4 18 | Sun core 160 19 | proton 2.8E+14 -------------------------------------------------------------------------------- /notebook/data/constants.txt: -------------------------------------------------------------------------------- 1 | name of constant value dimension 2 | ------------------------------------------------------------ 3 | speed of light 299792458.0 m/s 4 | gravitational constant 6.67259e-11 m**3/kg/s**2 5 | Planck constant 6.6260755e-34 J*s 6 | elementary charge 1.60217733e-19 C 7 | Avogadro number 6.0221367e23 1/mol 8 | Boltzmann constant 1.380658e-23 J/K 9 | electron mass 9.1093897e-31 kg 10 | proton mass 1.6726231e-27 kg 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Introduction to programming for geoscientists 2 | ============================================= 3 | 4 | This course closely follows the text book ["A Primer on Scientific Programming with Python", by Hans Petter Langtangen](http://www.springer.com/mathematics/computational+science+%26+engineering/book/978-3-642-18365-2). 5 | 6 | An updated version of this course can always be found on the [github page](http://ggorman.github.io/Introduction-to-programming-for-geoscientists/) 7 | 8 | ## License 9 | All the course material is licensed under a Creative Commons Attribution 3.0 Unported (CC BY 3.0) (http://creativecommons.org/licenses/by/3.0/) and MIT License - http://opensource.org/licenses/mit-license.html. 10 | -------------------------------------------------------------------------------- /notebook/data/human_evolution.txt: -------------------------------------------------------------------------------- 1 | Species Lived when Adult Adult Brain volume 2 | (mill. yrs) height (m) mass (kg) (cm**3) 3 | ------------------------------------------------------------------------------- 4 | H. habilis 2.2 - 1.6 1.0 - 1.5 33 - 55 660 5 | H. erectus 1.4 - 0.2 1.8 60 850 (early) - 1100 (late) 6 | H. ergaster 1.9 - 1.4 1.9 700 - 850 7 | H. heidelbergensis 0.6 - 0.35 1.8 60 1100 - 1400 8 | H. neanderthalensis 0.35 - 0.03 1.6 55 - 70 1200 - 1700 9 | H. sapiens sapiens 0.2 - present 1.4 - 1.9 50 - 100 1000 - 1850 10 | H. floresiensis 0.10 - 0.012 1.0 25 400 11 | ------------------------------------------------------------------------------- 12 | 13 | Source: http://en.wikipedia.org/wiki/Human_evolution 14 | 15 | -------------------------------------------------------------------------------- /notebook/data/acc.dat: -------------------------------------------------------------------------------- 1 | -0.00506375204384 2 | 0.00500006128645 3 | 0.0100038761223 4 | 0.01504328702 5 | 0.0371053663841 6 | 0.0258707514063 7 | 0.0324886779876 8 | 0.0409580920718 9 | 0.0673519873251 10 | 0.0686671827863 11 | 0.0912393785157 12 | 0.122076505027 13 | 0.19694346743 14 | 0.215055883452 15 | 0.279257312765 16 | 0.355379248594 17 | 0.412586096478 18 | 0.537831608562 19 | 0.638773914959 20 | 0.741057766836 21 | 0.841280639264 22 | 0.930698484064 23 | 1.00831994826 24 | 1.06861112889 25 | 1.09444312198 26 | 1.125 27 | 1.11821862414 28 | 1.08861112889 29 | 1.02259790009 30 | 0.970698484064 31 | 0.890010621484 32 | 0.801057766836 33 | 0.715401683611 34 | 0.617831608562 35 | 0.532298821058 36 | 0.455379248594 37 | 0.37818208082 38 | 0.335055883452 39 | 0.292901103555 40 | 0.262076505027 41 | 0.237854975819 42 | 0.228667182786 43 | 0.222501157101 44 | 0.220958092072 45 | 0.233602968411 46 | 0.225870751406 47 | 0.230236564053 48 | 0.23504328702 49 | 0.197498639303 50 | 0.245000061286 51 | 0.25 52 | 0.255000061286 53 | 0.252271814222 54 | 0.26504328702 55 | 0.270236564053 56 | 0.275870751406 57 | 0.233302904205 58 | 0.290958092072 59 | 0.302501157101 60 | 0.318667182786 61 | 0.299592239593 62 | 0.372076505027 63 | 0.412901103555 64 | 0.465055883452 65 | 0.56915191112 66 | 0.605379248594 67 | 0.692298821058 68 | 0.787831608562 69 | 0.882874020181 70 | 0.991057766836 71 | 1.09001062148 72 | 1.18069848406 73 | 1.26207241488 74 | 1.31861112889 75 | 1.35821862414 76 | 1.375 77 | 1.35919734155 78 | 1.33861112889 79 | 1.28831994826 80 | 1.22069848406 81 | 1.16380671843 82 | 1.05105776684 83 | 0.958773914959 84 | 0.867831608562 85 | 0.792616988369 86 | 0.705379248594 87 | 0.639257312765 88 | 0.585055883452 89 | 0.537012450633 90 | 0.512076505027 91 | 0.491239378516 92 | 0.478667182786 93 | 0.459673639368 94 | 0.470958092072 95 | 0.472488677988 96 | 0.475870751406 97 | 0.499940549512 98 | 0.48504328702 99 | 0.490003876122 100 | 0.495000061286 101 | 0.479565276825 102 | -------------------------------------------------------------------------------- /notebook/data/BrachiopodBiometrics.csv: -------------------------------------------------------------------------------- 1 | Locality,Length/mm,Width/mm 2 | Harper's Quarry,2.3,2.1 3 | Harper's Quarry,2.95,2.85 4 | Harper's Quarry,3.1,2.8 5 | Harper's Quarry,3.7,3.5 6 | Harper's Quarry,3.5,4.6 7 | Harper's Quarry,2.35,2.3 8 | Harper's Quarry,4,3.9 9 | Harper's Quarry,4,4.2 10 | Harper's Quarry,2.75,2.55 11 | Harper's Quarry,2.95,2.7 12 | Harper's Quarry,5,5.1 13 | Harper's Quarry,2.7,2.7 14 | Harper's Quarry,3,2.9 15 | Harper's Quarry,3.2,3.4 16 | Harper's Quarry,2.3,2.2 17 | Harper's Quarry,2.75,2.7 18 | Harper's Quarry,3.4,3.2 19 | Harper's Quarry,3.5,3.2 20 | Harper's Quarry,3.75,3.6 21 | Harper's Quarry,2.8,2.75 22 | Harper's Quarry,2.8,2.6 23 | Harper's Quarry,2.5,2.7 24 | Harper's Quarry,3.6,4 25 | Harper's Quarry,3.3,3.2 26 | Harper's Quarry,3.35,3.3 27 | Harper's Quarry,3.7,4.1 28 | Harper's Quarry,3.6,3.45 29 | Pen Cerrig Wood,3,3.2 30 | Pen Cerrig Wood,3.3,3.3 31 | Pen Cerrig Wood,3.3,3.2 32 | Pen Cerrig Wood,2.95,2.9 33 | Pen Cerrig Wood,3.4,3.4 34 | Pen Cerrig Wood,2.3,2.7 35 | Pen Cerrig Wood,4.4,3.9 36 | Pen Cerrig Wood,2.7,2.5 37 | Pen Cerrig Wood,2.8,2.8 38 | Pen Cerrig Wood,3.9,3.6 39 | Pen Cerrig Wood,2.7,3 40 | Pen Cerrig Wood,3.7,3.55 41 | Pen Cerrig Wood,3.8,4 42 | Pen Cerrig Wood,3.1,3.1 43 | Pen Cerrig Wood,2.7,2.2 44 | Pen Cerrig Wood,3.5,3.2 45 | Pen Cerrig Wood,3,3.1 46 | Pen Cerrig Wood,3.3,3.2 47 | Pen Cerrig Wood,3.3,3.3 48 | Pen Cerrig Wood,3.4,3.25 49 | Pen Cerrig Wood,3.1,3 50 | Pen Cerrig Wood,4,4 51 | Pen Cerrig Wood,3.7,3.6 52 | Pen Cerrig Wood,3.2,3.5 53 | Pen Cerrig Wood,3.25,3.2 54 | Pen Cerrig Wood,3.8,3.75 55 | Rorrington Fm,3.45,3.65 56 | Rorrington Fm,5.5,4.65 57 | Rorrington Fm,3.6,3.5 58 | Rorrington Fm,4,3.75 59 | Rorrington Fm,4.75,4.35 60 | Rorrington Fm,4.87,4.16 61 | Rorrington Fm,3.6,3.3 62 | Rorrington Fm,4,3.4 63 | Rorrington Fm,5.25,4.5 64 | Rorrington Fm,4.4,4.45 65 | Rorrington Fm,3.5,2.7 66 | Rorrington Fm,3.3,2.7 67 | Rorrington Fm,2.6,2.7 68 | Rorrington Fm,5.15,4.15 69 | Rorrington Fm,4.05,3.45 70 | Rorrington Fm,3.4,3.75 71 | Rorrington Fm,3.5,3.25 72 | Rorrington Fm,2.1,2.3 73 | Rorrington Fm,4.65,4.5 74 | Rorrington Fm,5.1,5.25 75 | Rorrington Fm,3.9,3.25 76 | Rorrington Fm,3.35,3.5 77 | -------------------------------------------------------------------------------- /notebook/hpip_yakutsk_borehole_data.txt: -------------------------------------------------------------------------------- 1 | "Permafrost borehole data for January. Temperature in deg. Celsius. ""-999"" means missing data. " 2 | 3 | Station_ID=003 4 | Region_ID=024 5 | WMO=24959 6 | Name=Yakutsk 7 | Latitude=62.0 8 | Longitude=129.7 9 | Elevation=98 10 | 11 | YEAR 0.80 m 3.20 m ds 570 surface temp 12 | 13 | 1915 -999.0 -999.0 -46.0 14 | 1916 -25.1 -8.4 -44.0 15 | 1917 -20.7 -6.6 -39.0 16 | 1918 -999.0 -999.0 -40.0 17 | 1919 -999.0 -999.0 -999.0 18 | 1920 -19.2 -6.1 -36.0 19 | 1921 -18.3 -6.0 -40.0 20 | 1922 -999.0 -999.0 -46.0 21 | 1923 -999.0 -6.5 -44.0 22 | 1924 -999.0 -999.0 -33.0 23 | 1925 -999.0 -999.0 -39.0 24 | 1926 -999.0 -999.0 -45.0 25 | 1927 -999.0 -999.0 -43.0 26 | 1928 -999.0 -999.0 -47.0 27 | 1929 -999.0 -6.0 -40.0 28 | 1930 -999.0 -7.3 -51.0 29 | 1931 -17.4 -3.7 -34.0 30 | 1932 -14.5 -2.0 -40.0 31 | 1933 -15.1 -1.4 -39.0 32 | 1934 -16.8 -1.3 -42.0 33 | 1935 -14.3 -999.0 -45.0 34 | 1936 -18.1 -1.3 -42.0 35 | 1937 -18.4 -1.3 -40.0 36 | 1938 -18.9 -999.0 -46.0 37 | 1939 -16.4 -999.0 -38.0 38 | 1940 -12.2 -1.3 -44.0 39 | 1941 -999.0 -1.9 -40.0 40 | 1942 -16.8 -2.1 -41.0 41 | 1943 -11.7 -1.6 -42.0 42 | 1944 -15.0 -1.8 -45.0 43 | 1945 -12.9 -1.7 -45.0 44 | 1946 -15.9 -1.5 -44.0 45 | 1947 -14.3 -1.7 -41.0 46 | 1948 -14.7 -1.7 -40.0 47 | 1949 -11.9 -1.2 -42.0 48 | 1950 -14.3 -1.0 -44.0 49 | 1951 -14.1 -1.3 -48.0 50 | 1952 -13.4 -1.6 -41.0 51 | 1953 -17.0 -2.4 -42.0 52 | 1954 -12.0 -1.3 -40.0 53 | 1955 -10.3 -1.1 -43.0 54 | 1956 -12.9 -1.0 -36.0 55 | 1957 -11.4 -1.7 -44.0 56 | 1958 -12.3 -1.9 -45.0 57 | 1959 -11.4 -2.0 -44.0 58 | 1960 -12.5 -1.8 -46.0 59 | 1961 -999.0 -2.0 -37.0 60 | 1962 -10.4 -1.8 -42.0 61 | 1963 -999.0 -1.9 -37.0 62 | 1964 -10.1 -1.7 -43.0 63 | 1965 -999.0 -0.6 -42.0 64 | 1966 -11.6 -0.8 -41.0 65 | 1967 -7.2 -0.9 -44.0 66 | 1968 -4.9 -0.8 -42.0 67 | 1969 -6.3 -0.6 -42.0 68 | 1970 -10.0 -0.7 -43.0 69 | 1971 -3.8 -0.7 -47.0 70 | 1972 -3.5 -999.0 -37.0 71 | 1973 -12.0 -0.6 -38.0 72 | 1974 -10.9 -1.0 -38.0 73 | 1975 -8.3 -0.8 -39.0 74 | 1976 -8.6 -0.8 -41.0 75 | 1977 -5.9 -0.8 -44.0 76 | 1978 -8.5 -0.7 -999.0 77 | 1979 -4.0 -0.8 -36.0 78 | 1980 -2.9 -0.6 -36.0 79 | 1981 -3.4 -0.6 -43.0 80 | 1982 -7.3 -0.6 -999.0 81 | 1983 -2.4 -0.8 -35.0 82 | 1984 -3.8 -0.7 -43.0 83 | 1985 -5.6 -0.6 -41.0 84 | 1986 -5.7 -0.7 -45.0 85 | 1987 -7.3 -0.7 -41.0 86 | 1988 -6.2 -0.9 -39.0 87 | 1989 -3.3 -0.8 -42.0 88 | 1990 -4.4 -0.5 -32.0 89 | 1991 -3.0 -0.7 -39.0 90 | 1992 -3.5 -0.6 -32.0 91 | 1993 -5.1 -0.5 -45.0 92 | 1994 -5.1 -0.5 -35.0 93 | 1995 -2.9 -0.5 -38.0 94 | 1996 -5.6 -0.5 -37.0 95 | 1997 -4.5 -0.7 -39.0 96 | 1998 -2.9 -0.8 -33.0 97 | 1999 -2.4 -0.4 -36.0 98 | 2000 -1.0 -0.5 -38.0 99 | -------------------------------------------------------------------------------- /notebook/data/hpip_yakutsk_borehole_data.txt: -------------------------------------------------------------------------------- 1 | "Permafrost borehole data for January. Temperature in deg. Celsius. ""-999"" means missing data. " 2 | 3 | Station_ID=003 4 | Region_ID=024 5 | WMO=24959 6 | Name=Yakutsk 7 | Latitude=62.0 8 | Longitude=129.7 9 | Elevation=98 10 | 11 | YEAR 0.80 m 3.20 m ds 570 surface temp 12 | 13 | 1915 -999.0 -999.0 -46.0 14 | 1916 -25.1 -8.4 -44.0 15 | 1917 -20.7 -6.6 -39.0 16 | 1918 -999.0 -999.0 -40.0 17 | 1919 -999.0 -999.0 -999.0 18 | 1920 -19.2 -6.1 -36.0 19 | 1921 -18.3 -6.0 -40.0 20 | 1922 -999.0 -999.0 -46.0 21 | 1923 -999.0 -6.5 -44.0 22 | 1924 -999.0 -999.0 -33.0 23 | 1925 -999.0 -999.0 -39.0 24 | 1926 -999.0 -999.0 -45.0 25 | 1927 -999.0 -999.0 -43.0 26 | 1928 -999.0 -999.0 -47.0 27 | 1929 -999.0 -6.0 -40.0 28 | 1930 -999.0 -7.3 -51.0 29 | 1931 -17.4 -3.7 -34.0 30 | 1932 -14.5 -2.0 -40.0 31 | 1933 -15.1 -1.4 -39.0 32 | 1934 -16.8 -1.3 -42.0 33 | 1935 -14.3 -999.0 -45.0 34 | 1936 -18.1 -1.3 -42.0 35 | 1937 -18.4 -1.3 -40.0 36 | 1938 -18.9 -999.0 -46.0 37 | 1939 -16.4 -999.0 -38.0 38 | 1940 -12.2 -1.3 -44.0 39 | 1941 -999.0 -1.9 -40.0 40 | 1942 -16.8 -2.1 -41.0 41 | 1943 -11.7 -1.6 -42.0 42 | 1944 -15.0 -1.8 -45.0 43 | 1945 -12.9 -1.7 -45.0 44 | 1946 -15.9 -1.5 -44.0 45 | 1947 -14.3 -1.7 -41.0 46 | 1948 -14.7 -1.7 -40.0 47 | 1949 -11.9 -1.2 -42.0 48 | 1950 -14.3 -1.0 -44.0 49 | 1951 -14.1 -1.3 -48.0 50 | 1952 -13.4 -1.6 -41.0 51 | 1953 -17.0 -2.4 -42.0 52 | 1954 -12.0 -1.3 -40.0 53 | 1955 -10.3 -1.1 -43.0 54 | 1956 -12.9 -1.0 -36.0 55 | 1957 -11.4 -1.7 -44.0 56 | 1958 -12.3 -1.9 -45.0 57 | 1959 -11.4 -2.0 -44.0 58 | 1960 -12.5 -1.8 -46.0 59 | 1961 -999.0 -2.0 -37.0 60 | 1962 -10.4 -1.8 -42.0 61 | 1963 -999.0 -1.9 -37.0 62 | 1964 -10.1 -1.7 -43.0 63 | 1965 -999.0 -0.6 -42.0 64 | 1966 -11.6 -0.8 -41.0 65 | 1967 -7.2 -0.9 -44.0 66 | 1968 -4.9 -0.8 -42.0 67 | 1969 -6.3 -0.6 -42.0 68 | 1970 -10.0 -0.7 -43.0 69 | 1971 -3.8 -0.7 -47.0 70 | 1972 -3.5 -999.0 -37.0 71 | 1973 -12.0 -0.6 -38.0 72 | 1974 -10.9 -1.0 -38.0 73 | 1975 -8.3 -0.8 -39.0 74 | 1976 -8.6 -0.8 -41.0 75 | 1977 -5.9 -0.8 -44.0 76 | 1978 -8.5 -0.7 -999.0 77 | 1979 -4.0 -0.8 -36.0 78 | 1980 -2.9 -0.6 -36.0 79 | 1981 -3.4 -0.6 -43.0 80 | 1982 -7.3 -0.6 -999.0 81 | 1983 -2.4 -0.8 -35.0 82 | 1984 -3.8 -0.7 -43.0 83 | 1985 -5.6 -0.6 -41.0 84 | 1986 -5.7 -0.7 -45.0 85 | 1987 -7.3 -0.7 -41.0 86 | 1988 -6.2 -0.9 -39.0 87 | 1989 -3.3 -0.8 -42.0 88 | 1990 -4.4 -0.5 -32.0 89 | 1991 -3.0 -0.7 -39.0 90 | 1992 -3.5 -0.6 -32.0 91 | 1993 -5.1 -0.5 -45.0 92 | 1994 -5.1 -0.5 -35.0 93 | 1995 -2.9 -0.5 -38.0 94 | 1996 -5.6 -0.5 -37.0 95 | 1997 -4.5 -0.7 -39.0 96 | 1998 -2.9 -0.8 -33.0 97 | 1999 -2.4 -0.4 -36.0 98 | 2000 -1.0 -0.5 -38.0 99 | -------------------------------------------------------------------------------- /notebook/battleship.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Battleship\n", 8 | "### You can learn a lot when you are having fun - [Gerard Gorman](http://www.imperial.ac.uk/people/g.gorman)" 9 | ] 10 | }, 11 | { 12 | "cell_type": "code", 13 | "execution_count": null, 14 | "metadata": {}, 15 | "outputs": [], 16 | "source": [ 17 | "import random\n", 18 | "\n", 19 | "def create_board(size):\n", 20 | " ''''Initialise the board using a Python list.'''\n", 21 | " board = []\n", 22 | " for x in range(0, size):\n", 23 | " board.append([\"O\"] * size)\n", 24 | " return board\n", 25 | "\n", 26 | "def print_board(board):\n", 27 | " '''Print out the current board.'''\n", 28 | " for row in board:\n", 29 | " print(\" \".join(row))\n", 30 | " return\n", 31 | "\n", 32 | "def generate_ship(max_ship_size, board_size):\n", 33 | " # We are going to define a ship as a list of board coordinates.\n", 34 | " ship = []\n", 35 | " \n", 36 | " # Randomly select define the size of the ship.\n", 37 | " ship_size = random.randint(1, max_ship_size)\n", 38 | " \n", 39 | " # Randomly define the orientation.\n", 40 | " orientation = random.randint(0, 1)\n", 41 | "\n", 42 | " # Randomly select the seed point for the ship.\n", 43 | " iseed = random.randint(0, board_size)\n", 44 | " jseed = random.randint(0, board_size)\n", 45 | "\n", 46 | " # Generate ship - here I'm not going to worry if it goes off the edge.\n", 47 | " if orientation==0:\n", 48 | " for i in range(ship_size):\n", 49 | " ship.append((iseed+i, jseed))\n", 50 | " else:\n", 51 | " for j in range(ship_size):\n", 52 | " ship.append((iseed, jseed+j))\n", 53 | "\n", 54 | " return ship\n", 55 | " \n", 56 | "# Set the size of the board and initialise the board.\n", 57 | "board_size = 10\n", 58 | "board = create_board(board_size)\n", 59 | "print_board(board)\n", 60 | "\n", 61 | "# Add the ship\n", 62 | "ship = generate_ship(6, board_size)\n", 63 | "\n", 64 | "print(\"Let's play Battleship!\")\n", 65 | "\n", 66 | "for turn in range(4):\n", 67 | " try:\n", 68 | " row = int(input(\"Guess row:\"))\n", 69 | " if row<0 or row>board_size-1:\n", 70 | " raise ValueError\n", 71 | " except:\n", 72 | " print(\"Value must be an integer between 0 and %d. Try again.\"%(board_size))\n", 73 | " continue\n", 74 | "\n", 75 | " try:\n", 76 | " column = int(input(\"Guess column:\"))\n", 77 | " if column<0 or column>board_size-1:\n", 78 | " raise ValueError\n", 79 | " except:\n", 80 | " print(\"Value must be an integer between 0 and %d. Try again.\"%(board_size))\n", 81 | " continue\n", 82 | " \n", 83 | " if (row, column) in ship:\n", 84 | " print(\"Congratulations! You sunk my battleship!\")\n", 85 | " break\n", 86 | " else:\n", 87 | " if turn == 3:\n", 88 | " board[row][column] = \"X\"\n", 89 | " print_board(board)\n", 90 | " print(\"Game Over\")\n", 91 | " else:\n", 92 | " board[row][column] = \"X\"\n", 93 | " print_board(board)" 94 | ] 95 | }, 96 | { 97 | "cell_type": "code", 98 | "execution_count": null, 99 | "metadata": { 100 | "collapsed": true 101 | }, 102 | "outputs": [], 103 | "source": [] 104 | } 105 | ], 106 | "metadata": { 107 | "kernelspec": { 108 | "display_name": "Python 3.6", 109 | "language": "python", 110 | "name": "python36" 111 | }, 112 | "language_info": { 113 | "codemirror_mode": { 114 | "name": "ipython", 115 | "version": 3 116 | }, 117 | "file_extension": ".py", 118 | "mimetype": "text/x-python", 119 | "name": "python", 120 | "nbconvert_exporter": "python", 121 | "pygments_lexer": "ipython3", 122 | "version": "3.6.0" 123 | } 124 | }, 125 | "nbformat": 4, 126 | "nbformat_minor": 1 127 | } 128 | -------------------------------------------------------------------------------- /notebook/Revision-2-Introduction-to-programming-for-geoscientists-Exercises.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "metadata": { 3 | "name": "Revision-2-Introduction-to-programming-for-geoscientists-Exercises" 4 | }, 5 | "nbformat": 3, 6 | "nbformat_minor": 0, 7 | "worksheets": [ 8 | { 9 | "cells": [ 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "#Introduction to programming for Geoscientists (through Python)\n", 15 | "###[Gerard Gorman](http://www.imperial.ac.uk/people/g.gorman), [Christian Jacobs](http://www.imperial.ac.uk/people/c.jacobs10)" 16 | ] 17 | }, 18 | { 19 | "cell_type": "markdown", 20 | "metadata": {}, 21 | "source": [ 22 | "#Revision Workshop 2" 23 | ] 24 | }, 25 | { 26 | "cell_type": "markdown", 27 | "metadata": {}, 28 | "source": [ 29 | "* **Vectorised function**\n", 30 | "Let $A$ be the two-dimensional array\n", 31 | "$$\n", 32 | "\\mathbf{A} = \\left\\lbrack\\begin{array}{ccc}\n", 33 | "0 & 12 & -1\\cr\n", 34 | "-1 & -1 & -1\\cr\n", 35 | "11 & 5 & 5\n", 36 | "\\end{array}\\right\\rbrack\n", 37 | "$$\n", 38 | "Implement and apply the function\n", 39 | "\n", 40 | "$$\n", 41 | "f(x) = x^3 + xe^x + 1\n", 42 | "$$\n", 43 | "\n", 44 | "to each element in $A$. Then calculate the result of the array expression $A^3 + Ae^A + 1$, and demonstrate that the end result of the two methods are the same." 45 | ] 46 | }, 47 | { 48 | "cell_type": "markdown", 49 | "metadata": {}, 50 | "source": [ 51 | "* **Plot the viscosity of water**\n", 52 | "The viscosity of water, $\\mu$, varies with the temperature $T$ (in Kelvin) according to\n", 53 | "\n", 54 | "$$\n", 55 | "\\mu = A\\times 10^{B/(T-C)}\n", 56 | "$$\n", 57 | "\n", 58 | "where $A$ = $2.414 \\times 10^{\u22125}$ Pa s, $B$ = 247.8 K, and $C$ = 140 K. Plot $\\mu(T)$ for $T$ between 0 and 100 degrees Celsius. Label the $x$ axis with \"temperature (C)\" and the $y$ axis with \"viscosity (Pa s)\". Note that $T$ in the formula for $\\mu$ must be in Kelvin." 59 | ] 60 | }, 61 | { 62 | "cell_type": "markdown", 63 | "metadata": {}, 64 | "source": [ 65 | "* **Explore a function graphically**\n", 66 | "The wave speed $c$ of water surface waves depends on the length $\\lambda$ of the waves. The following formula relates $c$ to $\\lambda$:\n", 67 | "\n", 68 | "$$\n", 69 | "c(\\lambda) = \\sqrt{\\frac{g\\lambda}{2\\pi}\\left(1 + s\\frac{4\\pi^2}{\\rho g \\lambda^2}\\right)\\tanh\\left(\\frac{2\\pi h}{\\lambda}\\right)}\n", 70 | "$$\n", 71 | "\n", 72 | "where $g$ is the acceleration of gravity, $s$ is the air-water surface tension ($7.9 \\times 10^{-2}$ N/m), $\\rho$ is the density of water (can be taken as 1000 kg/m$^3$ ), and $h$ is the water depth. Let us fix $h$ at 50 m. First make a plot of $c(\\lambda)$ for small $\\lambda$ (1 mm to 10 cm). Then make a plot $c(\\lambda)$ for larger $\\lambda$ (1 m to 2 km).\n" 73 | ] 74 | }, 75 | { 76 | "cell_type": "markdown", 77 | "metadata": {}, 78 | "source": [ 79 | "* **Load experimental data from a file and plot it**\n", 80 | "Suppose we have measured the oscillation period $T$ of a simple pendulum with a mass $m$ at the end of a massless rod of length $L$. We have varied $L$ and recorded the corresponding $T$ value. The measurements are found in a file *data/pendulum.dat*, containing two columns. The first column contains $L$ values and the second column has the corresponding $T$ values.\n", 81 | "Load the $L$ and $T$ values into two arrays. Plot $L$ versus $T$ using circles for the data points." 82 | ] 83 | }, 84 | { 85 | "cell_type": "markdown", 86 | "metadata": {}, 87 | "source": [ 88 | "* **Make a class for linear springs**\n", 89 | "To elongate a spring a distance x, one needs to pull the spring with a force $kx$. The parameter $k$ is known as the spring constant. The corresponding potential energy in the spring is $\\frac{1}{2}kx$. Make a class for springs. Let the constructor \\_\\_init\\_\\_ store $k$ as a class attribute, and implement the methods *force(x)* and *energy(x)* for evaluating the force and the potential energy, respectively." 90 | ] 91 | } 92 | ], 93 | "metadata": {} 94 | } 95 | ] 96 | } -------------------------------------------------------------------------------- /notebook/data/vp.dat: -------------------------------------------------------------------------------- 1 | Depth (m) Acoustic velocity (m/s) 2 | 0 nan 3 | 20 nan 4 | 40 nan 5 | 60 nan 6 | 80 nan 7 | 100 nan 8 | 120 nan 9 | 140 nan 10 | 160 nan 11 | 180 nan 12 | 200 nan 13 | 220 nan 14 | 240 nan 15 | 260 nan 16 | 280 nan 17 | 300 nan 18 | 320 nan 19 | 340 nan 20 | 360 nan 21 | 380 nan 22 | 400 nan 23 | 420 2016 24 | 440 2028 25 | 460 2040 26 | 480 2052 27 | 500 2064 28 | 520 2076 29 | 540 2088 30 | 560 2100 31 | 580 2112 32 | 600 2124 33 | 620 2136 34 | 640 2148 35 | 660 2160 36 | 680 2172 37 | 700 2184 38 | 720 2196 39 | 740 2208 40 | 760 2220 41 | 780 2232 42 | 800 2244 43 | 820 2256 44 | 840 2268 45 | 860 2280 46 | 880 2292 47 | 900 2304 48 | 920 2316 49 | 940 2328 50 | 960 2340 51 | 980 2352 52 | 1000 2364 53 | 1020 2376 54 | 1040 2388 55 | 1060 2400 56 | 1080 2412 57 | 1100 2424 58 | 1120 2436 59 | 1140 2448 60 | 1160 2460 61 | 1180 2472 62 | 1200 2484 63 | 1220 2496 64 | 1240 2508 65 | 1260 2520 66 | 1280 2532 67 | 1300 2544 68 | 1320 2556 69 | 1340 2568 70 | 1360 2580 71 | 1380 2592 72 | 1400 2604 73 | 1420 2616 74 | 1440 2628 75 | 1460 2640 76 | 1480 2652 77 | 1500 2664 78 | 1520 2676 79 | 1540 2688 80 | 1560 2700 81 | 1580 2712 82 | 1600 2724 83 | 1620 2736 84 | 1640 2748 85 | 1660 2760 86 | 1680 2772 87 | 1700 2784 88 | 1720 2796 89 | 1740 2808 90 | 1760 2820 91 | 1780 2832 92 | 1800 2844 93 | 1820 2856 94 | 1840 2868 95 | 1860 2880 96 | 1880 2892 97 | 1900 2904 98 | 1920 2916 99 | 1940 2928 100 | 1960 2940 101 | 1980 2952 102 | 2000 2964 103 | 2020 2976 104 | 2040 2988 105 | 2060 3000 106 | 2080 4900 107 | 2100 4902 108 | 2120 4904 109 | 2140 4906 110 | 2160 4908 111 | 2180 4910 112 | 2200 4912 113 | 2220 4914 114 | 2240 4916 115 | 2260 4918 116 | 2280 3304 117 | 2300 3312 118 | 2320 3320 119 | 2340 3328 120 | 2360 3336 121 | 2380 3344 122 | 2400 3352 123 | 2420 3360 124 | 2440 3368 125 | 2460 3376 126 | 2480 3384 127 | 2500 3392 128 | 2520 3400 129 | 2540 3408 130 | 2560 3416 131 | 2580 3424 132 | 2600 3432 133 | 2620 3440 134 | 2640 3448 135 | 2660 3456 136 | 2680 3464 137 | 2700 3472 138 | 2720 3480 139 | 2740 3488 140 | 2760 3496 141 | 2780 3504 142 | 2800 3512 143 | 2820 3520 144 | 2840 3528 145 | 2860 3536 146 | 2880 3544 147 | 2900 3552 148 | 2920 3560 149 | 2940 3568 150 | 2960 3576 151 | 2980 3584 152 | 3000 3592 153 | 3020 3600 154 | 3040 3950 155 | 3060 3949.4 156 | 3080 3948.8 157 | 3100 3948.2 158 | 3120 3947.6 159 | 3140 3947 160 | 3160 3946.4 161 | 3180 3945.8 162 | 3200 3945.2 163 | 3220 3944.6 164 | 3240 3944 165 | 3260 3943.4 166 | 3280 3942.8 167 | 3300 3942.2 168 | 3320 3941.6 169 | 3340 3941 170 | 3360 3940.4 171 | 3380 3939.8 172 | 3400 3939.2 173 | 3420 3938.6 174 | 3440 3938 175 | 3460 3937.4 176 | 3480 3936.8 177 | 3500 3936.2 178 | 3520 3935.6 179 | 3540 3935 180 | 3560 3934.4 181 | 3580 3933.8 182 | 3600 3933.2 183 | 3620 3932.6 184 | 3640 3932 185 | 3660 3931.4 186 | 3680 3930.8 187 | 3700 3930.2 188 | 3720 3929.6 189 | 3740 3929 190 | 3760 3928.4 191 | 3780 3927.8 192 | 3800 3927.2 193 | 3820 3926.6 194 | 3840 3926 195 | 3860 3925.4 196 | 3880 3924.8 197 | 3900 3924.2 198 | 3920 3923.6 199 | 3940 3923 200 | 3960 3922.4 201 | 3980 3921.8 202 | 4000 3921.2 203 | 4020 3920.6 204 | 4040 3920 205 | 4060 3919.4 206 | 4080 3918.8 207 | 4100 3918.2 208 | 4120 3917.6 209 | 4140 3917 210 | 4160 3916.4 211 | 4180 3915.8 212 | 4200 3915.2 213 | 4220 3914.6 214 | 4240 3914 215 | 4260 3913.4 216 | 4280 3912.8 217 | 4300 3912.2 218 | 4320 3911.6 219 | 4340 3911 220 | 4360 3910.4 221 | 4380 3909.8 222 | 4400 3909.2 223 | 4420 3908.6 224 | 4440 3908 225 | 4460 3907.4 226 | 4480 3906.8 227 | 4500 3906.2 228 | 4520 3905.6 229 | 4540 3905 230 | 4560 3904.4 231 | 4580 3903.8 232 | 4600 3903.2 233 | 4620 3902.6 234 | 4640 3902 235 | 4660 3901.4 236 | 4680 3900.8 237 | 4700 3900.2 238 | 4720 3899.6 239 | 4740 3899 240 | 4760 3898.4 241 | 4780 3897.8 242 | 4800 3600 243 | 4820 3604 244 | 4840 3608 245 | 4860 3612 246 | 4880 3616 247 | 4900 3620 248 | 4920 3624 249 | 4940 3628 250 | 4960 3632 251 | 4980 3636 252 | 5000 3640 253 | 5020 3644 254 | 5040 3648 255 | 5060 3652 256 | 5080 3656 257 | 5100 3660 258 | 5120 3664 259 | 5140 3668 260 | 5160 3672 261 | 5180 3676 262 | 5200 3680 263 | 5220 3684 264 | 5240 3688 265 | 5260 3692 266 | 5280 3696 267 | 5300 3700 268 | 5320 3704 269 | 5340 3708 270 | 5360 3712 271 | 5380 3716 272 | 5400 3720 273 | 5420 3724 274 | 5440 3728 275 | 5460 3732 276 | 5480 3736 277 | 5500 3740 278 | 5520 3744 279 | 5540 3748 280 | 5560 3752 281 | 5580 3756 282 | 5600 3760 283 | 5620 3764 284 | 5640 3768 285 | 5660 3772 286 | 5680 3776 287 | 5700 3780 288 | 5720 3784 289 | 5740 3788 290 | 5760 3792 291 | 5780 3796 292 | 5800 3800 293 | 5820 3804 294 | 5840 3808 295 | 5860 3812 296 | 5880 3816 297 | 5900 3820 298 | 5920 3824 299 | 5940 3828 300 | 5960 3832 301 | 5980 3836 302 | 6000 3840 303 | 6020 3844 304 | 6040 3848 305 | 6060 3852 306 | 6080 3856 307 | 6100 3860 308 | 6120 3864 309 | 6140 3868 310 | 6160 3872 311 | 6180 3876 312 | 6200 3880 313 | 6220 3884 314 | 6240 3888 315 | 6260 3892 316 | 6280 3896 317 | 6300 3900 318 | 6320 3904 319 | 6340 3908 320 | -------------------------------------------------------------------------------- /notebook/python_class_test_2014.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# 2.18 Programming for Geoscientists class test - 14:00-16:00 18th December 2014" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "#Test instructions\n", 15 | "\n", 16 | "* This test contains **5** questions each of which should be answered.\n", 17 | "* Write your program in a Python cell just under each question.\n", 18 | "* You can write an explanation of your solution as comments in your code.\n", 19 | "* In each case your solution program must fulfil all of the instructions - please check the instructions carefully and double check that your program fulfils all of the given instructions.\n", 20 | "* Save your work regularly.\n", 21 | "* At the end of the test you should email your IPython notebook document (i.e. this document) to [Gerard J. Gorman](http://www.imperial.ac.uk/people/g.gorman) at g.gorman@imperial.ac.uk" 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": {}, 27 | "source": [ 28 | "**Question 1** \n", 29 | "\n", 30 | "* Correct the 5 errors in the following program.\n", 31 | "* In each case add a comment explaining the error and the fix.\n", 32 | "* To verify your answer remember that $sin ^2( x ) + cos ^2( x ) = 1$." 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": null, 38 | "metadata": { 39 | "collapsed": false 40 | }, 41 | "outputs": [], 42 | "source": [ 43 | "from math import sin, cos\n", 44 | "x = pi /4\n", 45 | "1_val = sin^2( x ) + cos^2( x )\n", 46 | "print 1_VAL" 47 | ] 48 | }, 49 | { 50 | "cell_type": "markdown", 51 | "metadata": {}, 52 | "source": [ 53 | "**Question 2**\n", 54 | "\n", 55 | "* Create a python list containing 101 evenly spaced values between -1.0 and 1.0.\n", 56 | "* Show how this could be more efficently done using NumPy.\n", 57 | "* Print out the values using a formatted print statement." 58 | ] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": null, 63 | "metadata": { 64 | "collapsed": false 65 | }, 66 | "outputs": [], 67 | "source": [] 68 | }, 69 | { 70 | "cell_type": "markdown", 71 | "metadata": {}, 72 | "source": [ 73 | "**Question 3**\n", 74 | "\n", 75 | "* a. Write a python function that evaluates the equation below for input variables $x$ and $t$: $$f(x, t) = e^{-(x-3t)^2} \\sin \\left( 3\\pi \\left( x-t \\right) \\right)$$\n", 76 | "* b. Generate an array of $x$ values in the range $[-3.0, 10]$.\n", 77 | "* c. Using this array of x values, plot the function for $t=0.0$, $t=1.0$ and $t=2.0$." 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": null, 83 | "metadata": { 84 | "collapsed": false 85 | }, 86 | "outputs": [], 87 | "source": [] 88 | }, 89 | { 90 | "cell_type": "markdown", 91 | "metadata": {}, 92 | "source": [ 93 | "**Question 4**\n", 94 | "\n", 95 | "* Write a program to read the data file [seismic.dat](https://raw.githubusercontent.com/ggorman/Introduction-to-programming-for-geoscientists/master/notebook/data/seismic.dat) and store the magnitude of the earthquakes (*i.e.* the last column) in an numpy array.\n", 96 | "* How many earthquakes are there above magnitude 6.0?" 97 | ] 98 | }, 99 | { 100 | "cell_type": "code", 101 | "execution_count": null, 102 | "metadata": { 103 | "collapsed": false 104 | }, 105 | "outputs": [], 106 | "source": [] 107 | }, 108 | { 109 | "cell_type": "markdown", 110 | "metadata": {}, 111 | "source": [ 112 | "**Question 5** The file [human_evolution.txt](https://raw.githubusercontent.com/ggorman/Introduction-to-programming-for-geoscientists/master/notebook/data/human_evolution.txt) holds information about various human species and their hight, weight, and brain volume. \n", 113 | "\n", 114 | "* Write a program that reads this file and stores the data in a python dictionary humans.\n", 115 | "* The dictionary key should correspond to the specie name (e.g., “homo erectus”), and the value should be a list containing the corresponding data. For example, humans[\"H. habilis\"] should give [\"2.2 - 1.6\", \"1.0 – 1.5\", \"33 – 55\", \"660\"].\n", 116 | "* Write out the humans dictionary in a formatted tabular form." 117 | ] 118 | }, 119 | { 120 | "cell_type": "code", 121 | "execution_count": null, 122 | "metadata": { 123 | "collapsed": false 124 | }, 125 | "outputs": [], 126 | "source": [] 127 | } 128 | ], 129 | "metadata": { 130 | "kernelspec": { 131 | "display_name": "Python 2", 132 | "language": "python", 133 | "name": "python2" 134 | }, 135 | "language_info": { 136 | "codemirror_mode": { 137 | "name": "ipython", 138 | "version": 2 139 | }, 140 | "file_extension": ".py", 141 | "mimetype": "text/x-python", 142 | "name": "python", 143 | "nbconvert_exporter": "python", 144 | "pygments_lexer": "ipython2", 145 | "version": "2.7.12" 146 | } 147 | }, 148 | "nbformat": 4, 149 | "nbformat_minor": 0 150 | } 151 | -------------------------------------------------------------------------------- /notebook/python_class_test_2017.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# 2.18 Programming for Geoscientists class test 2017" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "# Test instructions\n", 15 | "\n", 16 | "* This test contains **3** questions each of which should be answered.\n", 17 | "* Write your program in a Python cell just under each question.\n", 18 | "* You can write an explanation of your solution as comments in your code.\n", 19 | "* In each case your solution program must fulfil all of the instructions - please check the instructions carefully and double check that your program fulfils all of the given instructions.\n", 20 | "* Save your work regularly.\n", 21 | "* At the end of the test you should email your notebook document (i.e. this document) to [Gerard J. Gorman](http://www.imperial.ac.uk/people/g.gorman) at g.gorman@imperial.ac.uk" 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": {}, 27 | "source": [ 28 | "**1.** The following cells contain at least one programming bug each. For each cell add a comment to identify and explain the bug, and correct the program." 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": null, 34 | "metadata": { 35 | "collapsed": true 36 | }, 37 | "outputs": [], 38 | "source": [ 39 | "# Q. 1.1\n", 40 | "\n", 41 | "v = sqrt(2)" 42 | ] 43 | }, 44 | { 45 | "cell_type": "code", 46 | "execution_count": null, 47 | "metadata": { 48 | "collapsed": true 49 | }, 50 | "outputs": [], 51 | "source": [ 52 | "# Q. 1.2\n", 53 | "\n", 54 | "v = [1, 4, 9, 16]\n", 55 | "v_squared = v*v" 56 | ] 57 | }, 58 | { 59 | "cell_type": "code", 60 | "execution_count": null, 61 | "metadata": { 62 | "collapsed": true 63 | }, 64 | "outputs": [], 65 | "source": [ 66 | "# Q. 1.3\n", 67 | "\n", 68 | "v = [1, 4, 9, 16]\n", 69 | "print(\"The last value in the list is %d\"%v[4])" 70 | ] 71 | }, 72 | { 73 | "cell_type": "code", 74 | "execution_count": null, 75 | "metadata": { 76 | "collapsed": true 77 | }, 78 | "outputs": [], 79 | "source": [ 80 | "# Q. 1.4\n", 81 | "\n", 82 | "if True\n", 83 | " print(\"This is always true\")" 84 | ] 85 | }, 86 | { 87 | "cell_type": "code", 88 | "execution_count": null, 89 | "metadata": { 90 | "collapsed": true 91 | }, 92 | "outputs": [], 93 | "source": [ 94 | "# Q. 1.5\n", 95 | "\n", 96 | "# Print every even number up to 10\n", 97 | "n = 0\n", 98 | "while True:\n", 99 | " if n%2==0:\n", 100 | " print(n)\n", 101 | " n+=1\n", 102 | " if n==10:\n", 103 | " break" 104 | ] 105 | }, 106 | { 107 | "cell_type": "markdown", 108 | "metadata": {}, 109 | "source": [ 110 | "**2.** A path is defined by the following list of *x, y* coordinate positions\n", 111 | "```\n", 112 | "[[0, 0], [1, 0], [1, 1], [2, 1], [2, 2], [3, 2], [3, 3], [4, 3], [4, 4], [5, 4], [5, 5]]\n", 113 | "```\n", 114 | "* Write a function that takes two positions as input and returns the distance between them. The distance between two points is defined as $$\\sqrt((x_i - x_{i-1})^2+(y_i - y_{i-1})^2).$$\n", 115 | "* Write a second function that takes as input the a path represented as above as a list of *x, y* coordinates and returns the total length of the path.\n", 116 | "* Make a line plot of the path. Add x and y labels to your plot." 117 | ] 118 | }, 119 | { 120 | "cell_type": "code", 121 | "execution_count": null, 122 | "metadata": { 123 | "collapsed": true 124 | }, 125 | "outputs": [], 126 | "source": [] 127 | }, 128 | { 129 | "cell_type": "markdown", 130 | "metadata": {}, 131 | "source": [ 132 | "**3.** The data file [borehole.txt](data/borehole.txt) (all of the data files are stored in the sub-folder *data/* of this notebook library) contains measurements taken from a well in the North Sea.\n", 133 | "\n", 134 | "* Read in the depth and porewater pressure from this data file into a numpy array. Notice that some of the data is missing so you should only store depth values that have a porewater pressure measurement.\n", 135 | "* Plot the porewater pressure against depth. Clearly label each axis including units.\n", 136 | "* Adapt your program to also read in Sleeve Friction, and plot this on the same graph as porewater pressure. Add a legend so that the two graphs can be clearly identified." 137 | ] 138 | }, 139 | { 140 | "cell_type": "code", 141 | "execution_count": null, 142 | "metadata": { 143 | "collapsed": true 144 | }, 145 | "outputs": [], 146 | "source": [] 147 | } 148 | ], 149 | "metadata": { 150 | "kernelspec": { 151 | "display_name": "Python 3", 152 | "language": "python", 153 | "name": "python3" 154 | }, 155 | "language_info": { 156 | "codemirror_mode": { 157 | "name": "ipython", 158 | "version": 3 159 | }, 160 | "file_extension": ".py", 161 | "mimetype": "text/x-python", 162 | "name": "python", 163 | "nbconvert_exporter": "python", 164 | "pygments_lexer": "ipython3", 165 | "version": "3.5.4" 166 | } 167 | }, 168 | "nbformat": 4, 169 | "nbformat_minor": 1 170 | } 171 | -------------------------------------------------------------------------------- /notebook/python_class_test_2012.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# 2.18 Programming for Geoscientists class test 2012. " 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "## Note: 2013 was the first time the exam was run using iPython rather than using a text editor and the command line. This iPython version was created for the 2013 class so that they would know what to expect." 15 | ] 16 | }, 17 | { 18 | "cell_type": "markdown", 19 | "metadata": {}, 20 | "source": [ 21 | "# Test instructions\n", 22 | "\n", 23 | "* This test contains **5** questions each of which should be answered.\n", 24 | "* Write your program in a Python cell just under each question.\n", 25 | "* You can write an explanation of your solution as comments in your code.\n", 26 | "* In each case your solution program must fulfil all of the instructions - please check the instructions carefully and double check that your program fulfils all of the given instructions.\n", 27 | "* Save your work regularly.\n", 28 | "* At the end of the test you should email your IPython notebook document (i.e. this document) to [Gerard J. Gorman](http://www.imperial.ac.uk/people/g.gorman) at g.gorman@imperial.ac.uk" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": {}, 34 | "source": [ 35 | "**1.** Ignore this question from 2012 as it deals with material no longer covered." 36 | ] 37 | }, 38 | { 39 | "cell_type": "markdown", 40 | "metadata": {}, 41 | "source": [ 42 | "**2.** Write a program, that creates a *list* $t$ with 6 values, 0.1, 0.2, ..., 0.6. Compute a corresponding *list* $y$ of $y(t)$ values using the formula:\n", 43 | "$$y(t) = v_0t − gt^2,$$\n", 44 | "where $v_0=6.0$ and $g=9.8$.\n", 45 | "\n", 46 | "* Store these two lists, t and y, in a new list t1.\n", 47 | "* Write out a table with a column of t and a column of y values by traversing the data in the nested t1 list.\n", 48 | "* You may use list or NumPy array for t and y.\n", 49 | "* Print out a table header with the column names ’t’ and ’y’.\n", 50 | "* For printing the table, iterate the nested list t1, do not access the previously computed t and y lists directly.\n", 51 | "* Print out the table t1 using format specifiers so that the columns are aligned." 52 | ] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "metadata": {}, 57 | "source": [ 58 | "**3.** The factorial of n, written as n!, is defined as:\n", 59 | "$$n! = n(n − 1)(n − 2)...2\\cdot1,$$\n", 60 | "with the special cases\n", 61 | "$$1! = 1, 0! = 1.$$\n", 62 | "For example, $4! = 4\\cdot3\\cdot2\\cdot1 = 24$, and $2! = 2\\cdot1 = 2$.\n", 63 | "\n", 64 | "* Write a function fact(n) that returns $n!$. You **must** not use the *fact* function from the math module.\n", 65 | "* Return 1 immediately if $x$ is 1 or 0, otherwise use a loop to compute $n!$.\n", 66 | "* The function must be called *fact* and take a single argument called n.\n", 67 | "* The software should check that the supplied value is a non-negative integer. If it is not, raise a ValueError exception." 68 | ] 69 | }, 70 | { 71 | "cell_type": "markdown", 72 | "metadata": {}, 73 | "source": [ 74 | "**4.** A table of temperatures and densities, in units of degrees ($C$) and $kg/m^3$, are given in the file [data/density_air.dat](https://raw.githubusercontent.com/ggorman/Introduction-to-programming-for-geoscientists/master/notebook/data/density_air.dat)\n", 75 | "Write a program that reads in the data from file into a list for temperature (first column) and density (second column) and plots the variation of density against temperature.\n", 76 | "\n", 77 | "* The input file contains blank lines and lines starting with a ’#’, which you must ignore when reading in the data.\n", 78 | "* You may use list or NumPy array for temperature and density.\n", 79 | "* Plot the variation of density against temperature.\n", 80 | "* Label the x axis \"Temperature (Celsius)\" and the y axis \"Density ($kg/m^3$)\".\n", 81 | "* Use the plot title \"Density of air at different temperatures, at 1 atm pressure\".\n", 82 | "* Display a legend with the label ’Air’." 83 | ] 84 | }, 85 | { 86 | "cell_type": "markdown", 87 | "metadata": {}, 88 | "source": [ 89 | "**5.** Based on the data in the file [data/constants.txt](https://raw.githubusercontent.com/ggorman/Introduction-to-programming-for-geoscientists/master/notebook/data/constants.txt), make a dictionary where the keys are the names of the physical constant and the values are a tuple containing the numerical value and the units.\n", 90 | "\n", 91 | "* Use a Python dictionary to store the data.\n", 92 | "* All numerical values should be of type float.\n", 93 | "* Print out the dictionary without any formatting." 94 | ] 95 | }, 96 | { 97 | "cell_type": "code", 98 | "execution_count": null, 99 | "metadata": { 100 | "collapsed": true 101 | }, 102 | "outputs": [], 103 | "source": [] 104 | } 105 | ], 106 | "metadata": { 107 | "kernelspec": { 108 | "display_name": "Python 2", 109 | "language": "python", 110 | "name": "python2" 111 | }, 112 | "language_info": { 113 | "codemirror_mode": { 114 | "name": "ipython", 115 | "version": 2 116 | }, 117 | "file_extension": ".py", 118 | "mimetype": "text/x-python", 119 | "name": "python", 120 | "nbconvert_exporter": "python", 121 | "pygments_lexer": "ipython2", 122 | "version": "2.7.12" 123 | } 124 | }, 125 | "nbformat": 4, 126 | "nbformat_minor": 0 127 | } 128 | -------------------------------------------------------------------------------- /notebook/python_class_test_2016.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# 2.18 Programming for Geoscientists class test 2016" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "# Test instructions\n", 15 | "\n", 16 | "* This test contains **4** questions each of which should be answered.\n", 17 | "* Write your program in a Python cell just under each question.\n", 18 | "* You can write an explanation of your solution as comments in your code.\n", 19 | "* In each case your solution program must fulfil all of the instructions - please check the instructions carefully and double check that your program fulfils all of the given instructions.\n", 20 | "* Save your work regularly.\n", 21 | "* At the end of the test you should email your IPython notebook document (i.e. this document) to [Gerard J. Gorman](http://www.imperial.ac.uk/people/g.gorman) at g.gorman@imperial.ac.uk" 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": {}, 27 | "source": [ 28 | "**1.** The following cells contain at least one programming bug each. For each cell add a comment to identify and explain the bug, and correct the program." 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": null, 34 | "metadata": {}, 35 | "outputs": [], 36 | "source": [ 37 | "# Function to calculate wave velocity.\n", 38 | "def wave_velocity(k, mu, rho):\n", 39 | " vp = sqrt((k+4*mu/3)/rho)\n", 40 | " \n", 41 | " return vp\n", 42 | "\n", 43 | "# Use the function to calculate the velocity of an\n", 44 | "# acoustic wave in water.\n", 45 | "vp = wave_velocity(k=0, mu=2.29e9, rho=1000)" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": null, 51 | "metadata": {}, 52 | "outputs": [], 53 | "source": [ 54 | "print \"Velocity of acoustic wave in water: %d\", vp" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": null, 60 | "metadata": {}, 61 | "outputs": [], 62 | "source": [ 63 | "data = (3.14, 2.29, 10, 12)\n", 64 | "data.append(4)" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": null, 70 | "metadata": {}, 71 | "outputs": [], 72 | "source": [ 73 | "line = \"2015-12-14T06:29:15.740Z,19.4333324,-155.2906647,1.66,2.14,ml,17,248,0.0123,0.36,hv,hv61126056,2015-12-14T06:34:58.500Z,5km W of Volcano, Hawaii,earthquake\"\n", 74 | "latitude = line.split(',')[1]\n", 75 | "longitude = line.split(',')[2]\n", 76 | "print \"longitude, latitude = (%g, %g)\"%(longitude, latitude)" 77 | ] 78 | }, 79 | { 80 | "cell_type": "markdown", 81 | "metadata": {}, 82 | "source": [ 83 | "**2.** The Ricker wavelet is frequently employed to model seismic data. The amplitude of the Ricker wavelet with peak frequency $f$ at time $t$ is computed as:\n", 84 | "\n", 85 | "$$A = (1-2 \\pi^2 f^2 t^2) e^{-\\pi^2 f^2 t^2}$$\n", 86 | "\n", 87 | "* Implement a function which calculates the amplitude of the Ricker wavelet for a given peak frequency $f$ and time $t$.\n", 88 | "* Use a *for loop* to create a python *list* for time ranging from $-0.5$ to $0.5$, using a peak frequency, $f$, of $10$.\n", 89 | "* Using the function created above, calculate a numpy array of the Ricker wavelet amplitudes for these times.\n", 90 | "* Plot a graph of time against Ricker wavelet." 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": null, 96 | "metadata": {}, 97 | "outputs": [], 98 | "source": [] 99 | }, 100 | { 101 | "cell_type": "markdown", 102 | "metadata": {}, 103 | "source": [ 104 | "**3.** The data file [vp.dat](data/vp.dat) (all of the data files are stored in the sub-folder *data/* of this notebook library) contains a profile of the acoustic velocity with respect to depth. Depth is measured with respect to a reference point; therefore the first few entries contain NaN's indicating that they are actually above ground.\n", 105 | "\n", 106 | "* Write a function to read in the depth and acoustic velocity.\n", 107 | "* Ensure you skip the entries that contain NaN's.\n", 108 | "* Store depth and velocities in two seperate numpy arrays.\n", 109 | "* Plot depth against velocity ensuring you label your axis." 110 | ] 111 | }, 112 | { 113 | "cell_type": "code", 114 | "execution_count": null, 115 | "metadata": {}, 116 | "outputs": [], 117 | "source": [] 118 | }, 119 | { 120 | "cell_type": "markdown", 121 | "metadata": {}, 122 | "source": [ 123 | "**4.** The file [BrachiopodBiometrics.csv](data/BrachiopodBiometrics.csv) contains the biometrics of Brachiopods found in 3 different locations.\n", 124 | "\n", 125 | "* Read the data file into a Python *dictionary*.\n", 126 | "* You should use the samples location as the *key*.\n", 127 | "* For each key you should form a Python *list* containing tuples of *length* and *width* of each sample.\n", 128 | "* For each location, calculate the mean length and width of the samples.\n", 129 | "* Print the result for each location using a formatted print statement. The mean values should only be printed to within one decimal place." 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": null, 135 | "metadata": {}, 136 | "outputs": [], 137 | "source": [] 138 | } 139 | ], 140 | "metadata": { 141 | "kernelspec": { 142 | "display_name": "Python 3", 143 | "language": "python", 144 | "name": "python3" 145 | }, 146 | "language_info": { 147 | "codemirror_mode": { 148 | "name": "ipython", 149 | "version": 3 150 | }, 151 | "file_extension": ".py", 152 | "mimetype": "text/x-python", 153 | "name": "python", 154 | "nbconvert_exporter": "python", 155 | "pygments_lexer": "ipython3", 156 | "version": "3.6.2" 157 | } 158 | }, 159 | "nbformat": 4, 160 | "nbformat_minor": 1 161 | } 162 | -------------------------------------------------------------------------------- /notebook/python_class_test_2013.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# 2.18 Programming for Geoscientists class test - 14:00-16:00 12th December 2013" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "# Test instructions\n", 15 | "\n", 16 | "* This test contains **5** questions each of which should be answered.\n", 17 | "* Write your program in a Python cell just under each question.\n", 18 | "* You can write an explanation of your solution as comments in your code.\n", 19 | "* In each case your solution program must fulfil all of the instructions - please check the instructions carefully and double check that your program fulfils all of the given instructions.\n", 20 | "* Save your work regularly.\n", 21 | "* At the end of the test you should email your IPython notebook document (i.e. this document) to [Gerard J. Gorman](http://www.imperial.ac.uk/people/g.gorman) at g.gorman@imperial.ac.uk" 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": {}, 27 | "source": [ 28 | "**1.** Correct the 5 errors in the following program." 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": null, 34 | "metadata": { 35 | "collapsed": true 36 | }, 37 | "outputs": [], 38 | "source": [ 39 | "# Part a\n", 40 | "x=1\n", 41 | "print \"sin(%g)=%g\" % (x, sin(x))\n", 42 | "\n", 43 | "# Part b\n", 44 | "F = 114\n", 45 | "print 5/9*(F-32)\n", 46 | "\n", 47 | "# Part c\n", 48 | "interest = \"0.1%\"\n", 49 | "print \"Growth = %g\" % 42.0*float(interest)\n", 50 | "\n", 51 | "# Part d\n", 52 | "# Table header:\n", 53 | "# Survey Name USGS ID Contributor Year Number of Tracklines KMS Shot\n", 54 | "line = \"Beaufort Sea W-62-77-AR WesternGeco 1977 69 4,987\"\n", 55 | "print \"The year the data was collected was %d\", line[4]\n", 56 | "\n", 57 | "# Part e\n", 58 | "heights = (1.56, 1.67, 1.97, 1.43)\n", 59 | "heights.append(1.81)\n", 60 | "print heights" 61 | ] 62 | }, 63 | { 64 | "cell_type": "markdown", 65 | "metadata": {}, 66 | "source": [ 67 | "**2.** The equation $s=ut-\\frac{1}{2}gt^2$ can be used to describe the height of a ball thrown vertically, where $s$ is the height, $u$ is the initial velocity, $t$ is the time and $g$ is acceleration (assumed here to be $9.81ms^{-2}$). \n", 68 | "\n", 69 | "* Assuming that the initial velocity is $2ms^{-1}$, plot a graph showing how the height varies from $t=0$ to the time it hits the ground, $t=\\frac{2u}{g}$.\n", 70 | "* Use 100 data points to generate your plot.\n", 71 | "* Label both the $x$ and $y$ axis appropriately." 72 | ] 73 | }, 74 | { 75 | "cell_type": "markdown", 76 | "metadata": {}, 77 | "source": [ 78 | "**3.** The Gaussian function can be defined as:\n", 79 | "$$g(x) = ae^{\\frac{(x-b)^2}{2c^2}}-d.$$\n", 80 | "\n", 81 | "* Implement a Python function that evaluates this expression for a given input for x.\n", 82 | "* The parameters $a$, $b$, $c$ and $d$ should be optional arguments to the function with default values 1.0, 0, 1.0 and 0.0 respectively.\n", 83 | "* Use NumPy to create an array of 101 $x$ values uniformly spaced in the range [−1, 1].\n", 84 | "* Use the function you created in the first part to create an array of Gaussian values.\n", 85 | "* Plot the result." 86 | ] 87 | }, 88 | { 89 | "cell_type": "markdown", 90 | "metadata": {}, 91 | "source": [ 92 | "**4.** The file [hpip\\_yakutsk\\_borehole\\_data.txt](https://raw.githubusercontent.com/ggorman/Introduction-to-programming-for-geoscientists/master/notebook/data/hpip_yakutsk_borehole_data.txt) (provided with this IPython notebook file) contains permafrost borehole temperature data (in degrees Celsius) for January between the years 1915 and 2000. By looking at the header of the text file you can see that the 2$^{nd}$ column contains the temperatures at a depth of 0.80m, the 3$^{rd}$ column contains the temperatures at a depth of 3.20m and the 4$^{th}$ column gives the surface temperatures taken from the *World Monthly Surface Climatology dataset (ds570.0)*. A temperature value of \"-999\" indicates that the data value is missing.\n", 93 | "\n", 94 | "* Write a program that reads in this data and plots each of the temperature profiles against the year.\n", 95 | "* Any year that contains missing temperature data (*i.e.* has a value of -999) should be skipped.\n", 96 | "* Label the *x* and *y* axis clearly.\n", 97 | "* Provide a legend and locate it in the best position for the plot." 98 | ] 99 | }, 100 | { 101 | "cell_type": "markdown", 102 | "metadata": {}, 103 | "source": [ 104 | "**5.** Create a Python class for *Igneous Rocks*.\n", 105 | "\n", 106 | "* The class should have the following attributes: *Rock Type*, *Grain Size*, *Usual Colour*, *Composition*, and *Notes*.\n", 107 | "* Add a class method to initialise the class.\n", 108 | "* Add a class method to print out a description of an object of this class.\n", 109 | "* Demonstrate the functionality of the class using the rock *Obsidian* where the grain size is *fine*, the usual colour is *dark*, the composition is *lava glass* and we note that it has a *glassy appearance*.\n", 110 | "* Use the class member function to print out the rock description." 111 | ] 112 | } 113 | ], 114 | "metadata": { 115 | "kernelspec": { 116 | "display_name": "Python 2", 117 | "language": "python", 118 | "name": "python2" 119 | }, 120 | "language_info": { 121 | "codemirror_mode": { 122 | "name": "ipython", 123 | "version": 2 124 | }, 125 | "file_extension": ".py", 126 | "mimetype": "text/x-python", 127 | "name": "python", 128 | "nbconvert_exporter": "python", 129 | "pygments_lexer": "ipython2", 130 | "version": "2.7.12" 131 | } 132 | }, 133 | "nbformat": 4, 134 | "nbformat_minor": 0 135 | } 136 | -------------------------------------------------------------------------------- /notebook/python_class_test_2015-sqt.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# 2.18 Programming for Geoscientists class test - 14:30-16:30 31st August 2016" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "# Test instructions\n", 15 | "\n", 16 | "* This test contains **4** questions each of which should be answered.\n", 17 | "* Write your program in a Python cell just under each question.\n", 18 | "* You can write an explanation of your solution as comments in your code.\n", 19 | "* You should work with the two data files (VostokStation.txt and last_months_earthquakes.csv) in their original form. They must **not** be modified.\n", 20 | "* In each case your solution program must fulfil all of the instructions - please check the instructions carefully and double check that your program fulfils all of the given instructions.\n", 21 | "* Save your work regularly.\n", 22 | "* At the end of the test you should email your IPython notebook document (i.e. this document) to [Gerard J. Gorman](http://www.imperial.ac.uk/people/g.gorman) at g.gorman@imperial.ac.uk" 23 | ] 24 | }, 25 | { 26 | "cell_type": "markdown", 27 | "metadata": {}, 28 | "source": [ 29 | "## Question 1\n", 30 | "\n", 31 | "1. Generate $x$ coordinates between $-1.0$ and $1.0$ (inclusive) with spacing $0.01$, using two different methods: (a) use a Python *for* loop to create a Python *list*; (b) create a numpy array directly (i.e. avoid the use of a Python list).\n", 32 | "2. Use a formatted print statement to print out all the values in the list." 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": null, 38 | "metadata": { 39 | "collapsed": false 40 | }, 41 | "outputs": [], 42 | "source": [] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "metadata": {}, 47 | "source": [ 48 | "## Question 2\n", 49 | "\n", 50 | "The longitudinal wave velocity in a material is given by the equation:\n", 51 | "$$V_p = \\sqrt{\\frac{k+4\\mu/3}{\\rho}},$$\n", 52 | "where $V_p$ is the longitudinal wave velocity, $k$ is the bulk modulus, $\\mu$ is the shear modulus and $\\rho$ is the density. The shear wave velocity is given by the equation:\n", 53 | "$$V_s = \\sqrt{\\frac{\\mu}{\\rho}},$$\n", 54 | "where $V_s$ is the shear velocity.\n", 55 | "\n", 56 | "1. Write a *function* that takes as arguments $k$, $\\mu$ and $\\rho$, and returns $V_p$ and $V_s$.\n", 57 | "2. Use this function to calculate the longitudinal and shear wave velocities for quartz, clay and water using parameters from the table below. Print out the results using a formatted print statement.\n", 58 | "\n", 59 | "| Material | Shear modulus (GPa) | Bulk modulus (GPa) | Density (kg/m^3)|\n", 60 | "|------------------------|---------------------|--------------------|-----------------|\n", 61 | "|Granite | 27 | 70 | 2900 | \n", 62 | "|Marble | 27 | 54 | 2700 |\n", 63 | "|Water | 0 | 2.29 | 1000 |\n" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": null, 69 | "metadata": { 70 | "collapsed": false 71 | }, 72 | "outputs": [], 73 | "source": [] 74 | }, 75 | { 76 | "cell_type": "markdown", 77 | "metadata": {}, 78 | "source": [ 79 | "## Question 3\n", 80 | "\n", 81 | "The file [VostokStation.txt](https://raw.githubusercontent.com/ggorman/Introduction-to-programming-for-geoscientists/master/notebook/data/VostokStation.txt) contains data derived from ice core data at Vostok Station. Each line contains the age of the ice, temperature at which the ice formed, the concentration of carbon dioxide and concentration of methane.\n", 82 | "\n", 83 | "1. Write a program to read in the data and store each column in its own numpy array.\n", 84 | "2. Create three plots: temperature versus years; carbon dioxide level versus years; and methane level versus years. Ensure that the plots are clearly labeled." 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": null, 90 | "metadata": { 91 | "collapsed": false 92 | }, 93 | "outputs": [], 94 | "source": [] 95 | }, 96 | { 97 | "cell_type": "markdown", 98 | "metadata": {}, 99 | "source": [ 100 | "## Question 4\n", 101 | "\n", 102 | "The file [last_months_earthquakes.csv](https://raw.githubusercontent.com/ggorman/Introduction-to-programming-for-geoscientists/master/notebook/data/last_months_earthquakes.csv) contains a list of earthquakes from around the world over the past month. Each field is delimited by a comma.\n", 103 | "\n", 104 | "1. Write a program that reads in the latitude-longitude coordinates, the depth and the magnitude (written as \"mag\" in the header) of each earthquake and stores the results in a numpy array.\n", 105 | "2. Use the coordinates to plot the position of each earthquake as an individual point. Clearly label the plots.\n", 106 | "3. Ensure that the x-axis is bounded between -180 and 180, and the y-axis is bounded between -90 and 90.\n", 107 | "4. Compute the minimum, mean and maximum earthquake depth and magnitude.\n" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": null, 113 | "metadata": { 114 | "collapsed": false 115 | }, 116 | "outputs": [], 117 | "source": [] 118 | } 119 | ], 120 | "metadata": { 121 | "kernelspec": { 122 | "display_name": "Python 2", 123 | "language": "python", 124 | "name": "python2" 125 | }, 126 | "language_info": { 127 | "codemirror_mode": { 128 | "name": "ipython", 129 | "version": 2 130 | }, 131 | "file_extension": ".py", 132 | "mimetype": "text/x-python", 133 | "name": "python", 134 | "nbconvert_exporter": "python", 135 | "pygments_lexer": "ipython2", 136 | "version": "2.7.11" 137 | } 138 | }, 139 | "nbformat": 4, 140 | "nbformat_minor": 0 141 | } 142 | -------------------------------------------------------------------------------- /notebook/python_class_test_2015.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# 2.18 Programming for Geoscientists class test - 14:00-16:00 17th December 2015" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "#Test instructions\n", 15 | "\n", 16 | "* This test contains **4** questions each of which should be answered.\n", 17 | "* Write your program in a Python cell just under each question.\n", 18 | "* You can write an explanation of your solution as comments in your code.\n", 19 | "* You should work with the two data files ([VostokStation.txt](https://raw.githubusercontent.com/ggorman/Introduction-to-programming-for-geoscientists/master/notebook/data/VostokStation.txt) and [last_months_earthquakes.csv](https://raw.githubusercontent.com/ggorman/Introduction-to-programming-for-geoscientists/master/notebook/data/last_months_earthquakes.csv)) in their original form. They must **not** be modified.\n", 20 | "* In each case your solution program must fulfil all of the instructions - please check the instructions carefully and double check that your program fulfils all of the given instructions.\n", 21 | "* Save your work regularly.\n", 22 | "* At the end of the test you should email your IPython notebook document (i.e. this document) to [Christian T. Jacobs](http://www.imperial.ac.uk/people/c.jacobs10) at c.jacobs10@imperial.ac.uk **and also** [Gerard J. Gorman](http://www.imperial.ac.uk/people/g.gorman) at g.gorman@imperial.ac.uk" 23 | ] 24 | }, 25 | { 26 | "cell_type": "markdown", 27 | "metadata": {}, 28 | "source": [ 29 | "##Question 1\n", 30 | "\n", 31 | "1. Generate $x$ coordinates between $1$ and $2$ (inclusive) with spacing $0.01$. The coordinates are given by the formula $x_i = 1 + ih$ where $h=0.01$ and $i$ runs over integers $0,1,...,100$. Compute the $x_i$ values and put them into a python *list*. Use a *for* loop and append each new $x_i$ value to a list that is initially empty.\n", 32 | "2. Use a formatted print statement to print out all the values in the list." 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": null, 38 | "metadata": {}, 39 | "outputs": [], 40 | "source": [] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "metadata": {}, 45 | "source": [ 46 | "##Question 2\n", 47 | "\n", 48 | "The longitudinal wave velocity in a material is given by the equation:\n", 49 | "$$V_p = \\sqrt{\\frac{k+4\\mu/3}{\\rho}},$$\n", 50 | "where $V_p$ is the longitudinal wave velocity, $k$ is the bulk modulus, $\\mu$ is the shear modulus and $\\rho$ is the density. The shear wave velocity is given by the equation:\n", 51 | "$$V_s = \\sqrt{\\frac{\\mu}{\\rho}},$$\n", 52 | "where $V_s$ is the shear velocity.\n", 53 | "\n", 54 | "1. Write a *function* that takes as arguments $k$, $\\mu$ and $\\rho$, and returns $V_p$ and $V_s$.\n", 55 | "2. Use this function to calculate the longitudinal and shear wave velocities for quartz, clay and water using parameters from the table below. Print out the results using a formatted print statement.\n", 56 | "\n", 57 | "| Material | Shear modulus (GPa) | Bulk modulus (GPa) | Density (kg/m^3)|\n", 58 | "|------------------------|---------------------|--------------------|-----------------|\n", 59 | "|Quartz | 44 | 38 | 2650 | \n", 60 | "|Clay | 6.85 | 20.9 | 2580 |\n", 61 | "|Water | 0 | 2.29 | 1000 |\n" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": null, 67 | "metadata": {}, 68 | "outputs": [], 69 | "source": [] 70 | }, 71 | { 72 | "cell_type": "markdown", 73 | "metadata": {}, 74 | "source": [ 75 | "## Question 3\n", 76 | "\n", 77 | "The file [VostokStation.txt](data/VostokStation.txt) in the library data folder contains data derived from ice core data at Vostok Station. Each line contains the age of the ice, temperature at which the ice formed, the concentration of carbon dioxide and concentration of methane.\n", 78 | "\n", 79 | "1. Write a program to read in the data and store each column in its own array.\n", 80 | "2. Create three plots: temperature versus years; carbon dioxide level versus years; and methane level versus years." 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "execution_count": null, 86 | "metadata": {}, 87 | "outputs": [], 88 | "source": [] 89 | }, 90 | { 91 | "cell_type": "markdown", 92 | "metadata": {}, 93 | "source": [ 94 | "## Question 4\n", 95 | "\n", 96 | "The file [last_months_earthquakes.csv](data/last_months_earthquakes.csv) in the data folder contains a list of earthquakes from around the world over the past month. Each field is delimited by a comma.\n", 97 | "\n", 98 | "1. Write a program that reads in the latitude-longitude coordinates, the depth and the magnitude (written as \"mag\" in the header) of each earthquake.\n", 99 | "2. Use the coordinates to plot the position of each earthquake as an individual point.\n", 100 | "3. Ensure that the x-axis is bounded between -180 and 180, and the y-axis is bounded between -90 and 90.\n", 101 | "4. Compute the mean earthquake depth and magnitude.\n" 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": null, 107 | "metadata": {}, 108 | "outputs": [], 109 | "source": [] 110 | } 111 | ], 112 | "metadata": { 113 | "kernelspec": { 114 | "display_name": "Python 3", 115 | "language": "python", 116 | "name": "python3" 117 | }, 118 | "language_info": { 119 | "codemirror_mode": { 120 | "name": "ipython", 121 | "version": 3 122 | }, 123 | "file_extension": ".py", 124 | "mimetype": "text/x-python", 125 | "name": "python", 126 | "nbconvert_exporter": "python", 127 | "pygments_lexer": "ipython3", 128 | "version": "3.6.2" 129 | } 130 | }, 131 | "nbformat": 4, 132 | "nbformat_minor": 1 133 | } 134 | -------------------------------------------------------------------------------- /notebook/data/VostokStation.txt: -------------------------------------------------------------------------------- 1 | ice_age (ka), temperature (degrees C), CO2 (ppmv), CH4 (ppbv) 2 | 5.06, -55.4533, 272.14, 666.93 3 | 5.45, -55.8133, 271.22, 653.54 4 | 5.85, -54.6283, 270.29, 640.15 5 | 6.27, -55.56, 268.39, 594.65 6 | 6.7, -55.71, 266.06, 593.28 7 | 7.14, -52.8083, 263.73, 591.92 8 | 7.57, -55.2983, 261.4, 590.55 9 | 8.01, -55.3233, 259.06, 589.19 10 | 8.44, -54.7833, 256.73, 585.64 11 | 8.87, -54.5533, 254.4, 579.11 12 | 9.31, -55.3967, 252.07, 593.3 13 | 9.76, -54.7733, 255.09, 607.49 14 | 10.24, -56.0417, 257.22, 621.4 15 | 10.74, -57.8517, 257.77, 634.89 16 | 11.24, -58.88, 258.31, 648.38 17 | 11.74, -58.5933, 258.86, 661.87 18 | 12.32, -57.3717, 257.58, 650.61 19 | 12.94, -59.1567, 255.66, 624.17 20 | 13.55, -60.6467, 253.75, 500.31 21 | 14.17, -61.6367, 251.83, 496.15 22 | 14.78, -62.8317, 249.91, 592.5 23 | 15.39, -63.7617, 247.99, 640.33 24 | 16.01, -64.6567, 246.07, 593.7 25 | 16.69, -63.66, 240.5, 466.61 26 | 17.48, -64.9317, 230.26, 435.7 27 | 18.26, -64.41, 220.02, 424.48 28 | 19.05, -64.3667, 209.79, 413.27 29 | 19.83, -65.2717, 199.55, 402.06 30 | 20.63, -64.62, 193.11, 388.12 31 | 21.45, -64.765, 193.43, 369.51 32 | 22.28, -63.415, 193.74, 356.85 33 | 23.11, -63.9, 194.05, 353.02 34 | 23.93, -64.135, 194.37, 376.64 35 | 24.76, -64.99, 195.13, 365.26 36 | 25.6, -63.755, 196.21, 349.99 37 | 26.43, -62.9483, 197.29, 381.42 38 | 27.27, -64.5567, 198.37, 403.16 39 | 28.1, -63.5867, 199.45, 395.28 40 | 28.93, -64.24, 199.81, 387.39 41 | 29.74, -63.0183, 199.41, 391.67 42 | 30.56, -63.6917, 199.02, 407.48 43 | 31.38, -62.755, 198.63, 416.47 44 | 32.19, -61.185, 198.24, 419 45 | 33, -61.6017, 201.8, 421.53 46 | 33.79, -63.265, 211.31, 425.3 47 | 34.59, -62.8517, 220.81, 430.79 48 | 35.37, -62.4017, 217.71, 488.22 49 | 36.16, -62.7617, 210.85, 536.7 50 | 36.94, -62.1333, 207.51, 508.13 51 | 37.71, -62.3433, 208.66, 476.62 52 | 38.48, -62.3117, 209.82, 474.92 53 | 39.24, -60.76, 209.48, 481.14 54 | 40.01, -61.745, 208.87, 473.2 55 | 40.77, -61.4483, 208.25, 453.2 56 | 41.53, -62.96, 207.63, 433.2 57 | 42.3, -62.705, 207.02, 427.04 58 | 43.06, -63.0467, 201.24, 432.67 59 | 43.82, -62.7417, 195.3, 438.3 60 | 44.58, -62.4933, 189.37, 436.13 61 | 45.34, -61.955, 183.43, 426.77 62 | 46.1, -61.7833, 179.86, 417.3 63 | 46.85, -61.5017, 187.85, 407.3 64 | 47.61, -61.8767, 195.84, 415.14 65 | 48.36, -61.4, 201.49, 443.08 66 | 49.1, -62.0433, 204.6, 468.87 67 | 49.85, -61.31, 207.7, 484.84 68 | 50.6, -62.7633, 206.42, 500.81 69 | 51.34, -62.305, 205.15, 495.58 70 | 52.09, -60.9617, 203.87, 485.05 71 | 52.84, -60.1867, 202.6, 486.85 72 | 53.58, -59.5267, 201.32, 500.03 73 | 54.35, -60.72, 201, 513.21 74 | 55.12, -61.4967, 201, 519.33 75 | 55.9, -61.3783, 204.78, 525 76 | 56.69, -62.32, 211.41, 512.51 77 | 57.49, -62.9817, 218.04, 479.56 78 | 58.3, -63.5883, 217.91, 446.61 79 | 59.11, -62.3283, 215.88, 431.71 80 | 59.94, -63.8567, 213.48, 419.74 81 | 60.78, -64.1017, 210.29, 411.32 82 | 61.63, -64.4217, 207.11, 412.52 83 | 62.5, -63.455, 204.63, 413.71 84 | 63.38, -63.7517, 202.32, 414.32 85 | 64.26, -62.105, 199.56, 414.74 86 | 65.13, -62.83, 196.2, 417.81 87 | 66.01, -62.7333, 192.84, 425.41 88 | 66.88, -61.8267, 192.36, 433.01 89 | 67.74, -62.7717, 192.83, 430.68 90 | 68.59, -63.1083, 195.81, 426.86 91 | 69.43, -62.96, 200.14, 427.44 92 | 70.27, -61.705, 204.46, 441.21 93 | 71.1, -60.3583, 212.63, 454.97 94 | 71.93, -61.5683, 222, 449.26 95 | 72.75, -63.2367, 229.73, 438.06 96 | 73.57, -61.7233, 235.93, 433.53 97 | 74.39, -62.46, 242.13, 446.13 98 | 75.19, -61.5367, 239.98, 458.72 99 | 75.99, -60.0633, 236.47, 444.31 100 | 76.79, -59.7833, 233.93, 420.41 101 | 77.58, -59.1233, 232.1, 405.39 102 | 78.37, -59.9767, 229.95, 420.15 103 | 79.15, -59.195, 225.77, 434.9 104 | 79.93, -59.98, 221.59, 457.1 105 | 80.7, -59.2417, 219.8, 481.28 106 | 81.47, -58.14, 220.39, 504.24 107 | 82.24, -59.055, 220.98, 524.93 108 | 83.01, -59.7683, 221.57, 545.53 109 | 83.78, -60.2333, 222.16, 563.35 110 | 84.55, -60.2983, 224.42, 581.17 111 | 85.33, -59.8583, 228.88, 586.42 112 | 86.1, -61.16, 233.33, 559.33 113 | 86.88, -62.1217, 228.31, 532.25 114 | 87.65, -61.825, 221.61, 496.31 115 | 88.43, -60.5467, 216.76, 459.17 116 | 89.21, -61.3983, 213.26, 424.68 117 | 89.99, -60.695, 210.35, 420.68 118 | 90.78, -59.6283, 215.3, 418.02 119 | 91.56, -60.7333, 220.26, 430.78 120 | 92.35, -60.4733, 222.77, 443.54 121 | 93.15, -59.9283, 224.47, 453.22 122 | 93.94, -60.245, 226.31, 448.91 123 | 94.73, -60.8333, 229.41, 444.6 124 | 95.53, -60.57, 232.51, 433.08 125 | 96.33, -59.615, 232.59, 417.34 126 | 97.13, -59.805, 229.88, 406.11 127 | 97.93, -59.7467, 227.18, 406.5 128 | 98.74, -59.3617, 229.6, 406.88 129 | 99.55, -58.7817, 233.73, 423.21 130 | 100.38, -58.3733, 234.1, 446.36 131 | 101.23, -58.9817, 229.87, 469.52 132 | 102.08, -60.1833, 225.63, 479.35 133 | 102.97, -59.9083, 226.38, 509.63 134 | 103.87, -60.405, 228.01, 506.34 135 | 104.78, -59.9883, 230.58, 501.91 136 | 105.71, -60.29, 234.62, 524.74 137 | 106.65, -60.3517, 238.44, 547.58 138 | 107.64, -62.8617, 236.94, 566.55 139 | 108.62, -62.4217, 235.44, 581.64 140 | 109.6, -62.105, 236.2, 573.31 141 | 110.57, -61.5667, 240.79, 463.41 142 | 111.53, -61.9633, 242.88, 444.23 143 | 112.45, -62.2983, 239.16, 452.74 144 | 113.37, -62.1067, 235.43, 459.43 145 | 114.27, -61.1567, 234.87, 466.13 146 | 115.15, -60.2167, 237.72, 463.5 147 | 116.02, -60.1783, 242.53, 457.25 148 | 116.85, -58.8933, 255.16, 451 149 | 117.68, -58.5483, 267.79, 445.98 150 | 118.5, -57.435, 275.36, 453.58 151 | 119.29, -57.5033, 273.52, 490.88 152 | 120.09, -56.9833, 271.68, 499.06 153 | 120.85, -56.8017, 274.51, 507.23 154 | 121.61, -56.85, 277.86, 515.59 155 | 122.36, -56.695, 278.75, 527.43 156 | 123.1, -55.8183, 275.28, 539.27 157 | 123.83, -55.9717, 271.81, 547.55 158 | 124.54, -54.9333, 269.32, 553.45 159 | 125.25, -55.2617, 266.93, 557.96 160 | 125.95, -56.0483, 265.96, 560.37 161 | 126.65, -55.3883, 268.01, 564.12 162 | 127.34, -54.6183, 270.06, 570.75 163 | 128.04, -54.925, 272.11, 577.37 164 | 128.74, -54.6783, 274.16, 584 165 | 129.44, -55.0117, 273.23, 585.04 166 | 130.15, -54.7217, 270.22, 586.6 167 | 130.86, -53.8433, 267.22, 594.07 168 | 131.57, -53.09, 269.27, 601.54 169 | 132.29, -53.3583, 272.92, 609.02 170 | 133.01, -52.33, 273.44, 616.49 171 | 133.74, -53.585, 269.81, 629.03 172 | 134.47, -55.6483, 266.18, 646.08 173 | 135.24, -53.9067, 277.41, 649.35 174 | 136, -55.035, 289.42, 693.41 175 | 136.8, -55.9433, 291.71, 600.31 176 | 137.64, -57.925, 280.02, 532.7 177 | 138.49, -58.29, 268.34, 527.77 178 | 139.43, -59.5067, 260, 509.61 179 | 140.4, -61.1133, 252.5, 483.99 180 | 141.39, -62.845, 245, 458.38 181 | 142.49, -63.3067, 237.51, 445.28 182 | 143.61, -63.055, 230.31, 435.5 183 | 144.89, -64.95, 225.05, 419.71 184 | 146.18, -64.8983, 219.79, 398.54 185 | 147.58, -63.915, 211.62, 352.91 186 | 149.11, -64.1667, 200.16, 363.05 187 | 150.67, -63.9183, 191.69, 369.66 188 | 152.35, -64.7883, 195.12, 337.2 189 | 154.02, -63.9667, 198.55, 318.25 190 | 155.7, -64.6783, 198.89, 318.94 191 | 157.38, -64.18, 195.15, 339.4 192 | 159.05, -64.9233, 191.41, 348.54 193 | 160.73, -64.2083, 192.8, 353.25 194 | -------------------------------------------------------------------------------- /notebook/data/precipitation.csv: -------------------------------------------------------------------------------- 1 | 37.5 , 106.6 , 110.7 , 28.3 , 48.3 , 58.3 , 37.3 , 81.1 , 39.4 , 107.6 , 106.7 , 87.9 2 | 37.3 , 27.6 , 50.2 , 49.3 , 46.8 , 63.5 , 85.8 , 135.1 , 48.6 , 107.4 , 31.1 , 32.9 3 | 77.5 , 30.3 , 24.2 , 81.5 , 50.8 , 24.4 , 104.2 , 35.0 , 151.1 , 40.3 , 57.8 , 65.3 4 | 116.5 , 65.6 , 106.3 , 63.6 , 9.1 , 24.7 , 55.8 , 71.7 , 41.8 , 23.9 , 51.4 , 121.4 5 | 79.2 , 14.3 , 44.8 , 79.6 , 36.1 , 58.8 , 116.9 , 31.8 , 65.7 , 52.9 , 37.1 , 65.3 6 | 70.8 , 12.1 , 34.5 , 29.1 , 35.5 , 5.8 , 7.3 , 46.6 , 33.8 , 26.0 , 51.9 , 43.0 7 | 86.9 , 62.5 , 51.8 , 82.3 , 27.4 , 34.3 , 92.2 , 84.2 , 47.5 , 24.5 , 40.3 , 81.1 8 | 36.6 , 103.4 , 59.3 , 64.5 , 58.9 , 11.0 , 58.8 , 58.9 , 56.6 , 142.5 , 41.4 , 73.1 9 | 71.5 , 13.1 , 32.3 , 73.7 , 100.1 , 65.8 , 91.4 , 67.9 , 106.0 , 110.2 , 64.7 , 101.1 10 | 76.5 , 96.3 , 18.1 , 62.6 , 76.2 , 1.3 , 98.1 , 77.8 , 70.3 , 91.0 , 67.2 , 76.1 11 | 91.6 , 64.3 , 11.1 , 77.9 , 57.3 , 79.2 , 52.1 , 31.5 , 32.5 , 67.6 , 143.8 , 11.1 12 | 63.1 , 100.8 , 72.0 , 45.6 , 30.6 , 82.8 , 78.4 , 105.2 , 138.5 , 51.4 , 77.9 , 93.3 13 | 112.8 , 47.5 , 50.7 , 40.8 , 44.0 , 59.4 , 58.4 , 68.1 , 20.8 , 137.0 , 75.3 , 77.3 14 | 34.0 , 23.1 , 2.0 , 28.8 , 51.3 , 31.2 , 43.3 , 43.1 , 10.4 , 97.8 , 175.6 , 148.8 15 | 92.1 , 21.8 , 36.2 , 55.0 , 64.3 , 18.8 , 61.3 , 70.0 , 80.9 , 41.6 , 121.0 , 72.5 16 | 47.4 , 47.9 , 12.5 , 87.8 , 73.1 , 52.9 , 82.7 , 101.3 , 58.2 , 16.9 , 96.1 , 22.5 17 | 61.3 , 5.9 , 41.9 , 64.5 , 119.9 , 30.4 , 73.2 , 47.7 , 66.6 , 146.4 , 38.7 , 21.4 18 | 52.4 , 70.6 , 74.1 , 25.8 , 57.3 , 41.4 , 44.4 , 22.6 , 74.0 , 44.1 , 28.5 , 14.5 19 | 52.4 , 4.9 , 61.6 , 54.8 , 16.8 , 35.8 , 38.3 , 54.8 , 51.8 , 46.3 , 70.5 , 176.3 20 | 23.4 , 85.2 , 14.8 , 85.9 , 46.7 , 83.1 , 31.2 , 75.0 , 106.3 , 93.5 , 148.2 , 82.8 21 | 112.8 , 56.5 , 40.0 , 43.5 , 14.9 , 100.8 , 102.1 , 15.7 , 75.4 , 42.3 , 101.2 , 58.5 22 | 124.9 , 124.9 , 85.2 , 66.1 , 74.9 , 44.9 , 38.1 , 49.3 , 54.8 , 72.3 , 43.4 , 100.5 23 | 85.9 , 17.9 , 9.9 , 4.2 , 46.9 , 17.1 , 38.3 , 73.9 , 60.5 , 86.6 , 93.6 , 88.2 24 | 127.5 , 29.0 , 38.1 , 74.8 , 33.3 , 42.2 , 72.0 , 63.7 , 19.5 , 154.0 , 144.9 , 41.0 25 | 72.8 , 64.5 , 78.9 , 43.7 , 38.8 , 17.0 , 77.0 , 1.7 , 34.4 , 89.0 , 203.0 , 46.4 26 | 80.7 , 71.0 , 86.1 , 38.6 , 53.0 , 46.4 , 87.5 , 117.3 , 15.4 , 29.4 , 77.9 , 47.0 27 | 84.4 , 20.0 , 64.9 , 35.3 , 83.6 , 13.7 , 51.1 , 75.3 , 43.3 , 94.3 , 48.7 , 81.1 28 | 130.2 , 35.9 , 15.2 , 28.9 , 64.5 , 40.9 , 48.0 , 42.9 , 47.4 , 81.6 , 41.9 , 50.4 29 | 48.1 , 21.7 , 4.6 , 45.0 , 21.2 , 41.9 , 53.2 , 60.5 , 60.8 , 102.9 , 117.0 , 49.4 30 | 50.0 , 49.1 , 28.0 , 31.1 , 57.7 , 57.2 , 103.8 , 42.8 , 52.3 , 80.0 , 7.3 , 98.0 31 | 54.9 , 70.6 , 33.1 , 53.6 , 82.7 , 76.1 , 48.2 , 114.5 , 85.7 , 33.2 , 126.7 , 70.9 32 | 66.8 , 56.8 , 150.7 , 49.4 , 36.0 , 54.7 , 41.5 , 14.3 , 32.7 , 12.5 , 34.4 , 67.4 33 | 125.3 , 37.6 , 20.1 , 36.6 , 79.0 , 66.1 , 31.7 , 96.2 , 52.4 , 56.2 , 46.6 , 86.0 34 | 27.6 , 28.0 , 35.0 , 39.7 , 51.1 , 14.1 , 23.7 , 40.3 , 35.9 , 189.3 , 76.2 , 44.6 35 | 23.2 , 117.3 , 28.0 , 60.7 , 54.5 , 36.4 , 105.5 , 72.2 , 79.2 , 13.4 , 137.9 , 50.7 36 | 88.2 , 138.3 , 96.4 , 66.4 , 58.9 , 44.3 , 53.9 , 112.1 , 89.5 , 30.9 , 161.9 , 58.5 37 | 59.7 , 18.8 , 81.7 , 46.2 , 56.7 , 35.9 , 14.6 , 86.9 , 93.6 , 87.2 , 99.9 , 68.7 38 | 28.4 , 37.4 , 12.1 , 59.0 , 45.6 , 55.9 , 87.5 , 56.3 , 68.3 , 77.9 , 40.9 , 17.8 39 | 35.3 , 64.7 , 73.0 , 8.9 , 62.3 , 91.8 , 77.8 , 76.8 , 62.4 , 61.0 , 131.0 , 59.8 40 | 79.9 , 46.1 , 31.5 , 10.7 , 110.5 , 68.0 , 16.5 , 27.8 , 51.0 , 77.9 , 42.2 , 79.9 41 | 113.7 , 8.9 , 18.1 , 39.1 , 9.1 , 63.0 , 91.3 , 101.7 , 73.4 , 47.0 , 18.3 , 100.0 42 | 50.7 , 97.7 , 38.4 , 5.8 , 32.1 , 39.3 , 94.8 , 81.4 , 83.5 , 50.5 , 70.0 , 60.2 43 | 90.9 , 70.9 , 38.6 , 26.3 , 64.5 , 101.9 , 54.2 , 85.3 , 107.4 , 73.2 , 61.4 , 90.9 44 | 81.1 , 2.4 , 60.8 , 58.6 , 17.6 , 25.5 , 56.0 , 36.2 , 3.0 , 68.8 , 79.5 , 143.4 45 | 78.9 , 67.7 , 48.2 , 19.2 , 49.1 , 57.3 , 98.8 , 102.5 , 115.8 , 167.0 , 132.2 , 97.5 46 | 98.7 , 64.1 , 2.6 , 75.8 , 34.5 , 30.6 , 41.6 , 41.5 , 75.2 , 86.4 , 56.3 , 102.0 47 | 92.2 , 12.5 , 39.1 , 50.3 , 47.0 , 7.5 , 53.7 , 73.4 , 94.0 , 41.7 , 69.7 , 67.7 48 | 23.4 , 19.1 , 85.1 , 73.3 , 41.7 , 65.7 , 38.3 , 87.0 , 63.4 , 51.8 , 141.0 , 21.4 49 | 17.4 , 24.1 , 97.7 , 79.6 , 66.0 , 90.0 , 31.1 , 34.4 , 19.1 , 45.3 , 51.6 , 65.5 50 | 82.9 , 11.6 , 57.1 , 43.8 , 47.8 , 62.4 , 82.1 , 72.4 , 116.2 , 18.0 , 90.4 , 126.9 51 | 45.4 , 105.4 , 15.3 , 105.4 , 56.1 , 80.2 , 75.7 , 92.5 , 36.3 , 129.1 , 52.0 , 79.1 52 | 57.7 , 69.5 , 45.0 , 54.9 , 108.9 , 45.3 , 47.2 , 50.1 , 74.2 , 126.6 , 55.7 , 66.6 53 | 62.6 , 40.0 , 25.7 , 64.2 , 59.8 , 72.9 , 89.3 , 68.4 , 135.5 , 77.8 , 43.6 , 77.1 54 | 87.6 , 45.0 , 65.8 , 29.7 , 80.2 , 26.5 , 60.7 , 74.3 , 20.8 , 4.8 , 108.4 , 70.0 55 | 90.3 , 58.1 , 51.0 , 67.4 , 23.2 , 31.1 , 54.7 , 62.2 , 66.1 , 23.1 , 186.4 , 40.5 56 | 98.4 , 22.4 , 61.1 , 46.0 , 51.8 , 134.4 , 28.4 , 85.5 , 16.0 , 63.6 , 64.1 , 25.3 57 | 73.1 , 61.5 , 56.9 , 57.2 , 54.5 , 39.4 , 33.4 , 18.4 , 31.1 , 26.2 , 78.4 , 94.0 58 | 26.1 , 20.2 , 14.5 , 48.9 , 76.6 , 71.7 , 50.4 , 35.8 , 59.5 , 38.6 , 29.4 , 45.1 59 | 91.8 , 92.5 , 37.6 , 13.1 , 30.4 , 70.6 , 44.2 , 88.1 , 164.7 , 77.1 , 158.5 , 45.8 60 | 108.5 , 31.4 , 91.7 , 51.5 , 56.5 , 15.7 , 31.7 , 32.8 , 122.8 , 26.8 , 60.2 , 32.3 61 | 18.8 , 25.6 , 17.2 , 10.0 , 26.4 , 14.0 , 29.2 , 12.4 , 123.4 , 141.5 , 120.0 , 87.7 62 | 87.6 , 104.9 , 67.7 , 36.3 , 42.9 , 65.8 , 17.8 , 132.8 , 20.3 , 50.9 , 75.6 , 90.7 63 | 96.9 , 59.3 , 67.7 , 57.3 , 63.6 , 45.2 , 74.1 , 42.2 , 23.0 , 5.2 , 21.3 , 144.9 64 | 80.1 , 65.3 , 109.7 , 70.6 , 104.4 , 44.5 , 31.7 , 56.1 , 21.2 , 79.2 , 60.5 , 122.6 65 | 45.9 , 60.0 , 84.2 , 19.1 , 27.7 , 94.0 , 91.5 , 69.5 , 42.5 , 110.1 , 52.9 , 42.8 66 | 34.9 , 23.6 , 131.2 , 43.5 , 82.1 , 34.8 , 41.9 , 43.8 , 115.0 , 95.1 , 40.8 , 84.4 67 | 44.4 , 33.4 , 80.9 , 22.7 , 52.4 , 95.7 , 28.6 , 49.8 , 64.2 , 143.0 , 100.9 , 87.0 68 | 62.5 , 33.3 , 43.1 , 96.2 , 98.5 , 33.3 , 42.7 , 23.8 , 58.9 , 49.0 , 46.5 , 72.1 69 | 112.4 , 38.4 , 69.7 , 5.1 , 81.5 , 31.0 , 25.7 , 35.8 , 84.3 , 89.0 , 102.0 , 75.7 70 | 58.2 , 32.4 , 48.3 , 38.4 , 58.2 , 89.3 , 52.3 , 89.5 , 17.8 , 25.8 , 51.9 , 103.7 71 | 110.1 , 16.0 , 62.3 , 67.9 , 62.0 , 22.0 , 45.0 , 103.8 , 33.9 , 82.5 , 101.4 , 89.6 72 | 18.7 , 36.5 , 68.7 , 57.1 , 46.2 , 85.2 , 68.8 , 48.8 , 39.4 , 198.7 , 73.0 , 27.7 73 | 143.8 , 39.6 , 75.1 , 35.4 , 49.2 , 33.1 , 85.5 , 43.8 , 45.8 , 68.0 , 24.9 , 17.6 74 | 33.2 , 58.8 , 64.4 , 78.6 , 14.3 , 35.7 , 29.1 , 35.7 , 22.9 , 67.3 , 37.9 , 143.8 75 | 98.7 , 122.3 , 8.9 , 41.5 , 7.7 , 56.8 , 15.1 , 33.6 , 38.6 , 79.1 , 41.4 , 60.1 76 | 86.7 , 39.6 , 51.4 , 57.1 , 14.1 , 102.0 , 85.2 , 13.7 , 56.5 , 40.2 , 67.1 , 20.1 77 | 24.9 , 27.7 , 46.3 , 73.8 , 57.5 , 38.6 , 80.1 , 98.6 , 84.1 , 85.1 , 132.8 , 56.4 78 | 90.1 , 7.1 , 29.2 , 84.7 , 56.6 , 57.7 , 60.8 , 34.2 , 127.4 , 112.5 , 56.8 , 133.9 79 | 115.6 , 62.5 , 52.9 , 66.2 , 88.3 , 29.7 , 24.9 , 65.7 , 90.1 , 100.0 , 58.1 , 99.6 80 | 143.1 , 92.4 , 54.1 , 19.5 , 29.7 , 15.9 , 37.1 , 3.4 , 127.8 , 30.3 , 63.2 , 95.3 81 | 57.8 , 69.3 , 35.3 , 31.2 , 43.2 , 20.3 , 38.5 , 65.2 , 23.9 , 50.9 , 122.6 , 24.6 82 | 15.3 , 82.9 , 13.9 , 11.3 , 50.3 , 100.6 , 36.5 , 78.1 , 13.8 , 69.7 , 90.3 , 75.6 83 | 83.7 , 9.1 , 56.5 , 102.1 , 22.6 , 88.6 , 33.2 , 20.8 , 112.9 , 128.1 , 65.8 , 78.4 84 | 96.2 , 27.5 , 33.4 , 58.0 , 41.2 , 76.2 , 29.5 , 108.9 , 102.6 , 64.3 , 42.7 , 109.5 85 | 22.1 , 80.3 , 20.1 , 144.6 , 109.3 , 20.6 , 47.6 , 47.3 , 86.1 , 185.9 , 146.6 , 110.1 86 | 93.1 , 92.9 , 122.4 , 75.7 , 32.2 , 25.8 , 51.5 , 83.4 , 70.1 , 133.0 , 43.0 , 25.2 87 | 69.4 , 79.1 , 44.6 , 42.9 , 78.4 , 58.1 , 69.5 , 43.2 , 37.5 , 88.4 , 175.4 , 137.3 88 | 80.1 , 27.6 , 25.6 , 35.6 , 45.3 , 49.5 , 46.4 , 16.2 , 11.0 , 52.8 , 142.6 , 74.3 89 | 86.3 , 29.7 , 40.5 , 81.8 , 48.7 , 31.1 , 52.0 , 101.8 , 26.7 , 121.0 , 33.4 , 55.9 90 | 34.4 , 21.0 , 48.8 , 46.5 , 28.2 , 35.7 , 57.3 , 49.9 , 48.5 , 91.5 , 50.0 , 64.9 91 | 24.2 , 52.5 , 52.5 , 42.9 , 97.3 , 19.8 , 29.6 , 72.0 , 62.0 , 100.2 , 85.7 , 89.0 92 | 71.9 , 104.5 , 52.7 , 2.3 , 113.5 , 94.3 , 108.2 , 51.0 , 33.7 , 44.4 , 77.8 , 58.4 93 | 99.1 , 22.9 , 89.9 , 63.5 , 100.6 , 38.2 , 69.1 , 72.4 , 64.7 , 62.2 , 97.1 , 39.2 94 | 88.6 , 70.3 , 38.7 , 37.2 , 35.3 , 35.2 , 78.0 , 33.1 , 28.2 , 60.7 , 177.3 , 107.6 95 | 63.5 , 101.5 , 52.0 , 20.2 , 36.6 , 38.6 , 26.8 , 105.8 , 50.4 , 75.6 , 65.4 , 29.3 96 | 102.4 , 53.8 , 15.8 , 4.3 , 25.9 , 83.8 , 49.9 , 74.7 , 36.4 , 33.8 , 39.2 , 91.7 97 | 49.7 , 19.9 , 27.9 , 130.0 , 41.6 , 131.2 , 101.9 , 42.5 , 54.4 , 122.6 , 90.2 , 138.9 98 | 63.6 , 38.5 , 68.6 , 41.1 , 52.9 , 22.5 , 31.8 , 50.6 , 56.2 , 141.1 , 71.5 , 138.6 99 | 181.9 , 130.3 , 38.7 , 63.0 , 83.5 , 38.3 , 53.0 , 109.9 , 13.8 , 108.5 , 135.3 , 55.8 100 | 93.1 , 56.0 , 26.8 , 22.1 , 62.3 , 27.8 , 68.5 , 104.1 , 63.4 , 54.0 , 75.2 , 70.2 101 | 114.1 , 49.1 , 79.7 , 55.6 , 61.3 , 114.4 , 21.6 , 31.0 , 46.4 , 28.7 , 94.9 , 17.4 -------------------------------------------------------------------------------- /notebook/Revision-1-Introduction-to-programming-for-geoscientists-Exercises.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "metadata": { 3 | "name": "", 4 | "signature": "sha256:120c22cc5f5f1abb596b7366aadef3837c4305d74dca5e36bc3c6168e131fea5" 5 | }, 6 | "nbformat": 3, 7 | "nbformat_minor": 0, 8 | "worksheets": [ 9 | { 10 | "cells": [ 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "#Introduction to programming for Geoscientists (through Python)\n", 16 | "###[Gerard Gorman](http://www.imperial.ac.uk/people/g.gorman), [Christian Jacobs](http://www.imperial.ac.uk/people/c.jacobs10)" 17 | ] 18 | }, 19 | { 20 | "cell_type": "markdown", 21 | "metadata": {}, 22 | "source": [ 23 | "#Revision Workshop 1" 24 | ] 25 | }, 26 | { 27 | "cell_type": "markdown", 28 | "metadata": {}, 29 | "source": [ 30 | "**1. Find errors in the coding of formulas**\n", 31 | "Some versions of the program for calculating the formula\n", 32 | "$$F = \\frac{9}{5}C + 32$$\n", 33 | "are listed below. Add comments to each line indicating whether the expression will work correctly. If it does not work correctly then also explain why." 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "collapsed": false, 39 | "input": [ 40 | "C = 21; F = 9/5*C + 32; print F\n", 41 | "C = 21.0; F = (9/5)*C + 32; print F\n", 42 | "C = 21.0; F = 9*C/5 + 32; print F\n", 43 | "C = 21.0; F = 9.*(C/5.0) + 32; print F\n", 44 | "C = 21.0; F = 9.0*C/5.0 + 32; print F\n", 45 | "C = 21; F = 9*C/5 + 32; print F\n", 46 | "C = 21.0; F = (1/5)*9*C + 32; print F\n", 47 | "C = 21; F = (1./5)*9*C + 32; print F" 48 | ], 49 | "language": "python", 50 | "metadata": {}, 51 | "outputs": [] 52 | }, 53 | { 54 | "cell_type": "markdown", 55 | "metadata": {}, 56 | "source": [ 57 | "**2. Index a nested lists**\n", 58 | "We define the following nested list:" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "collapsed": false, 64 | "input": [ 65 | "q = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h']]" 66 | ], 67 | "language": "python", 68 | "metadata": {}, 69 | "outputs": [] 70 | }, 71 | { 72 | "cell_type": "markdown", 73 | "metadata": {}, 74 | "source": [ 75 | "Use the approperiate list index to extract and print:\n", 76 | "\n", 77 | "* the letter *a*,\n", 78 | "* the list *['d', 'e', 'f']*,\n", 79 | "* the last element *h*,\n", 80 | "* the *d* element." 81 | ] 82 | }, 83 | { 84 | "cell_type": "code", 85 | "collapsed": false, 86 | "input": [], 87 | "language": "python", 88 | "metadata": {}, 89 | "outputs": [] 90 | }, 91 | { 92 | "cell_type": "markdown", 93 | "metadata": {}, 94 | "source": [ 95 | "Explain why *q[-1][-2]* has the value *g*." 96 | ] 97 | }, 98 | { 99 | "cell_type": "markdown", 100 | "metadata": {}, 101 | "source": [] 102 | }, 103 | { 104 | "cell_type": "markdown", 105 | "metadata": {}, 106 | "source": [ 107 | "**3. Implement the sum function**\n", 108 | "The standard Python function called *sum* takes a list as argument and computes the sum of the elements in the list:" 109 | ] 110 | }, 111 | { 112 | "cell_type": "code", 113 | "collapsed": false, 114 | "input": [ 115 | "sum([1,3,5,-5])" 116 | ], 117 | "language": "python", 118 | "metadata": {}, 119 | "outputs": [ 120 | { 121 | "metadata": {}, 122 | "output_type": "pyout", 123 | "prompt_number": 1, 124 | "text": [ 125 | "4" 126 | ] 127 | } 128 | ], 129 | "prompt_number": 1 130 | }, 131 | { 132 | "cell_type": "markdown", 133 | "metadata": {}, 134 | "source": [ 135 | "Implement your own version of *sum*." 136 | ] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "collapsed": false, 141 | "input": [], 142 | "language": "python", 143 | "metadata": {}, 144 | "outputs": [] 145 | }, 146 | { 147 | "cell_type": "markdown", 148 | "metadata": {}, 149 | "source": [ 150 | "**4. Construct a double for loop over a nested list**\n", 151 | "Consider the list *q* defined earlier. Construct a double *for* loop (i.e. a loop within a loop) to print out all of the elements in the nested list." 152 | ] 153 | }, 154 | { 155 | "cell_type": "code", 156 | "collapsed": false, 157 | "input": [], 158 | "language": "python", 159 | "metadata": {}, 160 | "outputs": [] 161 | }, 162 | { 163 | "cell_type": "markdown", 164 | "metadata": {}, 165 | "source": [ 166 | "**5. Implement the factorial function**\n", 167 | "The factorial of $n$, written as $n!$, is defined as\n", 168 | "\n", 169 | "$$n! = n(n \u2212 1)(n \u2212 2) \\cdots 2 \\cdot 1,$$\n", 170 | "\n", 171 | "with the special cases\n", 172 | "\n", 173 | "$$1! = 1,$$ $$0! = 1.$$\n", 174 | "\n", 175 | "For example, $4! = 4 \\cdot 3 \\cdot 2 \\cdot 1 = 24$, and $2! = 2 \\cdot 1 = 2$. Write a function *fact(n)* that returns $n!$. Return 1 immediately if $x$ is 1 or 0, otherwise use a loop to compute $n!$." 176 | ] 177 | }, 178 | { 179 | "cell_type": "code", 180 | "collapsed": false, 181 | "input": [], 182 | "language": "python", 183 | "metadata": {}, 184 | "outputs": [] 185 | }, 186 | { 187 | "cell_type": "markdown", 188 | "metadata": {}, 189 | "source": [ 190 | "**6. Add error checking**\n", 191 | "Add in a try-except block to the function *fact(n)*. An exception should be thrown/raised if the number *n* is negative. If an exception occurs, your program should print a helpful error message and quit." 192 | ] 193 | }, 194 | { 195 | "cell_type": "code", 196 | "collapsed": false, 197 | "input": [], 198 | "language": "python", 199 | "metadata": {}, 200 | "outputs": [] 201 | }, 202 | { 203 | "cell_type": "markdown", 204 | "metadata": {}, 205 | "source": [ 206 | "**7. Compute the length of a path**\n", 207 | "Some object is moving along a path in the plane. At $n$ points of time we have recorded the corresponding $(x, y)$ positions of the object:\n", 208 | "$(x_0, y_0), (x_1, y_1), \\ldots, (x_{n-1}, y_{n-1})$. The total length $L$ of the path from $(x_0, y_0)$ to $(x_{n-1}, y_{n-1})$ is the sum of all the individual line segments $(x_{i-1}, y_{i-1})$ to $(x_i, y_i)$, $i = 1, \\ldots, n-1$:\n", 209 | "\n", 210 | "$$L = \\sum_{i=1}^{n-1}{\\sqrt{(x_i - x_{i-1})^2 + (y_i - y_{i-1})^2}}.$$\n", 211 | "\n", 212 | "Make a function *pathlength(x, y)* for computing $L$ according to the formula. The arguments $x$ and $y$ hold all the $x_0, \\ldots, x_{n-1}$ and $y_0, \\ldots, y_{n-1}$ coordinates, respectively. Test the function on a triangular path with the four points (1, 1), (2, 1), (1, 2), and (1, 1)." 213 | ] 214 | }, 215 | { 216 | "cell_type": "code", 217 | "collapsed": false, 218 | "input": [], 219 | "language": "python", 220 | "metadata": {}, 221 | "outputs": [] 222 | }, 223 | { 224 | "cell_type": "markdown", 225 | "metadata": {}, 226 | "source": [ 227 | "**8. How to cook the perfect egg**\n", 228 | "As an egg cooks, the proteins first denature and then coagulate. When the temperature exceeds a critical point, reactions begin and proceed faster as the temperature increases. In the egg white the proteins start to coagulate for temperatures above 63 C, while in the yolk the proteins start to coagulate for temperatures above 70 C. For a soft boiled egg, the white needs to have been heated long enough to coagulate at a temperature above 63 C, but the yolk should not be heated above 70 C. For a hard boiled egg, the center of the yolk should be allowed to reach 70 C. The following formula expresses the time $t$ it takes (in seconds) for the center of the yolk to reach the temperature $T_y$ (in Celsius degrees):\n", 229 | "\n", 230 | "$$t = \\frac{M^{2/3}c\\rho^{1/3}}{K\\pi^2(4\\pi/3)^{2/3}}\\ln\\left[0.76\\frac{T_o - T_w}{T_y - T_w}\\right]$$\n", 231 | "\n", 232 | "Here, $M, \\rho, c$ and $K$ are properties of the egg: $M$ is the mass, $\\rho$ is the density, $c$ is the specific heat capacity, and $K$ is thermal conductivity. Relevant values are $M$ = 47 g for a small egg and $M$ = 67 g for a large egg, $\\rho$ = 1.038 g cm$^{-3}$, $c$ = 3.7 J g$^{-1}$K$^{-1}$, and $K$ = 5.4 $\\times$ 10$^{-3}$ W cm$^{-1}$ K$^{-1}$. Furthermore, $T_w$ is the temperature (in C degrees) of the boiling water, and $T_o$ is the original temperature (in C degrees) of the egg before being put in the water. Implement the formula in a program, set $T_w$ = 100 C and $T_y$ = 70 C, and compute $t$ for a large egg taken from the fridge ($T_o$ = 4 C) and from room temperature ($T_o$ = 20 C). \n" 233 | ] 234 | }, 235 | { 236 | "cell_type": "code", 237 | "collapsed": false, 238 | "input": [], 239 | "language": "python", 240 | "metadata": {}, 241 | "outputs": [] 242 | } 243 | ], 244 | "metadata": {} 245 | } 246 | ] 247 | } -------------------------------------------------------------------------------- /notebook/data/xy.dat: -------------------------------------------------------------------------------- 1 | -1.0000 -0.0000 2 | -0.9933 -0.0087 3 | -0.9867 -0.0179 4 | -0.9800 -0.0274 5 | -0.9733 -0.0374 6 | -0.9667 -0.0477 7 | -0.9600 -0.0583 8 | -0.9533 -0.0691 9 | -0.9467 -0.0802 10 | -0.9400 -0.0915 11 | -0.9333 -0.1029 12 | -0.9267 -0.1144 13 | -0.9200 -0.1260 14 | -0.9133 -0.1375 15 | -0.9067 -0.1489 16 | -0.9000 -0.1601 17 | -0.8933 -0.1711 18 | -0.8867 -0.1819 19 | -0.8800 -0.1923 20 | -0.8733 -0.2023 21 | -0.8667 -0.2117 22 | -0.8600 -0.2207 23 | -0.8533 -0.2290 24 | -0.8467 -0.2365 25 | -0.8400 -0.2434 26 | -0.8333 -0.2494 27 | -0.8267 -0.2544 28 | -0.8200 -0.2585 29 | -0.8133 -0.2616 30 | -0.8067 -0.2636 31 | -0.8000 -0.2644 32 | -0.7933 -0.2641 33 | -0.7867 -0.2624 34 | -0.7800 -0.2595 35 | -0.7733 -0.2553 36 | -0.7667 -0.2497 37 | -0.7600 -0.2427 38 | -0.7533 -0.2343 39 | -0.7467 -0.2245 40 | -0.7400 -0.2132 41 | -0.7333 -0.2005 42 | -0.7267 -0.1864 43 | -0.7200 -0.1708 44 | -0.7133 -0.1539 45 | -0.7067 -0.1356 46 | -0.7000 -0.1160 47 | -0.6933 -0.0951 48 | -0.6867 -0.0730 49 | -0.6800 -0.0497 50 | -0.6733 -0.0254 51 | -0.6667 0.0000 52 | -0.6600 0.0263 53 | -0.6533 0.0534 54 | -0.6467 0.0812 55 | -0.6400 0.1096 56 | -0.6333 0.1385 57 | -0.6267 0.1678 58 | -0.6200 0.1974 59 | -0.6133 0.2270 60 | -0.6067 0.2567 61 | -0.6000 0.2861 62 | -0.5933 0.3152 63 | -0.5867 0.3439 64 | -0.5800 0.3720 65 | -0.5733 0.3993 66 | -0.5667 0.4256 67 | -0.5600 0.4509 68 | -0.5533 0.4750 69 | -0.5467 0.4977 70 | -0.5400 0.5189 71 | -0.5333 0.5384 72 | -0.5267 0.5562 73 | -0.5200 0.5720 74 | -0.5133 0.5857 75 | -0.5067 0.5973 76 | -0.5000 0.6065 77 | -0.4933 0.6134 78 | -0.4867 0.6178 79 | -0.4800 0.6196 80 | -0.4733 0.6188 81 | -0.4667 0.6152 82 | -0.4600 0.6090 83 | -0.4533 0.5999 84 | -0.4467 0.5880 85 | -0.4400 0.5733 86 | -0.4333 0.5557 87 | -0.4267 0.5354 88 | -0.4200 0.5123 89 | -0.4133 0.4864 90 | -0.4067 0.4579 91 | -0.4000 0.4268 92 | -0.3933 0.3932 93 | -0.3867 0.3572 94 | -0.3800 0.3190 95 | -0.3733 0.2786 96 | -0.3667 0.2362 97 | -0.3600 0.1919 98 | -0.3533 0.1460 99 | -0.3467 0.0986 100 | -0.3400 0.0498 101 | -0.3333 -0.0000 102 | -0.3267 -0.0507 103 | -0.3200 -0.1021 104 | -0.3133 -0.1540 105 | -0.3067 -0.2060 106 | -0.3000 -0.2581 107 | -0.2933 -0.3099 108 | -0.2867 -0.3612 109 | -0.2800 -0.4118 110 | -0.2733 -0.4615 111 | -0.2667 -0.5099 112 | -0.2600 -0.5568 113 | -0.2533 -0.6021 114 | -0.2467 -0.6454 115 | -0.2400 -0.6867 116 | -0.2333 -0.7256 117 | -0.2267 -0.7619 118 | -0.2200 -0.7955 119 | -0.2133 -0.8261 120 | -0.2067 -0.8537 121 | -0.2000 -0.8779 122 | -0.1933 -0.8988 123 | -0.1867 -0.9162 124 | -0.1800 -0.9299 125 | -0.1733 -0.9398 126 | -0.1667 -0.9460 127 | -0.1600 -0.9482 128 | -0.1533 -0.9465 129 | -0.1467 -0.9409 130 | -0.1400 -0.9313 131 | -0.1333 -0.9178 132 | -0.1267 -0.9004 133 | -0.1200 -0.8791 134 | -0.1133 -0.8541 135 | -0.1067 -0.8253 136 | -0.1000 -0.7930 137 | -0.0933 -0.7572 138 | -0.0867 -0.7181 139 | -0.0800 -0.6758 140 | -0.0733 -0.6306 141 | -0.0667 -0.5826 142 | -0.0600 -0.5320 143 | -0.0533 -0.4790 144 | -0.0467 -0.4239 145 | -0.0400 -0.3669 146 | -0.0333 -0.3083 147 | -0.0267 -0.2483 148 | -0.0200 -0.1872 149 | -0.0133 -0.1253 150 | -0.0067 -0.0628 151 | 0.0000 0.0000 152 | 0.0067 0.0628 153 | 0.0133 0.1253 154 | 0.0200 0.1872 155 | 0.0267 0.2483 156 | 0.0333 0.3083 157 | 0.0400 0.3669 158 | 0.0467 0.4239 159 | 0.0533 0.4790 160 | 0.0600 0.5320 161 | 0.0667 0.5826 162 | 0.0733 0.6306 163 | 0.0800 0.6758 164 | 0.0867 0.7181 165 | 0.0933 0.7572 166 | 0.1000 0.7930 167 | 0.1067 0.8253 168 | 0.1133 0.8541 169 | 0.1200 0.8791 170 | 0.1267 0.9004 171 | 0.1333 0.9178 172 | 0.1400 0.9313 173 | 0.1467 0.9409 174 | 0.1533 0.9465 175 | 0.1600 0.9482 176 | 0.1667 0.9460 177 | 0.1733 0.9398 178 | 0.1800 0.9299 179 | 0.1867 0.9162 180 | 0.1933 0.8988 181 | 0.2000 0.8779 182 | 0.2067 0.8537 183 | 0.2133 0.8261 184 | 0.2200 0.7955 185 | 0.2267 0.7619 186 | 0.2333 0.7256 187 | 0.2400 0.6867 188 | 0.2467 0.6454 189 | 0.2533 0.6021 190 | 0.2600 0.5568 191 | 0.2667 0.5099 192 | 0.2733 0.4615 193 | 0.2800 0.4118 194 | 0.2867 0.3612 195 | 0.2933 0.3099 196 | 0.3000 0.2581 197 | 0.3067 0.2060 198 | 0.3133 0.1540 199 | 0.3200 0.1021 200 | 0.3267 0.0507 201 | 0.3333 -0.0000 202 | 0.3400 -0.0498 203 | 0.3467 -0.0986 204 | 0.3533 -0.1460 205 | 0.3600 -0.1919 206 | 0.3667 -0.2362 207 | 0.3733 -0.2786 208 | 0.3800 -0.3190 209 | 0.3867 -0.3572 210 | 0.3933 -0.3932 211 | 0.4000 -0.4268 212 | 0.4067 -0.4579 213 | 0.4133 -0.4864 214 | 0.4200 -0.5123 215 | 0.4267 -0.5354 216 | 0.4333 -0.5557 217 | 0.4400 -0.5733 218 | 0.4467 -0.5880 219 | 0.4533 -0.5999 220 | 0.4600 -0.6090 221 | 0.4667 -0.6152 222 | 0.4733 -0.6188 223 | 0.4800 -0.6196 224 | 0.4867 -0.6178 225 | 0.4933 -0.6134 226 | 0.5000 -0.6065 227 | 0.5067 -0.5973 228 | 0.5133 -0.5857 229 | 0.5200 -0.5720 230 | 0.5267 -0.5562 231 | 0.5333 -0.5384 232 | 0.5400 -0.5189 233 | 0.5467 -0.4977 234 | 0.5533 -0.4750 235 | 0.5600 -0.4509 236 | 0.5667 -0.4256 237 | 0.5733 -0.3993 238 | 0.5800 -0.3720 239 | 0.5867 -0.3439 240 | 0.5933 -0.3152 241 | 0.6000 -0.2861 242 | 0.6067 -0.2567 243 | 0.6133 -0.2270 244 | 0.6200 -0.1974 245 | 0.6267 -0.1678 246 | 0.6333 -0.1385 247 | 0.6400 -0.1096 248 | 0.6467 -0.0812 249 | 0.6533 -0.0534 250 | 0.6600 -0.0263 251 | 0.6667 0.0000 252 | 0.6733 0.0254 253 | 0.6800 0.0497 254 | 0.6867 0.0730 255 | 0.6933 0.0951 256 | 0.7000 0.1160 257 | 0.7067 0.1356 258 | 0.7133 0.1539 259 | 0.7200 0.1708 260 | 0.7267 0.1864 261 | 0.7333 0.2005 262 | 0.7400 0.2132 263 | 0.7467 0.2245 264 | 0.7533 0.2343 265 | 0.7600 0.2427 266 | 0.7667 0.2497 267 | 0.7733 0.2553 268 | 0.7800 0.2595 269 | 0.7867 0.2624 270 | 0.7933 0.2641 271 | 0.8000 0.2644 272 | 0.8067 0.2636 273 | 0.8133 0.2616 274 | 0.8200 0.2585 275 | 0.8267 0.2544 276 | 0.8333 0.2494 277 | 0.8400 0.2434 278 | 0.8467 0.2365 279 | 0.8533 0.2290 280 | 0.8600 0.2207 281 | 0.8667 0.2117 282 | 0.8733 0.2023 283 | 0.8800 0.1923 284 | 0.8867 0.1819 285 | 0.8933 0.1711 286 | 0.9000 0.1601 287 | 0.9067 0.1489 288 | 0.9133 0.1375 289 | 0.9200 0.1260 290 | 0.9267 0.1144 291 | 0.9333 0.1029 292 | 0.9400 0.0915 293 | 0.9467 0.0802 294 | 0.9533 0.0691 295 | 0.9600 0.0583 296 | 0.9667 0.0477 297 | 0.9733 0.0374 298 | 0.9800 0.0274 299 | 0.9867 0.0179 300 | 0.9933 0.0087 301 | 1.0000 0.0000 302 | -------------------------------------------------------------------------------- /notebook/Lecture-2-Introduction-to-programming-for-geoscientists-Solutions.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Introduction to programming for Geoscientists (through Python)" 8 | ] 9 | }, 10 | { 11 | "cell_type": "markdown", 12 | "metadata": {}, 13 | "source": [ 14 | "# Lecture 2: Solutions to exercises\n", 15 | "## Gerard J. Gorman (g.gorman@imperial.ac.uk) http://www.imperial.ac.uk/people/g.gorman" 16 | ] 17 | }, 18 | { 19 | "cell_type": "markdown", 20 | "metadata": {}, 21 | "source": [ 22 | "## Exercise 2.1: Values of boolean expressions" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": 1, 28 | "metadata": {}, 29 | "outputs": [ 30 | { 31 | "data": { 32 | "text/plain": [ 33 | "True" 34 | ] 35 | }, 36 | "execution_count": 1, 37 | "metadata": {}, 38 | "output_type": "execute_result" 39 | } 40 | ], 41 | "source": [ 42 | "C = 41\n", 43 | "\n", 44 | "# The value of C must be equal to 40 for this condition to be True. Otherwise,\n", 45 | "# this condition is False. Of course, 41 is not equal to 40, so this particular\n", 46 | "# condition is False.\n", 47 | "C == 40\n", 48 | "\n", 49 | "# Both conditions (C != 40 *and* C < 41) must be True for the whole statement\n", 50 | "# to be True. Although the first condition is True, the second condition is\n", 51 | "# False since C is not less than 41, so the whole statement is False.\n", 52 | "C != 40 and C < 41\n", 53 | "\n", 54 | "# Here, only one of the two conditions needs to be True in order for the whole\n", 55 | "# statement to be True. Since C != 40 is True, this particular statement is True.\n", 56 | "C != 40 or C < 41\n", 57 | "\n", 58 | "# The *not* keyword just negates whatever condition follows it. In this case,\n", 59 | "# C == 40 is False, so 'not C == 40' will return the opposite (True).\n", 60 | "not C == 40\n", 61 | "\n", 62 | "# C > 40 is True, so 'not C > 40' is False\n", 63 | "not C > 40\n", 64 | "\n", 65 | "# For this condition to be True, C must either be less than 40 *or* equal to 40.\n", 66 | "# If neither of these are True, then the condition is False.\n", 67 | "C <= 41\n", 68 | "\n", 69 | "# The *not* keyword will negate the result, so 'not False' is 'True'.\n", 70 | "not False\n", 71 | "\n", 72 | "# With the *and* logical operator, both conditions must be True for the whole \n", 73 | "# statement to be True. In this particular case, the statement is False.\n", 74 | "True and False\n", 75 | "\n", 76 | "# With the *or* logical operator, this whole statement is True since at least\n", 77 | "# one of the conditions is True.\n", 78 | "False or True\n", 79 | "\n", 80 | "# None of the conditions are True, so the whole statement is False.\n", 81 | "False or False or False\n", 82 | "\n", 83 | "# At least one of the conditions is False, so the whole statement is False.\n", 84 | "True and True and False\n", 85 | "\n", 86 | "# The integer value of False is 0, so this statement is True\n", 87 | "False == 0\n", 88 | "\n", 89 | "# The integer value of True is 1, so this statement is False\n", 90 | "True == 0\n", 91 | "\n", 92 | "# This statement is True (see above).\n", 93 | "True == 1" 94 | ] 95 | }, 96 | { 97 | "cell_type": "markdown", 98 | "metadata": {}, 99 | "source": [ 100 | "## Exercise 2.2: Make a Fahrenheit-Celsius conversion table\n", 101 | "Write a program that prints out a table with Fahrenheit degrees 0, 10, 20, ..., 100 in the first column and the corresponding Celsius degrees in the second column." 102 | ] 103 | }, 104 | { 105 | "cell_type": "code", 106 | "execution_count": 2, 107 | "metadata": {}, 108 | "outputs": [ 109 | { 110 | "name": "stdout", 111 | "output_type": "stream", 112 | "text": [ 113 | "0 -17.77777777777778\n", 114 | "10 -12.222222222222223\n", 115 | "20 -6.666666666666667\n", 116 | "30 -1.1111111111111112\n", 117 | "40 4.444444444444445\n", 118 | "50 10.0\n", 119 | "60 15.555555555555557\n", 120 | "70 21.11111111111111\n", 121 | "80 26.666666666666668\n", 122 | "90 32.22222222222222\n", 123 | "100 37.77777777777778\n" 124 | ] 125 | } 126 | ], 127 | "source": [ 128 | "# Make a Fahrenheit-Celsius conversion table\n", 129 | "F = 0 # Initialise F\n", 130 | "dF = 10 # Increment for F within the loop\n", 131 | "while F <= 100: # Loop heading with condition\n", 132 | " C = (F - 32)*(5.0/9.0) # 1st statement inside loop\n", 133 | " print(F, C) # 2nd statement inside loop\n", 134 | " F = F + dF # Increment F for the next iteration of the loop." 135 | ] 136 | }, 137 | { 138 | "cell_type": "markdown", 139 | "metadata": {}, 140 | "source": [ 141 | "## Exercise 2.3: Write an approximate Fahrenheit-Celsius conversion table\n", 142 | "Many people use an approximate formula for quickly converting Fahrenheit ($F$) to Celsius ($C$) degrees:\n", 143 | "$C \\approx \\hat{C} = \\frac{F − 30}{2}$\n", 144 | "Modify the program from the previous exercise so that it prints three columns: $F$, $C$, and the approximate value $\\hat{C}$." 145 | ] 146 | }, 147 | { 148 | "cell_type": "code", 149 | "execution_count": 3, 150 | "metadata": {}, 151 | "outputs": [ 152 | { 153 | "name": "stdout", 154 | "output_type": "stream", 155 | "text": [ 156 | "0 -17.77777777777778 -15.0\n", 157 | "10 -12.222222222222223 -10.0\n", 158 | "20 -6.666666666666667 -5.0\n", 159 | "30 -1.1111111111111112 0.0\n", 160 | "40 4.444444444444445 5.0\n", 161 | "50 10.0 10.0\n", 162 | "60 15.555555555555557 15.0\n", 163 | "70 21.11111111111111 20.0\n", 164 | "80 26.666666666666668 25.0\n", 165 | "90 32.22222222222222 30.0\n", 166 | "100 37.77777777777778 35.0\n" 167 | ] 168 | } 169 | ], 170 | "source": [ 171 | "# Write an approximate Fahrenheit-Celsius conversion table\n", 172 | "F = 0 # Initialise F\n", 173 | "dF = 10 # Increment for F within the loop\n", 174 | "while F <= 100: # Loop heading with condition\n", 175 | " C = (F - 32)*(5.0/9.0) # 1st statement inside loop\n", 176 | " C_hat = (F - 30)/2.0 # Compute the approximate value of C.\n", 177 | " print(F, C, C_hat) # 2nd statement inside loop\n", 178 | " F = F + dF # Increment F for the next iteration of the loop." 179 | ] 180 | }, 181 | { 182 | "cell_type": "markdown", 183 | "metadata": {}, 184 | "source": [ 185 | "## Exercise 2.4: Store odd numbers in a list\n", 186 | "Modify the program from the previous exercise to store the generated odd numbers in a list. Start with an empty list and use a while loop where you in each pass of the loop append a new element to the list. Finally, print the list elements to the screen." 187 | ] 188 | }, 189 | { 190 | "cell_type": "code", 191 | "execution_count": 4, 192 | "metadata": {}, 193 | "outputs": [ 194 | { 195 | "name": "stdout", 196 | "output_type": "stream", 197 | "text": [ 198 | "The odd numbers list = [1, 3, 5, 7, 9, 11, 13, 15]\n" 199 | ] 200 | } 201 | ], 202 | "source": [ 203 | "# Store odd numbers in a list\n", 204 | "n = 16\n", 205 | "\n", 206 | "i = 1\n", 207 | "odd_numbers = []\n", 208 | "while i <= n:\n", 209 | " odd_numbers.append(i) # Append the odd number 'i' to the list called 'odd_numbers'\n", 210 | " i = i + 2\n", 211 | "print(\"The odd numbers list = \", odd_numbers)" 212 | ] 213 | }, 214 | { 215 | "cell_type": "markdown", 216 | "metadata": {}, 217 | "source": [ 218 | "## Exercise 2.5: Repeat the previous exercise using: a for loop, list comprehension and the range function" 219 | ] 220 | }, 221 | { 222 | "cell_type": "code", 223 | "execution_count": 5, 224 | "metadata": {}, 225 | "outputs": [ 226 | { 227 | "name": "stdout", 228 | "output_type": "stream", 229 | "text": [ 230 | "The odd numbers list = [1, 3, 5, 7, 9, 11, 13, 15]\n", 231 | "The odd numbers list = [1, 3, 5, 7, 9, 11, 13, 15]\n" 232 | ] 233 | } 234 | ], 235 | "source": [ 236 | "# Generate odd numbers by a list comprehension\n", 237 | "n = 16\n", 238 | "\n", 239 | "# Use list comprehension to generate the list of odd numbers.\n", 240 | "# Remember to choose the step size to be 2 here.\n", 241 | "odd_numbers = [i for i in range(1, n+1, 2)]\n", 242 | "print(\"The odd numbers list = \", odd_numbers)\n", 243 | "\n", 244 | "# You could also do (using the default 'start' and 'step' values in the range function)\n", 245 | "odd_numbers = [2*i + 1 for i in range(int((n + 1)/2))]\n", 246 | "print(\"The odd numbers list = \", odd_numbers)" 247 | ] 248 | } 249 | ], 250 | "metadata": { 251 | "kernelspec": { 252 | "display_name": "Python 3", 253 | "language": "python", 254 | "name": "python3" 255 | }, 256 | "language_info": { 257 | "codemirror_mode": { 258 | "name": "ipython", 259 | "version": 3 260 | }, 261 | "file_extension": ".py", 262 | "mimetype": "text/x-python", 263 | "name": "python", 264 | "nbconvert_exporter": "python", 265 | "pygments_lexer": "ipython3", 266 | "version": "3.6.2" 267 | } 268 | }, 269 | "nbformat": 4, 270 | "nbformat_minor": 1 271 | } 272 | -------------------------------------------------------------------------------- /notebook/data/AVO.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 |
7 | 8 | 9 | 10 | 11 || Station name | Avonmouth |
|---|---|
| Country | UK |
| Latitude of measuring point | 51° 30' 39.2" N |
| Longitude of measuring point | 02° 42' 53.9" W |
| OS grid ref. of measuring point | ST 5047 7934 |
| Datum reference | All data refer to Admiralty Chart Datum (ACD) ACD = ODN -6.5m |
| Time reference | GMT (hours 00-23) |
| Contributor | Tide Gauge Inspectorate (TGI), National Oceanography Centre, Liverpool, Joseph Proudman Building, 6 Brownlow Street, Liverpool, L3 5DA, UK |
| Instrument type | Prior to 1984 - Port of Bristol Authority instrument. 1984 - DATARING system installed, Bubbler system. 1984 - Jetty hit by ship, equipment damaged. 1986 - DATARING - Bubbler system reinstalled. 1993 - DATARING - Underwater transducers installed. |
| Site of measuring point | Mounted on superstructure of the wartime jetty. |
| Position of tide gauge building | ST 5063 7900 - G.R.P. Building |
| Observational period | 1961-1962,1972-1976,1979-1984,1986-2012. THIS SITE WAS DECOMMISSIONED ON 11/04/2012. |
| Benchmark | OS Grid Ref. | Description | Height above ODN (m) |
|---|---|---|---|
| TGBM | ST 5057 7881 | OSBM bolt at base of bollard | 9.211 |
| Aux1 | ST 5072 7859 | Rivet adjacent to transit shed NW face W angle | 9.480 |
ODN = Ordnance Datum Newlyn
Please Note: All parameters listed below are sea level measured in metres. Different parameter codes represent different gauges. For an explanation of the codes, please see the BODC parameter dictionary.
| Period | Parameters | Completeness index (%) | Sample interval |
|---|---|---|---|
| 1961 | ASLVZZ01 | 52 | 60 minutes |
| 1962 | ASLVZZ01 | 61 | 60 minutes |
| 1972 | ASLVZZ01 | 2 | 60 minutes |
| 1973 | ASLVZZ01 | 98 | 60 minutes |
| 1974 | ASLVZZ01 | 98 | 60 minutes |
| 1975 | ASLVZZ01 | 99 | 60 minutes |
| 1976 | ASLVZZ01 | 1 | 60 minutes |
| 1979 | ASLVZZ01 | 10 | 60 minutes |
| 1980 | ASLVZZ01 | 14 | 60 minutes |
| 1981 | ASLVZZ01 | 10 | 60 minutes |
| 1982 | ASLVZZ01 | 26 | 60 minutes |
| 1983 | ASLVZZ01 | 1 | 60 minutes |
| 1984 | ASLVZZ01 ASLVBG01 | 23 (January to November) 5 (November to December) | 60 minutes |
| 1986 | ASLVBG01 | 27 | 60 minutes |
| 1987 | ASLVBG01 | 93 | 60 minutes |
| 1988 | ASLVBG01 | 88 | 60 minutes |
| 1989 | ASLVBG01 | 89 | 60 minutes |
| 1990 | ASLVBG01 | 99 | 60 minutes |
| 1991 | ASLVBG01 | 96 | 60 minutes |
| 1992 | ASLVBG01 | 92 | 60 minutes |
| 1993 | ASLVBG01 ASLVTD01 | 18 (January to March) 80 (March to December) | 15 minutes |
| 1994 | ASLVTD01 | 85 | 15 minutes |
| 1995 | ASLVTD01 | 97 | 15 minutes |
| 1996 | ASLVTD01 | 89 | 15 minutes |
| 1997 | ASLVTD01 | 98 | 15 minutes |
| 1998 | ASLVTD01 | 97 | 15 minutes |
| 1999 | ASLVTD01 | 99 | 15 minutes |
| 2000 | ASLVTD01 | 96 | 15 minutes |
| 2001 | ASLVTD01 | 92 | 15 minutes |
| 2002 | ASLVTD02 ASLVTD01 | 75 (January to September) 25 (October to December) | 15 minutes |
| 2003 | ASLVTD01 | 99 | 15 minutes |
| 2004 | ASLVTD02 | 92 | 15 minutes |
| 2005 | ASLVTD02 | 93 | 15 minutes |
| 2006 | ASLVTD02 | 96 | 15 minutes |
| 2007 | ASLVTD02 | 100 | 15 minutes |
| 2008 | ASLVTD02 | 100 | 15 minutes |
| 2009 | ASLVTD02 | 99 | 15 minutes |
| 2010 | ASLVTD02 | 100 | 15 minutes |
| 2011 | ASLVTD02 | 100 | 15 minutes |
| 2012 | ASLVTD02 | January - April | 15 minutes |
All data have been compared with the current Harmonic Constants library, and residuals checked. Records have been visually inspected for spikes, datum shifts and timing errors.
Where there are problems with the primary channel, data may be available from the backup channel. Please contact enquiries@bodc.ac.uk for more information.
1993 - The processing of the 1993 file has left a null value at the start of the file (00:00 hours 01/01/1993). This is due to the sampling interval changing from 60 to 15 minutes and the first data point being too far from 00:00 to interpolate.
In March 1993, the bubbler gauge (ASLVBG01) was replaced by a pressure transducer (ASLVTD01). There is a gap in the annual file where the instrument changes.
In 2002, up to September, the secondary channel was used as the data were of better quality than the primary channel. From October 2002 the primary channel has been used.
The annual file for 2002 contains output from the secondary (backup) channel for January to September and output from the primary channel for the period from October to December. There is a break in the middle of the file where the channel changes.
February 2003 - File output has been altered so that all values fall on the quarter hour and gaps are filled in with null values, marked with an 'N' flag.
March 2003 - Residuals (observed minus predicted sea level values, measured in metres) now included in the file output.
From the beginning of January 2004, channel two (ASLVTD02) became the primary channel and channel one (ASLVTD01) became the backup channel.
November 2012 - The file output has been altered to reflect the Contributor name change from Proudman Oceanographic Laboratory to National Oceanography Centre, Liverpool. Also, the Parameter code has been improved and now uses a controlled vocabulary.
Missing and suspect data have been reported on the following day numbers:-
| Period | Parameter | Missing data | Suspect data |
|---|---|---|---|
| 1961 | ASLVZZ01 | 001-174 | 220,290-296 |
| 1962 | ASLVZZ01 | 222-365 | 086 |
| 1972 | ASLVZZ01 | 001-357 | None |
| 1973 | ASLVZZ01 | 130-135 | 057-058 |
| 1974 | ASLVZZ01 | 026-028,035-036,234-235 | 016 |
| 1975 | ASLVZZ01 | 124-125,178 | 025,064 |
| 1976 | ASLVZZ01 | 002-366 | None |
| 1979 | ASLVZZ01 | 001-330 | None |
| 1980 | ASLVZZ01 | 018-137, 171-366 | None |
| 1981 | ASLVZZ01 | 001-327, 347-348 | 340-343 |
| 1982 | ASLVZZ01 | 095-365 | 045-046, 091 |
| 1983 | ASLVZZ01 | 001-364 | None |
| 1984 | ASLVZZ01 ASLVBG01 | 082-328 347-366 | None None |
| 1986 | ASLVBG01 | 001-267 | None |
| 1987 | ASLVBG01 | 014-016, 117-121, 189-195, 335-350 | 007-010, 037-039, 086, 289-290 |
| 1988 | ASLVBG01 | 064-070, 103-105, 329-366 | None |
| 1989 | ASLVBG01 | 001-040 | None |
| 1990 | ASLVBG01 | 093-095 | None |
| 1991 | ASLVBG01 | 037-041, 344-347, 351-358 | 067-069, 316 |
| 1992 | ASLVBG01 | 021-024, 028-029, 299-318, 357-366 | None |
| 1993 | ASLVBG01 ASLVTD01 | 068-070 075,089-092 | None 070-075,092-098 |
| 1994 | ASLVTD01 | 227-280 | 177-227 |
| 1995 | ASLVTD01 | 354-365 | 047-048 |
| 1996 | ASLVTD01 | 001-004,164-171,198-203,204-205,213-214,217-232,248-253 | 188 |
| 1997 | ASLVTD01 | 189,200-203,218-222,231-232 | None |
| 1998 | ASLVTD01 | 135,153-154,168-174,218-221,231 | None |
| 1999 | ASLVTD01 | None | 008,015,018-365 |
| 2000 | ASLVTD01 | 046-052,060,144-147,168-170,185-189,254-255 | 001-046,244,271,272,273,302,347 |
| 2001 | ASLVTD01 | 023-025,031-036,184-193,310-326,193-310,326-365 | 058-117,121-126,139-184 |
| 2002 | ASLVTD02 ASLVTD01 | None None | None 274-276 |
| 2003 | ASLVTD01 | 175,261 | None |
| 2004 | ASLVTD02 | 335-366 | None |
| 2005 | ASLVTD02 | 001-027 | None |
| 2006 | ASLVTD02 | 054-068 | None |
| 2007 | ASLVTD02 | None | None |
| 2008 | ASLVTD02 | None | None |
| 2009 | ASLVTD02 | 133,224 | None |
| 2010 | ASLVTD02 | None | 097-098,106-109,133,138-141,264 |
| 2011 | ASLVTD02 | None | None |
| 2012 | ASLVTD02 | 102-121 | 067-079,081-086,088-092,094-102 |