diff options
author | Aaron LI <aaronly.me@outlook.com> | 2017-02-19 16:29:00 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@outlook.com> | 2017-02-19 16:29:00 +0800 |
commit | 8c8e2b2fc8d88cfe8e130b2c693d01686f126d18 (patch) | |
tree | dbe5777dfad5e8dc399c3fd809ebb1f7e19c00cc | |
parent | 2aaf7d8106e7d596654c9ae1cf0fa75fd642f3eb (diff) | |
download | chandra-acis-analysis-8c8e2b2fc8d88cfe8e130b2c693d01686f126d18.tar.bz2 |
Split 'analyze_path.py' to two parts for 'acispy'
-rw-r--r-- | acispy/analyze_path.py | 53 | ||||
-rwxr-xr-x | scripts/analyze_path.py | 39 |
2 files changed, 55 insertions, 37 deletions
diff --git a/acispy/analyze_path.py b/acispy/analyze_path.py new file mode 100644 index 0000000..578a6db --- /dev/null +++ b/acispy/analyze_path.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2017 Weitian LI <liweitianux@live.com> +# MIT license +# +# Weitian LI +# 2017-02-06 + +""" +Extract the object name and observation ID from the directory path. + +The root directory of the object data has the format: + <name>_oi<obsid> +""" + +import re + + +RE_DATA_DIR = re.compile(r"^.*/(?P<name>[^/_]+)_oi(?P<obsid>\d+).*$") + + +def get_name(path): + """ + Extract the object name from the directory path. + + Parameters + ---------- + path : str + Path to the data directory + + Returns + ------- + objname : str + The name part of the data directory + """ + return RE_DATA_DIR.match(path).group("name") + + +def get_obsid(path): + """ + Extract the observation ID from the directory path. + + Parameters + ---------- + path : str + Path to the data directory + + Returns + ------- + obsid : int + The observation ID of the data + """ + return int(RE_DATA_DIR.match(path).group("obsid")) diff --git a/scripts/analyze_path.py b/scripts/analyze_path.py index dc33dcd..40ac393 100755 --- a/scripts/analyze_path.py +++ b/scripts/analyze_path.py @@ -15,44 +15,9 @@ The root directory of the object data has the format: import os import argparse -import re - -RE_DATA_DIR = re.compile(r"^.*/(?P<name>[^/_]+)_oi(?P<obsid>\d+).*$") - - -def get_name(path): - """ - Extract the object name from the directory path. - - Parameters - ---------- - path : str - Path to the data directory - - Returns - ------- - objname : str - The name part of the data directory - """ - return RE_DATA_DIR.match(path).group("name") - - -def get_obsid(path): - """ - Extract the observation ID from the directory path. - - Parameters - ---------- - path : str - Path to the data directory - - Returns - ------- - obsid : int - The observation ID of the data - """ - return int(RE_DATA_DIR.match(path).group("obsid")) +from context import acispy +from acispy.analyze_path import get_name, get_obsid def main(): |