# -*- coding: utf-8 -*-
from setuptools import setup

packages = \
['usgsm2m']

package_data = \
{'': ['*']}

install_requires = \
['click>=7.1,<8.0',
 'python-dateutil>=2.8,<3.0',
 'requests>=2.20,<3.0',
 'shapely>=1.7,<2.0',
 'tqdm>=4.58,<5.0']

entry_points = \
{'console_scripts': ['usgsm2m = usgsm2m.cli:cli']}

setup_kwargs = {
    'name': 'usgsm2m',
    'version': '0.10.0',
    'description': 'Search and download Landsat scenes from USGSM2M',
    'long_description': '[![Build](https://img.shields.io/github/workflow/status/ashutoshkumarjha/usgsm2m/Upload%20Python%20Package?label=build&logo=github)](https://github.com/ashutoshkumarjha/usgsm2m/actions/workflows/python-publish.yml)\n[![Tests](https://img.shields.io/github/workflow/status/ashutoshkumarjha/usgsm2m/Run%20tests?label=tests&logo=github)](https://github.com/ashutoshkumarjha/usgsm2m/actions/workflows/run-tests.yml)\n[![codecov](https://codecov.io/gh/ashutoshkumarjha/usgsm2m/branch/master/graph/badge.svg?token=NwVo09Edur)](https://codecov.io/gh/ashutoshkumarjha/usgsm2m)\n\n\n# Description\n\n![CLI Demo](https://raw.githubusercontent.com/ashutoshkumarjha/usgsm2m/master/demo.gif?s=0.5)\n\nThe **usgsm2m** Python package provides an interface to the [USGS M2M](https://m2m.cr.usgs.gov) portal to search and download scenes through a command-line interface or a Python API.\n\nThe following datasets are supported based on only entityid provided. For the different dataset other than this list requires the dataset name. The bulk download is also supported with resume facility.\n\n\n| Dataset Name | Dataset ID |\n|-|-|\n| Landsat 5 TM Collection 1 Level 1 | `landsat_tm_c1` |\n| Landsat 5 TM Collection 2 Level 1 | `landsat_tm_c2_l1` |\n| Landsat 5 TM Collection 2 Level 2 | `landsat_tm_c2_l2` |\n| Landsat 7 ETM+ Collection 1 Level 1 | `landsat_etm_c1` |\n| Landsat 7 ETM+ Collection 2 Level 1 | `landsat_etm_c2_l1` |\n| Landsat 7 ETM+ Collection 2 Level 2 | `landsat_etm_c2_l2` |\n| Landsat 8 Collection 1 Level 1 | `landsat_8_c1` |\n| Landsat 8 Collection 2 Level 1 | `landsat_ot_c2_l1` |\n| Landsat 8 Collection 2 Level 2 | `landsat_ot_c2_l2` |\n| Sentinel 2A | `sentinel_2a` |\n\n\n# Quick start\n\nSearching for Landsat 5 TM scenes that contains the location (12.53, -1.53) acquired during the year 1995.Set the \n\n```\nusgsm2m search --dataset LANDSAT_TM_C1 --location 30.32 78.03 \\\n    --start 1995-01-01 --end 1995-12-31\n```\n\nSearch for Landsat 7 ETM scenes in Brussels with less than 5% of clouds. Save the returned results in a `.csv` file.\n\n```\nusgsm2m search --dataset LANDSAT_ETM_C1 \\\n    --location 50.83 4.38 --clouds 5 > results.csv\n```\n\nDownloading three Landsat scenes from different datasets in the current directory.\n\n```\nusgsm2m download LT51960471995178MPS00 LC80390222013076EDC00 LC82150682015350LGN01\n```\n\nDownloading three Landsat scenes from different the entity file containing **display id** in ./downloadDir\n\n```\ndownloadbulk --entityfile 143042-cloud-5.csv --output ./downloadDir\n```\nTo use the package, Earth Explorer credentials are required ([registration](https://ers.cr.usgs.gov/register)).\n\n# Installation\n\nThe package can be installed using pip.\n\n```\npip install usgsm2m\n```\n\n# Usage\n\n**usgsm2m** can be used both through its command-line interface and as a Python module.\n\n## Command-line interface\n\n```\nusgsm2m --help\n```\n\n```\nUsage: usgsm2m [OPTIONS] COMMAND [ARGS]...\n\nOptions:\n  --help  Show this message and exit.\n\nCommands:\n  download  Download one or several Landsat scenes.\n  search    Search for Landsat scenes.\n```\n\n### Credentials\n\nCredentials for the Earth Explorer portal can be obtained [here](https://ers.cr.usgs.gov/register/).\n\n`--username` and `--password` can be provided as command-line options or as environment variables:\n\n``` shell\nexport USGSM2M_USERNAME=<your_username>\nexport USGSM2M_PASSWORD=<your_password>\n```\n\n### Searching\n\n```\nusgsm2m search --help\n```\n\n```\nUsage: usgsm2m search [OPTIONS]\n\n  Search for Landsat scenes.\n\nOptions:\n  -u, --username TEXT             EarthExplorer username.\n  -p, --password TEXT             EarthExplorer password.\n  -d, --dataset [landsat_tm_c1|landsat_etm_c1|landsat_8_c1|landsat_tm_c2_l1|landsat_tm_c2_l2|landsat_etm_c2_l1|landsat_etm_c2_l2|landsat_ot_c2_l1|landsat_ot_c2_l2|sentinel_2a]\n                                  Landsat data set.\n  -l, --location FLOAT...         Point of interest (latitude, longitude).\n  -b, --bbox FLOAT...             Bounding box (xmin, ymin, xmax, ymax).\n  -c, --clouds INTEGER            Max. cloud cover (1-100).\n  -s, --start TEXT                Start date (YYYY-MM-DD).\n  -e, --end TEXT                  End date (YYYY-MM-DD).\n  -o, --output [entity_id|display_id|json|csv]\n                                  Output format.\n  -m, --limit INTEGER             Max. results returned.\n  --help                          Show this message and exit.\n```\n\n### Downloading \n\n```\nusgsm2m download --help\n```\n\n```\nUsage: usgsm2m download [OPTIONS] [SCENES]...\n\n  Download one or several Landsat scenes.\n\nOptions:\n  -u, --username TEXT    EarthExplorer username.\n  -p, --password TEXT    EarthExplorer password.\n  -d, --dataset TEXT     Dataset.\n  -o, --output PATH      Output directory.\n  -t, --timeout INTEGER  Download timeout in seconds.\n  --skip\n  --help                 Show this message and exit.\n```\n\nIf the `--dataset` is not provided, the dataset is automatically guessed from the scene identifier. Note that only the newer Landsat Product Identifiers contain information related to collection number and processing level. To download Landsat Collection 2 products, use Product IDs or set the `--dataset` option correctly. The download supports the parallel download.\n\n## Bulk Download\n\n```\nusgsm2m download --help\n```\n\n```\nUsage: cli.py downloadbulk [OPTIONS]\n\n  Download one or several scenes.\n\nOptions:\n  -u, --username TEXT    USGS M2M username.\n  -p, --password TEXT    USGS M2M password.\n  -d, --dataset TEXT     Dataset\n  -e, --entityfile PATH  Entity File Name  [required]\n  -o, --output PATH      Output directory.\n  -f, --filetype TEXT    Download File Type {\'bundle\',\'band\'}\n  -i, --idfield TEXT     Entity Id Type {\'displayId\',\'entityId\'}\n  -t, --timeout INTEGER  Download timeout in seconds.\n  --skip\n  --help                 Show this message and exit.\n```\n\nThe --entityfile must contains the scene identifier in each line.If the `--dataset` is not provided, the dataset is automatically guessed from the scene identifier. Note that only the newer Landsat Product Identifiers contain information related to collection number and processing level. \n\n## API\n\n### USGS API\n\n**usgsm2m** provides an interface to the  USGS M2M JSON API. Please refer to the official ([documentation](https://m2m.cr.usgs.gov/api/docs/json/)) for possible request codes and parameters.\n\n#### Basic usage\n\n``` python\nfrom usgsm2m.api import API\n\n# Initialize a new API instance and get an access key\napi = API(username, password)\n\n# Perform a request. Results are returned in a dictionnary\nresponse = api.request(\n    \'<request_endpoint>\',\n    params={\n        "param_1": value_1,\n        "param_2": value_2\n    }\n)\n\n#\xa0Log out\napi.logout()\n```\n\nPlease refer to the official [JSON API Reference](https://m2m.cr.usgs.gov/api/docs/json/) for a list of all available requests.\n\n#### Searching for scenes\n\n``` python\nimport json\nfrom USGSM2M.api import API\n\n# Initialize a new API instance and get an access key\napi = API(username, password)\n\n# Search for Landsat TM scenes\nscenes = api.search(\n    dataset=\'landsat_tm_c1\',\n    latitude=50.85,\n    longitude=-4.35,\n    start_date=\'1995-01-01\',\n    end_date=\'1995-10-01\',\n    max_cloud_cover=10\n)\n\nprint(f"{len(scenes)} scenes found.")\n\n# Process the result\nfor scene in scenes:\n    print(scene[\'acquisition_date\'].strftime(\'%Y-%m-%d\'))\n    # Write scene footprints to disk\n    fname = f"{scene[\'landsat_product_id\']}.geojson"\n    with open(fname, "w") as f:\n        json.dump(scene[\'spatial_coverage\'].__geo_interface__, f)\n\napi.logout()\n```\n\nOutput:\n\n```\n4 scenes found.\n1995-09-23\n1995-08-22\n1995-08-15\n1995-06-28\n```\n\n#### Downloading scenes\n\n``` python\nfrom usgsm2m.usgsm2m import USGSM2M\n\nee = USGSM2M(username, password)\n\nee.download(\'LT51960471995178MPS00\', output_dir=\'./data\')\n\nee.logout()\n```\n',
    'author': 'Ashutosh Kumar Jha',
    'author_email': 'jha.ashutosh@gamil.com',
    'maintainer': 'Ashutosh Kumar Jha',
    'maintainer_email': 'jha.ashutosh@gamil.com',
    'url': 'https://github.com/ashutoshkumarjha/usgsm2m',
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'entry_points': entry_points,
    'python_requires': '>=3.7,<4.0',
}


setup(**setup_kwargs)
