Skip to content

Commit

Permalink
Merge pull request #35 from kateharborne/dev-MemoryBug
Browse files Browse the repository at this point in the history
dev-MemoryBug
  • Loading branch information
kateharborne committed Mar 14, 2022
2 parents 25273b3 + a805c6a commit 6a4c46f
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 50 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: SimSpin
Type: Package
Title: SimSpin - A package for the kinematic analysis of galaxy simulations
Version: 2.1.3
Version: 2.1.4
Author: Katherine Harborne
Maintainer: <katherine.harborne@icrar.org>
Description: The purpose of this package is to provide a set of tools to "observe" simulations of galaxies as if you were an observer using an integral field unit (IFU). The galaxy model can be observed at a chosen inclination and an IFU observation can be produced in a selection of different spatial shapes (square, circular, and hexagonal) to account for the variety of CCD arrangements used by current telescopes. This data cube can be used to calculate the value an observer would measure for the spin parameter compared to the value that is measured directly from the simulation.
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SimSpin v2.1.3 News
# SimSpin v2.1.4 News
### Author: Kate Harborne
### Last edit: 03/03/22

Expand Down Expand Up @@ -36,3 +36,4 @@ Below is a table containing a summary of all changes made to SimSpin, since the
| | (2) Modifying the EXTNAME for the HDU associated with the "raw" particle data (now prefixed with `"RAW_"`) and the "observed" collapsed velocity data cubes (now prefixed with `"OBS_").` | | |
| | (3) Update to the depends version number of R. Now requires R >= 4.0. This is to enable the generation of a container for the web application of SimSpin. | | |
| 03/03/22 | *Minor bugfix*. Specifying branch of ProSpect in the remotes installation. | 2.1.3 | a8b45bafa139304ee5d66d559b9b1cb0f510e365 |
| 14/03/22 | *Minor bugfix*. Specifying all initialised arrays with the correct type (rather than initiallised `NA`s) to imporve code memory handling and speed. | 2.1.4 | |
10 changes: 5 additions & 5 deletions R/blur_datacube.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ blur_datacube = function(datacube_output){
aperture_region = matrix(data = calc_region, nrow = cube_dims[1], ncol=cube_dims[2])

# 1. Blurring each plane of the spectral datacube
blur_cube = array(data = NA, dim = cube_dims)
blur_cube = array(data = 0.0, dim = cube_dims)
for (spatial_plane in seq(1, dim(cube)[3])){
blur_cube[,,spatial_plane] = ProFit::profitBruteConv(cube[,,spatial_plane], observation$psf_kernel) * aperture_region
}
Expand All @@ -72,7 +72,7 @@ blur_datacube = function(datacube_output){
aperture_region = matrix(data = calc_region, nrow = cube_dims[1], ncol=cube_dims[2])

# 1. Blurring each plane of the velocity datacube
blur_cube = array(data = NA, dim = cube_dims)
blur_cube = array(data = 0.0, dim = cube_dims)
for (spatial_plane in seq(1, cube_dims[3])){
blur_cube[,,spatial_plane] = ProFit::profitBruteConv(cube[,,spatial_plane], observation$psf_kernel) * aperture_region
}
Expand All @@ -87,9 +87,9 @@ blur_datacube = function(datacube_output){

# 2. Recompute the velocity and dispersion images from the blurred cube.
# Initializing empty arrays
blur_flux = array(NA, dim = c(cube_dims[c(1,2)]))
blur_velocity = array(NA, dim = c(cube_dims[c(1,2)]))
blur_dispersion = array(NA, dim = c(cube_dims[c(1,2)]))
blur_flux = array(0.0, dim = c(cube_dims[c(1,2)]))
blur_velocity = array(0.0, dim = c(cube_dims[c(1,2)]))
blur_dispersion = array(0.0, dim = c(cube_dims[c(1,2)]))

# Filling array based on blurred cubes
for (c in 1:cube_dims[1]){
Expand Down
12 changes: 6 additions & 6 deletions R/build_datacube.R
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ build_datacube = function(simspin_file, telescope, observing_strategy,
dims = dim(output$raw_images$velocity_image)

names(output$observed_images) = c("flux_image", "velocity_image", "dispersion_image") # default calling flux/mass as flux_image
output$observed_images$flux_image = array(NA, dim = dims[c(1,2)])
output$observed_images$velocity_image = array(NA, dim = dims[c(1,2)])
output$observed_images$dispersion_image = array(NA, dim = dims[c(1,2)])
output$observed_images$flux_image = array(0.0, dim = dims[c(1,2)])
output$observed_images$velocity_image = array(0.0, dim = dims[c(1,2)])
output$observed_images$dispersion_image = array(0.0, dim = dims[c(1,2)])

for (c in 1:dims[1]){
for (d in 1:dims[2]){
Expand Down Expand Up @@ -273,9 +273,9 @@ build_datacube = function(simspin_file, telescope, observing_strategy,
dims = dim(output$raw_images$velocity_image)

names(output$observed_images) = c("mass_image", "velocity_image", "dispersion_image")
output$observed_images$mass_image = array(NA, dim = dims[c(1,2)])
output$observed_images$velocity_image = array(NA, dim = dims[c(1,2)])
output$observed_images$dispersion_image = array(NA, dim = dims[c(1,2)])
output$observed_images$mass_image = array(0.0, dim = dims[c(1,2)])
output$observed_images$velocity_image = array(0.0, dim = dims[c(1,2)])
output$observed_images$dispersion_image = array(0.0, dim = dims[c(1,2)])

for (c in 1:dims[1]){
for (d in 1:dims[2]){
Expand Down
72 changes: 36 additions & 36 deletions R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@

ellip_radius = sqrt((x*x) + ((y/p)*(y/p)) + ((z/q)*(z/q)))

M = array(data = NA, dim = c(3,3))
M = array(data = 0.0, dim = c(3,3))

M[1,1] = sum((galaxy_data$Mass * x * x) / ellip_radius)
M[1,2] = sum((galaxy_data$Mass * x * y) / ellip_radius)
Expand Down Expand Up @@ -753,7 +753,7 @@
"lohi" = Z[3] * A[4],
"lolo" = Z[3] * A[3])

part_spec = array(data = NA, dim = c(1, length(Template$Wave)))
part_spec = array(data = 0.0, dim = c(1, length(Template$Wave)))

part_spec = ((Template$Zspec[[Z[2]]][A[2],] * weights$hihi) +
(Template$Zspec[[Z[2]]][A[1],] * weights$hilo) +
Expand Down Expand Up @@ -786,7 +786,7 @@
}

.circular_ap=function(sbin){
ap_region = matrix(data = NA, ncol = sbin, nrow = sbin)# empty matrix for aperture mask
ap_region = matrix(data = 0, ncol = sbin, nrow = sbin)# empty matrix for aperture mask
xcentre = sbin/2 + 0.5; ycentre = sbin/2 + 0.5
x = matrix(data = rep(seq(1,sbin), each=sbin), nrow = sbin, ncol = sbin)
y = matrix(data = rep(seq(sbin,1), sbin), nrow = sbin, ncol = sbin)
Expand All @@ -797,7 +797,7 @@
}

.hexagonal_ap=function(sbin){
ap_region = matrix(data = NA, ncol = sbin, nrow = sbin)# empty matrix for aperture mask
ap_region = matrix(data = 0, ncol = sbin, nrow = sbin)# empty matrix for aperture mask
xcentre = sbin/2 + 0.5; ycentre = sbin/2 + 0.5
for (x in 1:sbin){
for (y in 1:sbin){
Expand Down Expand Up @@ -874,10 +874,10 @@
# spectral mode -
.spectral_spaxels = function(part_in_spaxel, wavelength, observation, galaxy_data, simspin_data, verbose){

spectra = matrix(data = NA, ncol = observation$wave_bin, nrow = observation$sbin^2)
vel_los = array(data = NA, dim = observation$sbin^2)
dis_los = array(data = NA, dim = observation$sbin^2)
lum_map = array(data = NA, dim = observation$sbin^2)
spectra = matrix(data = 0.0, ncol = observation$wave_bin, nrow = observation$sbin^2)
vel_los = array(data = 0.0, dim = observation$sbin^2)
dis_los = array(data = 0.0, dim = observation$sbin^2)
lum_map = array(data = 0.0, dim = observation$sbin^2)
part_map = array(data=0, dim = observation$sbin^2)

for (i in 1:(dim(part_in_spaxel)[1])){ # computing the spectra at each occupied spatial pixel position
Expand Down Expand Up @@ -933,10 +933,10 @@

.spectral_spaxels_mc = function(part_in_spaxel, wavelength, observation, galaxy_data, simspin_data, verbose, cores){

spectra = matrix(data = NA, ncol = observation$wave_bin, nrow = observation$sbin^2)
vel_los = array(data = NA, dim = observation$sbin^2)
dis_los = array(data = NA, dim = observation$sbin^2)
lum_map = array(data = NA, dim = observation$sbin^2)
spectra = matrix(data = 0.0, ncol = observation$wave_bin, nrow = observation$sbin^2)
vel_los = array(data = 0.0, dim = observation$sbin^2)
dis_los = array(data = 0.0, dim = observation$sbin^2)
lum_map = array(data = 0.0, dim = observation$sbin^2)
part_map = array(data=0, dim = observation$sbin^2)

doParallel::registerDoParallel(cores)
Expand Down Expand Up @@ -1007,11 +1007,11 @@
.velocity_spaxels = function(part_in_spaxel, observation, galaxy_data, simspin_data, verbose, mass_flag){

vel_spec = matrix(data = 0, ncol = observation$vbin, nrow = observation$sbin^2)
vel_los = array(data = NA, dim = observation$sbin^2)
dis_los = array(data = NA, dim = observation$sbin^2)
lum_map = array(data = NA, dim = observation$sbin^2)
age_map = array(data = NA, dim = observation$sbin^2)
met_map = array(data = NA, dim = observation$sbin^2)
vel_los = array(data = 0.0, dim = observation$sbin^2)
dis_los = array(data = 0.0, dim = observation$sbin^2)
lum_map = array(data = 0.0, dim = observation$sbin^2)
age_map = array(data = 0.0, dim = observation$sbin^2)
met_map = array(data = 0.0, dim = observation$sbin^2)
part_map = array(data=0, dim = observation$sbin^2)

for (i in 1:(dim(part_in_spaxel)[1])){
Expand Down Expand Up @@ -1069,11 +1069,11 @@
.velocity_spaxels_mc = function(part_in_spaxel, observation, galaxy_data, simspin_data, verbose, cores, mass_flag){

vel_spec = matrix(data = 0, ncol = observation$vbin, nrow = observation$sbin^2)
vel_los = array(data = NA, dim = observation$sbin^2)
dis_los = array(data = NA, dim = observation$sbin^2)
lum_map = array(data = NA, dim = observation$sbin^2)
age_map = array(data = NA, dim = observation$sbin^2)
met_map = array(data = NA, dim = observation$sbin^2)
vel_los = array(data = 0.0, dim = observation$sbin^2)
dis_los = array(data = 0.0, dim = observation$sbin^2)
lum_map = array(data = 0.0, dim = observation$sbin^2)
age_map = array(data = 0.0, dim = observation$sbin^2)
met_map = array(data = 0.0, dim = observation$sbin^2)
part_map = array(data=0, dim = observation$sbin^2)

doParallel::registerDoParallel(cores)
Expand Down Expand Up @@ -1142,13 +1142,13 @@
# gas velocity mode -
.gas_velocity_spaxels = function(part_in_spaxel, observation, galaxy_data, simspin_data, verbose){

vel_spec = matrix(data = 0, ncol = observation$vbin, nrow = observation$sbin^2)
vel_los = array(data = NA, dim = observation$sbin^2)
dis_los = array(data = NA, dim = observation$sbin^2)
mass_map = array(data = NA, dim = observation$sbin^2)
SFR_map = array(data = NA, dim = observation$sbin^2)
Z_map = array(data = NA, dim = observation$sbin^2)
OH_map = array(data = NA, dim = observation$sbin^2)
vel_spec = matrix(data = 0.0, ncol = observation$vbin, nrow = observation$sbin^2)
vel_los = array(data = 0.0, dim = observation$sbin^2)
dis_los = array(data = 0.0, dim = observation$sbin^2)
mass_map = array(data = 0.0, dim = observation$sbin^2)
SFR_map = array(data = 0.0, dim = observation$sbin^2)
Z_map = array(data = 0.0, dim = observation$sbin^2)
OH_map = array(data = 0.0, dim = observation$sbin^2)

for (i in 1:(dim(part_in_spaxel)[1])){

Expand Down Expand Up @@ -1185,13 +1185,13 @@

.gas_velocity_spaxels_mc = function(part_in_spaxel, observation, galaxy_data, simspin_data, verbose, cores){

vel_spec = matrix(data = 0, ncol = observation$vbin, nrow = observation$sbin^2)
vel_los = array(data = NA, dim = observation$sbin^2)
dis_los = array(data = NA, dim = observation$sbin^2)
mass_map = array(data = NA, dim = observation$sbin^2)
SFR_map = array(data = NA, dim = observation$sbin^2)
Z_map = array(data = NA, dim = observation$sbin^2)
OH_map = array(data = NA, dim = observation$sbin^2)
vel_spec = matrix(data = 0.0, ncol = observation$vbin, nrow = observation$sbin^2)
vel_los = array(data = 0.0, dim = observation$sbin^2)
dis_los = array(data = 0.0, dim = observation$sbin^2)
mass_map = array(data = 0.0, dim = observation$sbin^2)
SFR_map = array(data = 0.0, dim = observation$sbin^2)
Z_map = array(data = 0.0, dim = observation$sbin^2)
OH_map = array(data = 0.0, dim = observation$sbin^2)

doParallel::registerDoParallel(cores)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<p>&nbsp;</p>

SimSpin v2.1.3 - A package for producing mock observations of particle simulations
SimSpin v2.1.4 - A package for producing mock observations of particle simulations

The purpose of the SimSpin R-package is to take a particle simulation of a galaxy and produce a spectral data cube in the style of a specified Integral Field Spectroscopy (IFS) instrument.

Expand Down

0 comments on commit 6a4c46f

Please sign in to comment.