def load_envi_file(filename): IDL.run('envi') IDL.ENVI_OPEN_FILE(filename)
def load_array(arr): IDL.run('envi') IDL.ENVI_ENTER_DATA(arr)
rfra = (rmax) + (cc[rmax+1,cmax] -cc[rmax-1,cmax])/denom denom = 2.*(2.*cc.max() - cc[rmax,cmax+1] - cc[rmax, cmax-1]) cfra = (cmax) + (cc[rmax,cmax+1] -cc[rmax,cmax-1])/denom rmax = rfra cmax = cfra return np.array([rmax - d0n.shape[0]/2. , cmax - d0n.shape[1]/2.]) ###################################################### if __name__ == "__main__": from idlpy import IDL import numpy as np import time a = np.random.rand(1024) b = np.random.rand(1024) print "IDL 1d SHC return: ",IDL.shc(a,b) print "Python 1d SHC numpy return:", shc_numpy(a,b) print "Python 1d SHC opencv return:", shc_opencv(a,b) aa = np.random.rand(1248,4238) aa[10:20,20:45] = 100. bb = np.random.rand(1248,4238) bb[15:25,21:46] = 100. print "IDL 2D SHC return:",IDL.shc(aa,bb) print "Python 2D SHC numpy return:",shc_numpy(aa,bb) print "Python 2D SHC opencv return:",shc_opencv(aa,bb) start = time.time() shc_numpy(aa,bb) end = time.time() print("numpy time:",end - start) start = time.time() shc_opencv(aa,bb)
def load_external_file(filename): IDL.run('envi') name, ext = os.path.splitext(os.path.basename(filename)) if ext in ['.tif', '.tiff']: IDL.ENVI_OPEN_DATA_FILE(filename, TIFF=1) elif ext in ['.txt', '.met']: IDL.ENVI_OPEN_DATA_FILE(filename, LANDSAT_METADATA=1)
def dspk_idl(data, std_dev=4.5, Niter=10): # IDL.run('$ pwd', stdout=1) cwd = os.path.dirname(os.path.realpath(__file__)) dir = cwd + '/../../idl/dspk"' cmd = '!path = !path + ":' + dir IDL.run(cmd) # IDL.run('print, !path', stdout=1) return IDL.despik(data, sigmas=std_dev, Niter=Niter)
def idl_do_execute(self, code, call_result, graphics): call_line = '' for each in code.splitlines(): each = each.rstrip() if each.lower().startswith('.run'): continue if len(each) > 0 and each[-1] == '$': call_line += each[0:-1] continue else: call_line += each result = IDL.run(call_line) call_line = '' idlmagic = getattr(IDL, '!MAGIC') if idlmagic['WINDOW'] != -1 and idlmagic['WINDOW'] not in graphics: graphics[idlmagic['WINDOW']] = idlmagic call_result.append(self._graphicid) if result is not None: call_result.append(result) if '.res' in each.lower() or '.f' in each.lower(): self.idl_initGConfig()
def top2wgs(self, top_latitude, top_elevation): IDL.top_latitude = top_latitude IDL.top_elevation = top_elevation wgs_latitude = None IDL.wgs_latitude = wgs_latitude wgs_elevation = None IDL.wgs_elevation = wgs_elevation # IDL.run('print, top_latitude, top_elevation', stdout=True) # IDL.run('print, wgs_latitude, wgs_elevation', stdout=True) IDL.run( 'top2wgs, top_latitude, top_elevation, wgs_latitude, wgs_elevation', stdout=True) wgs_latitude = IDL.wgs_latitude # pass by value wgs_elevation = IDL.wgs_elevation # pass by value return wgs_latitude, wgs_elevation
def init_ENVI(): """ Initialises ENVI. Should never need to be called manually, as will be called automatically where necessary. """ global e if e is None: print("Initialising ENVI") e = IDL.ENVI()
def generate_test_data(): """ Run IDL ANDROMEDA and create ``andromeda_idl.npz``. """ global DATACUBE from idlpy import IDL as idl idl.cube = DATACUBE.cube idl.angles = DATACUBE.angles idl.psf = DATACUBE.psf idl.run("andromeda_contrast_1 = ANDROMEDA(" "IMAGES_1_INPUT=cube," "ANGLES_INPUT=angles," "PSF_PLANET_INPUT=psf," "OVERSAMPLING_1_INPUT=1," "FILTERING_FRACTION_INPUT=1," # turn off high pass "MINIMUM_SEPARATION_INPUT=0.3," "OPT_METHOD_ANG_INPUT=1," # no optimization "NSMOOTH_SNR_INPUT=0," # turn off smoothing "/HOMOGENEOUS_VARIANCE_INPUT," "" # output: "SNR_OUTPUT=andromeda_snr_1," "SNR_NORM_OUTPUT=andromeda_snr_norm_1," "LIKELIHOOD_OUTPUT=andromeda_likelihood_1," "STDDEVCONTRAST_OUTPUT=andromeda_stddevcontrast_1," "STDDEVCONTRAST_NORM_OUTPUT=andromeda_stddevcontrast_norm_1," "EXT_RADIUS_OUTPUT=andromeda_ext_radius_1)") OUT = {} OUT["andromeda_contrast_1"] = idl.andromeda_contrast_1 OUT["andromeda_snr_1"] = idl.andromeda_snr_1 OUT["andromeda_snr_norm_1"] = idl.andromeda_snr_norm_1 OUT["andromeda_likelihood_1"] = idl.andromeda_likelihood_1 OUT["andromeda_stdcontrast_1"] = idl.andromeda_stddevcontrast_1 OUT["andromeda_stdcontrast_norm_1"] = idl.andromeda_stddevcontrast_norm_1 np.savez_compressed(os.path.join(CURRDIR, "andromeda_idl.npz"), **OUT)
def idl_output_result(self, result, graphics): # Check if PNG if result == self._graphicid and len(graphics) > 0: # Returns a tuple with the window ID and !magic info. idlmagic = graphics.popitem(False)[1] img = IDL.EncodeGraphic(idlmagic['WINDOW'], idlmagic['TYPE']) if img != None: # See Python logging module # self.log.warning("IDL graphic " + str(idlmagic['WINDOW']) + " md5=" + # hashlib.md5(img.encode()).hexdigest()) width = str(idlmagic['XSIZE']) height = str(idlmagic['YSIZE']) response = { 'data': { 'image/png': img }, 'metadata': { 'image/png': { 'width': width, 'height': height } } } else: err = 'Error: Unable to encode graphics window ' + str( idlmagic['WINDOW']) + '\n' response = {'data': {'text/plain': err}, 'metadata': {}} else: if result.startswith("<html>"): response = { 'data': { 'text/html': result + '\n' }, 'metadata': {} } else: response = { 'data': { 'text/plain': result + '\n' }, 'metadata': {} } self.send_response(self.iopub_socket, 'display_data', response)
def idl_initGConfig(self): IDL.run("compile_opt idl2", silent=True) IDL.run("!QUIET=1 & !MAGIC.embed=1 & !MAGIC.window=-1", silent=True)
def __init__(self): super(self.__class__, self).__init__() curPath = os.path.split(thisfile__abspath)[0] savFilePath = os.path.join(curPath, "ellipsoid.sav") IDL.run('restore, FILENAME = \'{0}\''.format(savFilePath), stdout=True)
def __init__(self, varfile='pvar.dat', npar_max=-1, datadir=False, sim=False, proc=-1, swap_endian=False, quiet=False, DEBUG=False): """ Read PVAR files from Pencil Code using IDL. Uses IDL<->Python Bridge, this must be activated manually! Args: - datadir specify datadir, default False - sim specify simulation from which you want to read - varfile put 'PVARXYZ' or just number here, 'VAR' will be replaced by 'PVAR' autom. - npar_max maximal number of particles to be read in - proc read from single proc, set number here - swap_endian change if needed to True, default False - quiet verbosity, default False """ import numpy as np import os import pencilnew as pcn from pencilnew.math import is_number from sys import byteorder try: cwd = os.getcwd() from idlpy import IDL os.chdir(cwd) except: print('! ERROR: no idl<->python bridge found. Try whats written in pstalk-comment to fix that issue.') print('! ') print('! Use something like: (enshure you have IDL 8.5.1 or larger)') print('! export PYTHONPATH=$PYTHONPATH:$IDL_HOME/lib/bridges:$IDL_HOME/bin/bin.linux.x86_64') print('! export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64:$IDL_HOME/bin/bin.linux.x86_64') print('! in your .bashrc') print('! ') return False ####### interprate parameters if datadir == False: if sim == False: sim = pcn.get_sim() datadir = sim.datadir if quiet == False: quiet = '0' else: quiet = '1' if swap_endian == False: if byteorder == 'little': swap_endian = '0' elif byteorder == 'big': swap_endian = '1' else: print('? WARNING: Couldnt determine endianness!') ####### preparing IDL call # cleanup of varfile string if is_number(varfile): varfile = 'PVAR'+str(varfile) varfile = str(varfile) if varfile=='var.dat': varfile='pvar.dat' if varfile[:3]=='VAR': varfile='P'+varfile # idl_call = ', '.join(['pc_read_pvar', 'obj=pvar', 'varfile="'+varfile+'"', 'datadir="'+datadir+'"', 'quiet='+quiet, 'swap_endian='+swap_endian, 'proc='+str(proc) ]) # reduce number of particles to be read in if npar_max > 0: idl_call= idl_call+', npar_max='+str(npar_max) ####### show idl_call string if DEBUG if DEBUG == True: print('~ DEBUG: idl_call: '+idl_call) ###### read in var file in IDL print('~ reading '+varfile+' in IDL..') IDL.run(idl_call) ####### parse to python print('~ parsing PVAR from IDL to python..') pvar = IDL.pvar for key in pvar.keys(): setattr(self, key, pvar[key])
def __init__(self, datadir=False, sim=False, swap_endian=False, quiet=False): """ Read PSTALK files from Pencil Code using IDL. Uses IDL<->Python Bridge, this must be activated manually! Args: - datadir specify datadir, default False - sim specify simulation from which you want to read - swap_endian change if needed to True, default False - quiet verbosity, default False """ import numpy as np import os import pencilnew as pcn try: cwd = os.getcwd() from idlpy import IDL os.chdir(cwd) except: print( '! ERROR: no idl<->python bridge found. Try whats written in pstalk-comment to fix that issue.' ) print('! ') print( '! Use something like: (enshure you have IDL 8.5.1 or larger)') print( '! export PYTHONPATH=$PYTHONPATH:$IDL_HOME/lib/bridges:$IDL_HOME/bin/bin.linux.x86_64' ) print( '! export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64:$IDL_HOME/bin/bin.linux.x86_64' ) print('! in your .bashrc') print('! ') print('~ reading pstalk in IDL..') if datadir == False: if sim == False: sim = pcn.get_sim() datadir = sim.datadir if quiet == False: quiet = '0' else: quiet = '1' if swap_endian == False: swap_endian = '0' else: swap_endian = '1' idl_call = ', '.join([ 'pc_read_pstalk', 'obj=pstalk', 'datadir="' + datadir + '"', 'quiet=' + quiet, 'swap_endian=' + swap_endian ]) IDL.run(idl_call) print('~ parsing pstalk from IDL to python..') ps = IDL.pstalk for key in ps.keys(): setattr(self, key, ps[key].T)
def __init__(self, datadir=False, sim=False, tmin=0, tmax=-1, noutmax='-1', swap_endian=False, quiet=False, use_existing_pstalk_sav=False): """ Read PSTALK files from Pencil Code using IDL. Uses IDL<->Python Bridge, this must be activated manually! Args: - datadir specify datadir, default False - sim specify simulation from which you want to read - swap_endian change if needed to True, default False - quiet verbosity, default False - use_existing_pstalk_sav use existing <sim.datadir>/data/pc/tmp/pstalk.sav for speed up """ import numpy as np import os from os.path import join from .. import get_sim if datadir == False: if sim == False: sim = get_sim() datadir = sim.datadir if quiet == False: quiet = '0' else: quiet = '1' if swap_endian == False: swap_endian = '0' else: swap_endian = '1' if use_existing_pstalk_sav == True: from scipy.io.idl import readsav print('~ reading existing pstalk..') ps = readsav(join(sim.pc_datadir,'tmp','pstalk.sav'))('pstalk') for key in set(ps.dtype.fields.keys()): if hasattr(self, key.lower()): continue setattr(self, key.lower(), ps[key][0].T) else: try: cwd = os.getcwd() from idlpy import IDL os.chdir(cwd) print('~ reading pstalk in IDL..') idl_call = ', '.join(['pc_read_pstalk', 'obj=pstalk', 'datadir="'+datadir+'"', 'it0='+str(tmin), 'it1='+str(tmax), 'quiet='+quiet, 'swap_endian='+swap_endian, 'noutmax='+str(noutmax)]) IDL.run(idl_call) print('~ parsing pstalk from IDL to python..') ps = IDL.pstalk for key in set(ps.keys()): if hasattr(self, key.lower()): continue setattr(self, key.lower(), ps[key].T) except: print('! ERROR: no idl<->python bridge found. Try whats written in pstalk-comment to fix that issue.') print('! ') print('! Use something like: (ensure you have IDL 8.5.1 or larger)') print('! export PYTHONPATH=$PYTHONPATH:$IDL_HOME/lib/bridges:$IDL_HOME/bin/bin.linux.x86_64') print('! export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64:$IDL_HOME/bin/bin.linux.x86_64') print('! in your .bashrc') print('! ') print('! If you have it already installed, try: from idlpy import IDL and check for errors') print('! ') print('~ BACKUP SOLUTION: reading pstalk via pidly, starting IDL..') from ..backpack import pidly IDL = pidly.IDL(long_delay=0.05) # start IDL engine from scipy.io.idl import readsav from ..io import mkdir ## read tstalk file print('## reading particle stalker file..') IDL('pc_read_pstalk, object=pstalk, datadir="'+sim.datadir+'"'+', quiet='+quiet+', it0='+str(tmin)+', it1='+str(tmax)+', swap_endian='+swap_endian) print('## transfering pstalk file from IDL to python..') mkdir(join(sim.pc_datadir,'tmp')) IDL('save, pstalk, filename="'+join(sim.pc_datadir,'tmp','pstalk_'+str(tmin)+'_'+str(tmax)+'.sav')+'"') ps = readsav(join(sim.pc_datadir,'tmp','pstalk.sav'))('pstalk') #from pc.io import debug_breakpoint; debug_breakpoint() for key in set(ps.dtype.fields.keys()): if hasattr(self, key.lower()): continue setattr(self, key.lower(), ps[key][0].T)
def __init__(self, varfile='pvar.dat', npar_max=-1, datadir=False, sim=False, proc=-1, swap_endian=False, quiet=False, DEBUG=False): """ Read PVAR files from Pencil Code using IDL. Uses IDL<->Python Bridge, this must be activated manually! Args: - datadir specify datadir, default False - sim specify simulation from which you want to read - varfile put 'PVARXYZ' or just number here, 'VAR' will be replaced by 'PVAR' autom. - npar_max maximal number of particles to be read in - proc read from single proc, set number here - swap_endian change if needed to True, default False - quiet verbosity, default False """ import numpy as np import os import pencilnew as pcn from pencilnew.math import is_number from sys import byteorder try: cwd = os.getcwd() from idlpy import IDL os.chdir(cwd) except: print('! ERROR: no idl<->python bridge found. Try whats written in pstalk-comment to fix that issue.') print('! ') print('! Use something like: (enshure you have IDL 8.5.1 or larger)') print('! export PYTHONPATH=$PYTHONPATH:$IDL_HOME/lib/bridges:$IDL_HOME/bin/bin.linux.x86_64') print('! export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64:$IDL_HOME/bin/bin.linux.x86_64') print('! in your .bashrc') print('! ') return None ####### interprate parameters if datadir == False: if sim == False: sim = pcn.get_sim() datadir = sim.datadir if quiet == False: quiet = '0' else: quiet = '1' if swap_endian == False: if byteorder == 'little': swap_endian = '0' elif byteorder == 'big': swap_endian = '1' else: print('? WARNING: Couldnt determine endianness!') ####### preparing IDL call # cleanup of varfile string if is_number(varfile): varfile = 'PVAR'+str(varfile) varfile = str(varfile) if varfile=='var.dat': varfile='pvar.dat' if varfile[:3]=='VAR': varfile='P'+varfile # idl_call = ', '.join(['pc_read_pvar', 'obj=pvar', 'varfile="'+varfile+'"', 'datadir="'+datadir+'"', 'quiet='+quiet, 'swap_endian='+swap_endian, 'proc='+str(proc) ]) # reduce number of particles to be read in if npar_max > 0: idl_call= idl_call+', npar_max='+str(npar_max) ####### show idl_call string if DEBUG if DEBUG == True: print('~ DEBUG: idl_call: '+idl_call) ###### read in var file in IDL print('~ reading '+varfile+' in IDL..') IDL.run(idl_call) ####### parse to python print('~ parsing PVAR from IDL to python..') pvar = IDL.pvar for key in pvar.keys(): setattr(self, key.lower(), pvar[key]) setattr(self, 'xp', pvar['XX'][0]) setattr(self, 'yp', pvar['XX'][1]) setattr(self, 'zp', pvar['XX'][2]) setattr(self, 'vpx', pvar['VV'][0]) setattr(self, 'vpy', pvar['VV'][1]) setattr(self, 'vpz', pvar['VV'][2])
def __init__( self, varfile="pvar.dat", npar_max=-1, datadir=False, sim=False, proc=-1, swap_endian=False, quiet=False, DEBUG=False, ): """ Read PVAR files from Pencil Code using IDL. Uses IDL<->Python Bridge, this must be activated manually! Args: - datadir specify datadir, default False - sim specify simulation from which you want to read - varfile put 'PVARXYZ' or just number here, 'VAR' will be replaced by 'PVAR' autom. - npar_max maximal number of particles to be read in - proc read from single proc, set number here - swap_endian change if needed to True, default False - quiet verbosity, default False """ import numpy as np import os from pencil import get_sim from pencil.math import is_number from sys import byteorder ####### interpret parameters if datadir == False: if sim == False: sim = get_sim() datadir = sim.datadir l_h5 = False if os.path.exists(os.path.join(datadir, "grid.h5")): l_h5 = True import h5py if not l_h5: try: cwd = os.getcwd() from idlpy import IDL os.chdir(cwd) except: print( "! ERROR: no idl<->python bridge found. Try whats written in pstalk-comment to fix that issue." ) print("! ") print( "! Use something like: (ensure you have IDL 8.5.1 or larger)" ) print( "! export PYTHONPATH=$PYTHONPATH:$IDL_HOME/lib/bridges:$IDL_HOME/bin/bin.linux.x86_64" ) print( "! export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64:$IDL_HOME/bin/bin.linux.x86_64" ) print("! in your .bashrc") print("! ") return None if not l_h5: if quiet == False: quiet = "0" else: quiet = "1" if swap_endian == False: if byteorder == "little": swap_endian = "0" elif byteorder == "big": swap_endian = "1" else: print("? WARNING: Couldnt determine endianness!") ####### preparing IDL call # cleanup of varfile string if is_number(varfile): varfile = "PVAR" + str(varfile) varfile = str(varfile) if varfile == "var.dat": varfile = "pvar.dat" if varfile[:3] == "VAR": varfile = "P" + varfile if l_h5: varfile = str.strip(varfile, ".dat") + ".h5" with h5py.File(os.path.join(datadir, "allprocs", varfile), "r") as hf: for key in hf["part"].keys(): setattr(self, key.lower(), hf["part"][key][()]) # else: idl_call = ", ".join([ "pc_read_pvar", "obj=pvar", 'varfile="' + varfile + '"', 'datadir="' + datadir + '"', "quiet=" + quiet, "swap_endian=" + swap_endian, "proc=" + str(proc), ]) # reduce number of particles to be read in if npar_max > 0: idl_call = idl_call + ", npar_max=" + str(npar_max) ####### show idl_call string if DEBUG if DEBUG == True: print("~ DEBUG: idl_call: " + idl_call) ###### read in var file in IDL print("~ reading " + varfile + " in IDL..") IDL.run(idl_call) ####### parse to python print("~ parsing PVAR from IDL to python..") pvar = IDL.pvar for key in pvar.keys(): setattr(self, key.lower(), pvar[key]) setattr(self, "xp", pvar["XX"][0]) setattr(self, "yp", pvar["XX"][1]) setattr(self, "zp", pvar["XX"][2]) setattr(self, "vpx", pvar["VV"][0]) setattr(self, "vpy", pvar["VV"][1]) setattr(self, "vpz", pvar["VV"][2])
def idl_resetGConfig(self): IDL.run("!MAGIC.window=-1", silent=True)
def startup(): print("Loading Python-IDL bridge...") import os cur_dir = os.getcwd() # check that required environmentals are defined try: idl_dir = os.environ['IDL_DIR'] except: print('$IDL_DIR is undefined.') return try: ssw = os.environ['SSW'] except: print('$SSW is undefined. Defaulting to vanilla IDL.') ssw = None pass # save personal IDL startup (to run later) try: pers_start = os.environ['IDL_STARTUP'] os.environ['IDL_STARTUP'] = '' except: pers_start = '' pass # switch to IDL bridge directory and import IDL-Python bridge object bridge_dir = os.path.join(idl_dir, 'lib', 'bridges') cur_dir = os.getcwd() os.chdir(bridge_dir) from idlpy import IDL # load preferred instruments if ssw: try: ssw_instr = os.environ['SSW_INSTR'] IDL.ssw_instr = ssw_instr print('Loading: ' + ssw_instr) IDL.run("setenv,'SSW_INSTR='+ssw_instr") except: print('SSW_INSTR is undefined. Defaulting to GEN.') pass startup_dir = os.path.join(ssw, 'gen', 'idl', 'ssw_system') os.chdir(startup_dir) IDL.run("!quiet=1") IDL.run("ssw_load") IDL.run("a=is_pyidl(/set)") # now load personal startup if os.path.isfile(pers_start): IDL.pers_start = pers_start os.environ['IDL_STARTUP'] = pers_start print('Executing personal IDL_STARTUP: ' + pers_start) IDL.run('@' + pers_start) IDL.run("!quiet=0") os.chdir(cur_dir) return IDL
def get_pyimage_arrays(sol, seq, train): # Get an array where each element is a list of files with the same pointing print getfile_command % (sol, seq) IDL.run(getfile_command % (sol, seq)) img_list = IDL.img_list print img_list image_names = set([]) for img_set in img_list: if len(img_set) < 6: print "# images = %d, skipping" % len(img_set) continue filter_count = 0 for file in img_set: # We don't want to use the 0 (Bayer RGB true color) filter if 'A0' in file: print "Skipping A0" continue # Read the PDS file into an IDL array IDL.run(readpds_command % file) py_img = IDL.img print 'SHAPE: ', py_img.shape # Numpy references image dimensions as Y x X x N, # whereas IDL references as N x X x Y. We only keep # the relevant Bayer band with the most info for that filter. if 'ML' in file: ins = 'ML' if 'A1' in file: img_0 = py_img[1, :, :] filter_count += 1 elif 'A2' in file: img_1 = py_img[2, :, :] filter_count += 1 elif 'A3' in file: img_2 = py_img[0, :, :] filter_count += 1 elif 'A4' in file: img_3 = py_img[0, :, :] filter_count += 1 elif 'A5' in file: img_4 = py_img[1, :, :] filter_count += 1 elif 'A6' in file: img_5 = py_img[1, :, :] filter_count += 1 elif 'MR' in file: ins = 'MR' if 'A1' in file: img_0 = py_img[1, :, :] filter_count += 1 elif 'A2' in file: img_1 = py_img[2, :, :] filter_count += 1 elif 'A3' in file: img_2 = py_img[0, :, :] filter_count += 1 elif 'A4' in file: img_3 = py_img[1, :, :] filter_count += 1 elif 'A5' in file: img_4 = py_img[1, :, :] filter_count += 1 elif 'A6' in file: img_5 = py_img[1, :, :] filter_count += 1 # Check that it was actually a complete multispectral image if filter_count == 6: print "All filters accounted for" img_6f = np.ndarray([img_0.shape[0], img_0.shape[1], 6]) img_6f[:, :, 0] = img_0 img_6f[:, :, 1] = img_1 img_6f[:, :, 2] = img_2 img_6f[:, :, 3] = img_3 img_6f[:, :, 4] = img_4 img_6f[:, :, 5] = img_5 version = file.split('R')[-1][0] new_name = '%s_%s_%s_%s.npy' % (seq, sol, ins, version) if new_name in image_names: new_name = '%s_%s_%s_%s_%d.npy' % (seq, sol, ins, version, int(time.time() * 1000)) else: image_names.add(new_name) if train: np.save(data_dir + '/train/' + new_name, img_6f) else: np.save(data_dir + '/expert/' + new_name, img_6f)