From 61f958b5e2d10ec4b076d961bb9751949de0bce5 Mon Sep 17 00:00:00 2001 From: IainHammond Date: Mon, 14 Aug 2023 17:18:03 +1000 Subject: [PATCH 01/31] typo and docstring fix --- vip_hci/fits/headers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vip_hci/fits/headers.py b/vip_hci/fits/headers.py index 1efb898f..aa5b4363 100644 --- a/vip_hci/fits/headers.py +++ b/vip_hci/fits/headers.py @@ -100,7 +100,7 @@ def open_header(fitsfilename: str, n: int = 0, extname: str = None, Returns ------- - header : dict or list of dict + header : `Header` dictionary Astropy Header class with both a dict-like and list-like interface. """ @@ -116,6 +116,6 @@ def open_header(fitsfilename: str, n: int = 0, extname: str = None, header = getheader(fitsfilename, ext=n, ignore_missing_end=True) if verbose: - print(f"Fits HDU-{n} header successfully loaded.") + print(f"FITS HDU-{n} header successfully loaded.") return header From d04db4310855278e40eeb05611022c8bba4acdf9 Mon Sep 17 00:00:00 2001 From: IainHammond Date: Mon, 14 Aug 2023 17:23:47 +1000 Subject: [PATCH 02/31] avoiding photutils deprecation --- vip_hci/metrics/roc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vip_hci/metrics/roc.py b/vip_hci/metrics/roc.py index 6fa4b114..1c2e1d59 100644 --- a/vip_hci/metrics/roc.py +++ b/vip_hci/metrics/roc.py @@ -9,7 +9,7 @@ import matplotlib.pyplot as plt from hciplot import plot_frames from scipy import stats -from photutils import detect_sources +from photutils.segmentation import detect_sources from munch import Munch from ..config import time_ini, timing, Progressbar from ..fm import cube_inject_companions From b1ae884acafdb6a13f40c45e7c9fb28391bbd758 Mon Sep 17 00:00:00 2001 From: IainHammond Date: Mon, 14 Aug 2023 17:28:33 +1000 Subject: [PATCH 03/31] removed unused import --- vip_hci/metrics/completeness.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/vip_hci/metrics/completeness.py b/vip_hci/metrics/completeness.py index 282ce3ae..00075ea7 100644 --- a/vip_hci/metrics/completeness.py +++ b/vip_hci/metrics/completeness.py @@ -31,20 +31,22 @@ __author__ = "C.H. Dahlqvist, V. Christiaens, T. Bédrine" __all__ = ["completeness_curve", "completeness_map"] +from math import gcd +from inspect import getfullargspec from multiprocessing import cpu_count + import numpy as np -from inspect import signature, getfullargspec -from skimage.draw import disk +from astropy.convolution import convolve, Tophat2DKernel from matplotlib import pyplot as plt -from ..fm import cube_inject_companions, normalize_psf +from skimage.draw import disk + +from .contrcurve import contrast_curve +from .snr_source import snrmap, _snr_approx, snr from ..config.utils_conf import pool_map, iterable, vip_figsize, vip_figdpi -from ..var import get_annulus_segments, frame_center +from ..fm import cube_inject_companions, normalize_psf from ..fm.utils_negfc import find_nearest from ..preproc import cube_crop_frames -from .snr_source import snrmap, _snr_approx, snr -from .contrcurve import contrast_curve -from astropy.convolution import convolve, Tophat2DKernel -import math +from ..var import get_annulus_segments, frame_center def _estimate_snr_fc( @@ -333,7 +335,7 @@ def completeness_curve( """ if (100 * completeness) % (100 / n_fc) > 0: - n_fc = int(100 / math.gcd(int(100 * completeness), 100)) + n_fc = int(100 / gcd(int(100 * completeness), 100)) if cube.ndim != 3 and cube.ndim != 4: raise TypeError("The input array is not a 3d or 4d cube") From f4bda26b6a89f11951f2056a037d944714e5bf5c Mon Sep 17 00:00:00 2001 From: IainHammond Date: Mon, 14 Aug 2023 17:31:06 +1000 Subject: [PATCH 04/31] cleaned up duplicated imports --- vip_hci/metrics/detection.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/vip_hci/metrics/detection.py b/vip_hci/metrics/detection.py index db8615c2..a3cad92e 100644 --- a/vip_hci/metrics/detection.py +++ b/vip_hci/metrics/detection.py @@ -14,11 +14,10 @@ import pandas as pn from hciplot import plot_frames from scipy.ndimage import correlate -from skimage import feature -from astropy.stats import sigma_clipped_stats -from astropy.stats import gaussian_fwhm_to_sigma, gaussian_sigma_to_fwhm +from astropy.stats import (sigma_clipped_stats, gaussian_fwhm_to_sigma, + gaussian_sigma_to_fwhm) from astropy.modeling import models, fitting -from skimage.feature import peak_local_max +from skimage.feature import peak_local_max, blob_log, blob_dog from ..var import (mask_circle, get_square, frame_center, fit_2dgaussian, frame_filter_lowpass, dist_matrix) from ..config.utils_conf import sep @@ -282,9 +281,9 @@ def print_abort(): elif mode == 'log': sigma = fwhm * gaussian_fwhm_to_sigma - coords = feature.blob_log(frame_det.astype('float'), - threshold=bkg_level, min_sigma=sigma-.5, - max_sigma=sigma+.5) + coords = blob_log(frame_det.astype('float'), + threshold=bkg_level, min_sigma=sigma-.5, + max_sigma=sigma+.5) if len(coords) == 0: print_abort() return 0, 0 @@ -296,9 +295,9 @@ def print_abort(): elif mode == 'dog': sigma = fwhm * gaussian_fwhm_to_sigma - coords = feature.blob_dog(frame_det.astype('float'), - threshold=bkg_level, min_sigma=sigma-.5, - max_sigma=sigma+.5) + coords = blob_dog(frame_det.astype('float'), + threshold=bkg_level, min_sigma=sigma-.5, + max_sigma=sigma+.5) if len(coords) == 0: print_abort() return 0, 0 From 1a418444b5fb49f9535fb0bfc3e68e554c287035 Mon Sep 17 00:00:00 2001 From: IainHammond Date: Mon, 14 Aug 2023 17:45:05 +1000 Subject: [PATCH 05/31] cleaned up imports --- vip_hci/var/shapes.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/vip_hci/var/shapes.py b/vip_hci/var/shapes.py index 7b0a7b67..74afe60d 100644 --- a/vip_hci/var/shapes.py +++ b/vip_hci/var/shapes.py @@ -28,11 +28,10 @@ 'mask_roi'] import numpy as np -from skimage.draw import polygon -from skimage.draw import disk +from skimage.draw import polygon, disk from sklearn.preprocessing import scale -from hciplot import plot_frames +from hciplot import plot_frames from .coords import frame_center, dist from ..config.utils_conf import frame_or_shape From 98d2ff09afd5d96ba293e96b54dc307427d0d577 Mon Sep 17 00:00:00 2001 From: IainHammond Date: Fri, 18 Aug 2023 13:29:58 +1000 Subject: [PATCH 06/31] fits -> FITS --- vip_hci/fits/fits.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vip_hci/fits/fits.py b/vip_hci/fits/fits.py index 1a21aa27..054c6a81 100644 --- a/vip_hci/fits/fits.py +++ b/vip_hci/fits/fits.py @@ -269,4 +269,4 @@ def write_fits(fitsfilename, array, header=None, output_verify="exception", writeto(fitsfilename, array, header, output_verify) if verbose: - print(f"Fits file successfully {res}") + print(f"FITS file successfully {res}") From 460670d8d3693e8cdd05e5799d129ee668501e3a Mon Sep 17 00:00:00 2001 From: IainHammond Date: Thu, 24 Aug 2023 16:02:13 +1000 Subject: [PATCH 07/31] fixed a docstring in dft upsampling --- vip_hci/preproc/recentering.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vip_hci/preproc/recentering.py b/vip_hci/preproc/recentering.py index ebd18cb5..ec77c7a2 100644 --- a/vip_hci/preproc/recentering.py +++ b/vip_hci/preproc/recentering.py @@ -1109,9 +1109,9 @@ def cube_recenter_dft_upsampling(array, center_fr1=None, negative=False, ---------- array : numpy ndarray Input cube. - center_fr1 = (cy_1, cx_1) : Tuple, optional - Coordinates of the center of the subimage for fitting a 2d Gaussian and - centroiding the 1st frame. + center_fr1 : tuple, optional + Coordinates in (y, x) of the center of the subimage for fitting a + 2d Gaussian and centroiding the 1st frame . negative : bool, optional If True the centroiding of the 1st frames is done with a negative 2d Gaussian fit. From 8593a3892f6ea62dbcb59c5c6d715890a86d242f Mon Sep 17 00:00:00 2001 From: IainHammond Date: Thu, 24 Aug 2023 16:04:51 +1000 Subject: [PATCH 08/31] fixed a docstring in dft upsampling --- vip_hci/preproc/recentering.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vip_hci/preproc/recentering.py b/vip_hci/preproc/recentering.py index ec77c7a2..dd55899c 100644 --- a/vip_hci/preproc/recentering.py +++ b/vip_hci/preproc/recentering.py @@ -1111,7 +1111,7 @@ def cube_recenter_dft_upsampling(array, center_fr1=None, negative=False, Input cube. center_fr1 : tuple, optional Coordinates in (y, x) of the center of the subimage for fitting a - 2d Gaussian and centroiding the 1st frame . + 2d Gaussian and centroiding the 1st frame. negative : bool, optional If True the centroiding of the 1st frames is done with a negative 2d Gaussian fit. From 4522c0836cf496bf87c36dbc29d1fcef8a65ee43 Mon Sep 17 00:00:00 2001 From: IainHammond Date: Wed, 30 Aug 2023 13:05:56 +1000 Subject: [PATCH 09/31] multiprocessing for cube shifts --- vip_hci/preproc/recentering.py | 41 +++++++++++++++------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/vip_hci/preproc/recentering.py b/vip_hci/preproc/recentering.py index dd55899c..8f5d5800 100644 --- a/vip_hci/preproc/recentering.py +++ b/vip_hci/preproc/recentering.py @@ -1833,7 +1833,6 @@ def cube_recenter_via_speckles(cube_sci, cube_ref=None, alignment_iter=5, alignment_cube = np.zeros((1 + n, subframesize, subframesize)) alignment_cube[1:(n + 1), :, :] = cube_sci_lpf - n_frames = alignment_cube.shape[0] # 1+n or 1+n+nref cum_y_shifts = 0 cum_x_shifts = 0 @@ -1879,32 +1878,30 @@ def cube_recenter_via_speckles(cube_sci, cube_ref=None, alignment_iter=5, mask_tmp = frame_crop(mask, subframesize) else: mask_tmp = mask - res = cube_recenter_dft_upsampling(cube_stret, (ceny, cenx), fwhm=fwhm, - subi_size=None, full_output=True, - verbose=False, plot=False, - mask=mask_tmp, imlib=imlib, - interpolation=interpolation, nproc=nproc) + res = cube_recenter_dft_upsampling(cube_stret, center_fr1=(ceny, cenx), + fwhm=fwhm, subi_size=None, + full_output=True, verbose=False, + plot=False, mask=mask_tmp, + imlib=imlib, interpolation=interpolation, + nproc=nproc) _, y_shift, x_shift = res sqsum_shifts = np.sum(np.sqrt(y_shift ** 2 + x_shift ** 2)) print('Square sum of shift vecs: ' + str(sqsum_shifts)) - for j in range(1, n_frames): - alignment_cube[j] = frame_shift(alignment_cube[j], y_shift[j], - x_shift[j], imlib=imlib, - interpolation=interpolation, - border_mode=border_mode) + alignment_cube = cube_shift(alignment_cube, shift_y=y_shift, shift_x=x_shift, + imlib=imlib, interpolation=interpolation, + border_mode=border_mode, nproc=nproc) cum_y_shifts += y_shift cum_x_shifts += x_shift - cube_reg_sci = cube_sci.copy() cum_y_shifts_sci = cum_y_shifts[1:(n + 1)] cum_x_shifts_sci = cum_x_shifts[1:(n + 1)] - for i in range(n): - cube_reg_sci[i] = frame_shift(cube_sci[i], cum_y_shifts_sci[i], - cum_x_shifts_sci[i], imlib=imlib, - interpolation=interpolation, - border_mode=border_mode) + + cube_reg_sci = cube_shift(cube_sci, shift_y=cum_y_shifts_sci, + shift_x=cum_x_shifts_sci, imlib=imlib, + interpolation=interpolation, + border_mode=border_mode, nproc=nproc) if plot: plt.figure(figsize=vip_figsize) @@ -1925,14 +1922,12 @@ def cube_recenter_via_speckles(cube_sci, cube_ref=None, alignment_iter=5, plt.xlabel('Pixels') if ref_star: - cube_reg_ref = cube_ref.copy() cum_y_shifts_ref = cum_y_shifts[(n + 1):] cum_x_shifts_ref = cum_x_shifts[(n + 1):] - for i in range(nref): - cube_reg_ref[i] = frame_shift(cube_ref[i], cum_y_shifts_ref[i], - cum_x_shifts_ref[i], imlib=imlib, - interpolation=interpolation, - border_mode=border_mode) + cube_reg_ref = cube_shift(cube_ref, shift_y=cum_y_shifts_ref, + shift_x=cum_x_shifts_ref, imlib=imlib, + interpolation=interpolation, + border_mode=border_mode, nproc=nproc) if ref_star: if full_output: From 30980129cb59c6216a9634377b715be5a0063459 Mon Sep 17 00:00:00 2001 From: IainHammond Date: Mon, 4 Sep 2023 16:45:37 +1000 Subject: [PATCH 10/31] multiprocessing for the cube shifts in radon, removed extra frame_crop import --- vip_hci/preproc/recentering.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/vip_hci/preproc/recentering.py b/vip_hci/preproc/recentering.py index 8f5d5800..eb78e817 100644 --- a/vip_hci/preproc/recentering.py +++ b/vip_hci/preproc/recentering.py @@ -732,7 +732,6 @@ def frame_center_radon(array, cropsize=None, hsize_ini=1., step_ini=0.1, [full_output=True] Radon cost function surface. """ - from .cosmetics import frame_crop if array.ndim != 2: raise TypeError('Input array is not a frame or 2d array') @@ -1063,11 +1062,10 @@ def cube_recenter_radon(array, full_output=False, verbose=True, imlib='vip-fft', start_time = time_ini() n_frames = array.shape[0] - x = np.zeros((n_frames)) - y = np.zeros((n_frames)) + x = np.zeros(n_frames) + y = np.zeros(n_frames) dyx = np.zeros((n_frames, 2)) cy, cx = frame_center(array[0]) - array_rec = array.copy() for i in Progressbar(range(n_frames), desc="Recentering frames...", verbose=verbose): @@ -1077,9 +1075,9 @@ def cube_recenter_radon(array, full_output=False, verbose=True, imlib='vip-fft', y[i] = res[0] x[i] = res[1] dyx[i] = res[2] - array_rec[i] = frame_shift(array[i], cy-y[i], cx-x[i], imlib=imlib, - interpolation=interpolation, - border_mode=border_mode) + array_rec = cube_shift(array, shift_y=cy-y, shift_x=cx-x, imlib=imlib, + interpolation=interpolation, border_mode=border_mode, + **kwargs) if verbose: timing(start_time) From 4c6a173d355bd8788420908942a1d29436191aa0 Mon Sep 17 00:00:00 2001 From: IainHammond Date: Mon, 4 Sep 2023 20:09:01 +1000 Subject: [PATCH 11/31] fixed multiprocessing for the cube shifts in radon --- vip_hci/preproc/recentering.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/vip_hci/preproc/recentering.py b/vip_hci/preproc/recentering.py index eb78e817..c977bc97 100644 --- a/vip_hci/preproc/recentering.py +++ b/vip_hci/preproc/recentering.py @@ -1016,7 +1016,7 @@ def _radon_costf(frame, cent, radint, coords, satspots_cfg=None, theta_0=0, def cube_recenter_radon(array, full_output=False, verbose=True, imlib='vip-fft', interpolation='lanczos4', border_mode='reflect', - **kwargs): + nproc=None, **kwargs): """ Recenters a cube looping through its frames and calling the ``frame_center_radon`` function, as in [PUE15]_. @@ -1057,6 +1057,8 @@ def cube_recenter_radon(array, full_output=False, verbose=True, imlib='vip-fft', """ check_array(array, dim=3) + if nproc is None: + nproc = int(cpu_count() / 2) if verbose: start_time = time_ini() @@ -1071,13 +1073,13 @@ def cube_recenter_radon(array, full_output=False, verbose=True, imlib='vip-fft', verbose=verbose): res = frame_center_radon(array[i], verbose=False, plot=False, imlib=imlib, interpolation=interpolation, - full_output=True, **kwargs) + full_output=True, nproc=nproc, **kwargs) y[i] = res[0] x[i] = res[1] dyx[i] = res[2] array_rec = cube_shift(array, shift_y=cy-y, shift_x=cx-x, imlib=imlib, interpolation=interpolation, border_mode=border_mode, - **kwargs) + nproc=nproc) if verbose: timing(start_time) From 92dbe481824d846bac50c56d51e05aafdd476ce1 Mon Sep 17 00:00:00 2001 From: IainHammond Date: Mon, 4 Sep 2023 20:14:39 +1000 Subject: [PATCH 12/31] added nproc to docstring of radon --- vip_hci/preproc/recentering.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vip_hci/preproc/recentering.py b/vip_hci/preproc/recentering.py index c977bc97..61320ecd 100644 --- a/vip_hci/preproc/recentering.py +++ b/vip_hci/preproc/recentering.py @@ -1040,6 +1040,9 @@ def cube_recenter_radon(array, full_output=False, verbose=True, imlib='vip-fft', beyond the edge with zeros. With 'mirror', the input is extended by reflecting about the center of the last pixel. With 'wrap', the input is extended by wrapping around to the opposite edge. Default is 'reflect'. + nproc : int, optional + Number of processes for parallel computing. If None the number of + processes will be set to cpu_count()/2. kwargs: Additional optional parameters for ``vip_hci.preproc.frame_center_radon`` function, such as cropsize, hsize, step, satspots_cfg, mask_center, From b5b6fb4c9fd13549e64c63e4099bae6e594871ad Mon Sep 17 00:00:00 2001 From: IainHammond Date: Mon, 11 Sep 2023 15:43:42 +1000 Subject: [PATCH 13/31] typo fix --- vip_hci/preproc/parangles.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vip_hci/preproc/parangles.py b/vip_hci/preproc/parangles.py index 7fa32ecc..f669d7f8 100644 --- a/vip_hci/preproc/parangles.py +++ b/vip_hci/preproc/parangles.py @@ -1,6 +1,6 @@ #! /usr/bin/env python """ -Module with frame parallactica angles calculations and de-rotation routines for +Module with frame parallactic angles calculations and de-rotation routines for ADI. .. [MEE98] From 51062eac39d7444eba911c8267807734e7d9bd67 Mon Sep 17 00:00:00 2001 From: IainHammond Date: Tue, 24 Oct 2023 17:45:08 +1100 Subject: [PATCH 14/31] dropped skimage<0.18 to comply with new dependencies --- requirements.txt | 2 +- vip_hci/preproc/recentering.py | 27 +++++++++++---------------- vip_hci/stats/distances.py | 20 ++++++++------------ 3 files changed, 20 insertions(+), 29 deletions(-) diff --git a/requirements.txt b/requirements.txt index e15ad3d3..d6b143e7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ scipy astropy photutils scikit-learn -scikit-image>0.17.0, <=0.18.3 +scikit-image>=0.18.3 emcee==2.2.1 nestle corner diff --git a/vip_hci/preproc/recentering.py b/vip_hci/preproc/recentering.py index 74a2ce57..4f33265b 100644 --- a/vip_hci/preproc/recentering.py +++ b/vip_hci/preproc/recentering.py @@ -30,9 +30,9 @@ 'cube_recenter_2dfit', 'cube_recenter_via_speckles'] -import numpy as np import warnings -from packaging import version + +import numpy as np try: import cv2 @@ -45,14 +45,11 @@ from hciplot import plot_frames from scipy.ndimage import fourier_shift from scipy.ndimage import shift -import skimage from skimage.transform import radon -if version.parse(skimage.__version__) <= version.parse('0.17.0'): - from skimage.feature import register_translation as cc_center -else: - from skimage.registration import phase_cross_correlation as cc_center +from skimage.registration import phase_cross_correlation as cc_center from multiprocessing import cpu_count from matplotlib import pyplot as plt + from ..config import time_ini, timing, Progressbar from ..config.utils_conf import vip_figsize, check_array from ..config.utils_conf import pool_map, iterable @@ -1136,7 +1133,7 @@ def cube_recenter_dft_upsampling(array, center_fr1=None, negative=False, mask: 2D np.ndarray, optional Binary mask indicating where the cross-correlation should be calculated in the images. If provided, should be the same size as array frames. - [Note: only used if version of skimage >= 0.18.0] + [Note: requires skimage >= 0.18.0] border_mode : {'reflect', 'nearest', 'constant', 'mirror', 'wrap'} Points outside the boundaries of the input are filled accordingly. With 'reflect', the input is extended by reflecting about the edge of @@ -1319,14 +1316,12 @@ def cube_recenter_dft_upsampling(array, center_fr1=None, negative=False, def _shift_dft(array_rec, array, frnum, upsample_factor, mask, interpolation, imlib, border_mode): """Function used in recenter_dft_unsampling.""" - if version.parse(skimage.__version__) > version.parse('0.17.0'): - shift_yx = cc_center(array_rec[0], array[frnum], - upsample_factor=upsample_factor, - reference_mask=mask, - return_error=False) - else: - shift_yx = cc_center(array_rec[0], array[frnum], - upsample_factor=upsample_factor) + + shift_yx = cc_center(array_rec[0], array[frnum], + upsample_factor=upsample_factor, + reference_mask=mask, + return_error=False) + y_i, x_i = shift_yx array_rec_i = frame_shift(array[frnum], shift_y=y_i, shift_x=x_i, imlib=imlib, interpolation=interpolation, diff --git a/vip_hci/stats/distances.py b/vip_hci/stats/distances.py index 7c563aeb..f9c569d9 100644 --- a/vip_hci/stats/distances.py +++ b/vip_hci/stats/distances.py @@ -25,19 +25,15 @@ __all__ = ['cube_distance', 'spectral_correlation'] -from astropy.stats import gaussian_fwhm_to_sigma import numpy as np -import scipy.stats -from scipy.optimize import curve_fit +from scipy.stats import pearsonr, spearmanr +from astropy.stats import gaussian_fwhm_to_sigma from matplotlib import pyplot as plt -try: - # for skimage version >= '0.16' use skimage.metrics.structural_similarity - from skimage.metrics import structural_similarity as ssim -except BaseException: - # before skimage version '0.16' use skimage.measure.compare_ssim - from skimage.measure import compare_ssim as ssim -from ..var import get_annulus_segments, get_circle +from scipy.optimize import curve_fit +from skimage.metrics import structural_similarity as ssim + from ..config import vip_figsize +from ..var import get_annulus_segments, get_circle def cube_distance(array, frame, mode='full', dist='sad', inradius=None, @@ -133,10 +129,10 @@ def cube_distance(array, frame, mode='full', dist='sad', inradius=None, elif dist == 'mse': lista.append((np.sum((frame_ref - framei)**2))/len(frame_ref)) elif dist == 'pearson': - pears, _ = scipy.stats.pearsonr(frame_ref.ravel(), framei.ravel()) + pears, _ = pearsonr(frame_ref.ravel(), framei.ravel()) lista.append(pears) elif dist == 'spearman': - spear, _ = scipy.stats.spearmanr(frame_ref.ravel(), framei.ravel()) + spear, _ = spearmanr(frame_ref.ravel(), framei.ravel()) lista.append(spear) elif dist == 'ssim': mean_ssim = ssim(frame_ref, framei, win_size=7, From 496d9929a84684db4888f4f74c56ada2ec73ecb0 Mon Sep 17 00:00:00 2001 From: IainHammond Date: Tue, 24 Oct 2023 17:49:54 +1100 Subject: [PATCH 15/31] cube_recenter_via_speckles - only use hpf if a max_spat_freq is provided --- vip_hci/preproc/recentering.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/vip_hci/preproc/recentering.py b/vip_hci/preproc/recentering.py index fa02799f..c6d5f9fd 100644 --- a/vip_hci/preproc/recentering.py +++ b/vip_hci/preproc/recentering.py @@ -1824,10 +1824,14 @@ def cube_recenter_via_speckles(cube_sci, cube_ref=None, alignment_iter=5, if ref_star: cube_ref_lpf = cube_ref_lpf + np.abs(np.min(cube_ref_lpf)) - median_size = int(fwhm * max_spat_freq) - # Remove spatial frequencies <0.5 lam/D and >3lam/D to isolate speckles - cube_sci_hpf = cube_filter_highpass(cube_sci_lpf, 'median-subt', - median_size=median_size, verbose=False) + if max_spat_freq > 0: + median_size = int(fwhm * max_spat_freq) + # Remove spatial frequencies <0.5 lam/D and >3lam/D to isolate speckles + cube_sci_hpf = cube_filter_highpass(cube_sci_lpf, 'median-subt', + median_size=median_size, verbose=False) + else: + cube_sci_hpf = cube_sci_lpf + if min_spat_freq > 0: cube_sci_lpf = cube_filter_lowpass(cube_sci_hpf, 'gauss', fwhm_size=min_spat_freq * fwhm, From a6d4644eb67ffc6486bcb518365269a58d86fd70 Mon Sep 17 00:00:00 2001 From: IainHammond Date: Thu, 26 Oct 2023 15:01:51 +1100 Subject: [PATCH 16/31] removed deprecated return_error in phase_cross_correlation from skimage --- vip_hci/preproc/recentering.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vip_hci/preproc/recentering.py b/vip_hci/preproc/recentering.py index c6d5f9fd..59589912 100644 --- a/vip_hci/preproc/recentering.py +++ b/vip_hci/preproc/recentering.py @@ -1344,8 +1344,7 @@ def _shift_dft(array_rec, array, frnum, upsample_factor, mask, interpolation, shift_yx = cc_center(array_rec[0], array[frnum], upsample_factor=upsample_factor, - reference_mask=mask, - return_error=False) + reference_mask=mask) y_i, x_i = shift_yx array_rec_i = frame_shift(array[frnum], shift_y=y_i, shift_x=x_i, From 2d6cb1183070f9aaa903eb9b5edbc86453c3171c Mon Sep 17 00:00:00 2001 From: IainHammond Date: Thu, 26 Oct 2023 17:19:07 +1100 Subject: [PATCH 17/31] clarified variable printed in cube_recenter_dft_upsampling --- vip_hci/preproc/recentering.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vip_hci/preproc/recentering.py b/vip_hci/preproc/recentering.py index 59589912..27b78115 100644 --- a/vip_hci/preproc/recentering.py +++ b/vip_hci/preproc/recentering.py @@ -1216,9 +1216,9 @@ def cube_recenter_dft_upsampling(array, center_fr1=None, negative=False, n_frames, sizey, sizex = array.shape if subi_size is not None: if center_fr1 is None: - print('`cx_1` or `cy_1` not provided') - print('Using the coordinates of the 1st frame center for ' - 'the Gaussian 2d fit') + print("`center_fr1` not provided") + print("Using the coordinates of the 1st frame center for " + "the Gaussian 2d fit") cy_1, cx_1 = frame_center(array[0]) else: cy_1, cx_1 = center_fr1 From 5bda8da1777ff741ca73c6e8f69e4c904d52d59f Mon Sep 17 00:00:00 2001 From: IainHammond Date: Thu, 26 Oct 2023 17:20:53 +1100 Subject: [PATCH 18/31] clarified shift dft docstring --- vip_hci/preproc/recentering.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vip_hci/preproc/recentering.py b/vip_hci/preproc/recentering.py index 27b78115..2c8de8d3 100644 --- a/vip_hci/preproc/recentering.py +++ b/vip_hci/preproc/recentering.py @@ -1340,7 +1340,7 @@ def cube_recenter_dft_upsampling(array, center_fr1=None, negative=False, def _shift_dft(array_rec, array, frnum, upsample_factor, mask, interpolation, imlib, border_mode): - """Function used in recenter_dft_unsampling.""" + """Function used in cube_recenter_dft_upsampling.""" shift_yx = cc_center(array_rec[0], array[frnum], upsample_factor=upsample_factor, From 8b9b21919877a785b3177ca7d8ca94e29936aba2 Mon Sep 17 00:00:00 2001 From: IainHammond Date: Thu, 26 Oct 2023 18:17:06 +1100 Subject: [PATCH 19/31] supports skimage 0.22 phase_cross_correlation returning three variables --- vip_hci/preproc/recentering.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/vip_hci/preproc/recentering.py b/vip_hci/preproc/recentering.py index 2c8de8d3..3075bf5d 100644 --- a/vip_hci/preproc/recentering.py +++ b/vip_hci/preproc/recentering.py @@ -46,7 +46,7 @@ from scipy.ndimage import fourier_shift from scipy.ndimage import shift from skimage.transform import radon -from skimage.registration import phase_cross_correlation as cc_center +from skimage.registration import phase_cross_correlation from multiprocessing import cpu_count from matplotlib import pyplot as plt @@ -1342,11 +1342,15 @@ def _shift_dft(array_rec, array, frnum, upsample_factor, mask, interpolation, imlib, border_mode): """Function used in cube_recenter_dft_upsampling.""" - shift_yx = cc_center(array_rec[0], array[frnum], - upsample_factor=upsample_factor, - reference_mask=mask) + shifts = phase_cross_correlation(array_rec[0], array[frnum], + upsample_factor=upsample_factor, + reference_mask=mask) + # from skimage 0.22, phase_cross_correlation returns two more variables + # in addition to the array of shifts + if len(shifts) == 3: + shifts = shifts[0] - y_i, x_i = shift_yx + y_i, x_i = shifts array_rec_i = frame_shift(array[frnum], shift_y=y_i, shift_x=x_i, imlib=imlib, interpolation=interpolation, border_mode=border_mode) From a052892886d8a1dc94473725f76b00a74dd50e9b Mon Sep 17 00:00:00 2001 From: IainHammond Date: Tue, 31 Oct 2023 11:28:54 +1100 Subject: [PATCH 20/31] reverting changes to high pass filtering --- vip_hci/preproc/recentering.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/vip_hci/preproc/recentering.py b/vip_hci/preproc/recentering.py index 3075bf5d..f3f5bd29 100644 --- a/vip_hci/preproc/recentering.py +++ b/vip_hci/preproc/recentering.py @@ -1827,13 +1827,10 @@ def cube_recenter_via_speckles(cube_sci, cube_ref=None, alignment_iter=5, if ref_star: cube_ref_lpf = cube_ref_lpf + np.abs(np.min(cube_ref_lpf)) - if max_spat_freq > 0: - median_size = int(fwhm * max_spat_freq) - # Remove spatial frequencies <0.5 lam/D and >3lam/D to isolate speckles - cube_sci_hpf = cube_filter_highpass(cube_sci_lpf, 'median-subt', - median_size=median_size, verbose=False) - else: - cube_sci_hpf = cube_sci_lpf + median_size = int(fwhm * max_spat_freq) + # Remove spatial frequencies <0.5 lam/D and >3lam/D to isolate speckles + cube_sci_hpf = cube_filter_highpass(cube_sci_lpf, 'median-subt', + median_size=median_size, verbose=False) if min_spat_freq > 0: cube_sci_lpf = cube_filter_lowpass(cube_sci_hpf, 'gauss', From 4a8aaa0f62849504e3de5fe7257598c4a981a5c3 Mon Sep 17 00:00:00 2001 From: IainHammond Date: Tue, 31 Oct 2023 12:06:44 +1100 Subject: [PATCH 21/31] Revert "multiprocessing for cube shifts" This reverts commit 4522c0836cf496bf87c36dbc29d1fcef8a65ee43. --- vip_hci/preproc/recentering.py | 41 +++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/vip_hci/preproc/recentering.py b/vip_hci/preproc/recentering.py index f3f5bd29..4921a055 100644 --- a/vip_hci/preproc/recentering.py +++ b/vip_hci/preproc/recentering.py @@ -1858,6 +1858,7 @@ def cube_recenter_via_speckles(cube_sci, cube_ref=None, alignment_iter=5, alignment_cube = np.zeros((1 + n, subframesize, subframesize)) alignment_cube[1:(n + 1), :, :] = cube_sci_lpf + n_frames = alignment_cube.shape[0] # 1+n or 1+n+nref cum_y_shifts = 0 cum_x_shifts = 0 @@ -1903,30 +1904,32 @@ def cube_recenter_via_speckles(cube_sci, cube_ref=None, alignment_iter=5, mask_tmp = frame_crop(mask, subframesize) else: mask_tmp = mask - res = cube_recenter_dft_upsampling(cube_stret, center_fr1=(ceny, cenx), - fwhm=fwhm, subi_size=None, - full_output=True, verbose=False, - plot=False, mask=mask_tmp, - imlib=imlib, interpolation=interpolation, - nproc=nproc) + res = cube_recenter_dft_upsampling(cube_stret, (ceny, cenx), fwhm=fwhm, + subi_size=None, full_output=True, + verbose=False, plot=False, + mask=mask_tmp, imlib=imlib, + interpolation=interpolation, nproc=nproc) _, y_shift, x_shift = res sqsum_shifts = np.sum(np.sqrt(y_shift ** 2 + x_shift ** 2)) print('Square sum of shift vecs: ' + str(sqsum_shifts)) - alignment_cube = cube_shift(alignment_cube, shift_y=y_shift, shift_x=x_shift, - imlib=imlib, interpolation=interpolation, - border_mode=border_mode, nproc=nproc) + for j in range(1, n_frames): + alignment_cube[j] = frame_shift(alignment_cube[j], y_shift[j], + x_shift[j], imlib=imlib, + interpolation=interpolation, + border_mode=border_mode) cum_y_shifts += y_shift cum_x_shifts += x_shift + cube_reg_sci = cube_sci.copy() cum_y_shifts_sci = cum_y_shifts[1:(n + 1)] cum_x_shifts_sci = cum_x_shifts[1:(n + 1)] - - cube_reg_sci = cube_shift(cube_sci, shift_y=cum_y_shifts_sci, - shift_x=cum_x_shifts_sci, imlib=imlib, - interpolation=interpolation, - border_mode=border_mode, nproc=nproc) + for i in range(n): + cube_reg_sci[i] = frame_shift(cube_sci[i], cum_y_shifts_sci[i], + cum_x_shifts_sci[i], imlib=imlib, + interpolation=interpolation, + border_mode=border_mode) if plot: plt.figure(figsize=vip_figsize) @@ -1947,12 +1950,14 @@ def cube_recenter_via_speckles(cube_sci, cube_ref=None, alignment_iter=5, plt.xlabel('Pixels') if ref_star: + cube_reg_ref = cube_ref.copy() cum_y_shifts_ref = cum_y_shifts[(n + 1):] cum_x_shifts_ref = cum_x_shifts[(n + 1):] - cube_reg_ref = cube_shift(cube_ref, shift_y=cum_y_shifts_ref, - shift_x=cum_x_shifts_ref, imlib=imlib, - interpolation=interpolation, - border_mode=border_mode, nproc=nproc) + for i in range(nref): + cube_reg_ref[i] = frame_shift(cube_ref[i], cum_y_shifts_ref[i], + cum_x_shifts_ref[i], imlib=imlib, + interpolation=interpolation, + border_mode=border_mode) if ref_star: if full_output: From 41d58159c1de2c134ede2d01a8b64b55a2567974 Mon Sep 17 00:00:00 2001 From: IainHammond Date: Tue, 31 Oct 2023 12:10:34 +1100 Subject: [PATCH 22/31] cube_shift -> frame_shift --- vip_hci/preproc/recentering.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/vip_hci/preproc/recentering.py b/vip_hci/preproc/recentering.py index 4921a055..a91fa622 100644 --- a/vip_hci/preproc/recentering.py +++ b/vip_hci/preproc/recentering.py @@ -1904,11 +1904,12 @@ def cube_recenter_via_speckles(cube_sci, cube_ref=None, alignment_iter=5, mask_tmp = frame_crop(mask, subframesize) else: mask_tmp = mask - res = cube_recenter_dft_upsampling(cube_stret, (ceny, cenx), fwhm=fwhm, - subi_size=None, full_output=True, - verbose=False, plot=False, - mask=mask_tmp, imlib=imlib, - interpolation=interpolation, nproc=nproc) + res = cube_recenter_dft_upsampling(cube_stret, center_fr1=(ceny, cenx), + fwhm=fwhm, subi_size=None, + full_output=True, verbose=False, + plot=False, mask=mask_tmp, + imlib=imlib, interpolation=interpolation, + nproc=nproc) _, y_shift, x_shift = res sqsum_shifts = np.sum(np.sqrt(y_shift ** 2 + x_shift ** 2)) print('Square sum of shift vecs: ' + str(sqsum_shifts)) From 7f38df683e5e86c2b880549cbcaf3bfdf14acd65 Mon Sep 17 00:00:00 2001 From: IainHammond Date: Tue, 31 Oct 2023 14:20:45 +1100 Subject: [PATCH 23/31] cube_shift -> frame_shift --- vip_hci/preproc/recentering.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/vip_hci/preproc/recentering.py b/vip_hci/preproc/recentering.py index a91fa622..2924ba3b 100644 --- a/vip_hci/preproc/recentering.py +++ b/vip_hci/preproc/recentering.py @@ -1088,10 +1088,11 @@ def cube_recenter_radon(array, full_output=False, verbose=True, imlib='vip-fft', start_time = time_ini() n_frames = array.shape[0] - x = np.zeros(n_frames) - y = np.zeros(n_frames) + x = np.zeros((n_frames)) + y = np.zeros((n_frames)) dyx = np.zeros((n_frames, 2)) cy, cx = frame_center(array[0]) + array_rec = array.copy() for i in Progressbar(range(n_frames), desc="Recentering frames...", verbose=verbose): @@ -1101,9 +1102,9 @@ def cube_recenter_radon(array, full_output=False, verbose=True, imlib='vip-fft', y[i] = res[0] x[i] = res[1] dyx[i] = res[2] - array_rec = cube_shift(array, shift_y=cy-y, shift_x=cx-x, imlib=imlib, - interpolation=interpolation, border_mode=border_mode, - nproc=nproc) + array_rec[i] = frame_shift(array[i], cy-y[i], cx-x[i], imlib=imlib, + interpolation=interpolation, + border_mode=border_mode) if verbose: timing(start_time) From 8ac52ce5bb4c48f145bcf20d95658745ff3e12ab Mon Sep 17 00:00:00 2001 From: IainHammond Date: Tue, 31 Oct 2023 16:23:14 +1100 Subject: [PATCH 24/31] reverting skimage version upgrade --- requirements.txt | 2 +- vip_hci/preproc/recentering.py | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/requirements.txt b/requirements.txt index d6b143e7..1f9ee604 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ scipy astropy photutils scikit-learn -scikit-image>=0.18.3 +scikit-image=0.18.3 emcee==2.2.1 nestle corner diff --git a/vip_hci/preproc/recentering.py b/vip_hci/preproc/recentering.py index 2924ba3b..976ba383 100644 --- a/vip_hci/preproc/recentering.py +++ b/vip_hci/preproc/recentering.py @@ -1343,15 +1343,12 @@ def _shift_dft(array_rec, array, frnum, upsample_factor, mask, interpolation, imlib, border_mode): """Function used in cube_recenter_dft_upsampling.""" - shifts = phase_cross_correlation(array_rec[0], array[frnum], - upsample_factor=upsample_factor, - reference_mask=mask) - # from skimage 0.22, phase_cross_correlation returns two more variables - # in addition to the array of shifts - if len(shifts) == 3: - shifts = shifts[0] - - y_i, x_i = shifts + shift_yx = phase_cross_correlation(array_rec[0], array[frnum], + upsample_factor=upsample_factor, + reference_mask=mask, + return_error=False) + + y_i, x_i = shift_yx array_rec_i = frame_shift(array[frnum], shift_y=y_i, shift_x=x_i, imlib=imlib, interpolation=interpolation, border_mode=border_mode) From a60b69be128f79b7eb5e92b6b1a1c7ff672a8b76 Mon Sep 17 00:00:00 2001 From: IainHammond Date: Tue, 31 Oct 2023 16:24:20 +1100 Subject: [PATCH 25/31] reverting skimage version upgrade --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 1f9ee604..d1f2f76a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ scipy astropy photutils scikit-learn -scikit-image=0.18.3 +scikit-image==0.18.3 emcee==2.2.1 nestle corner From cee21d76c80139750cda9e2ffa6dcc29a8cb29d6 Mon Sep 17 00:00:00 2001 From: IainHammond Date: Tue, 31 Oct 2023 18:52:29 +1100 Subject: [PATCH 26/31] testing skimage versions --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index d1f2f76a..256dd8b9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ scipy astropy photutils scikit-learn -scikit-image==0.18.3 +scikit-image<0.22 emcee==2.2.1 nestle corner From f9dc80d513ecc8fdcda0178241db2dec33fdacce Mon Sep 17 00:00:00 2001 From: IainHammond Date: Tue, 31 Oct 2023 20:12:13 +1100 Subject: [PATCH 27/31] testing skimage versions --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 256dd8b9..04ad98ff 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ scipy astropy photutils scikit-learn -scikit-image<0.22 +scikit-image<0.21 emcee==2.2.1 nestle corner From c69dc39c193da740b1635819a2ec8956d9df66d5 Mon Sep 17 00:00:00 2001 From: IainHammond Date: Wed, 1 Nov 2023 12:21:20 +1100 Subject: [PATCH 28/31] testing skimage versions --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 04ad98ff..ad5d62d7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ scipy astropy photutils scikit-learn -scikit-image<0.21 +scikit-image<0.20 emcee==2.2.1 nestle corner From fc6f112e9f381cd456fe7cea625c4d0c921c400c Mon Sep 17 00:00:00 2001 From: IainHammond Date: Wed, 1 Nov 2023 12:55:47 +1100 Subject: [PATCH 29/31] normalization=None in skimage phase_cross_correlation --- requirements.txt | 2 +- vip_hci/preproc/recentering.py | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/requirements.txt b/requirements.txt index ad5d62d7..2e001a15 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ scipy astropy photutils scikit-learn -scikit-image<0.20 +scikit-image==0.22 emcee==2.2.1 nestle corner diff --git a/vip_hci/preproc/recentering.py b/vip_hci/preproc/recentering.py index 976ba383..fdc98222 100644 --- a/vip_hci/preproc/recentering.py +++ b/vip_hci/preproc/recentering.py @@ -1343,12 +1343,16 @@ def _shift_dft(array_rec, array, frnum, upsample_factor, mask, interpolation, imlib, border_mode): """Function used in cube_recenter_dft_upsampling.""" - shift_yx = phase_cross_correlation(array_rec[0], array[frnum], - upsample_factor=upsample_factor, - reference_mask=mask, - return_error=False) - - y_i, x_i = shift_yx + shifts = phase_cross_correlation(array_rec[0], array[frnum], + upsample_factor=upsample_factor, + reference_mask=mask, + normalization=None) + # from skimage 0.22, phase_cross_correlation returns two more variables + # in addition to the array of shifts + if len(shifts) == 3: + shifts = shifts[0] + + y_i, x_i = shifts array_rec_i = frame_shift(array[frnum], shift_y=y_i, shift_x=x_i, imlib=imlib, interpolation=interpolation, border_mode=border_mode) From beff585576470df1d268992478b07c8760c4cffe Mon Sep 17 00:00:00 2001 From: IainHammond Date: Wed, 1 Nov 2023 13:58:06 +1100 Subject: [PATCH 30/31] final correction of scikit image --- requirements.txt | 2 +- vip_hci/preproc/recentering.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 2e001a15..e1f9a66e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ scipy astropy photutils scikit-learn -scikit-image==0.22 +scikit-image emcee==2.2.1 nestle corner diff --git a/vip_hci/preproc/recentering.py b/vip_hci/preproc/recentering.py index fdc98222..3d768c7b 100644 --- a/vip_hci/preproc/recentering.py +++ b/vip_hci/preproc/recentering.py @@ -1122,7 +1122,7 @@ def cube_recenter_dft_upsampling(array, center_fr1=None, negative=False, full_output=False, verbose=True, nproc=None, save_shifts=False, debug=False, plot=True): """ Recenters a cube of frames using the DFT upsampling method as proposed - in [GUI08]_ and implemented in the ``register_translation`` function from + in [GUI08]_ and implemented in the ``phase_cross_correlation`` function from scikit-image. The algorithm (DFT upsampling) obtains an initial estimate of the @@ -1341,7 +1341,10 @@ def cube_recenter_dft_upsampling(array, center_fr1=None, negative=False, def _shift_dft(array_rec, array, frnum, upsample_factor, mask, interpolation, imlib, border_mode): - """Function used in cube_recenter_dft_upsampling.""" + """Function used in cube_recenter_dft_upsampling. See the docstring of + skimage.register.phase_cross_correlation for a description of the + ``normalization`` parameter which was added in scikit-image 0.19. This + should be set to None to maintain the original behaviour of _shift_dft.""" shifts = phase_cross_correlation(array_rec[0], array[frnum], upsample_factor=upsample_factor, From fefd9cd9cc34bf9c471424477a54dbca876aa7a4 Mon Sep 17 00:00:00 2001 From: IainHammond Date: Wed, 1 Nov 2023 17:03:01 +1100 Subject: [PATCH 31/31] only highpass filter if user requests in cube_recenter_via_speckles --- vip_hci/preproc/recentering.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/vip_hci/preproc/recentering.py b/vip_hci/preproc/recentering.py index 3d768c7b..bfac4aaf 100644 --- a/vip_hci/preproc/recentering.py +++ b/vip_hci/preproc/recentering.py @@ -1815,34 +1815,37 @@ def cube_recenter_via_speckles(cube_sci, cube_ref=None, alignment_iter=5, force=True, verbose=False) else: subframesize = cube_sci.shape[-1] - cube_sci_subframe = cube_sci.copy() + cube_sci_subframe = np.copy(cube_sci) if ref_star: - cube_ref_subframe = cube_ref.copy() + cube_ref_subframe = np.copy(cube_ref) ceny, cenx = frame_center(cube_sci_subframe[0]) print('Sub frame shape: {}'.format(cube_sci_subframe.shape)) print('Center pixel: ({}, {})'.format(ceny, cenx)) # Filtering cubes. Will be used for alignment purposes - cube_sci_lpf = cube_sci_subframe.copy() + cube_sci_lpf = np.copy(cube_sci_subframe) if ref_star: - cube_ref_lpf = cube_ref_subframe.copy() + cube_ref_lpf = np.copy(cube_ref_subframe) cube_sci_lpf = cube_sci_lpf + np.abs(np.min(cube_sci_lpf)) if ref_star: cube_ref_lpf = cube_ref_lpf + np.abs(np.min(cube_ref_lpf)) - median_size = int(fwhm * max_spat_freq) # Remove spatial frequencies <0.5 lam/D and >3lam/D to isolate speckles - cube_sci_hpf = cube_filter_highpass(cube_sci_lpf, 'median-subt', - median_size=median_size, verbose=False) + if max_spat_freq > 0: + median_size = int(fwhm * max_spat_freq) + cube_sci_hpf = cube_filter_highpass(cube_sci_lpf, 'median-subt', + median_size=median_size, verbose=False) + else: + cube_sci_hpf = np.copy(cube_sci_lpf) if min_spat_freq > 0: cube_sci_lpf = cube_filter_lowpass(cube_sci_hpf, 'gauss', fwhm_size=min_spat_freq * fwhm, verbose=False) else: - cube_sci_lpf = cube_sci_hpf + cube_sci_lpf = np.copy(cube_sci_hpf) if ref_star: cube_ref_hpf = cube_filter_highpass(cube_ref_lpf, 'median-subt', @@ -1853,7 +1856,7 @@ def cube_recenter_via_speckles(cube_sci, cube_ref=None, alignment_iter=5, fwhm_size=min_spat_freq * fwhm, verbose=False) else: - cube_ref_lpf = cube_ref_hpf + cube_ref_lpf = np.copy(cube_ref_hpf) if ref_star: alignment_cube = np.zeros((1 + n + nref, subframesize, subframesize)) @@ -1928,7 +1931,7 @@ def cube_recenter_via_speckles(cube_sci, cube_ref=None, alignment_iter=5, cum_y_shifts += y_shift cum_x_shifts += x_shift - cube_reg_sci = cube_sci.copy() + cube_reg_sci = np.copy(cube_sci) cum_y_shifts_sci = cum_y_shifts[1:(n + 1)] cum_x_shifts_sci = cum_x_shifts[1:(n + 1)] for i in range(n): @@ -1956,7 +1959,7 @@ def cube_recenter_via_speckles(cube_sci, cube_ref=None, alignment_iter=5, plt.xlabel('Pixels') if ref_star: - cube_reg_ref = cube_ref.copy() + cube_reg_ref = np.copy(cube_ref) cum_y_shifts_ref = cum_y_shifts[(n + 1):] cum_x_shifts_ref = cum_x_shifts[(n + 1):] for i in range(nref): @@ -2040,8 +2043,6 @@ def _fit_2dannulus(array, fwhm=4, crop=False, cent=None, cropsize=15, ceny, cenx = frame_center(psf_subimage) ceny += y_sub_px cenx += x_sub_px - else: - psf_subimage = array.copy() ann_sz = ann_width*fwhm