Skip to content

Commit

Permalink
added scripts to run day and all downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
annajungbluth committed Jun 12, 2024
1 parent 3cb598f commit e2f5e8d
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 14 deletions.
11 changes: 4 additions & 7 deletions rs_tools/_src/data/modis/downloader_aqua.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
"""
A General Pipeline for create ML-Ready Data
- Downloading the Data
- Data Harmonization
- Normalizing
- Patching
Pipeline for downloading AQUA MODIS data
- Daytime and nightime data
"""
import autoroot
import numpy as np
Expand Down Expand Up @@ -39,7 +36,7 @@ def download(self) -> List[str]:
processing_level='L1b',
resolution="1KM",
bounding_box=self.bounding_box,
day_night_flag="day",
day_night_flag=None,
identifier= "02"
)
return aqua_files
Expand All @@ -56,7 +53,7 @@ def download_cloud_mask(self) -> List[str]:
processing_level='L2',
resolution="1KM",
bounding_box=self.bounding_box,
day_night_flag="day",
day_night_flag=None,
identifier= "35"
)
return aqua_files
Expand Down
108 changes: 108 additions & 0 deletions rs_tools/_src/data/modis/downloader_aqua_day.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
"""
Pipeline for downloading AQUA MODIS data
- Only daytime data
"""
import autoroot
import numpy as np

from pathlib import Path
from dataclasses import dataclass
from typing import List
from rs_tools import modis_download

import typer
from loguru import logger


@dataclass
class MODISAquaDownload:
"""Downloading class for AQUA/MODIS data and cloud mask"""
start_date: str
end_date: str
start_time: str
end_time: str
save_dir: str
bounding_box: tuple[float, float, float, float]

def download(self) -> List[str]:
aqua_files = modis_download(
start_date=self.start_date,
end_date=self.end_date,
start_time=self.start_time,
end_time=self.end_time,
day_step=1,
satellite="Aqua",
save_dir=Path(self.save_dir).joinpath("L1b"),
processing_level='L1b',
resolution="1KM",
bounding_box=self.bounding_box,
day_night_flag="day",
identifier= "02"
)
return aqua_files

def download_cloud_mask(self) -> List[str]:
aqua_files = modis_download(
start_date=self.start_date,
end_date=self.end_date,
start_time=self.start_time,
end_time=self.end_time,
day_step=1,
satellite="Aqua",
save_dir=Path(self.save_dir).joinpath("CM"),
processing_level='L2',
resolution="1KM",
bounding_box=self.bounding_box,
day_night_flag="day",
identifier= "35"
)
return aqua_files


def download(
start_date: str = "2020-10-01",
end_date: str = "2020-10-01",
start_time: str = "14:00:00",
end_time: str = "21:00:00",
save_dir: str = "./data/",
region: str = "-130 -15 -90 5",
cloud_mask: bool = True
):
"""
Downloads AQUA MODIS data including cloud mask
Args:
start_date (str): The start date of the period to download files for in the format "YYYY-MM-DD".
end_date (str): The end date of the period to download files for in the format "YYYY-MM-DD".
start_time (str): The start time of the period to download files for in the format "HH:MM:SS".
end_time (str): The end time of the period to download files for in the format "HH:MM:SS".
save_dir (str): The directory path to save the downloaded files.
region (str, optional): The geographic region to download files for in the format "min_lon min_lat max_lon max_lat".
cloud_mask (bool, optional): Whether to download the cloud mask data (default: True).
Returns:
None
"""
bounding_box = tuple(map(lambda x: int(x), region.split(" ")))
# Initialize AQUA Downloader
logger.info("Initializing AQUA Downloader...")
dc_aqua_download = MODISAquaDownload(
start_date=start_date,
end_date=end_date,
start_time=start_time,
end_time=end_time,
save_dir=Path(save_dir).joinpath("aqua"),
bounding_box=bounding_box,
)
logger.info("Downloading AQUA Data...")
modis_filenames = dc_aqua_download.download()
logger.info("Done!")
if cloud_mask:
logger.info("Downloading AQUA Cloud Mask...")
modis_filenames = dc_aqua_download.download_cloud_mask()
logger.info("Done!")

