void oskar_imager_init_dft(oskar_Imager* h, int* status) { int num_pixels; oskar_imager_free_dft(h, status); if (*status) return; /* Calculate pixel coordinate grid required for the DFT imager. */ num_pixels = h->image_size * h->image_size; h->l = oskar_mem_create(h->imager_prec, OSKAR_CPU, num_pixels, status); h->m = oskar_mem_create(h->imager_prec, OSKAR_CPU, num_pixels, status); h->n = oskar_mem_create(h->imager_prec, OSKAR_CPU, num_pixels, status); oskar_evaluate_image_lmn_grid(h->image_size, h->image_size, h->fov_deg * M_PI/180, h->fov_deg * M_PI/180, 0, h->l, h->m, h->n, status); oskar_mem_add_real(h->n, -1.0, status); /* n-1 */ }
void oskar_beam_pattern_generate_coordinates(oskar_BeamPattern* h, int beam_coord_type, int* status) { size_t num_pixels = 0; int nside = 0; /* Check if safe to proceed. */ if (*status) return; /* If memory is already allocated, do nothing. */ if (h->x) return; /* Calculate number of pixels if possible. */ if (h->coord_grid_type == 'B') /* Beam image */ { num_pixels = h->width * h->height; } else if (h->coord_grid_type == 'H') /* Healpix */ { nside = h->nside; num_pixels = 12 * nside * nside; } else if (h->coord_grid_type == 'S') /* Sky model */ num_pixels = 0; else { *status = OSKAR_ERR_INVALID_ARGUMENT; return; } /* Create output arrays. */ h->x = oskar_mem_create(h->prec, OSKAR_CPU, num_pixels, status); h->y = oskar_mem_create(h->prec, OSKAR_CPU, num_pixels, status); h->z = oskar_mem_create(h->prec, OSKAR_CPU, num_pixels, status); /* Get equatorial or horizon coordinates. */ if (h->coord_frame_type == 'E') { /* * Equatorial coordinates. */ switch (h->coord_grid_type) { case 'B': /* Beam image */ { oskar_evaluate_image_lmn_grid(h->width, h->height, h->fov_deg[0]*(M_PI/180.0), h->fov_deg[1]*(M_PI/180.0), 1, h->x, h->y, h->z, status); break; } case 'H': /* Healpix */ { int num_points, type, i; double ra0 = 0.0, dec0 = 0.0; oskar_Mem *theta, *phi; /* Generate theta and phi from nside. */ num_points = 12 * nside * nside; type = oskar_mem_type(h->x); theta = oskar_mem_create(type, OSKAR_CPU, num_points, status); phi = oskar_mem_create(type, OSKAR_CPU, num_points, status); oskar_convert_healpix_ring_to_theta_phi(nside, theta, phi, status); /* Convert theta from polar angle to elevation. */ if (type == OSKAR_DOUBLE) { double* theta_ = oskar_mem_double(theta, status); for (i = 0; i < num_points; ++i) theta_[i] = 90.0 - theta_[i]; } else if (type == OSKAR_SINGLE) { float* theta_ = oskar_mem_float(theta, status); for (i = 0; i < num_points; ++i) theta_[i] = 90.0f - theta_[i]; } else { *status = OSKAR_ERR_BAD_DATA_TYPE; } /* Evaluate beam phase centre coordinates in equatorial frame. */ if (beam_coord_type == OSKAR_SPHERICAL_TYPE_EQUATORIAL) { ra0 = oskar_telescope_phase_centre_ra_rad(h->tel); dec0 = oskar_telescope_phase_centre_dec_rad(h->tel); } else if (beam_coord_type == OSKAR_SPHERICAL_TYPE_AZEL) { /* TODO convert from az0, el0 to ra0, dec0 */ *status = OSKAR_FAIL; } else { *status = OSKAR_ERR_INVALID_ARGUMENT; } /* Convert equatorial angles to direction cosines in the frame * of the beam phase centre. */ oskar_convert_lon_lat_to_relative_directions(num_points, phi, theta, ra0, dec0, h->x, h->y, h->z, status); /* Free memory. */ oskar_mem_free(theta, status); oskar_mem_free(phi, status); break; } case 'S': /* Sky model */ { oskar_Mem *ra, *dec; int type = 0, num_points = 0; type = oskar_mem_type(h->x); ra = oskar_mem_create(type, OSKAR_CPU, 0, status); dec = oskar_mem_create(type, OSKAR_CPU, 0, status); load_coords(ra, dec, h->sky_model_file, status); num_points = oskar_mem_length(ra); oskar_mem_realloc(h->x, num_points, status); oskar_mem_realloc(h->y, num_points, status); oskar_mem_realloc(h->z, num_points, status); oskar_convert_lon_lat_to_relative_directions( num_points, ra, dec, oskar_telescope_phase_centre_ra_rad(h->tel), oskar_telescope_phase_centre_dec_rad(h->tel), h->x, h->y, h->z, status); oskar_mem_free(ra, status); oskar_mem_free(dec, status); break; } default: *status = OSKAR_ERR_INVALID_ARGUMENT; break; }; /* Set the return values. */ h->coord_type = OSKAR_RELATIVE_DIRECTIONS; h->lon0 = oskar_telescope_phase_centre_ra_rad(h->tel); h->lat0 = oskar_telescope_phase_centre_dec_rad(h->tel); } else if (h->coord_frame_type == 'H') { /* * Horizon coordinates. */ switch (h->coord_grid_type) { case 'B': /* Beam image */ { /* NOTE: This is for an all-sky image centred on the zenith. */ oskar_evaluate_image_lmn_grid(h->width, h->height, M_PI, M_PI, 1, h->x, h->y, h->z, status); break; } case 'H': /* Healpix */ { int num_points, type; oskar_Mem *theta, *phi; num_points = 12 * nside * nside; type = oskar_mem_type(h->x); theta = oskar_mem_create(type, OSKAR_CPU, num_points, status); phi = oskar_mem_create(type, OSKAR_CPU, num_points, status); oskar_convert_healpix_ring_to_theta_phi(nside, theta, phi, status); oskar_convert_theta_phi_to_enu_directions(num_points, theta, phi, h->x, h->y, h->z, status); oskar_mem_free(theta, status); oskar_mem_free(phi, status); break; } default: *status = OSKAR_ERR_INVALID_ARGUMENT; break; }; /* Set the return values. */ h->coord_type = OSKAR_ENU_DIRECTIONS; h->lon0 = 0.0; h->lat0 = M_PI / 2.0; } else { *status = OSKAR_ERR_INVALID_ARGUMENT; } /* Set the number of pixels. */ h->num_pixels = oskar_mem_length(h->x); }