<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Query Meta data in database Groups [v1.1]
Step1:  Setup
Step2:  Check one of the meta tables
Step3:  Query meta with Query dict
A simple example
Step4:  Another example
Step5:  One more
Step6:  Query meta at position
As with query catalog, the position coordinates can have a range of formats
One simple source
Step7:  Multiple meta entries (GGG)
Step8:  Multiple sources
Step9:  Restrict on groups
Step10:  Query Meta with Coordinates list
When querying with a coordinate list, there are two approaches to 
the data returned.  The default is to return the meta data
for the first spectrum matched to each coordinate.
The other option is to retrieve all of the meta data for each 
coordinate input.  The returned object is then a list of bool arrays
and a Table of all the meta data.
We provide examples for each.
Meta for first match for each coordinate
Returns a Table with a single meta data entry per coordinate even if multiple exist.
If there is no match, the row is empty in the Table.
If there are zero matches, return None.
Single source (which matches)
Step11:  Single source which fails to match
Step12:  Source where multiple spectra exist, but only the first record is returned
Step13:  Multiple coordinates, each matched
Step14:  Multiple coordinates, one fails to match by coordinate
Step15:  Multiple coordiantes, one fails to match input group list
Step16:  All Meta Data for each input coordinate
Here, a list of bool arrays relative to stacked meta table is returned.
This is a bit convoluted, but is *much* faster for large coordinate lists.
If there is no match to a given coordinate, the entry in the list is None
Two sources.  The second one has two spectra in the database
Step17:  Two sources, limit by groups
Step18:  Three sources; second one has no match
<ASSISTANT_TASK:>
Python Code:
# imports
from astropy import units as u
from astropy.coordinates import SkyCoord
import specdb
from specdb.specdb import SpecDB
from specdb import specdb as spdb_spdb
from specdb.cat_utils import flags_to_groups
Explanation: Query Meta data in database Groups [v1.1]
End of explanation
db_file = specdb.__path__[0]+'/tests/files/IGMspec_DB_v02_debug.hdf5'
reload(spdb_spdb)
sdb = spdb_spdb.SpecDB(db_file=db_file)
Explanation: Setup
End of explanation
ggg_meta = sdb['GGG'].meta
ggg_meta[0:4]
Explanation: Check one of the meta tables
End of explanation
qdict = {'TELESCOPE': 'Gemini-North', 'NPIX': (1580,1583), 'DISPERSER': ['B600', 'R400']}
qmeta = sdb.query_meta(qdict)
qmeta
Explanation: Query meta with Query dict
A simple example
End of explanation
qdict = {'R': (4000.,1e9), 'WV_MIN': (0., 4000.)}
qmeta = sdb.query_meta(qdict)
qmeta
Explanation: Another example
End of explanation
qdict = {'R': (1800.,2500), 'WV_MIN': (0., 4000.)}
qmeta = sdb.query_meta(qdict)
qmeta['GROUP'].data
Explanation: One more
End of explanation
meta = sdb.meta_from_position((0.0019,17.7737), 1*u.arcsec)
meta
Explanation: Query meta at position
As with query catalog, the position coordinates can have a range of formats
One simple source
End of explanation
meta = sdb.meta_from_position('001115.23+144601.8', 1*u.arcsec)
meta['WV_MIN'].data
Explanation: Multiple meta entries (GGG)
End of explanation
meta = sdb.meta_from_position((2.813500,14.767200), 20*u.deg)
meta[0:3]
meta['GROUP'].data
Explanation: Multiple sources
End of explanation
meta = sdb.meta_from_position((2.813500,14.767200), 20*u.deg, groups=['GGG','HD-LLS_DR1'])
meta['GROUP'].data
Explanation: Restrict on groups
End of explanation
coord = SkyCoord(ra=0.0019, dec=17.7737, unit='deg')
matches, meta = sdb.meta_from_coords(coord)
meta
Explanation: Query Meta with Coordinates list
When querying with a coordinate list, there are two approaches to 
the data returned.  The default is to return the meta data
for the first spectrum matched to each coordinate.
The other option is to retrieve all of the meta data for each 
coordinate input.  The returned object is then a list of bool arrays
and a Table of all the meta data.
We provide examples for each.
Meta for first match for each coordinate
Returns a Table with a single meta data entry per coordinate even if multiple exist.
If there is no match, the row is empty in the Table.
If there are zero matches, return None.
Single source (which matches)
End of explanation
coord = SkyCoord(ra=0.0019, dec=-17.7737, unit='deg')
matches, meta = sdb.meta_from_coords(coord)
print(meta)
Explanation: Single source which fails to match
End of explanation
coord = SkyCoord(ra=2.813458, dec=14.767167, unit='deg')
_, meta = sdb.meta_from_coords(coord)
meta
Explanation: Source where multiple spectra exist, but only the first record is returned
End of explanation
coords = SkyCoord(ra=[0.0028,2.813458], dec=[14.9747,14.767167], unit='deg')
matches, meta = sdb.meta_from_coords(coords)
print(matches)
meta
Explanation: Multiple coordinates, each matched
End of explanation
coords = SkyCoord(ra=[0.0028,9.99,2.813458], dec=[14.9747,-9.99,14.767167], unit='deg')
matches, meta = sdb.meta_from_coords(coords)
print(matches)
meta
Explanation: Multiple coordinates, one fails to match by coordinate
End of explanation
coords = SkyCoord(ra=[0.0028,2.813458], dec=[14.9747,14.767167], unit='deg')
matches, meta = sdb.meta_from_coords(coords, groups=['GGG'])
print(matches)
print(meta['IGM_ID'])
meta
Explanation: Multiple coordiantes, one fails to match input group list
End of explanation
coords = SkyCoord(ra=[0.0028,2.813458], dec=[14.9747,14.767167], unit='deg')
matches, list_of_meta, meta_stack = sdb.meta_from_coords(coords, first=False)
print('Matches = ', matches)
list_of_meta, meta_stack[list_of_meta[0]]
Explanation: All Meta Data for each input coordinate
Here, a list of bool arrays relative to stacked meta table is returned.
This is a bit convoluted, but is *much* faster for large coordinate lists.
If there is no match to a given coordinate, the entry in the list is None
Two sources.  The second one has two spectra in the database
End of explanation
matches, list_of_meta, meta_stack = sdb.meta_from_coords(coords, first=False, groups=['GGG'])
list_of_meta, meta_stack[list_of_meta[1]]
Explanation: Two sources, limit by groups
End of explanation
coords = SkyCoord(ra=[0.0028,9.99,2.813458], dec=[14.9747,-9.99,14.767167], unit='deg')
matches, list_of_meta, meta_stack = sdb.meta_from_coords(coords, first=False)
print('Matches = ', matches)
meta_stack[list_of_meta[0]]
Explanation: Three sources; second one has no match
End of explanation
<END_TASK>