• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dsavransky / EXOSIMS / 11294204788

11 Oct 2024 02:30PM UTC coverage: 66.032%. First build
11294204788

Pull #395

github

web-flow
Merge 79a05365c into 18ce85989
Pull Request #395: np.Inf and np.array(obj, copy = False) changed

86 of 104 new or added lines in 26 files covered. (82.69%)

9543 of 14452 relevant lines covered (66.03%)

0.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/EXOSIMS/TargetList/EclipticTargetList.py
1
import numpy as np
×
2
import astropy.units as u
×
3
from astropy.time import Time
×
4
from astropy.coordinates import SkyCoord
×
5
from EXOSIMS.Prototypes.TargetList import TargetList
×
NEW
6
from EXOSIMS.util._numpy_compat import copy_if_needed
×
7

8

9
class EclipticTargetList(TargetList):
×
10
    """Target list in which star positions may be obtained in heliocentric equatorial
11
    or ecliptic coordinates.
12

13
    Args:
14
        **specs:
15
            user specified values
16

17
    """
18

19
    def __init__(self, **specs):
×
20

21
        TargetList.__init__(self, **specs)
×
22

23
    def nan_filter(self):
×
24
        """Populates Target List and filters out values which are nan"""
25

26
        # filter out nan values in numerical attributes
27
        for att in self.catalog_atts:
×
28
            if ("close" in att) or ("bright" in att):
×
29
                continue
×
30
            if getattr(self, att).shape[0] == 0:
×
31
                pass
×
32
            elif isinstance(getattr(self, att)[0], (str, bytes)):
×
33
                # FIXME: intent here unclear:
34
                #   note float('nan') is an IEEE NaN, getattr(.) is a str,
35
                #   and != on NaNs is special
36
                i = np.where(getattr(self, att) != float("nan"))[0]
×
37
                self.revise_lists(i)
×
38
            # exclude non-numerical types
39
            elif type(getattr(self, att)[0]) not in (
×
40
                np.unicode_,
41
                np.string_,
42
                np.bool_,
43
                bytes,
44
            ):
45
                if att == "coords":
×
46
                    i1 = np.where(~np.isnan(self.coords.lon.to("deg").value))[0]
×
47
                    i2 = np.where(~np.isnan(self.coords.lat.to("deg").value))[0]
×
48
                    i = np.intersect1d(i1, i2)
×
49
                else:
50
                    i = np.where(~np.isnan(getattr(self, att)))[0]
×
51
                self.revise_lists(i)
×
52

53
    def revise_lists(self, sInds):
×
54
        """Replaces Target List catalog attributes with filtered values,
55
        and updates the number of target stars.
56

57
        Args:
58
            sInds (integer ndarray):
59
                Integer indices of the stars of interest
60

61
        """
62

63
        # cast sInds to array
NEW
64
        sInds = np.array(sInds, ndmin=1, copy=copy_if_needed)
×
65

66
        if len(sInds) == 0:
×
67
            raise IndexError("Target list filtered to empty.")
×
68

69
        for att in self.catalog_atts:
×
70
            if att == "coords":
×
71
                ra = self.coords.lon[sInds].to("deg")
×
72
                dec = self.coords.lat[sInds].to("deg")
×
73
                self.coords = SkyCoord(
×
74
                    ra, dec, self.dist.to("pc"), frame="barycentrictrueecliptic"
75
                )
76
            else:
77
                if getattr(self, att).size != 0:
×
78
                    setattr(self, att, getattr(self, att)[sInds])
×
79
        try:
×
80
            self.Completeness.revise_updates(sInds)
×
81
        except AttributeError:
×
82
            pass
×
83
        self.nStars = len(sInds)
×
84
        assert self.nStars, "Target list is empty: nStars = %r" % self.nStars
×
85

86
    def starprop(self, sInds, currentTime, eclip=False):
