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_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_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_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_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_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_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)