def test_qc_bar_plot(): ds_object = arm.read_netcdf(sample_files.EXAMPLE_MET1) ds_object.clean.cleanup() var_name = 'temp_mean' ds_object.qcfilter.set_test(var_name, index=range(100, 600), test_number=2) # Testing out when the assessment is not listed ds_object.qcfilter.set_test(var_name, index=range(500, 800), test_number=4) ds_object['qc_' + var_name].attrs['flag_assessments'][3] = 'Wonky' display = TimeSeriesDisplay({'sgpmetE13.b1': ds_object}, subplot_shape=(2, ), figsize=(7, 4)) display.plot(var_name, subplot_index=(0, ), assessment_overplot=True) display.day_night_background('sgpmetE13.b1', subplot_index=(0, )) color_lookup = { 'Bad': 'red', 'Incorrect': 'red', 'Indeterminate': 'orange', 'Suspect': 'orange', 'Missing': 'darkgray', 'Not Failing': 'green', 'Acceptable': 'green' } display.qc_flag_block_plot(var_name, subplot_index=(1, ), assessment_color=color_lookup) ds_object.close() try: return display.fig finally: matplotlib.pyplot.close(display.fig)
def test_assessment_overplot(): var_name = 'temp_mean' files = sample_files.EXAMPLE_MET1 ds = arm.read_netcdf(files) ds.load() ds.clean.cleanup() ds.qcfilter.set_test(var_name, index=np.arange(100, 300, dtype=int), test_number=2) ds.qcfilter.set_test(var_name, index=np.arange(420, 422, dtype=int), test_number=3) ds.qcfilter.set_test(var_name, index=np.arange(500, 800, dtype=int), test_number=4) ds.qcfilter.set_test(var_name, index=np.arange(900, 901, dtype=int), test_number=4) # Plot data display = TimeSeriesDisplay(ds, subplot_shape=(1, ), figsize=(10, 6)) display.plot(var_name, day_night_background=True, assessment_overplot=True) ds.close() return display.fig
def test_assessment_overplot_multi(): var_name1, var_name2 = 'wspd_arith_mean', 'wspd_vec_mean' files = sample_files.EXAMPLE_MET1 ds = arm.read_netcdf(files) ds.load() ds.clean.cleanup() ds.qcfilter.set_test(var_name1, index=np.arange(100, 200, dtype=int), test_number=2) ds.qcfilter.set_test(var_name1, index=np.arange(500, 600, dtype=int), test_number=4) ds.qcfilter.set_test(var_name2, index=np.arange(300, 400, dtype=int), test_number=4) # Plot data display = TimeSeriesDisplay(ds, subplot_shape=(1, ), figsize=(10, 6)) display.plot(var_name1, label=var_name1, assessment_overplot=True, overplot_behind=True) display.plot(var_name2, day_night_background=True, color='green', label=var_name2, assessment_overplot=True) ds.close() return display.fig
def test_multidataset_plot_tuple(): conn = boto3.resource('s3') conn.meta.client.meta.events.register('choose-signer.s3.*', disable_signing) bucket = conn.Bucket('act-tests') if not os.path.isdir((os.getcwd() + '/data/')): os.makedirs((os.getcwd() + '/data/')) for item in bucket.objects.all(): bucket.download_file(item.key, (os.getcwd() + '/data/' + item.key)) ceil_ds = arm.read_netcdf('data/sgpceilC1.b1*') sonde_ds = arm.read_netcdf(sample_files.EXAMPLE_MET_WILDCARD) # Removing fill value of -9999 as it was causing some warnings ceil_ds = ceil.correct_ceil(ceil_ds) # You can use tuples if the datasets in the tuple contain a # datastream attribute. This is required in all ARM datasets. display = TimeSeriesDisplay((ceil_ds, sonde_ds), subplot_shape=(2, ), figsize=(15, 10)) display.plot('backscatter', 'sgpceilC1.b1', subplot_index=(0, )) display.plot('temp_mean', 'sgpmetE13.b1', subplot_index=(1, )) display.day_night_background('sgpmetE13.b1', subplot_index=(1, )) ceil_ds.close() sonde_ds.close() return display.fig
def test_multidataset_plot_dict(): conn = boto3.resource('s3') conn.meta.client.meta.events.register('choose-signer.s3.*', disable_signing) bucket = conn.Bucket('act-tests') if not os.path.isdir((os.getcwd() + '/data/')): os.makedirs((os.getcwd() + '/data/')) for item in bucket.objects.all(): bucket.download_file(item.key, (os.getcwd() + '/data/' + item.key)) ceil_ds = arm.read_netcdf('data/sgpceilC1.b1*') sonde_ds = arm.read_netcdf(sample_files.EXAMPLE_MET_WILDCARD) ceil_ds = ceil.correct_ceil(ceil_ds, fill_value=-9999.) display = TimeSeriesDisplay( { 'ceiliometer': ceil_ds, 'rawinsonde': sonde_ds }, subplot_shape=(2, ), figsize=(15, 10)) display.plot('backscatter', 'ceiliometer', subplot_index=(0, )) display.plot('temp_mean', 'rawinsonde', subplot_index=(1, )) display.day_night_background('rawinsonde', subplot_index=(1, )) ceil_ds.close() sonde_ds.close() return display.fig
def test_multidataset_plot_tuple(): obj = arm.read_netcdf(sample_files.EXAMPLE_MET1) obj2 = arm.read_netcdf(sample_files.EXAMPLE_SIRS) obj = obj.rename({'lat': 'fun_time'}) obj['fun_time'].attrs['standard_name'] = 'latitude' obj = obj.rename({'lon': 'not_so_fun_time'}) obj['not_so_fun_time'].attrs['standard_name'] = 'longitude' # You can use tuples if the datasets in the tuple contain a # datastream attribute. This is required in all ARM datasets. display = TimeSeriesDisplay((obj, obj2), subplot_shape=(2, ), figsize=(15, 10)) display.plot('short_direct_normal', 'sgpsirsE13.b1', subplot_index=(0, )) display.day_night_background('sgpsirsE13.b1', subplot_index=(0, )) display.plot('temp_mean', 'sgpmetE13.b1', subplot_index=(1, )) display.day_night_background('sgpmetE13.b1', subplot_index=(1, )) ax = act.plotting.common.parse_ax(ax=None) ax, fig = act.plotting.common.parse_ax_fig(ax=None, fig=None) obj.close() obj2.close() try: return display.fig finally: matplotlib.pyplot.close(display.fig)
def test_2d_as_1d(): obj = arm.read_netcdf(sample_files.EXAMPLE_CEIL1) display = TimeSeriesDisplay(obj) display.plot('backscatter', force_line_plot=True) return display.fig
def test_2D_timeseries_plot(): obj = arm.read_netcdf(sample_files.EXAMPLE_CEIL1) display = TimeSeriesDisplay(obj) display.plot('backscatter', y_rng=[0, 5000], use_var_for_y='range') try: return display.fig finally: matplotlib.pyplot.close(display.fig)
def test_time_plot2(): files = sample_files.EXAMPLE_MET1 obj = arm.read_netcdf(files, decode_times=False, cftime_to_datetime64=False) display = TimeSeriesDisplay(obj) display.plot('time') return display.fig
def test_y_axis_flag_meanings(): variable = 'detection_status' obj = arm.read_netcdf( sample_files.EXAMPLE_CEIL1, keep_variables=[variable, 'lat', 'lon', 'alt'] ) obj.clean.clean_arm_state_variables(variable, override_cf_flag=True) display = TimeSeriesDisplay(obj, figsize=(12, 8), subplot_shape=(1,)) display.plot(variable, subplot_index=(0,), day_night_background=True, y_axis_flag_meanings=18) display.fig.subplots_adjust(left=0.15, right=0.95, bottom=0.1, top=0.94) return display.fig
def test_qc_flag_block_plot(): obj = arm.read_netcdf(sample_files.EXAMPLE_SURFSPECALB1MLAWER) display = TimeSeriesDisplay(obj, subplot_shape=(2, ), figsize=(8, 2 * 4)) display.plot('surface_albedo_mfr_narrowband_10m', force_line_plot=True, labels=True) display.qc_flag_block_plot('surface_albedo_mfr_narrowband_10m', subplot_index=(1, )) obj.close() del obj return display.fig
def test_2d_as_1d(): obj = arm.read_netcdf(sample_files.EXAMPLE_CEIL1) display = TimeSeriesDisplay(obj) display.plot('backscatter', force_line_plot=True) obj.close() del obj try: return display.fig finally: matplotlib.pyplot.close(display.fig)
def test_qc_bar_plot(): ds_object = arm.read_netcdf(sample_files.EXAMPLE_MET1) ds_object.clean.cleanup() var_name = 'temp_mean' ds_object.qcfilter.set_test(var_name, index=range(100, 600), test_number=2) display = TimeSeriesDisplay({'sgpmetE13.b1': ds_object}, subplot_shape=(2, ), figsize=(7, 4)) display.plot(var_name, subplot_index=(0, ), assessment_overplot=True) display.day_night_background('sgpmetE13.b1', subplot_index=(0, )) display.qc_flag_block_plot(var_name, subplot_index=(1, )) return display.fig
def test_colorbar_labels(): variable = 'cloud_phase_hsrl' obj = arm.read_netcdf(sample_files.EXAMPLE_CLOUDPHASE) obj.clean.clean_arm_state_variables(variable) display = TimeSeriesDisplay(obj, figsize=(12, 8), subplot_shape=(1,)) y_axis_labels = {} flag_colors = ['white', 'green', 'blue', 'red', 'cyan', 'orange', 'yellow', 'black', 'gray'] for value, meaning, color in zip( obj[variable].attrs['flag_values'], obj[variable].attrs['flag_meanings'], flag_colors ): y_axis_labels[value] = {'text': meaning, 'color': color} display.plot(variable, subplot_index=(0,), colorbar_labels=y_axis_labels, cbar_h_adjust=0) display.fig.subplots_adjust(left=0.08, right=0.88, bottom=0.1, top=0.94) return display.fig
def test_multidataset_plot_dict(): obj = arm.read_netcdf(sample_files.EXAMPLE_MET1) obj2 = arm.read_netcdf(sample_files.EXAMPLE_SIRS) # You can use tuples if the datasets in the tuple contain a # datastream attribute. This is required in all ARM datasets. display = TimeSeriesDisplay( {'sirs': obj2, 'met': obj}, subplot_shape=(2,), figsize=(15, 10)) display.plot('short_direct_normal', 'sirs', subplot_index=(0,)) display.day_night_background('sirs', subplot_index=(0,)) display.plot('temp_mean', 'met', subplot_index=(1,)) display.day_night_background('met', subplot_index=(1,)) obj.close() obj2.close() return display.fig
def test_qc_bar_plot(): ds_object = arm.read_netcdf(sample_files.EXAMPLE_MET1) ds_object.clean.cleanup() var_name = 'temp_mean' ds_object.qcfilter.set_test(var_name, index=range(100, 600), test_number=2) # Testing out when the assessment is not listed ds_object.qcfilter.set_test(var_name, index=range(500, 800), test_number=4) ds_object['qc_' + var_name].attrs['flag_assessments'][3] = 'Wonky' display = TimeSeriesDisplay({'sgpmetE13.b1': ds_object}, subplot_shape=(2, ), figsize=(7, 4)) display.plot(var_name, subplot_index=(0, ), assessment_overplot=True) display.day_night_background('sgpmetE13.b1', subplot_index=(0, )) display.qc_flag_block_plot(var_name, subplot_index=(1, )) ds_object.close() return display.fig
def test_plot(): # Process MET data to get simple LCL files = sample_files.EXAMPLE_MET_WILDCARD met = arm.read_netcdf(files) met_temp = met.temp_mean met_rh = met.rh_mean met_lcl = (20. + met_temp / 5.) * (100. - met_rh) / 1000. met['met_lcl'] = met_lcl * 1000. met['met_lcl'].attrs['units'] = 'm' met['met_lcl'].attrs['long_name'] = 'LCL Calculated from SGP MET E13' # Plot data display = TimeSeriesDisplay(met) display.add_subplots((2, 2), figsize=(15, 10)) display.plot('wspd_vec_mean', subplot_index=(0, 0)) display.plot('temp_mean', subplot_index=(1, 0)) display.plot('rh_mean', subplot_index=(0, 1)) windrose = WindRoseDisplay(met) display.put_display_in_subplot(windrose, subplot_index=(1, 1)) windrose.plot('wdir_vec_mean', 'wspd_vec_mean', spd_bins=np.linspace(0, 10, 4)) windrose.axes[0].legend(loc='best') met.close() return display.fig
def test_plot(): # Process MET data to get simple LCL files = sample_files.EXAMPLE_SONDE_WILDCARD met = arm.read_netcdf(files) met_temp = met.temp_mean met_rh = met.rh_mean met_lcl = (20. + met_temp / 5.) * (100. - met_rh) / 1000. met['met_lcl'] = met_lcl * 1000. met['met_lcl'].attrs['units'] = 'm' met['met_lcl'].attrs['long_name'] = 'LCL Calculated from SGP MET E13' # Plot data # Plot data display = TimeSeriesDisplay(met) display.add_subplots((3, ), figsize=(15, 10)) display.plot('wspd_vec_mean', subplot_index=(0, )) display.plot('temp_mean', subplot_index=(1, )) display.plot('rh_mean', subplot_index=(2, )) return display.fig
# Change variable units from degree C to degree F. Can specify specific variables. # Or list no variables and will attempt to change all variables to the desired # unit if the units are conicially matching. ds_obj = ds_obj.utils.change_units(variables='air_temperature_10m', desired_unit='degF') # Set up plotting ACT object to contain data to plot and other configurations my_disp = TimeSeriesDisplay({'noaa_gml_brw': ds_obj}, subplot_shape=(2, ), figsize=(15, 10)) # Plot two variables on one plot and set the plot axes title. Also color # background to indicate when sun is shining and local solar noon time. my_disp.plot('downwelling_global_solar', subplot_index=(0, ), label='Downwelling') my_disp.plot('upwelling_global_solar', subplot_index=(0, ), label='Upwelling', set_title=f"NOAA GML {ds_obj.attrs['location']} Global Solar", day_night_background=True) # Add second plot of air temperature. Use variable long name for plot axes title # and add background color to indicate when sun is shining and solar noon. var_name = 'air_temperature_10m' title = f"NOAA GML {ds_obj.attrs['location']} {ds_obj[var_name].attrs['long_name']}" my_disp.plot(var_name, subplot_index=(1, ), set_title=title, day_night_background=True)
# MET and Ozone do not have location variables in the file. Add location variables # from rad_obj to allow day/night background plotting. for var_name in ['lat', 'lon', 'alt']: ozone_obj[var_name] = rad_obj[var_name] met_obj[var_name] = rad_obj[var_name] # Create dictionary of all data objects to allow plotting from different # Xarray Datasets. location = "Barrow" plot_obj = {'met': met_obj, 'rad': rad_obj, 'ozone': ozone_obj} my_disp = TimeSeriesDisplay(plot_obj, subplot_shape=(3, ), figsize=(10, 8)) # Create first plot of two variables from Radiation file. my_disp.plot('downwelling_global_solar', dsname='rad', subplot_index=(0, ), label='Downwelling') my_disp.plot('upwelling_global_solar', dsname='rad', subplot_index=(0, ), label='Upwelling', set_title=f"NOAA GML {location} Global Solar", day_night_background=True) # Add second plot of Ozone. Use variable long name for plot axes title # and add background color to indicate when sun is shining and solar noon. var_name = 'ozone' my_disp.plot( var_name, dsname='ozone', subplot_index=(1, ),
def test_time_plot(): files = sample_files.EXAMPLE_MET1 obj = arm.read_netcdf(files) display = TimeSeriesDisplay(obj) display.plot('time') return display.fig
def test_errors(): files = sample_files.EXAMPLE_MET_WILDCARD obj = arm.read_netcdf(files) display = TimeSeriesDisplay(obj) display.axes = None with np.testing.assert_raises(RuntimeError): display.day_night_background() display = TimeSeriesDisplay({'met': obj, 'met2': obj}) with np.testing.assert_raises(ValueError): display.plot('temp_mean') with np.testing.assert_raises(ValueError): display.qc_flag_block_plot('qc_temp_mean') with np.testing.assert_raises(ValueError): display.plot_barbs_from_spd_dir('wdir_vec_mean', 'wspd_vec_mean') with np.testing.assert_raises(ValueError): display.plot_barbs_from_u_v('wdir_vec_mean', 'wspd_vec_mean') del obj.attrs['_file_dates'] data = np.empty(len(obj['time'])) * np.nan lat = obj['lat'].values lon = obj['lon'].values obj['lat'].values = data obj['lon'].values = data display = TimeSeriesDisplay(obj) display.plot('temp_mean') display.set_yrng([0, 0]) with np.testing.assert_warns(RuntimeWarning): display.day_night_background() obj['lat'].values = lat with np.testing.assert_warns(RuntimeWarning): display.day_night_background() obj['lon'].values = lon * 100. with np.testing.assert_warns(RuntimeWarning): display.day_night_background() obj['lat'].values = lat * 100. with np.testing.assert_warns(RuntimeWarning): display.day_night_background() obj.close() # Test some of the other errors obj = arm.read_netcdf(files) del obj['temp_mean'].attrs['units'] display = TimeSeriesDisplay(obj) display.axes = None with np.testing.assert_raises(RuntimeError): display.set_yrng([0, 10]) with np.testing.assert_raises(RuntimeError): display.set_xrng([0, 10]) display.fig = None display.plot('temp_mean', add_nan=True) assert display.fig is not None assert display.axes is not None with np.testing.assert_raises(AttributeError): display = TimeSeriesDisplay([]) fig, ax = matplotlib.pyplot.subplots() display = TimeSeriesDisplay(obj) display.add_subplots((2, 2), figsize=(15, 10)) display.assign_to_figure_axis(fig, ax) assert display.fig is not None assert display.axes is not None obj = arm.read_netcdf(files) display = TimeSeriesDisplay(obj) obj.clean.cleanup() display.axes = None display.fig = None display.qc_flag_block_plot('atmos_pressure') assert display.fig is not None assert display.axes is not None matplotlib.pyplot.close(fig=display.fig)
ds = ds.assign_coords(time=ds['time']) ds = ds.swap_dims({'index': 'time'}) ds = ds.drop('index') ds = ds.rename({'Latitude': 'latitude', 'Longitude': 'longitude'}) var_names = list(set(ds.keys()) - set(['time', 'Elapsed Seconds', 'latitude', 'longitude'])) var_names = [ii for ii in var_names if 'Avg.' not in ii] var_names.sort() my_disp = TimeSeriesDisplay({'pocketLab': ds}, subplot_shape=(int(len(var_names)/2), 2), figsize=(8*2, 2*len(var_names)/2)) row=0 col=0 for plot_num, var_name in enumerate(var_names): match = re.match(r".+\(([\S]+)\).*", var_name) units = '(1)' if match is not None: units = f"({match.groups()[0]})" axes = my_disp.plot(var_name, subplot_index=(row, col), day_night_background=True) axes.set_ylabel(units) row += 1 if plot_num == 4: col += 1 row = 0 plt.tight_layout() plt.subplots_adjust(hspace=0.4) plt.show()
from act.io.armfiles import read_netcdf from act.plotting import TimeSeriesDisplay from act.tests import EXAMPLE_SURFSPECALB1MLAWER # Read a data file that has a 2D DataArray of multiple 1D data. # The corresponding quality control DataArray is also read in and # will be used to make a summary plot of quality control infomation # of each assessment category. obj = read_netcdf(EXAMPLE_SURFSPECALB1MLAWER) # The name of the data variable we wish to plot var_name = 'surface_albedo_mfr_narrowband_10m' # Create the ACT display object used for plotting. This will have two # vertical plots of 800 by 400 pixels. display = TimeSeriesDisplay(obj, subplot_shape=(2, ), figsize=(8, 2 * 4)) # Create the top plot of data using the force_line_plot option. # This will force the plotting to not assume the data are 2D data that # would normally be plotted as a 2D plot. Rather for each index into the # filter dimention plot a 1D time series plot. Setting labels=True # will create a legend using the filter dimention DataArray. display.plot(var_name, force_line_plot=True, labels=True) # Create the bottom plot of summarized quality control by assessment # cateory. display.qc_flag_block_plot(var_name, subplot_index=(1, )) # Show the plot in a new window. plt.show()
# Clean up the variable attributes to match the needed internal standard. # Setting override_cf_flag allows the flag_meanings to be rewritten using # the better formatted attribute values to make the plot more pretty. obj.clean.clean_arm_state_variables(variable, override_cf_flag=True) # Creat Plot Display by setting figure size and number of plots display = TimeSeriesDisplay(obj, figsize=(12, 8), subplot_shape=(1,)) # Plot the variable and indicate the day/night background should be added # to the plot. # Since the string length for each value is long we can ask to wrap the # text to make a better looking plot by setting the number of characters # to keep per line with the value set to y_axis_flag_meanings. If the # strings were short we can just use y_axis_flag_meanings=True. display.plot(variable, day_night_background=True, y_axis_flag_meanings=18) # Display plot in a new window plt.show() # ----------------------------------------------------------------------- # # This example will plot the 2 dimentional state variable indicating # the cloud type classificaiton. The plot will use the correct formatting # for x and y axis, but will show a colorbar explaining color for each value. # ----------------------------------------------------------------------- # # Read in data to plot. Only read in the variables that will be used. variable = 'cloud_phase_hsrl' obj = read_netcdf(EXAMPLE_CLOUDPHASE) # Clean up the variable attributes to match the needed internal standard. obj.clean.clean_arm_state_variables(variable, override_cf_flag=True)