Skip to content

Commit

Permalink
Merge pull request #55 from giovannifacchinetti99/main
Browse files Browse the repository at this point in the history
now the cube algorithm counts all the possible combinations between the pairs
  • Loading branch information
darioizzo authored Nov 1, 2023
2 parents 59572ba + 480a783 commit b9946d9
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions doc/utilities/cubes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"from copy import deepcopy\n",
"import time\n",
"from collections import defaultdict\n",
"import itertools\n",
"\n",
"# sgp4 imports\n",
"import sgp4\n",
Expand Down Expand Up @@ -167,7 +168,8 @@
" a list containing lists of satelites idx occupying the same cube\n",
" \"\"\"\n",
" # init\n",
" retval = []\n",
" in_same_cube = []\n",
" pairs = []\n",
" cubes = defaultdict(list)\n",
"\n",
" # We compute the floored Cartesian coordinates identifying the bins.\n",
Expand All @@ -180,8 +182,11 @@
" # We find bins with more than one object\n",
" for key in cubes:\n",
" if len(cubes[key]) > 1:\n",
" retval.append(cubes[key])\n",
" return retval"
" in_same_cube.append(cubes[key])\n",
" # We compute all the combinations between the pairs\n",
" for group in in_same_cube:\n",
" pairs.extend(((list(itertools.combinations(group, 2)))))\n",
" return pairs"
]
},
{
Expand All @@ -205,7 +210,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"33.1 ms ± 178 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
"28.1 ms ± 4.92 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
]
}
],
Expand Down Expand Up @@ -277,7 +282,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Time to perform all numerical integrations: 19.566089153289795\n"
"Time to perform all numerical integrations: 7.937011003494263\n"
]
}
],
Expand Down Expand Up @@ -309,19 +314,22 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Collision! pair: [14084, 14352], years: 0.6844626967830253\n",
"Collision! pair: [8170, 13942], years: 1.7659137577002053\n",
"Collision! pair: [12625, 18100], years: 1.943874058863792\n",
"Collision! pair: [13644, 15509], years: 2.6694045174537986\n",
"Collision! pair: [13059, 15181], years: 6.1738535249828885\n",
"Collision! pair: [13322, 14410], years: 9.267624914442163\n",
"Collision! pair: [1012, 11892], years: 10.581793292265571\n",
"Collision! pair: [4762, 4984], years: 16.632443531827516\n",
"Collision! pair: [1671, 5447], years: 16.79671457905544\n",
"Time elasped: 67.86483788490295\n",
"Decayed objects: 4990\n",
"Number of collisions: 9\n",
"Expected number of collisions: 11.538803066221181\n"
"Collision! pair: (15977, 16424), years: 0.8213552361396304\n",
"Collision! pair: (15935, 16388), years: 1.273100616016427\n",
"Collision! pair: (1041, 6320), years: 1.4921286789869952\n",
"Collision! pair: (13484, 13591), years: 3.1074606433949348\n",
"Collision! pair: (13689, 13950), years: 6.365503080082136\n",
"Collision! pair: (14107, 15279), years: 10.704996577686517\n",
"Collision! pair: (3897, 15176), years: 11.567419575633128\n",
"Collision! pair: (10109, 11757), years: 12.320328542094456\n",
"Collision! pair: (12350, 13019), years: 13.566050650239562\n",
"Collision! pair: (4910, 12250), years: 14.099931553730322\n",
"Collision! pair: (13633, 14012), years: 15.824777549623546\n",
"Collision! pair: (2869, 3364), years: 16.892539356605067\n",
"Time elasped: 51.43294858932495\n",
"Decayed objects: 4992\n",
"Number of collisions: 12\n",
"Expected number of collisions: 13.336892648579166\n"
]
}
],
Expand All @@ -338,11 +346,11 @@
" undecayed = undecayed - decayed\n",
" undecayed_l = np.array([j for j in undecayed])\n",
" # We detect all satellites couples in the same cube of Lcube km size\n",
" collision = cubes(r_sgp4[undecayed_l,i,:], cube_dimension = Lcube)\n",
" pairs = cubes(r_sgp4[undecayed_l,i,:], cube_dimension = Lcube)\n",
" #kdt = KDTree(r[undecayed_l,i,:])\n",
" #collision = list(kdt.query_pairs(Lcube))\n",
" #print(collision)\n",
" for pair in collision:\n",
" for pair in pairs:\n",
" # we get the indexes in r,v\n",
" idx1 = undecayed_l[pair[0]]\n",
" idx2 = undecayed_l[pair[1]]\n",
Expand Down Expand Up @@ -404,7 +412,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8 | packaged by conda-forge | (main, Nov 22 2022, 08:26:04) [GCC 10.4.0]"
"version": "3.11.6"
},
"vscode": {
"interpreter": {
Expand Down

0 comments on commit b9946d9

Please sign in to comment.