Skip to content

Commit

Permalink
ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
javierggt committed Oct 11, 2024
1 parent c380520 commit 4085dd3
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 214 deletions.
9 changes: 5 additions & 4 deletions aperoll/scripts/aperoll_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

def get_parser():
import argparse

parse = argparse.ArgumentParser()
parse.add_argument('--date', default='2021-08-23 00:00:00.000')
parse.add_argument('--ra', default='6.45483333')
parse.add_argument('--dec', default='-26.03683611')
parse.add_argument("--date", default="2021-08-23 00:00:00.000")
parse.add_argument("--ra", default="6.45483333")
parse.add_argument("--dec", default="-26.03683611")
return parse


Expand All @@ -25,5 +26,5 @@ def main():
app.exec()


if __name__ == '__main__':
if __name__ == "__main__":
main()
111 changes: 59 additions & 52 deletions aperoll/widgets/main_window.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
# from PyQt5 import QtCore as QtC, QtWidgets as QtW, QtGui as QtG
from tempfile import TemporaryDirectory
from pathlib import Path

from PyQt5 import QtWidgets as QtW
from PyQt5 import QtCore as QtC
from tempfile import TemporaryDirectory

import PyQt5.QtWebEngineWidgets as QtWe

from .parameters import Parameters
from .star_plot import StarPlot

from Quaternion import Quat
from astropy import units as u

from cxotime import CxoTime

from proseco import get_aca_catalog
from sparkles.core import run_aca_review
from PyQt5 import QtCore as QtC
from PyQt5 import QtWidgets as QtW
from Quaternion import Quat

from .parameters import Parameters
from .star_plot import StarPlot


class WebPage(QtWe.QWebEnginePage):
def __init__(self, parent=None):
super().__init__(parent)

# trick from https://stackoverflow.com/questions/54920726/how-make-any-link-blank-open-in-same-window-using-qwebengine # noqa
# trick from https://stackoverflow.com/questions/54920726/how-make-any-link-blank-open-in-same-window-using-qwebengine
def createWindow(self, _type):
page = WebPage(self)
page.urlChanged.connect(self.on_url_changed)
Expand All @@ -37,8 +32,9 @@ def on_url_changed(self, url):


class MainWindow(QtW.QWidget):
def __init__(self, opts={}):
def __init__(self, opts=None):
super().__init__()
opts = {} if opts is None else opts
opts = {k: opts[k] for k in opts if opts[k] is not None}

self.web_page = None
Expand Down Expand Up @@ -75,75 +71,86 @@ def closeEvent(self, event):
event.accept()

def _init(self):
print('parameters:', self.parameters.values)
print("parameters:", self.parameters.values)
if self.parameters.values:
obsid = self.parameters.values['obsid']
ra, dec = self.parameters.values['ra'], self.parameters.values['dec']
roll = self.parameters.values['roll']
time = CxoTime(self.parameters.values['date'])
# obsid = self.parameters.values["obsid"]
ra, dec = self.parameters.values["ra"], self.parameters.values["dec"]
roll = self.parameters.values["roll"]
time = CxoTime(self.parameters.values["date"])

# aca_attitude = calc_aca_from_targ(
# Quat(equatorial=(float(ra / u.deg), float(dec / u.deg), nominal_roll)),
# 0,
# 0
# )
aca_attitude = Quat(equatorial=(float(ra / u.deg), float(dec / u.deg), roll))
print('ra, dec, roll =', (float(ra / u.deg), float(dec / u.deg), roll))
aca_attitude = Quat(
equatorial=(float(ra / u.deg), float(dec / u.deg), roll)
)
print("ra, dec, roll =", (float(ra / u.deg), float(dec / u.deg), roll))
self.plot.set_base_attitude(aca_attitude, update=False)
self.plot.set_time(time, update=True)

def _draw_test(self):
if self.parameters.values:
ra, dec = self.parameters.values['ra'], self.parameters.values['dec']
roll = self.parameters.values['roll']
aca_attitude = Quat(equatorial=(float(ra / u.deg), float(dec / u.deg), roll))
ra, dec = self.parameters.values["ra"], self.parameters.values["dec"]
roll = self.parameters.values["roll"]
aca_attitude = Quat(
equatorial=(float(ra / u.deg), float(dec / u.deg), roll)
)
# self.plot.show_test_stars_q(aca_attitude)
dq = self.plot._base_attitude.dq(aca_attitude)
self.plot.show_test_stars(ra_offset=dq.ra, dec_offset=dq.dec, roll_offset=dq.roll)
self.plot.show_test_stars(
ra_offset=dq.ra, dec_offset=dq.dec, roll_offset=dq.roll
)

def _do_it(self):
print('parameters:', self.parameters.values)
print("parameters:", self.parameters.values)
if self.parameters.values:
obsid = self.parameters.values['obsid']
ra, dec = self.parameters.values['ra'], self.parameters.values['dec']
roll = self.parameters.values['roll']
time = CxoTime(self.parameters.values['date'])
obsid = self.parameters.values["obsid"]
ra, dec = self.parameters.values["ra"], self.parameters.values["dec"]
roll = self.parameters.values["roll"]
time = CxoTime(self.parameters.values["date"])

