-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored master branch #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
|
||
|
|
||
| class Atmopshere(object): | ||
| pass | ||
|
|
||
|
|
||
| def atmosphere(H_gp): # class StandardAtmosphere | ||
| def atmosphere(H_gp): # class StandardAtmosphere | ||
|
Comment on lines
-52
to
+51
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| """ | ||
| US Standard Atmosphere, 1976 | ||
| As published by NOAA, NASA, and USAF | ||
|
|
@@ -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), | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| H = np.arange(0., Hmax, delh) | ||
| X = np.empty(Z.shape) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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}' | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| # def __repr__(self): | ||
| # return str(self) | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ): |
||
| setter(new) | ||
|
|
||
| # print( ) | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def center_proximity(self, position, idx=...): | ||
| """ | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| # print( 'Adding collection to axis' ) | ||
|
|
||
| # necessary for apertures to map correctly to data positions | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def update_from(self, aps): | ||
|
|
||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ): |
||
| # for key in self._properties.__broadcast__: | ||
| for key, val in props.items(): | ||
|
|
||
|
|
@@ -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: | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| rnew = self.radii | ||
| rnew[idx] += relative_motion | ||
| if not self.within_allowed_range(rnew): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| def phase_splitter(ph, *data, **kws): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def __set__(self, instance, value): | ||
| if value is keep: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| ax.add_patch( | ||
| Rectangle(xy - half_pixel_size, *fov[::-1], np.degrees(theta), | ||
|
|
@@ -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': | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| image = SkyImage(image, fov) | ||
|
|
||
| # | ||
|
|
@@ -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 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| _kws.update(kws) | ||
| return self.ax.text(*ulc(p, fov), name, | ||
| rotation=np.degrees(p[-1]), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ): |
||
|
|
||
| def _check_grid(self, grid): | ||
| # | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| # compute model values | ||
| z = self((), grid) | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ): |
||
| return ui | ||
|
|
||
|
|
||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return centres, xy_shifted.std(0), xy_offsets.squeeze(), outliers | ||
|
|
||
|
|
||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| *xy, theta = p | ||
| frame = Rectangle(np.subtract(xy, half_pixel_size), *urc, | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ): |
||
| reg = cls(**find_kws) | ||
| for i in indices: | ||
| reg(images[i], fovs[i], angles[i], plot=plot) | ||
|
|
@@ -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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| # todo: def proper_motion_correction(self, coords): | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
refractive_indexrefactored with the following changes:inline-immediately-returned-variable)