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

Style changes #344

Merged
merged 10 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 30 additions & 31 deletions src/kbmod/search/Filtering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,64 +12,63 @@
namespace search {

#ifdef HAVE_CUDA
/* The filter_kenerls.cu functions. */
extern "C" void sigmaGFilteredIndicesCU(float* values, int num_values, float sGL0, float sGL1,
float sigmaGCoeff, float width, int* idxArray, int* minKeepIndex,
int* maxKeepIndex);
/* The filter_kenerls.cu functions. */
extern "C" void SigmaGFilteredIndicesCU(float *values, int num_values, float sgl0, float sgl1, float sg_coeff,
float width, int *idx_array, int *min_keep_idx, int *max_keep_idx);
#endif

/* Return the list of indices from the values array such that those elements
pass the sigmaG filtering defined by percentiles [sGL0, sGL1] with coefficient
sigmaGCoeff and a multiplicative factor of width. */
std::vector<int> sigmaGFilteredIndices(const std::vector<float>& values, float sGL0, float sGL1,
float sigmaGCoeff, float width) {
pass the sigmaG filtering defined by percentiles [sgl0, sgl1] with coefficient
sigma_g_coeff and a multiplicative factor of width. */
std::vector<int> sigmaGFilteredIndices(const std::vector<float> &values, float sgl0, float sgl1,
float sigma_g_coeff, float width) {
// Bounds check the percentile values.
assert(sGL0 > 0.0);
assert(sGL1 < 1.0);
assert(sgl0 > 0.0);
assert(sgl1 < 1.0);

// Allocate space for the input and result.
const int num_values = values.size();
float values_arr[num_values];
int idxArray[num_values];
int idx_array[num_values];
for (int i = 0; i < num_values; ++i) {
values_arr[i] = values[i];
}

int minKeepIndex = 0;
int maxKeepIndex = num_values - 1;
int min_keep_idx = 0;
int max_keep_idx = num_values - 1;

#ifdef HAVE_CUDA
sigmaGFilteredIndicesCU(values_arr, num_values, sGL0, sGL1, sigmaGCoeff, width, idxArray,
&minKeepIndex, &maxKeepIndex);
#else
throw std::runtime_error("Non-GPU sigmaGFilteredIndicesCU is not implemented.");
#endif
#ifdef HAVE_CUDA
SigmaGFilteredIndicesCU(values_arr, num_values, sgl0, sgl1, sigma_g_coeff, width, idx_array,
&min_keep_idx, &max_keep_idx);
#else
throw std::runtime_error("Non-GPU SigmaGFilteredIndicesCU is not implemented.");
#endif

// Copy the result into a vector and return it.
std::vector<int> result;
for (int i = minKeepIndex; i <= maxKeepIndex; ++i) {
result.push_back(idxArray[i]);
for (int i = min_keep_idx; i <= max_keep_idx; ++i) {
result.push_back(idx_array[i]);
}
return result;
}

/* Given a set of psi and phi values,
return a likelihood value */
double calculateLikelihoodFromPsiPhi(std::vector<double> psiValues, std::vector<double> phiValues) {
assert(psiValues.size() == phiValues.size());
double psiSum = 0.0;
double phiSum = 0.0;
double calculateLikelihoodFromPsiPhi(std::vector<double> psi_values, std::vector<double> phi_values) {
assert(psi_values.size() == phi_values.size());
double psi_sum = 0.0;
double phi_sum = 0.0;

for (int i = 0; i < psiValues.size(); i++) {
psiSum += psiValues[i];
phiSum += phiValues[i];
for (int i = 0; i < psi_values.size(); i++) {
psi_sum += psi_values[i];
phi_sum += phi_values[i];
}

if (psiSum == 0.0 || phiSum <= 0.0) {
if (psi_sum == 0.0 || phi_sum <= 0.0) {
return 0.0;
}

return psiSum / sqrt(phiSum);
return psi_sum / sqrt(phi_sum);
}

} /* namespace search */
6 changes: 3 additions & 3 deletions src/kbmod/search/Filtering.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ 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
sigmaGCoeff and a multiplicative factor of width. */
std::vector<int> sigmaGFilteredIndices(const std::vector<float>& values, float sGL0, float sGL1,
float sigmaGCoeff, float width);
sigmag_coeff and a multiplicative factor of width. */
std::vector<int> sigmaGFilteredIndices(const std::vector<float>& values, float sgl0, float sgl1,
float sigma_g_coeff, float width);

} /* namespace search */

Expand Down
34 changes: 17 additions & 17 deletions src/kbmod/search/ImageStack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ ImageStack::ImageStack(const std::vector<std::string>& filenames, const std::vec
loadImages(filenames, psfs);
extractImageTimes();
setTimeOrigin();
globalMask = RawImage(getWidth(), getHeight());
globalMask.setAllPix(0.0);
global_mask = RawImage(getWidth(), getHeight());
global_mask.setAllPix(0.0);
}

ImageStack::ImageStack(const std::vector<LayeredImage>& imgs) {
verbose = true;
images = imgs;
extractImageTimes();
setTimeOrigin();
globalMask = RawImage(getWidth(), getHeight());
globalMask.setAllPix(0.0);
global_mask = RawImage(getWidth(), getHeight());
global_mask.setAllPix(0.0);
}

void ImageStack::loadImages(const std::vector<std::string>& fileNames,
void ImageStack::loadImages(const std::vector<std::string>& filenames,
const std::vector<PointSpreadFunc>& psfs) {
const int num_files = fileNames.size();
const int num_files = filenames.size();
if (num_files == 0) {
std::cout << "No files provided"
<< "\n";
Expand All @@ -40,24 +40,24 @@ void ImageStack::loadImages(const std::vector<std::string>& fileNames,

// Load images from file
for (int i = 0; i < num_files; ++i) {
images.push_back(LayeredImage(fileNames[i], psfs[i]));
images.push_back(LayeredImage(filenames[i], psfs[i]));
if (verbose) std::cout << "." << std::flush;
}
if (verbose) std::cout << "\n";
}

void ImageStack::extractImageTimes() {
// Load image times
imageTimes = std::vector<float>();
image_times = std::vector<float>();
for (auto& i : images) {
imageTimes.push_back(float(i.getObstime()));
image_times.push_back(float(i.getObstime()));
}
}

void ImageStack::setTimeOrigin() {
// Set beginning time to 0.0
double initialTime = imageTimes[0];
for (auto& t : imageTimes) t = t - initialTime;
double initial_time = image_times[0];
for (auto& t : image_times) t = t - initial_time;
}

LayeredImage& ImageStack::getSingleImage(int index) {
Expand All @@ -75,7 +75,7 @@ void ImageStack::setTimes(const std::vector<float>& times) {
throw std::runtime_error(
"List of times provided"
" does not match the number of images!");
imageTimes = times;
image_times = times;
setTimeOrigin();
}

Expand All @@ -85,13 +85,13 @@ void ImageStack::convolvePSF() {
for (auto& i : images) i.convolvePSF();
}

void ImageStack::saveGlobalMask(const std::string& path) { globalMask.saveToFile(path); }
void ImageStack::saveGlobalMask(const std::string& path) { global_mask.saveToFile(path); }

void ImageStack::saveImages(const std::string& path) {
for (auto& i : images) i.saveLayers(path);
}

const RawImage& ImageStack::getGlobalMask() const { return globalMask; }
const RawImage& ImageStack::getGlobalMask() const { return global_mask; }

void ImageStack::applyMaskFlags(int flags, const std::vector<int>& exceptions) {
for (auto& i : images) {
Expand All @@ -102,7 +102,7 @@ void ImageStack::applyMaskFlags(int flags, const std::vector<int>& exceptions) {
void ImageStack::applyGlobalMask(int flags, int threshold) {
createGlobalMask(flags, threshold);
for (auto& i : images) {
i.applyGlobalMask(globalMask);
i.applyGlobalMask(global_mask);
}
}

Expand All @@ -128,9 +128,9 @@ void ImageStack::createGlobalMask(int flags, int threshold) {
}

// Set all pixels below threshold to 0 and all above to 1
float* globalM = globalMask.getDataRef();
float* global_m = global_mask.getDataRef();
for (unsigned int p = 0; p < npixels; ++p) {
globalM[p] = counts[p] < threshold ? 0.0 : 1.0;
global_m[p] = counts[p] < threshold ? 0.0 : 1.0;
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/kbmod/search/ImageStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ class ImageStack {
unsigned getHeight() const { return images.size() > 0 ? images[0].getHeight() : 0; }
unsigned getNPixels() const { return images.size() > 0 ? images[0].getNPixels() : 0; }
std::vector<LayeredImage>& getImages() { return images; }
const std::vector<float>& getTimes() const { return imageTimes; }
float* getTimesDataRef() { return imageTimes.data(); }
const std::vector<float>& getTimes() const { return image_times; }
float* getTimesDataRef() { return image_times.data(); }
LayeredImage& getSingleImage(int index);

// Simple setters.
Expand All @@ -55,13 +55,13 @@ class ImageStack {
virtual ~ImageStack(){};

private:
void loadImages(const std::vector<std::string>& fileNames, const std::vector<PointSpreadFunc>& psfs);
void loadImages(const std::vector<std::string>& filenames, const std::vector<PointSpreadFunc>& psfs);
void extractImageTimes();
void setTimeOrigin();
void createGlobalMask(int flags, int threshold);
std::vector<LayeredImage> images;
RawImage globalMask;
std::vector<float> imageTimes;
RawImage global_mask;
std::vector<float> image_times;
bool verbose;
};

Expand Down
Loading