def end(self, discard=False): if discard: plt.close() return # backup previous lineage file previous_file = "data/cell_lines/lineage{0:02d}.npy".format(self.lineage_num) if os.path.exists(previous_file): if not os.path.exists("data/cell_lines/backups"): os.mkdir("data/cell_lines/backups") backup_file = "data/cell_lines/backups/{0}-lineage{1:02d}.npy".format( datetime.datetime.strftime(datetime.datetime.now(), "%Y%m%d-%H%M"), self.lineage_num ) attempt = 2 while os.path.exists(backup_file): first = backup_file.split(".npy")[0] backup_file = "{0}.npy-{1}".format(first, attempt) attempt += 1 print("Backing up previous lineage file to {0}".format(backup_file)) os.rename(previous_file, backup_file) print("Saving new lineage file") np.save( "data/cell_lines/lineage{0:02d}".format(self.lineage_num), self.cell_line ) if self.GEN_PLOTS: print("Saving new PDFs") spot_plot.plot_images(self.cell_line, int(self.lineage_num)) spot_plot.plot_graphs(self.cell_line, int(self.lineage_num), um=True) spot_spread.gen_xl(self.cell_line, int(self.lineage_num)) plt.close(self.fig)