Skip to content

Commit 182ed40

Browse files
committed
changes
1 parent 8e25f47 commit 182ed40

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

deepexo/rockyplanet.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from matplotlib.ticker import (MultipleLocator, AutoMinorLocator)
44
import numpy as np
55
import math
6+
import functools
67
import mdn
78
import joblib
89
import os
@@ -14,20 +15,41 @@
1415
# print(os.getcwd())
1516
model_path = os.path.join(os.getcwd(), "deepexo/model")
1617

18+
def lazy_property(fn):
19+
attr_name = "_lazy_" + fn.__name__
1720

21+
@property
22+
@functools.wraps(fn)
23+
def _lazy_property(self):
24+
if not hasattr(self, attr_name):
25+
setattr(self, attr_name, fn(self))
26+
return getattr(self, attr_name)
27+
28+
return _lazy_property
1829
class RockyPlanet:
1930
"""A class for characterizing the interior structure of rocky exoplanets."""
2031
def __init__(self):
21-
# print('init RockyPlanet')
22-
self.model_a = load_model(os.path.join(model_path, "model_a.h5"), custom_objects={
32+
pass
33+
34+
@lazy_property
35+
def model_a(self):
36+
return load_model(os.path.join(model_path, "model_a.h5"), custom_objects={
2337
'MDN': mdn.MDN(OUTPUT_DIMS, N_MIXES),
2438
"mdn_loss_func": mdn.get_mixture_loss_func(OUTPUT_DIMS, N_MIXES)}, compile=False)
25-
self.model_a_scaler = joblib.load(os.path.join(model_path, "model_a_scaler.save"))
26-
self.model_b = load_model(os.path.join(model_path, "model_b.h5"), custom_objects={
39+
40+
@lazy_property
41+
def model_a_scaler(self):
42+
return joblib.load(os.path.join(model_path, "model_a_scaler.save"))
43+
44+
@lazy_property
45+
def model_b(self):
46+
return load_model(os.path.join(model_path, "model_b.h5"), custom_objects={
2747
'MDN': mdn.MDN(OUTPUT_DIMS, N_MIXES),
2848
"mdn_loss_func": mdn.get_mixture_loss_func(OUTPUT_DIMS, N_MIXES)}, compile=False)
29-
self.model_b_scaler = joblib.load(os.path.join(model_path, "model_b_scaler.save"))
3049

50+
@lazy_property
51+
def model_b_scaler(self):
52+
return joblib.load(os.path.join(model_path, "model_b_scaler.save"))
3153
def predict(self, planet_params: object) -> object:
3254
"""Predicts the Water radial fraction, Mantle radial fraction, Core radial fraction, Core mass fraction,
3355
CMB pressure and CMB temperature for the given planetary parameters in terms of planetary mass M [M_Earth],
@@ -60,6 +82,8 @@ def plot(self, pred: object, save: object = False, filename: object = "pred.png"
6082
Returns:
6183
None or saves the plot to a file.
6284
"""
85+
print("###############################################")
86+
print("Plotting...")
6387
(y_min1, y_max1, y_min2, y_max2, y_min3, y_max3,
6488
y_min4, y_max4, y_min5, y_max5, y_min6, y_max6) = \
6589
0.00015137, 0.145835, 0.127618, 0.973427, 0.00787023, 0.799449, 1.17976e-06, 0.699986, 10.7182, 1999.49, 1689.37, 5673.87
@@ -154,6 +178,8 @@ def plot(self, pred: object, save: object = False, filename: object = "pred.png"
154178
ax.set_xlabel(predict_label[i])
155179
ax.set_ylabel("Probability density")
156180
if save:
181+
print("Saving figure to {}".format(filename))
157182
return plt.savefig(filename, dpi=300)
158183
else:
184+
print("Showing figure")
159185
return plt.show()

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ hdf5==1.10.4
22
h5py==2.10.0
33
joblib==0.14.1
44
tensorflow==2.3.0
5-
scikit-learn==0.22.1
5+
scikit-learn==0.24.0
66
tensorflow_probability==0.11.0
77
tensorflow-estimator==2.3.0
88
matplotlib==3.1.3

run.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
# Keplar-78b
44
M = 1.77 # mass in Earth masses
55
R = 1.228 # radius in Earth radii
6-
cFeMg = 0.685 # bulk Fe/(Mg + Si) (molar ratio)
6+
cFeMgSi = 0.685 # bulk Fe/(Mg + Si) (molar ratio)
77
k2 = 0.819 # tidal Love number
88

99
planet_params = [
1010
M,
1111
R,
12-
cFeMg,
12+
cFeMgSi,
1313
k2,
1414
]
1515
rp = RockyPlanet()

0 commit comments

Comments
 (0)