Exemple #1
0
def spectrum_redshift_calc(private_key, sender_id, msg_id, mtype, params,
                           extra):
    """
    spectrum_redshift_calc



    """
    try:
        info("spectrum_redshift_calc()")
        try:
            payload = DictionaryClass(params)
            x = decode_string(payload.x)
            y = decode_string(payload.y)
            yerr = decode_string(payload.yerr)
            from_redshift = float(payload.from_redshift)
            to_redshift = float(payload.to_redshift)

            sed = Sed(x, y, yerr, from_redshift)
            sed.redshift(to_redshift)

            payload.x = encode_string(sed.wavelength)
            payload.y = encode_string(sed.flux)
            payload.yerr = encode_string(sed.err)

            reply_success(msg_id, mtype, payload)

        except Exception, e:
            reply_error(msg_id, sedexceptions.SEDException, e, mtype)
            return

    except Exception:
        error(str(capture_exception()))
Exemple #2
0
def spectrum_redshift_calc(private_key, sender_id, msg_id, mtype, params,
                                      extra):
    """
    spectrum_redshift_calc



    """
    try:
        info("spectrum_redshift_calc()")
        try:
            payload = DictionaryClass(params)
            x = decode_string(payload.x)
            y = decode_string(payload.y)
            yerr = decode_string(payload.yerr)
            from_redshift = float(payload.from_redshift)
            to_redshift = float(payload.to_redshift)

            sed = Sed(x, y, yerr, from_redshift)
            sed.redshift(to_redshift)

            payload.x = encode_string(sed.wavelength)
            payload.y = encode_string(sed.flux)
            payload.yerr = encode_string(sed.err)

            reply_success(msg_id, mtype, payload)

        except Exception, e:
            reply_error(msg_id, sedexceptions.SEDException, e, mtype)
            return

    except Exception:
        error(str(capture_exception()))
Exemple #3
0
def stack_redshift(private_key, sender_id, msg_id, mtype, params,
                                      extra):
    try:
        info("stack_redshift()")
        try:
            payload = DictionaryClass(params)
            seds = []
            for segment in payload.segments:
                x = decode_string(segment.x)
                y = decode_string(segment.y)
                yerr = decode_string(segment.yerr)
                z = float(segment.z)
                id_ = str(segment.id)
                seds.append(IrisSed(x=x, y=y, yerr=yerr, z=z, id=id_))
            z0 = float(payload.z0)
            correct_flux = payload.correct_flux == "true"

            result = redshift(IrisStack(seds), z0, correct_flux)

            for i, segment in enumerate(payload.segments):
                segment.x = encode_string(result[i].x)
                segment.y = encode_string(result[i].y)
                segment.yerr = encode_string(result[i].yerr)

            payload.excludeds = result.excluded

            reply_success(msg_id, mtype, payload.get_dict())

        except Exception, e:
            reply_error(msg_id, sedexceptions.SEDException, e, mtype)
            return

    except Exception:
        error(str(capture_exception()))
Exemple #4
0
def stack_normalize(private_key, sender_id, msg_id, mtype, params,
                                      extra):
    try:
        info("stack_normalize()")
        try:
            payload = DictionaryClass(params)
            seds = []
            for segment in payload.segments:
                x = decode_string(segment.x)
                y = decode_string(segment.y)
                yerr = decode_string(segment.yerr)
                id_ = str(segment.id)
                seds.append(IrisSed(x=x, y=y, yerr=yerr, id=id_))
            stack = IrisStack(seds)

            result = normalize(stack, payload)
            for i, segment in enumerate(payload.segments):
                segment.x = encode_string(result[i].x)
                segment.y = encode_string(result[i].y)
                segment.yerr = encode_string(result[i].yerr)
                segment.norm_constant = str(result[i].norm_constant)
            payload.excludeds = result.excluded
            reply_success(msg_id, mtype, payload.get_dict())

        except Exception, e:
            reply_error(msg_id, sedexceptions.SEDException, e, mtype)
            return

    except Exception:
        error(str(capture_exception()))
