Package: prefect-earthdata
prefect-earthdataVisit the full docshereto see additional examples and the API reference.Prefect integrations with NASA Earthdata, taking advantage of theearthaccesslibrary.Getting startedprefect-earthdataprovides a Prefect credentials block and a few tasks to interact with
NASA Earthdata. It does so by leveraging theearthaccesslibrary and its API.Loading theEarthdataCredentialsblock with your credentials, corresponds to calling theearthaccess.login()function.After that, all otherearthaccessfunctions can be directly used, without having to login again.Nevertheless, a few tasks are provided to help taking full advantage of Prefect's observability features.Search and download on NASA Earthdatafromprefectimportflow,get_run_loggerfromprefect_earthdata.credentialsimportEarthdataCredentialsfromprefect_earthdata.tasksimportdownload,search_data@flow(log_prints=True)defexample_earthdata_download_flow():logger=get_run_logger()earthdata_credentials=EarthdataCredentials.load("earthdata-credentials")granules=search_data(earthdata_credentials,count=1,short_name="ATL08",bounding_box=(-92.86,16.26,-91.58,16.97),)logger.info(f"File URL:{granules[0].data_links()[0]}")download_path="/tmp"logger.info(f"Downloading data to{download_path}")files=download(credentials=earthdata_credentials,granules=granules,local_path=download_path,)logger.info(f"Downloaded files:{files}")returngranules,filesexample_earthdata_download_flow()Output:21:07:16.603|INFO|prefect.engine-Createdflowrun'cheerful-peacock'forflow'example-earthdata-download-flow'21:07:18.121|INFO|Flowrun'cheerful-peacock'-Createdtaskrun'search_data-0'fortask'search_data'21:07:18.121|INFO|Flowrun'cheerful-peacock'-Executing'search_data-0'immediately...21:07:19.642|INFO|Taskrun'search_data-0'-You're now authenticated with NASA Earthdata Login21:07:19.644|INFO|Taskrun'search_data-0'-Usingtokenwithexpirationdate:09/01/202321:07:20.243|INFO|Taskrun'search_data-0'-UsingenvironmentvariablesforEDL21:07:21.432|INFO|Taskrun'search_data-0'-Granulesfound:76021:07:22.211|INFO|Taskrun'search_data-0'-FinishedinstateCompleted()21:07:22.225|INFO|Flowrun'cheerful-peacock'-FileURL:https://data.nsidc.earthdatacloud.nasa.gov/nsidc-cumulus-prod-protected/ATLAS/ATL08/005/2018/11/05/ATL08_20181105083647_05760107_005_01.h521:07:22.226|INFO|Flowrun'cheerful-peacock'-Downloadingdatato/tmp21:07:22.586|INFO|Flowrun'cheerful-peacock'-Createdtaskrun'download-0'fortask'download'21:07:22.587|INFO|Flowrun'cheerful-peacock'-Executing'download-0'immediately...21:07:24.529|INFO|Taskrun'download-0'-WearealreadyauthenticatedwithNASAEDL21:07:28.677|INFO|Taskrun'download-0'-Getting1granules,approxdownloadsize:0.0GBQUEUEINGTASKS|:100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████|1/1[00:00<00:00,2016.49it/s]PROCESSINGTASKS|:100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████|1/1[00:11<00:00,11.45s/it]COLLECTINGRESULTS|:100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████|1/1[00:00<00:00,25115.59it/s]21:07:40.388|INFO|Taskrun'download-0'-FinishedinstateCompleted()21:07:40.392|INFO|Flowrun'cheerful-peacock'-Downloadedfiles:['ATL08_20181105083647_05760107_005_01.h5']21:07:41.243|INFO|Flowrun'cheerful-peacock'-FinishedinstateCompleted()ResourcesFor more tips on how to use tasks and flows in a Collection, check outUsing Collections!InstallationInstallprefect-earthdatawithpip:pipinstallprefect-earthdataRequires an installation of Python 3.8+.We recommend using a Python virtual environment manager such as pipenv, conda or virtualenv.These tasks are designed to work with Prefect 2.0. For more information about how to use Prefect, please refer to thePrefect documentation.FeedbackIf you encounter any bugs while usingprefect-earthdata, feel free to open an issue in theprefect-earthdatarepository.If you have any questions or issues while usingprefect-earthdata, you can find help in either thePrefect Discourse forumor thePrefect Slack community.Feel free to star or watchprefect-earthdatafor updates too!ContributingIf you'd like to help contribute to fix an issue or add a feature toprefect-earthdata, pleasepropose changes through a pull request from a fork of the repository.Here are the steps:Fork the repositoryClone the forked repositoryInstall the repository and its dependencies:pip install -e ".[dev]"Make desired changesAdd testsInsert an entry toCHANGELOG.mdInstallpre-committo perform quality checks prior to commit:pre-commit installgit commit,git push, and create a pull request