<jupyter_start><jupyter_text>Comparing SDO/AIA Response Functions: SSW and SunPyThis notebook runs comparisons between the results of SSW and SunPy in calculating the wavelength and temperature response functions of the AIA instrument on board SDO.<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import sunpy.instr.aia
%matplotlib inline<jupyter_output><empty_output><jupyter_text>Wavelength Response First, load the SSW results into some convenient data structure.<jupyter_code>data = np.loadtxt('../aia_sample_data/aia_wresponse_raw.dat')
channels = [94,131,171,193,211,304,335]
ssw_results = {}
for i in range(len(channels)):
    ssw_results[channels[i]] = {'wavelength':data[:,0],
                                'response':data[:,i+1]}<jupyter_output><empty_output><jupyter_text>Run the SunPy calculation.<jupyter_code>response = sunpy.instr.aia.Response(path_to_genx_dir='../ssw_aia_response_data/')
response.calculate_wavelength_response()<jupyter_output><empty_output><jupyter_text>Plot the results against each other.<jupyter_code>fig,axes = plt.subplots(3,3,figsize=(12,12))
for c,ax in zip(channels,axes.flatten()):
    #ssw
    ax.plot(ssw_results[c]['wavelength'],ssw_results[c]['response'],
           color=response.channel_colors[c],label='ssw')
    #sunpy
    ax.plot(response.wavelength_response[c]['wavelength'],response.wavelength_response[c]['response'],
        color=response.channel_colors[c],marker='.',ms=12,label='SunPy')
    if c!=335 and c!=304:
        ax.set_xlim([c-20,c+20])
    ax.set_title('{} $\mathrm{{\mathring{{A}}}}$'.format(c),fontsize=20)
    ax.set_xlabel(r'$\lambda$ ({0:latex})'.format(response.wavelength_response[c]['wavelength'].unit),fontsize=20)
    ax.set_ylabel(r'$R_i(\lambda)$ ({0:latex})'.format(response.wavelength_response[c]['response'].unit),fontsize=20)
axes[0,0].legend(loc='best')
plt.tight_layout()<jupyter_output><empty_output><jupyter_text>Now, do a "residual plot" of the differences between the two results.<jupyter_code>fig,axes = plt.subplots(3,3,figsize=(12,12),sharey=True,sharex=True)
for c,ax in zip(channels,axes.flatten()):
    #ssw
    ax2 = ax.twinx()
    ssw_interp = ssw_results[c]['response']*response.wavelength_response[c]['response'].unit
    delta_response = np.fabs(response.wavelength_response[c]['response'] - ssw_interp)/(ssw_interp)
    ax.plot(response.wavelength_response[c]['wavelength'],delta_response,color=response.channel_colors[c])
    ax2.plot(response.wavelength_response[c]['wavelength'],response.wavelength_response[c]['response'],
            color='k',linestyle='--')
    ax.set_title('{} $\mathrm{{\mathring{{A}}}}$'.format(c),fontsize=20)
    ax.set_xlabel(r'$\lambda$ ({0:latex})'.format(response.wavelength_response[c]['wavelength'].unit),fontsize=20)
    ax.set_ylabel(r'$\frac{|\mathrm{SSW}-\mathrm{SunPy}|}{\mathrm{SSW}}$',fontsize=20)
    ax2.set_ylabel(r'$R_i(\lambda)$ ({0:latex})'.format(response.wavelength_response[c]['response'].unit))
    ax.set_ylim([-1.1,1.1])
plt.tight_layout()<jupyter_output><empty_output><jupyter_text>Now, zooming in on the two spikes in the 335 and 304 $\mathrm{\mathring{A}}$ channels...<jupyter_code>fig,axes = plt.subplots(1,2,figsize=(10,5))
for c,ax in zip([304,335],axes.flatten()):
    #ssw
    ax.plot(ssw_results[c]['wavelength'],ssw_results[c]['response'],
           color=response.channel_colors[c],label='ssw')
    #sunpy
    ax.plot(response.wavelength_response[c]['wavelength'],response.wavelength_response[c]['response'],
        color=response.channel_colors[c],marker='.',ms=12,label='SunPy')
    if c==304:
        ax.set_xlim([80,100])
    if c==335:
        ax.set_xlim([120,140])
    ax.set_title('{} $\mathrm{{\mathring{{A}}}}$'.format(c),fontsize=20)
    ax.set_xlabel(r'$\lambda$ ({0:latex})'.format(response.wavelength_response[c]['wavelength'].unit),fontsize=20)
    ax.set_ylabel(r'$R_i(\lambda)$ ({0:latex})'.format(response.wavelength_response[c]['response'].unit),fontsize=20)
axes[0].legend(loc='best')
plt.tight_layout()<jupyter_output><empty_output><jupyter_text>It looks like there is contamination from the 94 $\mathrm{\mathring{A}}$ channel in the 304 $\mathrm{\mathring{A}}$ channel and contamination from 131 $\mathrm{\mathring{A}}$ in the 335 $\mathrm{\mathring{A}}$ channel. Why? Is this a mistake or just something we haven't accounted for in the SunPy calculation?  Now what if we test using the pre-calculated effective area loaded from the SSW genx files?<jupyter_code>fig,axes = plt.subplots(1,2,figsize=(10,5))
for ax,c in zip(axes.flatten(),[304,335]):
    wvl_response = response._channel_info[c]['effective_area']*response._calculate_system_gain(c)
    ax.plot(response.wavelength_response[c]['wavelength'],
           wvl_response,'--',color=response.channel_colors[c],label=r'EA from SSW')
    ax.plot(response.wavelength_response[c]['wavelength'],
           response.wavelength_response[c]['response'],'.',ms=12,color=response.channel_colors[c],
           label=r'SunPy')
    if c==304:
        ax.set_xlim([80,100])
    if c==335:
        ax.set_xlim([120,140])
    ax.set_title('{} $\mathrm{{\mathring{{A}}}}$'.format(c),fontsize=20)
    ax.set_xlabel(r'$\lambda$ ({0:latex})'.format(response.wavelength_response[c]['wavelength'].unit),fontsize=20)
    ax.set_ylabel(r'$R_i(\lambda)$ ({0:latex})'.format(response.wavelength_response[c]['response'].unit),fontsize=20)
axes[0].legend(loc='best')
plt.tight_layout()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17933687488551017, 'fraction_numerical': 0.0304084997252244, 'mean_word_length': 6.348586810228802, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '545062', 'license': 'MIT', 'n_tokens_mistral': 2033, 'n_tokens_neox': 1907, 'n_words': 258, 'path': 'notebooks/response_function_comparison.ipynb', 'repo_name': 'wtbarnes/aia_response', 'size': '5459'}