Skip to content

Commit

Permalink
Multiple modifications (irregular time steps, etc)
Browse files Browse the repository at this point in the history
  • Loading branch information
denislg committed May 26, 2020
1 parent 956150c commit 97e49df
Show file tree
Hide file tree
Showing 28 changed files with 2,459 additions and 2,234 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.idea/
venv/
*.png
data*
.idea/
venv/
*.png
data*
42 changes: 21 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
MIT License

Copyright (c) 2019 João Lucas de Sousa Almeida

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
MIT License
Copyright (c) 2019 João Lucas de Sousa Almeida
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# MLExp
Basic Python 3 codes aiming at being auxiliary tools for the class IM458 at Unicamp
# MLExp
Basic Python 3 codes aiming at being auxiliary tools for the class IM458 at Unicamp
180 changes: 90 additions & 90 deletions auxiliary/script_pitzDaily.py
Original file line number Diff line number Diff line change
@@ -1,90 +1,90 @@
import numpy as np
import os
from argparse import ArgumentParser
import vtk
from vtk.util.numpy_support import vtk_to_numpy
import tables

# Script for reading multiple VTK files and write a HDF5 file.
def name_index(input_string):

strings = input_string.split("_")
index = strings[-1]
index = int(index)

return index

parser = ArgumentParser(description='Argument parsers')
parser.add_argument('--path', type=str)

args = parser.parse_args()

path = args.path

items = [path + ii for ii in os.listdir(path)]
data_directories = list(filter(os.path.isdir, items))

data_directories = sorted(data_directories, key=name_index)

variables = {3: 'k', 4: 'nut', 5: 'p', 8: 'rho', 1: 'T', 9: 'U'}
n_variables = len(variables.keys()) + 2

variables_dict = {var:list() for var in variables.values()}

number_of_snapshots = len(data_directories)

# Reading the information about the number of cells
directory = data_directories[1]
vtu_file = directory + "\\"+"internal.vtu"
print("File {} read".format(vtu_file))

reader = vtk.vtkXMLUnstructuredGridReader()
reader.SetFileName(vtu_file)
reader.Update()
data = reader.GetOutput()
n_cells = data.GetNumberOfCells()

n_cells = data.GetNumberOfCells()
cells_dict = dict()

for cell_id in range(n_cells):

cell = data.GetCell(cell_id)
points = vtk_to_numpy(cell.GetPoints().GetData())
cells_dict[cell_id] = points.mean(0)
print("Cell {} read".format(cell_id))

hdf5_path = path + 'PitzDaily.hdf5'

# Creating the HDF5 file
h5f = tables.open_file(hdf5_path, mode='w')
#atom = tables.Atom.from_dtype(np.float64)
ds = h5f.create_array(h5f.root, 'AllData', np.empty((number_of_snapshots, n_cells, n_variables)))

for ss, directory in enumerate(data_directories[1:]):

vtu_file = directory + "\\"+"internal.vtu"
print("File {} read".format(vtu_file))

reader = vtk.vtkXMLUnstructuredGridReader()
reader.SetFileName(vtu_file)
reader.Update()
data = reader.GetOutput()

print("File {} readed".format(vtu_file))

variables_list = list()

for ii, name in variables.items():

array = vtk_to_numpy(data.GetCellData().GetArray(ii))
if len(array.shape) ==1: array = array[:,None]
variables_list.append(array)
print("Variable {} readed".format(name))

variables_array = np.hstack(variables_list)
ds[ss, :, :] = variables_array

h5f.close()

print("Input arguments read")
import numpy as np
import os
from argparse import ArgumentParser
import vtk
from vtk.util.numpy_support import vtk_to_numpy
import tables

# Script for reading multiple VTK files and write a HDF5 file.
def name_index(input_string):

strings = input_string.split("_")
index = strings[-1]
index = int(index)

return index

parser = ArgumentParser(description='Argument parsers')
parser.add_argument('--path', type=str)

args = parser.parse_args()

path = args.path

items = [path + ii for ii in os.listdir(path)]
data_directories = list(filter(os.path.isdir, items))

data_directories = sorted(data_directories, key=name_index)

variables = {3: 'k', 4: 'nut', 5: 'p', 8: 'rho', 1: 'T', 9: 'U'}
n_variables = len(variables.keys()) + 2

variables_dict = {var:list() for var in variables.values()}

number_of_snapshots = len(data_directories)

# Reading the information about the number of cells
directory = data_directories[1]
vtu_file = directory + "\\"+"internal.vtu"
print("File {} read".format(vtu_file))

reader = vtk.vtkXMLUnstructuredGridReader()
reader.SetFileName(vtu_file)
reader.Update()
data = reader.GetOutput()
n_cells = data.GetNumberOfCells()

n_cells = data.GetNumberOfCells()
cells_dict = dict()

for cell_id in range(n_cells):

cell = data.GetCell(cell_id)
points = vtk_to_numpy(cell.GetPoints().GetData())
cells_dict[cell_id] = points.mean(0)
print("Cell {} read".format(cell_id))

hdf5_path = path + 'PitzDaily.hdf5'

# Creating the HDF5 file
h5f = tables.open_file(hdf5_path, mode='w')
#atom = tables.Atom.from_dtype(np.float64)
ds = h5f.create_array(h5f.root, 'AllData', np.empty((number_of_snapshots, n_cells, n_variables)))

for ss, directory in enumerate(data_directories[1:]):

vtu_file = directory + "\\"+"internal.vtu"
print("File {} read".format(vtu_file))

reader = vtk.vtkXMLUnstructuredGridReader()
reader.SetFileName(vtu_file)
reader.Update()
data = reader.GetOutput()

print("File {} readed".format(vtu_file))

variables_list = list()

for ii, name in variables.items():

array = vtk_to_numpy(data.GetCellData().GetArray(ii))
if len(array.shape) ==1: array = array[:,None]
variables_list.append(array)
print("Variable {} readed".format(name))

variables_array = np.hstack(variables_list)
ds[ss, :, :] = variables_array

h5f.close()

print("Input arguments read")
Loading

0 comments on commit 97e49df

Please sign in to comment.