Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

De namespace #67

Merged
merged 3 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .hgignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Chandra.cmd_states.egg-info
chandra_cmd_states.egg-info
dist
2 changes: 1 addition & 1 deletion add_nonload_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"""

if __name__ == '__main__':
import Chandra.cmd_states.add_nonload_cmds as add_nonload_cmds
import chandra_cmd_states.add_nonload_cmds as add_nonload_cmds
add_nonload_cmds.main()
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .cmd_states import *
from .get_cmd_states import fetch_states

__version__ = ska_helpers.get_version('Chandra.cmd_states')
__version__ = ska_helpers.get_version('chandra_cmd_states')


def test(*args, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
import time


import Chandra.cmd_states as cmd_states
from Chandra.cmd_states.cmd_states import _tl_to_bs_cmds
import chandra_cmd_states as cmd_states
from chandra_cmd_states.cmd_states import _tl_to_bs_cmds
import Ska.DBI
from Chandra.Time import DateTime
import Ska.ParseCM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def fetch_states(start=None, stop=None, vals=None, allow_identical=False,
Examples::

# Get commanded states using the default HDF5 table
>>> from Chandra.cmd_states import fetch_states
>>> from chandra_cmd_states import fetch_states
>>> states = fetch_states('2011:100:12:00:00', '2011:101:12:00:00', vals=['obsid', 'simpos'])
>>> states[['datestart', 'datestop', 'obsid', 'simpos']]
array([('2011:100:11:53:12.378', '2011:101:00:23:01.434', 13255, 75624),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import logging

import Ska.DBI
import Chandra.cmd_states as cmd_states
import chandra_cmd_states as cmd_states


def get_options():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst

from Chandra.cmd_states import cmd_set
from chandra_cmd_states import cmd_set

# COMMAND_HW | TLMSID= AFIDP, HEX= 6480005, MSID= AFLCRSET

Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
import os
import sys
from pathlib import Path
from io import StringIO

import pytest
import numpy as np
from astropy.io import ascii

import Chandra.cmd_states
from Chandra.cmd_states.get_cmd_states import main, fetch_states
from Chandra.cmd_states.cmd_states import decode_power, get_state0, get_cmds, get_states

# Check that this test file is in the same package as the imported Chandra.cmd_states.
# Due to subtleties with pytest test collection and native namespace pacakges,
# running `pytest Ska/Numpy` in the git repo will end up getting the installed
# Chandra.cmd_states not the local one. Use `python setup.py test` instead.
assert Path(__file__).parent.parent == Path(Chandra.cmd_states.__file__).parent
from chandra_cmd_states.get_cmd_states import main, fetch_states
from chandra_cmd_states.cmd_states import decode_power, get_state0, get_cmds, get_states

HAS_SOTMP_FILES = os.path.exists(f'{os.environ["SKA"]}/data/mpcrit1/mplogs/2017')


# This is taken from the output of
# get_cmd_states --start=2010:100 --stop=2010:101 --vals=obsid,simpos,pcad_mode,clocking,power_cmd
# for Chandra.cmd_states version 0.07 in skare 0.13 on July 18, 2012.
# for chandra_cmd_states version 0.07 in skare 0.13 on July 18, 2012.
LINES = [
"datestart datestop tstart tstop obsid power_cmd pcad_mode clocking simpos",
"2010:100:11:39:57.675 2010:100:14:04:43.358 387286863.859 387295549.542 56340 XTZ0000005 NPNT 1 -99616",
Expand Down
12 changes: 6 additions & 6 deletions docs/api.rst
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
Chandra.cmd_states API
chandra_cmd_states API
======================

add_nonload_cmds
----------------

.. automodule:: Chandra.cmd_states.add_nonload_cmds
.. automodule:: chandra_cmd_states.add_nonload_cmds
:members:

cmd_states
----------------

.. automodule:: Chandra.cmd_states.cmd_states
.. automodule:: chandra_cmd_states.cmd_states
:members:

get_cmd_states
----------------

.. automodule:: Chandra.cmd_states.get_cmd_states
.. automodule:: chandra_cmd_states.get_cmd_states
:members:

interrupt_loads
----------------

.. automodule:: Chandra.cmd_states.interrupt_loads
.. automodule:: chandra_cmd_states.interrupt_loads
:members:

update_cmd_states
-----------------

.. automodule:: Chandra.cmd_states.update_cmd_states
.. automodule:: chandra_cmd_states.update_cmd_states
:members:

2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
# built documents.
#
# The short X.Y version.
from Chandra.cmd_states import __version__ as version
from chandra_cmd_states import __version__ as version
# The full version, including alpha/beta/rc tags.
release = version

Expand Down
2 changes: 1 addition & 1 deletion docs/get_cmd_states.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Get the Chandra commanded states over a range of time as a space-delimited
ASCII table.

This tool is a wrapper around the ``Chandra.cmd_states.get_cmd_states()``
This tool is a wrapper around the ``chandra_cmd_states.get_cmd_states()``
function. This function should be used within any Python code that requires
use of commanded states.

Expand Down
14 changes: 7 additions & 7 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ state and a predictive state at any time.
.. Warning:: Use of the commanded states database described here is deprecated
in favor of the `Kadi commands and states
package <http://cxc.cfa.harvard.edu/mta/ASPECT/tool_doc/kadi/commands_states.html>`_.
The replacement for the :func:`~Chandra.cmd_states.fetch_states` function is described
The replacement for the :func:`~chandra_cmd_states.fetch_states` function is described
in the `Chandra states and continuity
<http://cxc.cfa.harvard.edu/mta/ASPECT/tool_doc/kadi/commands_states.html#states>`_
section which makes use of the `get_states
Expand Down Expand Up @@ -49,9 +49,9 @@ available via the :ref:`get_cmd_states` tool. For example::
2012:121:16:04:07.192 2012:123:11:23:20.985 452189113.376 452345067.169 13847 75624

To access the commanded states database from within a Python script use the
:func:`~Chandra.cmd_states.fetch_states` function. For instance::
:func:`~chandra_cmd_states.fetch_states` function. For instance::

>>> from Chandra.cmd_states import fetch_states
>>> from chandra_cmd_states import fetch_states
>>> states = fetch_states('2011:100', '2011:101')
>>> states[['datestart', 'datestop', 'obsid', 'simpos']]
array([('2011:100:11:53:12.378', '2011:101:00:23:01.434', 13255, 75624),
Expand Down Expand Up @@ -145,13 +145,13 @@ Tools
make_cmd_tables
update_cmd_states

Chandra.cmd_states functions
chandra_cmd_states functions
-----------------------------

The following key functions within the ``Chandra.cmd_states`` module are
The following key functions within the ``chandra_cmd_states`` module are
available for users.

.. automodule:: Chandra.cmd_states
.. automodule:: chandra_cmd_states

get_cmds
^^^^^^^^^
Expand All @@ -176,7 +176,7 @@ reduce_states
API docs
--------------

The full API docs for ``Chandra.cmd_states`` are available here:
The full API docs for ``chandra_cmd_states`` are available here:

.. toctree::
:maxdepth: 2
Expand Down
8 changes: 4 additions & 4 deletions fix_pitch_simz.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

# import Ska.Table
import Ska.DBI
import Chandra.cmd_states as cmd_states
import chandra_cmd_states as cmd_states

def get_options():
from optparse import OptionParser
Expand All @@ -29,7 +29,7 @@ def get_options():
parser.add_option("--server",
default='db_base.db3',
help="DBI server (<filename>|sybase)")

(opt, args) = parser.parse_args()
return (opt, args)

Expand All @@ -45,7 +45,7 @@ def main():

db = Ska.DBI.DBI(dbi=opt.dbi, server=opt.server)

datestart = '2002:010:00:00:00'
datestart = '2002:010:00:00:00'
datestop = '2009:001:00:00:00'

if 'states' not in globals():
Expand Down Expand Up @@ -81,4 +81,4 @@ def main():

if __name__ == '__main__':
main()

2 changes: 1 addition & 1 deletion get_cmd_states
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

SKA_bin=`dirname $0`
eval `${SKA_bin}/flt_envs -shell sh`
exec $SKA_ARCH_OS/bin/python -m Chandra.cmd_states.get_cmd_states "$@"
exec $SKA_ARCH_OS/bin/python -m chandra_cmd_states.get_cmd_states "$@"

exit 1
2 changes: 1 addition & 1 deletion get_cmd_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"""

