File size: 2,672 Bytes
70159fb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
"""Dataset for the fluid cube
More on: https://inductiva.ai/blog/article/fluid-cube-dataset
"""
import json
import datasets
import numpy as np
_DESCRIPTION = 'https://inductiva.ai/blog/article/fluid-cube-dataset'
_BASE_URL = 'https://storage.googleapis.com/fluid_cube/'
class WindTunnel(datasets.GeneratorBasedBuilder):
'''The FluidCube builder'''
def __init__(self, version, **kwargs):
super().__init__(**kwargs)
self.bucket_url = _BASE_URL + f'{version}.tar.gz'
def _info(self):
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=datasets.Features({
'block_position': [datasets.Value('float32')],
'block_dimensions': [datasets.Value('float32')],
'fluid_volume':
datasets.Value('float32'),
'block_velocity': [datasets.Value('float32')],
'block_velocity_magnitude':
datasets.Value('float32'),
'kinematic_viscosity':
datasets.Value('float32'),
'density':
datasets.Value('float32'),
'tank_dimensions': [datasets.Value('float32')],
'time_max':
datasets.Value('float32'),
'time_step':
datasets.Value('float32'),
'particle_radius':
datasets.Value('float32'),
'number_of_fluid_particles':
datasets.Value('int32'),
# Float64 because pyArrow is not capable of
# [Array2D(shape, float32)].
# https://github.com/huggingface/datasets/issues/5936
'simulation_time_steps':
datasets.Sequence(
datasets.Array2D(dtype='float64', shape=(None, 6)))
}))
def _split_generators(self, dl_manager):
# Download and extract the zip file in the bucket.
downloaded_dir = dl_manager.download(self.bucket_url)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
gen_kwargs={
'json_files': dl_manager.iter_archive(downloaded_dir)
})
]
# pylint: disable=arguments-differ
def _generate_examples(self, json_files):
for id_, (_, json_file) in enumerate(json_files):
bytes_data = json_file.read()
data = json.loads(bytes_data)
data['simulation_time_steps'] = [
np.transpose(a) for a in data['simulation_time_steps']
]
yield id_, data
|