Skip to content

Commit 0b64a3b

Browse files
committed
Minor changes
- Fixed par1-error when selecting None - Fixed par1/2-error when selecting data blocks with longer data name - Minor changes to color/font-size
1 parent ac7eaa0 commit 0b64a3b

3 files changed

Lines changed: 67 additions & 48 deletions

File tree

README.rst

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,42 @@
1+
======
12
PyCORN
23
======
34

45
A script to extract data from UNICORN result (.res) files and plot them.
56

67
.. image:: https://raw.githubusercontent.com/pyahmed/PyCORN/master/samples/sample1_2009Jun16no001_plot.jpg
78

9+
A script extract data from .res (results) files generated by UNICORN Chromatography software supplied with AKTA Systems. This script will find all data blocks, extract the data and write out csv-files. If you have matplotlib installed it will also plot all the curves including fractions if present. Plots can be saved in any format supported by matplotlib (default is pdf). Alternatively you may import pycorn into your script and access the data inside res-files.
10+
11+
----
812

9-
A script to extract data from .res (results) files generated by UNICORN Chromatography software supplied with AKTA Systems. This script will
10-
find all data blocks, extract the data and write out csv-files. If you have matplotlib installed it will also plot all the curves including
11-
fractions if present. Plots can be saved in any format supported by matplotlib (default is pdf). Alternatively you may import pycorn into your script and access the data inside res-files.
13+
News
14+
----
15+
- v0.13 released, available on PyPI, see docs/CHANGES.txt
1216

13-
Installation:
1417

18+
Installation
19+
------------
1520
- pip install pycorn
1621

17-
Limitations:
1822

23+
Limitations
24+
-----------
1925
- See https://github.com/pyahmed/PyCORN/issues
2026

21-
Requirements:
2227

23-
- Python 2.7 or 3.x (Tested on Windows 7 / Mac OSX)
24-
- optional: working matplotlib installation (for plotting)
28+
Requirements
29+
------------
30+
- Python 2.7 or 3.x (Tested on Linux / Windows 7 / Mac OSX)
31+
- optional: matplotlib (for plotting)
2532

26-
Usage:
2733

34+
Usage
35+
-----
2836
- See docs/USAGE_pycorn-bin.txt if you want to extract/plot data directly
29-
- See docs/USAGE_pycorn_module.txt if you want to use it as module
30-
37+
- See docs/USAGE_pycorn_module.txt if you want to import it into your script
3138

32-
License:
3339

40+
License
41+
-------
3442
- GPLv2 see docs/LICENSE.txt

