Top_PLEQPT01
How to use this plot
Make sure you have the required datafields (air_temperature, geopotential_height, specific_humidity)
You can use it as is by appending this code into your mswms_settings.py:
from mslib.mswms.mpl_hsec_styles import HS_EQPTStyle_PL_01
register_horizontal_layers = [] if not register_horizontal_layers else register_horizontal_layers
register_horizontal_layers.append((HS_EQPTStyle_PL_01, [next(iter(data))]))
If you want to modify the plot
Download this
file
Put this file into your mswms_settings.py directory, e.g. ~/mss
Append this code into your mswms_settings.py:
from Top_PLEQPT01 import HS_EQPTStyle_PL_01
register_horizontal_layers = [] if not register_horizontal_layers else register_horizontal_layers
register_horizontal_layers.append((HS_EQPTStyle_PL_01, [next(iter(data))]))
Plot Code
"""
This file is part of MSS.
:copyright: Copyright 2021-2024 by the MSS team, see AUTHORS.
:license: APACHE-2.0, see LICENSE for details.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
import logging
import warnings
import numpy as np
import matplotlib.pyplot as plt
import mpl_toolkits.axes_grid1.inset_locator
import matplotlib.colors
import mpl_toolkits.basemap
from matplotlib import patheffects
from mslib.mswms.mpl_hsec import MPLBasemapHorizontalSectionStyle
from mslib.mswms.utils import make_cbar_labels_readable
import mslib.mswms.generics as generics
from mslib.utils import thermolib
from mslib.utils.units import convert_to
class HS_EQPTStyle_PL_01(MPLBasemapHorizontalSectionStyle):
"""
Upper Air Field: Equivalent Potential Temperature
Equivalent potential temperature and geopotential on pressure levels.
"""
name = "PLEQPT01"
title = "Equivalent Potential Temperature (degC) and Geopotential Height (m)"
# Variables with the highest number of dimensions first (otherwise
# MFDatasetCommonDims will throw an exception)!
required_datafields = [
("pl", "air_temperature", "K"),
("pl", "geopotential_height", "m"),
("pl", "specific_humidity", "kg/kg")]
def _prepare_datafields(self):
"""
Computes relative humidity from p, t, q.
"""
pressure = convert_to(self.level, self.get_elevation_units(), "Pa")
self.data["equivalent_potential_temperature"] = thermolib.eqpt_approx(
pressure, self.data["air_temperature"], self.data["specific_humidity"])
self.data["equivalent_potential_temperature"] = convert_to(
self.data["equivalent_potential_temperature"], "K", "degC")
def _plot_style(self):
"""
"""
bm = self.bm
ax = self.bm.ax
data = self.data
filled_contours = np.arange(0, 72, 2)
thin_contours = np.arange(-40, 100, 2)
eqpt = data["equivalent_potential_temperature"]
eqptc = bm.contourf(self.lonmesh, self.latmesh, eqpt,
filled_contours, cmap=plt.cm.gist_rainbow_r)
self.add_colorbar(eqptc, "Equivalent Potential Temperature (degC)")
# Colors in python2.6/site-packages/matplotlib/colors.py
cs = bm.contour(self.lonmesh, self.latmesh, eqpt,
thin_contours, colors="grey",
linewidths=0.5, linestyles="solid")
if cs.levels[0] in thin_contours[::2]:
lablevels = cs.levels[::2]
else:
lablevels = cs.levels[1::2]
ax.clabel(cs, lablevels, colors="grey", fontsize=10, fmt='%.0f')
# cs = bm.contour(self.lonmesh, self.latmesh, eqpt,
# np.arange(100, 170, 15), colors="yellow", linewidths=1)
# Plot geopotential height contours.
gpm = self.data["geopotential_height"]
gpm_interval = 40 if self.level <= 500 else 20
geop_contours = np.arange(400, 28000, gpm_interval)
cs = bm.contour(self.lonmesh, self.latmesh, gpm,
geop_contours, colors="white", linewidths=2)
if cs.levels[0] in geop_contours[::2]:
lablevels = cs.levels[::2]
else:
lablevels = cs.levels[1::2]
ax.clabel(cs, lablevels, fontsize=10, fmt='%.0f')
titlestring = "Equivalent Potential Temperature (degC) and Geopotential Height (m) at " \
f"{self.level:.0f} hPa"
titlestring += f'\nValid: {self.valid_time.strftime("%a %Y-%m-%d %H:%M UTC")}'
if self.uses_inittime_dimension():
time_step = self.valid_time - self.init_time
time_step_hrs = (time_step.days * 86400 + time_step.seconds) // 3600
titlestring += f' (step {time_step_hrs:d} hrs from {self.init_time.strftime("%a %Y-%m-%d %H:%M UTC")})'
if not self.noframe:
ax.set_title(titlestring,
horizontalalignment='left', x=0, fontsize=14)
else:
ax.text(bm.llcrnrx, bm.llcrnry, titlestring,
fontsize=10, bbox=dict(facecolor='white', alpha=0.6))