Skip to content

model_generator.py

association_models_generator(assoc_df)

Creates a generator object containing yielded Association objects from an input pipeline association dataframe.

Parameters:

Name Type Description Default
assoc_df DataFrame

The dataframe from the pipeline containing the associations between measurements and sources.

required

Returns:

Type Description
Iterable[Generator[Association, None, None]]

An iterable generator object containing the yielded Association objects.

Source code in vast_pipeline/pipeline/model_generator.py
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
def association_models_generator(
    assoc_df: pd.DataFrame
) -> Iterable[Generator[Association, None, None]]:
    """
    Creates a generator object containing yielded Association objects from
    an input pipeline association dataframe.

    Args:
        assoc_df:
            The dataframe from the pipeline containing the associations between
            measurements and sources.

    Returns:
        An iterable generator object containing the yielded Association objects.
    """
    logger.debug(f"Building {len(assoc_df)} association generators")
    for row in assoc_df.itertuples():
        yield Association(
            meas_id=row.id,
            source_id=row.source_id,
            d2d=row.d2d,
            dr=row.dr,
        )
    logger.debug(f"Built {len(assoc_df)} association generators")

measurement_models_generator(meas_df)

Creates a generator object containing yielded Measurement objects from an input pipeline measurement dataframe.

Parameters:

Name Type Description Default
meas_df DataFrame

The dataframe from the pipeline containing the measurements of an image.

required

Returns:

Type Description
Iterable[Generator[Measurement, None, None]]

An iterable generator object containing the yielded Measurement objects.

Source code in vast_pipeline/pipeline/model_generator.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
def measurement_models_generator(
    meas_df: pd.DataFrame
) -> Iterable[Generator[Measurement, None, None]]:
    """
    Creates a generator object containing yielded Measurement objects from
    an input pipeline measurement dataframe.

    Args:
        meas_df:
            The dataframe from the pipeline containing the measurements of an
            image.

    Returns:
        An iterable generator object containing the yielded Measurement
            objects.
    """
    for row in meas_df.itertuples():
        one_m = Measurement()
        for fld in one_m._meta.get_fields():
            if getattr(fld, 'attname', None) and hasattr(row, fld.attname):
                setattr(one_m, fld.attname, getattr(row, fld.attname))
        yield one_m

related_models_generator(related_df)

Creates a generator object containing yielded Association objects from an input pipeline association dataframe.

Parameters:

Name Type Description Default
related_df DataFrame

The dataframe from the pipeline containing the relations between sources.

required

Returns:

Type Description
Iterable[Generator[RelatedSource, None, None]]

An iterable generator object containing the yielded Association objects.

Source code in vast_pipeline/pipeline/model_generator.py
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
def related_models_generator(
    related_df: pd.DataFrame
) -> Iterable[Generator[RelatedSource, None, None]]:
    """
    Creates a generator object containing yielded Association objects from
    an input pipeline association dataframe.

    Args:
        related_df:
            The dataframe from the pipeline containing the relations between
            sources.

    Returns:
        An iterable generator object containing the yielded Association objects.
    """
    for row in related_df.itertuples(index=False):
        yield RelatedSource(**row._asdict())

source_models_generator(src_df, pipeline_run)

Creates a generator object containing yielded Source objects from an input pipeline sources dataframe.

Parameters:

Name Type Description Default
src_df DataFrame

The dataframe from the pipeline containing the measurements of an image.

required
pipeline_run Run

The pipeline Run object of which the sources are associated with.

required

Returns:

Type Description
Iterable[Generator[Source, None, None]]

An iterable generator object containing the yielded Source objects.

Source code in vast_pipeline/pipeline/model_generator.py
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
def source_models_generator(
    src_df: pd.DataFrame, pipeline_run: Run
) -> Iterable[Generator[Source, None, None]]:
    """
    Creates a generator object containing yielded Source objects from
    an input pipeline sources dataframe.

    Args:
        src_df:
            The dataframe from the pipeline containing the measurements of
            an image.
        pipeline_run:
            The pipeline Run object of which the sources are associated with.

    Returns:
        An iterable generator object containing the yielded Source objects.
    """
    for row in src_df.itertuples():
        # generate an IAU compliant source name, see
        # https://cdsweb.u-strasbg.fr/Dic/iau-spec.html
        name = (
            f"J{deg2hms(row.wavg_ra, precision=1, truncate=True)}"
            f"{deg2dms(row.wavg_dec, precision=0, truncate=True)}"
        ).replace(":", "")
        src = Source()
        src.run_id = pipeline_run.id
        src.name = name
        for fld in src._meta.get_fields():
            if getattr(fld, 'attname', None) and hasattr(row, fld.attname):
                setattr(src, fld.attname, getattr(row, fld.attname))

        yield src