astroquery/mast/cutouts.py
def download_cutouts(self, *, coordinates=None, size=5, sector=None, path=".", inflate=True,
                         objectname=None, moving_target=False, mt_type=None):
        """
        Download cutout target pixel file(s) around the given coordinates with indicated size.

        Parameters
        ----------
        coordinates : str or `astropy.coordinates` object, optional
            The target around which to search. It may be specified as a
            string or as the appropriate `astropy.coordinates` object.

            NOTE: If moving_target or objectname is supplied, this argument cannot be used.
        size : int, array-like, `~astropy.units.Quantity`
            Optional, default 5 pixels.
            The size of the cutout array. If ``size`` is a scalar number or
            a scalar `~astropy.units.Quantity`, then a square cutout of ``size``
            will be created.  If ``size`` has two elements, they should be in
            ``(ny, nx)`` order.  Scalar numbers in ``size`` are assumed to be in
            units of pixels. `~astropy.units.Quantity` objects must be in pixel or
            angular units.
        sector : int
            Optional.
            The TESS sector to return the cutout from.  If not supplied, cutouts
            from all available sectors on which the coordinate appears will be returned.
        path : str
            Optional.
            The directory in which the cutouts will be saved.
            Defaults to current directory.
        inflate : bool
            Optional, default True.
            Cutout target pixel files are returned from the server in a zip file,
            by default they will be inflated and the zip will be removed.
            Set inflate to false to stop before the inflate step.
        objectname : str, optional
            The target around which to search, by name (objectname="M104")
            or TIC ID (objectname="TIC 141914082"). If moving_target is True, input must be the name or ID (as understood by the
            `JPL ephemerides service <https://ssd.jpl.nasa.gov/horizons.cgi>`__)
            of a moving target such as an asteroid or comet.

            NOTE: If coordinates is supplied, this argument cannot be used.
        moving_target : str, optional
            Indicate whether the object is a moving target or not. Default is set to False, in other words, not a moving target.

            NOTE: If coordinates is supplied, this argument cannot be used.
        mt_type : str, optional
            The moving target type, valid inputs are majorbody and smallbody. If not supplied
            first majorbody is tried and then smallbody if a matching majorbody is not found.

            NOTE: If moving_target is supplied, this argument is ignored.

        Returns
        -------
        response : `~astropy.table.Table`
        """

        if moving_target:

            # Check that objectname has been passed in and coordinates
            # is not
            if coordinates:
                raise InvalidQueryError("Only one of moving_target and coordinates may be specified. Please remove coordinates if using moving_target and objectname.")

            if not objectname:
                raise InvalidQueryError("Please specify the object name or ID (as understood by the `JPL ephemerides service <https://ssd.jpl.nasa.gov/horizons.cgi>`__) of a moving target such as an asteroid or comet.")

            astrocut_request = f"moving_target/astrocut?obj_id={objectname}"
            if mt_type:
                astrocut_request += f"&obj_type={mt_type}"

        else:

            # Get Skycoord object for coordinates/object
            coordinates = parse_input_location(coordinates, objectname)

            astrocut_request = f"astrocut?ra={coordinates.ra.deg}&dec={coordinates.dec.deg}"

        # Adding the arguments that are common between moving/still astrocut requests
        size_dict = _parse_cutout_size(size)
        astrocut_request += f"&y={size_dict['y']}&x={size_dict['x']}&units={size_dict['units']}"

        if sector:
            astrocut_request += "&sector={}".format(sector)

        astrocut_url = self._service_api_connection.REQUEST_URL + astrocut_request
        path = os.path.join(path, '')
        zipfile_path = "{}tesscut_{}.zip".format(path, time.strftime("%Y%m%d%H%M%S"))
        self._download_file(astrocut_url, zipfile_path)

        localpath_table = Table(names=["Local Path"], dtype=[str])

        # Checking if we got a zip file or a json no results message
        if not zipfile.is_zipfile(zipfile_path):
            with open(zipfile_path, 'r') as FLE:
                response = json.load(FLE)
            warnings.warn(response['msg'], NoResultsWarning)
            return localpath_table

        if not inflate:  # not unzipping
            localpath_table['Local Path'] = [zipfile_path]
            return localpath_table

        print("Inflating...")
        # unzipping the zipfile
        zip_ref = zipfile.ZipFile(zipfile_path, 'r')
        cutout_files = zip_ref.namelist()
        zip_ref.extractall(path, members=cutout_files)
        zip_ref.close()
        os.remove(zipfile_path)

        localpath_table['Local Path'] = [path+x for x in cutout_files]
        return localpath_table

        Download cutout target pixel file(s) around the given coordinates with indicated size.

        Parameters
        ----------
        coordinates : str or `astropy.coordinates` object, optional
            The target around which to search. It may be specified as a
            string or as the appropriate `astropy.coordinates` object.

            NOTE: If moving_target or objectname is supplied, this argument cannot be used.
        size : int, array-like, `~astropy.units.Quantity`
            Optional, default 5 pixels.
            The size of the cutout array. If ``size`` is a scalar number or
            a scalar `~astropy.units.Quantity`, then a square cutout of ``size``
            will be created.  If ``size`` has two elements, they should be in
            ``(ny, nx)`` order.  Scalar numbers in ``size`` are assumed to be in
            units of pixels. `~astropy.units.Quantity` objects must be in pixel or
            angular units.
        sector : int
            Optional.
            The TESS sector to return the cutout from.  If not supplied, cutouts
            from all available sectors on which the coordinate appears will be returned.
        path : str
            Optional.
            The directory in which the cutouts will be saved.
            Defaults to current directory.
        inflate : bool
            Optional, default True.
            Cutout target pixel files are returned from the server in a zip file,
            by default they will be inflated and the zip will be removed.
            Set inflate to false to stop before the inflate step.
        objectname : str, optional
            The target around which to search, by name (objectname="M104")
            or TIC ID (objectname="TIC 141914082"). If moving_target is True, input must be the name or ID (as understood by the
            `JPL ephemerides service <https://ssd.jpl.nasa.gov/horizons.cgi>`__)
            of a moving target such as an asteroid or comet.

            NOTE: If coordinates is supplied, this argument cannot be used.
        moving_target : str, optional
            Indicate whether the object is a moving target or not. Default is set to False, in other words, not a moving target.

            NOTE: If coordinates is supplied, this argument cannot be used.
        mt_type : str, optional
            The moving target type, valid inputs are majorbody and smallbody. If not supplied
            first majorbody is tried and then smallbody if a matching majorbody is not found.

            NOTE: If moving_target is supplied, this argument is ignored.

        Returns
        -------
        response : `~astropy.table.Table`
        
