Python Pandas: Adding FAST System Noise to Simulated Blurred Maps
import pandas as pd import numpy as np
add FAST system noise on the blur map to simulate true observed map
sigma = 800 # \mu Jy, Standard Deviation of noise
read map
filepath = '/home/wangjiaxin/final/blurred/flux_blurred_all_gal_300f.hdf5' S_df = pd.read_hdf(filepath, key='S', mode='r')
xbin_df = pd.read_hdf(filepath, key='x_bin_edge', mode='r') ybin_df = pd.read_hdf(filepath, key='y_bin_edge', mode='r') fbin_df = pd.read_hdf(filepath, key='nu_bin_edge', mode='r')
add noise
noise = np.random.normal(0, sigma, S_df.shape) newdata = S_df + noise
save
output = '/home/dyliu/Filament/TNG_100/flux_blurred_all_gal_300f_800n.hdf5' newdata.to_hdf(output, key='S', mode='w') xbin_df.to_hdf(output, key='x_bin_edge', mode='a') ybin_df.to_hdf(output, key='y_bin_edge', mode='a') fbin_df.to_hdf(output, key='nu_bin_edge', mode='a')
Modifications to resolve 'cannot create a storer if the object is not existing nor a value are passed' error
1. Use 'mode='r'' for reading HDF5 files to ensure data is read without modification.
2. Use 'mode='w'' for writing new data to HDF5 file.
3. Use 'mode='a'' for appending data to existing HDF5 file.
Explanation:
'mode='r'' is for reading the HDF5 file without modification.
'mode='w'' overwrites the existing HDF5 file with the new data.
'mode='a'' appends data to the existing HDF5 file.
原文地址: https://www.cveoy.top/t/topic/nesA 著作权归作者所有。请勿转载和采集!