Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Clean up. #106

Merged
merged 3 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/mixsea-pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v2
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
repos:
# isort should run before black as black sometimes tweaks the isort output
- repo: https://github.com/timothycrosley/isort
rev: 4.3.21-2
rev: 5.12.0
hooks:
- id: isort
files: .+\.py$
Expand All @@ -12,7 +12,7 @@ repos:
rev: stable
hooks:
- id: black
- repo: https://gitlab.com/pycqa/flake8
- repo: https://github.com/pycqa/flake8
rev: 3.7.9
hooks:
- id: flake8
- id: flake8
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Overturn-based parameterization

overturn.eps_overturn
overturn.nan_eps_overturn
overturn.thorpe_scale

Shear/strain-based parameterization
===================================
Expand Down
7 changes: 0 additions & 7 deletions docs/getting_started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -534,13 +534,6 @@
" title='vertical diffusivity');\n",
"ax[0].invert_yaxis()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
82 changes: 52 additions & 30 deletions docs/thorpe_scales.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Here we'll examine some of the different parameter options used for estimating the turbulent dissipation rate, $\\epsilon$, from Thorpe scales. The method was first published by Stephen Thorpe see <cite data-cite=\"Thorpe1977\">Thorpe (1977)</cite>. "
"In this notebook we'll examine some of the different parameter options used for estimating the turbulent dissipation rate, $\\epsilon$, from Thorpe scales. The method was first published by Stephen Thorpe - see <cite data-cite=\"Thorpe1977\">Thorpe (1977)</cite>. "
]
},
{
Expand Down Expand Up @@ -52,7 +52,9 @@
"\\end{equation}\n",
" \n",
"where we identify $C_{0} = \\alpha^{-2}$ as an $\\mathcal{O}(1)$ free parameter, perhaps tuned based on microstructure measurements of $\\epsilon$.\n",
" \n",
"\n",
"---\n",
"\n",
"***Warning:** The Thorpe scale method is an **event-based** turbulence parameterization, so one must be wary of spatial and temporal intermittency when interpreting results.*\n",
"</div>"
]
Expand All @@ -61,8 +63,13 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Thus, the Thorpe scale method in practice can be separated three steps: 1) finding the overturns, 2) determining their Thorpe scales by sorting, and 3) determining the background stratification.\n",
"\n",
"The Thorpe scale method in practice can be separated into three steps: 1) finding the overturns, 2) determining their Thorpe scales by sorting, and 3) determining the background stratification."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Example\n",
"\n",
"First, we load modules and example data."
Expand Down Expand Up @@ -147,7 +154,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The standard output `eps` and `N2` (buoyancy frequency squared) have been quality controlled. The type and strictness of quality control can be set using arguments to `eps_overturn` (see the function docstring for details) In addition, numerous diagnostic variables are output in the dictionary `diag`. The diagnostic dictionary contains output from pre-quality control, as well as, flags which indicate the quality control state and miscellanous other variables that might be useful. "
"The standard output `eps` and `N2` (buoyancy frequency squared) have been quality controlled. The type and strictness of quality control can be set using arguments to `eps_overturn` (see the function docstring for details). In addition, numerous diagnostic variables are output in the dictionary `diag`. The diagnostic dictionary contains output from pre-quality control, as well as flags which indicate the quality control state and miscellaneous other variables that might be useful."
]
},
{
Expand All @@ -166,23 +173,28 @@
"source": [
"Some of the diagnostics are as follows:\n",
"\n",
"* `eps`: the dissipation rate estimated before applying quality control flags.\n",
"* `N2`: the buoyancy frequency squared estimated before applying quality control flags.\n",
"* `Lt`: the Thorpe scale.\n",
"* `thorpe_disp`: the Thorpe displacements.\n",
"* `dens`: potential density (this may appear 'steppy' due to the use of different reference pressures at for different pressure ranges).\n",
"* `dens_sorted`: sorted potential density.\n",
"* `dens_ip`: density from the intermediate profile method. (Does not appear in the list above because the intermediate profile method was not used)\n",
"* `t_ip`: temperature from the intermediate profile method. (Does not appear in the list above because intermediate profile method was not used)\n",
"* `Ro`: the overturn ratio.\n",
"* `eps`: dissipation rate estimated before applying quality control flags\n",
"* `N2`: buoyancy frequency squared estimated before applying quality control flags\n",
"* `Lt`: Thorpe scale\n",
"* `thorpe_disp`: Thorpe displacement\n",
"* `dens`: potential density (this may appear 'steppy' due to the use of different reference pressures for different pressure ranges)\n",
"* `dens_sorted`: sorted potential density\n",
"* `dens_ip`: density from the intermediate profile method (does not appear in the list above because the intermediate profile method was not used)\n",
"* `t_ip`: temperature from the intermediate profile method (does not appear in the list above because intermediate profile method was not used)\n",
"* `Ro`: overturn ratio\n",
"\n",
"Some of the quality control flags:\n",
"\n",
"* `noise_flag`: if density/CT difference from the top to bottom of the overturn is less than the noise parameter, this flag will be True.\n",
"* `N2_flag`: if buoyancy frequency is negative, this flag will be True.\n",
"* `ends_flag`: if an overturn contains the first or last point in the data, this flag will be True.\n",
"* `Ro_flag`: if the overturn ratio is less than the critical value, this flag will be True.\n",
"\n",
"* `noise_flag`: if density/CT difference from the top to bottom of the overturn is less than the noise parameter, this flag will be True\n",
"* `N2_flag`: if buoyancy frequency is negative, this flag will be True\n",
"* `ends_flag`: if an overturn contains the first or last point in the data, this flag will be True\n",
"* `Ro_flag`: if the overturn ratio is less than the critical value, this flag will be True"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If we zoom into a segment, it is easier to understand what these diagnostics mean."
]
},
Expand Down Expand Up @@ -229,9 +241,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Starting from the left, we have potential density and sorted potential density. Overturning patches should correspond to regions where the potential density is different from the sorted potential density. Next is the dissipation rate, $\\epsilon$, plotted in green are the values that have passed quality control and in red those that were rejected by some criteria. The plot looks a bit odd because there are jumps in $\\epsilon$. This is caused by small overturns adjacent to large overturns. Ultimately, a lot of small overturns will be rejected by quality control. Third from the left is buoyancy frequency, which can be calculated in a number of different ways. We will explore this in more detail later. Last is the Thorpe displacements and Thorpe length scale. Large negative values atop large positive values represent large overturns; whether this leads to large dissipation depends on the stratification.\n",
"Starting from the left, we have potential density and sorted potential density. Overturning patches should correspond to regions where the potential density is different from the sorted potential density. Next is the dissipation rate, $\\epsilon$. Plotted in green are values that have passed quality control and in red those that were rejected by some criteria. The plot looks a bit odd because there are jumps in $\\epsilon$. This is caused by small overturns adjacent to large overturns. Ultimately, a lot of small overturns will be rejected by quality control. Third from the left is buoyancy frequency, which can be calculated in a number of different ways. We will explore this in more detail later. Last are Thorpe displacements and Thorpe length scale. Large negative values atop large positive values represent large overturns; whether this leads to large dissipation depends on the stratification.\n",
"\n",
"The state (true/false) of some of the quality control flags is plotted below for the same segment of data."
"The state (True/False) of some of the quality control flags is plotted below for the same segment of data."
]
},
{
Expand Down Expand Up @@ -269,8 +281,13 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The noise flag is raised (true) where the density difference (top to bottom) of the overturning region is smaller than the noise parameter. The N2 flag has not been raised anywhere, indicating there are no regions of negative buoyancy frequency. The ends flag is raised for the last overturn since it contains the end point of the data. However, it is just a warning flag and not used to quality control the output. The Ro flag is raised where the overturn ratio is less than the critical value <cite data-cite=\"Gargett2008\">Gargett and Garner (2008)</cite>. Note that for this demonstration we have set the critical overturn ratio a bit higher than would be normal. \n",
"\n",
"The noise flag is raised (True) where the density difference (top to bottom) of the overturning region is smaller than the noise parameter. The N2 flag has not been raised anywhere, indicating there are no regions of negative buoyancy frequency. The ends flag is raised for the last overturn since it contains the end point of the data. However, it is just a warning flag and not used to quality control the output. The Ro flag is raised where the overturn ratio is less than the critical value <cite data-cite=\"Gargett2008\">Gargett and Garner (2008)</cite>. Note that for this demonstration we have set the critical overturn ratio a bit higher than would be normal. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### The intermediate profile method\n",
"\n",
"The intermediate profile method attempts to reduce the influence of random noise when estimating overturns. For technical details, see <cite data-cite=\"Ferron1998\">Ferron et al. (1998)</cite> and <cite data-cite=\"Gargett2008\">Gargett and Garner (2008)</cite>.\n",
Expand Down Expand Up @@ -301,7 +318,7 @@
"ax.plot(tdo, depth[cut], label='down')\n",
"ax.plot(tav, depth[cut], label='ave')\n",
"ax.legend()\n",
"ax.set_xlabel('Temperature [$^\\circ$C]')\n",
"ax.set_xlabel(r'Temperature [$^\\circ$C]')\n",
"ax.set_ylabel('Depth [m]');"
]
},
Expand Down Expand Up @@ -385,8 +402,13 @@
"source": [
"Now we're using the intermediate profile method, the results have changed dramatically. Overturns are diagnosed from the intermediate profile of density, which is different to the actual density. The overturning patches may be of different sizes to those estimated without the intermediate profile. Sorting the intermediate profile results in strange looking Thorpe displacements, because the sorting algorithm struggles when many data points have an identical value. There is an argument to be made the method should not be applied to data that has already been bin averaged (as ours has) and the method may work better on raw CTD data that is more noisy.\n",
"\n",
"Because the intermediate profile method fundamentally changes many aspects of the Thorpe scale method, including the size of detected overturns and the Thorpe displacements, it is not straightforward or necessarily meaningful to raise a flag for rejected overturns. Consequently, most flags are disabled when using the method and so are not shown.\n",
"\n",
"Because the intermediate profile method fundamentally changes many aspects of the Thorpe scale method, including the size of detected overturns and the Thorpe displacements, it is not straightforward or necessarily meaningful to raise a flag for rejected overturns. Consequently, most flags are disabled when using the method and so are not shown."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Compare methods of estimating $N^2$\n",
"\n",
"There are a few different options for calculating buoyancy frequency:"
Expand Down Expand Up @@ -429,7 +451,7 @@
"A brief explanation of the methods:\n",
"\n",
"* `teos`: This method estimates $N^2$ from the thermodynamic equation of state 2010 (TEOS), using the tempurature and salinity at the first and last point in the overturn.\n",
"* `toesp1`: This method is the same as above except it uses the temperature and salinity from the points immediately above and below the overturn (p1 meaning plus 1).\n",
"* `teosp1`: This method is the same as above except it uses the temperature and salinity from the points immediately above and below the overturn (p1 meaning plus 1).\n",
"* `bulk`: This method comes from <cite data-cite=\"Smyth2001\">Smyth et al. (2001)</cite> and has the advantage of being insensitive to errors in determining the patch size. Buoyancy frequency is proportional to the root mean square density anomaly of an overturn, divided by the Thorpe scale.\n",
"* `endpt`: This simple method estimates buoyancy frequency from the potential density gradient across each overturn.\n",
"\n",
Expand Down Expand Up @@ -621,9 +643,9 @@
"notebook_metadata_filter": "-jupytext.text_representation.jupytext_version"
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python [conda env:mixsea]",
"language": "python",
"name": "python3"
"name": "conda-env-mixsea-py"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -635,7 +657,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
"version": "3.12.0"
}
},
"nbformat": 4,
Expand Down
2 changes: 2 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ dependencies:
- ipython
- ipykernel
- pip
- pip:
- "-e ."
1 change: 0 additions & 1 deletion mixsea/overturn.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ def eps_overturn(

# Loop over pressure bins.
for idx_bin in range(nbins):

if EOS == "gsw":
dens = gsw.pot_rho_t_exact(SA, t, p, p_ref=p_refs[idx_bin])
elif EOS == "linear":
Expand Down
12 changes: 10 additions & 2 deletions mixsea/tests/test_shearstrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ def test_nan_shearstrain(ctd_profile, ladcp_profile, smooth):
m_include_sh = list(range(3))
m_include_st = list(range(1, 10))

(eps_shst, krho_shst, diag,) = shearstrain.nan_shearstrain(
(
eps_shst,
krho_shst,
diag,
) = shearstrain.nan_shearstrain(
ctd_profile["depth"],
ctd_profile["t"],
ctd_profile["SP"],
Expand Down Expand Up @@ -76,7 +80,11 @@ def test_shearstrain(ctd_profile, ladcp_profile):
m_include_sh = list(range(3))
m_include_st = list(range(1, 10))

(eps_shst, krho_shst, diag,) = shearstrain.shearstrain(
(
eps_shst,
krho_shst,
diag,
) = shearstrain.shearstrain(
depth,
t,
SP,
Expand Down
Loading