-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.py
150 lines (150 loc) · 4.44 KB
/
module.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
{
"cells": [
{
"cell_type": "code",
"execution_count": 7,
"id": "963b1b03",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from mocpy import MOC\n",
"from astropy.io import votable"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "7bfde678",
"metadata": {},
"outputs": [],
"source": [
"def details(order):\n",
" no_ipix_cells = 12*4**(order)\n",
" print(f\"Order {order} has {no_ipix_cells} number of ipix cells\")"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "8dd66b55",
"metadata": {},
"outputs": [],
"source": [
"def current_order(order):\n",
" nside = 2**order\n",
" hp = HEALPix(nside=nside, order = 'nested', frame = ICRS())\n",
" coord = SkyCoord(table[\"_RA\"], table[\"_DE\"], frame= 'icrs', unit = 'deg')\n",
" ipix = hp.skycoord_to_healpix(coord)\n",
" main_list = np.sort(np.unique(np.abs((ipix))))\n",
" string_list = \" \".join(map(str, main_list))\n",
" \n",
" return main_list"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "a6c4b156",
"metadata": {},
"outputs": [],
"source": [
"def increase_order(order, main_list):\n",
" \n",
" nside = 2**order\n",
" hp = HEALPix(nside=nside, order = 'nested', frame = ICRS())\n",
" coord = SkyCoord(table[\"_RA\"], table[\"_DE\"], frame= 'icrs', unit = 'deg')\n",
" ipix = hp.skycoord_to_healpix(coord)\n",
" main_list = np.sort(np.unique(np.abs((ipix))))\n",
" string_list = \" \".join(map(str, main_list))\n",
" \n",
" combined_child_ipix = []\n",
" for ipix in main_list:\n",
" child_ipix = [(ipix << 2), (ipix << 2) + 1, (ipix << 2) + 2, (ipix << 2) + 3]\n",
" combined_child_ipix.extend(child_ipix)\n",
" string_inc = \" \".join(map(str, combined_child_ipix))\n",
" \n",
" return string_inc #This represents the list of ipix cells of the higher order in string format."
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "df2bcb92",
"metadata": {},
"outputs": [],
"source": [
"def My_MOC(order, main_list):\n",
" \n",
" main_list = current_order(order)\n",
" \n",
" MOC_Tree_child = []\n",
" MOC_Tree_parent = []\n",
" MOC_Tree_root = []\n",
"\n",
" if order == 0:\n",
" MOC_Tree_root.extend(main_list)\n",
" print(f'{order}/', MOC_Tree_root)\n",
" else:\n",
" j = 0\n",
" while j < 12*(4)**(order): \n",
"\n",
" ideal_siblings = [(j), (j+1), (j+2), (j+3)]\n",
"\n",
" if all(item in main_list for item in ideal_siblings):\n",
" # All siblings are present\n",
" # Replace with parent in the ideal siblings list, which is the first item in every 4 items\n",
"\n",
" MOC_Tree_parent.append(j>>2)\n",
"\n",
" else:\n",
" if j in main_list:\n",
" MOC_Tree_child.append(j)\n",
"\n",
" if j+1 in main_list:\n",
" MOC_Tree_child.append(j+1)\n",
"\n",
" if j+2 in main_list:\n",
" MOC_Tree_child.append(j+2)\n",
"\n",
" if j+3 in main_list:\n",
" MOC_Tree_child.append(j+3)\n",
"\n",
" j = j + 4\n",
"\n",
" unique_MOC_Tree_c = np.unique(MOC_Tree_child)\n",
" unique_MOC_Tree_p = np.unique(MOC_Tree_parent)\n",
"\n",
" #convert list into string\n",
"\n",
" parents_string = \" \".join(map(str, unique_MOC_Tree_p))\n",
" children_string = \" \".join(map(str, unique_MOC_Tree_c))\n",
" final_string = f\"{order-1}/{parents_string}\\n{order}/{children_string}\"\n",
"\n",
" return final_string"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}