File: export.md

package info (click to toggle)
bornagain 23.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 103,948 kB
  • sloc: cpp: 423,131; python: 40,997; javascript: 11,167; awk: 630; sh: 318; ruby: 173; xml: 130; makefile: 51; ansic: 24
file content (39 lines) | stat: -rw-r--r-- 970 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
+++
title = "Export"
weight = 20
+++

## Export a Datafield

#### Save in various formats

A `Datafield` can be saved in various data formats
through the BornAgain Python method
```python
import bornagain as ba
simulation = ...
result = simulation.simulate()
ba.IOFactory.writeDatafield(result, file_name)
```
where `file_name` must have one of the extensions
- `.txt` --- ASCII file with 2D array [nrow][ncol], layout as in NumPy,
- `.int` --- BornAgain internal ASCII format,
- `.tif` --- 32-bits TIFF file,

to which one may append a second extension that specifies compression:
- `.gz`,
- `.bz2`.

#### Export to NumPy

To extract data from `Datafield` in form of NumPy arrays, use
```python
result = simulation.simulate()
arr_x  = result.xCenters()  # centers of x bins
arr_i  = result.dataArray() # intensities
arr_di = result.errors()    # error estimates thereof
```
To save any such array, use the NumPy method
```python
numpy.savetxt("intensity.txt", arr)
```