Program Listing for File PSF.h

Return to documentation for file (include/PSF.h)

#ifndef ECHELLESIMULATOR_PSF_H
#define ECHELLESIMULATOR_PSF_H

#include <string>
#include <map>
#include <vector>

class Matrix {
public:
    Matrix(size_t rows, size_t cols) {
        this->cols = cols;
        this->rows = rows;
        data = std::vector<std::vector<float>>(rows, std::vector<float>(cols, 0.));
    }
    Matrix(const Matrix& m){
        this->cols = m.cols;
        this->rows = m.rows;
        this->data = m.data;
    }

    Matrix(std::vector<std::vector<float>> mat) {
        cols = mat[0].size();
        rows = mat.size();
        data = mat;
    }

    Matrix() {

    }

    ~Matrix() = default;

    std::vector<std::vector<float>> data;
    size_t cols{};
    size_t rows{};

    float sum() {
        float total = 0;
        for (int i = 0; i < data.size(); ++i) {
            for (int j = 0; j < data[i].size(); ++j) {
                total += data[i][j];
            }
        }
        return total;
    }

    void delete_n_rows_symmetrically(int n) {
        rows -= n;
        data.erase(data.begin(), data.begin() + n);
        data.erase(data.end() - n, data.end());
    }

    void delete_n_cols_symmetrically(int n) {
        cols -= n;
        for (unsigned i = 0; i < rows; ++i) {
            data[i].erase(data[i].begin(), data[i].begin() + n - 1);
            data[i].erase(data[i].end() - n + 1, data[i].end());
        }
    }

    Matrix &operator=(const Matrix &M) {
        this->cols = M.cols;
        this->rows = M.rows;
        this->data = M.data;
        return *this;
    }

};

struct PSFdata {
    double wavelength;
    Matrix * psf;

    PSFdata(double w, const Matrix& p) : wavelength(w) {
        psf = new Matrix(p);
    };

    bool operator<(const PSFdata &str) const {
        return (wavelength < str.wavelength);
    }
};

class PSF {
public:
    PSF();

    virtual ~PSF();

    virtual Matrix get_PSF(int order, double wavelength) = 0;

    virtual Matrix get_PSF_nocut(int order, double wavelength) = 0;

    double pixelsampling{};
};

class PSF_ZEMAX : public PSF {
public:
    PSF_ZEMAX(const std::string& filename, int fiber_number);

    Matrix get_PSF(int order, double wavelength) override;

    Matrix get_PSF_nocut(int order, double wavelength) override;

private:
    Matrix interpolate_PSF(Matrix * psf1, Matrix * psf2, double w1, double w2, double w);

    Matrix interpolate_PSF_nocut(Matrix * psf1, Matrix * psf2, double w1, double w2, double w);

    std::map<int, std::vector<PSFdata> > psfs;

};

class PSF_gaussian : public PSF {
public:
    PSF_gaussian(double sigma, double aperture = 3.);

    Matrix get_PSF(int order, double wavelength);

private:
    // sigma of gaussian in px
    double sigma;
    int ksize;

};

#endif //ECHELLESIMULATOR_PSF_H