-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve cpymadtools.ptc module functionality (#46)
Docstrings now detail inner workings and parameters used for functions in cpymadtools.ptc. Both functions now have a fringe argument and transmit kwargs to either ptc_normal or ptc_twiss depending on which is used. Adds a cpymadtools.utils module with convenient functionality to export an internal MAD-X table
- Loading branch information
Showing
6 changed files
with
97 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
""" | ||
Module cpymadtools.utils | ||
------------------------ | ||
Created on 2021.07.22 | ||
:author: Felix Soubelet (felix.soubelet@cern.ch) | ||
A module with utility functions to do mundane operatiions with `cpymad.madx.Madx` objects. | ||
""" | ||
import tfs | ||
|
||
from cpymad.madx import Madx | ||
from loguru import logger | ||
|
||
|
||
def get_table_tfs(madx: Madx, table_name: str) -> tfs.TfsDataFrame: | ||
""" | ||
Turns an internal table from the `MAD-X` process into a `TfsDataFrame` object. | ||
Args: | ||
madx (cpymad.madx.Madx): an instanciated cpymad Madx object. | ||
table_name (str): the name of the internal table. | ||
Returns: | ||
A `TfsDataFrame` object with the table data, and the `SUMM` table as headers. | ||
""" | ||
logger.debug(f"Extracting table {table_name} into a TfsDataFrame") | ||
dframe = tfs.TfsDataFrame(madx.table[table_name].dframe()) | ||
dframe.columns = dframe.columns.str.upper() | ||
|
||
if "NAME" in dframe.columns: | ||
logger.trace("Uppercasing 'NAME' column contents") | ||
dframe.NAME = dframe.NAME.str.upper() | ||
|
||
logger.trace("Turning SUMM table into headers") | ||
dframe.headers = {var.upper(): madx.table.summ[var][0] for var in madx.table.summ} | ||
return dframe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters