def LoadMPC(self, **par): """ Input: boolean conditions for sampling. Output: allocate a masked dictionary of orbital parameters from MPC catalogue. """ from os import path from boolean_module import boolist from packdesig import convert_design as conv_desig # Loading the MPC catalogue from gzip compression. if path.isfile(path.join("catalogues", "MPC_ORBITS.gz")): import gzip MPC = gzip.open(path.join("catalogues", "MPC_ORBITS.gz"), "r") else: from urllib2 import urlopen MPC = urlopen("http://www.minorplanetcenter.net/iau/MPCORB/MPCORB.DAT", timeout=30) asteroid = dict() n = 0 for ast in MPC.readlines(): n += 1 if n > 41: try: tested_conditions = boolist( par, H=float(ast[8:12]), G=float(ast[15:19]), a=float(ast[93:103]), e=float(ast[70:79]), i=float(ast[59:68]), ) if all(tested_conditions): asteroid[conv_desig(ast[:7])] = tuple(ast[8:104].split()) except ValueError: try: tested_conditions = boolist(par, a=float(ast[93:103]), e=float(ast[70:79]), i=float(ast[59:68])) if all(tested_conditions): asteroid[conv_desig(ast[:7])] = tuple([0e0, 0.15] + ast[20:104].split()) except ValueError: # print("Null entry in the line ",n," of the MPC catalogue........continue") pass print( "\n MPC catalogue has been read. The total of asteroids fullfilling the conditions are ", len(asteroid), " of ", n - 43, ) # setting in self: self.asteroid = asteroid
def Sampling(self, datestart=None, datestop=None, typetime="hour", parse=2, **limits): """ This method conducts a query through ephemeris of MPC asteroid catalogue sampling objects within a date range and phase angle interval. """ from module import vmag, phase_angle, SeqDates, float_ra from boolean_methods import boolist degrees = ephem.degrees here = self.here # dates if datestart is None and datestop is None: datestart = NOW datestop = NOW + datedelta.relativedelta(days=+1) # range of dates. dates = SeqDates(datestart, datestop, typetime, parse) # designations designation = dict.viewkeys(self.asteroid) obj_ephem = {ast: self.LoadObject(ast) for ast in designation} query = dict() # Dictionary attendant = dict() for date in dates: date = str(date) query[date] = dict() # Dictionary inside Dictionary here.date = date for ast in designation: obj = obj_ephem[ast] obj.compute(here) # Ephemeris for the date angle = phase_angle(obj.elong, obj.earth_distance, obj.sun_distance, here) mag = vmag(obj._H, obj._G, angle, obj.sun_distance, obj.earth_distance) airmass = round(1e0 / cos(pi / 4e0 - float(obj.alt)), 4) tested_conditions = boolist( limits, ph=angle, r=obj.sun_distance, mag=mag, alt=degrees(float(obj.alt)), airmass=airmass, az=degrees(float(obj.az)), ra=float_ra(obj.a_ra), dec=degrees(float(obj.a_dec)), ) if all(tested_conditions) and obj.alt >= here.horizon: query[date][ast] = { "phase angle": round(angle, 3), "vmag": round(mag, 3), "solar distance": obj.sun_distance, "ra": str(obj.a_ra), "dec": str(obj.a_dec), "alt": str(obj.alt), "airmass": airmass, "az": str(obj.az), } # Dictionary inside Dictionary inside Dictionary if attendant.has_key(ast) == False: attendant[ast] = {"dates": list()} attendant[ast]["dates"].append(date) # setting in self self.attendant = attendant self.query = query print("There are ", len(dict.viewkeys(attendant)), " asteroids satisfying this query.")