Skip to content

Commit

Permalink
Make ObsCube and SimCube only defined when signal_id is installed; bo…
Browse files Browse the repository at this point in the history
…th raise error if used
  • Loading branch information
e-koch committed Jun 6, 2017
1 parent 35a4b43 commit cd84c06
Show file tree
Hide file tree
Showing 2 changed files with 227 additions and 223 deletions.
213 changes: 107 additions & 106 deletions turbustat/cube_tools/obs_cubes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,146 +9,147 @@

from spectral_cube import SpectralCube, CompositeMask

from cube_utils import _check_mask, _check_beam, _get_int_intensity
# from cleaning_algs import *

try:
from signal_id import Noise
except:
print("No signal_id package!")
pass
prefix = "/srv/astro/erickoch/" # Adjust if you're not me!
execfile(prefix + "Dropbox/code_development/signal-id/signal_id/noise.py")

class ObsCube(object):
"""
A wrapping class of SpectralCube which prepares observational data
cubes to be compared to any other data cube.
from cube_utils import _check_mask, _check_beam, _get_int_intensity
# from cleaning_algs import *
Parameters
----------
cube : str
Path to file.
mask : numpy.ndarray, any mask class from spectral_cube, optional
Mask to be applied to the cube.
algorithm : {NAME HERE}, optional
Name of the cleaning algorithm to use.
class ObsCube(object):
"""
A wrapping class of SpectralCube which prepares observational data cubes
to be compared to any other data cube.
Example
-------
```
from turbustat.cube_tools import ObsCube
Parameters
----------
cube = ObsCube("data.fits")
cube.apply_cleaning(algorithm="SUPERAWESOMECLEANING")
cube : str
Path to file.
mask : numpy.ndarray, any mask class from spectral_cube, optional
Mask to be applied to the cube.
algorithm : {NAME HERE}, optional
Name of the cleaning algorithm to use.
```
"""
def __init__(self, cube, mask=None, algorithm=None, beam=None):

Example
-------
```
from turbustat.cube_tools import ObsCube
raise NotImplementedError("ObsCube is not yet implemented for "
"general use.")

cube = ObsCube("data.fits")
cube.apply_cleaning(algorithm="SUPERAWESOMECLEANING")
super(ObsCube, self).__init__()
self.cube = SpectralCube.read(cube)

```
"""
def __init__(self, cube, mask=None, algorithm=None, beam=None):
super(ObsCube, self).__init__()
self.cube = sc.SpectralCube.read(cube)
self.algorithm = algorithm

self.algorithm = algorithm
# Make sure mask is an accepted type
if mask is not None:
_check_mask(mask)
self.mask = mask

# Make sure mask is an accepted type
if mask is not None:
_check_mask(mask)
self.mask = mask
if beam is not None:
_check_beam(beam)
self.noise = Noise(self.cube, beam=beam)

if beam is not None:
_check_beam(beam)
self.noise = Noise(self.cube, beam=beam)
def clean_cube(self, algorithm=None):
raise NotImplementedError("")

def clean_cube(self, algorithm=None):
raise NotImplementedError("")
def apply_mask(self, mask=None):
'''
Check if the given mask is acceptable abd apply to
SpectralCube.
'''

def apply_mask(self, mask=None):
'''
Check if the given mask is acceptable abd apply to
SpectralCube.
'''
# Update mask
if mask is not None:
_check_mask(mask)
self.mask = mask

# Update mask
if mask is not None:
_check_mask(mask)
self.mask = mask
# Create the mask, auto masking nan values
default_mask = np.isfinite(self.cube.filled_data[:])
if self.mask is not None:
self.mask = CompositeMask(default_mask, self.mask)
else:
self.mask = default_mask

# Create the mask, auto masking nan values
default_mask = np.isfinite(self.cube.filled_data[:])
if self.mask is not None:
self.mask = CompositeMask(default_mask, self.mask)
else:
self.mask = default_mask
# Apply mask to spectral cube object
self.cube = self.cube.with_mask(mask)

# Apply mask to spectral cube object
self.cube = self.cube.with_mask(mask)
return self

return self
def _update(self, data=None, wcs=None, beam=None, method="MAD"):
'''
Helper function to update classes.
'''

def _update(self, data=None, wcs=None, beam=None, method="MAD"):
'''
Helper function to update classes.
'''
# Check if we need a new SpectralCube
if data is None and wcs is None:
pass
else:
if data is None:
data = self.cube.unmasked_data[:]
if wcs is None:
wcs = self.cube.wcs
# Make new SpectralCube object
self.cube = SpectralCube(data=data, wcs=wcs)

# Check if we need a new SpectralCube
if data is None and wcs is None:
pass
else:
if data is None:
data = self.cube.unmasked_data[:]
if wcs is None:
wcs = self.cube.wcs
# Make new SpectralCube object
self.cube = SpectralCube(data=data, wcs=wcs)
if beam is not None:
_check_beam(beam)
self.noise = Noise(self.cube, beam=beam, method=method)

if beam is not None:
_check_beam(beam)
self.noise = Noise(self.cube, beam=beam, method=method)
def compute_properties(self):
'''
Use SpectralCube to compute the moments. Also compute the integrated
intensity based on the noise properties from Noise.
'''

def compute_properties(self):
'''
Use SpectralCube to compute the moments. Also compute the integrated
intensity based on the noise properties from Noise.
'''
self._moment0 = self.cube.moment0().value

self._moment0 = self.cube.moment0().value
self._moment1 = self.cube.moment1().value

self._moment1 = self.cube.moment1().value
self._moment2 = self.cube.moment2().value

self._moment2 = self.cube.moment2().value
_get_int_intensity(self)

_get_int_intensity(self)
return self

return self
@property
def moment0(self):
return self._moment0

@property
def moment0(self):
return self._moment0
@property
def moment1(self):
return self._moment1

@property
def moment1(self):
return self._moment1
@property
def moment2(self):
return self._moment2

@property
def moment2(self):
return self._moment2
@property
def intint(self):
return self._intint

@property
def intint(self):
return self._intint
def prep(self, mask=None, algorithm=None):
'''
Prepares the cube to be compared to another cube.
'''

def prep(self, mask=None, algorithm=None):
'''
Prepares the cube to be compared to another cube.
'''
if not mask is None:
self.apply_mask()

if not mask is None:
self.apply_mask()
self.clean_cube()
self.compute_properties()

self.clean_cube()
self.compute_properties()
return self

return self
except ImportError:
# raise ImportError("The signal_id package must be installed")
pass
Loading

0 comments on commit cd84c06

Please sign in to comment.