logger.info("Finished AQUA Downloading Script...")

if __name__ == '__main__':
typer.run(download)
11 changes: 4 additions & 7 deletions rs_tools/_src/data/modis/downloader_terra.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
"""
A General Pipeline for create ML-Ready Data
- Downloading the Data
- Data Harmonization
- Normalizing
- Patching
Pipeline for downloading TERRA MODIS data
- Daytime and nightime data
"""
import autoroot
import numpy as np
Expand Down Expand Up @@ -39,7 +36,7 @@ def download(self) -> List[str]:
processing_level='L1b',
resolution="1KM",
bounding_box=self.bounding_box,
day_night_flag="day",
day_night_flag=None,
identifier= "02"
)
return terra_files
Expand All @@ -56,7 +53,7 @@ def download_cloud_mask(self) -> List[str]:
processing_level='L2',
resolution="1KM",
bounding_box=self.bounding_box,
day_night_flag="day",
day_night_flag=None,
identifier= "35"
)
return terra_files
Expand Down
108 changes: 108 additions & 0 deletions rs_tools/_src/data/modis/downloader_terra_day.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
"""
Pipeline for downloading TERRA MODIS data
- Only daytime data
"""
import autoroot
import numpy as np

from pathlib import Path
from dataclasses import dataclass
from typing import List
from rs_tools import modis_download

import typer
from loguru import logger


@dataclass
class MODISTerraDownload:
"""Downloading class for TERRA/MODIS data and cloud mask"""
start_date: str
end_date: str
start_time: str
end_time: str
save_dir: str
bounding_box: tuple[float, float, float, float]

def download(self) -> List[str]:
terra_files = modis_download(
start_date=self.start_date,
end_date=self.end_date,
start_time=self.start_time,
end_time=self.end_time,
day_step=1,
satellite="Terra",
save_dir=Path(self.save_dir).joinpath("L1b"),
processing_level='L1b',
resolution="1KM",
bounding_box=self.bounding_box,
day_night_flag="day",
identifier= "02"
)
return terra_files

def download_cloud_mask(self) -> List[str]:
terra_files = modis_download(
start_date=self.start_date,
end_date=self.end_date,
start_time=self.start_time,
end_time=self.end_time,
day_step=1,
satellite="Terra",
save_dir=Path(self.save_dir).joinpath("CM"),
processing_level='L2',
resolution="1KM",
bounding_box=self.bounding_box,
day_night_flag="day",
identifier= "35"
)
return terra_files


def download(
start_date: str = "2020-10-01",
end_date: str = "2020-10-01",
start_time: str = "14:00:00",
end_time: str = "21:00:00",
save_dir: str = "./data/",
region: str = "-130 -15 -90 5",
cloud_mask: bool = True
):
"""
Downloads TERRA MODIS data including cloud mask
Args:
start_date (str): The start date of the period to download files for in the format "YYYY-MM-DD".
end_date (str): The end date of the period to download files for in the format "YYYY-MM-DD".
start_time (str): The start time of the period to download files for in the format "HH:MM:SS".
end_time (str): The end time of the period to download files for in the format "HH:MM:SS".
save_dir (str): The directory path to save the downloaded files.
region (str, optional): The geographic region to download files for in the format "min_lon min_lat max_lon max_lat".
cloud_mask (bool, optional): Whether to download the cloud mask data (default: True).
Returns:
None
"""
bounding_box = tuple(map(lambda x: int(x), region.split(" ")))
# Initialize TERRA Downloader
logger.info("Initializing TERRA Downloader...")
dc_terra_download = MODISTerraDownload(
start_date=start_date,
end_date=end_date,
start_time=start_time,
end_time=end_time,
save_dir=Path(save_dir).joinpath("terra"),
bounding_box=bounding_box,
)
logger.info("Downloading TERRA Data...")
modis_filenames = dc_terra_download.download()
logger.info("Done!")
if cloud_mask:
logger.info("Downloading TERRA Cloud Mask...")
modis_filenames = dc_terra_download.download_cloud_mask()
logger.info("Done!")

logger.info("Finished TERRA Downloading Script...")

if __name__ == '__main__':
typer.run(download)

0 comments on commit e2f5e8d

Please sign in to comment.