def test_do_plotting_warning(): test_plot = Display() with pytest.warns(UserWarning) as record: test_plot.do_plotting() # check that only one warning was raised assert len(record) == 1 # check that the message matches assert record[0].message.args[0] == """No plots have been created.
def test_do_plotting_warning(): test_plot = Display() with pytest.warns(UserWarning) as record: test_plot.do_plotting() # check that only one warning was raised assert len(record) == 1 # check that the message matches args = record[0].message.args # type: ignore expected = """No plots have been created. Please call a plotting function before calling 'do_plotting()'""" assert args[0] == expected
def test_Display(): no_args = Display() assert isinstance(no_args.fig, figure.Figure) assert isinstance(no_args.ax, axes.Axes) fig = plt.figure() fig_arg = Display(fig=fig) assert isinstance(fig_arg.fig, figure.Figure) assert isinstance(fig_arg.ax, axes.Axes) assert fig_arg.fig is fig fig = plt.figure() ax = fig.add_subplot(111) both_args = Display(fig=fig, ax=ax) assert isinstance(both_args.fig, figure.Figure) assert isinstance(both_args.ax, axes.Axes) assert both_args.fig is fig assert both_args.ax is ax for obj in [test_tuple, test_list_strs, test_list_ints, test_string, *test_numbers, test_dict]: with pytest.raises(TypeError): Display(fig=obj) with pytest.raises(TypeError): Display(fig=fig, ax=obj) fig = plt.figure() ax = fig.add_subplot(111) with pytest.raises(TypeError): Display(ax, fig)
def display(self): """ Display the Chromatogram """ self.constrain_zoom("x") display = Display(self.fig, self.ax) self.ax.clear() # Read the TIC from the tic.dat file in the experiment tarfile intensity_array, tic = self.experiment.tic_data # peak_list = load_peaks(os.path.join(ExprDir, "{}_peaks.dat".format(self.experiment.name))) display.plot_tic(tic, label=self.experiment.name, minutes=True) # display.plot_peaks(filtered_peak_list, "Peaks") # display.do_plotting('TIC and PyMS Detected Peaks') # display.do_plotting(f'{self.experiment.name} TIC') display.do_plotting('') x = [time / 60 for time in tic.time_list] self.ax.set_xlim(left=0, right=max(x)) self.ax.set_ylim(bottom=0) self.ax.set_xlabel("Retention Time") self.ax.set_ylabel("Intensity") self.fig.subplots_adjust(left=0.1, bottom=0.125, top=0.9, right=0.97) # figure.tight_layout() self.canvas.draw() self.setup_ylim_refresher(intensity_array, x)
area = peak_sum_area(im, peak) peak.area = area # print some details UID = peak.UID # height as sum of the intensities of the apexing ions height = sum(peak.get_mass_spectrum().mass_spec.tolist()) print(UID + f", {rt:.2f}, {height:.2f}, {peak.area:.2f}") # TIC from raw data tic = data.get_tic() # baseline correction for TIC tic_bc = tophat(tic, struct="1.5m") # Get Ion Chromatograms for all m/z channels n_mz = len(im.get_mass_list()) ic_list = [] for m in range(n_mz): ic_list.append(im.get_ic_at_index(m)) # Create a new display object, this time plot the ICs # and the TIC, as well as the peak list display = Display() display.plot_tic(tic_bc, 'TIC BC') for ic in ic_list: display.plot_ic(ic) display.plot_peaks(new_peak_list, 'Peaks') display.do_plotting('TIC, and PyMassSpec Detected Peaks') display.show_chart()
# real_peak_list is PyMassSpec' best guess at the true peak list ################## Run Simulator ###################### # Simulator takes a peak list, time_list and mass_list # and returns an IntensityMatrix object. # The mass_list and time_list are the same for the real # data and the simulated data. time_list = real_im.time_list mass_list = real_im.mass_list sim_im = gcms_sim(time_list, mass_list, real_peak_list) # sim_im is an IntensityMatrix object # select one ic to add noise to from this simulated intensity matrix ic = sim_im.get_ic_at_mass(73) ic_add_noise = copy.deepcopy(ic) # Now add noise to the simulated intensity matrix object scale = 1000 cutoff = 10000 prop = 0.0003 add_gaussv_noise_ic(ic_add_noise, scale, cutoff, prop) display = Display() display.plot_ics([ic, ic_add_noise], ['Without noise', 'With noise added']) display.do_plotting('Simulated IC for m/z = 73, with and without noise')
peak.area = area # real_peak_list is PyMassSpec' best guess at the true peak list ################## Run Simulator ###################### # Simulator takes a peak list, time_list and mass_list # and returns an IntensityMatrix object. # The mass_list and time_list are the same for the real # data and the simulated data. time_list = real_im.time_list mass_list = real_im.mass_list sim_im = gcms_sim(time_list, mass_list, real_peak_list) # sim_im is an IntensityMatrix object # Now add noise to the simulated intensity matrix object scale = 1000 add_gaussc_noise(sim_im, scale) ### Now display the ics from the simulated data ics = [] for i in range(n_mz): ics.append(sim_im.get_ic_at_index(i)) display = Display() for ic in ics: display.plot_ic(ic) display.do_plotting('ICs, and PyMassSpec Detected Peaks of Simulated Data') display.show_chart()
# real_peak_list is PyMassSpec' best guess at the true peak list ################## Run Simulator ###################### # Simulator takes a peak list, time_list and mass_list # and returns an IntensityMatrix object. # The mass_list and time_list are the same for the real # data and the simulated data. time_list = real_im.get_time_list() mass_list = real_im.get_mass_list() sim_im = gcms_sim(time_list, mass_list, real_peak_list) # sim_im is an IntensityMatrix object # select one ic to add noise to from this simulated intensity matrix ic = sim_im.get_ic_at_mass(73) ic_add_noise = copy.deepcopy(ic) # Now add noise to the simulated intensity matrix object scale = 1000 add_gaussc_noise_ic(ic_add_noise, scale) display = Display() display.plot_ic(ic, label="Without Noise") display.plot_ic(ic_add_noise, label="With Noise Added") display.do_plotting('Simulated IC for m/z = 73, with and without noise') display.show_chart()
def test_plot(): fig = plt.figure() ax = fig.add_subplot(111) test_plot = Display(fig, ax) return test_plot
# Set the peak areas for peak in real_peak_list: area = peak_sum_area(real_im, peak) peak.area = area # real_peak_list is PyMassSpec' best guess at the true peak list ################## Run Simulator ###################### # Simulator takes a peak list, time_list and mass_list # and returns an IntensityMatrix object. # The mass_list and time_list are the same for the real # data and the simulated data. time_list = real_im.get_time_list() mass_list = real_im.get_mass_list() sim_im = gcms_sim(time_list, mass_list, real_peak_list) # sim_im is an IntensityMatrix object ### Now display the ics from the simulated data ics = [] for i in range(n_mz): ics.append(sim_im.get_ic_at_index(i)) display = Display() for ic in ics: display.plot_ic(ic) display.do_plotting('ICs of Simulated Data') display.show_chart()