Fixing PEP recommendations raised by flake8

master
Benito Marcote 10 months ago
parent db8231f78e
commit ab48a192b8
  1. 30
      tests/dummy_obs.py
  2. 9
      tests/test_catalogs.py
  3. 9
      tests/test_observation.py
  4. 9
      tests/test_stations.py
  5. 22
      vlbiplanobs/Checkbox.py
  6. 78
      vlbiplanobs/graphical_elements.py

@ -4,22 +4,15 @@
By running it in an interactive mode it allows me to test all parts.
Note that this is not a full test...
"""
import os
import sys
import numpy as np
# import matplotlib.pyplot as plt
# import matplotlib.dates as mdates
from astropy import coordinates as coord
from astropy import units as u
from astropy.time import Time
from astropy.io import ascii
from vlbiplanobs import freqsetups as fs
from vlbiplanobs import stations
from vlbiplanobs import observation
target = observation.Source('10h58m29.6s +81d33m58.8s', name='Target')
obs = observation.Observation(target=target)
@ -33,6 +26,7 @@ obs.inttime = 2
all_stations = stations.Stations.get_stations_from_configfile()
def get_selected_antennas(list_of_selected_antennas):
"""Given a list of antenna codenames, it returns a Stations object containing
all given antennas.
@ -43,7 +37,6 @@ def get_selected_antennas(list_of_selected_antennas):
return selected_antennas
# evn6 = ['Ef', 'Jb2', 'On', 'Hh', 'T6', 'Wb', 'Sv', 'Zc']
evn6 = ['Ef', 'Jb2', 'On', 'Hh', 'T6', 'Wb', 'Sv', 'Zc', 'Pa', 'Mp', 'Ho', 'Nl', 'Pt', 'Sc', 'Kp', 'Hn']
obs.stations = get_selected_antennas(evn6)
@ -67,11 +60,6 @@ dirty_map_uniform = obs.get_dirtymap(robust='uniform')
# ax.set_xlabel(f"Time (UTC) - {obs.times.datetime[0].strftime('%d-%m-%Y')}")
def get_decimal_hour(dts):
return np.array([t.hour+(t.minute/60)+(t.second/3600) for t in dts])
@ -81,25 +69,17 @@ def t2gst(t):
# t2 = np.array([tt.hour+tt.minute/60+tt.second/3600 for tt in t])
gst_t_slope = 1.00273791 # Is this universal? it is about 16.4 min
# get the offset from the first timestamp
offset = -obs.times.datetime[0].hour-obs.times.datetime[0].minute/60 + \
obs.gstimes[0].hour
offset = -obs.times.datetime[0].hour-obs.times.datetime[0].minute/60 + obs.gstimes[0].hour
return (t*gst_t_slope + offset) % 24
# TODO: I see a 0.027379 hour offset in the example... is this stable?
def gst2t(t):
gst_t_slope = 1.00273791 # Is this universal? it is about 16.4 min
gst_t_slope = 1.00273791 # Is this universal? it is about 16.4 min
# get the offset from the first timestamp
offset = -obs.times.datetime[0].hour-obs.times.datetime[0].minute/60 + \
obs.gstimes[0].hour
offset = -obs.times.datetime[0].hour - obs.times.datetime[0].minute/60 + obs.gstimes[0].hour
return ((t - offset)/gst_t_slope) % 24
# ax_gst = ax.secondary_xaxis("top", functions=(t2gst, gst2t))
# ax_gst.cla()

@ -1,13 +1,8 @@
import pytest
import configparser
from importlib import resources
import numpy as np
from vlbiplanobs import stations
from astropy import coordinates as coord
from astropy import units as u
from astropy.time import Time
from astroplan import Observer, FixedTarget
def test_stations_catalog():
@ -63,7 +58,3 @@ def test_network_catalog():
temp = int(config[networkname]['max_datarate'])

@ -1,15 +1,8 @@
import pytest
import configparser
from importlib import resources
import numpy as np
# from vlbiplanobs import stations
from vlbiplanobs import observation as obs
from astropy import coordinates as coord
from astropy import units as u
from astropy.time import Time
from astroplan import Observer, FixedTarget
def test_source():
@ -37,5 +30,3 @@ def test_source():
assert s2.name == 'a_name'
assert s1.coord == s2.coord
assert s3.name == 'Cyg X-1'

