예제 #1
0
파일: Burrow.py 프로젝트: k-eks/Burrow
    def do_plothkl(self, argument):
        """plots a section of meerkat"""
        """Has some hard coded undistortion functions in it."""
        out.warn("Only poor error checking implemented!")
        out.warn("Only suitable for trigonal and hexagonal crystals!")
        errorcode, arguments = self.getArg(argument)
        if errorcode != ERROR_NO_ARGUMENTS and errorcode != ERROR_ODD_ARGUMENTS:
            index = 0 # default value
            if "-s" in arguments:
                section = arguments[arguments.index("-s") + 1]
            if "-i" in arguments:
                index = arguments[arguments.index("-i") + 1]

            if self.meta.format == mt.MeerkatMetaData.dtype_NORMAL:
                trans = ad.Transformations(self.dataset, section)
                self.currentData, x = ad.crossection_data(self.dataset, float(index), trans)
            else:
                slicer = mt.get_slicing_indices(section, int(index), self.meta.shape)
                # be careful: the slicing in i,:,: does a weird x-y swap
                self.currentData = (self.dataset['data'][slicer[0]:slicer[1],slicer[2]:slicer[3],slicer[4]:slicer[5]]).squeeze()
            self.currentData = np.tile(self.currentData, (1,1))
            # the following block is the hard coded undistortion of my trigonal crystals
            if section == "hkx":
                self.currentData = ad.hextransform(self.currentData)
            elif section == "xkl" or section == "hxl":
                # counteracting the weird slicing
                a = math.radians(90)
                T = np.array([[math.cos(a), math.sin(a)],[-math.sin(a), math.cos(a)]])
                self.currentData = ad.imtransform_centered(self.currentData, T)

            self.replot()
        elif errorcode == ERROR_NO_ARGUMENTS:
            out.error("No arguments supplied!")
예제 #2
0
파일: Burrow.py 프로젝트: k-eks/Burrow
 def do_openFile(self, argument):
     """Opens a given file."""
     errorcode, arguments = self.getArg(argument)
     filename = "reconstruction.h5" # a default filename is assumed
     filealias = "default" # a default name is assumed
     if errorcode != ERROR_ODD_ARGUMENTS:
         if "-n" in arguments:
             filename = arguments[arguments.index("-n") + 1]
         else:
             out.warn("No file name is given! Trying default name \"" + filename + "\".")
         if "-a" in arguments:
             filealias = arguments[arguments.index("-a") + 1]
         if os.path.isfile(filename):
             #TODO:requires replacement with arkadiy's routine
             file = h5py.File(filename, 'r')
             out.okay("File successfully opened as " + filealias + "!")
             self.activeDset = filealias
             pyplot.close("all") # to prevent display issues
             if filealias in self.dsetName:
                 self.dset[self.dsetName.index(filealias)] = file
             else:
                 self.dset.append(file)
                 self.dsetName.append(filealias)
             self.meta = mt.MeerkatMetaData(self.dataset)
             out.warn("Active data set is now " + filealias)
         else:
             out.error("File \"" + filename + "\" does not exist!")
예제 #3
0
파일: Burrow.py 프로젝트: k-eks/Burrow
 def do_info(self, argument):
     """Prints the meta data."""
     if self.meta != None:
         errorcode, arguments = self.getArg(argument)
         if errorcode != self.CODE_ODD_ARGUMENTS:
             options = "nafsit"
             if "-p" in arguments:
                 options = arguments[arguments.index("-p") + 1]
             if "n" in options:
                 print("Active file name: %s" %
                       os.path.split(self.dataset.filename)[1])
             if "a" in options:
                 print("Active file alias: %s" % self.activeDset)
             if "f" in options: print("File format: %s" % self.meta.format)
             if "s" in options:
                 print("Pixel dimensions: x = %s, y = %s, z = %s" %
                       tuple(self.meta.shape))
             if self.meta.format == mt.MeerkatMetaData.dtype_NORMAL:  # others do not have the fields
                 if "i" in options:
                     print("Pixel dimensions: h = %s, k = %s, l = %s" %
                           tuple(self.meta.hklRange))
                 if "t" in options:
                     print(
                         "Pixel dimensions: h/x = %s, k/y = %s, l/z = %s" %
                         tuple(self.meta.steps))
     else:
         out.error("Open a data file first!")
예제 #4
0
파일: Burrow.py 프로젝트: k-eks/Burrow
 def help_openFile(self):
     """openFile help page entry."""
     print("Opens a h5 file, either in meerkat or direct format.")
     out.error("Only meerkat data format implemented at the moment!")
     print("Arguments:")
     print("\t-n <file name>\tspecifies the file name, if not given \"reconstruction.h5\" is assumed.")
     print("\t-a <file alias>\tspecifies the alias for the data under which it can be called , if not given \"default\" is assumed.")
예제 #5
0
파일: Burrow.py 프로젝트: k-eks/Burrow
 def do_openFile(self, argument):
     """Opens a given file."""
     errorcode, arguments = self.getArg(argument)
     filename = "reconstruction.h5"  # a default filename is assumed
     filealias = "default"  # a default name is assumed
     if errorcode != ERROR_ODD_ARGUMENTS:
         if "-n" in arguments:
             filename = arguments[arguments.index("-n") + 1]
         else:
             out.warn("No file name is given! Trying default name \"" +
                      filename + "\".")
         if "-a" in arguments:
             filealias = arguments[arguments.index("-a") + 1]
         if os.path.isfile(filename):
             #TODO:requires replacement with arkadiy's routine
             file = h5py.File(filename, 'r')
             out.okay("File successfully opened as " + filealias + "!")
             self.activeDset = filealias
             pyplot.close("all")  # to prevent display issues
             if filealias in self.dsetName:
                 self.dset[self.dsetName.index(filealias)] = file
             else:
                 self.dset.append(file)
                 self.dsetName.append(filealias)
             self.meta = mt.MeerkatMetaData(self.dataset)
             out.warn("Active data set is now " + filealias)
         else:
             out.error("File \"" + filename + "\" does not exist!")
예제 #6
0
파일: Burrow.py 프로젝트: k-eks/Burrow
 def do_saveData(self, argument):
     """Saves the last displayed image as a csv file."""
     errorcode, arguments = self.getArg(argument)
     if errorcode != ERROR_NO_ARGUMENTS and errorcode != ERROR_ODD_ARGUMENTS:
         if "-o" in arguments:
             outfile = arguments[arguments.index("-o") + 1]
             data = np.asarray(self.currentData)
             np.savetxt(outfile, data, delimiter=";")
             out.okay("Successfully saved as " + outfile + "!")
         else:
             out.error("No output name given!")
예제 #7
0
파일: Burrow.py 프로젝트: k-eks/Burrow
 def help_openFile(self):
     """openFile help page entry."""
     print("Opens a h5 file, either in meerkat or direct format.")
     out.error("Only meerkat data format implemented at the moment!")
     print("Arguments:")
     print(
         "\t-n <file name>\tspecifies the file name, if not given \"reconstruction.h5\" is assumed."
     )
     print(
         "\t-a <file alias>\tspecifies the alias for the data under which it can be called , if not given \"default\" is assumed."
     )
예제 #8
0
파일: Burrow.py 프로젝트: k-eks/Burrow
 def do_saveData(self, argument):
     """Saves the last displayed image as a csv file."""
     errorcode, arguments = self.getArg(argument)
     if errorcode != ERROR_NO_ARGUMENTS and errorcode != ERROR_ODD_ARGUMENTS:
         if "-o" in arguments:
             outfile = arguments[arguments.index("-o") + 1]
             data = np.asarray(self.currentData)
             np.savetxt(outfile, data, delimiter=";")
             out.okay("Successfully saved as " + outfile + "!")
         else:
             out.error("No output name given!")
