Skip to content

Instantly share code, notes, and snippets.

View fzimmermann89's full-sized avatar

Felix F Zimmermann fzimmermann89

View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<title>Leaflet debug page</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-beta.2/leaflet.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-beta.2/leaflet.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="screen.css" />
@fzimmermann89
fzimmermann89 / ifi.py
Last active February 18, 2020 22:27
2d correlation
import numpy as np
#this accum class is ripped out of some of my other code, I think it should work standalone now
#or we just do it another way, we just need a mean^^
class accumulator:
'''
simple accumulator for large number of data points. allows retrieval of mean and stdev
'''
def __init__(self, like=None):
self._n = 0
@fzimmermann89
fzimmermann89 / radial_profile.py
Created February 22, 2020 03:00
radialprofile
def radial_profile(data, center=None, calcStd=False, os=1):
'''
calculates a radial profile of ND data around center. will ignore nans
calStd: calculate standard deviation, return tuple of (profile, std)
os: oversample by a factor. With default 1 the stepsize will be 1 pixel, with 2 it will be .5 pixels etc.
'''
if center is None:
center = np.array(data.shape)//2
if len(center) != data.ndim:
raise TypeError('center should be of length data.ndim')
###### SETTINGS ######
url= '"
username = ""
password = ""
team_name = ""
channel_name = ""
#######################
import os
import requests
from __future__ import print_function
import threading
from joblib import Parallel, delayed
import Queue
import os
# Fix print
_print = print
_rlock = threading.RLock()
def print(*args, **kwargs):
@fzimmermann89
fzimmermann89 / simplecorrelator.ipynb
Last active July 28, 2021 14:06
simplecorrelator
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fzimmermann89
fzimmermann89 / utilities_lv65.py
Last active July 28, 2021 16:54
utilities_lv65
import numpy as np
### Requested pixel2q and q2pixel ####
def pixel2q(pixel, E_ev, detz_m, pixelsize_m=75e-6):
"""
returns q in reciprocal nm
E_ev: photon Energy in eV
detz_m: detector distance in m
pixelsize_m: detector pixelsize in m
@fzimmermann89
fzimmermann89 / lut.py
Last active September 7, 2021 09:47
lut
import torch
from torch import nn
from typing import Tuple, Callable
class LUT(nn.Module):
def __init__(self, f: Callable, dx: float, xrange: Tuple[float, float], mode: str = "linear"):
"""
LUT of values of a function
f: function to use, does not need to be differentiable
@fzimmermann89
fzimmermann89 / mri_demo.ipynb
Last active November 14, 2022 09:36
MRI Demo for M4AIM Presentation @ PTB Berlin. (c) Felix Zimmermann, MIT License
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@fzimmermann89
fzimmermann89 / sliding_window.py
Created January 8, 2024 09:45
pytorch sliding window
import warnings
from typing import Sequence
import torch
import numpy as np
# fzimmermann89, felix.zimmermann@ptb.de, 2024
def sliding_window(x:torch.Tensor, window_shape:int|Sequence[int], axis:None|int|Sequence[int]|=None):
"""Sliding window into the tensor x.
Returns a view into the tensor x that represents a sliding window.