Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config file #38

Merged
merged 13 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
build_type: [Release, Debug, DebugASAN, DebugTSAN]
build_type: [Release, Debug, DebugASAN] # DebugTSAN
cpp_compiler: [g++, clang++]
include:
- os: ubuntu-latest
Expand Down Expand Up @@ -46,7 +46,7 @@ jobs:
shell: bash
run: |
sudo apt-get install libboost-all-dev
sudo apt-get install sextractor
sudo apt-get install source-extractor
if: runner.os == 'Linux'

- name: Clang-format check
Expand All @@ -72,4 +72,4 @@ jobs:

- name: Basic test
working-directory: ${{ github.workspace }}
run: ./scripts/run_basic_test.sh
run: ./scripts/run_tests.sh
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
[submodule "deps/sep"]
path = deps/sep
url = https://github.com/SeverinDenisenko/sep.git
[submodule "deps/libconfig"]
path = deps/libconfig
url = https://github.com/hyperrealm/libconfig.git
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/deps/cfitsio)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/deps/TRIANGLE)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/deps/GSL)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/deps/sep)
find_package(Boost COMPONENTS thread REQUIRED)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/deps/wcslib)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/deps/libconfig)

if(APPLE)
find_package(Boost COMPONENTS thread program_options filesystem process REQUIRED)
else()
find_package(Boost COMPONENTS thread program_options filesystem REQUIRED)
endif()

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(COMMON_COMPILE_OPTIONS -Wall -Wextra -pedantic -O0 -g)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This tool can add images (in .fits format) with stars on them. Tool computes pro
## Usage

```bash
imsum <base-image> <images-count> <other-images>
imsum --config <config.cfg path> --images <images list>
```

This command adds other images to base image and results in out.fits.
Expand Down Expand Up @@ -48,7 +48,7 @@ base_frame_loaded.write("result.fits")

## Dependencies

- Source extractor
- Source extractor (optional)
- Boost
- C++17 or higher

Expand Down
64 changes: 49 additions & 15 deletions astroimsum/main.cpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
#include <iostream>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>

#include "config.hpp"
#include "frame.hpp"
#include "frame_io.hpp"
#include "libconfig.h++"
#include "linalg.hpp"
#include "sumation.hpp"
#include "source_extractor.hpp"
#include "summation.hpp"
#include "types.hpp"

#include <boost/program_options.hpp>

