def load_co21_IRAM(): co21 = fits.open("/media/eric/Data_3/M33/co21/m33.ico.fits")[0] new_wcs = drop_axis(drop_axis(WCS(co21.header), 3), 2) co21_proj = Projection(co21.data.squeeze(), unit=u.K, wcs=new_wcs) return co21, co21_proj
def get_prop_hdrs(self): ''' Generate headers for the moments. ''' bunits = [self.cube.unit, self.cube.spectral_axis.unit, self.cube.spectral_axis.unit, self.cube.unit * self.cube.spectral_axis.unit] comments = ["Image of the Zeroth Moment", "Image of the First Moment", "Image of the Second Moment", "Image of the Integrated Intensity"] self.prop_headers = [] self.prop_err_headers = [] for i in range(len(bunits)): wcs = self.cube.wcs.copy() new_wcs = drop_axis(wcs, -1) hdr = new_wcs.to_header() hdr_err = new_wcs.to_header() hdr["BUNIT"] = bunits[i].to_string() hdr_err["BUNIT"] = bunits[i].to_string() hdr["COMMENT"] = comments[i] hdr_err["COMMENT"] = comments[i] + " Error." self.prop_headers.append(hdr) self.prop_err_headers.append(hdr_err)
def moment1_error(cube, scale, axis=0, how='auto', moment0=None, moment1=None): ''' Compute the first moment error. Parameters ---------- cube : SpectralCube Data cube. scale : SpectralCube or `~astropy.units.Quantity` The noise level in the data, either as a single value (with the same units as the cube) or a SpectralCube of noise values. axis : int Axis to compute moment over. how : {'auto', 'cube', 'slice'}, optional The computational method to use. Returns ------- moment1_err : `~spectral_cube.lower_dimensional_structures.Projection` ''' if how == "auto": how = iterator_strategy(cube, 0) if how == "ray": warn("Automatically selected 'ray' which isn't implemented. Using" " 'slice' instead.") how = 'slice' # Compute moments if they aren't given. if moment0 is None: moment0 = cube.moment0(how=how, axis=axis) if moment1 is None: moment1 = cube.moment1(how=how, axis=axis) # Remove velocity offset from centroid to match cube._pix_cen # Requires converting to a Quantity moment1 = u.Quantity(moment1) moment1 -= cube.spectral_axis[0] if how == "cube": moment1_err = _cube1(cube, axis, scale, moment0, moment1) elif how == "slice": moment1_err = _slice1(cube, axis, scale, moment0, moment1) else: raise ValueError("how must be 'cube' or 'slice'.") meta = {'moment_order': 1, 'moment_axis': axis, 'moment_method': how} cube_meta = cube.meta.copy() meta.update(cube_meta) new_wcs = drop_axis(cube._wcs, np2wcs[axis]) return Projection(moment1_err, copy=False, wcs=new_wcs, meta=meta, header=cube._nowcs_header)
def moment0_error(cube, scale, axis=0, how='auto'): ''' Compute the zeroth moment error. Parameters ---------- cube : SpectralCube Data cube. scale : SpectralCube or `~astropy.units.Quantity` The noise level in the data, either as a single value (with the same units as the cube) or a SpectralCube of noise values. axis : int Axis to compute moment over. how : {'auto', 'cube', 'slice'}, optional The computational method to use. Returns ------- moment0 : `~spectral_cube.lower_dimensional_structures.Projection` ''' if how == "auto": how = iterator_strategy(cube, 0) if how == "ray": warn("Automatically selected 'ray' which isn't implemented. Using" " 'slice' instead.") how = 'slice' if how == "cube": moment0_err = _cube0(cube, axis, scale) elif how == "slice": moment0_err = _slice0(cube, axis, scale) else: raise ValueError("how must be 'cube' or 'slice'.") # Multiply by spectral unit moment0_err *= cube.spectral_axis.unit meta = {'moment_order': 0, 'moment_axis': axis, 'moment_method': how} cube_meta = cube.meta.copy() meta.update(cube_meta) new_wcs = drop_axis(cube._wcs, np2wcs[axis]) return Projection(moment0_err, copy=False, wcs=new_wcs, meta=meta, header=cube._nowcs_header)