add relaxis file to pass fail dataset converter
This commit is contained in:
parent
eb39967226
commit
a84154d92f
@ -5,12 +5,13 @@ project(dataformaters)
|
||||
set(COMMON_SRC_FILES
|
||||
src/tokenize.cpp
|
||||
src/common.cpp
|
||||
src/hash.cpp
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
set(COMMON_LINK_LIBRARIES -leisgenerator_static -static-libgcc -static-libstdc++ -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive -Bdynamic)
|
||||
set(COMMON_LINK_LIBRARIES -lkisstype_static -leisgenerator_static -static-libgcc -static-libstdc++ -Wl,-Bstatic,--whole-archive -lwinpthread -Wl,--no-whole-archive -Bdynamic)
|
||||
else()
|
||||
set(COMMON_LINK_LIBRARIES -leisgenerator)
|
||||
set(COMMON_LINK_LIBRARIES -leisgenerator -lkisstype)
|
||||
endif()
|
||||
|
||||
add_compile_options(
|
||||
@ -37,6 +38,11 @@ target_link_libraries(maryamtoeis ${COMMON_LINK_LIBRARIES})
|
||||
set_property(TARGET maryamtoeis PROPERTY CXX_STANDARD 17)
|
||||
install(TARGETS maryamtoeis RUNTIME DESTINATION bin)
|
||||
|
||||
add_executable(rlxpassfail ${COMMON_SRC_FILES} src/rlxpassfail.cpp)
|
||||
target_link_libraries(rlxpassfail ${COMMON_LINK_LIBRARIES} -lrelaxisloader)
|
||||
set_property(TARGET rlxpassfail PROPERTY CXX_STANDARD 17)
|
||||
install(TARGETS rlxpassfail RUNTIME DESTINATION bin)
|
||||
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s")
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "common.h"
|
||||
|
||||
#include <eisgenerator/eistype.h>
|
||||
#include <kisstype/spectra.h>
|
||||
#include <eisgenerator/translators.h>
|
||||
#include <iostream>
|
||||
|
||||
@ -22,12 +22,15 @@ bool saveData(const std::string& exportName, const ModelData& data, const std::f
|
||||
++classIndex;
|
||||
} while(std::filesystem::exists(outDir/filename));
|
||||
|
||||
if(!saveToDisk(eis::EisSpectra(data.data, data.modelStr, data.id + ", \"" + originFile.filename().string() + "\""), outDir/filename))
|
||||
try
|
||||
{
|
||||
eis::Spectra(data.data, data.modelStr, data.id + ", \"" + originFile.filename().string() + "\"").saveToDisk(outDir/filename);
|
||||
return true;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
std::cerr<<"Unable to save to "<<outDir/filename;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool checkDir(const std::filesystem::path& outDir)
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <filesystem>
|
||||
#include <vector>
|
||||
#include <eisgenerator/eistype.h>
|
||||
#include <kisstype/type.h>
|
||||
|
||||
struct ModelData
|
||||
{
|
||||
|
49
src/hash.cpp
Normal file
49
src/hash.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
#include "hash.h"
|
||||
|
||||
uint64_t murmurHash64(const void* key, int len, uint64_t seed)
|
||||
{
|
||||
const uint64_t m = 0xc6a4a7935bd1e995;
|
||||
const int r = 47;
|
||||
|
||||
uint64_t h = seed ^ (len * m);
|
||||
|
||||
const uint64_t * data = (const uint64_t *)key;
|
||||
const uint64_t * end = data + (len/8);
|
||||
|
||||
while(data != end)
|
||||
{
|
||||
uint64_t k = *data++;
|
||||
k *= m;
|
||||
k ^= k >> r;
|
||||
k *= m;
|
||||
h ^= k;
|
||||
h *= m;
|
||||
}
|
||||
|
||||
const unsigned char * data2 = (const unsigned char*)data;
|
||||
|
||||
switch(len & 7)
|
||||
{
|
||||
case 7:
|
||||
h ^= ((uint64_t) data2[6]) << 48;
|
||||
case 6:
|
||||
h ^= ((uint64_t) data2[5]) << 40;
|
||||
case 5:
|
||||
h ^= ((uint64_t) data2[4]) << 32;
|
||||
case 4:
|
||||
h ^= ((uint64_t) data2[3]) << 24;
|
||||
case 3:
|
||||
h ^= ((uint64_t) data2[2]) << 16;
|
||||
case 2:
|
||||
h ^= ((uint64_t) data2[1]) << 8;
|
||||
case 1:
|
||||
h ^= ((uint64_t) data2[0]);
|
||||
h *= m;
|
||||
};
|
||||
|
||||
h ^= h >> r;
|
||||
h *= m;
|
||||
h ^= h >> r;
|
||||
|
||||
return h;
|
||||
}
|
4
src/hash.h
Normal file
4
src/hash.h
Normal file
@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
uint64_t murmurHash64(const void* key,int len, uint64_t seed);
|
@ -1,5 +1,5 @@
|
||||
#include <eisgenerator/translators.h>
|
||||
#include <eisgenerator/eistype.h>
|
||||
#include <kisstype/type.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include <eisgenerator/translators.h>
|
||||
#include <eisgenerator/eistype.h>
|
||||
#include <kisstype/type.h>
|
||||
|
||||
#include "csvBackend.h"
|
||||
#include "common.h"
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <cmath>
|
||||
#include <eisgenerator/translators.h>
|
||||
#include <eisgenerator/eistype.h>
|
||||
#include <kisstype/type.h>
|
||||
#include <kisstype/spectra.h>
|
||||
#include <eisgenerator/model.h>
|
||||
#include <eisgenerator/basicmath.h>
|
||||
#include <relaxisloaderpp/relaxisloaderpp.h>
|
||||
@ -10,6 +11,7 @@
|
||||
#include <filesystem>
|
||||
#include <set>
|
||||
|
||||
#include "hash.h"
|
||||
#include "common.h"
|
||||
|
||||
static bool saveDataRlx(const rlx::Spectra& data, const std::filesystem::path& outDir, const std::filesystem::path& originFile)
|
||||
@ -25,6 +27,8 @@ static bool saveDataRlx(const rlx::Spectra& data, const std::filesystem::path& o
|
||||
filename.assign("relaxisExport_");
|
||||
filename.concat(modelStrWithoutParams);
|
||||
filename.concat("_");
|
||||
filename.concat(std::to_string(murmurHash64(originFile.string().c_str(), originFile.string().length(), 24)));
|
||||
filename.concat("_");
|
||||
filename.concat(std::to_string(classIndex));
|
||||
filename.concat(".csv");
|
||||
++classIndex;
|
||||
@ -38,14 +42,17 @@ static bool saveDataRlx(const rlx::Spectra& data, const std::filesystem::path& o
|
||||
labels.push_back(meta.second);
|
||||
}
|
||||
|
||||
eis::EisSpectra eisSpectra(data.data, data.model, originFile, labels, labelNames);
|
||||
eis::Spectra eisSpectra(data.data, data.model, originFile, labels, labelNames);
|
||||
|
||||
if(!eisSpectra.saveToDisk(outDir/filename))
|
||||
try
|
||||
{
|
||||
eisSpectra.saveToDisk(outDir/filename);
|
||||
return true;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
std::cerr<<"Unable to save to "<<outDir/filename;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
|
86
src/rlxpassfail.cpp
Normal file
86
src/rlxpassfail.cpp
Normal file
@ -0,0 +1,86 @@
|
||||
#include <iostream>
|
||||
#include <kisstype/spectra.h>
|
||||
#include <relaxisloader/relaxisloader.h>
|
||||
#include <eisgenerator/basicmath.h>
|
||||
#include <kisstype/type.h>
|
||||
#include <filesystem>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if(argc < 2)
|
||||
{
|
||||
std::cout<<"Usage: "<<argv[0]<<" RELAXIS_FILES...\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::filesystem::path outdir("./out");
|
||||
std::filesystem::create_directory(outdir);
|
||||
|
||||
for(int i = 1; i < argc; ++i)
|
||||
{
|
||||
const char* err;
|
||||
struct rlxfile* file = rlx_open_file(argv[i], &err);
|
||||
if(!file)
|
||||
{
|
||||
std::cerr<<"Could not load "<<argv[i]<<'\n';
|
||||
return 2;
|
||||
}
|
||||
|
||||
struct rlx_project **projects = rlx_get_projects(file, NULL);
|
||||
if(!projects)
|
||||
{
|
||||
std::cerr<<"Could not load projects\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
for(struct rlx_project **piter = projects; *piter; ++piter)
|
||||
{
|
||||
struct rlx_project *project = *piter;
|
||||
struct rlx_spectra **spectras = rlx_get_all_spectra(file, project);
|
||||
if(!spectras)
|
||||
{
|
||||
std::cerr<<"Could not load spectras in "<<argv[i]<<'\n';
|
||||
continue;
|
||||
}
|
||||
|
||||
for(struct rlx_spectra **siter = spectras; *siter; ++siter)
|
||||
{
|
||||
struct rlx_spectra *spectra = *siter;
|
||||
struct rlx_metadata *meta = rlx_metadata_get(spectra, rlx_metadata_get_key(RLX_FIELD_FREE_VARIABLE_ONE));
|
||||
|
||||
float* real;
|
||||
float* imag;
|
||||
float* omega;
|
||||
rlx_get_float_arrays(spectra, &real, &imag, &omega);
|
||||
std::vector<eis::DataPoint> data(spectra->length);
|
||||
for(size_t i = 0; i < spectra->length; ++i)
|
||||
{
|
||||
data[i].im = {real[i], imag[i]};
|
||||
data[i].omega = omega[i];
|
||||
}
|
||||
|
||||
data = eis::rescale(data, 50);
|
||||
|
||||
eis::Spectra eisSpectra(data, !meta || meta->value == 0 ? "Pass" : "Fail", argv[i]);
|
||||
size_t index = 0;
|
||||
std::filesystem::path filename;
|
||||
do
|
||||
{
|
||||
filename.assign("relaxisPassFail_");
|
||||
filename.concat(!meta || meta->value == 0 ? "Pass" : "Fail");
|
||||
filename.concat("_");
|
||||
filename.concat(std::to_string(index));
|
||||
filename.concat(".csv");
|
||||
++index;
|
||||
} while(std::filesystem::exists(outdir/filename));
|
||||
eisSpectra.saveToDisk(outdir/filename);
|
||||
++spectra;
|
||||
}
|
||||
rlx_spectra_free_array(spectras);
|
||||
}
|
||||
rlx_project_free_array(projects);
|
||||
rlx_close_file(file);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user