if __name__ == '__main__':
from Chandra.cmd_states import get_cmd_states
from chandra_cmd_states import get_cmd_states
get_cmd_states.main()
2 changes: 1 addition & 1 deletion interrupt_loads.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"""

if __name__ == '__main__':
import Chandra.cmd_states.interrupt_loads as interrupt_loads
import chandra_cmd_states.interrupt_loads as interrupt_loads
interrupt_loads.main()
16 changes: 8 additions & 8 deletions nonload_cmds_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst

import Ska.DBI
import Chandra.cmd_states as cmd_states
from Chandra.cmd_states import generate_cmds, cmd_set, interrupt_loads
import chandra_cmd_states as cmd_states
from chandra_cmd_states import generate_cmds, cmd_set, interrupt_loads

def get_options():
from optparse import OptionParser
Expand Down Expand Up @@ -34,7 +34,7 @@ def get_options():
cmds = []

# Normal sun mode day 2008:225
cmds += generate_cmds('2008:225:10:00:00', cmd_set('nsm'))
cmds += generate_cmds('2008:225:10:00:00', cmd_set('nsm'))
cmds += generate_cmds('2008:227:20:00:00', cmd_set('manvr', 0.734142,-0.111682,0.558589,0.369515 ))
cmds += generate_cmds('2008:227:21:25:00', cmd_set('manvr', 0.784368,-0.0804672,0.535211,0.303053))
cmds += generate_cmds('2008:227:22:15:00', cmd_set('manvr', 0.946291,-0.219412,0.0853751,0.221591))
Expand All @@ -59,27 +59,27 @@ def get_options():
dict(cmd='ACISPKT',
tlmsid='WSVIDALLDN',
),
)
)
cmds += generate_cmds('2009:240:10:40:00.000', cap_cmds )


# ACIS Reboot; Contrived Power commands to match telemetry
cmds += generate_cmds('2010:025:09:11:00.000', ( dict(cmd='ACISPKT', tlmsid='WSPOW00306'),
dict(cmd='ACISPKT', tlmsid='AA00000000')
))
cmds += generate_cmds('2010:025:09:11:01.025', ( dict(cmd='ACISPKT', tlmsid='WSVIDALLDN'),
cmds += generate_cmds('2010:025:09:11:01.025', ( dict(cmd='ACISPKT', tlmsid='WSVIDALLDN'),
))

cmds += generate_cmds('2010:025:14:00:00.000', ( dict(cmd='ACISPKT', tlmsid='WSPOW0EC3E'),
dict(cmd='ACISPKT', tlmsid='AA00000000')
))
cmds += generate_cmds('2010:025:14:00:01.025', ( dict(cmd='ACISPKT', tlmsid='XTZ0000005'),
cmds += generate_cmds('2010:025:14:00:01.025', ( dict(cmd='ACISPKT', tlmsid='XTZ0000005'),
))

cmds += generate_cmds('2010:026:00:30:00.000', ( dict(cmd='ACISPKT', tlmsid='WSPOW01f1f'),
))

cmds += generate_cmds('2010:026:01:36:41.000', ( dict(cmd='ACISPKT', tlmsid='WSPOW00707'),
cmds += generate_cmds('2010:026:01:36:41.000', ( dict(cmd='ACISPKT', tlmsid='WSPOW00707'),
))

# Day 97 CAP made a strange state at 80W that looks like a fep=3,vid_board=on,clocking=off
Expand Down Expand Up @@ -162,7 +162,7 @@ def get_options():

cmd_states.insert_cmds_db(cmds, None, db)

# 2010:150 NSM commands
# 2010:150 NSM commands
# date=2010:150:04:00:00.000 cmd_set=nsm args=
cmds = generate_cmds('2010:150:04:00:00.000', cmd_set('nsm'))
cmd_states.insert_cmds_db(cmds, None, db)
Expand Down
8 changes: 4 additions & 4 deletions resample_states_verification/NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ I then used fetch_states against the flight cmd_states.h5 and the testing cmd_st
create dat files limited to the columns that really should not be changing due to this
update.

from Chandra.cmd_states.get_cmd_states import fetch_states
from chandra_cmd_states.get_cmd_states import fetch_states
from astropy.table import Table

official = fetch_states(start='2010:005', stop='2010:360', vals=['obsid', 'power_cmd',
'si_mode', 'pcad_mode', 'vid_board', 'clocking', 'fep_count', 'ccd_count', 'simpos',
'simfa_pos', 'hetg', 'letg'], server='/proj/sot/ska/data/cmd_states/cmd_states.h5')
Table(official).write('official_minus_point.dat', format='ascii')

test = fetch_states(start='2010:005', stop='2010:360', vals=['obsid', 'power_cmd',
'si_mode', 'pcad_mode', 'vid_board', 'clocking', 'fep_count', 'ccd_count', 'simpos',
'simfa_pos', 'hetg', 'letg'], server='t/all_2010/cmd_states.h5')
Table(test).write('test_minus_point.dat', format='ascii')

meld official_minus_point.dat test_minus_point.dat

There are fewer than a dozen timing diffs of less than 0.04 seconds in the NMAN / NPNT
Expand Down
27 changes: 14 additions & 13 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
from setuptools import setup
from ska_helpers.setup_helper import duplicate_package_info
from testr.setup_helper import cmdclass

try:
from testr.setup_helper import cmdclass
except ImportError:
cmdclass = {}
name = "chandra_cmd_states"
namespace = "Chandra.cmd_states"

setup(name='Chandra.cmd_states',
packages = ["chandra_cmd_states", "chandra_cmd_states.tests"]
package_dir = {name: name}

duplicate_package_info(packages, name, namespace)
duplicate_package_info(package_dir, name, namespace)

setup(name=name,
author='Tom Aldcroft',
description=('Functions for creating, manipulating and updating '
description=('(DEPRECATED) Functions for creating, manipulating and updating '
'the Chandra commanded states database'),
author_email='taldcroft@cfa.harvard.edu',
py_modules=['Chandra.cmd_states.cmd_states',
'Chandra.cmd_states.get_cmd_states',
'Chandra.cmd_states.update_cmd_states',
'Chandra.cmd_states.interrupt_loads',
'Chandra.cmd_states.add_nonload_cmds',
],
use_scm_version=True,
setup_requires=['setuptools_scm', 'setuptools_scm_git_archive'],
zip_safe=False,
packages=['Chandra', 'Chandra.cmd_states', 'Chandra.cmd_states.tests'],
packages=packages,
package_dir=package_dir,
tests_require=['pytest'],
cmdclass=cmdclass,
)
2 changes: 1 addition & 1 deletion tests/cmp_telem.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import logging
import Ska.Table
import Ska.DBI
import Chandra.cmd_states as cmd_states
import chandra_cmd_states as cmd_states
from Ska.Matplotlib import plot_cxctime, pointpair
from Chandra.Time import DateTime
from scipy.signal import medfilt
Expand Down
2 changes: 1 addition & 1 deletion tests/otg_telem.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""
import logging
import Ska.DBI
import Chandra.cmd_states as cmd_states
import chandra_cmd_states as cmd_states
from Ska.Matplotlib import plot_cxctime, pointpair
from Chandra.Time import DateTime
from scipy.signal import medfilt
Expand Down
Loading