예제 #1
0
def test_find_free_filename():
    path = os.path.dirname(__file__)
    assert sf.find_free_filename(
        path, "test_support_functions",
        ".py") == path + "test_support_functions(1).py"
    assert sf.find_free_filename(path, "doesntexist",
                                 ".dumb") == path + "doesntexist.dumb"
    def imsave(self,
               cmap="jet",
               log=False,
               title="Image of Data",
               savename="CCDPic",
               extension=".png"):
        """Saves the calibrated data."""
        try:
            assert isinstance(title, str), "title must be a string"
            assert isinstance(savename, str), "filename must be a string"
            assert isinstance(extension, str), "extension must be a string"
        except AssertionError as excep:
            raise self._error(excep) from excep

        for i in range(len(self.data)):
            fig = plt.figure(figsize=[15, 10.5])
            ax = fig.add_subplot(111)
            ax.set_title("Exposure Time =" +
                         str(round(self.data.time()[i], 6)))
            self._imshow(fig, ax, self.data.data()[i], cmap, log)
            if i == 0:
                fig.suptitle(title)
            else:
                fig.suptitle(title + " " + i)
            fig.savefig(
                sf.find_free_filename(self.savepath, savename, extension))
            plt.close(fig)
예제 #3
0
    def slicesave(self,
                  position=[None, None],
                  title="Slice of Data",
                  fit=False,
                  log=False,
                  savename="Slice",
                  extension=".png"):
        try:
            assert isinstance(title, str), "title must be a string"
            assert isinstance(savename, str), "savename must be a string"
            assert isinstance(extension, str), "extension must be a string"
        except AssertionError as excep:
            raise self._error(excep) from excep

        best_pos = self._find_slice_pos(position)
        for i in range(len(self.data)):
            fig = plt.figure(figsize=[15, 10.5])
            self._slicing(fig,
                          self.data.data()[i],
                          self.data.time()[i], best_pos[i], fit, log)
            if i == 0:
                fig.suptitle(title)
            else:
                fig.suptitle(title + " " + str(i))

            full_filename = sf.find_free_filename(self.savepath, savename,
                                                  extension)
            fig.savefig(full_filename)
            plt.close(fig)
예제 #4
0
    def save(self, title="Image of Data", log=False, both=False, savename="FocusPic", extension=".png"):
        """Saves the calibrated data."""
        try:
            assert isinstance(title, str), "title must be a string"
            assert isinstance(savename, str), "filename must be a string"
            assert isinstance(extension, str), "extension must be a string"
        except AssertionError as excep:
            raise self.error(excep) from excep

        for i in self.focus:
            fig = plt.figure(figsize=[15, 10.5])
            if both is True:
                ax1 = fig.add_subplot(211)
                ax2 = fig.add_subplot(212)
                ax1.set_title("Variation along x-axis")
                ax2.set_title("Variation along y-axis")
                sliced1 = i[:, self.delta, :].transpose()
                sliced2 = i[:, :, self.delta].transpose()
                self._show(sliced1, fig, ax1, log)
                self._show(sliced2, fig, ax2, log)
            else:
                ax = fig.add_subplot(111)
                sliced = i[:, self.delta, :].transpose()
                self._show(sliced, fig, ax, log)
            fig.suptitle(title)
            fig.savefig(sf.find_free_filename(self.savepath, savename, extension))
            plt.close(fig)
