''' these functions were needed to create the directory_address.txt file, which stores pointing information, roll angle, link in the cloud to each obsid. SInce this file was already created/edited, we don't need to use these functions constantly. Hence they designated "one time only" functions. ''' WISE_EXTRA=np.array([10231, 13120, 14354, 16468, 19939, 5873, 10239, 13126, 14361, 16469, 19946, 5874, 10257, 13128, 14371, 16470, 19972, 5876, 10258, 13132, 14372, 16471, 2153, 5877, 10259, 13135, 14380, 16472, 2155, 5878, 10411, 13137, 14437, 16486, 2160, 5879, 10413, 13138, 14448, 16487, 2162, 5880, 10439, 13145, 14473, 16514, 2164, 5881, 10444, 13155, 1454, 16515, 2167, 5882, 10448, 13194, 14566, 16516, 2168, 5883, 10468, 13201, 15101, 16524, 2170, 5884, 10469, 13213, 15103, 16525, 2172, 5895, 10470, 13232, 15109, 16526, 2201, 6105, 10471, 13233, 15110, 1654, 2202, 6107, 10720, 13382, 15111, 16545, 2207, 6163, 10786, 13391, 15112, 16562, 2230, 6173, 10790, 13392, 15114, 1666, 2240, 6258, 10797, 13394, 15116, 16969, 2264, 6264, 10798, 13395, 15118, 17160, 2265, 6266, 10822, 13396, 15122, 17176, 2541, 6276, 10862, 13397, 15123, 17179, 3183, 6292, 10918, 13398, 15127, 17180, 3188, 6294, 10922, 13401, 15128, 17182, 3189, 6295, 10924, 13402, 15129, 17184, 3201, 6296, 11530, 13403, 15130, 17185, 3206, 6393, 11613, 13405, 15133, 17187, 3249, 6791, 11621, 13412, 15138, 17188, 3251, 6891, 11622, 13413, 15141, 17189, 3255, 6950, 11623, 13414, 15142, 17190, 3256, 6951, 11624, 13415, 15143, 17202, 3259, 6952, 11637, 13416, 15144, 17203, 3261, 6953, 11639, 13417, 15146, 17207, 3262, 6954, 11653, 13424, 15148, 17208, 3263, 6955, 11655, 13442, 15150, 17211, 3264, 6956, 11657, 13443, 15151, 17212, 3266, 6972, 11658, 13444, 15155, 17215, 3267, 7016, 11659, 13445, 15157, 17217, 3270, 7017, 11660, 13446, 15160, 17219, 3273, 7018, 11681, 13447, 15162, 17223, 3278, 7019, 11682, 13448, 15163, 17226, 3280, 7020, 11719, 13449, 15164, 17227, 3285, 7059, 11730, 13450, 15177, 17228, 3286, 7191, 11738, 13451, 15189, 17229, 3288, 7225, 11741, 13452, 15254, 17231, 3300, 7248, 11742, 13453, 15260, 17232, 3302, 7250, 11744, 13454, 15266, 17233, 3306, 7323, 11746, 13455, 15279, 17399, 3307, 7324, 11747, 13456, 15280, 17400, 3349, 7328, 11748, 13457, 15281, 17401, 3351, 7359, 11754, 13462, 15285, 17402, 3353, 7374, 11758, 13463, 15303, 17403, 3578, 7686, 11763, 13464, 15304, 17404, 3579, 7688, 11789, 13465, 15308, 17406, 3581, 7698, 11791, 13466, 15309, 17407, 3586, 7700, 11792, 13467, 15313, 17408, 3710, 7705, 11799, 13468, 15314, 17409, 3712, 7708, 11859, 13469, 15363, 17410, 3922, 7712, 11864, 13470, 15367, 17411, 3986, 7718, 11867, 13471, 15371, 17427, 4002, 7914, 11870, 13472, 15372, 17428, 4168, 7915, 11874, 13475, 15373, 17429, 4169, 799, 11876, 13476, 15376, 17430, 4170, 8265, 11877, 13477, 15378, 17459, 4171, 8269, 11996, 13479, 15379, 17462, 4173, 840, 11997, 13480, 15380, 17463, 4174, 842, 11998, 13481, 15386, 17476, 4175, 8471, 12001, 13482, 15389, 17477, 4176, 8477, 12002, 13483, 15391, 17479, 4177, 8557, 12014, 13484, 15392, 17480, 4208, 8640, 12088, 13485, 15487, 17482, 4210, 868, 12091, 13487, 15488, 17501, 4211, 874, 12092, 13488, 15489, 17502, 4212, 888, 12096, 13489, 15490, 17503, 4273, 889, 12153, 13490, 15491, 17504, 4274, 8918, 12175, 13491, 15492, 17536, 4275, 892, 12177, 13492, 15538, 17597, 4276, 893, 12178, 13493, 15540, 17598, 4661, 905, 12179, 13494, 15547, 17599, 4662, 907, 12180, 13495, 15560, 17609, 4926, 913, 12181, 13496, 15571, 17611, 4928, 914, 12185, 13497, 15572, 17612, 4966, 9164, 12186, 13498, 15573, 17615, 4967, 920, 12189, 13499, 15574, 17616, 4971, 924, 12191, 13500, 15579, 17617, 4973, 927, 12194, 13501, 15582, 17618, 4980, 9333, 12196, 13504, 15583, 17619, 4981, 9334, 12238, 13505, 15588, 17620, 4982, 9335, 12240, 13506, 15589, 17623, 4993, 9341, 12243, 13507, 15658, 17625, 4994, 9345, 12244, 13517, 15665, 17628, 5010, 9374, 12245, 13518, 16028, 17629, 5011, 938, 12246, 13597, 16029, 17632, 5013, 9383, 12247, 13599, 16121, 17683, 513, 9385, 12250, 13600, 16122, 17684, 5183, 9392, 12252, 13601, 16123, 17698, 522, 9393, 12258, 13602, 16124, 17868, 531, 9409, 12259, 1386, 16125, 18266, 532, 9410, 12260, 13976, 16126, 18285, 534, 9411, 12262, 13978, 16127, 18290, 536, 9412, 12263, 13979, 16129, 18298, 540, 9413, 12265, 13980, 16131, 18353, 541, 9414, 12266, 13982, 16132, 18424, 542, 9415, 12268, 13997, 16133, 18427, 544, 9416, 12269, 14001, 16135, 18428, 548, 9417, 12270, 14002, 16139, 18429, 550, 9418, 12273, 14006, 16147, 18430, 553, 9419, 12274, 14010, 16149, 18431, 5749, 9427, 12278, 14012, 16152, 18432, 575, 9429, 12282, 14013, 16153, 18434, 5751, 9449, 12286, 14014, 16155, 18435, 5752, 9543, 12288, 14017, 16157, 18436, 5753, 957, 12300, 14018, 16226, 18437, 5755, 9595, 12302, 14022, 16228, 18438, 5756, 966, 12305, 14023, 16229, 18439, 5758, 967, 12306, 14025, 16272, 18480, 5760, 9897, 12308, 14027, 16273, 18481, 5762, 12309, 14034, 16275, 18592, 5764, 12473, 14035, 16278, 18594, 5778, 12813, 14037, 16279, 18595, 5780, 12815, 14038, 16280, 18624, 5797, 12817, 14039, 16282, 18632, 5798, 12819, 14042, 16285, 18637, 5799, 12836, 14050, 16292, 18711, 580, 12839, 14270, 16345, 18822, 5809, 12878, 14271, 16346, 18824, 5814, 12892, 14272, 16350, 18825, 5817, 12894, 14273, 16352, 18847, 5818, 12901, 14274, 16353, 18850, 583, 12913, 14275, 16354, 18853, 5837, 13020, 14333, 16355, 18877, 5843, 13021, 14338, 16373, 19869, 5844, 13023, 14343, 16434, 19870, 5861, 13108, 14345, 16435, 19871, 5862, 13109, 14346, 16436, 19872, 5866, 13110, 14347, 16437, 19873, 5867, 13111, 14349, 16438, 19874, 5868, 13112, 14350, 16439, 19875, 5871, 13113, 14351, 16467, 19876, 5872]) main_stack2=np.array([304, 324, 441, 523, 537, 538, 539, 543, 546, 547, 549, 552, 581, 582, 894, 909, 910, 937, 939]) sdss1=np.array([10230, 10246, 10267, 10271, 10424, 10432, 10436, 10442, 10450, 10454, 10458, 10748, 10803, 10848, 10896, 10923, 11636, 11710, 11714, 11726, 11765, 11961, 11967, 12033, 10241, 10249, 10268, 10272, 10425, 10433, 10437, 10445, 10451, 10455, 10459, 10769, 10804, 10849, 10898, 11633, 11643, 11711, 11718, 11727, 11768, 11962, 12025, 12036, 10242, 10252, 10269, 10273, 10426, 10434, 10438, 10447, 10452, 10456, 10534, 10785, 10805, 10876, 10899, 11634, 11644, 11712, 11723, 11728, 11770, 11963, 12026, 10244, 10266, 10270, 10415, 10427, 10435, 10441, 10449, 10453, 10457, 10744, 10794, 10847, 10877, 10908, 11635, 11684, 11713, 11725, 11761, 11960, 11964, 12027]) sdss3=np.array([304, 324, 378, 380, 517, 530, 533, 536, 538, 540, 542, 544, 547, 550, 555, 583, 874, 894, 904, 909, 920, 925, 937, 939, 966, 322, 361, 379, 502, 523, 532, 534, 537, 539, 541, 543, 546, 549, 552, 580, 868, 887, 900, 907, 910, 924, 927, 938, 957, 967]) main_stack1=np.array([1431, 1672, 2161, 2169, 2312, 2405, 2409, 5016, 5018, 5020, 5022, 7948, 8592, 8594, 8596, 9390, 9578, 9596, 1641, 2159, 2166, 2239, 2313, 2406, 5015, 5017, 5019, 5021, 6164, 8591, 8593, 8595, 8597, 9575, 9593, 9718]) main_stack3=np.array([11641, 12051, 12197, 12283, 12893, 13986, 14043, 15024, 15168, 15228, 15253, 15322, 15759, 16180, 16239, 16455, 16620, 17225, 17299, 17417, 17478, 17608, 18247, 18719, 11645, 12052, 12213, 12284, 12914, 13988, 14046, 15084, 15170, 15229, 15255, 15368, 16137, 16181, 16271, 16456, 16641, 17230, 17300, 17423, 17490, 17610, 18248, 18730, 11724, 12053, 12218, 12307, 13133, 13993, 14348, 15105, 15180, 15234, 15256, 15375, 16140, 16182, 16306, 16457, 16644, 17287, 17301, 17424, 17535, 17613, 18250, 18755, 11771, 12054, 12219, 12811, 13134, 13994, 14355, 15106, 15188, 15235, 15257, 15377, 16141, 16183, 16321, 16458, 16968, 17288, 17302, 17425, 17542, 17614, 18291, 18835, 11878, 12055, 12220, 12812, 13192, 13995, 14356, 15117, 15190, 15236, 15258, 15381, 16144, 16184, 16340, 16459, 17154, 17289, 17303, 17426, 17546, 17621, 18299, 19944, 11879, 12123, 12222, 12814, 13193, 13996, 14387, 15119, 15191, 15238, 15259, 15598, 16145, 16185, 16341, 16460, 17161, 17290, 17304, 17431, 17552, 17622, 18593, 19964, 12043, 12128, 12223, 12816, 13374, 14000, 14406, 15136, 15208, 15239, 15261, 15600, 16146, 16186, 16342, 16461, 17170, 17291, 17305, 17432, 17556, 17624, 18626, 12044, 12129, 12227, 12818, 13375, 14003, 14410, 15137, 15209, 15241, 15262, 15603, 16148, 16187, 16343, 16462, 17183, 17292, 17306, 17433, 17573, 17626, 18627, 12045, 12135, 12230, 12820, 13376, 14004, 14411, 15153, 15211, 15242, 15282, 15605, 16151, 16188, 16347, 16463, 17199, 17293, 17307, 17434, 17589, 17627, 18635, 12046, 12137, 12231, 12821, 13594, 14005, 14415, 15158, 15212, 15245, 15284, 15606, 16175, 16189, 16450, 16544, 17200, 17294, 17308, 17435, 17590, 17633, 18702, 12047, 12138, 12232, 12822, 13595, 14007, 14431, 15159, 15213, 15246, 15288, 15614, 16176, 16190, 16451, 16573, 17201, 17295, 17309, 17436, 17591, 17634, 18703, 12048, 12187, 12233, 12885, 13596, 14008, 14451, 15161, 15214, 15250, 15289, 15653, 16177, 16191, 16452, 16582, 17221, 17296, 17310, 17437, 17592, 17656, 18704, 12049, 12188, 12234, 12886, 13598, 14026, 14675, 15166, 15218, 15251, 15305, 15756, 16178, 16227, 16453, 16599, 17222, 17297, 17311, 17438, 17595, 17677, 18705, 12050, 12195, 12254, 12887, 13981, 14041, 15023, 15167, 15227, 15252, 15306, 15758, 16179, 16238, 16454, 16600, 17224, 17298, 17416, 17474, 17596, 18231, 1870911641, 12051, 12197, 12283, 12893, 13986, 14043, 15024, 15168, 15228, 15253, 15322, 15759, 16180, 16239, 16455, 16620, 17225, 17299, 17417, 17478, 17608, 18247, 18719, 11645, 12052, 12213, 12284, 12914, 13988, 14046, 15084, 15170, 15229, 15255, 15368, 16137, 16181, 16271, 16456, 16641, 17230, 17300, 17423, 17490, 17610, 18248, 18730, 11724, 12053, 12218, 12307, 13133, 13993, 14348, 15105, 15180, 15234, 15256, 15375, 16140, 16182, 16306, 16457, 16644, 17287, 17301, 17424, 17535, 17613, 18250, 18755, 11771, 12054, 12219, 12811, 13134, 13994, 14355, 15106, 15188, 15235, 15257, 15377, 16141, 16183, 16321, 16458, 16968, 17288, 17302, 17425, 17542, 17614, 18291, 18835, 11878, 12055, 12220, 12812, 13192, 13995, 14356, 15117, 15190, 15236, 15258, 15381, 16144, 16184, 16340, 16459, 17154, 17289, 17303, 17426, 17546, 17621, 18299, 19944, 11879, 12123, 12222, 12814, 13193, 13996, 14387, 15119, 15191, 15238, 15259, 15598, 16145, 16185, 16341, 16460, 17161, 17290, 17304, 17431, 17552, 17622, 18593, 19964, 12043, 12128, 12223, 12816, 13374, 14000, 14406, 15136, 15208, 15239, 15261, 15600, 16146, 16186, 16342, 16461, 17170, 17291, 17305, 17432, 17556, 17624, 18626, 12044, 12129, 12227, 12818, 13375, 14003, 14410, 15137, 15209, 15241, 15262, 15603, 16148, 16187, 16343, 16462, 17183, 17292, 17306, 17433, 17573, 17626, 18627, 12045, 12135, 12230, 12820, 13376, 14004, 14411, 15153, 15211, 15242, 15282, 15605, 16151, 16188, 16347, 16463, 17199, 17293, 17307, 17434, 17589, 17627, 18635, 12046, 12137, 12231, 12821, 13594, 14005, 14415, 15158, 15212, 15245, 15284, 15606, 16175, 16189, 16450, 16544, 17200, 17294, 17308, 17435, 17590, 17633, 18702, 12047, 12138, 12232, 12822, 13595, 14007, 14431, 15159, 15213, 15246, 15288, 15614, 16176, 16190, 16451, 16573, 17201, 17295, 17309, 17436, 17591, 17634, 18703, 12048, 12187, 12233, 12885, 13596, 14008, 14451, 15161, 15214, 15250, 15289, 15653, 16177, 16191, 16452, 16582, 17221, 17296, 17310, 17437, 17592, 17656, 18704, 12049, 12188, 12234, 12886, 13598, 14026, 14675, 15166, 15218, 15251, 15305, 15756, 16178, 16227, 16453, 16599, 17222, 17297, 17311, 17438, 17595, 17677, 18705, 12050, 12195, 12254, 12887, 13981, 14041, 15023, 15167, 15227, 15252, 15306, 15758, 16179, 16238, 16454, 16600, 17224, 17298, 17416, 17474, 17596, 18231, 18709]) sdss2=np.array([1112, 1687, 2344, 3274, 3590, 3622, 3653, 4226, 4257, 4885, 5014, 5774, 5857, 6212, 6958, 6997, 7236, 7695, 7928, 8008, 8124, 8617, 9380, 9461, 9758, 1113, 1688, 2386, 3275, 3591, 3623, 3654, 4227, 4258, 4886, 5023, 5776, 5858, 6213, 6959, 6998, 7237, 7696, 7929, 8009, 8456, 8619, 9381, 9479, 9759, 1114, 1689, 2421, 3290, 3593, 3624, 3655, 4228, 4259, 4887, 5024, 5777, 5859, 6214, 6960, 6999, 7238, 7697, 7930, 8010, 8478, 8620, 9384, 9480, 9760, 1302, 1690, 2423, 3293, 3594, 3625, 3656, 4229, 4260, 4888, 5025, 5779, 5860, 6215, 6961, 7000, 7239, 7699, 7931, 8011, 8482, 8621, 9386, 9509, 9767, 1448, 1691, 2452, 3294, 3595, 3626, 3657, 4230, 4261, 4925, 5026, 5781, 5863, 6216, 6962, 7001, 7242, 7701, 7932, 8012, 8483, 8622, 9387, 9510, 9793, 1453, 1692, 2790, 3298, 3596, 3627, 3658, 4231, 4262, 4927, 5027, 5786, 5864, 6217, 6963, 7002, 7267, 7702, 7933, 8013, 8493, 8623, 9395, 9552, 9794, 1517, 1693, 2791, 3299, 3597, 3628, 3659, 4232, 4263, 4929, 5028, 5793, 5865, 6218, 6964, 7003, 7289, 7704, 7934, 8014, 8494, 8624, 9396, 9553, 9795, 1656, 1697, 2941, 3305, 3598, 3629, 3660, 4233, 4264, 4930, 5029, 5810, 5869, 6219, 6965, 7004, 7321, 7706, 7935, 8015, 8496, 8625, 9397, 9616, 9796, 1657, 1698, 3130, 3343, 3599, 3630, 3784, 4234, 4265, 4931, 5030, 5819, 5870, 6220, 6966, 7005, 7322, 7707, 7936, 8016, 8497, 8626, 9403, 9714, 9797, 1659, 1699, 3180, 3344, 3600, 3631, 3785, 4235, 4266, 4932, 5031, 5822, 5875, 6221, 6967, 7006, 7343, 7709, 7937, 8017, 8503, 8627, 9404, 9717, 9804, 1660, 1708, 3182, 3345, 3601, 3632, 3926, 4236, 4267, 4933, 5032, 5823, 5903, 6222, 6968, 7007, 7370, 7710, 7938, 8018, 8549, 8628, 9421, 9720, 9808, 1661, 1873, 3197, 3346, 3602, 3633, 3929, 4237, 4268, 4934, 5033, 5826, 5904, 6223, 6969, 7008, 7375, 7713, 7941, 8019, 8550, 8629, 9422, 9721, 9836, 1662, 2073, 3199, 3347, 3603, 3634, 3987, 4238, 4269, 4935, 5034, 5827, 5912, 6277, 6970, 7009, 7376, 7714, 7942, 8020, 8552, 8630, 9436, 9722, 9840, 1663, 2204, 3203, 3348, 3604, 3635, 3988, 4239, 4270, 4942, 5177, 5828, 5913, 6353, 6979, 7010, 7377, 7716, 7943, 8021, 8553, 8631, 9437, 9723, 9842, 1664, 2205, 3204, 3352, 3605, 3636, 4163, 4240, 4271, 4959, 5289, 5835, 5914, 6356, 6980, 7011, 7378, 7720, 7944, 8022, 8555, 8632, 9438, 9724, 9843, 1665, 2227, 3211, 3388, 3606, 3637, 4180, 4241, 4272, 4960, 5290, 5836, 6100, 6357, 6981, 7012, 7379, 7721, 7945, 8023, 8601, 8633, 9440, 9725, 9844, 1671, 2228, 3219, 3389, 3607, 3638, 4184, 4242, 4277, 4961, 5294, 5838, 6101, 6358, 6982, 7013, 7380, 7824, 7946, 8024, 8602, 8634, 9443, 9726, 9863, 1673, 2229, 3222, 3390, 3608, 3639, 4187, 4243, 4278, 4965, 5350, 5841, 6106, 6359, 6983, 7014, 7381, 7825, 7947, 8025, 8603, 8635, 9445, 9727, 9866, 1674, 2231, 3224, 3391, 3609, 3640, 4192, 4244, 4279, 4972, 5377, 5842, 6109, 6366, 6984, 7015, 7382, 7826, 7995, 8026, 8604, 8636, 9446, 9729, 9870, 1675, 2232, 3227, 3408, 3610, 3641, 4194, 4245, 4280, 4990, 5378, 5845, 6110, 6391, 6985, 7021, 7383, 7827, 7996, 8027, 8605, 8637, 9448, 9730, 9873, 1676, 2233, 3229, 3409, 3611, 3642, 4201, 4246, 4281, 4991, 5597, 5846, 6111, 6392, 6986, 7022, 7384, 7828, 7997, 8028, 8606, 8638, 9450, 9731, 9875, 1677, 2234, 3239, 3436, 3612, 3643, 4209, 4247, 4282, 4996, 5635, 5847, 6112, 6661, 6987, 7023, 7385, 7892, 7998, 8029, 8607, 8639, 9451, 9733, 9876, 1678, 2235, 3244, 3437, 3613, 3644, 4217, 4248, 4357, 5002, 5757, 5848, 6128, 6792, 6988, 7057, 7386, 7893, 7999, 8030, 8608, 8641, 9452, 9734, 9878, 1679, 2236, 3245, 3482, 3614, 3645, 4218, 4249, 4361, 5003, 5759, 5849, 6129, 6880, 6989, 7169, 7387, 7897, 8000, 8031, 8609, 8642, 9453, 9735, 9879, 1680, 2237, 3248, 3558, 3615, 3646, 4219, 4250, 4365, 5004, 5763, 5850, 6159, 6881, 6990, 7180, 7388, 7898, 8001, 8032, 8610, 8919, 9454, 9736, 9880, 1681, 2238, 3252, 3575, 3616, 3647, 4220, 4251, 4415, 5005, 5765, 5851, 6161, 6930, 6991, 7181, 7610, 7899, 8002, 8033, 8611, 9167, 9455, 9737, 9881, 1682, 2252, 3253, 3580, 3617, 3648, 4221, 4252, 4724, 5006, 5766, 5852, 6162, 6932, 6992, 7187, 7689, 7918, 8003, 8034, 8612, 9370, 9456, 9738, 9910, 1683, 2254, 3254, 3585, 3618, 3649, 4222, 4253, 4881, 5007, 5767, 5853, 6172, 6933, 6993, 7188, 7690, 7923, 8004, 8035, 8613, 9371, 9457, 9739, 1684, 2260, 3258, 3587, 3619, 3650, 4223, 4254, 4882, 5008, 5771, 5854, 6186, 6947, 6994, 7210, 7691, 7925, 8005, 8036, 8614, 9375, 9458, 9740, 1685, 2261, 3260, 3588, 3620, 3651, 4224, 4255, 4883, 5009, 5772, 5855, 6210, 6949, 6995, 7211, 7692, 7926, 8006, 8122, 8615, 9376, 9459, 9756, 1686, 2263, 3265, 3589, 3621, 3652, 4225, 4256, 4884, 5012, 5773, 5856, 6211, 6957, 6996, 7212, 7693, 7927, 8007, 8123, 8616, 9379, 9460, 9757]) def directory_address_add_exp_time_info(): ''' TTA: one time only code snippet to add cycle into to directory address file so we don't need to rerun all the wise source extraction again ''' all_obsids,ev_names=DIRECTORY_ADDRESS["obsid"].data,DIRECTORY_ADDRESS["link"].data ''' if one_obsid!=0: the_num=np.where(all_obsids==one_obsid)[0] all_obsids=all_obsids[the_num] ev_names=ev_names[the_num] rapnts,dcpnts=[],[] ''' obs_dates=[] for obsid,event_file_name in zip(all_obsids,ev_names): #print(event_file_name) hdul = fits.open(event_file_name+'/analysis/'+str(obsid)+'_clean_evt2.fits') header_info=hdul[1].header obs_date=header_info["Date-OBS"] obs_date=obs_date.split("-")[0] obs_date=int(obs_date[2:])-1 if obs_date>66 or obs_date<0: obs_date=0 obs_dates.append(obs_date) print("writing pointing file") ascii.write([DIRECTORY_ADDRESS["obsid"].data,DIRECTORY_ADDRESS["j"].data, DIRECTORY_ADDRESS["k"].data,DIRECTORY_ADDRESS["rapnt"].data, DIRECTORY_ADDRESS["decpnt"].data, DIRECTORY_ADDRESS["roll"].data,DIRECTORY_ADDRESS["texp"].data, DIRECTORY_ADDRESS["dir"].data,DIRECTORY_ADDRESS["link"].data, obs_dates], "directory_LINK_LIST_fixed_cycle.txt", names=["obsid",'j','k','rapnt','decpnt','roll', 'texp','dir','link',"cycle"],overwrite=True) return def add_cycle_info_to_old_extract_file(): ''' TTA: one time only code - this one only works on splitsamples or the entire sample if no splitsamples exist, it accesses the extract file and adds cycle info by matching with directory address text file. ''' if define_old_sess.value: splsamp_dirs=glob.glob(define_old_sess.value+'splitsample_*' + os.path.sep) else: print("Choose an old session") if splsamp_dirs: for samp_file in splsamp_dirs:#[0:1]: #find event file: evt_file=glob.glob(samp_file+"all_stacked_evt.fits") print(evt_file) if not evt_file: print("No event file.") else: hdul = fits.open(evt_file[0]) final_stack=hdul[1].data hdul=0 final_stack=Table(final_stack) obsid_list_evt=final_stack["obsid"].data #CYC_INFO dir_obsids=DIRECTORY_ADDRESS["obsid"].data comm=np.intersect1d(obsid_list_evt,dir_obsids) #find the cyc info indices: ign,inds_need,ign2=np.intersect1d(dir_obsids,comm,return_indices=True) obs_date_info=DIRECTORY_ADDRESS["cycle"].data[inds_need] flux_from_soft=np.full(len(obsid_list_evt),-99.) flux_from_hard=np.full(len(obsid_list_evt),-99.) for cyc_in,obs_num in zip(obs_date_info,comm): find_all_matches=np.where(obsid_list_evt==obs_num)[0] flux_from_soft[find_all_matches]=CYC_INFO["soft_to_flux"][cyc_in] flux_from_hard[find_all_matches]=CYC_INFO["hard_to_flux"][cyc_in] #flux_from_soft=CYC_INFO["soft_to_flux"][obs_date] #flux_from_hard=CYC_INFO["hard_to_flux"][obs_date] final_stack.add_column(flux_from_soft, name="flux_from_soft") final_stack.add_column(flux_from_hard, name="flux_from_hard") hdu = fits.BinTableHDU(data=final_stack) #hdu.header["BOXSIZE"]=boxsize hdu.writeto(samp_file+"all_stacked_evt.fits",overwrite=True) return def remove_symlinks(): main_file="/Volumes/Tonima_4TB/stackfast/all_data/" folders=["WISE_EXTRA","main_stack2","sdss1","sdss3","main_stack1","main_stack3","sdss2"] for fold in folders: find_all=glob.glob(main_file+fold+"/*") for each_obs in find_all: micro=glob.glob(each_obs+"/*") for each_fold in micro: all_files=glob.glob(each_fold+"/*") for each_file in all_files: if os.path.islink(each_file): os.system("rm "+each_file) return def links_file_maker(): num_col=np.array([]) dir_col=np.full(len(WISE_EXTRA),"WISE_EXTRA") num_col=np.concatenate((num_col,WISE_EXTRA)) dir_col=np.concatenate((dir_col,np.full(len(main_stack2),"main_stack2"))) num_col=np.concatenate((num_col,main_stack2)) dir_col=np.concatenate((dir_col,np.full(len(sdss1),"sdss1"))) num_col=np.concatenate((num_col,sdss1)) dir_col=np.concatenate((dir_col,np.full(len(sdss3),"sdss3"))) num_col=np.concatenate((num_col,sdss3)) dir_col=np.concatenate((dir_col,np.full(len(main_stack1),"main_stack1"))) num_col=np.concatenate((num_col,main_stack1)) dir_col=np.concatenate((dir_col,np.full(len(main_stack3),"main_stack3"))) num_col=np.concatenate((num_col,main_stack3)) dir_col=np.concatenate((dir_col,np.full(len(sdss2),"sdss2"))) num_col=np.concatenate((num_col,sdss2)) link_all=[] for x,y in zip(dir_col,num_col): link=CONTAINER_INFO+x+'/'+str(int(y)) link_all.append(link) ascii.write([num_col,dir_col,link_all],'DIRECTORY_ADDRESS.txt',names=["obsid","dir","link"],overwrite=True) return def final_source_photon_accounting(create_srcimages=False,run_background=True,\ softe_new=np.array([500.,2000.]),harde_new=np.array([2000., 7000.]),\ mdistmax=1e9,lim=np.array([-1,200]),\ r90_frac=1.,min_exp_frac=0.0): #needs to read in stack_idl_file and exp_file #f=fits.open(stack_file) #stack_out=f[1].data exp_outf=fits.open(exp_file) exp_out=exp_outf[1].data exp_out=Table(exp_out) exp_outf=0 #sources_file=ascii.read(sources_file_name) global boxsize boxsize=float(outp_boxsize.value) with open(prepare_file_name, 'rb') as f: stack_file,boxsize,source_id,ra,dec,x,y,old_x,old_y,\ energy,source_ra,source_dec,mdist,r90,badid,bad,dist,\ id0,idv,nphv,ph_obsid,flux_from_soft,flux_from_hard = pickle.load(f) if create_srcimages: experimental_sf_create_src_imgs(x,y,energy,source_id, idv,id0,exp_out["source_obs_ind"], exp_out["source_obs_obs"],sources_id,#file["sources_id"], sources_ra,sources_dec,boxsize) #sources_file["sources_ra"],sources_file["sources_dec"], #boxsize) #no real point to this as we are definitely going to calculate background use_bgh = len(exp_out["source_obs_bgh"].data)>0#1 use_bgs = len(exp_out["source_obs_bgs"].data)>0#1 use_exp = ~(use_bgs or use_bgh) mdistmax=float(outp_mdistmax.value) if run_background: i_srcph_bgaper,srcph_bgfrac,\ bg_in_srcaper_soft,bg_in_srcaper_hard,bg_in_srcaper_soft_flux,bg_in_srcaper_hard_flux=sf_perform_background(mdistmax,softe_new,harde_new,r90_frac) return def pointing_ra_dec_file_fixer(one_obsid=0): all_obsids,ev_names=DIRECTORY_ADDRESS["obsid"].data,DIRECTORY_ADDRESS["link"].data if one_obsid!=0: the_num=np.where(all_obsids==one_obsid)[0] all_obsids=all_obsids[the_num] ev_names=ev_names[the_num] rapnts,dcpnts=[],[] for obsid,event_file_name in zip(all_obsids,ev_names): #print(event_file_name) hdul = fits.open(event_file_name+'/analysis/'+str(obsid)+'_clean_evt2.fits') header_info=hdul[1].header event_data=hdul[1].data event_data=Table(event_data) photond_x,photond_y=event_data['x'].data,event_data['y'].data#event_data['x'].data,event_data['y'].data try: maxx_x,minx_x,maxx_y,minx_y=np.argmax(photond_x),np.argmin(photond_x),np.argmax(photond_y),np.argmin(photond_y) center_x=0.5*(photond_x[minx_x]+photond_x[maxx_x]) center_y=0.5*(photond_y[minx_x]+photond_y[maxx_x]) rapnt,dcpnt=xy2ad(header_info,np.array([center_x]),np.array([center_y])) rapnt,dcpnt=rapnt[0],dcpnt[0] except ValueError: print("event_file_name with ValueError",event_file_name) rapnt,dcpnt=header_info['RA_PNT'],header_info['DEC_PNT'] #js.append(j) #ks.append(k) if one_obsid!=0: print(one_obsid,center_x,center_y,rapnt,dcpnt) rapnts.append(rapnt) dcpnts.append(dcpnt) if one_obsid==0: print("writing pointing file") ascii.write([DIRECTORY_ADDRESS["obsid"].data,DIRECTORY_ADDRESS["j"].data,DIRECTORY_ADDRESS["k"].data,rapnts,dcpnts,DIRECTORY_ADDRESS["roll"].data,DIRECTORY_ADDRESS["texp"].data,DIRECTORY_ADDRESS["dir"].data,DIRECTORY_ADDRESS["link"].data], "directory_LINK_LIST_fixed.txt", names=["obsid",'j','k','rapnt','decpnt','roll', 'texp','dir','link'],overwrite=True) return def pointing_ra_dec_file(): all_obsids=np.unique(DIR_OBSID_LIST) datab_dir="/Volumes/Tonima_4TB/stackfast/all_data/" obsid_list,js,ks,rapnts,dcpnts,rolls,texps,list_files,link_is,direc=[],[],[],[],[],[],[],[],[],[] for element in all_obsids: print("ele",element) str_obsid=str(element) right_ind=np.where(DIR_OBSID_LIST==element)[0] print("indices",DIRECTORY_ADDRESS["obsid"].data[right_ind],DIRECTORY_ADDRESS["dir"].data[right_ind]) event_file_name=datab_dir+DIRECTORY_ADDRESS["dir"].data[right_ind][0]+'/'+str_obsid+'/analysis/'+\ str_obsid+'_clean_evt2.fits' if glob.glob(event_file_name): #print(event_file_name) hdul = fits.open(event_file_name) header_info=hdul[1].header event_data=hdul[1].data photond_x,photond_y=event_data['x'].data,event_data['y'].data maxx_x,minx_x,maxx_y,minx_y=np.argmax(photond_x),np.argmin(photond_x),np.argmax(photond_y),np.argmin(photond_y) center_x=0.5*(photond_x[minx_x]+photond_x[maxx_x]) center_y=0.5*(photond_y[minx_x]+photond_y[maxx_x]) rapnt,dcpnt=xy2ad(header_info,np.array([center_x]),np.array([center_y])) rapnt,dcpnt=rapnt[0],decpnt[0] texp,roll=header_info["EXPOSURE"],header_info['ROLL_PNT'] #texp,roll,rapnt,dcpnt=header_info["EXPOSURE"],header_info['ROLL_PNT'],\ # header_info['RA_PNT'],header_info['DEC_PNT'] #print(element,texp,roll,rapnt,dcpnt) j,k=find_secondary(str_obsid,datab_dir+DIRECTORY_ADDRESS["dir"].data[right_ind][0]+'/'+str_obsid) link=CONTAINER_INFO+DIRECTORY_ADDRESS["dir"].data[right_ind][0]+'/'+str_obsid obsid_list.append(element) js.append(j) ks.append(k) rapnts.append(rapnt) dcpnts.append(dcpnt) rolls.append(roll) texps.append(texp) direc.append(DIRECTORY_ADDRESS["dir"].data[right_ind][0]) list_files.append(str_obsid+"_list.fits") link_is.append(link) #print("info",j,k,rapnt,roll,texp,str_obsid+"_list.fits") print("writing pointing file") ascii.write([obsid_list,js,ks,rapnts,dcpnts,rolls,texps,direc,list_files,link_is], "directory_LINK_LIST.txt", names=["obsid",'j','k','rapnt','decpnt','roll', 'texp','dir','list_files','link'],overwrite=True) return def find_secondary(obsid,database_dir): ''' find the numbers on either side of n in secondary *ev1.fits.gz ''' search_name=database_dir+'/secondary/*evt1.fits.gz' #search_name=LINK_LIST[get_link]+'/secondary/*evt1.fits.gz' name_of_file=glob.glob(search_name) relevant=name_of_file[0].split('/')[-1] relevant=relevant.split('_')[1] relevant=relevant.split('N') return int(relevant[0]),int(relevant[1]) def extract_multiprocess_splitsample(splsamp): extr=extraction_stacked_file.split('/')[-1] all_evts=fits.open(splsamp+extr) all_evts=all_evts[1].data all_evts=Table(all_evts) c2 = ac.SkyCoord(all_evts["ira"].data*u.degree, all_evts["idec"].data*u.degree, frame='icrs') idx, d2d, d3d = c1.match_to_catalog_sky(c2) necessary_iids=all_evts["iid"].data[idx] source_id = all_evts['iid'].data sorted_id,id0=np.unique(source_id,return_index=True) ig,ind_start,ind2=np.intersect1d(source_id,necessary_iids,return_indices=True) ig,ind_end,ind_ig=np.intersect1d(id0,ind_start,return_indices=True) bool_inds=np.array([]) for indi_start,indi_end in zip(ind_start[:-1],ind_end[:-1]): bool_inds=np.concatenate((bool_inds,np.arange(indi_start,id0[indi_end+1]))) if ind_end[-1]+1