Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

IRSA Tutorials

Number Density as a Function of Redshift

Learning Goals

Introduction

The Nancy Grace Roman Space Telescope will be a transformative tool for cosmology due to its unprecedented combination of wide field-of-view and high-resolution imaging. We choose to demonstrate the usefulness of the mock Roman suimulations in generating number density plots because they provide crucial insights into the large-scale structure of the universe and the distribution of matter over cosmic time. These plots illustrate how the number density of galaxies, quasars, or dark matter halos changes with redshift, revealing information about the processes of galaxy formation, evolution, and clustering. By analyzing number density plots, cosmologists can test theoretical models of structure formation, constrain cosmological parameters, and understand the influence of dark matter and dark energy on the evolution of the universe.

Instructions

Most of the notebook can be run with a single mock galaxy catalog file which easily fits in memory (3G). The final section uses all the data to make a final number density plot. The dataset in its entirety does not fit into memory all at once(out of memory) so we have carefully designed this function to use the least possible amount of memory. The dataset in its entirety also takes ~30 minutes to download and requires ~30G of space to store. We suggest only running download_simulations with download_all= True if you are ready to wait for the download and have enough storage space. Default is to work with only one catalog which is 10% of the dataset.

Techniques employed for working with out of memory datasets:

- read in only some columns from the original dataset
- convert data from float64 to float32 where high precision is not necessary
- careful management of the code structure to not need to read in all datasets to one dataframe

Input

Output

Imports

1. Read in the mock catalogs from IRSA

1.1 Download the files from IRSA

Notebook Cell
Notebook Cell
Notebook Cell
Starting parallel download of 1 files.
Downloaded: downloaded_hdf5_files/Roman_small_V2_0.hdf5
Successfully downloaded 1 files.

1.2 read files into a pandas dataframe so we can work with them

Notebook Cell
Notebook Cell
Notebook Cell

1.3 Pre-process dataset

Add some value-added columns to the dataframe, and calculate some variables which are used by mulitple functions

Loading...

1.3 Data Exploration

Let’s explore the dataset a bit to see what we are working with.

This function prints the following information:

Note that quite a few of the z_bin values are NaN because they are outside the redshift range of interest for this plot (1 < z < 3)

Loading...

DataFrame info (Data Types, Non-null counts):
<class 'pandas.DataFrame'>
RangeIndex: 29382943 entries, 0 to 29382942
Data columns (total 6 columns):
 #   Column             Dtype   
---  ------             -----   
 0   RA                 float64 
 1   DEC                float64 
 2   redshift_observed  float32 
 3   flux_Halpha6563    float32 
 4   z_bin              category
 5   RA_shifted         float64 
dtypes: category(1), float32(2), float64(3)
memory usage: 924.7 MB

Summary statistics for numeric columns:
Loading...

Memory usage of the DataFrame:
Index                      132
RA                   235063544
DEC                  235063544
redshift_observed    117531772
flux_Halpha6563      117531772
z_bin                 29383263
RA_shifted           235063544
dtype: int64
Total memory usage: 924.72 MB

Checking for NaN (missing) values in the DataFrame:
There are NaN values in the DataFrame.

Columns with NaN values and the number of missing values in each:
RA                          0
DEC                         0
redshift_observed           0
flux_Halpha6563             0
z_bin                14781902
RA_shifted                  0
dtype: int64

2. Make some helpful histograms

Do the numbers we are getting and their distributions make sense?

Notebook Cell
Notebook Cell
Notebook Cell
Notebook Cell
<Figure size 800x600 with 1 Axes>
<Figure size 800x600 with 1 Axes>

Figure Caption: Both plots have Declination on their X-axis. The top panel shows the total number of galaxies. The bottom panel shows the number of galaxies per square degree. Note that they y-axis is displayed in a log scale, and shows a quite small range. The goal of this plot is to explore the data a bit and see what variation we have as a function of declination bins.

3. Make Number density plot

This is a first pass at making a number density plot with just a single data file. We divide the sample into 10 declination bins in order to do a jackknife sampling and obtain error bars for the plot. We choose to use constant dec bins instead of constant RA bins since area is function of cosine dec so we don’t want to average over too much dec.

Notebook Cell
Notebook Cell
Original galaxy count: 29382943
<Figure size 1000x600 with 1 Axes>

Figure Caption: Number density plot. Note that the jackknife error bars are displayed on the plot but they are smaller than the point size. We see the expected shape of this plot, with a fall off toward higher redshift.

4. Expand to out-of-memory sized catalogs

Originally this section attempted to use dask instead of pandas to hold the data and be able to do this work. Dask is supposed to be able to do this sort of magic in the background with out of memory catalogs, but in reality, this does not seem to be possible, or at least not possible with a week or so of working on it. Instead, we will read in the catalogs one at a time, store counts of mean and standard deviation per square degree and then move on to the next catalog.

Notebook Cell
Notebook Cell
Notebook Cell
Notebook Cell
all_counts shape: (1, 20)
all_counts sample: [[908.19889809 747.2333674  794.9342837  676.17631576 655.19747312
  588.94982189 513.17670351 456.29600034 383.57721419 330.13751134
  267.43061388 217.22499701 175.30681804 144.16250588 112.40633963
   85.80426641  63.65060463  43.55867883  29.37146612  17.62327474]]
all_counts variance: [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
all_counts dtype: float64
<Figure size 1000x600 with 1 Axes>

Figure Caption: Number Density plots color coded by Halpha flux. Slight variations are noted in the shape of the curves as a function of Halpha flux, especially at higher redshifts. This plot may be a factor of 10 below the section 3 number density plot if you have not let it download all 10 input files. The 10 input files cover the same area on the sky, so the density will look smaller if fewer files are used.

4.1 Explore jackknife uncertainties

The uncertainties are plotted as error bars on the data points above. There are no jackknife uncertainties if you are only using one file, so they will in that case not be visible on the plot. This section is for the case where you are using more than one downloaded input file. Here we explore and plot the jackknife uncertainties in a way that makes them visible.

Notebook Cell
<Figure size 800x500 with 1 Axes>

Figure Caption: The fractional uncertainty is the standard deviation from jackknife sampling divided by the number of galaxies per square degree, here plotted as a function of redshift. Note that if you are using only 1 downloaded file this will be a flat plot with no uncertainties. However, if you are using all 10 input files, you will see the expected rise in uncertainty with increasing redshift.

Acknowledgements

About this notebook

Contact: IRSA Helpdesk with questions or problems.

Updated: 2025-04-01

Runtime: As of the date above, running on the Fornax Science Platform, this notebook takes about 9 minutes to run to completion on a machine with 8GB RAM and 4 CPU. This runtime inlcudes the notebook as is, using only one datafile out of 10. Runtime will be greater than 30 min. longer if the code is allowed to download and work with all 10 datafiles.