<jupyter_start><jupyter_text>Field manipulation and I/OIn this section we will go over the basics of how to change the data inside a radar file and save a new radar file. We will do this by creating a new field that stores a reflectivity mask.<jupyter_code>import pyart
%pylab inline<jupyter_output>Populating the interactive namespace from numpy and matplotlib<jupyter_text>As before, we will load our trusty radar file!<jupyter_code>radar = pyart.io.read('../inf_tutorial_data/sgpxsaprcmacsurI5.c1.20170801.044013.nc')<jupyter_output>C:\Users\rjackson\AppData\Local\Continuum\Anaconda2\envs\pyart-2018\lib\site-packages\jupyter_client\jsonutil.py:67: DeprecationWarning: Interpreting naive datetime as local 2018-03-06 14:42:09.494000. Please add timezone info to timestamps.
  new_obj[k] = extract_dates(v)<jupyter_text>Let's store the radar field into a variable.<jupyter_code>ref_field = radar.fields['reflectivity']['data']<jupyter_output>C:\Users\rjackson\AppData\Local\Continuum\Anaconda2\envs\pyart-2018\lib\site-packages\jupyter_client\jsonutil.py:67: DeprecationWarning: Interpreting naive datetime as local 2018-03-06 14:43:26.440000. Please add timezone info to timestamps.
  new_obj[k] = extract_dates(v)<jupyter_text>To create an array that is zero when the condition is false and one when it is true, we can make use of the np.ma.where command.<jupyter_code>ref_gt_0 = np.ma.where(ref_field > 0, 1, 0)
print(ref_gt_0)<jupyter_output>[[0 0 1 ... 0 0 0]
 [0 0 1 ... 0 0 0]
 [0 0 1 ... 0 0 0]
 ...
 [0 0 1 ... 0 0 0]
 [0 0 1 ... 0 0 0]
 [0 0 1 ... 0 0 0]]<jupyter_text>To create a new field, we need to create a dictionary with keys containing the data, the long name, the units, the fill value, and the standard name.<jupyter_code>mask_dict = {'data': ref_gt_0, 'units': '0 = Z < 0, 1 = Z >= 0', 'long_name': 'reflectivity_mask',
             '_FillValue': ref_gt_0.fill_value, 'standard_name': 'reflectivity_mask'}<jupyter_output>C:\Users\rjackson\AppData\Local\Continuum\Anaconda2\envs\pyart-2018\lib\site-packages\jupyter_client\jsonutil.py:67: DeprecationWarning: Interpreting naive datetime as local 2018-03-06 15:17:49.969000. Please add timezone info to timestamps.
  new_obj[k] = extract_dates(v)<jupyter_text>Adding this field into the radar object is as simple as doing radar.add_field()!<jupyter_code>radar.add_field('reflectivity_mask', mask_dict, replace_existing=True)<jupyter_output>C:\Users\rjackson\AppData\Local\Continuum\Anaconda2\envs\pyart-2018\lib\site-packages\jupyter_client\jsonutil.py:67: DeprecationWarning: Interpreting naive datetime as local 2018-03-06 15:17:51.143000. Please add timezone info to timestamps.
  new_obj[k] = extract_dates(v)<jupyter_text>We can now plot the field using RadarMapDisplayCartopy!<jupyter_code>plt.figure(figsize=(8,8))
display = pyart.graph.RadarMapDisplayCartopy(radar)
display.plot_ppi_map('reflectivity_mask', cmap='coolwarm', vmin=0, vmax=1)<jupyter_output>C:\Users\rjackson\AppData\Local\Continuum\Anaconda2\envs\pyart-2018\lib\site-packages\jupyter_client\jsonutil.py:67: DeprecationWarning: Interpreting naive datetime as local 2018-03-06 15:17:56.794000. Please add timezone info to timestamps.
  new_obj[k] = extract_dates(v)<jupyter_text>As you can see, we have now located all of the regions where the reflectivity is greater than 0 dBZ.<jupyter_code>plt.figure(figsize=(8,8))
display.plot_ppi_map('reflectivity', cmap='pyart_LangRainbow12', vmin=-10, vmax=60)<jupyter_output>C:\Users\rjackson\AppData\Local\Continuum\Anaconda2\envs\pyart-2018\lib\site-packages\jupyter_client\jsonutil.py:67: DeprecationWarning: Interpreting naive datetime as local 2018-03-06 14:54:29.277000. Please add timezone info to timestamps.
  new_obj[k] = extract_dates(v)<jupyter_text>Writing this radar object to a new file is as simple as uing pyart.io.write_cfradial()!<jupyter_code>pyart.io.write_cfradial('new_radar.nc', radar)<jupyter_output>C:\Users\rjackson\AppData\Local\Continuum\Anaconda2\envs\pyart-2018\lib\site-packages\jupyter_client\jsonutil.py:67: DeprecationWarning: Interpreting naive datetime as local 2018-03-06 15:00:09.585000. Please add timezone info to timestamps.
  new_obj[k] = extract_dates(v)<jupyter_text>ExerciseCreate a field that is zero when the normalized coherent power is  0.5<jupyter_code>%load section3_answer.py<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11070195627157653, 'fraction_numerical': 0.0616800920598389, 'mean_word_length': 5.975922953451043, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 34, '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': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '66147', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1765, 'n_tokens_neox': 1553, 'n_words': 365, 'path': '1_Introductory_pyart/1.3_Changing_a_field_and_saving.ipynb', 'repo_name': 'rcjackson/stm_2018_pyart_course', 'size': '4345'}