Пример #1
0
def abundance_window(abundance_dict, ab_type):
    """Create window to view and adjust element abundances.

    Args:
        abundance_dict (dict): dictionary with default/current element abundances
        ab_type (str): type of abundance window, "ejecta" or "ISM"
    """

    if ab_window_open[ab_type]:
        # Give focus to existing window rather than opening a second window
        ab_window_open[ab_type].root.focus()
    else:
        window = gui.ScrollWindow()
        ab_window_open[ab_type] = window
        window.root.focus()
        window.root.geometry("%dx%d+%d+%d" %(200, 290, APP.root.winfo_x(), APP.root.winfo_y()))
        frame = window.container
        gui.SectionTitle(frame, "Element", size=10)
        if window.os == "Linux":
            title = "log(X/H)+12"
        else:
            title = "log(X/H)\u200a+\a200a12"
        gui.SectionTitle(gui.LayoutFrame(frame, column=1, row=0), title, size=10)
        for element in ELEMENT_ORDER:
            entry = gui.InputEntry(frame, element, ELEMENT_NAMES[element], "{0:.2f}".format(abundance_dict[element]),
                                   condition=lambda value: 0 < value < 100, padding=(0, 0, 5, 0))
            entry.input.bind(
                "<Key>", lambda *args: gui.InputParam.instances[str(window.root)]["ab_type"].value_var.set("Custom"))
        button_frame = gui.LayoutFrame(frame, columnspan=2, padding=(0, 10))
        if ab_type == "ISM":
            types = ("LMC", "Solar")
            default_type = ism_ab_type
            #gui.InputDropdown(gui.LayoutFrame(button_frame, row=0, column=0, padding=(2, 1, 2, 0)), "ab_type", None,
            #                  ism_ab_type, lambda: reset_ab(str(window.root)), ("LMC", "Solar"), width=7)
        else:
            types = ("CC", "Type Ia")
            default_type = ej_ab_type
            #gui.SubmitButton(gui.LayoutFrame(button_frame, row=0, column=0), "Reset",
            #                 lambda: reset_ab(str(window.root), ab_type))
        gui.InputDropdown(gui.LayoutFrame(button_frame, row=0, column=0, padding=(2, 1, 2, 0)), "ab_type", None,
                          default_type, lambda: reset_ab(str(window.root)), types, width=7)
        gui.SubmitButton(gui.LayoutFrame(button_frame, row=0, column=1), "Submit",
                         lambda: ab_window_close(window.root, abundance_dict, ab_type))
        window.root.bind("<1>", lambda event: event.widget.focus_set())
        window.root.bind("<Return>", lambda event: ab_window_close(window.root, abundance_dict, ab_type, event))
        window.root.protocol("WM_DELETE_WINDOW", lambda: ab_window_close(window.root, abundance_dict, ab_type))
        window.root.update()
        window.canvas.config(scrollregion=(0, 0, window.container.winfo_reqwidth(), window.container.winfo_reqheight()))
