Beispiel #1
0
def scan_archive(sim_dir):
    progress_window = progress_class()
    progress_window.show()
    progress_window.start()
    archive_path = os.path.join(sim_dir, "build_archive.zip")
    if os.path.isfile(archive_path) == True:
        os.remove(archive_path)
    zf = zipfile.ZipFile(archive_path, 'a', zipfile.ZIP_DEFLATED)

    l = os.listdir(sim_dir)
    for i in range(0, len(l)):
        dir_to_zip = os.path.join(sim_dir, l[i])
        if os.path.isdir(dir_to_zip) == True:
            archive_add_dir(archive_path,
                            dir_to_zip,
                            sim_dir,
                            zf=zf,
                            remove_src_dir=True,
                            exclude=["gmon.out"])

        progress_window.set_fraction(float(i) / float(len(l)))
        progress_window.set_text(_("Adding: ") + l[i])

        #if server_break()==True:
        #	break
        process_events()

    zf.close()

    os.rename(archive_path, os.path.join(sim_dir, scan_next_archive(sim_dir)))

    progress_window.stop()
Beispiel #2
0
def export_materials(target):
	if target.endswith(".zip")==False:
		target=target+".zip"

	file_list=[]

	progress_window=progress_class()
	progress_window.show()
	progress_window.start()
	process_events()
	mat_files=["alpha_eq.inp","alpha_gen.omat","alpha.omat","cost.xlsx","dos.inp","fit.inp","mat.inp","n_eq.inp","n_gen.omat","n.omat","pl.inp"]
	for path, dirs, files in os.walk(os.path.join(os.getcwd(),"materials")):
		for file_name in files:
			if file_name in mat_files:
				file_list.append(os.path.join(path,file_name))

	zf = zipfile.ZipFile(target, 'a')

	for i in range(0,len(file_list)):
		cur_file=file_list[i]

		lines=[]
		if os.path.isfile(cur_file):
			f=open(cur_file, mode='rb')
			lines = f.read()
			f.close()


			zf.writestr(remove_cwdfrompath(cur_file), lines)
			progress_window.set_fraction(float(i)/float(len(file_list)))
			progress_window.set_text("Adding"+cur_file[len(os.getcwd()):])
			process_events()

	zf.close()
	progress_window.stop()
Beispiel #3
0
    def load_tabs(self):

        progress_window = progress_class()
        progress_window.show()
        progress_window.start()

        process_events()

        file_list = zip_lsdir(os.path.join(get_sim_path(), "sim.gpvdm"))
        files = []
        for i in range(0, len(file_list)):
            if file_list[i].startswith("pulse") and file_list[i].endswith(
                    ".inp"):
                name = inp_get_token_value(file_list[i], "#sim_menu_name")
                files.append([name, file_list[i]])

        files.sort()

        for i in range(0, len(files)):
            value = strextract_interger(files[i][1])
            if value != -1:
                self.add_page(value)

            progress_window.set_fraction(float(i) / float(len(files)))
            progress_window.set_text(_("Loading") + " " + files[i][0])
            process_events()

        progress_window.stop()
Beispiel #4
0
def clone_materials(dest,src_dir,file_type):
	if running_on_linux()==False:
		progress_window=progress_class()
		progress_window.show()
		progress_window.start()

		process_events()

		if os.path.isdir(dest)==False:
			os.makedirs(dest)

		files=find_materials(mat_path=src_dir,file_type=file_type)
		for i in range(0,len(files)):

			src_file=os.path.join(src_dir,files[i])
			dest_file=os.path.join(dest,files[i])
			
			clone_material(dest_file,src_file)

			progress_window.set_fraction(float(i)/float(len(files)))
			progress_window.set_text("Configuring "+files[i])
			process_events()

		progress_window.stop()
	else:
		os.symlink(src_dir, dest)
Beispiel #5
0
def export_archive(target,everything):
	if target.endswith(".gpvdm")==False:
		target=target+".gpvdm"

	file_list=[]

	progress_window=progress_class()
	progress_window.show()
	progress_window.start()
	process_events()

	if everything==True:
		for path, dirs, files in os.walk(get_sim_path()):
			for file_name in files:
				if file_name.endswith(".inp") or file_name.endswith(".dat") or file_name.endswith(".omat"):
					file_list.append(os.path.join(path,file_name))
	else:
		files=os.listdir(get_sim_path())
		for file_name in files:
			if file_name.endswith(".inp"):
				file_list.append(os.path.join(get_sim_path(),file_name))

	zf = zipfile.ZipFile(target, 'a')

	for i in range(0,len(file_list)):
		cur_file=file_list[i]

		lines=[]
		if os.path.isfile(cur_file):
			try:
				f=open(cur_file, mode='rb')
				lines = f.read()
				f.close()


				zf.writestr(remove_simpathfrompath(cur_file), lines)
			except:
				print(_("Can't open file ")+cur_file)

			progress_window.set_fraction(float(i)/float(len(file_list)))
			progress_window.set_text("Adding"+cur_file[len(get_sim_path()):])
			process_events()

	src_zf = zipfile.ZipFile(os.path.join(get_sim_path(),"sim.gpvdm"), 'r')

	for file_name in src_zf.namelist():
		if file_name not in zf.namelist():
			#print "adding from archive",file_name
			lines=src_zf.read(file_name)
			zf.writestr(file_name, lines)

	zf.close()
	src_zf.close()
	progress_window.stop()
def tree_gen_random_files(sim_path,flat_simulation_list,program_list,base_dir):
	length=0

	for program_line in program_list:
		if program_line.opp=="random_file_name":
			length=int(program_line.values)

	progress_window=progress_class()
	progress_window.show()
	progress_window.start()

	process_events()

	print("length",length)

	for i in range(0,length):
		rand=codecs.encode(os.urandom(int(16 / 2)), 'hex').decode()
		cur_dir=os.path.join(sim_path,rand)

		if not os.path.exists(cur_dir):
			os.makedirs(cur_dir)
			gpvdm_clone(cur_dir,src_archive=os.path.join(base_dir, "sim.gpvdm"),dest="file")

			os.chdir(cur_dir)
			archive_decompress(os.path.join(cur_dir,"sim.gpvdm"))

			t=scan_tree_leaf()
			t.program_list=program_list
			t.directory=cur_dir
			
			if t.apply_constants()==False:
				return False

			if t.apply_python_scripts()==False:
				return False


			t.duplicate_params()
			#tree_apply_duplicate(cur_dir,program_list)
			
			archive_compress(os.path.join(cur_dir,"sim.gpvdm"))

			flat_simulation_list.append(cur_dir)

			progress_window.set_fraction(float(i)/float(length))
			progress_window.set_text("Adding "+cur_dir)
			process_events()

	progress_window.stop()
Beispiel #7
0
    def update_progress(self, line, percent):
        if self.isVisible() == True:
            if line != -1:
                self.tab.setItem(
                    line, 5,
                    QTableWidgetItem(
                        str(self.update.file_list[line].get_status())))
                self.tab.setItem(
                    line, 4,
                    QTableWidgetItem(str(
                        self.update.file_list[line].md5_disk)))
                self.tab.selectRow(line)

        #self.progress.set_fraction(percent)
        #self.progress.set_text(self.update.get_progress_text())
        process_events()
Beispiel #8
0
    def send_files(self, target, src, files):
        progress_window = progress_class()
        progress_window.show()
        progress_window.start()

        process_events()

        count = 0
        banned = []

        for i in range(0, len(files)):
            data = tx_struct()

            progress_window.set_fraction(float(i) / float(len(files)))
            progress_window.set_text("Sending " + files[i])
            process_events()

            full_path = os.path.normpath(os.path.join(src, files[i]))

            data.stat = os.stat(full_path)[ST_MODE]

            f = open(full_path, 'rb')
            bytes = f.read()
            f.close()
            orig_size = len(bytes)

            print("tx file:", full_path)

            if target == "":
                data.target = src
            else:
                data.target = target

            data.id = "gpvdmfile"
            data.uzipsize = len(bytes)
            data.data = bytes
            data.zip = True
            data.file_name = strip_slash(files[i])
            count = count + 1
            self.tx_packet(data)
            #if count>2:
            #	break
            print("status>>>>>>>>", i, len(files))

        progress_window.stop()

        print("total=", count)
Beispiel #9
0
def scan_delete_files(dirs_to_del, parent_window=None):
    if parent_window != None:
        progress_window = progress_class()
        progress_window.show()
        progress_window.start()

        process_events()

    for i in range(0, len(dirs_to_del)):
        gpvdm_delete_file(dirs_to_del[i])
        if parent_window != None:
            progress_window.set_fraction(float(i) / float(len(dirs_to_del)))
            progress_window.set_text("Deleting" + dirs_to_del[i])
            process_events()

    if parent_window != None:
        progress_window.stop()
Beispiel #10
0
def scan_build_nested_simulation(root_simulation, nest_simulation):

    if os.path.isdir(nest_simulation) == False:
        print("Path ", nest_simulation, "does not exist")
        sys.exit(0)

    progress_window = progress_class()
    progress_window.show()
    progress_window.start()

    process_events()

    nest_simulation_name = os.path.basename(nest_simulation)
    program_list = tree_load_program(nest_simulation)

    files = os.listdir(root_simulation)
    simulations = []
    for i in range(0, len(files)):
        if os.path.isfile(os.path.join(root_simulation, files[i],
                                       "sim.gpvdm")) == True:
            simulations.append(files[i])

    flat_simulation_list = []

    path = os.getcwd()
    for i in range(0, len(simulations)):
        dest_name = os.path.join(root_simulation, simulations[i],
                                 nest_simulation_name)
        base_dir = os.path.join(root_simulation, simulations[i])
        #print(">>>",dest_name,base_dir,"<<",nest_simulation_name)
        tree_gen(dest_name, flat_simulation_list, program_list, base_dir)

        progress_window.set_fraction(float(i) / float(len(simulations)))
        progress_window.set_text(simulations[i])
        process_events()

    progress_window.stop()

    os.chdir(path)

    flat_simulation_list = tree_gen_flat_list(root_simulation, level=1)

    #print(flat_simulation_list)
    tree_save_flat_list(root_simulation, flat_simulation_list)

    return
Beispiel #11
0
def tree_gen_random_files(sim_path, flat_simulation_list, program_list,
                          base_dir):
    length = 0

    for i in range(0, len(program_list)):
        if program_list[i][3] == "random_file_name":
            length = int(program_list[i][2])

    progress_window = progress_class()
    progress_window.show()
    progress_window.start()

    process_events()

    for i in range(0, length):
        rand = codecs.encode(os.urandom(int(16 / 2)), 'hex').decode()
        cur_dir = os.path.join(sim_path, rand)

        if not os.path.exists(cur_dir):
            os.makedirs(cur_dir)
            gpvdm_clone(cur_dir,
                        src_archive=os.path.join(base_dir, "sim.gpvdm"),
                        dest="file")

            os.chdir(cur_dir)
            archive_decompress(os.path.join(cur_dir, "sim.gpvdm"))
            if tree_apply_constant(cur_dir, program_list) == False:
                return False

            if tree_apply_python_script(cur_dir, program_list) == False:
                return False

            tree_apply_mirror(cur_dir, program_list)

            archive_compress(os.path.join(cur_dir, "sim.gpvdm"))

            flat_simulation_list.append(cur_dir)

            progress_window.set_fraction(float(i) / float(length))
            progress_window.set_text("Adding " + cur_dir)
            process_events()

    progress_window.stop()