예제 #5
0
    def slicesave(self, zpos, position=[None, None], title="Slice of Data", log=False, both=False, fit=False,
                  overlap=False, savename="Slice", extension=".png"):
        try:
            assert isinstance(title, str), "title must be a string"
            assert isinstance(savename, str), "savename must be a string"
            assert isinstance(extension, str), "extension must be a string"
        except AssertionError as excep:
            raise self._error(excep) from excep

        data = self.focus[:, zpos]
        z = self.z[zpos]
        for i in range(len(data)):
            _data = data[i]
            axial_distr = self.focus[i, :, self.delta, self.delta]
            loc = np.argwhere(axial_distr == np.max(axial_distr)).reshape(-1)[0]
            fig = plt.figure(figsize=[15, 10.5])
            ax3 = fig.add_subplot(212)
            self._imshow(fig, ax3, _data, "jet", log)
            ax3.set_title(r"z = {} $\mu$m".format(round((z - self.z[loc]) * 1e6, 2)))
            ps = self.pixel_size * 1e6
            ax3.axhline(0, color="blue")
            if both is True:
                ax3.axvline(0, color="red")
                ax1 = fig.add_subplot(221)
                ax2 = fig.add_subplot(222)
                self._slice1D(ax2, _data[:, self.delta], fit, ps, "red")
                ax2.set_ylim(ymin=_data[:, self.delta].min(), ymax=_data[:, self.delta].max())
                ax2.set_xlabel(r"position ($\mu$m)")
                if log is not False:
                    ax1.semilogy()
                    ax2.semilogy()
            else:
                ax1 = fig.add_subplot(211)
                if log is not False:
                    ax1.semilogy()
                if overlap is True:
                    ax3.axvline(0, color="red")
                    self._slice1D(ax1, _data[:, self.delta], fit, ps, "red")
            self._slice1D(ax1, _data[self.delta, :], fit, ps, "blue")
            if overlap is True:
                ymin = np.min([_data[self.delta, :].min(), _data[:, self.delta].min()])
                ymax = np.max([_data[self.delta, :].max(), _data[:, self.delta].max()])
            else:
                ymin = _data[self.delta, :].min()
                ymax = _data[self.delta, :].max()
            ax1.set_ylim(ymin=ymin, ymax=ymax)
            ax1.set_xlabel(r"position ($\mu$m)")
            ax1.set_ylabel("Counts/s")
            if i == 0:
                fig.suptitle(title)
            else:
                fig.suptitle(title + " " + str(i))

            full_filename = sf.find_free_filename(self.savepath, savename, extension)
            fig.savefig(full_filename)
            plt.close(fig)
예제 #6
0
    def powersave(self,
                  title="Image of Data",
                  savename="FitsPicture",
                  extension=".png"):
        try:
            assert isinstance(title, str), "title must be a string"
            assert isinstance(savename, str), "savename must be a string"
            assert isinstance(extension, str), "extension must be a string"
        except AssertionError as excep:
            raise self._error(excep) from excep

        p = self.cum_power_fraction_within_area()
        for i in range(len(p)):
            full_filename = sf.find_free_filename(self.savepath, savename,
                                                  extension)
            fig = self._power(p[i])
            if i == 0:
                fig.suptitle(title)
            else:
                fig.suptitle(title + " " + i)
            fig.savefig(full_filename)
            plt.close(fig)
예제 #7
0
    def imsave(self, zpos, log=False, title="Image of Data", savename="CCDPic", extension=".png"):
        try:
            assert isinstance(zpos, int), "zpos must be an integer"
            assert isinstance(title, str), "title must be a string"
            assert isinstance(savename, str), "filename must be a string"
            assert isinstance(extension, str), "extension must be a string"
        except AssertionError as excep:
            raise self._error(excep)

        data = self.focus[:, zpos]
        z = self.z[zpos]
        for i in range(len(data)):
            axial_distr = self.focus[i, :, self.delta, self.delta]
            loc = np.argwhere(axial_distr == np.max(axial_distr)).reshape(-1)[0]
            fig = plt.figure(figsize=[15, 10.5])
            ax = fig.add_subplot(111)
            ax.set_title(r"z = {} $\mu$m".format(round((z - self.z[loc]) * 1e6, 2)))
            self._imshow(fig, ax, data[i], "jet", log)
            if i == 0:
                fig.suptitle(title)
            else:
                fig.suptitle(title + " " + i)
            fig.savefig(sf.find_free_filename(self.savepath, savename, extension))
            plt.close(fig)
예제 #8
0
 def characterise_save(self, plot=False, filename="Characteristics_focus"):
     text = self.characterise(plot)
     fullfilename = sf.find_free_filename(self.savepath, filename, ".txt")
     with open(fullfilename, "w") as f:
         f.write(text)