From 11aa3756d5f87105c6970248a8c18d749b3b8ee3 Mon Sep 17 00:00:00 2001 From: "Ryan C. Cooper" Date: Tue, 14 Jan 2020 10:07:44 -0500 Subject: [PATCH] finished project and notes --- ...d_global_temperature_anomaly-1880-2016.csv | 142 ------------------ ...> 02_Working_with_Python-checkpoint.ipynb} | 12 +- notebooks/01_Interacting_with_Python.ipynb | 2 +- ...ted.ipynb => 02_Working_with_Python.ipynb} | 12 +- notebooks/03-Numerical_error.ipynb | 29 +++- ...1_Getting-started-project-checkpoint.ipynb | 112 ++++++++++++++ project/01_Getting-started-project.ipynb | 140 +++++++++++++++++ 7 files changed, 296 insertions(+), 153 deletions(-) delete mode 100644 data/land_global_temperature_anomaly-1880-2016.csv rename notebooks/.ipynb_checkpoints/{02_Getting-started-checkpoint.ipynb => 02_Working_with_Python-checkpoint.ipynb} (99%) rename notebooks/{02_Getting-started.ipynb => 02_Working_with_Python.ipynb} (99%) create mode 100644 project/.ipynb_checkpoints/01_Getting-started-project-checkpoint.ipynb create mode 100644 project/01_Getting-started-project.ipynb diff --git a/data/land_global_temperature_anomaly-1880-2016.csv b/data/land_global_temperature_anomaly-1880-2016.csv deleted file mode 100644 index 749296e..0000000 --- a/data/land_global_temperature_anomaly-1880-2016.csv +++ /dev/null @@ -1,142 +0,0 @@ -Global Land Temperature Anomalies, January-December -Units: Degrees Celsius -Base Period: 1901-2000 -Missing: -999.0000 -Year,Value -1880,-0.47 -1881,-0.45 -1882,-0.41 -1883,-0.60 -1884,-0.60 -1885,-0.52 -1886,-0.48 -1887,-0.47 -1888,-0.46 -1889,-0.31 -1890,-0.49 -1891,-0.55 -1892,-0.52 -1893,-0.56 -1894,-0.35 -1895,-0.40 -1896,-0.27 -1897,-0.29 -1898,-0.37 -1899,-0.18 -1900,-0.13 -1901,-0.09 -1902,-0.33 -1903,-0.39 -1904,-0.46 -1905,-0.42 -1906,-0.20 -1907,-0.60 -1908,-0.49 -1909,-0.39 -1910,-0.33 -1911,-0.44 -1912,-0.51 -1913,-0.34 -1914,-0.07 -1915,-0.07 -1916,-0.36 -1917,-0.51 -1918,-0.37 -1919,-0.32 -1920,-0.28 -1921,-0.06 -1922,-0.24 -1923,-0.21 -1924,-0.26 -1925,-0.10 -1926,0.01 -1927,-0.15 -1928,-0.10 -1929,-0.40 -1930,-0.08 -1931,-0.03 -1932,-0.02 -1933,-0.34 -1934,-0.02 -1935,-0.14 -1936,-0.12 -1937,-0.03 -1938,0.17 -1939,0.09 -1940,0.04 -1941,0.11 -1942,0.07 -1943,0.09 -1944,0.21 -1945,-0.08 -1946,-0.01 -1947,0.06 -1948,0.06 -1949,-0.05 -1950,-0.33 -1951,-0.07 -1952,-0.08 -1953,0.17 -1954,-0.16 -1955,-0.13 -1956,-0.42 -1957,-0.05 -1958,0.13 -1959,0.05 -1960,-0.04 -1961,0.10 -1962,0.16 -1963,0.21 -1964,-0.24 -1965,-0.13 -1966,-0.07 -1967,-0.00 -1968,-0.11 -1969,-0.10 -1970,0.02 -1971,-0.04 -1972,-0.18 -1973,0.29 -1974,-0.21 -1975,0.12 -1976,-0.25 -1977,0.21 -1978,0.08 -1979,0.15 -1980,0.27 -1981,0.49 -1982,0.09 -1983,0.49 -1984,0.05 -1985,0.07 -1986,0.28 -1987,0.41 -1988,0.55 -1989,0.39 -1990,0.59 -1991,0.53 -1992,0.26 -1993,0.35 -1994,0.45 -1995,0.77 -1996,0.35 -1997,0.68 -1998,0.96 -1999,0.80 -2000,0.64 -2001,0.83 -2002,0.94 -2003,0.89 -2004,0.81 -2005,1.05 -2006,0.92 -2007,1.10 -2008,0.87 -2009,0.88 -2010,1.09 -2011,0.91 -2012,0.92 -2013,1.01 -2014,1.02 -2015,1.35 -2016,1.45 diff --git a/notebooks/.ipynb_checkpoints/02_Getting-started-checkpoint.ipynb b/notebooks/.ipynb_checkpoints/02_Working_with_Python-checkpoint.ipynb similarity index 99% rename from notebooks/.ipynb_checkpoints/02_Getting-started-checkpoint.ipynb rename to notebooks/.ipynb_checkpoints/02_Working_with_Python-checkpoint.ipynb index 9e533d2..227e92e 100644 --- a/notebooks/.ipynb_checkpoints/02_Getting-started-checkpoint.ipynb +++ b/notebooks/.ipynb_checkpoints/02_Working_with_Python-checkpoint.ipynb @@ -4,8 +4,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Getting Started\n", - "\n" + "###### Content modified under Creative Commons Attribution license CC-BY 4.0, code under BSD 3-Clause License © 2020 R.C. Cooper" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Working with Python" ] }, { @@ -156,7 +162,7 @@ " factorial_function(input_number): calculates the factorial of the input_number\n", " where the factorial is defined as N*(N-1)*(N-2)*...*3*2*1\n", " \n", - " Arguments\n", + " Arguments\n", " ---------\n", " input_value: an integer >= 0\n", " \n", diff --git a/notebooks/01_Interacting_with_Python.ipynb b/notebooks/01_Interacting_with_Python.ipynb index 6a71510..47869fa 100644 --- a/notebooks/01_Interacting_with_Python.ipynb +++ b/notebooks/01_Interacting_with_Python.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "###### Content under Creative Commons Attribution license CC-BY 4.0, code under BSD 3-Clause License © 2017 L.A. Barba, N.C. Clementi" + "###### Content modified under Creative Commons Attribution license CC-BY 4.0, code under BSD 3-Clause License © 2020 R.C. Cooper" ] }, { diff --git a/notebooks/02_Getting-started.ipynb b/notebooks/02_Working_with_Python.ipynb similarity index 99% rename from notebooks/02_Getting-started.ipynb rename to notebooks/02_Working_with_Python.ipynb index 9e533d2..227e92e 100644 --- a/notebooks/02_Getting-started.ipynb +++ b/notebooks/02_Working_with_Python.ipynb @@ -4,8 +4,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Getting Started\n", - "\n" + "###### Content modified under Creative Commons Attribution license CC-BY 4.0, code under BSD 3-Clause License © 2020 R.C. Cooper" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Working with Python" ] }, { @@ -156,7 +162,7 @@ " factorial_function(input_number): calculates the factorial of the input_number\n", " where the factorial is defined as N*(N-1)*(N-2)*...*3*2*1\n", " \n", - " Arguments\n", + " Arguments\n", " ---------\n", " input_value: an integer >= 0\n", " \n", diff --git a/notebooks/03-Numerical_error.ipynb b/notebooks/03-Numerical_error.ipynb index fa17246..1633722 100644 --- a/notebooks/03-Numerical_error.ipynb +++ b/notebooks/03-Numerical_error.ipynb @@ -1,5 +1,12 @@ { "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "###### Content modified under Creative Commons Attribution license CC-BY 4.0, code under BSD 3-Clause License © 2020 R.C. Cooper" + ] + }, { "cell_type": "markdown", "metadata": { @@ -8,8 +15,8 @@ } }, "source": [ - "# Freefall Model\n", - "## Computational solution\n", + "# Numerical Error\n", + "## Freefall Model Computational solution\n", "\n", " \n", "\n", @@ -1033,7 +1040,7 @@ }, { "cell_type": "code", - "execution_count": 301, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -1054,6 +1061,13 @@ "print(data)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "metadata": {}, @@ -1073,7 +1087,7 @@ }, { "cell_type": "code", - "execution_count": 273, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -1092,6 +1106,13 @@ " return ex\n", " " ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/project/.ipynb_checkpoints/01_Getting-started-project-checkpoint.ipynb b/project/.ipynb_checkpoints/01_Getting-started-project-checkpoint.ipynb new file mode 100644 index 0000000..fcd3dd5 --- /dev/null +++ b/project/.ipynb_checkpoints/01_Getting-started-project-checkpoint.ipynb @@ -0,0 +1,112 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Computational Mechanics Project #01 - Heat Transfer in Forensic Science\n", + "\n", + "We can use our current skillset for a macabre application. We can predict the time of death based upon the current temperature of a corpse. \n", + "\n", + "Forensic scientists use Newton's law of cooling to determine the time elapsed since the loss of life, \n", + "\n", + "$\\frac{dT}{dt} = -K(T-T_a)$,\n", + "\n", + "where $T$ is the current temperature, $T_a$ is the ambient temperature, $t$ is the elapsed time in hours, and $K$ is an empirical constant. \n", + "\n", + "Suppose the temperature of the corpse is 85$^o$F at 11:00 am. Then, 2 hours later the temperature is 74$^{o}$F. \n", + "\n", + "Assume ambient temperature is a constant 65$^{o}$F.\n", + "\n", + "1. Use Python to calculate $K$ using a finite difference approximation, $\\frac{dT}{dt} \\approx \\frac{T(t+\\Delta t)-T(t)}{\\Delta t}$. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "2. Change your work from problem 1 to create a function that accepts the temperature at two times, ambient temperature, and the time elapsed to return $K$. " + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "def measure_K(Temp_t1,Temp_t2,Temp_ambient,delta_t):\n", + " ''' Determine the value of K based upon temperature of corpse \n", + " when discovered, Temp_t1\n", + " after time, delta_t, Temp_t2\n", + " with ambient temperature, Temp_ambient\n", + " Arguments\n", + " ---------\n", + " your inputs...\n", + " \n", + " Returns\n", + " -------\n", + " your outputs...\n", + " \n", + " '''\n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "3. A first-order thermal system has the following analytical solution, \n", + "\n", + " $T(t) =T_a+(T(0)-T_a)e^{-Kt}$\n", + "\n", + " where $T(0)$ is the temperature of the corpse at t=0 hours i.e. at the time of discovery and $T_a$ is a constant ambient temperature. \n", + "\n", + " a. Show that an Euler integration converges to the analytical solution as the time step is decreased. Use the constant $K$ derived above and the initial temperature, T(0) = 85$^o$F. \n", + "\n", + " b. What is the final temperature as t$\\rightarrow\\infty$?\n", + " \n", + " c. At what time was the corpse 98.6$^{o}$F? i.e. what was the time of death?" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "4. Now that we have a working numerical model, we can look at the results if the ambient temperature is not constant i.e. T_a=f(t). ss" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.5" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/project/01_Getting-started-project.ipynb b/project/01_Getting-started-project.ipynb new file mode 100644 index 0000000..bbc50f6 --- /dev/null +++ b/project/01_Getting-started-project.ipynb @@ -0,0 +1,140 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Computational Mechanics Project #01 - Heat Transfer in Forensic Science\n", + "\n", + "We can use our current skillset for a macabre application. We can predict the time of death based upon the current temperature and change in temperature of a corpse. \n", + "\n", + "Forensic scientists use Newton's law of cooling to determine the time elapsed since the loss of life, \n", + "\n", + "$\\frac{dT}{dt} = -K(T-T_a)$,\n", + "\n", + "where $T$ is the current temperature, $T_a$ is the ambient temperature, $t$ is the elapsed time in hours, and $K$ is an empirical constant. \n", + "\n", + "Suppose the temperature of the corpse is 85$^o$F at 11:00 am. Then, 2 hours later the temperature is 74$^{o}$F. \n", + "\n", + "Assume ambient temperature is a constant 65$^{o}$F.\n", + "\n", + "1. Use Python to calculate $K$ using a finite difference approximation, $\\frac{dT}{dt} \\approx \\frac{T(t+\\Delta t)-T(t)}{\\Delta t}$. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "2. Change your work from problem 1 to create a function that accepts the temperature at two times, ambient temperature, and the time elapsed to return $K$. " + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "def measure_K(Temp_t1,Temp_t2,Temp_ambient,delta_t):\n", + " ''' Determine the value of K based upon temperature of corpse \n", + " when discovered, Temp_t1\n", + " after time, delta_t, Temp_t2\n", + " with ambient temperature, Temp_ambient\n", + " Arguments\n", + " ---------\n", + " your inputs...\n", + " \n", + " Returns\n", + " -------\n", + " your outputs...\n", + " \n", + " '''\n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "3. A first-order thermal system has the following analytical solution, \n", + "\n", + " $T(t) =T_a+(T(0)-T_a)e^{-Kt}$\n", + "\n", + " where $T(0)$ is the temperature of the corpse at t=0 hours i.e. at the time of discovery and $T_a$ is a constant ambient temperature. \n", + "\n", + " a. Show that an Euler integration converges to the analytical solution as the time step is decreased. Use the constant $K$ derived above and the initial temperature, T(0) = 85$^o$F. \n", + "\n", + " b. What is the final temperature as t$\\rightarrow\\infty$?\n", + " \n", + " c. At what time was the corpse 98.6$^{o}$F? i.e. what was the time of death?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "4. Now that we have a working numerical model, we can look at the results if the\n", + "ambient temperature is not constant i.e. T_a=f(t). We can use the weather to improve our estimate for time of death. Consider the following Temperature for the day in question. \n", + "\n", + " |time| Temp ($^o$F)|\n", + " |---|---|\n", + " |8am|55|\n", + " |9am|58|\n", + " |10am|60|\n", + " |11am|65|\n", + " |noon|66|\n", + " |1pm|67|\n", + "\n", + " a. Create a function that returns the current temperature based upon the time (0 hours=11am, 65$^{o}$F) \n", + " *Plot the function $T_a$ vs time. Does it look correct? Is there a better way to get $T_a(t)$?\n", + "\n", + " b. Modify the Euler approximation solution to account for changes in temperature at each hour. \n", + " Compare the new nonlinear Euler approximation to the linear analytical model. \n", + " At what time was the corpse 98.6$^{o}$F? i.e. what was the time of death? \n", + " \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.5" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}