Coverage for src/susi/io/wcs_coordinates.py: 0%

33 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2025-06-13 14:15 +0000

1#!/usr/bin/env python3 

2# -*- coding: utf-8 -*- 

3""" 

4module provides classes to hadle World Coordinate System standard 

5 

6@author: iglesias, castellanos, sanchez 

7""" 

8from datetime import datetime, timezone 

9 

10import numpy as np 

11import astropy.units as u 

12from astropy.coordinates import SkyCoord 

13# import sunpy.map 

14from .fits import Fits 

15from ..utils import Git 

16from ..reduc.pipeline import Block 

17from ..base.header_keys import * 

18from ..base import Logging 

19from ..base.config import Config 

20 

21 

22logger = Logging.get_logger() 

23 

24 

25class WcsCoordinates: 

26 def __init__(self): 

27 self.fits = None 

28 

29 def add_header(self, fits: Fits): 

30 """ 

31 add WCS header keywords to the input Fits 

32 Returns: 

33 header (Header): The header with WCS keywords. 

34 """ 

35 header = fits.header 

36 xcoord = fits.header['XCEN'] # central pixel x location in arcsec 

37 ycoord = fits.header['YCEN'] # central pixel y location in arcsec 

38 rotation = row['telescope_angle'] # rotation angle in degrees 

39 time_obs = fits.header['DATE-OBS'] # observation time 

40 

41 my_coord = SkyCoord( 

42 xcoord * u.arcsec, 

43 ycoord * u.arcsec, 

44 obstime=time_obs, 

45 observer='earth', 

46 frame=Helioprojective, 

47 ) 

48 

49 header = sunpy.map.make_fitswcs_header(fits.data, my_coord) 

50 scale = 47 / 1580.0 # 0.0378 # 47 / 1580. 

51 Fits.override_header(header, 'CDELT1', scale, 'arcsec') 

52 Fits.override_header(header, 'CDELT2', scale, 'arcsec') 

53 Fits.override_header(header, 'CROTA', rotation, 'deg') 

54 Fits.override_header(header, 'CROTA2', rotation, 'deg') 

55 Fits.override_header(header, 'PC1_1', np.cos(rotation * np.pi / 180.0), '') 

56 Fits.override_header(header, 'PC1_2', -np.sin(rotation * np.pi / 180.0), '') 

57 Fits.override_header(header, 'PC2_1', np.sin(rotation * np.pi / 180.0), '') 

58 Fits.override_header(header, 'PC2_2', np.cos(rotation * np.pi / 180.0), '') 

59 return header