Some examples on parsing to and from supported formats. More info about all parsing methods can be found in the manual section.
First, let's do all the necessary imports and generate the paths that we'll use for file import and export.
We'll then use the util_get_file_paths
function to get the file paths in those directories.
In [1]:
import os
import pygaps
# Get directory paths
xl_path = os.path.join(os.getcwd(), 'data', 'parsing', 'excel')
json_path = os.path.join(os.getcwd(), 'data', 'parsing', 'json')
csv_path = os.path.join(os.getcwd(), 'data', 'parsing', 'csv')
# Find files
json_file_paths = pygaps.util_get_file_paths(json_path, '.json')
xl_file_paths = pygaps.util_get_file_paths(xl_path, '.xls')
csv_file_paths = pygaps.util_get_file_paths(csv_path, '.csv')
In [2]:
# Import them
isotherms = []
for filepath in json_file_paths:
with open(filepath, 'r') as text_file:
isotherms.append(pygaps.isotherm_from_json(text_file.read()))
# See the files
for isotherm in isotherms:
print(isotherm)
In [3]:
for isotherm in isotherms:
filename = os.path.join(json_path,
' '.join([isotherm.material,
str(isotherm.adsorbate),
str(isotherm.temperature)]) + '.json')
with open(filename, mode='w') as f:
f.write(pygaps.isotherm_to_json(isotherm))
In [4]:
# Import them
[print(path) for path in xl_file_paths]
isotherms = [pygaps.isotherm_from_xl(path) for path in xl_file_paths]
# See the files
for isotherm in isotherms:
print(isotherm)
In [5]:
# Export each isotherm in turn
for isotherm in isotherms:
filename = ' '.join([isotherm.material, str(isotherm.adsorbate), str(isotherm.temperature)]) + '.xls'
pygaps.isotherm_to_xl(isotherm, os.path.join(xl_path, filename))
In [6]:
# Import them
isotherms = [pygaps.isotherm_from_csv(path) for path in csv_file_paths]
# See the files
for isotherm in isotherms:
print(isotherm)
In [7]:
# Export each isotherm in turn
for isotherm in isotherms:
filename = ' '.join([isotherm.material, str(isotherm.adsorbate), str(isotherm.temperature)]) + '.csv'
pygaps.isotherm_to_csv(isotherm, os.path.join(csv_path, filename))