Skip to content

Commit

Permalink
working on style checks
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverba137 committed Dec 15, 2023
1 parent 779f94d commit 3fffc03
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 105 deletions.
6 changes: 3 additions & 3 deletions pydl/photoop/tests/test_image.py
Expand Up @@ -13,7 +13,7 @@ def test_sdss_psf_recon():
with fits.open(psField) as hdulist:
psf = sdss_psf_recon(hdulist[3].data, 600, 500)
assert np.allclose(psf[23:26, 25],
np.array([0.02220068, 0.0738798 , 0.11940149]))
np.array([0.02220068, 0.0738798, 0.11940149]))


def test_sdss_psf_norm():
Expand All @@ -22,7 +22,7 @@ def test_sdss_psf_norm():
psf = sdss_psf_recon(hdulist[3].data, 600, 500, normalize=100.0)
assert np.allclose(psf.sum(), 100.0)
assert np.allclose(psf[23:26, 25],
np.array([2.194198, 7.301887, 11.801009]))
np.array([2.194198, 7.301887, 11.801009]))


def test_sdss_psf_recon_trim():
Expand All @@ -31,4 +31,4 @@ def test_sdss_psf_recon_trim():
psf = sdss_psf_recon(hdulist[3].data, 600, 500, trimdim=(25, 25))
# print(psf)
assert np.allclose(psf[10:13, 12],
np.array([0.02220068, 0.0738798 , 0.11940149]))
np.array([0.02220068, 0.0738798, 0.11940149]))
3 changes: 1 addition & 2 deletions pydl/pydlutils/coord.py
Expand Up @@ -47,8 +47,7 @@ class SDSSMuNu(ac.BaseCoordinateFrame):
defaultunit=u.deg)
]
}
frame_specific_representation_info['unitspherical'] = (
frame_specific_representation_info['spherical'])
frame_specific_representation_info['unitspherical'] = frame_specific_representation_info['spherical']
stripe = ac.Attribute(default=0)
node = ac.QuantityAttribute(default=ac.Angle(95.0, unit=u.deg),
unit=u.deg)
Expand Down
3 changes: 1 addition & 2 deletions pydl/pydlutils/mangle.py
Expand Up @@ -759,8 +759,7 @@ def set_use_caps(polygon, index_list, add=False, tol=1.0e-10,
if ((np.absolute(polygon.cm[i] -
polygon.cm[j]) < tol) or
((polygon.cm[i] +
polygon.cm[j]) < tol and
not allow_neg_doubles)):
polygon.cm[j]) < tol and not allow_neg_doubles)):
#
# Don't use
#
Expand Down
12 changes: 4 additions & 8 deletions pydl/pydlutils/math.py
Expand Up @@ -42,12 +42,10 @@ def __init__(self, bvec, sqivar, amatrix):
else:
self.nstar = 1
self.bvec = bvec * sqivar
self.mmatrix = self.amatrix * np.tile(sqivar, self.nstar).reshape(
self.nstar, bvec.size).transpose()
self.mmatrix = self.amatrix * np.tile(sqivar, self.nstar).reshape(self.nstar, bvec.size).transpose()
mm = np.dot(self.mmatrix.T, self.mmatrix)
self.uu, self.ww, self.vv = svd(mm, full_matrices=False)
self.mmi = np.dot((self.vv.T / np.tile(self.ww, self.nstar).reshape(
self.nstar, self.nstar)), self.uu.T)
self.mmi = np.dot((self.vv.T / np.tile(self.ww, self.nstar).reshape(self.nstar, self.nstar)), self.uu.T)
return

