Skip to content

Commit

Permalink
changed normalisation in lambertion method
Browse files Browse the repository at this point in the history
  • Loading branch information
tomlouden committed Oct 17, 2017
1 parent 73cf646 commit 7d328dc
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 55 deletions.
24 changes: 18 additions & 6 deletions c_src/_web.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,13 @@ static PyObject *web_generate_planet(PyObject *self, PyObject *args)
double yppval;

// star_bright = bb_flux(l1,l2,star_T,n_bb_seg);
ypp = spline_cubic_set( n_star, stellar_teffs, stellar_fluxes, 0, 0, 0, 0 );

star_surface_bright = spline_cubic_val( n_star, stellar_teffs, stellar_fluxes, ypp, star_T, &ypval, &yppval);
free(ypp);

star_bright = star_surface_bright*M_PI*pow(r2,2);
if (star_T != 0){
ypp = spline_cubic_set( n_star, stellar_teffs, stellar_fluxes, 0, 0, 0, 0 );
star_surface_bright = spline_cubic_val( n_star, stellar_teffs, stellar_fluxes, ypp, star_T, &ypval, &yppval);
free(ypp);
star_bright = star_surface_bright*M_PI*pow(r2,2);
}
}


Expand Down Expand Up @@ -853,6 +854,17 @@ static PyObject *web_call_map_model(PyObject *self, PyObject *args)
double phi0 = 0;

double star_bright = 1.0;
double star_surface_bright = 1.0;

if(bright_type == 9){
double r2 = brightness_params[5];
star_surface_bright = star_bright/(M_PI*pow(r2,2));
}
if(bright_type == 10){
double r2 = brightness_params[8];
star_surface_bright = star_bright/(M_PI*pow(r2,2));
}


//NEED TO UPDATE THIS WITH CORRECT STAR BRIGHTNESS VALUES OR REFLECTION MODELS WON'T BE CORRECT!//

Expand Down Expand Up @@ -892,7 +904,7 @@ static PyObject *web_call_map_model(PyObject *self, PyObject *args)
bcugrid(lo_2d, la_2d, T_2d, y1_grid, y2_grid, y12_grid, (int) brightness_params[0],(int) brightness_params[1]);
}

double *vals = call_map_model(la,lo,lambda0,phi0,bright_type,brightness_params,bb_g,0,0.0,0.0,0.0,0.0,star_bright,0.0,0.0,lo_2d,la_2d,T_2d,y1_grid,y2_grid,y12_grid);
double *vals = call_map_model(la,lo,lambda0,phi0,bright_type,brightness_params,bb_g,0,0.0,0.0,0.0,0.0,star_surface_bright,0.0,0.0,lo_2d,la_2d,T_2d,y1_grid,y2_grid,y12_grid);

/* Build the output tuple */

