Exemple #1
0
 def test_fg_filtered_multiple_key(self, tmpdir):
     tmpdir, flist = tmpdir
     fg = FitsFileGroup(location=tmpdir / 'fits', compression=False)
     nfg = fg.filtered({
         'object': 'Moon',
         'exptime': 1.0,
         'image': 'object_4_v.fits'
     })
     assert_equal(len(nfg), 1)
     assert_equal(nfg.files, [flist['fits'][24]])
Exemple #2
0
    def test_fg_create_filegroup_without_compression(self, tmpdir):
        tmpdir, flist = tmpdir
        fg = FitsFileGroup(location=tmpdir / 'fits', compression=False)
        assert_is_instance(fg, FitsFileGroup)
        assert_equal(len(fg), 30)
        assert_equal(sorted(fg.files), sorted(flist['fits']))

        #Default is False
        fg = FitsFileGroup(location=tmpdir / 'fits')
        assert_is_instance(fg, FitsFileGroup)
        assert_equal(len(fg), 30)
        assert_equal(sorted(fg.files), sorted(flist['fits']))
Exemple #3
0
    def test_fg_creation_glob_include_exclude(self, tmpdir):
        tmpdir, flist = tmpdir
        # only bias
        fg = FitsFileGroup(location=tmpdir / 'fits', glob_include='*bias*')
        assert_is_instance(fg, FitsFileGroup)
        assert_equal(len(fg), 10)
        assert_equal(sorted(fg.files), sorted(flist['fits'][:10]))

        # everything except bias
        fg = FitsFileGroup(location=tmpdir / 'fits', glob_exclude='*bias*')
        assert_is_instance(fg, FitsFileGroup)
        assert_equal(len(fg), 20)
        assert_equal(sorted(fg.files), sorted(flist['fits'][10:]))
Exemple #4
0
    def test_fg_filtered_empty(self, tmpdir):
        tmpdir, flist = tmpdir
        fg = FitsFileGroup(location=tmpdir / 'fits', compression=False)

        # non existing key
        nfg = fg.filtered({'NON-EXISTING': 1})
        assert_is_instance(nfg, FitsFileGroup)
        assert_equal(len(nfg), 0)
        assert_equal(nfg.files, [])

        # existing but not matched
        nfg = fg.filtered({'object': 'Sun'})
        assert_is_instance(nfg, FitsFileGroup)
        assert_equal(len(nfg), 0)
        assert_equal(nfg.files, [])
Exemple #5
0
 def test_fg_getitem_empty(self, tmpdir):
     tmpdir, flist = tmpdir
     fg = FitsFileGroup(location=tmpdir / 'fits', compression=False)
     row = fg[[]]
     assert_is_instance(row, FitsFileGroup)
     assert_equal(len(row), 0)
     assert_equal(row.files, [])
Exemple #6
0
 def test_fg_getitem_slice(self, tmpdir):
     tmpdir, flist = tmpdir
     fg = FitsFileGroup(location=tmpdir / 'fits', compression=False)
     row = fg[2:5]
     assert_is_instance(row, FitsFileGroup)
     assert_equal(len(row), 3)
     assert_equal(row.files, flist['fits'][2:5])
Exemple #7
0
    def test_fg_creation_no_std_extension(self, tmpdir):
        tmpdir, flist = tmpdir
        fg = FitsFileGroup(location=tmpdir / 'fts')
        assert_is_instance(fg, FitsFileGroup)
        assert_equal(len(fg), 30)
        assert_equal(sorted(fg.files), sorted(flist['fts']))

        fg = FitsFileGroup(location=tmpdir / 'fit')
        assert_is_instance(fg, FitsFileGroup)
        assert_equal(len(fg), 30)
        assert_equal(sorted(fg.files), sorted(flist['fit']))

        fg = FitsFileGroup(location=tmpdir / 'fz')
        assert_is_instance(fg, FitsFileGroup)
        assert_equal(len(fg), 30)
        assert_equal(sorted(fg.files), sorted(flist['fz']))
Exemple #8
0
 def test_fg_creation_custom_hdu(self, tmpdir, hdu):
     tmpdir, flist = tmpdir
     fg = FitsFileGroup(location=str(tmpdir / 'custom_hdu'), ext=hdu)
     assert_is_instance(fg, FitsFileGroup)
     assert_equal(len(fg), 10)
     assert_equal(sorted(fg.files), sorted(flist['custom_hdu']))
     for k in ('object', 'exptime', 'observer', 'filter'):
         assert_in(k, fg.summary.colnames)
     for i in fg.summary:
         assert_equal(i['object'], 'bias')
Exemple #9
0
    def test_fg_filtered_single_key(self, tmpdir):
        tmpdir, flist = tmpdir
        fg = FitsFileGroup(location=tmpdir / 'fits', compression=False)
        bias_files = flist['fits'][:10]
        flat_files = flist['fits'][10:20]
        sci_files = flist['fits'][20:]

        # object keyword
        fg_b = fg.filtered({'object': 'bias'})
        assert_equal(len(fg_b), 10)
        assert_equal(sorted(fg_b.files), sorted(bias_files))

        # filter keyword
        fg_v = fg.filtered({'filter': 'V'})
        assert_equal(len(fg_v), 20)
        assert_equal(sorted(fg_v.files), sorted(flat_files + sci_files))

        # Hierarch key with space
        fg_s = fg.filtered({'space key': 1})
        assert_equal(len(fg_s), 30)
        assert_equal(sorted(fg_s.files),
                     sorted(bias_files + flat_files + sci_files))
Exemple #10
0
    def test_fg_getitem_array_or_tuple(self, tmpdir):
        tmpdir, flist = tmpdir
        flist = flist['fits']
        files = [flist[2], flist[4]]
        fg = FitsFileGroup(location=tmpdir / 'fits', compression=False)

        row = fg[[2, 4]]
        assert_is_instance(row, FitsFileGroup)
        assert_equal(len(row), 2)
        assert_equal(row.files, files)

        row = fg[np.array([2, 4])]
        assert_is_instance(row, FitsFileGroup)
        assert_equal(len(row), 2)
        assert_equal(row.files, files)
Exemple #11
0
 def test_fg_getitem_keyerror(self, tmpdir):
     tmpdir, flist = tmpdir
     fg = FitsFileGroup(location=tmpdir / 'fits', compression=False)
     with pytest.raises(KeyError):
         fg['NonExistingKey']
Exemple #12
0
 def test_fg_getitem_column(self, tmpdir):
     tmpdir, flist = tmpdir
     fg = FitsFileGroup(location=tmpdir / 'fits', compression=False)
     obj_column = fg['object']
     assert_equal(sorted(obj_column),
                  sorted(['bias'] * 10 + ['flat'] * 10 + ['Moon'] * 10))
Exemple #13
0
 def test_fg_creation_files(self, tmpdir):
     tmpdir, flist = tmpdir
     fg = FitsFileGroup(files=flist['fits'])
     assert_is_instance(fg, FitsFileGroup)
     assert_equal(len(fg), 30)
     assert_equal(sorted(fg.files), sorted(flist['fits']))
Exemple #14
0
 def test_fg_create_filegroup(self, tmpdir):
     tmpdir, flist = tmpdir
     fg = FitsFileGroup(location=tmpdir / 'fits_gz', compression=True)
     assert_is_instance(fg, FitsFileGroup)
     assert_equal(len(fg), 30)
     assert_equal(sorted(fg.files), sorted(flist['fits.gz']))
Exemple #15
0
 def test_fg_creation_empty(self):
     fg = FitsFileGroup()
     assert_is_instance(fg, FitsFileGroup)
     assert_equal(len(fg), 0)