PSFEstimationwithCPSO
kippef.hpp
00001 /*
00002  * kippef.hpp
00003  *
00004  *  Created on: 27/05/2012
00005  *  Author: Peter Frank Perroni (pfperroni@inf.ufpr.br)
00006  */
00007 
00008 #ifndef _KIPPE_H_
00009 #define _KIPPE_H_
00010 
00011 #include <math.h>
00012 #include <iostream>
00013 #include <sstream>
00014 #include <fstream>
00015 #include <stdio.h>
00016 #include <stdlib.h>
00017 #include <time.h>
00018 #include <complex>
00019 #include <complex.h>
00020 #include <errno.h>
00021 #include <string.h>
00022 #include <fitsio.h>
00023 #include <time.h>
00024 #include <omp.h>
00025 #include "config.hpp"
00026 #include "psf_estimator.hpp"
00027 #include "cpso.hpp"
00028 #include "TimeTracker.hpp"
00029 #include "FitsManager.hpp"
00030 
00031 
00035 #define pi 3.1415926535897932
00036 
00042 #define exit_error(err) exit(err)
00043 
00050 #define rect_to_r(x, y) sqrt(pow(x, 2) + pow(y, 2))
00051 
00061 #define set_two_d_array_value(array, value, i, j, size_x) array[j * size_x + i] = value;
00062 
00071 #define get_two_d_array_value(array, i, j, size_x) array[j * size_x + i]
00072 
00081 #define cmp_freq_cut(tel_dia, img_scl, wavelength, img_size) ((pi * tel_dia * img_size * img_scl) / (3600.0 * 180.0 * wavelength))
00082 
00091 #define cmp_size_of_phase(tel_dia, image_scale, wavelength, N) ((int) round((tel_dia * image_scale * pi * N) / (180.0 * 3600.0 * wavelength)))
00092 
00102 #define copy_par(in, out, size) for (int _i = 0; _i < size; _i++) out[_i] = in[_i];
00103 
00111 #define scale_par(in, scale, size) for (int _i = 0; _i < size; _i++) in[_i] = in[_i] * scale;
00112 
00119 #define reset_phase(phase, size) memset(phase, 0, size * size * sizeof(double))
00120 
00128 void run_cpso(CPSO *cpso, fits_result *result, int n_cycles);
00129 
00130 
00150 void validate_psf_file(char *psfFileName, char *objFileName, char *imgFileName, double* zernikes, int* diffraction_mask, int *phase_mask,
00151                 int n_zernikes, int image_size, int phase_size, double range);
00152 
00153 
00154 void nollTest(double* object, double* zernikes, int* diffraction_mask,
00155                 int n_zernikes, int image_size, int phase_size, double range, int *phase_mask,
00156                 char *object_filename, vector<int> *_devices);
00157 
00187 void validate_psfcode(double* object, double* zernikes, int* diffraction_mask,
00188                 int n_zernikes, int image_size, int phase_size, double range, int *phase_mask,
00189                 char *object_filename, int n_validations, int rank_size, vector<int> *_devices,
00190                 int poisson, int parallel);
00191 
00209 void generate_random_images(double* object, double* zernikes, int* diffraction_mask,
00210                 int n_zernikes, int image_size, int phase_size, double range, int *phase_mask,
00211                 char *object_filename, int n_images, vector<int> *_devices, int poisson, int parallel);
00212 
00220 double rect_to_theta (double x, double y);
00221 
00230 void gen_radial_values(double* array, double radius, int size_x);
00231 
00238 void gen_angular_values(double* array, int size_x);
00239 
00245 double factorial_to(int n);
00246 
00254 double zernike_radial(double r, int n, int m);
00255 
00264 double zernike_angular(double theta, int n, int m, int evenOdd);
00265 
00275 void gen_zernike_values(double *zernikes, double* rarray, double* tarray, int size_x, int nz);
00276 
00287 void translate_noll_index(int j, int *n, int *m);
00288 
00297 void min_max_array(double *array, double *min, double *max, int size);
00298 
00306 void norm_zernikes(double *zernikes, int size, int nz);
00307 
00317 void gen_circ_mask(int * mask, double radius, double x, double y, int size);
00318 
00329 void gen_freq_mask(int* mask, double freq_cut, int size_x, int size_y);
00330 
00331 long read_fits_file(char* filename, double* image, int sx, int sy);
00332 long read_fits_file(char* filename, double* image, int size);
00333 long read_fits_file(char* filename, fitsfile *fptr, double* image, int sx, int sy, long firstByte);
00334 long read_fits_file(char* filename, fitsfile *fptr, double* image, int size, long firstByte);
00335 long read_fits_file(char* filename, fitsfile *fptr, bool closeFits, double* image, int size, long firstByte);
00336 
00345 int fitsSize(char* filename);
00346 
00350 void printerror(int status);
00351 
00352 void writeFitsFile(char* filename, WORD* array, int sx, int sy);
00353 
00354 void writeFitsFile(char* filename, double* array, int sx, int sy, int sz);
00355 
00365 void write_fits_file(char* filename, FFT_TYPE* array, int sx, int sy);
00366 
00375 void write_fits_file(char* filename, WORD* array, int sx, int sy);
00376 
00384 void sum_3dfits_file(FitsManager *fitsManager, double *sum, int img_area);
00385 
00386 void copy_image(double *image_from, double *image_to, int img_area);
00387 
00388 double calc_mean(double *image, int img_area);
00389 
00390 double calc_variance(double *image, int img_area);
00391 
00392 double calc_stddev(double *image, int img_area);
00393 
00394 int chooseNoiseFromTable(double *prob, int size);
00395 
00406 void addPoissonNoise(WORD *image, int img_size, int prob_size, double variance, double mean);
00407 
00415 void save_coefs(char *file_name, WORD *coefs, int n_coefs);
00416 
00425 void save_coefs(char *file_name, WORD *coefs, int n_coefs, int n_rows);
00426 
00427 char *ftoa(float val, char *buffer);
00428 
00435 void hamming(double *image, int img_area);
00436 
00443 void hanning(double *image, int img_area);
00444 
00455 void frac_hamming(double *window, float frac, int nx, int ny);
00456 
00464 void apply_window(double *img, double *window, int img_area);
00465 
00473 void test_gpu();
00474 
00478 void list_gpu();
00479 
00487 double rmsContrast(double* img, int width);
00488 
00489 #endif /* _KIPPE_H_ */
 All Classes Functions