<jupyter_start><jupyter_text>BASIC composite merging tutorial In this quick tutorial we'll load in some composite time-series, pass them through the BASIC algorithm, yielding a "super-merged" composite Start by importing required libraries<jupyter_code>import matplotlib.pyplot as plt
import numpy as np
import netCDF4
import basic<jupyter_output><empty_output><jupyter_text>Let's import some composites to run the BASIC merging algorithm on...<jupyter_code># Import the data
data = netCDF4.Dataset('data/hmc_2016_lotus_seascyc_sgo3_fac2.nc')
T = data["time"][:]
P = data["pressure"][:]
L = data["latitude"][:]

# Which pressure and latitude index do you want to analyze?
pressure = 22
latitude = 8

# List of data vectors for input to HMC
d = [data['comp_mean'][latitude, pressure, :, 0], data['comp_mean'][latitude, pressure, :, 1]]

# Let's plot the data to see how it looks

# Plot the selected data and error bars
plt.title('Pressure {:.2f} hPa; Latitude {:+.0f} deg'.format(P[pressure], L[latitude]))
plt.plot(T, data['comp_mean'][latitude, pressure, :, 0], color = 'red', alpha=0.5)
plt.plot(T, data['comp_mean'][latitude, pressure, :, 1], color = 'green', alpha=0.5)
plt.xlabel('time, T [Julian date]')
plt.ylabel(r'$O_3$ [ppm]')
plt.show()<jupyter_output><empty_output><jupyter_text>Now we need to construct the seasonal transition prior and SVD errors NB to Will: do your stuff here re SVD and transition priors, we need to read in an array of where to puff up the errors, right? And declare a constant for what factor to puff them up by? NB to Will: once you've written code to do the SVD errors and transition priors here, I'll put it all inside the function `run_basic_sampler()` below so the whole code is literally just one function and none of your stuff will appear "on the outside"<jupyter_code># Construct seasonal cycle prior
transition_prior = [data["anncyc_mean"][latitude, pressure, :], data["anncyc_std"][latitude, pressure, :]]

# Construct SVD errors
s = [data['comp_std'][latitude, pressure, :, 0], data['comp_std'][latitude, pressure, :, 1]]<jupyter_output><empty_output><jupyter_text>Run the HMC sampler NB to Will: once the SVD and transition prior construction bits are done, this will be the ONLY function that gets executed: it will take in the composites, an array of where to puff up the error bars and then do everything in one go<jupyter_code># Run the HMC sampler
samples = basic.run_basic_sampler(d, s, transition_prior, gamma=100, beta=0.5)
# Let's plot the output (posterior mean and standard deviation)

# Posterior mean and std-deviation
mean = np.mean(samples, axis=0)
std = np.std(samples, axis=0)

# Plot the mean and std-dev
plt.title('Pressure {:.2f} hPa; Latitude {:+.0f} deg'.format(P[pressure], L[latitude]))
plt.xlabel('time, T [Julian date]')
plt.ylabel(r'$O_3$ [ppm]')
plt.plot(T, np.mean(samples, axis=0))
plt.fill_between(T, mean - std, mean + std, color = 'grey', alpha = 0.5)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12138533960995293, 'fraction_numerical': 0.012441156691324815, 'mean_word_length': 5.854838709677419, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '275595', 'license': 'MIT', 'n_tokens_mistral': 1037, 'n_tokens_neox': 969, 'n_words': 355, 'path': 'BASIC_tutorial.ipynb', 'repo_name': 'justinalsing/basic', 'size': '2974'}