Skip to content

Commit

Permalink
fix globals
Browse files Browse the repository at this point in the history
  • Loading branch information
rieder committed Nov 18, 2024
1 parent 04f41ca commit bb9e173
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
27 changes: 15 additions & 12 deletions src/sunbather/construct_parker.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ def save_plain_parker_profile(
Mdot = float(Mdot)
T = int(T)

projectpath = tools.get_sunbather_project_path()
save_name = (
tools.projectpath
projectpath
+ "/parker_profiles/"
+ planet.name
+ "/"
Expand Down Expand Up @@ -418,7 +419,7 @@ def save_temp_parker_profile(
(r * planet.R, rho_array * rhos, v_array * vs * 1e5, mu_array)
)
save_name = (
tools.projectpath
projectpath
+ "/parker_profiles/"
+ planet.name
+ "/"
Expand Down Expand Up @@ -614,8 +615,9 @@ def save_cloudy_parker_profile(
Maximum altitude of the profile in units of the planet radius. By default 20.
"""

projectpath = tools.get_sunbather_project_path()
save_name = (
tools.projectpath
projectpath
+ "/parker_profiles/"
+ planet.name
+ "/"
Expand Down Expand Up @@ -813,7 +815,7 @@ def run_s(
20, int((p.a - p.Rstar) / p.R)
) # solve profile up to 20 Rp, unless the star is closer than that
spectrum = cloudy_spec_to_pwinds(
tools.cloudypath + "/data/SED/" + p.SEDname,
tools.get_cloudy_path() + "/data/SED/" + p.SEDname,
1.0,
(p.a - altmax * p.R) / tools.AU,
) # assumes SED is at 1 AU
Expand Down Expand Up @@ -1114,15 +1116,16 @@ def __call__(self, parser, namespace, values, option_string=None):
)

# set up the folder structure if it doesn't exist yet
if not os.path.isdir(tools.projectpath + "/parker_profiles/"):
os.mkdir(tools.projectpath + "/parker_profiles")
if not os.path.isdir(tools.projectpath + "/parker_profiles/" + args.plname + "/"):
os.mkdir(tools.projectpath + "/parker_profiles/" + args.plname)
projectpath = tools.get_sunbather_project_path()
if not os.path.isdir(projectpath + "/parker_profiles/"):
os.mkdir(projectpath + "/parker_profiles")
if not os.path.isdir(projectpath + "/parker_profiles/" + args.plname + "/"):
os.mkdir(projectpath + "/parker_profiles/" + args.plname)
if not os.path.isdir(
tools.projectpath + "/parker_profiles/" + args.plname + "/" + args.pdir + "/"
projectpath + "/parker_profiles/" + args.plname + "/" + args.pdir + "/"
):
os.mkdir(
tools.projectpath
projectpath
+ "/parker_profiles/"
+ args.plname
+ "/"
Expand All @@ -1131,7 +1134,7 @@ def __call__(self, parser, namespace, values, option_string=None):
)
if (args.fH is None) and (
not os.path.isdir(
tools.projectpath
projectpath
+ "/parker_profiles/"
+ args.plname
+ "/"
Expand All @@ -1140,7 +1143,7 @@ def __call__(self, parser, namespace, values, option_string=None):
)
):
os.mkdir(
tools.projectpath
projectpath
+ "/parker_profiles/"
+ args.plname
+ "/"
Expand Down
16 changes: 9 additions & 7 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,28 @@
# SETUP CHECKS

# make sure projectpath exists
projectpath = tools.get_sunbather_project_path()

assert os.path.isdir(
tools.projectpath
projectpath
), "Please create the projectpath folder on your machine"
# make sure the planets.txt file exists
assert os.path.isfile(
tools.projectpath + "/planets.txt"
projectpath + "/planets.txt"
), "Please make sure the 'planets.txt' file is present in $SUNBATHER_PROJECT_PATH"
# make sure the SED we need for this test has been copied to Cloudy
assert os.path.isfile(
tools.cloudypath + "/data/SED/eps_Eri_binned.spec"
tools.get_cloudy_path() + "/data/SED/eps_Eri_binned.spec"
), "Please copy /sunbather/stellar_SEDs/eps_Eri_binned.spec into $CLOUDY_PATH/data/SED/"


# ## CHECK IF test.py HAS BEEN RAN BEFORE ###

parker_profile_file = (
tools.projectpath
projectpath
+ "/parker_profiles/WASP52b/test/pprof_WASP52b_T=9000_M=11.000.txt"
)
simulation_folder = tools.projectpath + "/sims/1D/WASP52b/test/parker_9000_11.000/"
simulation_folder = projectpath + "/sims/1D/WASP52b/test/parker_9000_11.000/"

if os.path.exists(parker_profile_file) or os.path.exists(simulation_folder):
confirmation = input(
Expand Down Expand Up @@ -70,7 +72,7 @@
)
# load the created profile
pprof_created = pd.read_table(
tools.projectpath
projectpath
+ "/parker_profiles/WASP52b/test/pprof_WASP52b_T=9000_M=11.000.txt",
names=["alt", "rho", "v", "mu"],
dtype=np.float64,
Expand Down Expand Up @@ -111,7 +113,7 @@
)
# load the created simulation
sim_created = tools.Sim(
tools.projectpath + "/sims/1D/WASP52b/test/parker_9000_11.000/converged"
projectpath + "/sims/1D/WASP52b/test/parker_9000_11.000/converged"
)
# load the expected simulation
sim_expected = tools.Sim(this_path + "/materials/converged")
Expand Down
8 changes: 5 additions & 3 deletions tests/test_sunbather.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ def test_projectdirs():
Make sure projectpath exists
"""
from sunbather import tools
projectpath = tools.get_sunbather_project_path()
assert os.path.isdir(
tools.projectpath
projectpath
), "Please create the projectpath folder on your machine"


Expand All @@ -34,8 +35,9 @@ def test_planetstxt():
Make sure the planets.txt file exists
"""
from sunbather import tools
projectpath = tools.get_sunbather_project_path()
assert os.path.isfile(
tools.projectpath + "/planets.txt"
projectpath + "/planets.txt"
), "Please make sure the 'planets.txt' file is present in $SUNBATHER_PROJECT_PATH"


Expand All @@ -45,7 +47,7 @@ def test_seds():
"""
from sunbather import tools
assert os.path.isfile(
tools.cloudypath + "/data/SED/eps_Eri_binned.spec"
tools.get_cloudy_path() + "/data/SED/eps_Eri_binned.spec"
), (
"Please copy /sunbather/stellar_SEDs/eps_Eri_binned.spec "
"into $CLOUDY_PATH/data/SED/"
Expand Down

0 comments on commit bb9e173

Please sign in to comment.