Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Py3 server with + event/cmd cron jobs processing with django 3.0 #143

Merged
merged 35 commits into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ca64fa5
Changes to use scm_setuptools
javierggt Dec 16, 2019
cbd1657
flake8
javierggt Dec 16, 2019
f4df25e
Removed version.py file to use setuptools_scm
javierggt Dec 17, 2019
a0ca23d
flake8
javierggt Dec 17, 2019
f574a57
found and removed uses of version.py
javierggt Dec 17, 2019
703ea79
for setuptools_scm to work, use setuptools.setup and not distutils.co…
javierggt Dec 19, 2019
5a64bb5
Set env vars to work on new web-kadi / web-kadi-test servers
taldcroft Aug 30, 2019
a721dab
Initial Py3 / django 2.2 fixes
taldcroft Oct 9, 2019
3c5ad96
More fixes
taldcroft Oct 9, 2019
3d6fd06
Make it work as server and as standalone
taldcroft Oct 9, 2019
8b68dc9
Fixes for update_events with django 2.2
taldcroft Dec 3, 2019
436002d
Make obsid a generic field of TlmEvent
taldcroft Dec 3, 2019
a9a6323
Get rid of the local ./update_* launcher scripts
taldcroft Dec 3, 2019
25d655c
Do not override obsid field in Obsid model
taldcroft Dec 3, 2019
9eadc8e
More changes for successfully populating database
taldcroft Dec 3, 2019
5fceb68
Improve fault tolerance
taldcroft Dec 4, 2019
e417fa9
Remove six and PY2 compatibility
taldcroft Dec 4, 2019
b26e7fb
Fix test failure
taldcroft Dec 5, 2019
0d447c3
Fix mistake in six-removal re metaclasses
taldcroft Dec 5, 2019
c4a98d8
Fix an issue with non-UTF8 char in TLR files
taldcroft Dec 5, 2019
9fc3c79
Remove useless comment
taldcroft Dec 7, 2019
ca552b7
Change events database name to events3.db3
taldcroft Dec 7, 2019
1326587
Add WARNING in case of obsid not available
taldcroft Dec 7, 2019
9e4d108
Move ltt_bads into share and other setup changes
taldcroft Dec 8, 2019
4daddb8
Fix to work with find_attitude
taldcroft Dec 19, 2019
f68ada5
Fixes for standalone / macosx / zsh
taldcroft Dec 19, 2019
1d48cce
More changes for modern env and django 3.0
taldcroft Dec 28, 2019
a551bac
Autopep8 W504 move binary operator after line break
taldcroft Dec 28, 2019
07427a6
More flake8 changes
taldcroft Dec 28, 2019
532988c
Add logging information
taldcroft Dec 29, 2019
3365d36
Temporary change to alert to aldcroft not aca
taldcroft Dec 29, 2019
4ae68b7
Update build notes
taldcroft Dec 29, 2019
9909a82
Remove occ and ftp args; use ska_helpers.run_info
taldcroft Dec 29, 2019
497efa1
Use ska_helpers log_run_info for run info in events update
taldcroft Jan 3, 2020
664c41b
Fix leftover in use of run_info in update_cmds
taldcroft Jan 4, 2020
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
6 changes: 3 additions & 3 deletions NOTES.add_event_type
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ export KADI=$PWD

./manage.py syncdb

./update_events --start=1999:200 --stop=2001:001 --model=${ModelClassName}
python -m kadi.update_events --start=1999:200 --stop=2001:001 --model=${ModelClassName}
# Update early events first and look for warnings. Also confirm that the first event
# matches what is in the current database unless a change is intended.
# Some events may need a later start data to be fully sampled. Manvr, for example,
# should use a start of "1999:251" (1999:230 + 21 days lookback).
# Probably not needed for events that rely on only one event MSID.

./update_events --start=2001:001 --model=${ModelClassName}
python -m kadi.update_events --start=2001:001 --model=${ModelClassName}
# Update the rest of the time range for the updated model/event


Expand Down Expand Up @@ -104,7 +104,7 @@ Use the current flight kadi code and the test database and confirm that kadi tes
In [9]: kadi.test()
============================= test session starts ==============================
platform linux2 -- Python 2.7.9 -- py-1.4.26 -- pytest-2.6.4
collected 15 items
collected 15 items

kadi/tests/test_events.py ..........
kadi/tests/test_occweb.py .....
Expand Down
47 changes: 19 additions & 28 deletions NOTES.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,28 @@

cd ~/git/kadi
export KADI=$PWD
rm events.db3 cmds.h5 cmds.pkl
./manage.py syncdb

