Created
April 15, 2014 21:50
-
-
Save ChrisBeaumont/10780037 to your computer and use it in GitHub Desktop.
spectral_cube brainstorm
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
from spectral_cube import read | |
mycube = read("ant_COline_5kms_evenbeam.fits") | |
my_cube.get_data(views, fill='min') # nan replacement fill='min'/'max' | |
my_cube.flatten(views) # flat, reject nans | |
my_cube.spectral_slab(30 * u.km / u.s, 50 * u.km / u.s) | |
my_cube[:5, :10, :10] # Not implemented, but add. Returns Cube | |
# [:5, :10, :10] -> (slice(None, 5), slice(None, 10), slice(None, 10)) | |
my_cube.subcube(center=[deg, deg, spectral_coord], size=[deg, deg, spectral_width]) #boundary handling | |
my_cube.subcube_corners(xlo, xhi, ylo, yhi, vlo, vhi) #boundary handling | |
noise = Noise(my_cube) | |
mad = noise.calculate_mad() | |
signal = my_cube > (3 * mad) # returns a functional mask, supports broadcasting | |
def island_masks(mask): | |
lbl = ndimage.label(mask.included()) | |
return lbl.find_objects() | |
masks = signal.island_masks() # long list of masks | |
my_cube.save_islands(signal, prefix='signal_', format='.fits', padding=4) # signal_0.fits, signal_1.fits... with WCS | |
# Plot the mask over the cube | |
#cube.set_mask(signal) | |
def contour_on_peak(cube, noise, signal, axis): | |
squashed = cube.max(axis=axis) # numpy array, ignore non-valid pixels | |
signal = signal.max(axis=axis) # to be implemented | |
plt.imshow(squashed, vmin=0, vmax=noise.mad() * 3) | |
plt.contour(signal > 0.5) | |
def pare_on_volume(signal): | |
ndimage.morphology stuff on a boolean mask | |
signal.included() # bools | |
#pass to scipy | |
# build new mask from a boolean array | |
return SpectralCubeMask(mask_of_bools) | |
def cprops(noise, **kwargs): | |
std = noise.snr_cube() | |
#... | |
return SpectralCubeMask() | |
# Plot the mask again | |
mymask.contour_on_peak(scale=10) | |
# Link the mask back in to the cube | |
mycube.set_signal(mymask) | |
with cube.use_mask(~signal, stack=False): | |
cube.sum() | |
cube_with_signal = cube.add_mask(signal) | |
cube.reset_mask() # punt for now |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment