Skip to content

Instantly share code, notes, and snippets.

View xigrug's full-sized avatar

liuc xigrug

  • Beijing
View GitHub Profile
@jthielen
jthielen / wrf_python_extraction.py
Created May 3, 2019 18:44
Use wrf-python, xarray, and pyproj to post-process WRF output
from wrf import getvar
from netCDF4 import Dataset
import xarray as xr
import pyproj
# Extract the variables of interest at time index 17
ds = Dataset('../wrfout_d02_2015-07-12_1200.nc')
variables = [getvar(ds, var, 17) for var in ('z', 'dbz', 'pressure', 'ter', 'ua',
'va', 'wa', 'temp', 'rh')]
data = xr.merge(variables)
@dkapitan
dkapitan / seabornfig2grid.py
Created July 26, 2018 09:50
Multiple Seaborn plots in a grid
# https://stackoverflow.com/questions/35042255/how-to-plot-multiple-seaborn-jointplot-in-subplot
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import seaborn as sns
import numpy as np
class SeabornFig2Grid():
@lucainnocenti
lucainnocenti / bibitem-sorter.py
Last active December 13, 2023 06:17
Python script to sort the bibitem entries according to the citation order in the text. Useful when one has for some reason to not use bibtex and .bib files. Usage is as `python bibitem-sorter.py file.tex sorted_file.tex`
import argparse
import os
import sys
import re
def printBold(msg):
HEADER = '\033[95m'
BOLD = '\033[1m'
print(HEADER + BOLD + msg + '\x1b[0m')
@bshishov
bshishov / forecasting_metrics.py
Last active April 20, 2024 04:29
Python Numpy functions for most common forecasting metrics
import numpy as np
EPSILON = 1e-10
def _error(actual: np.ndarray, predicted: np.ndarray):
""" Simple error """
return actual - predicted
We couldn’t find that file to show.
@ruxi
ruxi / jointplot_w_hue.py
Last active March 13, 2021 23:39
jointplot_w_hue
__author__ = "lewis.r.liu@gmail.com"
__copyright__ = "Copyright 2020, 2018, https://gist.github.com/ruxi/ff0e9255d74a3c187667627214e1f5fa"
__license__ = "MIT"
__version__ = "0.0.2"
# update: June 13, 2020
# created: Feb 19, 2018
# desc: seaborn jointplot with 'hue'
# prepared for issue: https://github.com/mwaskom/seaborn/issues/365
# resolved (22 Aug 2020): https://github.com/mwaskom/seaborn/pull/2210
@mandli
mandli / rel_err_formula.py
Created September 10, 2017 22:14
Python script to compare two formulas for relative error.
# Based on the code by Nick Higham
# https://gist.github.com/higham/6f2ce1cdde0aae83697bca8577d22a6e
# Compares relative error formulations using single precision and compared to double precision
N = 501 # Note: Use 501 instead of 500 to avoid the zero value
d = numpy.finfo(numpy.float32).eps * 1e4
a = 3.0
x = a * numpy.ones(N, dtype=numpy.float32)
y = [x[i] + numpy.multiply((i - numpy.divide(N, 2.0, dtype=numpy.float32)), d, dtype=numpy.float32) for i in range(N)]
@ptantiku
ptantiku / install_texlive.sh
Created November 2, 2016 06:40
Install TexLive and TexStudio on Redhat 7.2
#!/bin/bash
yum -y install texlive texlive-latex texlive-xetex
yum -y install texlive-collection-latex
yum -y install texlive-collection-latexrecommended
yum -y install texlive-xetex-def
yum -y install texlive-collection-xetex
#Optional
#yum -y install texlive-collection-latexextra
yum -y install texlive-xltxtra
@shoyer
shoyer / xarray-tutorial-cleared.ipynb
Last active November 25, 2023 03:59
Xarray tutorial for Rossbypalooza
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.