Skip to content

Commit

Permalink
Added function 'catl_drop_cols' that deletes certain columns from
Browse files Browse the repository at this point in the history
catalogue
  • Loading branch information
vcalderon2009 committed Feb 22, 2018
1 parent 6a3596e commit e951660
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/data/mocks_create/eco_mocks_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,18 @@ def tarball_create(param_dict, proj_dict, catl_ext='hdf5'):
with tarfile.open(tar_file_path, mode='w:gz') as tf:
tf.add(readme_file, arcname=os.path.basename(readme_file))
for file_kk in catl_path_arr:
## Reading in DataFrame
gal_pd_kk = cu.read_hdf5_file_to_pandas_DF(file_kk)
## DataFrame `without` certain columns
gal_pd_mod = catl_drop_cols(gal_pd_kk)
## Saving modified DataFrame to file
file_mod_kk = file_kk+'.mod'
cu.pandas_df_to_hdf5_file(gal_pd_mod, file_mod_kk)
cu.File_Exists(file_mod_kk)
# Saving to Tar-file
tf.add(file_kk, arcname=os.path.basename(file_kk))
# Deleting extra file
os.remove(file_mod_kk)
tf.close()
cu.File_Exists(tar_file_path)
if param_dict['verbose']:
Expand Down Expand Up @@ -2127,36 +2138,32 @@ def group_mass_assignment(mockgal_pd, mockgroup_pd, param_dict, proj_dict):

return mockgal_pd_new, mockgroup_pd_new

def catl_drop_cols(mockgal_pd, mockgroup_pd, param_dict):
def catl_drop_cols(mockgal_pd):
"""
Drops certain columns from both DataFrames
Drops certain columns from the galaxy DataFrame
Parameters
-----------
mockgal_pd: pandas DataFrame
DataFrame containing information for each mock galaxy.
Includes galaxy properties + group ID
mockgroup_pd: pandas DataFrame
DataFame containing information for each galaxy group
param_dict: python dictionary
dictionary with `project` variables
Returns
-----------
mockgal_pd: pandas DataFrame
gal_pd_mod: pandas DataFrame
Updated version of the DataFrame containing information for each
mock galaxy.
mockgroup_pd: pandas DataFrame
Updated DataFame containing information for each galaxy group
"""
## Copies of DataFrames
gal_pd = mockgal_pd.copy()
group_pd = mockgroup_pd.copy()
## Columns
# gal_cols =
gal_cols = ['x','y','z','vx','vy','vz','galid','x_orig','y_orig','z_orig',
'idx','vel_pec']
# New object `without` these columns
gal_pd_mod = gal_pd.loc[:,~gal_pd.columns.isin(gal_cols)].copy()

return gal_pd_mod

## ---------| Halo Rvir calculation |------------##

Expand Down

0 comments on commit e951660

Please sign in to comment.