From 7a897753d7c2f522e465d7fe00a5400e66d1bbac Mon Sep 17 00:00:00 2001 From: chrisbrand-droid Date: Tue, 3 Nov 2026 13:22:50 +0100 Subject: [PATCH 1/2] Updated the following files: - setup.py import pkg_resources was deprecated and removed in Python 3.12. The code was updated to reflect this change by removing the import statement and any references to pkg_resources in the setup.py file. Now it takes the lines directly from the requirements.txt file without using pkg_resources. - gnlse/dispersion.py numpy.math.factorial was deprecated and removed in numpy 1.25.0. The code was updated to use the math module instead of numpy for calculating factorials. This change ensures compatibility with newer versions of numpy and avoids potential issues with deprecated functions. - gnlse/visualization.py Scipy.interpolate.interp1d was deprecated and removed in Scipy 1.14.0. The code was updated to use the new SciPy interpolator RegularGridInterpolator, ensuring that the visualization functions continue to work correctly with the latest version of the library. - examples/test_Dudley.py The plotting functions were updated to use logarithmic scales for better visualization of the data to reflect what was plotted in the book Supercontinuum Generation by Dudley and Taylor. The changes include replacing the original plotting functions with their logarithmic counterparts, allowing for a more accurate representation of the results in the plots. --- examples/test_Dudley.py | 4 ++-- gnlse/dispersion.py | 3 ++- gnlse/visualization.py | 15 +++++++++------ setup.py | 17 +++++++++++++---- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/examples/test_Dudley.py b/examples/test_Dudley.py index fef21bc..7dd40ad 100644 --- a/examples/test_Dudley.py +++ b/examples/test_Dudley.py @@ -61,10 +61,10 @@ plt.subplot(2, count, i + 1) plt.title(pulse_model.name) - gnlse.plot_wavelength_vs_distance(solution, WL_range=[400, 1400]) + gnlse.plot_wavelength_vs_distance_logarithmic(solution, WL_range=[400, 1400]) plt.subplot(2, count, i + 1 + count) - gnlse.plot_delay_vs_distance(solution, time_range=[-0.5, 5]) + gnlse.plot_delay_vs_distance_logarithmic(solution, time_range=[-0.5, 5]) plt.tight_layout() plt.show() diff --git a/gnlse/dispersion.py b/gnlse/dispersion.py index 0e05922..b02c4eb 100644 --- a/gnlse/dispersion.py +++ b/gnlse/dispersion.py @@ -6,6 +6,7 @@ """ import numpy as np +import math from scipy import interpolate from gnlse.common import c @@ -67,7 +68,7 @@ def D(self, V): self.calc_loss() # Taylor series for subsequent derivatives # of constant propagation - B = sum(beta / np.math.factorial(i + 2) * V**(i + 2) + B = sum(beta / math.factorial(i + 2) * V**(i + 2) for i, beta in enumerate(self.betas)) L = 1j * B - self.alpha / 2 return L diff --git a/gnlse/visualization.py b/gnlse/visualization.py index 56f3784..43c3d78 100644 --- a/gnlse/visualization.py +++ b/gnlse/visualization.py @@ -5,7 +5,8 @@ import numpy as np import matplotlib.pyplot as plt -from scipy.interpolate import interp2d +#from scipy.interpolate import interp2d - deprecated since SciPy version 1.14.0 +from scipy.interpolate import RegularGridInterpolator from gnlse.common import c @@ -582,9 +583,10 @@ def plot_wavelength_vs_distance(solver, WL_range=None, ax=None, WL_asc = WL_asc[iis] IW = IW[:, iis] - interpolator = interp2d(WL_asc, solver.Z, IW) + interpolator = RegularGridInterpolator((WL_asc, solver.Z), IW.T, method='cubic') newWL = np.linspace(np.min(WL_asc), np.max(WL_asc), IW.shape[1]) - toshow = interpolator(newWL, solver.Z) + WL_new_grid, Z_new_grid = np.meshgrid(newWL, solver.Z, indexing='ij') + toshow = interpolator((WL_new_grid, Z_new_grid)).T ax.imshow(toshow, origin='lower', aspect='auto', cmap=cmap, extent=[np.min(WL_asc), np.max(WL_asc), 0, np.max(solver.Z)], @@ -637,9 +639,10 @@ def plot_wavelength_vs_distance_logarithmic(solver, WL_range=None, WL_asc = WL_asc[iis] lIW = lIW[:, iis] - interpolator = interp2d(WL_asc, solver.Z, lIW) + interpolator = RegularGridInterpolator((WL_asc, solver.Z), lIW.T) newWL = np.linspace(np.min(WL_asc), np.max(WL_asc), lIW.shape[1]) - toshow = interpolator(newWL, solver.Z) + WL_new_grid, Z_new_grid = np.meshgrid(newWL, solver.Z, indexing='ij') + toshow = interpolator((WL_new_grid, Z_new_grid)).T ax.imshow(toshow, origin='lower', aspect='auto', cmap=cmap, extent=[np.min(WL_asc), np.max(WL_asc), 0, np.max(solver.Z)], @@ -666,4 +669,4 @@ def quick_plot(solution): plt.subplot(1, 2, 2) plot_delay_vs_distance(solution) - plt.show() + plt.show() \ No newline at end of file diff --git a/setup.py b/setup.py index 8286482..ce861ae 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,15 @@ -import pkg_resources +#import pkg_resources # old, doesn't work anymore with python 3.10.# +#from packaging.requirements import Requirement from setuptools import find_packages from setuptools import setup with open('requirements.txt', 'r') as fh: - reqs = [str(requirement) - for requirement in pkg_resources.parse_requirements(fh)] + reqs = [ + line.strip() + for line in fh + if line.strip() and not line.strip().startswith('#') + ] with open("README.md", "r") as fh: long_description = fh.read() @@ -23,9 +27,14 @@ packages=find_packages(), classifiers=[ 'Programming Language :: Python :: 3', - 'License :: OSI Approved :: MIT License', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', + 'Programming Language :: Python :: 3.13', + 'Programming Language :: Python :: 3.14', 'Operating System :: OS Independent', ], + license='MIT', python_requires='>=3.7', install_requires=reqs, ) From f4494a95bf9e1793dbd12c5018a23c7d5ee6a1a5 Mon Sep 17 00:00:00 2001 From: chrisbrand-droid Date: Fri, 6 Nov 2026 16:37:35 +0100 Subject: [PATCH 2/2] Formatting changes and requirement updates to fix test failures on previous pull request and some warnings. Changes to requirements.txt to update the minimum version of numpy, matplotlib, hdf5storage and scipy. Warnings: - visualization.py: in np.log10, added out=None to avoid warnings when the where condition is not met. - gnlse.py: in the tqdm progress bar, round the total (fibre length) to avoid warnings when the rounded fraction is greater than the total. - plot_input_pulse.py: Changed the plotting to plot the absolute values of the amplitude envelopes to avoid warnings when plotting complex numbers. Cosmetic changes: - Changed to logarithmic plots in test_raman.py to visualise the spectrum better. - setup.py: removed commented out code. - plot_input_pulse.py: fixed typos in comments. - visualization.py: split long line into two lines to avoid line length warnings. --- examples/plot_input_pulse.py | 20 ++++++++++---------- examples/test_raman.py | 4 ++-- gnlse/gnlse.py | 2 +- gnlse/visualization.py | 6 ++++-- requirements.txt | 8 ++++---- setup.py | 3 --- 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/examples/plot_input_pulse.py b/examples/plot_input_pulse.py index a56f0a8..2db1688 100644 --- a/examples/plot_input_pulse.py +++ b/examples/plot_input_pulse.py @@ -18,9 +18,9 @@ # peak power [W] Pmax = 100 - # Amplitude envelope of gaussina pulse + # Amplitude envelope of gaussian pulse A1 = gnlse.GaussianEnvelope(Pmax, FWHM).A(T) - # Amplitude envelope of hiperbolic secans pulse + # Amplitude envelope of hyperbolic secant pulse A2 = gnlse.SechEnvelope(Pmax, FWHM).A(T) # Amplitude envelope of lorentzian pulse A3 = gnlse.LorentzianEnvelope(Pmax, FWHM).A(T) @@ -29,19 +29,19 @@ plt.figure(figsize=(12, 8)) plt.subplot(1, 2, 1) - plt.plot(T, A1, label='gauss') - plt.plot(T, A2, label='sech') - plt.plot(T, A3, label='lorentz') - plt.plot(T, A4, label='cw') + plt.plot(T, np.abs(A1), label='gauss') + plt.plot(T, np.abs(A2), label='sech') + plt.plot(T, np.abs(A3), label='lorentz') + plt.plot(T, np.abs(A4), label='cw') plt.xlabel("Time [ps]") plt.ylabel("Amplitude [sqrt(W)]") plt.legend() plt.subplot(1, 2, 2) - plt.plot(T, A1**2, label='gauss') - plt.plot(T, A2**2, label='sech') - plt.plot(T, A3**2, label='lorentz') - plt.plot(T, A4**2, label='cw') + plt.plot(T, np.abs(A1)**2, label='gauss') + plt.plot(T, np.abs(A2)**2, label='sech') + plt.plot(T, np.abs(A3)**2, label='lorentz') + plt.plot(T, np.abs(A4)**2, label='cw') plt.xlabel("Time [ps]") plt.ylabel("Power [W]") plt.legend() diff --git a/examples/test_raman.py b/examples/test_raman.py index 29a17d0..6c032aa 100644 --- a/examples/test_raman.py +++ b/examples/test_raman.py @@ -59,9 +59,9 @@ plt.subplot(2, count, i + 1) plt.title(name) - gnlse.plot_wavelength_vs_distance(solution, WL_range=[500, 1250]) + gnlse.plot_wavelength_vs_distance_logarithmic(solution, WL_range=[500, 1250]) plt.subplot(2, count, i + 1 + count) - gnlse.plot_delay_vs_distance(solution, time_range=[-0.5, 4]) + gnlse.plot_delay_vs_distance_logarithmic(solution, time_range=[-0.5, 4]) plt.tight_layout() plt.show() diff --git a/gnlse/gnlse.py b/gnlse/gnlse.py index 888064f..d2befac 100644 --- a/gnlse/gnlse.py +++ b/gnlse/gnlse.py @@ -225,7 +225,7 @@ def run(self): plan_forward = pyfftw.FFTW(x, X) plan_inverse = pyfftw.FFTW(X, x, direction="FFTW_BACKWARD") - progress_bar = tqdm.tqdm(total=self.fiber_length, unit='m') + progress_bar = tqdm.tqdm(total=round(self.fiber_length, 3), unit='m') def rhs(z, AW): """ diff --git a/gnlse/visualization.py b/gnlse/visualization.py index 43c3d78..06c5301 100644 --- a/gnlse/visualization.py +++ b/gnlse/visualization.py @@ -583,7 +583,8 @@ def plot_wavelength_vs_distance(solver, WL_range=None, ax=None, WL_asc = WL_asc[iis] IW = IW[:, iis] - interpolator = RegularGridInterpolator((WL_asc, solver.Z), IW.T, method='cubic') + interpolator = RegularGridInterpolator((WL_asc, solver.Z), + IW.T, method='cubic') newWL = np.linspace(np.min(WL_asc), np.max(WL_asc), IW.shape[1]) WL_new_grid, Z_new_grid = np.meshgrid(newWL, solver.Z, indexing='ij') toshow = interpolator((WL_new_grid, Z_new_grid)).T @@ -669,4 +670,5 @@ def quick_plot(solution): plt.subplot(1, 2, 2) plot_delay_vs_distance(solution) - plt.show() \ No newline at end of file + plt.show() + \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 90e9a69..8030649 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ -matplotlib>=2.2.2 -numpy>=1.14.3 -scipy>=1.1.0 +matplotlib>=3.0.0 +numpy>=2.0.0 +scipy>=1.10.0 pyfftw>=0.10.0 -hdf5storage>=0.1.15 +hdf5storage>=0.2.0 tqdm>=4.11.2 diff --git a/setup.py b/setup.py index ce861ae..9fe9306 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,3 @@ -#import pkg_resources # old, doesn't work anymore with python 3.10.# -#from packaging.requirements import Requirement - from setuptools import find_packages from setuptools import setup