Beispiel #12
0
def scan_build_nested_simulation(root_simulation, nest_simulation):

    progress_window = progress_class()
    progress_window.show()
    progress_window.start()

    process_events()

    program_list = tree_load_program(nest_simulation)

    files = os.listdir(root_simulation)
    simulations = []
    for i in range(0, len(files)):
        if os.path.isfile(os.path.join(root_simulation, files[i],
                                       "sim.gpvdm")) == True:
            simulations.append(files[i])

    flat_simulation_list = []

    path = os.getcwd()
    for i in range(0, len(simulations)):
        dest_name = os.path.join(root_simulation, simulations[i])
        tree_gen(flat_simulation_list, program_list, dest_name, dest_name)

        progress_window.set_fraction(float(i) / float(len(simulations)))
        progress_window.set_text(simulations[i])
        process_events()

    progress_window.stop()

    os.chdir(path)

    flat_simulation_list = tree_gen_flat_list(root_simulation, level=1)

    print(flat_simulation_list)
    tree_save_flat_list(root_simulation, flat_simulation_list)

    return
Beispiel #13
0
    def load_tabs(self):
        progress_window = progress_class()
        progress_window.show()
        progress_window.start()

        process_events()

        file_list = zip_lsdir(os.path.join(get_sim_path(), "sim.gpvdm"))
        files = []
        for i in range(0, len(file_list)):
            if is_numbered_file(file_list[i], "is"):
                name = inp_get_token_value(file_list[i], "#sim_menu_name")
                files.append([name, file_list[i]])

        files.sort()

        for i in range(0, len(files)):
            self.add_page(files[i][1])

            progress_window.set_fraction(float(i) / float(len(files)))
            progress_window.set_text(_("Loading") + " " + files[i][0])
            process_events()

        progress_window.stop()
Beispiel #14
0
def scan_ml_build_vector(sim_dir):
	output_file=os.path.join(sim_dir,"vectors.dat")
	if os.path.isfile(output_file)==True:
		response=yes_no_cancel_dlg(None,"The file "+output_file+" already exists.  Continue? ")

		if response!="yes":
			sys.exit(0)

	out=open(output_file,'wb')
	progress_window=progress_class()
	progress_window.show()
	progress_window.start()

	tot_archives=0
	for archive_name in os.listdir(sim_dir):
		if archive_name.startswith("archive")==True and archive_name.endswith(".zip")==True:
			tot_archives=tot_archives+1

	done=0

	errors=0
	for archive_name in os.listdir(sim_dir):

		if archive_name.startswith("archive")==True and archive_name.endswith(".zip")==True:

			archive_path=os.path.join(sim_dir,archive_name)

			if done==0:		#Find the measurment files and determine which ones are needed
				found=[]
				zf = zipfile.ZipFile(archive_path, 'r')
				items=zf.namelist()
				for l in items:
					parts=l.split("/")
					fname=parts[-1]
					if fname.endswith("scan.inp")==True:
						found_item=os.path.join(parts[-2],parts[-1])

						a=parts[-2]
						#measurment()
						#a.experiment=parts[-2]
						#a.measurement_file=parts[-1]
						#a.token="#ml_input_"+parts[-1][8:-4]+"_"+parts[-2]

						if found.count(a)==False:
							found.append(a)

			zf = zipfile.ZipFile(archive_path, 'r')
			dirs=zip_lsdir(archive_path,zf=zf,sub_dir="/")

			items=len(dirs)
			for i in range(0,len(dirs)):
				rnd = [random.choice(string.ascii_letters + string.digits) for n in range(0,32)]
				rnd = "".join(rnd)

				tmp_dir="/dev/shm/gpvdm_"+rnd
				if os.path.isdir(tmp_dir)==True:
					shutil.rmtree(tmp_dir)

				os.mkdir(tmp_dir)

				extract_dir_from_archive(tmp_dir,"",dirs[i],zf=zf)
	
				full_name=tmp_dir
				written=False
				#print(dirs[i])

				error=False
				v="#ml_id\n"
				v=v+dirs[i]+"\n"

				
				for scan_folder in found:
					token="#ml_input_"+scan_folder
					v=v+token+"\n"

					dolog=False
					div=1.0
					mul=1.0
					do_fabs=False

					sim_mode=inp_get_token_value(os.path.join(full_name,scan_folder,"sim.inp"), "#simmode")
					if sim_mode==None:
						error=True
						break
					sim_mode=sim_mode.lower()

					light=float(inp_get_token_value(os.path.join(full_name,scan_folder,"light.inp"), "#Psun"))

					if sim_mode.endswith("jv") or sim_mode.startswith("jv"):
						file_name="jv.dat"
						sim_mode="jv"
						vector=[0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0]	#np.linspace(0.2,1.0,20)#

						if light>0.0:
							div=1e2

						if light==0.0:
							dolog=True

					elif sim_mode=="sun_voc":
						file_name="suns_voc.dat"
						vector=[0.02,0.04,0.05,0.1,0.5,0.7,1.0]
						dolog=True
						mul=-10.0

					elif sim_mode.startswith("tpc")==True:
						file_name="pulse_i.dat"
						vector=[1.1e-6,2e-6,2e-5,1e-4,0.02,0.1]
						dolog=True
						do_fabs=True
					elif sim_mode.startswith("celiv")==True:
						file_name="pulse_i.dat"
						vector=[2e-6,3e-6,4e-6,5e-6,6e-6,7e-6,8e-6]
						do_fabs=True
						mul=1000.0
					elif sim_mode.startswith("tpv")==True:
						file_name="pulse_v.dat"
						vector=[10e-6,20e-6,30e-6,40e-6,50e-6,60e-6,80e-6]
						do_fabs=True
						mul=10.0
					else:
						print(sim_mode)
						asdas
					ret=get_vectors(os.path.join(full_name,scan_folder,file_name),vector,dolog=dolog,div=div,mul=mul,fabs=do_fabs)
					#print(ret)
					if ret==False:
						error=True
						break
					v=v+ret+"\n"

					if sim_mode=="jv" and light>0.0:
						ret=scan_ml_build_token_abs(os.path.join(full_name,scan_folder,"sim_info.dat"),"#jv_pmax_tau","#jv_pmax_tau",min_max="avg",dolog=True)
						if ret==False:
							error=True
							break
						v=v+ret

						ret=scan_ml_build_token_abs(os.path.join(full_name,scan_folder,"sim_info.dat"),"#jv_pmax_mue","#jv_pmax_mue",min_max="avg",dolog=True)
						if ret==False:
							error=True
							break

						v=v+ret

						ret=scan_ml_build_token_abs(os.path.join(full_name,scan_folder,"sim_info.dat"),"#pce","#pce",min_max="avg",lim=0.1)
						if ret==False:
							error=True
							break

						v=v+ret

					#print(a.experiment,a.measurement_file,a.token)


				for min_max in ["min","max","avg"]:
					a=scan_ml_build_token_abs(os.path.join(full_name,"dos0.inp"),"#Etrape","#Etraph",min_max=min_max,mul=1e3)
					if a==False:
						error=True
						break
					v=v+a

					a=scan_ml_build_token_abs(os.path.join(full_name,"dos0.inp"),"#mueffe","#mueffh",min_max=min_max,dolog=True)
					if a==False:
						error=True
						break
					v=v+a

					a=scan_ml_build_token_abs(os.path.join(full_name,"dos0.inp"),"#Ntraph","#Ntrape",min_max=min_max,dolog=True)
					if a==False:
						error=True
						break
					v=v+a

				a=scan_ml_build_token_abs(os.path.join(full_name,"parasitic.inp"),"#Rshunt","#Rshunt",min_max="avg",dolog=True)
				if a==False:
					error=True
					break
				v=v+a

				a=scan_ml_build_token_abs(os.path.join(full_name,"parasitic.inp"),"#Rcontact","#Rcontact",min_max="avg")
				if a==False:
					error=True
					break
				v=v+a
		
				v=v+"#break\n"

				if error==False:
					out.write(str.encode(v))
					written=True
				else:
					errors=errors+1

				done=done+1


				progress_window.set_fraction(float(done)/float(len(dirs)*tot_archives))
				if written==True:
					progress_window.set_text(dirs[i])
				else:
					progress_window.set_text("                         /Last error: "+dirs[i]+" tot errors="+str(errors)+" "+str(round(100.0*errors/done,1))+"%")

				progress_window.set_text(dirs[i])

				#if server_break()==True:
				#	break
				process_events()
				#return

				shutil.rmtree(tmp_dir)

	out.close()
	progress_window.stop()

	tindex_dump(os.path.join(sim_dir,"index.dat"))
Beispiel #15
0
    def __init__(self):
        super(gpvdm_main_window, self).__init__()
        icon_init_db()
        #from scans_io import scans_io
        #from cal_path import get_sim_path
        #scans=scans_io(get_sim_path())
        #sims=scans.get_scan_dirs()
        #print(sims)
        #asdsa
        self.splash = splash_window()
        self.scan_human_labels = get_scan_human_labels()

        self.splash.inc_value()
        process_events()
        process_events()

        #from wiz import wiz
        #a=wiz()
        #a.exec_()

        #sys.exit()
        do_import()

        if os.path.isdir(os.path.dirname(sys.argv[0])) == False:
            error_dlg(self, _("I can't run from inside a zip file!"))
            sys.exit()

        self.splash.inc_value()
        self.splash.inc_value()

        server_init()
        self.splash.inc_value()

        self.check_sim_exists = check_sim_exists()
        self.splash.inc_value()

        self.check_sim_exists.start_thread()
        self.splash.inc_value()

        self.check_sim_exists.sim_gone.connect(self.sim_gone)
        self.splash.inc_value()

        self.my_server = server_get()
        self.my_server.init(get_sim_path())
        self.splash.inc_value()

        self.undo_list = undo_list_class()
        wpos_load()
        self.splash.inc_value()

        self.ribbon = ribbon()
        self.splash.inc_value()

        self.notebook_active_page = None
        self.setAcceptDrops(True)
        #self.setGeometry(200, 100, 1300, 600)
        self.setWindowTitle(
            "General-purpose Photovoltaic Device Model (https://www.gpvdm.com)"
        )

        self.l = lock_gui()

        #self.l.disable_all.connect(self.disable_interface)
        #self.l.enable_all.connect(self.enable_disable_buttons)

        #super(gpvdm_main_window, self).__init__(parent, QtCore.Qt.FramelessWindowHint)
        #gobject.GObject.__init__(self)

        #self.my_server.setup_gui(self.gui_sim_start)
        self.my_server.sim_started.connect(self.gui_sim_start)
        self.splash.inc_value()

        self.my_server.sim_finished.connect(self.gui_sim_stop)
        self.splash.inc_value()

        help_init()
        self.splash.inc_value()

        #help_window().help_set_help(["star.png",_("<big><b>Update available!</b></big><br>")])

        #self.show()

        if running_on_linux() == True:
            self.bus = dbus.SessionBus()
            self.bus.add_match_string_non_blocking(
                "type='signal',interface='org.my.gpvdm'")
            self.bus.add_message_filter(self.adbus)
        else:
            self.win_pipe = win_pipe()
            self.win_pipe.new_data.connect(self.win_dbus)
            self.win_pipe.start()

        self.notebook = gpvdm_notebook()
        vbox = QVBoxLayout()
        self.splash.inc_value()

        vbox.addWidget(self.ribbon)
        self.ribbon.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
        self.notebook.setSizePolicy(QSizePolicy.Expanding,
                                    QSizePolicy.Expanding)
        vbox.addWidget(self.notebook)
        wvbox = QWidget()
        self.splash.inc_value()

        wvbox.setLayout(vbox)
        self.setCentralWidget(wvbox)

        self.splash.inc_value()

        self.statusBar()

        temp_error = ver_error()
        #print(temp_error)
        if len(temp_error) > 0:
            error_dlg(self, temp_error)
            return

        self.setWindowIcon(
            QIcon(os.path.join(get_image_file_path(), "image.jpg")))
        self.splash.inc_value()

        self.show_tabs = True
        self.show_border = True

        self.ribbon.file.home_new.clicked.connect(self.callback_new)
        self.ribbon.file.home_open.clicked.connect(self.callback_open)
        self.ribbon.file.used_files_click.connect(self.load_sim)
        self.ribbon.home.undo.triggered.connect(self.callback_undo)
        self.ribbon.home.run.start_sim.connect(self.callback_simulate)
        self.splash.inc_value()

        #self.ribbon.home.stop.setEnabled(False)

        self.ribbon.home.scan.setEnabled(False)
        self.ribbon.thermal.setEnabled(False)

        self.ribbon.home.help.triggered.connect(self.callback_on_line_help)

        update_init()

        resize_window_to_be_sane(self, 0.7, 0.75)

        self.change_dir_and_refresh_interface(get_sim_path())
        self.splash.inc_value()

        #self.ribbon.home.sun.changed.connect(self.notebook.update)
        self.ribbon.setAutoFillBackground(True)
        self.splash.inc_value()
        self.show()

        help_window().show()

        self.enable_disable_buttons()

        val = inp_get_token_value(os.path.join(get_sim_path(), "config.inp"),
                                  "#use_gpvdm_local")
        if val != "false":
            if os.path.isdir(get_materials_path()) == False:
                clone_materials(get_materials_path(), get_base_material_path(),
                                "material")

            if os.path.isdir(get_emission_path()) == False:
                clone_materials(get_emission_path(), get_base_emission_path(),
                                "emission")

            if os.path.isdir(get_shape_path()) == False:
                clone_materials(get_shape_path(), get_base_shape_path(),
                                "shape")

            if os.path.isdir(get_scripts_path()) == False:
                shutil.copytree(get_base_scripts_path(),
                                get_scripts_path(),
                                symlinks=True)

            if os.path.isdir(get_spectra_path()) == False:
                clone_spectras(get_spectra_path())

        self.cache = cache(only_open_if_full=True)

        #from shape_editor import shape_editor
        #self.shape_window=shape_editor("/home/rod/gpvdm_local/shape/pedot")
        #self.shape_window.show()

        #from shape_import import shape_import
        #self.shape_import=shape_import("/home/rod/gpvdm_local/shape/pedot")
        #self.shape_import.show()
        check_lib_in_bash_rc()
Beispiel #16
0
    def build_vector(self):
        output_file = os.path.join(self.scan_dir, "vectors.dat")
        if os.path.isfile(output_file) == True:
            response = yes_no_cancel_dlg(
                None,
                "The file " + output_file + " already exists.  Continue? ")

            if response != "yes":
                sys.exit(0)

        out = open(output_file, 'wb')

        progress_window = progress_class()
        progress_window.show()
        progress_window.start()

        tot_archives = 0
        for archive_name in os.listdir(self.scan_dir):
            if archive_name.startswith(
                    "archive") == True and archive_name.endswith(
                        ".zip") == True:
                tot_archives = tot_archives + 1

        done = 0

        errors = 0
        for archive_name in os.listdir(self.scan_dir):

            if archive_name.startswith(
                    "archive") == True and archive_name.endswith(
                        ".zip") == True:

                archive_path = os.path.join(self.scan_dir, archive_name)

                if done == 0:  #on the first archive search it for sub sims and build a list
                    sub_sims = self.get_sub_sims(archive_path)

                zf = zipfile.ZipFile(archive_path, 'r')
                simulations = zip_lsdir(archive_path, zf=zf, sub_dir="/")

                for simulation in simulations:

                    tmp_dir = self.make_tmp_dir()

                    extract_dir_from_archive(tmp_dir, "", simulation, zf=zf)

                    written = False
                    #print(simulation)

                    error = False
                    v = []
                    v.append("#ml_id")
                    v.append(simulation)

                    sub_sim_folder = None
                    for scan_folder in sub_sims:
                        sub_sim_folder = os.path.join(tmp_dir, scan_folder)
                        #print(sub_sim_folder,tmp_dir)
                        dolog = False
                        div = 1.0
                        mul = 1.0
                        do_fabs = False

                        sim_mode = inp_get_token_value(
                            os.path.join(sub_sim_folder, "sim.inp"),
                            "#simmode")
                        if sim_mode == None:
                            error = True
                            break

                        sim_mode = sim_mode.lower()

                        light = float(
                            inp_get_token_value(
                                os.path.join(tmp_dir, scan_folder,
                                             "light.inp"), "#Psun"))
                        scan_folder_token = scan_folder.replace("/", "_")

                        if sim_mode.endswith("jv") or sim_mode.startswith(
                                "jv"):
                            file_name = ["jv.dat"]
                            sim_mode = "jv"
                            vector = [self.jv_sample_points]
                            token_ext = [scan_folder_token]
                            #if light>0.0:
                            #	div=1e2

                            #if light==0.0:
                            #	dolog=True
                        elif sim_mode.startswith("eqe") or sim_mode.endswith(
                                "qe"):
                            file_name = ["qe.dat"]
                            sim_mode = "eqe"
                            vector = [self.eqe_sample_points]
                            token_ext = [scan_folder_token]

                        elif sim_mode == "sun_voc":
                            file_name = ["suns_voc.dat"]
                            vector = [[0.02, 0.04, 0.05, 0.1, 0.5, 0.7, 1.0]]
                            token_ext = [scan_folder_token]
                            #dolog=True
                            #mul=-10.0

                        elif sim_mode.startswith("cv"):
                            file_name = ["cv.dat"]
                            vector = [[
                                -2.0, -1.8, -1.6, -1.4, -1.2, -1.0, -0.8, -0.6,
                                -0.4, -0.2, 0.0, 0.2, 0.4
                            ]]
                            token_ext = [scan_folder_token]

                        elif sim_mode.startswith("is"):
                            file_name = ["fx_imag.dat"]
                            vector = [self.fx_points]
                            token_ext = [scan_folder_token + "_fx_imag"]

                            file_name.append("fx_real.dat")
                            vector.append(self.fx_points)
                            token_ext.append(scan_folder_token + "_fx_real")

                        elif sim_mode.startswith("imps"):
                            file_name = ["fx_imag.dat"]
                            vector = [None]
                            token_ext = [scan_folder_token + "_fx_imag"]

                            file_name.append("fx_real.dat")
                            vector.append(None)
                            token_ext.append(scan_folder_token + "_fx_real")

                            file_name.append("fx_phi.dat")
                            vector.append(None)
                            token_ext.append(scan_folder_token + "_fx_phi")

                        elif sim_mode.startswith("imvs"):
                            file_name = ["fx_imag.dat"]
                            vector = [self.fx_points]
                            token_ext = [scan_folder_token + "_fx_imag"]

                            file_name.append("fx_real.dat")
                            vector.append(self.fx_points)
                            token_ext.append(scan_folder_token + "_fx_real")

                        elif sim_mode.startswith("tpc") == True:
                            file_name = ["time_i.dat"]
                            vector = [[1.1e-6, 2e-6, 2e-5, 1e-4, 0.02, 0.1]]
                            token_ext = [scan_folder_token]
                            #dolog=True
                            #do_fabs=True

                        elif sim_mode.startswith("celiv") == True:
                            file_name = ["time_i.dat"]
                            vector = [[
                                2e-6, 3e-6, 4e-6, 5e-6, 6e-6, 7e-6, 8e-6
                            ]]
                            token_ext = [scan_folder_token]
                            #do_fabs=True
                            #mul=1000.0

                        elif sim_mode.startswith("tpv") == True:
                            file_name = ["time_v.dat"]
                            vector = [[
                                10e-6, 20e-6, 30e-6, 40e-6, 50e-6, 60e-6, 80e-6
                            ]]
                            token_ext = [scan_folder_token]
                            #do_fabs=True
                            #mul=10.0
                        else:
                            print(sim_mode)
                            asdas

                        for c in range(0, len(file_name)):
                            ret = get_vectors(os.path.join(
                                tmp_dir, scan_folder, file_name[c]),
                                              vector[c],
                                              dolog=dolog,
                                              div=div,
                                              mul=mul,
                                              fabs=do_fabs)
                            #print(file_name[c],ret)
                            if ret == False:
                                error = True
                                break

                            v.append("#ml_input_" + token_ext[c])
                            v.append(ret)

                        if sim_mode == "jv" and light > 0.0:
                            for t in ["#jv_pmax_tau", "#jv_pmax_mue", "#pce"]:
                                ret = inp_get_token_value(
                                    os.path.join(tmp_dir, scan_folder,
                                                 "sim_info.dat"), t)
                                if ret == False:
                                    error = True
                                    break

                                v.append(t + "_" + scan_folder)
                                v.append(ret)

                    for p in self.scan.program_list:
                        if p.values.count("random") > 0:
                            full_inp_file_name = os.path.join(
                                tmp_dir, sub_sims[0], p.file)

                            temp = inp_get_token_value(full_inp_file_name,
                                                       p.token)
                            if temp == False:
                                error = True
                                break
                            else:
                                v.append(p.token)
                                v.append(temp)

                    #print(v,error)
                    if error == False:
                        out.write(str.encode("\n".join(v) + "\n"))
                        written = True
                    else:
                        errors = errors + 1

                    done = done + 1

                    progress_window.set_fraction(
                        float(done) / float(len(simulations) * tot_archives))
                    if written == True:
                        progress_window.set_text(simulation)
                    else:
                        progress_window.set_text(
                            "                         /Last error: " +
                            simulation + " tot errors=" + str(errors) + " " +
                            str(round(100.0 * errors / done, 1)) + "%")

                    progress_window.set_text(simulation)

                    #if server_break()==True:
                    #	break
                    process_events()
                    #return

                    shutil.rmtree(tmp_dir)

        out.close()
        progress_window.stop()
