PLATYPOS issueshttps://gitlab.aip.de/lketzer/platypos/-/issues2020-06-26T08:35:06Zhttps://gitlab.aip.de/lketzer/platypos/-/issues/10IDEA Cleaning: I won't do that but that is ok.2020-06-26T08:35:06ZYori Fourniery.fournier@aip.deIDEA Cleaning: I won't do that but that is ok.In this function you define a function in a function that is ok, but in this case not necessary.
see [https://gitlab.aip.de/lketzer/platypos/-/blob/master/platypos_package/Planet_class_LoFo14.py#L133](https://gitlab.aip.de/lketzer/platypos/-/blob/master/platypos_package/Planet_class_LoFo14.py#L133)
```python
def Solve_for_fenv(self):
""" For known core and planet radius, core mass, age and flux,
solve for envelope mass fraction."""
if self.radius == self.core_radius:
self.fenv = 0.0
else:
def Calculate_fenv(fenv):
age_exponent = {"solarZ": -0.11, "enhZ": -0.18}
return -self.radius + self.core_radius + (2.06\
* (self.core_mass/(1-(fenv/100)))**(-0.21)\
* (fenv/5)**0.59 * (self.flux)**0.044\
* ((self.age/1e3)/5)**(age_exponent[self.metallicity]))
f_guess = 0.1
fenv = optimize.fsolve(Calculate_fenv, x0=f_guess)[0]
self.fenv = fenv
# if fenv1 != fenv:
# print("Sth went wrong in solving for\
# the envelope mass fraction! Check!")
```
defining a function inside a function is totally fine in python. Even a class in a class...
However, it might be a bit difficult to debug. Because the function exists only in the namespace of the other function.
So even some time it is necessary to define a function into another function (a decorator for instance) here it is not.
And what is not necessary should be avoided.
```python
@staticmethod
def calculate_fenv(fenv):
age_exponent = {"solarZ": -0.11, "enhZ": -0.18}
return -1. * self.radius + self.core_radius \
+ (2.06 * (self.core_mass / (1 - (fenv / 100) ) )**(-0.21) \
* (fenv / 5)**0.59 * (self.flux)**0.044 \
* ( (self.age / 1.e3) / 5)**(age_exponent[self.metallicity]))
def Solve_for_fenv(self):
""" For known core and planet radius, core mass, age and flux,
solve for envelope mass fraction."""
if self.radius == self.core_radius:
self.fenv = 0.0
else:
f_guess = 0.1
fenv = optimize.fsolve(self.calculate_fenv, x0=f_guess)[0]
self.fenv = fenv
# if fenv1 != fenv:
# print("Sth went wrong in solving for\
# the envelope mass fraction! Check!")
```
The funny part here is that the `@staticmethod` decorator (decorator?? read the docs that is one of the most crazy part of python) actually defines `calculate_fenv` inside another method. X) but it does properly and debugging won't be an issue.In this function you define a function in a function that is ok, but in this case not necessary.
see [https://gitlab.aip.de/lketzer/platypos/-/blob/master/platypos_package/Planet_class_LoFo14.py#L133](https://gitlab.aip.de/lketzer/platypos/-/blob/master/platypos_package/Planet_class_LoFo14.py#L133)
```python
def Solve_for_fenv(self):
""" For known core and planet radius, core mass, age and flux,
solve for envelope mass fraction."""
if self.radius == self.core_radius:
self.fenv = 0.0
else:
def Calculate_fenv(fenv):
age_exponent = {"solarZ": -0.11, "enhZ": -0.18}
return -self.radius + self.core_radius + (2.06\
* (self.core_mass/(1-(fenv/100)))**(-0.21)\
* (fenv/5)**0.59 * (self.flux)**0.044\
* ((self.age/1e3)/5)**(age_exponent[self.metallicity]))
f_guess = 0.1
fenv = optimize.fsolve(Calculate_fenv, x0=f_guess)[0]
self.fenv = fenv
# if fenv1 != fenv:
# print("Sth went wrong in solving for\
# the envelope mass fraction! Check!")
```
defining a function inside a function is totally fine in python. Even a class in a class...
However, it might be a bit difficult to debug. Because the function exists only in the namespace of the other function.
So even some time it is necessary to define a function into another function (a decorator for instance) here it is not.
And what is not necessary should be avoided.
```python
@staticmethod
def calculate_fenv(fenv):
age_exponent = {"solarZ": -0.11, "enhZ": -0.18}
return -1. * self.radius + self.core_radius \
+ (2.06 * (self.core_mass / (1 - (fenv / 100) ) )**(-0.21) \
* (fenv / 5)**0.59 * (self.flux)**0.044 \
* ( (self.age / 1.e3) / 5)**(age_exponent[self.metallicity]))
def Solve_for_fenv(self):
""" For known core and planet radius, core mass, age and flux,
solve for envelope mass fraction."""
if self.radius == self.core_radius:
self.fenv = 0.0
else:
f_guess = 0.1
fenv = optimize.fsolve(self.calculate_fenv, x0=f_guess)[0]
self.fenv = fenv
# if fenv1 != fenv:
# print("Sth went wrong in solving for\
# the envelope mass fraction! Check!")
```
The funny part here is that the `@staticmethod` decorator (decorator?? read the docs that is one of the most crazy part of python) actually defines `calculate_fenv` inside another method. X) but it does properly and debugging won't be an issue.Fix all of Yori's comments.Laura KetzerLaura Ketzerhttps://gitlab.aip.de/lketzer/platypos/-/issues/5IDEA: usage of your package2020-06-26T08:35:05ZYori Fourniery.fournier@aip.deIDEA: usage of your packageIn this jupyter notebook [V1298Tau_Paper_Calculations_and_Plots.ipynb](https://gitlab.aip.de/lketzer/platypos/-/blob/master/example_V1298Tau/V1298Tau_Paper_Calculations_and_Plots.ipynb) I could find a few technical things you may improve:
* Do not import your package via changing the path!
* You can easily make the fonts to be latex (it looks much better in a paper)
* I would suggest not to use `plt.subplot` to create `Figure` and `Axes` it used to have a memory leak.
* a one column plot is 8 inch wide not 10. You may also want to fix the dpi to 300 for a better export.
Feel free to ask in the comment if you are interested about another way of doing these stuff.In this jupyter notebook [V1298Tau_Paper_Calculations_and_Plots.ipynb](https://gitlab.aip.de/lketzer/platypos/-/blob/master/example_V1298Tau/V1298Tau_Paper_Calculations_and_Plots.ipynb) I could find a few technical things you may improve:
* Do not import your package via changing the path!
* You can easily make the fonts to be latex (it looks much better in a paper)
* I would suggest not to use `plt.subplot` to create `Figure` and `Axes` it used to have a memory leak.
* a one column plot is 8 inch wide not 10. You may also want to fix the dpi to 300 for a better export.
Feel free to ask in the comment if you are interested about another way of doing these stuff.Fix all of Yori's comments.Laura KetzerLaura Ketzer