def __interpolateParameters__(self, height, latitude, tkcDeep, tkcUpper): # Preallocate result array and start looping through all values isScalar = not util.isArray(height) results = [] if isScalar: results = [0] height = [height] latitude = [latitude] else: results = np.zeros(height.shape) for i in range(0, len(height)): # Check where the height is with respect to the interpolation limits if height[i] <= tkcDeep[0][-1]: results[i] = scp_ip.splev(height[i], tkcDeep) elif height[i] >= tkcUpper[0][0]: results[i] = scp_ip.bisplev(height[i], latitude[i], tkcUpper) else: # Interpolate between the lower and upper interpolating functions (do # so linearly for now) low = scp_ip.splev(tkcDeep[0][-1], tkcDeep) high = scp_ip.bisplev(tkcUpper[0][0], latitude[i], tkcUpper) results[i] = low + (high - low) * (height[i] - tkcDeep[0][-1]) / \ (tkcUpper[0][0] - tkcDeep[0][-1]) if isScalar: return results[0] return results
def __printSplineCoefficients__(variableName, variable, valuesPerLine=5, baseTab=1): if not isinstance(variable, list): if not hasattr(variable, "__len__"): raise ValueError("Expected variable 'variable' to be a list") tabs = '' for i in range(0, baseTab): tabs += '\t' msg = tabs + variableName + " = [ " for iVariable in range(0, len(variable)): if util.isArray(variable[iVariable]): numValues = len(variable[iVariable]) numComplete = int((numValues - (numValues % valuesPerLine)) / valuesPerLine) numRemaining = numValues % valuesPerLine if (numRemaining == 0): numRemaining = valuesPerLine numComplete -= 1 if iVariable != 0: msg += tabs + "[ " else: msg += "[ " for iComplete in range(0, numComplete): for iSub in range(0, valuesPerLine): msg += str(variable[iVariable][iComplete * valuesPerLine + iSub]) + ", " msg += "\n\t" + tabs for iRemaining in range(0, numRemaining - 1): msg += str(variable[iVariable][numComplete * valuesPerLine + iRemaining]) + ", " msg += str(variable[iVariable][numComplete * valuesPerLine + numRemaining - 1]) + " ]" else: msg += tabs + str(variable[iVariable]) if iVariable != len(variable) - 1: msg += ",\n\t" msg += " ]" print(msg)
def kinematicViscosity(self, height, latitude, solarLongitude): density = self.density(height, latitude, solarLongitude) temperature = self.temperature(height, latitude, solarLongitude) isScalar = not util.isArray(height) if isScalar: return [ util.DynViscosity(temperature[0]) / density[2], util.DynViscosity(temperature[1]) / density[1], util.DynViscosity(temperature[2]) / density[0] ] dynViscosity = [ util.DynViscosity(temperature[0]), util.DynViscosity(temperature[1]), util.DynViscosity(temperature[2]) ] density = np.flipud(density) return dynViscosity / density
def __checkAndModifyParameters__(self, height, latitude, solarLongitude, tkc): # If any of the variables is an array, convert all the other scalars # to a similarly sized array arraySize = 0 if util.isArray(height): arraySize = len(height) elif util.isArray(latitude): arraySize = len(latitude) elif util.isArray(solarLongitude): arraySize = len(solarLongitude) if arraySize != 0: if not util.isArray(height): height = np.asarray([height] * arraySize) else: height = np.asarray(height) if not util.isArray(latitude): latitude = np.asarray([latitude] * arraySize) else: latitude = np.asarray(latitude) if not util.isArray(solarLongitude): solarLongitude = np.asarray([solarLongitude] * arraySize) else: solarLongitude = np.asarray(solarLongitude) latitude = abs(latitude) if arraySize != 0: # Cap latitude values (do not interpolate above or below the # known bounds) for i in range(0, len(latitude)): if latitude[i] < tkc[1][0]: latitude[i] = tkc[1][0] elif latitude[i] > tkc[1][-1]: latitude[i] = tkc[1][-1] for i in range(0, len(height)): if height[i] < 0 or height[i] > tkc[0][-1]: raise ValueError("Height is outside of the interpolation bounds") else: if height < 0 or height > tkc[0][-1]: raise ValueError("Height is outside of the interpolation bounds") return height, latitude, solarLongitude