@ -1,14 +1,10 @@
import pytest
import configparser
from importlib import resources
import numpy as np
from vlbiplanobs import stations
from astropy import coordinates as coord
from astropy import units as u
from astropy.time import Time
from astroplan import Observer, FixedTarget
from astroplan import FixedTarget
def test_station_init():
@ -38,7 +34,7 @@ def test_station_functions():
"""
sefds = {'18': 100, '6': 40, '0.1': 200}
a_station = stations.Station('name', 'Nm', 'VLBI',
coord.EarthLocation(3839348.973*u.m, 430403.51*u.m, 5057990.099*u.m), sefds, 20)
coord.EarthLocation(3839348.973*u.m, 430403.51*u.m, 5057990.099*u.m), sefds, 20)
assert isinstance(a_station.name, str)
assert isinstance(a_station.fullname, str)
assert a_station.fullname == a_station.name
@ -69,4 +65,3 @@ def test_station_functions():
assert np.equal(a_station.elevation(times2, src1).value, a_station.altaz(times2, src1).alt.value)[0]

@ -17,32 +17,40 @@ components in an app.
- key (string; optional): A unique identifier for the component, used to improve
performance by React.js while rendering components
See https://reactjs.org/docs/lists-and-keys.html for more info
- loading_state (dict; optional): Object that holds the loading state object coming from dash-renderer. loading_state has the following type: dict containing keys 'is_loading', 'prop_name', 'component_name'.
- loading_state (dict; optional): Object that holds the loading state object coming from dash-renderer.
loading_state has the following type: dict containing keys 'is_loading', 'prop_name', 'component_name'.
Those keys have the following types:
- is_loading (boolean; optional): Determines if the component is loading or not
- prop_name (string; optional): Holds which property is loading
- component_name (string; optional): Holds the name of the component that is loading
- persistence (boolean | string | number; optional): Used to allow user interactions in this component to be persisted when
- persistence (boolean | string | number; optional):
Used to allow user interactions in this component to be persisted when
the component - or the page - is refreshed. If `persisted` is truthy and
hasn't changed from its previous value, a `value` that the user has
changed while using the app will keep that change, as long as
the new `value` also matches what was given originally.
Used in conjunction with `persistence_type`.
- persisted_props (list of a value equal to: 'checked's; default ['checked']): Properties whose user interactions will persist after refreshing the
- persisted_props (list of a value equal to: 'checked's; default ['checked']):
Properties whose user interactions will persist after refreshing the
component or the page. Since only `value` is allowed this prop can
normally be ignored.
- persistence_type (a value equal to: 'local', 'session', 'memory'; default 'local'): Where persisted user changes will be stored:
- persistence_type (a value equal to: 'local', 'session', 'memory'; default 'local'):
Where persisted user changes will be stored:
memory: only kept in memory, reset on page refresh.
local: window.localStorage, data is kept after the browser quit.
session: window.sessionStorage, data is cleared once the browser quit."""
@_explicitize_args
def __init__(self, id=Component.UNDEFINED, checked=Component.UNDEFINED, disabled=Component.UNDEFINED, className=Component.UNDEFINED, style=Component.UNDEFINED, key=Component.UNDEFINED, loading_state=Component.UNDEFINED, persistence=Component.UNDEFINED, persisted_props=Component.UNDEFINED, persistence_type=Component.UNDEFINED, **kwargs):
def __init__(self, id=Component.UNDEFINED, checked=Component.UNDEFINED, disabled=Component.UNDEFINED,
className=Component.UNDEFINED, style=Component.UNDEFINED, key=Component.UNDEFINED,
loading_state=Component.UNDEFINED, persistence=Component.UNDEFINED,
persisted_props=Component.UNDEFINED, persistence_type=Component.UNDEFINED, **kwargs):
self._prop_names = ['id', 'checked', 'disabled', 'className', 'style', 'key', 'loading_state', 'persistence', 'persisted_props', 'persistence_type']
self._type = 'Checkbox'
self._namespace = 'dash_bootstrap_components'
self._valid_wildcard_attributes = []
self.available_properties = ['id', 'checked', 'disabled', 'className', 'style', 'key', 'loading_state', 'persistence', 'persisted_props', 'persistence_type']
self.available_wildcard_properties = []
self.available_properties = ['id', 'checked', 'disabled', 'className', 'style', 'key',
'loading_state', 'persistence', 'persisted_props', 'persistence_type']
self.available_wildcard_properties = []
_explicit_args = kwargs.pop('_explicit_args')
_locals = locals()

