Exemple #1
0
    def add_to_patch(self, filepath, index=None, verbose=False, **kwargs):
        """
        Add a file to the patch after initialization

        Args:
            filepath <str> - path to file which is to be added to the patch

        Kwargs:
            index <int> -  list index at which the file is inserted; default -1
            data <list/np.ndarray> - add the data of the .fits file directly
            hdr <dict> - add the header of the .fits file directly
            px2arcsec <float,float> - overwrite the pixel scale in the .fits header (in arcsecs)
            refpx <int,int> - overwrite reference pixel coordinates in .fits header (in pixels)
            refval <float,float> - overwrite reference pixel values in .fits header (in degrees)
            photzp <float> - overwrite photometric zero-point information
            verbose <bool> - verbose mode; print command line statements

        Return:
            filepath <str> - validated filepath which was added to the patch
        """
        filepath = SkyF.check_path(filepath, check_ext=False)
        if index is None or index == -1:
            self.filepaths.append(filepath)
            self.fs.append(SkyF(filepath, **kwargs))
        else:
            self.filepaths.insert(index, filepath)
            self.fs.insert(index, SkyF(filepath, **kwargs))
        if verbose:
            print(self.__v__)
        return filepath
Exemple #2
0
    def find_files(d_o_f,
                   sequence=[
                       ".U.", ".G.", ".R.", ".I.", ".I2.", ".Z.", ".u.", ".g.",
                       ".r.", ".i.", ".i2.", ".z."
                   ],
                   verbose=False):
        """
        Select all .fits files in the directory

        Args:
            d_o_f <list(str)/str> - 'directory or file' path to all the .fits files

        Kwargs:
            sequence <list(str)> - sequence of keys after which the files are ordered
            verbose <bool> - verbose mode; print command line statements

        Return:
            filepaths <list(str)> - list of all .fits file paths
        """

        # sorting files after band sequence
        def band_key(f):
            for i, s in enumerate(sequence):
                if s in f:
                    return i

        if d_o_f is None:
            return [None]
        if isinstance(d_o_f, str):  # single file input
            if any([d_o_f.endswith(ext) for ext in ('.fits', '.fit', '.fts')]):
                d_o_f = [d_o_f]
            else:
                d_o_f = [
                    '/'.join([d_o_f, f]) for f in os.listdir(d_o_f) if True in
                    [f.endswith(x) for x in ('.fits', '.fit', '.fts')]
                ]
        elif isinstance(d_o_f,
                        list) and len(d_o_f) == 1:  # input as list of files
            if not any(
                [d_o_f[0].endswith(ext) for ext in ('.fits', '.fit', '.fts')]):
                folder = d_o_f[0]
                d_o_f = [
                    '/'.join([folder, f]) for f in os.listdir(folder) if True
                    in [f.endswith(x) for x in ('.fits', '.fit', '.fts')]
                ]
        # input as directory string
        files = [SkyF.check_path(f, check_ext=False) for f in d_o_f]
        if verbose:
            print("Searching for files with '.fits' extension in {}".format(
                d_o_f))
        try:
            files = sorted(files, key=band_key)
        except TypeError:
            pass
        # some verbosity
        if verbose:
            print("Files in sorted order:")
            print("\n".join(files))
        return files
Exemple #3
0
 def test_check_path(self):
     """ # check_path """
     print(">>> {}".format(self.test_fits))
     fpath = SkyF.check_path(self.test_fits, **self.v)
     self.assertEqual(fpath, self.test_fits)