Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
else:
new_mask = None
if spectrum.uncertainty is not None:
new_uncertainty = np.delete(spectrum.uncertainty, excise_indices)
else:
new_uncertainty = None
# Return a new object with the regions excised.
return Spectrum1D(flux=new_flux,
spectral_axis=new_spectral_axis,
uncertainty=new_uncertainty,
mask=new_mask,
wcs=spectrum.wcs,
velocity_convention=spectrum.velocity_convention,
rest_value=spectrum.rest_value if not isinstance(new_spectral_axis, SpectralCoord) else None,
radial_velocity=spectrum.radial_velocity if not isinstance(new_spectral_axis, SpectralCoord) else None)
def from_tree(cls, node, ctx):
if isinstance(node, SpectralCoord):
return node
unit = UnitType.from_tree(node['unit'], ctx)
value = node['value']
if isinstance(value, NDArrayType):
value = value._make_array()
return SpectralCoord(value, unit=unit)
modified_flux[s:e+1] = np.linspace(flux[s], flux[e], modified_flux[s:e+1].size)
# Add the uncertainty of the two linear interpolation endpoints in
# quadrature and apply to the excised region.
if new_uncertainty is not None:
new_uncertainty[s:e] = np.sqrt(spectrum.uncertainty[s]**2 + spectrum.uncertainty[e]**2)
# Return a new object with the regions excised.
return Spectrum1D(flux=modified_flux,
spectral_axis=spectral_axis,
uncertainty=new_uncertainty,
wcs=spectrum.wcs,
mask=spectrum.mask,
velocity_convention=spectrum.velocity_convention,
rest_value=spectrum.rest_value if not isinstance(spectral_axis, SpectralCoord) else None,
radial_velocity=spectrum.radial_velocity if not isinstance(spectral_axis, SpectralCoord) else None)
def to_tree(cls, spec_coord, ctx):
node = {}
if isinstance(spec_coord, SpectralCoord):
node['value'] = custom_tree_to_tagged_tree(spec_coord.value, ctx)
node['unit'] = custom_tree_to_tagged_tree(spec_coord.unit, ctx)
return node
raise TypeError(f"'{spec_coord}' is not a valid SpectralCoord")
@classmethod
def assert_equal(cls, old, new):
"""
Equality test used in ASDF unit tests
"""
assert len(old) == len(new)
for x, y in zip(old, new):
Spectrum1DType.assert_equal(x, y)
class SpectralCoordType(SpecutilsType):
"""
ASDF tag implementation used to serialize/derialize SpectralCoord objects
"""
name = 'spectra/spectral_coord'
types = [SpectralCoord]
version = '1.0.0'
@classmethod
def to_tree(cls, spec_coord, ctx):
node = {}
if isinstance(spec_coord, SpectralCoord):
node['value'] = custom_tree_to_tagged_tree(spec_coord.value, ctx)
node['unit'] = custom_tree_to_tagged_tree(spec_coord.unit, ctx)
return node
raise TypeError(f"'{spec_coord}' is not a valid SpectralCoord")
@classmethod
def from_tree(cls, node, ctx):
if isinstance(node, SpectralCoord):
return node