Skip to content

Commit

Permalink
Creating global variable to set use_integrate
Browse files Browse the repository at this point in the history
  • Loading branch information
Kathleen Kiker authored and akoumjian committed Dec 19, 2024
1 parent 6ff172b commit 41f6d97
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/sorcha/ephemeris/simulation_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ def create_ephemeris(orbits_df, pointings_df, args, sconfigs):
nside = 2**sconfigs.simulation.ar_healpix_order
n_sub_intervals = 101 # configs["n_sub_intervals"]

if configs["ar_use_integrate"]:
#set global variable to use integrate method instead of integrate_or_interpolate
global USE_INTEGRATE
USE_INTEGRATE = True

ephemeris_csv_filename = None
if args.output_ephemeris_file and args.outpath:
ephemeris_csv_filename = os.path.join(args.outpath, args.output_ephemeris_file)
Expand Down
11 changes: 10 additions & 1 deletion src/sorcha/ephemeris/simulation_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,17 @@ def integrate_light_time(sim, ex, t, r_obs, lt0=0, iter=3, speed_of_light=SPEED_
Object velocity at t-lt
"""
lt = lt0
global USE_INTEGRATE
try:
USE_INTEGRATE
except NameError:
USE_INTEGRATE = False

for i in range(iter):
ex.integrate_or_interpolate(t - lt)
if USE_INTEGRATE:
sim.integrate(t - lt)
else:
ex.integrate_or_interpolate(t - lt)
target = np.array(sim.particles[0].xyz)
vtarget = np.array(sim.particles[0].vxyz)
rho = target - r_obs
Expand Down
15 changes: 15 additions & 0 deletions src/sorcha/modules/PPConfigParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,16 @@ def PPConfigFileParser(configfile, survey_name):
"ERROR: SNR limit and magnitude limit are mutually exclusive. Please delete one or both from config file."
)

try:
config_dict["ar_use_integrate"] = config.getboolean("EXPERT", "ar_use_integrate", fallback=False)
except ValueError:
pplogger.error(
"ERROR: could not parse value for ar_use_integrate as a boolean. Check formatting and try again."
)
sys.exit(
"ERROR: could not parse value for ar_use_integrate as a boolean. Check formatting and try again."
)

try:
config_dict["trailing_losses_on"] = config.getboolean("EXPERT", "trailing_losses_on", fallback=True)
except ValueError:
Expand Down Expand Up @@ -860,6 +870,11 @@ def PPPrintConfigsToLog(configs, cmd_args):
+ configs["phase_function"]
)

if configs["ar_use_integrate"]:
pplogger.info("ASSIST+REBOUND integration is ON. Integrate or interpolate will NOT be used.")
else:
pplogger.info("ASSIST+REBOUND integration is OFF. Integrate or interpolate will be used.")

if configs["trailing_losses_on"]:
pplogger.info("Computation of trailing losses is switched ON.")
else:
Expand Down
1 change: 1 addition & 0 deletions tests/data/test_PPPrintConfigsToLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ sorcha.modules.PPConfigParser INFO The main filter in which H is defined is
sorcha.modules.PPConfigParser INFO The filters included in the post-processing results are r g i z
sorcha.modules.PPConfigParser INFO Thus, the colour indices included in the simulation are g-r i-r z-r
sorcha.modules.PPConfigParser INFO The apparent brightness is calculated using the following phase function model: HG
sorcha.modules.PPConfigParser INFO ASSIST+REBOUND integration is OFF. Integrate or interpolate will be used.
sorcha.modules.PPConfigParser INFO Computation of trailing losses is switched ON.
sorcha.modules.PPConfigParser INFO Randomization of position and magnitude around uncertainties is switched ON.
sorcha.modules.PPConfigParser INFO Vignetting is switched ON.
Expand Down
18 changes: 18 additions & 0 deletions tests/ephemeris/test_ephemeris_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pytest
import os
import re
from numpy.testing import assert_almost_equal

from sorcha.utilities.dataUtilitiesForTests import get_test_filepath, get_demo_filepath
from sorcha.modules.PPConfigParser import PPConfigFileParser
Expand Down Expand Up @@ -151,6 +152,23 @@ def test_ephemeris_end2end(single_synthetic_pointing, tmp_path):
for file in files:
assert not re.match(r".+\.csv", file)

configs["ar_use_integrate"] = True

observations_integrate = create_ephemeris(
single_synthetic_pointing,
filterpointing,
args,
configs,
)

assert len(observations_integrate) == 10

assert_almost_equal(
observations_integrate["fieldMJD_TAI"].values, observations["fieldMJD_TAI"].values, decimal=6
)
assert_almost_equal(observations_integrate["RA_deg"].values, observations["RA_deg"].values, decimal=6)
assert_almost_equal(observations_integrate["Dec_deg"].values, observations["Dec_deg"].values, decimal=6)


def test_ephemeris_writeread_csv(single_synthetic_ephemeris, tmp_path):
"""Tests to ensure the ephemeris file is written out correctly AND
Expand Down
2 changes: 2 additions & 0 deletions tests/sorcha/test_PPConfigParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def test_PPConfigFileParser(setup_and_teardown_for_PPConfigFileParser):
"lc_model": None,
"randomization_on": True,
"vignetting_on": True,
"ar_use_integrate": False,
}

assert configs == test_configs
Expand Down Expand Up @@ -300,6 +301,7 @@ def test_PPPrintConfigsToLog(tmp_path):
"lc_model": None,
"randomization_on": True,
"vignetting_on": True,
"ar_use_integrate": False,
}

PPPrintConfigsToLog(configs, args)
Expand Down

0 comments on commit 41f6d97

Please sign in to comment.