Download cutout target pixel file(s) around the given coordinates with indicated size.
Parameters

coordinates : str or `astropy.coordinates` object, optional
The target around which to search. It may be specified as a
string or as the appropriate `astropy.coordinates` object.

If moving_target or objectname is supplied, this argument cannot be used.
size : int, array-like, `~astropy.units.Quantity`
Optional, default 5 pixels.
The size of the cutout array.

If coordinates is supplied, this argument cannot be used.
moving_target : str, optional
Indicate whether the object is a moving target or not. Default is set to False, in other words, not a moving target.

If coordinates is supplied, this argument cannot be used.
mt_type : str, optional
The moving target type, valid inputs are majorbody and smallbody. If not supplied
first majorbody is tried and then smallbody if a matching majorbody is not found.

If moving_target is supplied, this argument is ignored.

Returns


Download cutout target pixel file ( s ) around the given coordinates with indicated size . Parameters coordinates : str or ` astropy . coordinates ` object optional The target around which to search . It may be specified as a string or as the appropriate ` astropy . coordinates ` object . If moving_target or objectname is supplied this argument cannot be used . size : int array - like ` ~astropy . units . Quantity ` Optional default 5 pixels . The size of the cutout array . If coordinates is supplied this argument cannot be used . moving_target : str optional Indicate whether the object is a moving target or not . Default is set to False in other words not a moving target . If coordinates is supplied this argument cannot be used . mt_type : str optional The moving target type valid inputs are majorbody and smallbody . If not supplied first majorbody is tried and then smallbody if a matching majorbody is not found . If moving_target is supplied this argument is ignored . Returns
def download_cutouts(self, *, coordinates=None, size=5, sector=None, path=".", inflate=True,
                         objectname=None, moving_target=False, mt_type=None):
        if moving_target:
            if coordinates:
                raise InvalidQueryError("Only one of moving_target and coordinates may be specified. Please remove coordinates if using moving_target and objectname.")
            if not objectname:
                raise InvalidQueryError("Please specify the object name or ID (as understood by the `JPL ephemerides service <https://ssd.jpl.nasa.gov/horizons.cgi>`__) of a moving target such as an asteroid or comet.")
            astrocut_request = f"moving_target/astrocut?obj_id={objectname}"
            if mt_type:
                astrocut_request += f"&obj_type={mt_type}"
        else:
            coordinates = parse_input_location(coordinates, objectname)
            astrocut_request = f"astrocut?ra={coordinates.ra.deg}&dec={coordinates.dec.deg}"
        size_dict = _parse_cutout_size(size)
        astrocut_request += f"&y={size_dict['y']}&x={size_dict['x']}&units={size_dict['units']}"
        if sector:
            astrocut_request += "&sector={}".format(sector)
        astrocut_url = self._service_api_connection.REQUEST_URL + astrocut_request
        path = os.path.join(path, '')
        zipfile_path = "{}tesscut_{}.zip".format(path, time.strftime("%Y%m%d%H%M%S"))
        self._download_file(astrocut_url, zipfile_path)
        localpath_table = Table(names=["Local Path"], dtype=[str])
        if not zipfile.is_zipfile(zipfile_path):
            with open(zipfile_path, 'r') as FLE:
                response = json.load(FLE)
            warnings.warn(response['msg'], NoResultsWarning)
            return localpath_table
        if not inflate:  
            localpath_table['Local Path'] = [zipfile_path]
            return localpath_table
        print("Inflating...")
        zip_ref = zipfile.ZipFile(zipfile_path, 'r')
        cutout_files = zip_ref.namelist()
        zip_ref.extractall(path, members=cutout_files)
        zip_ref.close()
        os.remove(zipfile_path)
        localpath_table['Local Path'] = [path+x for x in cutout_files]
        return localpath_table
