Skip to content

Commit 1037d56

Browse files
authored
Beamprocess manual override (#106)
* Added BeamProcess Override * fixed some deprecated use of get_loc, append * documentation * github workflows * remove hdf5
1 parent 1c924c3 commit 1037d56

37 files changed

+210
-337
lines changed

.github/workflows/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ They are organised as follows.
66
### Documentation
77

88
The `documentation` workflow triggers on any push to master, builds the documentation and pushes it to the `gh-pages` branch (if the build is successful).
9-
It runs on `ubuntu-latest` and our lowest supported Python version, `Python 3.7`.
9+
It runs on `ubuntu-latest` and Python version, `Python 3.9`.
1010

1111
### Testing Suite
1212

1313
Tests are ensured in the `tests` workflow, which triggers on all pushes.
14-
It runs on a matrix of all supported operating systems (ubuntu-18.04, ubuntu-20.04, windows-latest and macos-latest) for all supported Python versions (currently `3.7`, `3.8`, `3.9` and `3.10`).
14+
It runs on a matrix of all supported operating systems (ubuntu-20.04, ubuntu-22.04, windows-latest and macos-latest) for all supported Python versions (currently `3.8`, `3.9` and `3.10`).
1515

1616
### Test Coverage
1717

1818
Test coverage is calculated in the `coverage` wokflow, which triggers on pushes to `master` and any push to a `pull request`.
19-
It runs on `ubuntu-latest` & the lowest supported Python version (`Python 3.7`), and reports the coverage results of the test suite to `CodeClimate`.
19+
It runs on `ubuntu-latest` & the Python version (`Python 3.9`), and reports the coverage results of the test suite to `CodeClimate`.
2020

2121
### Regular Testing
2222

2323
A `cron` workflow triggers every Monday at 3am (UTC time) and runs the full testing suite, on all available operating systems and supported Python versions.
24-
It also runs on `Python 3.x` so that newly released Python versions that would break tests are automatically included.
24+
It also runs on `Python 3.x` so that newly released Python versions that would break tests are automatically detected.
2525

2626
### Publishing
2727

.github/workflows/coverage.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ jobs:
1616
name: ${{ matrix.os }} / ${{ matrix.python-version }}
1717
runs-on: ${{ matrix.os }}
1818
strategy:
19-
matrix: # only lowest supported Python on latest ubuntu
19+
matrix:
2020
os: [ubuntu-latest]
21-
python-version: [3.7]
21+
python-version: [3.9]
2222

2323
steps:
2424
- uses: actions/checkout@v3

.github/workflows/cron.yml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,9 @@ jobs:
1515
runs-on: ${{ matrix.os }}
1616
strategy:
1717
matrix:
18-
os: [ubuntu-18.04, ubuntu-20.04, macos-latest, windows-latest]
18+
os: [ubuntu-20.04, ubuntu-22.04, macos-latest, windows-latest]
1919
# Make sure to escape 3.10 with quotes so it doesn't get interpreted as float 3.1 by GA's parser
20-
python-version: [3.7, 3.8, 3.9, "3.10", 3.x] # crons should always run latest python hence 3.x
21-
exclude:
22-
- os: windows-latest
23-
python-version: 3.10 # jpype1 doesn't build there
24-
# - os: macos-latest
25-
# python-version: 3.10 # jpype1 doesn't build there
26-
- os: windows-latest
27-
python-version: 3.10 # jpype1 doesn't build there
28-
# - os: macos-latest
29-
# python-version: 3.10 # jpype1 doesn't build there
20+
python-version: [3.8, 3.9, "3.10", "3.11", 3.x] # crons should always run latest python hence 3.x
3021

3122
steps:
3223
- uses: actions/checkout@v3

.github/workflows/documentation.yml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
# Build and publish documentation
1+
# Build documentation
2+
# The build is uploaded as artifact if the triggering event is a push for a pull request
3+
# The build is published to github pages if the triggering event is a push to the master branch (PR merge)
24
name: Build and upload documentation
35

46
defaults:
57
run:
68
shell: bash
79

8-
on: # Runs on any push event to master
10+
on: # Runs on any push event in a PR or any push event to master
11+
pull_request:
912
push:
1013
branches:
1114
- 'master'
@@ -15,9 +18,9 @@ jobs:
1518
name: ${{ matrix.os }} / ${{ matrix.python-version }}
1619
runs-on: ${{ matrix.os }}
1720
strategy:
18-
matrix: # only lowest supported Python on latest ubuntu
21+
matrix:
1922
os: [ubuntu-latest]
20-
python-version: [3.7]
23+
python-version: [3.9]
2124

2225
steps:
2326
- uses: actions/checkout@v3
@@ -42,10 +45,16 @@ jobs:
4245
- name: Build documentation
4346
run: python -m sphinx -b html doc ./doc_build -d ./doc_build
4447

48+
- name: Upload build artifacts # upload artifacts so reviewers can have a quick look without building documentation from the branch locally
49+
uses: actions/upload-artifact@v3
50+
if: success() && github.event_name == 'pull_request' # only for pushes in PR
51+
with:
52+
name: site-build
53+
path: doc_build
54+
retention-days: 5
55+
4556
- name: Upload documentation to gh-pages
46-
if: ${{ success() }}
47-
uses: JamesIves/github-pages-deploy-action@3.6.2
57+
if: success() && github.ref == 'refs/heads/master' # only for pushes to master
58+
uses: JamesIves/github-pages-deploy-action@v4
4859
with:
49-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50-
BRANCH: gh-pages
51-
FOLDER: doc_build
60+
folder: doc_build

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ jobs:
1414
name: ${{ matrix.os }} / ${{ matrix.python-version }}
1515
runs-on: ${{ matrix.os }}
1616
strategy:
17-
matrix: # only lowest supported Python on ubuntu-latest
17+
matrix:
1818
os: [ubuntu-latest]
19-
python-version: [3.7]
19+
python-version: [3.9]
2020

2121

2222
steps:

.github/workflows/tests.yml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,18 @@ defaults:
55
run:
66
shell: bash
77

8-
on: # Runs on all push events to any branch that isn't master
9-
push:
10-
branches-ignore:
11-
- 'master'
8+
on: [push] # Runs on all push events to any branch
9+
1210

1311
jobs:
1412
tests:
1513
name: ${{ matrix.os }} / ${{ matrix.python-version }}
1614
runs-on: ${{ matrix.os }}
1715
strategy:
1816
matrix:
19-
os: [ubuntu-18.04, ubuntu-20.04, macos-latest, windows-latest]
17+
os: [ubuntu-20.04, ubuntu-22.04, macos-latest, windows-latest]
2018
# Make sure to escape 3.10 with quotes so it doesn't get interpreted as float 3.1 by GA's parser
21-
python-version: [3.7, 3.8, 3.9, "3.10"]
22-
exclude:
23-
- os: windows-latest
24-
python-version: 3.10 # jpype1 doesn't build there
25-
# - os: macos-latest
26-
# python-version: 3.10 # jpype1 doesn't build there
19+
python-version: [3.8, 3.9, "3.10", "3.11"]
2720

2821
steps:
2922
- uses: actions/checkout@v3
@@ -46,4 +39,4 @@ jobs:
4639
run: python -m pip install '.[test]'
4740

4841
- name: Run basic tests
49-
run: python -m pytest -m "not cern_network" --mpl --cov-report xml --cov=pylhc
42+
run: python -m pytest -m "not cern_network" --mpl

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# pylhc Changelog
22

3+
## Version 0.8.0
4+
5+
Fixed:
6+
- replaced `get_loc` with `get_indexer` to be compatible with `pandas` > 2.0
7+
8+
Added:
9+
- `beamprocess` option to Machine Settings Info, to allow manual override.
10+
11+
Removed:
12+
- `hdf5` reader/writer for `tfs` as this is already in `tfs-pandas`
13+
314
## Version 0.7.4
415

516
Changes in Machine Settings Info

doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def about_package(init_posixpath: pathlib.Path) -> dict:
114114
#
115115
# This is also used if you do content translation via gettext catalogs.
116116
# Usually you set "language" from the command line for these cases.
117-
language = None
117+
language = "en"
118118

119119
# List of patterns, relative to source directory, that match files and
120120
# directories to ignore when looking for source files.

doc/entrypoints/analysis.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ Analysis Tools
33

44
.. automodule:: pylhc.bsrt_analysis
55
:members:
6+
:noindex:
67

78

89
.. automodule:: pylhc.forced_da_analysis
910
:members:
11+
:noindex:

doc/entrypoints/bpm_calibration.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ BPM Calibration
33

44
.. automodule:: pylhc.bpm_calibration
55
:members:
6+
:noindex:

doc/entrypoints/kickgroups.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ KickGroup Informations
33

44
.. automodule:: pylhc.kickgroups
55
:members:
6+
:noindex:

doc/entrypoints/lsa_to_madx.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ LSA Knobs to MAD-X Expressions Converter
33

44
.. automodule:: pylhc.lsa_to_madx
55
:members:
6+
:noindex:

doc/entrypoints/machine_info.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ Machine Information Tools
33

44
.. automodule:: pylhc.machine_settings_info
55
:members:
6+
:noindex:
67

78

89
.. automodule:: pylhc.bsrt_logger
910
:members:
11+
:noindex:
1012

doc/modules/calibration.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ BPM Calibration Utilities
33

44
.. automodule:: pylhc.calibration.beta
55
:members:
6+
:noindex:
67

78

89
.. automodule:: pylhc.calibration.dispersion
910
:members:
11+
:noindex:
1012

doc/modules/constants.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,24 @@ Constants Definitions
44

55
.. automodule:: pylhc.constants.general
66
:members:
7+
:noindex:
78

89

910
.. automodule:: pylhc.constants.forced_da_analysis
1011
:members:
12+
:noindex:
1113

1214

1315
.. automodule:: pylhc.constants.kickgroups
1416
:members:
17+
:noindex:
1518

1619

1720
.. automodule:: pylhc.constants.machine_settings_info
1821
:members:
22+
:noindex:
1923

2024

2125
.. automodule:: pylhc.constants.calibration
2226
:members:
27+
:noindex:

doc/modules/data_extract.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ Data Extraction
33

44
.. automodule:: pylhc.data_extract.lsa
55
:members:
6+
:noindex:
67

78

89
.. automodule:: pylhc.data_extract.timber
910
:members:
11+
:noindex:
1012

doc/modules/utils.rst

Lines changed: 0 additions & 5 deletions
This file was deleted.

pylhc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
__title__ = "pylhc"
1111
__description__ = "An accelerator physics script collection for the OMC team at CERN."
1212
__url__ = "https://github.com/pylhc/pylhc"
13-
__version__ = "0.7.4"
13+
__version__ = "0.8.0"
1414
__author__ = "pylhc"
1515
__author_email__ = "pylhc@github.com"
1616
__license__ = "MIT"

pylhc/bsrt_analysis.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@
2222
import pandas as pd
2323
import parse
2424
import pytz
25+
2526
import tfs
2627
from generic_parser import EntryPointParameters, entrypoint
2728
from omc3.utils import logging_tools, time_tools
28-
2929
from pylhc.constants.general import TFS_SUFFIX, TIME_COLUMN
30+
from pylhc.forced_da_analysis import get_approximate_index
3031

3132
LOG = logging_tools.get_logger(__name__)
3233
PLOT_FILE_SUFFIX = ".pdf"
@@ -150,7 +151,7 @@ def _select_files(opt, files_df):
150151
[opt["starttime"], opt["endtime"]], ["first_valid_index", "last_valid_index"]
151152
):
152153
indices.append(
153-
_get_closest_index(files_df, time if time is not None else getattr(files_df, fct)())
154+
get_approximate_index(files_df, time if time is not None else getattr(files_df, fct)())
154155
)
155156

