示例#1
0
文件: DSLR_LYR.py 项目: paalge/paskil
    def open(self, image_filename, info_filename):

        image = Image.open(image_filename)

        # Read site info file
        camera = {}
        processing = {}
        header = image.info

        with open(info_filename, "r") as info_file:
            for line in info_file:  # read file line by line
                if line.isspace():
                    continue  # ignore blank lines
                words = line.split("=")  # split the line at the = sign

                if len(words) != 2:
                    print("Error! allskyImagePlugins.DSLR_LYR.open(): Cannot read site info file, too many words per line")
                    sys.exit()

                # store the values (minus white space) in a dictionary
                camera[words[0].lstrip().rstrip()] = words[1].lstrip().rstrip()

        # Read creation time from filename
        filename = image.filename
        creation_time = datetime.datetime.strptime(
            filename.rstrip(".PPM"), "LYR-SLR-%Y%m%d_%H%M%S")

        creation_time = creation_time.strftime("%d %b %Y %H:%M:%S %Z")
        header = {'Wavelength': "Visible", 'Creation Time': creation_time}

        info = {'header': header, 'camera': camera, 'processing': processing}

        # return new allskyImage object
        return allskyImage.allskyImage(image, image.filename, info)
示例#2
0
    def open(self,image_filename, info_filename):
        image = Image.open(image_filename)
        
        #read image header data
        info=image.info

        #Read site info file
        camera={}
        processing={}
        header=image.info.copy() #copy header data stored in image
        
        with open(info_filename,"r") as info_file:
            for line in info_file: #read file line by line
                if line.isspace(): 
                    continue #ignore blank lines
                words=line.split("=") #split the line at the = sign
                
                if len(words) != 2:
                    print("Error! allskyImagePlugins.UiO_Allsky_LYR.open(): Cannot read site info file, too many words per line")
                    sys.exit()
                    
                camera[words[0].lstrip().rstrip()] = words[1].lstrip().rstrip() #store the values (minus white space) in a dictionary
        
        #create a dictionary containing all the metadata
        info={'header':header,'camera':camera,'processing':processing}
    
        #return new allskyImage object
        return allskyImage.allskyImage(image,image.filename,info)
示例#3
0
    def open(self, image_filename, info_filename):
        from PASKIL import allskyImage

        """
        Returns an allskyImage object containing the image data and image metadata contained in 'image_filename'.
        """
        image = Image.open(image_filename)

        # read image header data
        info = image.info

        # load the metadata from the image header data
        camera = eval(info["camera"])
        processing = eval(info["processing"])
        header = eval(info["header"])
        try:
            exif = eval(info["exif"])
            del info["exif"]
        except KeyError:
            exif = {}

        del info["camera"]
        del info["processing"]
        del info["header"]

        # create a dictionary containing all the metadata
        info = {"header": header, "camera": camera, "processing": processing, "exif": exif}

        # return new allskyImage object
        return allskyImage.allskyImage(image, image.filename, info)
示例#4
0
    def open(self, image_filename, info_filename):
        image = Image.open(image_filename)

        with open(info_filename, "r") as info_file:

            camera = {}
            processing = {}
            header = image.info.copy()

            # check that a site info file was specified
            if info_file == None:
                raise ValueError("You must specify a site information file for this type of image")

            # check that the wavelength in the header matches the wavelength in
            # the file extension
            if image.filename.endswith(("r", "s", "t", "u", "v")) and header["Wavelength"] != "630.0nm":
                raise ValueError("Wavelength in header does not match wavelength denoted by file extension")

            if image.filename.endswith(("g", "h", "i", "j", "k")) and header["Wavelength"] != "557.7nm":
                raise ValueError("Wavelength in header does not match wavelength denoted by file extension")

            if image.filename.endswith(("b", "c", "d", "e", "f")) and header["Wavelength"] != "427.8nm":
                raise ValueError("Wavelength in header does not match wavelength denoted by file extension")

            # Read site info file
            with open(info_filename, "r") as info_file:
                for line in info_file:  # read file line by line
                    if line.isspace():
                        continue  # ignore blank lines
                    words = line.split("=")  # split the line at the = sign

                    if len(words) != 2:
                        raise ValueError(
                            "Error! allskyImagePlugins.UiO_Allsky_PMIS.open(): Cannot read site info file, too many words per line"
                        )

                    # store the values (minus white space) in a dictionary
                    camera[words[0].lstrip().rstrip()] = words[1].lstrip().rstrip()

            # convert the creation time data stored in the PMIS header into the
            # PASKIL format
            try:
                creation_time = datetime.datetime.strptime(header["Creation Time"], "%Y-%m-%d_%H:%M:%S")
            except:
                # different date format for 1997
                creation_time = datetime.datetime.strptime(header["Creation Time"], "%Y-%m-%d_%H.%M.%S")

            header["Creation Time"] = creation_time.strftime("%d %b %Y %H:%M:%S %Z")

            info = {"header": header, "camera": camera, "processing": processing}

            # return new allskyImage object
            return allskyImage(image.convert("I"), image.filename, info)
