Skip to content

Commit

Permalink
Merge pull request #24 from sot/flatten-namespace-package-names
Browse files Browse the repository at this point in the history
Flatten namespace packages
  • Loading branch information
taldcroft authored Jan 12, 2024
2 parents d8630c9 + 2491ee1 commit 12dab81
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 50 deletions.
14 changes: 8 additions & 6 deletions acis_taco/antisun.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst
from __future__ import print_function

import numpy as np
from numpy import sin, cos, radians, arctan2, sqrt, arccos, degrees
import Ska.quatutil
import ska_quatutil
from numpy import arccos, arctan2, cos, degrees, radians, sin, sqrt


class AntiSun(object):
def __init__(self, phys_x0, phys_y0, img_pix_scale):
Expand Down Expand Up @@ -44,7 +46,7 @@ def phys2eci(self, phys_x, phys_y, sun_eci):
eci_img = np.array([cos(theta),
sin(phi) * sin_theta,
cos(phi) * sin_theta])
self.q_x_to_antisun = Ska.quatutil.quat_x_to_vec(-sun_eci)
self.q_x_to_antisun = ska_quatutil.quat_x_to_vec(-sun_eci)
eci = np.dot(self.q_x_to_antisun.transform, eci_img)
return eci

Expand All @@ -55,7 +57,7 @@ def img2sky(self, x, y, sun_eci):

def phys2sky(self, phys_x, phys_y, sun_eci):
eci = self.phys2eci(phys_x, phys_y, sun_eci)
ra, dec = Ska.quatutil.eci2radec(eci)
ra, dec = ska_quatutil.eci2radec(eci)
return ra, dec

