def is_spectral_cube(filename, **kwargs): """ Check that the file is a 3D or 4D FITS spectral cube """ if not is_fits(filename): return False try: StokesSpectralCube.read(filename) except Exception: return False else: return True
def read_spectral_cube(filename, **kwargs): """ Read in a FITS spectral cube. If multiple Stokes components are present, these are split into separate glue components. """ cube = StokesSpectralCube.read(filename) return spectral_cube_to_data(cube)
def is_spectral_cube(filename, **kwargs): """ Check that the file is a 3D or 4D FITS spectral cube """ file_format = identify_file_format(filename) if file_format is None: return False try: StokesSpectralCube.read(filename, format=file_format) except Exception: return False else: return True
def read_spectral_cube(filename, **kwargs): """ Read in a FITS spectral cube. If multiple Stokes components are present, these are split into separate glue components. """ cube = StokesSpectralCube.read(filename, format=identify_file_format(filename)) return spectral_cube_to_data(cube)
def spectral_cube_to_data(cube, label=None): if isinstance(cube, SpectralCube): cube = StokesSpectralCube({'I': cube}) result = Data(label=label) result.coords = coordinates_from_wcs(cube.wcs) for component in cube.components: data = getattr(cube, component)._data result.add_component(data, label='STOKES {0}'.format(component)) return result