Skip to content

Commit

Permalink
more testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ceyzeriat committed Sep 14, 2016
1 parent 1e97d3b commit ba6017a
Show file tree
Hide file tree
Showing 13 changed files with 387 additions and 76 deletions.
3 changes: 3 additions & 0 deletions soif/__init__.py
Expand Up @@ -32,6 +32,9 @@


from .oidata import *
from .oifits import *
from .oigrab import *
from .oidataempty import *
from .oigrab import *
from .oipriors import *
from .oimodel import *
Expand Down
68 changes: 53 additions & 15 deletions soif/oidata.py
Expand Up @@ -36,7 +36,7 @@
from . import core
np = core.np

__all__ = ['Oidata']
__all__ = []


class Oidata(OidataEmpty):
Expand All @@ -51,11 +51,6 @@ def __init__(self, src, hduidx, datatype, hduwlidx, indices=(),
hdu = hdus[self._input_hduidx[-1]]
hduwl = hdus[self._input_hduwlidx[-1]]

if self.datatype not in core.DATAKEYSUPPER:
if exc.raiseIt(exc.InvalidDataType,
self.raiseError,
datatype=self.datatype):
return
if core.DATAKEYSDATATYPE[self.datatype]['data'] \
not in core.hduToColNames(hdu):
if exc.raiseIt(exc.HduDatatypeMismatch,
Expand Down Expand Up @@ -133,6 +128,16 @@ def __init__(self, src, hduidx, datatype, hduwlidx, indices=(),
"_"+key,
core.replicate(getattr(self, "_"+key), (None, 3)))

# check shape sanity - might be raised in case there are several wl
# tables in the oifits. This feature is not covered by this library
extra_dim = (3,) if self.is_t3 else ()
if not self._u.shape == self._data.shape + extra_dim:
if exc.raiseIt(exc.shapeIssue,
self.raiseError,
uvshape=self._u.shape[:2],
datashape=self._data.shape):
return

# convert to radian if needed
if self.is_angle and degree:
self._data = self._data*core.DEG2RAD
Expand All @@ -146,12 +151,12 @@ def __init__(self, src, hduidx, datatype, hduwlidx, indices=(),
self.update()

def _info(self):
return "{} data, shape: {}, wl: {}{}".format(
return u"{} data, shape: {}, wl: {:.2f}{} µm".encode('utf-8').format(
self.datatype,
core.maskedshape(self.shapedata,
np.logical_not(self.mask).sum()),
self._wlmin,
" to {:.2f}".format(self._wlmax) if self._wlspan != 0 else "")
self._wlmin*1e6,
u" to {:.2f}".format(self._wlmax*1e6) if self._wlspan != 0 else "")

@property
def data(self):
Expand Down Expand Up @@ -241,6 +246,39 @@ def wl_d(self):
def wl_d(self, value):
exc.raiseIt(exc.ReadOnly, self.raiseError, attr="wl_d")

@property
def bl(self):
if self._use_mask:
return self._bl[self.mask]
else:
return self._bl

@bl.setter
def bl(self, value):
exc.raiseIt(exc.ReadOnly, self.raiseError, attr="bl")

@property
def pa(self):
if self._use_mask:
return self._pa[self.mask]
else:
return self._pa

@pa.setter
def pa(self, value):
exc.raiseIt(exc.ReadOnly, self.raiseError, attr="pa")

@property
def blwl(self):
if self._use_mask:
return self._blwl[self.mask]
else:
return self._blwl

@blwl.setter
def blwl(self, value):
exc.raiseIt(exc.ReadOnly, self.raiseError, attr="blwl")

@property
def shapedata(self):
return self.data.shape
Expand Down Expand Up @@ -345,12 +383,12 @@ def update(self, **kwargs):
if exc.raiseIt(exc.ZeroErrorbars, exc.doraise(self, **kwargs)):
return False
self._invvar = 1./self.error**2
self.bl = core.round_fig(np.hypot(self.v, self.u),
self.significant_figures)
self.pa = core.round_fig(np.arctan2(self.v, self.u),
self.significant_figures)
self.blwl = core.round_fig(self.bl/self.wl,
self.significant_figures)
self._bl = core.round_fig(np.hypot(self.v, self.u),
self.significant_figures)
self._pa = core.round_fig(np.arctan2(self.v, self.u),
self.significant_figures)
self._blwl = core.round_fig(self.bl/self.wl,
self.significant_figures)
self._wlmin = self.wl.min()
self._wlmax = self.wl.max()
self._wlspan = self._wlmax - self._wlmin
46 changes: 27 additions & 19 deletions soif/oiexception.py
Expand Up @@ -59,7 +59,7 @@ class NoTargetTable(OIException):
"""
def __init__(self, src="", *args, **kwargs):
super(NoTargetTable, self).__init__(src, *args, **kwargs)
self.message = "There's no OI_TARGET table in the oifits file '{}'! Oups".format(src)
self.message = "There's no OI_TARGET table in the oifits file '{}'".format(src)


class NoWavelengthTable(OIException):
Expand All @@ -68,7 +68,7 @@ class NoWavelengthTable(OIException):
"""
def __init__(self, src="", *args, **kwargs):
super(NoWavelengthTable, self).__init__(src, *args, **kwargs)
self.message = "There's no OI_WAVELENGTH table in the oifits file '{}'! Haha, you're screwed!".format(src)
self.message = "There's no OI_WAVELENGTH table in the oifits file '{}'".format(src)


class ReadOnly(OIException):
Expand All @@ -77,7 +77,7 @@ class ReadOnly(OIException):
"""
def __init__(self, attr, *args, **kwargs):
super(ReadOnly, self).__init__(attr, *args, **kwargs)
self.message = "Attribute '{}' is read-only. What did you think?".format(attr)
self.message = "Attribute '{}' is read-only".format(attr)


class InvalidDataType(OIException):
Expand All @@ -86,7 +86,7 @@ class InvalidDataType(OIException):
"""
def __init__(self, datatype, *args, **kwargs):
super(InvalidDataType, self).__init__(datatype, *args, **kwargs)
self.message = "Surprise! Data type '{}' does not exist".format(datatype)
self.message = "Data type '{}' does not exist".format(datatype)


class HduDatatypeMismatch(OIException):
Expand All @@ -96,7 +96,7 @@ class HduDatatypeMismatch(OIException):
def __init__(self, hduhead, datatype, *args, **kwargs):
super(HduDatatypeMismatch, self).__init__(hduhead, datatype,
*args, **kwargs)
self.message = "Data type '{}' and hdu with '{}' data do not match. Don't mix peas with poos".format(datatype, hduhead)
self.message = "Data type '{}' and hdu with '{}' data do not match".format(datatype, hduhead)


class BadMaskShape(OIException):
Expand All @@ -105,7 +105,7 @@ class BadMaskShape(OIException):
"""
def __init__(self, shape, *args, **kwargs):
super(BadMaskShape, self).__init__(shape, *args, **kwargs)
self.message = "Bad mask shape; it should be '{}'. Nudge it and try again".format(shape)
self.message = "Bad mask shape; it should be '{}'".format(shape)


class WrongData(OIException):
Expand All @@ -114,7 +114,7 @@ class WrongData(OIException):
"""
def __init__(self, typ, *args, **kwargs):
super(WrongData, self).__init__(typ, *args, **kwargs)
self.message = "Wrong data given, should be '{}'. Already told you, don't mix apples and camembert".format(typ)
self.message = "Wrong data given, should be '{}'".format(typ)


class IncompatibleData(OIException):
Expand All @@ -123,7 +123,7 @@ class IncompatibleData(OIException):
"""
def __init__(self, typ1, typ2, *args, **kwargs):
super(IncompatibleData, self).__init__(typ1, typ2, *args, **kwargs)
self.message = "Can't merge '{}' and '{}'. You looked very optimistic until now".format(typ1, typ2)
self.message = "Can't merge '{}' and '{}'".format(typ1, typ2)


class NotADataHdu(OIException):
Expand All @@ -132,7 +132,7 @@ class NotADataHdu(OIException):
"""
def __init__(self, idx, src, *args, **kwargs):
super(NotADataHdu, self).__init__(idx, src, *args, **kwargs)
self.message = "Hdu index '{}' in file '{}' does not contain data. Yep. Too bad".format(idx, src)
self.message = "Hdu index '{}' in file '{}' does not contain data".format(idx, src)


class NoSystematicsFit(OIException):
Expand All @@ -141,7 +141,7 @@ class NoSystematicsFit(OIException):
"""
def __init__(self, *args, **kwargs):
super(NoSystematicsFit, self).__init__(*args, **kwargs)
self.message = "You are not fitting systematics. But maybe you should"
self.message = "You are not fitting systematics"


class NotCallable(OIException):
Expand All @@ -150,7 +150,7 @@ class NotCallable(OIException):
"""
def __init__(self, fct, *args, **kwargs):
super(NotCallable, self).__init__(fct, *args, **kwargs)
self.message = "'{}' should be callable. Get up and go get it".format(fct)
self.message = "'{}' should be callable".format(fct)


class NoEMCEE(OIException):
Expand All @@ -159,7 +159,7 @@ class NoEMCEE(OIException):
"""
def __init__(self, *args, **kwargs):
super(NoEMCEE, self).__init__(*args, **kwargs)
self.message = "EMCEE is not installed. How come it is not?"
self.message = "EMCEE is not installed"


class AllParamsSet(OIException):
Expand All @@ -168,7 +168,7 @@ class AllParamsSet(OIException):
"""
def __init__(self, *args, **kwargs):
super(AllParamsSet, self).__init__(*args, **kwargs)
self.message = "All parameters are set, there is no reason for MCMC. That, was a successful simulation!"
self.message = "All parameters are set, there is no reason for MCMC"


class InvalidBound(OIException):
Expand All @@ -177,7 +177,7 @@ class InvalidBound(OIException):
"""
def __init__(self, name, param, vv, *args, **kwargs):
super(InvalidBound, self).__init__(name, param, vv, *args, **kwargs)
self.message = "Object '{}', parameter '{}' has invalid bounds: {}.".format(name, param, vv)
self.message = "Object '{}', parameter '{}' has invalid bounds: {}".format(name, param, vv)


class NotFoundName(OIException):
Expand All @@ -186,7 +186,7 @@ class NotFoundName(OIException):
"""
def __init__(self, name, *args, **kwargs):
super(NotFoundName, self).__init__(name, *args, **kwargs)
self.message = "Object name '{}' not found.".format(name)
self.message = "Object name '{}' not found".format(name)


class InalidUnitaryModel(OIException):
Expand All @@ -195,7 +195,7 @@ class InalidUnitaryModel(OIException):
"""
def __init__(self, typ, *args, **kwargs):
super(InalidUnitaryModel, self).__init__(typ, *args, **kwargs)
self.message = "Unitary model '{}' does not exist.".format(typ)
self.message = "Unitary model '{}' does not exist".format(typ)


class BusyName(OIException):
Expand All @@ -204,7 +204,7 @@ class BusyName(OIException):
"""
def __init__(self, name, *args, **kwargs):
super(BusyName, self).__init__(name, *args, **kwargs)
self.message = "Object name '{}' already exists.".format(name)
self.message = "Object name '{}' already exists".format(name)


class BadParamsSize(OIException):
Expand Down Expand Up @@ -232,7 +232,7 @@ class NoDataModel(OIException):
"""
def __init__(self, *args, **kwargs):
super(NoDataModel, self).__init__(*args, **kwargs)
self.message = "There is no data in this model. You cannot do that you unless specifically authorized"
self.message = "There is no data in this model"


class ZeroErrorbars(OIException):
Expand All @@ -241,4 +241,12 @@ class ZeroErrorbars(OIException):
"""
def __init__(self, *args, **kwargs):
super(ZeroErrorbars, self).__init__(*args, **kwargs)
self.message = "Some data-errors are 0. That's gonna be an issue very soon"
self.message = "Some data-errors are 0"

class shapeIssue(OIException):
"""
If there is some data errors are zero
"""
def __init__(self, uvshape, datashape, *args, **kwargs):
super(shapeIssue, self).__init__(uvshape, datashape, *args, **kwargs)
self.message = "The data shape '{}' is not compatible with the (U,V) shape '{}'".format(uvshape, datashape)
2 changes: 1 addition & 1 deletion soif/oifits.py
Expand Up @@ -36,7 +36,7 @@
from . import core
np = core.np

__all__ = []
__all__ = ['Oifits']


class Oifits(object):
Expand Down
4 changes: 2 additions & 2 deletions soif/oigrab.py
Expand Up @@ -165,7 +165,7 @@ def show_specs(self, ret=False, **kwargs):
if ret:
return tgtlist

def show_filtered(self, tgt=None, mjd=(None, None), hdus=(),
def filtered(self, tgt=None, mjd=(None, None), hdus=(),
vis2=True, t3phi=True, t3amp=True, visphi=True,
visamp=True, verbose=False, **kwargs):
"""
Expand Down Expand Up @@ -215,7 +215,7 @@ def extract(self, tgt=None, mjd=(None, None), wl=(None, None), hdus=(),
flatten=False, degree=True, significant_figures=5,
erb_sigma=None, sigma_erb=None, systematic_prior=None,
systematic_bounds=None, verbose=False, **kwargs):
datayouwant = self.show_filtered(
datayouwant = self.filtered(
tgt=tgt, mjd=mjd, vis2=vis2, hdus=hdus,
t3phi=t3phi, t3amp=t3amp, visphi=visphi, visamp=visamp,
verbose=verbose, **kwargs)
Expand Down
File renamed without changes.
63 changes: 63 additions & 0 deletions soif/test/test2.oifits

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit ba6017a

Please sign in to comment.