Skip to content

Units of azimuth and zenith in event header are wrong, should be rad #32

Closed
@VictorBarbosaMartins

Description

@VictorBarbosaMartins

After discussions with @orelgueta , we have decided to open this issue due to 2 reasons:

1 - It seems that the units for azimuth and zenith are not correct here (they are actually given in radians):

Field(11, "zenith", unit="deg"),
Field(12, "azimuth", unit="deg"),

I came across this by testing the implementation of the corsika output module in gammasim-tools. I suggest to change the two units to "rad".

2 - It would be very useful for us in the gammasim-tools team to have the units of the Fields in the event_header and run_header as astropy.units. Given that some of the "units" are non-trivial (e.g. GeV/c), I had to implement a quick solution that is working for us in gammasim-tools and that I copy it here as a suggestion or starting point:

def parse_astropy_unit(unit_in_string):
    """
    Convert units passed in form of a string to astropy.units.Unity.

    Parameters
    ----------
    unit_in_string: str
        Unit to be parsed, e.g. GeV/c
    """

    try:
        astropy_unit = u.Unit(unit_in_string)
    except ValueError:
        # Define the possible math operatos present in the string
        ops_symbol = {
            "+": operator.add,
            "-": operator.sub,
            "/": operator.truediv,
            "*": operator.mul,
            "^": operator.pow,
        }
        # Define the initial unit as dimensionless
        astropy_unit = u.dimensionless_unscaled
        for symbol in ops_symbol:
            # Split the given string according to the math operators
            splitted_unit_string = unit_in_string.split(symbol)
            # If it was indeed split into more than 1 piece, we handle it below
            if len(splitted_unit_string) > 1:
                for unit in splitted_unit_string:
                    # For now, `c` is the only constant that needed this manual adjustment.
                    if unit == "c":
                        unit = const.c
                    # For each unit element we use the current operator to bring it to the final
                    # unit.
                    astropy_unit = ops_symbol[symbol](astropy_unit, u.Unit(unit))
    return astropy_unit

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions