Exemplo n.º 1
0
	def __init__(self, config):

		dateConverter = lambda x: datetime.datetime.strptime(x, config.dateFormat)

		self.windSpeedBin = "WindSpeedBin"

		self.windSpeedBins = binning.Bins(1.0, 1, 30.0)
		self.aggregations = binning.Aggregations(minimumCount=1)

		dataFrame = pd.read_csv(config.inputTimeSeriesPath, index_col=config.timeStamp, parse_dates = True, date_parser = dateConverter, sep = '\t', skiprows = config.headerRows).replace(config.badData, np.nan)
		dataFrame[self.windSpeedBin] = dataFrame[config.inputHubWindSpeed].map(self.windSpeedBins.binCenter)

		powers = dataFrame[config.actualPower].groupby(dataFrame[self.windSpeedBin]).aggregate(self.aggregations.average)
		stdErrorPowers = dataFrame[config.actualPower].groupby(dataFrame[self.windSpeedBin]).aggregate(self.aggregations.standardError)

		catBPowerUncertainty = {}

		uPdyn_Applied = True
		uPVT_Applied = True

		catBPowerUncertainty = {}

		for windSpeed in self.windSpeedBins.centers:

			if windSpeed in powers:

				power = powers[windSpeed]

				catBPowerUncertainty[windSpeed] = CategoryBPowerUncertainty(power, uPdyn_Applied = uPdyn_Applied, uPVT_Applied = uPVT_Applied)
				print catBPowerUncertainty[windSpeed].catBPowerUncertainty
