2017年3月17日星期五

Malvern ZetaSizer Visualizer, a tool to plot the exported data from Malvern DLS

Many labs own Malvern ZetaSizer products, but the data export is always a problem. Nobody loves the low-resolution original output images and the built-in tool to automatically export the data is generates terrible results.The general method of exportation can be found in the user manual, and it is described in Chapter 11. You can follow this link to obtain a full text.

However, for size measurement, you can actually export a "size/volume/intensity distribution table" every time you conduct a measurement.  Albeit the terrible format it produces, this is the most favorable practice in the labs that I have worked in. To view it, you first need to turn on the panel/tab in Tool>>Setting>>Configure Workspace>>Size, and in the tab Report Pages, check Number Stats Table (M). Then after each measurement, just drag/copy the table to a .txt file and save it to your flash disk. Remember, one measurement in each file.

The file looks like this:
It seems to be a poorly formatted, tab separated file which is extremely unfriendly to the graph editing software.

I used to manually cut and paste and use Excel as well as some more specific data analysis software to visualize the data. Recently I am generating a large number of results, so I decided to write a script to process them.

Here is the Python-Gnuplot script. To run it on Windows, you need to first install python (for some reason, I am still using Python 2.7, but I believe it is also compatible with Python 3), Gnuplot and add their directory in %PATH%. Just check "add to %PATH%" options  when you install these softwares.

Then, put all the .txt files in the same directory, download this script file to the same directory and run it. A png figure will be generated for each .txt file in this directory, and it looks just like this one:
In the meantime, another .csv file is generated. You can import this file into other software for a further analysis.

Here is the code of the script:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import subprocess

def transcribe(fname):
 cumul = 0.0
 with open(fname,'r') as source,\
   open(fname[:-4]+'_trans.csv','w') as result:
  content = source.readlines()
  del content[0:2]
  for i in range(0,3):
   for j in content:
    if len(j.split('\t')[4*i])>0:
     x = j.split('\t')[4*i]
     y = j.split('\t')[4*i+1]
     cumul += float(y)
     result.write(x+','+y+','+str(cumul)+'\n')

def plot(fname):
 figtitle = fname[:-10]
 with open(fname,'r') as source:
  dataraw = source.readlines()
 for i in range(0, len(dataraw)-1):
  x = float(dataraw[i].strip().split(',')[0])
  y = float(dataraw[i].strip().split(',')[1])
 with open('gpl_temp.plt','w') as gTemp:
  gTemp.write("set term png\n")
  gTemp.write("set output \"%s.png\"\n" %fname[:-10])
  gTemp.write("set datafile separator \",\"\n")
  gTemp.write("set title \"%s\"\n"%figtitle)
  gTemp.write("set xlabel \"D (nm)\"\n")
  gTemp.write("set ylabel \"N%\"\n")
  gTemp.write("set yrange [0:110]\n")
  gTemp.write("set grid\n")
  gTemp.write("set logscale x\n")
  gTemp.write("set style fill solid 0.4 border\n")
  gTemp.write("plot \"%s\" using 1:2 \"%%lf,%%lf\" title \"\" with boxes,"%(fname)+\
              "\"\" using 1:3  title \"\" with line\n")
  gTemp.write("set output\n")
 p=subprocess.call("gnuplot gpl_temp.plt")


txtdir = os.listdir(os.getcwd())
for i in txtdir:
 if i[-4:] == '.txt':
  transcribe(i)
  plot(i[:-4]+'_trans.csv')

1 条评论 :

  1. I have to admit the indentation of the syntax highlighter is horrible...

    回复删除