<s> from __future__ import print_function <EOL> import numpy as np <EOL> from astropy import units as u <EOL> from astropy . extern import six <EOL> from astropy . io . fits import PrimaryHDU , ImageHDU , Header <EOL> from . utils . wcs_utils import get_spatial_scale , sanitize_wcs <EOL> from . geometry import extract_slice <EOL> from . geometry import path as paths <EOL> from . utils . wcs_slicing import slice_wcs <EOL> def extract_pv_slice ( cube , path , wcs = None , spacing = <NUM_LIT:1.0> , order = <NUM_LIT:3> , <EOL> respect_nan = True ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( cube , ( six . string_types , ImageHDU , PrimaryHDU ) ) : <EOL> try : <EOL> from spectral_cube import SpectralCube <EOL> cube = SpectralCube . read ( cube ) <EOL> except ImportError : <EOL> raise ImportError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if _is_spectral_cube ( cube ) : <EOL> wcs = cube . wcs <EOL> cube = cube . filled_data [ ... ] . value <EOL> if wcs is not None : <EOL> wcs = sanitize_wcs ( wcs ) <EOL> if not isinstance ( cube , np . ndarray ) or wcs is not None : <EOL> scale = get_spatial_scale ( wcs ) <EOL> if isinstance ( spacing , u . Quantity ) : <EOL> pixel_spacing = ( spacing / scale ) . decompose ( ) <EOL> world_spacing = spacing <EOL> else : <EOL> pixel_spacing = spacing <EOL> world_spacing = spacing * scale <EOL> else : <EOL> if isinstance ( spacing , u . Quantity ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> else : <EOL> pixel_spacing = spacing <EOL> world_spacing = None <EOL> if not isinstance ( path , paths . Path ) : <EOL> path = paths . Path ( path ) <EOL> pv_slice = extract_slice ( cube , path , wcs = wcs , spacing = pixel_spacing , <EOL> order = order , respect_nan = respect_nan ) <EOL> if wcs is None : <EOL> header = Header ( ) <EOL> else : <EOL> header = slice_wcs ( wcs , spatial_scale = world_spacing ) . to_header ( ) <EOL> return PrimaryHDU ( data = pv_slice , header = header ) <EOL> def _is_spectral_cube ( obj ) : <EOL> try : <EOL> from spectral_cube import SpectralCube <EOL> return isinstance ( obj , SpectralCube ) <EOL> except ImportError : <EOL> return False </s>