# aca_attitude = calc_aca_from_targ(
# Quat(equatorial=(float(ra / u.deg), float(dec / u.deg), nominal_roll)),
# 0,
# 0
# )
aca_attitude = Quat(equatorial=(float(ra / u.deg), float(dec / u.deg), roll))
print('ra, dec, roll =', (float(ra / u.deg), float(dec / u.deg), roll))
aca_attitude = Quat(
equatorial=(float(ra / u.deg), float(dec / u.deg), roll)
)
print("ra, dec, roll =", (float(ra / u.deg), float(dec / u.deg), roll))
from pprint import pprint
pprint(dict(
obsid=obsid,
att=aca_attitude,
date=time,
n_fid=self.parameters.values['n_fid'],
n_guide=self.parameters.values['n_guide'],
dither_acq=(16, 16), # standard dither with ACIS
dither_guide=(16, 16), # standard dither with ACIS
t_ccd_acq=self.parameters.values['t_ccd'],
t_ccd_guide=self.parameters.values['t_ccd'],
man_angle=0, # what is a sensible number to use??
detector=self.parameters.values['instrument'],
sim_offset=0, # docs say this is optional, but it does not seem to be
focus_offset=0, # docs say this is optional, but it does not seem to be
))

pprint(
{
"obsid": obsid,
"att": aca_attitude,
"date": time,
"n_fid": self.parameters.values["n_fid"],
"n_guide": self.parameters.values["n_guide"],
"dither_acq": (16, 16), # standard dither with ACIS
"dither_guide": (16, 16), # standard dither with ACIS
"t_ccd_acq": self.parameters.values["t_ccd"],
"t_ccd_guide": self.parameters.values["t_ccd"],
"man_angle": 0, # what is a sensible number to use??
"detector": self.parameters.values["instrument"],
"sim_offset": 0, # docs say this is optional, but it does not seem to be
"focus_offset": 0, # docs say this is optional, but it does not seem to be
}
)
catalog = get_aca_catalog(
obsid=obsid,
att=aca_attitude,
date=time,
n_fid=self.parameters.values['n_fid'],
n_guide=self.parameters.values['n_guide'],
n_fid=self.parameters.values["n_fid"],
n_guide=self.parameters.values["n_guide"],
dither_acq=(16, 16), # standard dither with ACIS
dither_guide=(16, 16), # standard dither with ACIS
t_ccd_acq=self.parameters.values['t_ccd'],
t_ccd_guide=self.parameters.values['t_ccd'],
t_ccd_acq=self.parameters.values["t_ccd"],
t_ccd_guide=self.parameters.values["t_ccd"],
man_angle=0, # what is a sensible number to use??
detector=self.parameters.values['instrument'],
detector=self.parameters.values["instrument"],
sim_offset=0, # docs say this is optional, but it does not seem to be
focus_offset=0, # docs say this is optional, but it does not seem to be
)
Expand Down
84 changes: 44 additions & 40 deletions aperoll/widgets/parameters.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
from PyQt5 import QtCore as QtC, QtWidgets as QtW

from astropy import units as u

import Ska.Sun as sun
from astropy import units as u
from cxotime.cxotime import CxoTime
from PyQt5 import QtCore as QtC
from PyQt5 import QtWidgets as QtW


def get_parameters():
import maude
from Quaternion import Quat
msid_list = ['3TSCPOS', 'AACCCDPT'] + [f'aoattqt{i}'.upper() for i in range(1,5)]

msid_list = ["3TSCPOS", "AACCCDPT"] + [f"aoattqt{i}".upper() for i in range(1, 5)]
msids = maude.get_msids(msid_list)
data = {msid: msids['data'][i]['values'][-1] for i, msid in enumerate(msid_list)}
q = Quat(q=[data[f'AOATTQT{i}'] for i in range(1, 5)])
data = {msid: msids["data"][i]["values"][-1] for i, msid in enumerate(msid_list)}
q = Quat(q=[data[f"AOATTQT{i}"] for i in range(1, 5)])
from kadi.commands.observations import get_detector_and_sim_offset
instrument, sim_offset = get_detector_and_sim_offset(data['3TSCPOS'])

instrument, sim_offset = get_detector_and_sim_offset(data["3TSCPOS"])
t_ccd = (data["AACCCDPT"] - 32) * 5 / 9

result = {
'date': CxoTime().date,
'attitude': q,
'instrument': instrument,
'sim_offset': sim_offset,
't_ccd': t_ccd,
"date": CxoTime().date,
"attitude": q,
"instrument": instrument,
"sim_offset": sim_offset,
"t_ccd": t_ccd,
}
from pprint import pprint

pprint(result)
return result

