示例#1
0
def spectrum_json(library, spec_id):
    path = os_path.join(args.path, library)
    x = SpectrumLibrarySqlite(path=path)
    spectrum = x.open(ids=int(spec_id)).extract_item(0)

    data = list(zip(spectrum.wavelengths, spectrum.values))
    return json.dumps(data)
示例#2
0
def spectrum_txt(library, spec_id):
    path = os_path.join(args.path, library)
    x = SpectrumLibrarySqlite(path=path)
    spectrum = x.open(ids=int(spec_id)).extract_item(0)
    data = np.asarray(list(zip(spectrum.wavelengths, spectrum.values, spectrum.value_errors)))

    txt_output = io.StringIO()
    np.savetxt(txt_output, data)
    response = make_response(txt_output.getvalue())
    response.headers['Content-Type'] = 'text/plain'
    return response
示例#3
0
def spectrum_png(library, spec_id, lambda_min, lambda_max):
    path = os_path.join(args.path, library)
    x = SpectrumLibrarySqlite(path=path)
    spectrum = x.open(ids=int(spec_id)).extract_item(0)

    fig = Figure(figsize=(16, 6))
    ax = fig.add_subplot(111)
    ax.set_xlabel('Wavelength / A')
    ax.set_ylabel('Value')
    ax.set_xlim([float(lambda_min), float(lambda_max)])
    ax.grid(True)
    ax.plot(spectrum.wavelengths, spectrum.values)
    canvas = FigureCanvas(fig)
    png_output = io.BytesIO()
    canvas.print_png(png_output)
    response = make_response(png_output.getvalue())
    response.headers['Content-Type'] = 'image/png'
    return response
    random.randint(0,
                   len(test_library_ids) - 1) for i in range(args.test_count)
]

# Start writing output
with open(args.output_file, "w") as output:
    column_headings_written = False
    stellar_label_names = []

    # Loop over the spectra we are going to test
    for index in indices:
        # Look up database ID of the test spectrum
        test_id = test_library_ids[index]

        # Load test spectrum
        test_spectrum = test_library.open(ids=[test_id]).extract_item(0)

        # Pick a number of MCMC steps to do
        if args.vary_mcmc_steps:
            rv_code.n_burn = rv_code.n_steps = random.randint(100, 1000)
        else:
            rv_code.n_burn = rv_code.n_steps = 500

        # Pick a random radial velocity
        radial_velocity = random_radial_velocity()  # Unit km/s

        # Pick coefficients for some random continuum
        continuum = (random.uniform(1, 100), random.uniform(-1e-2, 1e-2),
                     random.uniform(-1e-8, 1e-8))
        continuum_spectrum = SpectrumPolynomial(
            wavelengths=test_spectrum.wavelengths,