From e6c2bf433be755cbfb331d508609ace6a201682a Mon Sep 17 00:00:00 2001 From: kateharborne Date: Wed, 13 Mar 2024 13:32:56 +0800 Subject: [PATCH 01/12] If a mass-weighted kinematic cube is requested, also provide the psf-convolved observed mass map in the `observed_images` output list. This adds an extra output if `mass_flag == T`. --- R/build_datacube.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/build_datacube.R b/R/build_datacube.R index b249ad7..6ce2d5c 100644 --- a/R/build_datacube.R +++ b/R/build_datacube.R @@ -441,6 +441,10 @@ build_datacube = function(simspin_file, telescope, observing_strategy, "observed_images" = observed_images, "variance_cube" = NULL) + if (mass_flag){ + output$observed_images$mass_image = array(data = summed_images$mass, dim = c(observation$sbin, observation$sbin)) + } # ensures that the observed mass image is blurred with the same kernel + if (observation$psf_fwhm > 0){ if (verbose){cat("Convolving cube with PSF... \n") } output = blur_datacube(output) # apply psf convolution to each cube plane From 95258fa8f9c8a1eccd71d3b601ba0bcd90afc157 Mon Sep 17 00:00:00 2001 From: kateharborne Date: Wed, 13 Mar 2024 13:33:24 +0800 Subject: [PATCH 02/12] Ensuring that the added observed mass map is convolved with the PSF. --- R/blur_datacube.R | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/R/blur_datacube.R b/R/blur_datacube.R index c0855e5..1b30c15 100644 --- a/R/blur_datacube.R +++ b/R/blur_datacube.R @@ -83,6 +83,12 @@ blur_datacube = function(datacube_output){ blur_image = ProFit::profitBruteConv(datacube_output$observed_images$flux_image, observation$psf_kernel) * aperture_region datacube_output$observed_images$flux_image = blur_image + if (observation$mass_flag){ # ensuring "observed" mass map images are also blurred with the psf kernel + blur_image = array(data = 0.0, dim = cube_dims[c(1,2)]) + blur_image = ProFit::profitBruteConv(datacube_output$observed_images$mass_image, observation$psf_kernel) * aperture_region + datacube_output$observed_images$mass_image = blur_image + } + # Returning output in same format as input blur_output = list("velocity_cube" = blur_cube, "observation" = observation, From 5c17cfef3328af3e14cfe0c014aa544672baf799 Mon Sep 17 00:00:00 2001 From: kateharborne Date: Wed, 13 Mar 2024 13:33:40 +0800 Subject: [PATCH 03/12] Updated version number to reflect small change made. --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4bbd791..b21e274 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: SimSpin Type: Package Title: SimSpin - A package for the kinematic analysis of galaxy simulations -Version: 2.8.2 +Version: 2.8.3 Author: Katherine Harborne Co-author: Alice Serene Maintainer: From d8828d6990ca7d7bfd20651f75ca4823183d515f Mon Sep 17 00:00:00 2001 From: kateharborne Date: Wed, 13 Mar 2024 13:38:32 +0800 Subject: [PATCH 04/12] Updating NEWS to reflect new additions. --- NEWS.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index fa63a0a..c19824c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ -# SimSpin v2.8.2 News +# SimSpin v2.8.3 News -### Last edit: 29/02/2024 +### Last edit: 13/03/2024 Below is a table containing a summary of all changes made to SimSpin, since the date this file was created on 26/08/2021. @@ -16,7 +16,8 @@ All changes are noted in the changelog table below. | Date | Summary of change | Version | Commit | Author | |---------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |--------- |------------------------------------------ | ----------------- | -| 29/02/24 | *Bug fix.* Updating `make_simspin_file` to account for the `Time` at which the input simulation was extracted (for proper assignment of stellar ages relative to the snapshot, not z=0). Fixing issue #98.| 2.8.2 | | Kate Harborne | +| 13/03/24 | Adding observation-ally mapped mass images to the output `$observed_images` when `mass_flag = T` - the raw images are not blurred with the PSF, and for comparison with other properties, this must be made consistent. | 2.8.3 | | Kate Harborne | +| 29/02/24 | *Bug fix.* Updating `make_simspin_file` to account for the `Time` at which the input simulation was extracted (for proper assignment of stellar ages relative to the snapshot, not z=0). Fixing issue #98.| 2.8.2 | 0469ff454756e7b6195bf927b7c867fd02f20743 | Kate Harborne | | 10/01/24 | Also updating treatment for `mass_flag` = TRUE. No longer will the `observed_images` outputs change for the flag, the flux map will always be included. However, the kinematic maps observed will be weighted differently (by mass instead of the flux), which is now recorded in the `observation` log and output to FITS with a new header unit denoting mass rather than flux weighting. | 2.8.1 | 352c5601b04767e10d2598358b164f1b203a8d54 | Kate Harborne | | 10/01/24 | Standardising which cubes/images output are voronoi binned. Properties, such as the mass, flux and number of particles, are produced simply as the sum along that line-of-sight and as such should be presented at the pixel resolution of the instrument. As default, summed images are now given in this way, while any spectral/velocity cubes are binned along with any output average maps (kinematics such as velocity, dispersion, h3 and h4, metallicity and age). The same is done for gas maps, with all but the mass, SFR and particle number being given in binned form when the voronoi function is turned on. Also, added `raw_images$mass_image` to the output of spectral mode as this is now "free"" to produce. | 2.8.0 | 5af1ad3a90c7f84a55e6f9cb50492308fd422d7a | Kate Harborne | | 17/11/23 | Bug fix. The mass/flux in voronoi binned pixels were displayed as the sum of all the particles that fell within that bin. Now updated so that this value is averaged across the area of the bin (else outer larger bins appear brighter than inner ones...). Fixing issue #91. | 2.7.1 | e93c763c40ec670da58b37a353586887d0b34143 | Kate Harborne | From 5be04f0d3517736cf5a3c28e6d699a0d615c4216 Mon Sep 17 00:00:00 2001 From: kateharborne Date: Wed, 13 Mar 2024 13:45:00 +0800 Subject: [PATCH 05/12] Adding an "observed" mass image to all outputs rather than just those with `mass_flag = T` so that this resource is provided for stellar flux maps too. --- R/blur_datacube.R | 8 +++----- R/build_datacube.R | 7 ++----- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/R/blur_datacube.R b/R/blur_datacube.R index 1b30c15..bf252cf 100644 --- a/R/blur_datacube.R +++ b/R/blur_datacube.R @@ -83,11 +83,9 @@ blur_datacube = function(datacube_output){ blur_image = ProFit::profitBruteConv(datacube_output$observed_images$flux_image, observation$psf_kernel) * aperture_region datacube_output$observed_images$flux_image = blur_image - if (observation$mass_flag){ # ensuring "observed" mass map images are also blurred with the psf kernel - blur_image = array(data = 0.0, dim = cube_dims[c(1,2)]) - blur_image = ProFit::profitBruteConv(datacube_output$observed_images$mass_image, observation$psf_kernel) * aperture_region - datacube_output$observed_images$mass_image = blur_image - } + blur_mass_image = array(data = 0.0, dim = cube_dims[c(1,2)]) + blur_mass_image = ProFit::profitBruteConv(datacube_output$observed_images$mass_image, observation$psf_kernel) * aperture_region + datacube_output$observed_images$mass_image = blur_mass_image # Returning output in same format as input blur_output = list("velocity_cube" = blur_cube, diff --git a/R/build_datacube.R b/R/build_datacube.R index 6ce2d5c..731b04b 100644 --- a/R/build_datacube.R +++ b/R/build_datacube.R @@ -432,7 +432,8 @@ build_datacube = function(simspin_file, telescope, observing_strategy, dispersion_image = array(0.0, dim = c(observation$sbin, observation$sbin)), h3_image = array(0.0, dim = c(observation$sbin, observation$sbin)), h4_image = array(0.0, dim = c(observation$sbin, observation$sbin)), - residuals = array(0.0, dim = c(observation$sbin, observation$sbin)) + residuals = array(0.0, dim = c(observation$sbin, observation$sbin)), + mass_image = array(data = summed_images$mass, dim = c(observation$sbin, observation$sbin)) ) output = list("velocity_cube" = cube, @@ -441,10 +442,6 @@ build_datacube = function(simspin_file, telescope, observing_strategy, "observed_images" = observed_images, "variance_cube" = NULL) - if (mass_flag){ - output$observed_images$mass_image = array(data = summed_images$mass, dim = c(observation$sbin, observation$sbin)) - } # ensures that the observed mass image is blurred with the same kernel - if (observation$psf_fwhm > 0){ if (verbose){cat("Convolving cube with PSF... \n") } output = blur_datacube(output) # apply psf convolution to each cube plane From 6a0a6cbfbe7e8c1ef4314340eba7a66def46161d Mon Sep 17 00:00:00 2001 From: kateharborne Date: Wed, 13 Mar 2024 16:53:26 +0800 Subject: [PATCH 06/12] Rather than blur gas images which have been temporarily named as "flux_image", just default apply convolution to observed mass images and only flux if stellar obs. --- R/blur_datacube.R | 8 +++++--- R/build_datacube.R | 4 +--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/R/blur_datacube.R b/R/blur_datacube.R index bf252cf..1160dd7 100644 --- a/R/blur_datacube.R +++ b/R/blur_datacube.R @@ -79,9 +79,11 @@ blur_datacube = function(datacube_output){ } # 2. Blurring the observed flux map - blur_image = array(data = 0.0, dim = cube_dims[c(1,2)]) - blur_image = ProFit::profitBruteConv(datacube_output$observed_images$flux_image, observation$psf_kernel) * aperture_region - datacube_output$observed_images$flux_image = blur_image + if (observation$method == "velocity"){ # if your observation is of stars, blur the flux map + blur_image = array(data = 0.0, dim = cube_dims[c(1,2)]) + blur_image = ProFit::profitBruteConv(datacube_output$observed_images$flux_image, observation$psf_kernel) * aperture_region + datacube_output$observed_images$flux_image = blur_image + } blur_mass_image = array(data = 0.0, dim = cube_dims[c(1,2)]) blur_mass_image = ProFit::profitBruteConv(datacube_output$observed_images$mass_image, observation$psf_kernel) * aperture_region diff --git a/R/build_datacube.R b/R/build_datacube.R index 731b04b..67a871b 100644 --- a/R/build_datacube.R +++ b/R/build_datacube.R @@ -533,7 +533,7 @@ build_datacube = function(simspin_file, telescope, observing_strategy, voronoi_bins = array(data = output[[6]], dim = c(observation$sbin, observation$sbin)) ) observed_images = list( - flux_image = array(data = summed_images$mass, dim = c(observation$sbin, observation$sbin)), + mass_image = array(data = summed_images$mass, dim = c(observation$sbin, observation$sbin)), velocity_image = array(0.0, dim = c(observation$sbin, observation$sbin)), dispersion_image = array(0.0, dim = c(observation$sbin, observation$sbin)), h3_image = array(0.0, dim = c(observation$sbin, observation$sbin)), @@ -597,8 +597,6 @@ build_datacube = function(simspin_file, telescope, observing_strategy, } } - names(output$observed_images)[which(names(output$observed_images) == "flux_image")] = "mass_image" - if (verbose){cat("Done! \n")} } From 6ac07e4ac4191e14794a252e08708dbf7f1a42e6 Mon Sep 17 00:00:00 2001 From: kateharborne Date: Wed, 13 Mar 2024 16:53:51 +0800 Subject: [PATCH 07/12] Write blurred observed mass images to file. --- R/write_simspin_FITS.R | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/R/write_simspin_FITS.R b/R/write_simspin_FITS.R index 480d51a..ee46560 100644 --- a/R/write_simspin_FITS.R +++ b/R/write_simspin_FITS.R @@ -532,39 +532,39 @@ write_simspin_FITS = function(output_file, simspin_datacube, object_name, "EXTNAME"="Image extension name") extnames = if (voronoi){ - c("OBS_FLUX", "OBS_VEL", "OBS_DISP", "OBS_H3", "OBS_H4", "RESIDUAL", "RAW_FLUX", "RAW_MASS", "RAW_VEL", "RAW_DISP", "RAW_AGE", "RAW_Z", "NPART", "VORONOI") + c("OBS_FLUX", "OBS_VEL", "OBS_DISP", "OBS_H3", "OBS_H4", "RESIDUAL", "OBS_MASS", "RAW_FLUX", "RAW_MASS", "RAW_VEL", "RAW_DISP", "RAW_AGE", "RAW_Z", "NPART", "VORONOI") } else { - c("OBS_FLUX", "OBS_VEL", "OBS_DISP", "OBS_H3", "OBS_H4", "RESIDUAL", "RAW_FLUX", "RAW_MASS", "RAW_VEL", "RAW_DISP", "RAW_AGE", "RAW_Z", "NPART") + c("OBS_FLUX", "OBS_VEL", "OBS_DISP", "OBS_H3", "OBS_H4", "RESIDUAL", "OBS_MASS", "RAW_FLUX", "RAW_MASS", "RAW_VEL", "RAW_DISP", "RAW_AGE", "RAW_Z", "NPART") } bunits = if (voronoi){ - c("erg/s/cm**2", "km/s", "km/s", "unitless", "unitless", "percentage", "erg/s/cm**2", "Msol", "km/s", "km/s", "Gyr", "Z_solar", "Particle number", "Bin ID") + c("erg/s/cm**2", "km/s", "km/s", "unitless", "unitless", "percentage", "Msol", "erg/s/cm**2", "Msol", "km/s", "km/s", "Gyr", "Z_solar", "Particle number", "Bin ID") } else { - c("erg/s/cm**2", "km/s", "km/s", "unitless", "unitless", "percentage", "erg/s/cm**2", "Msol", "km/s", "km/s", "Gyr", "Z_solar", "Particle number") + c("erg/s/cm**2", "km/s", "km/s", "unitless", "unitless", "percentage", "Msol", "erg/s/cm**2", "Msol", "km/s", "km/s", "Gyr", "Z_solar", "Particle number") } image_names = if (voronoi){ - c("flux_image", "velocity_image", "dispersion_image", "h3_image", "h4_image", "residuals", + c("flux_image", "velocity_image", "dispersion_image", "h3_image", "h4_image", "residuals", "mass_image", "flux_image", "mass_image", "velocity_image", "dispersion_image", "age_image", "metallicity_image", "particle_image", "voronoi_bins") } else { - c("flux_image", "velocity_image", "dispersion_image", "h3_image", "h4_image", "residuals", + c("flux_image", "velocity_image", "dispersion_image", "h3_image", "h4_image", "residuals", "mass_image", "flux_image", "mass_image", "velocity_image", "dispersion_image", "age_image", "metallicity_image", "particle_image") } rawobs = if (voronoi){ - c("obs", "obs", "obs", "obs", "obs", "obs", "raw", "raw", "raw", "raw", "raw", "raw", "raw", "raw") + c("obs", "obs", "obs", "obs", "obs", "obs", "obs", "raw", "raw", "raw", "raw", "raw", "raw", "raw", "raw") } else { - c("obs", "obs", "obs", "obs", "obs", "obs", "raw", "raw", "raw", "raw", "raw", "raw", "raw") + c("obs", "obs", "obs", "obs", "obs", "obs", "obs", "raw", "raw", "raw", "raw", "raw", "raw", "raw") } output_image_file_names = paste0(output_dir, "/", output_file_root, "_", rawobs, "_", image_names, ".FITS") extnum = if (voronoi){ - c(4,5,6,7,8,9,10,11,12,13,14,15,16,17) + c(4,5,6,7,8,9,10,11,12,13,14,15,16,17,18) } else { - c(4,5,6,7,8,9,10,11,12,13,14,15,16) + c(4,5,6,7,8,9,10,11,12,13,14,15,16,17) } if (split_save){ # if writing each image to a seperate file From 4e00c6bcffeb676182eaffe4bd54fe31f7be6916 Mon Sep 17 00:00:00 2001 From: kateharborne Date: Wed, 13 Mar 2024 16:54:08 +0800 Subject: [PATCH 08/12] Updating the new numbers of images and written HDU. --- tests/testthat/test_build_datacube.R | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/testthat/test_build_datacube.R b/tests/testthat/test_build_datacube.R index c6f94d9..99bb8b3 100644 --- a/tests/testthat/test_build_datacube.R +++ b/tests/testthat/test_build_datacube.R @@ -34,16 +34,17 @@ spectra_number_of_hdu_snfalse = 10 spectral_raw_vel_loc = 5 velocity_raw_images_size = 7 -velocity_observed_images_size = 6 +velocity_observed_images_size = 7 -velocity_number_of_hdu_sntrue = 17 -velocity_number_of_hdu_snfalse = 16 +velocity_number_of_hdu_sntrue = 18 +velocity_number_of_hdu_snfalse = 17 velocity_obs_vel_loc = 5 velocity_obs_h3_loc = 7 velocity_obs_h4_loc = 8 velocity_obs_res_loc = 9 -velocity_raw_mass_loc = 11 -velocity_variance_loc = 17 +velocity_obs_mass_loc = 10 +velocity_raw_mass_loc = 12 +velocity_variance_loc = 18 gas_raw_images_size = 7 gas_observed_images_size = 6 @@ -664,6 +665,7 @@ test_that("Data cubes can be written to a single files", { expect_true(file.exists(paste0(temp_loc, "/ss_gadget_mft.FITS"))) expect_true(length(Rfits::Rfits_read(paste0(temp_loc, "/ss_gadget_mft.FITS"))) == velocity_number_of_hdu_sntrue) expect_true(names(Rfits::Rfits_read(paste0(temp_loc, "/ss_gadget_mft.FITS")))[velocity_raw_mass_loc] == "RAW_MASS") + expect_true(names(Rfits::Rfits_read(paste0(temp_loc, "/ss_gadget_mft.FITS")))[velocity_obs_mass_loc] == "OBS_MASS") expect_true(names(Rfits::Rfits_read(paste0(temp_loc, "/ss_gadget_mft.FITS")))[velocity_variance_loc] == "STAT") expect_true(stringr::str_detect(Rfits::Rfits_read_header_raw(paste0(temp_loc, "/ss_gadget_mft.FITS")), "Msol")) From 6c9e27f88fa96a4c9d6a9701f99a3bb6941b10a1 Mon Sep 17 00:00:00 2001 From: kateharborne Date: Wed, 13 Mar 2024 17:28:19 +0800 Subject: [PATCH 09/12] Update version number --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 33d3127..3e2c938 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@

 

