Import and export data

pytzer.io provides functions to import user data ready for use with pytzer, and export the results of your calculations.


.getmols

Imports a table of temperature and molality values, and format them ready for pz.model functions.

Syntax

mols, ions, tempK = pz.io.getmols(filename, delimiter=',', skip_top=0)

Inputs

Variable Description
filename Name of a text file containing a set of solution compositions and corresponding temperatures. See full decription below.
delimiter Optional. Specify the column delimiter used in filename. Defaults to ','.
skip_top Optional. Specify the number of rows in filename above the row containing the headers described below. Defaults to 0.

The input file filename should be formatted as follows:

  • the first row provides the header for each column;
  • each column represents the concentration of a different ion (or the temperature);
  • each row characterises a different solution composition.

The header of the column containing the temperatures (in K) must be tempK.

The other columns should be headed with the chemical symbol for the ion, excluding the charge, and without any brackets. Only internal stoichiometry should be included: SO42− becomes SO4; Na+ becomes Na, and would not be Na2 even if a solution of Na2SO4 was under investigation. For a more detailed explanation, see the section on naming conventions.

The order of the columns does not matter.

By default, it should be a comma-separated variable (CSV) file, but if another separator is used, this can be specified with the optional delimiter input.

For example, to specify these solutions:

  • NaCl at 0.10, 3.00 and 6.25 mol·kg−1,
  • KCl at 0.50 and 3.45 mol·kg−1,
  • a mixture containing 1.20 mol·kg−1 NaCl and 0.80 mol·kg−1 KCl,
  • Na2SO4 at 2.00 mol·kg−1,
  • all at 298.15 K,

we could use this CSV file:

tempK , Na  , K   , Cl  , SO4
298.15, 0.10,     , 0.10,
298.15, 3.00,     , 3.00,
298.15, 6.25,     , 6.25,
298.15,     , 0.50, 0.50,
298.15,     , 3.45, 3.45,
298.15, 1.20, 0.80, 2.00,
298.15, 4.00,     ,     , 2.00

Outputs

Variable Description Unit
mols Concentrations (molality) of ions in solution. Each row represents a different ion. Each column characterises a different solution composition. mol·kg−1
ions List of the ions, corresponding to the rows in mols. mol·kg−1
tempK Solution temperature. Each value corresponds to the matching column in mols. K

.saveall

Saves the results of all calculations to a CSV file, with a format similar to that described for the input file above.

Syntax

pz.io.saveall(filename, mols, ions, tempK, osm, aw, acfs)

Inputs

The input filename gives the name of the file to save, including the path. The file will be overwritten if it already exists, or created if not. It should end with .csv.

The other variables are the inputs mols, ions and tempK exactly as created by the io.getmols function above, while osm, aw and acfs are the results of the corresponding functions in model. For the current version, there is no flexibility in which calculation results can be provided.