Expand Down
3 changes: 2 additions & 1 deletion c_src/brightness_maps.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ double lambertian(double lat, double lon, double insol, double albedo){
// printf("%f %f \n",insol,albedo);

if((-M_PI/2.0 <= lon) && (lon <= M_PI/2.0)){
b = albedo*insol*cos(lat)*cos(lon)/2;
// b = albedo*insol*cos(lat)*cos(lon)/2;
b = albedo*insol*cos(lat)*cos(lon)*3.0/2.0;
// b = albedo*insol/M_PI;
}
else{
Expand Down
6 changes: 3 additions & 3 deletions c_src/generate.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,10 @@ double *call_map_model(double la,double lo,double lambda0, double phi0,int brigh
point_b = Hotspot_b(la, lo, la0,lo0,b1,b2,size,make_grid ,theta1,theta2,r1,r2,lambda0,phi0,la_cen,lo_cen);
}
else if(brightness_model == 9){
double albedo = brightness_params[0];
double ars = pow(brightness_params[1],2);
double albedo = brightness_params[3];
double ars = pow(brightness_params[4],2);
double insol = ars*star_bright;
// printf("%f \n",insol*M_PI);
point_b = lambertian(la,lo,insol,albedo);
}
else if(brightness_model == 10){
Expand All @@ -183,7 +184,6 @@ double *call_map_model(double la,double lo,double lambda0, double phi0,int brigh
double albedo = brightness_params[6];
double ars = pow(brightness_params[7],2);
double insol = ars*star_bright;
// printf("%f %f %f\n",ars, star_bright,insol);
point_b = point_b + lambertian(la,lo,insol,albedo);
}

Expand Down
1 change: 1 addition & 0 deletions c_src/web.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ double *lightcurve(int n_layers, int n_points, double *t, double tc, double per,
// output[n] = p_bright/star_bright;

free(coords);

}

int n_segments = pow(n_layers,2);
Expand Down
74 changes: 42 additions & 32 deletions spiderman/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,21 @@
import spiderman.plot as splt
import matplotlib.pyplot as plt

class ModelParams(object):
class MultiModelParams(object):
def __init__(self,brightness_models=['zhang','lambertian'],**kwargs):
self.webs = []
for i in range(0,len(brightness_models)):
self.webs += [sp.ModelParams(brightness_models[i],**kwargs)]

def lightcurve(self,*args,**kwargs):
total = sp.lightcurve(*args,self.webs[0],**kwargs)
for i in range(1,len(self.webs)):
total += sp.lightcurve(*args,self.webs[i],**kwargs) - 1.0

return total


class ModelParams(object):
def __init__(self,brightness_model='zhang',thermal=False, nearest=None):

self.n_layers = 5 # The default resolution for the grid
Expand Down Expand Up @@ -226,17 +239,25 @@ def format_bright_params(self):
elif (self.brightness_type == 9):
brightness_param_names = ['albedo']
ars = 1.0/self.a
r2 = 1.0/self.rp

if not hasattr(self, 'T_s'):
self.T_s = 0
self.l1 = 0
self.l2 = 0

try:
brightness_params = [self.albedo,ars]
brightness_params = [self.T_s,self.l1,self.l2,self.albedo,ars,r2]
except:
print('Brightness parameters incorrectly assigned')
print('should be',brightness_param_names)
quit()
elif (self.brightness_type == 10):
brightness_param_names = ['T_s','l1','l2','xi','T_n','delta_T','albedo']
ars = 1.0/self.a
r2 = 1.0/self.rp
try:
brightness_params = [self.T_s,self.l1,self.l2,self.xi,self.T_n,self.delta_T,self.albedo,ars]
brightness_params = [self.T_s,self.l1,self.l2,self.xi,self.T_n,self.delta_T,self.albedo,ars,r2]
except:
print('Brightness parameters incorrectly assigned')
print('should be',brightness_param_names)
Expand Down Expand Up @@ -297,6 +318,24 @@ def format_bright_params(self):
quit()
return brightness_params

def plot_square(self,*args,**kwargs):
return splt.plot_square(self,*args,**kwargs)

def plot_system(self,*args,**kwargs):
return splt.plot_system(self,*args,**kwargs)

def plot_planet(self,*args,**kwargs):
return splt.plot_planet(self,*args,**kwargs)

def plot_quad(self,*args,**kwargs):
return splt.plot_quad(self,*args,**kwargs)

def plot_uncertainty(self,*args,**kwargs):
return splt.plot_uncertainty(self,*args,**kwargs)

def lightcurve(self,*args,**kwargs):
return sp.lightcurve(*args,self,**kwargs)

def calc_phase(self,t):
self.phase = _web.calc_phase(t,self.t0,self.per)

Expand All @@ -307,19 +346,6 @@ def calc_substellar(self,t):
self.lambda0 = substellar[0]
self.phi0 = substellar[1]

def plot_square(self,ax=False,min_temp=False,max_temp=False,temp_map=False,min_bright=0.2,show_cax=True,scale_planet=1.0,planet_cen=[0.0,0.0],mycmap=plt.get_cmap('inferno'),theme='white',show_axes=True,nla=100,nlo=100):
return splt.plot_square(self,ax=ax,min_temp=min_temp,max_temp=max_temp,temp_map=temp_map,min_bright=min_bright,scale_planet=scale_planet,planet_cen=planet_cen,mycmap=mycmap,show_cax=show_cax,theme=theme,show_axes=show_axes,nla=nla,nlo=nlo)

def plot_system(self,t,ax=False,min_temp=False,max_temp=False,temp_map=False,min_bright=0.2,use_phase=False,show_cax=True,mycmap=plt.cm.inferno,theme='white',show_axes=True):
if use_phase == True:
t = self.t0 + self.per*t
return splt.plot_system(self,t,ax=ax,min_temp=min_temp,max_temp=max_temp,temp_map=temp_map,min_bright=min_bright,show_cax=show_cax,mycmap=mycmap,theme=theme,show_axes=show_axes)

def plot_planet(self,t,ax=False,min_temp=False,max_temp=False,temp_map=False,min_bright=0.2,scale_planet=1.0,planet_cen=[0.0,0.0],use_phase=False,show_cax=True,mycmap=plt.cm.inferno,theme='white',show_axes=False):
if use_phase == True:
t = self.t0 + self.per*t
return splt.plot_planet(self,t,ax=ax,min_temp=min_temp,max_temp=max_temp,temp_map=temp_map,min_bright=min_bright,scale_planet=scale_planet,planet_cen=planet_cen,show_cax=show_cax,mycmap=mycmap,theme=theme,show_axes=show_axes)

def get_lims(self,t,temp_map=False,use_phase=False):
if use_phase == True:
if self.t0 == None:
Expand All @@ -338,20 +364,6 @@ def get_lims(self,t,temp_map=False,use_phase=False):

return [np.min(temps),np.max(temps)]


def plot_quad(self,min_temp=False,max_temp=False,temp_map=False,min_bright=0.2,scale_planet=1.0,planet_cen=[0.0,0.0],use_phase=False,show_cax=True,mycmap=plt.cm.inferno,theme='white'):

return splt.plot_quad(self,min_temp=min_temp,max_temp=max_temp,temp_map=temp_map,min_bright=min_bright,scale_planet=scale_planet,planet_cen=planet_cen,use_phase=use_phase,show_cax=show_cax,mycmap=mycmap,theme=theme)

def plot_uncertainty(self,fs,min_temp=False,max_temp=False,temp_map=True,min_bright=0.2,scale_planet=1.0,planet_cen=[0.0,0.0],use_phase=False,show_cax=True,mycmap=plt.cm.viridis_r,theme='white'):

return splt.plot_uncertainty(self,fs,min_temp=min_temp,max_temp=max_temp,temp_map=temp_map,min_bright=min_bright,scale_planet=scale_planet,planet_cen=planet_cen,use_phase=use_phase,show_cax=show_cax,mycmap=mycmap,theme=theme)

def lightcurve(self,t,stellar_grid=False,logg=4.5,use_phase=False):

return sp.lightcurve(t,self,stellar_grid,logg,use_phase)


def eclipse_depth(self,phase=0.5,stellar_grid=False):

brightness_params = self.format_bright_params()
Expand Down Expand Up @@ -407,8 +419,6 @@ def eclipse_depth(self,phase=0.5,stellar_grid=False):
return np.array(out)

def total_luminosity(self,planet_radius,stellar_grid=False,reflection=False):
# CHANGE THIS - shouldn't really use the output of get_planet because of limb darkening

p1,p2 = self.phase_brightness([0,0.5],stellar_grid=stellar_grid,reflection=reflection,planet_radius=planet_radius)
return(p1+p2)

Expand Down
9 changes: 7 additions & 2 deletions spiderman/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def get_star_png():
image = read_png(png_name)
return image

def plot_system(spider_params,t,ax=False,min_temp=False,max_temp=False,temp_map=False,min_bright=0.2,mycmap=plt.get_cmap('inferno'),show_cax=True,theme='black',show_axes=False):
def plot_system(spider_params,t,ax=False,min_temp=False,max_temp=False,temp_map=False,min_bright=0.2,use_phase=False,show_cax=True,mycmap=plt.cm.inferno,theme='white',show_axes=True):

if theme == 'black':
bg = 'black'
Expand All @@ -29,6 +29,8 @@ def plot_system(spider_params,t,ax=False,min_temp=False,max_temp=False,temp_map=
bg = 'white'
tc = 'black'

if use_phase == True:
t = spider_params.t0 + spider_params.per*t

if ax == False:
f, ax = plt.subplots(facecolor=bg)
Expand Down Expand Up @@ -521,7 +523,7 @@ def plot_square(spider_params,ax=False,min_temp=False,max_temp=False,temp_map=Fa

return ax

def plot_planet(spider_params,t,ax=False,min_temp=False,max_temp=False,temp_map=False,min_bright=0.2,scale_planet=1.0,planet_cen=[0.0,0.0],mycmap=plt.get_cmap('inferno'),show_cax=True,theme='black',show_axes=False):
def plot_planet(spider_params,t,ax=False,min_temp=False,max_temp=False,temp_map=False,min_bright=0.2,scale_planet=1.0,planet_cen=[0.0,0.0],use_phase=False,show_cax=True,mycmap=plt.cm.inferno,theme='white',show_axes=False):

if theme == 'black':
bg = 'black'
Expand All @@ -530,6 +532,9 @@ def plot_planet(spider_params,t,ax=False,min_temp=False,max_temp=False,temp_map=
bg = 'white'
tc = 'black'

if use_phase == True:
t = spider_params.t0 + spider_params.per*t

if ax == False:
f, ax = plt.subplots(facecolor=bg)
new_ax = True
Expand Down
26 changes: 15 additions & 11 deletions spiderman/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,28 @@ def generate_planet(spider_params,t,use_phase=False,stellar_grid=False,logg=4.5)
t = spider_params.t0 + spider_params.per*t
brightness_params = spider_params.format_bright_params()

# if spider_params.thermal == True:
if ((spider_params.brightness_type == 9) or (spider_params.brightness_type == 10)):
if stellar_grid == False:
star_grid = sp.stellar_grid.gen_grid(spider_params.l1,spider_params.l2,logg=logg,response=spider_params.filter)
teffs = star_grid[0]
totals = star_grid[1]

if spider_params.thermal == True:
if ((spider_params.brightness_type == 9) or (spider_params.brightness_type == 10)):
if stellar_grid == False:
star_grid = sp.stellar_grid.gen_grid(spider_params.l1,spider_params.l2,logg=logg,response=spider_params.filter)
teffs = star_grid[0]
totals = star_grid[1]
else:
teffs = stellar_grid[0]
totals = stellar_grid[1]
else:
teffs = stellar_grid[0]
totals = stellar_grid[1]
teffs = []
totals = []
else:
teffs = []
totals = []

# teffs = []
# totals = []
n_star = len(totals)

spider_params.calc_substellar(t)
return np.array(_web.generate_planet(spider_params.n_layers,spider_params.lambda0,spider_params.phi0,spider_params.p_u1,spider_params.p_u2,spider_params.brightness_type,brightness_params,teffs,totals,len(totals),spider_params.rp,spider_params.grid[0].copy(),spider_params.grid[1].copy(),spider_params.grid[2].copy()))

return np.array(_web.generate_planet(spider_params.n_layers,spider_params.lambda0,spider_params.phi0,spider_params.p_u1,spider_params.p_u2,spider_params.brightness_type,brightness_params,teffs,totals,n_star,spider_params.rp,spider_params.grid[0].copy(),spider_params.grid[1].copy(),spider_params.grid[2].copy()))

def call_map_model(spider_params,la,lo):
# DEPRECATED - NOT CURRENTLY USED BY HIGHER LEVEL FUNCTIONS, NEEDS UPDATING
Expand Down

0 comments on commit 7d328dc

Please sign in to comment.