{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Plotting state variables\n\nSimple examples for plotting state variable using flag_values\nand flag_meanings.\n\nAuthor: Ken Kehoe\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from arm_test_data import DATASETS\nfrom matplotlib import pyplot as plt\n\nfrom act.io.arm import read_arm_netcdf\nfrom act.plotting import TimeSeriesDisplay\n\n# ---------------------------------------------------------------------- #\n# This example will create a plot of the detection status time dimentioned\n# varible and set the y axis to the string values defined in flag_meanings\n# instead of plotting the flag values.\n# ---------------------------------------------------------------------- #\n\n# Read in data to plot. Only read in the variables that will be used.\nvariable = 'detection_status'\nfilename_ceil = DATASETS.fetch('sgpceilC1.b1.20190101.000000.nc')\nds = read_arm_netcdf(filename_ceil, keep_variables=[variable, 'lat', 'lon', 'alt'])\n\n# Clean up the variable attributes to match the needed internal standard.\n# Setting override_cf_flag allows the flag_meanings to be rewritten using\n# the better formatted attribute values to make the plot more pretty.\nds.clean.clean_arm_state_variables(variable, override_cf_flag=True)\n\n# Creat Plot Display by setting figure size and number of plots\ndisplay = TimeSeriesDisplay(ds, figsize=(12, 8), subplot_shape=(1,))\n\n# Plot the variable and indicate the day/night background should be added\n# to the plot.\n# Since the string length for each value is long we can ask to wrap the\n# text to make a better looking plot by setting the number of characters\n# to keep per line with the value set to y_axis_flag_meanings. If the\n# strings were short we can just use y_axis_flag_meanings=True.\ndisplay.plot(variable, day_night_background=True, y_axis_flag_meanings=18)\n\n# Display plot in a new window\nplt.show()\n\n# ----------------------------------------------------------------------- #\n# This example will plot the 2 dimentional state variable indicating\n# the cloud type classificaiton. The plot will use the correct formatting\n# for x and y axis, but will show a colorbar explaining color for each value.\n# ----------------------------------------------------------------------- #\n# Read in data to plot. Only read in the variables that will be used.\nvariable = 'cloud_phase_hsrl'\nfilename_cloud = DATASETS.fetch('nsacloudphaseC1.c1.20180601.000000.nc')\nds = read_arm_netcdf(filename_cloud)\n\n# Clean up the variable attributes to match the needed internal standard.\nds.clean.clean_arm_state_variables(variable, override_cf_flag=True)\n\n# Creat Plot Display by setting figure size and number of plots\ndisplay = TimeSeriesDisplay(ds, figsize=(12, 8), subplot_shape=(1,))\n\n# We need to pass in a dictionary containing text and color information\n# for each value in the data variable. We will need to define what\n# color we want plotted for each value but use the flag_values and\n# flag_meanings attribute to supply the other needed information.\ny_axis_labels = {}\nflag_colors = ['white', 'green', 'blue', 'red', 'cyan', 'orange', 'yellow', 'black', 'gray']\nfor value, meaning, color in zip(\n ds[variable].attrs['flag_values'], ds[variable].attrs['flag_meanings'], flag_colors\n):\n y_axis_labels[value] = {'text': meaning, 'color': color}\n\n# Create plot and indicate the colorbar should use the defined colors\n# by passing in dictionary to colorbar_lables.\n# Also, since the test to display on the colorbar is longer than normal\n# we can adjust the placement of the colorbar by indicating the adjustment\n# of horizontal locaiton with cbar_h_adjust.\ndisplay.plot(variable, colorbar_labels=y_axis_labels, cbar_h_adjust=0)\n\n# To provide more room for colorbar and take up more of the defined\n# figure, we can adjust the margins around the initial plot.\ndisplay.fig.subplots_adjust(left=0.08, right=0.88, bottom=0.1, top=0.94)\n\n# Display plot in a new window\nplt.show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.14.3" } }, "nbformat": 4, "nbformat_minor": 0 }