Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def makecubelimits(axis, centers=None, hw=None):
- lims = ax.get_xlim(), ax.get_ylim(), ax.get_zlim()
- if centers == None:
- centers = [0.5*sum(pair) for pair in lims]
- if hw == None:
- widths = [pair[1] - pair[0] for pair in lims]
- hw = 0.5*max(widths)
- ax.set_xlim(centers[0]-hw, centers[0]+hw)
- ax.set_ylim(centers[1]-hw, centers[1]+hw)
- ax.set_zlim(centers[2]-hw, centers[2]+hw)
- print("hw was None so set to:", hw)
- else:
- try:
- hwx, hwy, hwz = hw
- print("ok hw requested: ", hwx, hwy, hwz)
- ax.set_xlim(centers[0]-hwx, centers[0]+hwx)
- ax.set_ylim(centers[1]-hwy, centers[1]+hwy)
- ax.set_zlim(centers[2]-hwz, centers[2]+hwz)
- except:
- print("nope hw requested: ", hw)
- ax.set_xlim(centers[0]-hw, centers[0]+hw)
- ax.set_ylim(centers[1]-hw, centers[1]+hw)
- ax.set_zlim(centers[2]-hw, centers[2]+hw)
- return centers, hw
- def make_lats_lons():
- theta = np.linspace(0, twopi, 201)
- cth, sth, zth = [f(theta) for f in (np.cos, np.sin, np.zeros_like)]
- lon0 = Re*np.vstack((cth, zth, sth))
- lons = []
- for phi in rads*np.arange(0, 180, 15):
- cph, sph = [f(phi) for f in (np.cos, np.sin)]
- lon = np.vstack((lon0[0]*cph - lon0[1]*sph,
- lon0[1]*cph + lon0[0]*sph,
- lon0[2]) )
- lons.append(lon)
- lat0 = Re*np.vstack((cth, sth, zth))
- lats = []
- for phi in rads*np.arange(-75, 90, 15):
- cph, sph = [f(phi) for f in (np.cos, np.sin)]
- lat = Re*np.vstack((cth*cph, sth*cph, zth+sph))
- lats.append(lat)
- return lats, lons
- debris_TLEs = """MICROSAT-R DEB
- 1 44117U 19006C 19094.64070647 .00455742 26153-4 80334-2 0 9998
- 2 44117 95.3237 4.1062 0861779 350.0688 8.4347 13.95892635 1153
- MICROSAT-R DEB
- 1 44118U 19006D 19094.46329163 .03050626 31109-2 24862-1 0 9992
- 2 44118 96.1629 6.2262 0272847 356.3910 3.5361 15.35582568 1229
- MICROSAT-R DEB
- 1 44119U 19006E 19094.46646588 .06439739 12728-5 97304-2 0 9996
- 2 44119 94.9178 4.6437 0181254 28.4691 332.6337 15.80679644 1248
- MICROSAT-R DEB
- 1 44120U 19006F 19095.00036339 .00527918 52265-4 56871-2 0 9990
- 2 44120 95.5094 5.4447 0422033 357.9318 2.0147 14.99373378 1301
- MICROSAT-R DEB
- 1 44121U 19006G 19095.01964115 .01508404 50846-3 14651-1 0 9995
- 2 44121 95.5844 5.6491 0360459 355.4980 4.3038 15.14169030 1318
- MICROSAT-R DEB
- 1 44122U 19006H 19094.75258187 .01086181 27867-3 91501-2 0 9991
- 2 44122 95.6006 5.5919 0297801 357.2150 2.7421 15.29557898 1264
- MICROSAT-R DEB
- 1 44123U 19006J 19095.06527372 .00842597 15862-3 65277-2 0 9995
- 2 44123 96.9468 7.8798 0329609 328.4083 29.7731 15.24689115 1321
- MICROSAT-R DEB
- 1 44124U 19006K 19095.01748409 .02829797 25262-2 22519-1 0 9991
- 2 44124 95.5327 5.6875 0284095 357.7110 2.2814 15.33730995 1318
- MICROSAT-R DEB
- 1 44125U 19006L 19094.82916466 .01599065 62368-3 14033-1 0 9992
- 2 44125 95.4484 5.4059 0316221 356.8319 3.0912 15.25133571 1273
- MICROSAT-R DEB
- 1 44126U 19006M 19094.58326523 .03116733 28646-2 27747-1 0 9990
- 2 44126 95.4679 5.2200 0335316 358.4564 3.3570 15.21318838 1238
- MICROSAT-R DEB
- 1 44127U 19006N 19095.03666368 .02187619 17695-2 13453-1 0 9997
- 2 44127 96.0706 6.8319 0171368 349.2468 10.5144 15.59755513 1133
- MICROSAT-R DEB
- 1 44128U 19006P 19095.07940328 .00382116 42589-4 23241-2 0 9999
- 2 44128 96.2830 7.3605 0146784 354.4416 5.5208 15.63728289 1155
- MICROSAT-R DEB
- 1 44129U 19006Q 19094.99492147 .01670420 99478-3 93211-2 0 9992
- 2 44129 96.2485 7.1558 0148156 351.6408 8.2387 15.65407990 1133
- MICROSAT-R DEB
- 1 44130U 19006R 19095.00058036 .00153632 65541-5 14379-2 0 9996
- 2 44130 96.3346 7.0172 0280946 346.9670 12.4412 15.30818108 1129
- MICROSAT-R DEB
- 1 44131U 19006S 19094.06316062 .00600230 47213-4 10182-1 0 9991
- 2 44131 95.4882 4.0634 0798088 353.5981 5.5555 14.10377672 757
- MICROSAT-R DEB
- 1 44132U 19006T 19094.73963079 .12979788 19429-5 11454-1 0 9994
- 2 44132 96.4009 7.4170 0027412 339.9728 20.0480 16.12094571 954
- MICROSAT-R DEB
- 1 44133U 19006U 19095.04008018 .00142556 57788-5 12170-2 0 9992
- 2 44133 96.4939 7.2182 0324841 329.5554 28.7166 15.23879318 964
- MICROSAT-R DEB
- 1 44134U 19006V 19094.98522109 .00061942 16890-5 96352-3 0 9990
- 2 44134 96.0918 5.7448 0663376 349.5401 9.2536 14.41154034 907
- MICROSAT-R DEB
- 1 44135U 19006W 19094.87046930 .02680902 37410-2 12244-1 0 9991
- 2 44135 96.2107 7.1091 0112268 355.6726 4.3559 15.75469894 954
- MICROSAT-R DEB
- 1 44136U 19006X 19095.04109403 .00809162 14876-3 71821-2 0 9995
- 2 44136 94.5750 4.3171 0296364 354.3855 5.4088 15.28815365 963
- MICROSAT-R DEB
- 1 44137U 19006Y 19094.80053007 .03433409 10222-1 12967-1 0 9991
- 2 44137 96.1784 7.0131 0082221 347.2816 12.6380 15.84654719 958
- MICROSAT-R DEB
- 1 44138U 19006Z 19095.04584499 .01687024 20239-5 42295-3 0 9997
- 2 44138 96.6639 8.4300 0125246 256.7733 101.9558 16.11801396 1016
- MICROSAT-R DEB
- 1 44139U 19006AA 19095.01018649 .01863761 14334-2 76060-2 0 9990
- 2 44139 95.4641 6.0314 0132951 316.5326 42.5520 15.73941483 983
- MICROSAT-R DEB
- 1 44140U 19006AB 19094.99401962 .00937025 14528-3 10253-1 0 9993
- 2 44140 95.6393 5.3278 0564445 4.3929 356.1942 14.68800488 1288
- MICROSAT-R DEB
- 1 44141U 19006AC 19095.05118892 .00929759 13751-3 12486-1 0 9991
- 2 44141 96.1001 5.9232 0590442 356.3473 3.3508 14.59478967 1289
- MICROSAT-R DEB
- 1 44142U 19006AD 19095.08823010 .00450387 29805-4 67642-2 0 9999
- 2 44142 96.5890 6.4539 0677192 345.9062 12.4022 14.38737046 1276
- MICROSAT-R DEB
- 1 44143U 19006AE 19095.05197432 .09474171 20938-5 60107-2 0 9993
- 2 44143 96.7877 8.4977 0027864 281.4570 78.3589 16.16667874 1307
- MICROSAT-R DEB
- 1 44144U 19006AF 19095.07438984 .00377444 46376-4 18035-2 0 9998
- 2 44144 95.6350 6.4585 0094274 347.7575 12.1403 15.76217231 645
- MICROSAT-R DEB
- 1 44145U 19006AG 19095.04888338 .01607578 46803-3 17450-1 0 9996
- 2 44145 95.6463 5.3980 0532778 2.6283 357.7536 14.75786071 597
- MICROSAT-R DEB
- 1 44146U 19006AH 19095.02837073 .00089273 19163-5 14515-3 0 9992
- 2 44146 96.5911 8.1980 0103814 264.0180 94.9258 15.93838830 630
- MICROSAT-R DEB
- 1 44147U 19006AJ 19095.06147560 .00157958 41062-5 23269-2 0 9996
- 2 44147 95.7673 5.1413 0774807 1.8709 358.5090 14.17974235 565
- MICROSAT-R DEB
- 1 44148U 19006AK 19095.05278179 .00260163 23632-4 10121-2 0 9995
- 2 44148 96.6499 8.1178 0099791 308.5716 50.6643 15.79515068 625
- MICROSAT-R DEB
- 1 44149U 19006AL 19095.04985371 .00138584 63554-5 90991-3 0 9997
- 2 44149 96.1023 6.9822 0182961 3.3819 356.8627 15.56156057 618
- MICROSAT-R DEB
- 1 44150U 19006AM 19094.24965542 .03380564 82179-2 13716-1 0 9997
- 2 44150 96.1314 6.4062 0109734 347.4104 13.2096 15.79057773 490
- MICROSAT-R DEB
- 1 44151U 19006AN 19095.07776720 .01139469 39308-3 70293-2 0 9993
- 2 44151 96.1917 7.1013 0175670 351.4915 8.3374 15.58677746 614
- MICROSAT-R DEB
- 1 44152U 19006AP 19095.00425471 .00274120 17165-4 25192-2 0 9990
- 2 44152 95.0640 5.0844 0281536 351.5372 8.1175 15.31038960 596
- MICROSAT-R DEB
- 1 44153U 19006AQ 19095.10037387 .00335950 24673-4 29766-2 0 9999
- 2 44153 95.0683 5.1111 0309678 359.8179 0.2901 15.26184379 608
- MICROSAT-R DEB
- 1 44154U 19006AR 19095.03166584 .00440937 19896-4 10013-1 0 9991
- 2 44154 96.7141 5.2587 1287411 353.6687 4.9420 12.99476955 508
- MICROSAT-R DEB
- 1 44155U 19006AS 19095.04684293 .00311061 27074-4 21063-2 0 9995
- 2 44155 96.0164 6.8512 0167909 345.7280 13.9264 15.58091161 608
- MICROSAT-R DEB
- 1 44156U 19006AT 19094.69707226 .05553740 38015-1 26327-1 0 9996
- 2 44156 96.2572 7.0051 0089971 352.8442 7.1537 15.81344557 554
- MICROSAT-R DEB
- 1 44157U 19006AU 19094.99880469 .00367995 17112-4 47305-2 0 9999
- 2 44157 95.4389 4.4696 0889261 7.5858 353.7787 13.95328540 535
- MICROSAT-R DEB
- 1 44158U 19006AV 19095.70863833 .00188098 10550-4 13478-2 0 9994
- 2 44158 96.3272 7.8877 0184127 337.4424 21.8813 15.54187536 705
- MICROSAT-R DEB
- 1 44159U 19006AW 19094.21895253 .16047287 19078-5 10135-1 0 9993
- 2 44159 96.3834 6.9600 0020619 341.3096 18.7434 16.17187137 484
- MICROSAT-R DEB
- 1 44160U 19006AX 19095.08101037 .00234973 69896-5 43180-2 0 9994
- 2 44160 95.3215 4.1745 0976328 347.1157 10.6586 13.70329689 538
- MICROSAT-R DEB
- 1 44161U 19006AY 19095.04864178 .00114018 53545-5 36847-3 0 9997
- 2 44161 96.2750 7.3879 0190135 296.2142 61.9683 15.67668399 605
- MICROSAT-R DEB
- 1 44162U 19006AZ 19095.07873983 .00836557 10839-3 11532-1 0 9993
- 2 44162 96.0404 5.8159 0611774 356.4193 3.2724 14.54410367 561
- MICROSAT-R DEB
- 1 44163U 19006BA 19095.07356566 .01011177 21458-3 99281-2 0 9998
- 2 44163 95.5073 5.5907 0365152 357.0211 2.8845 15.12958148 434
- MICROSAT-R DEB
- 1 44164U 19006BB 19095.09553700 .00177287 73485-5 19099-2 0 9992
- 2 44164 96.6780 7.3048 0403399 338.2118 20.2360 15.03284262 436
- MICROSAT-R DEB
- 1 44165U 19006BC 19095.07242078 .00225857 14659-4 14543-2 0 9997
- 2 44165 96.7326 7.9452 0202955 324.2145 34.5647 15.52942310 445
- MICROSAT-R DEB
- 1 44166U 19006BD 19095.04140141 .00362798 15115-4 72119-2 0 9990
- 2 44166 95.7142 4.5173 1043123 357.1107 2.4300 13.54482014 381
- MICROSAT-R DEB
- 1 44167U 19006BE 19095.05516230 .01576780 86773-3 88344-2 0 9991
- 2 44167 95.7015 6.3580 0149222 336.5257 22.9240 15.65131666 441
- MICROSAT-R DEB
- 1 44168U 19006BF 19095.04961209 .00527696 86952-4 28336-2 0 9997
- 2 44168 96.3473 7.5037 0118347 350.9074 9.0046 15.70583958 449
- MICROSAT-R DEB
- 1 44169U 19006BG 19095.04600491 .00244967 21667-4 83571-3 0 9993
- 2 44169 97.2645 9.1181 0110262 298.8316 60.1918 15.80462905 294
- MICROSAT-R DEB
- 1 44170U 19006BH 19094.29776842 .01477004 51465-3 13916-1 0 9998
- 2 44170 94.7415 4.0349 0321201 354.4045 5.3637 15.22743226 167
- MICROSAT-R DEB
- 1 44171U 19006BJ 19095.07665140 .00743869 12904-3 63401-2 0 9998
- 2 44171 95.6686 6.0475 0278790 356.6778 3.2606 15.33067039 280
- MICROSAT-R DEB
- 1 44172U 19006BK 19093.24832937 .06491989 10561-5 62839-2 0 9998
- 2 44172 94.5693 3.5604 0110923 40.5090 320.5757 15.99896821 05
- MICROSAT-R DEB
- 1 44173U 19006BL 19093.25107377 .00092895 25285-5 10000-2 0 9992
- 2 44173 95.4100 4.1032 0410196 3.5176 356.9078 15.01902668 09"""
- satellite_TLE = """MICROSAT-R
- 1 43947U 19006A 19095.00723967 .00076236 19544-5 99204-4 0 9991
- 2 43947 96.6394 8.2964 0101419 255.9464 103.0490 15.97527363 11238"""
- rocket_body_TLE = """KALAMSAT-V2 & PSLV R/B
- 1 43948U 19006B 19095.85094231 .00001425 00000-0 39567-4 0 9996
- 2 43948 98.7968 24.1719 0005302 24.0083 336.1406 15.39198615 10921"""
- ISS_TLE = """ISS (ZARYA)
- 1 25544U 98067A 19096.14813315 .00001499 00000-0 31543-4 0 9994
- 2 25544 51.6445 359.3289 0002204 153.5880 353.9123 15.52488458164067"""
- # https://celestrak.com/NORAD/elements/2019-006.php
- debris_TLEs = debris_TLEs.splitlines()
- debris_triplets = zip(*[debris_TLEs[i::3] for i in range(3)])
- class Thing(object):
- def __init__(self, name, L1, L2):
- self.name = name.rstrip()
- self.obj = EarthSatellite(L1, L2)
- import numpy as np
- import matplotlib.pyplot as plt
- from skyfield.api import Topos, Loader, EarthSatellite
- from mpl_toolkits.mplot3d import Axes3D
- halfpi, pi, twopi = [f*np.pi for f in (0.5, 1, 2)]
- degs, rads = 180/pi, pi/180
- Re = 6378.137 # km
- load = Loader('~/Documents/fishing/SkyData') # avoids multiple copies of large files
- data = load('de421.bsp')
- # data405 = load('de405.bsp')
- # data = data405 # need the longer time range for the outer planets
- ts = load.timescale()
- earth = data['earth']
- debris = []
- for triplet in debris_triplets: #debris
- thing = Thing(*triplet)
- debris.append(thing)
- satellite = Thing(*satellite_TLE.splitlines())
- rocket_body = Thing(*rocket_body_TLE.splitlines())
- ISS = Thing(*ISS_TLE.splitlines())
- minutes = np.arange(-150, 150.0, 0.1)
- times = ts.utc(2019, 4, 6, 0, minutes)
- for thing in debris + [satellite, rocket_body, ISS]:
- thing.posn = thing.obj.at(times).position.km
- thing.r = np.sqrt((thing.posn**2).sum(axis=0))
- thing.z = thing.posn[2]
- i1 = np.argmax((thing.z[ 2:]>0) * (thing.z[ 1:-1]<=0)) + 2
- i2 = np.argmax((thing.z[i1+2:]>0) * (thing.z[i1+1:-1]<=0)) + i1+2
- thing.i1, thing.i2 = i1, i2
- if True:
- fig = plt.figure(figsize=[10, 8]) # [12, 10]
- lw = 0.5
- ax = fig.add_subplot(1, 1, 1, projection='3d')
- for deb in debris:
- x, y, z = deb.posn[:, deb.i1:deb.i2+1]
- ax.plot(x, y, z, linewidth=0.5)
- for thing in (satellite, rocket_body, ISS):
- x, y, z = thing.posn[:, thing.i1:thing.i2+1]
- if 'ISS' in thing.name:
- ax.plot(x, y, z, '-k', linewidth=2)
- else:
- ax.plot(x, y, z, linewidth=0.5)
- lats, lons = make_lats_lons()
- if False:
- for x, y, z in lons:
- ax.plot(x, y, z, '-k', linewidth=0.5)
- for x, y, z in lats:
- ax.plot(x, y, z, '-k', linewidth=0.5)
- centers, hw = makecubelimits(ax)
- print("centers are: ", centers)
- print("hw is: ", hw)
- plt.show()
- if True:
- fig = plt.figure() # [12, 10]
- ax = fig.add_subplot(1, 1, 1) # , projection='3d'
- dmins = minutes[1] - minutes[0]
- for thing in debris:
- r = thing.r[thing.i1:thing.i2+1]
- # mins = minutes[thing.i1:thing.i2+1]
- mins = dmins * np.arange(len(r))
- ax.plot(mins, r - Re, linewidth=0.5)
- for thing in (satellite, rocket_body, ISS):
- r = thing.r[thing.i1:thing.i2+1]
- # mins = minutes[thing.i1:thing.i2+1]
- mins = dmins * np.arange(len(r))
- if 'ISS' in thing.name:
- ax.plot(mins, r - Re, '-k', linewidth=2)
- else:
- ax.plot(mins, r - Re, linewidth=0.5)
- plt.show()
RAW Paste Data