<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
Step6:  Snatching asteroids. A hijacking guide to the galaxy!
Ahoy, buddy! Welcome to the Earth Pirate Station.
The are plenty of loot floating around, so your task as a new crew
member is to get acquianted with locating and snatching the best
booty.
Search and watch the horizon
Survey to estimate the treasure
Choose the best one
Snatch and
Profit!
Feel free to annoy your fellow crew mates with questions and help
enhance this guide. More skilled pirates - more rum and booty!
Search
We've got a map - MPCORB from Minor Planet Center. Here is what you should know about it.
Asteroids!
They call them minor planets that roam around the sun. Pieces of rock, minerals, fuel and other valuable stuff that don't have an atmosphere and a comet trace. There are 700 000+ asteroids that are worthy to have some name, and a lot more that are too minor.
So, asteroids, where are they?
They are mostly moving around the Sun, and those what are not, are attaches to bigger planets as natural sattelites. Asteroids are moving in circles, and there is no sector or some constant address where all of them reside. Circles get distorted and turn into ellipses, paths known as asteroid orbits, and to catch an asteroid you need to work with that orbit.
How far are asteroids?
The most dista
Distance from Sun to asteroid can be found from asteroid brightness known as absolute magnitude (H). Brigthness of asteroid depends on its size, capability to reflect sunlight and distance.
Parsing MPCORB - Minor Planet Center Orbit Database
Step7:  Output format
<ASSISTANT_TASK:>
Python Code:
class MPCORB:
    class for accessing MRCORB database records
    def __init__(self, file='MRCORB.DAT'):
        self.file = file
class MPOrbit:
    parse and process MPCORB entries
       http://www.minorplanetcenter.org/iau/info/MPOrbitFormat.html
    
    def __init__(self, line):
        parse line and fill self.data dictionary with fields according
           to header line in MPCORB.DAT file. Fix MPCORB format issues:
           
            - adds header for uncertainty parameter U
        
        
        headerline = "Des'n  H  G  Epoch  M  Peri.  Node  Incl.  e  n  a  "\
                     "Reference  #Obs  #Opp  Arc  rms  Perts  Computer"
        self.headers = headerline.split()
        # fill missing Uncertainty header
        self.headers.insert(11, 'U')
        data = line.split()
        # join space separated Perts argument
        data[17:19] = [data[17]+' '+data[18]]
        for i, h in enumerate(self.headers):
            self.data = OrderedDict()
            self.data[h] = data[i]
    # dict-type access methods: mporbit['h']
    def __getitem__(self, name):
        return self.data.__getitem__(name)
    def __setitem__(self, name, value):
        return self.data.__setitem__(name, value)
        
def find_semiminor(major, e):
    Given semimajor and eccentricity, return semiminor
    return float(major)*math.sqrt(1-float(e)**2)
def find_diameter(absmag, albedo=0.15):
    Return asteroid diameter in km
    http://www.physics.sfasu.edu/astro/asteroids/sizemagnitude.html
    return (10**(-0.2*float(absmag)))*1329/math.sqrt(albedo)
def norm_radius(minr, maxr, minv, maxv, v):
    Given minimal/maximum radius, min/max value and value,
    return radius.
    
    return 
table = []
headers = []
for idx, line in enumerate(open('MPCORB.DAT', 'r')):
    if idx == 38:
        headers = line.split()
        headers.insert(11, 'U') # fill missing Uncertainty header
        #print(len(headers))
    if 40 < idx < 42+100:
        data = line.split()
        data[17:19] = [data[17]+' '+data[18]]
        entry = MPOrbit(line)
        #entry = dict()
        for i, h in enumerate(headers):
            if h == 'a':
                h = 'semimajor'
            if h == 'Des\'n':
                h = 'id'
            entry[h] = data[i]
        entry['semiminor'] = find_semiminor(entry['semimajor'], entry['e'])
        entry['size'] = find_diameter(entry['H'])
        table.append(entry)
Explanation: Snatching asteroids. A hijacking guide to the galaxy!
Ahoy, buddy! Welcome to the Earth Pirate Station.
The are plenty of loot floating around, so your task as a new crew
member is to get acquianted with locating and snatching the best
booty.
Search and watch the horizon
Survey to estimate the treasure
Choose the best one
Snatch and
Profit!
Feel free to annoy your fellow crew mates with questions and help
enhance this guide. More skilled pirates - more rum and booty!
Search
We've got a map - MPCORB from Minor Planet Center. Here is what you should know about it.
Asteroids!
They call them minor planets that roam around the sun. Pieces of rock, minerals, fuel and other valuable stuff that don't have an atmosphere and a comet trace. There are 700 000+ asteroids that are worthy to have some name, and a lot more that are too minor.
So, asteroids, where are they?
They are mostly moving around the Sun, and those what are not, are attaches to bigger planets as natural sattelites. Asteroids are moving in circles, and there is no sector or some constant address where all of them reside. Circles get distorted and turn into ellipses, paths known as asteroid orbits, and to catch an asteroid you need to work with that orbit.
How far are asteroids?
The most dista
Distance from Sun to asteroid can be found from asteroid brightness known as absolute magnitude (H). Brigthness of asteroid depends on its size, capability to reflect sunlight and distance.
Parsing MPCORB - Minor Planet Center Orbit Database
End of explanation
minv = min(e['semimajor'] for e in table)
maxv = max(e['semimajor'] for e in table)
asteroids = []
aheaders = 'id', 'size'
print('// id  size  distance platinum fuel terraforming orbit')
tojson = []
seed(3.14)
for e in table:
    a = OrderedDict()
    a['id'] = e['id']
    a['size'] = e['size']
    a['distance'] = float(e['semimajor'])
    a['period'] = 365/float(e['n'])  # n = Mean daily motion (degrees per day)
    a['---'] = ''
    a['platinum'] = random()
    a['fuel'] = random()
    a['terraforming'] = random()
    a['orbit'] = random()
    tojson.append(a)
import json
print('')
#e[radius] = norm_radius()
#print('{id} {size} {distance}'.format(**a))
print(json.dumps(tojson, indent=4))
with open('dataset.js', 'w') as fw:
    fw.write('var dataset = ')
    fw.write(json.dumps(tojson, indent=4))
Explanation: Output format:
json
var asteroids = [
  { radius: 0, color: 0 },
  { name: 'Vesta', radius: 30, color: 0xFF0000, mass: 1000, fossils: { H2O: 0.1, NH3: 0.2, CH4: 0.1, Ni: 0.01 } },
  { name: 'Pallad', radius: 20, color: 0xFFFF22 }
];
End of explanation
<END_TASK>