Exemplo n.º 2
0
    def __init__(self, config, rotorGeometry, analysisConfig):

        self.relativePath = configuration.RelativePath(config.path)
        self.nameColumn = "Dataset Name"
        self.name = config.name

        self.timeStepInSeconds = config.timeStepInSeconds

        self.timeStamp = config.timeStamp
        self.actualPower = "Actual Power"
        self.hasAllPowers = None not in (config.powerMin, config.powerMax,
                                         config.powerSD)
        self.powerMin = "Power Min"
        self.powerMax = "Power Max"
        self.powerSD = "Power SD"

        self.hubWindSpeed = "Hub Wind Speed"
        self.hubTurbulence = "Hub Turbulence"
        self.hubDensity = "Hub Density"
        self.shearExponent = "Shear Exponent"
        self.referenceShearExponent = "Reference Shear Exponent"
        self.turbineShearExponent = "Turbine Shear Exponent"
        self.windDirection = "Wind Direction"

        self.profileRotorWindSpeed = "Profile Rotor Wind Speed"
        self.profileHubWindSpeed = "Profile Hub Wind Speed"
        self.profileHubToRotorRatio = "Hub to Rotor Ratio"
        self.profileHubToRotorDeviation = "Hub to Rotor Deviation"
        self.residualWindSpeed = "Residual Wind Speed"

        self.hasShear = len(config.shearMeasurements) > 1
        self.hasDirection = config.referenceWindDirection not in (None, '')
        self.shearCalibration = "TurbineLocation" in config.shearMeasurements.keys(
        ) and "ReferenceLocation" in config.shearMeasurements.keys()
        self.hubWindSpeedForTurbulence = self.hubWindSpeed if config.turbulenceWSsource != 'Reference' else config.referenceWindSpeed
        self.turbRenormActive = analysisConfig.turbRenormActive
        self.turbulencePower = 'Turbulence Power'
        self.rewsDefined = config.rewsDefined

        self.sensitivityDataColumns = config.sensitivityDataColumns

        dateConverter = lambda x: datetime.datetime.strptime(
            x, config.dateFormat)
        dataFrame = pd.read_csv(self.relativePath.convertToAbsolutePath(config.inputTimeSeriesPath), index_col=config.timeStamp, \
                                parse_dates = True, date_parser = dateConverter, sep = getSeparatorValue(config.separator), \
                                skiprows = config.headerRows).replace(config.badData, np.nan)

        if config.startDate != None and config.endDate != None:
            dataFrame = dataFrame[config.startDate:config.endDate]
        elif config.startDate != None:
            dataFrame = dataFrame[config.startDate:]
        elif config.endDate != None:
            dataFrame = dataFrame[:config.endDate]

        dataFrame[self.nameColumn] = config.name
        dataFrame[self.timeStamp] = dataFrame.index

        if self.hasDirection:
            dataFrame[self.windDirection] = dataFrame[
                config.referenceWindDirection]

        if self.hasShear:
            if not self.shearCalibration:
                dataFrame[self.shearExponent] = dataFrame.apply(
                    ShearExponentCalculator(
                        config.shearMeasurements).shearExponent,
                    axis=1)
            else:
                dataFrame[self.turbineShearExponent] = dataFrame.apply(
                    ShearExponentCalculator(
                        config.shearMeasurements["TurbineLocation"]).
                    shearExponent,
                    axis=1)
                dataFrame[self.referenceShearExponent] = dataFrame.apply(
                    ShearExponentCalculator(
                        config.shearMeasurements["ReferenceLocation"]).
                    shearExponent,
                    axis=1)
                dataFrame[self.shearExponent] = dataFrame[
                    self.referenceShearExponent]

        dataFrame[self.residualWindSpeed] = 0.0

        if config.calculateHubWindSpeed:

            if dataFrame[config.referenceWindSpeed].count() < 1:
                raise Exception(
                    "Reference wind speed column is empty: cannot apply calibration"
                )

            if dataFrame[config.referenceWindDirection].count() < 1:
                raise Exception(
                    "Reference wind direction column is empty: cannot apply calibration"
                )

            self.calibrationCalculator = self.createCalibration(
                dataFrame, config, config.timeStepInSeconds)
            dataFrame[self.hubWindSpeed] = dataFrame.apply(
                self.calibrationCalculator.turbineValue, axis=1)

            if dataFrame[self.hubWindSpeed].count() < 1:
                raise Exception(
                    "Hub wind speed column is empty after application of calibration"
                )

            if (config.hubTurbulence != ''):
                dataFrame[self.hubTurbulence] = dataFrame[config.hubTurbulence]
            else:
                dataFrame[self.hubTurbulence] = dataFrame[
                    config.referenceWindSpeedStdDev] / dataFrame[
                        self.hubWindSpeedForTurbulence]

            if config.calibrationMethod != "Specified":

                dataFrame[self.residualWindSpeed] = (
                    dataFrame[self.hubWindSpeed] -
                    dataFrame[config.turbineLocationWindSpeed]
                ) / dataFrame[self.hubWindSpeed]

                windSpeedBin = "Wind Speed Bin"
                turbulenceBin = "Turbulence Bin"

                windSpeedBins = binning.Bins(analysisConfig.powerCurveFirstBin,
                                             analysisConfig.powerCurveBinSize,
                                             analysisConfig.powerCurveLastBin)
                turbulenceBins = binning.Bins(
                    0.01, 0.01 / windSpeedBins.numberOfBins, 0.02)
                aggregations = binning.Aggregations(
                    analysisConfig.powerCurveMinimumCount)

                dataFrame[windSpeedBin] = dataFrame[self.hubWindSpeed].map(
                    windSpeedBins.binCenter)
                dataFrame[turbulenceBin] = dataFrame[self.hubTurbulence].map(
                    turbulenceBins.binCenter)

                self.residualWindSpeedMatrix = DeviationMatrix(
                    dataFrame[self.residualWindSpeed].groupby([
                        dataFrame[windSpeedBin], dataFrame[turbulenceBin]
                    ]).aggregate(aggregations.average),
                    dataFrame[self.residualWindSpeed].groupby(
                        [dataFrame[windSpeedBin],
                         dataFrame[turbulenceBin]]).count())
            else:

                self.residualWindSpeedMatrix = None

        else:

            dataFrame[self.hubWindSpeed] = dataFrame[config.hubWindSpeed]
            if (config.hubTurbulence != ''):
                dataFrame[self.hubTurbulence] = dataFrame[config.hubTurbulence]
            else:
                dataFrame[self.hubTurbulence] = dataFrame[
                    config.referenceWindSpeedStdDev] / dataFrame[
                        self.hubWindSpeedForTurbulence]
            self.residualWindSpeedMatrix = None

        if self.shearCalibration and config.shearCalibrationMethod != "Reference":
            self.shearCalibrationCalculator = self.createShearCalibration(
                dataFrame, config, config.timeStepInSeconds)
            dataFrame[self.shearExponent] = dataFrame.apply(
                self.shearCalibrationCalculator.turbineValue, axis=1)

        if config.calculateDensity:
            dataFrame[self.hubDensity] = 100.0 * dataFrame[config.pressure] / (
                273.15 + dataFrame[config.temperature]) / 287.058
            self.hasDensity = True
        else:
            if config.density != None:
                dataFrame[self.hubDensity] = dataFrame[config.density]
                self.hasDensity = True
            else:
                self.hasDensity = False

        if config.power != None:
            dataFrame[self.actualPower] = dataFrame[config.power]
            self.hasActualPower = True
        else:
            self.hasActualPower = False

        if self.hasAllPowers:
            dataFrame[self.powerMin] = dataFrame[config.powerMin]
            dataFrame[self.powerMax] = dataFrame[config.powerMax]
            dataFrame[self.powerSD] = dataFrame[config.powerSD]

        dataFrame = self.filterDataFrame(dataFrame, config.filters)
        dataFrame = self.excludeData(dataFrame, config)

        if self.rewsDefined:
            dataFrame = self.defineREWS(dataFrame, config, rotorGeometry)

        self.fullDataFrame = dataFrame.copy()
        self.dataFrame = self.extractColumns(dataFrame).dropna()
        if self.windDirection in self.dataFrame.columns:
            self.analysedDirections = (
                round(self.fullDataFrame[self.windDirection].min() +
                      config.referenceWindDirectionOffset),
                round(self.fullDataFrame[self.windDirection].max() +
                      config.referenceWindDirectionOffset))
