{"id":29017846,"url":"https://github.com/danporter/xmcd_analysis_example","last_synced_at":"2025-10-13T08:39:48.627Z","repository":{"id":300166799,"uuid":"1005233544","full_name":"DanPorter/xmcd_analysis_example","owner":"DanPorter","description":"Example data analysis of xas spectra from beamline i06 at Diamond Light Source.","archived":false,"fork":false,"pushed_at":"2025-06-20T07:01:56.000Z","size":540,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-06-20T07:46:26.679Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DanPorter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-19T22:40:36.000Z","updated_at":"2025-06-20T07:02:00.000Z","dependencies_parsed_at":"2025-06-20T07:56:32.978Z","dependency_job_id":null,"html_url":"https://github.com/DanPorter/xmcd_analysis_example","commit_stats":null,"previous_names":["danporter/xmcd_analysis_example"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/DanPorter/xmcd_analysis_example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanPorter%2Fxmcd_analysis_example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanPorter%2Fxmcd_analysis_example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanPorter%2Fxmcd_analysis_example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanPorter%2Fxmcd_analysis_example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DanPorter","download_url":"https://codeload.github.com/DanPorter/xmcd_analysis_example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DanPorter%2Fxmcd_analysis_example/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261967132,"owners_count":23237663,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-25T23:07:14.668Z","updated_at":"2025-10-13T08:39:48.607Z","avatar_url":"https://github.com/DanPorter.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# xmcd_analysis_example\nExample data analysis of xas spectra from Diamond Light Source.\n\nIncludes generation of NeXus files with approximately the NXxas application definition,\nwhere each file contains multiple channels (TEY, TFY) and multiple processing steps.\nExample data is provided for the Fe-L3,2 edge in multiple sets of circular polarised \nXAS spectra from beamline i06-1. These spectra are processed to calculate the XMCD spectra.\n\n - Author: Dan Porter\n - Diamond Light Source Ltd\n - 2025\n\n### Methodology\nScan files from a Synchrotron X-Ray beamline (I06-1 @ Diamond Light Source) are given in the data folder.\nEach file is a fast, sweeping energy scan across the Fe L3,2 edge. The different files are for repeated\ncircular-right (CR) and circular-left (CL) polarisations (note the absolute direction is not known). \n\nEach scan file contains both electron-yield (TEY) and and fluorescence-yield (TFY) channels.\n\nThe code uses pythonic scan and spectra object models to make the analysis clearer (I hope!).\n\n#### Channel Processing steps\n\nFor each channel, the following steps are performed:\n - normalise signal by monitor\n - normalise signal by flat pre-edge signal\n - fit a generic background (see below) including a step-edge for each absorption edge\n - subtract the background and normalise by the step height.\n\n#### Averaging and Subtraction\nCombining the background-subtracted channels from each scan:\n - interpolate the energy steps to provide consistent spectra\n - average the signals of the scans for each polarisation and channel\n - subtract the averaged signal CR - CL to calculate the XMCD\n - Integrate the XMCD spectra to determine the sum rules.\n\n#### Background subtraction\nVarious background options are possible and several options are included in the code. \nThe examples use an automatic fitted background composed of step models and a polynomial:\n\n##### background = \n - Step_1[cen=L3, wid=1-3eV, height=2/3 step height] + \n - Step_2[cen=L2, wid=Step_1, height=1/3 step height] + \n - Poly[order 3]\n\nThe step edges are initially chosen by looking for typical L-edges in the energy window.\n\nMore information about the background subtraction options is available in [xmcd_analysis_functions/spectra_analysis.py](xmcd_analysis_functions/spectra_analysis.py)\n\n### Examples\nThe [xmcd_analysis_example.py](xmcd_analysis_example.py) script uses a suite of functions to generate the NXxas-like NeXus files and the final XMCD file.\n\nThe [xmcd_analysis_example.ipynb](xmcd_analysis_example.ipynb) jupyter notebook provides \nfurther explanation of the analysis steps and the Spectra object model used.\n\nNote, all NeXus file links in the README can be clicked on to be viewed online using [myHDF5](https://myhdf5.hdfgroup.org/).\n\n\n### NeXus Files\nXAS energy scans converted into NeXus file with ~NXxas application definition.\nEvery scan measures both TEY and TFY channels, however the default mode is chosen as TFY.\nEach scan has several processing steps. Each processing step is provided as an NXnote in the NXprocessing group, \nand has an associated NXdata containing the signal and background for both channels.\n\n| Polarisation | Original Scan   | Converted Scan                                                                                                                                                                             |\n|--------------|-----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| CR           | data/236463.dat | [236463_nxxas.nxs](https://myhdf5.hdfgroup.org/view?url=https%3A%2F%2Fgithub.com%2FDanPorter%2Fxmcd_analysis_example%2Fblob%2F69a249b1bd51acb50412176e0512806be91b15f0%2F236463_nxxas.nxs) |\n| CL           | data/236464.dat | [236464_nxxas.nxs](https://myhdf5.hdfgroup.org/view?url=https%3A%2F%2Fgithub.com%2FDanPorter%2Fxmcd_analysis_example%2Fblob%2F69a249b1bd51acb50412176e0512806be91b15f0%2F236464_nxxas.nxs) |\n| CL           | data/236465.dat | [236465_nxxas.nxs](https://myhdf5.hdfgroup.org/view?url=https%3A%2F%2Fgithub.com%2FDanPorter%2Fxmcd_analysis_example%2Fblob%2F69a249b1bd51acb50412176e0512806be91b15f0%2F236465_nxxas.nxs) |\n| CR           | data/236466.dat | [236466_nxxas.nxs](https://myhdf5.hdfgroup.org/view?url=https%3A%2F%2Fgithub.com%2FDanPorter%2Fxmcd_analysis_example%2Fblob%2F69a249b1bd51acb50412176e0512806be91b15f0%2F236466_nxxas.nxs) |\n| CR           | data/236467.dat | [236467_nxxas.nxs](https://myhdf5.hdfgroup.org/view?url=https%3A%2F%2Fgithub.com%2FDanPorter%2Fxmcd_analysis_example%2Fblob%2F69a249b1bd51acb50412176e0512806be91b15f0%2F236467_nxxas.nxs) |\n| CL           | data/236468.dat | [236468_nxxas.nxs](https://myhdf5.hdfgroup.org/view?url=https%3A%2F%2Fgithub.com%2FDanPorter%2Fxmcd_analysis_example%2Fblob%2F69a249b1bd51acb50412176e0512806be91b15f0%2F236468_nxxas.nxs) |\n| CL           | data/236469.dat | [236469_nxxas.nxs](https://myhdf5.hdfgroup.org/view?url=https%3A%2F%2Fgithub.com%2FDanPorter%2Fxmcd_analysis_example%2Fblob%2F69a249b1bd51acb50412176e0512806be91b15f0%2F236469_nxxas.nxs) |\n| CR           | data/236470.dat | [236470_nxxas.nxs](https://myhdf5.hdfgroup.org/view?url=https%3A%2F%2Fgithub.com%2FDanPorter%2Fxmcd_analysis_example%2Fblob%2F69a249b1bd51acb50412176e0512806be91b15f0%2F236470_nxxas.nxs) |\n\nEach polarisation is measured 4 times. The background-subtracted spectra are averaged for each polarisation\nand subtracted to provide the XMCD spectra, stored in a separate file. \nThis NeXus file follows a similar structure to the NXxas files above, but also contains an NXnote in NXprocessing \ngiving the integrated XMCD sum rules. \nPlease note the methodology used for the sum rules here is not very accurate and needs refining.\n\n - [236464_nxxas.nxs](https://myhdf5.hdfgroup.org/view?url=https%3A%2F%2Fgithub.com%2FDanPorter%2Fxmcd_analysis_example%2Fblob%2F69a249b1bd51acb50412176e0512806be91b15f0%2Fxmcd.nxs)\n\n### New NeXus Files (2025+)\nAn example of the new nexus files written directly from GDA on the beamline is provided, along with the processed\nversion. The new nexus files contain additional metadata and also contain a NXsubentry (`/entry/xas_entry`)\nwith application definition *NXxas*. These files trigger an autoprocessing ipython notebook that generates\nthe processed files and calculates XMCD. An example notebook is provided: [i10-1-37439_xas_notebook.ipynb](i10-1-37439_xas_notebook.ipynb).\n\n| Filename                                                                                                                                                                         | Description                            | \n|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------|\n| [data/i10-1-37436.nxs](https://myhdf5.hdfgroup.org/view?url=https%3A%2F%2Fgithub.com%2FDanPorter%2Fxmcd_analysis_example%2Fblob%2Fmaster%2Fdata%2Fi10-1-37436.nxs)               | RAW experiment data, CR polarisation   |\n| [i10-1-37436_xas_notebook.nxs](https://myhdf5.hdfgroup.org/view?url=https%3A%2F%2Fgithub.com%2FDanPorter%2Fxmcd_analysis_example%2Fblob%2Fmaster%2Fi10-1-37436_xas_notebook.nxs) | Processed data, CR polarisation        |\n| [data/i10-1-37439.nxs](https://myhdf5.hdfgroup.org/view?url=https%3A%2F%2Fgithub.com%2FDanPorter%2Fxmcd_analysis_example%2Fblob%2Fmaster%2Fdata%2Fi10-1-37439.nxs)               | RAW experiment data, CL polarisation   |\n| [i10-1-37439_xas_notebook.nxs](https://myhdf5.hdfgroup.org/view?url=https%3A%2F%2Fgithub.com%2FDanPorter%2Fxmcd_analysis_example%2Fblob%2Fmaster%2Fi10-1-37439_xas_notebook.nxs) | Processed data, CL polarisation        |\n| [37436-37439_xmcd.nxs](https://myhdf5.hdfgroup.org/view?url=https%3A%2F%2Fgithub.com%2FDanPorter%2Fxmcd_analysis_example%2Fblob%2Fmaster%2F37436-37439_xmcd.nxs)                 | Processed subtraction of polarisations |\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanporter%2Fxmcd_analysis_example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanporter%2Fxmcd_analysis_example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanporter%2Fxmcd_analysis_example/lists"}