Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small improvements tutorials #243

Merged
merged 5 commits into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:

- name: Run notebooks
run: |
poetry run pytest --nbval notebooks --sanitize-with tests/sanitize.cfg --ignore "notebooks/galsim_hub_tutorial.ipynb" --ignore "notebooks/scarlet-measure.ipynb"
poetry run pytest --nbval notebooks --sanitize-with tests/sanitize.cfg --ignore "notebooks/01c-galsim_hub_tutorial.ipynb" --ignore "notebooks/01b-scarlet-measure.ipynb"

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
Expand Down
22 changes: 12 additions & 10 deletions btk/measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def basic_measure(
):
"""Return centers detected with skimage.feature.peak_local_max.

For each potentially multi-band image, an average over the bands is taken before measurement.
NOTE: If this function is used with the multiresolution feature,
measurements will be carried on the first survey.

Expand All @@ -114,17 +115,17 @@ def basic_measure(
if surveys is None:
raise ValueError("surveys are required in order to use the MR feature.")
survey_name = surveys[0].name
coadd = np.mean(batch["blend_images"][survey_name][idx], axis=channel_indx)
avg_image = np.mean(batch["blend_images"][survey_name][idx], axis=channel_indx)
wcs = batch["wcs"][survey_name]

# single-survey
else:
coadd = np.mean(batch["blend_images"][idx], axis=channel_indx)
avg_image = np.mean(batch["blend_images"][idx], axis=channel_indx)
wcs = batch["wcs"]

# set detection threshold to 5 times std of image
threshold = 5 * np.std(coadd)
coordinates = peak_local_max(coadd, min_distance=2, threshold_abs=threshold)
threshold = 5 * np.std(avg_image)
coordinates = peak_local_max(avg_image, min_distance=2, threshold_abs=threshold)

# construct catalog from measurement.
catalog = astropy.table.Table()
Expand All @@ -145,6 +146,7 @@ def sep_measure(
):
"""Return detection, segmentation and deblending information with SEP.

For each potentially multi-band image, an average over the bands is taken before measurement.
NOTE: If this function is used with the multiresolution feature,
measurements will be carried on the first survey, and deblended images
or segmentations will not be returned.
Expand All @@ -166,19 +168,19 @@ def sep_measure(
raise ValueError("surveys are required in order to use the MR feature.")
survey_name = surveys[0].name
image = batch["blend_images"][survey_name][idx]
coadd = np.mean(image, axis=channel_indx)
avg_image = np.mean(image, axis=channel_indx)
wcs = batch["wcs"][survey_name]

# single-survey
else:
image = batch["blend_images"][idx]
coadd = np.mean(image, axis=channel_indx)
avg_image = np.mean(image, axis=channel_indx)
wcs = batch["wcs"]

stamp_size = coadd.shape[0]
bkg = sep.Background(coadd)
stamp_size = avg_image.shape[0]
bkg = sep.Background(avg_image)
catalog, segmentation = sep.extract(
coadd, sigma_noise, err=bkg.globalrms, segmentation_map=True
avg_image, sigma_noise, err=bkg.globalrms, segmentation_map=True
)

n_objects = len(catalog)
Expand Down Expand Up @@ -230,7 +232,7 @@ def __init__(
isolated images, blend catalog, wcs info, and psf.
cpus: The number of parallel processes to run [Default: 1].
verbose (bool): Whether to print information about measurement.
measure_kwargs (list): list of dictionaries containing keyword arguments
measure_kwargs (list): List of dictionaries containing keyword arguments
to be passed in to each of the `measure_functions`. Each dictionnary is
passed one time to each function, meaning that each function which be
ran as many times as there are different dictionnaries.
Expand Down
2 changes: 1 addition & 1 deletion btk/plot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def plot_blends(blend_images, blend_list, detected_centers=None, limits=None, ba
ax[0].set_title("gri bands")
ax[0].axis("off")
ax[1].imshow(np.sum(blend_images[i, :, :, :], axis=0))
ax[1].set_title("Coadd")
ax[1].set_title("Sum over bands")
if limits:
ax[1].set_xlim(limits)
ax[1].set_ylim(limits)
Expand Down
11 changes: 6 additions & 5 deletions docs/source/tutorials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ You can use BTK to directly carry out the measurements on the generated data. To
def sep_measure(batch, idx, channels_last=False, surveys=None, sigma_noise=1.5, **kwargs):
"""Return detection, segmentation and deblending information with SEP.

For each potentially multi-band image, an average over the bands is taken before measurement.
NOTE: If this function is used with the multiresolution feature,
measurements will be carried on the first survey, and deblended images
or segmentations will not be returned.
Expand All @@ -357,19 +358,19 @@ You can use BTK to directly carry out the measurements on the generated data. To
raise ValueError("surveys are required in order to use the MR feature.")
survey_name = surveys[0].name
image = batch["blend_images"][survey_name][idx]
coadd = np.mean(image, axis=channel_indx)
avg_image = np.mean(image, axis=channel_indx)
wcs = batch["wcs"][survey_name]

# single-survey
else:
image = batch["blend_images"][idx]
coadd = np.mean(image, axis=channel_indx)
avg_image = np.mean(image, axis=channel_indx)
wcs = batch["wcs"]

stamp_size = coadd.shape[0]
bkg = sep.Background(coadd)
stamp_size = avg_image.shape[0]
bkg = sep.Background(avg_image)
catalog, segmentation = sep.extract(
coadd, sigma_noise, err=bkg.globalrms, segmentation_map=True
avg_image, sigma_noise, err=bkg.globalrms, segmentation_map=True
)

n_objects = len(catalog)
Expand Down
Loading