Mantid
Loading...
Searching...
No Matches
LoadFITS.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2014 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9//---------------------------------------------------
10// Includes
11//---------------------------------------------------
12#include <map>
13#include <sstream>
14#include <string>
15#include <vector>
16
18#include "MantidDataHandling/DllConfig.h"
21
22namespace Mantid {
23namespace DataHandling {
24
25struct FITSInfo;
26
36class MANTID_DATAHANDLING_DLL LoadFITS : public API::IFileLoader<Kernel::FileDescriptor> {
37public:
38 LoadFITS();
39
41 const std::string name() const override { return "LoadFITS"; }
42
44 const std::string summary() const override { return "Load FITS files into workspaces of type Workspace2D."; }
45
47 int version() const override { return 1; }
48 const std::vector<std::string> seeAlso() const override { return {"Load", "SaveFITS"}; }
49
51 const std::string category() const override { return "DataHandling\\Imaging"; }
52
54 int confidence(Kernel::FileDescriptor &descriptor) const override;
55
58 bool loadMutipleAsOne() override { return true; }
59
60private:
62 void init() override;
64 void exec() override;
65
67 void loadHeader(const std::string &filePath, FITSInfo &header);
68
70 void headerSanityCheck(const FITSInfo &hdr, const FITSInfo &hdrFirst);
71
73 void doLoadFiles(const std::vector<std::string> &paths, const std::string &outWSName, bool loadAsRectImg, int binSize,
74 double noiseThresh);
75
77 void parseHeader(FITSInfo &headerInfo);
78
80 DataObjects::Workspace2D_sptr makeWorkspace(const FITSInfo &fileInfo, size_t &newFileNumber,
81 std::vector<char> &buffer, API::MantidImage &imageY,
83 bool loadAsRectImg = false, int binSize = 1, double noiseThresh = false);
84
85 void addAxesInfoAndLogs(const DataObjects::Workspace2D_sptr &ws, bool loadAsRectImg, const FITSInfo &fileInfo,
86 int binSize, double cmpp);
87
88 // Reads the data from a single FITS file into a workspace (directly, fast)
89 void readDataToWorkspace(const FITSInfo &fileInfo, double cmpp, const DataObjects::Workspace2D_sptr &ws,
90 std::vector<char> &buffer);
91
92 // Reads the data from a single FITS file into image objects (Y and E) that
93 // then can/will be copied into a workspace
94 void readDataToImgs(const FITSInfo &fileInfo, API::MantidImage &imageY, API::MantidImage &imageE,
95 std::vector<char> &buffer);
96
97 void readInBuffer(const FITSInfo &fileInfo, std::vector<char> &buffer, size_t len);
98
100 void doFilterNoise(double thresh, API::MantidImage &imageY, API::MantidImage &imageE);
101
103 void doRebin(size_t rebin, const API::MantidImage &imageY, const API::MantidImage &imageE,
104 API::MantidImage &rebinnedY, API::MantidImage &rebinnedE);
105
107 bool isInstrOtherThanIMAT(const FITSInfo &hdr);
108
109 void setupDefaultKeywordNames();
110
111 // Maps the header keys to specified values
112 void mapHeaderKeys();
113
116 size_t fetchNumber(const std::string &name);
117
118 // Adds a number of leading 0's to another number up to the totalDigitCount.
119 std::string padZeros(const size_t number, const size_t totalDigitCount);
120
121 // Strings used to map header keys
122 std::string m_headerScaleKey;
123 std::string m_headerOffsetKey;
128 std::vector<std::string> m_headerAxisNameKeys;
129 std::string m_mapFile;
130
131 static const std::string g_defaultImgType;
132
133 // names of extension headers
134 std::string m_sampleRotation;
135 std::string m_imageType;
136
138
139 // Number of digits for the fixed width appendix number added to
140 // workspace names, i.e. 3=> workspace_001; 5 => workspace_00001
141 static const size_t g_DIGIT_SIZE_APPEND = 6;
145 static const int g_BASE_HEADER_SIZE = 2880;
146
147 // TODO: in the next round of refactoring of LoadFITS, this should
148 // become common between LoadFITS and the new SaveFITS
149 // Names for several options that can be given in a "FITS" header
150 // setup file
151 static const std::string g_END_KEYNAME;
152 static const std::string g_COMMENT_KEYNAME;
153 static const std::string g_XTENSION_KEYNAME;
154 static const std::string g_BIT_DEPTH_NAME;
155 static const std::string g_AXIS_NAMES_NAME;
156 static const std::string g_ROTATION_NAME;
157 static const std::string g_IMAGE_KEY_NAME;
158 static const std::string g_HEADER_MAP_NAME;
159
160 // Bits per pixel
161 // This must be consistent with how the BITPIX header entries are processed
162 static const size_t g_maxBitDepth;
163 // max. bytes per pixel, for buffers
164 static const size_t g_maxBytesPP;
165};
166
167} // namespace DataHandling
168} // namespace Mantid
Defines an interface to an algorithm that loads a file so that it can take part in the automatic sele...
Definition: IFileLoader.h:19
LoadFITS: Load one or more of FITS files into a Workspace2D.
Definition: LoadFITS.h:36
static const size_t g_maxBitDepth
Definition: LoadFITS.h:162
static const std::string g_AXIS_NAMES_NAME
Definition: LoadFITS.h:155
std::string m_headerNAxisNameKey
Definition: LoadFITS.h:127
const std::string name() const override
Algorithm's name for identification overriding a virtual method.
Definition: LoadFITS.h:41
int version() const override
Algorithm's version for identification overriding a virtual method.
Definition: LoadFITS.h:47
static const std::string g_XTENSION_KEYNAME
Definition: LoadFITS.h:153
static const std::string g_COMMENT_KEYNAME
Definition: LoadFITS.h:152
const std::vector< std::string > seeAlso() const override
Function to return all of the seeAlso (these are not validated) algorithms related to this algorithm....
Definition: LoadFITS.h:48
static const size_t g_maxBytesPP
Definition: LoadFITS.h:164
std::vector< std::string > m_headerAxisNameKeys
Definition: LoadFITS.h:128
static const std::string g_BIT_DEPTH_NAME
Definition: LoadFITS.h:154
bool loadMutipleAsOne() override
Returns a value indicating whether or not loader wants to load multiple files into a single workspace...
Definition: LoadFITS.h:58
static const std::string g_HEADER_MAP_NAME
Definition: LoadFITS.h:158
static const std::string g_defaultImgType
Definition: LoadFITS.h:131
const std::string summary() const override
Summary of algorithms purpose.
Definition: LoadFITS.h:44
static const std::string g_END_KEYNAME
Definition: LoadFITS.h:151
static const std::string g_IMAGE_KEY_NAME
Definition: LoadFITS.h:157
static const std::string g_ROTATION_NAME
Definition: LoadFITS.h:156
const std::string category() const override
Algorithm's category for identification overriding a virtual method.
Definition: LoadFITS.h:51
Defines a wrapper around an open file.
std::vector< std::vector< double > > MantidImage
typedef for the image type
std::shared_ptr< Workspace2D > Workspace2D_sptr
shared pointer to Mantid::DataObjects::Workspace2D
Helper class which provides the Collimation Length for SANS instruments.