def handle(self, *args, **options): self.stdout.write("==== Fetching Arecibo targets %s ====" % (datetime.now().strftime('%Y-%m-%d %H:%M'))) radar_targets = fetch_arecibo_targets() if radar_targets: for obj_id in radar_targets: self.stdout.write("Reading Arecibo target %s" % obj_id) update_MPC_orbit(obj_id, origin='A') # Wait between 10 and 20 seconds delay = random_delay(10, 20) self.stdout.write("Slept for %d seconds" % delay) else: self.stdout.write("Found no Arecibo targets to update")
def handle(self, *args, **options): if options['target']: obj_id = str(options['target']).replace('_', ' ') bodies = Body.objects.filter(name=obj_id) else: bodies = get_characterization_targets() i = f = 0 for body in bodies: self.stdout.write("{} ==== Updating {} ==== ({} of {}) ".format(datetime.now().strftime('%Y-%m-%d %H:%M'), body.current_name(), i+1, len(bodies))) # measures = SourceMeasurement.objects.filter(body=body) # for measure in measures: # print(measure.astrometric_catalog) # Get new observations from MPC obslines = self.get_mpc_obs(body.current_name()) if obslines: measures = self.update_source_measurements(obslines) # add random 10-20s delay to keep MPC happy if len(bodies) > 1: random_delay() i += 1 self.stdout.write("{} ==== Updating Complete: {} of {} Objects Updated ====".format(datetime.now().strftime('%Y-%m-%d %H:%M'), f, i))
def handle(self, *args, **options): usage = 'Incorrect usage. Usage must include: --origin ' + origin_help origin_choices = [x[0] for x in ORIGINS] if options['origin'] not in origin_choices: raise CommandError(usage) self.stdout.write("==== Fetching New Targets %s ====" % (datetime.now().strftime('%Y-%m-%d %H:%M'))) list_targets = fetch_list_targets(options['list_targets']) for obj_id in list_targets: self.stdout.write("Reading New Target %s" % obj_id) update_MPC_orbit(obj_id, origin=options['origin']) # Wait between 10 and 20 seconds delay = random_delay(10, 20) self.stdout.write("Slept for %d seconds" % delay)
def handle(self, *args, **options): username = os.environ.get('NEOX_EMAIL_USERNAME', '') password = os.environ.get('NEOX_EMAIL_PASSWORD', '') if username != '' and password != '': self.stdout.write("==== Fetching NASA targets %s ====" % (datetime.now().strftime('%Y-%m-%d %H:%M'))) mailbox = imap_login(username, password) if mailbox: NASA_targets = fetch_NASA_targets(mailbox, folder="NASA-ARM") for obj_id in NASA_targets: self.stdout.write("Reading NASA target %s" % obj_id) update_MPC_orbit(obj_id, origin='N') # Wait between 10 and 20 seconds delay = random_delay(10, 20) self.stdout.write("Slept for %d seconds" % delay) mailbox.close() mailbox.logout()
def handle(self, *args, **options): self.stdout.write("==== Fetching Yarkovsky targets %s ====" % (datetime.now().strftime('%Y-%m-%d %H:%M'))) targets = [] yark_targets = [] if options['targetlist'] is not None: if options['targetlist'] == 'FTP': targets = None elif options['targetlist'].startswith('ftp://'): targets = options['targetlist'] else: with open(expanduser(options['targetlist'])) as f: targets = f.readlines() yark_targets = fetch_yarkovsky_targets(targets) yark_targets += options['yark_targets'] for obj_id in yark_targets: self.stdout.write("Reading Yarkovsky target %s" % obj_id) update_MPC_orbit(obj_id, origin='Y') # Wait between 10 and 20 seconds delay = random_delay(10, 20) self.stdout.write("Slept for %d seconds" % delay)
def handle(self, *args, **options): if options['target']: obj_id = str(options['target']).replace('_', ' ') bodies = Body.objects.filter(name=obj_id) else: bodies = get_characterization_targets() if type(options['date']) != datetime: try: start_date = datetime.strptime(options['date'], '%Y%m%d') start_date += timedelta(seconds=12*3600) except ValueError: raise CommandError(usage) else: start_date = options['date'] i = f = 0 for body in bodies: self.stdout.write("{} ==== Updating {} ==== ({} of {}) ".format(datetime.now().strftime('%Y-%m-%d %H:%M'), body.current_name(), i+1, len(bodies))) # Get new observations from MPC measures = update_MPC_obs(body.current_name()) # If we have no new measures, or previously flagged as fast # Check if close, change 'fast_moving' flag accordingly if not measures or body.fast_moving: body_elements = model_to_dict(body) eph = compute_ephem(datetime.now(), body_elements, 500, perturb=False) speed = eph['sky_motion'] delta = eph['mag'] if speed >= 5 or delta <= 0.1: fast_flag = {'fast_moving': True} else: fast_flag = {'fast_moving': False} if body.fast_moving != fast_flag['fast_moving']: updated = save_and_make_revision(body, fast_flag) body.refresh_from_db() if updated: self.stdout.write("Set 'Fast_moving' to {} for {}.".format(body.fast_moving, body.current_name())) # If new observations, use them to refit elements with findorb. # Will update epoch to date of most recent obs. # Will only update if new epoch closer to present than previous. # Don't refit Body's with MPC_COMET element type as this seems to misbehave. if ((measures or body.fast_moving) and body.elements_type != 'MPC_COMET') or options['target']: refit_with_findorb(body.id, 500, start_date) f += 1 body.refresh_from_db() else: self.stdout.write("Not refitting with find_orb") # If new obs pull most recent orbit from MPC # Updated infrequently for most targets # Will not overwrite later elements if measures or abs(body.epochofel-datetime.now()) >= timedelta(days=200): update_MPC_orbit(body.current_name(), origin=body.origin) body.refresh_from_db() # add random 10-20s delay to keep MPC happy random_delay() i += 1 self.stdout.write("{} ==== Updating Complete: {} of {} Objects Updated ====".format(datetime.now().strftime('%Y-%m-%d %H:%M'), f, i))