From 2fa11aa88baacc4e95c6e39bd648b0759c2b5d5b Mon Sep 17 00:00:00 2001 From: kateharborne Date: Wed, 21 Aug 2024 16:08:10 +0800 Subject: [PATCH 1/9] Recording the requested value of moments in the output observation table. --- R/build_datacube.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/build_datacube.R b/R/build_datacube.R index 54866ce..fecc2c9 100644 --- a/R/build_datacube.R +++ b/R/build_datacube.R @@ -115,6 +115,8 @@ build_datacube = function(simspin_file, telescope, observing_strategy, stop("ERROR: Invalid `moments` requested. Please specify `2` or `4` for the Gaussian or Gauss-Hermite polynomial fit.") } + observation$moments = moments + method = stringr::str_to_lower(method) if (method != "spectral" & From 7330020456bbb7a34eca823ecfd1b7dd30a2cd27 Mon Sep 17 00:00:00 2001 From: kateharborne Date: Wed, 21 Aug 2024 16:38:51 +0800 Subject: [PATCH 2/9] Modifying the reported H3 and H4 outputs to read "0" rather than NA, in order to avoid the warning messages from Rfits writing NA's to file. --- R/build_datacube.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/build_datacube.R b/R/build_datacube.R index fecc2c9..efa16ce 100644 --- a/R/build_datacube.R +++ b/R/build_datacube.R @@ -517,8 +517,8 @@ build_datacube = function(simspin_file, telescope, observing_strategy, output$observed_images$velocity_image[c,d] = kin[1] output$observed_images$dispersion_image[c,d] = kin[2] - output$observed_images$h3_image[c,d] = NA - output$observed_images$h4_image[c,d] = NA + output$observed_images$h3_image[c,d] = 0 + output$observed_images$h4_image[c,d] = 0 output$observed_images$residuals[c,d] = mean(abs(.losvd_out_vsig(x=observation$vbin_seq, vel=kin[1], sig=kin[2]) - output$velocity_cube[c,d,]/(max(output$velocity_cube[c,d,], na.rm=T)) ), na.rm=T) } @@ -649,8 +649,8 @@ build_datacube = function(simspin_file, telescope, observing_strategy, output$observed_images$velocity_image[c,d] = kin[1] output$observed_images$dispersion_image[c,d] = kin[2] - output$observed_images$h3_image[c,d] = NA - output$observed_images$h4_image[c,d] = NA + output$observed_images$h3_image[c,d] = 0 + output$observed_images$h4_image[c,d] = 0 output$observed_images$residuals[c,d] = mean(abs(.losvd_out_vsig(x=observation$vbin_seq, vel=kin[1], sig=kin[2]) - output$velocity_cube[c,d,]/(max(output$velocity_cube[c,d,], na.rm=T)) ), na.rm=T) From e615ed5f87c10d3c04546a6ea48dd82f5ff1e1b1 Mon Sep 17 00:00:00 2001 From: kateharborne Date: Wed, 21 Aug 2024 16:39:27 +0800 Subject: [PATCH 3/9] Adding the `moments` key to the output OBS_TABLE in the SimSpin fits outputs. --- R/write_simspin_FITS.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/write_simspin_FITS.R b/R/write_simspin_FITS.R index 8536f11..e7bf194 100644 --- a/R/write_simspin_FITS.R +++ b/R/write_simspin_FITS.R @@ -233,6 +233,7 @@ write_simspin_FITS = function(output_file, simspin_datacube, object_name, "lum_dist" = "num: distance to object in Mpc", "mass_flag" = "bool: kinematics are mass-weighted if true", "method" = "str: name of observing method employed", + "moments" = "num: Whether a 2-moment (Gaussian) or 4-moment (Gauss-Hermite) function has been fitted to the LOSVD", "origin" = "str: version of SimSpin used for observing", "particle_limit" = "int: minimum number of particles per pixel. If 0, model has not been voronoi binned", "pointing_kpc" = "num: x-y position of field of view centre relative to object centre in units of kpc", From 30862715cd39c257f0331fabbb1a44d0ab9f3504 Mon Sep 17 00:00:00 2001 From: kateharborne Date: Wed, 21 Aug 2024 16:52:48 +0800 Subject: [PATCH 4/9] Putting "moments" in the corect place in the script --- R/build_datacube.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/R/build_datacube.R b/R/build_datacube.R index efa16ce..82d86db 100644 --- a/R/build_datacube.R +++ b/R/build_datacube.R @@ -115,8 +115,6 @@ build_datacube = function(simspin_file, telescope, observing_strategy, stop("ERROR: Invalid `moments` requested. Please specify `2` or `4` for the Gaussian or Gauss-Hermite polynomial fit.") } - observation$moments = moments - method = stringr::str_to_lower(method) if (method != "spectral" & @@ -217,6 +215,7 @@ build_datacube = function(simspin_file, telescope, observing_strategy, temp = SimSpin::BC03lr } + observation$moments = moments # Twisting galaxy about the z-axis to look from an angle twisted_data = twist_galaxy(galaxy_data, twist_rad = observation$twist_rad) From 80b362059a500bd971cc289ae083457dbf24712b Mon Sep 17 00:00:00 2001 From: kateharborne Date: Wed, 21 Aug 2024 16:53:15 +0800 Subject: [PATCH 5/9] Adding a test to check that FITS files can be written without warnings --- tests/testthat/test_build_datacube.R | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test_build_datacube.R b/tests/testthat/test_build_datacube.R index 65ff6b1..121ce35 100644 --- a/tests/testthat/test_build_datacube.R +++ b/tests/testthat/test_build_datacube.R @@ -1819,28 +1819,34 @@ test_that("moments specifications all work when = 2", { gadget_velocity = build_datacube(simspin_file = ss_gadget, telescope = telescope(type="IFU", lsf_fwhm = 3.6, signal_to_noise = 3), observing_strategy = observing_strategy(dist_z = 0.03, inc_deg = 45, blur = T), - method = "velocity", moments=2, + method = "velocity", moments=2, write_fits = T, + output_location = paste0(temp_loc, "/ss_gadget_mom2.FITS"), verbose = T) expect_length(gadget_velocity, built_cube_size) expect_length(gadget_velocity$raw_images, velocity_raw_images_size) expect_length(gadget_velocity$observed_images, velocity_observed_images_size) - expect_true(all(is.na(gadget_velocity$observed_images$h3_image))) + expect_true(all((gadget_velocity$observed_images$h3_image==0))) gadget_velocity_mom4 = build_datacube(simspin_file = ss_gadget, telescope = telescope(type="IFU", lsf_fwhm = 3.6, signal_to_noise = 3), observing_strategy = observing_strategy(dist_z = 0.03, inc_deg = 45, blur = T), - method = "velocity", moments=4, + method = "velocity", moments=4, write_fits = T, + output_location = paste0(temp_loc, "/ss_gadget_mom4.FITS"), verbose = T) expect_length(gadget_velocity_mom4, built_cube_size) expect_length(gadget_velocity_mom4$raw_images, velocity_raw_images_size) expect_length(gadget_velocity_mom4$observed_images, velocity_observed_images_size) - expect_false(all(is.na(gadget_velocity_mom4$observed_images$h3_image))) + expect_false(all((gadget_velocity_mom4$observed_images$h3_image==0))) expect_false(all(gadget_velocity_mom4$observed_images$velocity_image == gadget_velocity$observed_images$velocity_image)) }) +unlink(c(paste0(temp_loc, "/ss_gadget_mom2.FITS"), + paste0(temp_loc, "/ss_gadget_mom4.FITS"))) + + test_that("moments specifications fail work when != 2 & != 4", { expect_error(build_datacube(simspin_file = ss_eagle, telescope = telescope(type = "SAMI"), From 7ef7367e98fd4b5643a3eed1fe4ec1f5f90b1ca0 Mon Sep 17 00:00:00 2001 From: kateharborne Date: Wed, 21 Aug 2024 17:15:06 +0800 Subject: [PATCH 6/9] Adding tests to check that the observation table written to FITS also contains the moments data --- tests/testthat/test_build_datacube.R | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/testthat/test_build_datacube.R b/tests/testthat/test_build_datacube.R index 121ce35..44e76da 100644 --- a/tests/testthat/test_build_datacube.R +++ b/tests/testthat/test_build_datacube.R @@ -1826,6 +1826,10 @@ test_that("moments specifications all work when = 2", { expect_length(gadget_velocity$raw_images, velocity_raw_images_size) expect_length(gadget_velocity$observed_images, velocity_observed_images_size) expect_true(all((gadget_velocity$observed_images$h3_image==0))) + expect_true(gadget_velocity$observation$moments == 2) + fits_2mom = Rfits::Rfits_read(paste0(temp_loc, "/ss_gadget_mom2.FITS")) + expect_true("moments" %in% fits_2mom$OB_TABLE$Name) + expect_true(fits_2mom$OB_TABLE$Value[fits_2mom$OB_TABLE$Name == "moments"] == 2) gadget_velocity_mom4 = build_datacube(simspin_file = ss_gadget, telescope = telescope(type="IFU", lsf_fwhm = 3.6, signal_to_noise = 3), @@ -1838,6 +1842,10 @@ test_that("moments specifications all work when = 2", { expect_length(gadget_velocity_mom4$raw_images, velocity_raw_images_size) expect_length(gadget_velocity_mom4$observed_images, velocity_observed_images_size) expect_false(all((gadget_velocity_mom4$observed_images$h3_image==0))) + expect_true(gadget_velocity_mom4$observation$moments == 4) + fits_4mom = Rfits::Rfits_read(paste0(temp_loc, "/ss_gadget_mom4.FITS")) + expect_true("moments" %in% fits_4mom$OB_TABLE$Name) + expect_true(fits_4mom$OB_TABLE$Value[fits_4mom$OB_TABLE$Name == "moments"] == 4) expect_false(all(gadget_velocity_mom4$observed_images$velocity_image == gadget_velocity$observed_images$velocity_image)) From c48d2b77df1c461aed946f2e36ff4c273955ed57 Mon Sep 17 00:00:00 2001 From: kateharborne Date: Wed, 21 Aug 2024 17:18:23 +0800 Subject: [PATCH 7/9] Updates to reflect changes to v2.9.1 --- DESCRIPTION | 2 +- NEWS.md | 7 ++++--- README.md | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9024a43..7994300 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.9.0 +Version: 2.9.1 Author: Katherine Harborne Co-author: Alice Serene Maintainer: diff --git a/NEWS.md b/NEWS.md index c69625e..29fa786 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ -# SimSpin v2.9.0 News +# SimSpin v2.9.1 News -### Last edit: 25/07/2024 +### Last edit: 21/08/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. @@ -17,7 +17,8 @@ All changes are noted in the changelog table below. | Date | Summary of change | Version | Commit | Author | |---------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |--------- |------------------------------------------ | ----------------- | -| 25/07/24 | *New feature!* Added the `moments` parameter to `build_datacube` function. You can now specify how many moments to fit the LOSVD. Either moments=2 (i.e. fitting a Gaussian to give v_los and sigma_los) or moments=4 (i.e. fitting a Gauss-Hermite polynomial to give v_los, sigma_los, h3 and h4). Fits moments=4 by default, in line with old behaviour of the code. Also *bug fix* to ensure the input variables to `write_simspin_FITS` are of the correct type and to give meaningful errors if not (resolving issue #109). | 2.9.0 | | Kate Harborne | +| 21/08/24 | Adding the `moments` parameter to output observation summary and ensuring this is written to out output FITS file. Also modifying the output h3 and h4 images in `moments=2` mode to be 0's rather than NA's to avoid warning messages when writing output to FITS. | 2.9.1 | | Kate Harborne | +| 25/07/24 | *New feature!* Added the `moments` parameter to `build_datacube` function. You can now specify how many moments to fit the LOSVD. Either moments=2 (i.e. fitting a Gaussian to give v_los and sigma_los) or moments=4 (i.e. fitting a Gauss-Hermite polynomial to give v_los, sigma_los, h3 and h4). Fits moments=4 by default, in line with old behaviour of the code. Also *bug fix* to ensure the input variables to `write_simspin_FITS` are of the correct type and to give meaningful errors if not (resolving issue #109). | 2.9.0 | f7ae49853c9821ac992502eb3e7ce3b10c7986c2 | Kate Harborne | | 19/07/24 | *Bug fix.* `.check_names()` function fails for TNG outputs if one 1 gas particle is contained in the snapshot due to indexing errors. Added in a catch for this error to prevent unnecessary code failure. | 2.8.8 | b0d53def1f52e12a6da502843a89f49434d88508 | Kate Harborne | | 17/06/24 | Adding measurement of radial gas temperature to the output of the `sim_analysis` function | 2.8.7 | ad32eb746479240c4106296999957d6ff74aecdd | Kate Harborne | | 25/04/24 | *Bug fix.* Providing a meaningful error message from the `voronoi.R` function when you cannot bin enough particles to reach the requested voronoi bin N limit. Resolves issue #105. | 2.8.6 | 4e8f0af0ebc0e43cc31729978deb3a554e039f6b | Kate Harborne | diff --git a/README.md b/README.md index cfaaa4b..792d104 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@

 

-v2.9.0 - A package for producing mock observations: +v2.9.1 - 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 529b6d9a524de70dc289011527f262d2cf7aa82d Mon Sep 17 00:00:00 2001 From: kateharborne Date: Thu, 22 Aug 2024 09:13:22 +0800 Subject: [PATCH 8/9] Adding test for mom=2 for gas build and removing a logical that is unrequired due to previous check in build_datacube. --- R/build_datacube.R | 3 --- tests/testthat/test_build_datacube.R | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/R/build_datacube.R b/R/build_datacube.R index 82d86db..40d5721 100644 --- a/R/build_datacube.R +++ b/R/build_datacube.R @@ -186,9 +186,6 @@ build_datacube = function(simspin_file, telescope, observing_strategy, stop(c("Error: No gas particles exist in this SimSpin file. \n", "Please specify a different method ('velocity' or 'spectral') and try again. \n")) } - } else { - stop(c("Error: Invalid method. \n", - "Please specify observation$method = 'spectral', 'velocity', 'sf gas', or 'gas' and try again. \n")) } if (!data.table::is.data.table(galaxy_data)){ diff --git a/tests/testthat/test_build_datacube.R b/tests/testthat/test_build_datacube.R index 44e76da..bc3f2bb 100644 --- a/tests/testthat/test_build_datacube.R +++ b/tests/testthat/test_build_datacube.R @@ -320,7 +320,7 @@ test_that("EAGLE files can be built - gas mode and be identical in series and pa eagle_gas = build_datacube(simspin_file = ss_eagle, telescope = telescope(type="IFU", lsf_fwhm = 3.6, signal_to_noise = NA), observing_strategy = observing_strategy(dist_z = 0.03, inc_deg = 45, blur = T), - method = "gas") + method = "gas", moments = 2, verbose=T) expect_length(eagle_gas, built_cube_size) expect_length(eagle_gas$raw_images, gas_raw_images_size) expect_length(eagle_gas$observed_images, gas_observed_images_size) From a6c33e1217f38f4fe333a94cd063286bb9676f98 Mon Sep 17 00:00:00 2001 From: kateharborne Date: Thu, 22 Aug 2024 09:39:17 +0800 Subject: [PATCH 9/9] Making sure that the two compared tests are actually running in the same mode... oops. --- tests/testthat/test_build_datacube.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test_build_datacube.R b/tests/testthat/test_build_datacube.R index bc3f2bb..3ad745d 100644 --- a/tests/testthat/test_build_datacube.R +++ b/tests/testthat/test_build_datacube.R @@ -329,7 +329,7 @@ test_that("EAGLE files can be built - gas mode and be identical in series and pa eagle_parallel_gas = build_datacube(simspin_file = ss_eagle, telescope = telescope(type="IFU", lsf_fwhm = 3.6, signal_to_noise = NA), observing_strategy = observing_strategy(dist_z = 0.03, inc_deg = 45, blur = T), - method = "gas", + method = "gas", moments=2, cores = 2) expect_length(eagle_parallel_gas, built_cube_size) expect_length(eagle_parallel_gas$raw_images, gas_raw_images_size)