Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# optics_functions

[![Cron Testing](https://github.com/pylhc/optics_functions/workflows/Cron%20Testing/badge.svg)](https://github.com/pylhc/optics_functions/actions?query=workflow%3A%22Cron+Testing%22)
[![Code Climate coverage](https://img.shields.io/codeclimate/coverage/pylhc/optics_functions.svg?style=popout)](https://codeclimate.com/github/pylhc/optics_functions)
[![Code Climate maintainability (percentage)](https://img.shields.io/codeclimate/maintainability-percentage/pylhc/optics_functions.svg?style=popout)](https://codeclimate.com/github/pylhc/optics_functions)
[![Tests](https://github.com/pylhc/optics_functions/actions/workflows/coverage.yml/badge.svg?branch=master)](https://github.com/pylhc/optics_functions/actions/workflows/coverage.yml)
[![GitHub last commit](https://img.shields.io/github/last-commit/pylhc/optics_functions.svg?style=popout)](https://github.com/pylhc/optics_functions)
<!-- [![GitHub release](https://img.shields.io/github/release/pylhc/optics_functions.svg?style=popout)](https://github.com/pylhc/optics_functions) -->
[![PyPI Version](https://img.shields.io/pypi/v/optics_functions?label=PyPI&logo=pypi)](https://pypi.org/project/optics_functions/)
[![GitHub release](https://img.shields.io/github/v/release/pylhc/optics_functions?logo=github)](https://github.com/pylhc/optics_functions/)
[![Conda-forge Version](https://img.shields.io/conda/vn/conda-forge/optics_functions?color=orange&logo=anaconda)](https://anaconda.org/conda-forge/optics_functions)
Expand All @@ -18,11 +15,13 @@ See the [API documentation](https://pylhc.github.io/optics_functions/) for detai
## Installing

Installation is easily done via `pip`:

```bash
python -m pip install optics_functions
```

One can also install in a `conda` environment via the `conda-forge` channel with:

```bash
conda install -c conda-forge optics_functions
```
Expand All @@ -32,7 +31,7 @@ conda install -c conda-forge optics_functions
> **Warning:** In certain scenarios, e.g. in case of non-zero closed orbit, the `RDT` calculations can be unreliable for **thick** lattices.
> Convert to a _thin_ lattice by slicing the lattice to reduce the error of the analytical approximation.
#### Coupling Example:
### Coupling Example

```python
import logging
Expand All @@ -52,7 +51,7 @@ df_twiss = tfs.read("twiss.tfs", index="NAME")
df_coupling = coupling_via_cmatrix(df_twiss)

# Example:
# print(df_coupling)
# print(df_coupling)
#
# F1001 F1010 ... C22 GAMMA
# NAME ...
Expand All @@ -75,7 +74,7 @@ df_dqmin = closest_tune_approach(
)

# Example:
# print(df_dqmin)
# print(df_dqmin)
#
# DELTAQMIN
# NAME
Expand All @@ -95,7 +94,7 @@ df_dqmin = closest_tune_approach(
# (...)

# write out
# as the writer can only handle real data,
# as the writer can only handle real data,
# you need to split the rdts into real and imaginary parts before writing
tfs.write(
"coupling.tfs",
Expand All @@ -104,7 +103,7 @@ tfs.write(
)
```

#### RDT Example:
### RDT Example

```python
import logging
Expand All @@ -123,7 +122,7 @@ df_twiss = tfs.read("twiss.tfs", index="NAME")
# generate all valid RDT names, here for RDTs of order 2
rdts = [jklm2str(*jklm) for jklm in generator(orders=[2])[2]]

# check correct signs (i.e if beam==4), merge twiss and errors,
# check correct signs (i.e if beam==4), merge twiss and errors,
# add empty K(S)L columns if needed
df_twiss = prepare_twiss_dataframe(df_twiss=df_twiss, df_errors=None, max_order=5)

Expand All @@ -136,8 +135,8 @@ df_rdts = calculate_rdts(
complex_columns=True, # complex output
)

# Example:
# print(df_rdts)
# Example:
# print(df_rdts)
# F0002 ... F2000
# NAME ...
# IP3 2.673376-1.045712j ... -2.863617-0.789910j
Expand All @@ -156,7 +155,7 @@ df_rdts = calculate_rdts(
# (...)

# write out
# as the writer can only handle real data, either set real = True above
# as the writer can only handle real data, either set real = True above
# or split the rdts into real and imaginary parts before writing
tfs.write(
"rdts.tfs",
Expand All @@ -165,7 +164,7 @@ tfs.write(
)
```

#### Appending Example:
### Appending Example

```python
import logging
Expand All @@ -187,7 +186,7 @@ df_twiss[["F1001", "F1010"]] = coupling_via_cmatrix(df_twiss, output=['rdts'])

# Example:
# print(df_twiss)
#
#
# Headers:
# NAME: TWISS
# TYPE: TWISS
Expand All @@ -196,7 +195,7 @@ df_twiss[["F1001", "F1010"]] = coupling_via_cmatrix(df_twiss, output=['rdts'])
# ORIGIN: 5.05.02 Linux 64
# DATE: 01/02/21
# TIME: 19.58.08
#
#
# KEYWORD S ... F1001 F1010
# NAME ...
# IP3 MARKER 0.0000 ... -0.000000+0.000004j -0.004026+0.003574j
Expand All @@ -211,14 +210,15 @@ df_twiss[["F1001", "F1010"]] = coupling_via_cmatrix(df_twiss, output=['rdts'])
# BPMW.4L3.B1 MONITOR 26636.4387 ... -0.000000+0.000004j -0.004831+0.002376j
# MCBWH.4L3.B1 HKICKER 26641.0332 ... -0.000000+0.000004j -0.004691+0.002641j
```
### Modules

## Modules

- `coupling` - Functions to estimate coupling from twiss dataframes and
different methods to calculate the closest tune approach from
the calculated coupling RDTs.
([**coupling.py**](optics_functions/coupling.py), [**doc**](https://pylhc.github.io/optics_functions/modules/coupling.html))
- `rdt` - Functions for the calculations of Resonance Driving Terms, as well as
getting lists of valid driving term indices for certain orders.
getting lists of valid driving term indices for certain orders.
([**rdt.py**](optics_functions/rdt.py), [**doc**](https://pylhc.github.io/optics_functions/modules/rdt.html))
- `utils` - Helper functions to prepare the twiss dataframes for use with the optics
functions as well as reusable utilities,
Expand Down
2 changes: 1 addition & 1 deletion optics_functions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
__title__ = "optics_functions"
__description__ = "Calculate optics parameters from TWISS outputs."
__url__ = "https://github.com/pylhc/optics_functions"
__version__ = "0.1.4"
__version__ = "0.1.5"
__author__ = "pylhc"
__author_email__ = "[email protected]"
__license__ = "MIT"
Expand Down
18 changes: 16 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ authors = [
]
license = "MIT"
dynamic = ["version"]
requires-python = ">=3.9"
requires-python = ">=3.10"

classifiers = [
"Development Status :: 5 - Production/Stable",
Expand All @@ -33,10 +33,11 @@ classifiers = [
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.9",
"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",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Scientific/Engineering",
"Topic :: Software Development :: Libraries :: Python Modules",
Expand Down Expand Up @@ -77,10 +78,23 @@ markers = [
"basic: basic tests run for every commit",
"extended: test run on PRs",
]

addopts = [
"--import-mode=importlib",
]

# Helpful for pytest-debugging (leave commented out on commit):
# log_cli=true
# log_level=DEBUG

[tool.coverage.run]
relative_files = true

[tool.coverage.report]
exclude_also = [
"if TYPE_CHECKING:", # do not count if TYPE_CHECKING block imports (ignored at runtime) for coverage
"except ImportError:", # do not count missing optional dependencies set to None, we monkeypatch and test that
]

# ----- Dev Tools Configuration ----- #

Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_coupling.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import pytest
import tfs
from pandas.testing import assert_frame_equal
from test_rdt import arrays_are_close_almost_everywhere

from optics_functions.constants import (
ALPHA,
Expand All @@ -32,6 +31,8 @@
)
from optics_functions.utils import prepare_twiss_dataframe

from .test_rdt import arrays_are_close_almost_everywhere

INPUT = Path(__file__).parent.parent / "inputs"
COUPLING_BUMP_INPUTS = INPUT / "coupling_bump"
COUPLING_BUMP_TWISS_BEAM_1 = COUPLING_BUMP_INPUTS / "twiss.lhc.b1.coupling_bump.tfs"
Expand Down
Loading