IO write module¶
The io_write
submodule offers the following functions to write files:
Function |
Description |
---|---|
Writes a XAFS group in xmu format. |
|
Writes LCF data to a file. |
|
Writes a LCF report to a file. |
|
Utility function to write an array to a file. |
|
Utility function to write a file header. |
- araucaria.io.io_write.write_xmu(fpath, group, fmt='%12.8g', replace=False)[source]¶
Writes a file in xmu format.
- Parameters
- Return type
- Returns
Confirmation message.
- Raises
TypeError – If
group
is not a valid Group instance.
Notes
By default the operation will be cancelled if the file already exists. The previous file can be overwritten with the option
replace=True
.See also
write_file
Writes an array to a file.
Example
>>> from araucaria.testdata import get_testpath >>> from araucaria.io import read_xmu, write_xmu >>> fpath = get_testpath('xmu_testfile.xmu') >>> # extracting mu and mu_ref scans >>> group_mu = read_xmu(fpath, scan='mu') >>> # saving a new xmu file >>> write_xmu('new_file.xmu', group_mu) 'xmu_testfile.xmu written to new_file.xmu.'
- araucaria.io.io_write.write_lcf(fpath, out, fmt='%12.8g', replace=False)[source]¶
Writes LCF data to a file.
- Parameters
- Return type
- Returns
Confirmation message.
- Raises
TypeError – If
out
is not a valid Dataset instance.AttributeError – If attribute
min_pars
,scangroup
, orrefgroups
does not exist inout
.
Notes
The returned file will contain in the header the output from
lcf_report()
, in addition to the following columns:energy
: array with energy values. Returned only iffit_region='xanes'
orfit_region='dxanes'
.k
: array with wavenumber values. Returned only iffit_region='exafs'
.scan
: array with values of the fitted spectrum.ref
: array with interpolated values for each reference spectrum.fit
: array with fit result.residual
: fit residuals.
See also
write_file()
Writes an array to a file.
Example
>>> from numpy.random import seed, normal >>> from numpy import arange, sin, pi >>> from araucaria import Group, Collection >>> from araucaria.fit import lcf >>> from araucaria.io import write_lcf >>> seed(1234) # seed of random values >>> k = arange(0, 12, 0.05) >>> eps = normal(0, 0.1, len(k)) >>> f1 = 1.2 # freq 1 >>> f2 = 2.6 # freq 2 >>> amp1 = 0.4 # amp 1 >>> amp2 = 0.6 # amp 2 >>> group1 = Group(**{'name': 'group1', 'k': k, 'chi': sin(2*pi*f1*k)}) >>> group2 = Group(**{'name': 'group2', 'k': k, 'chi': sin(2*pi*f2*k)}) >>> group3 = Group(**{'name': 'group3', 'k': k, ... 'chi' : amp1 * group1.chi + amp2 * group2.chi + eps}) >>> collection = Collection() >>> tags = ['ref', 'ref', 'scan'] >>> for i,group in enumerate((group1,group2, group3)): ... collection.add_group(group, tag=tags[i]) >>> # performing lcf >>> out = lcf(collection, fit_region='exafs', fit_range=[3,10], ... kweight=0, sum_one=False) >>> # saving lcf to a file >>> write_lcf('new_fit.lcf', out) 'lcf data written to new_fit.lcf.'
- araucaria.io.io_write.write_lcf_report(fpath, out, replace=False)[source]¶
Writes a LCF report to a file.
- Parameters
- Return type
- Returns
Confirmation message.
- Raises
TypeError – If
out
is not a valid Dataset instance.AttributeError – If attribute
min_pars
,lcf_pars
,scangroup
, orrefgroups
does not exist inout
.
Example
>>> from numpy.random import seed, normal >>> from numpy import arange, sin, pi >>> from araucaria import Group, Collection >>> from araucaria.fit import lcf >>> from araucaria.io import write_lcf_report >>> seed(1234) # seed of random values >>> k = arange(0, 12, 0.05) >>> eps = normal(0, 0.1, len(k)) >>> f1 = 1.2 # freq 1 >>> f2 = 2.6 # freq 2 >>> amp1 = 0.4 # amp 1 >>> amp2 = 0.6 # amp 2 >>> group1 = Group(**{'name': 'group1', 'k': k, 'chi': sin(2*pi*f1*k)}) >>> group2 = Group(**{'name': 'group2', 'k': k, 'chi': sin(2*pi*f2*k)}) >>> group3 = Group(**{'name': 'group3', 'k': k, ... 'chi' : amp1 * group1.chi + amp2 * group2.chi + eps}) >>> collection = Collection() >>> tags = ['ref', 'ref', 'scan'] >>> for i,group in enumerate((group1,group2, group3)): ... collection.add_group(group, tag=tags[i]) >>> # performing lcf >>> out = lcf(collection, fit_region='exafs', fit_range=[3,10], ... kweight=0, sum_one=False) >>> # saving lcf report to a file >>> write_lcf_report('lcf_report.log', out) 'lcf report written to lcf_report.log.'
- araucaria.io.io_write.write_file(fpath, data, name, fmt='%12.8g', header='', replace=False)[source]¶
Utility function to write a data array to a file.
- Parameters
- Return type
- Returns
Confirmation message.
- Raises
IOError – If the file already exists and
replace=False
.
- araucaria.io.io_write.set_header(fpath, file_type)[source]¶
Utility function for write a file header.
- Parameters
fpath – Path to file.
file_type (
str
) – Short descriptor for type of file.
- Return type
- Returns
Header for file.
Example
>>> from araucaria.io import set_header >>> from araucaria import Group >>> header = set_header('testdata.xmu', 'xmu') >>> header.splitlines()[0] 'xmu file created by araucaria' >>> header.splitlines()[2] 'name: testdata.xmu'