<jupyter_start><jupyter_text>MHKiT Power Module  The following example uses the [MHKiT power module](https://mhkit-software.github.io/MHKiT/mhkit-python/api.power.html) to compute power, instantaneous frequency, and harmonics from time-series of voltage and current. Start by importing the necessary python packages and MHKiT module.<jupyter_code>import numpy as np
import pandas as pd
from mhkit import power, utils<jupyter_output><empty_output><jupyter_text>Load Power DataWe will begin by reading in time-series data of measured three phase (a, b, and c) voltage and current. Note: IEC TS 62600-30 requires power quality assessments on a minimum of 10 minute time-series data, but for this example a shorter time-series is used.<jupyter_code># Read in time-series data of voltage (V) and current (I)
power_data = pd.read_csv('data/power/2020224_181521_PowRaw.csv',skip_blank_lines=True,index_col='Time_UTC') 
# Convert the time index to type "datetime" 
power_data.index=pd.to_datetime(power_data.index)
# Display the data
power_data.head()<jupyter_output><empty_output><jupyter_text>Power Characteristics The `power.characteristics` submodule is used to compute quantities of interest from voltage and current time-series. In this example, we will calculate active AC power and instantneous frequency. Active AC PowerTo compute the active AC power, the user must provide a `power_factor` for the efficency of the device.<jupyter_code># First seperate the voltage and current time-series into seperate dataFrames
voltage = power_data[['MODAQ_Va_V', 'MODAQ_Vb_V', 'MODAQ_Vc_V']]
current = power_data[['MODAQ_Ia_I','MODAQ_Ib_I','MODAQ_Ic_I']]

# Set the power factor for the system
power_factor = 0.96 

# Compute the instantaneous AC power in watts
ac_power = power.characteristics.ac_power_three_phase(voltage, current, power_factor) 
# Display the result
ac_power.Power.plot(figsize=(15,5),title='AC Power').set(xlabel='Time',ylabel='Power [W]');<jupyter_output><empty_output><jupyter_text>Instantaneous FrequencyCalculate the instantaneous frequency of the voltage time-series using the 3 phase voltage measurements. The time-varying instantaneous frequency is a required metric for power quality assessments.<jupyter_code># Compute the instantaneous frequency
inst_freq = power.characteristics.instantaneous_frequency(voltage) 

# Display the result
inst_freq.plot(figsize=(15,5), ylim=(0,100),
               title='Instantaneous Frequency').set(xlabel='Time [s]',
                                                    ylabel='Frequency [Hz]');
inst_freq.head()<jupyter_output><empty_output><jupyter_text>Power QualityThe `power.quality` module can be used to compute harmonics of current. and voltage and current distortions following IEC/TS 62600-30 and IEC/TS 61000-4-7. Harmonics and harmonic distortion are required as part of a power quality assessment and characterize the stability of the produced power.<jupyter_code># Set the nominal sampling frequency
sample_freq = 50000   #[Hz]

# Set the frequency of the grid the device would be conected to
grid_freq = 60        #[Hz] 

# Set the rated current of the device
rated_current = 18.8  # [Amps]

# Calculate the harmonics
harmonics = power.quality.harmonics(current, sample_freq, grid_freq)

# Plot the results
harmonics.plot(figsize=(15,5),xlim=(0,900),
               title='Current Harmonics').set(ylabel='Harmonic Amplitude',
                                              xlabel='Frequency [Hz]');<jupyter_output><empty_output><jupyter_text>Harmonic SubgroupsThe harmonic subgroups calculations are based on IEC/TS 62600-30. We can calculate them using our grid frequency and harmonics.<jupyter_code># Calcualte Harmonic Subgroups
h_s = power.quality.harmonic_subgroups(harmonics,grid_freq) 
# Display the results
h_s.head()<jupyter_output><empty_output><jupyter_text>Total Harmonic Current DistortionCompute the THCD from harmonic subgroups and rated current for the device<jupyter_code>#Finally we can compute the total harmonic current distortion as a percentage 
THCD=power.quality.total_harmonic_current_distortion(h_s,rated_current) 
THCD<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08061790972725079, 'fraction_numerical': 0.01786145305334299, 'mean_word_length': 5.414860681114551, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '228948', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1301, 'n_tokens_neox': 1197, 'n_words': 395, 'path': 'examples/power_example.ipynb', 'repo_name': 'fleming79/MHKiT-Python', 'size': '4143'}