export ENG_ARCHIVE=/proj/sot/ska/data/eng_archive/1999
./update_events --start=1999:200 --stop=2000:001 --model=SafeSun

export ENG_ARCHIVE=
./update_events --start=2000:001
./update_cmds --start=2000:001

NOTE: could potentially get all the 1999 events using the 1999 eng
archive.
rm -f events3.db3 cmds.h5 cmds.pkl
rm -rf kadi/events/migrations
./manage.py makemigrations events
./manage.py migrate

# For commands one MUST do this in a dedicated test env because the pickling
# of UpdatedDict does not work. That object gets a module of __main__ but for
# production it must be kadi.update_cmds. See e.g.
# https://www.stefaanlippens.net/python-pickling-and-dealing-with-attributeerror-
# module-object-has-no-attribute-thing.html
pip install . # to a TEST env!! (Maybe with -e for editable install?)

# First line is just to see that every model works. One can just drop the
# --stop=2000:001 if you are sure it will work.
kadi_update_events --start=1999:240 --stop=2000:001
kadi_update_events --start=2000:001
kadi_update_cmds --start=2000:001

#################################################################
# Remove certain tables in a local version of the flight events database
# Re-build single table
#################################################################

% export KADI=$PWD
% cp /proj/sot/ska/data/kadi/events.db3 ./
% sqlite3 events.db3
> drop table events_cap;

% ./manage.py syncdb
% ./update_events --start=2000:001 --model=CAP --delete-from-start


#################################################################
# Reprocess a table from a starting date in a local version of
# the flight events database
#################################################################

% cp /proj/sot/ska/data/kadi/events.db3 ./
% ./update_events --start=2012:001 --model=Scs107 --delete-from-start

