Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
example_tests:
name: Example tests
runs-on: ubuntu-latest
container: python:3.8.15
container: python:3.10
steps:
- name: Check out repository code
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ docs/_build
docs/*.rst
examples_for_ci.py
examples_output
replace_placeholders_in_md.py
replace_placeholders_in_md.py
23 changes: 23 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.6
hooks:
- id: ruff
args: [--fix]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.14.1
hooks:
- id: mypy
additional_dependencies:
- numpy
- types-tqdm
9 changes: 4 additions & 5 deletions cavity.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import numpy as np
import matplotlib.pyplot as plt

# from scipy import signal
from matplotlib import animation
import numpy as np

# import scipy.constants as con
from IPython.display import HTML

# from scipy import signal
from matplotlib import animation
from tqdm import tqdm

# import matplotlib.cm as cm
Expand All @@ -23,7 +23,6 @@ def resonator_modes(
spectrum_std=1000,
save_in="",
):

# length of the resonator
L = z.max() - z.min()
# calculate the frequency difference between two neighbouring modes of
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ librep
myst-parser~=0.17.0
pydata-sphinx-theme
sphinx-autoapi
Sphinx~=4.2.0
Sphinx~=4.2.0
8 changes: 3 additions & 5 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@

import os
import sys
import panim
from subprocess import run

import panim

sys.path.insert(0, os.path.abspath("."))
sys.path.insert(0, os.path.abspath("../../panim"))

Expand Down Expand Up @@ -74,10 +75,7 @@
run(command, capture_output=True, check=True).stdout.strip().decode("utf-8")
)

if "dev" in release:
version_match = "master"
else:
version_match = f"v{release}"
version_match = "master" if "dev" in release else f"v{release}"

html_theme = "pydata_sphinx_theme"
html_theme_options = {
Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ Indices and tables
* `Git repository <https://github.com/jobirk/panim>`_
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
* :ref:`search`
2 changes: 1 addition & 1 deletion docs/source/redirect_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
<meta http-equiv="refresh" content="0; url=./master/index.html">
<link rel="canonical" href="https://jobirk.github.io/panim/master/index.html">
</head>
</html>
</html>
9 changes: 5 additions & 4 deletions docs/sphinx_build_multiversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import os
from shutil import copy
from subprocess import run
import subprocess


def build_docs_version(version):
Expand Down Expand Up @@ -49,13 +48,15 @@ def build_docs_version(version):

def main():
"""main function that is executed when the script is called."""
with open("docs/source/_static/switcher.json", "r") as f: # pylint: disable=W1514
with open("docs/source/_static/switcher.json") as f: # pylint: disable=W1514
version_switcher = json.load(f)

# get currently active branch
command = "git rev-parse --abbrev-ref HEAD".split()
initial_branch = run(command, capture_output=True, check=True).stdout.strip().decode("utf-8")

initial_branch = (
run(command, capture_output=True, check=True).stdout.strip().decode("utf-8")
)

copy("docs/source/conf.py", "./conf_latest.py")

# build docs for main branch no matter what versions are present in the switcher
Expand Down
6 changes: 4 additions & 2 deletions examples/examples_components_demo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from panim import *
import os

import numpy as np

from panim import plot_pulses, sin_sum

z = np.linspace(-20, 200, 10000)
# +z_max=100 - nice settings to get three good pulses with stretching

Expand All @@ -28,7 +30,7 @@
0,
N_frequencies=4000,
nu_center=0.15,
k_i=(1, 3, 2),
k_i=[1, 3, 2],
spec_width=100,
plotting=True,
figuresize=(11, 1.2),
Expand Down
4 changes: 3 additions & 1 deletion examples/first_order_dispersion.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from panim import *
import os

import numpy as np

from panim import animate, calc_pulses

z = np.linspace(-20, 200, 10000)
os.makedirs("plots", exist_ok=True)

Expand Down
4 changes: 3 additions & 1 deletion examples/group_equal_phase.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from panim import *
import os

import numpy as np

from panim import animate, calc_pulses

z = np.linspace(-20, 200, 10000)
# +z_max=100 - nice settings to get three good pulses with stretching
os.makedirs("plots", exist_ok=True)
Expand Down
4 changes: 3 additions & 1 deletion examples/second_order_dispersion.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from panim import *
import os

import numpy as np

from panim import animate, calc_pulses

z = np.linspace(-20, 200, 10000)
os.makedirs("plots", exist_ok=True)

Expand Down
2 changes: 1 addition & 1 deletion examples/third_order_dispersion.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from panim import *
import os

import numpy as np

z = np.linspace(-20, 200, 10000)
Expand Down
44 changes: 30 additions & 14 deletions mode_locking.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from pulse_animation import *\n",
"%config InlineBackend.figure_format = 'retina'"
]
"source": "import numpy as np\n\nfrom cavity import animate_resonator\n\n%config InlineBackend.figure_format = 'retina'"
},
{
"cell_type": "code",
Expand Down Expand Up @@ -8613,18 +8610,17 @@
}
],
"source": [
"animate_resonator(np.linspace(0, 10, 100), np.linspace(0, 20, 400), n_modes=40, ms_between_frames=60)"
"animate_resonator(\n",
" np.linspace(0, 10, 100), np.linspace(0, 20, 400), n_modes=40, ms_between_frames=60\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from cavity import *\n",
"%config InlineBackend.figure_format = 'retina'"
]
"source": "import numpy as np\n\nfrom cavity import resonator_modes\n\n%config InlineBackend.figure_format = 'retina'"
},
{
"cell_type": "code",
Expand Down Expand Up @@ -8667,8 +8663,21 @@
}
],
"source": [
"d = resonator_modes(0.21, np.linspace(0, 1, 2000), 30, spectrum_std=1000, save_in=\"plots/mode_locking/locked_phase\")\n",
"b = resonator_modes(0.21, np.linspace(0, 1, 2000), 30, spectrum_std=1000, save_in=\"plots/mode_locking/random_phase\", random_phases=True)"
"d = resonator_modes(\n",
" 0.21,\n",
" np.linspace(0, 1, 2000),\n",
" 30,\n",
" spectrum_std=1000,\n",
" save_in=\"plots/mode_locking/locked_phase\",\n",
")\n",
"b = resonator_modes(\n",
" 0.21,\n",
" np.linspace(0, 1, 2000),\n",
" 30,\n",
" spectrum_std=1000,\n",
" save_in=\"plots/mode_locking/random_phase\",\n",
" random_phases=True,\n",
")"
]
},
{
Expand All @@ -8694,7 +8703,14 @@
}
],
"source": [
"b = resonator_modes(1, np.linspace(0, 1, 2000), 3, spectrum_std=1000, save_in=\"plots/mode_locking/resonator_3modes/illustration\", random_phases=True)"
"b = resonator_modes(\n",
" 1,\n",
" np.linspace(0, 1, 2000),\n",
" 3,\n",
" spectrum_std=1000,\n",
" save_in=\"plots/mode_locking/resonator_3modes/illustration\",\n",
" random_phases=True,\n",
")"
]
},
{
Expand Down
4 changes: 3 additions & 1 deletion optical_fibre.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from pulse_animation import *
import matplotlib
import numpy as np

from panim import animate_with_time, calc_pulses

matplotlib.rcParams.update({"font.size": 13})

Expand Down
38 changes: 23 additions & 15 deletions panim/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import numpy as np
import os

import matplotlib.pyplot as plt
from scipy import signal
from matplotlib import animation
import numpy as np

# import scipy.constants as con
from IPython.display import HTML
from matplotlib import animation
from scipy.signal import windows
from tqdm import tqdm
import os

__version__ = "0.1.1dev"

Expand Down Expand Up @@ -52,7 +53,7 @@ def sin_sum(
nu_min: float = 0.001,
N_frequencies: int = 4000,
spec_width: float = 200,
k_i: list = [1, 5, 0],
k_i: list | None = None,
plotting: bool = False,
z_arrow: bool = False,
figuresize: tuple = (11, 4),
Expand Down Expand Up @@ -108,11 +109,13 @@ def sin_sum(
E-field amplitude along the z-axis at time t.

"""
if k_i is None:
k_i = [1, 5, 0]

# create array of frequency spectrum and the corresponding weight
# i.e. how much the given frequency contributes
frequencies = np.linspace(nu_min, nu_center * 2, N_frequencies)
spectrum = signal.gaussian(len(frequencies), std=spec_width)
spectrum = windows.gaussian(len(frequencies), std=spec_width)

# create array for spectral components
E_field_spec_components = np.zeros([len(frequencies), len(z)])
Expand Down Expand Up @@ -141,12 +144,11 @@ def sin_sum(
2 * np.pi * frequencies[i] * t - phi_nu
)

if plotting:
if frequencies[i] in plotting_frequencies:
ax.plot(
z, E_field_spec_components[i], label=frequencies[i]
) # , color=colors[n_plotted])
n_plotted += 1
if plotting and frequencies[i] in plotting_frequencies:
ax.plot(
z, E_field_spec_components[i], label=frequencies[i]
) # , color=colors[n_plotted])
n_plotted += 1

# Calculate the total E-field as the sum over all spectral components
E_field = E_field_spec_components.sum(axis=0)
Expand Down Expand Up @@ -186,7 +188,7 @@ def sin_sum(
return E_field


def calc_pulses(z, t_start, t_end, n_steps, nu_center=1, k_i=[1, 5, 0], spec_width=100):
def calc_pulses(z, t_start, t_end, n_steps, nu_center=1, k_i=None, spec_width=100):
"""Calculates the spatial form of the pulse at different times

Parameters
Expand Down Expand Up @@ -220,6 +222,8 @@ def calc_pulses(z, t_start, t_end, n_steps, nu_center=1, k_i=[1, 5, 0], spec_wid
the wave at all time steps.

"""
if k_i is None:
k_i = [1, 5, 0]

times = np.linspace(t_start, t_end, n_steps)
pulses = np.zeros([n_steps, len(z)])
Expand Down Expand Up @@ -425,14 +429,14 @@ def plot_pulses(
z,
times,
nu_center=0.5,
k_i=[1, 10, 0],
k_i=None,
spec_width=400,
no_axes=False,
plotname="",
dpi=100,
figuresize=(11, 4),
z_arrow=False,
colors=["steelblue" for i in range(10)],
colors=None,
):
"""Plots the pulse at different times

Expand Down Expand Up @@ -474,6 +478,10 @@ def plot_pulses(
time steps are plotted with the standard python 'steelblue'.

"""
if k_i is None:
k_i = [1, 10, 0]
if colors is None:
colors = ["steelblue" for _ in range(10)]

pulses = [
sin_sum(z, t, nu_center=nu_center, k_i=k_i, spec_width=spec_width)
Expand Down
Loading