This repository has been archived by the owner on Sep 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
kpvt.py
122 lines (94 loc) · 4.17 KB
/
kpvt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
"""KPVT Map subclass definitions. This is used to register the KPVT instruments to sunpy."""
from __future__ import absolute_import, print_function, division
from sunpy.map import GenericMap
import astropy.units as u
from sunpy.sun import sun
from collections import namedtuple
__authors__ = ["Zach Werginz", "Andres Munoz-Jaramillo"]
__email__ = ["zachary.werginz@snc.edu", "amunozj@gsu.edu"]
Pair = namedtuple('Pair', 'x y')
__all__ = ["Ch512Map", "SPMGMap"]
class Ch512Map(GenericMap):
"""KPVT 512 Channel Image Map."""
def __init__(self, data, header, **kwargs):
GenericMap.__init__(self, data[2, :, :], header, **kwargs)
# Any Ch512 Instrument specific keyword manipulation
self.meta['detector'] = "512"
self._nickname = str(self.detector) + "" + str(self.measurement)
if self.meta['cunit1'] == 'ARC-SEC':
self.meta['cunit1'] = 'arcsec'
if self.meta['cunit2'] == 'ARC-SEC':
self.meta['cunit2'] = 'arcsec'
self.meta['pc2_1'] = 0
self.meta['pc1_2'] = 0
self.meta['B0'] = self.meta['EPH_B0']
self.meta['L0'] = self.meta['EPH_L0']
del self.meta['eph_b0']
del self.meta['eph_l0']
def __getitem__(self, key):
raise NotImplementedError(
"The ability to index Map by physical coordinate is not yet implemented.")
def meta(self):
"""Returns a neat list of header cards."""
return super(Ch512Map, self).meta()
@property
def scale(self):
"""Returns the scale of the instrument."""
return Pair(self.meta['cdelt1'] * self.spatial_units[0] / u.pixel * self.meta['CRR_SCLX'],
self.meta['cdelt2'] * self.spatial_units[1] / u.pixel * self.meta['CRR_SCLY'])
@property
def rsun_obs(self):
"""KPVT Magnetograms use a different keyword for distance to sun."""
return self.meta['EPH_R0'] * u.arcsec
@property
def dsun(self):
"""KPVT at earth."""
dsun = sun.sunearth_distance(self.date).to(u.m)
return u.Quantity(dsun, 'm')
@classmethod
def is_datasource_for(cls, data, header, **kwargs):
"""Determines if header corresponds to an 512 Channel image."""
return header.get('instrume') == '512-CH-MAG'
class SPMGMap(GenericMap):
"""KPVT SPMG Channel Image Map."""
def __init__(self, data, header, **kwargs):
GenericMap.__init__(self, data[5, :, :], header, **kwargs)
# Any Ch512 Instrument specific keyword manipulation
if self.meta['cunit1'] == 'ARC-SEC':
self.meta['cunit1'] = 'arcsec'
if self.meta['cunit2'] == 'ARC-SEC':
self.meta['cunit2'] = 'arcsec'
self.meta['detector'] = "SPMG"
self.meta['pc2_1'] = 0
self.meta['pc1_2'] = 0
self.meta['B0'] = self.meta['EPH_B0']
self.meta['L0'] = self.meta['EPH_L0']
del self.meta['eph_b0']
del self.meta['eph_l0']
self.meta['instrume'] = 'SPECTROMAGNETOGRAPH'
self.meta['telescop'] = 'KITT PEAK'
def __getitem__(self, key):
raise NotImplementedError(
"The ability to index Map by physical coordinate is not yet implemented.")
def meta(self):
"""Returns a neat list of header cards."""
return super(SPMGMap, self).meta()
@property
def rsun_obs(self):
""" KPVT Magnetograms use a different keyword for distance to sun"""
return self.meta['EPH_R0'] * u.arcsec
@property
def dsun(self):
""" KPVT at earth"""
dsun = sun.sunearth_distance(self.date).to(u.m)
return u.Quantity(dsun, 'm')
@property
def scale(self):
"""Returns the scale of the instrument."""
return Pair(self.meta['cdelt1'] * self.spatial_units[0] / u.pixel * self.meta['CRR_SCLX'],
self.meta['cdelt2'] * self.spatial_units[1] / u.pixel * self.meta['CRR_SCLY'])
@classmethod
def is_datasource_for(cls, data, header, **kwargs):
"""Determines if header corresponds to an 512 Channel image"""
# Have to decide by dimensions since the header has duplicate instrument keywords
return header.get('naxis1') == 1788 and header.get('obs-site').startswith('KITT')