Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/obstools/airmass.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,14 @@ def refractive_index(h_gp):
delta = 2.93e-4
rho = atmosphere(h_gp)

n = 1. + delta * (rho / RHO0)
return n
return 1. + delta * (rho / RHO0)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function refractive_index refactored with the following changes:



class Atmopshere(object):
pass


def atmosphere(H_gp): # class StandardAtmosphere
def atmosphere(H_gp): # class StandardAtmosphere
Comment on lines -52 to +51
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function atmosphere refactored with the following changes:

"""
US Standard Atmosphere, 1976
As published by NOAA, NASA, and USAF
Expand All @@ -69,13 +68,16 @@ def atmosphere(H_gp): # class StandardAtmosphere
if isinstance(H_gp, (float, int)):
H_gp = np.array([H_gp])

regions = [(0. <= H_gp) & (H_gp <= 11e3),
(11e3 < H_gp) & (H_gp <= 20e3),
(20e3 < H_gp) & (H_gp <= 32e3),
(32e3 < H_gp) & (H_gp <= 47e3),
(47e3 < H_gp) & (H_gp <= 51e3),
(51e3 < H_gp) & (H_gp <= 71e3),
(71e3 < H_gp) & (H_gp <= 84852.)]
regions = [
(H_gp >= 0.0) & (H_gp <= 11e3),
(H_gp > 11e3) & (H_gp <= 20e3),
(H_gp > 20e3) & (H_gp <= 32e3),
(H_gp > 32e3) & (H_gp <= 47e3),
(H_gp > 47e3) & (H_gp <= 51e3),
(H_gp > 51e3) & (H_gp <= 71e3),
(H_gp > 71e3) & (H_gp <= 84852.0),
]


expressions = [lambda x: RHO0 * (1. - x / 44330.94) ** 4.25587615,
lambda x: RHO0 * 0.29707755 * np.exp((11e3 - x) / 6341.62),
Expand Down Expand Up @@ -362,8 +364,7 @@ def delM(z, h):

cos_delphi = (4 * (rhm * np.cos(im)) ** 2 - (delh * np.sin(im)) ** 2) / (
4 * (rhm * np.cos(im)) ** 2 + (delh * np.sin(im)) ** 2)
dM = rho * np.sqrt(rh * rh + rhp * rhp - 2 * rh * rhp * cos_delphi)
return dM
return rho * np.sqrt(rh * rh + rhp * rhp - 2 * rh * rhp * cos_delphi)
Comment on lines -365 to +367
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Kivalov07.delM refactored with the following changes:


H = np.arange(0., Hmax, delh)
X = np.empty(Z.shape)
Expand Down
36 changes: 10 additions & 26 deletions src/obstools/aps/ApertureCollections.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def __init__(self, widths=None, heights=None, angles=None, **kws):

def __str__(self):
# FIXME: better repr with widths, heights, angles
return '%s of shape %s' % (self.__class__.__name__, self.shape)
return f'{self.__class__.__name__} of shape {self.shape}'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ApertureCollection.__str__ refactored with the following changes:


# def __repr__(self):
# return str(self)
Expand Down Expand Up @@ -518,26 +518,19 @@ def append(self, aps=None, **props):
print('#' * 300)
return

if not self.size:
concatenate = lambda o, a: a
# if the Collection was initialized as empty, set the new properties as current
else:
concatenate = props.concatenate

concatenate = props.concatenate if self.size else (lambda o, a: a)
# embed()
oprops = self._properties._original
# Find which properties differ and update those
for key, val in props.items():
if (not key in oprops) \
or (not np.array_equal(oprops[key], props[
key])): # `np.array_equal` here flags the empty properties as being unequal to the new ones, whereas `np.all` evaluates as True under the same conditions
if key not in oprops or not np.array_equal(oprops[key], props[key]): # `np.array_equal` here flags the empty properties as being unequal to the new ones, whereas `np.all` evaluates as True under the same conditions
new = concatenate(self[key], val)

# print( '8'*88 )
# print('APPEND', key, self[key], val )
# print( 'NEW:', new )

setter = getattr(self, 'set_%s' % key)
setter = getattr(self, f'set_{key}')
Comment on lines -521 to +533
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ApertureCollection.append refactored with the following changes:

This removes the following comments ( why? ):

# if the Collection was initialized as empty, set the new properties as current

setter(new)

# print( )
Expand Down Expand Up @@ -581,8 +574,7 @@ def area(self, idx=...):
def area_between(self, idxs):
"""return the area enclosed between the two apertures given by idxs"""
A = np.array(self.area(idxs), ndmin=2)
area = np.abs(np.subtract(*A.T))
return area
return np.abs(np.subtract(*A.T))
Comment on lines -584 to +577
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ApertureCollection.area_between refactored with the following changes:


def center_proximity(self, position, idx=...):
"""
Expand Down Expand Up @@ -645,7 +637,7 @@ def edge_proximity(self, position, idx=...):
# ==============================================================================================
# TODO: maybe maxe this a propetry??
def add_to_axes(self, ax=None):
if not self in ax.collections:
if self not in ax.collections:
Comment on lines -648 to +640
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ApertureCollection.add_to_axes refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

# print( 'Adding collection to axis' )

# necessary for apertures to map correctly to data positions
Expand Down Expand Up @@ -888,10 +880,7 @@ def __init__(self, apertures, ax, **kws):
# @expose.args( pre='='*100, post='?'*100 )
def make_segments(self, radii):

if radii.size:
return [list(zip((r, r), (0, 1))) for r in radii]
else:
return []
return [list(zip((r, r), (0, 1))) for r in radii] if radii.size else []
Comment on lines -891 to +883
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ApLineCollection.make_segments refactored with the following changes:


def update_from(self, aps):

Expand Down Expand Up @@ -1113,12 +1102,7 @@ def append(self, aps=None, **props):
# can all be changed at a specific index.

# FIXME: SMELLY CODE!!!!!!!!!!!!
if not self.size:
concatenate = lambda o, a: a
# HACK! if the Collection was initialized as empty, set the new properties as current
else:
concatenate = PropertyManager.concatenate

concatenate = PropertyManager.concatenate if self.size else (lambda o, a: a)
Comment on lines -1116 to +1105
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function InteractionMixin.append refactored with the following changes:

This removes the following comments ( why? ):

# HACK! if the Collection was initialized as empty, set the new properties as current

# for key in self._properties.__broadcast__:
for key, val in props.items():

Expand All @@ -1134,7 +1118,7 @@ def append(self, aps=None, **props):
print(e)
embed()

setter = getattr(self, 'set_%s' % key)
setter = getattr(self, f'set_{key}')

print()
# try:
Expand All @@ -1148,7 +1132,7 @@ def within_allowed_range(self, r):
def resize(self, relative_motion, idx=..., ):
print('RESIZING!', relative_motion, self.radii, idx)

if not relative_motion is None:
if relative_motion is not None:
Comment on lines -1151 to +1135
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function InteractionMixin.resize refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

rnew = self.radii
rnew[idx] += relative_motion
if not self.within_allowed_range(rnew):
Expand Down
9 changes: 4 additions & 5 deletions src/obstools/ephemeris.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,11 @@ def rephase(phase, offset, *data):
phase %= 1
if data is None:
return phase
else:
data = np.array(cosort(phase, *data))
data = np.array(cosort(phase, *data))

phase = data[0]
data = data[1:]
return phase, data
phase = data[0]
data = data[1:]
return phase, data
Comment on lines -156 to +160
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function rephase refactored with the following changes:



def phase_splitter(ph, *data, **kws):
Expand Down
4 changes: 1 addition & 3 deletions src/obstools/image/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ def __init__(self, name):
self.name = f'_{name}'

def __get__(self, instance, owner):
if instance is None:
return self
return getattr(instance, self.name)
return self if instance is None else getattr(instance, self.name)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CalibrationImage.__get__ refactored with the following changes:


