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

Extend GOES data retrieval to include NOAA's CLAss archive #249

Merged
merged 5 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
73 changes: 73 additions & 0 deletions satip/goes_download_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import logging
import os

import requests
from goes2go import GOES


Expand Down Expand Up @@ -94,3 +95,75 @@ def download_goes_data(self, start_time, end_time, product='ABI-L1b-RadC',
current_time += datetime.timedelta(minutes=time_increment)

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

def check_url_for_goes_data(self, url):
"""
Check if the provided URL contains the GOES-8 to GOES-15 data.
"""
response = requests.get(url)
if response.status_code == 200:
return True
else:
return False

def download_archival_goes_data(self, start_date, end_date, satellite):
"""
Download archival GOES data for a specified time range and satellite.

Args:
start_date (datetime): Start of the download period.
end_date (datetime): End of the download period.
satellite (str): GOES satellite range,
e.g., '8-15' for GOES-8 to GOES-15 or '15' for GOES-15.
"""
# Construct base URL
base_url = "https://www.aev.class.noaa.gov/saa/products/search?datatype_family=GVAR_IMG"

# Check if the provided URL contains the desired data
if self.check_url_for_goes_data(base_url):
# If satellite is a range
if '-' in satellite:
jacobbieker marked this conversation as resolved.
Show resolved Hide resolved
# Extract start and end satellite numbers
start_satellite, end_satellite = map(int, satellite.split('-'))

# Iterate over the range of satellites
for sat_num in range(start_satellite, end_satellite + 1):
# Construct URL for each satellite
url = f"{base_url}/GOES-{sat_num}"
print(f"Checking data availability for GOES-{sat_num}...")

# Download data
print(f"Downloading archival data from {url}...")
response = requests.get(url)

if response.status_code == 200:
# Save data to file
output_file = os.path.join(self.data_dir,
f"goes_archival_data_{sat_num}.nc")
with open(output_file, 'wb') as f:
f.write(response.content)
print(f"Archival data saved to {output_file}")
else:
print(f"Failed to download archival data for GOES-{sat_num}.")
else:
# Extract satellite number
sat_num = int(satellite)

# Construct URL for the specified satellite
url = f"{base_url}/GOES-{sat_num}"
print(f"Checking data availability for GOES-{sat_num}...")

# Download data
print(f"Downloading archival data from {url}...")
response = requests.get(url)

if response.status_code == 200:
# Save data to file
output_file = os.path.join(self.data_dir, f"goes_archival_data_{sat_num}.nc")
with open(output_file, 'wb') as f:
f.write(response.content)
print(f"Archival data saved to {output_file}")
else:
print(f"Failed to download archival data for GOES-{sat_num}.")
else:
print("The URL does not contain the desired GOES data")
22 changes: 22 additions & 0 deletions tests/test_goes_download_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from datetime import datetime
from satip.goes_download_manager import GOESDownloadManager


# Test case for downloading GOES-15 data from CLAss
def test_download_goes_15_data():
# Initialize GoesDownloadManager
download_manager = GOESDownloadManager(data_dir="data")

# Define time range
start_date = datetime(2010, 3, 1)
end_date = datetime(2018, 3, 2)

# Specify satellite (GOES-15)
satellite = "15"

# Download archival GOES-15 data
download_manager.download_archival_goes_data(start_date, end_date, satellite)

# Run the test case
if __name__ == "__main__":
jacobbieker marked this conversation as resolved.
Show resolved Hide resolved
test_download_goes_15_data()