blob: 0f97bce31845977df286a7ef414d253f5377c916 (
plain)
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
|
# 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"))
|