Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GOES Data Download Manager Script #240

Merged
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions satip/goes_download_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
"""
Script for downloading GOES data.
"""

import datetime
import logging
import os

from goes2go import GOES


class GOESDownloadManager:
14Richa marked this conversation as resolved.
Show resolved Hide resolved
"""
Manager class for downloading GOES data.
"""
def __init__(self, data_dir, log_directory=None):
"""
Initialize the GOESDownloadManager.

Args:
data_dir (str): Directory to save downloaded GOES data.
log_directory (str, optional): Directory to save logs.
If None, logging is printed to STDOUT.
"""
self.data_dir = data_dir
self.ensure_directory_exists(self.data_dir)

if log_directory:
self.ensure_directory_exists(log_directory)
logging.basicConfig(
filename=os.path.join(log_directory, 'goes_download.log'),
level=logging.INFO)
else:
logging.basicConfig(level=logging.INFO)

logging.info(f"GOESDownloadManager initialized. Data will be saved to: {data_dir}")

@staticmethod
def ensure_directory_exists(directory):
"""Ensures the specified directory exists, creating it if necessary."""
if not os.path.exists(directory):
try:
os.makedirs(directory)
logging.info(f"Created directory: {directory}")
except Exception as e:
logging.error(f"Error creating directory {directory}: {e}")
raise
def download_goes_data(self, start_time, end_time, product='ABI-L1b-RadC',
domain='F', satellite=16):
"""
Download GOES data for a specified time range and product.

Args:
start_time (datetime): Start of the download period.
end_time (datetime): End of the download period.
product (str): GOES product identifier. Default is 'ABI-L1b-RadC'.
domain (str): Domain for the product. Default is 'F' (Full Disk).
satellite (int): GOES satellite number. Default is 16.
"""
G = GOES(satellite=satellite, product=product, domain=domain)
current_time = start_time
while current_time <= end_time:
try:
# Download the data
ds = G.nearesttime(current_time)
14Richa marked this conversation as resolved.
Show resolved Hide resolved

# Format the date string for filename
date_string = current_time.strftime("%Y-%m-%d_%H-%M-%S")
14Richa marked this conversation as resolved.
Show resolved Hide resolved
filename = f"goes_data_{date_string}.nc"
filepath = os.path.join(self.data_dir, filename)

# Save to NetCDF
ds.to_netcdf(filepath)

logging.info(f"Downloaded and saved GOES data to: {filename}")
except Exception as e:
logging.error(f"Error downloading GOES data for {current_time}: {e}")

current_time += datetime.timedelta(minutes=1)
14Richa marked this conversation as resolved.
Show resolved Hide resolved

logging.info("Completed GOES data download.")

if __name__ == "__main__":
14Richa marked this conversation as resolved.
Show resolved Hide resolved

data_dir = "path to data directory"
log_directory = "path to log directory"
start_time = datetime.datetime(2023, 1, 1, 0, 0)
end_time = datetime.datetime(2023, 1, 1, 1, 0)
manager = GOESDownloadManager(data_dir, log_directory)
manager.download_goes_data(start_time, end_time)