Skip to content

Commit b4e1e14

Browse files
authored
Merge pull request #143 from astrorama/develop
Develop
2 parents d7f3f7b + 0d909a3 commit b4e1e14

File tree

15 files changed

+2181
-147
lines changed

15 files changed

+2181
-147
lines changed

.travis.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
language: minimal
2+
os: linux
3+
4+
branches:
5+
only:
6+
- develop
7+
- /^\d+.\d+(.\d+)?(-\S*)?$/
8+
9+
env:
10+
global:
11+
- OS_ARCH=x86_64
12+
13+
services:
14+
- docker
15+
16+
stages:
17+
- build
18+
- buildapp
19+
20+
jobs:
21+
include:
22+
- &build
23+
stage: build
24+
env: OS_TYPE=fedora OS_VERSION=29
25+
script:
26+
- docker run --name builder --volume "$(pwd):/src" "${OS_TYPE}:${OS_VERSION}" bash "/src/.travis/build-rpm.sh"
27+
- docker cp "builder:/build/Packages/RPM/RPMS/x86_64" "./packages"
28+
after_success: |
29+
if [ ! -z "${BINTRAY_REPO}" ] && [ -z "${TRAVIS_PULL_REQUEST_BRANCH}" ]; then
30+
package=$(grep elements_project CMakeLists.txt | sed 's/.*(//'| cut -d' ' -f1)
31+
32+
if [ ! -z "${TRAVIS_TAG}" ]; then
33+
target_repo="master"
34+
version="${TRAVIS_TAG}"
35+
else
36+
target_repo="${TRAVIS_BRANCH}"
37+
version=$(grep elements_project CMakeLists.txt | sed 's/.*(//' | sed 's/[^ ]* //' | sed 's/ .*//')
38+
fi
39+
40+
cd packages
41+
for p in *.rpm; do
42+
curl -T "${p}" "-u${BINTRAY_USER}:${BINTRAY_TOKEN}" "${BINTRAY_REPO}/${target_repo}/${OS_TYPE}/${OS_VERSION}/${OS_ARCH}/rpms/${p};bt_package=${package};bt_version=${version}?override=1&publish=1"
43+
done;
44+
fi
45+
- <<: *build
46+
env: OS_TYPE=fedora OS_VERSION=30
47+
- <<: *build
48+
env: OS_TYPE=fedora OS_VERSION=31
49+
- <<: *build
50+
env: OS_TYPE=fedora OS_VERSION=32
51+
- <<: *build
52+
env: OS_TYPE=centos OS_VERSION=7
53+
- stage: buildapp
54+
if: tag IS present
55+
env: OS_TYPE=fedora OS_VERSION=29
56+
script:
57+
- docker run --name appbuilder --device /dev/fuse --privileged --volume "$(pwd):/src" "${OS_TYPE}:${OS_VERSION}" bash "/src/.travis/build-appimage.sh"
58+
- docker cp "appbuilder:/sextractor++-x86_64.AppImage" "."
59+
deploy:
60+
provider: releases
61+
on:
62+
tags: true
63+
api_key: $GITHUB_OAUTH_TOKEN
64+
file: sextractor++-x86_64.AppImage
65+
skip_cleanup: true
66+

