Metadata-Version: 2.1
Name: yaw-sweep-sg-cali
Version: 1.2
Summary: Package to perform strain gauge of wind turbine towers calibration based on idling opeartions, so called, yaw sweeps
Author: Bruno and Zahra
Author-email: brofa@dtu.dk
Description-Content-Type: text/markdown
License-File: LICENSE

# V52 Tower Strain Gauges Calibration

## Dear dear user, this tool requires the installation of the toolbox Mysqlclient 2.1.1.

Installation:
```
pip install mysqlclient
```  
## Project Overview:

Tower strain gauges are commonly used in wind turbine applications to measure the strain on the tower or structure. To ensure accurate readings for a V52 wind turbine, it is important to regularly calibrate these gauges.This project aims to develop an automatic routine to generate strain gauge calibration factors for around 5 years (2018 to 2023), considering zero drift. The validation of the recordings will be pursued through specific idling operations, so called **Yaw Sweeps**.
- The research wind turbine V52:

The research wind turbine V52 from Vestas is situated at DTU RisÃ¸ Campus as a part of the row of wind turbines at the fjord. The 850 kW wind turbine arrived at DTU in 2015.- [DTU Wind and Energy Systems](https://wind.dtu.dk/Facilities/The-research-wind-turbine-V52) 
- Database:

To perform the project the databases used to test (SQL):

	- SCADA data from V52 and data from RisÃ¸ met mast.
	- Strain measures from V52 tower 
- Package stepwise:
First, identify yaw sweep operations, in which the aerodynamic contribution to the tower bending moment is negligible (low wind speed). Secondly, using such operations, automatically curve fits the raw bending moment signal and extracts relavant information, as max, min, and mean values. Finally, generate recommended calibration factors (offsets). The number of yaw sweeps operation throughout a year is unknown. 

## Improvements performed from first submission to final submission

- The code was made more robust, adding safety features to avoid the code did not run due to mistakes or missunderstandings. For this, some functions were created to avoid errors and ensure the code run as expected.  
- The code was check with pycodestyle, to ensure was properly with the recommended standards. 
- PEP 257 information added to each function

## Getting Started - How it works
This is a Python package for identifying and calibrating yaw sweeps in wind turbines. The package includes four main modules:

- Load_data: for loading the 1-minute and 50Hz data from SQL or local source.
- Yaw_sweep_identification: for identifying the yaw sweep instants based on name and scan_id.
- Curve_fitting: for fitting sinusoidal curves to the yaw sweep data to extract max, min, mean, and error values.
- Calibration_factors: for calculating the calibration factors (offset, gain, and wind speed) for the yaw sensors.

### Step 1:User Input
- start (YYYY,MM)
- stop (YYYY,MM)

The following variables are required to be defined by the user:

start: A tuple of the form (year, month) representing the start time period for analysis.
stop: A tuple of the form (year, month) representing the end time period for analysis.
turbine_file: The name of the file containing turbine data that will be used for calibration factors.
### Step 2:First Data loading (SQL or Local)
 This code loads data either from a local source or from an SQL database. It uses the function get_SQL_1_min(start, stop) from the module yaw_sweep_sg_cali.Load_data.
#### Inputs
- start: A tuple representing the start date and time for the data to be loaded in the format (year, month).
- stop: A tuple representing the stop date and time for the data to be loaded in the format (year, month).
#### Outputs
- data_1_min: A pandas DataFrame containing the loaded data.
Note: The specific source of the data (local or SQL) is determined by the implementation of the get_SQL_1_min() function, and is not directly controlled by the user through these inputs
### Step 3:Identifying the Yaw Sweep (ys) instants based on name and scan_id
This code line identifies the Yaw Sweep (ys) instants based on the input data data_1_min. It returns three variables name_ys, scan_id_ys, and numb_ys.
#### Inputs
- data_1_min: Input data to be analyzed to identify the yaw sweep.

#### Outputs
- name_ys: Name of the Yaw Sweep.
- scan_id_ys: Scan ID of the Yaw Sweep.
- numb_ys: Number of Yaw Sweeps present in the input data.
#### Parameters
- partial_plot: A Boolean parameter. If it's True, the partial plot will be shown during the analysis
### Step 4:Second Data Loading (SQL or Local) for calibration factors
get_SQL_50_Hz function loads data at 50Hz from the SQL database for yaw sweep data that was previously identified using identify_yaw_sweep function.
#### Inputs
- name_ys: the name of the data file containing yaw sweep data
- scan_id_ys: the ID of the scan where yaw sweep data is stored
- db_connection_string (optional): a connection string for connecting to the SQL database. If not provided, the function will use a default connection string.

#### Outputs
- data_50_Hz: a pandas DataFrame containing the 50Hz yaw sweep data
### Step 4: Fitting Sinus to extract max, min, mean, errs of curve fitting
The curve_fitting_ys function in this module fits a sinusoidal curve to the yaw sweep data and returns the maximum, minimum, mean, and error values. The input parameters for this function are:

- numb_ys: the number of yaw sweeps to fit.
- data_50_Hz: data with 50 Hz sampling frequency.
- name_ys: a string specifying the name of the yaw sweep.
- scan_id_ys: a string specifying the scan id of the yaw sweep.
- partial_plot: boolean specifying whether or not to plot partial results.
The output of the function is a dictionary containing the fitted curve outputs and warnings.
#### Usage
To use the curve_fitting_ys function, first call the get_SQL_1_min and get_SQL_50_Hz functions from the Load_data module to load the required data. Then use the identify_yaw_sweep function from the Yaw_sweep_identification module to identify the yaw sweep instances. Finally, call the curve_fitting_ys function with the required input parameters.
### Step 5:Calibration Factors (offset,gain,windspeed)
This script is designed to calculate calibration factors for a wind turbine based on data collected during yaw sweeps. The script requires several input parameters, and the output is a set of calibration factors that can be used to improve the accuracy of wind speed measurements.
#### Required Libraries
The following libraries are required for this script:

- yaw_sweep_sg_cali.Load_data
- yaw_sweep_sg_cali.Yaw_sweep_identification
- yaw_sweep_sg_cali.Curve_fitting
- yaw_sweep_sg_cali.Calibration_factors
#### User Input

The script requires the following user input parameters:

- start: a tuple representing the start date of the data collection period (year, month)
- stop: a tuple representing the end date of the data collection period (year, month)
turbine_file: a string representing the name of a file containing turbine inputs
##### Data Loading
The script first loads data from the SQL database or from local files using the get_SQL_1_min function.
##### Identifying Yaw Sweeps
The script then identifies the yaw sweep instants based on name and scan_id using the identify_yaw_sweep function. This function takes in the loaded data and returns three variables:
- name_ys: a string representing the name of the yaw sweep
- scan_id_ys: an integer representing the scan ID of the yaw sweep
- numb_ys: an integer representing the number of yaw sweeps in the data
##### Second Data Loading
The script then loads data from the SQL database or from local files using the get_SQL_50_Hz function.
##### Fitting Sinus
The script fits a sinus curve to the yaw sweep data using the curve_fitting_ys function. This function takes in the yaw sweep data and other variables returned by identify_yaw_sweep and returns two variables:

- fitted_curve_outputs: a list containing the maximum, minimum, mean, and error of the fitted sinus curve
- warnings: a string containing any warnings generated during curve fitting
##### Calculating Calibration Factors
The script then calculates calibration factors using the get_cali_factors function. This function takes in the fitted curve outputs, the turbine file name, and any warnings generated during curve fitting. It returns a dictionary containing the calibration factors.
#### User Input
The output of the script is a set of calibration factors that can be used to improve the accuracy of wind speed measurements. The calibration factors are stored in a dictionary with keys offset, gain, and windspeed. A plot of the fitted curve can also be generated by setting the plot parameter of get_cali_factors to True.

## Installation
To use this code, clone the repository and install the required dependencies:

```
git clone  https://github.com/username/yaw-sweep-sg-cali.git
cd yaw-sweep-sg-cali
pip install -r requirements.txt
```
The package can be installed using pip:
	- [ ] $ git clone https://github.com/username/yaw-sweep-sg-cali.git
	- [ ]  cd yaw-sweep-sg-cali
	- [ ]  pip install -r requirements.txt



## Add your files

- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:

```
cd existing_repo
git remote add origin https://gitlab.windenergy.dtu.dk/python-at-risoe/spp-2023/v52-strain-gauge-calibration.git
git branch -M main
git push -uf origin main
```

## Integrate with your tools

- [ ] [Set up project integrations](https://gitlab.windenergy.dtu.dk/python-at-risoe/spp-2023/v52-strain-gauge-calibration/-/settings/integrations)

## Collaborate with your team

- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)

## Test and Deploy

Use the built-in continuous integration in GitLab.

- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)

***

## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.

## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.

## License
This code is licensed under the MIT License.

