Skip to content

Commit

Permalink
Copy method working; Derivatives
Browse files Browse the repository at this point in the history
  • Loading branch information
nick5435 committed Feb 26, 2017
1 parent d4b68e8 commit 88cf8c4
Show file tree
Hide file tree
Showing 2 changed files with 283 additions and 1 deletion.
263 changes: 263 additions & 0 deletions notebooks/DerivativesWkst.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"end_time": "2017-02-26T23:44:44.858896Z",
"start_time": "2017-02-26T17:44:44.744888-06:00"
},
"collapsed": false,
"extensions": {
"jupyter_dashboards": {
"version": 1,
"views": {
"grid_default": {},
"report_default": {
"hidden": true
}
}
}
},
"run_control": {
"frozen": false,
"read_only": false
}
},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt, mpld3\n",
"import thermoDataGrabber as DG\n",
"import CoolProp.CoolProp as CP\n",
"from cytoolz import get\n",
"%matplotlib notebook\n",
"mpld3.enable_notebook()\n",
"#print(plt.style.available)\n",
"plt.style.use([\"seaborn-talk\",\"seaborn-notebook\",\"seaborn-paper\"])\n",
"rescale = lambda old, new: lambda x: (new[1] - new[0]) / (old[1] - old[0])*(x - old[0]) + new[0]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2017-02-26T23:24:56.417751Z",
"start_time": "2017-02-26T17:24:48.793400-06:00"
},
"collapsed": false
},
"outputs": [],
"source": [
"myfluid = DG.ThermoFluid(\"Water\", \"T\", \"P\", \"U\", [217, 217], \"viridis\")\n",
"print(myfluid.data.shape)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2017-02-26T23:25:23.097425Z",
"start_time": "2017-02-26T17:24:56.422251-06:00"
},
"collapsed": false
},
"outputs": [],
"source": [
"buffer = {}\n",
"derivatives = {\"d(U)/d(T)|P\": lambda state: CP.PropsSI(\"d(U)/d(T)|P\", 'P', state[\"P\"], 'T', state[\"T\"], myfluid.fluid),\n",
" \"d(U)/d(P)|T\": lambda state: CP.PropsSI(\"d(U)/d(P)|T\", 'P', state[\"P\"], 'T', state[\"T\"], myfluid.fluid),\n",
" }\n",
"\n",
"for key in derivatives:\n",
" buffer[key] = []\n",
" \n",
"for index, row in myfluid.data.iterrows():\n",
" for key in derivatives:\n",
" get(key, buffer).append(derivatives[key](row))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2017-02-26T23:25:23.141010Z",
"start_time": "2017-02-26T17:25:23.101426-06:00"
},
"collapsed": false
},
"outputs": [],
"source": [
"for key in derivatives:\n",
" myfluid.data[key] = pd.Series(get(key, buffer), index=myfluid.data.index)\n",
" \n",
"rescaled = myfluid.copy()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2017-02-26T23:25:23.274011Z",
"start_time": "2017-02-26T17:25:23.148515-06:00"
},
"collapsed": false
},
"outputs": [],
"source": [
"tmax = max(myfluid.data[\"T\"])\n",
"tmin = min(myfluid.data[\"T\"])\n",
"trange = [tmin, tmax]\n",
"pmax = max(myfluid.data[\"P\"])\n",
"pmin = min(myfluid.data[\"P\"])\n",
"prange = [pmin, pmax]\n",
"umax = max(myfluid.data[\"U\"])\n",
"umin = min(myfluid.data[\"U\"])\n",
"urange = [umin, umax]\n",
"dmax1 = max(myfluid.data[\"d(U)/d(T)|P\"])\n",
"dmin1 = min(myfluid.data[\"d(U)/d(T)|P\"])\n",
"drange1 = [dmin1, dmax1]\n",
"dmax2 = max(myfluid.data[\"d(U)/d(P)|T\"])\n",
"dmin2 = min(myfluid.data[\"d(U)/d(P)|T\"])\n",
"drange2 = [dmin2, dmax2]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2017-02-26T23:21:11.477422Z",
"start_time": "2017-02-26T17:21:11.150935-06:00"
},
"collapsed": false
},
"outputs": [],
"source": [
"rescaled.data[\"T\"] = rescaled.data[\"T\"].apply(rescale(trange, [0,216]))\n",
"rescaled.data[\"P\"] = rescaled.data[\"P\"].apply(rescale(prange, [0,216]))\n",
"rescaled.data[\"U\"] = rescaled.data[\"U\"].apply(rescale(urange, [15, 152]))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2017-02-26T23:23:29.993298Z",
"start_time": "2017-02-26T17:23:29.974807-06:00"
},
"collapsed": false
},
"outputs": [],
"source": [
"# for i in range(4):\n",
"# dU = 2 + i\n",
"# uSel = 25 + 25*i\n",
"# rescaled.ix[np.abs(rescaled[\"U\"] - uSel) <= 1, 'U'] = rescaled.ix[np.abs(rescaled[\"U\"] - uSel) <= 1 , \"U\"] + dU\n",
"# rescaled.ix[np.abs(rescaled[\"U\"] - uSel - 12.5) <= 1.5, 'U'] = rescaled.ix[np.abs(rescaled[\"U\"] - uSel - 12.5) <= 1.5 , \"U\"] - dU\n",
"\n",
"rescaled.data.ix[np.abs(rescaled.data[\"d(U)/d(T)|P\"] - 10000) <= 2500, 'U'] = rescaled.data.ix[np.abs(rescaled.data[\"d(U)/d(T)|P\"] - 10000) <= 2500, 'U'] + 10"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2017-02-26T23:23:33.233277Z",
"start_time": "2017-02-26T17:23:32.853254-06:00"
},
"collapsed": false
},
"outputs": [],
"source": [
"myfluid2 = rescaled.copy()\n",
"DG.fluid_plot(myfluid2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2017-02-26T23:24:30.150267Z",
"start_time": "2017-02-26T17:24:30.103764-06:00"
},
"collapsed": false
},
"outputs": [],
"source": [
"rescaled.data[np.abs(rescaled.data[\"d(U)/d(T)|P\"] - 10000) <= 2500]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"extensions": {
"jupyter_dashboards": {
"activeView": "report_default",
"version": 1,
"views": {
"grid_default": {
"name": "grid",
"type": "grid"
},
"report_default": {
"name": "report",
"type": "report"
}
}
}
},
"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.6.0"
},
"latex_envs": {
"LaTeX_envs_menu_present": true,
"bibliofile": "biblio.bib",
"cite_by": "apalike",
"current_citInitial": 1,
"eqLabelWithNumbers": true,
"eqNumInitial": 1,
"hotkeys": {
"equation": "Ctrl-E",
"itemize": "Ctrl-I"
},
"labels_anchors": false,
"latex_user_defs": false,
"report_style_numbering": false,
"user_envs_cfg": false
}
},
"nbformat": 4,
"nbformat_minor": 2
}
21 changes: 20 additions & 1 deletion thermoDataGrabber/thermoDataGrabber/thermoDataGrabber.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
.. moduleauthor:: Nick Meyer <nmeyer5435@gmail.com>
"""

import copy
import json

import CoolProp.CoolProp as CP
Expand Down Expand Up @@ -43,7 +44,7 @@ def __init__(self,
var1: str="T",
var2: str="P",
outvar: str="S",
numPoints: Union[List[int], int]=[250, 250],
numPoints: Union[List[int], int]=[216, 216],
colorMap: str="nipy_spectral") -> None:
"""
Call the class with these arguments
Expand Down Expand Up @@ -217,6 +218,15 @@ def write_data(self, path: str) -> None:
with open(path + middle_string + ".json", mode="w+") as f:
json.dump(dict(self.meta), f)

def copy(self):
"""
Returns a copy of itself
returns:
self (ThermoFluid): A copy of this object
"""
return copy.deepcopy(self)


class CSVFluid():
"""
Expand Down Expand Up @@ -295,6 +305,15 @@ def changeOrder(self, order: List[int]) -> None:
self.zvar = self.vars[2]
self.units = [self.units[i] for i in order]

def copy(self):
"""
Returns a copy of itself
returns:
self (CSVFluid): A copy of this object
"""
return copy.deepcopy(self)


def fluid_plot(fluid: Union[CSVFluid, ThermoFluid]) -> None:
"""
Expand Down

0 comments on commit 88cf8c4

Please sign in to comment.