:: A simple Python script for automating the calculation and visualization of gas uptake from a raw data file ::
Autogasuptake is a convinient tool for automating the calculation and visualization of gas uptake from a raw csv file that contains the cylinder volume and the pressure of the gas in the experimental system.
You will need below packages to run Autogasuptake. But don't worry, you can install them all with pip
or pip3
. Personally, I'm highly recommend you to use Anaconda as your Python distribution.
pandas
matplotlib
numpy
scipy
scikit-learn
seaborn
pyfiglet
tabulate
uniplot
- Can polish the raw data file
- z value calculation based on Peng-Robinson & Redlich-Kwong EOS models
- Can calculate the gas uptake based on the z value
- Supply various user options
- Can decorate the graph with research figure style
- Can export the graph as a png, pdf, or svg file
It is easy to install Autogasuptake. Just use pip
or pip3
to install it.
$ pip install autogasuptake
or
$ pip3 install autogasuptake
After installing Autogasuptake, you can execute it right in the terminal. But before you use it, you need to prepare csv files from your experimental data (mainly came from the LabVIEW program). Note that LabVIEW program exports the data in a csv file with space as the delimiter (but it's ok if you use comma (',') as delimiter. The program automatically recognizes this and proceeds with data processing normally). It looks like this:
570.000000 406.754852
569.799988 406.006744
569.799988 404.104126
569.799988 401.781738
The first column is the pressure (psi) of your system, and the second column is the volumn (mL) of the cylinder. Make sure to remember the location where you save these raw csv files.
Then, deploy Autogasuptake in your terminal.
$ autogasuptake
The program initiates, and firstly asks you to make the settings.txt
file if you don't have one.
ERROR There is no `settings.txt` file in the current directory. I will make a new `settings.txt` file for you.
INFO The `settings.txt` file has been created. Please edit the file and run the program again.
If you have already have your own settings.txt
file, you won't see this message.
The exported settings.txt
file looks like this:
###################################
############ SETTINGS.TXT #############
###################################
# NOTE: This file should be located in the directory where you are executing the program. This can be done by typing `pwd` in the terminal. Check your current location.
# NOTE: You can mark `#` in front of the lines you don't want to use.
# NOTE: This file should be named as `settings.txt`. If isn't, the program cannot load the settings.
###########################################################
# Target directory where the raw data files are located.
directory = ./
# Data collection frequency (in ms); the value when you set in the LabVIEW program.
frequency = 300000
# Experimental temperature (in K)
temperature = 276.3
# Critical temperature of your interested gas (in K)
tc = 209.5389
# Critical pressure of your interested gas (in bar)
pc = 55.034
# Acentric factor of your interested gas
omega = 0
# Time unit (h, m, or s)
tunit = m
# Whether to decorate the graph with research figure style (options: y, n)
graph-decorate = y
# Plot type (options: line, scatter)
plot-type = scatter
# Whether to include the title in the graph (options: y, n)
include-title = n
# Output file type (options: png, pdf, svg)
output-file-type = png
# Equation of state model (options: rk, pr)
eos = pr
# Water mass you used in the experiment (in g)
water-mass = 50
# Type of the clathrate (options: sI, sII, sH, SCS-I, TS–I, HS-I, and none)
clathrate-type = sII
- Basically, you should choose your interested gas and find its critical temperture, critical pressure, and acentric factor. And carefully modify
settings.txt
file according to your found values. Note that the demosettings.txt
file is written for the calculation of gas uptake of$Kr$ molecules. - After then, you can choose whether to decorate the graph with research figure style, whether to include the title in the graph, and the output file type. Especially, if you choose
y
for the graph decoration, the program will change the font-style, font-size, and line-width of the graph. If you writen
for the graph decoration, the plot will be exported with the default style. If you want to know more about the decorated style and the default style, refer to the below comparison.(n) Default style (y) Decorated style - You can also choose the equation of state model you want to use. Currently, the program supports two EOS models: Redlich-Kwong (RK) and Peng-Robinson (PR). The detailed information about the EOS models is given in the below section.
- The plot type can be either
line
orscatter
.(line) Line plot (scatter) Scatter plot - If you choose
line
, the program will plot the gas uptake data with a line. Consecutively, the program will ask the line width that you want to use. - If you choose
scatter
, the program will plot the gas uptake data with a scatter plot. Consecutively, the program will ask the total number of points that you want to include in the plot. The program will divide the total number of points by the number of data points you have, and then plot the data points with the same interval.
- If you choose
After the program outputs the graph, it collects the processed data and creates a new CSV file to provide to the user. After the program runs, check the target directory again. The file looks like this:
Pressure (psi) | Cylinder volume (mL) | Pressure (bar) | Cylinder volume (L) | Time (min) | Delta_V (L) | Gas uptake (mol of gas) | Gas uptake (mol of gas / mol of water) |
---|---|---|---|---|---|---|---|
... | ... | ... | ... | ... | ... | ... | ... |
Autogasuptake now includes a new feature that allows users to visualize their CSV data in the terminal using the embedded uniplot
library. Users can interactively view the graph and trim the x-axis by inputting the starting and ending points. The output graph will be automatically trimmed based on the user's x value inputs. If you select your desired CSV file, the terminal shows:
INFO Xlabel: Time (min), Ylabel: Gas uptake (mol of gas / mol of water)
┌────────────────────────────────────────────────────────────┐
│ │ │
│ │ ▗▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▟▀│
│ │ ▗▄▄▄▛▀▀▀▀▀▀▀▘ │
│ │ ▗▛▀ │ 0.1
│ │ ▟▀ │
│ │ ▗▌ │
│ │ ▐ │
│ │ ▟ │
│ │ ▌ │
│ │ ▗▌ │
│ │ ▐ │
│ │ ▟ │
│ │ ▌ │
│▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▝▀▘▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔│ -0.0
│ │ │
│ │ │
│ │ │
└────────────────────────────────────────────────────────────┘
-500 0 500 1,000
Move h/j/k/l, zoom u/n, or r to reset. ESC/q to quit
You are free to navigate the graph and choose the x-region that you want to trim. Once you have finished previewing the graph, you can exit by typing ESC or q. You will then be prompted with the question:
Do you want to trim the data? (y/n):
If you select 'y', the terminal will ask for the start and end times that you want to trim. You can enter the start and end times in minutes, e.g. "30" and "300", respectively. Once you have provided these values, the graph will be trimmed based on the selected x-region. And that's it! Your graph will now be displayed with the x-region trimmed as per your input.
Redlich-Kwong EOS is one of the most popular EOSs. To calculate the compressibility factor (
Peng-Robinson EOS is more newer than Redlich-Kwong EOS and also one of the most popular EOSs. To calculate the compressibility factor (
- A huge thanks for @CorySimon making the Peng-Robinson Equation of State solver. It was helpful to make a function for Peng-Robinson EOS.
- PR Wikipedia
- RK Wikipedia
The gas uptake (mol of gas / mol of water) is simply calculated by using the following equation:
When the user select the clathrate-type
option as sI
, sII
, sH
, SCS-I
, TS-I
, and HS-I
, the program will calculate the theoretical maximum gas uptake value. The program uses the following equation to calculate the theoretical maximum gas uptake value:
Where
If you don't want to mark the theoretical maximum gas uptake value in your plot, you can simply select the clathrate-type
option as none
.
When clathrate-type is on |
When clathrate-type is none |
---|---|
By utilizing the bash script, you can automate the sequence to treat several
.csv
files in your target folder. But make sure to check if it is okay to use the samesettings.txt
to treat your raw CSV files.
Let's see the example.
. ├── Raw1.csv ├── Raw2.csv ├── Raw3.csv ├── Raw4.csv └── settings.txt
I put 4 raw csv files in the same directory with the pre-written
settings.txt
file. It looks like this:################################### ############ SETTINGS.TXT ############# ################################### # NOTE: This file should be located in the directory where you are executing the program. This can be done by typing `pwd` in the terminal. Check your current location. # NOTE: You can mark `#` in front of the lines you don't want to use. # NOTE: This file should be named as `settings.txt`. If isn't, the program cannot load the settings. ########################################################### # Target directory where the raw data files are located. directory = ./ # Data collection frequency (in ms); the value when you set in the LabVIEW program. frequency = 300000 # Experimental temperature (in K) temperature = 276.3 # Critical temperature of your interested gas (in K) tc = 209.5389 # Critical pressure of your interested gas (in bar) pc = 55.034 # Acentric factor of your interested gas omega = 0 # Time unit (h, m, or s) tunit = m # Whether to decorate the graph with research figure style (options: y, n) graph-decorate = y # Plot type (options: line, scatter) plot-type = scatter # Whether to include the title in the graph (options: y, n) include-title = n # Output file type (options: png, pdf, svg) output-file-type = png # Equation of state model (options: rk, pr) eos = pr # Water mass you used in the experiment (in g) water-mass = 50 # Type of the clathrate (options: sI, sII, sH, SCS-I, TS–I, HS-I, and none) clathrate-type = sII
Note that the gas type used in those raw files is
$Kr$ . I wrote every$T_c$ ,$P_c$ ,$\omega$ values for$Kr$ , and I chose EOS as Peng-Robinson. Kr hydrate is known as sII structure, therefore, I wroteclathrate-type
assII
. For the scatter plot, I chose to contain 50 points of data in every plot. The automation code looks like this:#!/bin/bash # advanced.sh for filenum in 0 2 4 6 do autogasuptake << EOF $filenum 50 EOF doneUnfortunately,
autogasuptake
cannot distinguish output CSV data exported from running it. Thus, we might use the even number while the sequence loops. Authorizeadvanced.sh
.$ chmod +x advanced.sh
Then, execute it!
$ ./advanced.sh
Then, the overall files inside the current directory might be like this:
. ├── Raw1.csv ├── Raw1.png ├── Raw1_OUTDATA.csv ├── Raw2.csv ├── Raw2.png ├── Raw2_OUTDATA.csv ├── Raw3.csv ├── Raw3.png ├── Raw3_OUTDATA.csv ├── Raw4.csv ├── Raw4.png ├── Raw4_OUTDATA.csv ├── advanced.sh └── settings.txt
The output looks like this:
Raw 1 Raw 2 Raw 3 Raw 4 You can also refer to the folder entitled
Advanced_Ex_Kr/
.
- MIT License