source: sasview/src/sas/sascalc/dataloader/readers/nexus_reader.py @ 945f45d

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalcmagnetic_scattrelease-4.1.2release-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 945f45d was b699768, checked in by Piotr Rozyczko <piotr.rozyczko@…>, 9 years ago

Initial commit of the refactored SasCalc? module.

  • Property mode set to 100644
File size: 2.8 KB
RevLine 
[dd87647]1#####################################################################
2#This software was developed by the University of Tennessee as part of the
3#Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
4#project funded by the US National Science Foundation.
5#See the license text in license.txt
6#copyright 2012, University of Tennessee
7######################################################################
8"""
9    Nexus reader for 2D data reduced by Mantid
10"""
11import os
[b699768]12from sas.sascalc.dataloader.data_info import Data2D
[dd87647]13
14
15class Reader:
16    """
17        Nexus reader for 2D data reduced by Mantid
18    """
19    ## File type
20    type_name = "NXS"
21    ## Wildcards
22    type = ["Nexus files (*.nxs)|*.nxs"]
23    ## Extension
24    ext = ['.nxs']
25       
26    def read(self, filename=None):
27        """
28            Open and read the data in a file
29       
30            :param filename: path of the file
31        """
32        try:
33            import nxs
34        except:
35            msg = "Error reading Nexus file: Nexus package is missing.\n"
36            msg += "  Get it from http://http://www.nexusformat.org/"
37            raise RuntimeError, msg
38       
39        # Instantiate data object
40        output = Data2D()
41        output.filename = os.path.basename(filename)
42
43        fd = nxs.open(filename, 'rw')
44       
45        # Read in the 2D data
46        fd.opengroup('mantid_workspace_1')
47        fd.opengroup('workspace')
48        fd.opendata('values')
49        output.data = fd.getdata().copy()
50        fd.closedata()
51       
52        # Read in the errors
53        fd.opendata('errors')
54        output.err_data = fd.getdata().copy()
55        fd.closedata()
56       
57        # Read in the values on each axis
58        fd.opendata('axis1')
59        output.x_bins = fd.getdata().copy()
60        fd.closedata()
61       
62        fd.opendata('axis2')
63        output.y_bins = fd.getdata().copy()
64        fd.closedata()
65        fd.closegroup()
66               
67        output.xmin = min(output.x_bins)
68        output.xmax = max(output.x_bins)
69        output.ymin = min(output.y_bins)
70        output.ymax = max(output.y_bins)
71       
72        output.xaxis("\\rm{Q_{x}}", 'A^{-1}')
73        output.yaxis("\\rm{Q_{y}}", 'A^{-1}')
74        output.zaxis("\\rm{Intensity}", "cm^{-1}")
75
76        # Meta data
77        fd.opendata('title')
78        output.title = fd.getdata()
79        fd.closedata()
80       
81        fd.opengroup('instrument')
82        fd.opendata('name')
83        output.instrument = fd.getdata()
84        fd.closedata()
85        fd.closegroup()
86
87        fd.opengroup('logs')
88        fd.opengroup('run_number')
89        fd.opendata('value')
90        output.run = fd.getdata()
91
92        fd.close()
93
94        # Store loading process information
95        output.meta_data['loader'] = self.type_name
96        return output
Note: See TracBrowser for help on using the repository browser.