Remove old notebook with constellation parser

Look at that!  Back in 2015 someone contributed an example routine that
I just re-wrote without remembering it was there.  I guess I should grep
for “new” features before sitting down to re-implement them.
This commit is contained in:
Brandon Rhodes 2020-07-24 05:02:44 -04:00
parent 6e0201ecab
commit bce98b8fd6
1 changed files with 0 additions and 216 deletions

View File

@ -1,216 +0,0 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false,
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Failed to parse: 80\r\n",
"Segs don't match for: CrA 6 92989 93174 93174 93825 93825 94114 94114 94160 94160 94005 94005 93542 93542 92953\n",
"Failed to parse: \n"
]
},
{
"data": {
"text/plain": [
"[Constellation(abreviation='GSq', line_segments=['113963', '113881', '113881', '677', '677', '1067', '1067', '113963']),\n",
" Constellation(abreviation='Peg', line_segments=['113963', '113881', '113881', '1067', '1067', '113963', '113963', '112440', '112440', '112748', '112748', '112158', '112158', '109410', '114520', '113963', '113963', '114144', '113963', '112447', '112447', '112029', '112029', '109427', '112029', '107315', '112447', '109176', '109176', '107348', '112440', '109176', '109176', '107354', '107354', '105502']),\n",
" Constellation(abreviation='Cyg', line_segments=['95853', '97165', '97165', '100453', '100453', '102098', '102098', '104060', '102098', '99675', '99675', '96441', '96441', '95853', '100453', '102488', '102488', '104732', '104732', '103413', '103413', '102098', '103413', '105102', '105102', '104887', '100453', '98110', '98110', '96683', '96683', '95947']),\n",
" Constellation(abreviation='Lyr', line_segments=['91262', '91926', '91926', '92862', '92862', '94481', '94481', '94713', '94713', '93194', '93194', '92420', '92420', '89826', '89826', '91262', '93194', '92791', '92420', '91971']),\n",
" Constellation(abreviation='Sge', line_segments=['98337', '97365', '97365', '96837', '97365', '96757']),\n",
" Constellation(abreviation='Vul', line_segments=['95771', '98543']),\n",
" Constellation(abreviation='Dra', line_segments=['87585', '87833', '87833', '85670', '85670', '85829', '85829', '87585', '87585', '94376', '94376', '97433', '94376', '89908', '89937', '89908', '89908', '83895', '83895', '80331', '80331', '78527', '78527', '75458', '75458', '68756', '68756', '61281', '61281', '56211']),\n",
" Constellation(abreviation='UMi', line_segments=['11767', '85822', '85822', '82080', '82080', '77055', '77055', '79822', '79822', '75097', '75097', '72607', '72607', '77055']),\n",
" Constellation(abreviation='Cep', line_segments=['110991', '112724', '112724', '106032', '106032', '105199', '105199', '102422', '102422', '101093', '105199', '107259', '107259', '109857', '109857', '109492', '109492', '110991', '109492', '107418', '112724', '116727', '116727', '106032']),\n",
" Constellation(abreviation='Cas', line_segments=['8886', '6686', '6686', '4427', '4427', '3179', '3179', '746']),\n",
" Constellation(abreviation='Cam', line_segments=['23040', '23522', '23522', '17884', '17884', '16228', '17884', '17959', '17959', '22783', '22783', '23522', '22783', '33694', '33694', '29997']),\n",
" Constellation(abreviation='Lac', line_segments=['109937', '109754', '109754', '111104', '111104', '111944', '111944', '111022', '111022', '110351', '110351', '111104', '111022', '110609', '110609', '110538', '110538', '111169', '111169', '111022']),\n",
" Constellation(abreviation='Tri', line_segments=['10670', '10064', '10064', '8796', '8796', '10670']),\n",
" Constellation(abreviation='And', line_segments=['677', '3092', '3092', '2912', '2912', '5447', '5447', '3092', '3092', '3031', '3031', '3693', '3693', '4463', '5447', '7513', '7513', '9640', '5447', '4436', '4436', '3881', '3881', '5434', '5434', '7607', '2912', '1473', '1473', '116631', '116584', '116805', '116805', '116631', '116631', '113726']),\n",
" Constellation(abreviation='BgD', line_segments=['67301', '65378', '65378', '62956', '62956', '59774', '59774', '54061', '54061', '53910', '53910', '58001', '58001', '59774']),\n",
" Constellation(abreviation='Uma', line_segments=['67301', '65378', '65378', '62956', '62956', '59774', '59774', '54061', '54061', '53910', '53910', '58001', '58001', '59774', '54061', '46733', '46733', '41704', '41704', '44127', '44127', '44471', '44471', '50372', '50372', '46853', '46853', '48319', '48319', '46733', '50372', '50801', '50801', '55219', '55219', '55203', '55219', '54539', '54539', '57399', '57399', '67301']),\n",
" Constellation(abreviation='Boo', line_segments=['67275', '67459', '67459', '67927', '67927', '69673', '69673', '71795', '71795', '72105', '72105', '69673', '72105', '74666', '74666', '75411', '75411', '73555', '73555', '74666', '73555', '71075', '71075', '71053', '71053', '71284', '71284', '72105', '71075', '69732', '69732', '70497', '70497', '69483', '69483', '69732']),\n",
" Constellation(abreviation='Cvn', line_segments=['61317', '63125']),\n",
" Constellation(abreviation='Com', line_segments=['64241', '64394', '64394', '60742', '64394', '60697', '64394', '60746', '64394', '60351', '64394', '60514']),\n",
" Constellation(abreviation='CrB', line_segments=['76127', '75695', '75695', '76267', '76267', '76952', '76952', '77512', '77512', '78159']),\n",
" Constellation(abreviation='Her', line_segments=['84345', '84379', '84379', '85693', '85693', '86974', '86974', '88794', '88794', '88267', '88267', '88886', '88886', '90139', '90139', '92043', '92043', '92161', '88794', '87933', '87933', '84380', '84380', '85112', '85112', '87808', '87808', '86414', '86414', '81126', '81126', '79101', '79101', '79992', '79992', '86414', '86974', '83207', '83207', '81693', '81693', '81833', '81833', '84380', '84380', '83207', '83207', '80816', '80816', '80170']),\n",
" Constellation(abreviation='Aur', line_segments=['23015', '28380', '28380', '28360', '28360', '28358', '28358', '24608', '24608', '28360', '23015', '23767', '23767', '24608', '24608', '23416', '23416', '23453', '23453', '23767']),\n",
" Constellation(abreviation='Per', line_segments=['17448', '18246', '18246', '18614', '18614', '18532', '18532', '14576', '14576', '14354', '14354', '13254', '18532', '17529', '17529', '16335', '16335', '15863', '15863', '16826', '16826', '17358', '17358', '19343', '19343', '19812', '19812', '20070', '20070', '19167', '14576', '14668', '14668', '14632', '14632', '13531', '13531', '13268', '13268', '14328', '14328', '13531', '14328', '15863', '15863', '14632', '14632', '12777', '12777', '8068']),\n",
" Constellation(abreviation='Lyn', line_segments=['45860', '45688', '45688', '44248', '44248', '41075', '41075', '36145', '36145', '33449', '33449', '30060']),\n",
" Constellation(abreviation='Gem', line_segments=['31681', '34088', '34088', '35550', '35550', '35350', '35350', '32362', '35550', '36962', '36962', '37740', '36962', '37826', '36962', '36046', '36046', '34693', '34693', '36366', '36366', '36850', '34693', '33018', '34693', '32246', '32246', '30883', '32246', '30343', '30343', '29655', '29655', '28734']),\n",
" Constellation(abreviation='Can', line_segments=['43103', '42806', '42806', '40167', '40167', '40526', '40526', '42911', '42911', '42806', '42911', '44066']),\n",
" Constellation(abreviation='Leo', line_segments=['57632', '54872', '54872', '54879', '54879', '55642', '55642', '55434', '54879', '51624', '54879', '49583', '49583', '49669', '49583', '47508', '49583', '50583', '50583', '53954', '53954', '54872', '50583', '50335', '50335', '48455', '48455', '46146', '46146', '46750', '46750', '47908', '47908', '48455', '47908', '49583']),\n",
" Constellation(abreviation='LMi', line_segments=['53229', '51233', '51233', '49593', '49593', '46952', '49593', '51056', '51056', '53229']),\n",
" Constellation(abreviation='Del', line_segments=['101421', '101916', '101421', '101800', '101916', '101800', '101800', '101882', '101882', '102281', '102281', '102532', '102532', '101958', '101958', '101769', '101769', '101589', '101769', '101483', '101483', '101800']),\n",
" Constellation(abreviation='Equ', line_segments=['104987', '104858', '104858', '104521']),\n",
" Constellation(abreviation='CMi', line_segments=['37279', '36188']),\n",
" Constellation(abreviation='Ari', line_segments=['14838', '13914', '13914', '10306', '10306', '8832', '13914', '13209', '13209', '13061', '13061', '12719', '12719', '13209', '12719', '9884', '9884', '9153', '9153', '8903', '8903', '9884', '9884', '10306']),\n",
" Constellation(abreviation='Tau', line_segments=['25428', '21881', '21881', '20711', '20711', '17702', '21881', '26451', '26451', '21421', '21421', '20894', '20894', '20205', '20205', '20455', '20455', '20648', '20648', '20889', '20889', '20711', '20205', '21589', '21589', '21402', '20205', '19860', '20205', '18724', '18724', '16083', '16083', '16369', '16083', '15900', '15900', '16852', '15900', '18907']),\n",
" Constellation(abreviation='Vir', line_segments=['57380', '57757', '57757', '60129', '60129', '61941', '61941', '58948', '58948', '57380', '61941', '64238', '64238', '65474', '65474', '69427', '69427', '69701', '69701', '71957', '65474', '66249', '66249', '68520', '68520', '72220', '66249', '63090', '63090', '63608', '63090', '61941', '69701', '68520']),\n",
" Constellation(abreviation='Lib', line_segments=['73714', '72622', '72622', '74785', '74785', '76333', '76333', '72622', '76333', '76470', '76470', '76600']),\n",
" Constellation(abreviation='Sco', line_segments=['87261', '85927', '85927', '85696', '85696', '86170', '86170', '86670', '86670', '87073', '87073', '86228', '86228', '84143', '84143', '82671', '82671', '82514', '82514', '82396', '82396', '81266', '81266', '80763', '80763', '80112', '80112', '79404', '79404', '78104', '78104', '78265', '80112', '79374', '79374', '78820', '78820', '78401']),\n",
" Constellation(abreviation='Ser', line_segments=['92946', '88771', '88771', '88601', '88601', '89962', '89962', '88048', '88048', '86565', '86565', '86263', '86263', '84880', '80628', '79882', '79882', '79593', '79593', '77516', '77516', '77622', '77622', '77070', '77070', '77257', '77257', '76276', '76276', '77233', '77233', '78072', '78072', '77450', '77450', '76852', '76852', '77233']),\n",
" Constellation(abreviation='Oph', line_segments=['85423', '84405', '84405', '84970', '84970', '85340', '85340', '84893', '84893', '84012', '84012', '85365', '85365', '86742', '86742', '87108', '87108', '88601', '86742', '86032', '86032', '83000', '83000', '86742', '83000', '82673', '82673', '80883', '80883', '79593', '83000', '81377', '81377', '80894', '80894', '80569', '80569', '80343', '80343', '80975', '81377', '84012']),\n",
" Constellation(abreviation='Sct', line_segments=['92175', '91726', '91726', '90595', '90595', '91117', '91117', '92175']),\n",
" Constellation(abreviation='Crv', line_segments=['61174', '60965', '60965', '59803', '59803', '59316', '59316', '59199', '59316', '60189', '60189', '61359', '60189', '60965']),\n",
" Constellation(abreviation='Lup', line_segments=['78918', '77634', '77634', '76705', '76705', '75177', '75177', '78384', '75177', '75304', '75304', '75501', '75501', '76297', '76297', '76552', '76552', '76829', '75501', '75141', '75141', '74117', '74117', '74911', '74911', '75264', '74117', '73807', '73807', '74376', '74376', '74395', '73807', '71536', '71536', '71121', '71536', '71860', '71860', '69996', '71860', '70576', '71860', '72683', '72683', '73273', '73273', '75177']),\n",
" Constellation(abreviation='Nor', line_segments=['80000', '80582', '80582', '79653', '79653', '78639', '78639', '80000']),\n",
" Constellation(abreviation='Cru', line_segments=['61084', '60718', '62434', '59747']),\n",
" Constellation(abreviation='Cen', line_segments=['72010', '71865', '71865', '73334', '73334', '71352', '71352', '68245', '68245', '68862', '68862', '70300', '70300', '70090', '70090', '68933', '68933', '67464', '67464', '68245', '67153', '67457', '67153', '67669', '67153', '67786', '67153', '65109', '65109', '65936', '65936', '67464', '67464', '67472', '67472', '68002', '68002', '68523', '68523', '68282', '68282', '68245', '68002', '66657', '66657', '71683', '66657', '68702', '66657', '61932', '61932', '68002', '61932', '60823', '60823', '59449', '59449', '56561', '60823', '59196', '59196', '55425']),\n",
" Constellation(abreviation='Cir', line_segments=['71908', '75323', '71908', '74824']),\n",
" Constellation(abreviation='Tra', line_segments=['82273', '74946', '74946', '76440', '76440', '77952', '77952', '82273']),\n",
" Constellation(abreviation='Oct', line_segments=['107089', '112405', '112405', '70638', '70638', '107089']),\n",
" Constellation(abreviation='Pav', line_segments=['100751', '105858', '105858', '102395', '102395', '99240', '99240', '100751', '99240', '98495', '98495', '91792', '91792', '93015', '93015', '99240', '93015', '92609', '92609', '90098', '90098', '88866', '88866', '92609', '88866', '86929']),\n",
" Constellation(abreviation='Ara', line_segments=['88714', '85792', '85792', '83153', '83153', '83081', '83081', '82363', '82363', '85727', '85727', '88714']),\n",
" Constellation(abreviation='Aps', line_segments=['80047', '81065', '81065', '81852', '81852', '80047', '80047', '72370']),\n",
" Constellation(abreviation='Tel', line_segments=['90568', '90422']),\n",
" Constellation(abreviation='Mus', line_segments=['62322', '61585', '61585', '63613', '63613', '61199', '61199', '61585', '61585', '59929', '59929', '57363']),\n",
" Constellation(abreviation='Cha', line_segments=['40702', '51839', '51839', '52595', '52595', '60000', '60000', '58484', '58484', '51839']),\n",
" Constellation(abreviation='Hys', line_segments=['2021', '17678', '17678', '12394', '12394', '11001', '11001', '8928', '8928', '9236']),\n",
" Constellation(abreviation='Tuc', line_segments=['110130', '114996', '114996', '118322', '118322', '1599', '1599', '2484', '2484', '114996']),\n",
" Constellation(abreviation='Ind', line_segments=['101772', '102333', '102333', '103227', '103227', '108870', '108870', '108431', '108431', '103227']),\n",
" Constellation(abreviation='Gru', line_segments=['114131', '110997', '110997', '109268', '109268', '112122', '112122', '114421', '114421', '114131', '112122', '113638', '112122', '112623', '109268', '109111', '109111', '108085']),\n",
" Constellation(abreviation='CrA', line_segments=['92989', '93174', '93174', '93825', '93825', '94114', '94114', '94160', '94160', '94005', '94005', '93542', '93542', '92953']),\n",
" Constellation(abreviation='Sag', line_segments=['88635', '89931', '89931', '90185', '90185', '89642', '89642', '88635', '88635', '89341', '89341', '90496', '90496', '89931', '89931', '92041', '92041', '92855', '92855', '94141', '94141', '95168', '95168', '95176', '94141', '93085', '93085', '92855', '92855', '93864', '93864', '93506', '93506', '92041', '93864', '98412', '98412', '98032', '95241', '95347', '95347', '98412', '95347', '93506']),\n",
" Constellation(abreviation='Aql', line_segments=['98036', '97649', '97649', '97278', '97278', '96229', '96229', '95501', '95501', '97804', '99473', '97804', '95501', '93747', '93747', '93244', '95501', '93805', '93805', '93429']),\n",
" Constellation(abreviation='PsA', line_segments=['113368', '111954', '111954', '109285', '109285', '108661', '108661', '107608', '107608', '109285', '109285', '111188', '111188', '112948', '112948', '113246', '113246', '113368']),\n",
" Constellation(abreviation='Cap', line_segments=['100064', '100345', '100345', '104139', '104139', '105515', '105515', '106985', '106985', '107556', '105515', '106039', '106039', '105881', '105881', '104139', '104139', '104019', '104019', '104234', '104019', '101027', '100345', '101027', '101027', '102485', '102485', '102978']),\n",
" Constellation(abreviation='Aqu', line_segments=['102618', '103045', '103045', '104459', '104459', '106278', '106278', '109139', '106278', '109074', '109074', '110395', '110395', '111497', '111497', '110672', '110672', '109074', '109074', '110003', '110003', '112961', '112961', '114855', '114855', '114724', '114724', '112961', '112961', '112716', '112716', '113136', '113136', '114855', '114855', '114341', '114341', '114375', '114375', '114119', '114855', '115438', '115438', '115669', '115669', '116247']),\n",
" Constellation(abreviation='Pis', line_segments=['5586', '5742', '5586', '6193', '6193', '5742', '5742', '6706', '6706', '7097', '7097', '8198', '8198', '9487', '9487', '7884', '7884', '7007', '7007', '5737', '5737', '4906', '4906', '3786', '3786', '118268', '118268', '116771', '116771', '116928', '116928', '115738', '115738', '114971', '114971', '115227', '115227', '115830', '115830', '116771']),\n",
" Constellation(abreviation='Cet', line_segments=['12706', '11484', '11484', '12828', '12828', '13954', '13954', '14135', '14135', '12706', '12706', '12387', '12387', '10826', '10826', '8645', '8645', '6537', '6537', '1562', '1562', '3419', '3419', '8102', '3419', '9347', '9347', '12387']),\n",
" Constellation(abreviation='Ori', line_segments=['26727', '26311', '26311', '25930', '28691', '29426', '29426', '29038', '29038', '27913', '27913', '28691', '29239', '28614', '28614', '27989', '27989', '26727', '26727', '27366', '24436', '25281', '25281', '25930', '25930', '25336', '25336', '25813', '25813', '26207', '25813', '27989', '25336', '22449', '22449', '22549', '22549', '22797', '22797', '23123', '22449', '22509', '22509', '22845', '22845', '22833']),\n",
" Constellation(abreviation='Lep', line_segments=['28910', '28103', '28103', '27288', '27288', '25985', '25985', '24305', '28910', '27654', '27654', '27072', '27072', '25606', '25606', '23685', '25985', '25606', '24305', '24845', '24305', '24327', '23685', '24305', '24327', '24244', '24845', '24873']),\n",
" Constellation(abreviation='CMa', line_segments=['33160', '34045', '34045', '33347', '33347', '32349', '32349', '33977', '33977', '34444', '34444', '35037', '35037', '35904', '33579', '33856', '33856', '34444', '33579', '33152', '33152', '31592', '31592', '31125', '31592', '30324', '31592', '32349', '33579', '32759', '30122', '33579', '33347', '33160']),\n",
" Constellation(abreviation='Mon', line_segments=['41307', '39863', '29651', '30867', '30867', '34769', '34769', '32578', '32578', '30419', '34769', '39863', '39863', '37447', '32578', '31216', '30419', '31216', '31216', '31978']),\n",
" Constellation(abreviation='Hya', line_segments=['42799', '42402', '42402', '42313', '42313', '43109', '43109', '43813', '43813', '42799', '43813', '45336', '45336', '47431', '47431', '46390', '46390', '49841', '49841', '51069', '51069', '52943', '52943', '53740', '53740', '54682', '54682', '56343', '56343', '57936', '57936', '64166', '64166', '64962']),\n",
" Constellation(abreviation='Crt', line_segments=['53740', '54682', '54682', '55705', '55705', '55282', '55282', '53740', '55282', '55687', '55687', '56633', '56633', '58188', '58188', '57283', '57283', '55705']),\n",
" Constellation(abreviation='Vel', line_segments=['39953', '42913', '42913', '45941', '45941', '48774', '48774', '52727', '52727', '51986', '51986', '50191', '50191', '46651', '46651', '44816', '44816', '39953']),\n",
" Constellation(abreviation='Pyx', line_segments=['39429', '42515', '42515', '42828', '42828', '43409']),\n",
" Constellation(abreviation='Car', line_segments=['39429', '39953', '39953', '38827', '38827', '41037', '41037', '45556', '45556', '50371', '50371', '51232', '51232', '51849', '51849', '53253', '53253', '54463', '53253', '52468', '52468', '51576', '51576', '52419', '52419', '50099', '50099', '45238', '45238', '30438', '30438', '31685']),\n",
" Constellation(abreviation='Pup', line_segments=['31685', '35264', '35264', '36917', '36917', '37229', '37229', '37173', '37173', '38170', '38170', '38070', '38070', '37677', '37677', '36917', '38170', '39757', '39757', '39429']),\n",
" Constellation(abreviation='Vol', line_segments=['37504', '34481', '34481', '39794', '39794', '37504', '39794', '35228', '39794', '41312', '41312', '44382', '44382', '39794', '40817', '39794']),\n",
" Constellation(abreviation='Pic', line_segments=['32607', '27530', '27530', '27321', '32607', '27321']),\n",
" Constellation(abreviation='Dor', line_segments=['27100', '27890', '27890', '26069', '26069', '27100', '26069', '21281', '21281', '19893', '26069', '23693', '23693', '21281']),\n",
" Constellation(abreviation='Ret', line_segments=['19780', '19921', '19921', '18597', '18597', '17440', '17440', '19780']),\n",
" Constellation(abreviation='Pho', line_segments=['5348', '5165', '5165', '3245', '3245', '2072', '3245', '5348', '5165', '7083', '7083', '8837', '8837', '5165', '5165', '6867', '6867', '3245', '2072', '2081', '2081', '765', '765', '2072']),\n",
" Constellation(abreviation='Col', line_segments=['28328', '28199', '28199', '30277', '30277', '29807', '29807', '28199', '28199', '27628', '27628', '28328', '27628', '26634', '26634', '25859']),\n",
" Constellation(abreviation='Eri', line_segments=['7588', '9007', '9007', '10602', '10602', '11407', '11407', '12486', '12486', '13847', '13847', '15510', '15510', '17874', '17874', '20042', '20042', '20535', '20535', '21393', '21393', '21248', '21248', '18673', '18673', '18216', '18216', '17717', '17717', '17651', '17651', '16611', '16611', '15474', '15474', '14146', '14146', '13701', '13701', '16537', '16537', '17378', '17378', '18543', '18543', '19849', '19849', '19587', '19587', '21444', '21444', '22109', '22109', '23875', '23875', '21594'])]"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from collections import namedtuple\n",
"import re\n",
"\n",
"\n",
"class ParseError(Exception):\n",
" pass\n",
" \n",
"\n",
"def load_constellation_data():\n",
" \"\"\" \n",
" Loads data from constellationship.fab, a list of hipparcos catalog constellations.\n",
" \n",
" This data is taken from the wackymorningdj.users.sourceforge.net/ha_rey_stellarium.zip\n",
" \n",
" Warning:\n",
" The license for this data is not yet known.\n",
" \"\"\"\n",
" with open('../data/constellationship.fab', 'r') as file:\n",
" return file.read()\n",
"\n",
" \n",
"def get_constellation_data():\n",
" \"\"\" \n",
" Returns a list of Constellation namedtuples. \n",
" \n",
" Each Constellation namedtuple has an `abbreviation` attrib and a `line_segments` \n",
" attrib, which is an iterable of ints. \n",
" \n",
" The constellation data is formatted as:\n",
" <Three letter abreviation> <number of segments> <star coordinate> where each field is \n",
" white space seperated and star coordinates are ints. Constellation lines appear to be\n",
" defined by start and end coordinates, eg:\n",
" \n",
" Sge 3 98337 97365 97365 96837 97365 96757\n",
" \"\"\"\n",
" \n",
" constellation_data = load_constellation_data().split('\\n')\n",
" cleaned_data = []\n",
" for constellation_string in constellation_data:\n",
" cleaned_string = constellation_string.strip('\\r')\n",
" try:\n",
" constellation_tuple = parse_constellation_string(cleaned_string)\n",
" cleaned_data.append(constellation_tuple)\n",
" except ParseError:\n",
" print 'Failed to parse: {const_string}'.format(const_string=constellation_string)\n",
" return cleaned_data\n",
" \n",
"def parse_constellation_string(constellation_string):\n",
" \"\"\" \n",
" Returns a namedtuple of the constellation's abbrevation and line segments. \n",
" \n",
" Raises:\n",
" ParseError\n",
" \"\"\"\n",
" constellation = namedtuple('Constellation', ['abreviation', 'line_segments'])\n",
" \n",
" pattern = re.compile('(?P<abbrev>[A-Za-z]+) (?P<segs>[\\d]+)')\n",
" match = pattern.search(constellation_string)\n",
" try:\n",
" abbreviation, number_of_segments = match.group('abbrev'), match.group('segs')\n",
" line_segments = constellation_string.split(' ')[2:] \n",
" if int(number_of_segments) != len(line_segments)/2:\n",
" print(\"Segs don't match for: {}\".format(constellation_string))\n",
" \n",
" return constellation(abbreviation, line_segments) \n",
" except AttributeError:\n",
" raise ParseError(\"Failed to parse: {const_string}\".format(const_string=constellation_string))\n",
" \n",
"get_constellation_data()\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.9"
}
},
"nbformat": 4,
"nbformat_minor": 0
}