Skip to content

Instantly share code, notes, and snippets.

@Gdahuks
Gdahuks / transition_matrix.py
Created January 27, 2024 19:22
Calculates the transition matrix from a given 1D numpy array.
import numpy as np
def get_valid_indices(series: np.ndarray) -> (np.ndarray, np.ndarray):
"""
Get valid indices from a series.
This function gets valid indices from a given series. The valid indices are those where the series
value and successor value are not NaN. The function returns two arrays:
the valid indices and the valid indices shifted by one to calculate the transition matrix.
@Gdahuks
Gdahuks / calculate_stationary_state.py
Created January 27, 2024 19:59
Calculates the stationary state for the given transition matrix by solving an eigenproblem.
import numpy as np
import scipy
def calculate_stationary_state(transition_matrix: np.ndarray) -> np.ndarray:
"""
Calculate the stationary state of a transition matrix.
This function calculates the stationary state of a given transition matrix. The stationary state is the
state that the system will converge to over time. It is calculated by finding the eigenvector of the
@Gdahuks
Gdahuks / meto.zsh
Created March 2, 2024 19:01
Download meteorological data archive from https://danepubliczne.imgw.pl/datastore (default Air temperature)
# Download meteorological data archive from https://danepubliczne.imgw.pl/datastore
# Code Name
# B00300S Air temperature (official)
# B00305A Ground temperature (sensor)
# B00202A Wind direction (sensor)
# B00702A Average wind speed 10 minutes (sensor)
# B00703A Maximum wind speed (sensor)
# B00608S Precipitation sum 10 minutes
# B00604S Daily precipitation sum
# B00606S Hourly precipitation sum
# This script reformats multiple CSV files containing environmental data
# (see https://gist.github.com/Gdahuks/ae97bebaaff937189a235f9dfecb41e1)
# into a single Parquet table with the date and time as index and the station IDs as columns.
# Input: B00300S_2012_01.csv, B00300S_2012_01.csv, ..., B00300S_2022_12.csv
# 249190890;B00300S;2012-01-01 00:00;-2,9;
# 249190890;B00300S;2012-01-01 00:10;-2,8;
# 249190890;B00300S;2012-01-01 00:20;-2,9;
# 249190890;B00300S;2012-01-01 00:30;-3,3;
# ...