Skip to content

Commit

Permalink
MAINT: run autopep8 and touch up manually
Browse files Browse the repository at this point in the history
  • Loading branch information
bsipocz committed Oct 17, 2022
1 parent 166bd83 commit dca29ac
Show file tree
Hide file tree
Showing 31 changed files with 492 additions and 464 deletions.
14 changes: 9 additions & 5 deletions pyvo/dal/adhoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class AdhocServiceResultsMixin:
"""
Mixing for adhoc:service functionallity for results classes.
"""

def __init__(self, votable, url=None, session=None):
super().__init__(votable, url=url, session=session)

Expand Down Expand Up @@ -231,6 +232,7 @@ class DatalinkRecordMixin:
- ``getdataset()`` considers datalink.
"""

def getdatalink(self):
try:
datalink = self._results.get_adhocservice_by_ivoid(DATALINK_IVOID)
Expand Down Expand Up @@ -384,9 +386,9 @@ def from_resource(cls, rows, resource, session=None, **kwargs):
elif np.isscalar(input_param.value) and input_param.value:
query_params[name] = input_param.value
elif (
not np.isscalar(input_param.value) and
input_param.value.all() and
len(input_param.value)
not np.isscalar(input_param.value)
and input_param.value.all()
and len(input_param.value)
):
query_params[name] = " ".join(
str(_) for _ in input_param.value)
Expand Down Expand Up @@ -562,9 +564,9 @@ def bysemantics(self, semantics, include_narrower=True):
for term in core_terms:
if term in voc["terms"]:
additional_terms.extend(voc["terms"][term]["narrower"])
core_terms = core_terms+additional_terms
core_terms = core_terms + additional_terms

semantics = set("#"+term for term in core_terms) | set(other_terms)
semantics = set("#" + term for term in core_terms) | set(other_terms)
for record in self:
if record.semantics in semantics:
yield record
Expand Down Expand Up @@ -636,6 +638,7 @@ class SodaRecordMixin:
If used, it's result class must have
`pyvo.dal.datalink.AdhocServiceResultsMixin` mixed in.
"""

def _get_soda_resource(self):
try:
return self._results.get_adhocservice_by_ivoid(SODA_SYNC_IVOID)
Expand Down Expand Up @@ -856,6 +859,7 @@ class SodaQuery(DatalinkQuery, AxisParamMixin):
"""
a class for preparing a query to a SODA Service.
"""

def __init__(
self, baseurl, circle=None, range=None, polygon=None, band=None,
**kwargs):
Expand Down
3 changes: 2 additions & 1 deletion pyvo/dal/dbapi2.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def __init__(self, *values):
self._values = values

@property
def id(self): return self._values[0]
def id(self):
return self._values[0]

def __eq__(self, other):
if not isinstance(other, TypeObject):
Expand Down
16 changes: 12 additions & 4 deletions pyvo/dal/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def unify_value(func):
Decorator for serialize method to do unit conversion on input value.
The decorator converts the input value to the unit in the input param.
"""

def wrapper(self, value):
if self._param.unit:
value = Quantity(value)
Expand Down Expand Up @@ -80,6 +81,7 @@ class Converter:
Base class for all converters. Each subclass handles the conversion of a
input value based on a specific xtype.
"""

def __init__(self, param):
self._param = param

Expand Down Expand Up @@ -231,6 +233,7 @@ class AbstractDalQueryParam(MutableSet, metaclass=abc.ABCMeta):
Duplicates in the set are determine based on the formatted DAL
representation of the value.
"""

def __init__(self, values=()):
"""
Parameters
Expand Down Expand Up @@ -281,6 +284,7 @@ class StrQueryParam(AbstractDalQueryParam):
Representation of a unitless, single-value parameter. The formatter is
just a str() cast
"""

def get_dal_format(self, val):
return str(val)

Expand All @@ -290,6 +294,7 @@ class PosQueryParam(AbstractDalQueryParam):
Representation of a position parameter. Depending on the number
of entries, the resulting DAL format is CIRCLE, RANGE or POLYGON.
"""

