Skip to content

Commit

Permalink
Changed how write data methods worked, tweaked docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nick5435 committed Mar 10, 2017
1 parent 796b2b5 commit 8f8f414
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 58 deletions.
95 changes: 37 additions & 58 deletions ThermoPyle/ThermoPyle/ThermoPyle.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
class ThermoFluid():
"""
A class that will contain the data requested.
Call the class with these arguments
Parameters:
fluid (str): CoolProp Fluid type to use
var1 (str): x variable
var2 (str): y variable
outvar (str): z var (generated by code), normally S, U
numPoints (Union[List[int],int]): number of Points for linspaces
colorMap (str): What color map to use
Attributes:
xvar (str): What variable is on the x-axis
Expand All @@ -52,7 +61,6 @@ class ThermoFluid():
numPoints (List[int]): the x-resolution and y-resolution, in that order.
M (float): the molar mass of the fluid for the system.
meta (pyrsistent._pmap.PMap): a PMap containing metadata related to the current fluid.
"""

def __init__(self,
Expand All @@ -61,24 +69,7 @@ def __init__(self,
var2: str="P",
outvar: str="S",
numPoints: Union[List[int], int]=[217, 217],
colorMap: str="viridis") -> None:
"""
Call the class with these arguments
Parameters:
fluid (str): CoolProp Fluid type to use
var1 (str): x var, normally T, P
var2 (str): y var, normally P, V
outvar (str): z var (generated by code), normally S, U
numPoints (Union[List[int],int]): number of Points for linspaces
colorMap (str): What color map to use
"""
colorMap: str="viridis"):

self.fluid = fluid
if type(numPoints) is int:
Expand Down Expand Up @@ -252,39 +243,43 @@ def clean(self) -> None:
if "V" in self.vars:
self.data = self.data[self.data["V"] >= 0.1]

def write_data(self, path: str, **kwargs) -> None:
def write_data(self, path: str="./data/", filename: str="", mode: str="default") -> None:
"""
Does what it says on the tin. Makes a CSV and JSON files and saves them to data/FluidName_X-xpoints_Y-ypoints_Z.
Does what it says on the tin. Makes a CSV and JSON files and saves them to path given.
Parameters:
path (str): path where file should be saved
filename (str): what to name the file
mode (str): How to name the file
- **default**: ``FluidName_X-xpoints_Y-ypoints_Z``
- **custom**: fully custom name.
- **dual**: default + custom (with custom appended).
mode (str): How to name the file:
- **default**: ``FluidName_X-xpoints_Y-ypoints_Z``;
- **custom**: fully custom name;
- **dual**: default + custom.
"""
if bool(kwargs):
if "filename" not in kwargs and "mode" in kwargs and get("nameMode", kwargs) in {"dual", "custom"}:
raise TypeError(
"When supplying {0} mode, filename is required; None given".format(get('nameMode', kwargs)))
nameMode = get("mode", kwargs, "default")
else:
nameMode = "default"
try:
assert mode in {"dual", "custom", "default"}
except AssertionError:
raise ValueError(
"Mode must be one of 'dual', 'custom', or 'default'. {0} provided".format(mode))

if nameMode != "custom":
if filename == "" and mode in {"dual", "custom"}:
raise TypeError(
"When supplying {0} mode, filename is required; None given".format(mode))

if mode != "custom":
default_string = self.fluid + "_" + "_".join([str(varname) + "-" + str(point) for (
varname, point) in zip([self.xvar, self.yvar], self.numPoints)] + [self.zvar])

if nameMode == "custom":
middle_string = get("filename", kwargs)
if mode == "custom":
middle_string = filename

elif nameMode == "default":
elif mode == "default":
middle_string = default_string

elif nameMode == "dual":
middle_string = default_string + "_" + str(get("filename", kwargs))
elif mode == "dual":
middle_string = default_string + "_" + filename

self.make_meta()

Expand All @@ -303,39 +298,24 @@ class CSVFluid():
"""
A class that will help work with ThermoFluid data contained in CSV/JSON files.
Parameters:
pathToFile (str): The name of the files you want to use, NOT the path. Must have both a json and a CSV file for this purpose.
Attributes:
data (pandas.DataFrame): The data as read by pandas for the given fluid
columns (List[Text]): What variable is on the y-axis
zvar (str): What variable is on the z-axis, also, what variable is generated by CoolProp
colorMap (str): What ColorMap Matplotlib uses to make its plot
vars (List[Text]): a list of xvar, yvar, zvar
fluid (str): What fluid is being modeled
data (pandas.DataFrame):
units (List[Text]): the units for xvar, yvar, zvar, in that order.
numPoints (List[int]): the x-resolution and y-resolution, in that order.
M (float): the molar mass of the fluid for the system.
meta (pyrsistent._pmap.PMap): a PMap containing metadata related to the current fluid.
"""

def __init__(self, pathToFile: str) -> None:
"""
Call the class with these arguments
Parameters:
pathToFile (str): The name of the files you want to use, NOT the path. Must have both a json and a CSV file for this purpose.
"""
def __init__(self, pathToFile: str):

with open(pathToFile + ".json", mode="r+") as jf:
self.meta = pyr.pmap(json.loads(jf.read()))
Expand Down Expand Up @@ -379,7 +359,6 @@ def changeOrder(self, order: List[Text]) -> None:
def copy(self) -> C:
"""
Returns a copy of itself
"""
return deepcopy(self)

Expand Down
1 change: 1 addition & 0 deletions docs/source/CSVFluid.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ ThermoPyle.CSVFluid
###################

.. autoclass:: ThermoPyle.CSVFluid
:special-members:
:members:
1 change: 1 addition & 0 deletions docs/source/ThermoFluid.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ ThermoPyle.ThermoFluid
######################

.. autoclass:: ThermoPyle.ThermoFluid
:special-members:
:members:

0 comments on commit 8f8f414

Please sign in to comment.