Skip to content

Commit

Permalink
Merge pull request #1103 from dirac-institute/fading_function_on-beha…
Browse files Browse the repository at this point in the history
…ve-like-linkingfilter

Fading function on behave like linkingfilter
  • Loading branch information
Little-Ryugu authored Jan 17, 2025
2 parents fda3d1e + 4378b11 commit 0bfc9cc
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 78 deletions.
5 changes: 1 addition & 4 deletions docs/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ Applying :ref:`trailing losses<trailing>` is on by default, but it can be turned
Turning off Detection Efficiency/Applying the Fading Function
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Applying the :ref:`survey detection efficiency<fading>` is on by default, but it can be turned off by including the option in the :ref:`configs`::

[FADINGFUNCTION]
fading_function_on = False
The :ref:`survey detection efficiency<fading>` is disabled if the fading function section of the config file is removed or not included (When fadind_function_width and fadind_function_peak_efficency have not been given).

Turning Off the Camera Footprint Filter
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,6 @@ camera_model = footprint
footprint_edge_threshold = 2.


[FADINGFUNCTION]

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


[OUTPUT]

# Output format of the output file[s]
Expand Down
37 changes: 11 additions & 26 deletions src/sorcha/utilities/sorchaConfigs.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,25 +417,10 @@ def _validate_fadingfunction_configs(self):
None
"""

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:

if self.fading_function_width is not None and self.fading_function_peak_efficiency is not None:
self.fading_function_on = True
# when fading_function_on = true, fading_function_width and fading_function_peak_efficiency now mandatory
check_key_exists(self.fading_function_width, "fading_function_width")
check_key_exists(self.fading_function_peak_efficiency, "fading_function_peak_efficiency")

self.fading_function_width = cast_as_float(self.fading_function_width, "fading_function_width")
self.fading_function_peak_efficiency = cast_as_float(
self.fading_function_peak_efficiency, "fading_function_peak_efficiency"
Expand All @@ -457,15 +442,15 @@ def _validate_fadingfunction_configs(self):
)
sys.exit("ERROR: fading_function_peak_efficiency out of bounds. Must be between 0 and 1.")

elif self.fading_function_on == False:
# making sure these aren't populated when self.fading_function_on = False
check_key_doesnt_exist(
self.fading_function_width, "fading_function_width", "but fading_function_on is False."
elif self.fading_function_width is None and self.fading_function_peak_efficiency is None:
self.fading_function_on = False

else:
logging.error(
"ERROR: Both fading_function_peak_efficiency and fading_function_width are needed to be supplied for fading function"
)
check_key_doesnt_exist(
self.fading_function_peak_efficiency,
"fading_function_peak_efficiency",
"but fading_function_on is False.",
sys.exit(
"ERROR: Both fading_function_peak_efficiency and fading_function_width are needed to be supplied for fading function"
)


Expand Down
42 changes: 1 addition & 41 deletions tests/sorcha/test_sorchaConfigs.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,46 +611,6 @@ def test_fadingfunctionConfig_on_float(key_name):



@pytest.mark.parametrize(
"key_name", ["fading_function_width", "fading_function_peak_efficiency"]
)
def test_fadingfunction_mandatory(key_name):
"""
this loops through the mandatory keys and keys that shouldn't exist and makes sure the code fails correctly when each is missing
"""

fadingfunction_configs = correct_fadingfunction.copy()

del fadingfunction_configs[key_name]

with pytest.raises(SystemExit) as error_text:
test_configs = fadingfunctionConfigs(**fadingfunction_configs)

assert (
error_text.value.code
== f"ERROR: No value found for required key {key_name} in config file. Please check the file and try again."
)


@pytest.mark.parametrize("key_name", ["fading_function_width", "fading_function_peak_efficiency"])
def test_fadingfunction_notrequired(key_name):
"""
This loops through the not required keys and makes sure the code fails correctly when they're truthy
"""

# tests that "fading_function_width" and "fading_function_peak_efficiency" are not called when "fading_function_on" is false
fadingfunction_configs = correct_fadingfunction.copy()
fadingfunction_configs["fading_function_on"] = "False"
fadingfunction_configs["fading_function_width"] = None
fadingfunction_configs["fading_function_peak_efficiency"] = None
fadingfunction_configs[key_name] = 0.5
with pytest.raises(SystemExit) as error_text:
test_configs = fadingfunctionConfigs(**fadingfunction_configs)
assert (
error_text.value.code == f"ERROR: {key_name} supplied in config file but fading_function_on is False."
)


@pytest.mark.parametrize("key_name", ["fading_function_width", "fading_function_peak_efficiency"])
def test_fadingfunction_outofbounds(key_name):
"""
Expand Down Expand Up @@ -680,7 +640,7 @@ def test_fadingfunction_allnone():
"""
fadingfunction_configs = correct_fadingfunction.copy()
fadingfunction_configs["fading_function_on"] = None
fadingfunction_configs["fading_function_width"] = None
fadingfunction_configs["fading_function_width"] = 5.0
fadingfunction_configs["fading_function_peak_efficiency"] = None
with pytest.raises(SystemExit) as error_text:
test_configs = fadingfunctionConfigs(**fadingfunction_configs)
Expand Down

0 comments on commit 0bfc9cc

Please sign in to comment.