marvin icon indicating copy to clipboard operation
marvin copied to clipboard

Query example doesn't work

Open KateRowlands opened this issue 6 years ago • 7 comments

from marvin.tools.query import Query
filter = 'nsa.z < 0.1 and emline_gflux_ha_6564 > 25'
params = ['emline_gflux_hb_4862', 'stellar_vel', 'nii_to_ha']
q = Query(searchfilter=filter, returnparams=params)
r = q.run()

stvel = r.getListOf('stellar_vel')
stvel = [res.stellar_vel for res in r.results]

Produces

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
//anaconda/envs/msaviz/lib/python3.6/site-packages/marvin/utils/general/structs.py in __eq__(self, value)
    164         try:
--> 165             best = self.use_fuzzy(value, self_values)
    166         except ValueError:

//anaconda/envs/msaviz/lib/python3.6/site-packages/marvin/utils/datamodel/query/base.py in get_best_fuzzy(name, choices, cutoff, return_score)
    384     if best is None:
--> 385         raise ValueError('Could not find a match for {0}.  Please refine your text.'.format(name))
    386 

ValueError: Could not find a match for stellar_vel.  Please refine your text.

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-91-170de5ea6371> in <module>()
      5 
      6 # get list of stellar velocities
----> 7 stvel = r.getListOf('stellar_vel')

//anaconda/envs/msaviz/lib/python3.6/site-packages/marvin/tools/results.py in getListOf(self, name, to_json, to_ndarray, return_all)
    979 
    980         # check column name and get full name
--> 981         fullname = self._check_column(name, 'full')
    982 
    983         # deal with the output

//anaconda/envs/msaviz/lib/python3.6/site-packages/marvin/tools/results.py in _check_column(self, name, name_type)
    946             assert name_type in ['full', 'remote', 'name', 'short', 'display'], \
    947                 'name_type must be one of "full, remote, name, short, display"'
--> 948             return self.columns[str(name)].__getattribute__(name_type)
    949 
    950     def getListOf(self, name=None, to_json=False, to_ndarray=False, return_all=None):

//anaconda/envs/msaviz/lib/python3.6/site-packages/marvin/utils/general/structs.py in __getitem__(self, value)
    184 
    185         if isinstance(value, six.string_types):
--> 186             return self == value
    187         else:
    188             return list.__getitem__(self, value)

//anaconda/envs/msaviz/lib/python3.6/site-packages/marvin/utils/general/structs.py in __eq__(self, value)
    166         except ValueError:
    167             # Second pass, using underscores.
--> 168             best = self.use_fuzzy(value.replace(' ', '_'), self_values)
    169 
    170         return self[self_values.index(best)]

//anaconda/envs/msaviz/lib/python3.6/site-packages/marvin/utils/datamodel/query/base.py in get_best_fuzzy(name, choices, cutoff, return_score)
    383 
    384     if best is None:
--> 385         raise ValueError('Could not find a match for {0}.  Please refine your text.'.format(name))
    386 
    387     return best if return_score else best[0]

ValueError: Could not find a match for stellar_vel.  Please refine your text.

KateRowlands avatar Oct 24 '18 22:10 KateRowlands

This example is also broken:

from marvin.tools.query import Query
filter = 'nsa.z < 0.1 and emline_gflux_ha_6564 > 25'
params = ['emline_gflux_hb_4862', 'stellar_vel', 'nii_to_ha']
q = Query(search_filter=filter, returnparams=params, limit=10000)
r = q.run()
f='results_{0}_chunk{1}_to_{2}.mpf'.format(p.replace(' ','_'), r.start, r.end)
r.save(f)

#loop over and pickle each set of results
for chunk in xrange(0, r.totalcount, r.limit):
    r.getNext()
    f='results_{0}_chunk{1}_to_{2}.mpf'.format(p.replace(' ','_'), r.start, r.end)
    r.save(f)
    if r.end == r.totalcount: break

Produces

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-101-55ae4192a95b> in <module>()
      4 q = Query(search_filter=filter, returnparams=params, limit=10000)
      5 r = q.run()
----> 6 f='results_{0}_chunk{1}_to_{2}.mpf'.format(p.replace(' ','_'), r.start, r.end)
      7 r.save(f)
      8 

NameError: name 'p' is not defined

KateRowlands avatar Oct 25 '18 20:10 KateRowlands

The third example returns no results, but the documentation says it should return 22054.

from marvin.tools.query import Query

# Let's only get unbinned spaxels (i.e. bintype.name == 'SPX')
filter = 'nsa.z < 0.1 and emline_gflux_ha_6564 > 25 and bintype.name==SPX'

params = ['emline_gflux_hb_4862', 'stellar_vel', 'nii_to_ha', 'bintype.name', 'template.name']
q = Query(searchfilter=filter, returnparams=params, limit=10000)
r = q.run()

r.results
>> []

KateRowlands avatar Oct 25 '18 20:10 KateRowlands

Spaxel queries have been removed for the time being.

bretthandrews avatar Nov 21 '18 21:11 bretthandrews

Regardless we'll still need to update the documentation. I'd like to rearrange the documentation so most of the content can still exist but is hidden and when we're ready we can just turn it back on.

havok2063 avatar Nov 21 '18 21:11 havok2063

First problem: #547 is about updating documentation to change searchfilter to search_filter (and should cover returnparams too).

Second problem: Separate issue. Need to fix.

Third problem: Try on master.

bretthandrews avatar Nov 21 '18 21:11 bretthandrews

@havok2063 I have no idea what p refers to in p.replace(' ','_') in https://sdss-marvin.readthedocs.io/en/latest/tutorials/query-practice.html#pickle-your-query-and-results

bretthandrews avatar Nov 22 '18 02:11 bretthandrews

Example 3 works for me locally on master

bretthandrews avatar Nov 22 '18 02:11 bretthandrews