Last active
August 29, 2015 14:03
-
-
Save danielballan/b1ede9b5eb7b33cbf594 to your computer and use it in GitHub Desktop.
Parse Zetasizer data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Copyright 2014 Dan Allan | |
Read the data from a Zetasizer output file and return the intensity as | |
as a function of frequency in a spreadsheet-like object (pandas DataFrame) | |
that can exported to any convenient format. | |
This is only lightly tested. | |
""" | |
import pandas as pd | |
def _columns_subset(df, pattern): | |
return df[df.columns[df.columns.to_series().str.contains(pattern)]] | |
def parse_freq(filename): | |
"""Parse frequency data file from Zetasizer. | |
Parameters | |
---------- | |
filename : string | |
Returns | |
------- | |
intensities : DataFrame indexed by size in nm, with a column for each | |
measurement in the file | |
""" | |
df = pd.read_table(filename) | |
sizes = _columns_subset(df, 'Sizes') | |
intensities = _columns_subset(df, 'Intensities') | |
sizes.columns = sizes.columns.to_series().str.\ | |
extract(r'Sizes\[(\d+)\].*').astype('int') | |
intensities.columns = intensities.columns.to_series().str.\ | |
extract(r'Intensities\[(\d+)\].*').astype('int') | |
intensities = intensities.T | |
sizes = sizes.T[0] # Columns are redundant; just take the first one. | |
intensities.set_index(sizes, inplace=True) | |
return intensities |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment