Repository: OceanParcels/parcels (python)

Issue:
Adding metadata to ParticleFile
For reproducibility, it would be good to add more metadata to a `ParticleFiles` object. 

We should add at least be the version number of Parcels with which the file was generated, and probably also whether it was run in Scipy or JIT mode.

Furthermore, there should be a new method to add metadata to a `ParticleFile` object, so that users can for example store what type of diffusion constant they used

Pull request description:
Metadata in ParticleFiles
This PR adds support for easy addition of metadata in `ParticleFile` objects. The minimum metadata is the Parcels version, but other metadata can be added by the user through the `ParticleFile.add_metadata()` function.

This PR fixes #433 

Patch:
diff --git a/parcels/particlefile.py b/parcels/particlefile.py
index 2fc244ed..abc8fecf 100644
--- a/parcels/particlefile.py
+++ b/parcels/particlefile.py
@@ -4,6 +4,10 @@ import netCDF4
 from datetime import timedelta as delta
 from parcels.loggers import logger
 from os import path
+try:
+    from parcels._version import version as parcels_version
+except:
+    raise EnvironmentError('Parcels version can not be retrieved. Have you run ''python setup.py install''?')
 
 
 __all__ = ['ParticleFile']
@@ -54,6 +58,7 @@ class ParticleFile(object):
         self.dataset.feature_type = "trajectory"
         self.dataset.Conventions = "CF-1.6/CF-1.7"
         self.dataset.ncei_template_version = "NCEI_NetCDF_Trajectory_Template_v2.0"
+        self.dataset.parcels_version = parcels_version
         self.dataset.parcels_mesh = self.particleset.fieldset.gridset.grids[0].mesh
 
         # Create ID variable according to CF conventions
@@ -121,6 +126,15 @@ class ParticleFile(object):
         """Write all buffered data to disk"""
         self.dataset.sync()
 
+    def add_metadata(self, name, message):
+        """Add metadata to :class:`parcels.particleset.ParticleSet`
+        :param name: Name of the metadata variabale
+        :param message: message to be written
+        """
+        if self.dataset is None:
+            self.open_dataset()
+        setattr(self.dataset, name, message)
+
     def write(self, pset, time, sync=True, deleted_only=False):
         """Write :class:`parcels.particleset.ParticleSet` data to file
 


Test patch:
diff --git a/tests/test_particle_sets.py b/tests/test_particle_sets.py
index 1a027844..cfd1c945 100644
--- a/tests/test_particle_sets.py
+++ b/tests/test_particle_sets.py
@@ -424,6 +424,7 @@ def test_variable_written_ondelete(fieldset, mode, tmpdir, npart=3):
     pset = ParticleSet(fieldset, pclass=ptype[mode], lon=lon, lat=lat)
 
     outfile = pset.ParticleFile(name=filepath, write_ondelete=True)
+    outfile.add_metadata('runtime', runtime)
     pset.execute(move_west, runtime=runtime, dt=dt, output_file=outfile,
                  recovery={ErrorCode.ErrorOutOfBounds: DeleteP})
     ncfile = Dataset(filepath+".nc", 'r', 'NETCDF4')