Пример #2
0
def emissivity_window():
    """Create window to display emissivity data for an SNR with input parameters from the main window."""

    window = gui.ScrollWindow()
    window.root.focus()
    if window.os == "Linux":
        window.root.config(cursor="watch")
    else:
        window.root.config(cursor="wait")
    window.root.geometry("%dx%d+%d+%d" %(880, 650, (ws-880)/2, (hs-700)/2))
    window.root.update()
    window.canvas.grid_remove()
    left_frame = gui.LayoutFrame(window.container, 5)
    right_frame = gui.LayoutFrame(window.container, 5, column=1, row=0)
    root_id = str(window.root)
    SNR_EM = calc.SNREmissivity(SNR, root_id)
    gui.InputParam.instances[root_id] = {}
    widgets = gui.InputParam.instances[root_id]
    gui.SectionTitle(right_frame, "Output Plots:")
    energy_frame = gui.LayoutFrame(right_frame, 0, columnspan=2)
    gui.InputEntry(energy_frame, "energy", "Energy for specific intensity plot (keV):", 1,
                   SNR_EM.update_specific_intensity, gt_zero)
    SNR_EM.plots["Inu"] = plt.OutputPlot(gui.LayoutFrame(right_frame, (0, 5)), (5, 2.6),
                                         "Normalized impact parameter",
                                         "Specific intensity/\nerg cm$^{-2}$ s$^{-1}$ Hz$^{-1}$ sr$^{-1}$")
    range_frame = gui.LayoutFrame(right_frame, (0, 5, 0, 0), columnspan=4)
    gui.InputParam(gui.LayoutFrame(range_frame), None, "Energy range (keV):", None)
    gui.InputEntry(gui.LayoutFrame(range_frame, row=0, column=1), "emin", "", 0.3, SNR_EM.update_luminosity_spectrum,
                   lambda value: 0 < value < widgets["emax"].get_value(), padding=(0, 5))
    #gui.Text(gui.LayoutFrame(range_frame, row=0, column=2), "to", padding=(4, 5, 0, 0))
    gui.InputEntry(gui.LayoutFrame(range_frame, row=0, column=3), "emax", "to", 8, SNR_EM.update_luminosity_spectrum,
                   lambda value: value > widgets["emin"].get_value(), padding=(5, 5))
    SNR_EM.plots["Lnu"] = plt.OutputPlot(gui.LayoutFrame(right_frame), (5, 2.6), "Energy/keV",
                                         "Luminosity/\nerg s$^{-1}$ Hz$^{-1}$")
    gui.SectionTitle(left_frame, "SNR Properties:")
    gui.DisplayValue(left_frame, "Age", "yr", SNR.data["t"])
    gui.DisplayValue(left_frame, "Radius", "pc", SNR.calc["r"])
    gui.InputParam(left_frame, label="Model type:  \u200a{}".format(get_model_name(SNR.data["model"], SNR_EM)),
                   padding=(5, 2))
    if SNR_EM.data["model"] == "chev":
        gui.OutputValue(left_frame, "em", "Emission measure:", "cm\u207B\u00B3", 3, padding=(5, 1, 5, 0))
        em_frame = gui.LayoutFrame(left_frame, columnspan=2)
        gui.OutputValue(gui.LayoutFrame(em_frame, column=0, row=0), "em_f", "(Forward:", "cm\u207B\u00B3,", 3,
                        padding=(5, 0, 0, 0), font="-size 9")
        gui.OutputValue(gui.LayoutFrame(em_frame, column=1, row=0), "em_r", "reverse:", "cm\u207B\u00B3)", 3,
                        padding=(5, 0, 0, 0), font="-size 9")
        gui.OutputValue(left_frame, "Tem", "Emission weighted temperature:", "K", 3, padding=(5, 1, 5, 0))
        Tem_frame = gui.LayoutFrame(left_frame, columnspan=2)
        gui.OutputValue(gui.LayoutFrame(Tem_frame, column=0, row=0), "Tem_f", "(Forward:", "K,", 3, padding=(5, 0, 0, 0),
                        font="-size 9")
        gui.OutputValue(gui.LayoutFrame(Tem_frame, column=1, row=0), "Tem_r", "reverse:", "K)", 3,
                        padding=(5, 0, 0, 0), font="-size 9")
    else:
        gui.OutputValue(left_frame, "em", "Emission measure:", "cm\u207B\u00B3", 3)
        gui.OutputValue(left_frame, "Tem", "Emission weighted temperature:", "K", 3)
    gui.SectionTitle(left_frame, "Radial Profiles:", padding=(0, 10, 0, 0))
    SNR_EM.plots["temp"] = plt.OutputPlot(gui.LayoutFrame(left_frame, (0, 5, 0, 10), columnspan=5), (4.5, 2.3),
                                          "Normalized radius", "Temperature/K")
    SNR_EM.plots["density"] = plt.OutputPlot(gui.LayoutFrame(left_frame, 0, columnspan=5), (4.5, 2.3),
                                             "Normalized radius", "Density/g cm$^{-3}$",
                                             sharex=SNR_EM.plots["temp"].graph)
    if SNR_EM.data["model"] == "chev":
        gui.OutputValue(right_frame, "lum", "Luminosity over energy range:", "erg s\u207B\u00B9", 3,
                        padding=(5, 5, 5, 0))
        lum_frame = gui.LayoutFrame(right_frame, columnspan=2)
        gui.OutputValue(gui.LayoutFrame(lum_frame, column=0, row=0), "lum_f", "(Forward:", "erg s\u207B\u00B9,", 3,
                        padding=(5, 0, 0, 0), font="-size 9")
        gui.OutputValue(gui.LayoutFrame(lum_frame, column=1, row=0), "lum_r", "reverse:", "erg s\u207B\u00B9)", 3,
                        padding=(5, 0, 0, 0), font="-size 9")
    else:
        gui.OutputValue(right_frame, "lum", "Luminosity over energy range:", "erg s\u207B\u00B9", 3, padding=(5, 5))
    SNR_EM.plots["Lnu"].properties = {"function": SNR_EM.luminosity_spectrum, "color": "g"}
    SNR_EM.plots["Inu"].properties = {"function": SNR_EM.specific_intensity, "color": "m"}
    SNR_EM.plots["temp"].properties = {"function": lambda x: SNR_EM.vector_temperature(x) * SNR_EM.data["T_s"], "color": "b"}
    SNR_EM.plots["density"].properties = {"function": lambda x: SNR_EM.vector_density(x) * 4 * SNR_EM.data["n_0"] *
                                                                SNR_EM.data["mu_H"] * calc.M_H, "color": "r"}
    #print(timeit.timeit(SNR_EM.update_output, number=1))
    #profile.runctx("SNR_EM.update_output()", None, locals())
    SNR_EM.update_output()
    window.canvas.grid()
    window.root.bind("<1>", lambda event: event.widget.focus_set())
    window.root.bind("<Return>", enter_pressed)
    window.root.update()
    window.root.config(cursor="")
    window.canvas.config(scrollregion=(0, 0, window.container.winfo_reqwidth(), window.container.winfo_reqheight()))
