opticks.utils.parser_helpers

Package for Pydantic and YAML helpers.

Module Attributes

PydanticQty

Annotated Quantity type for use in Pydantic models.

PositivePydanticQty

Annotated Quantity type for use in Pydantic models, restricted to positive values.

Functions

is_quantity(quantity_text)

Checks whether the quantity_text can be parsed as a valid Quantity object.

PositivePydanticQty

Annotated Quantity type for use in Pydantic models, restricted to positive values.

alias of Annotated[Quantity, BeforeValidator(func=_parse_quantity, json_schema_input_type=PydanticUndefined), AfterValidator(func=_validate_positive_quantity), PlainSerializer(func=_serialize_quantity, return_type=str, when_used=always)]

PydanticQty

Annotated Quantity type for use in Pydantic models.

Parses strings like ‘12905 mm’ into astropy Quantity objects, and serializes them back to strings.

alias of Annotated[Quantity, BeforeValidator(func=_parse_quantity, json_schema_input_type=PydanticUndefined), PlainSerializer(func=_serialize_quantity, return_type=str, when_used=always)]

is_quantity(quantity_text)[source]

Checks whether the quantity_text can be parsed as a valid Quantity object.

Return type:

bool

Parameters:

quantity_text (str) – Text that will be parsed as a Quantity object

Returns:

is_quantity (bool) – True if text can be parsed, False otherwise