namespace astro {
static void sum_images(array_t<string_t> images)
static void sum_images(
array_t<string_t> images, uptr<source_extractor_interface> source_extractor)
{
sptr<iframeloader> frameloader = make_sptr<batch_frameloader>(images);

frame base_frame = frameloader->get_frame();

sptr<iframesaver> framesaver = make_sptr<casual_framesaver>("out.fits");
sptr<isumattor> sumattor = make_sptr<basic_star_sumattor>(base_frame);
sptr<frame_summator_interface> sumattor = make_sptr<delaney_frame_summator>(
base_frame, std::move(source_extractor));

while (frameloader->has_more()) {
sumattor->sum(frameloader->get_frame());
Expand All @@ -31,24 +39,50 @@ int main(int argc, char* argv[])
{
using namespace astro;

namespace po = boost::program_options;

try {
if (argc < 3) {
throw std::runtime_error("Wrong number of arguments");
po::options_description desc("imsum");
desc.add_options()("help", "show this message")(
"images",
po::value<array_t<string_t>>()->multitoken(),
"images to align and add, first image will be reference")(
"config", po::value<string_t>(), "specify config file");

po::variables_map vm;
po::store(po::command_line_parser(argc, argv).options(desc).run(), vm);
po::notify(vm);

if (vm.count("help")) {
std::cout << desc;
return 0;
}

string_t reference_image = argv[1];
long images_count = std::stoll(argv[2]);
array_t<string_t> images;
images.push_back(reference_image);
for (long i = 0; i < images_count; ++i) {
if (argc < i + 4) {
throw std::runtime_error("Wrong number of arguments");
}
if (!vm.count("images")) {
std::cout << desc;
return 0;
}

if (!vm.count("config")) {
std::cout << desc;
return 0;
}

string_t config_path = vm["config"].as<string_t>();
array_t<string_t> images = vm["images"].as<array_t<string_t>>();

config c = read_config(config_path);

images.push_back(argv[3 + i]);
uptr<source_extractor_interface> extractor;
if (c.source_extractor_type == "embeded") {
extractor = make_uptr<embeded_source_extractor>(
c.embeded_source_extractor);
} else {
extractor = make_uptr<external_source_extractor>(
c.external_source_extractor);
}

sum_images(images);
sum_images(images, std::move(extractor));
} catch (const std::exception& ex) {
std::cout << "Error: " << ex.what() << std::endl;
return 1;
Expand Down
8 changes: 4 additions & 4 deletions astroimsumlib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set(IMSUM_LIB_SRC
${CMAKE_CURRENT_SOURCE_DIR}/fits.cpp
${CMAKE_CURRENT_SOURCE_DIR}/frame_io.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sumation.cpp
${CMAKE_CURRENT_SOURCE_DIR}/summation.cpp
${CMAKE_CURRENT_SOURCE_DIR}/source_extractor.cpp
${CMAKE_CURRENT_SOURCE_DIR}/astrometric_reduction.cpp
${CMAKE_CURRENT_SOURCE_DIR}/delaney.cpp
Expand All @@ -11,18 +11,18 @@ set_property(TARGET imsumlib PROPERTY POSITION_INDEPENDENT_CODE 1)

target_compile_options(imsumlib PUBLIC ${COMMON_COMPILE_OPTIONS})
target_link_options(imsumlib PUBLIC ${COMMON_LINK_OPTIONS})
target_link_libraries(imsumlib PUBLIC ${Boost_LIBRARIES} cfitsio triangle GSL sep)
target_link_libraries(imsumlib PUBLIC ${Boost_LIBRARIES} cfitsio triangle GSL sep wcslib config++)
target_include_directories(imsumlib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)

add_library(imsumlib_shared SHARED $<TARGET_OBJECTS:imsumlib>)
add_library(imsumlib_static STATIC $<TARGET_OBJECTS:imsumlib>)

target_compile_options(imsumlib_shared PUBLIC ${COMMON_COMPILE_OPTIONS})
target_link_options(imsumlib_shared PUBLIC ${COMMON_LINK_OPTIONS})
target_link_libraries(imsumlib_shared PUBLIC ${Boost_LIBRARIES} cfitsio triangle GSL sep)
target_link_libraries(imsumlib_shared PUBLIC ${Boost_LIBRARIES} cfitsio triangle GSL sep wcslib config++)
target_include_directories(imsumlib_shared PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)

target_compile_options(imsumlib_static PUBLIC ${COMMON_COMPILE_OPTIONS})
target_link_options(imsumlib_static PUBLIC ${COMMON_LINK_OPTIONS})
target_link_libraries(imsumlib_static PUBLIC ${Boost_LIBRARIES} cfitsio triangle GSL sep)
target_link_libraries(imsumlib_static PUBLIC ${Boost_LIBRARIES} cfitsio triangle GSL sep wcslib config++)
target_include_directories(imsumlib_static PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
54 changes: 54 additions & 0 deletions astroimsumlib/include/config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#pragma once

#include "linalg.hpp"
#include "source_extractor.hpp"
#include "types.hpp"

#include <libconfig.hh>
#include <sstream>
#include <stdexcept>

namespace astro {
struct config {
string_t source_extractor_type { "embeded" };
embeded_source_extractor_params embeded_source_extractor {};
external_source_extractor_params external_source_extractor {};
};

inline config read_config(string_t path)
{
config c;

try {
libconfig::Config cfg;
cfg.readFile(path);

c.source_extractor_type
= static_cast<string_t>(cfg.lookup("source_extractor"));
c.embeded_source_extractor.detect_minarea = static_cast<integer_t>(
cfg.lookup("embeded_source_extractor.detect_minarea"));
c.embeded_source_extractor.detect_treshold = static_cast<real_t>(
cfg.lookup("embeded_source_extractor.detect_treshold"));
c.embeded_source_extractor.deblend_ntreshold = static_cast<integer_t>(
cfg.lookup("embeded_source_extractor.deblend_ntreshold"));
c.embeded_source_extractor.deblend_mincount = static_cast<real_t>(
cfg.lookup("embeded_source_extractor.deblend_mincount"));
c.external_source_extractor.path = static_cast<string_t>(
cfg.lookup("external_source_extractor.path"));
} catch (const libconfig::ParseException& ex) {
std::stringstream err;
err << "Cant pase config file:";
err << " file=" << ex.getFile();
err << " error = " << ex.getError();
err << " line = " << ex.getLine();
throw std::runtime_error(err.str());
} catch (const libconfig::SettingNotFoundException& ex) {
std::stringstream err;
err << "Cant pase config file:";
err << " path=" << ex.getPath();
throw std::runtime_error(err.str());
}

return c;
}
}
26 changes: 26 additions & 0 deletions astroimsumlib/include/path_find.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include "types.hpp"

namespace astro {

inline string_t path_find(array_t<string_t> variants)
{
string_t res = "";

for (string_t name : variants) {
if (!system(("which " + name + " > /dev/null 2>&1").c_str())) {
res = name;
break;
}
}

if (res == "") {
throw std::runtime_error(
"Can't find any of variants of " + variants[0]);
}

return res;
}

}
36 changes: 32 additions & 4 deletions astroimsumlib/include/source_extractor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,41 @@
#include "types.hpp"

namespace astro {
class source_extractor {

class source_extractor_interface {
public:
virtual array_t<point_t> extract(frame f) = 0;
virtual ~source_extractor_interface() = default;
};

struct external_source_extractor_params {
string_t path { "./sextractor/" };
};

class external_source_extractor : public source_extractor_interface {
public:
array_t<point_t> extract(string_t file);
external_source_extractor(external_source_extractor_params params);

array_t<point_t> extract(frame f) override;

private:
external_source_extractor_params params_;
};

struct embeded_source_extractor_params {
integer_t detect_minarea { 10 };
real_t detect_treshold { 3.0 };
integer_t deblend_ntreshold { 28 };
real_t deblend_mincount { 0.005 };
};

class embeded_source_extractor {
class embeded_source_extractor : public source_extractor_interface {
public:
array_t<point_t> extract(frame frame);
embeded_source_extractor(embeded_source_extractor_params params);

array_t<point_t> extract(frame f) override;

private:
embeded_source_extractor_params params_;
};
}
31 changes: 0 additions & 31 deletions astroimsumlib/include/sumation.hpp

This file was deleted.

42 changes: 42 additions & 0 deletions astroimsumlib/include/summation.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once

#include "frame.hpp"
#include "linalg.hpp"
#include "source_extractor.hpp"

namespace astro {
class frame_summator_interface {
public:
virtual void sum(frame) = 0;
virtual frame result() = 0;
virtual ~frame_summator_interface() = default;
};

class delaney_frame_summator : public frame_summator_interface {
public:
delaney_frame_summator(
frame base_frame, uptr<source_extractor_interface> source_extractor);

virtual void sum(frame fr) override;

virtual frame result() override;

private:
frame base_frame_;
uptr<source_extractor_interface> source_extractor_;
array_t<point_t> base_frame_points_;
};

class wcs_frame_summator : public frame_summator_interface {
public:
wcs_frame_summator(frame base_frame);

virtual void sum(frame fr) override;

virtual frame result() override;

private:
frame base_frame_;
};

}
Loading
Loading