def get_dal_format(self, val):
"""
formats the tuple values into a string to be sent to the service
Expand All @@ -308,7 +313,7 @@ def get_dal_format(self, val):
'even 6 and above (POLYGON) accepted.'.format(val))
return '{} {}'.format(shape, ' '.join(
[str(val.to(u.deg).value) if isinstance(val, Quantity) else
str((val*u.deg).value) for val in val]))
str((val * u.deg).value) for val in val]))

def _validate_pos(self, pos):
"""
Expand All @@ -323,7 +328,7 @@ def _validate_pos(self, pos):
radius = pos[2] * u.deg
else:
radius = pos[2]
if radius <= 0*u.deg or radius.to(u.deg) > 90*u.deg:
if radius <= 0 * u.deg or radius.to(u.deg) > 90 * u.deg:
raise ValueError('Invalid circle radius: {}'.format(radius))
elif len(pos) == 4:
ra_min = pos[0] if isinstance(pos[0], Quantity) else pos[0] * u.deg
Expand Down Expand Up @@ -366,6 +371,7 @@ class IntervalQueryParam(AbstractDalQueryParam):
"""
Representation of an interval DAL parameter.
"""

def __init__(self, unit=None, equivalencies=None):
"""
Parameters
Expand Down Expand Up @@ -397,10 +403,10 @@ def get_dal_format(self, val):
low, high))
if self._unit:
if not isinstance(low, Quantity):
low = low*self._unit
low = low * self._unit
low = low.to(self._unit, equivalencies=self._equivalencies).value
if not isinstance(high, Quantity):
high = high*self._unit
high = high * self._unit
high = high.to(self._unit, equivalencies=self._equivalencies).value

if low > high:
Expand All @@ -414,6 +420,7 @@ class TimeQueryParam(AbstractDalQueryParam):
"""
Representation of a timestamp parameter.
"""

def get_dal_format(self, val):
if isinstance(val, tuple):
if len(val) == 1:
Expand Down Expand Up @@ -442,6 +449,7 @@ class EnumQueryParam(AbstractDalQueryParam):
"""
Representation of an enum parameter
"""

def __init__(self, allowed_values):
"""
Parameters
Expand Down
4 changes: 2 additions & 2 deletions pyvo/dal/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,8 @@ def getdataurl(self):
for fieldname in self._results.fieldnames:
field = self._results.getdesc(fieldname)
if (field.utype and "access.reference" in field.utype.lower()) or (
field.ucd and "meta.dataset" in field.ucd and
"meta.ref.url" in field.ucd
field.ucd and "meta.dataset" in field.ucd
and "meta.ref.url" in field.ucd
):
out = self[fieldname]
if isinstance(out, bytes):
Expand Down
32 changes: 16 additions & 16 deletions pyvo/dal/sia2.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ def __init__(self, baseurl, session=None):
if cap.standardid.lower() == SIA2_STANDARD_ID.lower():
for interface in cap.interfaces:
if interface.accessurls and \
not (len(interface.securitymethods) == 1 and
interface.securitymethods[0].standardid ==
'ivo://ivoa.net/sso#BasicAA'):
not (len(interface.securitymethods) == 1
and interface.securitymethods[0].standardid
== 'ivo://ivoa.net/sso#BasicAA'):
self.query_ep = interface.accessurls[0].content
break

