Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Revision d745e74710ab581d489e815095d0dd4ee91e9c35 authored by Bryna Hazelton on 15 September 2025, 18:00:43 UTC, committed by Jonathan Pober on 15 September 2025, 18:31:58 UTC
remove macos-13 from our CI matrix because it is deprecated
1 parent ea19da5
  • Files
  • Changes
  • 0617af3
  • /
  • scripts
  • /
  • fhd_batch_convert.py
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • revision
  • directory
  • content
revision badge
swh:1:rev:d745e74710ab581d489e815095d0dd4ee91e9c35
directory badge
swh:1:dir:5cb9d966777e4709e445efe230c8d8cbeee7aa7c
content badge
swh:1:cnt:2e4c0415b060cfb0546b692b6edbf36af2cee265

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • revision
  • directory
  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
fhd_batch_convert.py
#! /usr/bin/env python
# Copyright (c) 2018 Radio Astronomy Software Group
# Licensed under the 2-clause BSD License
"""Convert multiple FHD datasets to UVFITS format."""

import argparse
import os
import os.path as op
import re

from pyuvdata import UVData


def parse_range(string):
    """Parse numbers from a range string."""
    m = re.match(r"(\d+)(?:-(\d+))?$", string)
    if not m:
        raise argparse.ArgumentTypeError(
            f"'{string}' is not a range of numbers. Expected forms like '0-5' or '2'."
        )
    start = int(m.group(1))
    end = int(m.group(2)) or start

    return start, end


parser = argparse.ArgumentParser()
parser.add_argument(
    "fhd_run_folder",
    help="name of an FHD output folder that contains a "
    "vis_data folder and a metadata folder",
)
parser.add_argument(
    "--obsid_range",
    type=parse_range,
    help="range of obsids to use, can be a single value or "
    "a min and max with a dash between",
)
parser.add_argument(
    "--no-dirty",
    dest="dirty",
    action="store_false",
    help="do not convert dirty visibilities",
)
parser.set_defaults(dirty=True)
parser.add_argument(
    "--no-model",
    dest="model",
    action="store_false",
    help="do not convert model visibilities",
)
parser.set_defaults(model=True)
args = parser.parse_args()

vis_folder = op.join(args.fhd_run_folder, "vis_data")
if not op.isdir(vis_folder):
    raise OSError(f"There is no vis_data folder in {args.fhd_run_folder}")

metadata_folder = op.join(args.fhd_run_folder, "metadata")
if not op.isdir(vis_folder):
    raise OSError(f"There is no metadata folder in {args.fhd_run_folder}")

output_folder = op.join(args.fhd_run_folder, "uvfits")
if not op.exists(output_folder):
    os.mkdir(output_folder)

files = []
obsids = []
for f in os.listdir(vis_folder):
    files.append(op.join(vis_folder, f))

for f in os.listdir(metadata_folder):
    files.append(op.join(metadata_folder, f))

file_dict = {}
for f in files:
    dirname, fname = op.split(f)
    fparts = fname.split("_")
    try:
        obsid = int(fparts[0])
        if obsid in file_dict:
            file_dict[obsid].append(f)
        else:
            file_dict[obsid] = [f]
    except ValueError:
        continue

try:
    obs_min = args.obsid_range[0]
    obs_max = args.obsid_range[1]
except TypeError:
    obs_min = min(file_dict.keys())
    obs_max = max(file_dict.keys())

for k in list(file_dict.keys()):
    if k > obs_max or k < obs_min:
        file_dict.pop(k)

for i, (k, v) in enumerate(file_dict.items()):
    if args.dirty:
        print(f"converting dirty vis for obsid {k}, ({i} of {len(file_dict)})")
        uvfits_file = op.join(output_folder, str(k) + ".uvfits")
        this_uv = UVData()
        this_uv.read_fhd(v)

        this_uv.write_uvfits(uvfits_file, spoof_nonessential=True)

        del this_uv

    if args.model:
        print(f"converting model vis for obsid {k}, ({i} of {len(file_dict)})")
        uvfits_file = op.join(output_folder, str(k) + "_model.uvfits")
        this_uv = UVData()
        this_uv.read_fhd(v, use_model=True)

        this_uv.write_uvfits(uvfits_file, spoof_nonessential=True)

        del this_uv
The diff you're trying to view is too large. Only the first 1000 changed files have been loaded.
Showing with 0 additions and 0 deletions (0 / 0 diffs computed)
swh spinner

Computing file changes ...

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API