nmathewa / tropcyc

Tropical cyclone exp
0 stars 0 forks source link

How to get forecasts from NHC (HWRF ocean coupled) #17

Open nmathewa opened 1 week ago

nmathewa commented 1 week ago

install aws cli

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

Retrieve event driven data from amazon s3

from datetime import datetime
from datetime import timezone 
name = '14l.'
dt_prefix = datetime.now().strftime('%Y%m%d')

def get_init_time():
    utc_time = datetime.now(timezone.utc) - pd.Timedelta(hours=5)
    if 0 <= utc_time.hour < 6:
        init_time = '00'
    elif 6 <= utc_time.hour < 12:
        init_time = '06'
    elif 12 <= utc_time.hour < 18:
        init_time = '12'
    else:
        init_time = '18'

    return init_time

dt_final = dt_prefix + get_init_time()

dft = pd.DataFrame(data=[name]*20,columns=['name'])

dft['dt'] = dt_final

dft['forecast_hour'] = np.arange(0,3*20,3)

dft['prefix'] = '.hfsb.storm.atm.'

dft['utc_time'] = pd.to_datetime(dft['dt'],format='%Y%m%d%H') + pd.to_timedelta(dft['forecast_hour'],unit='h')

dft['local_time'] = dft['utc_time'] - pd.Timedelta(hours=5,minutes=0)

dft['filename'] = dft['name'] + dft['dt'] + dft['prefix'] + 'f' +dft['forecast_hour'].astype(str).str.zfill(3) + '.grb2'

#dft['forecast_hour'].astype(str).str.zfill(3)

stats_file = f'{name}{dt_final}.hfsb.grib.stats.short'

# add the stats file the column filename while all other columns are the same
dft.loc[0,'filename'] = stats_file

dft
nmathewa commented 1 week ago
# download the files from aws cli
"""
aws s3 ls --no-sign-request s3://noaa-nws-hafs-pds/hfsb/20241006/12/

"""
import os
import subprocess

# just one file with no-sign-request

#subprocess.run(['aws','s3','cp', '--no-sign-request' ,f's3://noaa-nws-hafs-pds/{prefix_dir}','/Users/nalex2023/temp/'],check=True)

outfol = '/Users/nalex2023/Temp/cyclone_dsets/'

fol_name = f'{name}{dt_final}'

os.makedirs(outfol+fol_name,exist_ok=True)

for i in range(len(dft)):
    subprocess.run(['aws','s3','cp', '--no-sign-request' ,f's3://noaa-nws-hafs-pds/hfsb/20241006/12/{dft.loc[i,"filename"]}',outfol+fol_name],check=True)