examplescripts/pycorn-bin.py

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
help="Upper bound on the x-axis",
4949
metavar="#")
5050
group1.add_argument("--par1", type = str, default='Cond',
51-
help="Data for 2nd y-axis (Default=Cond)")
51+
help="Data for 2nd y-axis (Default=Cond), to disable 2nd y-axis, use --par1 None")
5252
group1.add_argument("--par2", type = str, default=None,
5353
help="Data for 3rd y-axis (Default=None)")
5454
group1.add_argument('-f', '--format', type = str,
@@ -126,7 +126,6 @@ def smartscale(inp):
126126
KeyError
127127
uv2_data = None
128128
uv3_data = None
129-
frac_delta = []
130129
try:
131130
frac_data = inp['Fractions']['data']
132131
frac_x, frac_y = xy_data(frac_data)
@@ -187,33 +186,43 @@ def plotterX(inp,fname):
187186
p0, = host.plot(x_dat, y_dat, label=inp[i]['data_name'], color=stl['color'],
188187
ls=stl['ls'], lw=stl['lw'],alpha=stl['alpha'])
189188
if args.par1:
190-
par1_inp = args.par1
191-
par1 = host.twinx()
192-
par1_data = inp[par1_inp]
193-
stl = styles[par1_inp]
194-
par1.set_ylabel(par1_data['data_name'] + " (" + par1_data['unit'] + ")", color=stl['color'])
195-
x_dat_p1, y_dat_p1 = xy_data(par1_data['data'])
196-
p1_ymin, p1_ymax = expander(min(y_dat_p1), max(y_dat_p1), 0.085)
197-
par1.set_ylim(p1_ymin, p1_ymax)
198-
print("Plotting: " + par1_data['data_name'])
199-
p1, = par1.plot(x_dat_p1, y_dat_p1, label=par1_data['data_name'], color=stl['color'],
200-
ls=stl['ls'], lw=stl['lw'], alpha=stl['alpha'])
189+
try:
190+
par1_inp = args.par1
191+
par1 = host.twinx()
192+
par1_data = inp[par1_inp]
193+
stl = styles[par1_inp[:4]]
194+
par1.set_ylabel(par1_data['data_name'] + " (" + par1_data['unit'] + ")", color=stl['color'])
195+
x_dat_p1, y_dat_p1 = xy_data(par1_data['data'])
196+
p1_ymin, p1_ymax = expander(min(y_dat_p1), max(y_dat_p1), 0.085)
197+
par1.set_ylim(p1_ymin, p1_ymax)
198+
print("Plotting: " + par1_data['data_name'])
199+
p1, = par1.plot(x_dat_p1, y_dat_p1, label=par1_data['data_name'],
200+
color=stl['color'], ls=stl['ls'], lw=stl['lw'], alpha=stl['alpha'])
201+
except:
202+
KeyError
203+
if par1_inp != None:
204+
print("Warning: Data block chosen for par1 does not exist!")
201205
if args.par2:
202-
par2_inp = args.par2
203-
par2 = host.twinx()
204-
offset = 60
205-
new_fixed_axis = par2.get_grid_helper().new_fixed_axis
206-
par2.axis["right"] = new_fixed_axis(loc="right", axes=par2, offset=(offset, 0))
207-
par2.axis["right"].toggle(all=True)
208-
par2_data = inp[par2_inp]
209-
stl = styles[par2_inp]
210-
par2.set_ylabel(par2_data['data_name'] + " (" + par2_data['unit'] + ")", color=stl['color'])
211-
x_dat_p2, y_dat_p2 = xy_data(par2_data['data'])
212-
p2_ymin, p2_ymax = expander(min(y_dat_p2), max(y_dat_p2), 0.075)
213-
par2.set_ylim(p2_ymin, p2_ymax)
214-
print("Plotting: " + par2_data['data_name'])
215-
p2, = par2.plot(x_dat_p2, y_dat_p2, label=par2_data['data_name'], color=stl['color'],
216-
ls=stl['ls'], lw=stl['lw'], alpha=stl['alpha'])
206+
try:
207+
par2_inp = args.par2
208+
par2 = host.twinx()
209+
offset = 60
210+
new_fixed_axis = par2.get_grid_helper().new_fixed_axis
211+
par2.axis["right"] = new_fixed_axis(loc="right", axes=par2, offset=(offset, 0))
212+
par2.axis["right"].toggle(all=True)
213+
par2_data = inp[par2_inp]
214+
stl = styles[par2_inp[:4]]
215+
par2.set_ylabel(par2_data['data_name'] + " (" + par2_data['unit'] + ")", color=stl['color'])
216+
x_dat_p2, y_dat_p2 = xy_data(par2_data['data'])
217+
p2_ymin, p2_ymax = expander(min(y_dat_p2), max(y_dat_p2), 0.075)
218+
par2.set_ylim(p2_ymin, p2_ymax)
219+
print("Plotting: " + par2_data['data_name'])
220+
p2, = par2.plot(x_dat_p2, y_dat_p2, label=par2_data['data_name'],
221+
color=stl['color'],ls=stl['ls'], lw=stl['lw'], alpha=stl['alpha'])
222+
except:
223+
KeyError
224+
if par2_inp != None:
225+
print("Warning: Data block chosen for par2 does not exist!")
217226
if args.no_fractions:
218227
try:
219228
frac_data = inp['Fractions']['data']
@@ -231,7 +240,7 @@ def plotterX(inp,fname):
231240
host.legend(fontsize=8, fancybox=True, labelspacing=0.4, loc='upper right')
232241
host.xaxis.set_minor_locator(AutoMinorLocator())
233242
host.yaxis.set_minor_locator(AutoMinorLocator())
234-
plt.title(fname, loc='left')
243+
plt.title(fname, loc='left', size=8)
235244
internal_run_name = str(inp['Logbook']['run_name'])
236245
plot_file = fname[:-4] + "_" + internal_run_name + "_plot." + args.format
237246
plt.savefig(plot_file, bbox_inches='tight', dpi=args.dpi)
@@ -269,10 +278,10 @@ def data_writer1(fname, inp):
269278
'UV1_':{'color': '#1919FF', 'lw': 1.6, 'ls': "-", 'alpha':1.0},
270279
'UV2_':{'color': '#e51616', 'lw': 1.4, 'ls': "-", 'alpha':1.0},
271280
'UV3_':{'color': '#c73de6', 'lw': 1.2, 'ls': "-", 'alpha':1.0},
272-
'Cond':{'color': '#62181A', 'lw': 1.4, 'ls': "-", 'alpha':0.75},
281+
'Cond':{'color': '#FF7C29', 'lw': 1.4, 'ls': "-", 'alpha':0.75},
273282
'Conc':{'color': '#0F990F', 'lw': 1.0, 'ls': "-", 'alpha':0.75},
274-
'Pres':{'color': '#3E1719', 'lw': 1.0, 'ls': "-", 'alpha':0.75},
275-
'Temp':{'color': '#e04730', 'lw': 1.0, 'ls': "-", 'alpha':0.75},
283+
'Pres':{'color': '#C0CBBA', 'lw': 1.0, 'ls': "-", 'alpha':0.50},
284+
'Temp':{'color': '#b29375', 'lw': 1.0, 'ls': "-", 'alpha':0.75},
276285
'Inje':{'color': '#d56d9d', 'lw': 1.0, 'ls': "-", 'alpha':0.75},
277286
'pH':{'color': '#0C7F7F', 'lw': 1.0, 'ls': "-", 'alpha':0.75},}
278287

