Skip to content

Commit

Permalink
Run autostyle on the C++ files.
Browse files Browse the repository at this point in the history
  • Loading branch information
DinoBektesevic committed Sep 25, 2023
1 parent 7fcc259 commit e7c0ad5
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 89 deletions.
26 changes: 13 additions & 13 deletions src/kbmod/search/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,19 +208,19 @@ namespace search {
.def("__repr__", [](const tj &t) { return "Trajectory(" + t.to_string() + ")"; })
.def("__str__", &tj::to_string)
.def(py::pickle(
[] (const tj &p) { // __getstate__
return py::make_tuple(p.vx, p.vy, p.lh, p.flux, p.x, p.y, p.obs_count);
},
[] (py::tuple t) { // __setstate__
if (t.size() != 7)
throw std::runtime_error("Invalid state!");
tj trj = {
t[0].cast<float>(), t[1].cast<float>(), t[2].cast<float>(),
t[3].cast<float>(), t[4].cast<short>(), t[5].cast<short>(),
t[6].cast<short>()
};
return trj;
})
[] (const tj &p) { // __getstate__
return py::make_tuple(p.vx, p.vy, p.lh, p.flux, p.x, p.y, p.obs_count);
},
[] (py::tuple t) { // __setstate__
if (t.size() != 7)
throw std::runtime_error("Invalid state!");
tj trj = {
t[0].cast<float>(), t[1].cast<float>(), t[2].cast<float>(),
t[3].cast<float>(), t[4].cast<short>(), t[5].cast<short>(),
t[6].cast<short>()
};
return trj;
})
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/kbmod/search/filtering.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "filtering.h"
#include <math.h>

namespace search {

namespace search {
#ifdef HAVE_CUDA
/* The filter_kenerls.cu functions. */
extern "C" void SigmaGFilteredIndicesCU(float *values, int num_values, float sgl0, float sgl1, float sg_coeff,
Expand Down
2 changes: 0 additions & 2 deletions src/kbmod/search/filtering.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#ifndef FILTERING_H_
#define FILTERING_H_


#include <vector>


namespace search {

/* Return the list of indices from the values array such that those elements
pass the sigmaG filtering defined by percentiles [sGL0, sGL1] with coefficient
sigmag_coeff and a multiplicative factor of width. */
Expand Down
5 changes: 3 additions & 2 deletions src/kbmod/search/image_stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace py = pybind11;


namespace search {

ImageStack::ImageStack(const std::vector<std::string>& filenames, const std::vector<PSF>& psfs) {
verbose = true;
reset_images();
Expand All @@ -26,7 +25,7 @@ namespace search {
}

void ImageStack::load_images(const std::vector<std::string>& filenames,
const std::vector<PSF>& psfs) {
const std::vector<PSF>& psfs) {
const int num_files = filenames.size();
if (num_files == 0) {
std::cout << "No files provided"
Expand Down Expand Up @@ -156,5 +155,7 @@ namespace search {
.def("get_height", &is::get_height, pydocs::DOC_ImageStack_get_height)
.def("get_npixels", &is::get_npixels, pydocs::DOC_ImageStack_get_npixels);
}

#endif /* Py_PYTHON_H */

} /* namespace search */
1 change: 0 additions & 1 deletion src/kbmod/search/image_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@


namespace search {

class ImageStack {
public:
ImageStack(const std::vector<std::string>& filenames, const std::vector<PSF>& psfs);
Expand Down
23 changes: 9 additions & 14 deletions src/kbmod/search/layered_image.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
/*
* LayeredImage.cpp
*
* Created on: Jul 11, 2017
* Author: kbmod-usr
*/

#include "layered_image.h"

namespace search {

namespace search {
LayeredImage::LayeredImage(std::string path, const PSF& psf) : psf(psf) {
int f_begin = path.find_last_of("/");
int f_end = path.find_last_of(".fits") - 4;
Expand All @@ -31,9 +24,9 @@ namespace search {
throw std::runtime_error("Science and Mask layers are not the same size.");
}

LayeredImage::LayeredImage(const RawImage& sci, const RawImage& var, const RawImage& msk,
const PSF& psf)
: psf(psf) {
LayeredImage::LayeredImage(const RawImage& sci, const RawImage& var, const RawImage& msk,
const PSF& psf)
: psf(psf) {
// Get the dimensions of the science layer and check for consistency with
// the other two layers.
width = sci.get_width();
Expand All @@ -53,9 +46,9 @@ LayeredImage::LayeredImage(const RawImage& sci, const RawImage& var, const RawIm
const PSF& psf)
: LayeredImage(name, w, h, noise_stdev, pixel_variance, time, psf, -1) {}

LayeredImage::LayeredImage(std::string name, int w, int h, float noise_stdev, float pixel_variance, double time,
const PSF& psf, int seed)
: psf(psf) {
LayeredImage::LayeredImage(std::string name, int w, int h, float noise_stdev, float pixel_variance, double time,
const PSF& psf, int seed)
: psf(psf) {
filename = name;
width = w;
height = h;
Expand Down Expand Up @@ -266,6 +259,8 @@ LayeredImage::LayeredImage(std::string name, int w, int h, float noise_stdev, fl
.def("generate_psi_image", &li::generate_psi_image, pydocs::DOC_LayeredImage_generate_psi_image)
.def("generate_phi_image", &li::generate_phi_image, pydocs::DOC_LayeredImage_generate_phi_image);
}

#endif /* Py_PYTHON_H */

} /* namespace search */

11 changes: 0 additions & 11 deletions src/kbmod/search/layered_image.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
/*
* layered_image.h
*
* Created on: Jul 11, 2017
* Author: kbmod-usr
*
* LayeredImage stores an image from a single time with different layers of
* data, such as science pixels, variance pixels, and mask pixels.
*/

#ifndef LAYEREDIMAGE_H_
#define LAYEREDIMAGE_H_

Expand All @@ -24,7 +14,6 @@


namespace search {

class LayeredImage {
public:
explicit LayeredImage(std::string path, const PSF& psf);
Expand Down
9 changes: 0 additions & 9 deletions src/kbmod/search/psf.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
/*
* psf.h
*
* Created on: Nov 12, 2016
* Author: peter
*
* A class for working with point spread functions.
*/

#ifndef PSF_H_
#define PSF_H_

Expand Down
2 changes: 1 addition & 1 deletion src/kbmod/search/pydocs/image_stack_docs.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace pydocs {
static const auto DOC_ImageStack = R"doc(
todo
)doc";
)doc";

static const auto DOC_ImageStack_get_images = R"doc(
todo
Expand Down
1 change: 0 additions & 1 deletion src/kbmod/search/raw_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ namespace py = pybind11;


namespace search {

#ifdef HAVE_CUDA
// Performs convolution between an image represented as an array of floats
// and a PSF on a GPU device.
Expand Down
9 changes: 0 additions & 9 deletions src/kbmod/search/raw_image.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
/*
* raw_image.h
*
* Created on: Jun 22, 2017
* Author: kbmod-usr
*
* RawImage stores pixel level data for a single image.
*/

#ifndef RAWIMAGE_H_
#define RAWIMAGE_H_

Expand Down
36 changes: 19 additions & 17 deletions src/kbmod/search/stack_search.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "stack_search.h"

namespace search {

namespace search {
#ifdef HAVE_CUDA
extern "C" void deviceSearchFilter(int num_images, int width, int height, float* psi_vect, float* phi_vect,
PerImageData img_data, SearchParameters params, int num_trajectories,
Expand Down Expand Up @@ -65,7 +65,7 @@ namespace search {
}

void StackSearch::enable_gpu_sigmag_filter(std::vector<float> percentiles, float sigmag_coeff,
float min_lh) {
float min_lh) {
params.do_sigmag_filter = true;
params.sgl_L = percentiles[0];
params.sgl_H = percentiles[1];
Expand Down Expand Up @@ -99,7 +99,7 @@ namespace search {
}

void StackSearch::search(int ang_steps, int vel_steps, float min_ang, float max_ang, float min_vel,
float mavx, int min_observations) {
float mavx, int min_observations) {
prepare_psi_phi();
create_search_list(ang_steps, vel_steps, min_ang, max_ang, min_vel, mavx);

Expand Down Expand Up @@ -183,7 +183,7 @@ namespace search {
}

std::vector<scaleParameters> StackSearch::compute_image_scaling(const std::vector<RawImage>& vect,
int encoding_bytes) const {
int encoding_bytes) const {
std::vector<scaleParameters> result;

const int num_images = vect.size();
Expand Down Expand Up @@ -222,7 +222,7 @@ namespace search {
}

void StackSearch::create_search_list(int angle_steps, int velocity_steps, float min_ang, float max_ang,
float min_vel, float mavx) {
float min_vel, float mavx) {
std::vector<float> angles(angle_steps);
float ang_stepsize = (max_ang - min_ang) / float(angle_steps);
for (int i = 0; i < angle_steps; ++i) {
Expand All @@ -246,8 +246,8 @@ namespace search {
}

void StackSearch::fill_psi_phi(const std::vector<RawImage>& psi_imgs,
const std::vector<RawImage>& phi_imgs, std::vector<float>* psi_vect,
std::vector<float>* phi_vect) {
const std::vector<RawImage>& phi_imgs, std::vector<float>* psi_vect,
std::vector<float>* phi_vect) {
assert(psi_vect != NULL);
assert(phi_vect != NULL);

Expand Down Expand Up @@ -277,7 +277,7 @@ namespace search {
}

std::vector<RawImage> StackSearch::create_stamps(const Trajectory& trj, int radius, bool interpolate,
bool keep_no_data, const std::vector<bool>& use_index) {
bool keep_no_data, const std::vector<bool>& use_index) {
if (use_index.size() > 0 && use_index.size() != stack.img_count()) {
throw std::runtime_error("Wrong size use_index passed into create_stamps()");
}
Expand Down Expand Up @@ -306,7 +306,7 @@ namespace search {
// For creating coadded stamps, we do not interpolate the pixel values and keep
// NO_DATA tagged (so we can filter it out of mean/median).
RawImage StackSearch::get_median_stamp(const Trajectory& trj, int radius,
const std::vector<bool>& use_index) {
const std::vector<bool>& use_index) {
return create_median_image(
create_stamps(trj, radius, false /*=interpolate*/, true /*=keep_no_data*/, use_index));
}
Expand All @@ -321,7 +321,7 @@ namespace search {
// For creating summed stamps, we do not interpolate the pixel values and replace NO_DATA
// with zero (which is the same as filtering it out for the sum).
RawImage StackSearch::get_summed_stamp(const Trajectory& trj, int radius,
const std::vector<bool>& use_index) {
const std::vector<bool>& use_index) {
return create_summed_image(
create_stamps(trj, radius, false /*=interpolate*/, false /*=keep_no_data*/, use_index));
}
Expand Down Expand Up @@ -365,8 +365,8 @@ namespace search {
}

std::vector<RawImage> StackSearch::get_coadded_stamps(std::vector<Trajectory>& t_array,
std::vector<std::vector<bool> >& use_index_vect,
const StampParameters& params, bool use_gpu) {
std::vector<std::vector<bool> >& use_index_vect,
const StampParameters& params, bool use_gpu) {
if (use_gpu) {
#ifdef HAVE_CUDA
return get_coadded_stamps_gpu(t_array, use_index_vect, params);
Expand All @@ -379,8 +379,8 @@ namespace search {
}

std::vector<RawImage> StackSearch::get_coadded_stamps_cpu(std::vector<Trajectory>& t_array,
std::vector<std::vector<bool> >& use_index_vect,
const StampParameters& params) {
std::vector<std::vector<bool> >& use_index_vect,
const StampParameters& params) {
const int num_trajectories = t_array.size();
std::vector<RawImage> results(num_trajectories);
std::vector<float> empty_pixels(1, NO_DATA);
Expand Down Expand Up @@ -416,8 +416,8 @@ namespace search {
}

std::vector<RawImage> StackSearch::get_coadded_stamps_gpu(std::vector<Trajectory>& t_array,
std::vector<std::vector<bool> >& use_index_vect,
const StampParameters& params) {
std::vector<std::vector<bool> >& use_index_vect,
const StampParameters& params) {
// Right now only limited stamp sizes are allowed.
if (2 * params.radius + 1 > MAX_STAMP_EDGE || params.radius <= 0) {
throw std::runtime_error("Invalid Radius.");
Expand Down Expand Up @@ -468,7 +468,7 @@ namespace search {
}

std::vector<RawImage> StackSearch::create_stamps(Trajectory t, int radius, const std::vector<RawImage*>& imgs,
bool interpolate) {
bool interpolate) {
if (radius < 0) throw std::runtime_error("stamp radius must be at least 0");
std::vector<RawImage> stamps;
for (int i = 0; i < imgs.size(); ++i) {
Expand Down Expand Up @@ -647,5 +647,7 @@ namespace search {
.def("get_results", &ks::get_results, pydocs::DOC_StackSearch_get_results)
.def("set_results", &ks::set_results, pydocs::DOC_StackSearch_set_results);
}

#endif /* Py_PYTHON_H */

} /* namespace search */
15 changes: 7 additions & 8 deletions src/kbmod/search/stack_search.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef KBMODSEARCH_H_
#define KBMODSEARCH_H_


#include <parallel/algorithm>
#include <algorithm>
#include <functional>
Expand Down Expand Up @@ -96,11 +95,11 @@ namespace search {

// Fill an interleaved vector for the GPU functions.
void fill_psi_phi(const std::vector<RawImage>& psi_imgs, const std::vector<RawImage>& phi_imgs,
std::vector<float>* psi_vect, std::vector<float>* phi_vect);
std::vector<float>* psi_vect, std::vector<float>* phi_vect);

// Set the parameter min/max/scale from the psi/phi/other images.
std::vector<scaleParameters> compute_image_scaling(const std::vector<RawImage>& vect,
int encoding_bytes) const;
int encoding_bytes) const;

// Functions to create and access stamps around proposed trajectories or
// regions. Used to visualize the results.
Expand All @@ -110,15 +109,15 @@ namespace search {

// Creates list of trajectories to search.
void create_search_list(int angle_steps, int velocity_steps, float min_ang, float max_ang,
float min_vel, float max_vel);
float min_vel, float max_vel);

std::vector<RawImage> get_coadded_stamps_gpu(std::vector<Trajectory>& t_array,
std::vector<std::vector<bool> >& use_index_vect,
const StampParameters& params);
std::vector<std::vector<bool> >& use_index_vect,
const StampParameters& params);

std::vector<RawImage> get_coadded_stamps_cpu(std::vector<Trajectory>& t_array,
std::vector<std::vector<bool> >& use_index_vect,
const StampParameters& params);
std::vector<std::vector<bool> >& use_index_vect,
const StampParameters& params);
// Helper functions for timing operations of the search.
void start_timer(const std::string& message);
void end_timer();
Expand Down

0 comments on commit e7c0ad5

Please sign in to comment.