11# -*- coding: utf-8 -*-
22"""
33Created on Wed May 6 17:07:00 2015
4-
5- @author: jmilli
64"""
75import numpy as np
86
9- class Dust_distribution :
7+ _author__ = 'Julien Milli'
8+
9+
10+ class Dust_distribution (object ):
1011 """This class represents the dust distribution
1112 """
12-
13- def __init__ ( self , density_dico = { 'name' : '2PowerLaws' , 'ain' : 5 , 'aout' : - 5 ,\
14- 'a' : 60 , 'e' : 0 , 'ksi0' : 1. , 'gamma' : 2. , 'beta' :1. }):
13+ def __init__ ( self , density_dico = { 'name' : '2PowerLaws' , 'ain' : 5 , 'aout' : - 5 ,
14+ 'a' : 60 , 'e' : 0 , 'ksi0' : 1. , 'gamma' : 2. ,
15+ 'beta' :1. }):
1516 """
1617 Constructor for the Dust_distribution class.
1718
@@ -20,55 +21,63 @@ def __init__(self,density_dico={'name':'2PowerLaws','ain':5,'aout':-5,\
2021 the midplane, and vertically whenever it drops below 0.5% of the
2122 peak density in the midplane
2223 """
23- self .accuracy = 5.e-3
24- if not isinstance (density_dico ,dict ):
25- raise TypeError ('The parameters describing the dust density distribution must be a Python dictionnary' )
24+ self .accuracy = 5.e-3
25+ if not isinstance (density_dico , dict ):
26+ errmsg = 'The parameters describing the dust density distribution' \
27+ ' must be a Python dictionnary'
28+ raise TypeError (errmsg )
2629 if 'name' not in density_dico .keys ():
27- raise TypeError ('The dictionnary describing the dust density distribution must contain the key "name"' )
30+ errmsg = 'The dictionnary describing the dust density ' \
31+ 'distribution must contain the key "name"'
32+ raise TypeError (errmsg )
2833 self .type = density_dico ['name' ]
2934 if self .type == '2PowerLaws' :
30- self .dust_distribution_calc = DustEllipticalDistribution2PowerLaws (\
31- self .accuracy ,density_dico )
35+ self .dust_distribution_calc = DustEllipticalDistribution2PowerLaws (
36+ self .accuracy , density_dico )
3237 else :
33- raise TypeError ('The only dust distribution implemented so far is the "2PowerLaws"' )
38+ errmsg = 'The only dust distribution implemented so far is the' \
39+ ' "2PowerLaws"'
40+ raise TypeError (errmsg )
3441
3542 def set_density_distribution (self ,density_dico ):
3643 """
37- Updates the parameters of the density distribution.
44+ Update the parameters of the density distribution.
3845 """
3946 self .dust_distribution_calc .set_density_distribution (density_dico )
4047
41- def density_cylindrical (self ,r , costheta ,z ):
48+ def density_cylindrical (self , r , costheta , z ):
4249 """
43- Returns the particule volume density at r, theta, z
50+ Return the particule volume density at r, theta, z.
4451 """
45- return self .dust_distribution_calc .density_cylindrical (r ,costheta ,z )
52+ return self .dust_distribution_calc .density_cylindrical (r , costheta , z )
4653
47- def density_cartesian (self ,x , y , z ):
54+ def density_cartesian (self , x , y , z ):
4855 """
49- Returns the particule volume density at x,y,z, taking into account the offset
50- of the disk
56+ Return the particule volume density at x,y,z, taking into account the
57+ offset of the disk.
5158 """
52- return self .dust_distribution_calc .density_cartesian (x ,y , z )
59+ return self .dust_distribution_calc .density_cartesian (x , y , z )
5360
54-
55- def print_info (self ,pxInAu = None ):
61+ def print_info (self , pxInAu = None ):
5662 """
57- Utility function that displays the parameters of the radial distribution of the dust
63+ Utility function that displays the parameters of the radial distribution
64+ of the dust
65+
5866 Input:
5967 - pxInAu (optional): the pixel size in au
6068 """
6169 print ('----------------------------' )
6270 print ('Dust distribution parameters' )
6371 print ('----------------------------' )
64- self .dust_distribution_calc .print_info (pxInAu = None )
65-
72+ self .dust_distribution_calc .print_info (pxInAu )
73+
74+
6675class DustEllipticalDistribution2PowerLaws :
6776 """
6877 """
69-
70- def __init__ ( self , accuracy = 5.e-3 , density_dico = { 'ain' : 5 , 'aout' : - 5 ,\
71- 'a' : 60 , 'e' : 0 , 'ksi0' : 1. , 'gamma' :2. ,'beta' :1. }):
78+ def __init__ ( self , accuracy = 5.e-3 , density_dico = { 'ain' : 5 , 'aout' : - 5 ,
79+ 'a' : 60 , 'e' : 0 , 'ksi0' : 1. ,
80+ 'gamma' :2. ,'beta' :1. }):
7281 """
7382 Constructor for the Dust_distribution class.
7483
@@ -84,37 +93,37 @@ def set_density_distribution(self,density_dico):
8493 """
8594 """
8695 if 'ksi0' not in density_dico .keys ():
87- ksi0 = 1.
96+ ksi0 = 1.
8897 else :
89- ksi0 = density_dico ['ksi0' ]
98+ ksi0 = density_dico ['ksi0' ]
9099 if 'beta' not in density_dico .keys ():
91- beta = 1.
100+ beta = 1.
92101 else :
93- beta = density_dico ['beta' ]
102+ beta = density_dico ['beta' ]
94103 if 'gamma' not in density_dico .keys ():
95- gamma = 1.
104+ gamma = 1.
96105 else :
97- gamma = density_dico ['gamma' ]
106+ gamma = density_dico ['gamma' ]
98107 if 'aout' not in density_dico .keys ():
99- aout = - 5.
108+ aout = - 5.
100109 else :
101- aout = density_dico ['aout' ]
110+ aout = density_dico ['aout' ]
102111 if 'ain' not in density_dico .keys ():
103- ain = 5.
112+ ain = 5.
104113 else :
105- ain = density_dico ['ain' ]
114+ ain = density_dico ['ain' ]
106115 if 'e' not in density_dico .keys ():
107- e = 0.
116+ e = 0.
108117 else :
109- e = density_dico ['e' ]
118+ e = density_dico ['e' ]
110119 if 'a' not in density_dico .keys ():
111- a = 60.
120+ a = 60.
112121 else :
113- a = density_dico ['a' ]
114- self .set_vertical_density (ksi0 = ksi0 ,gamma = gamma ,beta = beta )
115- self .set_radial_density (ain = ain ,aout = aout ,a = a ,e = e )
122+ a = density_dico ['a' ]
123+ self .set_vertical_density (ksi0 = ksi0 , gamma = gamma , beta = beta )
124+ self .set_radial_density (ain = ain , aout = aout , a = a , e = e )
116125
117- def set_vertical_density (self ,ksi0 = 1. ,gamma = 2. ,beta = 1. ):
126+ def set_vertical_density (self , ksi0 = 1. , gamma = 2. , beta = 1. ):
118127 """
119128 Sets the parameters of the vertical density function
120129
@@ -139,12 +148,12 @@ def set_vertical_density(self,ksi0=1.,gamma=2.,beta=1.):
139148 print ('Warning the flaring coefficient beta is negative' )
140149 print ('beta was changed from {0:6.2f} to 0 (flat disk)' .format (beta ))
141150 beta = 0.
142- self .ksi0 = float (ksi0 )
143- self .gamma = float (gamma )
144- self .beta = float (beta )
145- self .zmax = ksi0 * (- np .log (self .accuracy ))** (1. / gamma )
151+ self .ksi0 = float (ksi0 )
152+ self .gamma = float (gamma )
153+ self .beta = float (beta )
154+ self .zmax = ksi0 * (- np .log (self .accuracy ))** (1. / gamma )
146155
147- def set_radial_density (self ,ain = 5. ,aout = - 5. ,a = 60. ,e = 0. ):
156+ def set_radial_density (self , ain = 5. , aout = - 5. , a = 60. , e = 0. ):
148157 """
149158 Sets the parameters of the radial density function
150159
@@ -179,15 +188,17 @@ def set_radial_density(self,ain=5.,aout=-5.,a=60.,e=0.):
179188 e = 0.99
180189 if a < 0 :
181190 raise ValueError ('Warning the semi-major axis a is negative' )
182- self .ain = float (ain )
183- self .aout = float (aout )
184- self .a = float (a )
185- self .e = float (e )
186- self .p = self .a * (1 - self .e ** 2 )
191+ self .ain = float (ain )
192+ self .aout = float (aout )
193+ self .a = float (a )
194+ self .e = float (e )
195+ self .p = self .a * (1 - self .e ** 2 )
187196 try :
188- self .rmax = self .a * self .accuracy ** (1 / self .aout ) #maximum distance of integration, AU
189- if self .ain != self .aout :
190- self .apeak = self .a * np .power (- self .ain / self .aout ,1. / (2. * (self .ain - self .aout )))
197+ # maximum distance of integration, AU
198+ self .rmax = self .a * self .accuracy ** (1 / self .aout )
199+ if self .ain != self .aout :
200+ self .apeak = self .a * np .power (- self .ain / self .aout ,
201+ 1. / (2. * (self .ain - self .aout )))
191202 else :
192203 self .apeak = self .a
193204 except OverflowError :
@@ -204,69 +215,85 @@ def set_radial_density(self,ain=5.,aout=-5.,a=60.,e=0.):
204215 raise ZeroDivisionError
205216 self .itiltthreshold = np .rad2deg (np .arctan (self .rmax / self .zmax ))
206217
207- def print_info (self ,pxInAu = None ):
218+ def print_info (self , pxInAu = None ):
208219 """
209- Utility function that displays the parameters of the radial distribution of the dust
220+ Utility function that displays the parameters of the radial distribution
221+ of the dust
222+
210223 Input:
211224 - pxInAu (optional): the pixel size in au
212225 """
213226 if pxInAu is not None :
214- print ('Reference semi-major axis: {0:.1f}au or {1:.1f}px' .format (self .a ,self .a / pxInAu ))
215- print ('Semi-major axis at maximum dust density: {0:.1f}au or {1:.1f}px (same as ref sma if ain=-aout)' .format (self .apeak ,self .apeak / pxInAu ))
216- print ('Ellipse p parameter: {0:.1f}au or {1:.1f}px' .format (self .p ,self .p / pxInAu ))
227+ msg = 'Reference semi-major axis: {0:.1f}au or {1:.1f}px'
228+ print (msg .format (self .a ,self .a / pxInAu ))
229+ msg2 = 'Semi-major axis at maximum dust density: {0:.1f}au or ' \
230+ '{1:.1f}px (same as ref sma if ain=-aout)'
231+ print (msg2 .format (self .apeak ,self .apeak / pxInAu ))
232+ msg3 = 'Ellipse p parameter: {0:.1f}au or {1:.1f}px'
233+ print (msg3 .format (self .p ,self .p / pxInAu ))
217234 else :
218235 print ('Reference semi-major axis: {0:.1f}au' .format (self .a ))
219- print ('Semi-major axis at maximum dust density: {0:.1f}au (same as ref sma if ain=-aout)' .format (self .apeak ))
236+ msg = 'Semi-major axis at maximum dust density: {0:.1f}au (same ' \
237+ 'as ref sma if ain=-aout)'
238+ print (msg .format (self .apeak ))
220239 print ('Ellipse p parameter: {0:.1f}au' .format (self .p ))
221240 print ('Ellipticity: {0:.3f}' .format (self .e ))
222241 print ('Inner slope: {0:.2f}' .format (self .ain ))
223242 print ('Outer slope: {0:.2f}' .format (self .aout ))
224243 if pxInAu is not None :
225- print ('Scale height: {0:.1f}au or {1:.1f}px at {2:.1f}' .format (self .ksi0 ,self .ksi0 / pxInAu ,self .a ))
244+ msg = 'Scale height: {0:.1f}au or {1:.1f}px at {2:.1f}'
245+ print (msg .format (self .ksi0 ,self .ksi0 / pxInAu ,self .a ))
226246 else :
227- print ('Scale height: {0:.2f} au at {1:.2f}' .format (self .ksi0 ,self .a ))
247+ print ('Scale height: {0:.2f} au at {1:.2f}' .format (self .ksi0 ,
248+ self .a ))
228249 print ('Vertical profile index: {0:.2f}' .format (self .gamma ))
229- print ('Disc vertical FWHM: {0:.2f} at {1:.2f}' .format (2. * self .ksi0 * np .power (np .log10 (2. ),1. / self .gamma ),self .a ))
250+ msg = 'Disc vertical FWHM: {0:.2f} at {1:.2f}'
251+ print (msg .format (2. * self .ksi0 * np .power (np .log10 (2. ), 1. / self .gamma ),
252+ self .a ))
230253 print ('Flaring coefficient: {0:.2f}' .format (self .beta ))
231254 print ('------------------------------------' )
232255 print ('Properties for numerical integration' )
233256 print ('------------------------------------' )
234257 print ('Requested accuracy {0:.2e}' .format (self .accuracy ))
235258# print('Minimum radius for integration: {0:.2f} au'.format(self.rmin))
236259 print ('Maximum radius for integration: {0:.2f} au' .format (self .rmax ))
237- print ('Maximum height for integration: {0:.2f} au' .format (self .zmax ))
238- print ('Inclination threshold: {0:.2f} degrees' .format (self .itiltthreshold ))
260+ print ('Maximum height for integration: {0:.2f} au' .format (self .zmax ))
261+ msg = 'Inclination threshold: {0:.2f} degrees'
262+ print (msg .format (self .itiltthreshold ))
239263 return
240264
241- def density_cylindrical (self ,r , costheta ,z ):
265+ def density_cylindrical (self , r , costheta , z ):
242266 """ Returns the particule volume density at r, theta, z
243267 """
244- radial_ratio = r / (self .p / (1 - self .e * costheta ))
245- radial_density_term = np .sqrt (2. / (np .power (radial_ratio ,- 2 * self .ain )+ np .power (radial_ratio ,- 2 * self .aout )))
246- vertical_density_term = np .exp (- np .power (np .abs (z )/ (self .ksi0 * np .power (radial_ratio ,self .beta )),self .gamma ))
268+ radial_ratio = r / (self .p / (1 - self .e * costheta ))
269+ den = (np .power (radial_ratio , - 2 * self .ain ) +
270+ np .power (radial_ratio ,- 2 * self .aout ))
271+ radial_density_term = np .sqrt (2. / den )
272+ den2 = (self .ksi0 * np .power (radial_ratio ,self .beta ))
273+ vertical_density_term = np .exp (- np .power (np .abs (z )/ den2 , self .gamma ))
247274 return radial_density_term * vertical_density_term
248275
249- def density_cartesian (self ,x , y , z ):
250- """ Returns the particule volume density at x,y,z, taking into account the offset
251- of the disk
276+ def density_cartesian (self , x , y , z ):
277+ """ Returns the particule volume density at x,y,z, taking into account
278+ the offset of the disk
252279 """
253- r = np .sqrt (x ** 2 + y ** 2 )
254- if r == 0 :
280+ r = np .sqrt (x ** 2 + y ** 2 )
281+ if r == 0 :
255282 costheta = 0
256283 else :
257- costheta = x / r
284+ costheta = x / r
258285 return self .density_cylindrical (r ,costheta ,z )
259286
260- if __name__ == '__main__' :
287+
288+ if __name__ == '__main__' :
261289 """
262290 Main of the class for debugging
263291 """
264292 test = DustEllipticalDistribution2PowerLaws ()
265- test .set_radial_density (ain = 5. ,aout = - 5. ,a = 60. ,e = 0. )
293+ test .set_radial_density (ain = 5. , aout = - 5. , a = 60. , e = 0. )
266294 test .print_info ()
267- costheta = 0.
268- z = 0.
295+ costheta = 0.
296+ z = 0.
269297 for a in np .linspace (60 - 5 ,60 + 5 ,11 ):
270- t = test .density_cylindrical (a ,costheta ,z )
271- print ('r={0:.1f} density={1:.4f}' .format (a ,t ))
272-
298+ t = test .density_cylindrical (a , costheta , z )
299+ print ('r={0:.1f} density={1:.4f}' .format (a , t ))
0 commit comments