@@ -297,4 +306,4 @@ def main2():
297306
if args.plot:
298307
plotterX(fdata, fname)
299308

300-
main2()
309+
main2()

pycorn/pycorn.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
#!/usr/bin/env python
21
# -*- coding: utf-8 -*-
32
'''
43
PyCORN - script to extract data from .res (results) files generated
54
by UNICORN Chromatography software supplied with ÄKTA Systems
65
(c)2014-2015 - Yasar L. Ahmed
7-
v0.13
6+
v0.14
87
'''
98

109
from __future__ import print_function
@@ -218,6 +217,9 @@ def sensor_read(self, dat, show=False):
218217
for i in range(dat['adresse'] + 207, dat['adresse'] + 222, 15):
219218
s_unit = struct.unpack("15s", fread[i:i + 15])
220219
s_unit_dec = (codecs.decode(s_unit[0], 'iso8859-1')).rstrip('\x00')
220+
# FIX: in some files the unit for temperature reads 'C' instead of '°C'
221+
if s_unit_dec == 'C':
222+
s_unit_dec = u'°C'
221223
for i in range(dat['d_start'], dat['d_end'], 8):
222224
sread = struct.unpack("ii", fread[i:i + 8])
223225
data = round((sread[0] / 100.0) - self.inject_vol, 4), sread[1] / sensor_div
@@ -259,4 +261,4 @@ def load(self, show=False):
259261
self[name] = dat
260262
else:
261263
# TODO: Maybe we should keep this around?
262-
del self[name]
264+
del self[name]

0 commit comments

Comments
 (0)