示例#5
0
    def open(self, image_filename, info_filename):
        from PASKIL import allskyImage

        """
        Returns an allskyImage object containing the image data and image metadata contained in 'image_filename'.
        """
        image = Image.open(image_filename)
        exif_data = misc.readExifData(image_filename)

        info_str = exif_data.pop("Exif.Photo.UserComment")
        info = eval(info_str)
        info["exif"] = exif_data

        # return new allskyImage object
        return allskyImage.allskyImage(image, image.filename, info)
示例#6
0
    def open(self, image_filename, info_filename):
        """
        Returns a PASKIL allskyImage object containing the image data and its
        associated meta-data.
        """
        image = Image.open(image_filename)

        with open(info_filename, "rb") as fp:
            info = pickle.load(fp)

        # attempt to load the exif data
        try:
            info['exif'] = misc.readExifData(image_filename)
        except:
            print("Couldn't read the exif")
            pass

        # return new allskyImage object
        return allskyImage.allskyImage(image, image.filename, info)
示例#7
0
    def open(self, image_filename, info_filename):
        from PASKIL import allskyImage

        """
        Returns an allskyImage object containing the image data and image metadata contained in 'image'.
        """
        header = {}
        camera = {}
        processing = {}
        exif = {}

        # open fits file using pyfits
        hdulist = pyfits.open(image_filename)

        # read header data locations from header
        header_hdu = hdulist[hdulist[0].header["PSKHEAD"]]
        camera_hdu = hdulist[hdulist[0].header["PSKCAM"]]
        processing_hdu = hdulist[hdulist[0].header["PSKPRO"]]
        exif_hdu = hdulist[hdulist[0].header["PSKEXIF"]]

        # write image info dictionary
        for i in range(header_hdu.data.size):
            try:
                header[header_hdu.data[i][0]] = eval(header_hdu.data[i][1])
            except:
                header[header_hdu.data[i][0]] = header_hdu.data[i][1]

        for i in range(camera_hdu.data.size):
            try:
                camera[camera_hdu.data[i][0]] = eval(camera_hdu.data[i][1])
            except:
                camera[camera_hdu.data[i][0]] = camera_hdu.data[i][1]

        for i in range(processing_hdu.data.size):
            try:
                processing[processing_hdu.data[i][0]] = eval(processing_hdu.data[i][1])
            except:
                processing[processing_hdu.data[i][0]] = processing_hdu.data[i][1]

        for i in range(exif_hdu.data.size):
            try:
                exif[exif_hdu.data[i][0]] = eval(exif_hdu.data[i][1])
            except:
                exif[exif_hdu.data[i][0]] = exif_hdu.data[i][1]

        info = {"header": header, "camera": camera, "processing": processing, "exif": exif}

        mode = hdulist[0].header["PSKMODE"]

        # load image data
        image_data = hdulist[0].data

        if mode != "RGB":
            # need to flip image as it is read in upside down
            new_image = ImageOps.flip(Image.fromarray(image_data))
        else:
            # read in separate RGB channels and then combine them into one
            # image
            red_image = Image.fromarray(image_data[0])
            green_image = Image.fromarray(image_data[1])
            blue_image = Image.fromarray(image_data[2])

            new_image = ImageOps.flip(Image.merge("RGB", [red_image, green_image, blue_image]))

        return allskyImage.allskyImage(new_image, image_filename, info)