Skip to content

Commit

Permalink
Fixes to photometry stage.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmccully committed Oct 20, 2023
1 parent cf614fd commit 367b0ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
16 changes: 7 additions & 9 deletions banzai/photometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ def radius_of_contour(contour, source):


def flag_sources(sources, source_labels, segmentation_map, mask, flag, mask_value):
affected_sources = np.unique(segmentation_map[mask == mask_value])
affected_sources = np.unique(segmentation_map.data[mask == mask_value])
sources['flag'][np.in1d(source_labels, affected_sources)] |= flag


def flag_deblended(sources, catalog, segmentation_map, deblended_seg_map, flag_value=2):
# By default deblending appends labels instead of reassigning them so we can just use the
# extras in the deblended map
deblended_sources = np.unique(deblended_seg_map[deblended_seg_map > np.max(segmentation_map)])
deblended_sources = np.unique(deblended_seg_map.data[deblended_seg_map > np.max(segmentation_map)])
# Get the sources that were originally blended
original_blends = np.unique(segmentation_map[deblended_seg_map > np.max(segmentation_map)])
deblended_sources = np.hstack([deblend_sources, original_blends])
original_blends = np.unique(segmentation_map.data[deblended_seg_map > np.max(segmentation_map)])
deblended_sources = np.hstack([deblended_sources, original_blends])
sources['flag'][np.in1d(catalog.labels, deblended_sources)] |= flag_value


Expand Down Expand Up @@ -76,9 +76,6 @@ def __init__(self, runtime_context):

def do_stage(self, image):
try:
# Increase the internal buffer size in sep. This is most necessary for crowded fields.
ny, nx = image.shape

data = image.data.copy()
error = image.uncertainty

Expand All @@ -101,10 +98,11 @@ def do_stage(self, image):
kernel_squared = CustomKernel(kernel.array * kernel.array)
normalization = np.sqrt(convolve(1 / (error * error), kernel_squared))
convolved_data /= normalization

logger.info('Running image segmentation', image=image)
# Do an initial source detection
segmentation_map = detect_sources(convolved_data, self.threshold, npixels=self.min_area)

logger.info('Deblending sources', image=image)
# Note that nlevels here is DEBLEND_NTHRESH in source extractor which is 32 by default
deblended_seg_map = deblend_sources(convolved_data, segmentation_map,
npixels=self.min_area, nlevels=32,
Expand Down Expand Up @@ -255,7 +253,7 @@ def do_stage(self, image):
image.meta['L1ELLIP'] = (mean_ellipticity, 'Mean image ellipticity (1-B/A)')

mean_position_angle = stats.sigma_clipped_mean(catalog['theta'][good_objects], 3.0)
image.meta['L1ELLIPA'] = (mean_position_angle,'[deg] PA of mean image ellipticity')
image.meta['L1ELLIPA'] = (mean_position_angle, '[deg] PA of mean image ellipticity')

logging_tags = {key: float(image.meta[key]) for key in ['L1MEAN', 'L1MEDIAN', 'L1SIGMA',
'L1FWHM', 'L1ELLIP', 'L1ELLIPA']}
Expand Down
6 changes: 3 additions & 3 deletions banzai/tests/e2e-k8s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ spec:
- name: TASK_HOST
value: "redis://localhost:6379/0"
- name: BANZAI_WORKER_LOGLEVEL
value: debug
value: info
- name: CALIBRATE_PROPOSAL_ID
value: "calibrate"
- name: OBSERVATION_PORTAL_URL
value: "http://internal-observation-portal.lco.gtn/api/observations/"
- name: OMP_NUM_THREADS
value: "4"
value: "2"
- name: FITS_EXCHANGE
value: "fits_files"
- name: OPENTSDB_PYTHON_METRICS_TEST_MODE
Expand All @@ -117,7 +117,7 @@ spec:
- --hostname
- "banzai-celery-worker"
- --concurrency
- "4"
- "2"
- "-l"
- "info"
- "-Q"
Expand Down

0 comments on commit 367b0ba

Please sign in to comment.