From bb9e173bb6dc1766393a37b03bf438322635af29 Mon Sep 17 00:00:00 2001 From: Steven Rieder Date: Mon, 18 Nov 2024 16:04:57 +0100 Subject: [PATCH] fix globals --- src/sunbather/construct_parker.py | 27 +++++++++++++++------------ tests/test.py | 16 +++++++++------- tests/test_sunbather.py | 8 +++++--- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/sunbather/construct_parker.py b/src/sunbather/construct_parker.py index 807b1fd..242a011 100644 --- a/src/sunbather/construct_parker.py +++ b/src/sunbather/construct_parker.py @@ -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 + "/" @@ -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 + "/" @@ -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 + "/" @@ -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 @@ -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 + "/" @@ -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 + "/" @@ -1140,7 +1143,7 @@ def __call__(self, parser, namespace, values, option_string=None): ) ): os.mkdir( - tools.projectpath + projectpath + "/parker_profiles/" + args.plname + "/" diff --git a/tests/test.py b/tests/test.py index a7bb374..11071c3 100644 --- a/tests/test.py +++ b/tests/test.py @@ -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( @@ -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, @@ -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") diff --git a/tests/test_sunbather.py b/tests/test_sunbather.py index 4d7f7df..8790393 100644 --- a/tests/test_sunbather.py +++ b/tests/test_sunbather.py @@ -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" @@ -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" @@ -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/"