Exemple #5
0
def stack_normalize(private_key, sender_id, msg_id, mtype, params, extra):
    try:
        info("stack_normalize()")
        try:
            payload = DictionaryClass(params)
            seds = []
            for segment in payload.segments:
                x = decode_string(segment.x)
                y = decode_string(segment.y)
                yerr = decode_string(segment.yerr)
                id_ = str(segment.id)
                seds.append(IrisSed(x=x, y=y, yerr=yerr, id=id_))
            stack = IrisStack(seds)

            result = normalize(stack, payload)
            for i, segment in enumerate(payload.segments):
                segment.x = encode_string(result[i].x)
                segment.y = encode_string(result[i].y)
                segment.yerr = encode_string(result[i].yerr)
                segment.norm_constant = str(result[i].norm_constant)
            payload.excludeds = result.excluded
            reply_success(msg_id, mtype, payload.get_dict())

        except Exception, e:
            reply_error(msg_id, sedexceptions.SEDException, e, mtype)
            return

    except Exception:
        error(str(capture_exception()))
Exemple #6
0
def stack_redshift(private_key, sender_id, msg_id, mtype, params, extra):
    try:
        info("stack_redshift()")
        try:
            payload = DictionaryClass(params)
            seds = []
            for segment in payload.segments:
                x = decode_string(segment.x)
                y = decode_string(segment.y)
                yerr = decode_string(segment.yerr)
                z = float(segment.z)
                id_ = str(segment.id)
                seds.append(IrisSed(x=x, y=y, yerr=yerr, z=z, id=id_))
            z0 = float(payload.z0)
            correct_flux = payload.correct_flux == "true"

            result = redshift(IrisStack(seds), z0, correct_flux)

            for i, segment in enumerate(payload.segments):
                segment.x = encode_string(result[i].x)
                segment.y = encode_string(result[i].y)
                segment.yerr = encode_string(result[i].yerr)

            payload.excludeds = result.excluded

            reply_success(msg_id, mtype, payload.get_dict())

        except Exception, e:
            reply_error(msg_id, sedexceptions.SEDException, e, mtype)
            return

    except Exception:
        error(str(capture_exception()))
Exemple #7
0
def spectrum_interpolate(private_key, sender_id, msg_id, mtype, params,
                                      extra):
    """
    spectrum_interpolate



    """

    try:
        info("spectrum_interpolate()")
        try:
            methods = {'Neville' : neville,
                       'Linear' : linear_interp,
                       'Nearest Neighbor' : nearest_interp,
                       'Linear Spline' : interp1d,
                       }
            payload = DictionaryClass(params)
            x = decode_string(payload.x)
            y = decode_string(payload.y)
            x_min = max(float(payload.x_min), min(x))
            x_max = min(float(payload.x_max), max(x))
            method = methods[payload.method]
            info("method " + method.__name__)
            n_bins = int(payload.n_bins)

            log = payload.log=='true';

            sed = Sed(x, y)
            newSed = sed.interpolate(method, (x_min, x_max), n_bins, log);

            filtered = False

            if payload.smooth == "true":
                info('smoothing')
                newSed = filter(newSed)
                newSed.smooth(int(payload.box_size))

            if payload.normalize=="true":
                info('normalizing')
                if not filtered:
                    newSed = filter(newSed)
                newSed.normalise()

            payload.x = encode_string(newSed.wavelength)
            payload.y = encode_string(newSed.flux)

            reply_success(msg_id, mtype, payload)
            info("success")

        except Exception, e:
            reply_error(msg_id, sedexceptions.SEDException, e, mtype)
            error("error: " + repr(e))
            return

    except Exception:
        error(str(capture_exception()))
Exemple #8
0
def fit_worker(func, outq, errq):
    try:
        results = func()
        outq.put(results)

    except Exception:
        e = capture_exception()
        errq.put(e)
        outq.put(None)
Exemple #9
0
def fit_worker(func, outq, errq):
    try:
        results = func()
        outq.put(results)

    except Exception:
        e = capture_exception()
        errq.put(e)
        outq.put(None)
