Skip to content

Output

Parser turns a circular into Output, an object containing extracted claims along with metadata about the circular and the parser run. You can serialize Output with to_json() and restore it later with Output.from_json(). Output.info.calls records every model call in execution order—including any failed attempts—along with details such as the parsing stage, model, and timestamps.

Starting from Output, you can obtain a View, an object useful for exploring a parsed circular's content:

from tgcn.parser import Output

output = Output.from_json(...)
view = output.view()

Each View holds two collections: context, which contains every claim extracted from the circular, and selected, which contains the currently selected claims. Filtering and navigation return a new view with the same context.

For example, consider a circular with a subject for a transient classified as SciClass.GRB and another subject for its optical counterpart. This snippet selects the claim about the GRB subject:

from tgcn import SciClass

grbs = view.classified(SciClass.GRB)

The next snippet moves from the GRB to its optical counterpart:

counterparts = view.classified(SciClass.GRB).counterparts()

Warning

Order matters: .classified(SciClass.GRB).counterparts() does not produce the same view as .counterparts().classified(SciClass.GRB). The first selects claims about counterparts of subjects classified as a GRB. The second selects claims about subjects that are counterparts of any subject and are themselves classified as a GRB.

The View interface makes it easy to explore a parsed circular with a fluent, readable syntax. The next snippet extracts localization quantities, if any, for all of the GRB's counterparts:

from tgcn import SciClass

locs = view.classified(SciClass.GRB).counterparts().localizations

tgcn.Output

A parsed circular, with info on parser and model calls.

Provide methods for importing and exporting in JSON format, and to opt-in a view.

Attributes:

Name Type Description
info Info

versions for software and parser, circular ID and a recap on model calls.

claims tuple[Claim, ...]

the claims parsed from the circular.

from_json

from_json(payload: str | bytes) -> Self

Loads a parsed circular from JSON.

Parameters:

Name Type Description Default
payload str | bytes

JSON produced by to_json, as text or bytes.

required

Returns:

Type Description
Self

A parsed circular with the input claims and info.

Raises:

Type Description
ValidationError

The payload is invalid JSON or does not match the serialized claims schema.

to_json

to_json() -> str

Serialize the output to JSON.

Returns:

Type Description
str

A JSON string containing the claims and their provenance.

view

view() -> View

Returns a view interface for exploring the parsed circular content.

Returns:

Type Description
View

A View object.

tgcn.View

An immutable view of claims parsed from a circular.

Read quantities from the current selection or navigate to related subjects.

Attributes:

Name Type Description
selected tuple[Claim, ...]

Claims in the current selection.

context tuple[Claim, ...]

Claims available for navigation.

Examples:

Extract all X-ray and gamma fluxes, if any, from a parsed circular:

view.he_fluxes

Get redshifts reported for host subjects:

view.hosts().redshifts

Get magnitudes for counterparts to subjects classified as long GRBs:

from tgcn import SciClass

view.classified(SciClass.LONG_GRB).counterparts().magnitudes

detections

detections: list[DetectionTime]

Return claims detection times.

durations

durations: list[T90 | T50]

Return claims T90 and T50 durations.

he_fluences

he_fluences: list[HEFluence]

Return claims high-energy fluences.

he_fluxes

he_fluxes: list[HEFlux | UpperLimit[HEFlux]]

Return claims high-energy fluxes and their upper limits.

instruments

instruments: list[Instrument]

Return unique instruments in first-seen order, including limits.

localizations

localizations: list[Localization]

Return all claims localizations.

magnitudes

magnitudes: list[Magnitude | UpperLimit[Magnitude]]

Return claims magnitudes and their upper limits.

quantities

quantities: list[Quantity]

Return all quantities in claims order.

radio_fluxes

radio_fluxes: list[RadioFlux | UpperLimit[RadioFlux]]

Return claims radio flux densities and their upper limits.

redshifts

redshifts: list[Redshift]

Return claims redshifts.

__post_init__

__post_init__() -> None

Check input to be a tuple and that each selected subject is present in the context.

classified

classified(classification: SciClass, *, include_uncertain: bool = True, include_negated: bool = False) -> Self

Select this class and its subtypes. Negated classes match exactly.

Parameters:

Name Type Description Default
classification SciClass

Scientific class to match.

required
include_uncertain bool

Whether to match uncertain classifications.

True
include_negated bool

Whether to match negated classifications.

False

Returns:

Type Description
Self

A view containing matching claims from the current selection.

counterparts

counterparts(*, include_uncertain: bool = True, include_negated: bool = False) -> Self

Navigates to counterparts, optionally including negated and uncertain relations.

Parameters:

Name Type Description Default
include_uncertain bool

Whether to follow uncertain relations.

True
include_negated bool

Whether to follow negated relations.

False

Returns:

Type Description
Self

A view containing counterpart claims from the full circular context.

hosts

hosts(*, include_uncertain: bool = True, include_negated: bool = False) -> Self

Navigates to hosts, optionally including negated and uncertain relations.

Parameters:

Name Type Description Default
include_uncertain bool

Whether to follow uncertain relations.

True
include_negated bool

Whether to follow negated relations.

False

Returns:

Type Description
Self

A view containing host claims from the full circular context.

localization_compatible

localization_compatible(*, include_uncertain: bool = True, include_negated: bool = False) -> Self

Follow localization compatibility one hop in either direction, optionally including negated and uncertain relations.

Parameters:

Name Type Description Default
include_uncertain bool

Whether to follow uncertain relations.

True
include_negated bool

Whether to follow negated relations.

False

Returns:

Type Description
Self

A view containing claims for localization-compatible subjects from

Self

the full circular context.

related_by

related_by(kind: RelationKind | str, *, include_uncertain: bool = True, include_negated: bool = False) -> Self

Navigate one hop to subjects linked by the given relation kind.

Host and counterpart queries return the subjects in those roles. Localization compatibility can be followed in either direction.

Parameters:

Name Type Description Default
kind RelationKind | str

Relation kind or its string value.

required
include_uncertain bool

Whether to follow uncertain relations.

True
include_negated bool

Whether to follow negated relations.

False

Returns:

Type Description
Self

A view containing destination claims from the full circular context.

Raises:

Type Description
ValueError

kind is an unknown relation kind.

subject

subject(identifier: str) -> Self

Select claims matching an ID or alias.

Parameters:

Name Type Description Default
identifier str

Subject ID or alias. Exact IDs take precedence over aliases in the full circular context.

required

Returns:

Type Description
Self

A view containing matching claims from the current selection.

tgcn.parser.Info

Provenance of a parsed circular.

calls

calls: tuple[InfoCall, ...]

Model call records in attempt order, including failed attempts.

circularId

circularId: Annotated[StrictInt, Field(ge=0)]

GCN circular number.

circular_version

circular_version: Annotated[StrictInt, Field(ge=0)] | None = None

GCN circular version.

completed_at

completed_at: AwareDatetime

A datetime ISO 8601 timestamp for when the parser completed.

id

id: UUID4

A unique identifier for the parser output.

version

version: str

Package version that produced the output.

version_parser

version_parser: str

Parser version that produced the output.

tgcn.parser.InfoCall

Safe for export metadata for one model call.

completed_at

completed_at: AwareDatetime

A datetime ISO 8601, UTC timestamp for when the call completed.

model

model: str

Request settings used for the call.

stage

stage: Stage

Parsing stage that made the call.

success

success: bool

Whether the response was parsed and processed successfully.