def _resampleClimatology(dbname, ptable, name, dt0):
    tilesize = 10
    res = 2.5
    db = dbio.connect(dbname)
    cur = db.cursor()
    cur.execute(
        "select * from pg_catalog.pg_class c inner join pg_catalog.pg_namespace n on c.relnamespace=n.oid where n.nspname='precip' and c.relname='{0}_iri'".format(ptable))
    if not bool(cur.rowcount):
        sql = "create table precip.{0}_iri as (with f as (select fdate,st_tile(st_rescale(rast,{0},'average'),{2},{2}) as rast from precip.{1}) select fdate,rast,dense_rank() over (order by st_upperleftx(rast),st_upperlefty(rast)) as rid from f)".format(
            res, ptable, tilesize)
        cur.execute(sql)
        cur.execute(
            "create index {0}_iri_r on precip.{0}_iri(rid)".format(ptable))
        cur.execute(
            "create index {0}_iri_t on precip.{0}_iri(fdate)".format(ptable))
        db.commit()
    _deleteTableIfExists(dbname, 'precip', "{0}_iri_xy".format(ptable))
    sql = "create table precip.{0}_iri_xy as (select gid,st_worldtorastercoordx(rast,geom) as x,st_worldtorastercoordy(rast,geom) as y,rid as tile from precip.{0}_iri,{1}.basin where fdate=date'{2}-{3}-{4}' and st_intersects(rast,geom))".format(
        ptable, name, dt0.year, dt0.month, dt0.day)
    cur.execute(sql)
    db.commit()
    cur.execute(
        "create index {0}_iri_xy_r on precip.{0}_iri_xy(tile)".format(ptable))
    db.commit()
    cur.close()
    db.close()
Resample finer scale climatology to IRI spatial resolution.
dataset/ETHPy150Open nasa/RHEAS/src/datasets/iri.py/_resampleClimatology