Exemplo n.º 3
0
    def calculate_hub_wind_speed(self, config, analysisConfig, dataFrame):

        self.verify_column_datatype(dataFrame, config.referenceWindSpeed)

        dataFrame[self.referenceWindSpeed] = dataFrame[
            config.referenceWindSpeed]

        if config.turbineLocationWindSpeed not in ('', None):
            dataFrame[self.turbineLocationWindSpeed] = dataFrame[
                config.turbineLocationWindSpeed]

        if dataFrame[config.referenceWindSpeed].count() < 1:
            raise Exception(
                "Reference wind speed column is empty: cannot apply calibration"
            )

        if dataFrame[config.referenceWindDirection].count() < 1:
            raise Exception(
                "Reference wind direction column is empty: cannot apply calibration"
            )

        self.calibrationCalculator = self.createCalibration(
            dataFrame, config, config.timeStepInSeconds)
        dataFrame[self.hubWindSpeed] = dataFrame.apply(
            self.calibrationCalculator.turbineValue, axis=1)

        if dataFrame[self.hubWindSpeed].count() < 1:
            raise Exception(
                "Hub wind speed column is empty after application of calibration"
            )

        if (config.hubTurbulence != ''):
            dataFrame[self.hubTurbulence] = dataFrame[config.hubTurbulence]
        else:
            dataFrame[self.hubTurbulence] = dataFrame[
                config.referenceWindSpeedStdDev] / dataFrame[
                    self.hubWindSpeedForTurbulence]

        if config.calibrationMethod != "Specified":

            dataFrame[self.residualWindSpeed] = (
                dataFrame[self.hubWindSpeed] -
                dataFrame[config.turbineLocationWindSpeed]
            ) / dataFrame[self.hubWindSpeed]

            dimensions = []
            windSpeedBin = "Wind Speed Bin"
            turbulenceBin = "Turbulence Bin"

            windSpeedBins = binning.Bins(analysisConfig.powerCurveFirstBin,
                                         analysisConfig.powerCurveBinSize,
                                         analysisConfig.powerCurveLastBin)
            turbulenceBins = binning.Bins(0.01,
                                          0.01 / windSpeedBins.numberOfBins,
                                          0.02)

            dimensions.append(
                PowerDeviationMatrixDimension(self.hubWindSpeed,
                                              windSpeedBins.centerOfFirstBin,
                                              windSpeedBins.binWidth,
                                              windSpeedBins.numberOfBins))
            dimensions.append(
                PowerDeviationMatrixDimension(self.hubTurbulence,
                                              turbulenceBins.centerOfFirstBin,
                                              turbulenceBins.binWidth,
                                              turbulenceBins.numberOfBins))

            aggregations = binning.Aggregations(
                analysisConfig.powerCurveMinimumCount)

            windSpeedBins = binning.Bins(analysisConfig.powerCurveFirstBin,
                                         analysisConfig.powerCurveBinSize,
                                         analysisConfig.powerCurveLastBin)
            turbulenceBins = binning.Bins(0.01,
                                          0.01 / windSpeedBins.numberOfBins,
                                          0.02)
            aggregations = binning.Aggregations(
                analysisConfig.powerCurveMinimumCount)

            dataFrame[windSpeedBin] = dataFrame[self.hubWindSpeed].map(
                windSpeedBins.binCenter)
            dataFrame[turbulenceBin] = dataFrame[self.hubTurbulence].map(
                turbulenceBins.binCenter)

            self.residualWindSpeedMatrix = AverageOfDeviationsMatrix(
                dataFrame[self.residualWindSpeed].groupby([
                    dataFrame[windSpeedBin], dataFrame[turbulenceBin]
                ]).aggregate(aggregations.average),
                dataFrame[self.residualWindSpeed].groupby(
                    [dataFrame[windSpeedBin],
                     dataFrame[turbulenceBin]]).count(), dimensions)
        else:

            self.residualWindSpeedMatrix = None

        return dataFrame