API Python

Documentação detalhada de todos os métodos presentes na biblioteca


Cbers4aAPI

The CBERS4A API class. Query, download or transform data from CBERS-4A STAC API.

Parameters:
  • email (Optional[str], default: None ) –

    Sign-in e-mail used at https://www.dgi.inpe.br/catalogo/explore

query(location, initial_date, end_date, cloud, limit, collections) staticmethod

Query Images from INPE's catalog

Parameters:
  • location (Union[list[float], Polygon, tuple]) –

    Bounding box, Polygon shape or Path and Row Tuple

  • initial_date (date) –

    Images from this date

  • end_date (date) –

    Images to this date

  • cloud (int) –

    Percentage of cloud coverage

  • limit (int) –

    Limit of returned images

  • collections (Union[list[str], list[Collections]]) –

    Collection's name(s)

Notes: Location: - Bounding box: location=[-0.5, 1.0, 0.5, -0.5] - Polygon shape from shapely - Path and row respectively: location=(225,75) Initial and end dates: - Use date object from datetime library: datetime.date(2021,05,25) - Caution to end date always be bigger than initial date - e.g. initial_date=datetime.date(2021,08,15) Cloud coverage: - Search for scenes less or equal (<=) cloud coverage percentage. - e.g. cloud=70 - Must be between 0 and 100. Limit: - Values greater than 0. - e.g. limit=500. Collections: - Use the collections enum via from cbers4asat import Collections as col - Available collections from INPE catalog https://www.dgi.inpe.br/catalogo/explore - Always an array of collections name. - e.g. [col.AMAZONIA1_WFI_L2_DN] or [col.AMAZONIA1_WFI_L2_DN, col.CBERS4A_WPM_L4_DN] etc.

Returns:
  • dict( dict ) –

    Dict with GeoJSON-like format

Raises: Exception: If any input is invalid.

query_by_id(scene_id, collection) staticmethod

Search a product by id

Parameters:
  • scene_id (Union[List[str], str]) –

    One or more scene's id

  • collection (Union[str, Collections]) –

    Collection's name

Returns: dict: Dict with GeoJSON-like format

download(products, bands, threads=cpu_count(), outdir=getcwd(), with_folder=False, with_metadata=False)

Download bands from all given scenes

Parameters:
  • products (Union[dict, GeoDataFrame]) –

    Data returned from API

  • bands (list[str]) –

    List of band color's name. "red", "green", "blue", "nir", "pan"

  • threads (int, default: cpu_count() ) –

    Max of cpu threads

  • outdir (str, default: getcwd() ) –

    Output path

  • with_folder (bool, default: False ) –

    Group scene bands in a sub folder

  • with_metadata (bool, default: False ) –

    Download band's metadata (XML)

Examples: - download(my_query_result, ['red', 'green'], 3, './downlaods', true) - download(my_query_result, ['red'], outdir='./downloads', with_folder=true) - download(my_query_result, ['blue'], with_metadata=True) Returns: GeoTIFF files

to_geodataframe(products) staticmethod

Transform products list to a GeoDataFrame

Parameters:
  • products (dict) –

    GeoJSON-like dictionary returned from API

Returns: GeoDataFrame of products.


Tools

rgbn_composite(red, green, blue, nir=None, outdir=getcwd(), filename='rgbn_composite.tif')

Stack bands

Parameters:
  • red (str) –

    Red channel

  • green (str) –

    Green channel

  • blue (str) –

    Blue channel

  • nir (str, default: None ) –

    (Optional) Nir channel

  • outdir (str, default: getcwd() ) –

    Output path

  • filename (str, default: 'rgbn_composite.tif' ) –

    Output filename

Returns: GeoTIFF file

pansharpening(panchromatic=None, multispectral=None, outdir=getcwd(), filename='pansharp.tif')

Pansharpen multispectral file

Parameters:
  • panchromatic (str, default: None ) –

    Panchromatic band (Band 0)

  • multispectral (str, default: None ) –

    Multispectral band

  • outdir (str, default: getcwd() ) –

    Output Directory

  • filename (str, default: 'pansharp.tif' ) –

    Output file name

Returns: GeoTIFF file

clip(raster, mask, outdir=getcwd(), filename='raster_clip.tif', **kwargs)

Clip raster

Parameters:
  • raster (str) –

    Image to clip

  • mask (Union[Dict, Polygon]) –

    Area to use as clip mask

  • outdir (str, default: getcwd() ) –

    Output Directory

  • filename (str, default: 'raster_clip.tif' ) –

    Output file name

  • kwargs

    Any option you want to add in rasterio mask method

Returns: GeoTIFF file


grid_download(satellite='cbers4a', sensor='mux', outdir=getcwd())

Download path and row grid from CBERS-04A and AMAZONIA1

Parameters:
  • satellite (Literal['cbers4a', 'amazonia1'], default: 'cbers4a' ) –

    "cbers4a" or "amazonia1"

  • sensor (Literal['mux', 'wfi'], default: 'mux' ) –

    "mux" or "wfi"

  • outdir (str, default: getcwd() ) –

    Output path

Examples: - grid_download("cbers4a", "mux") - grid_download(satellite="amazonia1", "wfi", outdir="./downloads") Returns: .kmz file


read_geojson(geojson_file)

Read a GeoJSON file into a GeoJSON object.

Parameters:
  • geojson_file (str) –

    GeoJson file path

Returns: GeoJson object