<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 My First Query
One of the most powerful features of Marvin 2.0 is ability to query the newly created DRP and DAP databases. You can do this in two ways
Step1:  Let's search for galaxies with M$\star$ > 3 $\times$ 10$^{11}$ M$\odot$.
To specify our search parameter, M$_\star$, we must know the database table and name of the parameter. In this case, MaNGA uses the NASA-Sloan Atlas (NSA) for target selection so we will use the Sersic profile determination for stellar mass, which is the sersic_mass parameter of the nsa table, so our search parameter will be nsa.sersic_mass.  You can also use nsa.sersic_logmass
Generically, the search parameter will take the form table.parameter.
Step2:  Running the query produces a Results object (r1)
Step3:  We will learn how to use the features of our Results object a little bit later, but first let's revise our search to see how more complex search queries work.
Multiple Search Criteria
Let's add to our search to find only galaxies with a redshift less than 0.1.
Redshift is the z parameter and is also in the nsa table, so its full search parameter designation is nsa.z.
Step4:  Compound Search Statements
We were hoping for a few more than 3 galaxies, so let's try to increase our search by broadening the criteria to also include galaxies with 127 fiber IFUs and a b/a ratio of at least 0.95.
To find 127 fiber IFUs, we'll use the name parameter of the ifu table, which means the full search parameter is ifu.name. However, ifu.name returns the IFU design name, such as 12701, so we need to to set the value to 127*.
The b/a ratio is in nsa table as the elpetro_ba parameter.
We're also going to join this to or previous query with an OR operator and use parentheses to group our individual search statements into a compound search statement.
Step5:  Design Your Own Search
OK, now it's your turn to try designing a search.
Exercise
Step6:  Finding the Available Parameters
Now you might want to go out and try all of the interesting queries that you've been saving up, but you don't know what the parameters are called or what database table they are in. 
You can find all of the availabale parameters by
Step7:  Go ahead and try to create some new searches on your own from the parameter list. Please feel free to also try out the some of the same search on the Marvin-web Search page.
Returning Bonus Parameters
Often you want to run a query and see the value of parameters that you didn't explicitly search on. For instance, you want to find galaxies above a redshift of 0.1 and would like to know their RA and DECs.
In Marvin-tools, this is as easy as specifying the returnparams option with either a string (for a single bonus parameter) or a list of strings (for multiple bonus parameters).
<ASSISTANT_TASK:>
Python Code:
# Python 2/3 compatibility
from __future__ import print_function, division, absolute_import
from marvin import config
config.setRelease('MPL-4')
from marvin.tools.query import Query
Explanation: My First Query
One of the most powerful features of Marvin 2.0 is ability to query the newly created DRP and DAP databases. You can do this in two ways:
1. via the Marvin-web Search page or
2. via Python (in the terminal/notebook/script) with Marvin-tools.
The best part is that both interfaces use the same underlying query structure, so your input search will be the same. Here we will run a few queries with Marvin-tools to learn the basics of how to construct a query and also test drive some of the more advanced features that are unique to the Marvin-tools version of querying.
End of explanation
myquery1 = 'nsa.sersic_mass > 3e11'
# or
myquery1 = 'nsa.sersic_logmass > 11.47'
q1 = Query(searchfilter=myquery1)
r1 = q1.run()
Explanation: Let's search for galaxies with M$\star$ > 3 $\times$ 10$^{11}$ M$\odot$.
To specify our search parameter, M$_\star$, we must know the database table and name of the parameter. In this case, MaNGA uses the NASA-Sloan Atlas (NSA) for target selection so we will use the Sersic profile determination for stellar mass, which is the sersic_mass parameter of the nsa table, so our search parameter will be nsa.sersic_mass.  You can also use nsa.sersic_logmass
Generically, the search parameter will take the form table.parameter.
End of explanation
# show results
r1.results
Explanation: Running the query produces a Results object (r1):
End of explanation
myquery2 = 'nsa.sersic_mass > 3e11 AND nsa.z < 0.1'
q2 = Query(searchfilter=myquery2)
r2 = q2.run()
r2.results
Explanation: We will learn how to use the features of our Results object a little bit later, but first let's revise our search to see how more complex search queries work.
Multiple Search Criteria
Let's add to our search to find only galaxies with a redshift less than 0.1.
Redshift is the z parameter and is also in the nsa table, so its full search parameter designation is nsa.z.
End of explanation
myquery3 = '(nsa.sersic_mass > 3e11 AND nsa.z < 0.1) OR (ifu.name=127* AND nsa.elpetro_ba >= 0.95)'
q3 = Query(searchfilter=myquery3)
r3 = q3.run()
r3.results
Explanation: Compound Search Statements
We were hoping for a few more than 3 galaxies, so let's try to increase our search by broadening the criteria to also include galaxies with 127 fiber IFUs and a b/a ratio of at least 0.95.
To find 127 fiber IFUs, we'll use the name parameter of the ifu table, which means the full search parameter is ifu.name. However, ifu.name returns the IFU design name, such as 12701, so we need to to set the value to 127*.
The b/a ratio is in nsa table as the elpetro_ba parameter.
We're also going to join this to or previous query with an OR operator and use parentheses to group our individual search statements into a compound search statement.
End of explanation
# Enter your search here
Explanation: Design Your Own Search
OK, now it's your turn to try designing a search.
Exercise: Write a search filter that will find galaxies with a redshift less than 0.02 that were observed with the 1901 IFU?
End of explanation
# You might have to do an svn update to get this to work (otherwise try the next cell)
q = Query()
q.get_available_params()
Explanation: Finding the Available Parameters
Now you might want to go out and try all of the interesting queries that you've been saving up, but you don't know what the parameters are called or what database table they are in. 
You can find all of the availabale parameters by:
1. clicking on in the Return Parameters dropdown menu on the left side of the Marvin-web Search page,
2. reading the Marvin Docs page, or
3. via Marvin-tools (see next two cells)
End of explanation
myquery5 = 'nsa.z > 0.1'
bonusparams5 = ['cube.ra', 'cube.dec']
# bonusparams5 = 'cube.ra'  # This works too
q5 = Query(searchfilter=myquery5, returnparams=bonusparams5)
r5 = q5.run()
r5.results
Explanation: Go ahead and try to create some new searches on your own from the parameter list. Please feel free to also try out the some of the same search on the Marvin-web Search page.
Returning Bonus Parameters
Often you want to run a query and see the value of parameters that you didn't explicitly search on. For instance, you want to find galaxies above a redshift of 0.1 and would like to know their RA and DECs.
In Marvin-tools, this is as easy as specifying the returnparams option with either a string (for a single bonus parameter) or a list of strings (for multiple bonus parameters).
End of explanation
<END_TASK>