Beispiel #17
0
def merge_archives(src_archive,dest_archive,only_over_write):
	debug=False

	progress_window=progress_class()
	progress_window.show()
	progress_window.start()

	process_events()

#	src_dir=os.path.dirname(src_archive)
#	dest_dir=os.path.dirname(dest_archive)
	dest_path=os.path.dirname(dest_archive)
	template_archive=gpvdm_paths.get_inp_template_path()

	remove_non_used_index_files(dest_archive,src_archive)

	ls=zip_lsdir(src_archive)

	#copy files without checking ver

	for i in range(0,len(ls)):
		info=get_file_info(ls[i])
		if info!=False:
			if info.copy_opp==file_type().JUST_COPY:
				#print(ls[i])
				archive_copy_file(dest_archive,ls[i],src_archive,ls[i],dest=info.dest)

			
			#src_ver=inp_get_file_ver(src_archive,ls[i])

			if info.copy_opp==file_type().CHECK_VER_THEN_COPY:
				template_ver=inp().get_ver(os.path.join(template_archive,info.base_file))
				src_ver=inp_get_file_ver(src_archive,ls[i])

				if template_ver!=False and src_ver!="":
					if template_ver==src_ver:
						archive_copy_file(dest_archive,ls[i],src_archive,ls[i])
						#print("complex copy")

			if info.copy_opp==file_type().MERGE:
				if only_over_write==False:
					if archive_isfile(dest_archive,ls[i])==False:
						if archive_copy_file(dest_archive,ls[i],template_archive,info.base_file)==False:
							print("problem copying",template_archive,info.base_file)
							#if info.base_file=="dump.inp":
							#	sys.exit(0)
						#print("made new file",dest_archive,ls[i])

				ret=archive_merge_file(dest_archive,src_archive,ls[i],ls[i])
		
		progress_window.set_fraction(float(i)/float(len(ls)))
		progress_window.set_text("Importing "+ls[i])
		process_events()

	#if you find a materials directory in the archive try to merge it
	for i in range(0,len(ls)):
		zip_dir_name=ls[i].split("/")
		if zip_dir_name[0]=="materials":
			dest=os.path.join(os.path.dirname(get_materials_path()))
			#print("Try to read",src_archive,ls[i],dest)
			extract_file_from_archive(dest,src_archive,ls[i])

		if zip_dir_name[0]=="sim":
			extract_file_from_archive(dest_path,src_archive,ls[i])

		if zip_dir_name[0]=="calibrate":
			extract_file_from_archive(dest_path,src_archive,ls[i])

	#search for scan directories
	scan_dirs=[]
	for i in range(0,len(ls)):
		if ls[i].endswith("gpvdm_gui_config.inp"):
			scan_dirs.append(os.path.dirname(ls[i]))

	#extract scan directories
	for i in range(0,len(ls)):
		for ii in range(0,len(scan_dirs)):
			if ls[i].startswith(scan_dirs[ii])==True:
				#print("Try to read",src_archive,ls[i])
				extract_file_from_archive(dest_path,src_archive,ls[i])
	print("search",scan_dirs)

	progress_window.stop()