×
87
        """Finds target star positions vector in heliocentric equatorial (default)
88
        or ecliptic frame for current time (MJD).
89

90
        This method uses ICRS coordinates which is approximately the same as
91
        equatorial coordinates.
92

93
        Args:
94
            sInds (integer ndarray):
95
                Integer indices of the stars of interest
96
            currentTime (astropy Time):
97
                Current absolute mission time in MJD
98
            eclip (boolean):
99
                Boolean used to switch to heliocentric ecliptic frame. Defaults to
100
                False, corresponding to heliocentric equatorial frame.
101

102
        Returns:
103
            r_targ (astropy Quantity array):
104
                Target star positions vector in heliocentric equatorial (default)
105
                or ecliptic frame in units of pc. Will return an m x n x 3 array
106
                where m is size of currentTime, n is size of sInds. If either m or
107
                n is 1, will return n x 3 or m x 3.
108

109
        Note: Use eclip=True to get ecliptic coordinates.
110

111
        """
112

113
        # if multiple time values, check they are different otherwise reduce to scalar
114
        if currentTime.size > 1:
×
115
            if np.all(currentTime == currentTime[0]):
×
116
                currentTime = currentTime[0]
×
117

118
        # cast sInds to array
NEW
119
        sInds = np.array(sInds, ndmin=1, copy=copy_if_needed)
×
120

121
        # get all array sizes
122
        nStars = sInds.size
×
123
        nTimes = currentTime.size
×
124

125
        # if the starprop_static method was created (staticStars is True), then use it
126
        if self.starprop_static is not None:
×
127
            r_targ = self.starprop_static(sInds, currentTime, eclip)
×
128
            if nTimes == 1 or nStars == 1 or nTimes == nStars:
×
129
                return r_targ
×
130
            else:
131
                return np.tile(r_targ, (nTimes, 1, 1))
×
132

133
        # target star ICRS coordinates
134
        coord_old = self.coords[sInds]
×
135
        # right ascension and declination
136
        ra = coord_old.lon
×
137
        dec = coord_old.lat
×
138
        # directions
139
        p0 = np.array([-np.sin(ra), np.cos(ra), np.zeros(sInds.size)])
×
140
        q0 = np.array(
×
141
            [-np.sin(dec) * np.cos(ra), -np.sin(dec) * np.sin(ra), np.cos(dec)]
142
        )
143
        r0 = coord_old.cartesian.xyz / coord_old.distance
×
144
        # proper motion vector
145
        mu0 = p0 * self.pmra[sInds] + q0 * self.pmdec[sInds]
×
146
        # space velocity vector
147
        v = mu0 / self.parx[sInds] * u.AU + r0 * self.rv[sInds]
×
148
        # set J2000 epoch
149
        j2000 = Time(2000.0, format="jyear")
×
150

151
        # if only 1 time in currentTime
152
        if nTimes == 1 or nStars == 1 or nTimes == nStars:
×
153
            # target star positions vector in heliocentric equatorial frame
154
            dr = v * (currentTime.mjd - j2000.mjd) * u.day
×
155
            r_targ = (coord_old.cartesian.xyz + dr).T.to("pc")
×
156

157
            if eclip:
×
158
                # transform to heliocentric true ecliptic frame
159
                coord_new = SkyCoord(
×
160
                    r_targ[:, 0], r_targ[:, 1], r_targ[:, 2], representation="cartesian"
161
                )
162
                r_targ = coord_new.heliocentrictrueecliptic.cartesian.xyz.T.to("pc")
×
163
            return r_targ
×
164

165
        # create multi-dimensional array for r_targ
166
        else:
167
            # target star positions vector in heliocentric equatorial frame
168
            r_targ = np.zeros([nTimes, nStars, 3]) * u.pc
×
169
            for i, m in enumerate(currentTime):
×
170
                dr = v * (m.mjd - j2000.mjd) * u.day
×
171
                r_targ[i, :, :] = (coord_old.cartesian.xyz + dr).T.to("pc")
×
172

173
            if eclip:
×
174
                # transform to heliocentric true ecliptic frame
175
                coord_new = SkyCoord(
×
176
                    r_targ[i, :, 0],
177
                    r_targ[i, :, 1],
178
                    r_targ[i, :, 2],
179
                    representation="cartesian",
180
                )
181
                r_targ[i, :, :] = coord_new.heliocentrictrueecliptic.cartesian.xyz.T.to(
×
182
                    "pc"
183
                )
184
            return r_targ
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc