Skip to content

Commit

Permalink
COO-40 Cleanup atlas organization structure (#6)
Browse files Browse the repository at this point in the history
* COO-40 Cleanup atlas organization structure
  • Loading branch information
prkrtg authored Sep 17, 2024
1 parent fb9c9c1 commit 814a8c3
Show file tree
Hide file tree
Showing 11 changed files with 588 additions and 715 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.10", "3.11"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand Down
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extension-pkg-whitelist=PyQt5
fail-on=

# Specify a score threshold under which the program will exit with error.
fail-under=10
fail-under=7

# Interpret the stdin as a python script, whose filename needs to be passed as
# the module_or_package argument.
Expand Down
624 changes: 0 additions & 624 deletions fits_viewer.py

This file was deleted.

32 changes: 0 additions & 32 deletions image_utils.py

This file was deleted.

19 changes: 0 additions & 19 deletions main.py

This file was deleted.

21 changes: 21 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import sys
from PyQt5.QtWidgets import QApplication
from view.fits_viewer import FITSViewer # Import the view
from viewmodel.fits_viewmodel import FITSViewModel # Import the view model

def main():
app = QApplication(sys.argv)

# Initialize the view model
view_model = FITSViewModel()

# Initialize the view with the view model
viewer = FITSViewer(view_model)

# Show the main window
viewer.show()

sys.exit(app.exec_())

if __name__ == '__main__':
main()
62 changes: 62 additions & 0 deletions src/model/fits_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from PyQt5.QtGui import QImage
from astropy.io import fits
import numpy as np

class FITSModel:
def load_fits_image(self, file_name):
"""Load image data and header information from a FITS file."""
with fits.open(file_name) as hdul:
image_data = hdul[0].data
header_info = hdul[0].header
return image_data, header_info

def normalize_image(self, image_data):
"""
Normalizes image data to the range [0, 255] for display purposes,
handling various data types from FITS files.
Args:
image_data (numpy.ndarray): The input image data to be normalized.
Returns:
numpy.ndarray: The normalized image data scaled to the range [0, 255].
"""
# Handle endianness and convert to little-endian if necessary
if image_data.dtype.byteorder == '>':
image_data = image_data.newbyteorder('<')

# Convert image data to float for normalization
image_data = image_data.astype(np.float32)

# Determine the min and max values
min_val = np.min(image_data)
max_val = np.max(image_data)

# Special case handling for different data types
if image_data.dtype.kind in {'i', 'u'}: # Integer types
# Normalize to the range [0, 255]
normalized_data = 255 * (image_data - min_val) / (max_val - min_val)
elif image_data.dtype.kind == 'f': # Floating-point types
# Assuming floating-point data is already in a reasonable range
# Normalize to the range [0, 255] considering typical floating-point ranges
normalized_data = 255 * (image_data - min_val) / (np.ptp(image_data) if np.ptp(image_data) > 0 else 1)
else:
raise TypeError("Unsupported data type for normalization")

# Clip values to the range [0, 255]
normalized_data = np.clip(normalized_data, 0, 255).astype(np.uint8)

return normalized_data

def convert_to_qimage(self, image_data):
"""
Convert numpy array image data to QImage.
"""
if image_data.ndim == 2:
height, width = image_data.shape
return QImage(image_data.data, width, height, width, QImage.Format_Grayscale8)
elif image_data.ndim == 3:
height, width, channels = image_data.shape
return QImage(image_data.data, width, height, width * channels, QImage.Format_RGB888)
else:
raise ValueError("Unsupported image data format.")
Loading

0 comments on commit 814a8c3

Please sign in to comment.