Beispiel #18
0
    def __init__(self):
        super(gpvdm_main_window, self).__init__()

        self.splash = splash_window()
        self.splash.inc_value()
        process_events()
        process_events()

        #from wiz import wiz
        #a=wiz()
        #a.exec_()

        #sys.exit()
        do_import()

        if os.path.isdir(os.path.dirname(sys.argv[0])) == False:
            error_dlg(self, _("I can't run from inside a zip file!"))
            sys.exit()

        self.splash.inc_value()
        self.splash.inc_value()

        server_init()
        self.splash.inc_value()

        self.check_sim_exists = check_sim_exists()
        self.splash.inc_value()

        self.check_sim_exists.start_thread()
        self.splash.inc_value()

        self.check_sim_exists.sim_gone.connect(self.sim_gone)
        self.splash.inc_value()

        self.my_server = server_get()
        self.my_server.init(get_sim_path())
        self.splash.inc_value()

        self.undo_list = undo_list_class()
        wpos_load()
        self.splash.inc_value()

        self.ribbon = ribbon()
        self.splash.inc_value()

        self.notebook_active_page = None
        self.setAcceptDrops(True)
        #self.setGeometry(200, 100, 1300, 600)
        self.setWindowTitle(
            "General-purpose Photovoltaic Device Model (https://www.gpvdm.com)"
        )

        #super(gpvdm_main_window, self).__init__(parent, QtCore.Qt.FramelessWindowHint)
        #gobject.GObject.__init__(self)

        self.my_server.setup_gui(self.gui_sim_start)
        self.splash.inc_value()

        self.my_server.sim_finished.connect(self.gui_sim_stop)
        self.splash.inc_value()

        help_init()
        self.splash.inc_value()

        #help_window().help_set_help(["star.png",_("<big><b>Update available!</b></big><br>")])

        #self.show()

        if running_on_linux() == True:
            DBusQtMainLoop(set_as_default=True)
            self.bus = dbus.SessionBus()
            self.bus.add_match_string_non_blocking(
                "type='signal',interface='org.my.gpvdm'")
            self.bus.add_message_filter(self.adbus)
        else:
            self.win_pipe = win_pipe()
            self.win_pipe.new_data.connect(self.win_dbus)
            self.win_pipe.start()

        self.notebook = gpvdm_notebook()
        vbox = QVBoxLayout()
        self.splash.inc_value()

        vbox.addWidget(self.ribbon)
        vbox.addWidget(self.notebook)
        wvbox = QWidget()
        self.splash.inc_value()

        wvbox.setLayout(vbox)
        self.setCentralWidget(wvbox)

        self.splash.inc_value()

        self.statusBar()

        temp_error = ver_error()
        #print(temp_error)
        if len(temp_error) > 0:
            error_dlg(self, temp_error)
            return

        self.setWindowIcon(
            QIcon(os.path.join(get_image_file_path(), "image.jpg")))
        self.splash.inc_value()

        self.show_tabs = True
        self.show_border = True

        self.ribbon.home_export.triggered.connect(self.callback_export)

        #if enable_webupdates()==False:
        #	self.help_menu_update=help_menu.addAction("&"+_("Check for updates"))
        #	self.help_menu_update.triggered.connect(self.callback_update)

        self.ribbon.home_new.triggered.connect(self.callback_new)
        self.ribbon.home_open.triggered.connect(self.callback_open)
        self.ribbon.home.undo.triggered.connect(self.callback_undo)
        self.ribbon.home.run.triggered.connect(self.callback_simulate)
        self.splash.inc_value()

        self.ribbon.home.stop.setEnabled(False)

        self.ribbon.home.scan.setEnabled(False)

        self.ribbon.home.help.triggered.connect(self.callback_on_line_help)

        resize_window_to_be_sane(self, 0.7, 0.75)

        self.change_dir_and_refresh_interface(get_sim_path())
        self.splash.inc_value()

        self.ribbon.home.sun.changed.connect(self.notebook.update)
        self.ribbon.setAutoFillBackground(True)
        self.splash.inc_value()
        self.show()
        help_window().show()

        from update import update_window
        self.a = update_window()
        self.a.show()