def eci2polar(self, eci, sun_eci):
Expand All @@ -64,15 +66,15 @@ def eci2polar(self, eci, sun_eci):
= arctan2(sin(theta) * sin(phi), sin(theta) * cos(phi))
= arctan2(y, z)
"""
q_x_to_antisun = Ska.quatutil.quat_x_to_vec(-sun_eci)
q_x_to_antisun = ska_quatutil.quat_x_to_vec(-sun_eci)
eci_img = np.dot(q_x_to_antisun.transform.transpose(), eci)
theta = arccos(eci_img[0])
phi = arctan2(eci_img[1], eci_img[2])
r = degrees(theta)
return r, phi

def eci2phys(self, eci, sun_eci):
q_x_to_antisun = Ska.quatutil.quat_x_to_vec(-sun_eci)
q_x_to_antisun = ska_quatutil.quat_x_to_vec(-sun_eci)
eci_img = np.dot(q_x_to_antisun.transform.transpose(), eci)
r = degrees(arccos(eci_img[0]))
r12 = np.sqrt(eci_img[1]**2 + eci_img[2]**2)
Expand Down
18 changes: 9 additions & 9 deletions dev/acis_rad_illum.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
import numpy as np
from multiprocessing import Process, Queue

import Ska.Table
import ska_table
import Quaternion
from Chandra.Time import DateTime
import Ska.engarchive.fetch_sci as fetch
import Ska.Numpy
from chandra_time import DateTime
import cheta.fetch_sci as fetch
import ska_numpy
import matplotlib
if __name__ == '__main__':
matplotlib.use('Agg')
import matplotlib.pyplot as plt
from Ska.Matplotlib import plot_cxctime
from ska_matplotlib import plot_cxctime

import taco2 as taco

Expand Down Expand Up @@ -129,9 +129,9 @@ def main():
q4s = qatts['aoattqt4'].vals[::opt.sample]
q_times = qatts['aoattqt1'].times[::opt.sample]

ephem_x_vals = Ska.Numpy.interpolate(ephem_x.vals, ephem_times, q_times)
ephem_y_vals = Ska.Numpy.interpolate(ephem_y.vals, ephem_times, q_times)
ephem_z_vals = Ska.Numpy.interpolate(ephem_z.vals, ephem_times, q_times)
ephem_x_vals = ska_numpy.interpolate(ephem_x.vals, ephem_times, q_times)
ephem_y_vals = ska_numpy.interpolate(ephem_y.vals, ephem_times, q_times)
ephem_z_vals = ska_numpy.interpolate(ephem_z.vals, ephem_times, q_times)

chandra_ecis = np.array([ephem_x_vals, ephem_y_vals, ephem_z_vals]).copy().transpose()

Expand Down Expand Up @@ -196,7 +196,7 @@ def main():

# Write results to FITS table
filename = opt.out + '.fits'
Ska.Table.write_fits_table(opt.out + '.fits', illum)
ska_table.write_fits_table(opt.out + '.fits', illum)
print 'Created FITS table', filename

if opt.movie:
Expand Down
20 changes: 10 additions & 10 deletions dev/test_acis_rad_illum.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@

import numpy as np

import Ska.Table
import ska_table
import Quaternion
from Chandra.Time import DateTime
from Ska.TelemArchive.fetch import fetch
import Ska.Numpy
from chandra_time import DateTime
from ska_telemarchive.fetch import fetch
import ska_numpy
import matplotlib.pyplot as plt
from Ska.Matplotlib import plot_cxctime
from ska_matplotlib import plot_cxctime

import test_taco as taco

Expand Down Expand Up @@ -83,7 +83,7 @@ def main():

# Get orbital ephemeris in requested time range
print 'Reading orbital ephemeris file', opt.ephemfile
ephem = Ska.Table.read_table(opt.ephemfile)
ephem = ska_table.read_table(opt.ephemfile)
tstart = DateTime(opt.tstart).secs
tstop = DateTime(opt.tstop).secs
ephem = ephem[(ephem.Time >= tstart)
Expand All @@ -102,10 +102,10 @@ def main():
cols, atts = fetch(start=ephem.Time[0], stop=ephem.Time[-1], dt=dt, time_format='secs',
colspecs=['aoattqt1', 'aoattqt2', 'aoattqt3', 'aoattqt4'])
atts = np.rec.fromrecords(atts, names=cols)
q1s = Ska.Numpy.interpolate(atts.aoattqt1, atts.date, ephem.Time)
q2s = Ska.Numpy.interpolate(atts.aoattqt2, atts.date, ephem.Time)
q3s = Ska.Numpy.interpolate(atts.aoattqt3, atts.date, ephem.Time)
q4s = Ska.Numpy.interpolate(atts.aoattqt4, atts.date, ephem.Time)
q1s = ska_numpy.interpolate(atts.aoattqt1, atts.date, ephem.Time)
q2s = ska_numpy.interpolate(atts.aoattqt2, atts.date, ephem.Time)
q3s = ska_numpy.interpolate(atts.aoattqt3, atts.date, ephem.Time)
q4s = ska_numpy.interpolate(atts.aoattqt4, atts.date, ephem.Time)

# Divy up calculations amongst the n-processors
i0s = range(0, len(q1s), len(q1s) // opt.nproc + 1)
Expand Down
37 changes: 19 additions & 18 deletions scripts/esaview.py
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
#!/usr/bin/env python
# Licensed under a 3-clause BSD style license - see LICENSE.rst
from __future__ import print_function

import argparse
import os
import six.moves.tkinter as Tk
import six.moves.cPickle as pickle
import sys

import argparse
import numpy as np
import matplotlib
import numpy as np
import six.moves.cPickle as pickle
import six.moves.tkinter as Tk

matplotlib.use('TkAgg')
import ska_matplotlib
import ska_quatutil
import ska_sun
from chandra_time import DateTime
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
from matplotlib.figure import Figure
from mpl_toolkits.axes_grid1 import make_axes_locatable
from mpl_toolkits.mplot3d import Axes3D

import Ska.quatutil
from Chandra.Time import DateTime
import Ska.Matplotlib
from Ska.Matplotlib import cxctime2plotdate
import Ska.Sun
from Quaternion import Quat
from ska_matplotlib import cxctime2plotdate


def plot_cxctime(times, y, fmt='-b', fig=None, ax=None, yerr=None, xerr=None, tz=None,
state_codes=None, interactive=True, **kwargs):
Expand Down Expand Up @@ -68,18 +69,18 @@ def plot_cxctime(times, y, fmt='-b', fig=None, ax=None, yerr=None, xerr=None, tz
ax.xaxis_date(tz)
else:
ax.plot_date(cxctime2plotdate(times), y, fmt=fmt, **kwargs)
ticklocs = Ska.Matplotlib.set_time_ticks(ax)
ticklocs = ska_matplotlib.set_time_ticks(ax)
fig.autofmt_xdate()

if state_codes is not None:
counts, codes = zip(*state_codes)
ax.yaxis.set_major_locator(Ska.Matplotlib.FixedLocator(counts))
ax.yaxis.set_major_formatter(Ska.Matplotlib.FixedFormatter(codes))
ax.yaxis.set_major_locator(ska_matplotlib.FixedLocator(counts))
ax.yaxis.set_major_formatter(ska_matplotlib.FixedFormatter(codes))

# If plotting interactively then show the figure and enable interactive resizing
if interactive and hasattr(fig, 'show'):
# fig.canvas.draw()
ax.callbacks.connect('xlim_changed', Ska.Matplotlib.remake_ticks)
ax.callbacks.connect('xlim_changed', ska_matplotlib.remake_ticks)

return ticklocs, fig, ax

Expand Down Expand Up @@ -271,10 +272,10 @@ def update(self, event):
earth_eci = ephem_xyzs['earth'][:, i_ephem]
ra, dec = antisun.img2sky(x, y, sun_eci)
r, phi = antisun.img2polar(x, y)
roll = Ska.Sun.nominal_roll(ra, dec, times[i_ephem])
roll = ska_sun.nominal_roll(ra, dec, times[i_ephem])
q_att = Quat([ra, dec, roll])
earth_cb = np.dot(q_att.transform.transpose(), earth_eci)
earth_ra_cb, earth_dec_cb = Ska.quatutil.eci2radec(earth_cb)
earth_ra_cb, earth_dec_cb = ska_quatutil.eci2radec(earth_cb)
pitch = 180 - r
self.textvar['ra'].set('{0:.4f}'.format(ra))
self.textvar['dec'].set('{0:.4f}'.format(dec))
Expand Down Expand Up @@ -335,7 +336,7 @@ def __init__(self, name, times, xyzs, color, ax, npoly=40):
ecis = np.array([np.cos(theta) * np.ones(len(phis)),
np.sin(phis) * sin_theta,
np.cos(phis) * sin_theta]) # OFLS uses -cos(phi)
quat_x_to_obj = Ska.quatutil.quat_x_to_vec(xyz)
quat_x_to_obj = ska_quatutil.quat_x_to_vec(xyz)
obj_ecis = np.dot(quat_x_to_obj.transform, ecis)
sun_eci = ephem_xyzs['sun'][:, idx]
x, y = antisun.eci2img(obj_ecis, sun_eci)
Expand Down
15 changes: 8 additions & 7 deletions share/make_esaview_data.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
import os
from datetime import date

import Ska.Sun
import Ska.engarchive.fetch_sci as fetch
import Ska.quatutil
import six.moves.cPickle as pickle
import cheta.fetch_sci as fetch
import numpy as np
from Chandra.Time import DateTime
import six.moves.cPickle as pickle
import ska_quatutil
import ska_sun
from chandra_time import DateTime

import acis_taco


def get_options():
from optparse import OptionParser
parser = OptionParser()
Expand Down Expand Up @@ -106,15 +107,15 @@ def calc_perigee_map(start='2010:114:20:00:00', stop='2010:117:16:00:00', ngrid=
continue
sun_eci = ephem_xyzs['solar'][:, i_ephem] - ephem_xyzs['orbit'][:, i_ephem]
att_vecs = antisun.img2eci(xs, ys, sun_eci)
ras, decs = Ska.quatutil.eci2radec(att_vecs)
ras, decs = ska_quatutil.eci2radec(att_vecs)
illum_map = np.zeros((ngrid, ngrid), dtype=np.float32)
print(i_ephem, n_ephem, ephem_xyz)
for iy in range(ngrid):
for ix in range(ngrid):
i_vec = iy * ngrid + ix
if antisun_pitches[i_vec] < 135:
ra, dec = ras[i_vec], decs[i_vec]
roll = Ska.Sun.nominal_roll(ra, dec, times[i_ephem])
roll = ska_sun.nominal_roll(ra, dec, times[i_ephem])
_, att_illums, _ = acis_taco.calc_earth_vis(ephem_xyz, [ra, dec, roll], max_reflect=5)
illum = sum(att_illums)
else:
Expand Down

0 comments on commit 12dab81

Please sign in to comment.