From 8c8e2b2fc8d88cfe8e130b2c693d01686f126d18 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sun, 19 Feb 2017 16:29:00 +0800 Subject: Split 'analyze_path.py' to two parts for 'acispy' --- acispy/analyze_path.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 acispy/analyze_path.py (limited to 'acispy') 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 +# 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: + _oi +""" + +import re + + +RE_DATA_DIR = re.compile(r"^.*/(?P[^/_]+)_oi(?P\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")) -- cgit v1.2.2