Expand Down Expand Up @@ -712,22 +712,22 @@ def access_estsize(self):
required. Provision of dataset size estimates is important whenever it
is possible that datasets can be very large.
"""
return self.get('access_estsize')*1000*u.byte
return self.get('access_estsize') * 1000 * u.byte

# SPATIAL CHARACTERISATION
@property
def s_ra(self):
"""
ICRS Right Ascension of the center of the observation
"""
return self.get('s_ra')*u.deg
return self.get('s_ra') * u.deg

@property
def s_dec(self):
"""
CRS Declination of the center of the observation
"""
return self.get('s_dec')*u.deg
return self.get('s_dec') * u.deg

@property
def s_fov(self):
Expand All @@ -744,7 +744,7 @@ def s_fov(self):
data product. The spatial coverage of a data product can be more
precisely specified using the region attribute.
"""
return self.get('s_fov')*u.deg
return self.get('s_fov') * u.deg

@property
def s_region(self):
Expand Down Expand Up @@ -773,7 +773,7 @@ def s_resolution(self):
characterisation may be necessary to fully specify the spatial
characteristics of the data.
"""
return self.get('s_resolution')*u.arcsec
return self.get('s_resolution') * u.arcsec

@property
def s_xel1(self):
Expand Down Expand Up @@ -809,7 +809,7 @@ def s_resolution_min(self):
Resolution min value on spatial axis (FHWM of PSF)
"""
rmin = self.get('s_resolution_min', default=None)
return rmin if not rmin else rmin*u.arcsec
return rmin if not rmin else rmin * u.arcsec

@property
def s_resolution_max(self):
Expand Down Expand Up @@ -898,14 +898,14 @@ def t_exptime(self):
often adjusted to achieve similar signal to noise ratio for different
targets.
"""
return self.get('t_exptime')*u.second
return self.get('t_exptime') * u.second

@property
def t_resolution(self):
"""
Estimated or average value of the temporal resolution.
"""
return self.get('t_resolution')*u.second
return self.get('t_resolution') * u.second

@property
def t_calib_status(self):
Expand All @@ -922,7 +922,7 @@ def t_stat_error(self):
Time coord statistical error on the time measurements in seconds
"""
ter = self.get('t_stat_error', default=None)
return ter if not ter else ter*u.second
return ter if not ter else ter * u.second

# SPECTRAL CHARACTERISATION
@property
Expand Down Expand Up @@ -961,14 +961,14 @@ def em_min(self):
"""
Minimum of the spectral interval covered by the observation
"""
return self.get('em_min')*u.meter
return self.get('em_min') * u.meter

@property
def em_max(self):
"""
Maximum of the spectral interval covered by the observation
"""
return self.get('em_max')*u.meter
return self.get('em_max') * u.meter

@property
def em_res_power(self):
Expand Down Expand Up @@ -1001,7 +1001,7 @@ def em_resolution(self):
power is preferable due to the LSF variation along the spectral axis.
"""
if 'em_resolution' in self.keys():
return self.get('em_resolution')*u.meter
return self.get('em_resolution') * u.meter
return None

@property
Expand All @@ -1010,7 +1010,7 @@ def em_stat_error(self):
Spectral coord statistical error (accuracy along the spectral axis)
"""
if 'em_stat_error' in self.keys():
return self.get('em_stat_error')*u.meter
return self.get('em_stat_error') * u.meter
return None

# OBSERVABLE AXIS
Expand Down
14 changes: 7 additions & 7 deletions pyvo/dal/tests/test_adhoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def test_pos():
class TestClass(dict, AxisParamMixin):
pass
test_obj = TestClass()
test_obj.pos.add((1, 2, 3)*u.deg)
test_obj.pos.add((1, 2, 3) * u.deg)
assert len(test_obj._pos) == 1
assert test_obj['POS'] == ['CIRCLE 1.0 2.0 3.0']

Expand All @@ -41,9 +41,9 @@ class TestClass(dict, AxisParamMixin):
'POLYGON 1.0 2.0 3.0 4.0 5.0 6.0']

