def handle(self, *args, **options): with open(args[0], 'rb') as csvfile: mreader = csv.reader(csvfile) iteritems = iter(mreader) next(iteritems) # Skip the first row for row in iteritems: id = row[0] ngc = row[1] type = row[2] constellation = Constellation.objects.get(latin_name=row[3]) ra_hours = row[4] ra_minutes = float(row[5]) dec_sign = row[6] dec_deg = row[7] dec_min = float(row[8]) magnitude = float(row[9]) size = float(row[10]) distance = float(row[11]) m_name = "M{0}".format(id) common_name = row[12] if row[12] else m_name astro_object = AstroObject( type=type, ra_hours=ra_hours, ra_minutes=ra_minutes, dec_sign=dec_sign, dec_deg=dec_deg, dec_min=dec_min, magnitude=magnitude, size=size, distance=distance, constellation=constellation, common_name=common_name, index=id, ) points = 1 if magnitude < 10: points = 10 if magnitude < 8: points = 20 if magnitude < 6: points = 30 if magnitude < 4: points = 50 if magnitude < 2: points = 100 astro_object.points = points # print "getting image" # image = urllib.urlretrieve('http://messier.seds.org/Jpg/m{0}.jpg'.format(i)) # astro_object.image.save('m{0}.jpg'.format(i), File(open(image[0])), save=False) astro_object.save() print "sucessfully saved {0}".format(astro_object.common_name) catalog_object = CatalogObject(astro_object=astro_object, catalog="M", designation="{0}".format(id)) catalog_object.save() print "sucessfully saved {0}".format(catalog_object) if int(ngc[3:]) > 0: catalog_object = CatalogObject(astro_object=astro_object, catalog="NGC", designation="{0}".format(ngc[3:])) catalog_object.save() print "sucessfully saved {0}".format(catalog_object)
def handle(self, *args, **options): with open(args[0], 'rb') as csvfile: mreader = csv.reader(csvfile) iteritems = iter(mreader) next(iteritems) # Skip the first row for row in iteritems: id = row[0] try: type = row[2] except: type = "Unknown" constellation = Constellation.objects.get(abbreviation=row[3]) try: magnitude = float(row[4]) except: magnitude = 9999 details = row[5] ra_hours = row[6] ra_minutes = float(row[7]) dec_sign = row[8] dec_deg = row[9] dec_min = float(row[10]) common_name = "NGC{0}".format(id) index = 1000 + int(id) astro_object = AstroObject( type=type, ra_hours=ra_hours, ra_minutes=ra_minutes, dec_sign=dec_sign, dec_deg=dec_deg, dec_min=dec_min, magnitude=magnitude, details=details, constellation=constellation, common_name=common_name, index=index, ) points = 1 if magnitude < 10: points = 10 if magnitude < 8: points = 20 if magnitude < 6: points = 30 if magnitude < 4: points = 50 if magnitude < 2: points = 100 astro_object.points = points try: ca = CatalogObject.objects.get(catalog="NGC", designation=id) astro_object = ca.astro_object astro_object.details = details astro_object.save() print "updated {0} with details".format(astro_object) except ObjectDoesNotExist: astro_object.save() catalog_object = CatalogObject( astro_object=astro_object, catalog="NGC", designation="{0}".format(id)) catalog_object.save() print "created {0} and added catalog object {1}".format( astro_object, catalog_object)
def handle(self, *args, **options): with open(args[0], 'rb') as csvfile: mreader = csv.reader(csvfile) iteritems = iter(mreader) next(iteritems) # Skip the first row for row in iteritems: id = row[0] ngc = row[1] type = row[2] constellation = Constellation.objects.get(latin_name=row[3]) ra_hours = row[4] ra_minutes = float(row[5]) dec_sign = row[6] dec_deg = row[7] dec_min = float(row[8]) magnitude = float(row[9]) size = float(row[10]) distance = float(row[11]) m_name = "M{0}".format(id) common_name = row[12] if row[12] else m_name astro_object = AstroObject( type=type, ra_hours=ra_hours, ra_minutes=ra_minutes, dec_sign=dec_sign, dec_deg=dec_deg, dec_min=dec_min, magnitude=magnitude, size=size, distance=distance, constellation=constellation, common_name=common_name, index=id, ) points = 1 if magnitude < 10: points = 10 if magnitude < 8: points = 20 if magnitude < 6: points = 30 if magnitude < 4: points = 50 if magnitude < 2: points = 100 astro_object.points = points # print "getting image" # image = urllib.urlretrieve('http://messier.seds.org/Jpg/m{0}.jpg'.format(i)) # astro_object.image.save('m{0}.jpg'.format(i), File(open(image[0])), save=False) astro_object.save() print "sucessfully saved {0}".format(astro_object.common_name) catalog_object = CatalogObject(astro_object=astro_object, catalog="M", designation="{0}".format(id)) catalog_object.save() print "sucessfully saved {0}".format(catalog_object) if int(ngc[3:]) > 0: catalog_object = CatalogObject(astro_object=astro_object, catalog="NGC", designation="{0}".format( ngc[3:])) catalog_object.save() print "sucessfully saved {0}".format(catalog_object)
def handle(self, *args, **options): with open(args[0], 'rb') as textfile: # skip first 9 lines for _ in xrange(9): next(textfile) for line in textfile: row = line.split('|') id = row[0] ra = row[5].split() ra_hours = int(ra[0].strip('h')) ra_minutes = int(ra[1].strip('m')) ra_seconds = float(ra[2].strip('s')) dec = row[6].split() dec_sign = dec[0][0] dec_deg = int(dec[0].strip('-').strip('+').strip('*')) dec_min = int(dec[1].strip('\'')) dec_sec = float(dec[2].strip('"').strip('\'\'')) constellation = Constellation.objects.get(abbreviation=row[7]) details = row[8] discoverer = row[9] try: discovery_date = date(int(row[10][:4]), 1, 1) except: discovery_date = None classifcation = self.classifications.get(row[13], '?') size = row[15].replace('x', 'X').split('X') try: arc_min = max(map(self.to_minutes, size)) except: arc_min = None magnitude = float(row[17] if row[17] != '...' else 9999) other_ngc = map(int, row[20].split('/') if row[20] != '...' and '?' not in row[20] else []) ic_desgs = map(int, row[21].split('/') if row[21] != '...' and '?' not in row[21] else []) astro_object = AstroObject( type=classifcation, ra_hours=ra_hours, ra_minutes=ra_minutes, ra_seconds=ra_seconds, dec_sign=dec_sign, dec_deg=dec_deg, dec_min=dec_min, dec_seconds=dec_sec, constellation=constellation, details=details, discoverer=discoverer, discovery_date=discovery_date, size=arc_min, magnitude=magnitude, common_name="NGC{0}".format(id), ) points = 1 if magnitude < 10: points = 10 if magnitude < 8: points = 20 if magnitude < 6: points = 30 if magnitude < 4: points = 50 if magnitude < 2: points = 100 astro_object.points = points try: ca = CatalogObject.objects.get(catalog="NGC", designation=id) existing_astro_object = ca.astro_object for attr, value in existing_astro_object.__dict__.iteritems(): if not value and getattr(astro_object, attr): setattr(existing_astro_object, attr, getattr(astro_object, attr)) print "updated {0} with additional data for {1}".format(existing_astro_object, attr) existing_astro_object.save() for ngcid in other_ngc: catalog_object = CatalogObject(astro_object=existing_astro_object, catalog="NGC", designation=str(ngcid)) try: catalog_object.save() print "created addtional catalog object {0}".format(catalog_object) except: pass for icid in ic_desgs: catalog_object = CatalogObject(astro_object=existing_astro_object, catalog="IC", designation=str(icid)) try: catalog_object.save() print "created addtional catalog object {0}".format(catalog_object) except: pass except ObjectDoesNotExist: astro_object.save() catalog_object = CatalogObject(astro_object=astro_object, catalog="NGC", designation="{0}".format(id)) catalog_object.save() print "created {0} and added catalog object {1}".format(astro_object, catalog_object) for ngcid in other_ngc: catalog_object = CatalogObject(astro_object=astro_object, catalog="NGC", designation=str(ngcid)) try: catalog_object.save() print "created addtional catalog object {0}".format(catalog_object) except: pass for icid in ic_desgs: catalog_object = CatalogObject(astro_object=astro_object, catalog="IC", designation=str(icid)) try: catalog_object.save() print "created addtional catalog object {0}".format(catalog_object) except: pass
def handle(self, *args, **options): astroobjects = {} with open(args[0], 'rb') as csvfile: mreader = csv.reader(csvfile) iteritems = iter(mreader) next(iteritems) # Skip the first row next(iteritems) # Skip the second row stars = 0 for row in iteritems: if float(row[13]) < 3.8: stars += 1 id = row[0] hip = row[1] hd = row[2] bayer = row[27] common_name = row[6] ra = str(ephem.hours(row[7])).split(':') dec = str(ephem.hours(row[8])).split(':') distance = float(row[9]) * 3.262 magnitude = float(row[13]) constellation = Constellation.objects.get(abbreviation=row[29]) type = "Star" ra_hours = float(ra[0]) ra_minutes = float(ra[1]) ra_seconds = float(ra[2]) dec_sign = '-' if dec[0][0] == '-' else '+' dec_deg = float(dec[0].strip('-+')) dec_min = float(dec[1]) dec_seconds = float(dec[2]) if not common_name: if bayer: common_name = '{0}{1}'.format(bayer, constellation.abbreviation) else: common_name = 'HIP{0}'.format(hip) if hip or hd: # dont save stars that have no designation in either of these catalogs astro_object = { 'type': type, 'ra_hours': ra_hours, 'ra_minutes': ra_minutes, 'ra_seconds': ra_seconds, 'dec_sign': dec_sign, 'dec_deg': dec_deg, 'dec_min': dec_min, 'dec_seconds': dec_seconds, 'magnitude': magnitude, 'distance': distance, 'constellation': constellation, 'common_name': common_name, 'points': 1, 'hip': hip, 'hd': hd, } astroobjects[id] = astro_object # Double star search with open(args[0], 'rb') as bcsvfile: breader = csv.reader(bcsvfile) doubleItems = iter(breader) next(doubleItems) next(doubleItems) for dRow in doubleItems: if dRow[30] != '1' and astroobjects.get(dRow[31], None): if dRow[30] == '3': astroobjects[dRow[31]]['type'] = "Triple Star" astroobjects[dRow[31]]['points'] = 10 else: astroobjects[dRow[31]]['type'] = "Double Star" astroobjects[dRow[31]]['points'] = 10 for key, astro_object in astroobjects.iteritems(): hip = astro_object.get('hip') hd = astro_object.get('hd') del(astro_object['hip']) del(astro_object['hd']) astro_object = AstroObject(**astro_object) astro_object.save() print "sucessfully saved {0}".format(astro_object) if hip: catalog_object = CatalogObject(astro_object=astro_object, catalog="HIP", designation=str(hip)) catalog_object.save() print "sucessfully saved {0}".format(catalog_object) if hd: catalog_object = CatalogObject(astro_object=astro_object, catalog="HD", designation=str(hd)) catalog_object.save() print "sucessfully saved {0}".format(catalog_object)
def handle(self, *args, **options): with open(args[0], "rb") as csvfile: mreader = csv.reader(csvfile) iteritems = iter(mreader) next(iteritems) # Skip the first row for row in iteritems: id = row[0] try: type = row[2] except: type = "Unknown" constellation = Constellation.objects.get(abbreviation=row[3]) try: magnitude = float(row[4]) except: magnitude = 9999 details = row[5] ra_hours = row[6] ra_minutes = float(row[7]) dec_sign = row[8] dec_deg = row[9] dec_min = float(row[10]) common_name = "NGC{0}".format(id) index = 1000 + int(id) astro_object = AstroObject( type=type, ra_hours=ra_hours, ra_minutes=ra_minutes, dec_sign=dec_sign, dec_deg=dec_deg, dec_min=dec_min, magnitude=magnitude, details=details, constellation=constellation, common_name=common_name, index=index, ) points = 1 if magnitude < 10: points = 10 if magnitude < 8: points = 20 if magnitude < 6: points = 30 if magnitude < 4: points = 50 if magnitude < 2: points = 100 astro_object.points = points try: ca = CatalogObject.objects.get(catalog="NGC", designation=id) astro_object = ca.astro_object astro_object.details = details astro_object.save() print "updated {0} with details".format(astro_object) except ObjectDoesNotExist: astro_object.save() catalog_object = CatalogObject( astro_object=astro_object, catalog="NGC", designation="{0}".format(id) ) catalog_object.save() print "created {0} and added catalog object {1}".format(astro_object, catalog_object)