Skip to content
Snippets Groups Projects
RPPtools.py 1.3 KiB
Newer Older
#
import numpy as np
#
FillValue=np.nan
IntFillValue=999999
#
# Overlap with the the lat/lon box. The function only tests if there is a potential overlap.
# The default answer is that there is an overlap, unless we find it impossible.
#
def potoverlap(refpoly, testpoly) :
    po = True
    if np.max(np.array(testpoly)[:,0]) < np.min(np.array(refpoly)[:,0]) and np.min(np.array(testpoly)[:,0]) > np.max(np.array(refpoly)[:,0]) :
              po = False
    if np.max(np.array(testpoly)[:,1]) < np.min(np.array(refpoly)[:,1]) and np.min(np.array(testpoly)[:,1]) > np.max(np.array(refpoly)[:,1]) :
              po = False
    return po
#
# Routine to generate a square polygone around the centre point
#
def boxit(cent, dlon, dlat) :
    polyres=8
    boxll=[]
    loninc = dlon/polyres
    latinc = dlat/polyres
    # Side 1
    for pts in range(polyres) :
        boxll.append([cent[0]-dlon/2.0+loninc*pts, cent[1]+dlat/2.0])
    # Side 2
    for pts in range(polyres) :
        boxll.append([cent[0]+dlon/2.0, cent[1]+dlat/2.0-latinc*pts])
    # Side 3
    for pts in range(polyres) :
        boxll.append([cent[0]+dlon/2.0-loninc*pts, cent[1]-dlat/2.0])
    # Side 4
    for pts in range(polyres) :
        boxll.append([cent[0]-dlon/2.0, cent[1]-dlat/2.0+latinc*pts])
    # Close
    boxll.append(boxll[0])
    return boxll