-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0259709
Showing
3,795 changed files
with
723,824 additions
and
0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Sphinx build info version 1 | ||
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. | ||
config: 6b9bc7419996ce8c286367192c70b090 | ||
tags: 645f666f9bcd5a90fca523b33c5a78b7 |
Empty file.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+839 KB
_downloads/0624ebe9afe9f51c4ef42a73e1b6f632/kernel_resampler-1.hires.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
import imageio | ||
from sofia_redux.toolkit.image.fill import maskinterp | ||
|
||
image = imageio.imread('imageio:camera.png').astype(float) | ||
image /= image.max() | ||
original = image.copy() | ||
rand = np.random.RandomState(41) | ||
badpix = rand.rand(100, 100) > 0.5 | ||
cut = image[75:175, 180:280] | ||
cut[badpix] = np.nan | ||
|
||
result = maskinterp(image, kx=2, ky=2, minpoints=9) | ||
fig, ax = plt.subplots(nrows=1, ncols=3, figsize=(15, 5)) | ||
c = 'copper' | ||
ax[0].imshow(original, cmap=c) | ||
ax[0].set_title("Original Image") | ||
ax[1].imshow(image, cmap=c) | ||
ax[1].set_title("Holey Image") | ||
ax[2].imshow(result, cmap=c) | ||
ax[2].set_title("Corrected Image (maskinterp)") | ||
for a in ax: | ||
a.set_xlim(165, 295) | ||
a.set_ylim(190, 60) |
46 changes: 46 additions & 0 deletions
46
_downloads/119e1df0b4e0c8a4e37b67d4e3975d83/fitpeaks1d-3.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
from astropy.modeling import models, fitting | ||
from sofia_redux.toolkit.fitting.fitpeaks1d import (medabs_baseline, get_search_model, | ||
guess_xy_mad, dofit, get_fitter) | ||
|
||
x = np.linspace(0, 10, 1001) | ||
model1 = models.Gaussian1D(amplitude=3, mean=5, stddev=0.5) | ||
model2 = models.Gaussian1D(amplitude=4, mean=4, stddev=0.2) | ||
y = model1(x) + model2(x) + 0.05 * x + 100 | ||
rand = np.random.RandomState(42) | ||
y += rand.normal(0, 0.01, y.size) | ||
|
||
peak_model = models.Gaussian1D | ||
fitter = get_fitter(fitting.LevMarLSQFitter) | ||
model_box = get_search_model( | ||
peak_model, models.Box1D, box_width=('stddev', 3)) | ||
model_nobox = get_search_model(peak_model, None) | ||
|
||
y_prime, baseline = medabs_baseline(x, y) | ||
x_peak, y_peak = guess_xy_mad(x, y_prime) | ||
tmp = model_box.parameters | ||
tmp[0:3] = y_peak, x_peak, 0.1 | ||
model_box.parameters = tmp | ||
tmp = model_nobox.parameters | ||
tmp[0:3] = y_peak, x_peak, 0.1 | ||
model_nobox.parameters = tmp | ||
|
||
x_peak, y_peak = guess_xy_mad(x, y_prime) | ||
fit_box = dofit(fitter, model_box, x, y_prime) | ||
fit_nobox = dofit(fitter, model_nobox, x, y_prime) | ||
|
||
fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(10, 5)) | ||
ax[0].plot(x, y_prime) | ||
ax[0].plot(x, fit_box(x)) | ||
ax[0].set_title("Fit with box function") | ||
ax[0].set_xlabel("x") | ||
ax[0].set_ylabel("$y^{\prime}$") | ||
ax[0].set_xlim(3, 6) | ||
|
||
ax[1].plot(x, y_prime) | ||
ax[1].plot(x, fit_nobox(x)) | ||
ax[1].set_title("Fit without box function") | ||
ax[1].set_xlabel("x") | ||
ax[1].set_ylabel("$y^{\prime}$") | ||
ax[1].set_xlim(3, 6) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
from sofia_redux.toolkit.image.smooth import bicubic_evaluate | ||
|
||
z_corners = np.array([0.0, 1.0, 2.0, 1.0]) # values at corners | ||
dx = np.full(4, 1.0) # x-gradients at corners | ||
dy = dx.copy() # y-gradients at corners | ||
dxy = np.zeros(4) # not present here | ||
xrange = [0, 1] | ||
yrange = [0, 1] | ||
|
||
x, y = np.meshgrid(np.linspace(0, 1, 100), np.linspace(0, 1, 100)) | ||
z_new = bicubic_evaluate(z_corners, dx, dy, dxy, xrange, yrange, x, y) | ||
plt.imshow(z_new, origin='lower', cmap='gray', extent=[0, 1, 0, 1]) | ||
plt.colorbar() | ||
plt.title("Bicubic Interpolation") | ||
plt.xlabel("x") | ||
plt.ylabel("y") |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+295 KB
_downloads/1d8ca355fcb4f7165b280b13f02123d0/spline_examples-1.hires.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
25 changes: 25 additions & 0 deletions
25
_downloads/1dd55efaf062425d80b79046c46896d0/fitpeaks1d-7.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
from astropy.modeling import models, fitting | ||
from sofia_redux.toolkit.fitting.fitpeaks1d import fitpeaks1d | ||
|
||
# Create some fake data with noise | ||
x = np.linspace(0, 10, 1001) | ||
model1 = models.Gaussian1D(amplitude=3, mean=5, stddev=0.5) | ||
model2 = models.Gaussian1D(amplitude=4, mean=4, stddev=0.2) | ||
y = model1(x) + model2(x) + 0.05 * x + 100 | ||
rand = np.random.RandomState(42) | ||
y += rand.normal(0, 0.01, y.size) | ||
|
||
model = fitpeaks1d(x, y, npeaks=2, background_class=models.Linear1D, | ||
box_width=('stddev', 3), | ||
search_kwargs={'stddev_0': 0.1}) | ||
|
||
fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(10, 5)) | ||
ax[0].plot(x, y - model[2](x)) | ||
ax[0].set_title('Baseline Subtracted Data') | ||
ax[1].plot(x, y, label='Data', color='blue') | ||
ax[1].plot(x, (model[1] + model[2])(x), '--', | ||
label='baseline + 2nd peak', color='red') | ||
ax[1].set_title("Adding Model Components") | ||
ax[1].legend() |
39 changes: 39 additions & 0 deletions
39
_downloads/1e6757115d5230df3927bea687e99a7b/scan_usage-1.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from sofia_redux.scan.reduction.reduction import Reduction | ||
|
||
from astropy import units | ||
from astropy.io import fits | ||
from astropy.wcs import WCS | ||
import matplotlib.pyplot as plt | ||
from astropy.visualization import astropy_mpl_style | ||
import os | ||
import tempfile | ||
|
||
plt.style.use(astropy_mpl_style) | ||
|
||
work_path = tempfile.mkdtemp(suffix='scan_example') | ||
filename = os.path.join(work_path, 'simulated_data.fits') | ||
|
||
# Initialize the reduction for the example instrument | ||
reduction = Reduction('example') | ||
|
||
# Create a simulated data file | ||
reduction.info.write_simulated_hdul( | ||
filename, fwhm=10 * units.arcsec, scan_type='daisy', | ||
n_oscillations=22, radial_period=12 * units.second, | ||
ra='17h45m39.60213s', dec='-29d00m22.0000s', | ||
source_type='single_gaussian', constant_speed=True, | ||
s2n=30.0) | ||
|
||
# Perform the reduction | ||
hdul = reduction.run(filename, outpath=work_path, | ||
blacklist='correlated.bias') | ||
|
||
# Display the results | ||
# The contents of the output FITS file and the hdul above are identical. | ||
output_file = os.path.join(work_path, 'Simulation.Simulation.1.fits') | ||
image_data = fits.getdata(output_file, ext=0) | ||
wcs = WCS(fits.getheader(output_file, ext=0)) | ||
plt.subplot(projection=wcs) | ||
plt.imshow(image_data, origin='lower') | ||
plt.xlabel('Right Ascension') | ||
plt.ylabel('Declination') |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions
33
_downloads/1f8317e2dd0cb20f2c92d8b6105d5ba3/kernel_resampler-2.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
from sofia_redux.toolkit.resampling.resample_kernel import ResampleKernel | ||
|
||
# Create an irregular kernel | ||
rand = np.random.RandomState(2) | ||
width = 4 | ||
x_range = 30 | ||
n_impulse = 10 | ||
n_kernel = 1000 | ||
n_samples = 1000 | ||
|
||
x = width * (rand.random(n_kernel) - 0.5) | ||
kernel = np.sinc(x * 4) * np.exp(-(x ** 2)) | ||
|
||
# Add random impulses | ||
impulse_locations = rand.random(n_samples) * x_range | ||
impulses = np.zeros(n_samples) | ||
impulses[:n_impulse] = 1 - 0.5 * rand.random(n_impulse) | ||
|
||
resampler = ResampleKernel(impulse_locations, impulses, kernel, | ||
kernel_offsets=x[None], smoothing=1e-6) | ||
|
||
x_out = np.linspace(0, x_range, 500) | ||
fit = resampler(x_out, normalize=False) | ||
|
||
plt.plot(x_out, fit, label='fit') | ||
plt.vlines(impulse_locations[:n_impulse], 0, impulses[:n_impulse], | ||
linestyles='dashed', colors='r', linewidth=1) | ||
plt.plot(impulse_locations[:n_impulse], impulses[:n_impulse], 'x', | ||
color='r', label='impulses') | ||
plt.legend() | ||
plt.title('A set of impulse signals convolved with an irregular kernel.') |
35 changes: 35 additions & 0 deletions
35
_downloads/2200aa5dd268b6e1f5dd2adb225acb91/fitpeaks1d-9.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
import imageio | ||
from sofia_redux.toolkit.fitting.fitpeaks1d import fitpeaks1d | ||
|
||
image = imageio.imread('imageio:hubble_deep_field.png') | ||
y = image[400].sum(axis=1).astype(float) | ||
x = np.arange(y.size) | ||
model = fitpeaks1d(x, y, npeaks=10) | ||
|
||
fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(15, 5)) | ||
ax[0].plot(x, y) | ||
background = model[-1].amplitude | ||
|
||
for i in range(10): | ||
px, py = model[i].mean.value, model[i].amplitude.value + background | ||
ax[0].plot(px, py, 'x', | ||
markersize=10, color='red') | ||
ax[0].annotate(str(i + 1), (px - 40, py)) | ||
|
||
ax[0].legend(['Data', 'Fitted peak'], loc='upper right') | ||
ax[0].set_title("Default Settings and Identification Order") | ||
ax[0].set_xlabel('x') | ||
ax[0].set_ylabel('y') | ||
|
||
ax[1].plot(x, y, label='Data', color='blue') | ||
ax[1].plot(x, model[0](x) + background, '-.', label='Gaussian Fit', | ||
color='green') | ||
ax[1].plot(x, model(x), '--', label='Composite Fit', | ||
color='red') | ||
ax[1].set_xlim(90, 160) | ||
ax[1].legend(loc='upper right') | ||
ax[1].set_title("Peak 1: Simple and Composite Fit") | ||
ax[1].set_xlabel('x') | ||
ax[1].set_ylabel('y') |
Binary file not shown.
56 changes: 56 additions & 0 deletions
56
_downloads/234701149f2bc46cd2cac42fd6857459/kernel_resampler-1.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
import imageio | ||
from sofia_redux.toolkit.resampling.resample_kernel import ResampleKernel | ||
|
||
def mexican_hat(x, y, period=1): | ||
r = np.sqrt(x ** 2 + y ** 2 + np.finfo(float).eps) | ||
rs = r * 2 * np.pi / period | ||
result = np.sin(rs) / rs | ||
return result | ||
|
||
# Create a set of random kernel coordinates and values | ||
rand = np.random.RandomState(0) | ||
width = 6 | ||
w2 = width / 2 | ||
|
||
kx = width * (rand.random(1000) - 0.5) | ||
ky = width * (rand.random(1000) - 0.5) | ||
kernel = mexican_hat(kx, ky, period=w2) | ||
kernel_offsets = np.stack([kx, ky]) | ||
|
||
# First create a representation of the kernel on a grid by convolving | ||
# with a delta function. | ||
xx, yy = np.meshgrid(np.linspace(-w2, w2, 101), np.linspace(-w2, w2, 101)) | ||
cc = np.stack([xx.ravel(), yy.ravel()]) | ||
delta = np.zeros_like(xx) | ||
delta[50, 50] = 1 | ||
|
||
resampler = ResampleKernel(cc, delta.ravel(), kernel, degrees=3, | ||
smoothing=1e-5, kernel_offsets=kernel_offsets) | ||
|
||
regular_kernel = resampler(cc, jobs=-1, normalize=False).reshape( | ||
delta.shape) | ||
|
||
# Now show an example of edge detection using the irregular kernel | ||
image = imageio.imread('imageio:camera.png').astype(float) | ||
image -= image.min() | ||
image /= image.max() | ||
|
||
ny, nx = image.shape | ||
iy, ix = np.mgrid[:ny, :nx] | ||
coordinates = np.stack([ix.ravel(), iy.ravel()]) | ||
data = image.ravel() | ||
|
||
resampler = ResampleKernel(coordinates, data, kernel, degrees=3, | ||
smoothing=1e-3, kernel_offsets=kernel_offsets) | ||
edges = abs(resampler(coordinates, jobs=-1, normalize=False)).reshape( | ||
image.shape) | ||
|
||
fig, ((ax1, ax2, ax3)) = plt.subplots(1, 3, figsize=(15, 5)) | ||
ax1.imshow(image, cmap='gray') | ||
ax1.set_title('Original image') | ||
ax2.imshow(regular_kernel, interpolation='none', extent=[-w2, w2, -w2, w2]) | ||
ax2.set_title('Interpolated regular kernel') | ||
ax3.imshow(edges, cmap='gray') | ||
ax3.set_title('Irregular kernel convolved with image') |
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import matplotlib.pyplot as plt | ||
import imageio | ||
from sofia_redux.toolkit.convolve.filter import sobel | ||
|
||
image = imageio.imread('imageio:page.png') | ||
fig, ax = plt.subplots(nrows=2, ncols=2, figsize=(10, 6)) | ||
ax[0, 0].imshow(image, cmap='gray') | ||
ax[0, 0].set_title("Image") | ||
ax[0, 1].imshow(sobel(image), cmap='gray_r') | ||
ax[0, 1].set_title("Sobel-Feldman filter p-norm=1") | ||
ax[1, 0].imshow(sobel(image, pnorm=2), cmap='gray_r') | ||
ax[1, 0].set_title("Sobel-Feldman filter p-norm=2") | ||
ax[1, 1].imshow(sobel(image, pnorm=2, kperp=(3, 10, 3)), cmap='gray_r') | ||
ax[1, 1].set_title("Scharr filter p-norm=2") | ||
fig.tight_layout() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
import imageio | ||
from sofia_redux.toolkit.image.fill import maskinterp | ||
|
||
image = imageio.imread('imageio:camera.png').astype(float) | ||
image /= image.max() | ||
original = image.copy() | ||
rand = np.random.RandomState(41) | ||
badpix = rand.rand(100, 100) > 0.5 | ||
cut = image[75:175, 180:280] | ||
cut[badpix] = np.nan | ||
|
||
median_filled = maskinterp(image, func=np.median, statistical=True) | ||
plt.figure(figsize=(5, 5)) | ||
plt.imshow(median_filled[60:190, 165:295], cmap='copper') | ||
plt.title("Maskinterp with user defined median function") |
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from sofia_redux.toolkit.image.fill import polyfillaa | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
px = [[0, 0, 2, 2], [4, 2, 8], [10, 10, 12, 12]] | ||
py = [[0, 2, 2, 0], [2, 9, 5], [4, 5, 5, 4]] | ||
|
||
# Add a pentagon | ||
def mypoly(x, y, r, n): | ||
ang = (np.arange(n) + 1) * 2 * np.pi / n | ||
return list(r * np.cos(ang) + x), list(r * np.sin(ang) + y) | ||
|
||
hx, hy = mypoly(10.5, 10.5, 3, 5) | ||
px.append(hx) | ||
py.append(hy) | ||
|
||
result, areas = polyfillaa(px, py, area=True) | ||
|
||
grid = np.full((15, 15), np.nan) | ||
for i in range(len(result.keys())): | ||
grid[result[i][:,0], result[i][:,1]] = areas[i] | ||
|
||
fig, ax = plt.subplots(figsize=(7, 5)) | ||
ax.set_xticks(np.arange(-0.5, 15, 1)) | ||
ax.set_yticks(np.arange(-0.5, 15, 1)) | ||
ax.set_xticklabels(np.arange(16)) | ||
ax.set_yticklabels(np.arange(16)) | ||
|
||
ax.grid(which='major', axis='both', linestyle='--', | ||
color='k', linewidth=1) | ||
img = ax.imshow(grid, cmap='cividis', origin='lower') | ||
|
||
for i in range(len(px)): | ||
x = px[i] + [px[i][0]] | ||
y = py[i] + [py[i][0]] | ||
ax.plot(np.array(x) - 0.5, np.array(y) - 0.5, | ||
'-o', color='red', linewidth=3, markersize=7) | ||
|
||
fig.colorbar(img, ax=ax) | ||
ax.set_title("Multiple polygons and fractional area") |
Binary file not shown.
Oops, something went wrong.