diff --git a/example/cfis/config_Rc.ini b/example/cfis/config_Rc.ini index 8c24d1e81..2fec0a0fc 100644 --- a/example/cfis/config_Rc.ini +++ b/example/cfis/config_Rc.ini @@ -65,3 +65,12 @@ N_RANDOM = 50000 # N_RANDOM is per square degrees if True DENSITY = True + +# Output healpix mask if True +SAVE_MASK_AS_HEALPIX = True + +# Healpix mask file base name (used if SAVE_MASK_AS_HEALPIX is True) +HEALPIX_OUT_FILE_BASE = mask_hp + +# Healpix mask nside (used if SAVE_MASK_AS_HEALPIX is True) +HEALPIX_OUT_NSIDE = 1024 diff --git a/shapepipe/modules/random_cat_package/__init__.py b/shapepipe/modules/random_cat_package/__init__.py index 2dda4943c..b3a1cf21e 100644 --- a/shapepipe/modules/random_cat_package/__init__.py +++ b/shapepipe/modules/random_cat_package/__init__.py @@ -24,8 +24,13 @@ DENSITY : bool, optional Option to interpret the number of random objects per square degree; the default is ``False`` -TILE_LIST : str, optional - Path to tile IDs for overlap flagging +SAVE_MASK_AS_HEALPIX : bool + Output healpix mask if ``True`` +HEALPIX_OUT_FILE_BASE : str, optional + Output halpix mask file base name; used only if SAVE_MASK_AS_HEALPIX is + ``True`` +HEALPIX_OUT_NSIDE : int, optional + Output healpix mask nside; used only if SAVE_MASK_AS_HEALPIX is ``True`` """ diff --git a/shapepipe/modules/random_cat_package/random_cat.py b/shapepipe/modules/random_cat_package/random_cat.py index 2f24a3970..f91fc2d21 100644 --- a/shapepipe/modules/random_cat_package/random_cat.py +++ b/shapepipe/modules/random_cat_package/random_cat.py @@ -72,15 +72,15 @@ def __init__( self._w_log = w_log self._healpix_options = healpix_options - def save_as_healpix(self, hdu_mask, header): + def save_as_healpix(self, mask, header): """Save As Healpix. Save mask as healpix FITS file. Parameters ---------- - hdu_mask : class HDUList - HDU with 2D pixel mask image + mask : numpy.ndarray + 2D pixel mask image header : class Header Image header with WCS information @@ -88,22 +88,25 @@ def save_as_healpix(self, hdu_mask, header): if not self._healpix_options: return + # Tranform config entry from str to int + nside = int(self._healpix_options['NSIDE']) + mask_1d, footprint = reproject_to_healpix( - (hdu_mask, header), + (mask, header), 'galactic', - nside=self._healpix_options['OUT_NSIDE'] + nside=nside, ) t = Table() t['flux'] = mask_1d t.meta['ORDERING'] = 'RING' t.meta['COORDSYS'] = 'G' - t.meta['NSIDE'] = self._healpix_options['OUT_NSIDE'] + t.meta['NSIDE'] = nside t.meta['INDXSCHM'] = 'IMPLICIT' output_path = ( - f'{output_dir}/{self._healpix_options["FILE_BASE"]}-' - + f'{file_number_string}.fits' + f'{self._output_dir}/{self._healpix_options["FILE_BASE"]}-' + + f'{self._file_number_string}.fits' ) t.write(output_path) @@ -135,7 +138,7 @@ def process(self): mask = hdu_mask[0].data # Save mask in healpix format (if option is set) - self._save_as_healpix(hdu_mask, header) + self.save_as_healpix(mask, header) # Number of pixels n_pix_x = mask.data.shape[0] @@ -143,7 +146,7 @@ def process(self): n_pix = n_pix_x * n_pix_y # Number of non-masked pixels - n_unmasked = len(np.where(hdu_mask[0].data == 0)[0]) + n_unmasked = len(np.where(mask == 0)[0]) # Compute various areas @@ -209,10 +212,10 @@ def process(self): # Tile ID output_path = ( - f'{output_dir}/{output_file_pattern}-' - + f'{file_number_string}.fits' + f'{self._output_dir}/{self._output_file_pattern}-' + + f'{self._file_number_string}.fits' ) - file_name = os.path.split(self._output_path)[1] + file_name = os.path.split(output_path)[1] file_base = os.path.splitext(file_name)[0] tile_ID_str = re.split('-', file_base)[1:] tile_id = float('.'.join(tile_ID_str)) @@ -230,7 +233,7 @@ def process(self): # TODO: Add units to header output = file_io.FITSCatalogue( - self._output_path, + output_path, open_mode=file_io.BaseCatalogue.OpenMode.ReadWrite ) output.save_as_fits(cat_out, names=column_names) diff --git a/shapepipe/modules/random_cat_runner.py b/shapepipe/modules/random_cat_runner.py index 7aad692a6..5595a53ad 100644 --- a/shapepipe/modules/random_cat_runner.py +++ b/shapepipe/modules/random_cat_runner.py @@ -56,7 +56,7 @@ def random_cat_runner( ) if save_mask_as_healpix: healpix_options = {} - for option_trunc in ['FILE_BASE', 'OUT_NSIDE']: + for option_trunc in ['FILE_BASE', 'NSIDE']: option = f'HEALPIX_OUT_{option_trunc}' healpix_options[option_trunc] = config.get( module_config_sec,