{"id":366,"date":"2014-02-12T15:23:56","date_gmt":"2014-02-12T15:23:56","guid":{"rendered":"http:\/\/partridges.org.uk\/?p=366"},"modified":"2014-02-12T15:23:56","modified_gmt":"2014-02-12T15:23:56","slug":"messing-around-in-stutterspace","status":"publish","type":"post","link":"https:\/\/partridge.site\/blog\/index.php\/2014\/02\/12\/messing-around-in-stutterspace\/","title":{"rendered":"Messing around in stutterspace"},"content":{"rendered":"<p>Having done the Chinese arm, my next effort has been to try and do a new map of the French arm based on Constantine&#8217;s updated near star list. \u00a0However I found I was running into problems because I was relying on a variety of websites to tell me the distances between stars, and sometimes they contradicted each other, or sometimes they just didn&#8217;t have the stars that I was interested in (but that Constantine was showing as being within 7.7 ly). \u00a0Now the simple solution would have been to have used Astrosynthesis like he does, but I have a very old Mac Mini at home, and it is a PC piece of software, so that was out. \u00a0And anyway, I didn&#8217;t want all of the features of Astrosynthesis, just something that would tell me the distance between two coordinates, which is Pythagoras. \u00a0So I decided that the simplest thing would be to knock up a quick script (not my first thought though &#8211; that was to do it in Excel, which is possible, but produces a matrix that is very sparsely populated, and very difficult to read). \u00a0Normally I would script something in php, but a friend had been extolling the virtues of Python, so I decided to use it as an opportunity to learn some basic Python as well.<\/p>\n<p>The input is designed to be a simple csv file of star coordinates, names and characteristics. \u00a0The output, in this version, is a text file and html file, listing each star in alphabetical order, with the distances to all the stars that are within 7.7 ly.<\/p>\n<p>The python script is:<\/p>\n<pre>import math\nfrom operator import itemgetter\n\ndef main(filepath):\n star_data = []\n nav_data = []\n import_position_data(filepath, star_data)\n calculate_distances(star_data, nav_data)\n write_output_file(nav_data)\n write_html_file(nav_data)\n\ndef import_position_data(filepath, star_data):\n input_f = open(filepath, 'r')\n for line in input_f:\n  line_data = line.split(',')\n  star_data.append(line_data)\n input_f.close()\n\ndef calculate_distances(star_data, nav_data):\n for star_a in star_data:\n  this_nav_data = star_a\n  for star_b in star_data:\n   if star_a[2] != star_b[2]:\n    distance = math.sqrt(\n    (float(star_a[3]) - float(star_b[3]))**2\n    +(float(star_a[4]) - float(star_b[4]))**2\n    +(float(star_a[5]) - float(star_b[5]))**2)\n    if distance &lt;= 7.7:\n     this_route_data = [star_b[2], distance, star_b[3], star_b[4], star_b[5]] \n     this_nav_data.append(this_route_data)\n     del this_route_data\n   nav_data.append(this_nav_data)\n   del this_nav_data\n\ndef write_output_file(nav_data):\n # sort into Star name order\n sorted_nav_data = sorted(nav_data, key=itemgetter(2))\n output_f = open(\"star_distances.txt\", 'w')\n for star in sorted_nav_data:\n  output_f.write('=' * 40 + '\\n')\n  output_f.write(star[2] + '\\n')\n  output_f.write('-' * 20 + '\\n')\n  output_f.write(star[9] + '\\n')\n  output_f.write('X coordinate: ' + star[3] + '\\n')\n  output_f.write('Y coordinate: ' + star[4] + '\\n')\n  output_f.write('Z coordinate: ' + star[5] + '\\n')\n  distance_from_sol = math.sqrt(\n  (float(star[3]))**2\n  +(float(star[4]))**2\n  +(float(star[5]))**2)\n  output_f.write('Distance from Sol: ' + str(distance_from_sol)[0:4] + ' ly\\n')\n  output_f.write('\\n') \n  output_f.write('Neighbours\\n')\n  for neighbour in star[12:]: \n   output_f.write(neighbour[0] + \" at \" + str(neighbour[1])[0:4] + \"ly\\n\")\n  output_f.write('\\n')\n  del distance_from_sol\n output_f.close()\n\ndef write_html_file(nav_data):\n # sort into Star name order\n sorted_nav_data = sorted(nav_data, key=itemgetter(2))\n output_f = open(\"star_distances.html\", 'w')\n output_f.write('&lt;html&gt;&lt;head&gt;&lt;\/head&gt;&lt;body&gt;\\n')\n for star in sorted_nav_data:\n  output_f.write('&lt;h2&gt;' + star[2] + '&lt;\/h2&gt;\\n')\n  output_f.write('&lt;p&gt;Type: ' + star[9] + '&lt;\/p&gt;\\n')\n  output_f.write('&lt;p&gt;X coordinate: ' + star[3] + '&lt;\/p&gt;\\n')\n  output_f.write('&lt;p&gt;Y coordinate: ' + star[4] + '&lt;\/p&gt;\\n')\n  output_f.write('&lt;p&gt;Z coordinate: ' + star[5] + '&lt;\/p&gt;\\n')\n  distance_from_sol = math.sqrt(\n  (float(star[3]))**2\n  +(float(star[4]))**2\n  +(float(star[5]))**2)\n  output_f.write('&lt;p&gt;Distance from Sol: ' + str(distance_from_sol)[0:4] + ' ly&lt;\/p&gt;\\n')\n  output_f.write('&lt;\/br&gt;\\n')\n  output_f.write('&lt;p&gt;Neighbours:&lt;\/p&gt;\\n')\n  for neighbour in star[12:]:\n   output_f.write('&lt;p&gt;' + neighbour[0] + \" at \" + str(neighbour[1])[0:4] + \"ly&lt;\/p&gt;\\n\")\n  output_f.write('&lt;\/br&gt;\\n')\n  del distance_from_sol\n output_f.write('&lt;\/body&gt;&lt;\/html&gt;\\n')\n output_f.close()\n\n<span style=\"color: #222222; font-family: 'Courier 10 Pitch', Courier, monospace; line-height: 21px;\">if __name__ == '__main__':\n<\/span> import sys\n if len(sys.argv) &gt; 1:\n  main(sys.argv[1])\n else:\n  main('Raw Star Data.csv')<\/pre>\n<p>Formatting isn&#8217;t great but you get the idea&#8230;<\/p>\n<p>The one problem with this&#8230; One of the many problems with this, is that the txt file it produces is about 600 pages long if I do it for stars with 100 ly of Sol. \u00a0Which is a wonderful academic astronomical resource, but not as useful as a practical 2300AD astrogation resource. \u00a0So we need to trim out the stars that we can&#8217;t possibly reach using a 7.7 ly stutterwarp. \u00a0First step is to remove all the stars which have no other star within 7.7 ly, because they are obviously inaccessible. \u00a0Next and more difficult step is to trim out the stars that have no route to Sol, which is more difficult and computationally intensive, but it occurs to me that if I start near Sol, and store the routes as I find them, then all I need to do is find a connection to a star that is already on a route and I know that it must connect to Sol.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Having done the Chinese arm, my next effort has been to try and do a new map of the French arm based on Constantine&#8217;s updated near star list. \u00a0However I found I was running into problems because I was relying on a variety of websites to tell me the distances between stars, and sometimes they &hellip; <a href=\"https:\/\/partridge.site\/blog\/index.php\/2014\/02\/12\/messing-around-in-stutterspace\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Messing around in stutterspace&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-366","post","type-post","status-publish","format-standard","hentry","category-rpg"],"_links":{"self":[{"href":"https:\/\/partridge.site\/blog\/index.php\/wp-json\/wp\/v2\/posts\/366","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/partridge.site\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/partridge.site\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/partridge.site\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/partridge.site\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=366"}],"version-history":[{"count":0,"href":"https:\/\/partridge.site\/blog\/index.php\/wp-json\/wp\/v2\/posts\/366\/revisions"}],"wp:attachment":[{"href":"https:\/\/partridge.site\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/partridge.site\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/partridge.site\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}