# test borders
test_obj.pos.discard((1, 2, 3)*u.deg)
test_obj.pos.discard((1, 2, 3) * u.deg)
test_obj.pos.discard((1, 2, 3, 4, 5, 6))
assert(len(test_obj._pos) == 0)
assert (len(test_obj._pos) == 0)
test_obj.pos.add((0, 90, 90))
assert len(test_obj._pos) == 1
assert test_obj['POS'] == ['CIRCLE 0.0 90.0 90.0']
Expand Down Expand Up @@ -92,12 +92,12 @@ class TestClass(dict, AxisParamMixin):
test_obj.band.add(33)
assert 33 in test_obj.band
assert test_obj['BAND'] == ['33.0 33.0']
test_obj.band.add((50*u.meter, 500))
test_obj.band.add((50 * u.meter, 500))
assert 33 in test_obj.band
assert (50*u.meter, 500) in test_obj.band
assert (50 * u.meter, 500) in test_obj.band
assert test_obj['BAND'] == ['33.0 33.0', '50.0 500.0']
test_obj.band.discard(33)
assert (50*u.meter, 500) in test_obj.band
assert (50 * u.meter, 500) in test_obj.band
assert test_obj['BAND'] == ['50.0 500.0']
test_obj.band.pop()
assert not test_obj.band
Expand Down Expand Up @@ -198,7 +198,7 @@ def test_soda_query():
assert not hasattr(test_obj, '_polygon')
assert not hasattr(test_obj, '_range')

test_obj.range = (8, 9, 3, 4)*u.deg
test_obj.range = (8, 9, 3, 4) * u.deg
assert test_obj['POS'] == 'RANGE 8.0 9.0 3.0 4.0'
assert test_obj._range is not None
assert not hasattr(test_obj, '_polygon')
Expand Down
10 changes: 5 additions & 5 deletions pyvo/dal/tests/test_datalink.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def test_access_with_expansion(self):
def test_access_without_expansion(self):
datalink = DatalinkResults.from_result_url('http://example.com/proc')
res = [r["access_url"] for r in datalink.bysemantics(
["#this", "#preview"], include_narrower=False)]
["#this", "#preview"], include_narrower=False)]
assert len(res) == 2
assert res[0].endswith("eq010000ms/20100927.comb_avg.0001.fits.fz")
assert res[1].endswith("http://dc.zah.uni-heidelberg.de/wider.dat")
Expand All @@ -183,10 +183,10 @@ def test_all_mixed(self):
datalink = DatalinkResults.from_result_url('http://example.com/proc')
res = [r["access_url"]
for r in datalink.bysemantics([
"urn:example:rdf/dlext#oracle",
'http://www.ivoa.net/rdf/datalink/core#preview',
'#this',
'non-existing-term'])]
"urn:example:rdf/dlext#oracle",
'http://www.ivoa.net/rdf/datalink/core#preview',
'#this',
'non-existing-term'])]
assert len(res) == 4
assert res[0].endswith("eq010000ms/20100927.comb_avg.0001.fits.fz")
assert res[1].endswith("comb_avg.0001.fits.fz?preview=True")
Expand Down
8 changes: 4 additions & 4 deletions pyvo/dal/tests/test_mimetype.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
get_pkg_data_contents, package=__package__, encoding='binary')

try:
from PIL import Image
from PIL import Image # noqa: F401
HAS_PILLOW = True
except ImportError:
HAS_PILLOW = False
Expand All @@ -44,14 +44,14 @@ def callback(request, context):
@pytest.mark.skipif('not HAS_PILLOW')
def test_mime_object_maker():

assert 'Text content' == mime_object_maker(mime_url+'mime-text',
assert 'Text content' == mime_object_maker(mime_url + 'mime-text',
'text/csv')

img = mime_object_maker(mime_url+'image', 'image/jpeg')
img = mime_object_maker(mime_url + 'image', 'image/jpeg')
assert img
assert 'JPEG' == img.format

fits = mime_object_maker(mime_url+'fits', 'application/fits')
fits = mime_object_maker(mime_url + 'fits', 'application/fits')
assert 2 == len(fits)

# error cases
Expand Down
Loading

0 comments on commit dca29ac

Please sign in to comment.