This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %reload_ext autoreload | |
| %autoreload 1 | |
| %matplotlib inline | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| # Modules imported by devpkg must also be listed here to get the same treatment. | |
| %aimport devpkg | |
| %aimport devpkg.util |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # See https://stackoverflow.com/questions/6910641/how-do-i-get-indices-of-n-maximum-values-in-a-numpy-array | |
| # argpartition requires numpy >= 1.8.0 | |
| # See also http://seanlaw.github.io/2020/01/03/finding-top-or-bottom-k-in-a-numpy-array/ | |
| def argkmax1(a, k, axis=-1): | |
| """Return the indices of the k largest elements of a. | |
| With k=1, this is identical to argmax except that it | |
| returns an array of length 1 instead of a scalar. | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| Save this file to scripts/myprog.py then add these lines to setup.py: | |
| entry_points = { | |
| 'console_scripts': [ | |
| 'myprog=fpoffline.scripts.myprog:main', | |
| ], | |
| } | |
| ''' | |
| import argparse |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def downsample(data, downsampling, summary=np.sum, allow_trim=False): | |
| """Downsample a 2D array. | |
| Parameters | |
| ---------- | |
| data : array | |
| Two dimensional array of values to downsample. | |
| downsampling : int | |
| Downsampling factor to use along both dimensions. Must evenly divide the | |
| data dimensions when allow_trim is False. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Given ellipticity parameters (e1, e2) and size s = det(Q)**(1/4) | |
| # https://github.com/dkirkby/desietcimg/blob/master/desietcimg/plot.py | |
| def draw_ellipse_se1e2(ax, x0, y0, s, g1, g2, nsigmas=1, **ellipseopts): | |
| g = np.sqrt(g1 ** 2 + g2 ** 2) | |
| if g > 1: | |
| raise ValueError('g1 ** 2 + g2 ** 2 > 1') | |
| center = np.array([x0, y0]) | |
| angle = np.rad2deg(0.5 * np.arctan2(g2, g1)) | |
| ratio = np.sqrt((1 + g) / (1 - g)) | |
| width = 2 * s * ratio * nsigmas |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://stackoverflow.com/a/37977222/4726728 | |
| # Requires numpy >= 1.7 | |
| c = np.divide(a, b, out=np.zeros_like(a), where=b!=0) | |
| # Another method that maps all inexact values with finite ones. | |
| # Unlike the method above, this also works inside @jax.jit | |
| c = np.nan_to_num(a / b, posinf=0., neginf=0.) |
NewerOlder