Exemple #10
0
def spectrum_interpolate(private_key, sender_id, msg_id, mtype, params, extra):
    """
    spectrum_interpolate



    """

    try:
        info("spectrum_interpolate()")
        try:
            methods = {
                'Neville': neville,
                'Linear': linear_interp,
                'Nearest Neighbor': nearest_interp,
                'Linear Spline': interp1d,
            }
            payload = DictionaryClass(params)
            x = decode_string(payload.x)
            y = decode_string(payload.y)
            x_min = max(float(payload.x_min), min(x))
            x_max = min(float(payload.x_max), max(x))
            method = methods[payload.method]
            info("method " + method.__name__)
            n_bins = int(payload.n_bins)

            log = payload.log == 'true'

            sed = Sed(x, y)
            newSed = sed.interpolate(method, (x_min, x_max), n_bins, log)

            filtered = False

            if payload.smooth == "true":
                info('smoothing')
                newSed = filter(newSed)
                newSed.smooth(int(payload.box_size))

            if payload.normalize == "true":
                info('normalizing')
                if not filtered:
                    newSed = filter(newSed)
                newSed.normalise()

            payload.x = encode_string(newSed.wavelength)
            payload.y = encode_string(newSed.flux)

            reply_success(msg_id, mtype, payload)
            info("success")

        except Exception, e:
            reply_error(msg_id, sedexceptions.SEDException, e, mtype)
            error("error: " + repr(e))
            return

    except Exception:
        error(str(capture_exception()))
Exemple #11
0
 def worker(ui_p):
     try:
         signal.signal(signal.SIGTERM, signal.SIG_DFL)
         ui_p.session.fit()
         results = ui_p.get_fit_results()
         outq.put(results)
     except Exception, e:
         trace = capture_exception()
         msg = str(trace)
         if e.args:
             msg = e.args[0]
         errq.put((msg, trace))
         outq.put(None)
Exemple #12
0
 def worker(ui_p):
     try:
         signal.signal(signal.SIGTERM, signal.SIG_DFL)
         ui_p.session.fit()
         results = ui_p.get_fit_results()
         outq.put(results)
     except Exception, e:
         trace = capture_exception()
         msg = str(trace)
         if e.args:
             msg = e.args[0]
         errq.put( (msg, trace) )
         outq.put(None)
Exemple #13
0
def reply_error(msg_id, exception, e, mtype):

    errtrace = capture_exception()
    logger.exception(e)
    #error(errtrace)
    cli.reply(msg_id, {"samp.status": samp.SAMP_STATUS_ERROR,
    #cli.reply(msg_id, {"samp.status": "samp.notok",
                       "samp.result": {"exception": str(exception.__name__),
                                       "message": str(e) #str(errtrace)
                                       },
                       "samp.error" : {"samp.errortxt" : "Sherpa exception"},
                       })
    info("sent reply_error to " + msg_id)
Exemple #14
0
def conf_worker(func, outq, errq):
    try:

        #confoutput = logging.StreamHandler()
        # confoutput = ConfStreamHandler(sys.stderr)
        # confoutput.setLevel(logging.INFO)
        # logger.addHandler(confoutput)

        results = func()
        outq.put(results)

    except Exception:
        e = capture_exception()
        errq.put(e)
        outq.put(None)
Exemple #15
0
def conf_worker(func, outq, errq):
    try:

        #confoutput = logging.StreamHandler()
        # confoutput = ConfStreamHandler(sys.stderr)
        # confoutput.setLevel(logging.INFO)
        # logger.addHandler(confoutput)

        results = func()
        outq.put(results)

    except Exception:
        e = capture_exception()
        errq.put(e)
        outq.put(None)
Exemple #16
0
def spectrum_integrate(private_key, sender_id, msg_id, mtype, params,
                                      extra):
    """
    spectrum_integrate



    """
    try:
        info("spectrum_integrate()")
        try:
            payload = DictionaryClass(params)

            x = decode_string(payload.x)
            y = decode_string(payload.y)

            sed = Sed(x, y)

            response = dict()
            response['points'] = list()

            for curve in payload.curves:
                pb = Passband(curve.file_name)
                flux = sed.calcFlux(pb)
                point = dict()
                point['id'] = curve.id
                point['wavelength'] = curve.eff_wave
                point['flux'] = str(flux)
                response['points'].append(point)

            for window in payload.windows:
                xmin = float(window.min)
                xmax = float(window.max)
                flux = sed.integrate(xmin, xmax)
                point = dict()
                point['id'] = window.id
                point['wavelength'] = str((xmax+xmin)/2)
                point['flux'] = str(flux)
                response['points'].append(point)

            reply_success(msg_id, mtype, response)

        except Exception, e:
            reply_error(msg_id, sedexceptions.SEDException, e, mtype)
            return

    except Exception:
        error(str(capture_exception()))
