from scipy import misc import cv2 import numpy as np import math import paramhelpers as ph import matplotlib.image as image import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec from PIL import Image img_data_path = ph.getParam("img_data_path", "../data/test1") threshold = float(ph.getParam("threshold", 0.4)) iteration_num = int(ph.getParam("iteration_num", 6)) def prepro_img(): ''' #test for numpy's function test = np.full((2, 2), np.nan) test[0,0]=0.12 test[1,1]=1.222 A = np.array( [[1,1], [0,1]] ) B = np.array( [[2,0], [3,4]] ) print ("A=","\n",A) print ("B=","\n",B) print ("A*B=","\n",A*B) # Aij * Bij print ("A.dot(B)=","\n",np.dot(A,B)) # matrix multiply print(np.min([1,2,3]))
import tensorflow as tf from tensorflow.python.client import timeline # load manta tools sys.path.append("../tools") import tilecreator as tc import paramhelpers as ph import fluiddataloader as FDL # there's no GAN here, but this script simplified the setup of conv nets from GAN import GAN, lrelu # --------------------------------------------- # initialize parameters / command line params outputOnly = int(ph.getParam( "out", False)) > 0 # output/generation mode, main mode switch basePath = ph.getParam("basePath", '../data/') randSeed = int(ph.getParam("randSeed", 1)) # seed for np and tf initialization load_model_test = int( ph.getParam("load_model_test", -1) ) # the number of the test to load a model from. can be used in training and output mode. -1 to not load a model load_model_no = int(ph.getParam("load_model_no", -1)) # nubmber of the model to load simSizeLow = int(ph.getParam("simSize", 64)) # tiles of low res sim tileSizeLow = int(ph.getParam("tileSize", 16)) # size of low res tiles upRes = int(ph.getParam("upRes", 4)) # scaling factor #Data and Output loadPath = ph.getParam("loadPath", '../data/') # path to training data fromSim = int(ph.getParam("fromSim", 1000)) # range of sim data to use, start index
# Main params ----------------------------------------------------------------------# steps = 200 savedata = True saveppm = False simNo = 1000 # start ID showGui = 0 basePath = '../data/' npSeedstr = "-1" res = 64 # debugging #steps = 50 # shorter test #savedata = False # debug , dont write... #showGui = 1 basePath = ph.getParam( "basePath", basePath ) npSeedstr = ph.getParam( "npSeed" , npSeedstr ) simNo = int(ph.getParam( "simNo" , simNo )) res = int(ph.getParam( "res" , res )) steps = int(ph.getParam( "steps" , steps )) npSeed = int(npSeedstr) ph.checkUnusedParams() # Scene settings ---------------------------------------------------------------------# setDebugLevel(1) # Solver params ----------------------------------------------------------------------# dim = 2 offset = 20 interval = 1
# optional, add velocity as additional channels to input? useVelocities = 0 # --------------------------------------------- # load an existing model when load_ values > -1 # when training , manually abort when it's good enough # then enter test_XXXX id and model checkpoint ID below to load load_model_test = -1 load_model_no = -1 testPathStartNo = 1 # command line params outputOnly = int(ph.getParam("out", outputOnly)) > 0 trainingEpochs = int(ph.getParam("trainingEpochs", trainingEpochs)) load_model_test = int(ph.getParam("loadModelTest", load_model_test)) load_model_no = int(ph.getParam("loadModelNo", load_model_no)) basePath = ph.getParam("basePath", basePath) useVelocities = int(ph.getParam("useVelocities", useVelocities)) testPathStartNo = int(ph.getParam("testPathStartNo", testPathStartNo)) fromSim = int(ph.getParam("fromSim", fromSim)) toSim = int(ph.getParam("toSim", toSim)) alwaysSave = int(ph.getParam( "alwaysSave", False)) # by default, only save when cost is lower, can be turned off here useLegacyNet = int(ph.getParam("useLegacyNet", False)) > 0 randSeed = int(ph.getParam("randSeed", randSeed)) simSizeLow = int(ph.getParam("simSizeLow", simSizeLow)) upRes = int(ph.getParam("upRes", upRes))
cropTileSizeLow = tileSizeLow - 2*cropOverlap # --------------------------------------------- # load an existing model when load_ values > -1 # when training , manually abort when it's good enough # then enter test_XXXX id and model checkpoint ID below to load loadModelTest = -1 loadModelNo = -1 testPathStartNo = 1 # command line params, explanations mostly above with variables outputOnly = int(ph.getParam( "out", outputOnly ))>0 trainingEpochs = int(ph.getParam( "trainingEpochs", trainingEpochs )) loadModelTest = int(ph.getParam( "loadModelTest", loadModelTest)) loadModelNo = int(ph.getParam( "loadModelNo", loadModelNo)) basePath = ph.getParam( "basePath", basePath ) useVelocities = int(ph.getParam( "useVelocities", useVelocities )) testPathStartNo = int(ph.getParam( "testPathStartNo", testPathStartNo )) fromSim = int(ph.getParam( "fromSim", fromSim )) toSim = int(ph.getParam( "toSim", toSim )) randSeed = int(ph.getParam( "randSeed", randSeed )) simSizeLow = int(ph.getParam( "simSizeLow", simSizeLow )) upRes = int(ph.getParam( "upRes", upRes )) outputInputs = int(ph.getParam( "outInputs", outputInputs)) ph.checkUnusedParams() # initialize
# Main params ----------------------------------------------------------------------# steps = 200 savedata = True saveppm = False simNo = 1000 # start ID showGui = 0 basePath = '../data/' npSeedstr = "-1" # debugging #steps = 50 # shorter test #savedata = False # debug , dont write... #showGui = 1 basePath = ph.getParam("basePath", basePath) npSeedstr = ph.getParam("npSeed", npSeedstr) npSeed = int(npSeedstr) ph.checkUnusedParams() # Scene settings ---------------------------------------------------------------------# setDebugLevel(1) # Solver params ----------------------------------------------------------------------# res = 64 dim = 2 offset = 20 scaleFactor = 4 #ratio = 1.2
# Copyright 2018 You Xie, Erik Franz, Mengyu Chu, Nils Thuerey # # Plume data generation, 3D # from manta import * import os, shutil, math, sys, time from datetime import datetime sys.path.append("../tools") import paramhelpers as ph import uniio outputpath = "../3ddata_sim_test/" # default target, but actual path set by getNextSimPath below simNo = 3006 outputpath, simNo = ph.getNextSimPath(simNo, outputpath) basePath = ph.getParam("basePath", "../data/") savedata = int(ph.getParam("savedata", 1)) > 0 def cubeSetup(len, setupFactor, dim): res = int(setupFactor * len) gs = vec3(res, res, res) if (dim == 2): gs.z = 1 # 2D test mainDt = 0.5 s = FluidSolver(name='main', gridSize=gs, dim=dim) s.timestep = mainDt / int(setupFactor) vel = s.create(MACGrid) flags = s.create(FlagGrid) density = s.create(RealGrid)
# -*- coding: utf-8 -*- import os, math, sys import scipy.misc, numpy as np import numpy as np from os.path import basename sys.path.append("../tools") import paramhelpers as ph from manta import * file_type = r"npz" folder = '/home/roseyu/Documents/manta/saves/seq2seq/' # npz file path folder = ph.getParam("folder", folder) print("Converting ", file_type, " to ppm!") sz = vec3(64, 64, 64) # simulation resolution sz.z = 1 #2D Sl = Solver(name='sl', gridSize=sz, dim=2) Gd = Sl.create(RealGrid) for root, dirs, files in os.walk(folder): for f in sorted(files): if f.endswith(".npz") <= 0: continue filepath = os.path.join(root, f) nparray = np.copy( np.load(filepath)["arr_0"] ) # we usually use "arr_0", np copy is usually good to avoid non-standard view # check image/video n_imgs = nparray.shape[0] for i in range(n_imgs): copyArrayToGridReal(nparray[i, ], Gd) new_fname = os.path.splitext( basename(f))[0] + "_" + str(i) + ".ppm"
steps = 120 simNo = 1000 # start ID showGui = 0 basePath = '../data3d_growing/' npSeedstr = "-1" dim = 3 # Solver params res = 64 resetN = 1 saveEveryK = 2 targettimestep = 0.5 wup = 10 + np.random.randint(6) # cmd line basePath = ph.getParam("basepath", basePath) npSeedstr = ph.getParam("seed", npSeedstr) npSeed = int(npSeedstr) resetN = int(ph.getParam("reset", resetN)) dim = int(ph.getParam("dim", dim)) simMode = int(ph.getParam("mode", 1)) # 1 = double sim, 2 = wlt savenpz = int(ph.getParam("savenpz", False)) > 0 saveuni = int(ph.getParam("saveuni", True)) > 0 saveppm = int(ph.getParam("saveppm", False)) > 0 showGui = int(ph.getParam("gui", showGui)) res = int(ph.getParam("res", res)) steps = int(ph.getParam("steps", steps)) timeOffset = int(ph.getParam("warmup", wup)) # skip certain no of steps at beginning scaleFactorMin = int(ph.getParam("minUpRes", 2)) scaleFactorMax = int(ph.getParam("maxUpRes", 8))
import paramhelpers as ph from PyQt5.QtWidgets import QApplication, QLabel, QSlider from PyQt5 import QtWidgets, QtCore, QtGui import PyQt5.QtCore from PyQt5.QtCore import Qt, QPoint from PyQt5.QtGui import QPixmap, QImage, QPainter from PyQt5.QtWidgets import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtCore import * from PyQt5.QtWidgets import * import cv2 img_data_path = ph.getParam("img_data_path", "../../data/test1") width = int(ph.getParam("width", 0)) height = int(ph.getParam("height", 0)) class BtnLabel(QLabel): global my_dialog def __init__(self, parent=None): super(BtnLabel, self).__init__(parent) self.if_mouse_press = False self.segment_status = False self.dir_status = False self.pix = QPixmap() #empty painterdevice self.tempix = QPixmap() #empty temporary painterdevice
from scipy import misc import cv2 import numpy as np import math import paramhelpers as ph import matplotlib.image as image import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec from PIL import Image img_data_path=ph.getParam("img_data_path","../data/test1") def get_theta_map(): dense_theta_map=np.loadtxt(img_data_path+"/"+"dense_theta_map_py.txt",dtype=np.float32) print(dense_theta_map.shape) shape_here=dense_theta_map.shape visualize_img=np.zeros(shape=(dense_theta_map.shape[0],dense_theta_map.shape[1],3),dtype=np.float32) for i in range (shape_here[0]): for j in range (shape_here[1]): if(dense_theta_map[i,j]>-0.0001): visualize_img[i,j,0]=(np.cos(dense_theta_map[i,j])+1)*0.5 visualize_img[i,j,1]=(np.sin(dense_theta_map[i,j])+1)*0.5 visualize_img[i,j,2]=0 image.imsave(img_data_path+"/"+"dense_theta_map_visalize.png",visualize_img) get_theta_map()
# for conv_trans nets, the output tiles have to be created in the same batch size is_convolution_transpose_network = False # --------------------------------------------- # load an existing model when load_ values > -1 # when training , manually abort when it's good enough # then enter test_XXXX id and model checkpoint ID below to load loadModelTest = -1 loadModelNo = -1 testPathStartNo = 1 # command line params, explanations mostly above with variables outputOnly = int(ph.getParam("out", outputOnly)) > 0 trainingEpochs = int(ph.getParam("trainingEpochs", trainingEpochs)) loadModelTest = int(ph.getParam("loadModelTest", loadModelTest)) loadModelNo = int(ph.getParam("loadModelNo", loadModelNo)) basePath = ph.getParam("basePath", basePath) useVelocities = int(ph.getParam("useVelocities", useVelocities)) testPathStartNo = int(ph.getParam("testPathStartNo", testPathStartNo)) fromSim = int(ph.getParam("fromSim", fromSim)) toSim = int(ph.getParam("toSim", toSim)) alwaysSave = int( ph.getParam("alwaysSave", False) ) # by default, only save checkpoint when cost is lower, can be turned off here randSeed = int(ph.getParam("randSeed", randSeed)) simSizeLow = int(ph.getParam("simSizeLow", simSizeLow)) upRes = int(ph.getParam("upRes", upRes)) fileFormat = ph.getParam("fileFormat", fileFormat) # create pngs for inputs
#!usr/bin/python #get low resolution data set by gauss filtering the high resolution and interpolation the blur result to low resolution version. # maybe there are some smoothing filter and the interpolation method's combination. What is the best for the recovering(super resolution problem) #from scipy import misc import cv2 import numpy as np import math import paramhelpers as ph import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec data_path = ph.getParam("data_path", '../SWE_solver/data/data_velocity_2') index_begin = int(ph.getParam("index_begin", 0)) index_end = int(ph.getParam("index_end", 20)) frame_num_per_sim = int(ph.getParam("frame_num_per_sim", 120)) scale = float(ph.getParam("scale", 4.0)) size_sim_high = int(ph.getParam("size_sim_high", 256)) size_sim_low = int(ph.getParam("size_sim_low", 64)) interp = ph.getParam("interp", 'bicubic') sigma = scale / 2.0 / math.sqrt(math.pi) kernal_size = (int(6 * sigma + 1), int(6 * sigma + 1)) print(kernal_size) file_name = open(data_path + "/log.txt", 'a') print >> file_name, "data_path: %s" % data_path print >> file_name, "index_begin: %d" % index_begin print >> file_name, "index_end: %d" % index_end print >> file_name, "frame_num_per_sim: %d" % frame_num_per_sim print >> file_name, "scale: %f" % scale
import numpy as np import os import faulthandler faulthandler.enable() import tensorflow as tf # load manta tools sys.path.append("../tools_wscale") import tilecreator_t as tc import uniio import fluiddataloader as FDL import paramhelpers as ph from GAN import GAN, lrelu # initialize parameters / command line params outputOnly = int(ph.getParam( "out", False)) > 0 # output/generation mode, main mode switch basePath = ph.getParam("basePath", '../2ddata_gan/') randSeed = int(ph.getParam("randSeed", 1)) # seed for np and tf initialization load_model_test_1 = int( ph.getParam("load_model_test_1", -1) ) # the number of the test to load a model from. can be used in training and output mode. -1 to not load a model load_model_test_2 = int( ph.getParam("load_model_test_2", -1) ) # the number of the test to load a model from. can be used in training and output mode. -1 to not load a model load_model_test_3 = int( ph.getParam("load_model_test_3", -1) ) # the number of the test to load a model from. can be used in training and output mode. -1 to not load a model load_model_no_1 = int(ph.getParam("load_model_no_1", -1)) # nubmber of the model to load load_model_no_2 = int(ph.getParam("load_model_no_2",
# optional, add velocity as additional channels to input? useVelocities = 0 # --------------------------------------------- # load an existing model when load_ values > -1 # when training , manually abort when it's good enough # then enter test_XXXX id and model checkpoint ID below to load loadModelTest = -1 loadModelNo = -1 testPathStartNo = 1 # command line params outputOnly = int(ph.getParam( "out", outputOnly ))>0 trainingEpochs = int(ph.getParam( "trainingEpochs", trainingEpochs )) loadModelTest = int(ph.getParam( "loadModelTest", loadModelTest)) loadModelNo = int(ph.getParam( "loadModelNo", loadModelNo)) basePath = ph.getParam( "basePath", basePath ) useVelocities = int(ph.getParam( "useVelocities", useVelocities )) testPathStartNo = int(ph.getParam( "testPathStartNo", testPathStartNo )) fromSim = int(ph.getParam( "fromSim", fromSim )) # range of sim data to use toSim = int(ph.getParam( "toSim", toSim )) alwaysSave = int(ph.getParam( "alwaysSave", False )) # by default, only save when cost is lower, can be turned off here randSeed = int(ph.getParam( "randSeed", randSeed )) simSizeLow = int(ph.getParam( "simSizeLow", simSizeLow )) upRes = int(ph.getParam( "upRes", upRes )) fileFormat = ph.getParam( "fileFormat", fileFormat) # either npz or uni ph.checkUnusedParams()
sys.path.append("../tools") import paramhelpers as ph # Main params ----------------------------------------------------------------------# steps = 100 simNo = 1000 # start ID showGui = 0 basePath = '../test_data/' npSeedstr = "-1" dim = 2 # Solver params res = 64 # cmd line basePath = ph.getParam("basepath", basePath) npSeedstr = ph.getParam("seed", npSeedstr) npSeed = int(npSeedstr) dim = int(ph.getParam("dim", dim)) savenpz = int(ph.getParam("savenpz", False)) > 0 saveuni = int(ph.getParam("saveuni", False)) > 0 saveppm = int(ph.getParam("saveppm", False)) > 0 showGui = int(ph.getParam("gui", showGui)) res = int(ph.getParam("res", res)) steps = int(ph.getParam("steps", steps)) setDt = float(ph.getParam("dt", 1)) frameLen = float(ph.getParam("frameLen", 3.0)) timeOffset = int(ph.getParam("warmup", 5)) # skip certain no of frames at beginning ph.checkUnusedParams()
useVelocities = 0 # load pressure as reference data (instead of density by default) outputPressure = 0 outputDataName = '' # name of data to be regressed; by default, does nothing (density), e.g. if output data is pressure set to "pressure" bWidth = -1 # special: boundaryWidth to be cut away, in line with "bWidth" in manta scene files # previous test to load (id X for test_X dir) loadModelTest = -1 loadModelNo = -1 # specific saved model to load, searches for latest by default testPathStartNo = 1 # --------------------------------------------- # command line params, explanations mostly above with variables outputOnly = int(ph.getParam("out", outputOnly)) > 0 trainingEpochs = int(ph.getParam("trainingEpochs", trainingEpochs)) loadModelTest = int(ph.getParam("loadModelTest", loadModelTest)) loadModelNo = int(ph.getParam("loadModelNo", loadModelNo)) basePath = ph.getParam("basePath", basePath) useDensity = int(ph.getParam("useDensity", useDensity)) useVelocities = int(ph.getParam("useVelocities", useVelocities)) outputPressure = int(ph.getParam("outputPressure", outputPressure)) testPathStartNo = int(ph.getParam("testPathStartNo", testPathStartNo)) fromSim = int(ph.getParam("fromSim", fromSim)) toSim = int(ph.getParam("toSim", toSim)) alwaysSave = int( ph.getParam("alwaysSave", False) ) # by default, only save checkpoint when cost is lower, can be turned off here randSeed = int(ph.getParam("randSeed", randSeed)) simSizeLow = int(ph.getParam("simSizeLow", simSizeLow))
import paramhelpers as ph #os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' ''' show all info #1 only show all warning and error #2 only show all error #3 ''' # main parameter #------------------------------------------------------ # this is for getting training data #for example, 6-7 0-12 start_frame=int(ph.getParam("start_frame",6)) end_frame=int(ph.getParam("end_frame",7)) get_model=int(ph.getParam("get_model",0)) #0# state of the pipeline learning_rate_ori=float(ph.getParam("learning_rate_ori",0.0002))#0.00001 #0.0002 decay_lr=float(ph.getParam("decay_lr",0.05))#0.05 #main file location parameter data_path=ph.getParam("data_path",'./SWE_solver/data/') #"./SWE_solver/data/" # include the test & train dir log_path=ph.getParam("log_path",'./log/')#"./log/" # print and save the log file model_path=ph.getParam("model_path",'./model/')#"./model/" # save the model test_path=ph.getParam("test_path",'./test/')#"./test/"# save the generator's results on the test data sets which is located in the "./data/test/" directory k1=float(ph.getParam("k1",0.1))#0.1 #5.0 #weight of l1 term on generator loss k2=float(ph.getParam("k2",0.1))#0.1 #1.0 #weight of layer_loss term on generator loss k2_l1=float(ph.getParam("k2_l1",0.00001))#0.00001 #weight of l1 layer_loss term on gen loss k2_l2=float(ph.getParam("k2_l2",0.00001))#0.00001 #weight of l2 layer_loss term on gen loss k2_l3=float(ph.getParam("k2_l3",0.00001))#0.00001 #weight of l3 layer_loss term on gen loss
# Main params ----------------------------------------------------------------------# steps = 120 simNo = 1000 # start ID showGui = 1 basePath = '../data/' npSeedstr = "-1" dim = 2 # Solver params res = 64 scaleFactor = 4 resetN = 1 # cmd line basePath = ph.getParam("basepath", basePath) npSeedstr = ph.getParam("seed", npSeedstr) npSeed = int(npSeedstr) resetN = int(ph.getParam("reset", resetN)) dim = int(ph.getParam("dim", dim)) simMode = int(ph.getParam("mode", 1)) # 1 = double sim, 2 = wlt savenpz = int(ph.getParam("savenpz", False)) > 0 saveuni = int(ph.getParam("saveuni", False)) > 0 saveppm = int(ph.getParam("saveppm", False)) > 0 showGui = int(ph.getParam("gui", showGui)) res = int(ph.getParam("res", res)) scaleFactor = int(ph.getParam("fac", scaleFactor)) steps = int(ph.getParam("steps", steps)) timeOffset = int(ph.getParam("warmup", 20)) # skip certain no of steps at beginning ph.checkUnusedParams()
from scipy import misc import cv2 import numpy as np import math import paramhelpers as ph import matplotlib.image as image import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec from PIL import Image img_data_path=ph.getParam("img_data_path","../data/test1") iteration_num=ph.getParam("iteration_num",6) def get_theta_map(): sparse_theta_map=np.loadtxt(img_data_path+"/"+"sparse_theta_map_"+str(iteration_num)+".txt") dir_map_x=np.loadtxt(img_data_path+"/"+"dir_map_x.txt") dir_map_y=np.loadtxt(img_data_path+"/"+"dir_map_y.txt") whether_hair=np.loadtxt(img_data_path+"/"+"whether_hair.txt") #print(dir_map_x.shape,dir_map_x[280,367],dir_map_y[280,367]) #print(sparse_theta_map.shape,sparse_theta_map[280,367]) #print(whether_hair.shape,whether_hair[280,367]) mat_shape=dir_map_x.shape #################################### #write the sparse theta map into vtk for vector visualization f = open(img_data_path+"/sparse_theta_map_origin.vtk",'w') f.write('# vtk DataFile Version 2.0\n') f.write('point\n') f.write('ASCII\n') f.write('DATASET UNSTRUCTURED_GRID\n') f.write('POINTS '+str(mat_shape[0]*mat_shape[1])+' double\n')