Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions autoarray/config/visualize/general.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ colormap: autoarray # Default colormap for 2D plots. Use any matpl
ticks:
extent_factor_2d: 0.75 # Fraction of half-extent used for 2D tick positions (< 1.0 pulls ticks inward from edges).
number_of_ticks_2d: 3 # Number of ticks on each spatial axis of 2D plots.
symbol_over_decimal: false # If true, place the arcsec double-prime symbol over the decimal point, e.g. 3.″8, instead of after the value, e.g. 3.8".
contour:
total_contours: 10 # Number of contour levels drawn over log10 (and explicit linear) plots.
include_values: true # Whether to label each contour line with its value.
Expand Down
23 changes: 22 additions & 1 deletion autoarray/plot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,14 @@ def _conf_ticks(key: str, default: float) -> float:
return default


def _conf_ticks_flag(key: str, default: bool) -> bool:
try:
from autoconf import conf
return bool(conf.instance["visualize"]["general"]["ticks"][key])
except Exception:
return default


def _inward_ticks(lo: float, hi: float, factor: float, n: int) -> np.ndarray:
"""Return *n* tick positions pulled inward from the extent edges by *factor*."""
centre = (lo + hi) / 2.0
Expand Down Expand Up @@ -895,11 +903,24 @@ def _arcsec_labels(ticks) -> List[str]:
"""Format tick values as arcsecond coordinate strings.

Values that all end in ``.0`` are stripped of the decimal point before the
``"`` suffix is appended, so ``[-1.0, 0.0, 1.0]`` → ``['-1"', '0"', '1"']``.
``"`` suffix is appended, so ``[-1.0, 0.0, 1.0]`` becomes
``['-1"', '0"', '1"']``. By default decimal labels keep the suffix form
``3.8"``. When ``ticks.symbol_over_decimal`` is true, labels use the
double-prime arcsecond symbol and decimal labels place it over the decimal
point, e.g. ``3.″8``.
"""
labels = [f'{v:g}' for v in ticks]
if all(label.endswith(".0") for label in labels):
labels = [label[:-2] for label in labels]
if _conf_ticks_flag("symbol_over_decimal", False):
symbol_labels = []
for label in labels:
if "." in label:
int_part, frac_part = label.split(".", 1)
symbol_labels.append(f"{int_part}.″{frac_part}")
else:
symbol_labels.append(f"{label}″")
return symbol_labels
return [f'{label}"' for label in labels]


Expand Down
26 changes: 26 additions & 0 deletions test_autoarray/plot/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from autoconf import conf

from autoarray.plot.utils import _arcsec_labels


def test_arcsec_labels_default_suffix_format():
conf.instance["visualize"]["general"]["ticks"]["symbol_over_decimal"] = False

assert _arcsec_labels([-1.0, 0.0, 1.0]) == ['-1"', '0"', '1"']
assert _arcsec_labels([3.8]) == ['3.8"']
Comment on lines +6 to +10


def test_arcsec_labels_symbol_over_decimal():
ticks = conf.instance["visualize"]["general"]["ticks"]
original = ticks.get("symbol_over_decimal", False)
try:
ticks["symbol_over_decimal"] = True

assert _arcsec_labels([-1.69, 0.13, 1.95]) == [
"-1.″69",
"0.″13",
"1.″95",
]
assert _arcsec_labels([3.0]) == ["3″"]
finally:
ticks["symbol_over_decimal"] = original