Esempio n. 1
0
oskar_Imager* oskar_imager_create(int imager_precision, int* status)
{
    oskar_Imager* h = 0;
    h = (oskar_Imager*) calloc(1, sizeof(oskar_Imager));

    /* Create timers. */
    h->tmr_grid_finalise = oskar_timer_create(OSKAR_TIMER_NATIVE);
    h->tmr_grid_update = oskar_timer_create(OSKAR_TIMER_NATIVE);
    h->tmr_init = oskar_timer_create(OSKAR_TIMER_NATIVE);
    h->tmr_read = oskar_timer_create(OSKAR_TIMER_NATIVE);
    h->tmr_write = oskar_timer_create(OSKAR_TIMER_NATIVE);
    h->mutex = oskar_mutex_create();

    /* Create scratch arrays. */
    h->imager_prec = imager_precision;
    h->uu_im       = oskar_mem_create(imager_precision, OSKAR_CPU, 0, status);
    h->vv_im       = oskar_mem_create(imager_precision, OSKAR_CPU, 0, status);
    h->ww_im       = oskar_mem_create(imager_precision, OSKAR_CPU, 0, status);
    h->uu_tmp      = oskar_mem_create(imager_precision, OSKAR_CPU, 0, status);
    h->vv_tmp      = oskar_mem_create(imager_precision, OSKAR_CPU, 0, status);
    h->ww_tmp      = oskar_mem_create(imager_precision, OSKAR_CPU, 0, status);
    h->vis_im      = oskar_mem_create(imager_precision | OSKAR_COMPLEX,
            OSKAR_CPU, 0, status);
    h->weight_im   = oskar_mem_create(imager_precision, OSKAR_CPU, 0, status);
    h->weight_tmp  = oskar_mem_create(imager_precision, OSKAR_CPU, 0, status);
    h->time_im     = oskar_mem_create(OSKAR_DOUBLE, OSKAR_CPU, 0, status);

    /* Check data type. */
    if (imager_precision != OSKAR_SINGLE && imager_precision != OSKAR_DOUBLE)
    {
        *status = OSKAR_ERR_BAD_DATA_TYPE;
        return h;
    }

    /* Get number of devices available, and device location. */
    oskar_device_set_require_double_precision(imager_precision == OSKAR_DOUBLE);
    h->num_gpus_avail = oskar_device_count(0, &h->dev_loc);

    /* Set sensible defaults. */
    oskar_imager_set_gpus(h, -1, 0, status);
    oskar_imager_set_num_devices(h, -1);
    oskar_imager_set_algorithm(h, "FFT", status);
    oskar_imager_set_image_type(h, "I", status);
    oskar_imager_set_weighting(h, "Natural", status);
    oskar_imager_set_ms_column(h, "DATA", status);
    oskar_imager_set_default_direction(h);
    oskar_imager_set_generate_w_kernels_on_gpu(h, 1);
    oskar_imager_set_fov(h, 1.0);
    oskar_imager_set_size(h, 256, status);
    oskar_imager_set_uv_filter_max(h, DBL_MAX);
    return h;
}
Esempio n. 2
0
oskar_Imager* oskar_imager_create(int imager_precision, int* status)
{
    oskar_Imager* h = 0;
    h = (oskar_Imager*) calloc(1, sizeof(oskar_Imager));

    /* Create scratch arrays. */
    h->imager_prec = imager_precision;
    h->uu_im       = oskar_mem_create(imager_precision, OSKAR_CPU, 0, status);
    h->vv_im       = oskar_mem_create(imager_precision, OSKAR_CPU, 0, status);
    h->ww_im       = oskar_mem_create(imager_precision, OSKAR_CPU, 0, status);
    h->uu_tmp      = oskar_mem_create(imager_precision, OSKAR_CPU, 0, status);
    h->vv_tmp      = oskar_mem_create(imager_precision, OSKAR_CPU, 0, status);
    h->ww_tmp      = oskar_mem_create(imager_precision, OSKAR_CPU, 0, status);
    h->vis_im      = oskar_mem_create(imager_precision | OSKAR_COMPLEX,
            OSKAR_CPU, 0, status);
    h->weight_im   = oskar_mem_create(imager_precision, OSKAR_CPU, 0, status);
    h->weight_tmp  = oskar_mem_create(imager_precision, OSKAR_CPU, 0, status);

    /* Check data type. */
    if (imager_precision != OSKAR_SINGLE && imager_precision != OSKAR_DOUBLE)
    {
        *status = OSKAR_ERR_BAD_DATA_TYPE;
        return h;
    }

    /* Set sensible defaults. */
    oskar_imager_set_gpus(h, -1, 0, status);
    oskar_imager_set_fft_on_gpu(h, 0);
    oskar_imager_set_generate_w_kernels_on_gpu(h, 1);
    oskar_imager_set_fov(h, 1.0);
    oskar_imager_set_size(h, 256, status);
    oskar_imager_set_channel_start(h, 0);
    oskar_imager_set_channel_end(h, -1);
    oskar_imager_set_channel_snapshots(h, 1);
    oskar_imager_set_time_start(h, 0);
    oskar_imager_set_time_end(h, -1);
    oskar_imager_set_time_snapshots(h, 0);
    oskar_imager_set_uv_filter_max(h, -1.0);
    oskar_imager_set_image_type(h, "I", status);
    oskar_imager_set_algorithm(h, "FFT", status);
    oskar_imager_set_weighting(h, "Natural", status);
    oskar_imager_set_ms_column(h, "DATA", status);
    oskar_imager_set_default_direction(h);
    return h;
}
Esempio n. 3
0
TEST(imager, grid_sum)
{
    int status = 0, type = OSKAR_DOUBLE;
    int size = 2048, grid_size = size * size;

    // Create and set up the imager.
    oskar_Imager* im = oskar_imager_create(type, &status);
    oskar_imager_set_grid_kernel(im, "pillbox", 1, 1, &status);
    oskar_imager_set_fov(im, 5.0);
    oskar_imager_set_size(im, size, &status);
    oskar_Mem* grid = oskar_mem_create(type | OSKAR_COMPLEX, OSKAR_CPU,
            grid_size, &status);
    ASSERT_EQ(0, status);

    // Create visibility data.
    int num_vis = 10000;
    oskar_Mem* uu = oskar_mem_create(type, OSKAR_CPU, num_vis, &status);
    oskar_Mem* vv = oskar_mem_create(type, OSKAR_CPU, num_vis, &status);
    oskar_Mem* ww = oskar_mem_create(type, OSKAR_CPU, num_vis, &status);
    oskar_Mem* vis = oskar_mem_create(type | OSKAR_COMPLEX, OSKAR_CPU, num_vis,
            &status);
    oskar_Mem* weight = oskar_mem_create(type, OSKAR_CPU, num_vis, &status);
    oskar_mem_random_gaussian(uu, 0, 1, 2, 3, 100.0, &status);
    oskar_mem_random_gaussian(vv, 4, 5, 6, 7, 100.0, &status);
    oskar_mem_set_value_real(vis, 1.0, 0, num_vis, &status);
    oskar_mem_set_value_real(weight, 1.0, 0, num_vis, &status);

    // Grid visibility data.
    double plane_norm = 0.0;
    oskar_imager_update_plane(im, num_vis, uu, vv, ww, vis, weight, grid,
            &plane_norm, 0, &status);
    ASSERT_DOUBLE_EQ((double)num_vis, plane_norm);

    // Sum the grid.
    double2* t = oskar_mem_double2(grid, &status);
    double sum = 0.0;
    for (int i = 0; i < grid_size; i++) sum += t[i].x;
    ASSERT_DOUBLE_EQ((double)num_vis, sum);

    // Finalise the image.
    oskar_imager_finalise_plane(im, grid, plane_norm, &status);
    ASSERT_EQ(0, status);

#ifdef WRITE_FITS
    // Get the real part only.
    if (oskar_mem_precision(grid) == OSKAR_DOUBLE)
    {
        double *t = oskar_mem_double(grid, &status);
        for (int j = 0; j < grid_size; ++j) t[j] = t[2 * j];
    }
    else
    {
        float *t = oskar_mem_float(grid, &status);
        for (int j = 0; j < grid_size; ++j) t[j] = t[2 * j];
    }

    // Save the real part.
    fitsfile* f;
    long naxes[2] = {size, size}, firstpix[2] = {1, 1};
    fits_create_file(&f, "test_imager_grid_sum.fits", &status);
    fits_create_img(f, (type == OSKAR_DOUBLE ? DOUBLE_IMG : FLOAT_IMG),
            2, naxes, &status);
    fits_write_pix(f, (type == OSKAR_DOUBLE ? TDOUBLE : TFLOAT),
            firstpix, grid_size, oskar_mem_void(grid), &status);
    fits_close_file(f, &status);
#endif

    // Clean up.
    oskar_imager_free(im, &status);
    oskar_mem_free(uu, &status);
    oskar_mem_free(vv, &status);
    oskar_mem_free(ww, &status);
    oskar_mem_free(vis, &status);
    oskar_mem_free(weight, &status);
    oskar_mem_free(grid, &status);
}