From 6ef853471c7ea630bdb2d4b62713e8379b360c50 Mon Sep 17 00:00:00 2001 From: Israel Silber <55999320+isilber@users.noreply.github.com> Date: Mon, 4 Nov 2024 15:23:20 -0800 Subject: [PATCH] DEP: remove/fix deprecated objects/command (#124) * DEP: remove/fix deprecated objects/command --- emc2/core/model.py | 14 +++++++------- emc2/io/load_mie_file.py | 2 +- tests/test_plotting.py | 22 +++++++++++----------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/emc2/core/model.py b/emc2/core/model.py index 86a377c9..8ee428df 100644 --- a/emc2/core/model.py +++ b/emc2/core/model.py @@ -252,7 +252,7 @@ def num_subcolumns(self): Gets the number of subcolumns in the model. Will return 0 if the number of subcolumns has not yet been set. """ - if 'subcolumn' in self.ds.dims.keys(): + if 'subcolumn' in self.ds.dims: return self.ds.dims['subcolumn'] else: return 0 @@ -378,15 +378,15 @@ def check_and_stack_time_lat_lon(self, out_coord_name="time_lat_lon", file_path= do_process = 0 # 0 - do nothing, 1 - stack lat+lon, 2 - stack lat dim only # Add time dimension for processing (remove later if length = 1) - if not self.time_dim in [x for x in self.ds.dims.keys()]: + if not self.time_dim in [x for x in self.ds.dims]: self.ds = self.ds.expand_dims(self.time_dim) # Check to make sure we are loading a single column - if self.lat_dim in [x for x in self.ds.dims.keys()]: - if self.ds.dims[self.lat_dim] != 1: + if self.lat_dim in [x for x in self.ds.dims]: + if self.ds.sizes[self.lat_dim] != 1: do_process = 1 - if self.lon_dim in [x for x in self.ds.dims.keys()]: - if self.ds.dims[self.lon_dim] != 1: + if self.lon_dim in [x for x in self.ds.dims]: + if self.ds.sizes[self.lon_dim] != 1: do_process = 1 elif do_process == 1: do_process = 2 @@ -411,7 +411,7 @@ def check_and_stack_time_lat_lon(self, out_coord_name="time_lat_lon", file_path= self.ds = self.ds.stack({out_coord_name: (self.lat_dim, self.time_dim)}) self.stacked_time_dim, self.time_dim = self.time_dim, out_coord_name else: - if self.lon_dim in [x for x in self.ds.dims.keys()]: + if self.lon_dim in [x for x in self.ds.dims]: # No need for lat and lon dimensions self.ds = self.ds.squeeze(dim=(self.lat_dim, self.lon_dim)) else: diff --git a/emc2/io/load_mie_file.py b/emc2/io/load_mie_file.py index 7c2477ce..132ee6ed 100644 --- a/emc2/io/load_mie_file.py +++ b/emc2/io/load_mie_file.py @@ -18,7 +18,7 @@ def load_mie_file(filename): descriptive metadata. """ - my_df = pd.read_csv(filename, delim_whitespace=True, + my_df = pd.read_csv(filename, sep='\s+', names=["wavelength", "p_diam", "size_parameter", "compre_real", "compre_im", "scat_p", "alpha_p", "beta_p", "scat_eff", "ext_eff", "backscat_eff"]) diff --git a/tests/test_plotting.py b/tests/test_plotting.py index 0f8f7efd..fb59ae7c 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -12,7 +12,7 @@ def test_plot_timeseries(): model_display.plot_subcolumn_timeseries('sub_col_Ze_cl_strat', 2, subplot_index=(1, 0)) model_display.plot_subcolumn_timeseries('sub_col_Ze_cl_strat', 3, subplot_index=(0, 1)) model_display.plot_subcolumn_timeseries('sub_col_Ze_cl_strat', 4, subplot_index=(1, 1)) - return model_display.fig + assert model_display.fig @pytest.mark.mpl_image_compare(tolerance=30) @@ -21,7 +21,7 @@ def test_plot_single_time(): model_display = emc2.plotting.SubcolumnDisplay(model, ds_name="ModelE", figsize=(10, 10)) model_display.plot_single_profile('sub_col_Ze_cl_strat', time='2016-08-16T09:30:00') - return model_display.fig + assert model_display.fig @pytest.mark.mpl_image_compare(tolerance=30) @@ -30,7 +30,7 @@ def test_plot_profile(): model_display = emc2.plotting.SubcolumnDisplay(model, ds_name="ModelE", figsize=(10, 10)) model_display.plot_subcolumn_mean_profile('sub_col_Ze_cl_strat', time='2016-08-16T09:30:00') - return model_display.fig + assert model_display.fig @pytest.mark.mpl_image_compare(tolerance=30) @@ -44,7 +44,7 @@ def test_plot_instrument(): subplot_index=(0, 0), vmin=0.0, vmax=0.5) model_display.plot_instrument_timeseries(HSRL, "beta_a_backscat", log_plot=True, cmap='magma', subplot_index=(0, 1), vmin=1e-8, vmax=1e-3) - return model_display.fig + assert model_display.fig @pytest.mark.mpl_image_compare(tolerance=30) @@ -55,7 +55,7 @@ def test_plot_instrument_profile(): model_display = emc2.plotting.SubcolumnDisplay(model, ds_name="ModelE", figsize=(10, 10)) model_display.plot_instrument_mean_profile(HSRL, 'linear_depol', pressure_coords=False) - return model_display.fig + assert model_display.fig @pytest.mark.mpl_image_compare(tolerance=30) @@ -66,7 +66,7 @@ def test_plot_classification(): _, cb = model_display.plot_subcolumn_timeseries('phase_mask_KAZR_sounding_all_hyd', 1) model_display.change_plot_to_class_mask(cb, variable="phase_mask_KAZR_sounding_all_hyd", class_legend=["Cloud", "precip", "mixed"]) - return model_display.fig + assert model_display.fig @pytest.mark.mpl_image_compare(tolerance=30) @@ -104,7 +104,7 @@ def test_plot_SR_subcol_timeseries(): Ncolumns, Npoints, Nlevels, Nglevels, col_num, newgrid_bot, newgrid_top) emc2.statistics_LLNL.statistical_plots.plot_every_subcolumn_timeseries_SR( my_e3sm, atb_total_4D, atb_mol_4D, col_index, '', '', 'addpl_rad') - return plt.gcf() + assert plt.gcf() @pytest.mark.mpl_image_compare(tolerance=30) @@ -164,7 +164,7 @@ def test_plot_get_CFAD_SR(): cfadSR_cal_alltime = np.nanmean(cfadSR_cal_alltime_col, axis=2) emc2.statistics_LLNL.statistical_plots.plot_lidar_SR_CFAD( SR_EDGES, newgrid_mid, cfadSR_cal_alltime, '', '', 'addpl_rad') - return plt.gcf() + assert plt.gcf() @pytest.mark.mpl_image_compare(tolerance=30) @@ -224,7 +224,7 @@ def test_plot_regridded_CF_timeseries(): CF_3D, newgrid_mid, col_index, y_range=y_range, cmap=cmap, title='', vmin=vmin_max[ii][0], vmax=vmin_max[ii][1], cbar_label=cbar_label[ii]) - return model_display3.fig + assert model_display3.fig @pytest.mark.mpl_image_compare(tolerance=30) @@ -262,7 +262,7 @@ def test_plot_subcolumn_timeseries(): field_to_plot[ii], subcol_ind, log_plot=log_plot[ii], y_range=y_range, subplot_index=(0, ii), cmap=cmap, title='', vmin=vmin_max[ii][0], vmax=vmin_max[ii][1], pressure_coords=False) - return model_display.fig + assert model_display.fig @pytest.mark.mpl_image_compare(tolerance=30) @@ -280,4 +280,4 @@ def test_plotting_every_subcolumn_timeseries_radarlidarsignal(): unstack_dims=True, finalize_fields=True, use_rad_logic=True) emc2.statistics_LLNL.statistical_plots.plot_every_subcolumn_timeseries_radarlidarsignal( my_e3sm, col_index, '', '', 'addpl_radiation') - return plt.gcf() + assert plt.gcf()