Skip to content

Commit b95a31e

Browse files
authored
POL5809 (jettison global state, part1) and POL5842 (extracting features from 4D datasets) (#304)
1 parent 6d25491 commit b95a31e

File tree

223 files changed

+10373
-6852
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

223 files changed

+10373
-6852
lines changed

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ option(RUN_GTEST "Downloads google unit test API and runs google test scripts to
133133
#==== Source files
134134
set(SOURCE
135135
src/nyx/3rdparty/dsyevj3.cpp
136-
src/nyx/arrow_output_stream.cpp
137136
src/nyx/features/basic_morphology.cpp
138137
src/nyx/features/caliper_feret.cpp
139138
src/nyx/features/caliper_martin.cpp
@@ -197,13 +196,16 @@ set(SOURCE
197196
src/nyx/io/nifti/nifti2_io.cpp
198197
src/nyx/io/nifti/znzlib.cpp
199198
src/nyx/arrow_helpers.cpp
199+
src/nyx/arrow_output_stream.cpp
200+
src/nyx/cache.cpp
200201
src/nyx/cli_anisotropy_options.cpp
201202
src/nyx/cli_fpimage_options.cpp
202203
src/nyx/cli_gabor_options.cpp
203204
src/nyx/cli_glcm_options.cpp
204205
src/nyx/cli_gpu_options.cpp
205206
src/nyx/cli_nested_roi_options.cpp
206207
src/nyx/common_stats.cpp
208+
src/nyx/dataset.cpp
207209
src/nyx/dirs_and_files.cpp
208210
src/nyx/environment.cpp
209211
src/nyx/environment_basic.cpp
@@ -227,7 +229,6 @@ set(SOURCE
227229
src/nyx/phase3.cpp
228230
src/nyx/pixel_feed.cpp
229231
src/nyx/raw_image_loader.cpp
230-
src/nyx/reduce_by_feature.cpp
231232
src/nyx/reduce_trivial_rois.cpp
232233
src/nyx/roi_blacklist.cpp
233234
src/nyx/roi_cache.cpp
@@ -347,6 +348,7 @@ if(USEGPU)
347348

348349
include_directories("${CUDAToolkit_INCLUDE_DIRS}")
349350
set(GPU_SOURCE_FILES
351+
src/nyx/gpu/cache.cu
350352
src/nyx/gpu/erosion.cu
351353
src/nyx/gpu/gabor.cu
352354
src/nyx/gpu/gpu_helpers.cu

src/nyx/abs_tile_loader.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ class AbstractTileLoader
5757
return 1;
5858
}
5959

60+
/// \brief Getter to the length of full time series (default 1) usually used in NIFTI
61+
/// @param level file's level considered
62+
/// \return Number of timestamps in file's time series
63+
[[nodiscard]] virtual size_t fullTimestamps ([[maybe_unused]] size_t level) const {
64+
return 1;
65+
}
66+
6067
/// \brief Getter to the number of channels (default 1)
6168
/// \return Number of pixel's channels
6269
[[nodiscard]] virtual size_t numberChannels() const {
@@ -80,6 +87,13 @@ class AbstractTileLoader
8087
return 1;
8188
}
8289

90+
/// \brief Getter to the length of tile's time series (default 1) usually used in NIFTI
91+
/// @param level tile's level considered
92+
/// \return Number of timestamps in tile's time series
93+
[[nodiscard]] virtual size_t tileTimestamps ([[maybe_unused]] size_t level) const {
94+
return 1;
95+
}
96+
8397
/// \brief Get file bits per samples
8498
/// \return File bits per sample
8599
[[nodiscard]] virtual short bitsPerSample() const = 0;

src/nyx/arrow_output_stream.cpp

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,82 +5,92 @@
55
namespace Nyxus {
66

77
#ifdef USE_ARROW
8-
std::tuple<bool, std::optional<std::string>> ArrowOutputStream::create_arrow_file(const Nyxus::SaveOption& arrow_file_type,
9-
const std::string& output_path,
10-
const std::vector<std::string>& header) {
118

12-
if (output_path == ""){
13-
return {false, "No path provided for Arrow file."};
9+
std::tuple<bool, std::optional<std::string>> ArrowOutputStream::create_arrow_file(
10+
const Nyxus::SaveOption& arrow_file_type,
11+
const std::string& output_path,
12+
const std::vector<std::string>& header) {
13+
14+
if (output_path == "") {
15+
return { false, "No path provided for Arrow file." };
1416
}
1517

1618
this->arrow_file_path_ = output_path;
17-
if (auto parent_path = fs::path(output_path).parent_path();
18-
!parent_path.empty() && !fs::is_directory(parent_path)){
19+
if (auto parent_path = fs::path(output_path).parent_path();
20+
!parent_path.empty() && !fs::is_directory(parent_path)) {
1921
try {
2022
fs::create_directory(parent_path);
21-
} catch (std::exception& e) {
22-
return {false, e.what()};
2323
}
24-
}
24+
catch (std::exception& e) {
25+
return { false, e.what() };
26+
}
27+
}
2528

2629
std::optional<std::string> error_msg;
2730
std::tie(writer_, error_msg) = WriterFactory::create_writer(arrow_file_path_, header);
2831
if (writer_) {
29-
return {true, std::nullopt};
30-
} else {
31-
return {false, error_msg};
32+
return { true, std::nullopt };
33+
}
34+
else {
35+
return { false, error_msg };
3236
}
3337
}
3438

35-
36-
std::string ArrowOutputStream::get_arrow_path() {
39+
std::string ArrowOutputStream::get_arrow_path()
40+
{
3741
return arrow_file_path_;
3842
}
3943

40-
std::tuple<bool, std::optional<std::string>> ArrowOutputStream::write_arrow_file (const std::vector<std::tuple<std::vector<std::string>, int, std::vector<double>>>& features){
41-
if (writer_){
44+
std::tuple<bool, std::optional<std::string>> ArrowOutputStream::write_arrow_file(
45+
const std::vector<FTABLE_RECORD>& features) {
46+
if (writer_) {
4247
auto status = writer_->write(features);
4348
if (status.ok()) {
44-
return {true, std::nullopt};
49+
return { true, std::nullopt };
4550
}
4651
else {
47-
return {false, status.ToString()};
52+
return { false, status.ToString() };
4853
}
4954
}
50-
return {false, "Arrow Writer is not initialized."};
55+
return { false, "Arrow Writer is not initialized." };
5156
}
52-
std::tuple<bool, std::optional<std::string>> ArrowOutputStream::close_arrow_file (){
53-
if (writer_){
57+
std::tuple<bool, std::optional<std::string>> ArrowOutputStream::close_arrow_file() {
58+
if (writer_) {
5459
auto status = writer_->close();
5560
if (status.ok()) {
56-
return {true, std::nullopt};
61+
return { true, std::nullopt };
5762
}
5863
else {
59-
return {false, status.ToString()};
64+
return { false, status.ToString() };
6065
}
6166
}
62-
return {false, "Arrow Writer is not initialized."};
67+
return { false, "Arrow Writer is not initialized." };
6368
}
6469

65-
#else
66-
std::tuple<bool, std::optional<std::string>> ArrowOutputStream::create_arrow_file(const Nyxus::SaveOption& arrow_file_type,
67-
const std::string& arrow_file_path,
68-
const std::vector<std::string>& header) {
69-
70-
std::cerr << "Apache Arrow functionality is not available. Please install Nyxus with Arrow enabled to use this functionality." << std::endl;
70+
#else
7171

72-
return {false, "Apache Arrow functionality is not available."};
72+
// stubs
73+
74+
std::tuple<bool, std::optional<std::string>> ArrowOutputStream::create_arrow_file(
75+
const Nyxus::SaveOption& arrow_file_type,
76+
const std::string& arrow_file_path,
77+
const std::vector<std::string>& header)
78+
{
79+
std::cerr << "Apache Arrow functionality is not available. Please install Nyxus with Arrow enabled to use this functionality." << std::endl;
80+
return { false, "Apache Arrow functionality is not available." };
7381
}
7482

75-
std::tuple<bool, std::optional<std::string>> ArrowOutputStream::write_arrow_file (const std::vector<std::tuple<std::vector<std::string>, int, std::vector<double>>>& features){
83+
std::tuple<bool, std::optional<std::string>> ArrowOutputStream::write_arrow_file (const std::vector<FTABLE_RECORD>& features)
84+
{
7685
std::cerr << "Apache Arrow functionality is not available. Please install Nyxus with Arrow enabled to use this functionality." << std::endl;
77-
return {false, "Apache Arrow functionality is not available."};
86+
return { false, "Apache Arrow functionality is not available." };
7887
}
79-
std::tuple<bool, std::optional<std::string>> ArrowOutputStream::close_arrow_file (){
88+
std::tuple<bool, std::optional<std::string>> ArrowOutputStream::close_arrow_file()
89+
{
8090
std::cerr << "Apache Arrow functionality is not available. Please install Nyxus with Arrow enabled to use this functionality." << std::endl;
81-
return {false, "Apache Arrow functionality is not available."};
91+
return { false, "Apache Arrow functionality is not available." };
8292
}
8393

94+
#endif
95+
};
8496

85-
#endif
86-
};

src/nyx/arrow_output_stream.h

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,56 +5,57 @@
55
#include <memory>
66
#include <tuple>
77
#include <vector>
8-
98
#include "output_writers.h"
109
#include "save_option.h"
1110

1211
namespace Nyxus
1312
{
1413

15-
#ifdef USE_ARROW
16-
17-
/**
18-
* @brief Class to write to Apache Arrow formats
19-
*
20-
* This class provides methods for writing to the Arrow IPC and Parquet formats.
21-
*
22-
*/
23-
class ArrowOutputStream {
24-
25-
private:
26-
27-
std::string arrow_file_path_ = "";
28-
std::unique_ptr<ApacheArrowWriter> writer_ = nullptr;
29-
std::string arrow_output_type_ = "";
30-
31-
public:
32-
std::tuple<bool, std::optional<std::string>> create_arrow_file(const Nyxus::SaveOption& arrow_file_type,
33-
const std::string& output_path,
34-
const std::vector<std::string>& header);
35-
std::string get_arrow_path();
36-
std::tuple<bool, std::optional<std::string>> write_arrow_file (const std::vector<std::tuple<std::vector<std::string>, int, std::vector<double>>>& features);
37-
std::tuple<bool, std::optional<std::string>> close_arrow_file ();
38-
};
39-
40-
#else
41-
42-
/**
43-
* @brief Class to write to Apache Arrow formats
44-
*
45-
* This class provides a place holder for the Arrow writer class when Nyxus is built without arrow.
46-
*
47-
*/
48-
class ArrowOutputStream {
49-
50-
public:
51-
std::tuple<bool, std::optional<std::string>> create_arrow_file(const Nyxus::SaveOption& arrow_file_type,
52-
const std::string& arrow_file_path,
53-
const std::vector<std::string>& header);
54-
std::tuple<bool, std::optional<std::string>> write_arrow_file (const std::vector<std::tuple<std::vector<std::string>, int, std::vector<double>>>& features);
55-
std::tuple<bool, std::optional<std::string>> close_arrow_file ();
56-
};
57-
58-
59-
#endif
60-
};
14+
#ifdef USE_ARROW
15+
16+
/**
17+
* @brief Class to write to Apache Arrow formats
18+
*
19+
* This class provides methods for writing to the Arrow IPC and Parquet formats.
20+
*
21+
*/
22+
class ArrowOutputStream
23+
{
24+
private:
25+
26+
std::string arrow_file_path_ = "";
27+
std::unique_ptr<ApacheArrowWriter> writer_ = nullptr;
28+
std::string arrow_output_type_ = "";
29+
30+
public:
31+
std::tuple<bool, std::optional<std::string>> create_arrow_file(const Nyxus::SaveOption& arrow_file_type,
32+
const std::string& output_path,
33+
const std::vector<std::string>& header);
34+
std::string get_arrow_path();
35+
std::tuple<bool, std::optional<std::string>> write_arrow_file(const std::vector<FTABLE_RECORD>& features);
36+
std::tuple<bool, std::optional<std::string>> close_arrow_file();
37+
};
38+
39+
#else
40+
41+
/**
42+
* @brief Class to write to Apache Arrow formats
43+
*
44+
* This class provides a place holder for the Arrow writer class when Nyxus is built without arrow.
45+
*
46+
*/
47+
48+
class ArrowOutputStream
49+
{
50+
public:
51+
std::tuple<bool, std::optional<std::string>> create_arrow_file(const Nyxus::SaveOption& arrow_file_type,
52+
const std::string& output_path,
53+
const std::vector<std::string>& header);
54+
std::string get_arrow_path();
55+
std::tuple<bool, std::optional<std::string>> write_arrow_file(const std::vector<FTABLE_RECORD>& features);
56+
std::tuple<bool, std::optional<std::string>> close_arrow_file();
57+
};
58+
59+
#endif
60+
};
61+

0 commit comments

Comments
 (0)