@ -425,7 +425,7 @@ def summary_printable(app, obs):
return pdf
# Single string version
return "EVN Observation Planner - Summary Report\n\n\n" \
return "EVN Observation Planner - Summary Report\n\n\n"
"- Schedule\n\n" \
f"{obs.print_obs_times()}.\n" \
f"{optimal_units(obs.ontarget_time, [u.h, u.min, u.s, u.ms]):.3n} are on target.\n" \
@ -440,7 +440,8 @@ def summary_printable(app, obs):
f"time integration: {optimal_units(obs.inttime, [u.s,u.ms,u.us]):.2n}.\n\n\n" \
"- VLBI Network\n\n" \
f"Participating antennas: {ants}.\n" \
f"The expected synthesized beam will be approx. {synthbeam['bmaj'].to(synthbeam_units).value:.3n} x {synthbeam['bmin'].to(synthbeam_units):.3n}, PA = {synthbeam['pa']:.3n}.\n" \
f"The expected synthesized beam will be approx. {synthbeam['bmaj'].to(synthbeam_units).value:.3n} " \
f"x {synthbeam['bmin'].to(synthbeam_units):.3n}, PA = {synthbeam['pa']:.3n}.\n" \
f"Expected rms thermal noise level: {rms:.3n}/beam.\n" \
f"Per spectral channel: {rms_channel:.3n}/beam.\n" \
f"Time smearing (10% loss): {optimal_units(tm_smearing, [u.arcmin, u.arcsec]):.3n}\n" \
@ -452,15 +453,16 @@ def summary_printable(app, obs):
html.H5("Schedule"),
html.P(f"{obs.print_obs_times()}."),
html.P(f"{optimal_units(obs.ontarget_time, [u.h, u.min, u.s, u.ms]):.3n} are on target."),
html.P(f"Target source: {obs.target.coord.to_string('hmsdms')}" \
f"{' ('+obs.target.name+').' if obs.target.name != 'Source' else '.'}" \
if obs.target is not None else 'Target source: Unspecified.'),
html.P(f"Target source: {obs.target.coord.to_string('hmsdms')}"
f"{' ('+obs.target.name+').' if obs.target.name != 'Source' else '.'}"
if obs.target is not None else 'Target source: Unspecified.'),
html.P(f"FITS file size: {optimal_units(obs.datasize(), [u.TB, u.GB, u.MB, u.kB]):.3n}."),
html.H5("Frequency Setup"),
html.P(f"Central frequency: {optimal_units(obs.frequency, [u.GHz, u.MHz]):.3n} " \
html.P(f"Central frequency: {optimal_units(obs.frequency, [u.GHz, u.MHz]):.3n} "
f"({optimal_units(obs.wavelength, [u.m, u.cm, u.mm]):.2n})."),
html.P(f"{obs.subbands} subbands of {optimal_units(obs.bandwidth/obs.subbands, [u.GHz, u.MHz, u.kHz]):.3n} each."),
html.P(f"{obs.subbands} subbands of "
f"{optimal_units(obs.bandwidth/obs.subbands, [u.GHz, u.MHz, u.kHz]):.3n} each."),
html.P(f"Channels per subband: {obs.channels}."),
html.P(f"Polarization: {pol_dict[obs.polarizations]}."),
html.P(f"time integration: {optimal_units(obs.inttime, [u.s,u.ms,u.us]):.2n}."),
@ -468,7 +470,9 @@ def summary_printable(app, obs):
html.H5("VLBI Network"),
html.P(f"Participating antennas: {ants}."),
html.P(f"The expected synthesized beam will be approx. {synthbeam['bmaj'].to(synthbeam_units).value:.3n} x {synthbeam['bmin'].to(synthbeam_units):.3n}, PA = {synthbeam['pa']:.3n}."),
html.P("The expected synthesized beam will be approx. "
f"{synthbeam['bmaj'].to(synthbeam_units).value:.3n} x "
f"{synthbeam['bmin'].to(synthbeam_units):.3n}, PA = {synthbeam['pa']:.3n}."),
html.P(f"Expected rms thermal noise level: {rms:.3n}/beam."),
html.P(f"Per spectral channel: {rms_channel:.3n}/beam."),
html.P(f"Time smearing (10% loss): {optimal_units(tm_smearing, [u.arcmin, u.arcsec]):.3n}"),
@ -478,7 +482,6 @@ def summary_printable(app, obs):
])
#################################################################################
# Some small graphical elements
@ -500,11 +503,11 @@ def baseline_img(app, is_long=True):
is for a long baseline (True) or for a short baseline (False).
"""
if is_long:
baseline = html.Td(className='baseline-td-hr',children=html.Hr(className='hr-baseline'),
style={'width': '80%', 'padding': '0', 'margin': '0'})
baseline = html.Td(className='baseline-td-hr', children=html.Hr(className='hr-baseline'),
style={'width': '80%', 'padding': '0', 'margin': '0'})
else:
baseline = html.Td(className='baseline-td-hr',children=html.Hr(className='hr-baseline'),
style={'width': '30%', 'padding': '0', 'margin': '0'})
baseline = html.Td(className='baseline-td-hr', children=html.Hr(className='hr-baseline'),
style={'width': '30%', 'padding': '0', 'margin': '0'})
return [html.Table(className='baseline-table', children=[
html.Tr(className='baseline-tr', children=[
@ -518,8 +521,6 @@ def baseline_img(app, is_long=True):
])])]
#################################################################################
# Some small graphical elements
@ -566,7 +567,6 @@ def optimal_units(value, units):
return value.to(units[-1])
#################################################################################
# Cards from the initial window where user keeps selecting options
@ -601,7 +601,6 @@ def initial_window_start(app):
]
def initial_window_pick_band():
"""Initial window with the introduction to the EVN Observation Planner and the band selection.
"""
@ -616,8 +615,8 @@ def initial_window_pick_band():
dcc.Slider(id='initial-band', min=0, max=len(fs.bands)-1,
value=tuple(fs.bands).index('18cm'), step=-1,
marks={i: fq for i,fq in enumerate(fs.bands)},
persistence=True, # tooltip={'always_visible': True, 'placement': 'top'},
updatemode='drag', included=False)), html.Br(), #html.Br(),
persistence=True,
updatemode='drag', included=False)), html.Br(),
html.Div(id='initial-pickband-label', className='row justify-content-center', children=''),
html.Br(),
html.Div(className='row text-center',
@ -639,7 +638,7 @@ def initial_window_pick_network(app, vlbi_networks):
]),
html.Br(),
html.Div(className='row justify-content-center', children=[
network_card(app, a_network, vlbi_networks[a_network]['name'], "") \
network_card(app, a_network, vlbi_networks[a_network]['name'], "")
for a_network in vlbi_networks if a_network != 'e-EVN'
]),
html.Br(),
@ -676,7 +675,7 @@ def initial_window_pick_time():
value=SourceEpoch.SOURCE_AND_EPOCH.value, id="initial-timeselection",
inline=True, persistence=True),
html.Br(),
], className='col-6', inline=True), #),
], className='col-6', inline=True),
html.Div(className='col-6', children=[
html.Small("", id='timeselection-div-smalltext', style={'color': '#999999'})
])]
@ -732,9 +731,6 @@ def initial_window_pick_time():
html.Small(id='initial-error_duration', className='form-text text-danger')
]),
]),
# html.Div(id='initial-timeselection-div-guess', className='row justify-content-center',
# children=[
# html.Small("Choose this option if you just want to find out when your source will "
@ -783,7 +779,6 @@ def initial_window_pick_time():
]
def initial_window_pick_mode(app):
"""Initial window to select the observing mode: spectral line or continuum observation.
"""
@ -807,20 +802,21 @@ def initial_window_pick_mode(app):
]), className='text-center shadow-0')
),
html.Button(id='button-mode-line', className='card-button btn btn-gray m-4',
title='Go to the main window containing all options to configure.',
children=[dbc.Card(dbc.CardBody([
html.H5("Spectral line mode", className='card-title'),
html.Img(height='80rem', src=app.get_asset_url('waves-line.png'),
className='card-text m-3'),
html.Br(),
html.P("Provides higher frequency resolution", className='card-text px-0'),
html.P("In general uses a reduced bandwidth", className='card-text px-0')
]), className='text-center shadow-0')]
title='Go to the main window containing all options to configure.',
children=[dbc.Card(dbc.CardBody([
html.H5("Spectral line mode", className='card-title'),
html.Img(height='80rem', src=app.get_asset_url('waves-line.png'),
className='card-text m-3'),
html.Br(),
html.P("Provides higher frequency resolution", className='card-text px-0'),
html.P("In general uses a reduced bandwidth", className='card-text px-0')
]), className='text-center shadow-0')]
)
]),
html.Div(hidden=True, children=[dbc.Checklist(id='is_line',
options=[{'label': 'line obs', 'value': False}], value=[])])
]
options=[{'label': 'line obs', 'value': False}],
value=[])])
]
def initial_window_final():
@ -831,14 +827,14 @@ def initial_window_final():
html.Div(className='row justify-content-center', children=[
html.H3('You are now ready'),
html.P(["Press compute to produce the summary for your observation. "
"You would then see different tabs with the information. "
"You will also be able to change the setup and re-compute it."]),
"You would then see different tabs with the information. "
"You will also be able to change the setup and re-compute it."]),
html.Br(),
]),
html.Div(style={'height': '4rem'}),
html.Div(className='row justify-content-center',
children=html.Button('Compute', id='antenna-selection-button',
className='btn btn-primary btn-lg')),
children=html.Button('Compute', id='antenna-selection-button',
className='btn btn-primary btn-lg')),
html.Br(),
html.Div(className='col-9 text-center justify-content-center', children=[
dcc.Loading(id="loading", children=[html.Div(id="loading-output",
@ -846,7 +842,7 @@ def initial_window_final():
type="dot"),
]),
html.Div(className='row text-center justify-content-center',
children=dcc.ConfirmDialog(id='global-error', message=''))
children=dcc.ConfirmDialog(id='global-error', message=''))
])]

Loading…
Cancel
Save