#!/usr/bin/env python3 # # meteo_ftp.py --- download Meteorological Data via FTP # See HYSPLIT Tutorial Sec 3.2 # # Change history: # 10 May 2025 (BB) - initial, cross-platform version import os import sys import platform from pathlib import Path import subprocess import webbrowser if sys.version_info < (3, 8): print("Please use Python 3.8 or higher.") sys.exit(1) system = platform.system().lower() if system == "windows": PGM = Path(sys.argv[1]) if len(sys.argv) > 1 else Path("C:/hysplit") OUT = Path(sys.argv[2]) if len(sys.argv) > 2 else PGM / "working" DSP = sys.argv[3] if len(sys.argv) > 3 else "YES" TTR = Path(os.environ.get("TTR", "C:/Tutorial")) exe_suffix = ".exe" else: PGM = Path(sys.argv[1]) if len(sys.argv) > 1 else Path.home() / "hysplit" OUT = Path(sys.argv[2]) if len(sys.argv) > 2 else PGM / "working" DSP = sys.argv[3] if len(sys.argv) > 3 else "YES" TTR = Path(os.environ.get("TTR", Path.home() / "tutorial")) exe_suffix = "" if not PGM.exists(): script = Path(__file__).name if "__file__" in globals() else "parm_case.py" print(f"ERROR: HYSPLIT not found at {PGM}") print(f""" Please specify the path to your HYSPLIT installation using a command-line argument: python {script} YOUR_HYSPLIT_DIRECTORY [OUT] [DSP (YES|NO)] Example: python {script} C:\\hysplit C:\\hysplit\\working YES """) sys.exit(1) if not TTR.exists(): print(f"ERROR: HYSPLIT tutorial not found at {TTR}") print(""" Please set the TTR environment variable to point to your HYSPLIT tutorial directory. For Windows users (Command Prompt): SET TTR=YOUR_HYSPLIT_TUTORIAL_DIRECTORY For Linux users (bash shell): export TTR='YOUR_HYSPLIT_TUTORIAL_DIRECTORY' For Linux users (csh or tcsh shell): setenv TTR 'YOUR_HYSPLIT_TUTORIAL_DIRECTORY' """) sys.exit(1) # Work from OUT os.chdir(OUT) #!/usr/bin/env python3 # # get_reanal.py --- download a monthly global reanalysis file # from the NOAA ARL FTP server # # Change history: # 27 Sep 2026 - initial, cross-platform version translated from batch script import os import sys import platform from ftplib import FTP, all_errors from pathlib import Path if sys.version_info < (3,8): print("Please use Python 3.8 or higher.") sys.exit(1) # Detect OS and handle CLI args or fallback defaults system = platform.system().lower() if system == "windows": PGM = Path(sys.argv[1]) if len(sys.argv) >= 2 else Path("C:\\hysplit") OUT = Path(sys.argv[2]) if len(sys.argv) >= 3 else PGM / "working" else: PGM = Path(sys.argv[1]) if len(sys.argv) >= 2 else Path.home() / "hysplit" OUT = Path(sys.argv[2]) if len(sys.argv) >= 3 else PGM / "working" # Verify required paths if not PGM.exists(): script = Path(__file__).name if "__file__" in globals() else "get_reanal.py" print(f"ERROR: HYSPLIT not found at {PGM}") print(f""" Please specify the path to your HYSPLIT installation using a command-line argument: python {script} YOUR_HYSPLIT_DIRECTORY [OUT] Example: python {script} C:\\hysplit C:\\hysplit\\working """) sys.exit(1) if not OUT.exists(): print(f"ERROR: Output directory not found at {OUT}") sys.exit(1) os.chdir(OUT) # Set parameters syr, smo = "1983", "09" data = f"RP{syr}{smo}.gbl" host = "ftp.arl.noaa.gov" user, passwd = "anonymous", "name@server.com" remote_dir = "/pub/archives/reanalysis" local_file = OUT / data # Download file (binary mode) print("Starting FTP ...") try: with FTP(host) as ftp: ftp.login(user=user, passwd=passwd) ftp.cwd(remote_dir) with open(local_file, "wb") as f: ftp.retrbinary(f"RETR {data}", f.write) except all_errors as e: print(f"ERROR: FTP transfer failed -> {e}") if local_file.exists() and local_file.stat().st_size == 0: local_file.unlink() sys.exit(1) print(f"Completed transfer {data}") input("Press Enter to continue . . .")