예제 #9
0
파일: Burrow.py 프로젝트: k-eks/Burrow
 def getArg(self, line):
     """Splits the arguments and checks if the correct number of arguments are given."""
     errorcode = NO_ERROR
     arguments = str(line).split()
     if len(arguments) == 0:  #no arguments supplied
         arguments = ""
         errorcode = ERROR_NO_ARGUMENTS
     elif len(arguments) % 2 != 0:  #invalid number of arguments
         arguments = ""
         errorcode = ERROR_ODD_ARGUMENTS
         out.error("Invalid number of arguments!")
     return errorcode, arguments
예제 #10
0
파일: Burrow.py 프로젝트: k-eks/Burrow
 def getArg(self, line):
     """Splits the arguments and checks if the correct number of arguments are given."""
     errorcode = NO_ERROR
     arguments = str(line).split()
     if len(arguments) == 0: #no arguments supplied
         arguments = ""
         errorcode = ERROR_NO_ARGUMENTS
     elif len(arguments) % 2 != 0: #invalid number of arguments
         arguments = ""
         errorcode = ERROR_ODD_ARGUMENTS
         out.error("Invalid number of arguments!")
     return errorcode, arguments
예제 #11
0
파일: Burrow.py 프로젝트: k-eks/Burrow
 def do_saveImage(self, argument):
     """Saves the last displayed image as a csv file."""
     errorcode, arguments = self.getArg(argument)
     if self.currentImage != None:
         if errorcode != ERROR_NO_ARGUMENTS and errorcode != ERROR_ODD_ARGUMENTS:
             if "-o" in arguments:
                 outfile = arguments[arguments.index("-o") + 1]
                 self.currentImage.save(outfile)
                 out.okay("Successfully saved as " + outfile + "!")
             else:
                 out.error("No output name given!")
     else:
         out.error("No image in buffer to save!")
예제 #12
0
파일: Burrow.py 프로젝트: k-eks/Burrow
 def do_saveImage(self, argument):
     """Saves the last displayed image as a csv file."""
     errorcode, arguments = self.getArg(argument)
     if self.currentImage != None:
         if errorcode != ERROR_NO_ARGUMENTS and errorcode != ERROR_ODD_ARGUMENTS:
             if "-o" in arguments:
                 outfile = arguments[arguments.index("-o") + 1]
                 self.currentImage.save(outfile)
                 out.okay("Successfully saved as " + outfile + "!")
             else:
                 out.error("No output name given!")
     else:
         out.error("No image in buffer to save!")
예제 #13
0
파일: Burrow.py 프로젝트: k-eks/Burrow
 def do_layout(self, argument):
     """Changes the layout of pyplot."""
     errorcode, arguments = self.getArg(argument)
     if self.activeDset != None:
         if errorcode != ERROR_NO_ARGUMENTS and errorcode != ERROR_ODD_ARGUMENTS:
             if "-min" in arguments:
                 self.contrast_min = float(
                     arguments[arguments.index("-min") + 1])
             if "-max" in arguments:
                 self.contrast_max = float(
                     arguments[arguments.index("-max") + 1])
             if "-c" in arguments:
                 self.cmap_selection = int(arguments[arguments.index("-c") +
                                                     1])
                 if self.cmap_selection >= len(
                         self.cmaps) or self.cmap_selection < 0:
                     out.error("Unknown color map index.")
                     self.cmap_selection = 0
                     out.warn("Color map set to default.")
             if "-scale" in arguments:
                 if (arguments[arguments.index("-scale") + 1]
                         == self.LIN_SCALE) or (
                             arguments[arguments.index("-scale") + 1]
                             == self.LOG_SCALE):
                     self.plotscale = arguments[arguments.index("-scale") +
                                                1]
                 else:
                     out.error("Unknown scale!")
             self.replot()
         elif errorcode != ERROR_NO_ARGUMENTS:
             out.error("Input required!")
     else:
         out.error("No data selected!")
