Skip to content

Commit

Permalink
Merge pull request #536 from MDAnalysis/scipy-ncdf-precision
Browse files Browse the repository at this point in the history
AMBER NetCDF file writing -- enforcing float32 precision
  • Loading branch information
richardjgowers committed Nov 12, 2015
2 parents d168f86 + 4f0827f commit 3754059
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Changes
* built html doc files are no longer version controlled (Issue #491)

Fixes
* AMBER netcdf writer now correctly uses float32 precision (Issue #518)
* Fixed a numpy incompatibility in `analysis.leaflet.LeafletFinder`.
(Issue #533)
* Cleaned up `MDAnalysis.Writer` docs regarding `dt` usage. (Issue #522)
Expand Down
4 changes: 2 additions & 2 deletions package/MDAnalysis/coordinates/TRJ.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,14 +691,14 @@ def _init_netcdf(self, periodic=True):
ncfile.createDimension('label', 5) # needed for cell_angular

# Create variables.
coords = ncfile.createVariable('coordinates', 'f8', ('frame', 'atom', 'spatial'),
coords = ncfile.createVariable('coordinates', 'f4', ('frame', 'atom', 'spatial'),
zlib=self.zlib, complevel=self.cmplevel)
setattr(coords, 'units', 'angstrom')

spatial = ncfile.createVariable('spatial', 'c', ('spatial',))
spatial[:] = np.asarray(list('xyz'))

time = ncfile.createVariable('time', 'f8', ('frame',),
time = ncfile.createVariable('time', 'f4', ('frame',),
zlib=self.zlib, complevel=self.cmplevel)
setattr(time, 'units', 'picosecond')

Expand Down
10 changes: 10 additions & 0 deletions testsuite/MDAnalysisTests/coordinates/test_netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ def test_write_trajectory(self):
with self.Writer(self.outfile, t.n_atoms, dt=t.dt) as W:
self._copy_traj(W)
self._check_new_traj()
import netCDF4
#for issue #518 -- preserve float32 data in ncdf output
dataset = netCDF4.Dataset(self.outfile, 'r', format='NETCDF3')
variable_dict = dataset.variables
coords = variable_dict['coordinates']
time = variable_dict['time']
self.assertTrue('float32' in coords.__repr__(),
'ncdf coord output not float32')
self.assertTrue('float32' in time.__repr__(),
'ncdf time output not float32')

def test_OtherWriter(self):
t = self.universe.trajectory
Expand Down

0 comments on commit 3754059

Please sign in to comment.