{ "info": { "author": "Dominik Vilsmeier", "author_email": "d.vilsmeier@gsi.de", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3 :: Only", "Topic :: Scientific/Engineering :: Physics", "Topic :: Scientific/Engineering :: Visualization" ], "description": "madplot\n=======\n\nThis project aims to facilitate working with MADX from within Python. It contains the following\nmajor components:\n\n* **MADX API**: Build, parse and run MADX scripts.\n* **Plot API**: Plot MADX output in various formats.\n* **Utilities**: For example convert MADX output tables to pandas data frames.\n\n\nMADX API\n--------\n\nThe MADX API consists of three parts: *building*, *parsing* and *running* MADX scripts.\n\n\nBuilder\n```````\n\nThe builder API can be used for creating MADX scripts. The following example code shows the\nvarious features.\n\n.. code-block:: python\n\n from madplot.madx.builder import Script\n\n # At first generate a new script.\n s = Script()\n\n # Labeled or declaration statements can be created via `[]` access.\n # This produces the following statement in the resulting MADX script:\n # L = 5;\n # N = 10;\n s['L'] = 5\n s['N'] = 10\n\n # MADX commands can be created by accessing them through the script instance.\n # Output: `DP: SBEND, L = L/2, ANGLE = 2*PI/(2*N);`.\n s['DP'] = s.SBEND(L='L/2', ANGLE='2*PI/(2*N)')\n\n # Output: `QF: MULTIPOLE, KNL = {0, 1/f};`.\n s['QF'] = s.MULTIPOLE(KNL=[0, '1/f'])\n\n # Sequences can be generated using the `Sequence` class.\n from madplot.madx.builder import Sequence\n\n with Sequence(refer='entry', l='N*L') as seq:\n for n in range(s.N): # Python loop over number of cells.\n # Unlabeled statements can be just added the script instance.\n # Stored element definitions can be reused via attribute access of the script instance.\n # This produces the following output: `QF, at = 0 * L;`.\n seq += s.QF(at=f'{n} * L')\n\n # [...] Add more elements.\n\n # Adding a sequence to the script will auto-expand it when dumping the script.\n # This produces the following output:\n # `LATTICE: sequence, refer = entry, l = N*L;`\n # ` QF, at = 0 * L;`\n # ` [...]`\n # `endsequence;`\n s['LATTICE'] = seq\n\n # A script can be dumped by converting to `str`.\n with open('example.seq', 'w') as f:\n f.write(str(s))\n\nComplete code example\n~~~~~~~~~~~~~~~~~~~~~\n\nThe following is a complete code example.\n\n.. code-block:: python\n\n from madplot.madx.builder import Sequence, Script\n\n s = Script()\n\n s['N_cells'] = 60\n s['L_cell'] = 13.45\n s['f'] = 7.570366\n\n s['DP'] = s.SBEND(L='L_cell/2', ANGLE='2*PI / (2*N_cells)')\n s['QF'] = s.MULTIPOLE(KNL=['0', '1/f'])\n s['QD'] = s.MULTIPOLE(KNL=['0', '-1/f'])\n\n with Sequence(refer='entry', l='N_cells*L_cell') as seq:\n for n in range(s.N_cells):\n seq += s.QF(at=f'{n} * L_cell')\n seq += s.DP(at=f'{n} * L_cell')\n seq += s.QD(at=f'{n} * L_cell + 0.50 * L_cell')\n seq += s.DP(at=f'{n} * L_cell + 0.50 * L_cell')\n\n s['FODO_LATTICE'] = seq\n\n with open('example.seq', 'w') as f:\n f.write(str(s))\n\nAdvanced control\n~~~~~~~~~~~~~~~~\n\nThe following operations allow for advanced control statements.\n\n* Comments can be placed as strings: ``s += '// Comment'``.\n* Re-evaluated (deferred) expressions (`:=`) can be created via the ``E`` class: ``from madplot.madx.builder import E; s += s.ealign(dx=E('ranf()'))``.\n* Any MADX command can be accessed via the script instance: ``s += s.TWISS(file='optics')``.\n\n\nParser\n``````\n\nThe ``parser.Parser`` class has two methods available:\n\n* ``Parser.raw_parse``: This method parses the given script into its statements and returns a list thereof. The different statement types can be found in ``Parser._types``. The literal values of command attributes will be returned.\n* ``Parser.parse``: Parses the script into its statements as well but only returns non-comment non-variable declaration statements and interpolates any command attribute values.\n\nFor example:\n\n.. code-block:: python\n\n >>> madx = '''\n ... L = 5;\n ... QF: QUADRUPOLE, k1 := pi/5, l = L;\n ... '''\n >>> Parser.raw_parse(madx)\n [[Variable] L = 5, [Command] QF: QUADRUPOLE {'k1': 'pi/5', 'l': 'L'}]\n >>> Parser.parse(madx)\n [[Command] QF: QUADRUPOLE {'k1': 0.6283185307179586, 'l': 5}]\n\n\nEngine\n``````\n\nThe MADX Engine API can be used to run MADX scripts. The `MADXEngine` class expects a set of templates\nwhich will be used to run the script. A template is a MADX script that contains unfilled parts which\ncan be interpolated later on. The first template is considered the entry point (the main script) and will be run.\n\nThe following code creates an engine:\n\n.. code-block:: python\n\n from madplot.madx.engine import MADXEngine\n\n engine = MADXEngine(\n ['test.madx', 'test.seq'], # Template files; `test.madx` is the main script.\n madx='/opt/madx', # File path to the MADX executable; if not specifed the `MADX` environment variable will be considered.\n working_directory='/tmp/test' # The directory in which the engine runs the scripts.\n )\n\nThe templates can contain substitutions following the Python string formatting rules.\nFor example: ``QF: QUADRUPOLE, KL={kl};``. The ``{kl}`` part can be interpolated when running the scripts.\n\nThe ``run`` method can be invoked to run a script. It expects a list of output file names (which need to be\ngenerated by the template scripts). By default the file contents will be returned as ``pandas.DataFrame``\ninstances.\n\n.. code-block:: python\n\n twiss, = engine.run(['example.twiss'])\n\nHere the file ``example.twiss`` needs to be generated when running ``test.madx``.\nIn case one or more template scripts require interpolation the corresponding values can be specified\nusing the `configuration` keyword argument:\n\n.. code-block:: python\n\n twiss, = engine.run(\n ['example.twiss'],\n configuration={'test.madx': {'kl': 0.01}}\n )\n\nSpecial arguments for the output conversion can be specified per output in form of a ``dict``:\n\n.. code-block:: python\n\n (twiss, meta), = engine.run([('example.twiss', {'return_meta': True}])\n\nThis will return meta data (prefixed with `@` in the TFS output) along the main data frame.\n\n\nSessions\n~~~~~~~~\n\nThe ``MADXSession`` can be used to run interactive MADX sessions. This is advantageous to avoid rerunning parts of\na script that are the same for each run (e.g. sequence structure); also it doesn't require starting a new process for\neach run. Instead one can only issue the relevant commands (e.g. update an optics parameter) and then\nask for the results (e.g. Twiss file generation). For example:\n\n.. code-block:: python\n\n from madplot.madx.engine import MADXSession\n\n with open('/tmp/log', 'w') as log:\n session = MADXSession(stderr=log, stdout=log)\n session.run(['a := ranf()'])\n session.run(['value a'] * 3)\n\n # Running a script at start-up.\n session = MADXSession(['twiss_script.madx'])\n twiss, = session.run(results=['example.twiss'])\n # Update a parameter and regenerate twiss.\n twiss, = session.run(['some_parameter = 0', 'twiss, file=\"example.twiss\"'],\n results=['example.twiss'])\n\n\n\nPlotting\n--------\n\nVarious functions for plotting are available in the ``madplot.plot`` module. Please refer directly\nto this module for further information.\n\n\nUtilities\n---------\n\nUtilities for conversion of data formats are available at ``madplot.utils``:\n\n* ``Convert.tfs``: Converts TFS file to pandas data frame,\n* ``Convert.trackone``: Converts trackone table (as outputted by ``TRACK, onetable = true``) to pandas data frame.\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://gitlab.com/Dominik1123/madplot", "keywords": "MAD,MADX,accelerator,design,interface,plot,simulation,visualization", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "madplot", "package_url": "https://pypi.org/project/madplot/", "platform": "", "project_url": "https://pypi.org/project/madplot/", "project_urls": { "Homepage": "https://gitlab.com/Dominik1123/madplot" }, "release_url": "https://pypi.org/project/madplot/0.2.5/", "requires_dist": [ "matplotlib", "numpy", "pandas", "scipy" ], "requires_python": ">=3.6", "summary": "Plot MAD output (and more).", "version": "0.2.5" }, "last_serial": 5207543, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "d16801ecb8b3b1d6b77134f5b1d8a344", "sha256": "7382aba170f2fa8d9bc7e10c72a5d74a93f2a08ec21f8f23c3843109191f02db" }, "downloads": -1, "filename": "madplot-0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "d16801ecb8b3b1d6b77134f5b1d8a344", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 13657, "upload_time": "2018-12-17T09:18:17", "url": "https://files.pythonhosted.org/packages/e0/24/a89eec22391b9b7eee41e9632baca2cdf9c51f911c0ffd540f09b0a302a9/madplot-0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "72c0b05a1a76e9bc9d2df893fd546d4c", "sha256": "82ad9e7d38b845df4e8fa371197d13d2b02bb888e17979777aa0d4cf96b8fca8" }, "downloads": -1, "filename": "madplot-0.1.tar.gz", "has_sig": false, "md5_digest": "72c0b05a1a76e9bc9d2df893fd546d4c", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 14030, "upload_time": "2018-12-17T09:18:25", "url": "https://files.pythonhosted.org/packages/6b/a0/def8f1fde6bfcdb7ebcfd78ab8cb1276f1bf45cb9492a6da7c3474f1aabb/madplot-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "196fc6642e23d60ad2fe28e69c3fc1df", "sha256": "b329efeedab0dbfe9766501932c2dc12ce0b2d51466a436eb174a9d3c0adbca7" }, "downloads": -1, "filename": "madplot-0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "196fc6642e23d60ad2fe28e69c3fc1df", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 14569, "upload_time": "2019-01-11T12:01:44", "url": "https://files.pythonhosted.org/packages/39/08/29718deef4a1321e0f7338791f60e92f13d5cfa57988a2b2714ef0f9b0de/madplot-0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "00543f8b96cb3ad85c12d4c9a5f0597b", "sha256": "19ab90478b9dbd1cd579588a4dad043cdcb7dbd53f6827d41694eed81a77b7d8" }, "downloads": -1, "filename": "madplot-0.2.tar.gz", "has_sig": false, "md5_digest": "00543f8b96cb3ad85c12d4c9a5f0597b", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 14876, "upload_time": "2019-01-11T12:01:50", "url": "https://files.pythonhosted.org/packages/ad/76/ad418d5f4844a267a373d987e25aafc620256b97ae78727190da537cf1bd/madplot-0.2.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "c4700bd87f167921d1f9d5d1b142ee0b", "sha256": "e147504967420ed3e38cd6b59982239022b3608dadf2f1d226c44c363a2b15e7" }, "downloads": -1, "filename": "madplot-0.2.1-py3-none-any.whl", "has_sig": false, "md5_digest": "c4700bd87f167921d1f9d5d1b142ee0b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 15206, "upload_time": "2019-03-23T12:36:07", "url": "https://files.pythonhosted.org/packages/15/d5/87847d3cf9c3508222f1f4ac2b383ecd9851cff4fc038c6d7959e8b1b571/madplot-0.2.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "afb9c8ada74ff4515ff768b672766b22", "sha256": "69e816b32f655444310a34060484f48b2d5f9cb232d2e976ed1e5e362994f2f2" }, "downloads": -1, "filename": "madplot-0.2.1.tar.gz", "has_sig": false, "md5_digest": "afb9c8ada74ff4515ff768b672766b22", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 15448, "upload_time": "2019-03-23T12:36:08", "url": "https://files.pythonhosted.org/packages/c1/a8/b97616cd8ce5ad0806f7e62f1221d77451f5871870b346149e9bc3c2bef4/madplot-0.2.1.tar.gz" } ], "0.2.2": [ { "comment_text": "", "digests": { "md5": "8da3f1f9d1c465ed11e00b220d0c427a", "sha256": "8d7c65a172c1973276d57f8e4d4b1fa0c2bf7895e51c04f23bba6e50062db0bd" }, "downloads": -1, "filename": "madplot-0.2.2-py3-none-any.whl", "has_sig": false, "md5_digest": "8da3f1f9d1c465ed11e00b220d0c427a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 15536, "upload_time": "2019-04-29T01:16:45", "url": "https://files.pythonhosted.org/packages/5d/c2/9c69f14e832bee714886884b71552f39f017c9ff0e61bcaef78ec235c9fb/madplot-0.2.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6fb3b73b9b76a29490a300e868334880", "sha256": "9065790442e104b3049668e6dff0f882fadb4e0a5bda2f812ed65296b5e5a78b" }, "downloads": -1, "filename": "madplot-0.2.2.tar.gz", "has_sig": false, "md5_digest": "6fb3b73b9b76a29490a300e868334880", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 15734, "upload_time": "2019-04-29T01:16:52", "url": "https://files.pythonhosted.org/packages/78/49/0c9fdc23757314fced33870179e4eff33a7fc6fef3c4586fb3ca365ff57b/madplot-0.2.2.tar.gz" } ], "0.2.3": [ { "comment_text": "", "digests": { "md5": "5dce784784f2b547771765a3b0e1ac4b", "sha256": "db26c16c8f31c62639d0b799ddb86cd54e8d4adf01e391f88f7abe29e6540723" }, "downloads": -1, "filename": "madplot-0.2.3-py3-none-any.whl", "has_sig": false, "md5_digest": "5dce784784f2b547771765a3b0e1ac4b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 15847, "upload_time": "2019-04-29T02:04:03", "url": "https://files.pythonhosted.org/packages/a1/ee/bce3ff45db826ba3133d7aa4b436dfb95eafaeca6d832da8f2803e50f5ea/madplot-0.2.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "1d866460a9830f744338489519551bda", "sha256": "4ab20b500f76d82d6d5e8bf3353eac66cd5816534b894895ab56a377288c97a1" }, "downloads": -1, "filename": "madplot-0.2.3.tar.gz", "has_sig": false, "md5_digest": "1d866460a9830f744338489519551bda", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 16055, "upload_time": "2019-04-29T02:04:06", "url": "https://files.pythonhosted.org/packages/74/04/43d837aa0eba998e57467686307fb5670906ac793772d37523c844d0fd3a/madplot-0.2.3.tar.gz" } ], "0.2.4": [ { "comment_text": "", "digests": { "md5": "cee82f1b9c6c835ca8a65b72019c38f7", "sha256": "1d5270cd74839b31de52fd0a45f31878eb620f87fc1a34f61b17ea286dc2f60f" }, "downloads": -1, "filename": "madplot-0.2.4-py3-none-any.whl", "has_sig": false, "md5_digest": "cee82f1b9c6c835ca8a65b72019c38f7", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 16737, "upload_time": "2019-04-30T00:40:17", "url": "https://files.pythonhosted.org/packages/33/9a/fed83283a4a06dd915b18353346ae6cf53acf930a6d17504c535fe5561f9/madplot-0.2.4-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "46581e33a31c4662d06a5328bdd5141b", "sha256": "05c84cfced55ccbf33c219f3f8dfa55315ae83789ed1592101f1a307a030f725" }, "downloads": -1, "filename": "madplot-0.2.4.tar.gz", "has_sig": false, "md5_digest": "46581e33a31c4662d06a5328bdd5141b", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 17315, "upload_time": "2019-04-30T00:40:22", "url": "https://files.pythonhosted.org/packages/a1/8f/9d2e46d2e8895671dca4c6e2db7f3f5db926b5c7d226154d793311819b23/madplot-0.2.4.tar.gz" } ], "0.2.5": [ { "comment_text": "", "digests": { "md5": "ce957938d66f51339468263ab2b8e704", "sha256": "44700cee361e108aa3ec78bed3deb90cb2829ea18e1b9231f465ebe955a45748" }, "downloads": -1, "filename": "madplot-0.2.5-py3-none-any.whl", "has_sig": false, "md5_digest": "ce957938d66f51339468263ab2b8e704", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 16922, "upload_time": "2019-04-30T10:10:43", "url": "https://files.pythonhosted.org/packages/60/bd/9f16f10a24ab6b9dd65b3669bfe6f316369d4a20aa01ad8a8d8d431b6626/madplot-0.2.5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "76f6a186ac9a6206b4f1216d04006443", "sha256": "15c1adf6ec27e830a0745e07f7245f1802f64149c07acbd53d791426b22fecd2" }, "downloads": -1, "filename": "madplot-0.2.5.tar.gz", "has_sig": false, "md5_digest": "76f6a186ac9a6206b4f1216d04006443", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 17517, "upload_time": "2019-04-30T10:10:50", "url": "https://files.pythonhosted.org/packages/e5/c8/ded469b49416a74e82eb17c7d5a20f2ca8c5acf2df3c81c8dd69602c0459/madplot-0.2.5.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "ce957938d66f51339468263ab2b8e704", "sha256": "44700cee361e108aa3ec78bed3deb90cb2829ea18e1b9231f465ebe955a45748" }, "downloads": -1, "filename": "madplot-0.2.5-py3-none-any.whl", "has_sig": false, "md5_digest": "ce957938d66f51339468263ab2b8e704", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6", "size": 16922, "upload_time": "2019-04-30T10:10:43", "url": "https://files.pythonhosted.org/packages/60/bd/9f16f10a24ab6b9dd65b3669bfe6f316369d4a20aa01ad8a8d8d431b6626/madplot-0.2.5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "76f6a186ac9a6206b4f1216d04006443", "sha256": "15c1adf6ec27e830a0745e07f7245f1802f64149c07acbd53d791426b22fecd2" }, "downloads": -1, "filename": "madplot-0.2.5.tar.gz", "has_sig": false, "md5_digest": "76f6a186ac9a6206b4f1216d04006443", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6", "size": 17517, "upload_time": "2019-04-30T10:10:50", "url": "https://files.pythonhosted.org/packages/e5/c8/ded469b49416a74e82eb17c7d5a20f2ca8c5acf2df3c81c8dd69602c0459/madplot-0.2.5.tar.gz" } ] }