From a4bf77b57f2c62b56ea1eb0e42258a3f984edb2b Mon Sep 17 00:00:00 2001 From: "r.jaepel" Date: Fri, 22 Mar 2024 12:34:13 +0100 Subject: [PATCH] Update test suite fixup! Update test suite --- .github/workflows/pipeline.yml | 39 +++++- setup.cfg | 6 +- setup.py | 7 ++ tests/__init__.py | 0 {examples => tests}/common.py | 6 +- .../test_MSSMA_2comp.py | 71 ++++++----- examples/SMB.py => tests/test_SMB.py | 118 ++++++++++-------- tests/test_autodetection.py | 6 + tests/test_duplicate_keys.py | 3 +- {examples => tests}/test_lwe.py | 68 +++++----- 10 files changed, 186 insertions(+), 138 deletions(-) create mode 100644 tests/__init__.py rename {examples => tests}/common.py (90%) rename examples/MSSMA_2comp.py => tests/test_MSSMA_2comp.py (83%) rename examples/SMB.py => tests/test_SMB.py (72%) create mode 100644 tests/test_autodetection.py rename {examples => tests}/test_lwe.py (78%) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index f1adfcc..190a984 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -10,23 +10,50 @@ on: jobs: test-job: runs-on: ubuntu-latest + + defaults: + run: + shell: bash -l {0} + strategy: matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: ["3.9", "3.10", "3.11"] steps: - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + + - name: Get Date + id: get-date + run: echo "today=$(/bin/date -u '+%Y%m%d')" >> $GITHUB_OUTPUT + shell: bash + + - name: Setup Conda Environment + uses: conda-incubator/setup-miniconda@v3 with: - python-version: ${{ matrix.python-version }} + miniforge-variant: Mambaforge + use-mamba: true + activate-environment: cadet-python + channels: conda-forge, + + - name: Cache conda + uses: actions/cache@v3 + env: + # Increase this value to reset cache if environment.yml has not changed + CACHE_NUMBER: 0 + with: + path: ${{ env.CONDA }}/envs + key: python_${{ matrix.python-version }}-${{ steps.get-date.outputs.today }}-${{ env.CACHE_NUMBER }} + - name: Test Wheel install and import run: | + mamba install python==${{ matrix.python-version }} pip install wheel python setup.py bdist_wheel cd dist pip install CADET_Python*.whl python -c "import cadet; print(cadet.__version__)" + cd .. - name: Test with pytest run: | - pip install pytest - pytest tests --rootdir=tests + pip install .[testing] + mamba install cadet -c conda-forge + pytest tests --rootdir=tests -m "not slow" diff --git a/setup.cfg b/setup.cfg index 9d5f797..23d72ac 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,3 +1,7 @@ # Inside of setup.cfg [metadata] -description-file = README.md \ No newline at end of file +description-file = README.md + +[tool:pytest] +markers = + slow: marks tests as slow (deselect with '-m "not slow"') diff --git a/setup.py b/setup.py index 4d11f1d..54cf7e2 100644 --- a/setup.py +++ b/setup.py @@ -24,5 +24,12 @@ "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", ], + extras_require={ + "testing": [ + "pytest", + "matplotlib", + "pandas", + ], + }, python_requires='>=3.7', ) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/examples/common.py b/tests/common.py similarity index 90% rename from examples/common.py rename to tests/common.py index 0caccaa..db6a9fd 100644 --- a/examples/common.py +++ b/tests/common.py @@ -7,11 +7,9 @@ root.input.model.solver.gs_type = 1 root.input.model.solver.max_krylov = 0 root.input.model.solver.max_restarts = 10 -root.input.model.solver.schur_safety = 1e-8 +root.input.model.solver.schur_safety = 1e-8 -#CADET 3.1 and CADET-dev flags are in here so that it works with both -#CADET-dev removed column from the name on the inputs and outputs since for many -#operations it no longer makes sense +# CADET 3.1 and CADET-dev flags are in here so that it works with both root.input['return'].write_solution_times = 1 root.input['return'].split_components_data = 1 root.input['return'].unit_000.write_sens_bulk = 0 diff --git a/examples/MSSMA_2comp.py b/tests/test_MSSMA_2comp.py similarity index 83% rename from examples/MSSMA_2comp.py rename to tests/test_MSSMA_2comp.py index ab3f5fa..06f6713 100644 --- a/examples/MSSMA_2comp.py +++ b/tests/test_MSSMA_2comp.py @@ -1,31 +1,17 @@ -#!/usr/bin/env python3.6 +import os -# Everything in here is based on CADET3.pdf in the same directory -# - -# Basic Python CADET file based interface compatible with CADET 3.0 and 3.1 -# Some additional fields have been added so that the generated simulations will also -# work in 3.1 and where those differences are I have noted them. -# This whole file follows the CADET pdf documentation. I have broken the system up into many -# functions in order to make it simpler and to make code reuse easier. - -# Normally the main function is placed at the bottom of the file but I have placed it at the top so that -# This interface is more like a tutorial and can be read from the top down and any given function -# can be drilled into to learn more about it. - -import numpy - -#use to render results import matplotlib.pyplot as plt +import numpy +import pandas +import pytest from cadet import Cadet -Cadet.cadet_path = "C:/Users/kosh_000/cadet_build/CADET-dev/cadet3.1-win7-x64/bin/cadet-cli.exe" +from tests import common -import common -import pandas def gen_fraction_times(start, stop, bins): - return numpy.linspace(start, stop, bins+1, endpoint=True) + return numpy.linspace(start, stop, bins + 1, endpoint=True) + def gen_fractions(fraction_times, sim): nComp = sim.root.input.model.unit_000.ncomp @@ -36,24 +22,29 @@ def gen_fractions(fraction_times, sim): for idx, (start, stop) in enumerate(zip(fraction_times[:-1], fraction_times[1:])): selected = (times >= start) & (times <= stop) - temp = {'Start':start, 'Stop':stop} + temp = {'Start': start, 'Stop': stop} for comp in range(nComp): local_times = times[selected] local_values = sim.root.output.solution.unit_001["solution_outlet_comp_%03d" % comp][selected] - + temp[str(comp)] = numpy.trapz(local_values, local_times) / (stop - start) df = df.append(temp, ignore_index=True) return df + def main(): + if not os.path.exists("tmp"): + os.makedirs("tmp") simulation = Cadet(common.common.root) - simulation.filename = "MSSMA_2comp.h5" + simulation.filename = "tmp/MSSMA_2comp.h5" createSimulation(simulation) simulation.save() data = simulation.run() print(data) simulation.load() plotSimulation(simulation) + return simulation + def createSimulation(simulation): root = simulation.root @@ -97,18 +88,18 @@ def createSimulation(simulation): root.input.model.unit_001.par_surfdiffusion = [0.0, 0.0, 0.0, 0.0, 0.0] root.input.model.unit_001.unit_type = 'GENERAL_RATE_MODEL' root.input.model.unit_001.velocity = 0.001 - + root.input.model.unit_001.adsorption.is_kinetic = 1 root.input.model.unit_001.adsorption.mssma_ka = [0.0, 1E11, 8E6, 1E11, 8E6] root.input.model.unit_001.adsorption.mssma_kd = [0.0, 6E11, 2E16, 6E11, 2E16] root.input.model.unit_001.adsorption.mssma_lambda = 225 root.input.model.unit_001.adsorption.mssma_nu = [0.0, 10, 25, 20, 50] - root.input.model.unit_001.adsorption.mssma_sigma = [0.0, 48, 66, 48*2, 66*2] + root.input.model.unit_001.adsorption.mssma_sigma = [0.0, 48, 66, 48 * 2, 66 * 2] root.input.model.unit_001.adsorption.mssma_refq = 225 root.input.model.unit_001.adsorption.mssma_refc0 = 520.0 root.input.model.unit_001.adsorption.mssma_rates = [0.0, 0.0, 1e20, 10, 0.0, 0.0, 1e20, 10, 0.0] - root.input.model.unit_001.discretization.nbound = [1, 2,2] + root.input.model.unit_001.discretization.nbound = [1, 2, 2] root.input.model.unit_001.discretization.ncol = 50 root.input.model.unit_001.discretization.npar = 5 @@ -122,12 +113,14 @@ def createSimulation(simulation): root.input.solver.consistent_init_mode = 3 + def plotSimulation(simulation): f, (ax1, ax2) = plt.subplots(1, 2, figsize=[16, 8]) plotInlet(ax1, simulation) plotOutlet(ax2, simulation) f.tight_layout() - plt.show() + plt.savefig("tmp/MSSMA.png") + def plotInlet(axis, simulation): solution_times = simulation.root.output.solution.solution_times @@ -139,7 +132,7 @@ def plotInlet(axis, simulation): axis.set_title("Inlet") axis.plot(solution_times, inlet_salt, 'b-', label="Salt") axis.set_xlabel('time (s)') - + # Make the y-axis label, ticks and tick labels match the line color. axis.set_ylabel('mMol Salt', color='b') axis.tick_params('y', colors='b') @@ -150,7 +143,6 @@ def plotInlet(axis, simulation): axis2.set_ylabel('mMol Protein', color='r') axis2.tick_params('y', colors='r') - lines, labels = axis.get_legend_handles_labels() lines2, labels2 = axis2.get_legend_handles_labels() axis2.legend(lines + lines2, labels + labels2, loc=0) @@ -164,22 +156,22 @@ def plotOutlet(axis, simulation): outlet_p2 = simulation.root.output.solution.unit_002.solution_outlet_comp_002 data = numpy.vstack([solution_times, outlet_p1]).transpose() - numpy.savetxt('comp2_1.csv', data, delimiter=',') + numpy.savetxt('tmp/comp2_1.csv', data, delimiter=',') data = numpy.vstack([solution_times, outlet_p2]).transpose() - numpy.savetxt('comp2_2.csv', data, delimiter=',') + numpy.savetxt('tmp/comp2_2.csv', data, delimiter=',') data = numpy.vstack([solution_times, outlet_p1 + outlet_p2]).transpose() - numpy.savetxt('comp2_comb.csv', data, delimiter=',') + numpy.savetxt('tmp/comp2_comb.csv', data, delimiter=',') fraction_times = gen_fraction_times(6000, 14000, 10) df = gen_fractions(fraction_times, simulation) - df.to_csv("comp2_fraction.csv", columns=('Start', 'Stop', '1'), index=False) + df.to_csv("tmp/comp2_fraction.csv", columns=('Start', 'Stop', '1'), index=False) axis.set_title("Output") axis.plot(solution_times, outlet_salt, 'b-', label="Salt") axis.set_xlabel('time (s)') - + # Make the y-axis label, ticks and tick labels match the line color. axis.set_ylabel('mMol Salt', color='b') axis.tick_params('y', colors='b') @@ -190,13 +182,20 @@ def plotOutlet(axis, simulation): axis2.set_ylabel('mMol Protein', color='r') axis2.tick_params('y', colors='r') - lines, labels = axis.get_legend_handles_labels() lines2, labels2 = axis2.get_legend_handles_labels() axis2.legend(lines + lines2, labels + labels2, loc=0) +@pytest.mark.slow +def test_MSSMA_2comp(): + sim = main() + assert isinstance(sim.root.output.solution.unit_002.solution_outlet_comp_001, numpy.ndarray) + assert isinstance(sim.root.output.solution.unit_002.solution_outlet_comp_000, numpy.ndarray) + + if __name__ == "__main__": import sys + print(sys.version) main() diff --git a/examples/SMB.py b/tests/test_SMB.py similarity index 72% rename from examples/SMB.py rename to tests/test_SMB.py index df13e12..07a7e22 100644 --- a/examples/SMB.py +++ b/tests/test_SMB.py @@ -1,65 +1,67 @@ -#!/usr/bin/env python3.6 +# Basic 4-zone SMB setup -#Basic 4-zone SMB setup - -import numpy as np import math +import os.path -from cadet import Cadet -#Cadet.cadet_path = "C:/Users/kosh_000/cadet_build/CADET-dev/MS_SMKL_RELEASE/bin/cadet-cli.exe" -Cadet.cadet_path = "C:/Users/kosh_000/cadet_build/CADET/VCPKG/bin/cadet-cli.exe" - -#use to render results import matplotlib.pyplot as plt +import numpy +import pytest + +from cadet import Cadet -#number of columns in a cycle +# number of columns in a cycle cycle_size = 8 -#number of cycles +# number of cycles cycles = 4 -#number of times flows have to be expanded for a 4-zone model -repeat_size = int(cycle_size/4) +# number of times flows have to be expanded for a 4-zone model +repeat_size = int(cycle_size / 4) + def gen_connections(units, cycle_size, size, step, flows, flows_static): temp = [] - connections = list(zip(units, np.roll(units,-1), flows)) - io = np.roll(units, step)[[0, size*2, size-1, size*3-1]] + connections = list(zip(units, numpy.roll(units, -1), flows)) + io = numpy.roll(units, step)[[0, size * 2, size - 1, size * 3 - 1]] ios = list(zip([0, 1, 2, 3], io)) for connection in connections: temp.append([connection[0], connection[1], -1, -1, connection[2]]) - #inputs + # inputs idx = 0 for io in ios[:2]: temp.append([io[0], io[1], -1, -1, flows_static[idx]]) - idx+=1; - #outputs + idx += 1 + # outputs for io in ios[2:]: temp.append([io[1], io[0], -1, -1, flows_static[idx]]) - idx+=1; - return np.array(temp) + idx += 1 + return numpy.array(temp) + def expand_flow(seq, inlet1, inlet2, number): "expand the flows for smb, this is more complex since we need link values" temp = [] - temp.extend([seq[3] + inlet1] * (number-1)) + temp.extend([seq[3] + inlet1] * (number - 1)) temp.append(seq[0]) - temp.extend([seq[0]] * (number-1)) + temp.extend([seq[0]] * (number - 1)) temp.append(seq[1]) - temp.extend([seq[1] + inlet2] * (number-1)) + temp.extend([seq[1] + inlet2] * (number - 1)) temp.append(seq[2]) - temp.extend([seq[2]] * (number-1)) + temp.extend([seq[2]] * (number - 1)) temp.append(seq[3]) return temp + def main(): + if not os.path.exists("tmp"): + os.makedirs("tmp") smb = Cadet() - smb.filename = 'F:/temp/SMB.h5' + smb.filename = 'tmp/SMB.h5' createSimulation(smb) print("Simulated Created") smb.save() @@ -67,6 +69,8 @@ def main(): smb.load() print("Simulation Run") plotSimulation(smb) + return smb + def createSimulation(simulation): simulation.root.input.model.nunits = 4 + cycle_size @@ -76,27 +80,31 @@ def createSimulation(simulation): simulation.root.input.model.solver.max_restarts = 0 simulation.root.input.model.solver.schur_safety = 1e-8 - - #setup connections + # setup connections simulation.root.input.model.connections.nswitches = cycle_size - units = range(4, 4+cycle_size) + units = range(4, 4 + cycle_size) flows = expand_flow([7.66E-07, 7.66E-07, 8.08E-07, 8.08E-07], 0.98e-7, 1.96e-07, repeat_size) - flows_static = np.array([0.98e-7, 1.96e-7, 1.4e-7, 1.54e-7]) + flows_static = numpy.array([0.98e-7, 1.96e-7, 1.4e-7, 1.54e-7]) for i in range(cycle_size): simulation.root.input.model.connections["switch_%03d" % i].section = i - simulation.root.input.model.connections["switch_%03d" % i].connections = gen_connections(units, cycle_size, repeat_size, -i, np.array(list(np.roll(flows, i))), flows_static ) - - #setup inlets + simulation.root.input.model.connections["switch_%03d" % i].connections = gen_connections(units, cycle_size, + repeat_size, -i, + numpy.array(list( + numpy.roll(flows, + i))), + flows_static) + + # setup inlets simulation.root.input.model.unit_000.inlet_type = 'PIECEWISE_CUBIC_POLY' simulation.root.input.model.unit_000.ncomp = 2 simulation.root.input.model.unit_000.unit_type = 'INLET' for i in range(cycle_size): - #section - simulation.root.input.model.unit_000["sec_%03d" % i].const_coeff = [0.55/180.16, 0.55/180.16] + # section + simulation.root.input.model.unit_000["sec_%03d" % i].const_coeff = [0.55 / 180.16, 0.55 / 180.16] simulation.root.input.model.unit_000["sec_%03d" % i].lin_coeff = [0.0, 0.0] simulation.root.input.model.unit_000["sec_%03d" % i].quad_coeff = [0.0, 0.0] simulation.root.input.model.unit_000["sec_%03d" % i].cube_coeff = [0.0, 0.0] @@ -106,23 +114,22 @@ def createSimulation(simulation): simulation.root.input.model.unit_001.unit_type = 'INLET' for i in range(cycle_size): - #section + # section simulation.root.input.model.unit_001["sec_%03d" % i].const_coeff = [0.0, 0.0] simulation.root.input.model.unit_001["sec_%03d" % i].lin_coeff = [0.0, 0.0] simulation.root.input.model.unit_001["sec_%03d" % i].quad_coeff = [0.0, 0.0] simulation.root.input.model.unit_001["sec_%03d" % i].cube_coeff = [0.0, 0.0] - #create columns + # create columns for unit in range(4, 4 + cycle_size): - simulation.root.input.model["unit_%03d" % unit].unit_type = 'GENERAL_RATE_MODEL' col = simulation.root.input.model["unit_%03d" % unit] col.ncomp = 2 - col.cross_section_area = math.pi * (0.02**2)/4.0 + col.cross_section_area = math.pi * (0.02 ** 2) / 4.0 col.col_dispersion = 3.8148e-20 - col.col_length = 0.25/repeat_size + col.col_length = 0.25 / repeat_size col.col_porosity = 0.83 col.init_c = [0.0, 0.0] col.init_q = [0.0, 0.0] @@ -154,14 +161,14 @@ def createSimulation(simulation): col.discretization.weno.weno_eps = 1e-12 col.discretization.weno.weno_order = 3 - #create outlets + # create outlets simulation.root.input.model.unit_002.ncomp = 2 simulation.root.input.model.unit_002.unit_type = 'OUTLET' simulation.root.input.model.unit_003.ncomp = 2 simulation.root.input.model.unit_003.unit_type = 'OUTLET' - #create output information + # create output information simulation.root.input['return'].write_solution_times = 1 @@ -192,12 +199,13 @@ def createSimulation(simulation): ret.unit_003.write_solution_column_outlet = 1 ret.unit_003.write_solution_flux = 0 ret.unit_003.write_solution_particle = 0 - + simulation.root.input.solver.nthreads = 0 - simulation.root.input.solver.user_solution_times = np.linspace(0, cycles*180*4, 1000*cycle_size*cycles) - simulation.root.input.solver.sections.nsec = cycle_size*cycles - simulation.root.input.solver.sections.section_continuity = [0] * (cycle_size*cycles -1) - simulation.root.input.solver.sections.section_times = [float(i) * 180*4.0/cycle_size for i in range(cycle_size*cycles+1)] + simulation.root.input.solver.user_solution_times = numpy.linspace(0, cycles * 180 * 4, 1000 * cycle_size * cycles) + simulation.root.input.solver.sections.nsec = cycle_size * cycles + simulation.root.input.solver.sections.section_continuity = [0] * (cycle_size * cycles - 1) + simulation.root.input.solver.sections.section_times = [float(i) * 180 * 4.0 / cycle_size for i in + range(cycle_size * cycles + 1)] simulation.root.input.solver.time_integrator.abstol = 1e-10 simulation.root.input.solver.time_integrator.algtol = 1e-10 @@ -215,8 +223,7 @@ def plotSimulation(simulation): r_0 = simulation.root.output.solution.unit_003.solution_outlet_comp_000 r_1 = simulation.root.output.solution.unit_003.solution_outlet_comp_001 - - fig = plt.figure(figsize=[10, 2*10]) + fig = plt.figure(figsize=[10, 2 * 10]) graph = fig.add_subplot(2, 1, 1) graph.set_title("Extract") @@ -224,17 +231,28 @@ def plotSimulation(simulation): graph.plot(solution_times, e_0, 'r', label='1') graph.plot(solution_times, e_1, 'g', label='2') graph.legend() - + graph = fig.add_subplot(2, 1, 2) graph.set_title("Raffinate") graph.plot(solution_times, r_0, 'r', label='1') graph.plot(solution_times, r_1, 'g', label='2') graph.legend() - plt.show() + plt.savefig("tmp/SMB.png") + + +@pytest.mark.slow +def test_SMB(): + from datetime import datetime + start = datetime.now() + sim = main() + print(datetime.now() - start) + assert isinstance(sim.root.output.solution.unit_003.solution_outlet_comp_001, numpy.ndarray) + assert isinstance(sim.root.output.solution.unit_003.solution_outlet_comp_000, numpy.ndarray) if __name__ == "__main__": import sys + print(sys.version) main() diff --git a/tests/test_autodetection.py b/tests/test_autodetection.py new file mode 100644 index 0000000..8401049 --- /dev/null +++ b/tests/test_autodetection.py @@ -0,0 +1,6 @@ +from cadet import Cadet + + +def test_autodetection(): + sim = Cadet() + assert sim.cadet_runner is not None diff --git a/tests/test_duplicate_keys.py b/tests/test_duplicate_keys.py index b148b87..53ed45e 100644 --- a/tests/test_duplicate_keys.py +++ b/tests/test_duplicate_keys.py @@ -1,6 +1,7 @@ -import pytest import tempfile +import pytest + from cadet import Cadet diff --git a/examples/test_lwe.py b/tests/test_lwe.py similarity index 78% rename from examples/test_lwe.py rename to tests/test_lwe.py index e134cf5..bd0acad 100644 --- a/examples/test_lwe.py +++ b/tests/test_lwe.py @@ -1,27 +1,13 @@ -#!/usr/bin/env python3.6 - -# Everything in here is based on CADET3.pdf in the same directory -# - -# Basic Python CADET file based interface compatible with CADET 3.0 and 3.1 -# Some additional fields have been added so that the generated simulations will also -# work in 3.1 and where those differences are I have noted them. -# This whole file follows the CADET pdf documentation. I have broken the system up into many -# functions in order to make it simpler and to make code reuse easier. - -# Normally the main function is placed at the bottom of the file but I have placed it at the top so that +# Normally the main function is placed at the bottom of the file, but I have placed it at the top so that # This interface is more like a tutorial and can be read from the top down and any given function # can be drilled into to learn more about it. +import os -#use to render results import matplotlib.pyplot as plt - import numpy from cadet import Cadet -import common - -Cadet.cadet_path = "C:/Users/kosh_000/cadet_build/CADET-dev/MS_SMKL_RELEASE/bin/cadet-cli.exe" +from tests import common # Helper functions that make it easier to set the values in the HDF5 file @@ -29,14 +15,18 @@ # below match those types. def main(): + if not os.path.exists("tmp"): + os.makedirs("tmp") simulation = Cadet(common.common.root) - simulation.filename = "f:/temp/LWE.h5" + simulation.filename = "tmp/LWE.h5" createSimulation(simulation) simulation.save() simulation.run() simulation.load() plotSimulation(simulation) + return simulation + def createSimulation(simulation): root = simulation.root @@ -81,11 +71,10 @@ def createSimulation(simulation): root.input.model.unit_001.par_surfdiffusion = [0.0, 0.0] root.input.model.unit_001.unit_type = 'GENERAL_RATE_MODEL' - #root.input.model.unit_001.velocity = 1 - #root.input.model.unit_001.cross_section_area = 4700.352526439483 + # root.input.model.unit_001.velocity = 1 + # root.input.model.unit_001.cross_section_area = 4700.352526439483 root.input.model.unit_001.velocity = 5.75e-4 - root.input.model.unit_001.adsorption.is_kinetic = 0 root.input.model.unit_001.adsorption.sma_ka = [0.0, 35.5] root.input.model.unit_001.adsorption.sma_kd = [0.0, 1000.0] @@ -104,38 +93,39 @@ def createSimulation(simulation): root.input.solver.sections.nsec = 3 root.input.solver.sections.section_continuity = [0, 0] root.input.solver.sections.section_times = [0.0, 10.0, 90.0, 1500.0] - + + def plotSimulation(simulation): f, (ax1, ax2) = plt.subplots(1, 2, figsize=[16, 8]) plotInlet(ax1, simulation) plotOutlet(ax2, simulation) f.tight_layout() - plt.show() + plt.savefig("tmp/lwe.png") + def plotInlet(axis, simulation): solution_times = simulation.root.output.solution.solution_times inlet_salt = simulation.root.output.solution.unit_000.solution_inlet_comp_000 inlet_p1 = simulation.root.output.solution.unit_000.solution_inlet_comp_001 - #inlet_p2 = simulation.root.output.solution.unit_000.solution_inlet_comp_002 - #inlet_p3 = simulation.root.output.solution.unit_000.solution_inlet_comp_003 + # inlet_p2 = simulation.root.output.solution.unit_000.solution_inlet_comp_002 + # inlet_p3 = simulation.root.output.solution.unit_000.solution_inlet_comp_003 axis.set_title("Inlet") axis.plot(solution_times, inlet_salt, 'b-', label="Salt") axis.set_xlabel('time (s)') - + # Make the y-axis label, ticks and tick labels match the line color. axis.set_ylabel('mMol Salt', color='b') axis.tick_params('y', colors='b') axis2 = axis.twinx() axis2.plot(solution_times, inlet_p1, 'r-', label="P1") - #axis2.plot(solution_times, inlet_p2, 'g-', label="P2") - #axis2.plot(solution_times, inlet_p3, 'k-', label="P3") + # axis2.plot(solution_times, inlet_p2, 'g-', label="P2") + # axis2.plot(solution_times, inlet_p3, 'k-', label="P3") axis2.set_ylabel('mMol Protein', color='r') axis2.tick_params('y', colors='r') - lines, labels = axis.get_legend_handles_labels() lines2, labels2 = axis2.get_legend_handles_labels() axis2.legend(lines + lines2, labels + labels2, loc=0) @@ -146,32 +136,30 @@ def plotOutlet(axis, simulation): outlet_salt = simulation.root.output.solution.unit_002.solution_outlet_comp_000 outlet_p1 = simulation.root.output.solution.unit_002.solution_outlet_comp_001 - #outlet_p2 = simulation.root.output.solution.unit_002.solution_outlet_comp_002 - #outlet_p3 = simulation.root.output.solution.unit_002.solution_outlet_comp_003 + # outlet_p2 = simulation.root.output.solution.unit_002.solution_outlet_comp_002 + # outlet_p3 = simulation.root.output.solution.unit_002.solution_outlet_comp_003 axis.set_title("Output") axis.plot(solution_times, outlet_salt, 'b-', label="Salt") axis.set_xlabel('time (s)') - + # Make the y-axis label, ticks and tick labels match the line color. axis.set_ylabel('mMol Salt', color='b') axis.tick_params('y', colors='b') axis2 = axis.twinx() axis2.plot(solution_times, outlet_p1, 'r-', label="P1") - #axis2.plot(solution_times, outlet_p2, 'g-', label="P2") - #axis2.plot(solution_times, outlet_p3, 'k-', label="P3") + # axis2.plot(solution_times, outlet_p2, 'g-', label="P2") + # axis2.plot(solution_times, outlet_p3, 'k-', label="P3") axis2.set_ylabel('mMol Protein', color='r') axis2.tick_params('y', colors='r') - lines, labels = axis.get_legend_handles_labels() lines2, labels2 = axis2.get_legend_handles_labels() axis2.legend(lines + lines2, labels + labels2, loc=0) -if __name__ == "__main__": - import sys - print(sys.version) - main() - +def test_lwe(): + sim = main() + assert isinstance(sim.root.output.solution.unit_002.solution_outlet_comp_001, numpy.ndarray) + assert isinstance(sim.root.output.solution.unit_002.solution_outlet_comp_000, numpy.ndarray)