Skip to content

Commit

Permalink
Merge pull request #346 from dsavransky/kw_cleanup
Browse files Browse the repository at this point in the history
outspec and cache cleanup
  • Loading branch information
dsavransky authored Apr 20, 2023
2 parents 100f855 + 9c7367f commit ac601f8
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 29 deletions.
6 changes: 4 additions & 2 deletions EXOSIMS/Completeness/BrownCompleteness.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,10 @@ def generate_cache_names(self, **specs):
self.extstr = ""
for att in sorted(atts, key=str.lower):
if (
not callable(getattr(self.PlanetPopulation, att))
and att != "PlanetPhysicalModel"
not (callable(getattr(self.PlanetPopulation, att)))
and (att != "PlanetPhysicalModel")
and (att != "cachedir")
and (att != "_outspec")
):
self.extstr += "%s: " % att + str(getattr(self.PlanetPopulation, att))
ext = hashlib.md5(self.extstr.encode("utf-8")).hexdigest()
Expand Down
11 changes: 4 additions & 7 deletions EXOSIMS/PlanetPopulation/AlbedoByRadius.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def __init__(
**specs
):

# pop required values back into specs, set input attributes and call upstream
# init
self.ps = np.array(ps, ndmin=1, copy=False)
self.Rb = np.array(Rb, ndmin=1, copy=False)
specs["prange"] = [np.min(ps), np.max(ps)]
SAG13.__init__(
self,
Expand All @@ -57,9 +61,6 @@ def __init__(
**specs
)

# cast inputs to arrays
self.ps = np.array(ps, ndmin=1, copy=False)
self.Rb = np.array(Rb, ndmin=1, copy=False)
# check to ensure proper inputs
assert (
len(self.ps) - len(self.Rb) == 1
Expand All @@ -69,10 +70,6 @@ def __init__(
# albedo is constant for planetary radius range
self.pfromRp = True

# populate _outspec with new specific attributes
self._outspec["ps"] = self.ps
self._outspec["Rb"] = self.Rb

def gen_plan_params(self, n):
"""Generate semi-major axis (AU), eccentricity, geometric albedo, and
planetary radius (earthRad)
Expand Down
9 changes: 2 additions & 7 deletions EXOSIMS/PlanetPopulation/AlbedoByRadiusDulzPlavchan.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@ def __init__(
**specs
):

self.ps = np.array(ps, ndmin=1, copy=False)
self.Rb = np.array(Rb, ndmin=1, copy=False)
specs["prange"] = [np.min(ps), np.max(ps)]
DulzPlavchan.__init__(
self, starMass=starMass, occDataPath=occDataPath, esigma=esigma, **specs
)

# cast inputs to arrays
self.ps = np.array(ps, ndmin=1, copy=False)
self.Rb = np.array(Rb, ndmin=1, copy=False)
# check to ensure proper inputs
assert (
len(self.ps) - len(self.Rb) == 1
Expand All @@ -64,10 +63,6 @@ def __init__(
# albedo is constant for planetary radius range
self.pfromRp = True

# populate _outspec with new specific attributes
self._outspec["ps"] = self.ps
self._outspec["Rb"] = self.Rb

def gen_plan_params(self, n):
"""Generate semi-major axis (AU), eccentricity, geometric albedo, and
planetary radius (earthRad)
Expand Down
4 changes: 3 additions & 1 deletion EXOSIMS/PlanetPopulation/DulzPlavchan.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ def __init__(
esigma=0.175 / np.sqrt(np.pi / 2.0),
**specs
):
PlanetPopulation.__init__(self, **specs)
# set local input attributes and call upstream init
self.starMass = starMass * u.M_sun
self.occDataPath = occDataPath
self.esigma = float(esigma)
PlanetPopulation.__init__(self, **specs)

er = self.erange
self.enorm = np.exp(-er[0] ** 2 / (2.0 * self.esigma**2)) - np.exp(
-er[1] ** 2 / (2.0 * self.esigma**2)
Expand Down
9 changes: 4 additions & 5 deletions EXOSIMS/PlanetPopulation/KeplerLike1.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ def __init__(
**specs
):

# put potentially popped elements back into specs and populate input attributes
specs["prange"] = prange
specs["Rprange"] = Rprange
self.smaknee = float(smaknee)
self.esigma = float(esigma)
PlanetPopulation.__init__(self, **specs)

# calculate norm for sma distribution with decay point (knee)
self.smaknee = float(smaknee)
ar = self.arange.to("AU").value
# sma distribution without normalization
tmp_dist_sma = lambda x, s0=self.smaknee: x ** (-0.62) * np.exp(
Expand All @@ -63,7 +65,6 @@ def __init__(
self.smanorm = integrate.quad(tmp_dist_sma, ar[0], ar[1])[0]

# calculate norm for eccentricity Rayleigh distribution
self.esigma = float(esigma)
er = self.erange
self.enorm = np.exp(-er[0] ** 2 / (2.0 * self.esigma**2)) - np.exp(
-er[1] ** 2 / (2.0 * self.esigma**2)
Expand All @@ -85,9 +86,7 @@ def __init__(
self.Rvals = Rvals
self.eta = np.sum(Rvals)

# populate outspec with attributes specific to KeplerLike1
self._outspec["smaknee"] = self.smaknee
self._outspec["esigma"] = self.esigma
# update outspec eta
self._outspec["eta"] = self.eta

self.dist_albedo_built = None
Expand Down
6 changes: 6 additions & 0 deletions EXOSIMS/PlanetPopulation/KnownRVPlanets.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class KnownRVPlanets(KeplerLike1):
assumes default file in PlanetPopulation directory of EXOSIMS.
period (astropy Quantity array):
Orbital period in units of day. Error in perioderr.
planetfile (str):
Name of input file to use
rvplanetfilepath (str, optional):
Path on disk of planetfile
tper (astropy Time):
Periastron time in units of jd. Error in tpererr.
Expand All @@ -62,6 +66,8 @@ def __init__(
**specs
):

self.rvplanetfilepath = rvplanetfilepath
self.planetfile = planetfile
KeplerLike1.__init__(self, smaknee=smaknee, esigma=esigma, **specs)

# default file is ipac_2016-05-15
Expand Down
4 changes: 0 additions & 4 deletions EXOSIMS/PlanetPopulation/SAG13.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,6 @@ def __init__(
# populate _outspec with SAG13 specific attributes
self._outspec["SAG13starMass"] = self.SAG13starMass.to("solMass").value
self._outspec["SAG13coeffs"] = self.SAG13coeffs
self._outspec["Gamma"] = self.Gamma
self._outspec["alpha"] = self.alpha
self._outspec["beta"] = self.beta
self._outspec["Rplim"] = self.Rplim

def gen_radius_sma(self, n):
"""Generate radius values in earth radius and semi-major axis values in AU.
Expand Down
8 changes: 6 additions & 2 deletions EXOSIMS/Prototypes/PlanetPopulation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from EXOSIMS.util.vprint import vprint
from EXOSIMS.util.get_module import get_module
from EXOSIMS.util.get_dirs import get_cache_dir
from EXOSIMS.util.keyword_fun import get_all_args
import astropy.units as u
import numpy as np
import copy
Expand Down Expand Up @@ -139,8 +140,11 @@ def __init__(
# star in a given universe
self.eta = eta

# populate all attributes to outspec
for att in self.__dict__:
# populate outspec with all inputs
kws = get_all_args(self.__class__)
ignore_kws = ["self", "cachedir"]
kws = list((set(kws) - set(ignore_kws)))
for att in kws:
if att not in ["vprint", "_outspec"]:
dat = copy.copy(self.__dict__[att])
self._outspec[att] = dat.value if isinstance(dat, u.Quantity) else dat
Expand Down
1 change: 1 addition & 0 deletions EXOSIMS/SimulatedUniverse/SAG13Universe.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def __init__(self, earthPF=False, **specs):

self.earthPF = earthPF
SimulatedUniverse.__init__(self, **specs)
self._outspec["earthPF"] = self.earthPF

def gen_physical_properties(self, **specs):
"""Generating universe based on SAG13 planet radius and period sampling.
Expand Down
2 changes: 1 addition & 1 deletion EXOSIMS/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging

name = "EXOSIMS"
__version__ = "3.1.2"
__version__ = "3.1.3"

# Set up a default logging handler to avoid "No handler found" warnings.
# Other handlers can add to this one.
Expand Down

0 comments on commit ac601f8

Please sign in to comment.