Skip to content

Fix flux density unit change on preprocess, Change Axis Label style - #57

Open
tgross03 wants to merge 3 commits into
mainfrom
fix_fiducial_flux
Open

tgross03 wants to merge 3 commits into
mainfrom
fix_fiducial_flux

Conversation

@tgross03

@tgross03 tgross03 commented Aug 4, 2026

Copy link
Copy Markdown
Member
  • Fix: Fix flux density unit change on preprocess
  • Chore: Change Axis Label style for fiducial plots

@tgross03
tgross03 requested a review from aknierim August 4, 2026 20:58
@codecov-commenter

codecov-commenter commented Aug 4, 2026

Copy link
Copy Markdown

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
15 1 14 0
View the top 1 failed test(s) by shortest run time
tests/test_fiducial.py::TestFiducial::test_plot
Stack Traces | 0.344s run time
cls = <class 'astropy.units.core.Unit'>, s = 'JY', represents = None
format = None, namespace = None, doc = None, parse_strict = 'raise'

    def __call__(
        cls,
        s="",
        represents=None,
        format=None,
        namespace=None,
        doc=None,
        parse_strict="raise",
    ):
        # Short-circuit if we're already a unit
        if hasattr(s, "_physical_type_id"):
            return s
    
        if represents is not None:
            # This has the effect of calling the real __new__ and
            # __init__ on the Unit class.
            return super().__call__(
                s, represents, format=format, namespace=namespace, doc=doc
            )
    
        if isinstance(s, (str, bytes)):
            if len(s.strip()) == 0:
                # Return the NULL unit
                return dimensionless_unscaled
    
            from .format import Generic, get_format
    
            try:
                f = get_format(format)
            except (TypeError, ValueError) as err:
                from .format import known_parsers
    
                err.add_note(known_parsers())
                raise err
            if isinstance(s, bytes):
                s = s.decode("ascii")
    
            try:
                return f._validate_unit(s)  # Try a shortcut
            except (AttributeError, KeyError):
                # No `f._validate_unit()` (AttributeError)
                # or `s` was a composite unit (KeyError).
                pass
    
            try:
                with (
                    _WARNING_LOCK,
                    warnings.catch_warnings(
                        action=_WARNING_ACTIONS[parse_strict],
                        category=UnitParserWarning,
                    ),
                ):
>                   return f.parse(s)
                           ^^^^^^^^^^

../../...../radiotools-dev/lib/python3.11.../astropy/units/core.py:2070: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
../../...../radiotools-dev/lib/python3.11.../units/format/generic.py:501: in parse
    result = cls._do_parse(s, debug)
             ^^^^^^^^^^^^^^^^^^^^^^^