예제 #14
0
파일: Burrow.py 프로젝트: k-eks/Burrow
 def do_layout(self, argument):
     """Changes the layout of pyplot."""
     errorcode, arguments = self.getArg(argument)
     if self.activeDset != None:
         if errorcode != ERROR_NO_ARGUMENTS and errorcode != ERROR_ODD_ARGUMENTS:
             if "-min" in arguments:
                 self.contrast_min = float(arguments[arguments.index("-min") + 1])
             if "-max" in arguments:
                 self.contrast_max = float(arguments[arguments.index("-max") + 1])
             if "-c" in arguments:
                 self.cmap_selection = int(arguments[arguments.index("-c") + 1])
                 if self.cmap_selection >= len(self.cmaps) or self.cmap_selection < 0:
                     out.error("Unknown color map index.")
                     self.cmap_selection = 0
                     out.warn("Color map set to default.")
             if "-scale" in arguments:
                 if (arguments[arguments.index("-scale") + 1] == self.LIN_SCALE) or (arguments[arguments.index("-scale") + 1] == self.LOG_SCALE):
                     self.plotscale = arguments[arguments.index("-scale") + 1]
                 else:
                     out.error("Unknown scale!")
             self.replot()
         elif errorcode != ERROR_NO_ARGUMENTS:
             out.error("Input required!")
     else:
         out.error("No data selected!")
예제 #15
0
파일: Burrow.py 프로젝트: k-eks/Burrow
 def do_info(self, argument):
     """Prints the meta data."""
     if self.meta != None:
         errorcode, arguments = self.getArg(argument)
         if errorcode != self.CODE_ODD_ARGUMENTS:
             options = "nafsit"
             if "-p" in arguments:
                 options = arguments[arguments.index("-p") + 1]
             if "n" in options: print("Active file name: %s" % os.path.split(self.dataset.filename)[1])
             if "a" in options: print("Active file alias: %s" % self.activeDset)
             if "f" in options: print("File format: %s" % self.meta.format)
             if "s" in options: print("Pixel dimensions: x = %s, y = %s, z = %s" % tuple(self.meta.shape))
             if self.meta.format == mt.MeerkatMetaData.dtype_NORMAL: # others do not have the fields
                 if "i" in options: print("Pixel dimensions: h = %s, k = %s, l = %s" % tuple(self.meta.hklRange))
                 if "t" in options: print("Pixel dimensions: h/x = %s, k/y = %s, l/z = %s" % tuple(self.meta.steps))
     else:
         out.error("Open a data file first!")
예제 #16
0
파일: Burrow.py 프로젝트: k-eks/Burrow
 def do_setActive(self, argument):
     """Activates a dataset."""
     errorcode, arguments = self.getArg(argument)
     alias = "default"  #default value
     if errorcode != ERROR_NO_ARGUMENTS and errorcode != ERROR_ODD_ARGUMENTS:
         if "-a" in arguments:
             alias = arguments[arguments.index("-a") + 1]
         else:
             out.warn("No arguments supplied, trying default.")
         if alias in self.dsetName:
             self.activeDset = alias
             self.meta = mt.MeerkatMetaData(self.dataset)
             pyplot.close("all")  #in order to prevent display issues
             out.okay("Activated " + alias + "!")
         else:
             out.error(alias + " not found!")
     elif errorcode == ERROR_NO_ARGUMENTS:
         out.error("No arguments supplied!")
예제 #17
0
파일: Burrow.py 프로젝트: k-eks/Burrow
 def do_setActive(self, argument):
     """Activates a dataset."""
     errorcode, arguments = self.getArg(argument)
     alias = "default" #default value
     if errorcode != ERROR_NO_ARGUMENTS and errorcode != ERROR_ODD_ARGUMENTS:
         if "-a" in arguments:
             alias = arguments[arguments.index("-a") + 1]
         else:
             out.warn("No arguments supplied, trying default.")
         if alias in self.dsetName:
             self.activeDset = alias
             self.meta = mt.MeerkatMetaData(self.dataset)
             pyplot.close("all") #in order to prevent display issues
             out.okay("Activated " + alias + "!")
         else:
             out.error(alias + " not found!")
     elif errorcode == ERROR_NO_ARGUMENTS:
         out.error("No arguments supplied!")
