def ContourLevelsL(numCont, decades, Z): if numCont < 3: numCont = 3 maxVal = np.amax(Z) maxDec = 0.5 + np.log10(maxVal) minDec = maxDec - decades - 1 levels = list(np.linspace(minDec, maxDec, numCont)) if maxDec not in levels: levels.append(maxDec) minTick = int(np.ceil(np.amin(levels))) maxTick = int(np.floor(np.amax(levels))) dLevel = int((maxTick - minTick + 1) / numCont) if dLevel < 1: dLevel = 1 levels = [10**x for x in levels] tick = list(range(minTick, maxTick + 1, dLevel)) levelTicks = [10**x for x in tick] maxLevTick = 8 if len(levelTicks) > maxLevTick: indxStep = int(np.ceil(float(len(levelTicks)) / maxLevTick)) lastTick = levelTicks[-1] levelTicks = levelTicks[0:-1:indxStep] if lastTick not in levelTicks: levelTicks.append(lastTick) levelTickLabels = ['$10^{' + str(x) + '}$' for x in levelTicks] return (levels, levelTicks, levelTickLabels)
def ProcessPointsXYZ(x, y, z, auxDict): if 'xlim' in auxDict and auxDict['xlim'] is not None: xlim = auxDict['xlim'] indxMax = x < float(xlim[1]) x = x[indxMax] z = z[indxMax, :] indxMin = x >= float(xlim[0]) x = x[indxMin] z = z[indxMin, :] nx = len(x) if nx == 0: print('No points within specfied x-limits: ') print('EXITING!') sys.exit() if 'ylim' in auxDict and auxDict['ylim'] is not None: ylim = auxDict['ylim'] indxMax = y < float(ylim[1]) y = y[indxMax] z = z[:, indxMax] indxMin = y >= float(ylim[0]) y = y[indxMin] z = z[:, indxMin] ny = len(y) if ny == 0: print('No points within specfied y-limits: ') print('EXITING!') sys.exit() indxStep = 1 if nx > int(configs._G["pointsX_2D"]): indxStep = int(np.ceil(float(nx) / int(configs._G["pointsX_2D"]))) x = x[0:nx:indxStep] z = z[0:nx:indxStep, :] indxStep = 1 if ny > int(configs._G["pointsY_2D"]): indxStep = int(np.ceil(float(ny) / int(configs._G["pointsY_2D"]))) y = y[0:ny:indxStep] z = z[:, 0:ny:indxStep] if 'ycordID' in auxDict: if (auxDict['ycordID'] == 'R' or auxDict['ycordID'] == 'SR'): y = np.hstack([-np.flipud(y), y]) z = np.hstack([np.fliplr(z), z]) if 'decades' in auxDict and auxDict['decades'] is not None: z = ProcessDecadeLimits(float(auxDict['decades']), z) return (x, y, z)
def ProcessDecadeLimits(decades, data): datamax = 10.0 * np.amax(data) datamin = pow(10, -decades - 1) * datamax maxLevel = int(np.ceil(np.log10(datamax))) minLevel = int(maxLevel - decades - 1) data[data < pow(10, minLevel)] = pow(10, minLevel) return data
def ProcessPointsX(x, y, auxDict): if 'xlim' in auxDict and auxDict['xlim'] is not None: xlim = auxDict['xlim'] indxMax = x < float(xlim[1]) x = x[indxMax] y = y[indxMax] indxMin = x >= float(xlim[0]) x = x[indxMin] y = y[indxMin] nx = len(x) if nx == 0: raise Exception('No points within specified x-limits') indxStep = 1 if nx > int(configs._G["points1D"]): indxStep = int(np.ceil(float(nx) / int(configs._G["points1D"]))) x = x[0:nx:indxStep] y = y[0:nx:indxStep] else: xvals = np.linspace(x[0], x[-1], int(configs._G["points1D"])) y = np.interp(xvals, x, y) x = xvals if 'xcordID' in auxDict: if (auxDict['xcordID'] == 'R'): x = np.hstack([-np.flipud(x), x]) y = np.hstack([np.flipud(y), y]) return (x, y)
def ContourLevels(levels, Z): zmin = None zmax = None if levels is None: numCont = int(configs._G['contours']) zmin = float(np.amin(Z)) zmax = float(np.amax(Z)) dz = (zmax - zmin) / (numCont - 1) levels = np.zeros(numCont, dtype=float) for i in range(numCont): levels[i] = zmin + i * dz if not isinstance(levels, int): numCont = len(levels) else: numCont = levels if zmin is not None: minTick = zmin else: minTick = float(np.amin(Z)) if zmax is not None: maxTick = zmax else: maxTick = float(np.amax(Z)) levelTicks = list(np.linspace(minTick, maxTick, numCont)) maxLevTick = 6 if len(levelTicks) > maxLevTick: indxStep = int(np.ceil(float(len(levelTicks)) / maxLevTick)) lastTick = levelTicks[-1] levelTicks = levelTicks[0:-1:indxStep] if lastTick not in levelTicks: levelTicks.append(lastTick) levelTickLabels = [str(np.round(tick, 2)) for tick in levelTicks] return (levels, levelTicks, levelTickLabels)