Пример #3
0
    window.root.update()
    window.root.config(cursor="")
    window.canvas.config(scrollregion=(0, 0, window.container.winfo_reqwidth(), window.container.winfo_reqheight()))


def gt_zero(value):
    """Checks if value is positive and non-zero."""

    return value > 0

if __name__ == '__main__':
    ab_window_open = {"ISM": False, "Ejecta": False}
    # Set initial ISM abundance type
    ism_ab_type = "LMC"
    ej_ab_type = "Type Ia"
    APP = gui.ScrollWindow("root")
    root_id = "." + APP.container.winfo_parent().split(".")[1]
    gui.InputParam.instances[root_id] = {}
    widgets = gui.InputParam.instances[root_id]
    SNR = calc.SuperNovaRemnant(root_id)
    SNR.data["abundance"] = ABUNDANCE[ism_ab_type].copy()
    SNR.data["ej_abundance"] = ABUNDANCE[ej_ab_type].copy()
    APP.root.wm_title("SNR Modelling Program")
    if APP.os == "Windows":
        ICON = "Crab_Nebula.ico"
        # Uncomment line before using pyinstaller in --onefile mode
        #ICON = sys._MEIPASS+"/Crab_Nebula.ico"
        APP.root.tk.call("wm", "iconbitmap", APP.root._w, "-default", ICON)
    ws = APP.root.winfo_screenwidth()
    hs = APP.root.winfo_screenheight()
    if APP.os == "Linux":