<jupyter_start><jupyter_text>Demo 3b: Compute on Horizontal Sections<jupyter_code>%matplotlib inline

# Import OceanSpy
import oceanspy as ospy

# Additional packages
import matplotlib.pyplot as plt
import numpy             as np

# Import the OceanDataset
od = ospy.open_oceandataset.get_started()

# For this notebook we will focus on one snapshot in the top 100m of the water column
clean_od = od.subsample.cutout(ZRange=[0, -100], timeRange='2007-09-01', dropAxes=['time'])<jupyter_output>Opening [Getting Started with OceanSpy]:
[A small cutout from EGshelfIIseas2km_ASR.].<jupyter_text>Brunt–Väisälä frequency$\huge N^2 = -\frac{g}{\rho_0}\frac{\partial\sigma_0}{\partial z}$  Backend functions:* `compute.potential_density_anomaly`* `compute.gradient`* `compute.weighted_mean`<jupyter_code># Compute N2
od = clean_od.compute.Brunt_Vaisala_frequency()

# Plot 
fig = plt.figure(figsize=(10,10))
ax  = od.plot.horizontal_section(varName='N2', meanAxes=['Z'], robust=True)<jupyter_output>Computing potential density anomaly using the following parameters: {'eq_state': 'jmd95'}.
Computing Brunt-Väisälä Frequency using the following parameters: {'rho0': 1027, 'g': 9.81}.
Computing gradient.
Computing weighted averages.<jupyter_text>Vertical component of relative vorticity$\huge \zeta = \hat{\mathbf{k}}\cdot\left(\nabla\times\overline{u}\right)$  Backend functions:* `compute.curl`* `compute.weighted_mean`<jupyter_code># Rename relative vorticity computed by the model
ds = clean_od.dataset.rename(momVort3='momVort3_model')
od = ospy.OceanDataset(ds)

# Compute the relative vorticity and rename
ds = ospy.compute.vertical_relative_vorticity(od)
od = od.merge_into_oceandataset(ds['momVort3'].rename('momVort3_OceanSpy'))

# Compute difference
diff = (od.dataset['momVort3_OceanSpy'] - od.dataset['momVort3_model']).rename('momVort3_diff')
print('Maximum error: {:.2E} s^-1'.format(np.fabs(diff).max().values))

# Plot 
fig = plt.figure(figsize=(10,10))
_   = od.plot.horizontal_section(varName='momVort3_OceanSpy', meanAxes=['Z'], robust=True)<jupyter_output>Computing vertical component of relative vorticity.
Computing curl.<jupyter_text>Ertel Potential vorticity$\huge Q = (f + \zeta)\frac{N^2}{g} +            \frac{\left(\mathbf{\zeta_h}+e\hat{\mathbf{y}}\right)\cdot\nabla_h\rho}{\rho_0}$  Backend functions:* `compute.relative_vorticity`* `compute.relative_gradient`* `compute.relative_curl`* `compute.potential_density_anomaly`* `compute.Brunt_Vaisala_frequency`* `compute.weighted_mean`<jupyter_code># Compute Ertel PV
od = od.compute.Ertel_potential_vorticity(full=True)

# Plot 
fig = plt.figure(figsize=(10,10))
_   = od.plot.horizontal_section(varName='Ertel_PV', meanAxes=['Z'], robust=True)<jupyter_output>Computing relative vorticity
Computing curl.
Computing gradient.
Computing gradient.
Computing gradient.
Computing gradient.
Computing potential density anomaly using the following parameters: {'eq_state': 'jmd95'}.
Computing Brunt-Väisälä Frequency using the following parameters: {'rho0': 1027, 'g': 9.81}.
Computing gradient.
Computing Ertel potential vorticity using the following parameters: {'rho0': 1027, 'g': 9.81, 'omega': 7.292123516990375e-05}.
Computing potential density anomaly using the following parameters: {'eq_state': 'jmd95'}.
Computing gradient.
Computing weighted averages.
{'fraction_non_alphanumeric': 0.13199037883343356, 'fraction_numerical': 0.02826217678893566, 'mean_word_length': 6.755244755244755, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '377896', 'license': 'MIT', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1135, 'n_words': 246, 'path': 'docs/Demo3b_ComputeHS.ipynb', 'repo_name': 'rabernat/oceanspy', 'size': '3326'}