From ed3320b11f11a462fe8430dda7b6ac522f428220 Mon Sep 17 00:00:00 2001 From: Richa <41283476+14Richa@users.noreply.github.com> Date: Thu, 11 Apr 2024 19:06:55 +0530 Subject: [PATCH] Extend GOES data retrieval to include NOAA's CLAss archive (#249) * added new function for archive data * added new function for archive data * added statellite range code * added new test file * minor fix --- satip/goes_download_manager.py | 73 +++++++++++++++++++++++++++++ tests/test_goes_download_manager.py | 22 +++++++++ 2 files changed, 95 insertions(+) create mode 100644 tests/test_goes_download_manager.py diff --git a/satip/goes_download_manager.py b/satip/goes_download_manager.py index 40726601..6780a2da 100644 --- a/satip/goes_download_manager.py +++ b/satip/goes_download_manager.py @@ -6,6 +6,7 @@ import logging import os +import requests from goes2go import GOES @@ -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: + # 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") diff --git a/tests/test_goes_download_manager.py b/tests/test_goes_download_manager.py new file mode 100644 index 00000000..e9954665 --- /dev/null +++ b/tests/test_goes_download_manager.py @@ -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__": + test_download_goes_15_data()