Beispiel #19
0
def scan_ml_build_vector(sim_dir):

    out = open(os.path.join(sim_dir, "vectors.dat"), 'wb')
    for archive_name in os.listdir(sim_dir):
        if archive_name.startswith(
                "archive") == True and archive_name.endswith(".zip") == True:
            progress_window = progress_class()
            progress_window.show()
            progress_window.start()

            archive_path = os.path.join(sim_dir, archive_name)

            zf = zipfile.ZipFile(archive_path, 'r')
            dirs = zip_lsdir(archive_path, zf=zf, sub_dir="/")

            items = len(dirs)
            print(items, archive_path, dirs)
            for i in range(0, len(dirs)):
                tmp_dir = "/dev/shm/gpvdm"
                if os.path.isdir(tmp_dir) == True:
                    shutil.rmtree(tmp_dir)

                os.mkdir(tmp_dir)

                extract_dir_from_archive(tmp_dir, "", dirs[i], zf=zf)

                full_name = tmp_dir
                written = False
                #print(dirs[i])
                while (1):
                    v = "#ml_id\n"
                    v = v + dirs[i] + "\n"

                    v = v + "#ml_input_jv_dark\n"
                    ret = get_vectors(full_name,
                                      "0.0",
                                      "measure_jv.dat",
                                      dolog=True)
                    if ret == False:
                        print("ml_input_jv_dark")
                        break
                    v = v + ret + "\n"

                    v = v + "#ml_input_jv_light\n"
                    ret = get_vectors(full_name,
                                      "1.0",
                                      "measure_jv.dat",
                                      div=1e2)
                    if ret == False:
                        print("ml_input_jv_ligh")
                        break
                    v = v + ret + "\n"

                    v = v + "#ml_input_tpc_neg\n"
                    ret = get_vectors(full_name,
                                      "TPC",
                                      "measure_tpc.dat",
                                      fabs=True,
                                      dolog=True)
                    if ret == False:
                        break
                    v = v + ret + "\n"

                    v = v + "#ml_input_tpc\n"
                    ret = get_vectors(full_name,
                                      "TPC_0",
                                      "measure_tpc.dat",
                                      fabs=True,
                                      dolog=True)
                    if ret == False:
                        break
                    v = v + ret + "\n"

                    v = v + "#ml_input_tpc_neg_norm\n"
                    ret = get_vectors(full_name,
                                      "TPC",
                                      "measure_tpc.dat",
                                      fabs=True,
                                      dolog=True,
                                      do_norm=True)
                    if ret == False:
                        break
                    v = v + ret + "\n"

                    v = v + "#ml_input_tpc_norm\n"
                    ret = get_vectors(full_name,
                                      "TPC_0",
                                      "measure_tpc.dat",
                                      fabs=True,
                                      dolog=True,
                                      do_norm=True)
                    if ret == False:
                        break
                    v = v + ret + "\n"

                    v = v + "#ml_input_tpc_ideal\n"
                    ret = get_vectors(full_name,
                                      "TPC_ideal",
                                      "measure_tpc.dat",
                                      fabs=True,
                                      dolog=True)
                    if ret == False:
                        break
                    v = v + ret + "\n"

                    v = v + "#ml_input_tpc_ideal_norm\n"
                    ret = get_vectors(full_name,
                                      "TPC_ideal",
                                      "measure_tpc.dat",
                                      fabs=True,
                                      dolog=True,
                                      do_norm=True)
                    if ret == False:
                        break
                    v = v + ret + "\n"

                    v = v + "#ml_input_tpv\n"
                    ret = get_vectors(full_name,
                                      "TPV",
                                      "measure_tpv.dat",
                                      fabs=True)
                    if ret == False:
                        break
                    v = v + ret + "\n"

                    v = v + "#ml_input_celiv\n"
                    ret = get_vectors(full_name,
                                      "CELIV",
                                      "measure_celiv.dat",
                                      fabs=True)
                    if ret == False:
                        break
                    v = v + ret + "\n"

                    v = v + get_vectors_binary(full_name, "1.0")
                    for min_max in ["min", "max", "avg"]:
                        a = scan_ml_build_token_vectors(
                            os.path.join(full_name, "dos0.inp"),
                            "#Etrape",
                            "#Etraph",
                            [40e-3, 50e-3, 60e-3, 70e-3, 80e-3, 90e-3, 100e-3],
                            min_max=min_max)
                        v = v + a

                        a = scan_ml_build_token_vectors(
                            os.path.join(full_name, "dos0.inp"),
                            "#mueffe",
                            "#mueffh",
                            [1e-9, 1e-8, 1e-7, 1e-6, 1e-5, 1e-4, 1e-3],
                            min_max=min_max)
                        v = v + a

                        a = scan_ml_build_token_vectors(
                            os.path.join(full_name, "dos0.inp"),
                            "#Ntraph",
                            "#Ntrape",
                            [1e20, 1e21, 1e22, 1e23, 1e24, 1e25, 1e26, 1e27],
                            min_max=min_max)
                        v = v + a

                    a = scan_ml_build_token_vectors(
                        os.path.join(full_name, "parasitic.inp"),
                        "#Rshunt",
                        "#Rshunt", [1e2, 1e3, 1e4, 1e5, 1e6, 1e7],
                        min_max="avg")
                    v = v + a

                    #a=scan_ml_build_token_abs(os.path.join(full_name,"parasitic.inp"),"#Rshunt","#Rshunt",min_max="avg")
                    #v=v+a

                    a = scan_ml_build_token_vectors(
                        os.path.join(full_name, "parasitic.inp"),
                        "#Rcontact",
                        "#Rcontact", [5, 10, 15, 20, 25, 30, 35, 40],
                        min_max="avg")
                    v = v + a

                    a = scan_ml_build_token_vectors(
                        os.path.join(full_name, "1.0", "sim_info.dat"),
                        "#jv_pmax_tau",
                        "#jv_pmax_tau",
                        [1e-1, 1e-2, 1e-3, 1e-4, 1e-5, 1e-6, 1e-7],
                        min_max="avg")
                    v = v + a

                    a = scan_ml_build_token_vectors(
                        os.path.join(full_name, "1.0", "sim_info.dat"),
                        "#jv_pmax_mue",
                        "#jv_pmax_mue",
                        [1e-9, 1e-8, 1e-7, 1e-6, 1e-5, 1e-4, 1e-3],
                        min_max="avg")
                    v = v + a

                    out.write(str.encode(v))
                    written = True
                    break

                if written == False:
                    print("Error", dirs[i])
                progress_window.set_fraction(float(i) / float(len(dirs)))
                progress_window.set_text(dirs[i])

                #if server_break()==True:
                #	break
                process_events()
                #return
            progress_window.stop()