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
4 changes: 2 additions & 2 deletions .github/actions/install_requirements/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ runs:
shell: bash

- name: Upload lockfiles
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: lockfiles
name: lockfiles_${{ github.job }}_${{ matrix.python }}
path: lockfiles

# This eliminates the class of problems where the requirements being given no
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
fail-fast: false
matrix:
os: ["ubuntu-latest"] # can add windows-latest, macos-latest
python: ["3.7", "3.9", "3.10"]
python: ["3.9", "3.10"]
install: ["-e .[dev]"]
# Make one version be non-editable to test both paths of version code
include:
Expand Down Expand Up @@ -88,9 +88,9 @@ jobs:
pipx run build

- name: Upload sdist and wheel as artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: dist
name: dist_${{ github.job }}_${{ matrix.python }}
path: dist

- name: Check for packaging errors
Expand Down Expand Up @@ -124,7 +124,7 @@ jobs:
run: echo IMAGE_REPOSITORY=ghcr.io/$(tr '[:upper:]' '[:lower:]' <<< "${{ github.repository }}") >> $GITHUB_ENV

- name: Download wheel and lockfiles
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
path: artifacts/

Expand Down Expand Up @@ -153,7 +153,7 @@ jobs:
uses: docker/build-push-action@v3
with:
build-args: |
PIP_OPTIONS=-r lockfiles/requirements.txt dist/*.whl
PIP_OPTIONS=-r lockfiles_dist_/requirements.txt dist_dist_/*.whl
push: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }}
load: ${{ ! (github.event_name == 'push' && startsWith(github.ref, 'refs/tags')) }}
tags: ${{ steps.meta.outputs.tags }}
Expand All @@ -177,11 +177,11 @@ jobs:
HAS_PYPI_TOKEN: ${{ secrets.PYPI_TOKEN != '' }}

steps:
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4

- name: Fixup blank lockfiles
# Github release artifacts can't be blank
run: for f in lockfiles/*; do [ -s $f ] || echo '# No requirements' >> $f; done
run: for f in lockfiles_dist_/*; do [ -s $f ] || echo '# No requirements' >> $f; done

- name: Github Release
# We pin to the SHA, not the tag, for security reasons.
Expand All @@ -190,8 +190,8 @@ jobs:
with:
prerelease: ${{ contains(github.ref_name, 'a') || contains(github.ref_name, 'b') || contains(github.ref_name, 'rc') }}
files: |
dist/*
lockfiles/*
dist_dist_/*
lockfiles_dist_/*
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion src/pytac/data/DIAD/simple_devices.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
el_id,field,value,readonly
0,energy,3000000000,True
0,energy,3000,True
2 changes: 1 addition & 1 deletion src/pytac/data/DIAD/uc_poly_data.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
uc_id,coeff,val
1,0,0.000000
1,1,1e-06
1,1,1e06
2,0,0.000000
2,1,1e-09
3,0,0.000000
Expand Down
2 changes: 1 addition & 1 deletion src/pytac/data/DIAD/unitconv.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ el_id,field,uc_type,uc_id,phys_units,eng_units,lower_lim,upper_lim
0,dispersion,null,0,m,m,,
0,beam_current,null,0,A,A,,
1492,f,null,0,Hz,Hz,,
0,energy,poly,1,Gev,Mev,,
0,energy,poly,1,eV,MeV,,
0,emittance_x,poly,2,m,nm,,
0,emittance_y,poly,3,m,pm,,
5,b1,pchip,4,m^-2,A,0,200
Expand Down
2 changes: 1 addition & 1 deletion src/pytac/data/DIADSP/simple_devices.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
el_id,field,value,readonly
0,energy,3000000000,True
0,energy,3000,True
2 changes: 1 addition & 1 deletion src/pytac/data/DIADSP/uc_poly_data.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
uc_id,coeff,val
1,0,0.000000
1,1,1e-06
1,1,1e06
2,0,0.000000
2,1,1e-09
3,0,0.000000
Expand Down
2 changes: 1 addition & 1 deletion src/pytac/data/DIADSP/unitconv.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ el_id,field,uc_type,uc_id,phys_units,eng_units,lower_lim,upper_lim
0,dispersion,null,0,m,m,,
0,beam_current,null,0,A,A,,
1492,f,null,0,Hz,Hz,,
0,energy,poly,1,Gev,Mev,,
0,energy,poly,1,eV,MeV,,
0,emittance_x,poly,2,m,nm,,
0,emittance_y,poly,3,m,pm,,
5,b1,pchip,4,m^-2,A,0,200
Expand Down
2 changes: 1 addition & 1 deletion src/pytac/data/DIADTHz/simple_devices.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
el_id,field,value,readonly
0,energy,3000000000,True
0,energy,3000,True
2 changes: 1 addition & 1 deletion src/pytac/data/DIADTHz/uc_poly_data.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
uc_id,coeff,val
1,0,0.000000
1,1,1e-06
1,1,1e06
2,0,0.000000
2,1,1e-09
3,0,0.000000
Expand Down
2 changes: 1 addition & 1 deletion src/pytac/data/DIADTHz/unitconv.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ el_id,field,uc_type,uc_id,phys_units,eng_units,lower_lim,upper_lim
0,dispersion,null,0,m,m,,
0,beam_current,null,0,A,A,,
1492,f,null,0,Hz,Hz,,
0,energy,poly,1,Gev,Mev,,
0,energy,poly,1,eV,MeV,,
0,emittance_x,poly,2,m,nm,,
0,emittance_y,poly,3,m,pm,,
5,b1,pchip,4,m^-2,A,0,200
Expand Down
2 changes: 1 addition & 1 deletion src/pytac/data/I04/simple_devices.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
el_id,field,value,readonly
0,energy,3000000000,True
0,energy,3000,True
2 changes: 1 addition & 1 deletion src/pytac/data/I04/uc_poly_data.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
uc_id,coeff,val
1,0,0.000000
1,1,1e-06
1,1,1e06
2,0,0.000000
2,1,1e-09
3,0,0.000000
Expand Down
2 changes: 1 addition & 1 deletion src/pytac/data/I04/unitconv.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ el_id,field,uc_type,uc_id,phys_units,eng_units,lower_lim,upper_lim
0,dispersion,null,0,m,m,,
0,beam_current,null,0,A,A,,
1510,f,null,0,Hz,Hz,,
0,energy,poly,1,Gev,Mev,,
0,energy,poly,1,eV,MeV,,
0,emittance_x,poly,2,m,nm,,
0,emittance_y,poly,3,m,pm,,
5,b1,pchip,4,m^-2,A,0,200
Expand Down
2 changes: 1 addition & 1 deletion src/pytac/data/I04SP/simple_devices.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
el_id,field,value,readonly
0,energy,3000000000,True
0,energy,3000,True
2 changes: 1 addition & 1 deletion src/pytac/data/I04SP/uc_poly_data.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
uc_id,coeff,val
1,0,0.000000
1,1,1e-06
1,1,1e06
2,0,0.000000
2,1,1e-09
3,0,0.000000
Expand Down
2 changes: 1 addition & 1 deletion src/pytac/data/I04SP/unitconv.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ el_id,field,uc_type,uc_id,phys_units,eng_units,lower_lim,upper_lim
0,dispersion,null,0,m,m,,
0,beam_current,null,0,A,A,,
1510,f,null,0,Hz,Hz,,
0,energy,poly,1,Gev,Mev,,
0,energy,poly,1,eV,MeV,,
0,emittance_x,poly,2,m,nm,,
0,emittance_y,poly,3,m,pm,,
5,b1,pchip,4,m^-2,A,0,200
Expand Down
2 changes: 1 addition & 1 deletion src/pytac/data/I04THz/simple_devices.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
el_id,field,value,readonly
0,energy,3000000000,True
0,energy,3000,True
2 changes: 1 addition & 1 deletion src/pytac/data/I04THz/uc_poly_data.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
uc_id,coeff,val
1,0,0.000000
1,1,1e-06
1,1,1e06
2,0,0.000000
2,1,1e-09
3,0,0.000000
Expand Down
2 changes: 1 addition & 1 deletion src/pytac/data/I04THz/unitconv.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ el_id,field,uc_type,uc_id,phys_units,eng_units,lower_lim,upper_lim
0,dispersion,null,0,m,m,,
0,beam_current,null,0,A,A,,
1510,f,null,0,Hz,Hz,,
0,energy,poly,1,Gev,Mev,,
0,energy,poly,1,eV,MeV,,
0,emittance_x,poly,2,m,nm,,
0,emittance_y,poly,3,m,pm,,
5,b1,pchip,4,m^-2,A,0,200
Expand Down
2 changes: 1 addition & 1 deletion src/pytac/data/SRI0913_MOGA/simple_devices.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
el_id,field,value,readonly
0,energy,3000000000,True
0,energy,3000,True
2 changes: 1 addition & 1 deletion src/pytac/data/SRI0913_MOGA/uc_poly_data.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
uc_id,coeff,val
1,0,0.000000
1,1,1e-06
1,1,1e06
2,0,0.000000
2,1,1e-09
3,0,0.000000
Expand Down
2 changes: 1 addition & 1 deletion src/pytac/data/SRI0913_MOGA/unitconv.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ el_id,field,uc_type,uc_id,phys_units,eng_units,lower_lim,upper_lim
0,dispersion,null,0,m,m,,
0,beam_current,null,0,A,A,,
1492,f,null,0,Hz,Hz,,
0,energy,poly,1,Gev,Mev,,
0,energy,poly,1,eV,MeV,,
0,emittance_x,poly,2,m,nm,,
0,emittance_y,poly,3,m,pm,,
5,b1,pchip,4,m^-2,A,0,200
Expand Down
2 changes: 1 addition & 1 deletion src/pytac/data/VMX/simple_devices.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
el_id,field,value,readonly
0,energy,3000000000,True
0,energy,3000,True
2 changes: 1 addition & 1 deletion src/pytac/data/VMX/uc_poly_data.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
uc_id,coeff,val
1,0,0.000000
1,1,1e-06
1,1,1e06
2,0,0.000000
2,1,1e-09
3,0,0.000000
Expand Down
2 changes: 1 addition & 1 deletion src/pytac/data/VMX/unitconv.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ el_id,field,uc_type,uc_id,phys_units,eng_units,lower_lim,upper_lim
0,dispersion,null,0,m,m,,
0,beam_current,null,0,A,A,,
1490,f,null,0,Hz,Hz,,
0,energy,poly,1,Gev,Mev,,
0,energy,poly,1,eV,MeV,,
0,emittance_x,poly,2,m,nm,,
0,emittance_y,poly,3,m,pm,,
5,b1,pchip,4,m^-2,A,0,200
Expand Down
2 changes: 1 addition & 1 deletion src/pytac/data/VMXSP/simple_devices.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
el_id,field,value,readonly
0,energy,3000000000,True
0,energy,3000,True
2 changes: 1 addition & 1 deletion src/pytac/data/VMXSP/uc_poly_data.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
uc_id,coeff,val
1,0,0.000000
1,1,1e-06
1,1,1e06
2,0,0.000000
2,1,1e-09
3,0,0.000000
Expand Down
2 changes: 1 addition & 1 deletion src/pytac/data/VMXSP/unitconv.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ el_id,field,uc_type,uc_id,phys_units,eng_units,lower_lim,upper_lim
0,dispersion,null,0,m,m,,
0,beam_current,null,0,A,A,,
1490,f,null,0,Hz,Hz,,
0,energy,poly,1,Gev,Mev,,
0,energy,poly,1,eV,MeV,,
0,emittance_x,poly,2,m,nm,,
0,emittance_y,poly,3,m,pm,,
5,b1,pchip,4,m^-2,A,0,200
Expand Down
2 changes: 1 addition & 1 deletion src/pytac/data/VMXTHz/simple_devices.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
el_id,field,value,readonly
0,energy,3000000000,True
0,energy,3000,True
2 changes: 1 addition & 1 deletion src/pytac/data/VMXTHz/uc_poly_data.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
uc_id,coeff,val
1,0,0.000000
1,1,1e-06
1,1,1e06
2,0,0.000000
2,1,1e-09
3,0,0.000000
Expand Down
2 changes: 1 addition & 1 deletion src/pytac/data/VMXTHz/unitconv.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ el_id,field,uc_type,uc_id,phys_units,eng_units,lower_lim,upper_lim
0,dispersion,null,0,m,m,,
0,beam_current,null,0,A,A,,
1490,f,null,0,Hz,Hz,,
0,energy,poly,1,Gev,Mev,,
0,energy,poly,1,eV,MeV,,
0,emittance_x,poly,2,m,nm,,
0,emittance_y,poly,3,m,pm,,
5,b1,pchip,4,m^-2,A,0,200
Expand Down
2 changes: 1 addition & 1 deletion src/pytac/data/utils/load_mml.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function load_mml(ringmode)
ao = getao();

% Hard-coded beam energy value.
fprintf(f_simple_devices, '0,energy,3e9,True\n');
fprintf(f_simple_devices, '0,energy,3000,True\n');

% The individual BPM PVs are not stored in middlelayer.
BPMS = get_bpm_pvs(ao);
Expand Down
4 changes: 2 additions & 2 deletions src/pytac/data/utils/load_unitconv.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ function load_unitconv(ringmode, renamedIndexes)
% Unit conversions for lattice fields
% the conversion limits are '' as these fields don't have a Setpoint field
uc_id = uc_id + 1;
fprintf(f_units, '%d,%s,poly,%d,%s,%s,%s,%s\n', 0, 'energy', uc_id, 'Gev', 'Mev', '', '');
fprintf(f_units, '%d,%s,poly,%d,%s,%s,%s,%s\n', 0, 'energy', uc_id, 'eV', 'MeV', '', '');
fprintf(f_poly, '%d,%d,%f\n', uc_id, 0, 0);
fprintf(f_poly, '%d,%d,%g\n', uc_id, 1, 1e-6);
fprintf(f_poly, '%d,%d,%g\n', uc_id, 1, 1e6);
uc_id = uc_id + 1;
fprintf(f_units, '%d,%s,poly,%d,%s,%s,%s,%s\n', 0, 'emittance_x', uc_id, 'm', 'nm', '', '');
fprintf(f_poly, '%d,%d,%f\n', uc_id, 0, 0);
Expand Down
2 changes: 1 addition & 1 deletion src/pytac/lattice.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Representation of a lattice object which contains all the elements of the
machine.
machine.
"""

import logging
Expand Down
37 changes: 35 additions & 2 deletions src/pytac/load_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
import copy
import csv
import logging
import os
from pathlib import Path
from typing import Dict, Iterator
from typing import Dict, Iterator, Set

import pytac
from pytac import data_source, element, utils
Expand Down Expand Up @@ -166,7 +167,7 @@ def load_unitconv(mode_dir: Path, lattice: Lattice) -> None:
# TODO: This should probably be moved into the .csv files somewhere.
rigidity_families = {"hstr", "vstr", "quadrupole", "sextupole", "bend"}
if item["uc_type"] != "null" and element._families & rigidity_families:
energy = lattice.get_value("energy", units=pytac.PHYS)
energy = lattice.get_value("energy", units=pytac.ENG)
uc.set_post_eng_to_phys(utils.get_div_rigidity(energy))
uc.set_pre_phys_to_eng(utils.get_mult_rigidity(energy))
element.set_unitconv(item["field"], uc)
Expand Down Expand Up @@ -263,3 +264,35 @@ def load(mode, control_system=None, directory=None, symmetry=None) -> EpicsLatti
if unitconv_file.exists():
load_unitconv(mode_dir, lat)
return lat


def available_ringmodes(directory=None) -> Set[str]:
"""Return the possible ringmodes based on the subdirectories and files in
the given directory.

.. Note:: It is not guaranteed that the modes returned will be able to be
successfully loaded due to errors, missing data, etc. I.e., any mode
that can be loaded will always be returned, but modes that can't be
loaded might also sometimes be returned.

Args:
directory (str): The data directory to check inside. If no directory
is given the default data directory location is used.

Returns:
set[str]: A set of possible ringmodes.

Raises:
OSError: if no ringmodes can be found in the specified directory.
"""
if directory is None:
directory = Path(__file__).resolve().parent / "data"
modes = set()
for directory_object in os.scandir(directory):
if directory_object.is_dir():
contents = os.listdir(directory_object.path)
if ELEMENTS_FILENAME in contents and FAMILIES_FILENAME in contents:
modes.add(directory_object.name)
if not modes:
raise OSError(f"No ringmodes found in {os.path.realpath(directory)}")
return modes
Loading