Example #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()))
Example #2
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()))
Example #3
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()))
Example #4
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()))
Example #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()))
Example #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()))
Example #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()))
Example #8
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()))
Example #9
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()))
Example #10
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()))
Example #11
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()))
Example #12
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()))
Example #13
0
    def set_data(self, datamaps):
        if not numpy.iterable(datamaps):
            raise TypeError("datamaps is not iterable")
        # keys = ["x", "y", "staterror", "syserror", "weights"]
        keys = ["x", "y", "staterror", "syserror"]
        for ii, data in enumerate(datamaps):
            for key in keys:
                if data.has_key(key):
                    data[key] = decode_string(data[key])
                    info("decoding" + key)

            self.session.set_data(ii, sherpa.data.Data1D(**data))

            d = self.session.get_data(ii)
            numpy.set_printoptions(precision=4, threshold=6)
            info("DataSet %i x: " % ii + numpy.array2string(d.x))
            info("DataSet %i y: " % ii + numpy.array2string(d.y))
            info("DataSet %i staterror: " % ii + numpy.array2string(d.staterror))
Example #14
0
    def set_data(self, datamaps):
        if not numpy.iterable(datamaps):
            raise TypeError("datamaps is not iterable")
        #keys = ["x", "y", "staterror", "syserror", "weights"]
        keys = ["x", "y", "staterror", "syserror"]
        for ii, data in enumerate(datamaps):
            for key in keys:
                if data.has_key(key):
                    data[key] = decode_string(data[key])
                    info('decoding' + key)

            self.session.set_data(ii, sherpa.data.Data1D(**data))

            d = self.session.get_data(ii)
            numpy.set_printoptions(precision=4, threshold=6)
            info("DataSet %i x: " % ii + numpy.array2string(d.x))
            info("DataSet %i y: " % ii + numpy.array2string(d.y))
            info("DataSet %i staterror: " % ii +
                 numpy.array2string(d.staterror))