Skip to content

pilot_fields_info.py

A script to query the VAST Pilot Survey observations.

Includes options to show PSF sizes and saving the outputs to file.

Example
pilot_fields_info VAST_0532-50A VAST_1212+00A VAST_2257-06A

Attributes:

Name Type Description
runstart datetime

The running start time of the script.

main()

The main function.

Returns:

Type Description
None

None

Source code in vasttools/bin/pilot_fields_info.py
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
def main() -> None:
    """The main function.

    Returns:
        None
    """
    args = parse_args()
    os.nice(args.nice)

    logfile = "pilot_fields_info_{}.log".format(
        runstart.strftime("%Y%m%d_%H:%M:%S"))
    logger = get_logger(args.debug, args.quiet, logfile=logfile)

    if len(args.fields) == 1:
        file_name = args.fields[0]
        if os.path.isfile(file_name):
            logger.info("Input file detected - reading file...")
            fields = read_fields(file_name)
            if len(fields) == 0:
                logger.error(
                    "Failed to read any fields from {}!".format(
                        file_name
                    )
                )
                sys.exit()
        else:
            fields = args.fields
    else:
        fields = args.fields

    if sum([args.psf, args.largest_psf, args.common_psf]) > 1:
        logger.warning(
            "More than one psf option has been selected."
            " Please correct and re-run."
        )
        sys.exit()

    logger.info("Will find information for the following fields:")
    [logger.info(i) for i in fields]

    for i, field in enumerate(fields):
        query = FieldQuery(field)
        if i == 0:
            query.run_query(
                psf=args.psf,
                largest_psf=args.largest_psf,
                common_psf=args.common_psf,
                all_psf=args.all_psf,
                save=args.save
            )
            try:
                pilot_info = query.pilot_info
            except Exception as e:
                continue
        else:
            query.run_query(
                psf=args.psf,
                largest_psf=args.largest_psf,
                common_psf=args.common_psf,
                all_psf=args.all_psf,
                save=args.save,
                _pilot_info=pilot_info
            )

    runend = datetime.datetime.now()
    runtime = runend - runstart
    logger.info(
        "Processing took {:.1f} minutes.".format(
            runtime.seconds / 60.))

parse_args()

Parse the arguments.

Returns:

Type Description
Namespace

The argument namespace.

Source code in vasttools/bin/pilot_fields_info.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
def parse_args() -> argparse.Namespace:
    """
    Parse the arguments.

    Returns:
        The argument namespace.
    """
    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument(
        'fields',
        type=str,
        nargs="+",
        help='Fields to query (or csv file containing fields).')
    parser.add_argument(
        '--psf',
        action="store_true",
        help=(
            'Include the used PSF of the 36'
            ' beams that make up the field.'
            ' Usually set from beam 00.'
            ))
    parser.add_argument(
        '--largest-psf',
        action="store_true",
        help=(
            'Include the largest PSF of the 36'
            ' beams that make up the field.'
            ))
    parser.add_argument(
        '--common-psf',
        action="store_true",
        help=(
            'Include the common PSF of the 36'
            ' beams that make up the field.'
            ))
    parser.add_argument(
        '--all-psf',
        action="store_true",
        help='Include all the PSF information for the field.')
    parser.add_argument(
        '--save',
        action="store_true",
        help=(
            "Save the resulting information."
            " Files will be saved to the current working directory"
            " in the form of 'VAST_XXXX+/-XXA_field_info.csv'."
        ))
    parser.add_argument(
        '--quiet',
        action="store_true",
        help='Turn off non-essential terminal output.')
    parser.add_argument(
        '--debug',
        action="store_true",
        help='Turn on debug output.')
    parser.add_argument(
        '--nice',
        type=int,
        help='Set nice level.',
        default=5)

    args = parser.parse_args()

    return args

read_fields(fields_file)

Reads the field names from the input file.

Parameters:

Name Type Description Default
fields_file str

The path of the input file containing the field names.

required

Returns:

Type Description
List[str]

List of field names to query.

Source code in vasttools/bin/pilot_fields_info.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
def read_fields(fields_file: str) -> List[str]:
    """Reads the field names from the input file.

    Args:
        fields_file: The path of the input file containing the field names.

    Returns:
        List of field names to query.
    """
    fields = pd.read_csv(fields_file, comment='#')
    try:
        fields = fields.field_name.to_list()
    except Exception as e:
        logger.error("Could not find column 'field_name' in file.")
        fields = []
    return fields