Skip to content

Commit e3aabc7

Browse files
committed
modify functoins to read filters from MTH5 files
1 parent eb3554c commit e3aabc7

11 files changed

Lines changed: 152 additions & 168 deletions

docs/Manual_Of_TRACMT.pdf

5.23 KB
Binary file not shown.

src/Analysis.cpp

Lines changed: 24 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ void Analysis::run( std::vector<CommonParameters::DataFileSet>& dataFileSets ){
111111
// Apply decimation
112112
decimation(dataFileSets);
113113

114+
#ifdef _MTH5
115+
if (ptrControl->doesReadMTH5() && ptrControl->doesReadMTH5Filters()) {
116+
(MTH5::getInstance())->readFiltersAll(ptrControl->getNumberOfChannels(), dataFileSets);
117+
}
118+
#endif
119+
114120
// Read calibration files for main analysis
115121
readCalibrationFiles(freqAll);
116122

@@ -923,22 +929,6 @@ void Analysis::readCalibrationFiles( const std::vector<double>& freq ){
923929
}
924930
}
925931
}
926-
#ifdef _MTH5
927-
else if (ptrControl->doesReadMTH5()) {
928-
const int numFilterInfo = ptrControl->getNumFilterInfoMTH5();
929-
if (numFilterInfo > 0) {
930-
if (numFilterInfo != ptrControl->getNumberOfChannels()) {
931-
(OutputFiles::getInstance())->writeErrorMessage("Number of the filter info should be equal to channel number");
932-
}
933-
const MTH5* ptrMTH5 = MTH5::getInstance();
934-
for (int iChan = 0; iChan < numFilterInfo; ++iChan) {
935-
const std::string fileName = ptrControl->getFileNameForFilterInMTH5(iChan);
936-
const std::string path = ptrControl->getPathFilterInMTH5(iChan);
937-
ptrMTH5->makeCalibrationFile(iChan, freq);
938-
}
939-
}
940-
}
941-
#endif
942932

943933
if (m_calibrationFunctions != NULL) {
944934
delete[] m_calibrationFunctions;
@@ -1178,19 +1168,9 @@ void Analysis::convertToFrequencyData( const int segmentLength, const std::vecto
11781168
}else{
11791169
memcpy(dataSegments[iChan][counterSegment], &(itr->dataFile[iChan].data[index]), sizeof(double)*segmentLength);
11801170
}
1181-
//#ifdef _DEBUG_WRITE
1182-
// std::ostringstream oss;
1183-
// oss << "sect_" << section << "_seg_" << counterSegment << "_chan_" << iChan << ".csv";
1184-
// std::ofstream ofs;
1185-
// ofs.open( oss.str().c_str(), std::ios::out );
1186-
// if( ofs.fail() ){
1187-
// ptrOutputFiles->writeLogMessage("File open error !! : " + oss.str());
1188-
// }
1189-
// for( int i = 0; i < segmentLength; ++i ){
1190-
// ofs << std::setprecision(12) << std::scientific << dataSegments[iChan][counterSegment][i] << std::endl;
1191-
// }
1192-
// ofs.close();
1193-
//#endif
1171+
#ifdef _MTH5
1172+
m_segmentIndexToSectionIndex.insert(std::make_pair(counterSegment, section));
1173+
#endif
11941174
}
11951175
// Start time
11961176
const int index1 = iSeg * shiftLength;
@@ -1219,19 +1199,6 @@ void Analysis::convertToFrequencyData( const int segmentLength, const std::vecto
12191199
for( int iChan = 0; iChan < numChannels; ++iChan ){
12201200
for( int iSeg = 0; iSeg < numSegmentsTotal; ++iSeg ){
12211201
Util::hanningWindow(segmentLength, dataSegments[iChan][iSeg]);
1222-
//#ifdef _DEBUG_WRITE
1223-
// std::ostringstream oss;
1224-
// oss << "seg_" << iSeg << "_chan_" << iChan << "_hanning.csv";
1225-
// std::ofstream ofs;
1226-
// ofs.open( oss.str().c_str(), std::ios::out );
1227-
// if( ofs.fail() ){
1228-
// ptrOutputFiles->writeLogMessage("File open error !! : " + oss.str());
1229-
// }
1230-
// for( int i = 0; i < segmentLength; ++i ){
1231-
// ofs << std::setprecision(12) << std::scientific << dataSegments[iChan][iSeg][i] << std::endl;
1232-
// }
1233-
// ofs.close();
1234-
//#endif
12351202
}
12361203
}
12371204

@@ -1364,6 +1331,21 @@ void Analysis::calibrationCorrection(const int iChan, const int numSegmentsTotal
13641331
ftval[iSeg] *= calCorrFunc;
13651332
}
13661333

1334+
#ifdef _MTH5
1335+
if (ptrControl->doesReadMTH5() && ptrControl->doesReadMTH5Filters()) {
1336+
OutputFiles* ptrOutputFiles = OutputFiles::getInstance();
1337+
const MTH5* ptrMTH5 = MTH5::getInstance();
1338+
for(int iSeg = 0; iSeg < numSegmentsTotal; ++iSeg) {
1339+
std::map<int, int>::const_iterator itrFind = m_segmentIndexToSectionIndex.find(iSeg);
1340+
if (itrFind == m_segmentIndexToSectionIndex.end()) {
1341+
ptrOutputFiles->writeErrorMessage("Segment " + Util::toString(iSeg) + " is not stored in the map");
1342+
}
1343+
const int iSection = itrFind->second;
1344+
ftval[iSeg] /= ptrMTH5->calcResponse(iSection, iChan, freq);
1345+
}
1346+
}
1347+
#endif
1348+
13671349
}
13681350

