Skip to content

Commit a7befbd

Browse files
committed
Changed recursively_load to correctly handle paths and their children to restrictively load only certain trees from hdf5
1 parent 9af7f4e commit a7befbd

File tree

9 files changed

+92
-13
lines changed

9 files changed

+92
-13
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@
1818
/ron.py
1919
/CADET.egg-info
2020
/dist
21+
/build/lib/cadet
22+
/cadet/__pycache__

CADETPython.egg-info/PKG-INFO

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
Metadata-Version: 2.1
2+
Name: CADETPython
3+
Version: 0.2
4+
Summary: CADET is a python interface to the CADET chromatography simulator
5+
Home-page: https://github.com/modsim/CADET-Python
6+
Author: William Heymann
7+
Author-email: [email protected]
8+
License: UNKNOWN
9+
Description: CADET python is a file based python interface for CADET
10+
CADET still must be downloaded and built from https://github.com/modsim/CADET
11+
12+
CADET python almost exactly maps to the documented CADET interface except that all dataset names
13+
are lowercase. This simplifies useing the interface.
14+
15+
This package includes the Cadet class and H5 class. H5 can be used as a simple generic HDF5 interface.
16+
17+
As an example look at setting column porosity for column 1. From the CADET manual the path for this is
18+
/input/model/unit_001/COL_POROSITY
19+
20+
In the python interface this becomes
21+
22+
sim = Cadet()
23+
sim.root.input.model.unit_001.col_porosity = 0.33
24+
25+
Once the simulation has been created it must be saved before it can be run
26+
27+
sim.filename = "/path/to/where/you/want/the/file.hdf5"
28+
sim.save()
29+
30+
#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
31+
32+
sim.cadet_path = '/path/to/cadet-cli'
33+
34+
#next run the simulation
35+
36+
print(sim.run())
37+
38+
#load the data
39+
sim.load()
40+
41+
42+
At this point any data can be read
43+
44+
If you have a file you want to read that has already been simulated this is also easy to do
45+
46+
sim = Cadet()
47+
sim.filename = "/path/to/where/you/want/the/file.hdf5"
48+
sim.load()
49+
50+
Platform: UNKNOWN
51+
Classifier: Programming Language :: Python :: 3
52+
Classifier: License :: OSI Approved :: BSD License
53+
Classifier: Operating System :: OS Independent
54+
Requires-Python: >=3.6
55+
Description-Content-Type: text/markdown

CADETPython.egg-info/SOURCES.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
README.md
2+
setup.cfg
3+
setup.py
4+
CADETPython.egg-info/PKG-INFO
5+
CADETPython.egg-info/SOURCES.txt
6+
CADETPython.egg-info/dependency_links.txt
7+
CADETPython.egg-info/requires.txt
8+
CADETPython.egg-info/top_level.txt
9+
cadet/__init__.py
10+
cadet/cadet.py
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

CADETPython.egg-info/requires.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
addict
2+
numpy
3+
h5py

CADETPython.egg-info/top_level.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cadet

cadet/cadet.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,24 +91,30 @@ def inverse_transform(self, x):
9191

9292
def run(self, timeout = None, check=None):
9393
if self.filename is not None:
94-
data = subprocess.run([self.cadet_path, self.filename], timeout = timeout, check=check, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
94+
data = subprocess.run([self.cadet_path, self.filename], timeout = timeout, check=check, capture_output=True)
9595
self.return_information = data
9696
return data
9797
else:
9898
print("Filename must be set before run can be used")
9999

100100
def recursively_load( h5file, path, func, paths):
101-
102-
ans = {}
103-
for key_original in h5file[path].keys():
104-
key = func(key_original)
105-
local_path = path + key
106-
if paths is None or (paths is not None and local_path in paths):
101+
ans = Dict()
102+
if paths is not None:
103+
for path in paths:
104+
item = h5file[path]
105+
if isinstance(item, h5py._hl.dataset.Dataset):
106+
ans[path[1:]] = item[()]
107+
elif isinstance(item, h5py._hl.group.Group):
108+
ans[path[1:]] = recursively_load(h5file, path + '/', func, None)
109+
else:
110+
for key_original in h5file[path].keys():
111+
key = func(key_original)
112+
local_path = path + key
107113
item = h5file[path][key_original]
108114
if isinstance(item, h5py._hl.dataset.Dataset):
109115
ans[key] = item[()]
110116
elif isinstance(item, h5py._hl.group.Group):
111-
ans[key] = recursively_load(h5file, local_path + '/', func, paths)
117+
ans[key] = recursively_load(h5file, local_path + '/', func, None)
112118
return ans
113119

114120
def recursively_save( h5file, path, dic, func):

examples/SMB.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66
import math
77

88
from cadet import Cadet
9-
Cadet.cadet_path = "C:/Users/kosh_000/cadet_build/CADET-dev/MS_SMKL_RELEASE/bin/cadet-cli.exe"
9+
#Cadet.cadet_path = "C:/Users/kosh_000/cadet_build/CADET-dev/MS_SMKL_RELEASE/bin/cadet-cli.exe"
10+
Cadet.cadet_path = "C:/Users/kosh_000/cadet_build/CADET/VCPKG/bin/cadet-cli.exe"
1011

1112
#use to render results
1213
import matplotlib.pyplot as plt
1314

1415
#number of columns in a cycle
15-
cycle_size = 4
16+
cycle_size = 8
1617

1718
#number of cycles
18-
cycles = 7
19+
cycles = 4
1920

2021
#number of times flows have to be expanded for a 4-zone model
2122
repeat_size = int(cycle_size/4)
@@ -121,7 +122,7 @@ def createSimulation(simulation):
121122
col.ncomp = 2
122123
col.cross_section_area = math.pi * (0.02**2)/4.0
123124
col.col_dispersion = 3.8148e-20
124-
col.col_length = 0.25
125+
col.col_length = 0.25/repeat_size
125126
col.col_porosity = 0.83
126127
col.init_c = [0.0, 0.0]
127128
col.init_q = [0.0, 0.0]

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="CADET",
8-
version="0.2",
8+
version="0.3",
99
author="William Heymann",
1010
author_email="[email protected]",
1111
description="CADET is a python interface to the CADET chromatography simulator",

0 commit comments

Comments
 (0)