Skip to content

Commit

Permalink
Merge pull request #111 from kateharborne/dev-obs_table_row
Browse files Browse the repository at this point in the history
dev-obs_table_row
kateharborne authored Aug 22, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents f7ae498 + a6c33e1 commit e69a91e
Showing 6 changed files with 32 additions and 18 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.9.0
Version: 2.9.1
Author: Katherine Harborne
Co-author: Alice Serene
Maintainer: <katherine.harborne@icrar.org>
7 changes: 4 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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 |
12 changes: 5 additions & 7 deletions R/build_datacube.R
Original file line number Diff line number Diff line change
@@ -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)){
@@ -215,6 +212,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)
@@ -515,8 +513,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)
}
@@ -647,8 +645,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)

1 change: 1 addition & 0 deletions R/write_simspin_FITS.R
Original file line number Diff line number Diff line change
@@ -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",
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@

<p>&nbsp;</p>

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/).
26 changes: 20 additions & 6 deletions tests/testthat/test_build_datacube.R
Original file line number Diff line number Diff line change
@@ -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)
@@ -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)
@@ -1819,28 +1819,42 @@ 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)))
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),
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_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))

})

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"),

0 comments on commit e69a91e

Please sign in to comment.