Skip to content

Commit

Permalink
fixed some bugs in floater_convert (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
rabernat committed May 15, 2017
1 parent 20700b8 commit 6dfedb2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ python:

env:
- CONDA_PACKAGES="numpy scipy pandas bcolz pytest future xarray dask scikit-image"
PIP_PACKAGES="tqdm codecov pytest-cov"
PIP_PACKAGES="tqdm codecov pytest-cov tqdm"

before_install:
- if [[ "$TRAVIS_PYTHON_VERSION" == "2.7" ]]; then
Expand Down
15 changes: 9 additions & 6 deletions floater/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,19 +245,22 @@ def floats_to_netcdf(input_dir, output_fname,
import dask.dataframe as dd
import xarray as xr
from glob import glob
from tqdm import tqdm

output_fname = _maybe_add_suffix(output_fname, '_netcdf')

float_files = glob(float_file_prefix+'.*.csv')
match_pattern = float_file_prefix + '.*.csv'
float_files = glob(os.path.join(input_dir, match_pattern))
float_digits = 10
step_code = len(float_file_prefix) + float_digits + 1
float_timesteps = sorted(list({float_file[:step_code] for float_file in float_files}))
float_timesteps = set(sorted([int(float_file[-22:-12]) for float_file in float_files]))

float_columns = ['npart', 'time', 'x', 'y', 'z', 'u', 'v', 'vort']
var_names = float_columns[2:]

for float_timestep in float_timesteps:
input_path = input_dir + float_timestep + '.*.csv'
for float_timestep in tqdm(float_timesteps):
input_path = os.path.join(input_dir,
'%s.%010d.*.csv' % (float_file_prefix, float_timestep))
df = dd.read_csv(input_path, names=float_columns, header=None)
dfc = df.compute()
dfcs = dfc.sort_values('npart')
Expand All @@ -273,8 +276,8 @@ def floats_to_netcdf(input_dir, output_fname,
var_shape = (1, len(npart))
data_vars = {var_name: (['time', 'npart'], dfcs[var_name].values.astype(np.float32).reshape(var_shape)) for var_name in var_names}
ds = xr.Dataset(data_vars, coords={'time': time, 'npart': npart})
output_path = output_dir + output_fname + '/'
output_path = os.path.join(output_dir, output_fname)
if not os.path.exists(output_path):
os.makedirs(output_path)
output_nc = output_path + output_prefix + float_timestep[-(float_digits+1):] + '.nc'
output_nc = os.path.join(output_path, '%s.%010d.nc' % (output_prefix, float_timestep))
ds.to_netcdf(output_nc)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ def readme():
license='MIT',
packages=['floater'],
scripts=['scripts/floater_convert'],
install_requires=['numpy', 'scipy', 'future', 'scikit-image'],
install_requires=['numpy', 'scipy', 'future', 'scikit-image', 'tqdm'],
zip_safe=False)

0 comments on commit 6dfedb2

Please sign in to comment.