File: regions_parse.py

package info (click to toggle)
astropy-regions 0.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,096 kB
  • sloc: python: 7,703; makefile: 117
file content (51 lines) | stat: -rw-r--r-- 1,139 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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
# Licensed under a 3-clause BSD style license - see LICENSE.rst

from pathlib import Path

import click
import pyregion
from astropy import log

from regions import read_ds9

log.setLevel('DEBUG')

TEST_FILE_DIR = Path('../regions/io/ds9/tests/data')


@click.group()
def cli():
    """
    Region parser debugging tool.
    """
    pass


@cli.command('list-files')
def list_files():
    print('Available files')
    for ffile in TEST_FILE_DIR.glob('*.reg'):
        print(ffile.parts[-1])


@cli.command('parse')
@click.option('--interactive', is_flag=True, default=False)
@click.option('--parser', default='regions')
@click.option('--errors', default='strict')
@click.argument('filename')
def parse(filename, interactive, parser, errors):
    readname = TEST_FILE_DIR / filename
    print(f'Reading {readname}')
    print(f'Using parser {parser}')
    if parser == 'regions':
        regions = read_ds9(str(readname), errors=errors)
    elif parser == 'pyregion':
        regions = pyregion.open(str(readname))
    print(regions)
    if interactive:
        import IPython
        IPython.embed()


if __name__ == '__main__':
    cli()