@@ -37,84 +37,21 @@ and the orbit track can be visualized with
37
37
imshow(orb, proj=:Robinson, region=:global, coast=true)
38
38
"""
39
39
function sat_tracks (; geocentric:: Bool = false , tiles:: Bool = false , position:: Bool = false , kwargs... )
40
- # ...
41
- (position && tiles) && error (" Cannot require tiles and a single position. Makes no sense." )
42
- d = KW (kwargs)
43
-
44
- start = ((val = find_in_dict (d, [:start ])[1 ]) === nothing ) ? now (Dates. UTC) : getitDTime (val)
45
-
46
- (tiles) && (sat_name = get_sat_name (d))
47
- (tiles) && (start = round (start, Dates. Minute (5 ))) # This is for MODIS only
48
-
49
- if ((val = find_in_dict (d, [:duration ])[1 ]) != = nothing )
50
- if (isa (val, String)) # Accept duration in D(ays), h(ours), m(inutes) or s(econds)
51
- if (endswith (val," D" )) dur = Day (parse (Int, val[1 : end - 1 ]))
52
- elseif (endswith (val," h" )) dur = Hour (parse (Int, val[1 : end - 1 ]))
53
- elseif (endswith (val," m" )) dur = Minute (parse (Int, val[1 : end - 1 ]))
54
- elseif (endswith (val," s" )) dur = Second (parse (Int, val[1 : end - 1 ]))
55
- else error (" Only 'D', 'h', 'm' or 's' are accepted in duration" )
56
- end
57
- elseif (isa (val, Real)) # Assume duration was given in minutes
58
- dur = Minute (trunc (Int, val))
59
- end
60
- stop = start + dur
61
- else
62
- if ((val = find_in_dict (d, [:stop ])[1 ]) != = nothing )
63
- stop = getitDTime (val)
64
- else
65
- stop = start + Minute (100 ) # Default is ~Terra period
66
- end
67
- end
68
- if ((val = find_in_dict (d, [:step :inc :dt ])[1 ]) != = nothing ) # Steps are in seconds
69
- if (isa (val, String))
70
- if (endswith (val," m" )) dt = parse (Int, val[1 : end - 1 ]) * 60
71
- elseif (endswith (val," s" )) dt = parse (Int, val[1 : end - 1 ])
72
- else error (" Only 's' or 'm' are accepted in increment" )
73
- end
74
- else
75
- dt = trunc (Int, val)
76
- end
77
- else
78
- dt = 30
79
- end
80
-
81
- if ((val_tle = find_in_dict (d, [:tle_obj ])[1 ]) != = nothing ) tle = val_tle # Some other fun already got it
82
- else tle = loadTLE (d)
83
- end
84
- orbp = SatelliteToolboxPropagators. Propagators. init (Val (:SGP4 ), tle)
85
-
86
- epoch_jd = orbp. sgp4d. epoch
87
- startmfe = (datetime2julian (DateTime (start)) - epoch_jd) * 24 * 3600
88
- stopmfe = (datetime2julian (DateTime (stop)) - epoch_jd) * 24 * 3600
89
- (tiles) && (dt = 60 ) # Arbitrary choice that works well for MODIS but may need revision for others
90
- t = startmfe: dt: stopmfe
91
-
92
- (position) && (t = [t[1 ]]) # Single position. Doing it here wastes work above but code is way cleaner
93
-
94
- out = Matrix {Float64} (undef, length (t), 4 )
95
- # r = SatelliteToolboxPropagators.Propagators.propagate!.(orbp, t)[1] # Doesn't work. Why?
96
-
97
- for n = 1 : length (t)
98
- r = SatelliteToolboxPropagators. Propagators. propagate! (orbp, t[n])[1 ]
99
- jd = epoch_jd + t[n] / (24 * 3600 )
100
- tt = SatelliteToolboxTransformations. r_eci_to_ecef (SatelliteToolboxTransformations. TEME (), SatelliteToolboxTransformations. PEF (), jd) * r
101
- out[n,1 ], out[n,2 ], out[n,3 ], out[n, 4 ] = tt[1 ], tt[2 ], tt[3 ], jd
102
- end
40
+ ! (isdefined (Main, :SatelliteToolboxPropagators )) &&
41
+ (printstyled (" Satellite Toolbox Propagators not loaded. Load them with:\n\n " ; color= :blue ); printstyled (" using SatelliteToolboxTle, SatelliteToolboxPropagators, SatelliteToolboxTransformations" ; color= :yellow ); return nothing )
42
+ sat_tracks_ext (; geocentric= geocentric, tiles= tiles, position= position, kwargs... )
43
+ end
103
44
104
- if (tiles)
105
- out = mapproject (out, E= true , I= true )
106
- return make_sat_tiles (out[1 ]. data, SCENE_HALFW[sat_name], sat_name)
107
- end
45
+ function sat_tracks_ext end
108
46
109
- if (geocentric)
110
- D = mat2ds (out, geom= UInt32 (2 ), colnames= [" X" , " Y" , " Z" , " JulianDay" ])
111
- else
112
- D = mapproject (out, E= true , I= true )
113
- D. colnames, D. proj4, D. geom = [" lon" , " lat" , " alt" , " JulianDay" ], GMT. prj4WGS84, UInt32 (2 )
114
- end
115
- D
47
+ function loadTLE (d:: Dict )
48
+ ! (isdefined (Main, :SatelliteToolboxTle )) &&
49
+ (printstyled (" Satellite Toolbox Propagators not loaded. Load them with:\n\n " ; color= :blue ); printstyled (" using SatelliteToolboxTle, SatelliteToolboxPropagators, SatelliteToolboxTransformations" ; color= :yellow ); return nothing )
50
+ loadTLE_ext (d)
116
51
end
117
52
53
+ function loadTLE_ext end
54
+
118
55
# --------------------------------------------------------------------------------------------
119
56
function getitDTime (val)
120
57
if isa (val, String) || isa (val, Tuple) ret:: DateTime = DateTime (val)
@@ -124,23 +61,6 @@ function getitDTime(val)
124
61
return ret
125
62
end
126
63
127
- # --------------------------------------------------------------------------------------------
128
- function loadTLE (d:: Dict )
129
- # Load a TLE or use a default one. In a function because it's used by two functions
130
- if ((val = find_in_dict (d, [:tle :TLE ])[1 ]) != = nothing )
131
- if (isa (val, String)) tle = SatelliteToolboxTle. read_tle (val)
132
- elseif (isa (val, Vector{String}) && length (val) == 2 )
133
- tle = SatelliteToolboxTle. read_tle (val[1 ], val[2 ])
134
- else
135
- error (" BAD input TLE data" )
136
- end
137
- else
138
- # tle = SatelliteToolbox.read_tle("C:\\v\\Landsat8.tle")
139
- tle = SatelliteToolboxTle. read_tle (" C:\\ v\\ AQUA.tle" )
140
- end
141
- tle
142
- end
143
-
144
64
# --------------------------------------------------------------------------------------------
145
65
function get_sat_name (d:: Dict ):: String
146
66
# Get the satellite name from kwargs (encoded in 'd'). Used by at least two functions
@@ -189,7 +109,7 @@ function sat_scenes(track, sat_name::String)
189
109
ll14 = geod (track[k,1 : 2 ], [azim[k]+ 90 , azim[k]- 90 ], halfwidth)[1 ]
190
110
ll23 = geod (track[k+ 5 ,1 : 2 ], [azim[k+ 5 ]+ 90 , azim[k+ 5 ]- 90 ], halfwidth)[1 ]
191
111
sc = get_MODIS_scene_name (track[k,4 ], sat_name)
192
- D[n+= 1 ] = GMTdataset ([ll14[1 : 1 ,:]; ll23[1 : 1 ,:]; ll23[2 : 2 ,:]; ll14[2 : 2 ,:]; ll14[1 : 1 ,:]], Float64[], Float64[], Dict {String, String} (), [" lon" ," lat" ], String[], sc, String[], " " , " " , 0 , GMT. Gdal. wkbPolygon)
112
+ D[n+= 1 ] = GMTdataset ([ll14[1 : 1 ,:]; ll23[1 : 1 ,:]; ll23[2 : 2 ,:]; ll14[2 : 2 ,:]; ll14[1 : 1 ,:]], Float64[], Float64[], GMT . DictSvS (), [" lon" ," lat" ], String[], sc, String[], " " , " " , 0 , GMT. Gdal. wkbPolygon)
193
113
end
194
114
D[1 ]. proj4 = GMT. prj4WGS84
195
115
D
@@ -237,7 +157,7 @@ function clip_orbits(track, bb::Vector{<:Real})
237
157
end_seg = [inds[2 : 2 : length (inds)]; length (azim)+ 1 ]
238
158
D = Vector {GMTdataset} (undef, length (begin_seg))
239
159
colnames, prj4 = isa (track, Vector) ? (track[1 ]. colnames, track[1 ]. proj4) : (track. colnames, track. proj4)
240
- for k = 1 : length (begin_seg)
160
+ for k = 1 : GMT . numel (begin_seg)
241
161
D[k] = GMTdataset (isa (segments, Vector) ? segments[1 ][begin_seg[k]: end_seg[k], :] : segments[begin_seg[k]: end_seg[k], :], Float64[], Float64[], GMT. DictSvS (), colnames, String[], " " , String[], prj4, " " , 0 , GMT. Gdal. wkbLineString)
242
162
end
243
163
D[1 ]. proj4 = GMT. prj4WGS84
@@ -312,7 +232,7 @@ function findscenes(lon::Real, lat::Real; kwargs...)
312
232
313
233
scenes = Vector {String} (undef, 0 )
314
234
dists = mapproject (D, G= (lon,lat))
315
- for k = 1 : length (dists)
235
+ for k = 1 : GMT . numel (dists)
316
236
d, ind = findmin (view (dists[k]. data, :,5 ))
317
237
if (d <= SCENE_HALFW[sat])
318
238
jd = datetime2julian (floor (julian2datetime (dists[k][ind,4 ]), Dates. Minute (5 )))
@@ -329,7 +249,7 @@ function day_night_orbits(D; day::Bool=false, night::Bool=false)
329
249
(! day && ! night) && return D # No selection requested
330
250
331
251
pass = zeros (Bool, length (D))
332
- for k = 1 : length (D)
252
+ for k = 1 : GMT . numel (D)
333
253
lon, lat = D[k][1 ,1 : 2 ]
334
254
jd = D[k][1 ,4 ]
335
255
raise, set = solar (I= @sprintf (" %.4f/%.4f+d%s" , lon, lat, string (julian2datetime (jd))), C= true )[5 : 6 ]
0 commit comments