Skip to content

Instantly share code, notes, and snippets.

View gerritjandebruin's full-sized avatar

Gerrit Jan de Bruin gerritjandebruin

View GitHub Profile
@gerritjandebruin
gerritjandebruin / RIVM.ipynb
Created December 18, 2023 18:15
RIVM Luchtkwaliteitsindex kleuren
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gerritjandebruin
gerritjandebruin / import_lml_from_api.py
Created August 9, 2023 06:43
Import Landelijk Meetnetwerk Lucht (LML) data
from pathlib import Path
import requests
import pandas as pd
from tqdm import tqdm
def get_locations(base_url: str = "https://api.luchtmeetnet.nl/open_api/stations"):
"""Get all locations from the LML API.
Parameters:
-----------
from osgeo import ogr
import pandas as pd
import geopandas as gpd
def get_data(file):
ds = ogr.Open(file)
result = list()
for lyr in ds:
for feat in lyr:
@gerritjandebruin
gerritjandebruin / hide_prints.py
Created January 15, 2022 07:56
Hide any print statement
import os
import sys
class HiddenPrints:
def __enter__(self):
self._original_stdout = sys.stdout
sys.stdout = open(os.devnull, 'w')
def __exit__(self, exc_type, exc_val, exc_tb):
sys.stdout.close()
@gerritjandebruin
gerritjandebruin / send_mail.py
Created January 15, 2022 07:26
Send an e-mail on any DSlab server in LIACS.
import os, smtplib
from os.path import basename
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.utils import COMMASPACE, formatdate
def send_mail(
send_from="bruingjde@liacs.leidenuniv.nl",
send_to: list = ["gerritjan.debruin@gmail.com"],
@gerritjandebruin
gerritjandebruin / influx_drop_measurement.sh
Last active January 14, 2022 20:41
Drop measurements in Influxdb
for i in 'lightlevel' 'lumi_lumi' 'multisensor' 'rwl021' 'batterij' 'verbinding' 'herstart' 'notificatie' 'oplader' 'tradfri' 'water' 'wifi_signal' 'relais' 'on_off'
do
influx -host xxx -username homeassistant -password xxx -port 8086 --execute 'show measurements' --database=homeassistant | grep $i | xargs -I{} influx -host xxx -username homeassistant -password xxx -port 8086 --execute 'drop measurement "{}"' --database=homeassistant
done
@gerritjandebruin
gerritjandebruin / enumitem.tex
Created January 14, 2022 20:40
Usefull to make any iteration you want in Latex.
% Define research questions: https://tex.stackexchange.com/questions/525921/ideas-for-presenting-the-research-question
\usepackage{enumitem}
\newlist{questions}{enumerate}{2}
\setlist[questions,1]{wide=0pt,leftmargin=\parindent,label=RQ\arabic*.,ref=RQ\arabic*}
\setlist[questions,2]{label=(\alph*),ref=\thequestionsi(\alph*)}
% In document
\begin{questions}
\item \label{rq:events} How should event-based links, which may re-occur over time, be dealt with in order to accurately predict future links?
\item \label{rq:availability} To what extent does the availability of temporal information improve the performance of link prediction approaches?
@gerritjandebruin
gerritjandebruin / teexgraph.ipynb
Last active October 28, 2021 10:52
Teexgraph.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@gerritjandebruin
gerritjandebruin / create_html.py
Created May 12, 2021 12:27
Plot hip and plotly to a webpage
html = hip.Experiment.from_iterable(df.to_dict(orient='records')).to_html()
soup = BeautifulSoup(html, 'html.parser')
tag1 = soup.new_tag('div', attrs={'margin-left': 'auto', 'margin-right': 'auto'})
tag1.append(BeautifulSoup(fig1.to_html(include_plotlyjs='cdn', full_html=False)))
soup.body.insert(0, tag1)
tag2 = soup.new_tag('div', attrs={'margin-left': 'auto', 'margin-right': 'auto'})
tag2.append(BeautifulSoup(fig2.to_html(include_plotlyjs='cdn', full_html=False)))
soup.body.insert(1, tag2)
with open('docs/run3.html', 'w') as file:
file.write(str(soup))
import joblib
from tqdm.auto import tqdm
class ProgressParallel(joblib.Parallel):
def __init__(self, use_tqdm=True, total=None, desc=None, *args, **kwargs):
self._use_tqdm = use_tqdm
self._total = total
self._desc = desc
super().__init__(*args, **kwargs)