Exemple #17
0
def spectrum_integrate(private_key, sender_id, msg_id, mtype, params, extra):
    """
    spectrum_integrate



    """
    try:
        info("spectrum_integrate()")
        try:
            payload = DictionaryClass(params)

            x = decode_string(payload.x)
            y = decode_string(payload.y)

            sed = Sed(x, y)

            response = dict()
            response['points'] = list()

            for curve in payload.curves:
                pb = Passband(curve.file_name)
                flux = sed.calcFlux(pb)
                point = dict()
                point['id'] = curve.id
                point['wavelength'] = curve.eff_wave
                point['flux'] = str(flux)
                response['points'].append(point)

            for window in payload.windows:
                xmin = float(window.min)
                xmax = float(window.max)
                flux = sed.integrate(xmin, xmax)
                point = dict()
                point['id'] = window.id
                point['wavelength'] = str((xmax + xmin) / 2)
                point['flux'] = str(flux)
                response['points'].append(point)

            reply_success(msg_id, mtype, response)

        except Exception, e:
            reply_error(msg_id, sedexceptions.SEDException, e, mtype)
            return

    except Exception:
        error(str(capture_exception()))
Exemple #18
0
def reply_error(msg_id, exception, e, mtype):

    errtrace = capture_exception()
    logger.exception(e)
    #error(errtrace)
    cli.reply(
        msg_id,
        {
            "samp.status": samp.SAMP_STATUS_ERROR,
            #cli.reply(msg_id, {"samp.status": "samp.notok",
            "samp.result": {
                "exception": str(exception.__name__),
                "message": str(e)  #str(errtrace)
            },
            "samp.error": {
                "samp.errortxt": "Sherpa exception"
            },
        })
    info("sent reply_error to " + msg_id)
Exemple #19
0
def stack_stack(private_key, sender_id, msg_id, mtype, params, extra):
    try:
        info("stack_stack()")
        try:
            payload = DictionaryClass(params)
            seds = []
            for segment in payload.segments:
                x = decode_string(segment.x)
                y = decode_string(segment.y)
                yerr = decode_string(segment.yerr)
                seds.append(IrisSed(x=x, y=y, yerr=yerr))
            i_stack = IrisStack(seds)

            binsize = float(payload.binsize)
            statistic = str(payload.statistic)
            smooth = payload.smooth == "true"
            smooth_binsize = float(payload.smooth_binsize)
            logbin = payload.log_bin == "true"

            result = sedstacker.sed.stack(i_stack,
                                          binsize,
                                          statistic,
                                          fill='remove',
                                          smooth=smooth,
                                          smooth_binsize=smooth_binsize,
                                          logbin=logbin)

            payload.segments[0].x = encode_string(result.x)
            payload.segments[0].y = encode_string(result.y)
            payload.segments[0].yerr = encode_string(result.yerr)
            payload.segments[0].counts = encode_string(result.counts)
            payload.segments = [payload.segments[0]]
            get_dict = payload.get_dict()
            reply_success(msg_id, mtype, payload.get_dict())

        except Exception, e:
            reply_error(msg_id, sedexceptions.SEDException, e, mtype)
            return

    except Exception:
        error(str(capture_exception()))
Exemple #20
0
class MtypeReceiveReplyNoResponse(object):
    def __init__(self, func, exceptionClass):
        self.func = func
        self.exceptionClass = exceptionClass

    def __call__(self, private_key, sender_id, msg_id, mtype, params, extra):

        try:
            info(self.func.__name__ + "()")

            try:

                self.func(private_key, sender_id, msg_id, mtype, params, extra)

            except Exception, e:
                reply_error(msg_id, exceptionClass, e, mtype)
                return

            reply_success(msg_id, mtype)

        except Exception:
            error(str(capture_exception()))
