From e513842fe9e1729045e249b10e6692fd21fb9064 Mon Sep 17 00:00:00 2001 From: Martin Kilbinger Date: Fri, 9 Sep 2022 17:19:12 +0200 Subject: [PATCH 1/6] random runner: hp masks working; doc updated --- example/cfis/config_Rc.ini | 11 ++++++- .../modules/random_cat_package/__init__.py | 9 ++++-- .../modules/random_cat_package/random_cat.py | 32 +++++++++++-------- shapepipe/modules/random_cat_runner.py | 2 +- 4 files changed, 36 insertions(+), 18 deletions(-) diff --git a/example/cfis/config_Rc.ini b/example/cfis/config_Rc.ini index 8c24d1e81..a682d92ce 100644 --- a/example/cfis/config_Rc.ini +++ b/example/cfis/config_Rc.ini @@ -8,7 +8,7 @@ VERBOSE = True # Name of run (optional) default: shapepipe_run -RUN_NAME = run_sp_Rc +RUN_NAME = run_sp_Rc_hp # Add date and time to RUN_NAME, optional, default: False RUN_DATETIME = False @@ -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..2055c8964 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..47ff8d7e1 100644 --- a/shapepipe/modules/random_cat_package/random_cat.py +++ b/shapepipe/modules/random_cat_package/random_cat.py @@ -72,38 +72,42 @@ 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 : ndarray + 2D pixel mask image header : class Header Image header with WCS information """ + 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 +139,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 +147,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 +213,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 +234,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, From 066e071eda0f0aef1e0bb9a72c6ecf7aa982d4df Mon Sep 17 00:00:00 2001 From: Martin Kilbinger Date: Fri, 9 Sep 2022 17:24:01 +0200 Subject: [PATCH 2/6] random runner config file updated --- example/cfis/config_Rc.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/cfis/config_Rc.ini b/example/cfis/config_Rc.ini index a682d92ce..2fec0a0fc 100644 --- a/example/cfis/config_Rc.ini +++ b/example/cfis/config_Rc.ini @@ -8,7 +8,7 @@ VERBOSE = True # Name of run (optional) default: shapepipe_run -RUN_NAME = run_sp_Rc_hp +RUN_NAME = run_sp_Rc # Add date and time to RUN_NAME, optional, default: False RUN_DATETIME = False From e1f93f1ea1b911c368e44bbafabfe80537cdd3bd Mon Sep 17 00:00:00 2001 From: Martin Kilbinger Date: Fri, 9 Sep 2022 18:05:52 +0200 Subject: [PATCH 3/6] Update shapepipe/modules/random_cat_package/random_cat.py Co-authored-by: Samuel Farrens --- shapepipe/modules/random_cat_package/random_cat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shapepipe/modules/random_cat_package/random_cat.py b/shapepipe/modules/random_cat_package/random_cat.py index 47ff8d7e1..98312457b 100644 --- a/shapepipe/modules/random_cat_package/random_cat.py +++ b/shapepipe/modules/random_cat_package/random_cat.py @@ -79,7 +79,7 @@ def save_as_healpix(self, mask, header): Parameters ---------- - mask : ndarray + mask : numpy.ndarray 2D pixel mask image header : class Header Image header with WCS information From 1fd448b908a8e7ced1fb93e6071150a9e8028e2d Mon Sep 17 00:00:00 2001 From: Martin Kilbinger Date: Mon, 12 Sep 2022 11:32:02 +0200 Subject: [PATCH 4/6] passing tests --- shapepipe/modules/random_cat_package/random_cat.py | 1 - 1 file changed, 1 deletion(-) diff --git a/shapepipe/modules/random_cat_package/random_cat.py b/shapepipe/modules/random_cat_package/random_cat.py index 98312457b..f91fc2d21 100644 --- a/shapepipe/modules/random_cat_package/random_cat.py +++ b/shapepipe/modules/random_cat_package/random_cat.py @@ -85,7 +85,6 @@ def save_as_healpix(self, mask, header): Image header with WCS information """ - if not self._healpix_options: return From c36c3edfc61cb5f87dfd72fe9e6520c8e52f9b4b Mon Sep 17 00:00:00 2001 From: Martin Kilbinger Date: Wed, 5 Oct 2022 11:49:07 +0200 Subject: [PATCH 5/6] Update shapepipe/modules/random_cat_package/__init__.py Co-authored-by: Samuel Farrens --- shapepipe/modules/random_cat_package/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shapepipe/modules/random_cat_package/__init__.py b/shapepipe/modules/random_cat_package/__init__.py index 2055c8964..d2858cda7 100644 --- a/shapepipe/modules/random_cat_package/__init__.py +++ b/shapepipe/modules/random_cat_package/__init__.py @@ -28,7 +28,7 @@ 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 + ``True`` HEALPIX_OUT_NSIDE : int, optional Output healpix mask nside; used only if SAVE_MASK_AS_HEALPIX is True From 2d59db72f0b61eebc9d48f1ced943537b5fe708f Mon Sep 17 00:00:00 2001 From: Martin Kilbinger Date: Wed, 5 Oct 2022 11:49:13 +0200 Subject: [PATCH 6/6] Update shapepipe/modules/random_cat_package/__init__.py Co-authored-by: Samuel Farrens --- shapepipe/modules/random_cat_package/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shapepipe/modules/random_cat_package/__init__.py b/shapepipe/modules/random_cat_package/__init__.py index d2858cda7..b3a1cf21e 100644 --- a/shapepipe/modules/random_cat_package/__init__.py +++ b/shapepipe/modules/random_cat_package/__init__.py @@ -30,7 +30,7 @@ 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 + Output healpix mask nside; used only if SAVE_MASK_AS_HEALPIX is ``True`` """