def main(): inputs = ds.data_store() num_pins = 9 # number of assemblies (with single pin conc) filename = sys.argv[1] inputs.enrichments = [] try: file = open("./super_cell", 'r') except in_file_error: usage_error("input file error: (check path and that it exists!)") quit() else: filedata = file.read() for pn in range(1, num_pins + 1): enrichment = aw_round(random.uniform(0.8, 5.0)) print("pin number " + str(pn)) filedata = filedata.replace( '%pin' + str(pn) + '%', "UO2_{:02d}".format(int(enrichment * 10))) inputs.enrichments.append(enrichment) # Write the file out again try: file = open(filename, 'w') except out_file_error: usage_error("file output error") quit() else: file.write(filedata) try: f = open(filename + ".pickle", "wb+") # you should be creating state.pickle here... except: print("Error opening output file") exit() else: f.write(pickle.dumps(inputs)) f.close()
def run_filter(filter, imu_data, gps_data, filter_data, config=None): data_dict = data_store.data_store() errors = [] # Using while loop starting at k (set to kstart) and going to end # of .mat file gps_index = 0 filter_index = 0 new_gps = 0 if config and config['call_init']: filter_init = False else: filter_init = True if config and 'start_time' in config: for k, imu_pt in enumerate(imu_data): if imu_pt.time >= config['start_time']: k_start = k break else: k_start = 0 if config and 'end_time' in config: for k, imu_pt in enumerate(imu_data): if imu_pt.time >= config['end_time']: k_end = k break else: k_end = len(imu_data) #print k_start, k_end for k in range(k_start, k_end): imupt = imu_data[k] if gps_index < len(gps_data) - 1: # walk the gps counter forward as needed newData = 0 while gps_data[gps_index+1].time - gps_latency <= imupt.time: gps_index += 1 newData = 1 gpspt = gps_data[gps_index] gpspt.newData = newData else: # no more gps data, stay on the last record gpspt = gps_data[gps_index] gpspt.newData = 0 #print gpspt.time` # walk the filter counter forward as needed if len(filter_data): if imupt.time > filter_data[filter_index].time: filter_index += 1 if filter_index >= len(filter_data): # no more filter data, stay on the last record filter_index = len(filter_data)-1 filterpt = filter_data[filter_index] else: filterpt = None #print "t(imu) = " + str(imupt.time) + " t(gps) = " + str(gpspt.time) # If k is at the initialization time init_nav else get_nav if not filter_init and gps_index > 0: print "init:", imupt.time, gpspt.time navpt = filter.init(imupt, gpspt, filterpt) filter_init = True elif filter_init: navpt = filter.update(imupt, gpspt, filterpt) # Store the desired results obtained from the compiled test # navigation filter and the baseline filter if filter_init: data_dict.append(navpt) if gpspt.newData: # compute error metric with each new gps report # full 3d distance error (in ecef) p1 = navpy.lla2ecef(gpspt.lat, gpspt.lon, gpspt.alt, latlon_unit='deg') p2 = navpy.lla2ecef(navpt.lat, navpt.lon, navpt.alt, latlon_unit='rad') pe = np.linalg.norm(p1 - p2) # weight horizontal error more highly than vertical error ref = gps_data[0] n1 = navpy.lla2ned(gpspt.lat, gpspt.lon, gpspt.alt, ref.lat, ref.lon, 0.0, latlon_unit='deg') n2 = navpy.lla2ned(navpt.lat*r2d, navpt.lon*r2d, navpt.alt, ref.lat, ref.lon, 0.0, latlon_unit='deg') dn = n2 - n1 ne = math.sqrt(dn[0]*dn[0] + dn[1]*dn[1] + dn[2]*dn[2]*0.5) # it is always tempting to fit to the velocity vector # (especially when seeing some of the weird velocity fits # that the optimizer spews out), but it never helps # ... seems to make the solution convergence much more # shallow, ultimately never seems to produce a better fit # than using position directly. Weird fits happen when # the inertial errors just don't fit the gps errors. # Fitting to velocity doesn't seem to improve that # problem. v1 = np.array( [gpspt.vn, gpspt.ve, gpspt.vd] ) v2 = np.array( [navpt.vn, navpt.ve, navpt.vd] ) ve = np.linalg.norm(v1 - v2) errors.append(ne) # ned error weighted towards horizontal # Increment time up one step for the next iteration of the # while loop. k += 1 # proper cleanup filter.close() return errors, data_dict
if args.flight: plotname = os.path.basename(args.flight) elif args.aura_flight: plotname = os.path.basename(args.aura_flight) elif args.sentera_flight: plotname = os.path.basename(args.sentera_flight) elif args.sentera2_flight: plotname = os.path.basename(args.sentera2_flight) elif args.umn_flight: plotname = os.path.basename(args.umn_flight) # plots plt = plots.Plots(plotname) # plot onboard filter data_ob = data_store.data_store() for filterpt in filter_data: data_ob.append_from_filter(filterpt) plt.update(data_ob, 'On Board', c='g', alpha=0.5) # plot gps data_gps = data_store.data_store() for gpspt in gps_data: data_gps.append_from_gps(gpspt) plt.update(data_gps, 'GPS', marker='*', c='g', alpha=0.5) # find the range of gps time stamps that represent some significant # amount of velocity k_start = 0 for k, gpspt in enumerate(gps_data): gps_vel = math.sqrt(gpspt.vn*gpspt.vn + gpspt.ve*gpspt.ve)
import unittest import data_store ds = data_store.data_store() class TestCalc(unittest.TestCase): def test_Key_type(self): with self.assertRaises(Exception): ds.ClearAll() ds.CheckKey(None) with self.assertRaises(Exception): ds.ClearAll() ds.CheckKey(3) with self.assertRaises(Exception): ds.ClearAll() ds.CheckKey(1.2) with self.assertRaises(Exception): ds.ClearAll() ds.CheckKey(True) def test_Value_type(self): with self.assertRaises(Exception): ds.ClearAll() ds.CheckValue(None) with self.assertRaises(Exception): ds.ClearAll() ds.CheckValue(3) with self.assertRaises(Exception): ds.ClearAll()
def run_filter(filter, data, call_init=True, start_time=None, end_time=None): # for convenience ... imu_data = data['imu'] gps_data = data['gps'] if 'air' in data: air_data = data['air'] else: air_data = [] filter_data = data['filter'] if 'pilot' in data: pilot_data = data['pilot'] else: pilot_data = [] if 'act' in data: act_data = data['act'] else: act_data = [] data_dict = data_store.data_store() # t_store = [] # Using while loop starting at k (set to kstart) and going to end # of .mat file run_start = time.time() gps_index = 0 air_index = 0 airpt = nav.structs.Airdata() filter_index = 0 pilot_index = 0 pilotpt = None act_index = 0 actpt = None new_gps = 0 if call_init: filter_init = False else: filter_init = True k_start = 0 if start_time != None: for k, imu_pt in enumerate(imu_data): #print k_start, imu_pt.time, start_time if imu_pt.time >= start_time: k_start = k break k_end = len(imu_data) if end_time != None: for k, imu_pt in enumerate(imu_data): if imu_pt.time >= end_time: k_end = k break print k_start, k_end for k in range(k_start, k_end): imupt = imu_data[k] if gps_index < len(gps_data) - 1: # walk the gps counter forward as needed newData = 0 while gps_index < len(gps_data) - 1 and gps_data[gps_index+1].time <= imupt.time: gps_index += 1 newData = 1 gpspt = gps_data[gps_index] gpspt.newData = newData else: # no more gps data, stay on the last record gpspt = gps_data[gps_index] gpspt.newData = 0 #print gpspt.time if air_index < len(air_data) - 1: # walk the airdata counter forward as needed while air_index < len(air_data) - 1 and air_data[air_index+1].time <= imupt.time: air_index += 1 airpt = air_data[air_index] elif len(air_data): # no more air data, stay on the last record airpt = air_data[air_index] # print airpt.time # walk the filter counter forward as needed if len(filter_data): while filter_index < len(filter_data) - 1 and filter_data[filter_index].time <= imupt.time: filter_index += 1 filterpt = filter_data[filter_index] else: filterpt = filter_data[filter_index] #print "t(imu) = " + str(imupt.time) + " t(gps) = " + str(gpspt.time) if 'pilot' in data: while pilot_index < len(pilot_data) - 1 and pilot_data[pilot_index].time <= imupt.time: pilot_index += 1 pilotpt = pilot_data[pilot_index] elif 'pilot' in data: pilotpt = pilot_data[pilot_index] if 'act' in data: while act_index < len(act_data) - 1 and act_data[act_index].time <= imupt.time: act_index += 1 actpt = act_data[act_index] #print act_index, imupt.time, actpt.time, actpt.throttle, actpt.elevator elif 'act' in data: actpt = act_data[act_index] # If k is at the initialization time init_nav else get_nav if not filter_init and gps_index > 0: print "init:", imupt.time, gpspt.time navpt = filter.init(imupt, gpspt, filterpt) filter_init = True elif filter_init: navpt = filter.update(imupt, gpspt, filterpt) if filter_init: # experimental: run wind estimator # print airpt.airspeed (wn, we, ps) = wind.update_wind(imupt.time, airpt.airspeed, navpt.psi, navpt.vn, navpt.ve) #print wn, we, math.atan2(wn, we), math.atan2(wn, we)*r2d wind_deg = 90 - math.atan2(wn, we) * r2d if wind_deg < 0: wind_deg += 360.0 wind_kt = math.sqrt( we*we + wn*wn ) * mps2kt #print wn, we, ps, wind_deg, wind_kt # experimental: synthetic airspeed estimator if 'act' in data and synth_asi.rbfi == None: #print airpt.airspeed, actpt.throttle, actpt.elevator synth_asi.append(navpt.phi, actpt.throttle, actpt.elevator, imupt.q, airpt.airspeed) elif 'act' in data: asi_kt = synth_asi.est_airspeed(navpt.phi, actpt.throttle, actpt.elevator, imupt.q) data_dict.add_asi(airpt.airspeed, asi_kt) # Store the desired results obtained from the compiled test # navigation filter and the baseline filter if filter_init: data_dict.append(navpt, imupt) data_dict.add_wind(wind_deg, wind_kt, ps) # Increment time up one step for the next iteration of the # while loop. k += 1 # proper cleanup filter.close() run_end = time.time() elapsed_sec = run_end - run_start return data_dict, elapsed_sec
def run_filter(filter, data, call_init=True, start_time=None, end_time=None): # for convenience ... imu_data = data['imu'] gps_data = data['gps'] if 'air' in data: air_data = data['air'] else: air_data = [] filter_data = data['filter'] if 'pilot' in data: pilot_data = data['pilot'] else: pilot_data = [] if 'act' in data: act_data = data['act'] else: act_data = [] data_dict = data_store.data_store() # t_store = [] # Using while loop starting at k (set to kstart) and going to end # of .mat file run_start = time.time() gps_index = 0 air_index = 0 airpt = nav.structs.Airdata() filter_index = 0 pilot_index = 0 pilotpt = None act_index = 0 actpt = None new_gps = 0 synth_filt_asi = 0 if call_init: filter_init = False else: filter_init = True k_start = 0 if start_time != None: for k, imu_pt in enumerate(imu_data): #print k_start, imu_pt.time, start_time if imu_pt.time >= start_time: k_start = k break k_end = len(imu_data) if end_time != None: for k, imu_pt in enumerate(imu_data): if imu_pt.time >= end_time: k_end = k break print k_start, k_end for k in range(k_start, k_end): imupt = imu_data[k] if gps_index < len(gps_data) - 1: # walk the gps counter forward as needed newData = 0 while gps_index < len(gps_data) - 1 and gps_data[gps_index+1].time - args.gps_lag <= imupt.time: gps_index += 1 newData = 1 gpspt = gps_data[gps_index] gpspt.newData = newData else: # no more gps data, stay on the last record gpspt = gps_data[gps_index] gpspt.newData = 0 #print gpspt.time if air_index < len(air_data) - 1: # walk the airdata counter forward as needed while air_index < len(air_data) - 1 and air_data[air_index+1].time <= imupt.time: air_index += 1 airpt = air_data[air_index] elif len(air_data): # no more air data, stay on the last record airpt = air_data[air_index] # print airpt.time # walk the filter counter forward as needed if len(filter_data): while filter_index < len(filter_data) - 1 and filter_data[filter_index].time <= imupt.time: filter_index += 1 filterpt = filter_data[filter_index] else: filterpt = filter_data[filter_index] #print "t(imu) = " + str(imupt.time) + " t(gps) = " + str(gpspt.time) if 'pilot' in data: while pilot_index < len(pilot_data) - 1 and pilot_data[pilot_index].time <= imupt.time: pilot_index += 1 pilotpt = pilot_data[pilot_index] elif 'pilot' in data: pilotpt = pilot_data[pilot_index] if 'act' in data: while act_index < len(act_data) - 1 and act_data[act_index].time <= imupt.time: act_index += 1 actpt = act_data[act_index] #print act_index, imupt.time, actpt.time, actpt.throttle, actpt.elevator elif 'act' in data: actpt = act_data[act_index] # If k is at the initialization time init_nav else get_nav if not filter_init and gps_index > 0: print "init:", imupt.time, gpspt.time navpt = filter.init(imupt, gpspt, filterpt) filter_init = True elif filter_init: navpt = filter.update(imupt, gpspt, filterpt) if filter_init: # experimental: run wind estimator # print airpt.airspeed (wn, we, ps) = wind.update_wind(imupt.time, airpt.airspeed, navpt.psi, navpt.vn, navpt.ve) #print wn, we, math.atan2(wn, we), math.atan2(wn, we)*r2d wind_deg = 90 - math.atan2(wn, we) * r2d if wind_deg < 0: wind_deg += 360.0 wind_kt = math.sqrt( we*we + wn*wn ) * mps2kt #print wn, we, ps, wind_deg, wind_kt # experimental: synthetic airspeed estimator if 'act' in data and synth_asi.rbfi == None: #print airpt.airspeed, actpt.throttle, actpt.elevator synth_asi.append(navpt.phi, actpt.throttle, actpt.elevator, imupt.q, airpt.airspeed) elif 'act' in data: asi_kt = synth_asi.est_airspeed(navpt.phi, actpt.throttle, actpt.elevator, imupt.q) synth_filt_asi = 0.9 * synth_filt_asi + 0.1 * asi_kt data_dict.add_asi(airpt.airspeed, synth_filt_asi) # Store the desired results obtained from the compiled test # navigation filter and the baseline filter if filter_init: data_dict.append(navpt, imupt) data_dict.add_wind(wind_deg, wind_kt, ps) # Increment time up one step for the next iteration of the # while loop. k += 1 # proper cleanup filter.close() run_end = time.time() elapsed_sec = run_end - run_start return data_dict, elapsed_sec
def run_filter(filter, imu_data, gps_data, filter_data, config=None): data_dict = data_store.data_store() errors = [] # Using while loop starting at k (set to kstart) and going to end # of .mat file gps_index = 0 filter_index = 0 new_gps = 0 if config and config['call_init']: filter_init = False else: filter_init = True if config and 'start_time' in config: for k, imu_pt in enumerate(imu_data): if imu_pt.time >= config['start_time']: k_start = k break else: k_start = 0 if config and 'end_time' in config: for k, imu_pt in enumerate(imu_data): if imu_pt.time >= config['end_time']: k_end = k break else: k_end = len(imu_data) #print k_start, k_end for k in range(k_start, k_end): imupt = imu_data[k] if gps_index < len(gps_data) - 1: # walk the gps counter forward as needed newData = 0 while gps_data[gps_index+1].time - gps_latency <= imupt.time: gps_index += 1 newData = 1 gpspt = gps_data[gps_index] gpspt.newData = newData else: # no more gps data, stay on the last record gpspt = gps_data[gps_index] gpspt.newData = 0 #print gpspt.time` # walk the filter counter forward as needed if len(filter_data): if imupt.time > filter_data[filter_index].time: filter_index += 1 if filter_index >= len(filter_data): # no more filter data, stay on the last record filter_index = len(filter_data)-1 filterpt = filter_data[filter_index] else: filterpt = None #print "t(imu) = " + str(imupt.time) + " t(gps) = " + str(gpspt.time) # If k is at the initialization time init_nav else get_nav if not filter_init and gps_index > 0: print "init:", imupt.time, gpspt.time navpt = filter.init(imupt, gpspt, filterpt) filter_init = True elif filter_init: navpt = filter.update(imupt, gpspt, filterpt) # Store the desired results obtained from the compiled test # navigation filter and the baseline filter if filter_init: data_dict.append(navpt, imupt) if gpspt.newData: # compute error metric with each new gps report # full 3d distance error (in ecef) p1 = navpy.lla2ecef(gpspt.lat, gpspt.lon, gpspt.alt, latlon_unit='deg') p2 = navpy.lla2ecef(navpt.lat, navpt.lon, navpt.alt, latlon_unit='rad') pe = np.linalg.norm(p1 - p2) # weight horizontal error more highly than vertical error ref = gps_data[0] n1 = navpy.lla2ned(gpspt.lat, gpspt.lon, gpspt.alt, ref.lat, ref.lon, 0.0, latlon_unit='deg') n2 = navpy.lla2ned(navpt.lat*r2d, navpt.lon*r2d, navpt.alt, ref.lat, ref.lon, 0.0, latlon_unit='deg') dn = n2 - n1 ne = math.sqrt(dn[0]*dn[0] + dn[1]*dn[1] + dn[2]*dn[2]*0.5) # it is always tempting to fit to the velocity vector # (especially when seeing some of the weird velocity fits # that the optimizer spews out), but it never helps # ... seems to make the solution convergence much more # shallow, ultimately never seems to produce a better fit # than using position directly. Weird fits happen when # the inertial errors just don't fit the gps errors. # Fitting to velocity doesn't seem to improve that # problem. v1 = np.array( [gpspt.vn, gpspt.ve, gpspt.vd] ) v2 = np.array( [navpt.vn, navpt.ve, navpt.vd] ) ve = np.linalg.norm(v1 - v2) errors.append(ne) # ned error weighted towards horizontal # Increment time up one step for the next iteration of the # while loop. k += 1 # proper cleanup filter.close() return errors, data_dict
elif args.px4_sdlog2: plotname = os.path.basename(args.px4_sdlog2) elif args.sentera_flight: plotname = os.path.basename(args.sentera_flight) elif args.sentera2_flight: plotname = os.path.basename(args.sentera2_flight) elif args.umn_flight: plotname = os.path.basename(args.umn_flight) else: plotname = "plotname not set correctly" # plots plt = plots.Plots(plotname) # plot onboard filter data_ob = data_store.data_store() for filterpt in data['filter']: data_ob.append_from_filter(filterpt) plt.update(data_ob, 'On Board', c='g', alpha=0.5) # plot gps data_gps = data_store.data_store() for gpspt in data['gps']: data_gps.append_from_gps(gpspt) plt.update(data_gps, 'GPS', marker='*', c='g', alpha=0.5) # find the range of gps time stamps that represent some significant # amount of velocity k_start = 0 for k, gpspt in enumerate(data['gps']): gps_vel = math.sqrt(gpspt.vn*gpspt.vn + gpspt.ve*gpspt.ve)
from data_init import data_init from data_store import data_store from data_sort import data_sort data = {} data_init(data) # print(data) data_store(data, "关键字 参数") data_store(data, "J RT") data_store(data, "J AA") data_store(data, "B RT") full_name = input("输入全名,注意空格分隔开姓和名\n") data_store(data, full_name) label = input("输入要first_name 或者 last_name来指定查找的字段\n") name = input("输入要查找字段:%s的值?\n" % label) result = data_sort(data, label, name) print(result)
# test load of tri-grid if False: tg = tri_grid() fh = open(EU("../grids/eu_mesh_1_7_meta"), 'rb') tg.load(fh) print tg.get_meta_data() y = tg.get_triangles_at_level(3) for z in y: print z.get_data().get_label() fh.close() # test load of data-store (regridded data) file_stub = "../test_data/hadam3p_eu_2kci_1962_1_007425047_1/2kciga.pdg2dec" if False: ds = data_store() fh = open(EU(file_stub + "_l7.rgd"), 'rb') ds.load(fh) print ds.get_meta_data() print ds.get_n_idxs(), ds.get_n_t_steps() print ds[0,1], ds[29,345] fh.close() # test load of extrema-list (identified extrema) if False: ex = extrema_list() fh = open(EU(file_stub + "_l7.ex"), 'rb') ex.load(fh) print ex.get_meta_data() print ex.get_n_t_steps() print ex.get_n_extrema(0)