| 1 |
# -*- coding: utf-8 -*- |
| 2 |
""" |
| 3 |
.. module:: simple.py |
| 4 |
:platform: Unix |
| 5 |
:synopsis: Generate test files in data exchange. |
| 6 |
|
| 7 |
:Author: |
| 8 |
`Francesco De Carlo <mailto: [email protected]>`_ |
| 9 |
|
| 10 |
:Organization: |
| 11 |
Argonne National Laboratory, Argonne, IL 60439 USA |
| 12 |
|
| 13 |
:Version: 2014.08.15 |
| 14 |
""" |
| 15 |
|
| 16 |
import dxfile.dxtomo as dx |
| 17 |
import numpy as np |
| 18 |
import datetime |
| 19 |
import os |
| 20 |
import time |
| 21 |
|
| 22 |
def main(): |
| 23 |
|
| 24 |
fname = './demo.h5' |
| 25 |
|
| 26 |
experimenter_name="Francesco De Carlo" |
| 27 |
experimenter_affiliation="Argonne National Laboratory" |
| 28 |
experimenter_email="[email protected]" |
| 29 |
instrument_comment="32-ID TXM" |
| 30 |
sample_name = 'sample_name' |
| 31 |
|
| 32 |
size = 180 |
| 33 |
|
| 34 |
theta = range(0, 180, 180/size) |
| 35 |
|
| 36 |
|
| 37 |
if (fname != None): |
| 38 |
if os.path.isfile(fname): |
| 39 |
print "Data Exchange file already exists: ", fname |
| 40 |
else: |
| 41 |
# Create new folder. |
| 42 |
dirPath = os.path.dirname(fname) |
| 43 |
if not os.path.exists(dirPath): |
| 44 |
os.makedirs(dirPath) |
| 45 |
|
| 46 |
# Open DataExchange file |
| 47 |
f = dx.File(fname, mode='w') |
| 48 |
|
| 49 |
# Write the Data Exchange HDF5 file. |
| 50 |
f.add_entry(dx.Entry.experimenter(name={'value':experimenter_name})) |
| 51 |
f.add_entry(dx.Entry.experimenter(affiliation={'value':experimenter_affiliation})) |
| 52 |
f.add_entry(dx.Entry.experimenter(email={'value':experimenter_email})) |
| 53 |
f.add_entry(dx.Entry.instrument(comment={'value': instrument_comment})) |
| 54 |
f.add_entry(dx.Entry.sample( name={'value':sample_name})) |
| 55 |
|
| 56 |
f.add_entry(dx.Entry.data(theta={'value': theta, 'units':'degrees'})) |
| 57 |
|
| 58 |
f.close() |
| 59 |
|
| 60 |
else: |
| 61 |
print "Nothing to do ..." |
| 62 |
|
| 63 |
if __name__ == "__main__": |
| 64 |
main() |
| 65 |
|