Metadata-Version: 2.4
Name: tropomi_downloader_mpic
Version: 0.1.2
Summary: Download TROPOMI granules from NASA Earthdata into a product and date directory structure
License-Expression: 0BSD
Project-URL: Repository, https://github.com/LeonKuhn/tropomi_downloader_mpic
Project-URL: Documentation, https://github.com/LeonKuhn/tropomi_downloader_mpic#readme
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: earthaccess>=0.19.0
Dynamic: license-file

# TROPOMI downloader (MPIC)

Download full TROPOMI granules from NASA Earthdata into a specified directory
structure.

## Installation

Requires Python 3.12 or newer. Clone this repository and install the package and its dependencies:

```bash
git clone https://github.com/LeonKuhn/tropomi_downloader_mpic.git
cd tropomi_downloader_mpic
python -m pip install .
```

afterwards, you can call `tropomi_download` as an executable.

## Authentication

Create a free [NASA Earthdata Login account](https://urs.earthdata.nasa.gov/).
Store its credentials in `~/.netrc`:

```text
machine urs.earthdata.nasa.gov
login YOUR_EARTHDATA_USERNAME
password YOUR_EARTHDATA_PASSWORD
```

On Linux or macOS, restrict access to this file:

```bash
chmod 0600 ~/.netrc
```

Alternatively, set the `NETRC` environment variable to the absolute path of an
existing credentials file.

See also [NASA's credential setup instructions](https://urs.earthdata.nasa.gov/documentation/for_users/data_access/curl_and_wget).


## Usage from the command line

To download NO2 data for a single day (here: 2022-04-06), run:

```bash
tropomi_download S5P_L2__NO2____HiR --date 2022-04-06
```

In order to download orbits within a date range (here: 2022-04-06 to 2022-04-08), including both boundary days, run:

```bash
tropomi_download S5P_L2__NO2____HiR \
  --date_start 2022-04-06 --date_end 2022-04-08
```

By default, `tropomi_download` stores the downloaded files in the current working directory.
The output directory can be specified using `--output_dir` or `-o`, e.g.:

```bash
tropomi_download S5P_L2__NO2____HiR \
  --date_start 2022-04-06 --date_end 2022-04-08 \
  --output_dir ~/tropomi_data
```

The full table of arguments is given below:

| Argument | Meaning | Default |
| --- | --- | --- |
| `product` | Earthdata product short name | Required |
| `--date`, `-d` | One day, in `YYYY-MM-DD` format | Supply this or both range boundaries |
| `--date_start`, `-s` | First day of a date range | Required with `--date_end` |
| `--date_end`, `-e` | Last day of a date range | Required with `--date_start` |
| `--dataset_version`, `-v` | Earthdata dataset version | `2` |
| `--output_dir`, `-o` | Root directory for downloaded data | Current working directory |
| `--threads` | Download threads per directory | `1` |

Note that:

- `--date` and the date range arguments `--date_start` and `--date_end` are mutually exclusive.
- `threads` must be at least one. 
- Relative output paths are resolved against the current working directory.
- The available product shortnames are available under [available TROPOMI products in Earthdata Search](https://registry.opendata.aws/nasa-sentinel-5p/).

## Usage from within Python

After installing the package into your script's Python environment:

```python
from tropomi_downloader_mpic import download

download(
    product="S5P_L2__NO2____HiR",
    date_start="2022-04-06",
    date_end="2022-04-08",
    output_dir="./data",
    threads=4,
)
```

Dates accept `YYYY-MM-DD` strings or `datetime.date` objects. Both boundary days
are included. `output_dir` accepts a string or `pathlib.Path` and defaults to the
current working directory when omitted. The product and date subdirectories are
created beneath this directory.

## License

This code is available under the [Zero-Clause BSD license (0BSD)](LICENSE).
You may use, copy, modify, and redistribute it for any purpose, including
commercial use, without attribution or a requirement to publish your changes.
The software is provided without warranty.
