AguaClara / aguaclara

An open-source Python package for designing and performing research on AguaClara water treatment plants.
https://aguaclara.github.io/aguaclara/
MIT License
24 stars 13 forks source link

Restructuring research.tube_sizing #193

Closed HannahSi closed 5 years ago

HannahSi commented 5 years ago

In the next release of the research subpackage, we'll include fixes to the missing "rev" unit (for revolutions) and the error while reading tubing_data.txt in the research.tube_sizing module, as well as a test file for the module. We'll also restructure tube_sizing as explained below:

There are several functions in the module that involve calculating unknown parameters of a reactor given the other parameters. These functions are taking in the same parameters each time and sometimes referencing each other in order to do so. We can make them simpler and more intuitive by placing them in classes that represent different reactors, each distinguished by its unknown parameter(s).

Our task for the rest of this week will be to make this code object oriented and split it into two modules (rough outline below):

peristaltic_tube.py These functions will look up the volume per revolution that flows from a certain tube and a certain pump. These functions will only apply to the tubes and pumps used by the AguaClara Cornell lab.

def vol_per_rev_3stop(color): 
    look up the inner diameter of 3-stop Ismatec tubing of the given color
    look up/interpolate the volume per revolution that flows from a tube of the
        inner diameter when passed through a 6-roller pump

def vol_per_rev_LS(id_number):
    look up the volume per revolution that flows from the Masterflex L/S tube
        of the given ID when passed through a 2(?) roller pump

stock_qc.py These classes and functions will solve for unknown parameters of a reactor design given desired parameters.

class Variable_C_Stock:
    def __init__(Q_sys, C_sys, Q_stock)
    def C_stock: Q_sys*C_sys/Q_stock

class Variable_Q_Stock:
    def __init__(Q_sys, C_sys, C_stock, vol_per_rev)
    def pump_speed: rpm(Q_sys*C_sys/C_stock, vol_per_rev)

def rpm(Q, vol_per_rev): return Q/vol_per_min
def Q_stock(vol_per_rev, rpm): return vol_per_rev * rpm
def T_stock(Q_stock, V_stock): return V_stock/Q_stock
def M_stock(C_stock, V_stock): return C_stock*V_stock
def V_super_stock(V_stock, C_stock, C_super_stock): return V_stock*C_stock/C_super_stock
def dilution_factor(C_stock, C_super_stock): return C_stock/C_super_stock
HannahSi commented 5 years ago

Revision of stock_qc.py, with functions outside of the two classes placed in a parent class:

class Reactor:
    def rpm(Q, vol_per_rev): return Q/vol_per_min
    def Q_stock(vol_per_rev, rpm): return vol_per_rev * rpm
    def T_stock(Q_stock, V_stock): return V_stock/Q_stock
    def M_stock(C_stock, V_stock): return C_stock*V_stock
    def V_super_stock(V_stock, C_stock, C_super_stock): return V_stock*C_stock/C_super_stock
    def dilution_factor(C_stock, C_super_stock): return C_stock/C_super_stock

class Variable_C_Stock(Reactor):
    def __init__(Q_sys, C_sys, Q_stock)
    def C_stock: Q_sys*C_sys/Q_stock

class Variable_Q_Stock(Reactor):
    def __init__(Q_sys, C_sys, C_stock, vol_per_rev)
    def pump_speed: rpm(Q_sys*C_sys/C_stock, vol_per_rev)
elenapertsalis commented 5 years ago

Should we test extraneous numbers such as negative numbers or absurdly large numbers?

elenapertsalis commented 5 years ago

What is a range of reasonable numbers to expect for these functions?

HannahSi commented 5 years ago

For these functions, we don't need to test negative or excessively large values, just those within the range of physical application (what researchers will use).

Here are some example ranges for our lab:

elenapertsalis commented 5 years ago

Thank you! I will keep this in mind when testing.

HannahSi commented 5 years ago

These two modules are now fully documented and tested and ready to be published in version 24 (see branch v0.0.24)! There is example code in the module specifications that will be generated into a webpage like the one below. Our next step is to make sure that the AguaClara package website, where this webpage would appear, actually builds (currently it has a 404 Not Found error).

Screen Shot 2019-03-28 at 7 22 15 PM

elenapertsalis commented 5 years ago

We need to fix this a little because some of the test cases aren't passing.

HannahSi commented 5 years ago

All the tests are passing now! Most were minor syntax or input type errors. The code is now ready to use in release v0.0.24. The documentation site is also working!