../../...../radiotools-dev/lib/python3.11.../units/format/base.py:225: in _do_parse
    return cls._parser.parse(s, lexer=cls._lexer, debug=debug)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../...../radiotools-dev/lib/python3.11.../astropy/utils/parsing.py:109: in parse
    return self.parser.parse(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../...../radiotools-dev/lib/python3.11.../extern/ply/yacc.py:333: in parse
    return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../../...../radiotools-dev/lib/python3.11.../extern/ply/yacc.py:1063: in parseopt_notrack
    lookahead = get_token()     # Get the next token
                ^^^^^^^^^^^
../../...../radiotools-dev/lib/python3.11.../extern/ply/lex.py:350: in token
    newtok = func(tok)
             ^^^^^^^^^
../../...../radiotools-dev/lib/python3.11.../units/format/generic.py:100: in t_UNIT
    t.value = cls._get_unit(t)
              ^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cls = <class 'astropy.units.format.generic.Generic'>
t = LexToken(UNIT,'JY',1,0)

    @classmethod
    def _get_unit(cls, t: LexToken) -> UnitBase:
        try:
            return cls._validate_unit(t.value)
        except KeyError:
            registry = get_current_unit_registry()
            if t.value in registry.aliases:
                return registry.aliases[t.value]
    
>           raise ValueError(
                f"At col {t.lexpos}, {cls._invalid_unit_error_message(t.value)}"
            ) from None
E           ValueError: At col 0, JY is not a valid unit. Did you mean Jy, µJy or μJy?

../../...../radiotools-dev/lib/python3.11.../units/format/base.py:241: ValueError

During handling of the above exception, another exception occurred:

self = <test_fiducial.TestFiducial object at 0x7f219128b510>

    def test_plot(self):
        path = download_fits()
        fiducial = Fiducial(fits_path=path)
    
>       fiducial.plot()

tests/test_fiducial.py:97: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
.../radiotools/fiducial/fiducial.py:653: in plot
    flux_unit_full = units.Unit(flux_unit_components[0]) / units.Unit(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

cls = <class 'astropy.units.core.Unit'>, s = 'JY', represents = None
format = None, namespace = None, doc = None, parse_strict = 'raise'

    def __call__(
        cls,
        s="",
        represents=None,
        format=None,
        namespace=None,
        doc=None,
        parse_strict="raise",
    ):
        # Short-circuit if we're already a unit
        if hasattr(s, "_physical_type_id"):
            return s
    
        if represents is not None:
            # This has the effect of calling the real __new__ and
            # __init__ on the Unit class.
            return super().__call__(
                s, represents, format=format, namespace=namespace, doc=doc
            )
    
        if isinstance(s, (str, bytes)):
            if len(s.strip()) == 0:
                # Return the NULL unit
                return dimensionless_unscaled
    
            from .format import Generic, get_format
    
            try:
                f = get_format(format)
            except (TypeError, ValueError) as err:
                from .format import known_parsers
    
                err.add_note(known_parsers())
                raise err
            if isinstance(s, bytes):
                s = s.decode("ascii")
    
            try:
                return f._validate_unit(s)  # Try a shortcut
            except (AttributeError, KeyError):
                # No `f._validate_unit()` (AttributeError)
                # or `s` was a composite unit (KeyError).
                pass
    
            try:
                with (
                    _WARNING_LOCK,
                    warnings.catch_warnings(
                        action=_WARNING_ACTIONS[parse_strict],
                        category=UnitParserWarning,
                    ),
                ):
                    return f.parse(s)
            except NotImplementedError:
                raise
            except UnitParserWarning as err:
                new_err = ValueError(err)
                new_err.add_note(
                    "If you cannot change the unit string then try specifying the "
                    "'parse_strict' argument."
                )
                raise new_err from err
            except KeyError as err:
                if parse_strict in _WARNING_ACTIONS:
                    raise
                raise ValueError(
                    "'parse_strict' must be 'warn', 'raise' or 'silent'"
                ) from None
            except Exception as e:
                if parse_strict != "silent":
                    # Deliberately not issubclass here. Subclasses
                    # should use their name.
                    format_clause = "" if f is Generic else f.name + " "
                    msg = (
                        f"'{s}' did not parse as {format_clause}unit: {str(e)} "
                        "If this is meant to be a custom unit, "
                        "define it with 'u.def_unit'. To have it "
                        "recognized inside a file reader or other code, "
                        "enable it with 'u.add_enabled_units'. "
                        "For details, see "
                        "https://docs.astropy..../latest/units/combining_and_defining.html"
                    )
                    if parse_strict == "raise":
>                       raise ValueError(msg)
E                       ValueError: 'JY' did not parse as unit: At col 0, JY is not a valid unit. Did you mean Jy, µJy or μJy? If this is meant to be a custom unit, define it with 'u.def_unit'. To have it recognized inside a file reader or other code, enable it with 'u.add_enabled_units'. For details, see https://docs.astropy..../latest/units/combining_and_defining.html

../../...../radiotools-dev/lib/python3.11.../astropy/units/core.py:2101: ValueError

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants