11 #include "utilities_slsim.h"
13 #include "image_processing.h"
16 double mag_to_jansky_AB(
double);
17 double jansky_to_mag_AB(
double flux);
20 double mag_to_flux_AB(
double);
22 double flux_to_mag_AB(
double flux);
25 T flux_to_mag(T flux,T zeropoint){
26 if(flux <=0)
return 100;
27 return -2.5 * log10(flux) + zeropoint;
31 T 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;}
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;
193 class 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;
325 ,
int Npixels, PosType resolution, PosType* arr_val
326 ,PosType zero_point,
Band my_band);
327 template <
typename T>
329 , PosType z,PosType factor, PosType zero_point,
Band my_band);
335 inline PosType getTotalFlux()
const {
return flux;}
336 inline PosType getRadius()
const {
return source_r;}
337 inline PosType* getEll(){
return ell;};
338 inline PosType getQuad(
int i,
int j){
return quad[i][j];};
339 inline PosType getSize(){
return size;};
340 inline PosType* getCentroid(){
return centroid;};
341 inline PosType getMag(){
return flux_to_mag(flux);};
347 void calcTotalFlux();
356 std::valarray<PosType> values;
373 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);
374 SourceShapelets(PosType my_z, PosType my_mag, std::string shap_file, PosType *my_center, PosType my_ang, PosType zero_point,
Band band);
384 cos_sin[0] = s.cos_sin[0];
385 cos_sin[1] = s.cos_sin[1];
386 coeff_flux = s.coeff_flux;
391 if(
this == &s)
return *
this;
393 SourceColored::operator=(s);
398 cos_sin[0] = s.cos_sin[0];
399 cos_sin[1] = s.cos_sin[1];
400 coeff_flux = s.coeff_flux;
408 cos_sin[0] = cos(ang);
409 cos_sin[1] = sin(ang);
423 for(
int i=0 ; i < n ; ++i){
425 double theta = 2*PI*ran();
426 double ff = f*( t - t2 * ran() );
428 Point_2d x( r*cos(theta) , r*sin(theta) );
430 grains.emplace_back(ff,s,x);
434 double sub_structure_sb(
double *x){
437 for(
auto &g : grains){
446 PepperCorn(
double f,
double sig,
Point_2d &x):
447 x(x),sigma(sig),fo(f){};
449 double operator()(
double *y){
450 return fo * exp(-( (x[0]-y[0])*(x[0]-y[0]) - (x[1]-y[1])*(x[1]-y[1]) ) /sigma/sigma);
463 void Hermite(std::vector<PosType> &hg,
int N, PosType x)
const;
465 void NormalizeFlux();
466 std::valarray<PosType> coeff;
473 std::vector<SourceShapelets::PepperCorn> grains;
484 ,PosType radius_in_radians
502 ,PosType radius_in_radians
505 ):SourceColored(magnitude,radius_in_radians,position,z,SBlimit,band)
513 void printSource(){};
515 void rotate(PosType t){};
522 class SourceGaussian :
public Source{
532 Source(0,position,z,SBlimit,zero_point),source_gauss_r2(r_size*r_size)
542 PosType source_gauss_r2;
547 PosType getTotalFlux()
const {
return 2*PI*source_gauss_r2;}
557 PosType getTotalFlux()
const {std::cout <<
"No total flux in SourceBLR yet" << std::endl; exit(1);}
559 virtual inline PosType getRadius()
const {
return source_r_out;}
572 float source_opening_angle;
580 inline PosType getDlDs()
const{
return DlDs;}
592 PosType getTotalFlux()
const {std::cout <<
"No total flux in SourceBLRDisk yet" << std::endl; exit(1);}
602 PosType getTotalFlux()
const {std::cout <<
"No total flux in SourceBLRSph1 yet" << std::endl; exit(1);}
612 PosType getTotalFlux()
const {std::cout <<
"No total flux in SourceBLRSph2 yet" << std::endl; exit(1);}
633 PosType getNorm() {
return pow(10,log_phi)*norm;};
653 PosType ave_colors[4];
654 PosType color_dev[4];
656 std::string kcorr_file, colors_file;
667 LF_kernel(PosType alpha,PosType beta,PosType mstar)
668 : alpha(alpha),beta(beta),mstar(mstar){};
674 double operator () (
double mag) {
675 return 1.0/( pow(10,0.4*(alpha+1)*(mag-mstar)) + pow(10,0.4*(beta+1)*(mag-mstar)) );
686 double operator()(
double x,
double y)
689 double z[2] = {x, y};
704 template <
typename T>
709 , PosType my_zero_point
712 :SourceColored(0,sqrt(gal_map.getRangeX()*gal_map.getRangeX() + gal_map.getRangeY()*gal_map.getRangeY())/2
713 ,
Point_2d(0,0),my_z, -1.0e100,my_zero_point,band){
714 if(gal_map.getNx() != gal_map.getNy()){
715 std::cout <<
"SourcePixelled::SourcePixelled() Doesn't work on nonsquare maps" << std::endl;
716 throw std::runtime_error(
"nonsquare");
720 resolution = gal_map.getResolution();
721 Npixels = gal_map.getNx();
722 range = resolution*(Npixels-1);
723 source_x[0] = gal_map.getCenter()[0];
724 source_x[1] = gal_map.getCenter()[1];
726 values.resize(Npixels*Npixels);
728 double convertion = 1.0/resolution/resolution*factor;
729 for (
int i = 0; i < Npixels*Npixels; i++)
730 values[i] = gal_map(i)*convertion;
733 float mag = SourceColored::flux_to_mag(flux);