.travis/build-appimage.sh

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/bash
2+
set -ex
3+
4+
# Platform-specific configuration
5+
source /etc/os-release
6+
7+
CMAKEFLAGS="-DINSTALL_DOC=ON -DRPM_NO_CHECK=OFF"
8+
9+
if [ $NAME == 'Fedora' ] && [ $VERSION_ID -ge 30 ]; then
10+
PYTHON="python3"
11+
PIP="pip3"
12+
else
13+
PYTHON="python2"
14+
PIP="pip2"
15+
fi
16+
17+
18+
# Astrorama repository
19+
cat > /etc/yum.repos.d/astrorama.repo << EOF
20+
[bintray--astrorama-fedora]
21+
name=bintray--astrorama-fedora
22+
baseurl=https://dl.bintray.com/astrorama/travis/master/fedora/\$releasever/\$basearch
23+
gpgcheck=0
24+
repo_gpgcheck=0
25+
enabled=1
26+
EOF
27+
28+
# Install pip, virtualenv, fuse and which
29+
yum install -y ${PYTHON}-pip python3-virtualenv fuse-libs which
30+
31+
# Install sextractor from rpms
32+
yum install -y SExtractorxx
33+
34+
# Download linuxdeploy
35+
curl -OL 'https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage'
36+
chmod a+x 'linuxdeploy-x86_64.AppImage'
37+
38+
# Create a virtualenv with the dependencies
39+
# are self-contained
40+
APPDIR=`mktemp -d`
41+
virtualenv --clear --no-pip --no-wheel --no-setuptools --python="${PYTHON}" "${APPDIR}"
42+
source "${APPDIR}/bin/activate"
43+
44+
"${PIP}" --isolated install --ignore-installed --prefix "/usr" --root "${APPDIR}" astropy
45+
46+
deactivate
47+
48+
virtualenv --relocatable "${APPDIR}"
49+
50+
sed -i 's/VIRTUAL_ENV=.*/VIRTUAL_ENV="${APPIMAGE_MOUNT}"/g' "${APPDIR}/bin/activate"
51+
52+
# virtualenv create symlinks to the system Python installation
53+
# Replace them with the actual content
54+
# virtualenv has --always-copy, but it is quite buggy and the result ends being unusable
55+
PYTHONDIRNAME="$(ls -1 ${APPDIR}/usr/lib64/ | grep '^python')"
56+
for symlink in $(find "${APPDIR}/lib/${PYTHONDIRNAME}" -type l); do
57+
original="$(readlink "${symlink}")"
58+
echo "Replacing symlink with copy ${symlink} => ${original}"
59+
rm -f "${symlink}"
60+
cp -rfv "${original}" "${symlink}"
61+
done
62+
63+
# These files are missing for some reason ¯\_(ツ)_/¯
64+
DISTUTILSDIR="$(dirname "$(${PYTHON} -c 'import distutils; print(distutils.__file__)')")"
65+
cp -vf ${DISTUTILSDIR}/*.py "${APPDIR}/lib/${PYTHONDIRNAME}/distutils"
66+
67+
# Bundle
68+
SRCDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/../"
69+
RSCDIR="${SRCDIR}/SEMain/auxdir/SEMain"
70+
SCRIPTDIR="${SRCDIR}/SEMain/scripts/"
71+
72+
./linuxdeploy-x86_64.AppImage \
73+
--appdir "${APPDIR}" \
74+
-d "${RSCDIR}/sextractor++.desktop" -i "${RSCDIR}/sextractor++.png" \
75+
--custom-apprun="${SCRIPTDIR}/AppRun" \
76+
-e $(which sextractor++) \
77+
-o appimage
78+
79+
# Try it
80+
unset PYTHONPATH
81+
./sextractor++-x86_64.AppImage --version
82+
if [[ $? != 0 ]]; then
83+
echo "Failed to build the AppImage!"
84+
exit 1
85+
else
86+
echo "Success!"
87+
exit 0
88+
fi
89+

.travis/build-rpm.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
set -ex
3+
4+
# Environment
5+
export VERBOSE=0
6+
export CTEST_OUTPUT_ON_FAILURE=1
7+
8+
# Platform-specific configuration
9+
source /etc/os-release
10+
11+
CMAKEFLAGS="-DINSTALL_DOC=ON -DRPM_NO_CHECK=OFF"
12+
13+
if [ "$ID" == "fedora" ]; then
14+
if [ "$VERSION_ID" -ge 30 ]; then
15+
PYTHON="python3"
16+
CMAKEFLAGS="$CMAKEFLAGS -DPYTHON_EXPLICIT_VERSION=3"
17+
else
18+
PYTHON="python2"
19+
fi
20+
elif [ "$ID" == "centos" ]; then
21+
yum install -y -q epel-release
22+
PYTHON="python2"
23+
fi
24+
25+
# Astrorama repository
26+
cat > /etc/yum.repos.d/astrorama.repo << EOF
27+
[bintray--astrorama-fedora]
28+
name=bintray--astrorama-fedora
29+
baseurl=https://dl.bintray.com/astrorama/travis/master/${ID}/\$releasever/\$basearch
30+
gpgcheck=0
31+
repo_gpgcheck=0
32+
enabled=1
33+
34+
[bintray--astrorama-fedora-develop]
35+
name=bintray--astrorama-fedora-develop
36+
baseurl=https://dl.bintray.com/astrorama/travis/develop/${ID}/\$releasever/\$basearch
37+
gpgcheck=0
38+
repo_gpgcheck=0
39+
enabled=1
40+
EOF
41+
42+
# From the CMakeLists.txt, retrieve the list of dependencies
43+
cmake_deps=$(grep -oP 'elements_project\(\S+\s+\S+ USE \K(\S+ \S+)*(?=\))' /src/CMakeLists.txt)
44+
rpm_dev_deps=$(echo ${cmake_deps} | awk '{for(i=1;i<NF;i+=2){print $i "-devel-" $(i+1)}}')
45+
rpm_doc_deps=$(echo ${cmake_deps} | awk '{for(i=1;i<NF;i+=2){print $i "-doc-" $(i+1)}}')
46+
yum install -y -q ${rpm_dev_deps} ${rpm_doc_deps}
47+
48+
# Dependencies
49+
yum install -y -q cmake make gcc-c++ rpm-build
50+
yum install -y -q boost-devel $PYTHON-pytest log4cpp-devel doxygen CCfits-devel
51+
yum install -y -q graphviz $PYTHON-sphinx $PYTHON-sphinxcontrib-apidoc
52+
yum install -y -q gmock-devel gtest-devel
53+
yum install -y -q ${PYTHON}-devel boost-${PYTHON}-devel fftw-devel levmar-devel wcslib-devel
54+
55+
# Build
56+
mkdir -p /build
57+
cd /build
58+
cmake -DCMAKE_INSTALL_PREFIX=/usr $CMAKEFLAGS /src
59+
make $MAKEFLAGS rpm
60+

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ find_package(ElementsProject)
66
#---------------------------------------------------------------
77

88
# Declare project name and version
9-
elements_project(SExtractorxx 0.1 USE Alexandria 2.14 Elements 5.8)
9+
elements_project(SExtractorxx 0.1 USE Alexandria 2.14.1 Elements 5.8)

SEImplementation/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ find_package(PythonLibs ${PYTHON_EXPLICIT_VERSION} REQUIRED)
3636
find_package(BoostPython ${PYTHON_EXPLICIT_VERSION})
3737
find_package(Boost 1.53 REQUIRED)
3838

39-
if (${Boost_VERSION} LESS "106600")
39+
if (${Boost_VERSION} LESS "106700")
4040
message(WARNING "
41-
Numerical differentiation is available starting from Boost 106600 (${Boost_VERSION} found instead).
41+
Numerical differentiation is available starting from Boost 106700 (${Boost_VERSION} found instead).
4242
The model fitting plugin will use a potentially less robust fallback method for computing error margins!")
4343
endif ()
4444

SEImplementation/SEImplementation/Plugin/FlexibleModelFitting/FlexibleModelFittingTask.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,10 @@ class FlexibleModelFittingTask : public GroupTask {
6565
void updateCheckImages(SourceGroupInterface& group,
6666
double pixel_scale, FlexibleModelFittingParameterManager& manager) const;
6767

68-
SeFloat computeReducedChiSquaredForFrame(std::shared_ptr<const Image<SeFloat>> image,
69-
std::shared_ptr<const Image<SeFloat>> model, std::shared_ptr<const Image<SeFloat>> weights,
70-
int nb_of_free_params) const;
71-
SeFloat computeReducedChiSquared(SourceGroupInterface& group,
72-
double pixel_scale, FlexibleModelFittingParameterManager& manager) const;
68+
SeFloat computeChiSquaredForFrame(std::shared_ptr<const Image<SeFloat>> image,
69+
std::shared_ptr<const Image<SeFloat>> model, std::shared_ptr<const Image<SeFloat>> weights, int& data_points) const;
70+
SeFloat computeChiSquared(SourceGroupInterface& group,
71+
double pixel_scale, FlexibleModelFittingParameterManager& manager, int& total_data_points) const;
7372

7473
// Task configuration
7574
unsigned int m_max_iterations;

SEImplementation/src/lib/CheckImages/CheckImages.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ void CheckImages::saveImages() {
258258
filename += "_" + ci.first->getLabel();
259259
filename.replace_extension(m_residual_filename.extension());
260260
auto frame_filename = m_residual_filename.parent_path() / filename;
261-
FitsWriter::writeFile(*residual_image, filename.native(), ci.first->getCoordinateSystem());
261+
FitsWriter::writeFile(*residual_image, frame_filename.native(), ci.first->getCoordinateSystem());
262262
}
263263
}
264264

SEImplementation/src/lib/Plugin/FlexibleModelFitting/FlexibleModelFittingParameter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include <iostream>
2525

2626
#include <boost/version.hpp>
27-
#if BOOST_VERSION >= 106600
27+
#if BOOST_VERSION >= 106700
2828

2929
#if BOOST_VERSION >= 107000
3030
#include <boost/math/differentiation/finite_difference.hpp>
@@ -182,7 +182,7 @@ std::vector<double> FlexibleModelFittingDependentParameter::getPartialDerivative
182182
return m_value_calculator(cs, params);
183183
};
184184

185-
#if BOOST_VERSION >= 106600
185+
#if BOOST_VERSION >= 106700
186186
result[i] = bmd::finite_difference_derivative(f, param_values[i]);
187187
#else
188188
// if boost's function is unavailable use our own function

SEImplementation/src/lib/Plugin/FlexibleModelFitting/FlexibleModelFittingTask.cpp

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,21 @@ void FlexibleModelFittingTask::computeProperties(SourceGroupInterface& group) co
307307
LevmarEngine engine{m_max_iterations, 1E-6, 1E-6, 1E-6, 1E-6, 1E-4};
308308
auto solution = engine.solveProblem(engine_parameter_manager, res_estimator);
309309
size_t iterations = (size_t) boost::any_cast<std::array<double, 10>>(solution.underlying_framework_info)[5];
310-
SeFloat avg_reduced_chi_squared = computeReducedChiSquared(group, pixel_scale, parameter_manager);
310+
311+
int total_data_points = 0;
312+
SeFloat avg_reduced_chi_squared = computeChiSquared(group, pixel_scale, parameter_manager, total_data_points);
313+
314+
int nb_of_free_parameters = 0;
315+
for (auto& source : group) {
316+
for (auto parameter : m_parameters) {
317+
bool is_free_parameter = std::dynamic_pointer_cast<FlexibleModelFittingFreeParameter>(parameter).get();
318+
bool accessed_by_modelfitting = parameter_manager.isParamAccessed(source, parameter);
319+
if (is_free_parameter && accessed_by_modelfitting) {
320+
nb_of_free_parameters++;
321+
}
322+
}
323+
}
324+
avg_reduced_chi_squared /= (total_data_points - nb_of_free_parameters);
311325

312326
// Collect parameters for output
313327
for (auto& source : group) {
@@ -316,10 +330,10 @@ void FlexibleModelFittingTask::computeProperties(SourceGroupInterface& group) co
316330

317331
for (auto parameter : m_parameters) {
318332
bool is_dependent_parameter = std::dynamic_pointer_cast<FlexibleModelFittingDependentParameter>(parameter).get();
319-
bool accesed_by_modelfitting = parameter_manager.isParamAccessed(source, parameter);
333+
bool accessed_by_modelfitting = parameter_manager.isParamAccessed(source, parameter);
320334
auto modelfitting_parameter = parameter_manager.getParameter(source, parameter);
321335

322-
if (is_dependent_parameter || accesed_by_modelfitting) {
336+
if (is_dependent_parameter || accessed_by_modelfitting) {
323337
parameter_values[parameter->getId()] = modelfitting_parameter->getValue();
324338
parameter_sigmas[parameter->getId()] = parameter->getSigma(parameter_manager, source, solution.parameter_sigmas);
325339
}
@@ -334,6 +348,7 @@ void FlexibleModelFittingTask::computeProperties(SourceGroupInterface& group) co
334348
source_flags |= Flags::PARTIAL_FIT;
335349
}
336350
}
351+
337352
source.setProperty<FlexibleModelFitting>(iterations, avg_reduced_chi_squared, source_flags, parameter_values,
338353
parameter_sigmas);
339354
}
@@ -374,11 +389,10 @@ void FlexibleModelFittingTask::updateCheckImages(SourceGroupInterface& group,
374389
}
375390
}
376391

377-
SeFloat FlexibleModelFittingTask::computeReducedChiSquaredForFrame(std::shared_ptr<const Image<SeFloat>> image,
378-
std::shared_ptr<const Image<SeFloat>> model, std::shared_ptr<const Image<SeFloat>> weights,
379-
int nb_of_free_params) const {
392+
SeFloat FlexibleModelFittingTask::computeChiSquaredForFrame(std::shared_ptr<const Image<SeFloat>> image,
393+
std::shared_ptr<const Image<SeFloat>> model, std::shared_ptr<const Image<SeFloat>> weights, int& data_points) const {
380394
double reduced_chi_squared = 0.0;
381-
int data_points = 0;
395+
data_points = 0;
382396
for (int y=0; y < image->getHeight(); y++) {
383397
for (int x=0; x < image->getWidth(); x++) {
384398
double tmp = image->getValue(x, y) - model->getValue(x, y);
@@ -388,13 +402,14 @@ SeFloat FlexibleModelFittingTask::computeReducedChiSquaredForFrame(std::shared_p
388402
}
389403
}
390404
}
391-
return reduced_chi_squared / (data_points - nb_of_free_params);
405+
return reduced_chi_squared;
392406
}
393407

394-
SeFloat FlexibleModelFittingTask::computeReducedChiSquared(SourceGroupInterface& group,
395-
double pixel_scale, FlexibleModelFittingParameterManager& manager) const {
408+
SeFloat FlexibleModelFittingTask::computeChiSquared(SourceGroupInterface& group,
409+
double pixel_scale, FlexibleModelFittingParameterManager& manager, int& total_data_points) const {
396410

397-
SeFloat avg_reduced_chi_squared = 0;
411+
SeFloat total_chi_squared = 0;
412+
total_data_points = 0;
398413
int valid_frames = 0;
399414
for (auto frame : m_frames) {
400415
int frame_index = frame->getFrameNb();
@@ -408,13 +423,16 @@ SeFloat FlexibleModelFittingTask::computeReducedChiSquared(SourceGroupInterface&
408423
auto image = createImageCopy(group, frame_index);
409424
auto weight = createWeightImage(group, frame_index);
410425

411-
SeFloat reduced_chi_squared = computeReducedChiSquaredForFrame(
412-
image, final_stamp, weight, manager.getParameterNb());
413-
avg_reduced_chi_squared += reduced_chi_squared;
426+
int data_points = 0;
427+
SeFloat chi_squared = computeChiSquaredForFrame(
428+
image, final_stamp, weight, data_points);
429+
430+
total_data_points += data_points;
431+
total_chi_squared += chi_squared;
414432
}
415433
}
416434

417-
return avg_reduced_chi_squared / valid_frames;
435+
return total_chi_squared;
418436
}
419437

420438
FlexibleModelFittingTask::~FlexibleModelFittingTask() {

SEMain/auxdir/SEMain/sextractor++.desktop

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ Terminal=true
55
NoDisplay=true
66
Exec=sextractor++
77
Icon=sextractor++
8-
8+
Categories=Education;

0 commit comments

Comments
 (0)