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

DRAFT: add option to change grid, default to TL479 #137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
68 changes: 43 additions & 25 deletions globsim/download/JRA3Q_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#


def download_constant(access, dest_dir) -> Path:
url, path, name = url_LL125_surf()
def download_constant(access, dest_dir, grid="TL479") -> Path:
url, path, name = url_surf(grid=grid)
dirpath = Path(dest_dir, path[1:])
fname = Path(dirpath, name)

Expand All @@ -35,12 +35,12 @@ def download_constant(access, dest_dir) -> Path:
return fname


def download_daily_gribs(access, dest_dir, year, month, day) -> "tuple[list[Path], list[Path], list[Path]]":
def download_daily_gribs(access, dest_dir, year, month, day, grid="TL479") -> "tuple[list[Path], list[Path], list[Path]]":
sa, pl, sf = [], [], []

for hour in range(0, 24, 6):
# surface
url, path, name = url_anl_surf125(year, month, day, hour)
url, path, name = url_anl_surf(year, month, day, hour, grid=grid)
dirpath = Path(dest_dir, path[1:])
fname = Path(dirpath, name)
sa.append(fname)
Expand All @@ -52,7 +52,7 @@ def download_daily_gribs(access, dest_dir, year, month, day) -> "tuple[list[Path

# pressure-level
for var in ['tmp', 'spfh', 'rh', 'ugrd', 'vgrd', 'hgt']:
url, path, name = url_anl_p125(year, month, day, hour, var)
url, path, name = url_anl_p(year, month, day, hour, var, grid=grid)
dirpath = Path(dest_dir, path[1:])
fname = Path(dirpath, name)
pl.append(fname)
Expand All @@ -64,7 +64,7 @@ def download_daily_gribs(access, dest_dir, year, month, day) -> "tuple[list[Path

# forecast
for hour in range(0, 24, 1):
url, path, name = url_fcst_phy2m125(year, month, day, hour)
url, path, name = url_fcst_phy2m(year, month, day, hour, grid=grid)
dirpath = Path(dest_dir, path[1:])
fname = Path(dirpath, name)
sf.append(fname)
Expand All @@ -77,7 +77,7 @@ def download_daily_gribs(access, dest_dir, year, month, day) -> "tuple[list[Path
return sa, sf, pl


def download_monthly_gribs(access, dest_dir, year, month):
def download_monthly_gribs(access, dest_dir, year, month, grid="TL479"):
if month in [1, 3, 5, 7, 8, 10, 12]:
days = 31
elif month in [4, 6, 9, 11]:
Expand All @@ -92,20 +92,26 @@ def download_monthly_gribs(access, dest_dir, year, month):

for day in range(1, days + 1):
try:
sa, sf, pl = download_daily_gribs(access, dest_dir, year, month, day)
sa, sf, pl = download_daily_gribs(access, dest_dir, year, month, day, grid=grid)
except Exception as e:
print(f"Error downloading {year}-{month}-{day}: {e}")


def url_LL125_surf():
url = r"https://data.diasjp.net/dl/storages/downloadCmd/L0pSQTNRL0NvbnN0L0xMMTI1X3N1cmYuZ3JpYjI="
p1 = "/JRA3Q/Const/"
p2 = "LL125_surf.grib2"

def url_surf(grid="TL479"):
if grid == "LL125":
url = r"https://data.diasjp.net/dl/storages/downloadCmd/L0pSQTNRL0NvbnN0L0xMMTI1X3N1cmYuZ3JpYjI="
p1 = "/JRA3Q/Const/"
p2 = "LL125_surf.grib2"

elif grid == "TL479":
url = r"https://data.diasjp.net/dl/storages/downloadCmd/L0pSQTNRL0NvbnN0L1RMNDc5X3N1cmYuZ3JpYjI="
p1 = "/JRA3Q/Const/"
p2 = "TL479_surf.grib2"

return url, p1, p2


def url_anl_surf125(year, month, day, hour):
def url_anl_surf(year, month, day, hour, grid="TL479"):
"""
1 Total column vertically-integrated water vapour
2 Potential temperature
Expand All @@ -126,17 +132,21 @@ def url_anl_surf125(year, month, day, hour):
DD = "{:02}".format(day)
HH = "{:02}".format(hour)

p1 = f"/JRA3Q/Hist/Daily/anl_surf125/{YYYY}{MM}/"
p2 = f"anl_surf125.{YYYY}{MM}{DD}{HH}"
if grid == "LL125":
p1 = f"/JRA3Q/Hist/Daily/anl_surf125/{YYYY}{MM}/"
p2 = f"anl_surf125.{YYYY}{MM}{DD}{HH}"
elif grid == "TL479":
p1 = f"/JRA3Q/Hist/Daily/anl_surf/{YYYY}{MM}/"
p2 = f"anl_surf.{YYYY}{MM}{DD}{HH}"

coded = base64.b64encode((p1 + p2).encode("utf-8")).decode("UTF-8")

url = f"https://data.diasjp.net/dl/storages/downloadCmd/{coded}"

return url, p1, p2


def url_anl_p125(year, month, day, hour, var):

def url_anl_p(year, month, day, hour, var, grid="TL479"):
"""
Parameters
----------
Expand All @@ -148,18 +158,22 @@ def url_anl_p125(year, month, day, hour, var):
DD = "{:02}".format(day)
HH = "{:02}".format(hour)

p1 = f"/JRA3Q/Hist/Daily/anl_p125/{YYYY}{MM}/"
p2 = f"anl_p125_{var}.{YYYY}{MM}{DD}{HH}"
if grid == "LL125":
p1 = f"/JRA3Q/Hist/Daily/anl_p125/{YYYY}{MM}/"
p2 = f"anl_p125_{var}.{YYYY}{MM}{DD}{HH}"
elif grid == "TL479":
p1 = f"/JRA3Q/Hist/Daily/anl_p/{YYYY}{MM}/"
p2 = f"anl_p_{var}.{YYYY}{MM}{DD}{HH}"

coded = base64.b64encode((p1 + p2).encode("utf-8")).decode("UTF-8")

# url = f"https://data.diasjp.net/dl/storages/file/{coded}"
url = f"https://data.diasjp.net/dl/storages/downloadCmd/{coded}"

return url, p1, p2


def url_fcst_phy2m125(year, month, day, hour):
def url_fcst_phy2m(year, month, day, hour, grid="TL479"):
"""
1 unknown
2 unknown
Expand Down Expand Up @@ -195,8 +209,12 @@ def url_fcst_phy2m125(year, month, day, hour):
DD = "{:02}".format(day)
HH = "{:02}".format(hour)

p1 = f"/JRA3Q/Hist/Daily/fcst_phy2m125/{YYYY}{MM}/"
p2 = f"fcst_phy2m125.{YYYY}{MM}{DD}{HH}"
if grid == "LL125":
p1 = f"/JRA3Q/Hist/Daily/fcst_phy2m125/{YYYY}{MM}/"
p2 = f"fcst_phy2m125.{YYYY}{MM}{DD}{HH}"
elif grid == "TL479":
p1 = f"/JRA3Q/Hist/Daily/fcst_phy2m/{YYYY}{MM}/"
p2 = f"fcst_phy2m.{YYYY}{MM}{DD}{HH}"

coded = base64.b64encode((p1 + p2).encode("utf-8")).decode("UTF-8")

Expand Down