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

Adds normalization operation and corrects typo #32

Merged
merged 3 commits into from
Sep 16, 2024
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 datalab/datalab_session/data_operations/data_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def operate(self):
"""

def perform_operation(self):
""" The generic method to perform perform the operation if its not in progress """
""" The generic method to perform the operation if its not in progress """
status = self.get_status()
if status == 'PENDING' or status == 'FAILED':
self.set_status('IN_PROGRESS')
Expand Down
66 changes: 66 additions & 0 deletions datalab/datalab_session/data_operations/normalization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import logging

import numpy as np

from datalab.datalab_session.data_operations.data_operation import BaseDataOperation
from datalab.datalab_session.file_utils import create_fits, create_jpgs
from datalab.datalab_session.s3_utils import save_fits_and_thumbnails

log = logging.getLogger()
log.setLevel(logging.INFO)


class Normalization(BaseDataOperation):

@staticmethod
def name():
return 'Normalization'

@staticmethod
def description():
return """The normalize operation takes in 1..n input images and calculates each image's median value and divides every pixel by that value.

The output is a normalized image. This operation is commonly used as a precursor step for flat removal."""

@staticmethod
def wizard_description():
return {
'name': Normalization.name(),
'description': Normalization.description(),
'category': 'image',
'inputs': {
'input_files': {
'name': 'Input Files',
'description': 'The input files to operate on',
'type': 'file',
'minimum': 1,
'maximum': 999
}
}
}

def operate(self):

input = self.input_data.get('input_files', [])

log.info(f'Executing normalization operation on {len(input)} file(s)')

image_data_list = self.get_fits_npdata(input)
self.set_percent_completion(0.40)

output_files = []
for index, image in enumerate(image_data_list):
median = np.median(image)
normalized_image = image / median

fits_file = create_fits(self.cache_key, normalized_image)
large_jpg_path, small_jpg_path = create_jpgs(self.cache_key, fits_file)
output_file = save_fits_and_thumbnails(self.cache_key, fits_file, large_jpg_path, small_jpg_path, index=index)
output_files.append(output_file)

self.set_percent_completion(self.get_percent_completion() + .40 * (index + 1) / len(input))

output = {'output_files': output_files}

self.set_output(output)
log.info(f'Normalization output: {self.get_output()}')
Loading