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]])
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']))
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:]))
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, [])
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, [])
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])
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']))
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')
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))
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)
def test_fg_getitem_keyerror(self, tmpdir): tmpdir, flist = tmpdir fg = FitsFileGroup(location=tmpdir / 'fits', compression=False) with pytest.raises(KeyError): fg['NonExistingKey']
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))
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']))
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']))
def test_fg_creation_empty(self): fg = FitsFileGroup() assert_is_instance(fg, FitsFileGroup) assert_equal(len(fg), 0)