def main(): io = Io() io.eval_args() args = sys.argv fail = False ret = {'ok': True} unit = 'Pa' cmc = False if '--ids' in args: idx_ids = args.index('--ids') + 1 try: ids = args[idx_ids].split('@') except: fail = True if not fail and len(ids) > 0: for id in ids: doc = io.get_doc_db(id) customer_object = doc.get('Calibration').get('CustomerObject') if customer_object.get("Class") == "SRG": customer_device = Srg(doc, customer_object) if customer_object.get("Class") == "CDG": customer_device = Cdg(doc, customer_object) tdo = ToDo(doc) analysis = doc.get('Calibration').get('Analysis') if "Values" in analysis and "Uncertainty" in analysis["Values"]: del analysis["Values"]["Uncertainty"] ana = Analysis(doc, init_dict=analysis) se2_uncert = UncertSe2(doc) result_type = analysis.get("AnalysisType", "default") result_type = "se2_expansion_direct" res = Result(doc, result_type=result_type) p_cal = ana.pick('Pressure', 'cal', unit) p_ind_corr = ana.pick('Pressure', 'ind_corr', unit) p_off = ana.pick('Pressure', 'offset', unit) conv = res.Const.get_conv(from_unit=unit, to_unit=res.ToDo.pressure_unit) average_index = res.ToDo.make_average_index( p_cal * conv, res.ToDo.pressure_unit) print(average_index) average_index = ana.coarse_error_filtering( average_index=average_index) print(average_index) average_index, ref_mean, ref_std, loops = ana.fine_error_filtering( average_index=average_index) pressure_range_index = ana.make_pressure_range_index( ana, average_index) print(average_index) print(ref_mean) print(ref_std) print(loops) if result_type == "se2_expansion_direct" and tdo.type == "error": average_index, reject_index = ana.ask_for_reject( average_index=average_index) reject_index_offset = ana.ask_for_reject_offset( average_index=average_index) d = { "AverageIndex": average_index, "AverageIndexFlat": ana.flatten(average_index), "PressureRangeIndex": pressure_range_index, "RejectIndex": reject_index, "RejectIndexOffset": reject_index_offset } p_tdo, p_tdo_unit = tdo.Pres.get_value_and_unit("target") conv = res.Const.get_conv(from_unit=p_tdo_unit, to_unit="Pa") p_tdo = conv * p_tdo #assuming pascals, temperature correction only if more than 1 decade below 100 Pa p_tdo_evis = [ p_tdo[i] for i in range(len(p_tdo)) if p_tdo[i] < 9.5 ] if len(p_tdo_evis) > 1: e_vis, cf_vis, u_vis, vis_unit = ana.ask_for_evis() d["Evis"] = e_vis d["CFvis"] = cf_vis d["Uvis"] = u_vis d["VisUnit"] = vis_unit print(d) ana.store_dict(quant="AuxValues", d=d, dest=None, plain=True) res.store_dict(quant="AuxValues", d=d, dest=None, plain=True) if "Uncertainty" in customer_object: print("lll") u_dev = customer_device.get_total_uncert( meas_vec=p_ind_corr, meas_unit="Pa", return_unit="Pa", res=ana, skip_source="standard", prefix=False) se2_uncert.u_PTB_rel(ana) se2_uncert.make_offset_stability(ana) customer_device.repeat_uncert(ana) customer_device.device_uncert(ana) ana.total_uncert() u = ana.pick("Uncertainty", "total_rel", "1") print(customer_device.doc) print("ffffffffffffffffffffffffffffff") print(tdo.type) print(result_type) if result_type == "se2_expansion_direct" and tdo.type == "sigma": p_ind_corr = np.take(p_ind_corr, ana.flatten(average_index)) p_cal = np.take(p_cal, ana.flatten(average_index)) p_off = np.take(p_off, ana.flatten(average_index)) d = { "AverageIndex": average_index, "AverageIndexFlat": ana.flatten(average_index) } print(p_ind_corr) print(p_cal) #u = np.delete(u, skip) sigma_null, sigma_slope, sigma_std = customer_device.sigma_null( p_cal=p_cal, cal_unit=unit, p_ind=p_ind_corr, ind_unit=unit) d["SigmaNull"] = sigma_null d["SigmaCorrSlope"] = np.abs(sigma_slope / sigma_null) d["SigmaStd"] = sigma_std # aux_values_pres = Values(doc.get('Calibration').get('Measurement').get("AuxValues").get("Pressure")) # rd, rd_unit = aux_values_pres.get_value_and_unit(d_type="offset") # d["OffsetMean"] = np.nanmean(rd) # d["OffsetStd"] = np.nanstd(rd) # d["OffsetUnit"] = rd_unit ana.store_dict(quant="AuxValues", d=d, dest=None, plain=True) res.store_dict(quant="AuxValues", d=d, dest=None, plain=True) maesurement_date = cl.Counter( doc["Calibration"]["Measurement"]["Values"]["Date"] ["Value"]).most_common(1)[0][0] doc["Calibration"]["Measurement"]["Date"] = [{ "Type": "measurement", "Value": [maesurement_date] }] res.make_measurement_data_section(ana, result_type=result_type) if tdo.type == "error": # start build cert table p_ind, err, u = res.make_error_table(ana, pressure_unit=unit, error_unit='1') doc = ana.build_doc("Analysis", doc) doc = res.build_doc("Result", doc) io.save_doc(doc) else: ret = {"error": "no --ids found"}
def main(): io = Io() io.eval_args() ret = {"ok": True} result_type = "sens" i_unit = "A" for id in io.ids: doc = io.get_doc_db(id) tdo = ToDo(doc) if tdo.type not in ["sens"]: sys.exit("wrong script") if tdo.type == "sens": result_type = "sens" display = Display(doc) cus_dev = init_customer_device(doc) analysis = doc.get("Calibration").get("Analysis") ## wrong type: del analysis["Values"]["Sensitivity"] ana = Analysis(doc, init_dict=analysis, analysis_type=result_type) res = Result(doc, result_type=result_type, skip=io.skip) ## conversion to ana.pressure_unit if necessary cal_dict = ana.pick_dict("Pressure", "cal") p_ind_corr = ana.pick("Pressure", "ind_corr", i_unit) p_ind = ana.pick("Pressure", "ind", i_unit) p_ind_offset = ana.pick("Pressure", "ind_offset", i_unit) if cal_dict.get("Unit") != ana.pressure_unit: p_cal = ana.pick("Pressure", "cal", tdo.pressure_unit) conv = ana.Const.get_conv(from_unit=tdo.pressure_unit, to_unit=ana.pressure_unit) p_cal = p_cal * conv else: p_cal = ana.pick("Pressure", "cal", ana.pressure_unit) T_gas = ana.pick("Temperature", "Tuhv", "K") T_room = ana.pick("Temperature", "Troom", "K") if T_room is None: T_room = T_gas u_std = ana.pick("Uncertainty", "uncertPcal_rel", "1") ## recal Sensitivity s = p_ind_corr / (cus_dev.emis_current(i_unit) * p_cal) ana.store("Pressure", "cal", p_cal, ana.pressure_unit) ana.store("Pressure", "offset", p_ind_offset, i_unit) ana.store("Sensitivity", "gauge", s, "1/{}".format(ana.pressure_unit)) ana.store("Uncertainty", "standard", u_std, "1") ana.store("Temperature", "gas", T_gas, "K") ana.store("Temperature", "room", T_room, "K") conv = ana.Const.get_conv(from_unit=ana.pressure_unit, to_unit=tdo.pressure_unit) average_index = tdo.make_average_index(p_cal * conv, tdo.pressure_unit, max_dev=0.2) ## will be filled up with aux values: d = {} display.check_outlier_sens(ana) average_index, reject_index = ana.ask_for_reject( average_index=average_index) flat_average_index = ana.flatten(average_index) if result_type == "sens": T, Tu = ana.ask_for_bake_out_temperature() if T is not None: d["Bakeout"] = True d["BakeoutTemperature"] = float(T) d["BakeoutTemperatureUnit"] = Tu t, tu = ana.ask_for_bake_out_time() d["BakeoutTime"] = float(t) d["BakeoutTimeUnit"] = tu else: d["Bakeout"] = False p, pu, t, tu = ana.ask_for_sputter() if T is not None: d["Sputter"] = True d["SputterPressure"] = float(p) d["SputterPressureUnit"] = pu d["SputterTime"] = float(t) d["SputterTimeUnit"] = tu else: d["Sputter"] = False d["AverageIndex"] = average_index d["AverageIndexFlat"] = flat_average_index ana.store_dict(quant="AuxValues", d=d, dest=None) ## rm values p_cal = np.take(p_cal, flat_average_index) p_ind_corr = np.take(p_ind_corr, flat_average_index) s = np.take(s, flat_average_index) ## store reduced quant. for plot ana.store("Pressure", "red_ind_corr", p_ind_corr, i_unit, dest="AuxValues") ana.store("Pressure", "red_cal", p_cal, ana.pressure_unit, dest="AuxValues") ana.store("Sensitivity", "red_gauge", s, "1/{}".format(ana.pressure_unit), dest="AuxValues") ## offset contrib cus_dev.coll_uncert(ana, ind_unit=i_unit) ## default uncert. contrib. repeat cus_dev.repeat_uncert(ana, ind_unit=i_unit) cus_dev.digit_uncert(ana, ind_unit=i_unit) cus_dev.emis_uncert(ana, ind_unit=i_unit) cus_dev.device_uncert(ana) ## the uncertainty of the standard is # already calculated at analysis step ana.total_uncert() ## store red version for plot u_rep = ana.pick("Uncertainty", "repeat", "1") u_off = ana.pick("Uncertainty", "offset", "1") u_tot = ana.pick("Uncertainty", "total_rel", "1") u_dev = ana.pick("Uncertainty", "device", "1") u_std = ana.pick("Uncertainty", "standard", "1") ana.store("Uncertainty", "red_u_rep", np.take(u_rep, flat_average_index), "1", dest="AuxValues") ana.store("Uncertainty", "red_u_std", np.take(u_std, flat_average_index), "1", dest="AuxValues") ana.store("Uncertainty", "red_u_dev", np.take(u_dev, flat_average_index), "1", dest="AuxValues") ana.store("Uncertainty", "red_u_tot", np.take(u_tot, flat_average_index), "1", dest="AuxValues") ana.store("Uncertainty", "red_u_off", np.take(u_off, flat_average_index), "1", dest="AuxValues") display.plot_uncert(ana) # start making data sections res.make_measurement_data_section(ana, result_type=result_type) # start build cert table p_cal_mv, p_ind_mv, s_mv, u_mv = res.make_sens_table( ana, pressure_unit=ana.pressure_unit, sens_unit='1/Pa', uncert_unit="1", ind_unit="A") ana.store("Pressure", "ind_mean", p_ind_mv, i_unit, dest="AuxValues") ana.store("Pressure", "cal_mean", p_cal_mv, ana.pressure_unit, dest="AuxValues") ana.store("Sensitivity", "gauge_mean", s_mv, "1/{}".format(ana.pressure_unit), dest="AuxValues") ana.store("Uncertainty", "total_mean", u_mv, "1", dest="AuxValues") display.plot_mean(ana) doc = ana.build_doc("Analysis", doc) doc = res.build_doc("Result", doc) io.save_doc(doc)