156157
return files_df.iloc[indices[0] : indices[1] + 1]
@@ -178,10 +179,6 @@ def _load_files_in_df(opt):
178179
return files_df
179180

180181

181-
def _get_closest_index(df, time):
182-
return df.index.get_loc(time, method="nearest")
183-
184-
185182
def _get_timestamp_from_name(name, formatstring):
186183
year, month, day, hour, minute, second, microsecond = map(int, parse.parse(formatstring, name))
187184
return datetime.datetime(
@@ -203,12 +200,11 @@ def _load_pickled_data(opt, files_df):
203200
merged_df = pd.DataFrame()
204201
for bsrtfile in files_df["FILES"]:
205202
data = pickle.load(gzip.open(bsrtfile, "rb"))
206-
for entry in data:
207-
entry = _check_and_fix_entries(entry)
208-
merged_df = merged_df.append(entry, ignore_index=True)
203+
new_df = pd.DataFrame.from_records([_check_and_fix_entries(entry) for entry in data])
204+
merged_df = pd.concat([merged_df, new_df], axis="index", ignore_index=True)
209205

210206
merged_df = merged_df.set_index(
211-
pd.to_datetime(merged_df["acqTime"], format=BSRT_FESA_TIME_FORMAT)
207+
pd.to_datetime(merged_df["acqTime"], format=BSRT_FESA_TIME_FORMAT, utc=True)
212208
)
213209
merged_df.index.name = "TimeIndex"
214210
merged_df = merged_df.drop_duplicates(subset=["acqCounter", "acqTime"])
@@ -363,7 +359,7 @@ def plot_crosssection_for_timesteps(opt, bsrt_df):
363359
for idx, _ in kick_df.iterrows():
364360
timestamp = pd.to_datetime(time_tools.cern_utc_string_to_utc(idx))
365361

366-
data_row = bsrt_df.iloc[_get_closest_index(bsrt_df, timestamp)]
362+
data_row = bsrt_df.iloc[get_approximate_index(bsrt_df, timestamp)]
367363
fig, ax = plt.subplots(nrows=1, ncols=3, figsize=(18, 9), constrained_layout=True)
368364

369365
fig.suptitle(f"Timestamp: {timestamp}")

pylhc/calibration/beta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def _get_factors_from_phase_fit(
175175
if calibration_phase_fit is None:
176176
calibration_phase_fit = c_fit
177177
else:
178-
calibration_phase_fit = calibration_phase_fit.append(c_fit)
178+
calibration_phase_fit = pd.concat([calibration_phase_fit, c_fit], axis="index")
179179

180180
# Change the colum names for _fit
181181
calibration_phase_fit.columns = (LABELS[3], LABELS[4])

pylhc/calibration/dispersion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,6 @@ def get_calibration_factors_from_dispersion(
222222
if "X" not in calibration_factors.keys():
223223
calibration_factors = {"X": factors_for_ip}
224224
else:
225-
calibration_factors["X"] = calibration_factors["X"].append(factors_for_ip)
225+
calibration_factors["X"] = pd.concat([calibration_factors["X"], factors_for_ip], axis="index")
226226

227227
return calibration_factors

pylhc/data_extract/lsa.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ def get_trim_history(
203203
LOG.debug(f"{len(trims)} trims extracted.")
204204
trims_not_found = [k for k in knobs if k not in trims.keys()]
205205
if len(trims_not_found):
206-
LOG.warning(f"The following knobs were not found in '{beamprocess}': {trims_not_found}")
206+
LOG.warning(
207+
f"The following knobs were not found in '{beamprocess}' "
208+
f"or had no trims during the given time: {trims_not_found}")
207209
return trims
208210

209211
def get_beamprocess_info(self, beamprocess: Union[str, object]) -> Dict:

0 commit comments

Comments
 (0)