% python -m kadi.update_events --start=1999:001 --model=CAP --delete-from-start
2 changes: 1 addition & 1 deletion NOTES.reprocess
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ If the kadi events.db3 database gets corrupted (e.g. problems related to the
cp /proj/sot/ska/data/kadi/events.db3 ./

# Update from 2017:017 (for example) to present
./update_events --start=2017:017 --delete-from-start
python -m kadi.update_events --start=2017:017 --delete-from-start

cp events.db3 /proj/sot/ska/data/kadi/
4 changes: 2 additions & 2 deletions NOTES.update_ltt_bads
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Test
----

export KADI=$PWD
./update_events --start '1999:100' --delete-from-start --loop-days=10000 \
python -m kadi.update_events --start '1999:100' --delete-from-start --loop-days=10000 \
--model=LttBad >& run.log &

# Confirm new events added as expected
Expand All @@ -23,7 +23,7 @@ make install # or just copy ltt_bads.dat to $ska/data/kadi/.

unset KADI
cd $ska/share/kadi
./update_events --start '1999:100' --delete-from-start --loop-days=10000 \
python -m kadi.update_events --start '1999:100' --delete-from-start --loop-days=10000 \
--data-root=$ska/data/kadi --model=LttBad >& run.log &


Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
# built documents.
#
# The full version, including alpha/beta/rc tags.
from kadi.version import version as release
from kadi import __version__ as release
# The short X.Y version.
version = '.'.join(release.split('.')[:2])

Expand Down
5 changes: 4 additions & 1 deletion kadi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
from .version import __version__, __git_version__ # noqa

import ska_helpers

__version__ = ska_helpers.get_version(__package__)


def test(*args, **kwargs):
Expand Down
20 changes: 9 additions & 11 deletions kadi/cmds/cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@

from astropy.table import Table
from Chandra.Time import DateTime
import six
from six.moves import cPickle as pickle
import pickle

from ..paths import IDX_CMDS_PATH, PARS_DICT_PATH

Expand Down Expand Up @@ -51,8 +50,7 @@ def load_idx_cmds():

def load_pars_dict():
with open(PARS_DICT_PATH(), 'rb') as fh:
kwargs = {} if six.PY2 else {'encoding': 'ascii'}
pars_dict = pickle.load(fh, **kwargs)
pars_dict = pickle.load(fh, encoding='ascii')
return pars_dict


Expand Down Expand Up @@ -141,7 +139,7 @@ def _find(start=None, stop=None, **kwargs):
ok &= idx_cmds['date'] < DateTime(stop).date
for key, val in kwargs.items():
key = key.lower()
if isinstance(val, six.string_types):
if isinstance(val, str):
val = val.upper()
if key in idx_cmds.dtype.names:
ok &= idx_cmds[key] == val
Expand Down Expand Up @@ -173,17 +171,17 @@ def __init__(self, cmd):
if self['tlmsid'] == 'None':
colnames.remove('tlmsid')

self._ordered_keys = (colnames[1:] +
[par[0] for par in rev_pars_dict[cmd['idx']]])
self._ordered_keys = (colnames[1:]
+ [par[0] for par in rev_pars_dict[cmd['idx']]])

def __repr__(self):
out = ('<{} '.format(self.__class__.__name__) + str(self) + '>')
return out

def __str__(self):
out = ('{} {:11s} '.format(self['date'], self['type']) +
' '.join('{}={}'.format(key, self[key]) for key in self._ordered_keys
if key not in ('type', 'date')))
out = ('{} {:11s} '.format(self['date'], self['type'])
+ ' '.join('{}={}'.format(key, self[key]) for key in self._ordered_keys
if key not in ('type', 'date')))
return out


Expand All @@ -203,7 +201,7 @@ def __len__(self):

def __getitem__(self, item):
cmds = self.cmds
if isinstance(item, six.string_types):
if isinstance(item, str):
if item in cmds.colnames:
return cmds[item]

Expand Down
35 changes: 14 additions & 21 deletions kadi/commands/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

from astropy.table import Table, Row, Column, vstack
from Chandra.Time import DateTime
import six
from six.moves import cPickle as pickle
import pickle

from ..paths import IDX_CMDS_PATH, PARS_DICT_PATH

Expand Down Expand Up @@ -52,8 +51,7 @@ def load_idx_cmds():

def load_pars_dict():
with open(PARS_DICT_PATH(), 'rb') as fh:
kwargs = {} if six.PY2 else {'encoding': 'ascii'}
pars_dict = pickle.load(fh, **kwargs)
pars_dict = pickle.load(fh, encoding='ascii')
return pars_dict


Expand Down Expand Up @@ -195,7 +193,7 @@ def _find(start=None, stop=None, **kwargs):
ok &= idx_cmds['date'] < DateTime(stop).date
for key, val in kwargs.items():
key = key.lower()
if isinstance(val, six.string_types):
if isinstance(val, str):
val = val.upper()
if key in idx_cmds.dtype.names:
ok &= idx_cmds[key] == val
Expand Down Expand Up @@ -246,9 +244,9 @@ def __str__(self):
if 'idx' in keys:
keys.remove('idx')

out = ('{} {} '.format(self['date'], self['type']) +
' '.join('{}={}'.format(key, self[key]) for key in keys
if key not in ('type', 'date')))
out = ('{} {} '.format(self['date'], self['type'])
+ ' '.join('{}={}'.format(key, self[key]) for key in keys
if key not in ('type', 'date')))
return out

def __sstr__(self):
Expand All @@ -262,7 +260,7 @@ class CommandTable(Table):
"""

def __getitem__(self, item):
if isinstance(item, six.string_types):
if isinstance(item, str):
if item in self.colnames:
return self.columns[item]
else:
Expand All @@ -280,11 +278,11 @@ def __getitem__(self, item):
keys=self.groups._keys)
return out

elif (isinstance(item, slice) or
isinstance(item, np.ndarray) or
isinstance(item, list) or
isinstance(item, tuple) and all(isinstance(x, np.ndarray)
for x in item)):
elif (isinstance(item, slice)
or isinstance(item, np.ndarray)
or isinstance(item, list)
or isinstance(item, tuple) and all(isinstance(x, np.ndarray)
for x in item)):
# here for the many ways to give a slice; a tuple of ndarray
# is produced by np.where, as in t[np.where(t['a'] > 2)]
# For all, a new table is constructed with slice of all columns
Expand All @@ -294,7 +292,7 @@ def __getitem__(self, item):
raise ValueError('Illegal type {0} for table item access'
.format(type(item)))

def __unicode__(self):
def __str__(self):
# Cut out params column for printing
colnames = self.colnames
if 'idx' in colnames:
Expand All @@ -320,13 +318,8 @@ def __unicode__(self):
lines = tmp.pformat(max_width=-1)
return '\n'.join(lines)

if not six.PY2:
__str__ = __unicode__

def __bytes__(self):
return six.text_type(self).encode('utf-8')
if six.PY2:
__str__ = __bytes__
return str(self).encode('utf-8')

def fetch_params(self):
"""
Expand Down
20 changes: 8 additions & 12 deletions kadi/commands/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import inspect

import numpy as np
import six
from six.moves import range

from astropy.table import Table, Column

Expand Down Expand Up @@ -40,10 +38,10 @@

# State keys for PCAD-related transitions. If *any* of these are requested then
# *all* of them need to be processed to get the correct answer.
PCAD_STATE_KEYS = (QUAT_COMPS +
['targ_' + qc for qc in QUAT_COMPS] +
['ra', 'dec', 'roll'] +
['auto_npnt', 'pcad_mode', 'pitch', 'off_nom_roll'])
PCAD_STATE_KEYS = (QUAT_COMPS
+ ['targ_' + qc for qc in QUAT_COMPS]
+ ['ra', 'dec', 'roll']
+ ['auto_npnt', 'pcad_mode', 'pitch', 'off_nom_roll'])

# Default state keys (mostly matches classic command states list)
DEFAULT_STATE_KEYS = ('ccd_count', 'clocking', 'dec', 'dither', 'fep_count',
Expand Down Expand Up @@ -114,12 +112,10 @@ def __new__(mcls, name, bases, members):
return cls


@six.add_metaclass(TransitionMeta)
class BaseTransition(object):
class BaseTransition(object, metaclass=TransitionMeta):
"""
Base transition class from which all actual transition classes are derived.
"""

@classmethod
def get_state_changing_commands(cls, cmds):
"""
Expand Down Expand Up @@ -192,8 +188,8 @@ def _auto_update_docstring(cls):

others = []
for attr, val in cls.__dict__.items():
if (attr.startswith('_') or inspect.ismethod(val) or
attr in ('state_keys', 'command_attributes', 'command_params')):
if (attr.startswith('_') or inspect.ismethod(val)
or attr in ('state_keys', 'command_attributes', 'command_params')):
continue
others.append('{}={}'.format(attr, val))
if others:
Expand Down Expand Up @@ -992,7 +988,7 @@ def get_transition_classes(state_keys=None):
Get all BaseTransition subclasses in this module corresponding to
state keys ``state_keys``.
"""
if isinstance(state_keys, six.string_types):
if isinstance(state_keys, str):
state_keys = [state_keys]
elif state_keys is None:
state_keys = DEFAULT_STATE_KEYS
Expand Down
13 changes: 7 additions & 6 deletions kadi/commands/tests/test_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ def test_quick():
Test for a few days in 2017. Sanity check for refactoring etc.
"""
state_keys = (['obsid', 'clocking', 'power_cmd', 'fep_count', 'vid_board',
'si_mode', 'ccd_count'] +
['q1', 'q2', 'q3', 'q4', 'pcad_mode', 'dither', 'ra', 'dec', 'roll'] +
['letg', 'hetg'] +
['simpos', 'simfa_pos'])
'si_mode', 'ccd_count']
+ ['q1', 'q2', 'q3', 'q4', 'pcad_mode', 'dither', 'ra', 'dec', 'roll']
+ ['letg', 'hetg']
+ ['simpos', 'simfa_pos'])
continuity = {'letg': 'RETR', 'hetg': 'RETR'} # Not necessarily set within 7 days
rc, rk = compare_states('2018:235', '2018:245', state_keys, continuity=continuity)

Expand Down Expand Up @@ -154,6 +154,7 @@ def test_states_2017():
maneuver commanding (so the NMAN period before maneuver starts is OK) while kadi
will insert pitch breaks only in NPNT. (Tested later).
"""

state_keys = (['obsid', 'clocking', 'power_cmd', 'fep_count']
+ ['q1', 'q2', 'q3', 'q4', 'pcad_mode', 'dither', 'ra', 'dec', 'roll']
+ ['letg', 'hetg']
Expand Down Expand Up @@ -442,8 +443,8 @@ def test_reduce_states_cmd_states():
cs = cmd_states.fetch_states('2018:235', '2018:245', allow_identical=True)
cs = Table(cs)

state_keys = (set(cmd_states.STATE0) -
set(['datestart', 'datestop', 'trans_keys', 'tstart', 'tstop']))
state_keys = (set(cmd_states.STATE0)
- set(['datestart', 'datestop', 'trans_keys', 'tstart', 'tstop']))

# Default setting is reduce states with merge_identical=False, which is the same
# as cmd_states.
Expand Down
16 changes: 6 additions & 10 deletions kadi/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,12 @@
import os
import django

# If we are running standalone then this ENV var is not set. Need to explicitly
# do the setup and then import query module attributes for standalone.
# For WSGI server the env var is set in wsgi.py.
# For the dev server it is set in manage.py.

if 'DJANGO_SETTINGS_MODULE' not in os.environ:
os.environ['DJANGO_SETTINGS_MODULE'] = 'kadi.settings'

# In django >= 1.8 an explicit call to setup is required for standalone.
# This attribute does not exist in 1.6.
# https://docs.djangoproject.com/en/1.10/topics/settings/#calling-django-setup-is-required-for-standalone-django-usage
try:
django.setup()
except AttributeError:
pass

# from .models import *
from .query import * # noqa
from .query import * # noqa
Loading