From 7ac3e9c34fcfc6f822f2c06b828a8663c346b025 Mon Sep 17 00:00:00 2001 From: fdannert <62441325+fdannert@users.noreply.github.com> Date: Thu, 10 Dec 2020 17:56:43 +0100 Subject: [PATCH 1/5] added edge_mode option --- spectres/spectral_resampling.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/spectres/spectral_resampling.py b/spectres/spectral_resampling.py index fd3fe94..1193a74 100644 --- a/spectres/spectral_resampling.py +++ b/spectres/spectral_resampling.py @@ -7,18 +7,16 @@ def make_bins(wavs): """ Given a series of wavelength points, find the edges and widths of corresponding wavelength bins. """ edges = np.zeros(wavs.shape[0]+1) - widths = np.zeros(wavs.shape[0]) edges[0] = wavs[0] - (wavs[1] - wavs[0])/2 - widths[-1] = (wavs[-1] - wavs[-2]) edges[-1] = wavs[-1] + (wavs[-1] - wavs[-2])/2 edges[1:-1] = (wavs[1:] + wavs[:-1])/2 - widths[:-1] = edges[1:-1] - edges[:-2] + widths = edges[1:] - edges[:-1] return edges, widths def spectres(new_wavs, spec_wavs, spec_fluxes, spec_errs=None, fill=None, - verbose=True): + verbose=True, edge_mode=False): """ Function for resampling spectra (and optionally associated @@ -53,6 +51,11 @@ def spectres(new_wavs, spec_wavs, spec_fluxes, spec_errs=None, fill=None, Setting verbose to False will suppress the default warning about new_wavs extending outside spec_wavs and "fill" being used. + edge_mode : bool (optional) + If edge_mode is set to true, new_wavs will be read as the edges + of the bins for the desired + sampling. + Returns ------- @@ -74,10 +77,15 @@ def spectres(new_wavs, spec_wavs, spec_fluxes, spec_errs=None, fill=None, # Make arrays of edge positions and widths for the old and new bins old_edges, old_widths = make_bins(old_wavs) - new_edges, new_widths = make_bins(new_wavs) + bins_shape = list(new_wavs.shape) + if edge_mode: + new_edges = new_wavs + bins_shape[0] -= 1 + else: + new_edges, _ = make_bins(new_wavs) # Generate output arrays to be populated - new_fluxes = np.zeros(old_fluxes[..., 0].shape + new_wavs.shape) + new_fluxes = np.zeros(list(old_fluxes[..., 0].shape) + bins_shape) if old_errs is not None: if old_errs.shape != old_fluxes.shape: @@ -91,7 +99,7 @@ def spectres(new_wavs, spec_wavs, spec_fluxes, spec_errs=None, fill=None, warned = False # Calculate new flux and uncertainty values, looping over new bins - for j in range(new_wavs.shape[0]): + for j in range(bins_shape[0]): # Add filler values if new_wavs extends outside of spec_wavs if (new_edges[j] < old_edges[0]) or (new_edges[j+1] > old_edges[-1]): @@ -100,7 +108,7 @@ def spectres(new_wavs, spec_wavs, spec_fluxes, spec_errs=None, fill=None, if spec_errs is not None: new_errs[..., j] = fill - if (j == 0 or j == new_wavs.shape[0]-1) and verbose and not warned: + if (j == 0 or j == bins_shape[0]-1) and verbose and not warned: warned = True print("\nSpectres: new_wavs contains values outside the range " "in spec_wavs, new_fluxes and new_errs will be filled " From 5cda1330919d7e1d4d2ddb2f70354f2912c95ec4 Mon Sep 17 00:00:00 2001 From: fdannert <62441325+fdannert@users.noreply.github.com> Date: Wed, 20 Jan 2021 19:01:21 +0100 Subject: [PATCH 2/5] indentation fix --- spectres/spectral_resampling.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spectres/spectral_resampling.py b/spectres/spectral_resampling.py index 1193a74..dad2ca2 100644 --- a/spectres/spectral_resampling.py +++ b/spectres/spectral_resampling.py @@ -53,8 +53,7 @@ def spectres(new_wavs, spec_wavs, spec_fluxes, spec_errs=None, fill=None, edge_mode : bool (optional) If edge_mode is set to true, new_wavs will be read as the edges - of the bins for the desired - sampling. + of the bins for the desired sampling. Returns ------- From 189906b69bd46ccbfd80bd83542ac34c25848e6d Mon Sep 17 00:00:00 2001 From: fdannert <62441325+fdannert@users.noreply.github.com> Date: Tue, 18 May 2021 20:40:33 +0200 Subject: [PATCH 3/5] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 1a15abc..06d6754 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setup( name='spectres', - version='2.1.1', + version='2.0.1', description='Simple spectral resampling', From 35165cc9e8920fa9971d266f36edb9df1e275754 Mon Sep 17 00:00:00 2001 From: fdannert <62441325+fdannert@users.noreply.github.com> Date: Tue, 18 May 2021 20:49:34 +0200 Subject: [PATCH 4/5] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 06d6754..f02ba87 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setup( name='spectres', - version='2.0.1', + version='2.1.1ex', description='Simple spectral resampling', From 7a8c83025096c8907de30db633cca30c6f4b97ce Mon Sep 17 00:00:00 2001 From: fdannert <62441325+fdannert@users.noreply.github.com> Date: Tue, 18 May 2021 21:17:17 +0200 Subject: [PATCH 5/5] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index f02ba87..1a15abc 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setup( name='spectres', - version='2.1.1ex', + version='2.1.1', description='Simple spectral resampling',