Side_VS_CW01
How to use this plot
Make sure you have the required datafields (air_pressure, air_temperature, cloud_area_fraction_in_atmosphere_layer, eastward_wind, northward_wind)
You can use it as is by appending this code into your mswms_settings.py:
from mslib.mswms.mpl_vsec_styles import VS_CloudsWindStyle_01
register_vertical_layers = [] if not register_vertical_layers else register_vertical_layers
register_vertical_layers.append((VS_CloudsWindStyle_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 Side_VS_CW01 import VS_CloudsWindStyle_01
register_vertical_layers = [] if not register_vertical_layers else register_vertical_layers
register_vertical_layers.append((VS_CloudsWindStyle_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 warnings
import matplotlib
import matplotlib.pyplot as plt
import mpl_toolkits.axes_grid1.inset_locator
from matplotlib import patheffects
import numpy as np
from mslib.mswms.mpl_vsec import AbstractVerticalSectionStyle
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 VS_CloudsWindStyle_01(AbstractVerticalSectionStyle):
"""
Vertical section of cloud cover and horizontal wind speed.
"""
name = "VS_CW01"
title = "Cloud Cover (0-1) and Wind Speed (m/s) Vertical Section"
abstract = "Cloud cover (0-1) with wind speed (m/s) and potential temperature (K)"
# Variables with the highest number of dimensions first (otherwise
# MFDatasetCommonDims will throw an exception)!
required_datafields = [
("ml", "air_pressure", "Pa"),
("ml", "air_temperature", "K"),
("ml", "cloud_area_fraction_in_atmosphere_layer", 'dimensionless'),
("ml", "eastward_wind", "m/s"),
("ml", "northward_wind", "m/s")]
def _prepare_datafields(self):
"""
Computes potential temperature from pressure and temperature and
total horizontal wind speed.
"""
self.data['air_potential_temperature'] = thermolib.pot_temp(
self.data['air_pressure'], self.data['air_temperature'])
self.data["horizontal_wind"] = np.hypot(
self.data["eastward_wind"], self.data["northward_wind"])
def _plot_style(self):
"""
Make a cloud cover vertical section with wind speed and potential
temperature overlay.
"""
ax = self.ax
curtain_p = self.data["air_pressure"]
curtain_pt = self.data["air_potential_temperature"]
curtain_cc = self.data["cloud_area_fraction_in_atmosphere_layer"]
curtain_v = self.data["horizontal_wind"]
# Contour spacing for temperature lines.
delta_pt = 5 if (np.log(self.p_bot) - np.log(self.p_top)) < 2.2 else 10
wind_contours = np.arange(20, 70, 10)
# Filled contour plot of cloud cover.
cs = ax.contourf(self.horizontal_coordinate, curtain_p, curtain_cc,
np.arange(0.2, 1.1, 0.1), cmap=plt.cm.winter)
# Contour line plot of wind speed.
cs_t = ax.contour(self.horizontal_coordinate, curtain_p, curtain_v,
wind_contours, colors='red', linestyles='solid',
linewidths=2) # gist_earth
ax.clabel(cs_t, fontsize=12, fmt='%.0f')
# Contour line plot of potential temperature.
cs_pt = ax.contour(self.horizontal_coordinate, curtain_p, curtain_pt,
np.arange(200, 700, delta_pt), colors='0.40',
linestyles='solid', linewidths=1)
ax.clabel(cs_pt, fontsize=12, fmt='%.0f')
# Pressure decreases with index, i.e. orography is stored at the
# zero-p-index (data field is flipped in mss_plot_driver.py if
# pressure increases with index).
self._latlon_logp_setup(orography=curtain_p[0, :])
# Add colorbar.
if not self.noframe:
self.fig.subplots_adjust(left=0.08, right=0.95, top=0.9, bottom=0.14)
cbar = self.fig.colorbar(cs, fraction=0.05, pad=0.01)
cbar.set_label("Cloud cover (0-1)")
else:
axins1 = mpl_toolkits.axes_grid1.inset_locator.inset_axes(
ax, width="1%", height="30%", loc=1)
cbar = self.fig.colorbar(cs, cax=axins1, orientation="vertical")
axins1.yaxis.set_ticks_position("left")
make_cbar_labels_readable(self.fig, axins1)