def download_cutouts ( self , * , coordinates = None , size = 5 , sector = None , path = "." , inflate = True , objectname = None , moving_target = False , mt_type = None ) : if moving_target : if coordinates : raise InvalidQueryError ( "Only one of moving_target and coordinates may be specified. Please remove coordinates if using moving_target and objectname." ) if not objectname : raise InvalidQueryError ( "Please specify the object name or ID (as understood by the `JPL ephemerides service <https://ssd.jpl.nasa.gov/horizons.cgi>`__) of a moving target such as an asteroid or comet." ) astrocut_request = f"moving_target/astrocut?obj_id={objectname}" if mt_type : astrocut_request += f"&obj_type={mt_type}" else : coordinates = parse_input_location ( coordinates , objectname ) astrocut_request = f"astrocut?ra={coordinates.ra.deg}&dec={coordinates.dec.deg}" size_dict = _parse_cutout_size ( size ) astrocut_request += f"&y={size_dict['y']}&x={size_dict['x']}&units={size_dict['units']}" if sector : astrocut_request += "&sector={}" . format ( sector ) astrocut_url = self . _service_api_connection . REQUEST_URL + astrocut_request path = os . path . join ( path , '' ) zipfile_path = "{}tesscut_{}.zip" . format ( path , time . strftime ( "%Y%m%d%H%M%S" ) ) self . _download_file ( astrocut_url , zipfile_path ) localpath_table = Table ( names = [ "Local Path" ] , dtype = [ str ] ) if not zipfile . is_zipfile ( zipfile_path ) : with open ( zipfile_path , 'r' ) as FLE : response = json . load ( FLE ) warnings . warn ( response [ 'msg' ] , NoResultsWarning ) return localpath_table if not inflate : localpath_table [ 'Local Path' ] = [ zipfile_path ] return localpath_table print ( "Inflating..." ) zip_ref = zipfile . ZipFile ( zipfile_path , 'r' ) cutout_files = zip_ref . namelist ( ) zip_ref . extractall ( path , members = cutout_files ) zip_ref . close ( ) os . remove ( zipfile_path ) localpath_table [ 'Local Path' ] = [ path + x for x in cutout_files ] return localpath_table
Download cutout target pixel file(s) around the given coordinates with indicated size.
Download cutout target pixel file ( s ) around the given coordinates with indicated size .
"""
        Download cutout target pixel file(s) around the given coordinates with indicated size.

        Parameters
        ----------
        coordinates : str or `astropy.coordinates` object, optional
            The target around which to search. It may be specified as a
            string or as the appropriate `astropy.coordinates` object.

            NOTE: If moving_target or objectname is supplied, this argument cannot be used.
        size : int, array-like, `~astropy.units.Quantity`
            Optional, default 5 pixels.
            The size of the cutout array. If ``size`` is a scalar number or
            a scalar `~astropy.units.Quantity`, then a square cutout of ``size``
            will be created.  If ``size`` has two elements, they should be in
            ``(ny, nx)`` order.  Scalar numbers in ``size`` are assumed to be in
            units of pixels. `~astropy.units.Quantity` objects must be in pixel or
            angular units.
        sector : int
            Optional.
            The TESS sector to return the cutout from.  If not supplied, cutouts
            from all available sectors on which the coordinate appears will be returned.
        path : str
            Optional.
            The directory in which the cutouts will be saved.
            Defaults to current directory.
        inflate : bool
            Optional, default True.
            Cutout target pixel files are returned from the server in a zip file,
            by default they will be inflated and the zip will be removed.
            Set inflate to false to stop before the inflate step.
        objectname : str, optional
            The target around which to search, by name (objectname="M104")
            or TIC ID (objectname="TIC 141914082"). If moving_target is True, input must be the name or ID (as understood by the
            `JPL ephemerides service <https://ssd.jpl.nasa.gov/horizons.cgi>`__)
            of a moving target such as an asteroid or comet.

            NOTE: If coordinates is supplied, this argument cannot be used.
        moving_target : str, optional
            Indicate whether the object is a moving target or not. Default is set to False, in other words, not a moving target.

            NOTE: If coordinates is supplied, this argument cannot be used.
        mt_type : str, optional
            The moving target type, valid inputs are majorbody and smallbody. If not supplied
            first majorbody is tried and then smallbody if a matching majorbody is not found.

            NOTE: If moving_target is supplied, this argument is ignored.

        Returns
        -------
        response : `~astropy.table.Table`
        """ # Check that objectname has been passed in and coordinates # is not # Get Skycoord object for coordinates/object # Adding the arguments that are common between moving/still astrocut requests # Checking if we got a zip file or a json no results message # not unzipping # unzipping the zipfile
self
coordinates
size
sector
path
inflate
objectname
moving_target
mt_type