parent
bcedcd82ab
commit
013accefef
@ -0,0 +1 @@
|
||||
from .service import Grib
|
||||
@ -0,0 +1,58 @@
|
||||
import requests
|
||||
|
||||
|
||||
class Grib:
|
||||
@staticmethod
|
||||
def is_reachable(url: str):
|
||||
"""Check if url is reachable at all with the current setup
|
||||
|
||||
:param url: URL to check
|
||||
:return: True if url is reachable, False otherwise
|
||||
"""
|
||||
if requests.head(url):
|
||||
return True
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def form_gfs_link(target_time=None, prod_hour=384):
|
||||
"""Return well formed link to gfs data which
|
||||
should be available by given time
|
||||
|
||||
:param target_time: time to check, defaults to current time
|
||||
:param prod_hour: forecast hour to link to, defaults to 384
|
||||
:returns: URL to gfs file
|
||||
"""
|
||||
if not target_time:
|
||||
target_time = datetime.now(
|
||||
tz=ZoneInfo("US/Eastern")
|
||||
) # noaa is located in washington
|
||||
|
||||
looking_at = "atmos"
|
||||
prod_hour = str(prod_hour).zfill(3)
|
||||
|
||||
date_str = target_time.strftime("%Y%m%d")
|
||||
hour_str = str((target_time.hour // 6) * 6).zfill(2)
|
||||
target_url = f"https://nomads.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/gfs.{date_str}/{hour_str}/{looking_at}/gfs.t{hour_str}z.pgrb2.0p25.f{prod_hour}"
|
||||
return target_url
|
||||
|
||||
@staticmethod
|
||||
def form_gfswave_link(target_time=None, prod_hour=384):
|
||||
"""Return well formed link to gfs data which
|
||||
should be available by given time
|
||||
|
||||
:param target_time: time to check, defaults to current time
|
||||
:param prod_hour: forecast hour to link to, defaults to 384
|
||||
:returns: URL to gfs file
|
||||
"""
|
||||
if not target_time:
|
||||
target_time = datetime.now(
|
||||
tz=ZoneInfo("US/Eastern")
|
||||
) # noaa is located in washington
|
||||
|
||||
looking_at = "wave"
|
||||
prod_hour = str(prod_hour).zfill(3)
|
||||
|
||||
date_str = target_time.strftime("%Y%m%d")
|
||||
hour_str = str((target_time.hour // 6) * 6).zfill(2)
|
||||
target_url = f"https://nomads.ncep.noaa.gov/pub/data/nccf/com/gfs/prod/gfs.{date_str}/{hour_str}/{looking_at}/gridded/gfs{looking_at}.t{hour_str}z.global.0p25.f{prod_hour}.grib2"
|
||||
return target_url
|
||||
Loading…
Reference in new issue