Quick Reference
Calculations
Calculation |
Function |
Required args |
|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Tip
Single sample: v.calculate_*(...).result — append .result to get values.
Batch: myfile.calculate_*(...) — called on a BatchFile object, no .result needed.
Models
Use v.get_model_names() to print a list of all models.
Mixed |
|
H2O |
|
CO2 |
|
Arguments
Argument |
Type |
Description |
|---|---|---|
|
Sample |
A |
|
float or str |
Temperature in degrees C. Pass a column name (str) for batch calculations. |
|
float or str |
Pressure in bars. Pass a column name (str) for batch calculations. |
|
float or str |
Mole fraction of CO2 in the fluid (0 to 1). Pass a column name (str) for batch. |
|
str |
Model name. Default: |
|
bool |
Return extra values (single-sample only). Default: |
|
bool |
Print progress (batch only). Default: |
Sample
Task |
Syntax |
|---|---|
Create manually |
|
With normalization |
|
With input units |
|
With output units |
|
Extract from file |
|
Get composition |
|
Get normalized |
|
Update composition |
|
BatchFile
Task |
Syntax |
|---|---|
Import CSV or Excel file |
|
Specific sheet (name) |
|
Specific sheet (index) |
|
With normalization |
|
Specify input units (default is wt% oxides) |
|
Specify output units (default is wt% oxides) |
|
From DataFrame |
|
Get all data |
|
Get normalized data |
|
Extract one sample (defaults to return as dict, pass |
|
Normalization
Value |
Description |
|---|---|
|
No normalization is applied. |
|
Normalizes all oxides (including volatiles) to 100 wt%. |
|
Normalizes to 100 wt%, but H2O and CO2 stay fixed while other oxides are reduced proportionally. |
|
Normalizes non-volatile oxides to 100 wt%. Original H2O and CO2 are added on top, so the total may exceed 100%. |
Units
Value |
Description |
|---|---|
|
Weight percent oxides. |
|
Mol fraction oxides. |
|
Mol fraction cations. |
|
Mol fraction on a single-oxygen basis. |
units vs default_units
units tells VESIcal what your input data are in.
default_units tells VESIcal what units to return data in.
Saving
Method |
Description |
|---|---|
Save any VESIcal objects, DataFrames, dicts, or scalars to CSV or Excel with flexible output modes. |
|
Save to a |
|
Save to one CSV file per calculation. |
*these will be deprecated in the next major release.
Examples
Setup
import VESIcal as v
Create a Sample
my_sample = v.Sample({'SiO2': 77.3, 'TiO2': 0.08, ... })
- class VESIcal.sample_class.Sample(composition, units='wtpt_oxides', default_normalization='none', default_units='wtpt_oxides')[source]
The sample class stores compositional information for samples, and contains methods for normalization and other compositional calculations.
Extract a sample from an imported file:
extracted_sample = myfile.get_sample_composition('SampleOne', asSampleClass=True)
Import an Excel or CSV File
myfile = v.BatchFile('path/to/your/file.xlsx')
# specific sheet by name
myfile = v.BatchFile('path/to/your/file.xlsx', sheet_name="NameOfYourSheet")
# specific sheet by index (0-based)
myfile = v.BatchFile('path/to/your/file.xlsx', sheet_name=0)
- class VESIcal.batchfile.BatchFile(filename, sheet_name=0, file_type='excel', units='wtpt_oxides', label='Label', default_normalization='none', default_units='wtpt_oxides', dataframe=None, **kwargs)[source]
A batch file with sample names and oxide compositions
- Variables:
filename (str) – Path to the batch file, e.g., “my_file.xlsx”. This always needs to be passed, even if the user is passing a pandas DataFrame rather than an batch file. If passing a DataFrame, filename should be set to None. File can be excel file (.xlsx) or .csv.
sheet_name (str) –
OPTIONAL. For Excel files. Default value is 0 which gets the first sheet in the batch spreadsheet file. This implements the pandas. read_excel() sheet_name parameter. But functionality to read in more than one sheet at a time (e.g., pandas.read_excel(sheet_name=None)) is not yet imlpemented in VESIcal. From the pandas 1.0.4 documentation:
Available cases: - Defaults to 0: 1st sheet as a DataFrame - 1: 2nd sheet as a DataFrame - “Sheet1”: Load sheet with name “Sheet1”
file_type (str) – OPTIONAL. Default is ‘excel’, which denotes that passed file has extension .xlsx. Other option is ‘csv’, which denotes that the passed file has extension .csv.
units (str) – OPTIONAL. Default is ‘wtpt_oxides’. String defining whether the oxide composition is given in wt percent (“wtpt_oxides”, which is the default), mole oxides (mol_oxides) or mole cations (mol_cations).
default_normalization (None or str) –
The type of normalization to apply to the data by default. One of: - None (no normalization) - ‘standard’ (default): Normalizes an input composition to 100%. - ‘fixedvolatiles’: Normalizes major element oxides to 100 wt%,
including volatiles. The volatile wt% will remain fixed, whilst the other major element oxides are reduced proportionally so that the total is 100 wt%.
’additionalvolatiles’: Normalises major element oxide wt% to 100%, assuming it is volatile-free. If H2O or CO2 are passed to the function, their un-normalized values will be retained in addition to the normalized non-volatile oxides, summing to >100%.
str (default_units) – The type of composition to return by default, one of: - wtpt_oxides (default) - mol_oxides - mol_cations
label (str) – OPTIONAL. Default is ‘Label’. Name of the column within the passed file referring to sample names.
dataframe (pandas DataFrame) – OPTIONAL. Default is None in which case this argument is ignored. This argument is used when the user wishes to turn a pandas DataFrame into an BatchFile object, for example when user data is already in python rather than being imported from a file. In this case set dataframe equal to the dataframe object being passed in. If using this option, pass None to filename.
Normalization
On import:
my_sample = v.Sample({...}, default_normalization='standard')
myfile = v.BatchFile('file.xlsx', default_normalization='standard')
On existing data:
normed = mysample.get_composition(normalization="standard")
mysample.change_composition(normed)
Normalize an entire BatchFile:
my_normed_data = myfile.get_data(normalization="standard")
myNewData = v.BatchFile(filename=None, dataframe=my_normed_data)
Units
# input is mol fraction oxides, output as mol fraction oxides
my_sample = v.Sample({...}, units='mol_oxides', default_units='mol_oxides')
# input is wt% (default), convert output to mol fraction oxides
myfile = v.BatchFile('file.xlsx', default_units='mol_oxides')
Tips and Tricks
Pull arguments from a file:
myfile.calculate_dissolved_volatiles(
temperature="MyTemps", # column name in your file
pressure="SomePs", # column name in your file
X_fluid=0.35 # single value applied to all samples
).result
Choose a model:
v.get_model_names() # list all available models
v.calculate_saturation_pressure(
sample=my_sample, temperature=900,
model='ShishkinaIdealMixing'
).result
Dissolved Volatile Concentrations
v.calculate_dissolved_volatiles(sample, temperature, pressure, X_fluid)
# single sample
v.calculate_dissolved_volatiles(
sample=my_sample, temperature=1000, pressure=2000, X_fluid=0.5
).result
# batch
myfile.calculate_dissolved_volatiles(temperature=1000, pressure=2000, X_fluid=0.5)
Equilibrium Fluid Compositions
v.calculate_equilibrium_fluid_comp(sample, temperature, pressure)
# single sample
v.calculate_equilibrium_fluid_comp(
sample=my_sample, temperature=1000, pressure=2000
).result
# batch
myfile.calculate_equilibrium_fluid_comp(temperature=1000, pressure=2000)
Saturation Pressures
v.calculate_saturation_pressure(sample, temperature)
# single sample
v.calculate_saturation_pressure(sample=my_sample, temperature=1000).result
# batch
myfile.calculate_saturation_pressure(temperature=1000)
Isobars and Isopleths
v.calculate_isobars_and_isopleths(sample, temperature, pressure_list, isopleth_list)
Single-sample only.
Extra argument |
Description |
|---|---|
|
List of pressures (bars) at which to calculate isobars. |
|
List of X_fluid values at which to calculate isopleths. |
isobars, isopleths = v.calculate_isobars_and_isopleths(
sample=my_sample,
temperature=1000,
pressure_list=[500, 1000, 2000],
isopleth_list=[0.25, 0.5, 0.75]
).result
fig, ax = v.plot(isobars=isobars, isopleths=isopleths)
v.show()
For custom plotting, get smoothed data as a DataFrame:
smoothed = v.vplot.smooth_isobars_and_isopleths(isobars=isobars, isopleths=isopleths)
Degassing Paths
v.calculate_degassing_path(sample, temperature)
Single-sample only.
Extra argument |
Description |
|---|---|
|
Initial percent of exsolved fluid (e.g., |
|
Fraction of fluid removed at each step. |
# closed system (default)
closed = v.calculate_degassing_path(sample=my_sample, temperature=1000).result
# closed system with 2% initial fluid
init = v.calculate_degassing_path(sample=my_sample, temperature=1000, init_vapor=2.0).result
# fully open system
opened = v.calculate_degassing_path(sample=my_sample, temperature=1000, fractionate_vapor=1.0).result
# partially open (20% removed per step)
partial = v.calculate_degassing_path(sample=my_sample, temperature=1000, fractionate_vapor=0.2).result
fig, ax = v.plot(
degassing_paths=[closed, init, opened, partial],
degassing_path_labels=["Closed", "2% Initial Fluid", "Open", "Partly Open"]
)
v.show()
Liquid Density
v.calculate_liquid_density(sample, temperature, pressure)
# single sample
v.calculate_liquid_density(sample=my_sample, temperature=1000, pressure=2000).result
# batch
myfile.calculate_liquid_density(temperature=1000, pressure=2000)
Liquid Viscosity
v.calculate_liquid_viscosity(sample, temperature)
# single sample
v.calculate_liquid_viscosity(sample=my_sample, temperature=1000).result
# batch
myfile.calculate_liquid_viscosity(temperature=1000)
Save Results (General Purpose)
v.save_results(filename, obj, filetype="csv", mode="single_sheet", descriptions=None)
Save any combination of VESIcal objects, DataFrames, dicts, or scalars to CSV or Excel. Supports Sample, Calculate, and BatchFile objects, as well as pandas DataFrames/Series, dictionaries, lists, and scalar values.
Argument |
Description |
|---|---|
|
Base filename. Extension is added or replaced automatically. For |
|
Data to save: a single object or a list of objects. |
|
|
|
|
|
Optional list of string labels added as a |
# Save a single calculation result
v.save_results("satP.csv", satP)
# Save a list of mixed types to Excel, one sheet per item
v.save_results("results.xlsx", [mysample, satP, dissolved],
filetype="excel", mode="multi_sheet",
descriptions=["Sample", "Saturation Pressure", "Dissolved Volatiles"])
# Save each item to its own CSV file
v.save_results("output", [satP, dissolved],
filetype="csv", mode="multi_file")
Old save methods
These will be deprecated in next major release.
Save to Excel
dissolved = myfile.calculate_dissolved_volatiles(temperature=900, pressure=1000, X_fluid=0.5)
SatP = myfile.calculate_saturation_pressure(temperature=900)
myfile.save_excel("myoutput.xlsx", calculations=[dissolved, SatP])
# with custom sheet names
myfile.save_excel("myoutput.xlsx",
calculations=[dissolved, SatP],
sheet_names=["Dissolved", "Saturation Pressures"]
)
Save to CSV
myfile.save_csv(
filename=["my_dissolved_output.csv", "my_SatP_output.csv"],
calculations=[dissolved, SatP]
)