├── .gitattributes ├── .gitignore ├── README.rst ├── examplescripts └── pycorn-bin.py ├── pycorn ├── __init__.py ├── docs │ ├── CHANGES.txt │ ├── LICENSE.txt │ ├── RES_files_layout.txt │ ├── USAGE_pycorn-bin.txt │ └── USAGE_pycorn_module.txt └── pycorn.py ├── samples ├── sample1.res └── sample1_2009Jun16no001_plot.jpg └── setup.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | x64/ 49 | build/ 50 | [Bb]in/ 51 | [Oo]bj/ 52 | 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | 57 | *_i.c 58 | *_p.c 59 | *.ilk 60 | *.meta 61 | *.obj 62 | *.pch 63 | *.pdb 64 | *.pgc 65 | *.pgd 66 | *.rsp 67 | *.sbr 68 | *.tlb 69 | *.tli 70 | *.tlh 71 | *.tmp 72 | *.tmp_proj 73 | *.log 74 | *.vspscc 75 | *.vssscc 76 | .builds 77 | *.pidb 78 | *.log 79 | *.scc 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | *.ncrunch* 109 | .*crunch*.local.xml 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.Publish.xml 129 | *.pubxml 130 | 131 | # NuGet Packages Directory 132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 133 | #packages/ 134 | 135 | # Windows Azure Build Output 136 | csx 137 | *.build.csdef 138 | 139 | # Windows Store app package directory 140 | AppPackages/ 141 | 142 | # Others 143 | sql/ 144 | *.Cache 145 | ClientBin/ 146 | [Ss]tyle[Cc]op.* 147 | ~$* 148 | *~ 149 | *.dbmdl 150 | *.[Pp]ublish.xml 151 | *.pfx 152 | *.publishsettings 153 | 154 | # RIA/Silverlight projects 155 | Generated_Code/ 156 | 157 | # Backup & report files from converting an old project file to a newer 158 | # Visual Studio version. Backup files are not needed, because we have git ;-) 159 | _UpgradeReport_Files/ 160 | Backup*/ 161 | UpgradeLog*.XML 162 | UpgradeLog*.htm 163 | 164 | # SQL Server files 165 | App_Data/*.mdf 166 | App_Data/*.ldf 167 | 168 | ############# 169 | ## Windows detritus 170 | ############# 171 | 172 | # Windows image file caches 173 | Thumbs.db 174 | ehthumbs.db 175 | 176 | # Folder config file 177 | Desktop.ini 178 | 179 | # Recycle Bin used on file shares 180 | $RECYCLE.BIN/ 181 | 182 | # Mac crap 183 | .DS_Store 184 | 185 | 186 | ############# 187 | ## Python 188 | ############# 189 | 190 | *.py[co] 191 | 192 | # Packages 193 | *.egg 194 | *.egg-info 195 | dist/ 196 | build/ 197 | eggs/ 198 | parts/ 199 | var/ 200 | sdist/ 201 | develop-eggs/ 202 | .installed.cfg 203 | 204 | # Installer logs 205 | pip-log.txt 206 | 207 | # Unit test / coverage reports 208 | .coverage 209 | .tox 210 | 211 | #Translations 212 | *.mo 213 | 214 | #Mr Developer 215 | .mr.developer.cfg 216 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | ====== 2 | PyCORN 3 | ====== 4 | 5 | A script to extract data from UNICORN result (.res) files and plot them. 6 | 7 | .. image:: https://raw.githubusercontent.com/pyahmed/PyCORN/master/samples/sample1_2009Jun16no001_plot.jpg 8 | 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 | ---- 12 | 13 | News 14 | ---- 15 | PyCORN-WEB launched: 16 | PyCORN is now available as a web-service. Just drop your res/zip file, get a preview of the plot (generated with plotly) - adjust as needed and download a high-quality PNG file. No need to open a terminal, no Python installation etc required :-) 17 | 18 | visit: http://pycornweb.appspot.com 19 | 20 | ======= 21 | 22 | v0.19 released: 23 | 24 | - FIXED: Injection points not recognized properly (see https://github.com/pyahmed/PyCORN/issues/12) 25 | 26 | 27 | Installation 28 | ------------ 29 | - pip install pycorn 30 | 31 | 32 | Known issues 33 | ------------ 34 | - See https://github.com/pyahmed/PyCORN/issues 35 | 36 | 37 | Requirements 38 | ------------ 39 | - Python 2.7 or 3.x (Tested on Linux / Windows 7 / Mac OSX) 40 | - optional: matplotlib (for plotting) 41 | - optional: xlsxwriter (for xlsx-output) 42 | 43 | Usage 44 | ----- 45 | - See pycorn/docs/USAGE_pycorn-bin.txt if you want to extract/plot data directly 46 | - See pycorn/docs/USAGE_pycorn_module.txt if you want to import it into your script 47 | 48 | 49 | License 50 | ------- 51 | - GPLv2 see docs/LICENSE.txt 52 | -------------------------------------------------------------------------------- /examplescripts/pycorn-bin.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | ''' 4 | PyCORN - script to extract data from .res (results) files generated 5 | by UNICORN Chromatography software supplied with ÄKTA Systems 6 | (c)2014-2016 - Yasar L. Ahmed 7 | v0.18 8 | ''' 9 | 10 | import argparse 11 | from pycorn import pc_res3 12 | from pycorn import pc_uni6 13 | 14 | try: 15 | from mpl_toolkits.axes_grid1 import host_subplot 16 | from matplotlib.ticker import AutoMinorLocator 17 | import mpl_toolkits.axisartist as AA 18 | import matplotlib.pyplot as plt 19 | plotting = True 20 | except: 21 | ImportError 22 | print("WARNING: Matplotlib not found - Plotting disabled!") 23 | plotting = False 24 | 25 | try: 26 | import xlsxwriter 27 | xlsx = True 28 | except: 29 | ImportError 30 | print("WARNING: xlsxwriter not found - xlsx-output disabled!") 31 | xlsx = False 32 | 33 | pcscript_version = 0.14 34 | 35 | parser = argparse.ArgumentParser( 36 | description = "Extract data from UNICORN .res files to .csv/.txt and plot them (matplotlib required)", 37 | epilog = "Make it so!") 38 | parser.add_argument("-c", "--check", 39 | help = "Perform simple check if file is supported", 40 | action = "store_true") 41 | parser.add_argument("-n", "--info", 42 | help = "Display entries in header", 43 | action = "store_true") 44 | parser.add_argument("-i", "--inject", type = int, default = None, 45 | help = "Set injection number # as zero retention, use -t to find injection points", 46 | metavar="#") 47 | parser.add_argument("-r", "--reduce", type = int, default = 1, 48 | help = "Write/Plot only every n sample", 49 | metavar="#") 50 | parser.add_argument("-t", "--points", 51 | help = "Display injection points", 52 | action = "store_true") 53 | 54 | group0 = parser.add_argument_group('Extracting', 'Options for writing csv/txt files') 55 | group0.add_argument("-e", "--extract", type=str, choices=['csv','xlsx'], 56 | help = "Write data to csv or xlsx file for supported data blocks") 57 | 58 | group1 = parser.add_argument_group('Plotting', 'Options for plotting') 59 | group1.add_argument("-p", "--plot", 60 | help = 'Plot curves', 61 | action = "store_true") 62 | group1.add_argument("--no_fractions", 63 | help="Disable plotting of fractions", 64 | action = "store_true") 65 | group1.add_argument("--no_inject", 66 | help="Disable plotting of inject marker(s)", 67 | action = "store_true") 68 | group1.add_argument("--no_legend", 69 | help="Disable legend for plot", 70 | action = "store_true") 71 | group1.add_argument("--no_title", 72 | help="Disable title for plot", 73 | action = "store_true") 74 | group1.add_argument("--xmin", type = float, default=None, 75 | help="Lower bound on the x-axis", 76 | metavar="#") 77 | group1.add_argument("--xmax", type = float, default=None, 78 | help="Upper bound on the x-axis", 79 | metavar="#") 80 | group1.add_argument("--par1", type = str, default='Cond', 81 | help="Data for 2nd y-axis (Default=Cond), to disable 2nd y-axis, use --par1 None") 82 | group1.add_argument("--par2", type = str, default=None, 83 | help="Data for 3rd y-axis (Default=None)") 84 | group1.add_argument('-f', '--format', type = str, 85 | choices=['svg','svgz','tif','tiff','jpg','jpeg', 86 | 'png','ps','eps','raw','rgba','pdf','pgf'], 87 | default = 'pdf', 88 | help = "File format of plot files (default: pdf)") 89 | group1.add_argument('-d', '--dpi', default=300, type=int, 90 | help="DPI (dots per inch) for raster images (png, jpg, etc.). Default is 300.") 91 | parser.add_argument("-u", "--user", 92 | help = "Show stored user name", 93 | action = "store_true") 94 | parser.add_argument('--version', action='version', version=str(pcscript_version)) 95 | parser.add_argument("inp_res", 96 | help="Input .res file(s)", 97 | nargs='+', 98 | metavar=".res") 99 | #args.no_inject 100 | args = parser.parse_args() 101 | 102 | def mapper(min_val, max_val, perc): 103 | ''' 104 | calculate relative position in delta min/max 105 | ''' 106 | x = abs(max_val - min_val) * perc 107 | if min_val < 0: 108 | return (x - abs(min_val)) 109 | else: 110 | return (x + min_val) 111 | 112 | 113 | def expander(min_val, max_val, perc): 114 | ''' 115 | expand -/+ direction of two values by a percentage of their delta 116 | ''' 117 | delta = abs(max_val - min_val) 118 | x = delta * perc 119 | return (min_val - x, max_val + x) 120 | 121 | 122 | def xy_data(inp): 123 | ''' 124 | Takes a data block and returns two lists with x- and y-data 125 | ''' 126 | x_data = [x[0] for x in inp] 127 | y_data = [x[1] for x in inp] 128 | return x_data, y_data 129 | 130 | 131 | def uvdata(inp): 132 | ''' 133 | helps in finding the useful data 134 | ''' 135 | UV_blocks = [i for i in inp if i.startswith('UV') or i.endswith('nm')] 136 | for i in UV_blocks: 137 | if i.endswith("_0nm"): 138 | UV_blocks.remove(i) 139 | 140 | 141 | def smartscale(inp): 142 | ''' 143 | input is the entire fdata block 144 | checks user input/fractions to determine scaling of x/y-axis 145 | returns min/max for x/y 146 | ''' 147 | UV_blocks = [i for i in inp.keys() if i.startswith('UV') and not i.endswith('_0nm')] 148 | uv1_data = inp[UV_blocks[0]]['data'] 149 | uv1_x, uv1_y = xy_data(uv1_data) 150 | try: 151 | uv2_data = inp[UV_blocks[1]]['data'] 152 | uv2_x, uv2_y = xy_data(uv2_data) 153 | uv3_data = inp[UV_blocks[2]]['data'] 154 | uv3_x, uv3_y = xy_data(uv3_data) 155 | except: 156 | KeyError 157 | uv2_data = None 158 | uv3_data = None 159 | try: 160 | frac_data = inp['Fractions']['data'] 161 | frac_x, frac_y = xy_data(frac_data) 162 | frac_delta = [abs(a - b) for a, b in zip(frac_x, frac_x[1:])] 163 | frac_delta.append(frac_delta[-1]) 164 | except: 165 | KeyError 166 | frac_data = None 167 | if args.xmin != None: 168 | plot_x_min = args.xmin 169 | else: 170 | if frac_data: 171 | plot_x_min = frac_data[0][0] 172 | else: 173 | plot_x_min = uv1_x[0] 174 | if args.xmax: 175 | plot_x_max = args.xmax 176 | else: 177 | if frac_data: 178 | plot_x_max = frac_data[-1][0] + frac_delta[-1]*2 # recheck 179 | else: 180 | plot_x_max = uv1_x[-1] 181 | if plot_x_min > plot_x_max: 182 | print("Warning: xmin bigger than xmax - adjusting...") 183 | plot_x_min = uv1_x[0] 184 | if plot_x_max < plot_x_min: 185 | print("Warning: xmax smaller than xmin - adjusting...") 186 | plot_x_max = uv1_x[-1] 187 | # optimize y_scaling 188 | min_y_values = [] 189 | max_y_values = [] 190 | for i in UV_blocks: 191 | tmp_x, tmp_y = xy_data(inp[i]['data']) 192 | range_min_lst = [abs(a - plot_x_min) for a in tmp_x] 193 | range_min_idx = range_min_lst.index(min(range_min_lst)) 194 | range_max_lst = [abs(a - plot_x_max) for a in tmp_x] 195 | range_max_idx = range_max_lst.index(min(range_max_lst)) 196 | values_in_range = tmp_y[range_min_idx:range_max_idx] 197 | min_y_values.append(min(values_in_range)) 198 | max_y_values.append(max(values_in_range)) 199 | plot_y_min_tmp = min(min_y_values) 200 | plot_y_max_tmp = max(max_y_values) 201 | plot_y_min, plot_y_max = expander(plot_y_min_tmp, plot_y_max_tmp, 0.085) 202 | return plot_x_min, plot_x_max, plot_y_min, plot_y_max 203 | 204 | def plotterX(inp,fname): 205 | plot_x_min, plot_x_max, plot_y_min, plot_y_max = smartscale(inp) 206 | host = host_subplot(111, axes_class=AA.Axes) 207 | host.set_xlabel("Elution volume (ml)") 208 | host.set_ylabel("Absorbance (mAu)") 209 | host.set_xlim(plot_x_min, plot_x_max) 210 | host.set_ylim(plot_y_min, plot_y_max) 211 | for i in inp.keys(): 212 | if i.startswith('UV') and not i.endswith('_0nm'): 213 | x_dat, y_dat = xy_data(inp[i]['data']) 214 | print("Plotting: " + inp[i]['data_name']) 215 | stl = styles[i[:4]] 216 | p0, = host.plot(x_dat, y_dat, label=inp[i]['data_name'], color=stl['color'], 217 | ls=stl['ls'], lw=stl['lw'],alpha=stl['alpha']) 218 | if args.par1 == 'None': 219 | args.par1 = None 220 | if args.par1: 221 | try: 222 | par1_inp = args.par1 223 | par1 = host.twinx() 224 | par1_data = inp[par1_inp] 225 | stl = styles[par1_inp[:4]] 226 | par1.set_ylabel(par1_data['data_name'] + " (" + par1_data['unit'] + ")", color=stl['color']) 227 | x_dat_p1, y_dat_p1 = xy_data(par1_data['data']) 228 | p1_ymin, p1_ymax = expander(min(y_dat_p1), max(y_dat_p1), 0.085) 229 | par1.set_ylim(p1_ymin, p1_ymax) 230 | print("Plotting: " + par1_data['data_name']) 231 | p1, = par1.plot(x_dat_p1, y_dat_p1, label=par1_data['data_name'], 232 | color=stl['color'], ls=stl['ls'], lw=stl['lw'], alpha=stl['alpha']) 233 | except: 234 | KeyError 235 | if par1_inp != None: 236 | print("Warning: Data block chosen for par1 does not exist!") 237 | if args.par2: 238 | try: 239 | par2_inp = args.par2 240 | par2 = host.twinx() 241 | offset = 60 242 | new_fixed_axis = par2.get_grid_helper().new_fixed_axis 243 | par2.axis["right"] = new_fixed_axis(loc="right", axes=par2, offset=(offset, 0)) 244 | par2.axis["right"].toggle(all=True) 245 | par2_data = inp[par2_inp] 246 | stl = styles[par2_inp[:4]] 247 | par2.set_ylabel(par2_data['data_name'] + " (" + par2_data['unit'] + ")", color=stl['color']) 248 | x_dat_p2, y_dat_p2 = xy_data(par2_data['data']) 249 | p2_ymin, p2_ymax = expander(min(y_dat_p2), max(y_dat_p2), 0.075) 250 | par2.set_ylim(p2_ymin, p2_ymax) 251 | print("Plotting: " + par2_data['data_name']) 252 | p2, = par2.plot(x_dat_p2, y_dat_p2, label=par2_data['data_name'], 253 | color=stl['color'],ls=stl['ls'], lw=stl['lw'], alpha=stl['alpha']) 254 | except: 255 | KeyError 256 | if par2_inp != None: 257 | print("Warning: Data block chosen for par2 does not exist!") 258 | if not args.no_fractions: 259 | try: 260 | frac_data = inp['Fractions']['data'] 261 | frac_x, frac_y = xy_data(frac_data) 262 | frac_delta = [abs(a - b) for a, b in zip(frac_x, frac_x[1:])] 263 | frac_delta.append(frac_delta[-1]) 264 | frac_y_pos = mapper(host.get_ylim()[0], host.get_ylim()[1], 0.015) 265 | for i in frac_data: 266 | host.axvline(x=i[0], ymin=0.065, ymax=0.0, color='r', linewidth=0.85) 267 | host.annotate(str(i[1]), xy=(i[0] + frac_delta[frac_data.index(i)] * 0.55, frac_y_pos), 268 | horizontalalignment='center', verticalalignment='bottom', size=8, rotation=90) 269 | except: 270 | KeyError 271 | if inp.inject_vol != 0.0: 272 | injections = inp.injection_points 273 | host.axvline(x=0, ymin=0.10, ymax=0.0, color='#FF3292', 274 | ls ='-', marker='v', markevery=2, linewidth=1.5, alpha=0.85, label='Inject') 275 | host.set_xlim(plot_x_min, plot_x_max) 276 | if not args.no_legend: 277 | host.legend(fontsize=8, fancybox=True, labelspacing=0.4, loc='upper right', numpoints=1) 278 | host.xaxis.set_minor_locator(AutoMinorLocator()) 279 | host.yaxis.set_minor_locator(AutoMinorLocator()) 280 | if not args.no_title: 281 | plt.title(fname, loc='left', size=9) 282 | plot_file = fname[:-4] + "_" + inp.run_name + "_plot." + args.format 283 | plt.savefig(plot_file, bbox_inches='tight', dpi=args.dpi) 284 | print("Plot saved to: " + plot_file) 285 | plt.clf() 286 | 287 | def data_writer1(fname, inp): 288 | ''' 289 | writes sensor/run-data to csv-files 290 | ''' 291 | for i in inp.keys(): 292 | print("Writing: " + inp[i]['data_name']) 293 | outfile_base = fname[:-4] + "_" + inp.run_name + "_" + inp[i]['data_name'] 294 | type = inp[i]['data_type'] 295 | if type == 'meta': 296 | data = inp[i]['data'] 297 | data_to_write = data.encode('utf-8') 298 | ext = '.txt' 299 | sep = '\t' 300 | with open(outfile_base + ext, 'wb') as fout: 301 | fout.write(data_to_write) 302 | else: 303 | x_dat,y_dat = xy_data(inp[i]['data']) 304 | ext = '.csv' 305 | sep = ',' 306 | with open(outfile_base + ext, 'wb') as fout: 307 | for x,y in zip(x_dat,y_dat): 308 | dp = str(x) + sep + str(y) + str('\r\n') 309 | data_to_write = dp.encode('utf-8') 310 | fout.write(data_to_write) 311 | 312 | def generate_xls(inp, fname): 313 | ''' 314 | Input = pycorn object 315 | output = xlsx file 316 | ''' 317 | xls_filename = fname[:-4] + "_" + inp.run_name + ".xlsx" 318 | workbook = xlsxwriter.Workbook(xls_filename) 319 | worksheet = workbook.add_worksheet() 320 | writable_blocks = [inp.Fractions_id, inp.Fractions_id2, inp.SensData_id, inp.SensData_id2] 321 | d_list = [] 322 | for i in inp.keys(): 323 | if inp[i]['magic_id'] in writable_blocks: 324 | d_list.append(i) 325 | for i in d_list: 326 | dat = inp[i]['data'] 327 | try: 328 | unit = inp[i]['unit'] 329 | except: 330 | KeyError 331 | unit = 'Fraction' 332 | header1 = (inp[i]['data_name'], '') 333 | header2 = ('ml', unit) 334 | dat.insert(0, header1) 335 | dat.insert(1, header2) 336 | row = 0 337 | col = d_list.index(i) *2 338 | print("Writing: " + i) 339 | for x_val, y_val in (dat): 340 | worksheet.write(row, col, x_val) 341 | worksheet.write(row, col + 1, y_val) 342 | row += 1 343 | workbook.close() 344 | print("Data written to: " + xls_filename) 345 | 346 | 347 | styles = {'UV':{'color': '#1919FF', 'lw': 1.6, 'ls': "-", 'alpha':1.0}, 348 | 'UV1_':{'color': '#1919FF', 'lw': 1.6, 'ls': "-", 'alpha':1.0}, 349 | 'UV2_':{'color': '#e51616', 'lw': 1.4, 'ls': "-", 'alpha':1.0}, 350 | 'UV3_':{'color': '#c73de6', 'lw': 1.2, 'ls': "-", 'alpha':1.0}, 351 | 'UV 1':{'color': '#1919FF', 'lw': 1.6, 'ls': "-", 'alpha':1.0}, 352 | 'UV 2':{'color': '#e51616', 'lw': 1.4, 'ls': "-", 'alpha':1.0}, 353 | 'UV 3':{'color': '#c73de6', 'lw': 1.2, 'ls': "-", 'alpha':1.0}, 354 | 'Cond':{'color': '#FF7C29', 'lw': 1.4, 'ls': "-", 'alpha':0.75}, 355 | 'Conc':{'color': '#0F990F', 'lw': 1.0, 'ls': "-", 'alpha':0.75}, 356 | 'Pres':{'color': '#C0CBBA', 'lw': 1.0, 'ls': "-", 'alpha':0.50}, 357 | 'Temp':{'color': '#b29375', 'lw': 1.0, 'ls': "-", 'alpha':0.75}, 358 | 'Inje':{'color': '#d56d9d', 'lw': 1.0, 'ls': "-", 'alpha':0.75}, 359 | 'pH':{'color': '#0C7F7F', 'lw': 1.0, 'ls': "-", 'alpha':0.75},} 360 | 361 | 362 | def main2(): 363 | for fname in args.inp_res: 364 | if args.inject == None: 365 | args.inject = -1 366 | if (fname[-3:]).lower() == "zip": 367 | fdata = pc_uni6(fname) 368 | fdata.load() 369 | fdata.xml_parse() 370 | fdata.clean_up() 371 | if (fname[-3:]).lower() == "res": 372 | fdata = pc_res3(fname, reduce = args.reduce, inj_sel=args.inject) 373 | fdata.load() 374 | if args.extract == 'csv': 375 | data_writer1(fname, fdata) 376 | if args.extract == 'xlsx' and xlsx == True: 377 | generate_xls(fdata, fname) 378 | if args.check: 379 | fdata.input_check(show=True) 380 | if args.info: 381 | fdata.showheader() 382 | if args.points: 383 | fdata.inject_det(show=True) 384 | if args.user: 385 | user = fdata.get_user() 386 | print("User: " + user) 387 | if args.plot and plotting: 388 | plotterX(fdata, fname) 389 | 390 | main2() 391 | -------------------------------------------------------------------------------- /pycorn/__init__.py: -------------------------------------------------------------------------------- 1 | from .pycorn import * 2 | -------------------------------------------------------------------------------- /pycorn/docs/CHANGES.txt: -------------------------------------------------------------------------------- 1 | v0.18 2 | ====== 3 | - FIXED: xmin being ignored when 0 4 | - FIXED: Files with capitalised name ending are not loaded 5 | 6 | v0.17 7 | ====== 8 | - Added experimental support for extracting and plotting UNICORN6 zip bundles 9 | 10 | v0.16b 11 | ====== 12 | - Fixed line ending on non-Windows setups 13 | 14 | v0.15 15 | ====== 16 | - Added option to disable title for plot 17 | - Added option to disable plotting inject marks 18 | - Added option to disable legend 19 | 20 | v0.14 21 | ====== 22 | - Inject mark is also plotted 23 | - xlsx output added (requires xlsxwriter) 24 | - Fixed par1-error when selecting None 25 | - Fixed par1/2-error when selecting data blocks with longer data name 26 | - Minor changes & fixes 27 | - Included Docs 28 | 29 | v0.13 30 | ====== 31 | - Conversion to of PyCORN to class-structure, allows using PyCORN in other scripts (by Wendell Smith) 32 | - Plots are now UV + user selectable 2nd/3rd data block (2nd y-axis is Conductivity by default) 33 | - Made some changes to adapt for PyPI 34 | - Installation should place pycorn-bin.py in Python/Scripts-folder 35 | 36 | v0.12 37 | ====== 38 | - Logbook is extracted and written to txt-file 39 | - Some parts rewritten 40 | - Fractions are also plotted 41 | - Improved scaling of y-axis (still not perfect) 42 | - Option to set start/end-point for plotting 43 | - Handles files that have been analyzed and re-saved 44 | 45 | 46 | 47 | v0.11 48 | ====== 49 | - changed data structure (now mostly dicts) 50 | - made plotting independent of writing csv/txt files 51 | - all plots contain (if present) fractions 52 | - x-axis scaling is based on first and last fraction 53 | - plots can be saved now in all matplotlib-supported formats (default: pdf) 54 | 55 | 56 | v0.1 57 | ====== 58 | - Initial release 59 | -------------------------------------------------------------------------------- /pycorn/docs/LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /pycorn/docs/RES_files_layout.txt: -------------------------------------------------------------------------------- 1 | UNICORN result files 2 | ==================== 3 | 4 | UNICORN is a control/evaluation software supplied with ÄKTA chromatography systems from GE Healthcare. Every chromatography run generates a result file (res-file), which is a binary file containing metadata about the run and data retrieved from various sensors in the chromatography system. Common sensors included in most ÄKTA-Systems cover UV-absorption, pH, conductivity, system pressure etc. 5 | 6 | The documentation supplied here is the result of reverse-engineering a limited number of such files obtained from ÄKTA Prime and ÄKTA Purifier systems. Different versions (especially newer ones) of UNICORN may generate files with different layout/encoding. 7 | 8 | General layout (s. samples/sample1.res) 9 | -------------------- 10 | START --> HEADER --> DATA_BLOCKS 11 | To follow along - open sample1.res (under samples/) in a hex-viewer/editor. Hex numbers given in parenthesis are from the sample1.res. Padding bytes may not be explicitly described throughout this document. 12 | 13 | ---START--- 14 | Res-files start with a few check/info bytes: 15 | - first 16 bytes are "11 47 11 47 18 00 00 00 B0 02 00 00 20 6C 03 00" 16 | most likely magic number to positively identify a res file 17 | - next 4 bytes give EOF/file size (20 EA 0D 00) 18 | probably allow a check if recorded file size matches actual file 19 | - next 4 bytes are empty 20 | - next 12 bytes contain string "UNICORN 3.10" (55 4E 49 43 4F 52 4E 20 33 2E 31 30) 21 | file format version(?) 22 | - at position 118 is the user name as used in Purifier systems or "prime" if the file originates from an ÄKTA Prime system. Length up to 40 characters. (70 72 69 6D 65) 23 | 24 | ---HEADER--- 25 | The header contains entries of the recorded data. Entries are made up of the original file name = run name ("Manual Run 3" for ex.) and name of data series (1_UV for ex.). Additionally their position in the file and several offsets are recorded. The header ends with the last entry called "LogBook" (notice capital "B"). 26 | - Entries start at position 686, first entry is either CONFIG or Methods 27 | - Entries are 344 bytes 28 | FORMAT of entries 29 | - 8 bytes magic-id defining type of data (meta/sensor/aux etc). WARNING: If a file has been opened and resaved the 2nd last byte is incremented by one (see table at the end, ... 01 14 --> 02 14) 30 | - 296 bytes (incl. padding) Name of data entry (CONFIG, METHOD, Logbook, 1_UV, UV1_280nm etc.) 31 | - 4 bytes int, size of the data block 32 | - 4 bytes int, offset to next data block (from meta to meta) 33 | - 4 bytes int, adresse of the data block (including some metadata) 34 | - 4 bytes int, offset from metadata to actual data 35 | -> S. example below 36 | - entries that deal with data generated by the machine during the run (UV, pressure etc.) are preceeded by hex "00 00 01 00 04 00 01 14" 37 | - Last entry is called "LogBook" (notice capital B! LogBook only occurs once per file) preceeded by hex value "00 00 00 01 00 02 00 01 13" 38 | The entries are followed by lots of padding and eventually the data blocks which hold the data. 39 | 40 | Example values: 41 | sample1.res UV-entry (at 2366) 42 | C8 A0 01 00 00 A2 01 00 20 92 03 00 F0 00 00 00 43 | ----V1----- ----V2----- ----V3----- ----V4----- 44 | V1 (C8 A0 01 00) signed int, 106696 is the size of the data block including metadata 45 | V2 (00 A2 01 00) signed int, 107008 is the offset to next data block (from meta to meta) 46 | V3 (20 92 03 00) signed int, 234016 is the begin of the data block including metadata 47 | V4 (F0 00 00 00) signed int, 240 is the offset from V2 to actual begin of data 48 | 49 | ---DATA_BLOCKS--- 50 | There are different types of data blocks: 51 | - Sensor data, marked with "06 00 02 00 01 00 4E 00" (adresse specified in header) 52 | - Metadata (type1, generated during the run), marked with "06 00 06 00 01 00 4E 00" (adresse specified in header) 53 | - Metadata (type2, generated before run), no offset, pure string data, no special marker 54 | 55 | Structure of sensor data 56 | 8 bytes per pair 57 | 4 bytes sig/int Accumulated volume, divide by 100 to obtain value in ml 58 | 4 bytes sig/int Sensor value, divide by 1000/100/10 depending on sensor type 59 | 60 | Structure of meta-data/type1 (Logbook, Fractions etc.) 61 | 180 bytes per pair/trio 62 | 8 bytes double float accumulated time (in minutes?) 63 | 8 bytes double float accumulated volume (in ml) 64 | 164 bytes string Logbook-event, Fraction number or "Waste" 65 | 66 | Structure of meta-data/type2 (pure meta-data like method used during run) 67 | - size defined in header (but maybe off by 1 or two bytes!) 68 | - pure string 69 | - string encoding is windows cp1250 / variants of it, depending on installed system 70 | 71 | There are two logbooks per file. Logbook and LogBook (notice capital B in 2nd one). They contain similar but not exactly the same information. LogBook is always the last entry in a res-file. LogBook contains entries acc. to system time 72 | - strings in format like this "Concentration 0 %B.09, 21:51:45, Method : , Result : C:\...\prime\2009Jun16no001.RES" 73 | - entries are separated by 202 bytes from begin to begin 74 | 75 | ---- 76 | Magic bytes preceeding header entries: 77 | - System data shares same id 78 | - Fractions and LogBook/Logbook have the same/similar format but have different id 79 | - Ids are consistent across (at least two) different systems (Prime/Purifier) 80 | - Ids for Logbook, sensor data (UV/cond/conc/...), Injection marks and fractions are changed if a file is opened and resaved (2nd last byte is incremented by one: 81 | Logbook ... 48 04 --> ... 49 04 82 | Sens. data ... 01 14 --> ... 02 14 83 | Inj. mark ... 46 04 --> ... 47 04 84 | Fractions ... 44 04 --> ... 45 04 85 | 86 | ---Magic-ids--- 87 | The following magic_ids have been found and assigned so far: 88 | AKTA PRIME 89 | HEX VALUE String 90 | 00 00 01 00 02 00 01 00 CONFIG 91 | 00 00 01 00 02 00 04 02 METHODINFO 92 | 00 00 01 00 02 00 03 22 CreationNotes = Program / plain text 93 | 00 00 01 00 04 00 48 04 Logbook 94 | 00 00 01 00 04 00 01 14 UV 95 | 00 00 01 00 04 00 01 14 Cond 96 | 00 00 01 00 04 00 01 14 pH 97 | 00 00 01 00 04 00 01 14 Pressure 98 | 00 00 01 00 04 00 01 14 Temp 99 | 00 00 01 00 04 00 01 14 Conc 100 | 00 00 01 00 04 00 44 04 Fractions 101 | 00 00 01 00 02 00 50 03 1 102 | 00 00 01 00 02 00 01 13 LogBook 103 | 104 | AKTA PURIFIER 105 | HEX VALUE String 106 | 00 00 01 00 02 00 01 02 Methods 107 | 00 00 01 00 02 00 07 22 MethodHistory 108 | 00 00 01 00 02 00 02 12 DOCUMENT 109 | 00 00 01 00 02 00 03 22 CreationNotes 110 | 00 00 01 00 02 00 55 22 StrategyInformation 111 | 00 00 01 00 02 00 10 22 MethodStrategyNotes 112 | 00 00 01 00 02 00 01 00 Methods Signatures 113 | 00 00 01 00 02 00 01 00 CONFIG 114 | 00 00 01 00 02 00 01 00 CALIB 115 | 00 00 01 00 02 00 04 02 METHODINFO 116 | 00 00 01 00 02 00 10 22 ResultStrategyNotes 117 | 00 00 01 00 04 00 48 04 Logbook 118 | 00 00 01 00 04 00 01 14 UV1_280nm 119 | 00 00 01 00 04 00 01 14 UV2_254nm 120 | 00 00 01 00 04 00 01 14 UV3_0nm 121 | 00 00 01 00 04 00 01 14 Cond 122 | 00 00 01 00 04 00 01 14 Cond% 123 | 00 00 01 00 04 00 01 14 Conc 124 | 00 00 01 00 04 00 01 14 Pressure 125 | 00 00 01 00 04 00 01 14 Flow 126 | 00 00 01 00 04 00 01 14 Temp 127 | 00 00 01 00 04 00 01 14 AuxIn1 128 | 00 00 01 00 04 00 01 14 AuxOut1 129 | 00 00 01 00 04 00 01 14 P960_Press 130 | 00 00 01 00 04 00 01 14 P960_Flow 131 | 00 00 01 00 04 00 46 04 Inject 132 | 00 00 01 00 02 00 01 13 LogBook 133 | -------------------------------------------------------------------------------- /pycorn/docs/USAGE_pycorn-bin.txt: -------------------------------------------------------------------------------- 1 | How to use PyCORN 2 | 3 | PyCORN may be used either via the pycorn-bin.py-script or imported as a module in your scripts (see USAGE_pycorn_module.txt). 4 | 5 | pycorn-bin.py: 6 | -------------- 7 | The default installation places pycorn-bin.py in the python/scripts-folder and therefor ready-to-use on most platforms. This script re-implements most of the features of the original pycorn.py-script. Usage is very similar, as only a few paramters have changed. Data from UNICORN6 zip-bundles may also be plotted or extracted (experimental). 8 | 9 | 10 | usage: pycorn-bin.py [-h] [-c] [-n] [-i #] [-r #] [-t] [-e] [-p] 11 | [--no_fractions] [--xmin #] [--xmax #] [--par1 PAR1] 12 | [--par2 PAR2] 13 | [-f {svg,svgz,tif,tiff,jpg,jpeg,png,ps,eps,raw,rgba,pdf,pgf 14 | }] 15 | [-d DPI] [-u] [--version] 16 | .res [.res ...] 17 | 18 | Extract data from UNICORN .res files to .csv/.txt and plot them (matplotlib 19 | required) 20 | 21 | positional arguments: 22 | .res Input .res file(s) 23 | 24 | optional arguments: 25 | -h, --help show this help message and exit 26 | -c, --check Perform simple check if file is supported 27 | -n, --info Display entries in header 28 | -i #, --inject # Set injection number # as zero retention, use -t to 29 | find injection points 30 | -r #, --reduce # Write/Plot only every n sample 31 | -t, --points Display injection points 32 | -u, --user Show stored user name 33 | --version show program's version number and exit 34 | 35 | Extracting: 36 | Options for writing csv/txt files 37 | 38 | -e {csv,xlsx}, --extract {csv,xlsx} 39 | Write data to csv or xlsx file for supported data 40 | blocks 41 | 42 | Plotting: 43 | Options for plotting 44 | 45 | -p, --plot Plot curves 46 | --no_fractions Disable plotting of fractions 47 | --xmin # Lower bound on the x-axis 48 | --xmax # Upper bound on the x-axis 49 | --par1 PAR1 Data for 2nd y-axis (Default=Cond) 50 | --par2 PAR2 Data for 3rd y-axis (Default=None) 51 | -f {svg,svgz,tif,tiff,jpg,jpeg,png,ps,eps,raw,rgba,pdf,pgf}, --format {svg,svg 52 | z,tif,tiff,jpg,jpeg,png,ps,eps,raw,rgba,pdf,pgf} 53 | File format of plot files (default: pdf) 54 | -d DPI, --dpi DPI DPI (dots per inch) for raster images (png, jpg, 55 | etc.). Default is 300. 56 | 57 | Notes: 58 | By default pycorn-bin.py will plot from first to last fraction, as that is usually the interesting part. If no fractions are present in the run then from beginning to end. To override this behaviour you can use the (both) optional --xmin/--xmax switches to specify beginning and end of the plot. 59 | 60 | Examples: 61 | Show user who ran method: 62 | pycorn-bin.py -u input.res 63 | 64 | Show injection points: 65 | pycorn-bin.py -t input.res 66 | 67 | Extract data to csv files: 68 | pycorn-bin.py -e csv input.res 69 | 70 | 71 | Extract data to xlsx-file: 72 | pycorn-bin.py -e xlsx input.res 73 | 74 | Plot all data: 75 | pycorn-bin.py -p input.res 76 | 77 | Extract/plot data and adjust retention volume to injection point 1 (counting starts at 0!): 78 | pycorn-bin.py -p -e -i 1 input.res 79 | 80 | Plot every third value: 81 | pycorn-bin.py -p -r 3 input.res 82 | 83 | Plot from 100 to 200ml: 84 | pycorn-bin.py -p --xmin 100 --xmax 200 input.res -------------------------------------------------------------------------------- /pycorn/docs/USAGE_pycorn_module.txt: -------------------------------------------------------------------------------- 1 | Using the pycorn module: 2 | 3 | # Importing the module 4 | from pycorn import pc_res3 5 | 6 | # Create an instance of the pycorn object, there are a couple of options that can be specified: 7 | # file_name = file name of the res-file that you want to load 8 | # reduce = integer to only read every n sample (similar to the option found in UNICORN during export to asc) 9 | # inj_sel = which injection point to use as zero-rentention. By default the last injection point is used (same as in UNICORN) 10 | 11 | # Create the instance using default options 12 | my_res_file = pc_res3("sample1.res") 13 | 14 | # Parse the file 15 | my_res_file.load() 16 | 17 | # Show available data 18 | print(list(my_res_file.keys())) 19 | 20 | >>>[u'CreationNotes', u'Logbook', u'UV', u'Cond', u'pH', u'Pressure', u'Temp', u'Conc', u'Fractions'] 21 | 22 | # The above list is your key to access the data inside the file 23 | # my_res_file[key][value] value can be: 24 | # data: contains the actual data, either pure text or a list with x/y-pairs as tuples 25 | # unit: the unit for this data block (mAu, ms/cm etc.) 26 | # run_name: an internal name (like "Manual Run 8") 27 | 28 | # For example to read-out the the unit for the UV-block: 29 | my_res_file['UV']['unit'] 30 | 31 | # To read the actual UV-data: 32 | x = my_res_file['UV']['data'] 33 | print(x[0:3]) 34 | >>>[(0.0, -9.22), (0.06, -0.007), (0.13, -0.004)] 35 | -------------------------------------------------------------------------------- /pycorn/pycorn.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | ''' 3 | PyCORN - script to extract data from .res (results) files generated 4 | by UNICORN Chromatography software supplied with ÄKTA Systems 5 | (c)2014-2016 - Yasar L. Ahmed 6 | v0.18b 7 | ''' 8 | 9 | from __future__ import print_function 10 | from collections import OrderedDict 11 | from zipfile import ZipFile 12 | from zipfile import is_zipfile 13 | import xml.etree.ElementTree as ET 14 | import struct 15 | import codecs 16 | import os 17 | import io 18 | 19 | class pc_res3(OrderedDict): 20 | """A class for holding the PyCORN/RESv3 data. 21 | A subclass of `dict`, with the form `data_name`: `data`. 22 | """ 23 | 24 | # first, some magic numbers 25 | RES_magic_id = b'\x11\x47\x11\x47\x18\x00\x00\x00\xB0\x02\x00\x00\x20\x6C\x03\x00' 26 | CNotes_id = b'\x00\x00\x01\x00\x02\x00\x03\x22' 27 | Methods_id = b'\x00\x00\x01\x00\x02\x00\x01\x02' 28 | Logbook_id = b'\x00\x00\x01\x00\x04\x00\x48\x04' 29 | Logbook_id2 = b'\x00\x00\x01\x00\x04\x00\x49\x04' 30 | SensData_id = b'\x00\x00\x01\x00\x04\x00\x01\x14' 31 | SensData_id2 = b'\x00\x00\x01\x00\x04\x00\x02\x14' 32 | Fractions_id = b'\x00\x00\x01\x00\x04\x00\x44\x04' 33 | Fractions_id2 = b'\x00\x00\x01\x00\x04\x00\x45\x04' 34 | Inject_id = b'\x00\x00\x01\x00\x04\x00\x46\x04' 35 | Inject_id2 = b'\x00\x00\x01\x00\x04\x00\x47\x04' 36 | LogBook_id = b'\x00\x00\x01\x00\x02\x00\x01\x13' # capital B! 37 | 38 | def __init__(self, file_name, reduce=1, inj_sel=-1): 39 | OrderedDict.__init__(self) 40 | self.file_name = file_name 41 | self.reduce = reduce 42 | self.injection_points = None 43 | self.inj_sel = inj_sel 44 | self.inject_vol = None 45 | self.header_read = False 46 | self.run_name = '' 47 | 48 | with open(self.file_name, 'rb') as f: 49 | self.raw_data = f.read() 50 | 51 | def input_check(self, show=False): 52 | ''' 53 | Checks if input file is a supported res file 54 | x = magic number, y = version string, z = file size/EOF 55 | 56 | Returns True or False 57 | ''' 58 | if show: print((" ---- \n Input file: {0}").format(self.file_name)) 59 | 60 | x = self.raw_data.find(self.RES_magic_id, 0, 16) 61 | y = self.raw_data.find(b'UNICORN 3.10', 16, 36) 62 | z = struct.unpack("i", self.raw_data[16:20]) 63 | 64 | if (x, y) == (0, 24): 65 | if show: print(" Input is a UNICORN 3.10 file!") 66 | x, y = (0, 0) 67 | else: 68 | if show: print(" Input is not a UNICORN 3.10 file!") 69 | x, y = (1, 1) 70 | 71 | if z[0] == os.path.getsize(self.file_name): 72 | if show: print(" File size check - OK") 73 | z = 0 74 | else: 75 | if show: print(" File size mismatch - file corrupted?") 76 | z = 1 77 | if (x, y, z) != (0, 0, 0): 78 | if show: print("\n File not supported - stop!") 79 | return False 80 | else: 81 | if show: print("\n Alles safe! - Go go go!") 82 | return True 83 | 84 | def readheader(self): 85 | ''' 86 | Extracts all the entries/declarations in the header (starts at position 686) 87 | ''' 88 | 89 | # we only need to do this once 90 | if self.header_read: return 91 | self.header_read = True 92 | 93 | fread = self.raw_data 94 | header_end = fread.find(self.LogBook_id) + 342 95 | for i in range(686, header_end, 344): 96 | decl = struct.unpack("8s296s4i", fread[i:i + 320]) 97 | full_label = codecs.decode(decl[1], 'iso8859-1').rstrip("\x00") 98 | if full_label.find(':') == -1: 99 | r_name = '' 100 | d_name = full_label 101 | else: 102 | r_name = full_label[:full_label.find(':')] 103 | d_name = full_label[full_label.find('_') + 1:] 104 | x = dict(magic_id=decl[0], 105 | run_name=r_name, 106 | data_name=d_name, 107 | d_size=decl[2], 108 | off_next=decl[3], 109 | adresse=decl[4], 110 | off_data=decl[5], 111 | d_start=decl[4] + decl[5], 112 | d_end=decl[4] + decl[2]) 113 | name = x['data_name'] 114 | dat = self.get(name, dict()) 115 | dat.update(x) 116 | self[name] = dat 117 | 118 | def showheader(self, full=True): 119 | ''' 120 | Prints content of header 121 | ''' 122 | print((" ---- \n Header of {0}: \n").format(self.file_name)) 123 | if full: 124 | print(" MAGIC_ID, ENTRY_NAME, BLOCK_SIZE, OFFSET_TO_NEXT, ADRESSE, OFFSET_TO_DATA") 125 | else: 126 | print(" ENTRY_NAME, BLOCK_SIZE, OFFSET_TO_NEXT, ADRESSE, OFFSET_TO_DATA") 127 | num_blocks = len(self.items()) 128 | for i in range(num_blocks): 129 | dtp = (list(self.items()))[i][1] 130 | if full: 131 | print(" ", dtp['magic_id'], dtp['data_name'], dtp['d_size'], dtp['off_next'], dtp['adresse'], 132 | dtp['off_data']) 133 | else: 134 | print(" ", dtp['data_name'], dtp['d_size'], dtp['off_next'], dtp['adresse'], dtp['off_data']) 135 | 136 | def get_user(self): 137 | ''' 138 | Show stored user name 139 | ''' 140 | fread = self.raw_data[:512] 141 | u = struct.unpack("40s", fread[118:158]) 142 | dec_u = codecs.decode(u[0], 'iso8859-1').rstrip("\x00") 143 | return dec_u 144 | 145 | def dataextractor(self, dat, show=False): 146 | ''' 147 | Identify data type by comparing magic id, then run appropriate 148 | function to extract data, update orig. dict to include new data 149 | ''' 150 | meta1 = [ 151 | self.Logbook_id, self.Logbook_id2, 152 | self.Inject_id, self.Inject_id2, 153 | self.Fractions_id, self.Fractions_id2] 154 | meta2 = [self.CNotes_id, self.Methods_id] 155 | sensor = [self.SensData_id, self.SensData_id2] 156 | if dat['d_size'] == 0: 157 | pass 158 | elif dat['magic_id'] in meta1: 159 | dat.update(data=self.meta1_read(dat, show=show), data_type= 'annotation') 160 | return dat 161 | elif dat['magic_id'] in meta2: 162 | dat.update(data=self.meta2_read(dat, show=show), data_type= 'meta') 163 | return dat 164 | elif dat['magic_id'] in sensor: 165 | values, unit = self.sensor_read(dat, show=show) 166 | dat.update(data=values, unit=unit, data_type= 'curve') 167 | return dat 168 | 169 | def meta1_read(self, dat, show=False, do_it_for_inj_det=False): 170 | ''' 171 | Extracts meta-data/type1, Logbook, fractions and Inject marks 172 | for a specific datum 173 | ''' 174 | if show: 175 | print((" Reading: {0}").format(dat['data_name'])) 176 | final_data = [] 177 | inj_vol_to_subtract = self.inject_vol 178 | if do_it_for_inj_det: 179 | inj_vol_to_subtract = 0.0 180 | for i in range(dat['d_start'], dat['d_end'], 180): 181 | dp = struct.unpack("dd158s", self.raw_data[i:i + 174]) 182 | # acc_time = dp[0] # not used atm 183 | acc_volume = round(dp[1] - inj_vol_to_subtract, 4) 184 | label = (codecs.decode(dp[2], 'iso8859-1')).rstrip('\x00') 185 | merged_data = acc_volume, label 186 | final_data.append(merged_data) 187 | return (final_data) 188 | 189 | def meta2_read(self, dat, show=False): 190 | ''' 191 | Extracts meta-data/type2, Method/Program used in the run 192 | ''' 193 | if show: print((" Reading: {0}").format(dat['data_name'])) 194 | start, size = dat['d_start'], dat['d_size'] 195 | tmp_data = self.raw_data[start:start + size] 196 | size = tmp_data.rfind(b'\n') # declared block-size in header is always off 197 | # by a few bytes, hence it is redetermined here 198 | if show and size != len(tmp_data): 199 | print('meta2: reevaluated size {} -> {}'.format(size, len(tmp_data))) 200 | 201 | raw_data = codecs.decode(self.raw_data[start:start + size], 'iso8859-1') 202 | if '\r' in raw_data: 203 | data = raw_data 204 | else: 205 | data = raw_data.replace('\n', '\r\n') 206 | return data 207 | 208 | def sensor_read(self, dat, show=False): 209 | ''' 210 | extracts sensor/run-data and applies correct division 211 | ''' 212 | final_data = [] 213 | if "UV" in dat['data_name'] or "Cond" == dat['data_name'] or "Flow" == dat['data_name']: 214 | sensor_div = 1000.0 215 | elif "Pressure" in dat['data_name']: 216 | sensor_div = 100.0 217 | else: 218 | sensor_div = 10.0 219 | if show: print((" Reading: {0}").format(dat['data_name'])) 220 | 221 | fread = self.raw_data 222 | for i in range(dat['adresse'] + 207, dat['adresse'] + 222, 15): 223 | s_unit = struct.unpack("15s", fread[i:i + 15]) 224 | s_unit_dec = (codecs.decode(s_unit[0], 'iso8859-1')).rstrip('\x00') 225 | # FIX: in some files the unit for temperature reads 'C' instead of '°C' 226 | if s_unit_dec == 'C': 227 | s_unit_dec = u'°C' 228 | for i in range(dat['d_start'], dat['d_end'], 8): 229 | sread = struct.unpack("ii", fread[i:i + 8]) 230 | data = round((sread[0] / 100.0) - self.inject_vol, 4), sread[1] / sensor_div 231 | final_data.append(data) 232 | return (final_data[0::self.reduce], s_unit_dec) 233 | 234 | def inject_det(self, show=False): 235 | ''' 236 | Finds injection points - required for adjusting retention volume 237 | ''' 238 | inject_ids = [self.Inject_id, self.Inject_id2] 239 | injections = [] 240 | if self.injection_points == None: 241 | self.injection_points = [0.0] 242 | for i in self.values(): 243 | if i['magic_id'] in inject_ids: 244 | injections = self.meta1_read(i, show=show, do_it_for_inj_det=True) 245 | for i in injections: 246 | if i[0] != 0.0: 247 | self.injection_points.append(i[0]) 248 | if show: 249 | print(" ---- \n Injection points: \n # \t ml") 250 | for x, y in enumerate(self.injection_points): 251 | print((" {0} \t {1}").format(x, y)) 252 | 253 | 254 | def load(self, show=False): 255 | ''' 256 | extract all data and store in list 257 | ''' 258 | self.readheader() 259 | self.run_name = self['Logbook']['run_name'] 260 | self.inject_det() 261 | try: 262 | self.inject_vol = self.injection_points[self.inj_sel] 263 | except IndexError: 264 | print("\n WARNING - Injection point does not exist! Selected default.\n") 265 | self.inject_vol = self.injection_points[-1] 266 | for name, dat in list(self.items()): 267 | dat = self.dataextractor(dat, show=show) 268 | if dat is not None: 269 | self[name] = dat 270 | else: 271 | # TODO: Maybe we should keep this around? 272 | del self[name] 273 | 274 | class pc_uni6(OrderedDict): 275 | ''' 276 | A class for holding the pycorn/RESv6 data 277 | A subclass of `dict`, with the form `data_name`: `data`. 278 | ''' 279 | # for manual zip-detection 280 | zip_magic_start = b'\x50\x4B\x03\x04\x2D\x00\x00\x00\x08' 281 | zip_magic_end = b'\x50\x4B\x05\x06\x00\x00\x00\x00' 282 | 283 | # hack to get pycorn-bin to move on 284 | SensData_id = 0 285 | SensData_id2 = 0 286 | Fractions_id = 0 287 | Fractions_id2 = 0 288 | 289 | def __init__(self, inp_file): 290 | OrderedDict.__init__(self) 291 | self.file_name = inp_file 292 | self.inject_vol = 0.0 293 | self.run_name = 'blank' 294 | 295 | def load(self, show=False): 296 | ''' 297 | zip-files inside the zip-bundle are replaced by dicts, again with dicts with filename:content 298 | Chrom.#_#_True (=zip-files) files are unpacked from binary to floats by unpacker() 299 | To access x/y-value of Chrom.1_2: 300 | udata = pc_uni6("mybundle.zip") 301 | udata.load() 302 | x = udata['Chrom.1_2_True']['CoordinateData.Volumes'] 303 | y = udata['Chrom.1_2_True']['CoordinateData.Amplitudes'] 304 | ''' 305 | with open(self.file_name, 'rb') as f: 306 | input_zip = ZipFile(f) 307 | zip_data = self.zip2dict(input_zip) 308 | self.update(zip_data) 309 | proc_yes = [] 310 | proc_no = [] 311 | for i in self.keys(): 312 | tmp_raw = io.BytesIO(input_zip.read(i)) 313 | f_header = tmp_raw.read(9) 314 | # tmp_raw.seek(0) 315 | # the following if block is to fix the non-standard zip files 316 | # by stripping out all the null-bytes at the end 317 | # see https://bugs.python.org/issue24621 318 | if f_header == self.zip_magic_start: 319 | proper_zip = tmp_raw.getvalue() 320 | f_end = proper_zip.rindex(self.zip_magic_end) + 22 321 | tmp_raw = io.BytesIO(proper_zip[0:f_end]) 322 | if is_zipfile(tmp_raw): 323 | tmp_zip = ZipFile(tmp_raw) 324 | x = {i:self.zip2dict(tmp_zip)} 325 | self.update(x) 326 | proc_yes.append(i) 327 | else: 328 | pass 329 | proc_no.append(i) 330 | if show: 331 | print("Loaded " + self.file_name + " into memory") 332 | print("\n-Supported-") 333 | for i in proc_yes: 334 | print(" " + i) 335 | print("\n-Not supported-") 336 | for i in proc_no: 337 | print(" " + i) 338 | # filter out data we dont deal with atm 339 | to_process = [] 340 | for i in self.keys(): 341 | if "Chrom" in i and not "Xml" in i: 342 | to_process.append(i) 343 | if show: 344 | print("\nFiles to process:") 345 | for i in to_process: 346 | print(" " + i) 347 | for i in to_process: 348 | for n in self[i].keys(): 349 | if "DataType" in n: 350 | a = self[i][n] 351 | b = a.decode('utf-8') 352 | x = b.strip("\r\n") 353 | else: 354 | x = self.unpacker(self[i][n]) 355 | tmp_dict = {n:x} 356 | self[i].update(tmp_dict) 357 | if show: 358 | print("Finished decoding x/y-data!") 359 | 360 | @staticmethod 361 | def zip2dict(inp): 362 | ''' 363 | input = zip object 364 | outout = dict with filename:file-object pairs 365 | ''' 366 | mydict = {} 367 | for i in inp.NameToInfo: 368 | tmp_dict = {i:inp.read(i)} 369 | mydict.update(tmp_dict) 370 | return(mydict) 371 | 372 | @staticmethod 373 | def unpacker(inp): 374 | ''' 375 | input = data block 376 | output = list of values 377 | ''' 378 | read_size = len(inp) - 48 379 | values = [] 380 | for i in range(47, read_size, 4): 381 | x = struct.unpack("