Skip to content

Commit

Permalink
Changed recursively_load to correctly handle paths and their children…
Browse files Browse the repository at this point in the history
… to restrictively load only certain trees from hdf5
  • Loading branch information
Immudzen committed May 8, 2020
1 parent 9af7f4e commit a7befbd
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@
/ron.py
/CADET.egg-info
/dist
/build/lib/cadet
/cadet/__pycache__
55 changes: 55 additions & 0 deletions CADETPython.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
Metadata-Version: 2.1
Name: CADETPython
Version: 0.2
Summary: CADET is a python interface to the CADET chromatography simulator
Home-page: https://github.com/modsim/CADET-Python
Author: William Heymann
Author-email: [email protected]
License: UNKNOWN
Description: CADET python is a file based python interface for CADET
CADET still must be downloaded and built from https://github.com/modsim/CADET

CADET python almost exactly maps to the documented CADET interface except that all dataset names
are lowercase. This simplifies useing the interface.

This package includes the Cadet class and H5 class. H5 can be used as a simple generic HDF5 interface.

As an example look at setting column porosity for column 1. From the CADET manual the path for this is
/input/model/unit_001/COL_POROSITY

In the python interface this becomes

sim = Cadet()
sim.root.input.model.unit_001.col_porosity = 0.33

Once the simulation has been created it must be saved before it can be run

sim.filename = "/path/to/where/you/want/the/file.hdf5"
sim.save()

#Next the path to cadet needs to be set before a simulation can be run, if running on windows you need the path to cadet-cli.exe

sim.cadet_path = '/path/to/cadet-cli'

#next run the simulation

print(sim.run())

#load the data
sim.load()


At this point any data can be read

If you have a file you want to read that has already been simulated this is also easy to do

sim = Cadet()
sim.filename = "/path/to/where/you/want/the/file.hdf5"
sim.load()

Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.6
Description-Content-Type: text/markdown
10 changes: 10 additions & 0 deletions CADETPython.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
README.md
setup.cfg
setup.py
CADETPython.egg-info/PKG-INFO
CADETPython.egg-info/SOURCES.txt
CADETPython.egg-info/dependency_links.txt
CADETPython.egg-info/requires.txt
CADETPython.egg-info/top_level.txt
cadet/__init__.py
cadet/cadet.py
1 change: 1 addition & 0 deletions CADETPython.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 3 additions & 0 deletions CADETPython.egg-info/requires.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
addict
numpy
h5py
1 change: 1 addition & 0 deletions CADETPython.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cadet
22 changes: 14 additions & 8 deletions cadet/cadet.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,30 @@ def inverse_transform(self, x):

def run(self, timeout = None, check=None):
if self.filename is not None:
data = subprocess.run([self.cadet_path, self.filename], timeout = timeout, check=check, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
data = subprocess.run([self.cadet_path, self.filename], timeout = timeout, check=check, capture_output=True)
self.return_information = data
return data
else:
print("Filename must be set before run can be used")

def recursively_load( h5file, path, func, paths):

ans = {}
for key_original in h5file[path].keys():
key = func(key_original)
local_path = path + key
if paths is None or (paths is not None and local_path in paths):
ans = Dict()
if paths is not None:
for path in paths:
item = h5file[path]
if isinstance(item, h5py._hl.dataset.Dataset):
ans[path[1:]] = item[()]
elif isinstance(item, h5py._hl.group.Group):
ans[path[1:]] = recursively_load(h5file, path + '/', func, None)
else:
for key_original in h5file[path].keys():
key = func(key_original)
local_path = path + key
item = h5file[path][key_original]
if isinstance(item, h5py._hl.dataset.Dataset):
ans[key] = item[()]
elif isinstance(item, h5py._hl.group.Group):
ans[key] = recursively_load(h5file, local_path + '/', func, paths)
ans[key] = recursively_load(h5file, local_path + '/', func, None)
return ans

def recursively_save( h5file, path, dic, func):
Expand Down
9 changes: 5 additions & 4 deletions examples/SMB.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
import math

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-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

#number of columns in a cycle
cycle_size = 4
cycle_size = 8

#number of cycles
cycles = 7
cycles = 4

#number of times flows have to be expanded for a 4-zone model
repeat_size = int(cycle_size/4)
Expand Down Expand Up @@ -121,7 +122,7 @@ def createSimulation(simulation):
col.ncomp = 2
col.cross_section_area = math.pi * (0.02**2)/4.0
col.col_dispersion = 3.8148e-20
col.col_length = 0.25
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]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="CADET",
version="0.2",
version="0.3",
author="William Heymann",
author_email="[email protected]",
description="CADET is a python interface to the CADET chromatography simulator",
Expand Down

0 comments on commit a7befbd

Please sign in to comment.