@au.lazyproperty
Expand Down Expand Up @@ -152,15 +150,13 @@ def djs_median(array, dimension=None, width=None, boundary='none'):
bigarr = np.zeros(array.shape[0]+2*padsize, dtype=array.dtype)
bigarr[padsize:padsize+array.shape[0]] = array
bigarr[0:padsize] = array[0:padsize][::-1]
bigarr[padsize+array.shape[0]:padsize*2+array.shape[0]] = (
array[array.shape[0]-padsize:array.shape[0]][::-1])
bigarr[padsize+array.shape[0]:padsize*2+array.shape[0]] = (array[array.shape[0]-padsize:array.shape[0]][::-1])
f = median(bigarr, width)
medarray = f[padsize:padsize+array.shape[0]]
return medarray
elif array.ndim == 2:
bigarr = np.zeros((array.shape[0]+2*padsize,
array.shape[1]+2*padsize),
dtype=array.dtype)
array.shape[1]+2*padsize), dtype=array.dtype)
bigarr[padsize:padsize+array.shape[0], padsize:padsize+array.shape[1]] = array
# Copy into top + bottom
bigarr[0:padsize, padsize:array.shape[1]+padsize] = array[0:padsize, :][::-1, :]
Expand Down
26 changes: 12 additions & 14 deletions pydl/pydlutils/misc.py
Expand Up @@ -186,10 +186,9 @@ def hogg_iau_name(ra, dec, prefix='SDSS', precision=1):
des = des.astype(np.int32)
ded = ded.astype(np.int32)
dem = dem.astype(np.int32)
adformat = "{{0:02d}}{{1:02d}}{ras}{{3:s}}{{4:02d}}{{5:02d}}{des}".format(
ras=rasformat, des=desformat)
adstr = [adformat.format(*x) for x in zip(
rah, ram, ras, desgn, ded, dem, des)]
adformat = f"{{0:02d}}{{1:02d}}{rasformat}{{3:s}}{{4:02d}}{{5:02d}}{desformat}"
adstr = [adformat.format(*x)
for x in zip(rah, ram, ras, desgn, ded, dem, des)]
if prefix == '':
jstr = 'J'
else:
Expand All @@ -212,7 +211,7 @@ def hogg_iau_name_main(): # pragma: no cover
metavar='STR', default='SDSS',
help='Add this prefix to the name.')
parser.add_argument('ra', metavar='RA', type=float,
help='Right Ascension.')
help='Right Ascension.')
parser.add_argument('dec', metavar='Dec', type=float,
help='Declination.')
options = parser.parse_args()
Expand Down Expand Up @@ -344,8 +343,7 @@ def struct_print(array, filename=None, formatcodes=None, alias=None,
thisn = max(d.itemsize, len(tag))
thiscode = "{{{0:d}:{1:d}s}}".format(k, thisn)
else:
raise PydlutilsException(
"Unsupported kind: {0}".format(d.kind))
raise PydlutilsException("Unsupported kind: {0}".format(d.kind))
formatcodes[tag] = thiscode
nchar[tag] = thisn
#
Expand All @@ -362,11 +360,12 @@ def struct_print(array, filename=None, formatcodes=None, alias=None,
lines.append(hdr1)
else:
if not no_head:
hdr1 = (headstart + headsep.join([("{{0:{0:d}s}}".format(
nchar[tag])).format(alias[tag])
for tag in array.dtype.names]) + headend)
hdr2 = (headstart + headsep.join(['-' * nchar[tag]
for tag in array.dtype.names]) + headend)
hdr1 = (headstart +
headsep.join([("{{0:{0:d}s}}".format(nchar[tag])).format(alias[tag])
for tag in array.dtype.names]) + headend)
hdr2 = (headstart +
headsep.join(['-' * nchar[tag]
for tag in array.dtype.names]) + headend)
lines.append(hdr1)
lines.append(hdr2)
#
Expand All @@ -375,8 +374,7 @@ def struct_print(array, filename=None, formatcodes=None, alias=None,
rowformat = (colstart + colsep.join([formatcodes[tag]
for tag in array.dtype.names]) + colend)
for k in range(array.size):
lines.append(rowformat.format(
*([decode_mixed(l) for l in array[k].tolist()])))
lines.append(rowformat.format(*([decode_mixed(l) for l in array[k].tolist()])))
if html:
lines.append('</table>')
f = None # This variable will store a file handle
Expand Down
4 changes: 2 additions & 2 deletions pydl/pydlutils/sdss.py
Expand Up @@ -117,7 +117,7 @@ def sdss_astrombad(run, camcol, field, photolog_version='dr10'):
else:
iversion = 'tags/'+photolog_version
baseurl = ('https://svn.sdss.org/public/data/sdss/photolog/' +
'{0}/opfiles/opBadfields.par').format(iversion)
'{0}/opfiles/opBadfields.par').format(iversion)
filename = download_file(baseurl, cache=True)
else:
filename = os.path.join(os.getenv('PHOTOLOG_DIR'), 'opfiles',
Expand Down Expand Up @@ -599,7 +599,7 @@ def sdss_sweep_circle(ra, dec, radius, stype='star', allobj=False):
ira = np.array([ra])
idec = np.array([dec])
m1, m2, d12 = spherematch(index['RA'], index['DEC'], ira, idec,
radius+0.36, maxmatch=0)
radius+0.36, maxmatch=0)
if len(m1) == 0:
return None
if not allobj:
Expand Down
8 changes: 4 additions & 4 deletions pydl/pydlutils/tests/test_bspline.py
Expand Up @@ -44,9 +44,9 @@ def test_iterfit():


def test_cholesky_band():
ab = np.array([[ 8., 9., 10., 11., 12., 13., 14., 0., 0., 0.],
[ 1., 2., 3., 4., 5., 6., 0., 0., 0., 0.],
[ 1., 2., 3., 4., 5., 0., 0., 0., 0., 0.]])
ab = np.array([[8., 9., 10., 11., 12., 13., 14., 0., 0., 0.],
[1., 2., 3., 4., 5., 6., 0., 0., 0., 0.],
[1., 2., 3., 4., 5., 0., 0., 0., 0., 0.]])
l = np.array([[2.82842712, 2.97909382, 3.07877788, 3.1382224, 3.16559183, 3.16295604, 3.12782377, 0., 0., 0.],
[0.35355339, 0.62938602, 0.8371714, 1.01466666, 1.17093392, 1.31223108, 0., 0., 0., 0.],
[0.35355339, 0.67134509, 0.97441261, 1.27460692, 1.57948348, 0., 0., 0., 0., 0.]])
Expand All @@ -58,7 +58,7 @@ def test_cholesky_band():
assert len(w) > 0
assert str(w[0].message) == "Bad entries: [0]"
assert i == 0
# ab[0, :] = np.array([ 1., 2., 3., 4., 5., 6., 7., 0., 0., 0.])
# ab[0, :] = np.array([1., 2., 3., 4., 5., 6., 7., 0., 0., 0.])
# with pytest.warns(PydlutilsUserWarning) as w:
# i, ll = cholesky_band(ab)
# assert len(w) > 0
Expand Down
16 changes: 8 additions & 8 deletions pydl/pydlutils/tests/test_math.py
Expand Up @@ -11,13 +11,13 @@
def test_computechi2():
x = np.arange(20)
y = np.array([6.6198438, 1.3491303, 0.41035045, 9.4013375, 4.1103360,
4.3522868, 4.6338078, 4.7400367, 5.1860726, 5.1082748,
5.1084596, 5.2990997, 5.5987537, 5.7007504, 5.7855296,
4.1123709, 6.9437957, 4.9956179, 4.3724215, 3.6245063])
4.3522868, 4.6338078, 4.7400367, 5.1860726, 5.1082748,
5.1084596, 5.2990997, 5.5987537, 5.7007504, 5.7855296,
4.1123709, 6.9437957, 4.9956179, 4.3724215, 3.6245063])
sqivar = np.array([1.32531, 0.886090, 1.08384, 1.04489, 1.46807,
1.30800, 0.507725, 1.12840, 0.955025, 1.35925,
1.10126, 1.45690, 0.575700, 0.949710, 1.23368,
0.536489, 0.772543, 0.957729, 0.883976, 1.11559])
1.30800, 0.507725, 1.12840, 0.955025, 1.35925,
1.10126, 1.45690, 0.575700, 0.949710, 1.23368,
0.536489, 0.772543, 0.957729, 0.883976, 1.11559])
templates = np.vstack((np.ones((20,), dtype='d'), x)).transpose()
chi2 = computechi2(y, sqivar, templates)
#
Expand Down Expand Up @@ -49,9 +49,9 @@ def test_djs_median():
#
assert np.allclose(np.median(data), djs_median(data))
assert np.allclose(np.median(data2, axis=0),
djs_median(data2, dimension=0))
djs_median(data2, dimension=0))
assert np.allclose(np.median(data2, axis=1),
djs_median(data2, dimension=1))
djs_median(data2, dimension=1))
#
# Test widths.
#
Expand Down
18 changes: 8 additions & 10 deletions pydl/pydlutils/tests/test_misc.py
Expand Up @@ -19,10 +19,9 @@ def test_djs_laxisgen():
# 2d
#
l = np.array([[0, 0, 0, 0],
[1, 1, 1, 1],
[2, 2, 2, 2],
[3, 3, 3, 3]],
dtype='i4')
[1, 1, 1, 1],
[2, 2, 2, 2],
[3, 3, 3, 3]], dtype='i4')
assert (l == djs_laxisgen((4, 4))).all()
assert (l.T == djs_laxisgen((4, 4), iaxis=1)).all()
with pytest.raises(ValueError):
Expand Down Expand Up @@ -55,10 +54,9 @@ def test_djs_laxisnum():
# 2d
#
l = np.array([[0, 0, 0, 0],
[1, 1, 1, 1],
[2, 2, 2, 2],
[3, 3, 3, 3]],
dtype='i4')
[1, 1, 1, 1],
[2, 2, 2, 2],
[3, 3, 3, 3]], dtype='i4')
assert (l == djs_laxisnum((4, 4))).all()
assert (l.T == djs_laxisnum((4, 4), iaxis=1)).all()
with pytest.raises(ValueError):
Expand Down Expand Up @@ -109,7 +107,7 @@ def test_struct_print():
slist = np.array([(1, 2.34, 'five'),
(2, 3.456, 'seven'),
(3, -4.5678, 'nine')],
dtype=[('a', 'i4'), ('bb', 'f4'), ('ccc', 'S5')])
dtype=[('a', 'i4'), ('bb', 'f4'), ('ccc', 'S5')])
lines, css = struct_print(slist, silent=True)
assert lines[0] == 'a bb ccc '
assert lines[1] == '- ------------ -----'
Expand Down Expand Up @@ -165,7 +163,7 @@ def test_struct_print():
slist = np.array([(1, 2.34, 'five'),
(2, 3.456, 'seven'),
(3, -4.5678, 'nine')],
dtype=[('a', 'i4'), ('bb', 'f8'), ('ccc', 'S5')])
dtype=[('a', 'i4'), ('bb', 'f8'), ('ccc', 'S5')])
lines, css = struct_print(slist, silent=True, ddigit=3)
assert lines[0] == 'a bb ccc '
assert lines[1] == '- ---------- -----'
Expand Down
4 changes: 2 additions & 2 deletions pydl/pydlutils/tests/test_yanny.py
Expand Up @@ -320,9 +320,9 @@ def test_yanny(self):
# Test values
#
assert np.allclose(par['MYSTRUCT'].mag[0],
np.array([17.5, 17.546, 17.4, 16.1, 16.0]))
np.array([17.5, 17.546, 17.4, 16.1, 16.0]))
assert np.allclose(par['MYSTRUCT'].mag[5],
np.array([19.3, 18.2, 17.1, 16.0, 15.9]))
np.array([19.3, 18.2, 17.1, 16.0, 15.9]))
assert par['MYSTRUCT'].foo[1] == b"My dog has no nose."
assert np.allclose(par['MYSTRUCT'].c[2], 7.24345567)
assert (par['MYSTRUCT']['flags'][2] == np.array([123123, 0])).all()
Expand Down
3 changes: 1 addition & 2 deletions pydl/pydlutils/trace.py
Expand Up @@ -283,8 +283,7 @@ class TraceSet(object):
When initialized with x,y positions, this contains the fitted y
values.
"""
_func_map = {'poly': fpoly, 'legendre': flegendre,
'chebyshev': fchebyshev}
_func_map = {'poly': fpoly, 'legendre': flegendre, 'chebyshev': fchebyshev}

def __init__(self, *args, **kwargs):
"""This class can be initialized either with a set of xy positions,
Expand Down
16 changes: 6 additions & 10 deletions pydl/pydlutils/yanny.py
Expand Up @@ -865,8 +865,7 @@ def write(self, newfile=None, comments=None):
"{0} exists, aborting write!".format(newfile))
if comments is None:
basefile = os.path.basename(newfile)
timestamp = datetime.datetime.utcnow().strftime(
'%Y-%m-%d %H:%M:%S UTC')
timestamp = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S UTC')
comments = f"""#
# {basefile}
#
Expand Down Expand Up @@ -948,8 +947,7 @@ def append(self, datatable):
if not isinstance(datatable, dict):
raise ValueError("Data to append is not of the correct type. " +
"Use a dict!")
timestamp = datetime.datetime.utcnow().strftime(
'%Y-%m-%d %H:%M:%S UTC')
timestamp = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S UTC')
contents = ''
#
# Print any key/value pairs
Expand Down Expand Up @@ -1051,12 +1049,10 @@ def _parse(self):
#
# Find structure & enumeration definitions & strip them out
#
self._symbols['struct'] = re.findall(
r'typedef\s+struct\s*\{[^}]+\}\s*\w+\s*;',
lines)
self._symbols['enum'] = re.findall(
r'typedef\s+enum\s*\{[^}]+\}\s*\w+\s*;',
lines)
self._symbols['struct'] = re.findall(r'typedef\s+struct\s*\{[^}]+\}\s*\w+\s*;',
lines)
self._symbols['enum'] = re.findall(r'typedef\s+enum\s*\{[^}]+\}\s*\w+\s*;',
lines)
lines = re.sub(r'typedef\s+struct\s*\{[^}]+\}\s*\w+\s*;', '', lines)
lines = re.sub(r'typedef\s+enum\s*\{[^}]+\}\s*\w+\s*;', '', lines)
#
Expand Down
5 changes: 2 additions & 3 deletions pydl/rebin.py
Expand Up @@ -95,9 +95,8 @@ def rebin(x, d, sample=False):
sliceobj1[k] = slice(fp + 1, fp + 2)
rshape = r[tuple(sliceobj)].shape
r[tuple(sliceobj)] = (xx[tuple(sliceobj0)].reshape(rshape) +
(p - fp)*(xx[tuple(sliceobj1)] -
xx[tuple(sliceobj0)]).reshape(rshape)
)
(p - fp)*(xx[tuple(sliceobj1)] -
xx[tuple(sliceobj0)]).reshape(rshape))
else:
r[tuple(sliceobj)] = xx[tuple(sliceobj0)]
elif d[k] == d0[k]:
Expand Down

0 comments on commit 3fffc03

Please sign in to comment.