def search(self, *query): """ Query data from the VSO with the new API. Takes a variable number of attributes as parameter, which are chained together using AND. The new query language allows complex queries to be easily formed. Examples -------- Query all data from eit or aia between 2010-01-01T00:00 and 2010-01-01T01:00. >>> from datetime import datetime >>> from sunpy.net import vso, attrs as a >>> client = vso.VSOClient() # doctest: +REMOTE_DATA >>> client.search( ... a.Time(datetime(2010, 1, 1), datetime(2010, 1, 1, 1)), ... a.Instrument('eit') | a.Instrument('aia')) # doctest: +REMOTE_DATA <QTable length=5> Start Time [1] End Time [1] Source ... Type Wavelength [2] ... Angstrom str19 str19 str4 ... str8 float64 ------------------- ------------------- ------ ... -------- -------------- 2010-01-01 00:00:08 2010-01-01 00:00:20 SOHO ... FULLDISK 195.0 .. 195.0 2010-01-01 00:12:08 2010-01-01 00:12:20 SOHO ... FULLDISK 195.0 .. 195.0 2010-01-01 00:24:10 2010-01-01 00:24:22 SOHO ... FULLDISK 195.0 .. 195.0 2010-01-01 00:36:08 2010-01-01 00:36:20 SOHO ... FULLDISK 195.0 .. 195.0 2010-01-01 00:48:09 2010-01-01 00:48:21 SOHO ... FULLDISK 195.0 .. 195.0 Returns ------- out : :py:class:`QueryResult` (enhanced list) Matched items. Return value is of same type as the one of :py:meth:`VSOClient.search`. """ query = and_(*query) QueryRequest = self.api.get_type('VSO:QueryRequest') VSOQueryResponse = self.api.get_type('VSO:QueryResponse') responses = [] for block in walker.create(query, self.api): try: query_response = self.api.service.Query( QueryRequest(block=block) ) for resp in query_response: if resp["error"]: warnings.warn(resp["error"], SunpyUserWarning) responses.append( VSOQueryResponse(query_response) ) except Exception as ex: response = QueryResponse.create(self.merge(responses)) response.add_error(ex) return QueryResponse.create(self.merge(responses))
def search(self, *query, response_format=None): """ Query data from the VSO with the new API. Takes a variable number of attributes as parameter, which are chained together using AND. Parameters ---------- response_format: {``"legacy"``, ``"table"``}, optional The response format from the search, this can be either ``"legacy"`` to return a list-like object of the zeep responses, or ``"table"`` to return the responses in a subclass of `~astropy.table.QTable`. Examples -------- Query all data from eit or aia between 2010-01-01T00:00 and 2010-01-01T01:00. >>> from datetime import datetime >>> from sunpy.net import vso, attrs as a >>> client = vso.VSOClient() # doctest: +REMOTE_DATA >>> client.search( ... a.Time(datetime(2010, 1, 1), datetime(2010, 1, 1, 1)), ... a.Instrument.eit | a.Instrument.aia, ... response_format="table") # doctest: +REMOTE_DATA <sunpy.net.vso.table_response.VSOQueryResponseTable object at ...> Start Time End Time Source ... Extent Type Size ... Mibyte ----------------------- ----------------------- ------ ... ----------- ------- 2010-01-01 00:00:08.000 2010-01-01 00:00:20.000 SOHO ... FULLDISK 2.01074 2010-01-01 00:12:08.000 2010-01-01 00:12:20.000 SOHO ... FULLDISK 2.01074 2010-01-01 00:24:10.000 2010-01-01 00:24:22.000 SOHO ... FULLDISK 2.01074 2010-01-01 00:36:08.000 2010-01-01 00:36:20.000 SOHO ... FULLDISK 2.01074 2010-01-01 00:48:09.000 2010-01-01 00:48:21.000 SOHO ... FULLDISK 2.01074 Returns ------- out : `~sunpy.net.vso.table_response.VSOQueryResponseTable` Matched items. Return value is of same type as the one of :meth:`VSOClient.search`. """ if response_format is None: response_format = "table" query = and_(*query) QueryRequest = self.api.get_type('VSO:QueryRequest') VSOQueryResponse = self.api.get_type('VSO:QueryResponse') responses = [] exceptions = [] for block in walker.create(query, self.api): try: query_response = self.api.service.Query( QueryRequest(block=block) ) for resp in query_response: if resp["error"]: warn_user(resp["error"]) responses.append( VSOQueryResponse(query_response) ) except Exception as ex: exceptions.append(ex) responses = self.merge(responses) if response_format == "legacy": response = QueryResponse.create(responses) else: response = VSOQueryResponseTable.from_zeep_response(responses, client=self) for ex in exceptions: response.add_error(ex) return response