示例#1
0
static PyObject* from_fits_file(PyObject* self, PyObject* args)
{
    oskar_Sky* h = 0;
    PyObject* capsule = 0;
    int status = 0, override_units = 0, prec = 0;
    double frequency_hz, spectral_index, min_peak_fraction, min_abs_val;
    const char *default_map_units = 0, *filename = 0, *type = 0;
    if (!PyArg_ParseTuple(args, "sddsidds", &filename,
            &min_peak_fraction, &min_abs_val, &default_map_units,
            &override_units, &frequency_hz, &spectral_index, &type))
        return 0;
    prec = (type[0] == 'S' || type[0] == 's') ? OSKAR_SINGLE : OSKAR_DOUBLE;
    h = oskar_sky_from_fits_file(prec, filename, min_peak_fraction,
            min_abs_val, default_map_units, override_units, frequency_hz,
            spectral_index, &status);
    capsule = PyCapsule_New((void*)h, name, (PyCapsule_Destructor)sky_free);

    /* Check for errors. */
    if (status)
    {
        PyErr_Format(PyExc_RuntimeError,
                "oskar_sky_from_fits_file() failed with code %d (%s).",
                status, oskar_get_error_string(status));
        return 0;
    }
    return Py_BuildValue("N", capsule); /* Don't increment refcount. */
}
int main(int argc, char** argv)
{
    int error = 0;

    oskar::OptionParser opt("oskar_fits_image_to_sky_model",
            oskar_version_string());
    opt.set_description("Converts a FITS image to an OSKAR sky model. A number "
            "of options are provided to control how much of the image is used "
            "to make the sky model.");
    opt.add_required("FITS file", "The input FITS image to convert.");
    opt.add_required("sky model file", "The output OSKAR sky model file name to save.");
    opt.add_flag("-s", "Spectral index. This is the spectral index that will "
            "be given to each pixel in the output sky model.", 1, "0.0");
    opt.add_flag("-f", "Minimum allowed fraction of image peak. Pixel values "
            "below this fraction will be ignored.", 1, "0.0");
    opt.add_flag("-n", "Noise floor in units of original image. "
            "Pixels below this value will be ignored.", 1, "0.0");
    if (!opt.check_options(argc, argv)) return EXIT_FAILURE;

    // Parse command line.
    double spectral_index = 0.0;
    double min_peak_fraction = 0.0;
    double min_abs_val = 0.0;
    opt.get("-f")->getDouble(min_peak_fraction);
    opt.get("-n")->getDouble(min_abs_val);
    opt.get("-s")->getDouble(spectral_index);

    // Load the FITS image data.
    oskar_Sky* sky = oskar_sky_from_fits_file(OSKAR_DOUBLE, opt.get_arg(0),
            min_peak_fraction, min_abs_val, "Jy/beam", 0, 0.0, spectral_index,
            &error);

    // Write out the sky model.
    oskar_sky_save(opt.get_arg(1), sky, &error);
    if (error)
    {
        oskar_log_error(0, oskar_get_error_string(error));
        return error;
    }

    oskar_sky_free(sky, &error);
    return 0;
}