Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALPulsar 7.1.1.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
public_sft_directory.py
Go to the documentation of this file.
1# Copyright (C) 2022 Karl Wette
2#
3# This program is free software; you can redistribute it and/or modify it
4# under the terms of the GNU General Public License as published by the
5# Free Software Foundation; either version 2 of the License, or (at your
6# option) any later version.
7#
8# This program is distributed in the hope that it will be useful, but
9# WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11# Public License for more details.
12#
13# You should have received a copy of the GNU General Public License along
14# with this program; if not, write to the Free Software Foundation, Inc.,
15# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16
17## \defgroup lalpulsar_py_public_sft_directory Public SFT Directory Function
18## \ingroup lalpulsar_python
19"""
20Implements the public SFT directory naming convention detailed in the SFT spec (T040164)
21"""
22
23import os
24
25__author__ = "Karl Wette <karl.wette@ligo.org>"
26__version__ = "Consistent with SFT spec LIGO-T040164-v2"
27__date__ = "2022"
28
29
31 # split off the filename, if any
32 _, filename = os.path.split(filename)
33
34 # break into S, D, G, T tokens
35 lvl1 = filename.split("-")
36 if len(lvl1) == 4:
37 S, D, G, T_extn = lvl1
38 else:
39 raise ValueError(f'"{filename}" does not contain 4 tokens separated by "-"')
40
41 # break D into 4 or 5 tokens
42 lvl2 = D.split("_")
43 if len(lvl2) == 5:
44 D1, D2, D3, D4, D5 = lvl2
45 if not D5.startswith("NBF"):
46 raise ValueError(
47 f'"{filename}" token "{D5}" does not match the narrow-band SFT filename spec'
48 )
49 elif len(lvl2) == 4:
50 D1, D2, D3, D4 = lvl2
51 D5 = None
52 else:
53 raise ValueError(
54 f'"{filename}" token "{D}" does not contain 4 or 5 tokens separated by "_"'
55 )
56 if not "+" in D4:
57 raise ValueError(
58 f'"{filename}" token "{D4}" does not match the public SFT filename spec'
59 )
60
61 # build common SFT directory part
62 SFT_base_directory = f"{D2}_{D3}_{D4}"
63
64 if D5:
65 # build narrow-band SFT directory
66 SFT_base_directory += "_NARROWBAND"
67 SFT_subdirectory = D5
68
69 else:
70 # build broad-band SFT directory
71 SFT_base_directory += "_BROADBAND"
72 G_million = int(G) // 1000000
73 SFT_subdirectory = f"GPS{G_million}M"
74
75 return os.path.join(SFT_base_directory, SFT_subdirectory)
76
77
79 # return README.md describing the SFT file/directory naming scheme
80 path = os.path.dirname(os.path.realpath(__file__))
81 with open(os.path.join(path, "public_sft_directory_README.md")) as f:
82 return f.read()