13691351
// Calculate apparent resistivity

src/Analysis.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "RobustWeightThomson.h"
3636
#include "RobustWeightTukeysBiweights.h"
3737
#include <vector>
38+
#include <map>
3839

3940
// Class of analysis
4041
class Analysis{
@@ -272,6 +273,11 @@ class Analysis{
272273
// M-estimators
273274
RobustWeight* m_robustWeight[2];
274275

276+
#ifdef _MTH5
277+
// Map segment index to sectionindex
278+
std::map<int, int> m_segmentIndexToSectionIndex;
279+
#endif
280+
275281
};
276282

277283
#endif

src/Control.cpp

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ Control::Control() :
9595
m_procedureType(Control::ORDINARY_REMOTE_REFERENCE),
9696
m_readAtsBinary(false),
9797
m_readMTH5(false),
98+
m_readMTH5Filters(false),
9899
m_readElogDualBinary(false),
99100
m_readElogMTBinary(false),
100101
m_timingEOFBasedDenoising(Control::BEFORE_DECIMATION),
@@ -210,16 +211,12 @@ Control::~Control(){
210211
}
211212

212213
// Run analysis
213-
void Control::run(const bool outputToConsole){
214+
void Control::run(const bool outputToConsole) {
214215

215216
OutputFiles* ptrOutputFiles = OutputFiles::getInstance();
216217
ptrOutputFiles->setOutputToConsole(outputToConsole);
217218
readParameterFile();
218219

219-
#ifdef _MTH5
220-
(MTH5::getInstance())->createChannelResponses(m_filterInfoForMTH5);
221-
#endif
222-
223220
m_analysis->run(m_dataFileSets);
224221

225222
ptrOutputFiles->writeLogMessage("End " + Util::toString(CommonParameters::programName) );
@@ -281,6 +278,11 @@ bool Control::doesReadMTH5() const {
281278
return m_readMTH5;
282279
}
283280

281+
// Get flag specifing whether MTH5 filters are read or not
282+
bool Control::doesReadMTH5Filters() const {
283+
return m_readMTH5Filters;
284+
}
285+
284286
// Get flag specifing whether input file is ELOG-Dual binary file
285287
bool Control::doesReadElogDualBinary() const {
286288
return m_readElogDualBinary;
@@ -427,26 +429,11 @@ int Control::getNumCalibrationFilesForMFS() const {
427429
return static_cast<int>(m_calibrationFilesForMFS.size());
428430
}
429431

430-
// Get number of filter info (pair of file name and path) for MTH5
431-
int Control::getNumFilterInfoMTH5() const {
432-
return static_cast<int>(m_filterInfoForMTH5.size());
433-
}
434-
435432
// Get name of calibration file for MFS
436433
std::string Control::getCalibrationFileNameForMFS(const int iFile) const {
437434
return m_calibrationFilesForMFS[iFile];
438435
}
439436

440-
// Get name of MTH5 file storing filter
441-
std::string Control::getFileNameForFilterInMTH5(const int i) const {
442-
return m_filterInfoForMTH5[i].first;
443-
}
444-
445-
// Get path of the filter in MTH5 file
446-
std::string Control::getPathFilterInMTH5(const int i) const {
447-
return m_filterInfoForMTH5[i].second;
448-
}
449-
450437
// Get numebur of calibration files
451438
int Control::getNumCalibrationFiles() const{
452439
return static_cast<int>( m_calibrationFiles.size() );
@@ -863,18 +850,7 @@ void Control::readParameterFile(){
863850
}
864851
#ifdef _MTH5
865852
else if (line.find("MTH5_FILTERS") != std::string::npos) {
866-
const int numChannels = getNumberOfChannels();
867-
m_filterInfoForMTH5.clear();
868-
m_filterInfoForMTH5.reserve(numChannels);
869-
m_calibrationFiles.clear();
870-
m_calibrationFiles.reserve(numChannels);
871-
for (int iChan = 0; iChan < numChannels; ++iChan) {
872-
std::string fileName;
873-
std::string channelPath;
874-
ifs >> fileName >> channelPath;
875-
m_filterInfoForMTH5.push_back(std::make_pair(fileName, channelPath));
876-
m_calibrationFiles.push_back(MTH5::getCalibrationFileName(iChan));
877-
}
853+
m_readMTH5Filters = true;
878854
}
879855
else if (line.find("MTH5") != std::string::npos) {
880856
m_readMTH5 = true;
@@ -1748,15 +1724,8 @@ void Control::readParameterFile(){
17481724
}
17491725
if( doesReadMTH5() ) {
17501726
ptrOutputFiles->writeLogMessage("Read MTH5 files", false);
1751-
ptrOutputFiles->writeLogMessage("Filters stored in MTH5 files are used for the calibration", false);
1752-
ptrOutputFiles->writeLogMessage(" File Path", false);
1753-
for (std::vector< std::pair< std::string, std::string> >::const_iterator itr = m_filterInfoForMTH5.begin(); itr != m_filterInfoForMTH5.end(); ++itr) {
1754-
std::ostringstream oss;
1755-
oss << std::setw(5) << "";
1756-
oss << itr->first;
1757-
oss << std::setw(5) << " ";
1758-
oss << itr->second;
1759-
ptrOutputFiles->writeLogMessage(oss.str(), false);
1727+
if (doesReadMTH5Filters()) {
1728+
ptrOutputFiles->writeLogMessage("Read MTH5 filters", false);
17601729
}
17611730
}
17621731
if (doesMakeCalibrationFileForMFS()) {

src/Control.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ class Control{
295295
// Get flag specifing whether input file is MTH5 file
296296
bool doesReadMTH5() const;
297297

298+
// Get flag specifing whether MTH5 filters are read or not
299+
bool doesReadMTH5Filters() const;
300+
298301
// Get flag specifing whether input file is ELOG-Dual binary file
299302
bool doesReadElogDualBinary() const;
300303

@@ -373,12 +376,6 @@ class Control{
373376
// Get name of calibration file for MFS
374377
std::string getCalibrationFileNameForMFS(const int iFile) const;
375378

376-
// Get name of MTH5 file storing filter
377-
std::string getFileNameForFilterInMTH5(const int i) const;
378-
379-
// Get path of the filter in MTH5 file
380-
std::string getPathFilterInMTH5(const int i) const;
381-
382379
// Get numebur of calibration files
383380
int getNumCalibrationFiles() const;
384381

@@ -603,9 +600,6 @@ class Control{
603600
// Calibration file for MFS
604601
std::vector<std::string> m_calibrationFilesForMFS;
605602

606-
// Filter information in MTH5 files
607-
std::vector< std::pair< std::string, std::string> > m_filterInfoForMTH5;
608-
609603
// Percentage of ommited data in subset deletion jackknife
610604
double m_percentageOfOmmitedDataSubsetDeletionJackknife;
611605

@@ -696,6 +690,9 @@ class Control{
696690
// Flag specifing whether input file is MTH5 file
697691
bool m_readMTH5;
698692

693+
// Flag specifing whether input file is MTH5 filters
694+
bool m_readMTH5Filters;
695+
699696
// Flag specifing whether ELOG-Dual binary is read
700697
bool m_readElogDualBinary;
701698

src/MTH5.cpp

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,23 @@
3434
#include <algorithm>
3535
#include <sstream>
3636
#include <iomanip>
37+
#include <assert.h>
3738

3839
// Default constructer
3940
MTH5::MTH5():
40-
m_numOfChannelRespones(0),
41-
m_channelResponses(NULL)
41+
m_numOfChannelRespones(0)
4242
{
4343
}
4444

4545
// Destructer
4646
MTH5::~MTH5(){
47-
if (m_channelResponses != NULL) {
48-
delete[] m_channelResponses;
47+
48+
for (std::vector<MTH5ChannelResponse*>::iterator itr = m_channelResponses.begin(); itr != m_channelResponses.end(); ++itr) {
49+
if ( *itr != NULL) {
50+
delete[] * itr;
51+
}
4952
}
53+
5054
}
5155

5256
// Return the instance of the class
@@ -99,32 +103,30 @@ std::string MTH5::getCalibrationFileName(const int channelIndex){
99103

100104
}
101105

102-
// Get all filters and combine filters into a complete channel response for each channel
103-
void MTH5::createChannelResponses(const std::vector< std::pair< std::string, std::string> >& fileNameAndPath) {
106+
// Calculate frequency response functions using the frequency response functions of all filter
107+
std::complex<double> MTH5::calcResponse(const int sectionIndex, const int channelIndex, const double freq) const {
104108

105-
if (fileNameAndPath.empty()) {
106-
return;
107-
}
108-
m_numOfChannelRespones = static_cast<int>(fileNameAndPath.size());
109-
m_channelResponses = new MTH5ChannelResponse[m_numOfChannelRespones];
110-
int iChan(0);
111-
for (std::vector< std::pair< std::string, std::string> >::const_iterator itr = fileNameAndPath.begin(); itr != fileNameAndPath.end(); ++itr, ++iChan) {
112-
m_channelResponses[iChan].createChannelResponse(itr->first, itr->second);
113-
}
109+
assert(sectionIndex >= 0 && sectionIndex < m_channelResponses.size());
110+
assert(channelIndex >= 0);
111+
112+
return m_channelResponses[sectionIndex][channelIndex].calcResponse(freq);
114113

115114
}
116115

117-
// Make calibration files using the requency response functions of all filter
118-
void MTH5::makeCalibrationFile(const int channelIndex, const std::vector<double>& freqs) const {
116+
// Read filters for indivial sections and channels
117+
void MTH5::readFiltersAll(const int numChannels, const std::vector<CommonParameters::DataFileSet>& dataFileSets) {
119118

120-
if (m_channelResponses[channelIndex].isAppliedForwardly()) {
121-
return;
122-
}
123-
124-
if (channelIndex < 0 && channelIndex >= m_numOfChannelRespones) {
125-
OutputFiles::getInstance()->writeErrorMessage("Channel index is out of range: " + Util::toString(channelIndex));
119+
m_numOfChannelRespones = numChannels;
120+
121+
for(std::vector<CommonParameters::DataFileSet>::const_iterator itr = dataFileSets.begin(); itr != dataFileSets.end(); ++itr){
122+
const std::vector<CommonParameters::DataFile>& dataFileList = itr->dataFile;
123+
MTH5ChannelResponse* channelResponses = new MTH5ChannelResponse[numChannels];
124+
for (int iChan = 0; iChan < numChannels; ++iChan) {
125+
const std::string fileName = dataFileList[iChan].fileName;
126+
const std::string channelPath = dataFileList[iChan].mth5GroupName;
127+
channelResponses[iChan].createChannelResponse(fileName, channelPath);
128+
}
129+
m_channelResponses.push_back(channelResponses);
126130
}
127-
128-
m_channelResponses[channelIndex].makeCalibrationFile(getCalibrationFileName(channelIndex), channelIndex, freqs);
129131

130132
}

src/MTH5.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <H5Cpp.h>
3535

3636
#include "MTH5ChannelResponse.h"
37+
#include "CommonParameters.h"
3738

3839
// Class of MTH5 file
3940
class MTH5{
@@ -49,22 +50,19 @@ class MTH5{
4950
// Get name of the calibration file name made from the channel responses
5051
static std::string getCalibrationFileName(const int channelIndex);
5152

52-
// Get all filters and combine filters into a complete channel response for each channel
53-
void createChannelResponses(const std::vector< std::pair< std::string, std::string> >& fileNameAndPath);
53+
// Read filters for indivial sections and channels
54+
void readFiltersAll(const int numChannels, const std::vector<CommonParameters::DataFileSet>& dataFileSets);
5455

55-
//// Correct frequency response functions using the requency response functions of all filter
56-
//void correctResponse(const int channelIndex, const double freq, const double samplingFreq, std::complex<double>& response) const;
57-
58-
// Make calibration files using the requency response functions of all filter
59-
void makeCalibrationFile(const int channelIndex, const std::vector<double>& freqs) const;
56+
// Calculate frequency response functions using the frequency response functions of all filter
57+
std::complex<double> calcResponse(const int sectionIndex, const int channelIndex, const double freq) const;
6058

6159
private:
6260

6361
// Number of channel responses
6462
int m_numOfChannelRespones;
6563

6664
// List of channel response (combination of all filters)
67-
MTH5ChannelResponse* m_channelResponses;
65+
std::vector<MTH5ChannelResponse*> m_channelResponses;
6866

6967
// Constructer
7068
MTH5();

0 commit comments

Comments
 (0)