# Cloud removal from Sentinel 2

A QGIS plugin that builds a cloud-free Sentinel-2 mosaic for a date range and adds it to
the map or exports it to Google Drive. The area of interest is either a Vietnamese
administrative unit (province or commune, 2025 units) or a rectangle drawn anywhere in the
world.

The whole interface is bilingual: English first, Vietnamese after the slash.

## Requirements

The plugin does the image processing on Google Earth Engine, so it cannot work on its own:

* QGIS 3.22 or newer, including QGIS 4 (Qt6).
* The **Google Earth Engine** plugin, installed in the same QGIS profile and signed in.
  It provides the `earthengine-api` Python package and the authentication that this plugin
  reuses.
* A Google Earth Engine account, registered for a cloud project.
* An internet connection. Nothing is computed locally.

If the Earth Engine runtime is missing, the plugin still loads and says what to install
instead of failing during QGIS start-up.

## Installation

From the QGIS plugin manager: *Plugins > Manage and Install Plugins > All*, search for
"Cloud removal from sentinel 2".

To install a zip built from this source: *Plugins > Manage and Install Plugins >
Install from ZIP*.

## Usage

Two buttons are added to their own toolbar:

* **Search S2 by Vietnam boundary** — pick a province, then optionally a commune. Both
  lists are searchable: type any part of the name, with or without accents ("hue" finds
  "Thành phố Huế"). Leaving the commune box empty takes the whole province.
* **Search S2 by drawn rectangle** — drag a rectangle on the map canvas. The extent is
  shown in the dialog and can be edited by hand.

In both dialogs:

1. Choose the start and end date. Both bounds are inclusive.
2. Set the cloud probability threshold. A pixel is masked when
   `COPERNICUS/S2_CLOUD_PROBABILITY` is above this value; 20 is a good starting point.
3. Press **Preview** to see one true colour thumbnail per acquisition day of the range,
   with the cloud cover of each. From there a single day can be searched directly, which is
   the fastest way to escape a cloudy period.
4. Tick the outputs to export (RGB, NDVI, NBR) and give them a file name prefix. The file
   name box only turns on once an output is ticked; without any tick the composite is only
   added to the map.
5. Press **OK**. A progress window stays up until the layers are on the map and the Earth
   Engine export tasks have been submitted.

The composite is added to the map through the Earth Engine plugin: RGB is switched on,
NDVI and NBR come in unchecked. Exports are written to the Google Drive of the signed-in
Earth Engine account, in a folder named after the file name prefix. Depending on the size
of the area they can take a while, and their progress is visible in the Earth Engine task
manager, not in QGIS.

## Imagery and processing

* Surface reflectance: `COPERNICUS/S2_SR_HARMONIZED`.
* Cloud mask: `COPERNICUS/S2_CLOUD_PROBABILITY`, joined per scene, threshold set in the UI.
* Composite: per-pixel median of the masked scenes in the range.
* NDVI from bands B8 and B4, NBR from B8 and B12, both exported as single band floats with
  a colour palette applied on the map.

## Bundled data

`boundary/DiaPhan_CapTinh_2025.json` and `boundary/DiaPhan_CapXa_2025.json` hold the
Vietnamese administrative units of 2025 (34 provinces and their communes) as GeoJSON. They
are read from disk, so the boundary tool needs no external service. Only Vietnam is
covered; use the rectangle tool for any other part of the world.

## License

GPL-2.0-or-later. See [LICENSE](LICENSE).

---

## Tiếng Việt

Plugin ghép ảnh Sentinel-2 đã lọc mây trong một khoảng thời gian, thêm vào bản đồ hoặc xuất
ra Google Drive. Vùng cần lấy ảnh chọn theo ranh giới hành chính Việt Nam (tỉnh hoặc xã,
đơn vị năm 2025) hoặc vẽ một hình chữ nhật ở bất kỳ đâu trên thế giới.

Plugin cần cài plugin **Google Earth Engine** trong cùng profile QGIS và đăng nhập tài
khoản GEE, vì toàn bộ việc tìm và ghép ảnh chạy trên Earth Engine.

Cách dùng: chọn vùng, chọn khoảng ngày, đặt ngưỡng mây, bấm **Preview** để xem ảnh từng
ngày trong khoảng đó rồi chọn lại ngày nếu nhiều mây, tích các sản phẩm cần xuất (RGB,
NDVI, NBR) và bấm **OK**. Ảnh xuất được ghi vào Google Drive của tài khoản Earth Engine
đang đăng nhập.