def __set__(self, instance, value):
if value is keep:
Expand Down
6 changes: 3 additions & 3 deletions src/obstools/image/mosaic.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def plot_transformed_image(ax, image, fov=None, p=(0, 0, 0), frame=True,

frame_kws = dict(fc='none', lw=0.5, ec='0.5', alpha=kws.get('alpha'))
if isinstance(frame, dict):
frame_kws.update(frame)
frame_kws |= frame
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function plot_transformed_image refactored with the following changes:


ax.add_patch(
Rectangle(xy - half_pixel_size, *fov[::-1], np.degrees(theta),
Expand Down Expand Up @@ -256,7 +256,7 @@ def plot_image(self, image=None, fov=None, p=(0, 0, 0), name=None,

#
# if not isinstance(image, SkyImage):
if not image.__class__.__name__ == 'SkyImage':
if image.__class__.__name__ != 'SkyImage':
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MosaicPlotter.plot_image refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

image = SkyImage(image, fov)

#
Expand Down Expand Up @@ -373,7 +373,7 @@ def mark_target(self, xy, name, colour='forestgreen', arrow_size=10,
def label_image(self, name='', p=(0, 0, 0), fov=(0, 0), **kws):
# default args for init
_kws = {}
_kws.update(self.label_props)
_kws |= self.label_props
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MosaicPlotter.label_image refactored with the following changes:

_kws.update(kws)
return self.ax.text(*ulc(p, fov), name,
rotation=np.degrees(p[-1]),
Expand Down
45 changes: 16 additions & 29 deletions src/obstools/image/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,7 @@ def _checks(self, p, xy=None, *args, **kws):
return self._check_params(p), self._check_grid(xy)

def _check_params(self, p):
if (p is None) or (p == ()):
# default parameter values for evaluation
return np.zeros(self.dof)
return p
return np.zeros(self.dof) if (p is None) or (p == ()) else p
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MultivariateGaussians._check_params refactored with the following changes:

This removes the following comments ( why? ):

# default parameter values for evaluation


def _check_grid(self, grid):
#
Expand Down Expand Up @@ -373,9 +370,8 @@ def plot(self, grid=100, show_xy=True, show_peak=True, **kws):
grid = duplicate_if_scalar(grid, self.n_dims, raises=False)
if grid.size == self.n_dims:
grid = self._auto_grid(grid)
else:
if (grid.ndim != 3) or (grid.shape[-1] != self.n_dims):
raise ValueError('Invalid grid')
elif (grid.ndim != 3) or (grid.shape[-1] != self.n_dims):
raise ValueError('Invalid grid')
Comment on lines -376 to +374
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MultivariateGaussians.plot refactored with the following changes:


# compute model values
z = self((), grid)
Expand Down Expand Up @@ -691,15 +687,13 @@ def display_multitab(images, fovs, params, coords):
import more_itertools as mit

ui = MplMultiTab()
for i, (image, fov, p, yx) in enumerate(zip(images, fovs, params, coords)):
for image, fov, p, yx in zip(images, fovs, params, coords):
xy = yx[:, ::-1] # roto_translate_yx(yx, np.r_[-p[:2], 0])[:, ::-1]
ex = mit.interleave((0, 0), fov)
im = ImageDisplay(image, extent=list(ex))
im.ax.plot(*xy.T, 'kx', ms=5)
ui.add_tab(im.figure)
plt.close(im.figure)
# if i == 1:
# break
Comment on lines -694 to -702
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function display_multitab refactored with the following changes:

This removes the following comments ( why? ):

#    break
# if i == 1:

return ui


Expand Down Expand Up @@ -1102,20 +1096,18 @@ def _measure_positions_offsets(xy, centres, d_cut=None):
out_new = (d > d_cut)
out_new = np.ma.getdata(out_new) | np.ma.getmask(out_new)

changed = (outliers != out_new).any()
if changed:
out = out_new
xym[out] = np.ma.masked
n_out = out.sum()
if not (changed := (outliers != out_new).any()):
break

if n_out / n_points > 0.5:
raise Exception('Too many outliers!!')
out = out_new
xym[out] = np.ma.masked
n_out = out.sum()

logger.info('Ignoring %i/%i (%.1f%%) values with |δr| > %.3f',
n_out, n_points, (n_out / n_points) * 100, d_cut)
else:
break
if n_out / n_points > 0.5:
raise Exception('Too many outliers!!')

logger.info('Ignoring %i/%i (%.1f%%) values with |δr| > %.3f',
n_out, n_points, (n_out / n_points) * 100, d_cut)
Comment on lines -1105 to +1110
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _measure_positions_offsets refactored with the following changes:

return centres, xy_shifted.std(0), xy_offsets.squeeze(), outliers


Expand Down Expand Up @@ -1385,7 +1377,7 @@ def plot(self, ax=None, p=(0, 0, 0), scale='fov', frame=True, **kws):
frame_kws = dict(fc='none', lw=1, ec='0.5',
alpha=kws.get('alpha'))
if isinstance(frame, dict):
frame_kws.update(frame)
frame_kws |= frame
Comment on lines -1388 to +1380
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SkyImage.plot refactored with the following changes:


*xy, theta = p
frame = Rectangle(np.subtract(xy, half_pixel_size), *urc,
Expand Down Expand Up @@ -1652,11 +1644,7 @@ def from_images(cls, images, fovs, angles=(), ridx=None, plot=False,
# message
cls.logger.info('Aligning %i images on image %i', n, ridx)

if len(angles):
angles = np.array(angles) - angles[ridx] # relative angles
else:
angles = np.zeros(n)

angles = np.array(angles) - angles[ridx] if len(angles) else np.zeros(n)
Comment on lines -1655 to +1647
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ImageRegister.from_images refactored with the following changes:

This removes the following comments ( why? ):

# relative angles

reg = cls(**find_kws)
for i in indices:
reg(images[i], fovs[i], angles[i], plot=plot)
Expand Down Expand Up @@ -2566,8 +2554,7 @@ def mosaic(self, names=(), **kws):
def get_rotation(self):
# transform pixel to ICRS coordinate
h = self.hdu[0].header
theta = np.pi / 2 - np.arctan(-h['CD1_1'] / h['CD1_2'])
return theta
return np.pi / 2 - np.arctan(-h['CD1_1'] / h['CD1_2'])
Comment on lines -2569 to +2557
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ImageRegistrationDSS.get_rotation refactored with the following changes:


# todo: def proper_motion_correction(self, coords):

Expand Down
Loading