Skip to content

Instantly share code, notes, and snippets.

View janpipek's full-sized avatar
🤔
...

Jan Pipek janpipek

🤔
...
View GitHub Profile
@janpipek
janpipek / input-storage.js
Created June 19, 2013 09:56
Auto-store state of input elements in localStorage (jQuery)
/**
* Simple jQuery utility for saving element values in localStorage.
*
* Usage:
* - Add class "store-state" to the element you want to save.
* - Add id attribute to the element or specify your own storage key (attribute data-storage-name)
* - Add attribute "data-storage-name" to the element if you
* want to control under which name the value will be stored
* - Add attribute "data-storage-noload" to suppress loading (will be stored though, it is
* useful, when HTML-specified value is temporarily more important).
@janpipek
janpipek / export.py
Created August 21, 2014 19:35
Export pixel array from DICOM file to HDF5
import dicom
import h5py
def export_pixel_array(in_file, out_file, dataset_name="data"):
pixel_array = dicom.read_file(in_file).pixel_array
h5 = h5py.File(out_file)
h5.create_dataset(dataset_name, data=pixel_array)
h5.close()
@janpipek
janpipek / normalize_series.py
Created August 16, 2022 16:59
Normalize series
import numbers
from typing import Literal, Optional, Union
import numpy as np
import pandas as pd
def normalize_series(
series: pd.Series,
*,
@janpipek
janpipek / gamma.py
Created September 25, 2014 17:41
Calculation of gamma index on two matrices of the same shape (full and optimized version)
import numpy as np
def gamma_matrix(rm, tm, dta=1.0, dd=0.05):
'''Compute matrix of gammma indices.
:param rm: reference matrix (relative values assumed)
:param tm: tested matrix (relative values assumed)
:param dta: maximum distance-to-agreement (in voxels)
:param dd: maximum dose difference
@janpipek
janpipek / recompress_hdf5.py
Last active June 16, 2021 06:13
Create a copy of HDF5 with compressed everything that could be compressed.
import h5py
import os
def _report(operation, key, obj):
type_str = type(obj).__name__.split(".")[-1].lower()
print "%s %s: %s." % (operation, type_str, key)
def h5py_compatible_attributes(in_object):
'''Are all attributes of an object readable in h5py?'''
try:
@janpipek
janpipek / create_bookshelf.py
Last active January 21, 2021 13:46
Home bookshelf design
import matplotlib.pyplot as plt
import numpy as np
from draw import *
from data import *
fig, ax = plt.subplots(figsize=(20, 12))
nonwallcolor = "#c0c0c0"
@janpipek
janpipek / ukol_1.py
Last active October 22, 2020 09:35
opakovaci_ukoly
# 1. Spočítejte a nakreslete graf, jak se v průběhu let vyvíjel
# celkový počet udělených medailí (zvlášť pro zimní a letní hry).
import pandas as pd
import seaborn as sns
%matplotlib inline
olympics = pd.read_csv("athlete_events.csv")
@janpipek
janpipek / plot_world_covid.py
Created March 11, 2020 18:45
Plot simple map with Prague and
from bokeh.plotting import figure, show, output_notebook
from bokeh.models import HoverTool
from bokeh.tile_providers import Vendors, get_provider
import pandas as pd
def web_mercator(long, lat):
import numpy as np
scale_x = 4e7 / 360
limit_lat = 2 * np.arctan(np.exp(np.pi)) - np.pi / 2
@janpipek
janpipek / gleamviz_data.py
Last active March 11, 2020 17:05
Gleamviz data reader
import os
from typing import List, Optional
import pandas
class DataReader:
def __init__(self, root_path: str):
self.root_path = root_path
@janpipek
janpipek / private_members.py
Created January 30, 2020 07:10
Private members in Python
class Jablko:
def __init__(self):
self.__bar = 123
@staticmethod
def show_me(o):
print(o.__bar)
class IgnorePrivateMembers:
def __getattr__(self, name: str):