from datetime import datetime, timedelta
import logging

import numpy as np
from matplotlib.transforms import Bbox

from pyschism.forcing.hycom.hycom2schism import DownloadHycom
from pyschism.mesh.hgrid import Hgrid

logging.basicConfig(
    format="[%(asctime)s] %(name)s %(levelname)s: %(message)s",
    force=True,
)
logger = logging.getLogger('pyschism')
logger.setLevel(logging.INFO)

if __name__ == '__main__':
    #4326 is lon/lat
    hgrid = Hgrid.open('hgrid.gr3', crs='epsg:4326')
    bbox = hgrid.bbox
    #Specify bbox below if desired
    xmin=bbox.xmin-1; xmax=bbox.xmax+1
    ymin=bbox.ymin-1; ymax=bbox.ymax+1

    print(f'bbox {xmin} {xmax} {ymin} {ymax}')
    bbox = Bbox.from_extents(xmin, ymin, xmax, ymax)

    startdate=datetime(2013, 4, 1)
    rnday = 61
    
    datevectors = np.arange(startdate, startdate + timedelta(days=rnday+1), timedelta(days=1)).astype(datetime)

    hycom = DownloadHycom(hgrid)
    for date in datevectors:
        hycom.fetch_data(date, outdir='./')
