From 31d23145735dfdbab540896a41a5cf0ac6be03a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joseph=20Hopfm=C3=BCller?= Date: Tue, 10 Sep 2024 19:00:27 +0200 Subject: [PATCH] first commit --- .gitignore | 167 +++++++++++++++++++++++++++++++++++++++++++++++++++++ run2.py | 78 +++++++++++++++++++++++++ 2 files changed, 245 insertions(+) create mode 100644 .gitignore create mode 100644 run2.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2c59b68 --- /dev/null +++ b/.gitignore @@ -0,0 +1,167 @@ +.vscode + +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so +!speedfiber.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/latest/usage/project/#working-with-version-control +.pdm.toml +.pdm-python +.pdm-build/ + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ +.python-version +config/wisdom_pyfftw_4096.npy diff --git a/run2.py b/run2.py new file mode 100644 index 0000000..b054961 --- /dev/null +++ b/run2.py @@ -0,0 +1,78 @@ +import pypho +from pypho import functions as pf + +# from pypho_functions import * +# from pypho import functions as pf +import numpy as np +import copy +import matplotlib.pyplot as plt +from scipy.interpolate import UnivariateSpline + +# Define network elements +gp = pypho.setup(nos =2**4, sps = 256, symbolrate = 10.0e9) + + +symbolsrc = pypho.symbols(glova = gp, nos = gp.nos, pattern = 'debruijn') +esigsrc = pypho.signalsrc(glova = gp, pulseshape = 'rect' , fwhm = 0.85) +sig_1550 = pypho.lasmod(glova = gp, power = 0, Df = 0, theta = 0) +SSMF = pypho.fiber(glova = gp, l = 60.0e3, D = 17.0, S = 0, alpha = 0.2e-12, gamma = 1.4e-12, phi_max = 10.0) + +# Simulation +bits = symbolsrc() +esig = esigsrc(bitsequence = bits) + +E_Tx = sig_1550(esig = esig) + + + +# Define your parameters here +T_0 = 25.0e-12 +z = SSMF.l +D = 17.0 +beta_2, beta_3 = pf.DS_to_beta(17.0, 0, gp.lambda0) + + +# Create a single pulse with gaussian shape (not power!) +E_Tx[0]['E'][0] = E_Tx[0]['E'][0]*0 + np.exp(-(gp.timeax()-gp.timeax()[-1]/2)**2 / (2.0*T_0**2) ) + +E = copy.deepcopy(E_Tx) + + +# Fiber transmission +E = SSMF(E = E, D = D, l = z) +#sys.exit() + +# Get FWHM of the input signal E_Tx +spline_0 = UnivariateSpline(gp.timeax()*1.0e12, np.abs(E_Tx[0]['E'][0])-1*np.max(np.abs(E_Tx[0]['E'][0]))/2, s=0) +r1_0, r2_0 = spline_0.roots() # find the roots +# Get FWHM of the output signal E +spline_1 = UnivariateSpline(gp.timeax()*1.0e12, np.abs(E[0]['E'][0])-1*np.max(np.abs(E[0]['E'][0]))/2, s=0) +r1_1, r2_1 = spline_1.roots() # find the roots + +T_FWHM_0 = (r2_0-r1_0) * 1e-12 +T_0_plot = T_FWHM_0 / 2.35482 +T_FWHM_1 = (r2_1-r1_1) * 1e-12 +L_D = (T_0_plot)**2 / np.abs(beta_2) + +# Plot Input and Output signal +plt.figure(1) +plt.plot(gp.timeax()*1.0e12, np.abs(E_Tx[0]['E'][0]), 'r', label='$E(0, t)$') +plt.plot(gp.timeax()*1.0e12, np.abs(E[0]['E'][0]), 'g', label=f'$E(z={SSMF.l/1000}km, t$)') + +plt.annotate(text='', xy=(r1_0,np.max(np.abs(E_Tx[0]['E'][0]))/2), xytext=(r2_0,np.max(np.abs(E_Tx[0]['E'][0]))/2), arrowprops=dict(arrowstyle='<->')) +plt.text(np.max((r2_0,r2_1))+10, np.max(np.abs(E_Tx[0]['E'][0]))/2, f'$T_{{FWHM,0}}$ = {r2_0-r1_0:.2f} ps', fontsize=12, horizontalalignment='left', verticalalignment='center') +plt.annotate(text='', xy=(r1_1,np.max(np.abs(E[0]['E'][0]))/2), xytext=(r2_1,np.max(np.abs(E[0]['E'][0]))/2), arrowprops=dict(arrowstyle='<->')) +plt.text(np.max((r2_0,r2_1))+10, np.max(np.abs(E[0]['E'][0]))/2, f'$T_{{FWHM,1}}$ = {r2_1-r1_1:.2f} ps', fontsize=12, horizontalalignment='left', verticalalignment='center') + +plt.ylabel('$|E|$ a.u.') +plt.xlabel('Time $t$ [ps]') +plt.grid() +legend = plt.legend(loc='upper right') +# Print the results +print(f'Input signal 1/e-pulse width by definition: T_0 = {T_0*1e12:.6f} ps') +print(f'Input signal 1/e-pulse width from plot: T_0 = {T_0_plot*1e12:.6f} ps') +print(f'Input signal FWHM-pulse width from plot: T_FWHM,0 = {T_FWHM_0*1e12:.6f} ps') +print(f'Output signal FWHM-pulse width from plot: T_FWHM,1 = {T_FWHM_1*1e12:.6f} ps') +print(f'Calculated output FWHM-pulse width: T_FWHM,1 = {T_FWHM_0 * np.sqrt(1 + (z/L_D)**2)*1e12:.6f} ps') + +plt.show() \ No newline at end of file