Skip to content

Commit

Permalink
Merge pull request #79 from kateharborne/dev-ages
Browse files Browse the repository at this point in the history
dev-ages
  • Loading branch information
kateharborne committed Jan 25, 2023
2 parents 44b7033 + 9e89c41 commit 956405f
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 15 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.4.3
Version: 2.4.4
Author: Katherine Harborne
Co-author: Alice Serene
Maintainer: <katherine.harborne@icrar.org>
Expand Down
7 changes: 4 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SimSpin v2.4.3 News
# SimSpin v2.4.4 News

### Last edit: 17/01/23
### Last edit: 25/01/23

Below is a table containing a summary of all changes made to SimSpin, since the date this file was created on 26/08/2021.

Expand All @@ -16,7 +16,8 @@ All changes are noted in the changelog table below.

| Date | Summary of change | Version | Commit | Author |
|---------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |--------- |------------------------------------------ | ----------------- |
| 17/01/23 | *Bug fix.* Addressing issue #12. When a hydrodynamical simulation HDF5 is input without a `RunLabel` in the header, the file is processed like an N-body model (often meaning that no stellar particles are read in.) Catches added to stop the code with meaningful error if this is the case. Further interpretation added for named datasets in Hydro default names rather than expected. | 2.4.3 | | Kate Harborne |
| 25/01/23 | *Bug fix.* Addressing issues #76 and #77. When working with the BC03 templates, the first AgeBin was labeled 0 Gyr. This was causing a problematic log10() age bin when gridding up the templates to match to the stellar ages within the model such that any stars that fell into this bin were associated with spectra of NA's. This was not clear until testing with IllustrisTNG galaxies that have very young stars in the outputs. Now fixed by setting low age bins to non-zero values (i.e. 0 Gyr -> 1e-9 Gyr). Tests and documentation updated for these changes. | 2.4.4 | | Alice Serene & Kate Harborne |
| 17/01/23 | *Bug fix.* Addressing issue #12. When a hydrodynamical simulation HDF5 is input without a `RunLabel` in the header, the file is processed like an N-body model (often meaning that no stellar particles are read in.) Catches added to stop the code with meaningful error if this is the case. Further interpretation added for named datasets in Hydro default names rather than expected. | 2.4.3 | 44b703304efde31d08fd8e857f986fc93879b3ee | Kate Harborne |
| 16/01/23 | **New feature!** Update to add support for IllustrisTNG. Updates to `make_simspin_file`, `utilities`, and tests were implemented. | 2.4.2 | 5fb9ad5803f26bc1dad81f9818dff24225f4e1d0 | Alice Serene |
| 28/10/22 | *Bug fix.* Addressing issue #72. Output fluxes are much higher than they should be due to an improper scaling of SSP templates wrt stellar particle mass. | 2.4.1 | ef171e40626edacc350c1e119cc6f807c6335529 | Kate Harborne |
| 30/09/22 | Tagging a release for the SimSpin web app. This update has no code developments from the previous version. Stable version. | 2.4.0 | 9307ffb7b1775540426966eb2903da119c6d7495 | Kate Harborne |
Expand Down
8 changes: 6 additions & 2 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@
#' with a given stellar age and metallicity. At each age/metallicity bin, a
#' template spectrum is given in units of solar luminoisities per angstrom for
#' 1 solar mass of star formation. Values are given at a series of wavelengths,
#' contained within the dataset.
#' contained within the dataset. Note that while the first age bin is a
#' template for Age = 0 stars, we have re-labelled this bin with a non-zero small
#' number to avoid log errors.
#'
#' @format A list with 4 elements:
#' \describe{
Expand All @@ -95,7 +97,9 @@
#' with a given stellar age and metallicity. At each age/metallicity bin, a
#' template spectrum is given in units of solar luminoisities per angstrom for
#' 1 solar mass of star formation. Values are given at a series of wavelengths,
#' contained within the dataset.
#' contained within the dataset. Note that while the first age bin is a
#' template for Age = 0 stars, we have re-labelled this bin with a non-zero small
#' number to avoid log errors.
#'
#' @format A list with 4 elements:
#' \describe{
Expand Down
12 changes: 9 additions & 3 deletions R/make_simspin_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
#'@param bulge_age The age of the bulge particles in Gyr.
#'@param disk_Z The metallicity of the disk particles as a mass fraction (mass
#' of all metal elements above He over the total mass).
#'@param bulge_Z The metallicity of the bulge particles in Gyr.
#'@param bulge_Z The metallicity of the bulge particles as a mass fraction (mass
#' of all metal elements above He over the total mass).
#'@param template The stellar templates from which to derive the SEDs. Options
#' include "BC03lr" (GALEXEV low resolution, Bruzual & Charlot 2003), "BC03hr"
#' (GALEXEV high resolution, Bruzual & Charlot 2003) or "EMILES" (Vazdekis et
Expand Down Expand Up @@ -76,8 +77,7 @@ make_simspin_file = function(filename, cores=1, disk_age=5, bulge_age=10,

if (write_to_file){
if (missing(output)){
output = paste(sub('\\..*', '', filename), "_", temp_name, ".Rdata", sep="")

output = paste(sub('\\..*', '', filename), "_", temp_name, ".Rdata", sep="")
}
if (file.exists(output) & !overwrite){
stop(cat("FileExists Error:: SimSpin file already exists at: ", output, "\n",
Expand Down Expand Up @@ -177,6 +177,10 @@ make_simspin_file = function(filename, cores=1, disk_age=5, bulge_age=10,

# now binning stellar particles based on their A/Z position
if (length(unique(galaxy_data$ssp$Age)) > 2){ # if not an N-body simulation

# reassign any age==0 particles to have a small non-zero age
galaxy_data$ssp$Age[galaxy_data$ssp$Age==0] = 1e-9

age_grid = 10^(seq(log10(min(galaxy_data$ssp$Age))-0.02, log10(max(galaxy_data$ssp$Age))+0.02, by = 0.02))
Z_grid = 10^(seq(log10(min(galaxy_data$ssp$Metallicity))-0.1, log10(max(galaxy_data$ssp$Metallicity))+0.1, by = 0.1))

Expand Down Expand Up @@ -248,6 +252,8 @@ make_simspin_file = function(filename, cores=1, disk_age=5, bulge_age=10,
}
}



simspin_file = list("header" = header,
"star_part" = galaxy_data$star_part,
"gas_part" = galaxy_data$gas_part,
Expand Down
2 changes: 1 addition & 1 deletion R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ globalVariables(c(".N", ":=", "Age", "Carbon", "CellSize", "Density", "Hydrogen"
}

# Functions for reading in HDF5 files
.read_hdf5 = function(f, cores=1){
.read_hdf5 = function(f, cores=1){

data = hdf5r::h5file(f, mode="r")

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

<p>&nbsp;</p>

v2.4.0 - A package for producing mock observations:
v2.4.x - 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. A mock observation is produced using three simple steps:

Expand Down
Binary file modified data/BC03hr.rda
Binary file not shown.
Binary file modified data/BC03lr.rda
Binary file not shown.
4 changes: 3 additions & 1 deletion man/BC03hr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/BC03lr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/make_simspin_file.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions tests/testthat/test_make_simspin_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -528,3 +528,71 @@ test_that("An HDF5 file for a hydro sim will give warning without neccesary RunL
unlink(paste0(temp_loc, "/SimSpin_example_illustris_copy.hdf5"))
})

test_that("A galaxy with a star with age of 0 will NOT raise an error.", {
# Testing that we can build a SimSpin file if we have a particle with Age = 0
built_cube_size = 4

file.copy(from = ss_illustris, to = paste0(temp_loc, "/SimSpin_example_illustris_copy.hdf5"), overwrite = T)
modified_age = hdf5r::h5file(paste0(temp_loc, "/SimSpin_example_illustris_copy.hdf5"), mode = "r+") # read in the eagle file and rename the RubLabel

sft = hdf5r::readDataSet(modified_age[["PartType4/GFM_StellarFormationTime"]])
aexp = hdf5r::h5attr(modified_age[["PartType4/GFM_StellarFormationTime"]], "a_scaling")
h = hdf5r::h5attr(modified_age[["PartType4/GFM_StellarFormationTime"]], "h_scaling")
cgs = hdf5r::h5attr(modified_age[["PartType4/GFM_StellarFormationTime"]], "to_cgs")
sft[1] = 1

modified_age[["PartType4/"]]$link_delete("GFM_StellarFormationTime")

modified_age[["PartType4/GFM_StellarFormationTime"]] = sft
hdf5r::h5attr(modified_age[["PartType4/GFM_StellarFormationTime"]], "a_scaling") = aexp
hdf5r::h5attr(modified_age[["PartType4/GFM_StellarFormationTime"]], "h_scaling") = h
hdf5r::h5attr(modified_age[["PartType4/GFM_StellarFormationTime"]], "to_cgs") = cgs

hdf5r::h5close(modified_age)

ss_file = make_simspin_file(filename = paste0(temp_loc, "/SimSpin_example_illustris_copy.hdf5"), write_to_file = F)

expect_length(ss_file, ss_file_length)
expect_length(build_datacube(simspin_file = ss_file,
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"), built_cube_size)

unlink(paste0(temp_loc, "/SimSpin_example_illustris_copy.hdf5"))
})


test_that("A galaxy with a star with a very small age will NOT raise an error.", {
# Testing that we can build a SimSpin file if we have a particle with Age = 0
built_cube_size = 4

file.copy(from = ss_illustris, to = paste0(temp_loc, "/SimSpin_example_illustris_copy.hdf5"), overwrite = T)
modified_age = hdf5r::h5file(paste0(temp_loc, "/SimSpin_example_illustris_copy.hdf5"), mode = "r+") # read in the eagle file and rename the RubLabel

sft = hdf5r::readDataSet(modified_age[["PartType4/GFM_StellarFormationTime"]])
aexp = hdf5r::h5attr(modified_age[["PartType4/GFM_StellarFormationTime"]], "a_scaling")
h = hdf5r::h5attr(modified_age[["PartType4/GFM_StellarFormationTime"]], "h_scaling")
cgs = hdf5r::h5attr(modified_age[["PartType4/GFM_StellarFormationTime"]], "to_cgs")
sft[1] = 0.99999999999

modified_age[["PartType4/"]]$link_delete("GFM_StellarFormationTime")

modified_age[["PartType4/GFM_StellarFormationTime"]] = sft
hdf5r::h5attr(modified_age[["PartType4/GFM_StellarFormationTime"]], "a_scaling") = aexp
hdf5r::h5attr(modified_age[["PartType4/GFM_StellarFormationTime"]], "h_scaling") = h
hdf5r::h5attr(modified_age[["PartType4/GFM_StellarFormationTime"]], "to_cgs") = cgs

hdf5r::h5close(modified_age)

ss_file = make_simspin_file(filename = paste0(temp_loc, "/SimSpin_example_illustris_copy.hdf5"), write_to_file = F)

expect_length(ss_file, ss_file_length)
expect_length(build_datacube(simspin_file = ss_file,
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"), built_cube_size)

unlink(paste0(temp_loc, "/SimSpin_example_illustris_copy.hdf5"))
})


Binary file modified vignettes/SAMI_cube_phys.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion vignettes/using_simspin_v2.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ png(file="SAMI_cube_phys%02d.png", width=456, height=500)
for (i in 1:25){
image_nan(z = asinh(sub_cube[,,i]), zlim = flux_val, col = grey((0:1000)/1000), na.color = "white", xaxt="n",
yaxt="n", ann=FALSE, magmap=FALSE, family="mono", font=1)
legend("topleft", inset=c(-0.01,0.01), parse(text=sprintf('lambda == %s',sub_wave[i])), bty="n")
legend("topleft", inset=c(-0.01,0.01), paste0('λ = ',sub_wave[i]), text.col = "white", bty="n")
}
dev.off()
Expand Down

0 comments on commit 956405f

Please sign in to comment.