From 9754df4b20ed0afcb42798af4fd8ba98b282ec2e Mon Sep 17 00:00:00 2001 From: Tomas Stolker Date: Wed, 13 Dec 2023 12:19:45 +0100 Subject: [PATCH 01/10] Added docstrings to super-Gaussian functions, added window_contours parameter to show_clean_params --- amical/data_processing.py | 44 +++++++++++++++++++++++-------- amical/tools.py | 54 +++++++++++++++++++++++++++++++++------ 2 files changed, 80 insertions(+), 18 deletions(-) diff --git a/amical/data_processing.py b/amical/data_processing.py index a1b014c0..5bcb57f2 100644 --- a/amical/data_processing.py +++ b/amical/data_processing.py @@ -17,7 +17,7 @@ from rich import print as rprint from rich.progress import track -from amical.tools import apply_windowing, crop_max, find_max +from amical.tools import apply_windowing, crop_max, find_max, super_gaussian def _apply_patch_ghost(cube, xc, yc, radius=20, dx=0, dy=-200, method="bg"): @@ -373,6 +373,7 @@ def show_clean_params( *, ifu=False, mask=None, + window_contours=False, ): """Display the input parameters for the cleaning. @@ -389,6 +390,7 @@ def show_clean_params( `remove_bad` {bool}: If True, the bad pixels are removed using a gaussian interpolation,\n `nframe` {int}: Frame number to be shown (default: 0),\n `ihdu` {int}: Hdu number of the fits file. Normally 1 for NIRISS and 0 for SPHERE (default: 0). + `window_contours` {bool}: shown contours of the super-Gaussian windowing (default: False). """ import matplotlib.pyplot as plt from astropy.io import fits @@ -424,8 +426,7 @@ def show_clean_params( img1 = fix_bad_pixels(img0, bmap0, add_bad=ab0) else: img1 = img0.copy() - cropped_infos = crop_max(img1, isz, offx=offx, offy=offy, f=f_kernel) - pos = cropped_infos[1] + _, pos = crop_max(img1, isz, offx=offx, offy=offy, f=f_kernel) noBadPixel = False bad_pix_x, bad_pix_y = [], [] @@ -455,10 +456,6 @@ def show_clean_params( bg_x = bg_coords[0] bg_y = bg_coords[1] sky_method = "mask" - if window is not None: - r3 = window - x3 = r3 * np.cos(theta) + x0 - y3 = r3 * np.sin(theta) + y0 xs1, ys1 = x0 + isz // 2, y0 + isz // 2 xs2, ys2 = x0 - isz // 2, y0 + isz // 2 @@ -485,9 +482,36 @@ def show_clean_params( s=20, label="Pixels used for sky subtraction", ) - if apod: - if window is not None: - plt.plot(x3, y3, "--", label="Super-gaussian windowing") + if apod and window is not None: + # The window parameter gives the FWHM of the super-Gaussian + # windowing. Dividing by 2 gives the HWHM since the value + # is used as the radius for the circle that is plotted + x3 = window/2.0 * np.cos(theta) + x0 + y3 = window/2.0 * np.sin(theta) + y0 + plt.plot(x3, y3, "--", label="Super-gaussian windowing (FWHM)") + + if window_contours: + # Create distance grid for windowing, + # relative to the new image center (x0, y0) + y_coord = np.arange(img1.shape[0]) - y0 + x_coord = np.arange(img1.shape[1]) - x0 + xx_grid, yy_grid = np.meshgrid(x_coord, y_coord) + distance = np.hypot(xx_grid, yy_grid) + + # Create the super-Gaussian window function + super_gauss = super_gaussian(distance, window=window) + + # Plot contours of the window function + # Create a new meshgrid because the coordinate system + # in the plot is relative to the bottom left corner + y_coord = np.arange(img1.shape[0]) + x_coord = np.arange(img1.shape[1]) + xx_grid, yy_grid = np.meshgrid(x_coord, y_coord) + levels = [0.1, 0.25, 0.5, 0.75, 0.9] + contours = plt.contour(xx_grid, yy_grid, super_gauss, levels=levels, + linestyles=':', linewidths=0.8, colors='white') + plt.clabel(contours, contours.levels, inline=True, fontsize=7.) + plt.plot(x0, y0, "+", color="c", ms=10, label="Centering position") plt.plot( [xs1, xs2, xs3, xs4, xs1], diff --git a/amical/tools.py b/amical/tools.py index 7a6b606b..53615c9f 100644 --- a/amical/tools.py +++ b/amical/tools.py @@ -13,6 +13,8 @@ import sys import warnings +from typing import Tuple + import numpy as np from rich import print as rprint @@ -278,22 +280,59 @@ def cov2cor(cov): return cor, sigma -def super_gaussian(x, sigma, m, amp=1, x0=0): - sigma = float(sigma) - m = float(m) +def super_gaussian(x: np.ndarray, window: float, m: float = 3.0, amp: float = 1.0, x0: float = 0.0) -> np.ndarray: + """ + Function for creating a super-Gaussian window. + + Parameters + ---------- + x : np.ndarray + 2D array with the distances of each pixel to the image center. + window : float + Full width at half maximum of the super-Gaussian window. + m : float + Exponent used for the super-Gaussian function (default: 3.0). + amp : float + Amplitude of the Gaussian function (default: 1.0). + x0 : float + Offset applied to the distances (default: 0.0) + + Returns + ------- + np.ndarray + 2D array with the super-Gaussian window function. + """ + return amp * ( ( np.exp( -(2 ** (2 * m - 1)) * np.log(2) - * (((x - x0) ** 2) / ((sigma) ** 2)) ** (m) + * (((x - x0) ** 2) / (window ** 2)) ** m ) ) ** 2 ) -def apply_windowing(img, window=80, m=3): +def apply_windowing(img: np.ndarray, window: float = 80.0, m: float = 3.0) -> np.ndarray: + """ + Function for applying a super-Gaussian window to an image. + + Parameters + ---------- + img : np.ndarray + 2D array with the input image. + window : float + Full width at half maximum of the window function (default: 80.0). + m : float + Exponent used for the super-Gaussian function (default: 3.0). + + Returns + ------- + np.ndarray + 2D array with the windowed input image. + """ isz = len(img) xx, yy = np.arange(isz), np.arange(isz) xx2 = xx - isz // 2 @@ -302,11 +341,10 @@ def apply_windowing(img, window=80, m=3): distance = np.sqrt(xx2**2 + yy2[:, np.newaxis] ** 2) # Super-gaussian windowing - window = super_gaussian(distance, sigma=window * 2, m=m) + super_gauss = super_gaussian(distance, window=window, m=m) # Apply the windowing - img_apod = img * window - return img_apod + return img * super_gauss def sanitize_array(dic): # pragma: no cover From cba54b576eb95a7d39f5916f957c867bb2f2ddb1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 13 Dec 2023 11:37:46 +0000 Subject: [PATCH 02/10] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- amical/data_processing.py | 17 ++++++++++++----- amical/tools.py | 14 +++++++------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/amical/data_processing.py b/amical/data_processing.py index 5bcb57f2..42ae9fa6 100644 --- a/amical/data_processing.py +++ b/amical/data_processing.py @@ -486,8 +486,8 @@ def show_clean_params( # The window parameter gives the FWHM of the super-Gaussian # windowing. Dividing by 2 gives the HWHM since the value # is used as the radius for the circle that is plotted - x3 = window/2.0 * np.cos(theta) + x0 - y3 = window/2.0 * np.sin(theta) + y0 + x3 = window / 2.0 * np.cos(theta) + x0 + y3 = window / 2.0 * np.sin(theta) + y0 plt.plot(x3, y3, "--", label="Super-gaussian windowing (FWHM)") if window_contours: @@ -508,9 +508,16 @@ def show_clean_params( x_coord = np.arange(img1.shape[1]) xx_grid, yy_grid = np.meshgrid(x_coord, y_coord) levels = [0.1, 0.25, 0.5, 0.75, 0.9] - contours = plt.contour(xx_grid, yy_grid, super_gauss, levels=levels, - linestyles=':', linewidths=0.8, colors='white') - plt.clabel(contours, contours.levels, inline=True, fontsize=7.) + contours = plt.contour( + xx_grid, + yy_grid, + super_gauss, + levels=levels, + linestyles=":", + linewidths=0.8, + colors="white", + ) + plt.clabel(contours, contours.levels, inline=True, fontsize=7.0) plt.plot(x0, y0, "+", color="c", ms=10, label="Centering position") plt.plot( diff --git a/amical/tools.py b/amical/tools.py index 53615c9f..bb189c04 100644 --- a/amical/tools.py +++ b/amical/tools.py @@ -13,8 +13,6 @@ import sys import warnings -from typing import Tuple - import numpy as np from rich import print as rprint @@ -280,7 +278,9 @@ def cov2cor(cov): return cor, sigma -def super_gaussian(x: np.ndarray, window: float, m: float = 3.0, amp: float = 1.0, x0: float = 0.0) -> np.ndarray: +def super_gaussian( + x: np.ndarray, window: float, m: float = 3.0, amp: float = 1.0, x0: float = 0.0 +) -> np.ndarray: """ Function for creating a super-Gaussian window. @@ -306,16 +306,16 @@ def super_gaussian(x: np.ndarray, window: float, m: float = 3.0, amp: float = 1. return amp * ( ( np.exp( - -(2 ** (2 * m - 1)) - * np.log(2) - * (((x - x0) ** 2) / (window ** 2)) ** m + -(2 ** (2 * m - 1)) * np.log(2) * (((x - x0) ** 2) / (window**2)) ** m ) ) ** 2 ) -def apply_windowing(img: np.ndarray, window: float = 80.0, m: float = 3.0) -> np.ndarray: +def apply_windowing( + img: np.ndarray, window: float = 80.0, m: float = 3.0 +) -> np.ndarray: """ Function for applying a super-Gaussian window to an image. From ae52eb096eec1d9f4b1c6035b8fcb0b5f3804257 Mon Sep 17 00:00:00 2001 From: Tomas Stolker Date: Tue, 2 Jan 2024 09:38:08 +0100 Subject: [PATCH 03/10] Changed the window parameter in super_gaussian back to sigma --- amical/tools.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/amical/tools.py b/amical/tools.py index bb189c04..8f1dd04e 100644 --- a/amical/tools.py +++ b/amical/tools.py @@ -279,7 +279,7 @@ def cov2cor(cov): def super_gaussian( - x: np.ndarray, window: float, m: float = 3.0, amp: float = 1.0, x0: float = 0.0 + x: np.ndarray, sigma: float, m: float = 3.0, amp: float = 1.0, x0: float = 0.0 ) -> np.ndarray: """ Function for creating a super-Gaussian window. @@ -288,8 +288,10 @@ def super_gaussian( ---------- x : np.ndarray 2D array with the distances of each pixel to the image center. - window : float - Full width at half maximum of the super-Gaussian window. + sigma : float + Full width at half maximum of the super-Gaussian window. It + is therefore not the standard deviation, as the parameter + name would suggest. m : float Exponent used for the super-Gaussian function (default: 3.0). amp : float @@ -306,7 +308,7 @@ def super_gaussian( return amp * ( ( np.exp( - -(2 ** (2 * m - 1)) * np.log(2) * (((x - x0) ** 2) / (window**2)) ** m + -(2 ** (2 * m - 1)) * np.log(2) * (((x - x0) ** 2) / (sigma**2)) ** m ) ) ** 2 From 2badd7b8ef826394a15946bc5a0c7d83c5b2d468 Mon Sep 17 00:00:00 2001 From: Tomas Stolker Date: Tue, 2 Jan 2024 10:52:40 +0100 Subject: [PATCH 04/10] Fixed parameter name when calling super_gaussian --- amical/data_processing.py | 2 +- amical/tools.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/amical/data_processing.py b/amical/data_processing.py index 42ae9fa6..5d9ee9b9 100644 --- a/amical/data_processing.py +++ b/amical/data_processing.py @@ -499,7 +499,7 @@ def show_clean_params( distance = np.hypot(xx_grid, yy_grid) # Create the super-Gaussian window function - super_gauss = super_gaussian(distance, window=window) + super_gauss = super_gaussian(distance, sigma=window) # Plot contours of the window function # Create a new meshgrid because the coordinate system diff --git a/amical/tools.py b/amical/tools.py index 8f1dd04e..e34cebaa 100644 --- a/amical/tools.py +++ b/amical/tools.py @@ -343,7 +343,7 @@ def apply_windowing( distance = np.sqrt(xx2**2 + yy2[:, np.newaxis] ** 2) # Super-gaussian windowing - super_gauss = super_gaussian(distance, window=window, m=m) + super_gauss = super_gaussian(distance, sigma=window, m=m) # Apply the windowing return img * super_gauss From cf04ba34705622350aff042c7376ec1bfb0682b7 Mon Sep 17 00:00:00 2001 From: Tomas Stolker Date: Thu, 4 Jan 2024 10:52:06 +0100 Subject: [PATCH 05/10] Fixed documentation of window parameter to HWHM, added warnings about deprecation of the apod parameter --- amical/_cli/main.py | 4 +- amical/data_processing.py | 78 +++++++++++++++++++++++++++++++-------- amical/tools.py | 9 +++-- 3 files changed, 70 insertions(+), 21 deletions(-) diff --git a/amical/_cli/main.py b/amical/_cli/main.py index 20f34d64..5286f3ee 100644 --- a/amical/_cli/main.py +++ b/amical/_cli/main.py @@ -59,13 +59,13 @@ def main(argv: Optional[List[str]] = None) -> int: action="store_true", help="Perform apodisation using a super-gaussian function " + "(known as windowing)." - + " The gaussian FWHM is set by the parameter `window`.", + + " The gaussian HWHM is set by the parameter `window`.", ) clean_parser.add_argument( "--window", default=65, type=int, - help="FWHM used for windowing (used with --apod)(default: %(default)s)", + help="HWHM used for windowing (used with --apod)(default: %(default)s)", ) clean_parser.add_argument( "--sky", diff --git a/amical/data_processing.py b/amical/data_processing.py index d0569498..80df7247 100644 --- a/amical/data_processing.py +++ b/amical/data_processing.py @@ -396,6 +396,28 @@ def show_clean_params( from astropy.io import fits from matplotlib.colors import PowerNorm + if apod: + warnings.warn("The 'apod' parameter is deprecated and will be " + "removed in a future release. Please only use " + "the 'window' parameter instead. The argument of " + "'window' can be set to None for not applying the " + "super-Gaussian windowing.", DeprecationWarning) + + if window is None: + warnings.warn("The argument of 'apod' will be forced to " + "False because the argument of `window` was " + "set to None`.") + + apod = False + + elif not apod and window is not None: + warnings.warn("The argument of 'apod' will be forced to " + "True because the `window` size has been " + "set. To not apply the apodization, please " + "set the argument of 'window' to None.") + + apod = True + with fits.open(filename) as fd: data = fd[ihdu].data @@ -489,13 +511,13 @@ def show_clean_params( s=20, label="Pixels used for sky subtraction", ) - if apod and window is not None: - # The window parameter gives the FWHM of the super-Gaussian - # windowing. Dividing by 2 gives the HWHM since the value - # is used as the radius for the circle that is plotted - x3 = window / 2.0 * np.cos(theta) + x0 - y3 = window / 2.0 * np.sin(theta) + y0 - plt.plot(x3, y3, "--", label="Super-gaussian windowing (FWHM)") + + if window is not None: + # The window parameter gives the HWHM of the super-Gaussian. + # The value is used as the radius for the circle in the plot. + x3 = window * np.cos(theta) + x0 + y3 = window * np.sin(theta) + y0 + plt.plot(x3, y3, "--", label="Super-Gaussian windowing (HWHM)") if window_contours: # Create distance grid for windowing, @@ -590,7 +612,7 @@ def clean_data( edge=0, bad_map=None, add_bad=None, - apod=True, + apod=False, offx=0, offy=0, sky=True, @@ -701,7 +723,7 @@ def select_clean_data( offx=0, offy=0, clip_fact=0.5, - apod=True, + apod=False, sky=True, window=None, darkfile=None, @@ -727,18 +749,22 @@ def select_clean_data( `edge` {int}: Patch the edges of the image (VLT/SPHERE artifact, default: {0}),\n `clip` {bool}: If True, sigma-clipping is used to reject frames with low integrated flux,\n `clip_fact` {float}: Relative sigma if rejecting frames by sigma-clipping,\n - `apod` {bool}: If True, apodisation is performed in the image plan using a super-gaussian - function (known as windowing). The gaussian FWHM is set by the parameter `window`,\n - `window` {float}: FWHM of the super-gaussian to apodise the image (smoothly go to zero - on the edges),\n + `apod` {bool}: If True, apodisation is performed in the image plan using a super-Gaussian + function (known as windowing). The Gaussian HWHM is set by the parameter `window`. This + parameter is deprecated and will be removed in a future release. Instead, the apodization + is applied when providing a value to the `window` parameter. Setting the argument of + `window` to None will not apply the super-Gaussian windowing,\n + `window` {float}: Half width at half maximum (HWHM) of the super-Gaussian to apodise + the image (smoothly go to zero on the edges). The windowing is not applied when the + argument is set to None,\n `sky` {bool}: If True, the sky is remove using the annulus technique (computed between `r1` - and `r1` + `dr`), + and `r1` + `dr`),\n `darkfile` {str}: If specified (default: None), the input dark (master_dark averaged if multiple integrations) is substracted from the raw image,\n image,\n `f_kernel` {float}: kernel size used in the applied median filter (to find the center). `remove_bad` {bool}: If True, the bad pixels are removed in the cleaning parameter - plots using a gaussian interpolation (default: {True}),\n + plots using a Gaussian interpolation (default: {True}),\n `nframe` {int}: Frame number used to show cleaning parameters (default: {0}),\n Returns: @@ -747,6 +773,28 @@ def select_clean_data( """ from astropy.io import fits + if apod: + warnings.warn("The 'apod' parameter is deprecated and will be " + "removed in a future release. Please only use " + "the 'window' parameter instead. The argument of " + "'window' can be set to None for not applying the " + "super-Gaussian windowing.", DeprecationWarning) + + if window is None: + warnings.warn("The argument of 'apod' will be forced to " + "False because the argument of `window` was " + "set to None`.") + + apod = False + + elif not apod and window is not None: + warnings.warn("The argument of 'apod' will be forced to " + "True because the `window` size has been " + "set. To not apply the apodization, please " + "set the argument of 'window' to None.") + + apod = True + with fits.open(filename) as hdu: cube = hdu[ihdu].data hdr = hdu[0].header diff --git a/amical/tools.py b/amical/tools.py index e34cebaa..50c4f57a 100644 --- a/amical/tools.py +++ b/amical/tools.py @@ -289,9 +289,9 @@ def super_gaussian( x : np.ndarray 2D array with the distances of each pixel to the image center. sigma : float - Full width at half maximum of the super-Gaussian window. It - is therefore not the standard deviation, as the parameter - name would suggest. + Half width at half maximum (HWHM) of the super-Gaussian + window. It is therefore not the standard deviation, as the + parameter name would suggest. m : float Exponent used for the super-Gaussian function (default: 3.0). amp : float @@ -326,7 +326,8 @@ def apply_windowing( img : np.ndarray 2D array with the input image. window : float - Full width at half maximum of the window function (default: 80.0). + Half width at half maximum (HWHM) of the window function + (default: 80.0). m : float Exponent used for the super-Gaussian function (default: 3.0). From 809311e1c8ca25b7dcd6290df2a5c4d0a3d69c71 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 4 Jan 2024 09:52:27 +0000 Subject: [PATCH 06/10] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- amical/data_processing.py | 62 ++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/amical/data_processing.py b/amical/data_processing.py index 80df7247..45e5741a 100644 --- a/amical/data_processing.py +++ b/amical/data_processing.py @@ -397,24 +397,31 @@ def show_clean_params( from matplotlib.colors import PowerNorm if apod: - warnings.warn("The 'apod' parameter is deprecated and will be " - "removed in a future release. Please only use " - "the 'window' parameter instead. The argument of " - "'window' can be set to None for not applying the " - "super-Gaussian windowing.", DeprecationWarning) + warnings.warn( + "The 'apod' parameter is deprecated and will be " + "removed in a future release. Please only use " + "the 'window' parameter instead. The argument of " + "'window' can be set to None for not applying the " + "super-Gaussian windowing.", + DeprecationWarning, + ) if window is None: - warnings.warn("The argument of 'apod' will be forced to " - "False because the argument of `window` was " - "set to None`.") + warnings.warn( + "The argument of 'apod' will be forced to " + "False because the argument of `window` was " + "set to None`." + ) apod = False elif not apod and window is not None: - warnings.warn("The argument of 'apod' will be forced to " - "True because the `window` size has been " - "set. To not apply the apodization, please " - "set the argument of 'window' to None.") + warnings.warn( + "The argument of 'apod' will be forced to " + "True because the `window` size has been " + "set. To not apply the apodization, please " + "set the argument of 'window' to None." + ) apod = True @@ -774,24 +781,31 @@ def select_clean_data( from astropy.io import fits if apod: - warnings.warn("The 'apod' parameter is deprecated and will be " - "removed in a future release. Please only use " - "the 'window' parameter instead. The argument of " - "'window' can be set to None for not applying the " - "super-Gaussian windowing.", DeprecationWarning) + warnings.warn( + "The 'apod' parameter is deprecated and will be " + "removed in a future release. Please only use " + "the 'window' parameter instead. The argument of " + "'window' can be set to None for not applying the " + "super-Gaussian windowing.", + DeprecationWarning, + ) if window is None: - warnings.warn("The argument of 'apod' will be forced to " - "False because the argument of `window` was " - "set to None`.") + warnings.warn( + "The argument of 'apod' will be forced to " + "False because the argument of `window` was " + "set to None`." + ) apod = False elif not apod and window is not None: - warnings.warn("The argument of 'apod' will be forced to " - "True because the `window` size has been " - "set. To not apply the apodization, please " - "set the argument of 'window' to None.") + warnings.warn( + "The argument of 'apod' will be forced to " + "True because the `window` size has been " + "set. To not apply the apodization, please " + "set the argument of 'window' to None." + ) apod = True From 3f05a3865af78123bc2022068c1fd2d1b8f41173 Mon Sep 17 00:00:00 2001 From: Tomas Stolker Date: Thu, 4 Jan 2024 10:58:41 +0100 Subject: [PATCH 07/10] Added back the factor 2 to change from HWHM to FWHM --- amical/data_processing.py | 3 ++- amical/tools.py | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/amical/data_processing.py b/amical/data_processing.py index 45e5741a..aa9d893e 100644 --- a/amical/data_processing.py +++ b/amical/data_processing.py @@ -535,7 +535,8 @@ def show_clean_params( distance = np.hypot(xx_grid, yy_grid) # Create the super-Gaussian window function - super_gauss = super_gaussian(distance, sigma=window) + # Mutiply the window value with 2 to change from HWHM to FWHM + super_gauss = super_gaussian(distance, sigma=window * 2) # Plot contours of the window function # Create a new meshgrid because the coordinate system diff --git a/amical/tools.py b/amical/tools.py index 50c4f57a..8fbafa71 100644 --- a/amical/tools.py +++ b/amical/tools.py @@ -289,7 +289,7 @@ def super_gaussian( x : np.ndarray 2D array with the distances of each pixel to the image center. sigma : float - Half width at half maximum (HWHM) of the super-Gaussian + Full width at half maximum (FWHM) of the super-Gaussian window. It is therefore not the standard deviation, as the parameter name would suggest. m : float @@ -344,7 +344,8 @@ def apply_windowing( distance = np.sqrt(xx2**2 + yy2[:, np.newaxis] ** 2) # Super-gaussian windowing - super_gauss = super_gaussian(distance, sigma=window, m=m) + # Mutiply the window value with 2 to change from HWHM to FWHM + super_gauss = super_gaussian(distance, sigma=window * 2, m=m) # Apply the windowing return img * super_gauss From af0e6a4c22f1ecb4d6937c7be2e4a186de8c8be9 Mon Sep 17 00:00:00 2001 From: Tomas Stolker Date: Thu, 4 Jan 2024 11:28:51 +0100 Subject: [PATCH 08/10] Commented the warnings about apod deprecation --- amical/data_processing.py | 116 +++++++++++++++++++------------------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/amical/data_processing.py b/amical/data_processing.py index aa9d893e..bbedf193 100644 --- a/amical/data_processing.py +++ b/amical/data_processing.py @@ -368,7 +368,7 @@ def show_clean_params( f_kernel=3, offx=0, offy=0, - apod=False, + apod=True, window=None, *, ifu=False, @@ -396,34 +396,34 @@ def show_clean_params( from astropy.io import fits from matplotlib.colors import PowerNorm - if apod: - warnings.warn( - "The 'apod' parameter is deprecated and will be " - "removed in a future release. Please only use " - "the 'window' parameter instead. The argument of " - "'window' can be set to None for not applying the " - "super-Gaussian windowing.", - DeprecationWarning, - ) - - if window is None: - warnings.warn( - "The argument of 'apod' will be forced to " - "False because the argument of `window` was " - "set to None`." - ) - - apod = False - - elif not apod and window is not None: - warnings.warn( - "The argument of 'apod' will be forced to " - "True because the `window` size has been " - "set. To not apply the apodization, please " - "set the argument of 'window' to None." - ) - - apod = True + # if apod: + # warnings.warn( + # "The 'apod' parameter is deprecated and will be " + # "removed in a future release. Please only use " + # "the 'window' parameter instead. The argument of " + # "'window' can be set to None for not applying the " + # "super-Gaussian windowing.", + # DeprecationWarning, + # ) + # + # if window is None: + # warnings.warn( + # "The argument of 'apod' will be forced to " + # "False because the argument of `window` was " + # "set to None`." + # ) + # + # apod = False + # + # elif not apod and window is not None: + # warnings.warn( + # "The argument of 'apod' will be forced to " + # "True because the `window` size has been " + # "set. To not apply the apodization, please " + # "set the argument of 'window' to None." + # ) + # + # apod = True with fits.open(filename) as fd: data = fd[ihdu].data @@ -620,7 +620,7 @@ def clean_data( edge=0, bad_map=None, add_bad=None, - apod=False, + apod=True, offx=0, offy=0, sky=True, @@ -781,34 +781,34 @@ def select_clean_data( """ from astropy.io import fits - if apod: - warnings.warn( - "The 'apod' parameter is deprecated and will be " - "removed in a future release. Please only use " - "the 'window' parameter instead. The argument of " - "'window' can be set to None for not applying the " - "super-Gaussian windowing.", - DeprecationWarning, - ) - - if window is None: - warnings.warn( - "The argument of 'apod' will be forced to " - "False because the argument of `window` was " - "set to None`." - ) - - apod = False - - elif not apod and window is not None: - warnings.warn( - "The argument of 'apod' will be forced to " - "True because the `window` size has been " - "set. To not apply the apodization, please " - "set the argument of 'window' to None." - ) - - apod = True + # if apod: + # warnings.warn( + # "The 'apod' parameter is deprecated and will be " + # "removed in a future release. Please only use " + # "the 'window' parameter instead. The argument of " + # "'window' can be set to None for not applying the " + # "super-Gaussian windowing.", + # DeprecationWarning, + # ) + # + # if window is None: + # warnings.warn( + # "The argument of 'apod' will be forced to " + # "False because the argument of `window` was " + # "set to None`." + # ) + # + # apod = False + # + # elif not apod and window is not None: + # warnings.warn( + # "The argument of 'apod' will be forced to " + # "True because the `window` size has been " + # "set. To not apply the apodization, please " + # "set the argument of 'window' to None." + # ) + # + # apod = True with fits.open(filename) as hdu: cube = hdu[ihdu].data From df92aa9be1d959f83b7ef764c5d5d01745ee6caf Mon Sep 17 00:00:00 2001 From: Tomas Stolker Date: Thu, 4 Jan 2024 11:52:17 +0100 Subject: [PATCH 09/10] Removed comments --- amical/data_processing.py | 58 --------------------------------------- 1 file changed, 58 deletions(-) diff --git a/amical/data_processing.py b/amical/data_processing.py index bbedf193..54e4f5f6 100644 --- a/amical/data_processing.py +++ b/amical/data_processing.py @@ -396,35 +396,6 @@ def show_clean_params( from astropy.io import fits from matplotlib.colors import PowerNorm - # if apod: - # warnings.warn( - # "The 'apod' parameter is deprecated and will be " - # "removed in a future release. Please only use " - # "the 'window' parameter instead. The argument of " - # "'window' can be set to None for not applying the " - # "super-Gaussian windowing.", - # DeprecationWarning, - # ) - # - # if window is None: - # warnings.warn( - # "The argument of 'apod' will be forced to " - # "False because the argument of `window` was " - # "set to None`." - # ) - # - # apod = False - # - # elif not apod and window is not None: - # warnings.warn( - # "The argument of 'apod' will be forced to " - # "True because the `window` size has been " - # "set. To not apply the apodization, please " - # "set the argument of 'window' to None." - # ) - # - # apod = True - with fits.open(filename) as fd: data = fd[ihdu].data @@ -781,35 +752,6 @@ def select_clean_data( """ from astropy.io import fits - # if apod: - # warnings.warn( - # "The 'apod' parameter is deprecated and will be " - # "removed in a future release. Please only use " - # "the 'window' parameter instead. The argument of " - # "'window' can be set to None for not applying the " - # "super-Gaussian windowing.", - # DeprecationWarning, - # ) - # - # if window is None: - # warnings.warn( - # "The argument of 'apod' will be forced to " - # "False because the argument of `window` was " - # "set to None`." - # ) - # - # apod = False - # - # elif not apod and window is not None: - # warnings.warn( - # "The argument of 'apod' will be forced to " - # "True because the `window` size has been " - # "set. To not apply the apodization, please " - # "set the argument of 'window' to None." - # ) - # - # apod = True - with fits.open(filename) as hdu: cube = hdu[ihdu].data hdr = hdu[0].header From 9419a31fe145011ad7aac771aa4b895d305f7bc4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 16 Jul 2024 15:43:41 +0000 Subject: [PATCH 10/10] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- amical/tools.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/amical/tools.py b/amical/tools.py index f8b5dfda..c2a173a1 100644 --- a/amical/tools.py +++ b/amical/tools.py @@ -305,11 +305,7 @@ def super_gaussian( """ return amp * ( - ( - np.exp( - -(2 ** (2 * m - 1)) * np.log(2) * (((x - x0) ** 2) / (sigma**2)) ** m - ) - ) + (np.exp(-(2 ** (2 * m - 1)) * np.log(2) * (((x - x0) ** 2) / (sigma**2)) ** m)) ** 2 )