Skip to content

Instantly share code, notes, and snippets.

@AyrtonB
AyrtonB / eiclean.py
Created May 31, 2022 11:09
This gist loads the electric insights files found in https://github.com/AyrtonB/Electric-Insights and cleans the onshore wind data which often has missing data
import pandas as pd
from typing import Optional
def clean_onshore_s(
s_onshore: pd.Series,
delta_theshold_quantile: float = 0.96
) -> pd.Series:
s_onshore_diff = s_onshore.diff()
delta_theshold_abs_value = s_onshore_diff.abs().quantile(delta_theshold_quantile)
@AyrtonB
AyrtonB / GB_curtailment.py
Created June 3, 2021 09:35
GB Curtailment Calculator
# Imports
import os
import dotenv
import pandas as pd
import ElexonDataPortal.API as edp_API
# Helper Functions
def create_BMRS_wrapper(API_key=None, env_fp='.env'):
import pandas as pd
def dt_rng_to_SPs(start_date:datetime, end_date:datetime, freq='30T', tz='Europe/London'):
dt_rng = pd.date_range(start_date, end_date, freq=freq, tz=tz)
dt_strs = dt_rng.strftime('%Y-%m-%d')
dt_SP_counts = pd.Series(dt_strs).groupby(dt_strs).count()
SPs = []
for num_SPs in dt_SP_counts.values:
@AyrtonB
AyrtonB / mpl_date_tick_handler.py
Last active December 27, 2020 00:54
`AxTransformer` enables conversion from data coordinates to tick locations, `set_date_ticks` allows custom date ranges to be applied to plots (including a seaborn heatmap)
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from collections.abc import Iterable
from sklearn import linear_model
class AxTransformer:
def __init__(self, datetime_vals=False):
self.datetime_vals = datetime_vals
self.lr = linear_model.LinearRegression()
@AyrtonB
AyrtonB / isitdown.py
Last active May 18, 2023 16:35
Python function for checking whether a site is down or not
import re
import requests
def isitdown(domain, return_bool=True):
"""
Uses the website 'isitdownrightnow.com' to check
whether the domain provided is down or not.
Parameters