예제 #18
0
파일: Burrow.py 프로젝트: k-eks/Burrow
    def do_plothkl(self, argument):
        """plots a section of meerkat"""
        """Has some hard coded undistortion functions in it."""
        out.warn("Only poor error checking implemented!")
        out.warn("Only suitable for trigonal and hexagonal crystals!")
        errorcode, arguments = self.getArg(argument)
        if errorcode != ERROR_NO_ARGUMENTS and errorcode != ERROR_ODD_ARGUMENTS:
            index = 0  # default value
            if "-s" in arguments:
                section = arguments[arguments.index("-s") + 1]
            if "-i" in arguments:
                index = arguments[arguments.index("-i") + 1]

            if self.meta.format == mt.MeerkatMetaData.dtype_NORMAL:
                trans = ad.Transformations(self.dataset, section)
                self.currentData, x = ad.crossection_data(
                    self.dataset, float(index), trans)
            else:
                slicer = mt.get_slicing_indices(section, int(index),
                                                self.meta.shape)
                # be careful: the slicing in i,:,: does a weird x-y swap
                self.currentData = (
                    self.dataset['data'][slicer[0]:slicer[1],
                                         slicer[2]:slicer[3],
                                         slicer[4]:slicer[5]]).squeeze()
            self.currentData = np.tile(self.currentData, (1, 1))
            # the following block is the hard coded undistortion of my trigonal crystals
            if section == "hkx":
                self.currentData = ad.hextransform(self.currentData)
            elif section == "xkl" or section == "hxl":
                # counteracting the weird slicing
                a = math.radians(90)
                T = np.array([[math.cos(a), math.sin(a)],
                              [-math.sin(a), math.cos(a)]])
                self.currentData = ad.imtransform_centered(self.currentData, T)

            self.replot()
        elif errorcode == ERROR_NO_ARGUMENTS:
            out.error("No arguments supplied!")
예제 #19
0
파일: Burrow.py 프로젝트: k-eks/Burrow
    def plot2img(self, figure):
        """Converts a pyplot figure into a PIL image by the use of the buffer."""
        buf = io.BytesIO()
        pyplot.savefig(buf, format='png')
        buf.seek(0)
        return Image.open(buf)

    #offblock
    #end of internal functions
    #offblock

if __name__ == '__main__':
    """Main loop creation, can run in terminal mode or script mode."""
    if len(
            sys.argv
    ) == 2:  # in this case, it is assumed that the user provides a file with a list of commands
        input = open(sys.argv[1], 'rt')
        try:
            # setting up silent script mode
            interpreter = Burrow(stdin=input)
            interpreter.use_rawinput = False  # required for file input to read new lines etc correctly
            interpreter.prompt = ""  # silent mode
            interpreter.cmdloop()
        finally:
            input.close()
    elif len(sys.argv) == 1:  # plain old commandline
        interpreter = Burrow()
        interpreter.cmdloop()
    else:
        out.error("Wrong input, <none> or <script filename> expected!")
예제 #20
0
파일: Burrow.py 프로젝트: k-eks/Burrow
        pyplot.show()

    #onblock convertion of images und plots
    def plot2img(self, figure):
        """Converts a pyplot figure into a PIL image by the use of the buffer."""
        buf = io.BytesIO()
        pyplot.savefig(buf, format='png')
        buf.seek(0)
        return Image.open(buf)
    #offblock
    #end of internal functions
    #offblock

if __name__ == '__main__':
    """Main loop creation, can run in terminal mode or script mode."""
    if len(sys.argv) == 2: # in this case, it is assumed that the user provides a file with a list of commands
        input = open(sys.argv[1], 'rt')
        try:
            # setting up silent script mode
            interpreter = Burrow(stdin=input)
            interpreter.use_rawinput = False # required for file input to read new lines etc correctly
            interpreter.prompt = "" # silent mode
            interpreter.cmdloop()
        finally:
            input.close()
    elif len(sys.argv) == 1: # plain old commandline
        interpreter = Burrow()
        interpreter.cmdloop()
    else:
        out.error("Wrong input, <none> or <script filename> expected!")