.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/correct/plot_cloud_mask.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_correct_plot_cloud_mask.py: ===================================== Calculating and Plotting a Cloud Mask ===================================== This example shows how to correct and plot reflectivity from an ARM KAZR using a noise floor cloud mask. .. GENERATED FROM PYTHON SOURCE LINES 10-21 .. code-block:: Python print(__doc__) # Author: Adam Theisen and Zach Sherman # License: BSD 3 clause import matplotlib.pyplot as plt import numpy as np from open_radar_data import DATASETS import pyart .. GENERATED FROM PYTHON SOURCE LINES 22-25 **Read and plot raw data** First let's read and plot our dataset without any mask. .. GENERATED FROM PYTHON SOURCE LINES 25-36 .. code-block:: Python # Fetch and read in the ARM KAZR file. filename = DATASETS.fetch("sgpkazrgeC1.a1.20190529.000002.cdf") radar = pyart.aux_io.read_kazr(filename) # Let's now take a look at reflectivity data prior to any corrections. display = pyart.graph.RadarDisplay(radar) display.plot("reflectivity_copol") display.set_limits(xlim=(0, 55)) plt.show() .. image-sg:: /examples/correct/images/sphx_glr_plot_cloud_mask_001.png :alt: 2019-05-29T15:00:00Z Reflectivity, copolar :srcset: /examples/correct/images/sphx_glr_plot_cloud_mask_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 37-42 **Calculate cloud mask and plot corrected data** Now lets apply a mask by using the calc_cloud_mask function that will use a noise floor calculation from range and more to calculate the mask. .. GENERATED FROM PYTHON SOURCE LINES 42-67 .. code-block:: Python # First lets correct the data by calculating the mask. cloud_mask_radar = pyart.correct.calc_cloud_mask(radar, "reflectivity_copol", "range") # In this new radar object we should now have a new cloud mask field. print(cloud_mask_radar.fields["cloud_mask_2"]) # Next we'll create a copy of the reflectivity field so we are not # overwriting the original data. cloud_mask_radar.add_field_like( "reflectivity_copol", "reflectivity_cloud_mask", cloud_mask_radar.fields["reflectivity_copol"]["data"].copy(), ) # Now let's apply the mask to the copied reflectivity data. cloud_mask_radar.fields["reflectivity_cloud_mask"]["data"][ cloud_mask_radar.fields["cloud_mask_2"]["data"] == 0 ] = np.nan # And now we can plot the masked reflectivity field. display = pyart.graph.RadarDisplay(cloud_mask_radar) display.plot("reflectivity_cloud_mask") display.set_limits(xlim=(0, 55)) plt.show() .. image-sg:: /examples/correct/images/sphx_glr_plot_cloud_mask_002.png :alt: 2019-05-29T15:00:00Z Reflectivity, copolar :srcset: /examples/correct/images/sphx_glr_plot_cloud_mask_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none {'long_name': 'Cloud mask 2 (2D box)', 'units': '1', 'comment': 'The mask uses a 2D box to filter out noise.', 'flag_values': [0, 1], 'flag_meanings': ['no_cloud', 'cloud'], 'data': masked_array( data=[[0, 0, 0, ..., 0, 0, 0], [0, 0, 1, ..., 0, 0, 0], [0, 1, 1, ..., 0, 0, 0], ..., [0, 1, 1, ..., 0, 0, 0], [0, 0, 1, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0]], mask=[[False, False, False, ..., False, False, False], [False, False, False, ..., False, False, False], [False, False, False, ..., False, False, False], ..., [False, False, False, ..., False, False, False], [False, False, False, ..., False, False, False], [False, False, False, ..., False, False, False]], fill_value=np.int64(999999), dtype=int16)} .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.685 seconds) .. _sphx_glr_download_examples_correct_plot_cloud_mask.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_cloud_mask.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_cloud_mask.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_cloud_mask.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_