{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"# Configure Jupyter so figures appear in the notebook\n",
"%matplotlib inline\n",
"\n",
"# Configure Jupyter to display the assigned value after an assignment\n",
"%config InteractiveShell.ast_node_interactivity='last_expr_or_assign'\n",
"\n",
"# import functions from the modsim.py module\n",
"\n",
"from modsim import *\n",
"\n",
"import pandas as pd\n",
"\n",
"from pandas import read_html\n",
"\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"def eval_gs():\n",
" #Amount of evaportanted water per second (kg/s)\n",
"\n",
" # (25 + 19v): evaporation coefficient\n",
"\n",
" # v: velocity of air above water surface (m/s)\n",
" v = 6.7056\n",
"\n",
" #evaporation coefficient (kg/m^2h)\n",
" theta = (25 + 19 * v)\n",
"\n",
" #water surface area (m^2)\n",
" A = 360000000000\n",
"\n",
" # xs: max humidity ratio of saturated air (kg water / kg dry air)\n",
" xs = 0.62198\n",
"\n",
" # x: humidity ratio air (kg water / kg dry air)\n",
" x = 0.01062\n",
"\n",
" return theta * A * (xs - x) / 3600"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" values | \n",
"
\n",
" \n",
" \n",
" \n",
" gs | \n",
" 9.317518e+09 | \n",
"
\n",
" \n",
" t_0 | \n",
" 0.000000e+00 | \n",
"
\n",
" \n",
" t_end | \n",
" 1.200000e+02 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
"gs 9.317518e+09\n",
"t_0 0.000000e+00\n",
"t_end 1.200000e+02\n",
"dtype: float64"
]
},
"execution_count": 20,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"params = Params(\n",
"# surface_temp = pd.read_csv('sea-surface-temp_\u001cg-1.csv', header = 1),\n",
"# heat_constant = pd.read_csv('temp.csv', header = 2),\n",
" gs = eval_gs(), t_0=0, t_end=120)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"# heat_constant = pd.read_csv('temp.csv', header = 0)\n",
"# heat_constant"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"def pick_constant(heat_constant):\n",
" input = 15\n",
" trim_temp = heat_constant[\"Temperature\"][3:36]\n",
" for data in trim_temp:\n",
" data = int(data)\n",
" data -= input\n",
" data = abs(data)\n",
" print(data)\n",
" out = np.min(data)\n",
" print(out)\n",
" type (data)\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"\n",
"\n",
"\n",
"\n",
"def make_system(params):\n",
" \"\"\"Makes a System object with the given parameters.\n",
" \n",
" params: sequence of G0, k1, k2, k3\n",
" data: DataFrame with `glucose` and `insulin`\n",
" \n",
" returns: System object\n",
" \"\"\"\n",
" gamma, mu, tao, beta, rho, alpha, sigma, delta, pi, t_0, t_end = params\n",
" \n",
"\n",
" init = State(R=200, L=0, E=0, V=4e-7)\n",
"\n",
" \n",
" return System(params,\n",
" init=init,gamma=gamma, mu=mu, tao=tao, beta=beta, rho=rho, alpha=alpha, sigma=sigma, delta=delta, pi=pi,\n",
" t_0=t_0, t_end=t_end, dt=(80/(60*24)))"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"def update_func(state, t, system):\n",
" # stock values are stored in system.state\n",
" # \n",
" R, L, E, V = state\n",
" gamma, mu, tao, beta, rho, alpha, sigma, delta, pi = system.gamma, system.mu, system.tao, system.beta, system.rho, system.alpha, system.sigma, system.delta, system.pi\n",
" \n",
" dt=system.dt\n",
" \n",
" dRdt = gamma*tao-mu*R-beta*R*V\n",
" dLdt = rho*beta*R*V-mu*L-alpha*L\n",
" dEdt = (1-rho)*beta*R*V +alpha*L - delta*E\n",
" dVdt = pi*E -sigma*V\n",
" \n",
" R += dRdt*dt\n",
" L += dLdt*dt\n",
" E += dEdt*dt\n",
" V += dVdt*dt\n",
" return State(R=R, L=L, E=E, V=V)\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"def run_simulation(system, update_func):\n",
" \"\"\"Runs a simulation of the system.\n",
" \n",
" system: System object\n",
" update_func: function that updates state\n",
" \n",
" returns: TimeFrame\n",
" \"\"\"\n",
" init = system.init\n",
" t_0, t_end, dt = system.t_0, system.t_end, system.dt\n",
" \n",
" frame = TimeFrame(columns=init.index)\n",
" frame.row[t_0] = init\n",
" ts = linrange(t_0, t_end, dt)\n",
" \n",
" for t in ts:\n",
" frame.row[t+dt] = update_func(frame.row[t], t, system)\n",
" \n",
" return frame\n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" values | \n",
"
\n",
" \n",
" \n",
" \n",
" T | \n",
" 24 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
"T 24\n",
"dtype: int64"
]
},
"execution_count": 11,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"init = State(T=24)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" values | \n",
"
\n",
" \n",
" \n",
" \n",
" init | \n",
" T 24\n",
"dtype: int64 | \n",
"
\n",
" \n",
" m | \n",
" 1 | \n",
"
\n",
" \n",
" cp | \n",
" 4190 | \n",
"
\n",
" \n",
" t_0 | \n",
" 0 | \n",
"
\n",
" \n",
" t_end | \n",
" 100 | \n",
"
\n",
" \n",
" T_env | \n",
" 24 | \n",
"
\n",
" \n",
" dt | \n",
" 1 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
"init T 24\n",
"dtype: int64\n",
"m 1\n",
"cp 4190\n",
"t_0 0\n",
"t_end 100\n",
"T_env 24\n",
"dt 1\n",
"dtype: object"
]
},
"execution_count": 12,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"# water energy\n",
"q = System(init=init,\n",
" m=1,\n",
" cp=4190,\n",
" t_0=0,\n",
" t_end=100,\n",
" T_env=24,\n",
" dt=1)\n",
"\n",
"# m: mass (kg)\n",
"\n",
"# cp: specific heat of substance (J/kg deg C); water is 4190\n",
"\n",
"# dt: change in temperature (deg C)\n",
"\n",
"# q: thermal energy per kg of water\n",
"# q = m * cp * dt"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"def update_func(state, t, system):\n",
" \"\"\"Update the thermal transfer model.\n",
" \n",
" state: State (temp)\n",
" t: time\n",
" system: System object\n",
" \n",
" returns: State (temp)\n",
" \"\"\"\n",
" r, dt = system.r, system.T_env, system.dt\n",
" \n",
" T = state.T\n",
" T += -r * (T - T_env) * dt\n",
" \n",
" return State(T=T)"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [
],
"source": [
" # water evaporation rate\n",
"# gs: water evaporated per second (kg/s)\n",
"# # (25 + 19v): evaporation coe\u001ecient\n",
"# # v: velocity of air above water surface\n",
"# v = 75\n",
"# # A: water surface area (m^2)\n",
"# A = 1\n",
"# # xs: max humidity ratio of saturated air (kg water / kg dry air)\n",
"# # xs =\n",
"# # x: humidity ratio air (kg water / kg dry air)\n",
"# # x =\n",
"# gs = (25 + 19 * v) * A * (xs - x) / 3600\n"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
"def heat(ocean_temp, gs):\n",
" \n",
" #heat supplied (kJ/s (kW))\n",
" hwe = 5\n",
"# evaporation heat of water (kJ/kg)\n",
" kW = 3412 \n",
"# Btu/h\n",
"\n",
" return "
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"103929.0"
]
},
"execution_count": 37,
"metadata": {
},
"output_type": "execute_result"
}
],
"source": [
"# atmospheric energy\n",
"\n",
"# R: gas constant for dry air in atmosphere\n",
"R = 8.31432 * 10 ** 3\n",
"\n",
"# T: temperature of air\n",
"T = 5\n",
"\n",
"# u: total energy per kg of air\n",
"u = (5 / 2) * R * T"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"outputs": [
],
"source": [
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"collapsed": false
},
"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.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}