def get_region_latitude_wts_bnds(latRegionpass, latType, latSize): """ #------------------------------------------------------------------- # # routine: get_region_latitude_wts_bnds # # purpose: compare the passed latitudes, latRegion, with the global # ones calculated here and extract the wts and bounds for # the region # # usage: wts,bnds = get_region_latitude_wts_bnds(latRegion, latType, latSize) # where latRegion is the regional grid to check # # return: wts, bnds - tuple with weights and bounds # #-------------------------------------------------------------------------""" latTypeList = ['gaussian', 'equalarea', 'uniform', 'generic'] if latType not in latTypeList: sendmsg("Error in latType -- it must be 'gaussian', 'equalarea', 'even' or 'generic' and not ", latType) raise ValueError return if latSize == None: sendmsg('Error in latSize -- it must be a number') raise ValueError return nlat = len(latRegionpass) reverse_latitude = 'no' # ------ set latitude direction to n to s for comparisons ------- if latRegionpass[0] < latRegionpass[nlat-1]: # need a copy? latRegion = numpy.array(latRegionpass, numpy.float64) latRegion = latlatRegion[::-1] reverse_latitude = 'yes' else: latRegion = latRegionpass small = 0.001 # use as tolerance in checking values # ------ check the pass for gaussian latitudes ------- if latType != 'generic': pts_wts_bnds = _regrid.gridattr(latSize, latType) # n to s global pts, wts and bnds latvals = pts_wts_bnds[0] imatch = -1 i = 0 while(imatch == -1): if abs(latvals[i] - latRegion[0]) < small: # first index found startIndex = i imatch = 0 i = i + 1 imatch = -1 while(imatch == -1): if abs(latvals[i] - latRegion[nlat - 1]) < small: # last index found lastIndex = i imatch = 0 i = i + 1 wts = pts_wts_bnds[1][startIndex:lastIndex + 1] bnds = pts_wts_bnds[2][startIndex:lastIndex + 2] if reverse_latitude == 'yes': wts = wts[::-1] bnds = bnds[::-1] return (wts,bnds) else: # must be generic latitude ------- wts, bnds = generic_wts_bnds(latIn) if reverse_latitude == 'yes': wts = wts[::-1] bnds = bnds[::-1] return (wts,bnds)
def get_region_latitude_wts_bnds(latRegionpass, latType, latSize): """ #------------------------------------------------------------------- # # routine: get_region_latitude_wts_bnds # # purpose: compare the passed latitudes, latRegion, with the global # ones calculated here and extract the wts and bounds for # the region # # usage: wts,bnds = get_region_latitude_wts_bnds(latRegion, latType, latSize) # where latRegion is the regional grid to check # # return: wts, bnds - tuple with weights and bounds # #-------------------------------------------------------------------------""" latTypeList = ['gaussian', 'equalarea', 'uniform', 'generic'] if latType not in latTypeList: sendmsg( "Error in latType -- it must be 'gaussian', 'equalarea', 'even' or 'generic' and not ", latType) raise ValueError return if latSize == None: sendmsg('Error in latSize -- it must be a number') raise ValueError return nlat = len(latRegionpass) reverse_latitude = 'no' # ------ set latitude direction to n to s for comparisons ------- if latRegionpass[0] < latRegionpass[nlat - 1]: # need a copy? latRegion = numpy.array(latRegionpass, numpy.float64) latRegion = latlatRegion[::-1] reverse_latitude = 'yes' else: latRegion = latRegionpass small = 0.001 # use as tolerance in checking values # ------ check the pass for gaussian latitudes ------- if latType != 'generic': pts_wts_bnds = _regrid.gridattr( latSize, latType) # n to s global pts, wts and bnds latvals = pts_wts_bnds[0] imatch = -1 i = 0 while (imatch == -1): if abs(latvals[i] - latRegion[0]) < small: # first index found startIndex = i imatch = 0 i = i + 1 imatch = -1 while (imatch == -1): if abs(latvals[i] - latRegion[nlat - 1]) < small: # last index found lastIndex = i imatch = 0 i = i + 1 wts = pts_wts_bnds[1][startIndex:lastIndex + 1] bnds = pts_wts_bnds[2][startIndex:lastIndex + 2] if reverse_latitude == 'yes': wts = wts[::-1] bnds = bnds[::-1] return (wts, bnds) else: # must be generic latitude ------- wts, bnds = generic_wts_bnds(latIn) if reverse_latitude == 'yes': wts = wts[::-1] bnds = bnds[::-1] return (wts, bnds)
def get_latitude_wts_bnds(checklatpass): """ #------------------------------------------------------------------- # # routine: get_latitude_wts_bnds # # purpose: compare the passed checklatpass with the correct geophysical # ones calculated here. After finding a match call the function # to get the bounds. # # usage: wts,bnds = get_latitude_wts_bnds(checklatpass) # where checklatpass is the grid to check # # return: wts, bnds - tuple with weights and bounds # #-------------------------------------------------------------------------""" small = 0.001 # use as tolerance in checking values nlat = len(checklatpass) reverse_latitude = 'no' # ------ set latitude direction to n to s for comparisons ------- if checklatpass[0] < checklatpass[nlat-1]: # need a copy? checklat = numpy.array(checklatpass, numpy.float64) checklat = checklat[::-1] reverse_latitude = 'yes' else: checklat = checklatpass # ------ check the pass for evenly spaced latitudes ------- firstdelta = abs(checklat[0] - checklat[1]) maxdiff = 0.0 for i in range(1, nlat - 1): diff = abs(firstdelta - (checklat[i] - checklat[i+1])) if diff > maxdiff: maxdiff = diff if maxdiff < small: if abs(90. - checklat[0]) > small or abs(-90. - checklat[nlat-1]) > small: grid_type = 'even' # evenly spaced without poles wts, bnds = generic_wts_bnds(checklat) if reverse_latitude == 'yes': wts = wts[::-1] bnds = bnds[::-1] return (wts,bnds) else: grid_type = 'uniform' # evenly spaced with poles pts_wts_bnds = _regrid.gridattr(nlat, grid_type) wts = pts_wts_bnds[1] bnds = pts_wts_bnds[2] if reverse_latitude == 'yes': wts = wts[::-1] bnds = bnds[::-1] return (wts,bnds) # ------ check the pass for gaussian latitudes ------- grid_type = 'gaussian' pts_wts_bnds = _regrid.gridattr(nlat, grid_type) latvals = pts_wts_bnds[0] laterror = max( abs(latvals - checklat) ) if laterror < small: wts = pts_wts_bnds[1] bnds = pts_wts_bnds[2] if reverse_latitude == 'yes': wts = wts[::-1] bnds = bnds[::-1] return (wts,bnds) # ------ check the pass for equalarea latitudes ------- grid_type = 'equalarea' pts_wts_bnds = _regrid.gridattr(nlat, grid_type) latvals = pts_wts_bnds[0] laterror = max( abs(latvals - checklat) ) if laterror < small: wts = pts_wts_bnds[1] bnds = pts_wts_bnds[2] if reverse_latitude == 'yes': wts = wts[::-1] bnds = bnds[::-1] return (wts,bnds) # ------ must be generic latitude ------- wts, bnds = generic_wts_bnds(checklat) if reverse_latitude == 'yes': wts = wts[::-1] bnds = bnds[::-1] return (wts,bnds)
def get_latitude_wts_bnds(checklatpass): """ #------------------------------------------------------------------- # # routine: get_latitude_wts_bnds # # purpose: compare the passed checklatpass with the correct geophysical # ones calculated here. After finding a match call the function # to get the bounds. # # usage: wts,bnds = get_latitude_wts_bnds(checklatpass) # where checklatpass is the grid to check # # return: wts, bnds - tuple with weights and bounds # #-------------------------------------------------------------------------""" small = 0.001 # use as tolerance in checking values nlat = len(checklatpass) reverse_latitude = 'no' # ------ set latitude direction to n to s for comparisons ------- if checklatpass[0] < checklatpass[nlat - 1]: # need a copy? checklat = numpy.array(checklatpass, numpy.float64) checklat = checklat[::-1] reverse_latitude = 'yes' else: checklat = checklatpass # ------ check the pass for evenly spaced latitudes ------- firstdelta = abs(checklat[0] - checklat[1]) maxdiff = 0.0 for i in range(1, nlat - 1): diff = abs(firstdelta - (checklat[i] - checklat[i + 1])) if diff > maxdiff: maxdiff = diff if maxdiff < small: if abs(90. - checklat[0]) > small or abs(-90. - checklat[nlat - 1]) > small: grid_type = 'even' # evenly spaced without poles wts, bnds = generic_wts_bnds(checklat) if reverse_latitude == 'yes': wts = wts[::-1] bnds = bnds[::-1] return (wts, bnds) else: grid_type = 'uniform' # evenly spaced with poles pts_wts_bnds = _regrid.gridattr(nlat, grid_type) wts = pts_wts_bnds[1] bnds = pts_wts_bnds[2] if reverse_latitude == 'yes': wts = wts[::-1] bnds = bnds[::-1] return (wts, bnds) # ------ check the pass for gaussian latitudes ------- grid_type = 'gaussian' pts_wts_bnds = _regrid.gridattr(nlat, grid_type) latvals = pts_wts_bnds[0] laterror = max(abs(latvals - checklat)) if laterror < small: wts = pts_wts_bnds[1] bnds = pts_wts_bnds[2] if reverse_latitude == 'yes': wts = wts[::-1] bnds = bnds[::-1] return (wts, bnds) # ------ check the pass for equalarea latitudes ------- grid_type = 'equalarea' pts_wts_bnds = _regrid.gridattr(nlat, grid_type) latvals = pts_wts_bnds[0] laterror = max(abs(latvals - checklat)) if laterror < small: wts = pts_wts_bnds[1] bnds = pts_wts_bnds[2] if reverse_latitude == 'yes': wts = wts[::-1] bnds = bnds[::-1] return (wts, bnds) # ------ must be generic latitude ------- wts, bnds = generic_wts_bnds(checklat) if reverse_latitude == 'yes': wts = wts[::-1] bnds = bnds[::-1] return (wts, bnds)