Expand All @@ -33,17 +35,17 @@ class Parameters(QtW.QWidget):
do_it = QtC.pyqtSignal()
draw_test = QtC.pyqtSignal()

def __init__(self, **kwargs):
def __init__(self, **kwargs): # noqa: PLR0915
kwargs = {}

super().__init__()
self.date_label = QtW.QLabel('date')
self.date_label = QtW.QLabel("date")
self.date_edit = QtW.QLineEdit(self)
self.ra_label = QtW.QLabel('ra')
self.ra_label = QtW.QLabel("ra")
self.ra_edit = QtW.QLineEdit(self)
self.dec_label = QtW.QLabel('dec')
self.dec_label = QtW.QLabel("dec")
self.dec_edit = QtW.QLineEdit(self)
self.roll_label = QtW.QLabel('roll')
self.roll_label = QtW.QLabel("roll")
self.roll_edit = QtW.QLineEdit(self)
self.n_guide_label = QtW.QLabel("n_guide")
self.n_guide_edit = QtW.QLineEdit(self)
Expand All @@ -53,7 +55,7 @@ def __init__(self, **kwargs):
self.n_t_ccd_edit = QtW.QLineEdit(self)
self.instrument_label = QtW.QLabel("instrument")
self.instrument_edit = QtW.QComboBox(self)
self.instrument_edit.addItems(['ACIS-S', 'ACIS-I', 'HRC-S', 'HRC-I'])
self.instrument_edit.addItems(["ACIS-S", "ACIS-I", "HRC-S", "HRC-I"])
self.do = QtW.QPushButton("Starcheck")
self.draw_test_button = QtW.QPushButton("Draw Test")
v_layout = QtW.QVBoxLayout(self)
Expand Down Expand Up @@ -81,14 +83,16 @@ def __init__(self, **kwargs):

params = get_parameters()

self.date_edit.setText(kwargs.get('date', params['date']))
self.ra_edit.setText(kwargs.get('ra', f"{params['attitude'].ra:.8f}"))
self.dec_edit.setText(kwargs.get('dec', f"{params['attitude'].dec:.8f}"))
self.roll_edit.setText(kwargs.get('roll', f"{params['attitude'].roll:.8f}"))
self.n_guide_edit.setText(kwargs.get('n_guide', '5'))
self.n_fid_edit.setText(kwargs.get('n_fid', '3'))
self.n_t_ccd_edit.setText(kwargs.get('t_ccd', f"{params['t_ccd']:.2f}"))
self.instrument_edit.setCurrentText(kwargs.get('instrument', params['instrument']))
self.date_edit.setText(kwargs.get("date", params["date"]))
self.ra_edit.setText(kwargs.get("ra", f"{params['attitude'].ra:.8f}"))
self.dec_edit.setText(kwargs.get("dec", f"{params['attitude'].dec:.8f}"))
self.roll_edit.setText(kwargs.get("roll", f"{params['attitude'].roll:.8f}"))
self.n_guide_edit.setText(kwargs.get("n_guide", "5"))
self.n_fid_edit.setText(kwargs.get("n_fid", "3"))
self.n_t_ccd_edit.setText(kwargs.get("t_ccd", f"{params['t_ccd']:.2f}"))
self.instrument_edit.setCurrentText(
kwargs.get("instrument", params["instrument"])
)

self.setLayout(v_layout)

Expand All @@ -106,27 +110,27 @@ def _validate(self, quiet=False):
n_fid = int(self.n_fid_edit.text())
n_guide = int(self.n_guide_edit.text())
obsid = 0 if n_fid else 38000
assert self.date_edit.text() != '', "No date"
assert self.ra_edit.text() != '', "No RA"
assert self.dec_edit.text() != '', "No dec"
assert self.date_edit.text() != "", "No date"
assert self.ra_edit.text() != "", "No RA"
assert self.dec_edit.text() != "", "No dec"
assert n_fid + n_guide == 8, "n_fid + n_guide != 8"
ra = float(self.ra_edit.text()) * u.deg
dec = float(self.dec_edit.text()) * u.deg
time = CxoTime(self.date_edit.text())
if self.roll_edit.text() == '':
if self.roll_edit.text() == "":
roll = sun.nominal_roll(ra, dec, time)
else:
roll = float(self.roll_edit.text())
return {
'date': self.date_edit.text(),
'ra': ra,
'dec': dec,
'roll': roll,
'n_guide': n_guide,
'n_fid': n_fid,
't_ccd': float(self.n_t_ccd_edit.text()),
'instrument': self.instrument_edit.currentText(),
'obsid': obsid,
"date": self.date_edit.text(),
"ra": ra,
"dec": dec,
"roll": roll,
"n_guide": n_guide,
"n_fid": n_fid,
"t_ccd": float(self.n_t_ccd_edit.text()),
"instrument": self.instrument_edit.currentText(),
"obsid": obsid,
}
except Exception as e:
if not quiet:
Expand Down
Loading

0 comments on commit 4085dd3

Please sign in to comment.