-v2.8.2 - A package for producing mock observations: +v2.8.3 - A package for producing mock observations: SimSpin allows you to take a simulation of a galaxy and produce a data cube in the style of an Integral Field Spectroscopy (IFS) instrument. You can find the live documentation for this code at the following [website](https://kateharborne.github.io/SimSpin/). From 354cea3f1bf5ad3032d3ae2aa7221fb8af2b0af0 Mon Sep 17 00:00:00 2001 From: kateharborne Date: Wed, 13 Mar 2024 17:30:24 +0800 Subject: [PATCH 10/12] Clarifying that the blurred mass observations are now added to all observed image outputs run in `method="velocity"` --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index c19824c..a81bc44 100644 --- a/NEWS.md +++ b/NEWS.md @@ -16,7 +16,7 @@ All changes are noted in the changelog table below. | Date | Summary of change | Version | Commit | Author | |---------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |--------- |------------------------------------------ | ----------------- | -| 13/03/24 | Adding observation-ally mapped mass images to the output `$observed_images` when `mass_flag = T` - the raw images are not blurred with the PSF, and for comparison with other properties, this must be made consistent. | 2.8.3 | | Kate Harborne | +| 13/03/24 | Adding observation-ally mapped mass images to the output `$observed_images` - the raw images are not blurred with the PSF, but for comparison with other observed properties, this PSF convolution is necessary. Now output on all `method="velocity"` cubes as default. | 2.8.3 | | Kate Harborne | | 29/02/24 | *Bug fix.* Updating `make_simspin_file` to account for the `Time` at which the input simulation was extracted (for proper assignment of stellar ages relative to the snapshot, not z=0). Fixing issue #98.| 2.8.2 | 0469ff454756e7b6195bf927b7c867fd02f20743 | Kate Harborne | | 10/01/24 | Also updating treatment for `mass_flag` = TRUE. No longer will the `observed_images` outputs change for the flag, the flux map will always be included. However, the kinematic maps observed will be weighted differently (by mass instead of the flux), which is now recorded in the `observation` log and output to FITS with a new header unit denoting mass rather than flux weighting. | 2.8.1 | 352c5601b04767e10d2598358b164f1b203a8d54 | Kate Harborne | | 10/01/24 | Standardising which cubes/images output are voronoi binned. Properties, such as the mass, flux and number of particles, are produced simply as the sum along that line-of-sight and as such should be presented at the pixel resolution of the instrument. As default, summed images are now given in this way, while any spectral/velocity cubes are binned along with any output average maps (kinematics such as velocity, dispersion, h3 and h4, metallicity and age). The same is done for gas maps, with all but the mass, SFR and particle number being given in binned form when the voronoi function is turned on. Also, added `raw_images$mass_image` to the output of spectral mode as this is now "free"" to produce. | 2.8.0 | 5af1ad3a90c7f84a55e6f9cb50492308fd422d7a | Kate Harborne | From c7dc77e92fe4a8ff1845b687a247af2eb2f22371 Mon Sep 17 00:00:00 2001 From: kateharborne Date: Thu, 14 Mar 2024 11:09:58 +0800 Subject: [PATCH 11/12] Adding PSF convolved SFR maps to the output "observed" cubes. --- R/blur_datacube.R | 7 +++++ R/build_datacube.R | 3 ++- R/write_simspin_FITS.R | 40 ++++++++++++++++------------ tests/testthat/test_build_datacube.R | 8 +++--- 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/R/blur_datacube.R b/R/blur_datacube.R index 1160dd7..2c545dd 100644 --- a/R/blur_datacube.R +++ b/R/blur_datacube.R @@ -89,6 +89,13 @@ blur_datacube = function(datacube_output){ blur_mass_image = ProFit::profitBruteConv(datacube_output$observed_images$mass_image, observation$psf_kernel) * aperture_region datacube_output$observed_images$mass_image = blur_mass_image + if (observation$method == "gas" | observation$method == "sf gas"){ # if your observation is of gas, blur the sfr map + blur_sfr_image = array(data = 0.0, dim = cube_dims[c(1,2)]) + blur_sfr_image = ProFit::profitBruteConv(datacube_output$observed_images$SFR_image, observation$psf_kernel) * aperture_region + datacube_output$observed_images$SFR_image = blur_sfr_image + } + + # Returning output in same format as input blur_output = list("velocity_cube" = blur_cube, "observation" = observation, diff --git a/R/build_datacube.R b/R/build_datacube.R index 67a871b..a2f5ce2 100644 --- a/R/build_datacube.R +++ b/R/build_datacube.R @@ -538,7 +538,8 @@ build_datacube = function(simspin_file, telescope, observing_strategy, dispersion_image = array(0.0, dim = c(observation$sbin, observation$sbin)), h3_image = array(0.0, dim = c(observation$sbin, observation$sbin)), h4_image = array(0.0, dim = c(observation$sbin, observation$sbin)), - residuals = array(0.0, dim = c(observation$sbin, observation$sbin)) + residuals = array(0.0, dim = c(observation$sbin, observation$sbin)), + SFR_image = array(data = summed_images$sfr, dim = c(observation$sbin, observation$sbin)) ) output = list("velocity_cube" = cube, diff --git a/R/write_simspin_FITS.R b/R/write_simspin_FITS.R index ee46560..2ab884c 100644 --- a/R/write_simspin_FITS.R +++ b/R/write_simspin_FITS.R @@ -544,19 +544,23 @@ write_simspin_FITS = function(output_file, simspin_datacube, object_name, } image_names = if (voronoi){ - c("flux_image", "velocity_image", "dispersion_image", "h3_image", "h4_image", "residuals", "mass_image", + c("flux_image", "velocity_image", "dispersion_image", "h3_image", "h4_image", + "residuals", "mass_image", "flux_image", "mass_image", "velocity_image", "dispersion_image", "age_image", "metallicity_image", "particle_image", "voronoi_bins") } else { - c("flux_image", "velocity_image", "dispersion_image", "h3_image", "h4_image", "residuals", "mass_image", + c("flux_image", "velocity_image", "dispersion_image", "h3_image", "h4_image", + "residuals", "mass_image", "flux_image", "mass_image", "velocity_image", "dispersion_image", "age_image", "metallicity_image", "particle_image") } rawobs = if (voronoi){ - c("obs", "obs", "obs", "obs", "obs", "obs", "obs", "raw", "raw", "raw", "raw", "raw", "raw", "raw", "raw") + c("obs", "obs", "obs", "obs", "obs", "obs", "obs", + "raw", "raw", "raw", "raw", "raw", "raw", "raw", "raw") } else { - c("obs", "obs", "obs", "obs", "obs", "obs", "obs", "raw", "raw", "raw", "raw", "raw", "raw", "raw") + c("obs", "obs", "obs", "obs", "obs", "obs", "obs", + "raw", "raw", "raw", "raw", "raw", "raw", "raw") } output_image_file_names = paste0(output_dir, "/", output_file_root, "_", rawobs, "_", image_names, ".FITS") @@ -578,7 +582,7 @@ write_simspin_FITS = function(output_file, simspin_datacube, object_name, image_keyvalues$BUNIT = bunits[i] image_keyvalues$EXTNAME = extnames[i] - if (i < 7){ # 2. Write the image to this new file HDU 2 + if (i < 8){ # 2. Write the image to this new file HDU 2 Rfits::Rfits_write_image(data = simspin_datacube$observed_images[[which(names(simspin_datacube$observed_images) == image_names[i])]], filename = output_image_file_names[i], ext=2, keyvalues = image_keyvalues, keycomments = image_keycomments, @@ -598,7 +602,7 @@ write_simspin_FITS = function(output_file, simspin_datacube, object_name, image_keyvalues$BUNIT = bunits[i] image_keyvalues$EXTNAME = extnames[i] - if (i < 7){ # Write each subsequent image to the next HDU + if (i < 8){ # Write each subsequent image to the next HDU Rfits::Rfits_write_image(data = simspin_datacube$observed_images[[which(names(simspin_datacube$observed_images) == image_names[i])]], filename = cube_file_name, ext=extnum[i], keyvalues = image_keyvalues, keycomments = image_keycomments, @@ -718,20 +722,20 @@ write_simspin_FITS = function(output_file, simspin_datacube, object_name, extnames = if (voronoi){ - c("OBS_MASS", "OBS_VEL", "OBS_DISP", "OBS_H3", "OBS_H4", "RESIDUAL", + c("OBS_MASS", "OBS_VEL", "OBS_DISP", "OBS_H3", "OBS_H4", "RESIDUAL", "OBS_SFR", "RAW_MASS", "RAW_VEL", "RAW_DISP", "RAW_Z", "RAW_OH", "RAW_SFR", "NPART", "VORONOI") } else { - c("OBS_MASS", "OBS_VEL", "OBS_DISP", "OBS_H3", "OBS_H4", "RESIDUAL", + c("OBS_MASS", "OBS_VEL", "OBS_DISP", "OBS_H3", "OBS_H4", "RESIDUAL", "OBS_SFR", "RAW_MASS", "RAW_VEL", "RAW_DISP", "RAW_Z", "RAW_OH", "RAW_SFR", "NPART") } bunits = if (voronoi){ - c("Msol", "km/s", "km/s", "unitless", "unitless", "percentage", + c("Msol", "km/s", "km/s", "unitless", "unitless", "percentage", "Msol/year", "Msol", "km/s", "km/s", "log10(Z/Z_solar)", "log10(O/H)+12", "Msol/year", "Particle number", "Bin ID") } else { - c("Msol", "km/s", "km/s", "unitless", "unitless", "percentage", + c("Msol", "km/s", "km/s", "unitless", "unitless", "percentage", "Msol/year", "Msol", "km/s", "km/s", "log10(Z/Z_solar)", "log10(O/H)+12", "Msol/year", "Particle number") } @@ -739,20 +743,22 @@ write_simspin_FITS = function(output_file, simspin_datacube, object_name, image_names = if (voronoi){ c("mass_image", "velocity_image", "dispersion_image", "h3_image", "h4_image", - "residuals", "mass_image", "velocity_image", "dispersion_image", "metallicity_image", + "residuals", "SFR_image", + "mass_image", "velocity_image", "dispersion_image", "metallicity_image", "OH_image", "SFR_image", "particle_image", "voronoi_bins") } else { c("mass_image", "velocity_image", "dispersion_image", "h3_image", "h4_image", - "residuals", "mass_image", "velocity_image", "dispersion_image", "metallicity_image", + "residuals", "SFR_image", + "mass_image", "velocity_image", "dispersion_image", "metallicity_image", "OH_image", "SFR_image", "particle_image") } rawobs = if (voronoi){ - c("obs", "obs", "obs", "obs", "obs", "obs", + c("obs", "obs", "obs", "obs", "obs", "obs", "obs", "raw", "raw", "raw", "raw", "raw", "raw", "raw", "raw") } else { - c("obs", "obs", "obs", "obs", "obs", "obs", + c("obs", "obs", "obs", "obs", "obs", "obs", "obs", "raw", "raw", "raw", "raw", "raw", "raw", "raw") } @@ -760,9 +766,9 @@ write_simspin_FITS = function(output_file, simspin_datacube, object_name, extnum = if (voronoi){ - c(4,5,6,7,8,9,10,11,12,13,14,15,16,17) + c(4,5,6,7,8,9,10,11,12,13,14,15,16,17,18) } else { - c(4,5,6,7,8,9,10,11,12,13,14,15,16) + c(4,5,6,7,8,9,10,11,12,13,14,15,16,17) } if (split_save){ # if writing each image to a seperate file @@ -775,7 +781,7 @@ write_simspin_FITS = function(output_file, simspin_datacube, object_name, image_keyvalues$BUNIT = bunits[i] image_keyvalues$EXTNAME = extnames[i] - if (i < 7){ # write observed mass, velocity and dispersion images to the file + if (i < 8){ # write observed mass, velocity and dispersion images to the file Rfits::Rfits_write_image(data = simspin_datacube$observed_images[[which(names(simspin_datacube$observed_images) == image_names[i])]], filename = output_image_file_names[i], ext=2, keyvalues = image_keyvalues, keycomments = image_keycomments, diff --git a/tests/testthat/test_build_datacube.R b/tests/testthat/test_build_datacube.R index 99bb8b3..050ca3a 100644 --- a/tests/testthat/test_build_datacube.R +++ b/tests/testthat/test_build_datacube.R @@ -47,10 +47,11 @@ velocity_raw_mass_loc = 12 velocity_variance_loc = 18 gas_raw_images_size = 7 -gas_observed_images_size = 6 -gas_number_of_hdu_snfalse = 16 -gas_number_of_hdu_sntrue = 17 +gas_observed_images_size = 7 +gas_number_of_hdu_snfalse = 17 +gas_number_of_hdu_sntrue = 18 gas_obs_res_loc = 9 +gas_obs_sfr_loc = 10 # Testing that build_datacube works in spectral mode ---- @@ -752,6 +753,7 @@ test_that("Data cubes can be written to a single files", { expect_true(file.exists(paste0(temp_loc, "/ss_magneticum.FITS"))) expect_true(length(Rfits::Rfits_read(paste0(temp_loc, "/ss_magneticum.FITS"))) == gas_number_of_hdu_snfalse) expect_true(Rfits::Rfits_read(paste0(temp_loc, "/ss_magneticum.FITS"))[[gas_obs_res_loc]]$keyvalues$EXTNAME == "RESIDUAL") + expect_true(Rfits::Rfits_read(paste0(temp_loc, "/ss_magneticum.FITS"))[[gas_obs_sfr_loc]]$keyvalues$EXTNAME == "OBS_SFR") expect_length(build_datacube(simspin_file = ss_hdf5, telescope = telescope(type="IFU", lsf_fwhm = 3.6, signal_to_noise = 10, spatial_res = 0.25, fov=50), From 00f0ea70e4d85eb2fc40b45ba8a3bbeae50b57c4 Mon Sep 17 00:00:00 2001 From: kateharborne Date: Thu, 14 Mar 2024 16:09:20 +0800 Subject: [PATCH 12/12] Updating news to reflect the new addition of blurred SFR outputs. Adding tests for vorbinned gas. --- NEWS.md | 2 +- tests/testthat/test_build_datacube.R | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index a81bc44..4e5a42f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -16,7 +16,7 @@ All changes are noted in the changelog table below. | Date | Summary of change | Version | Commit | Author | |---------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |--------- |------------------------------------------ | ----------------- | -| 13/03/24 | Adding observation-ally mapped mass images to the output `$observed_images` - the raw images are not blurred with the PSF, but for comparison with other observed properties, this PSF convolution is necessary. Now output on all `method="velocity"` cubes as default. | 2.8.3 | | Kate Harborne | +| 13/03/24 | Adding observation-ally mapped mass and SFR images to the output `$observed_images` - the raw images are not blurred with the PSF, but for comparison with other observed properties, this PSF convolution is necessary. Now mass maps are output on all `method="velocity"` cubes as default and SFR maps on all `method="gas"` or `"sf gas"`. | 2.8.3 | | Kate Harborne | | 29/02/24 | *Bug fix.* Updating `make_simspin_file` to account for the `Time` at which the input simulation was extracted (for proper assignment of stellar ages relative to the snapshot, not z=0). Fixing issue #98.| 2.8.2 | 0469ff454756e7b6195bf927b7c867fd02f20743 | Kate Harborne | | 10/01/24 | Also updating treatment for `mass_flag` = TRUE. No longer will the `observed_images` outputs change for the flag, the flux map will always be included. However, the kinematic maps observed will be weighted differently (by mass instead of the flux), which is now recorded in the `observation` log and output to FITS with a new header unit denoting mass rather than flux weighting. | 2.8.1 | 352c5601b04767e10d2598358b164f1b203a8d54 | Kate Harborne | | 10/01/24 | Standardising which cubes/images output are voronoi binned. Properties, such as the mass, flux and number of particles, are produced simply as the sum along that line-of-sight and as such should be presented at the pixel resolution of the instrument. As default, summed images are now given in this way, while any spectral/velocity cubes are binned along with any output average maps (kinematics such as velocity, dispersion, h3 and h4, metallicity and age). The same is done for gas maps, with all but the mass, SFR and particle number being given in binned form when the voronoi function is turned on. Also, added `raw_images$mass_image` to the output of spectral mode as this is now "free"" to produce. | 2.8.0 | 5af1ad3a90c7f84a55e6f9cb50492308fd422d7a | Kate Harborne | diff --git a/tests/testthat/test_build_datacube.R b/tests/testthat/test_build_datacube.R index 050ca3a..74159bb 100644 --- a/tests/testthat/test_build_datacube.R +++ b/tests/testthat/test_build_datacube.R @@ -748,10 +748,10 @@ test_that("Data cubes can be written to a single files", { observing_strategy = observing_strategy(dist_z = 0.03, inc_deg = 45, blur = T), method="sf gas", write_fits = T, output_location = paste0(temp_loc, "/ss_magneticum.FITS"), - split_save=F), built_cube_size) + split_save=F, voronoi_bin = T, vorbin_limit = 10), built_cube_size) expect_true(file.exists(paste0(temp_loc, "/ss_magneticum.FITS"))) - expect_true(length(Rfits::Rfits_read(paste0(temp_loc, "/ss_magneticum.FITS"))) == gas_number_of_hdu_snfalse) + expect_true(length(Rfits::Rfits_read(paste0(temp_loc, "/ss_magneticum.FITS"))) == (gas_number_of_hdu_snfalse+1)) expect_true(Rfits::Rfits_read(paste0(temp_loc, "/ss_magneticum.FITS"))[[gas_obs_res_loc]]$keyvalues$EXTNAME == "RESIDUAL") expect_true(Rfits::Rfits_read(paste0(temp_loc, "/ss_magneticum.FITS"))[[gas_obs_sfr_loc]]$keyvalues$EXTNAME == "OBS_SFR")