<jupyter_start><jupyter_text>Demonstration of deconvolving PAX dataFor details, see the manuscript<jupyter_code># Install pax_deconvolve (if not already installed)
#!pip install git+https://github.com/dhigley6/PAX2
# import standard python modules:
import numpy as np 
import matplotlib.pyplot as plt
%matplotlib inline
%load_ext tensorboard

# import custom python module for PAX deconvolution:
import pax_deconvolve

# set simulation parameters
LOG10_NUM_ELECTRONS = 5.0  # 10^5 detected electrons (over entire dateset)
RIXS_MODEL = 'schlappa'  # use RIXS model chosen to approximate that in Justine Schlappa et al.'s 2012 Nature paper
PHOTOEMISSION_MODEL = 'ag'   # use Ag 3d core levels as model photoemission
NUM_SIMULATIONS = 100    # Number of PAX spectra to simulate
ENERGY_LOSS = np.arange(-8, 10, 0.01)  # energy loss values of RIXS to simulate over
REGULARIZATION_STRENGTHS = np.logspace(-3, -1, 10)  # Regularization strengths to try
ITERATIONS = 100    # Number of iterations to run simulations for
CV_FOLD = 3   # Number of folds to use for cross validation
# Simulate some PAX data 
impulse_response, pax_spectra, xray_xy = pax_deconvolve.simulate_from_presets(
    LOG10_NUM_ELECTRONS,
    RIXS_MODEL,
    PHOTOEMISSION_MODEL,
    NUM_SIMULATIONS,
    ENERGY_LOSS
)
plt.figure()
plt.plot(xray_xy['x'], xray_xy['y'])
# Assess convergence of PAX data

# Run convergence assessment
pax_deconvolve.assess_convergence(
    impulse_response['x'],
    impulse_response['y'],
    pax_spectra['x'],
    pax_spectra['y'],
    REGULARIZATION_STRENGTHS,
    ITERATIONS
)

# Show data which can be used to assess convergence (see manuscript):
%tensorboard --logdir logdir
# Since this is simulated data, the deconvolved mean squared error is also shown,
# but that would usually not be accessible since the ground truth is usually
# unknown
# (note that, as currently implemented, one should delete the files in the log 
# directory between runs or they will plot on top of eachother)
#  Deconvolve PAX data, determining regulariation strength by cross validation of how well
#  we can estimate unseen data from the deconvolved result

# Run deconvolution
deconvolver = pax_deconvolve.LRFisterGrid(
        impulse_response['x'],
        impulse_response['y'],
        pax_spectra['x'],
        REGULARIZATION_STRENGTHS,
        ITERATIONS,
        xray_xy['y'],
        CV_FOLD
)
_ = deconvolver.fit(np.array(pax_spectra['y']))
# Plot results
pax_deconvolve.plot_photoemission(deconvolver)
pax_deconvolve.plot_result(deconvolver)
pax_deconvolve.plot_cv(deconvolver)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07387456714120816, 'fraction_numerical': 0.012697191227395151, 'mean_word_length': 4.764966740576496, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '634060', 'license': 'MIT', 'n_tokens_mistral': 912, 'n_tokens_neox': 841, 'n_words': 262, 'path': 'notebooks/demonstration.ipynb', 'repo_name': 'dhigley6/PAX2', 'size': '2599'}