Skip to content

Commit

Permalink
Changes to fading_function_on
Browse files Browse the repository at this point in the history
fading_function_on is True by default. User has to manually set  fading_function_on = False to turn off fading function.
  • Loading branch information
Little-Ryugu committed Jan 14, 2025
1 parent 380af93 commit 106d3b9
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 32 deletions.
3 changes: 1 addition & 2 deletions src/sorcha/data/demo/sorcha_config_demo.ini
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,8 @@ footprint_edge_threshold = 2.

[FADINGFUNCTION]

# Detection efficiency fading function on or off. Uses the fading function as outlined in
# Uses the fading function as outlined in
# Chesley and Vereš (2017) to remove observations.
fading_function_on = True

# Width parameter for fading function. Should be greater than zero and less than 0.5.
# Suggested value is 0.1 after Chesley and Vereš (2017).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ circle_radius = 1.75

[FADINGFUNCTION]

# Detection efficiency fading function on or off. Uses the fading function as outlined in
# Uses the fading function as outlined in
# Chesley and Vereš (2017) to remove observations.
fading_function_on = True

# Width parameter for fading function. Should be greater than zero and less than 0.5.
# Suggested value is 0.1 after Chesley and Vereš (2017).
Expand Down
3 changes: 1 addition & 2 deletions src/sorcha/data/survey_setups/Rubin_full_footprint.ini
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ footprint_edge_threshold = 2.

[FADINGFUNCTION]

# Detection efficiency fading function on or off. Uses the fading function as outlined in
# Uses the fading function as outlined in
# Chesley and Vereš (2017) to remove observations.
fading_function_on = True

# Width parameter for fading function. Should be greater than zero and less than 0.5.
# Suggested value is 0.1 after Chesley and Vereš (2017).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ footprint_edge_threshold = 2.

[FADINGFUNCTION]

# Detection efficiency fading function on or off. Uses the fading function as outlined in
# Uses the fading function as outlined in
# Chesley and Vereš (2017) to remove observations.
fading_function_on = False

Expand Down
20 changes: 15 additions & 5 deletions src/sorcha/utilities/sorchaConfigs.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ class fadingfunctionConfigs:
"""Data class for holding FADINGFUNCTION section configuration file keys and validating them"""

fading_function_on: bool = None
"""Detection efficiency fading function on or off."""
"""Detection efficiency fading function on or off. Default True"""

fading_function_width: float = None
"""Width parameter for fading function. Should be greater than zero and less than 0.5."""
Expand All @@ -417,10 +417,20 @@ def _validate_fadingfunction_configs(self):
None
"""

# make sure all the mandatory keys have been populated.
check_key_exists(self.fading_function_on, "fading_function_on")
self.fading_function_on = cast_as_bool(self.fading_function_on, "fading_function_on")

if (
self.fading_function_on is None
and self.fading_function_peak_efficiency is None
and self.fading_function_width is None
):
logging.error(
"ERROR: Both fading_function_peak_efficiency and fading_function_width are needed to be supplied for fading function"
)
sys.exit(
"ERROR: Both fading_function_peak_efficiency and fading_function_width are needed to be supplied for fading function"
)
self.fading_function_on = cast_as_bool_or_set_default(
self.fading_function_on, "fading_function_on", True
)
if self.fading_function_on == True:

# when fading_function_on = true, fading_function_width and fading_function_peak_efficiency now mandatory
Expand Down
34 changes: 14 additions & 20 deletions tests/sorcha/test_sorchaConfigs.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,27 +610,9 @@ def test_fadingfunctionConfig_on_float(key_name):
)


def test_fadingfunctionConfig_bool():
"""
Tests that wrong inputs for fadingfunctionConfig bool attributes is caught correctly
"""

fadingfunction_configs = correct_fadingfunction.copy()
test_configs = fadingfunctionConfigs(**fadingfunction_configs)
assert test_configs.__dict__ == fadingfunction_configs

fadingfunction_configs["fading_function_on"] = "ten"
with pytest.raises(SystemExit) as error_text:
test_configs = fadingfunctionConfigs(**fadingfunction_configs)

assert (
error_text.value.code
== "ERROR: expected a bool for config parameter fading_function_on. Check value in config file."
)


@pytest.mark.parametrize(
"key_name", ["fading_function_on", "fading_function_width", "fading_function_peak_efficiency"]
"key_name", ["fading_function_width", "fading_function_peak_efficiency"]
)
def test_fadingfunction_mandatory(key_name):
"""
Expand Down Expand Up @@ -692,7 +674,19 @@ def test_fadingfunction_outofbounds(key_name):
== "ERROR: fading_function_peak_efficiency out of bounds. Must be between 0 and 1."
)


def test_fadingfunction_allnone():
"""
This loops through the not required keys and makes sure the code fails correctly when all attributes are none
"""
fadingfunction_configs = correct_fadingfunction.copy()
fadingfunction_configs["fading_function_on"] = None
fadingfunction_configs["fading_function_width"] = None
fadingfunction_configs["fading_function_peak_efficiency"] = None
with pytest.raises(SystemExit) as error_text:
test_configs = fadingfunctionConfigs(**fadingfunction_configs)
assert (
error_text.value.code == "ERROR: Both fading_function_peak_efficiency and fading_function_width are needed to be supplied for fading function"
)
##################################################################################################################################

# linkingfilter tests
Expand Down

0 comments on commit 106d3b9

Please sign in to comment.