Exemple #21
0
def stack_stack(private_key, sender_id, msg_id, mtype, params,
                                      extra):
    try:
        info("stack_stack()")
        try:
            payload = DictionaryClass(params)
            seds = []
            for segment in payload.segments:
                x = decode_string(segment.x)
                y = decode_string(segment.y)
                yerr = decode_string(segment.yerr)
                seds.append(IrisSed(x=x, y=y, yerr=yerr))
            i_stack = IrisStack(seds)

            binsize = float(payload.binsize)
            statistic = str(payload.statistic)
            smooth = payload.smooth == "true"
            smooth_binsize = float(payload.smooth_binsize)
            logbin = payload.log_bin == "true"

            result = sedstacker.sed.stack(i_stack, binsize, statistic, fill='remove', smooth=smooth, smooth_binsize=smooth_binsize, logbin=logbin)

            payload.segments[0].x = encode_string(result.x)
            payload.segments[0].y = encode_string(result.y)
            payload.segments[0].yerr = encode_string(result.yerr)
            payload.segments[0].counts = encode_string(result.counts)
            payload.segments = [payload.segments[0]]
            get_dict = payload.get_dict()
            reply_success(msg_id, mtype, payload.get_dict())

        except Exception, e:
            reply_error(msg_id, sedexceptions.SEDException, e, mtype)
            return

    except Exception:
        error(str(capture_exception()))
Exemple #22
0
            def worker(ui_p, cdict):
                try:
                    signal.signal(signal.SIGTERM, signal.SIG_DFL)
                    ui_p.set_confidence(cdict)

                    handler = ConfidenceHandler()
                    handler.setLevel(logging.INFO)
                    logger = logging.getLogger('sherpa')
                    logger.setLevel(logging.INFO)
                    logger.addHandler(handler)

                    ui_p.run_confidence(cdict)

                    logger.removeHandler(handler)

                    results = ui_p.get_confidence_results(cdict)
                    outq.put(results)
                except Exception, e:
                    trace = capture_exception()
                    msg = str(trace)
                    if e.args:
                        msg = e.args[0]
                    errq.put((msg, trace))
                    outq.put(None)
Exemple #23
0
            def worker(ui_p, cdict):
                try:
                    signal.signal(signal.SIGTERM, signal.SIG_DFL)
                    ui_p.set_confidence(cdict)

                    handler = ConfidenceHandler()
                    handler.setLevel(logging.INFO)
                    logger = logging.getLogger('sherpa')
                    logger.setLevel(logging.INFO)
                    logger.addHandler(handler)

                    ui_p.run_confidence(cdict)

                    logger.removeHandler(handler)

                    results = ui_p.get_confidence_results(cdict)
                    outq.put(results)
                except Exception, e:
                    trace = capture_exception()
                    msg = str(trace)
                    if e.args:
                        msg = e.args[0]
                    errq.put( (msg, trace) )
                    outq.put(None)
Exemple #24
0
    """
    try:
        info("load_table_votable()")

        try:

            pass

        except Exception, e:
            reply_error(msg_id, sedexceptions.DataException, e, mtype)
            return

        reply_success(msg_id, mtype)

    except Exception:
        error(str(capture_exception()))


def load_table_fits(private_key, sender_id, msg_id, mtype, params, extra):
    """
    load_table_fits

    
    """
    try:
        info("load_table_fits()")
        ui = SherpaSession()

        try:
            # native Sherpa command
            ui.session.load_table(params["url"])
Exemple #25
0
    """
    try:
        info("load_table_votable()")

        try:

            pass

        except Exception, e:
            reply_error(msg_id, sedexceptions.DataException, e, mtype)
            return

        reply_success(msg_id, mtype)

    except Exception:
        error(str(capture_exception()))


def load_table_fits(private_key, sender_id, msg_id, mtype, params, extra):
    """
    load_table_fits

    
    """
    try:
        info("load_table_fits()")
        ui = SherpaSession()

        try:
            # native Sherpa command
            ui.session.load_table(params["url"])