Skip to main content

Python wrapper for ASF's SearchAPI

Project description

asf_search

PyPI version Conda version

PyPI pyversions PyPI license

CodeFactor Github workflow

CodeCov

Documentation Join the chat at https://gitter.im/ASFDiscovery/asf_search

Python wrapper for the ASF SearchAPI

import asf_search as asf

results = asf.granule_search(['ALPSRS279162400', 'ALPSRS279162200'])
print(results)

wkt = 'POLYGON((-135.7 58.2,-136.6 58.1,-135.8 56.9,-134.6 56.1,-134.9 58.0,-135.7 58.2))'
results = asf.geo_search(platform=[asf.PLATFORM.SENTINEL1], intersectsWith=wkt, maxResults=10)
print(results)

Install

In order to easily manage dependencies, we recommend using dedicated project environments via Anaconda/Miniconda or Python virtual environments.

asf_search can be installed into a conda environment with

conda install -c conda-forge asf_search

or into a virtual environment with

python3 -m pip install asf_search

To install pytest/cov packages for testing, along with the minimal packages:

python3 -m pip install asf_search[test]

Usage

Full documentation is available at https://docs.asf.alaska.edu/asf_search/basics/

Programmatically searching for ASF data is made simple with asf_search. Several search functions are provided:

  • geo_search() Find product info over an area of interest using a WKT string
  • granule_search() Find product info using a list of scenes
  • product_search() Find product info using a list of products
  • search() Find product info using any combination combination of search parameters
  • stack() Find a baseline stack of products using a reference scene
  • Additionally, numerous constants are provided to ease the search process

Additionally, asf_search support downloading data, both from search results as provided by the above search functions, and directly on product URLs. An authenticated session is generally required. This is provided by the ASFSession class, and use of one of its three authentication methods:

  • auth_with_creds('user', 'pass')
  • auth_with_token('EDL token')
  • auth_with_cookiejar(http.cookiejar)

That session should be passed to whichever download method is being called, can be re-used, and is thread safe. Examples:

results = asf_search.granule_search([...])
session = asf_search.ASFSession()
session.auth_with_creds('user', 'pass')
results.download(path='/Users/SARGuru/data', session=session)

Alternately, downloading a list of URLs contained in urls and creating the session inline:

urls = [...]
asf_search.download_urls(urls=urls, path='/Users/SARGuru/data', session=ASFSession().auth_with_token('EDL token'))

Also note that ASFSearchResults.download() and the generic download_urls() function both accept a processes parameter which allows for parallel downloads.

Further examples of all of the above can be found in examples/

Development

Branching

Instance Branch Description, Instructions, Notes
Stable stable Accepts merges from Working and Hotfixes
Working master Accepts merges from Features/Issues and Hotfixes
Features/Issues topic-* Always branch off HEAD of Working
Hotfix hotfix-* Always branch off Stable

For an extended description of our workflow, see https://gist.github.com/digitaljhelms/4287848

Enable Logging

We use standard the standard logging in our package for output.

Heres a basic example for hooking into it with your application:

import asf_search as asf
import logging
ASF_LOGGER = logging.getLogger("asf_search")
formatter = logging.Formatter('[ %(asctime)s (%(name)s) %(filename)s:%(lineno)d ] %(levelname)s - %(message)s')

# Get output to the console:
stream_handle = logging.StreamHandler()
stream_handle.setFormatter(formatter)
ASF_LOGGER.addHandler(stream_handle)
# If you want it write to a file too:
file_handle = logging.FileHandler('MyCustomApp.log')
file_handle.setFormatter(formatter)
ASF_LOGGER.addHandler(file_handle)
# Only see messages that might affect you
ASF_LOGGER.setLevel(logging.WARNING)
# Test if the logger throws an error, you see it as expected:
ASF_LOGGER.error("This is only a drill. Please do not panic.")
# Should output this:
# [ 2023-01-17 10:04:53,780 (asf_search) main.py:42 ] ERROR - This is only a drill. Please do not panic.

For more configure options on logging, please visit their howto page.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asf_search-9.0.7.tar.gz (844.2 kB view details)

Uploaded Source

Built Distribution

asf_search-9.0.7-py3-none-any.whl (107.6 kB view details)

Uploaded Python 3

File details

Details for the file asf_search-9.0.7.tar.gz.

File metadata

  • Download URL: asf_search-9.0.7.tar.gz
  • Upload date:
  • Size: 844.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for asf_search-9.0.7.tar.gz
Algorithm Hash digest
SHA256 78ae9b0b5ed6bc9cf5a65a798c673e66d896cd860c620fc799aa8967810ee8f3
MD5 a42b84d1d16e271df2d94cd7242d3f68
BLAKE2b-256 5be9519735f4cb5fbcc2345f77446efa3ebc4e53c27a728fd4944adc6bdc52aa

See more details on using hashes here.

File details

Details for the file asf_search-9.0.7-py3-none-any.whl.

File metadata

  • Download URL: asf_search-9.0.7-py3-none-any.whl
  • Upload date:
  • Size: 107.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.23

File hashes

Hashes for asf_search-9.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 34df4c8fb96a6512eec78709c37dc535dad85c782bd5742abe2cd87436bdd67e
MD5 6f110d3f138f16502537363991559f41
BLAKE2b-256 57eecb90af0c8db00864568da7ec19c050ae2d7c7f10d3c9860e058602f20be9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page