izisat 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- izisat-0.1.0/LICENSE +21 -0
- izisat-0.1.0/PKG-INFO +151 -0
- izisat-0.1.0/README.md +138 -0
- izisat-0.1.0/pyproject.toml +12 -0
- izisat-0.1.0/setup.cfg +4 -0
- izisat-0.1.0/src/izisat/__init__.py +0 -0
- izisat-0.1.0/src/izisat/izisentinel.py +161 -0
- izisat-0.1.0/src/izisat/misc/__init__.py +0 -0
- izisat-0.1.0/src/izisat/misc/connections.py +554 -0
- izisat-0.1.0/src/izisat/misc/dates.py +24 -0
- izisat-0.1.0/src/izisat/misc/files.py +135 -0
- izisat-0.1.0/src/izisat/misc/raster_processing.py +373 -0
- izisat-0.1.0/src/izisat/misc/utils.py +162 -0
- izisat-0.1.0/src/izisat.egg-info/PKG-INFO +151 -0
- izisat-0.1.0/src/izisat.egg-info/SOURCES.txt +16 -0
- izisat-0.1.0/src/izisat.egg-info/dependency_links.txt +1 -0
- izisat-0.1.0/src/izisat.egg-info/requires.txt +4 -0
- izisat-0.1.0/src/izisat.egg-info/top_level.txt +1 -0
izisat-0.1.0/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2025 anderson stolfi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
izisat-0.1.0/PKG-INFO
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: izisat
|
3
|
+
Version: 0.1.0
|
4
|
+
Summary: Add your description here
|
5
|
+
Requires-Python: >=3.12
|
6
|
+
Description-Content-Type: text/markdown
|
7
|
+
License-File: LICENSE
|
8
|
+
Requires-Dist: geopandas>=1.1.1
|
9
|
+
Requires-Dist: loguru>=0.7.3
|
10
|
+
Requires-Dist: requests>=2.32.4
|
11
|
+
Requires-Dist: tqdm>=4.67.1
|
12
|
+
Dynamic: license-file
|
13
|
+
|
14
|
+
# izisat
|
15
|
+
|
16
|
+
`izisat` is a Python library designed to facilitate the automated download of Sentinel-2 satellite imagery bands from the Copernicus Open Access Hub (previously SciHub). It provides functionalities to connect to the Copernicus API, construct queries based on geographical footprints and time ranges, retrieve product information, and download specified bands to a local directory structure.
|
17
|
+
|
18
|
+
## Features
|
19
|
+
|
20
|
+
* **API Connection:** Securely connect to the Copernicus Open Access Hub using provided credentials.
|
21
|
+
* **Query Construction:** Build complex queries for Sentinel-2 products based on:
|
22
|
+
* Geographical footprint (WKT format)
|
23
|
+
* Start and End Dates
|
24
|
+
* Cloud Cover Percentage
|
25
|
+
* Product Type (e.g., L2A)
|
26
|
+
* Platform Name (e.g., SENTINEL-2)
|
27
|
+
* **Product Retrieval:** Fetch a list of available Sentinel-2 products matching the constructed query.
|
28
|
+
* **Automated Folder Creation:** Organize downloaded bands into a structured directory based on product information (e.g., `auxiliary/Sentinel-2/YYYY/MM/DD/TILE/L2A/RESOLUTION/`).
|
29
|
+
* **Band Downloading:** Download specific Sentinel-2 bands (e.g., B02, B03, B04, B08) for retrieved products.
|
30
|
+
|
31
|
+
## Installation
|
32
|
+
|
33
|
+
*(Placeholder: Add installation instructions here, e.g., using pip and a `requirements.txt` or `pyproject.toml`)*
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
|
37
|
+
The `IZISentinel` class is the main entry point for interacting with the library. Below is an example demonstrating how to use `izisat` to download Sentinel-2 bands.
|
38
|
+
|
39
|
+
```python
|
40
|
+
import geopandas as gpd
|
41
|
+
from datetime import datetime, timedelta
|
42
|
+
from izisat.izisentinel import IZISentinel
|
43
|
+
|
44
|
+
# Configuration
|
45
|
+
DOWNLOAD_FOLDER = '/home/ppz/Documentos/coding/izisat/auxiliary' # Adjust as needed
|
46
|
+
MAX_CLOUD_COVER = 99
|
47
|
+
BANDS_DICT = {"L2A":{"10m": ["B02", "B03","B04", "B08"]}} # Specify bands and resolutions
|
48
|
+
PLATFORM_NAME = "SENTINEL-2"
|
49
|
+
SATELLITE_TYPE = 'L2A' # Level 2A products (bottom-of-atmosphere corrected)
|
50
|
+
COPERNICUS_USER='your_copernicus_username' # Replace with your Copernicus username
|
51
|
+
COPERNICUS_PASSWD='your_copernicus_password' # Replace with your Copernicus password
|
52
|
+
|
53
|
+
# Define date range
|
54
|
+
today = datetime.now().strftime('%Y-%m-%d')
|
55
|
+
one_week_ago = (datetime.now() - timedelta(days=7)).strftime('%Y-%m-%d')
|
56
|
+
|
57
|
+
# Initialize the downloader
|
58
|
+
downloader = IZISentinel(output_base_path=DOWNLOAD_FOLDER)
|
59
|
+
|
60
|
+
# 1. Connect to Copernicus API
|
61
|
+
access_token, refresh_token, dt_access_token = downloader.connect_to_api(
|
62
|
+
username=COPERNICUS_USER,
|
63
|
+
password=COPERNICUS_PASSWD
|
64
|
+
)
|
65
|
+
|
66
|
+
# 2. Load geographical footprint (example using a GeoJSON file)
|
67
|
+
# Replace 'path/to/your/farm.geojson' with the actual path to your GeoJSON file
|
68
|
+
# The GeoJSON should contain a polygon representing your area of interest.
|
69
|
+
try:
|
70
|
+
farm = gpd.read_file('/home/ppz/Documentos/coding/forestry_monitor/data/vectors/farms/farms.geojson')
|
71
|
+
footprint = farm.iloc[0].geometry.wkt # Assuming the first feature's geometry is the desired footprint
|
72
|
+
except Exception as e:
|
73
|
+
print(f"Error loading GeoJSON or extracting footprint: {e}")
|
74
|
+
print("Please ensure 'forestry_monitor/data/vectors/farms/farms.geojson' exists and is valid, or provide a WKT string directly.")
|
75
|
+
footprint = "POLYGON ((<lon1> <lat1>, <lon2> <lat2>, ...))" # Example placeholder for direct WKT
|
76
|
+
|
77
|
+
# 3. Construct the query
|
78
|
+
query = downloader.construct_query(
|
79
|
+
footprint=footprint,
|
80
|
+
end_date=today,
|
81
|
+
start_date=one_week_ago,
|
82
|
+
cloud_cover_percentage=MAX_CLOUD_COVER,
|
83
|
+
type=SATELLITE_TYPE,
|
84
|
+
platform_name=PLATFORM_NAME
|
85
|
+
)
|
86
|
+
|
87
|
+
# 4. Retrieve products
|
88
|
+
products = downloader.products_from_sentinel_2(query)
|
89
|
+
|
90
|
+
# 5. Download specified bands
|
91
|
+
if products:
|
92
|
+
images_downloaded = downloader.download_sentinel2_bands(
|
93
|
+
access_token,
|
94
|
+
products,
|
95
|
+
BANDS_DICT,
|
96
|
+
dt_access_token,
|
97
|
+
refresh_token,
|
98
|
+
tile=None # Specify a tile if you want to filter by tile, otherwise None
|
99
|
+
)
|
100
|
+
print(f"Downloaded images info: {images_downloaded}")
|
101
|
+
else:
|
102
|
+
print("No products found for the given query.")
|
103
|
+
```
|
104
|
+
|
105
|
+
## Dependencies
|
106
|
+
|
107
|
+
The core dependencies for `izisat` include:
|
108
|
+
|
109
|
+
* `loguru`: For logging.
|
110
|
+
* `geopandas`: For handling geographical data (used in the example for footprint).
|
111
|
+
* `datetime`: For date and time operations.
|
112
|
+
|
113
|
+
*(Note: Specific versions and other implicit dependencies from `izisat.misc` modules would be listed in `pyproject.toml` or `requirements.txt`)*
|
114
|
+
|
115
|
+
## Project Structure
|
116
|
+
|
117
|
+
```
|
118
|
+
.
|
119
|
+
├── auxiliary/
|
120
|
+
│ └── Sentinel-2/ # Default download location for Sentinel-2 bands
|
121
|
+
├── src/
|
122
|
+
│ └── izisat/
|
123
|
+
│ ├── __init__.py
|
124
|
+
│ ├── izisentinel.py # Main class for Sentinel-2 band downloading
|
125
|
+
│ └── misc/
|
126
|
+
│ ├── __init__.py
|
127
|
+
│ ├── connections.py # Handles API connections to Copernicus
|
128
|
+
│ ├── dates.py # Utility functions for date handling
|
129
|
+
│ ├── files.py # Utility functions for file and directory operations
|
130
|
+
│ └── utils.py # General utility functions (e.g., query construction, product info retrieval)
|
131
|
+
├── .gitignore
|
132
|
+
├── LICENSE
|
133
|
+
├── pyproject.toml
|
134
|
+
├── README.md
|
135
|
+
└── uv.lock
|
136
|
+
```
|
137
|
+
|
138
|
+
## How to Contribute
|
139
|
+
|
140
|
+
We welcome contributions to `izisat`! If you'd like to contribute, please follow these guidelines:
|
141
|
+
|
142
|
+
1. **Reporting Bugs:** If you find a bug, please open an issue on the GitHub repository. Provide a clear and concise description of the bug, steps to reproduce it, and expected behavior.
|
143
|
+
2. **Suggesting Features:** For new features or enhancements, open an issue to discuss your ideas.
|
144
|
+
3. **Submitting Pull Requests:**
|
145
|
+
* Fork the repository and create a new branch for your changes.
|
146
|
+
* Ensure your code adheres to the project's coding style.
|
147
|
+
* Write clear and concise commit messages.
|
148
|
+
* Include tests for new features or bug fixes.
|
149
|
+
* Submit a pull request with a detailed description of your changes.
|
150
|
+
|
151
|
+
Thank you for your contributions!
|
izisat-0.1.0/README.md
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
# izisat
|
2
|
+
|
3
|
+
`izisat` is a Python library designed to facilitate the automated download of Sentinel-2 satellite imagery bands from the Copernicus Open Access Hub (previously SciHub). It provides functionalities to connect to the Copernicus API, construct queries based on geographical footprints and time ranges, retrieve product information, and download specified bands to a local directory structure.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
* **API Connection:** Securely connect to the Copernicus Open Access Hub using provided credentials.
|
8
|
+
* **Query Construction:** Build complex queries for Sentinel-2 products based on:
|
9
|
+
* Geographical footprint (WKT format)
|
10
|
+
* Start and End Dates
|
11
|
+
* Cloud Cover Percentage
|
12
|
+
* Product Type (e.g., L2A)
|
13
|
+
* Platform Name (e.g., SENTINEL-2)
|
14
|
+
* **Product Retrieval:** Fetch a list of available Sentinel-2 products matching the constructed query.
|
15
|
+
* **Automated Folder Creation:** Organize downloaded bands into a structured directory based on product information (e.g., `auxiliary/Sentinel-2/YYYY/MM/DD/TILE/L2A/RESOLUTION/`).
|
16
|
+
* **Band Downloading:** Download specific Sentinel-2 bands (e.g., B02, B03, B04, B08) for retrieved products.
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
*(Placeholder: Add installation instructions here, e.g., using pip and a `requirements.txt` or `pyproject.toml`)*
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
The `IZISentinel` class is the main entry point for interacting with the library. Below is an example demonstrating how to use `izisat` to download Sentinel-2 bands.
|
25
|
+
|
26
|
+
```python
|
27
|
+
import geopandas as gpd
|
28
|
+
from datetime import datetime, timedelta
|
29
|
+
from izisat.izisentinel import IZISentinel
|
30
|
+
|
31
|
+
# Configuration
|
32
|
+
DOWNLOAD_FOLDER = '/home/ppz/Documentos/coding/izisat/auxiliary' # Adjust as needed
|
33
|
+
MAX_CLOUD_COVER = 99
|
34
|
+
BANDS_DICT = {"L2A":{"10m": ["B02", "B03","B04", "B08"]}} # Specify bands and resolutions
|
35
|
+
PLATFORM_NAME = "SENTINEL-2"
|
36
|
+
SATELLITE_TYPE = 'L2A' # Level 2A products (bottom-of-atmosphere corrected)
|
37
|
+
COPERNICUS_USER='your_copernicus_username' # Replace with your Copernicus username
|
38
|
+
COPERNICUS_PASSWD='your_copernicus_password' # Replace with your Copernicus password
|
39
|
+
|
40
|
+
# Define date range
|
41
|
+
today = datetime.now().strftime('%Y-%m-%d')
|
42
|
+
one_week_ago = (datetime.now() - timedelta(days=7)).strftime('%Y-%m-%d')
|
43
|
+
|
44
|
+
# Initialize the downloader
|
45
|
+
downloader = IZISentinel(output_base_path=DOWNLOAD_FOLDER)
|
46
|
+
|
47
|
+
# 1. Connect to Copernicus API
|
48
|
+
access_token, refresh_token, dt_access_token = downloader.connect_to_api(
|
49
|
+
username=COPERNICUS_USER,
|
50
|
+
password=COPERNICUS_PASSWD
|
51
|
+
)
|
52
|
+
|
53
|
+
# 2. Load geographical footprint (example using a GeoJSON file)
|
54
|
+
# Replace 'path/to/your/farm.geojson' with the actual path to your GeoJSON file
|
55
|
+
# The GeoJSON should contain a polygon representing your area of interest.
|
56
|
+
try:
|
57
|
+
farm = gpd.read_file('/home/ppz/Documentos/coding/forestry_monitor/data/vectors/farms/farms.geojson')
|
58
|
+
footprint = farm.iloc[0].geometry.wkt # Assuming the first feature's geometry is the desired footprint
|
59
|
+
except Exception as e:
|
60
|
+
print(f"Error loading GeoJSON or extracting footprint: {e}")
|
61
|
+
print("Please ensure 'forestry_monitor/data/vectors/farms/farms.geojson' exists and is valid, or provide a WKT string directly.")
|
62
|
+
footprint = "POLYGON ((<lon1> <lat1>, <lon2> <lat2>, ...))" # Example placeholder for direct WKT
|
63
|
+
|
64
|
+
# 3. Construct the query
|
65
|
+
query = downloader.construct_query(
|
66
|
+
footprint=footprint,
|
67
|
+
end_date=today,
|
68
|
+
start_date=one_week_ago,
|
69
|
+
cloud_cover_percentage=MAX_CLOUD_COVER,
|
70
|
+
type=SATELLITE_TYPE,
|
71
|
+
platform_name=PLATFORM_NAME
|
72
|
+
)
|
73
|
+
|
74
|
+
# 4. Retrieve products
|
75
|
+
products = downloader.products_from_sentinel_2(query)
|
76
|
+
|
77
|
+
# 5. Download specified bands
|
78
|
+
if products:
|
79
|
+
images_downloaded = downloader.download_sentinel2_bands(
|
80
|
+
access_token,
|
81
|
+
products,
|
82
|
+
BANDS_DICT,
|
83
|
+
dt_access_token,
|
84
|
+
refresh_token,
|
85
|
+
tile=None # Specify a tile if you want to filter by tile, otherwise None
|
86
|
+
)
|
87
|
+
print(f"Downloaded images info: {images_downloaded}")
|
88
|
+
else:
|
89
|
+
print("No products found for the given query.")
|
90
|
+
```
|
91
|
+
|
92
|
+
## Dependencies
|
93
|
+
|
94
|
+
The core dependencies for `izisat` include:
|
95
|
+
|
96
|
+
* `loguru`: For logging.
|
97
|
+
* `geopandas`: For handling geographical data (used in the example for footprint).
|
98
|
+
* `datetime`: For date and time operations.
|
99
|
+
|
100
|
+
*(Note: Specific versions and other implicit dependencies from `izisat.misc` modules would be listed in `pyproject.toml` or `requirements.txt`)*
|
101
|
+
|
102
|
+
## Project Structure
|
103
|
+
|
104
|
+
```
|
105
|
+
.
|
106
|
+
├── auxiliary/
|
107
|
+
│ └── Sentinel-2/ # Default download location for Sentinel-2 bands
|
108
|
+
├── src/
|
109
|
+
│ └── izisat/
|
110
|
+
│ ├── __init__.py
|
111
|
+
│ ├── izisentinel.py # Main class for Sentinel-2 band downloading
|
112
|
+
│ └── misc/
|
113
|
+
│ ├── __init__.py
|
114
|
+
│ ├── connections.py # Handles API connections to Copernicus
|
115
|
+
│ ├── dates.py # Utility functions for date handling
|
116
|
+
│ ├── files.py # Utility functions for file and directory operations
|
117
|
+
│ └── utils.py # General utility functions (e.g., query construction, product info retrieval)
|
118
|
+
├── .gitignore
|
119
|
+
├── LICENSE
|
120
|
+
├── pyproject.toml
|
121
|
+
├── README.md
|
122
|
+
└── uv.lock
|
123
|
+
```
|
124
|
+
|
125
|
+
## How to Contribute
|
126
|
+
|
127
|
+
We welcome contributions to `izisat`! If you'd like to contribute, please follow these guidelines:
|
128
|
+
|
129
|
+
1. **Reporting Bugs:** If you find a bug, please open an issue on the GitHub repository. Provide a clear and concise description of the bug, steps to reproduce it, and expected behavior.
|
130
|
+
2. **Suggesting Features:** For new features or enhancements, open an issue to discuss your ideas.
|
131
|
+
3. **Submitting Pull Requests:**
|
132
|
+
* Fork the repository and create a new branch for your changes.
|
133
|
+
* Ensure your code adheres to the project's coding style.
|
134
|
+
* Write clear and concise commit messages.
|
135
|
+
* Include tests for new features or bug fixes.
|
136
|
+
* Submit a pull request with a detailed description of your changes.
|
137
|
+
|
138
|
+
Thank you for your contributions!
|
izisat-0.1.0/setup.cfg
ADDED
File without changes
|
@@ -0,0 +1,161 @@
|
|
1
|
+
|
2
|
+
from izisat.misc.raster_processing import RasterProcessing
|
3
|
+
from izisat.misc.connections import Connections
|
4
|
+
from izisat.misc.utils import Utils
|
5
|
+
from izisat.misc.files import Files
|
6
|
+
from loguru import logger
|
7
|
+
import geopandas as gpd
|
8
|
+
from datetime import datetime, timedelta
|
9
|
+
from shapely.geometry import box
|
10
|
+
|
11
|
+
|
12
|
+
class IZISentinel:
|
13
|
+
def __init__(self, output_base_path, username, password):
|
14
|
+
"""Initializes the Sentinel2_Band_Downloader instance."""
|
15
|
+
self.output_base_path = output_base_path
|
16
|
+
self.access_token, self.refresh_token, self.dt_access_token = self.connect_to_api(username, password)
|
17
|
+
|
18
|
+
def connect_to_api(self, username, password):
|
19
|
+
"""Connects to the Sentinel API and obtains an access token."""
|
20
|
+
connections = Connections()
|
21
|
+
access_token, refresh_token, dt_access_token = connections.access_token(username, password)
|
22
|
+
return access_token, refresh_token, dt_access_token
|
23
|
+
|
24
|
+
def construct_query(self, geodataframe, end_date, cloud_cover_percentage, type, platform_name):
|
25
|
+
"""Constructs a query for retrieving Sentinel-2 products based on specified parameters."""
|
26
|
+
utils = Utils()
|
27
|
+
start_date = (end_date - timedelta(days=1)).strftime('%Y-%m-%d')
|
28
|
+
end_date = end_date.strftime('%Y-%m-%d')
|
29
|
+
projected_gdf = gdf.to_crs(geodataframe.estimate_utm_crs('SIRGAS 2000'))
|
30
|
+
geodataframe = projected_gdf.buffer(1000)
|
31
|
+
geodataframe = geodataframe.to_crs(4674)
|
32
|
+
minx, miny, maxx, maxy = geodataframe.total_bounds
|
33
|
+
bbox_geom = box(minx, miny, maxx, maxy)
|
34
|
+
bbox_gdf = gpd.GeoDataFrame(geometry=[bbox_geom], crs=geodataframe.crs)
|
35
|
+
footprint = bbox_gdf.iloc[0].geometry.wkt
|
36
|
+
query = utils.construct_query_for_sentinel2_products(footprint, start_date, end_date, cloud_cover_percentage, type, platform_name)
|
37
|
+
return query
|
38
|
+
|
39
|
+
def products_from_sentinel_2(self, params):
|
40
|
+
"""Retrieves Sentinel-2 products based on the provided query parameters."""
|
41
|
+
connections = Connections()
|
42
|
+
products = connections.retrieve_sent_prod_from_query(params)
|
43
|
+
return products
|
44
|
+
|
45
|
+
def get_products_info(self, products):
|
46
|
+
"""Retrieves information about Sentinel-2 products."""
|
47
|
+
utils = Utils()
|
48
|
+
products_info = utils.retrieve_products_info(products)
|
49
|
+
return products_info
|
50
|
+
|
51
|
+
def output_folder(self, products_info, bands_dict):
|
52
|
+
"""Creates output folders to save downloaded bands."""
|
53
|
+
files = Files()
|
54
|
+
directory_paths = files.create_output_folders(self.output_base_path, products_info, bands_dict)
|
55
|
+
return directory_paths
|
56
|
+
|
57
|
+
def get_bands_links(self, products_info, bands_dict):
|
58
|
+
"""Retrieves links to bands for Sentinel-2 products."""
|
59
|
+
connections = Connections()
|
60
|
+
bands_links = connections.retrieve_bands_links(self.access_token, products_info, bands_dict)
|
61
|
+
return bands_links
|
62
|
+
|
63
|
+
def download_band(self, products_info, bands_link, base_dir, tile):
|
64
|
+
"""Downloads bands for Sentinel-2 products based on the provided links."""
|
65
|
+
connections = Connections()
|
66
|
+
connections.download_bands(self.access_token, products_info, bands_link, base_dir, self.dt_access_token, self.refresh_token, tile)
|
67
|
+
|
68
|
+
def download_sentinel2_bands(self, products, bands_dict, tile):
|
69
|
+
"""Orchestrates the download process for Sentinel-2 bands."""
|
70
|
+
utils = Utils()
|
71
|
+
if products is None:
|
72
|
+
logger.warning("Stopping further execution.")
|
73
|
+
else:
|
74
|
+
products_info = self.get_products_info(products)
|
75
|
+
self.output_folder(products_info, bands_dict)
|
76
|
+
links = self.get_bands_links(products_info, bands_dict)
|
77
|
+
products=self.download_band(products_info, links, self.output_base_path, tile)
|
78
|
+
|
79
|
+
downloaded_dict = utils.generate_sentinel2_band_paths_nested_by_tile(self.output_base_path, products_info)
|
80
|
+
return downloaded_dict
|
81
|
+
|
82
|
+
def get_composite_data(self, gdf, downloaded_dict, output_rgb=None, output_ndvi=None, output_evi=None):
|
83
|
+
raster_processing = RasterProcessing()
|
84
|
+
first_key = next(iter(downloaded_dict))
|
85
|
+
first_entry = downloaded_dict[first_key]
|
86
|
+
if len(first_entry) == 1:
|
87
|
+
band_paths = first_entry[0]
|
88
|
+
b02_array, b03_array, b04_array, b08_array, profile = raster_processing.get_cropped_bands_no_merge(gdf, band_paths)
|
89
|
+
elif len(first_entry) > 1:
|
90
|
+
b02_array, b03_array, b04_array, b08_array, profile = raster_processing.get_cropped_bands_with_merge(gdf, first_entry)
|
91
|
+
|
92
|
+
if output_rgb is not None:
|
93
|
+
raster_processing.create_rgb(b02_array, b03_array, b04_array, profile, output_rgb)
|
94
|
+
|
95
|
+
if output_ndvi is not None:
|
96
|
+
raster_processing.create_ndvi(b04_array, b08_array, profile, output_ndvi)
|
97
|
+
|
98
|
+
if output_evi is not None:
|
99
|
+
raster_processing.create_evi(b04_array, b04_array, b08_array, profile, output_evi)
|
100
|
+
|
101
|
+
def get_satellite_image(self, geodataframe, end_date, cloud_cover_percentage, type='L2A', platform_name='SENTINEL-2', bands_dict={"L2A":{"10m": ["B02", "B03","B04", "B08"]}}, output_rgb=None, output_ndvi=None, output_evi=None):
|
102
|
+
query = self.construct_query(geodataframe, end_date, cloud_cover_percentage, type, platform_name)
|
103
|
+
products = self.products_from_sentinel_2(query)
|
104
|
+
if products == None:
|
105
|
+
return
|
106
|
+
downloaded_dict = self.download_sentinel2_bands(products, bands_dict, None)
|
107
|
+
self.get_composite_data(geodataframe, downloaded_dict, output_rgb, output_ndvi, output_evi)
|
108
|
+
|
109
|
+
|
110
|
+
if __name__ == '__main__':
|
111
|
+
DOWNLOAD_FOLDER = '/home/ppz/Documentos/coding/izisat/auxiliary'
|
112
|
+
MAX_CLOUD_COVER = 99
|
113
|
+
BANDS_DICT = {"L2A":{"10m": ["B02", "B03","B04", "B08"]}}
|
114
|
+
PLATFORM_NAME = "SENTINEL-2"
|
115
|
+
SATELLITE_TYPE = 'L2A'
|
116
|
+
COPERNICUS_USER=''
|
117
|
+
COPERNICUS_PASSWD='!'
|
118
|
+
|
119
|
+
zona_unica=False
|
120
|
+
|
121
|
+
###TESTE ZONA UNICA###
|
122
|
+
downloader = IZISentinel(output_base_path=DOWNLOAD_FOLDER, username=COPERNICUS_USER, password=COPERNICUS_PASSWD)
|
123
|
+
if zona_unica is True:
|
124
|
+
today = datetime(2025, 4, 14, 1, 0, 0)
|
125
|
+
gdf = gpd.read_file('/home/ppz/Documentos/coding/izisat/auxiliary/base_ldcelulose/base_cadastral/FULL_20250709_VIEW.shp')
|
126
|
+
gdf = gdf.loc[(gdf['TALHAO'] == '0112') & (gdf['ID_PROJETO'] == '5822')]
|
127
|
+
|
128
|
+
output_rgb = '/home/ppz/Documentos/coding/izisat/auxiliary/raster_lake/rgb/teste_rgb.tif'
|
129
|
+
output_ndvi = '/home/ppz/Documentos/coding/izisat/auxiliary/raster_lake/ndvi/teste_ndvi.tif'
|
130
|
+
downloader.get_satellite_image(
|
131
|
+
geodataframe=gdf,
|
132
|
+
end_date=today,
|
133
|
+
cloud_cover_percentage=MAX_CLOUD_COVER,
|
134
|
+
type=SATELLITE_TYPE,
|
135
|
+
platform_name=PLATFORM_NAME,
|
136
|
+
bands_dict=BANDS_DICT,
|
137
|
+
output_rgb=output_rgb,
|
138
|
+
output_ndvi=output_ndvi,
|
139
|
+
)
|
140
|
+
|
141
|
+
elif zona_unica is not True:
|
142
|
+
today = datetime(2025, 4, 9, 1, 0, 0)
|
143
|
+
gdf = gpd.read_file('/home/ppz/Documentos/coding/izisat/auxiliary/base_ldcelulose/base_filtrada.geojson')
|
144
|
+
gdf = gdf.dissolve(by='PROJETO').reset_index()
|
145
|
+
#gdf = gpd.read_file('/home/ppz/Documentos/coding/izisat/testing.geojson')
|
146
|
+
for index, row in gdf.iterrows():
|
147
|
+
print(f'linha - {index} de {len(gdf)} -- TALHAO: {row.TALHAO}')
|
148
|
+
row_gdf = gdf.iloc[[index]]
|
149
|
+
output_rgb = f'/home/ppz/Documentos/coding/izisat/auxiliary/raster_lake/rgb/teste_rgb_{row.TALHAO}.tif'
|
150
|
+
output_ndvi = f'/home/ppz/Documentos/coding/izisat/auxiliary/raster_lake/ndvi/teste_ndvi_{row.TALHAO}.tif'
|
151
|
+
output_evi = f'/home/ppz/Documentos/coding/izisat/auxiliary/raster_lake/evi/teste_evi_{row.TALHAO}.tif'
|
152
|
+
downloader.get_satellite_image(
|
153
|
+
geodataframe=row_gdf,
|
154
|
+
end_date=today,
|
155
|
+
cloud_cover_percentage=MAX_CLOUD_COVER,
|
156
|
+
type=SATELLITE_TYPE,
|
157
|
+
platform_name=PLATFORM_NAME,
|
158
|
+
bands_dict=BANDS_DICT,
|
159
|
+
output_rgb=output_rgb,
|
160
|
+
output_ndvi=output_ndvi,
|
161
|
+
output_evi=output_evi)
|
File without changes
|