Skip to content

Commit

Permalink
Merge pull request #1 from sot/general-versions
Browse files Browse the repository at this point in the history
Generalized versions and P011
  • Loading branch information
taldcroft committed Jun 6, 2014
2 parents b015fb0 + 3aea421 commit f6cbd66
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
20 changes: 14 additions & 6 deletions Ska/tdb/tdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
"""
import os
import re
import glob

import numpy as np

from .version import version as __version__

__all__ = ['msids', 'tables', '__version__', 'set_tdb_version', 'get_tdb_version',
'TableView', 'MsidView']

TDB_VERSIONS = (4, 6, 7, 8, 9, 10)
TDB_VERSION = 10

# Set None values for module globals that are set in set_tdb_version
TDB_VERSIONS = None
TDB_VERSION = None
DATA_DIR = None
tables = None
msids = None
Expand Down Expand Up @@ -48,17 +50,23 @@
""".lower().split()


def set_tdb_version(version):
def set_tdb_version(version=None):
"""
Set the version of the TDB which is used.
:param version: TDB version (integer, e.g. 10)
:param version: TDB version (integer or None => latest)
"""
global TDB_VERSION
global TDB_VERSIONS
global DATA_DIR
global tables
global msids
if version not in TDB_VERSIONS:
version_dirs = glob.glob(os.path.join(os.path.dirname(__file__), 'data', 'p0??'))
TDB_VERSIONS = sorted([int(os.path.basename(vdir)[2:]) for vdir in version_dirs])

if version is None:
version = TDB_VERSIONS[-1]
elif version not in TDB_VERSIONS:
raise ValueError('TDB version must be one of the following: {}'.format(TDB_VERSIONS))

TDB_VERSION = version
Expand Down Expand Up @@ -234,4 +242,4 @@ def __repr__(self):
return object.__repr__(self)


set_tdb_version(TDB_VERSION)
set_tdb_version() # Choose the most recent version
2 changes: 1 addition & 1 deletion Ska/tdb/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
therein are applicable.
"""

version = '0.2'
version = '0.3'

_versplit = version.replace('dev', '').split('.')
major = int(_versplit[0])
Expand Down
22 changes: 12 additions & 10 deletions make_tdb.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
"""
Make the numpy data files that are used by Ska.tdb.
Make the numpy data files that are used by Ska.tdb. From the repo root directory:
% python make_tdb.py
This creates files in Ska/tdb/data/p0<VERSION>/.
This creates files in ./Ska/tdb/data/p0<VERSION>/.
"""

from __future__ import print_function

import os
import glob

import numpy as np
from astropy.io import ascii

TDB_ROOT = '/proj/sot/ska/ops/TDB'

# Run this within the data/ directory, then move pck files to tdb/data/.
# Reader=asciitable.Rdb, fill_values=[('', '0')])

names = 'tcntr tes tlmt tloc tmsrment towner tpc tpp tsc tsmpl tstream ttdm_fmt ttdm'.split()

for version in (4, 6, 7, 8, 9, 10):
TDB_version = 'p{:03d}'.format(version)
TDB_versions = [os.path.basename(x) for x in glob.glob(os.path.join(TDB_ROOT, 'p0??'))]

for TDB_version in sorted(TDB_versions):
out_path = os.path.join('Ska', 'tdb', 'data', TDB_version)
if os.path.exists(out_path):
print('Skipping TDB version {}'.format(TDB_version))
continue
os.mkdir(out_path)
print('Processing TDB version {}'.format(TDB_version))

for name in names:
filename = os.path.join(TDB_ROOT, TDB_version, name + '.txt')
print(name, filename)
Expand Down Expand Up @@ -56,7 +61,4 @@
print('Masked : {}'.format(dat.masked))
print()

out_path = os.path.join('Ska', 'tdb', 'data', TDB_version)
if not os.path.exists(out_path):
os.mkdir(out_path)
np.save(os.path.join(out_path, name + '.npy'), dat)

0 comments on commit f6cbd66

Please sign in to comment.