11#include "utilities_slsim.h" 
   13#include "image_processing.h" 
   16double mag_to_jansky_AB(
double);
 
   17double jansky_to_mag_AB(
double flux);
 
   20double mag_to_flux_AB(
double);
 
   22double flux_to_mag_AB(
double flux);
 
   25T flux_to_mag(T flux,T zeropoint){
 
   26  if(flux <=0) 
return 100;
 
   27  return -2.5 * log10(flux) + zeropoint;
 
   31T mag_to_flux(T m,T zeropoint){
 
   32  if(m == 100) 
return 0;
 
   33  return pow(10,-0.4*(m - zeropoint));
 
   67    mag_zero_point(s.mag_zero_point){ }
 
   70    if(
this == &s) 
return *
this;
 
   74    sb_limit = s.sb_limit;
 
   76    mag_zero_point = s.mag_zero_point;
 
   87  virtual PosType getTotalFlux() 
const = 0;
 
   88  virtual void printSource() = 0;
 
   91  double SBlimit_magarcsec(
double limit) {
return mag_to_flux(limit,mag_zero_point)*pow(180*60*60/PI,2);}
 
  101 void setZ(PosType my_z){
zsource = my_z;}
 
  121  void setMagZeroPoint(
float zeropoint){mag_zero_point=zeropoint;}
 
  122  double getMagZeroPoint(){
return mag_zero_point;}
 
  124 PosType 
changeFilter(std::string filter_in, std::string filter_out, std::string sed);
 
  125 PosType 
integrateFilter(std::vector<PosType> wavel_fil, std::vector<PosType> fil);
 
  126 PosType 
integrateFilterSED(std::vector<PosType> wavel_fil, std::vector<PosType> fil, std::vector<PosType> wavel_sed, std::vector<PosType> sed);
 
  136    double total_flux = 0;
 
  138    for(
size_t i=0 ; i<N ; ++i){
 
  139      for(
size_t j=0 ; j<N ; ++j){
 
  146    total_flux *= res*res;
 
  148    std::cout << 
"------- check flux ----------" << std::endl;
 
  149    std::cout << 
" total flux in pixels : " << total_flux << std::endl;
 
  150    std::cout << 
" getTotalFlux() : " << getTotalFlux() << std::endl;
 
  151    std::cout << 
" fractional difference : " << (total_flux - getTotalFlux()) / getTotalFlux() << std::endl;
 
  152    std::cout << 
" magnitude from flux in pixels : " << flux_to_mag(total_flux) << std::endl;
 
  153    std::cout << 
" mag from getTotalFlux() : " <<  flux_to_mag(getTotalFlux()) << std::endl;
 
  154    std::cout << 
"-----------------------------" << std::endl;
 
  156    if(abs( (total_flux - getTotalFlux()) / getTotalFlux() ) > 0.1 ){
 
 
  163  long getID()
 const {
return id;}
 
  164  void setID(
long i){
id=i;}
 
  167  virtual void assignParams(InputParams& params){};
 
  179  double flux_to_mag(
double flux)
 const {
 
  180    if(flux <=0) 
return 100;
 
  181    return -2.5 * log10(flux) + mag_zero_point;
 
  190  double mag_zero_point;
 
 
  193class SourceColored : 
public Source{
 
  195  SourceColored(PosType magnitude,PosType r,Point_2d x,PosType z
 
  196                ,PosType SBlimit,
Band band)
 
  197  :
Source(r,x,z,SBlimit,zeropoints.at(band))
 
  199    if(zeropoints.find(band) == zeropoints.end()){
 
  200      std::cerr << 
"SourceColored band " << to_string(band) << 
" zeropoint needs to be set." << std::endl;
 
  201      throw std::runtime_error(
"unset zeropoint");
 
  206    mag_map[current_band]=magnitude;
 
  208    flux_total = mag_to_flux(mag,zeropoints.at(band));
 
  212  SourceColored(PosType magnitude,PosType r,Point_2d x,PosType z
 
  213                ,PosType SBlimit,
double zero_point,
Band band)
 
  214  :
Source(r,x,z,SBlimit,zero_point)
 
  216    zeropoints[band] = zero_point;
 
  219    mag_map[current_band]=magnitude;
 
  221    flux_total = mag_to_flux(mag,zero_point);
 
  225  SourceColored(
const SourceColored &s):
Source(s){
 
  228    current_band = s.current_band;
 
  229    sed_type = s.sed_type;
 
  230    flux_total = s.flux_total;
 
  233  SourceColored & operator= (
const SourceColored &s){
 
  234    if(
this == &s) 
return *
this;
 
  236    Source::operator=(s);
 
  239    current_band = s.current_band;
 
  240    sed_type = s.sed_type;
 
  241    flux_total = s.flux_total;
 
  247  SourceColored & copy_color(
const SourceColored &s){
 
  248    if(
this == &s) 
return *
this;
 
  250    Source::operator=(s);
 
  253    current_band = s.current_band;
 
  254    sed_type = s.sed_type;
 
  255    flux_total = s.flux_total;
 
  260  virtual ~SourceColored(){};
 
  262  PosType getMag()
 const { assert(current_band != Band::NoBand); 
return mag;}
 
  263  PosType getMag(
Band band)
 const {
return (mag_map.size() > 0) ? mag_map.at(band) : mag;}
 
  264  Band getBand()
 const{
return current_band;}
 
  265  float getSEDtype()
 const {
return sed_type;}
 
  266  double getMagZeroPoint(
Band band)
 const {
return zeropoints.at(band);}
 
  268  void setSEDtype(
float sed) {sed_type = sed;}
 
  269  static void setMagZeroPoint(
Band band,
double zeropoint){zeropoints[band]=zeropoint;}
 
  270  static void setMagZeroPoints(std::map<Band,PosType> &zero_points){
 
  271    for(
auto &p : zero_points){
 
  272      zeropoints[p.first] = p.second;
 
  276  void setActiveBand(
Band band);
 
  278  inline PosType getTotalFlux()
 const {
return flux_total;}
 
  279  void setMag(
float magnitude,
Band band,
double zeropoint){
 
  280    mag_map[band]=magnitude;
 
  281    zeropoints[band]=zeropoint;
 
  282    if(band==current_band) flux_total = mag_to_flux(mag,zeropoint);
 
  286  void setMag(
float magnitude,
Band band){
 
  287    mag_map[band]=magnitude;
 
  288    if(band==current_band) flux_total = mag_to_flux(mag,zeropoints.at(band));
 
  292  virtual void rotate(PosType theta) = 0;
 
  295  void shiftmag(
float delta_mag){
 
  297    flux_total = mag_to_flux(mag,zeropoints[current_band]);
 
  298    for(
auto &b : mag_map){
 
  299      b.second += delta_mag;
 
  305  static std::map<Band,PosType> zeropoints;
 
  312  std::map<Band,PosType> mag_map;
 
  324 SourcePixelled(PosType my_z, PosType* center, 
int Npixels, PosType resolution, PosType* arr_val,PosType zero_point);
 
  325  template <
typename T>
 
  332 inline PosType getTotalFlux()
 const {
return flux;}
 
  333 inline PosType getRadius()
 const {
return source_r;}
 
  334 inline PosType* getEll(){
return ell;};
 
  335 inline PosType getQuad(
int i, 
int j){
return quad[i][j];};
 
  336 inline PosType getSize(){
return size;};
 
  337 inline PosType* getCentroid(){
return centroid;};
 
  338 inline PosType getMag(){
return flux_to_mag(flux);};
 
  344 void calcTotalFlux();
 
  353 std::valarray<PosType> values;
 
 
  368  friend SourceMultiShapelets;
 
  370 SourceShapelets(PosType my_z, PosType my_mag, PosType my_scale, std::valarray<PosType> my_coeff, PosType* my_center, PosType my_ang,PosType zero_point,
Band band);
 
  371 SourceShapelets(PosType my_z, PosType my_mag, std::string shap_file, PosType *my_center, PosType my_ang, PosType zero_point,
Band band);
 
  381    cos_sin[0] = s.cos_sin[0];
 
  382    cos_sin[1] = s.cos_sin[1];
 
  383    coeff_flux = s.coeff_flux;
 
  388    if(
this == &s) 
return *
this;
 
  390    SourceColored::operator=(s);
 
  395    cos_sin[0] = s.cos_sin[0];
 
  396    cos_sin[1] = s.cos_sin[1];
 
  397    coeff_flux = s.coeff_flux;
 
  405    cos_sin[0] = cos(ang);
 
  406    cos_sin[1] = sin(ang);
 
 
  420    for(
int i=0 ; i < n ; ++i){
 
  422      double theta = 2*PI*ran();
 
  423      double ff = f*( t - t2 * ran() );
 
  425      Point_2d x( r*cos(theta) , r*sin(theta) );
 
  427      grains.emplace_back(ff,s,x);
 
  431  double sub_structure_sb(
double *x){
 
  434    for(
auto &g : grains){
 
  443    PepperCorn(
double f,
double sig,Point_2d &x):
 
  444    x(x),sigma(sig),fo(f){};
 
  446    double operator()(
double *y){
 
  447      return fo * exp(-( (x[0]-y[0])*(x[0]-y[0]) - (x[1]-y[1])*(x[1]-y[1]) ) /sigma/sigma);
 
  459 void assignParams(InputParams& params);
 
  460  void Hermite(std::vector<PosType> &hg,
int N, PosType x) 
const;
 
  462 void NormalizeFlux();
 
  463 std::valarray<PosType> coeff;
 
  470  std::vector<SourceShapelets::PepperCorn> grains;
 
 
  481                ,PosType radius_in_radians  
 
 
  499              ,PosType radius_in_radians  
 
  502):SourceColored(magnitude,radius_in_radians,position,z,SBlimit,band)
 
 
  510  void printSource(){};
 
  511  void assignParams(InputParams& params){}; 
 
  512  void rotate(PosType t){};                 
 
 
  519class SourceGaussian : 
public Source{
 
  529  Source(0,position,z,SBlimit,zero_point),source_gauss_r2(r_size*r_size)
 
  539 PosType source_gauss_r2;
 
  541 PosType SurfaceBrightness(
const PosType *y) 
const;
 
  542 void assignParams(InputParams& params);
 
  544 PosType getTotalFlux()
 const {
return 2*PI*source_gauss_r2;}
 
  554 PosType getTotalFlux()
 const {std::cout << 
"No total flux in SourceBLR yet" << std::endl; exit(1);}
 
  556 virtual inline PosType getRadius()
 const {
return source_r_out;}
 
  569 float source_opening_angle;
 
  577  inline PosType getDlDs()
 const{
return DlDs;}
 
 
  589 PosType getTotalFlux()
 const {std::cout << 
"No total flux in SourceBLRDisk yet" << std::endl; exit(1);}
 
 
  599 PosType getTotalFlux()
 const {std::cout << 
"No total flux in SourceBLRSph1 yet" << std::endl; exit(1);}
 
 
  609 PosType getTotalFlux()
 const {std::cout << 
"No total flux in SourceBLRSph2 yet" << std::endl; exit(1);}
 
 
  630    PosType getNorm() {
return pow(10,log_phi)*norm;}; 
 
  650    PosType ave_colors[4];
 
  651    PosType color_dev[4];
 
  653    std::string kcorr_file, colors_file;
 
  664        LF_kernel(PosType alpha,PosType beta,PosType mstar)
 
  665        : alpha(alpha),beta(beta),mstar(mstar){};
 
  671        double operator () (
double mag) { 
 
  672            return 1.0/( pow(10,0.4*(alpha+1)*(mag-mstar)) + pow(10,0.4*(beta+1)*(mag-mstar)) );
 
 
  681 SourceFunctor(
Source& source) : source(source) {}
 
  683 double operator()(
double x, 
double y)
 
  686  double z[2] = {x, y};
 
  687  return source.SurfaceBrightness(z);
 
 
  707  if(gal_map.getNx() != gal_map.getNy()){
 
  708    std::cout << 
"SourcePixelled::SourcePixelled() Doesn't work on nonsquare maps" << std::endl;
 
  709    throw std::runtime_error(
"nonsquare");
 
  713  resolution = gal_map.getResolution();
 
  714  Npixels = gal_map.getNx();
 
  715  range = resolution*(Npixels-1);
 
  716  source_x[0] = gal_map.getCenter()[0];
 
  717  source_x[1] = gal_map.getCenter()[1];
 
  719  values.resize(Npixels*Npixels);
 
  721  double convertion = 1.0/resolution/resolution*factor;
 
  722  for (
int i = 0; i < Npixels*Npixels; i++)
 
  723    values[i] = gal_map(i)*convertion;
 
 
Image structure that can be manipulated and exported to/from fits files.
Definition pixelmap.h:42
 
pointer to surface brightness function
Definition source.h:625
 
PosType getFluxRatio(Band band)
Returns flux ratio (F_band/F_i) for a quasar at the redshift equal to QuasarLF::red.
Definition quasarLF.cpp:200
 
PosType getColor(Band band)
Returns mean color (band - i) for a quasar at the redshift equal to QuasarLF::red.
Definition quasarLF.cpp:183
 
PosType getRandomMag(Utilities::RandomNumbers_NR &rand)
returns random apparent magnitude according to the luminosity function in I band
Definition quasarLF.cpp:138
 
PosType getRandomFlux(Band band, Utilities::RandomNumbers_NR &rand)
returns random flux according to the luminosity function must be divided by an angular area in rad^2 ...
Definition quasarLF.cpp:175
 
A source representing a BLR with a Keplarian disk.
Definition source.h:586
 
PosType SurfaceBrightness(const PosType *y) const
Definition source.cpp:215
 
Base class for all sources representing the Broad Line Region (BLR) of a AGN/QSO.
Definition source.h:548
 
PosType source_nu
frequency
Definition source.h:561
 
float source_inclination
inclination of BLR in radians, face on is
Definition source.h:568
 
float source_fK
fraction of Keplerian velocity in random motions
Definition source.h:573
 
PosType source_tau
lag time
Definition source.h:559
 
bool source_monocrome
set to true to integrate over frequency
Definition source.h:575
 
float source_r_out
outer radius of BLR
Definition source.h:566
 
float source_r_in
inner radius of BLR
Definition source.h:564
 
A source representing a BLR with a spherical symmetry and circular orbits.
Definition source.h:596
 
PosType SurfaceBrightness(const PosType *y) const
Definition source.cpp:220
 
A source representing a BLR with a spherical symmetry and random velocity dispersion.
Definition source.h:606
 
PosType SurfaceBrightness(const PosType *y) const
Definition source.cpp:223
 
Base class for all sources.
Definition source.h:44
 
PosType integrateFilter(std::vector< PosType > wavel_fil, std::vector< PosType > fil)
Calculates the integral of the filter curve given as an array of (x,y) values.
Definition source.cpp:425
 
PosType source_r
charactoristic source size
Definition source.h:171
 
void setTheta(PosType *xx)
Reset the position of the source in radians.
Definition source.h:114
 
PosType changeFilter(std::string filter_in, std::string filter_out, std::string sed)
Calculates the difference in magnitude when changing the observing filter.
Definition source.cpp:342
 
PosType getRadius() const
Radius of source in radians.
Definition source.h:103
 
virtual PosType SurfaceBrightness(const PosType *y) const =0
 
void getTheta(Point_2d &x) const
position of source in radians
Definition source.h:111
 
Point_2d source_x
center of source
Definition source.h:173
 
PosType getZ() const
Redshift of source.
Definition source.h:100
 
void setRadius(PosType my_radius)
Reset the radius of the source in radians.
Definition source.h:105
 
PosType getSBlimit_magarcsec()
Gets sb_limit in mag/arcsec^2.
Definition source.h:96
 
void getTheta(PosType *x) const
position of source in radians
Definition source.h:109
 
PosType zsource
redshift of source
Definition source.h:176
 
double TEST_surface_brightness(double res, int N)
test if flux in pixels matches total flux
Definition source.h:131
 
void setSBlimit(float limit)
Sets sb_limit in erg/cm^2/sec/rad^2/Hz.
Definition source.h:119
 
double SBlimit_magarcsec(double limit)
convert mag/arcsec^2 to flux units
Definition source.h:91
 
PosType integrateFilterSED(std::vector< PosType > wavel_fil, std::vector< PosType > fil, std::vector< PosType > wavel_sed, std::vector< PosType > sed)
Calculates the integral of the sed multiplied by the filter curve.
Definition source.cpp:437
 
Point_2d getTheta() const
position of source in radians
Definition source.h:107
 
Source(PosType r, Point_2d x, PosType z, PosType SBlimit, PosType zero_point)
shell constructor
Definition source.h:48
 
PosType getSBlimit()
Gets sb_limit in erg/cm^2/sec/rad^2/Hz.
Definition source.h:94
 
Class for reading in and handling an array of SourceShapelets, made on the model of SourceMultiAnaGal...
Definition sourceAnaGalaxy.h:184
 
SourcePixelled(PosType my_z, PosType *center, int Npixels, PosType resolution, PosType *arr_val, PosType zero_point)
Definition source.cpp:233
 
PosType SurfaceBrightness(const PosType *y) const
Definition source.cpp:318
 
A uniform surface brightness circular source.
Definition source.h:493
 
virtual PosType SurfaceBrightness(const PosType *y) const
Definition source.h:509
 
SourcePoint(Point_2d position, PosType z, PosType magnitude, PosType radius_in_radians, double SBlimit, Band band)
Definition source.h:495
 
PosType getRadius() const
maximum size
Definition source.h:412
 
PosType SurfaceBrightness(const PosType *y) const
Definition source.cpp:642
 
void rotate(PosType ang)
rotate source
Definition source.h:403
 
SourceShapelets(PosType my_z, PosType my_mag, PosType my_scale, std::valarray< PosType > my_coeff, PosType *my_center, PosType my_ang, PosType zero_point, Band band)
Definition source.cpp:497
 
This is a class for generating random numbers. It simplifies and fool proofs initialization and allow...
Definition utilities_slsim.h:1059
 
Class for representing points or vectors in 2 dimensions. Not that the dereferencing operator is over...
Definition point.h:48