예제 #1
0
    def get_results(self):
        """Returns the job results
        This method will block if the job is asynchronous and the job has not
        finished yet.

        Returns
        -------
        The job results (astropy.table).
        """
        if self.results is not None:
            return self.results
        # try load results from file
        # read_results_table_from_file checks whether
        # the file already exists or not
        outputFormat = self.parameters['format']
        results = modelutils.read_results_table_from_file(self.outputFile,
                                                          outputFormat)
        if results is not None:
            self.results = results
            return results
        # Try to load from server: only async
        if not self.async_:
            # sync: result is in a file
            return None
        else:
            # async: result is in the server once the job is finished
            self.__load_async_job_results()
            return self.results
예제 #2
0
파일: job.py 프로젝트: astropy/astroquery
    def get_results(self):
        """Returns the job results
        This method will block if the job is asynchronous and the job has not
        finished yet.

        Returns
        -------
        The job results (astropy.table).
        """
        if self.results is not None:
            return self.results
        # try load results from file
        # read_results_table_from_file checks whether the file already exists or not
        outputFormat = self.parameters['format']
        results = modelutils.read_results_table_from_file(self.outputFile,
                                                          outputFormat)
        if results is not None:
            self.results = results
            return results
        # Try to load from server: only async
        if not self.async_:
            # sync: result is in a file
            return None
        else:
            # async: result is in the server once the job is finished
            self.__load_async_job_results()
            return self.results
예제 #3
0
    def load_gaia_table(self, table):
        """Load a previously saved GAIA .vot table."""
        # if this line breaks, it's f****d
        # apparently very shallow wrap of result = astropy.table.Table.read(file_name, format=output_format)
        data = read_results_table_from_file(table,
                                            output_format='votable',
                                            correct_units=True)
        radius = float(table.rpartition('_')[-1].strip('.vot')) / 100

        self.gaia_data[radius] = data
        self.log.append(f'For radius {radius}; table loaded from {table}')
예제 #4
0
    def get_table(self,
                  filename,
                  response,
                  output_format='votable',
                  verbose=False):
        with open(filename, 'wb') as fh:
            fh.write(response.content)

        table = modelutils.read_results_table_from_file(
            filename, str(output_format))
        return table
예제 #5
0
    def query_target(self,
                     name,
                     filename=None,
                     output_format='votable',
                     verbose=False):
        """
        It executes a query over EHST and download the xml with the results.

        Parameters
        ----------
        name : string
            target name to be requested, mandatory
        filename : string
            file name to be used to store the metadata, optional, default None
        output_format : string
            optional, default 'votable'
            output format of the query
        verbose : bool
            optional, default 'False'
            Flag to display information about the process

        Returns
        -------
        Table with the result of the query. It downloads metadata as a file.
        """

        params = {
            "RESOURCE_CLASS": "OBSERVATION",
            "USERNAME": "******",
            "SELECTED_FIELDS": "OBSERVATION",
            "QUERY": "(TARGET.TARGET_NAME=='" + name + "')",
            "RETURN_TYPE": str(output_format)
        }
        response = self._request('GET',
                                 self.metadata_url,
                                 save=True,
                                 cache=True,
                                 params=params)

        if verbose:
            log.info(self.metadata_url + "?RESOURCE_CLASS=OBSERVATION&"
                     "SELECTED_FIELDS=OBSERVATION&QUERY=(TARGET.TARGET_NAME"
                     "=='" + name + "')&USERNAME=ehst-astroquery&"
                     "RETURN_TYPE=" + str(output_format))
            log.info(self.copying_string.format(filename))
        if filename is None:
            filename = "target.xml"

        shutil.move(response, filename)

        return modelutils.read_results_table_from_file(filename,
                                                       str(output_format))