<commit_before>#!/usr/bin/env python3
#
# Copyright (c) 2017 <NAME> <<EMAIL>>
# MIT license
#
# <NAME>
# 2017-02-06

"""
Determine the Chandra ACIS type for the given observation.
"""

import argparse
import subprocess
import re

from setup_pfiles import setup_pfiles


def get_acis_type(infile):
    """
    Determine the Chandra ACIS type (``I`` or ``S``) according the
    active ACIS chips.

    Parameters
    ----------
    infile : str
        Filename of the FITS file

    Returns
    -------
    acis_type : str
        ``I`` if ACIS-I, ``S`` if ACIS-S, otherwise, ``ValueError`` raised.
    """
    subprocess.check_call(["punlearn", "dmkeypar"])
    detnam = subprocess.check_output([
        "dmkeypar", "infile=%s" % infile, "keyword=DETNAM", "echo=yes"
    ]).decode("utf-8").strip()
    if re.match(r"^ACIS-0123", detnam):
        return "I"
    elif re.match(r"^ACIS-[0-6]*7", detnam):
        return "S"
    else:
        raise ValueError("unknown chip combination: %s" % detnam)


def main():
    parser = argparse.ArgumentParser(description="Determine Chandra ACIS type")
    parser.add_argument("-b", "--brief", dest="brief",
                        action="store_true", help="Be brief")
    parser.add_argument("infile", help="Input FITS file")
    args = parser.parse_args()

    setup_pfiles(["dmkeypar"])
    acis_type = get_acis_type(args.infile)
    if not args.brief:
        print("ACIS-type:", end=" ")
    print(acis_type)


if __name__ == "__main__":
    main()<commit_msg>chandra_acis.py: Add function "get_chips()"<commit_after>#!/usr/bin/env python3
#
# Copyright (c) 2017 <NAME> <<EMAIL>>
# MIT license
#
# <NAME>
# 2017-02-06

"""
Determine the Chandra ACIS type for the given observation.

TODO: move these methods to module `acis.py`
"""

import argparse
import subprocess
import re

from setup_pfiles import setup_pfiles


def get_acis_type(filepath):
    """
    Determine the Chandra ACIS type (``I`` or ``S``) according the
    active ACIS chips.

    Parameters
    ----------
    filepath : str
        Path to the input FITS file

    Returns
    -------
    acis_type : str
        ``I`` if ACIS-I, ``S`` if ACIS-S, otherwise, ``ValueError`` raised.
    """
    subprocess.check_call(["punlearn", "dmkeypar"])
    detnam = subprocess.check_output([
        "dmkeypar", "infile=%s" % filepath, "keyword=DETNAM", "echo=yes"
    ]).decode("utf-8").strip()
    if re.match(r"^ACIS-0123", detnam):
        return "I"
    elif re.match(r"^ACIS-[0-6]*7", detnam):
        return "S"
    else:
        raise ValueError("unknown chip combination: %s" % detnam)


def get_chips(filepath, sep=":"):
    """
    Get the corresponding chips of interest according to the active ACIS type.

    Parameters
    ----------
    filepath : str
        Path to the input FITS file
    sep : str, optional
        Separator to join the chip ranges, e.g., 0:3, 0-3

    Returns
    -------
    chips : str
        ``0:3`` if ACIS-I, ``7`` if ACIS-S, otherwise, ``ValueError`` raised.
    """
    acis_type = get_acis_type(filepath)
    if acis_type == "I":
        return sep.join(["0", "3"])
    elif acis_type == "S":
        return "7"
    else:
        raise ValueError("unknown ACIS type")


def main():
    parser = argparse.ArgumentParser(description="Determine Chandra ACIS type")
    parser.add_argument("-b", "--brief", dest="brief",
                        action="store_true", help="Be brief")
    parser.add_argument("infile", help="Input FITS file")
    args = parser.parse_args()

    setup_pfiles(["dmkeypar"])
    acis_type = get_acis_type(args.infile)
    if not args.brief:
        print("ACIS-type:", end=" ")
    print(acis_type)


if __name__ == "__main__":
    main()
{'fraction_non_alphanumeric': 0.15773889636608346, 'fraction_numerical': 0.013997308209959623, 'mean_word_length': 2.745967741935484, 'pattern_counts': {'":': 5, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1038051', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1237, 'n_words': 324}