def find_mask_for_hdu(hdu, threshold=0.001, v1=-100.0, v2=100.0): mask = hdu.data < threshold # Cut out a window around line center w = WCS(hdu.header, key='A') waves = vels2waves([v1, v2], w.wcs.restwav, hdu.header) [i1, i2], _, _ = w.all_world2pix(waves, [0, 0], [0, 0], 0) i1, i2 = int(i1), int(i2) + 1 mask[:, :, i1:i2] = False return mask
# Eliminate degenerate 3rd dimension from data array and trim off bad bits spec2d = spechdu.data[0] # Rest wavelength from FITS header is in meters wavrest = wspec.wcs.restwav*u.m # Find wavelength limits for line extraction window if vrange is None: # Original case: use a window of wavelength full width dwline waves = wavrest + np.array([-0.5, 0.5])*dwline else: # Extract velocity limits from the vrange command line argument # vrange should be of a form like '-100+100' or '+020+030' v1, v2 = float(vrange[:4]), float(vrange[-4:]) print('Velocity window:', v1, 'to', v2) waves = vels2waves([v1, v2], wavrest, spechdu.header) print('Wavelength window: {:.2f} to {:.2f}'.format(*waves.to(u.Angstrom))) # Find pixel indices for line extraction window i1, i2 = waves2pixels(waves, wspec) print('Pixel window:', i1, 'to', i2) # Extract profile for this wavelength or velocity window profile = spec2d[:, i1:i2:sgn].sum(axis=-1) # Find celestial coordinates for each pixel along the slit NS = len(profile) slit_coords = pixel_to_skycoord(range(NS), [0]*NS, wspec, 0) # Trim off bad parts of slit profile = profile[goodslice]
# Eliminate degenerate 3rd dimension from data array and trim off bad bits spec2d = spechdu.data[0] # Rest wavelength from FITS header is in meters wavrest = wspec.wcs.restwav * u.m # Find wavelength limits for line extraction window if vrange is None: # Original case: use a window of wavelength full width dwline waves = wavrest + np.array([-0.5, 0.5]) * dwline else: # Extract velocity limits from the vrange command line argument # vrange should be of a form like '-100+100' or '+020+030' v1, v2 = float(vrange[:4]), float(vrange[-4:]) print('Velocity window:', v1, 'to', v2) waves = vels2waves([v1, v2], wavrest, spechdu.header) print('Wavelength window: {:.2f} to {:.2f}'.format(*waves.to(u.Angstrom))) # Find pixel indices for line extraction window i1, i2 = waves2pixels(waves, wspec) print('Pixel window:', i1, 'to', i2) # Extract profile for this wavelength or velocity window profile = spec2d[:, i1:i2:sgn].sum(axis=-1) # Find celestial coordinates for each pixel along the slit NS = len(profile) slit_coords = pixel_to_skycoord(range(NS), [0] * NS, wspec, 0) # Trim off bad parts of slit profile = profile[goodslice]