Creating a new Fieldset.from_modulefile() method
#1566
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In developing plasticparcels, we realised that for many teams it could be useful to have a way to directly and effortlessly create a
FieldSetinstance from all the files in a particular directory. This is particularly useful if many use the same data on a shared storage.This PR implements a simple method,
Fieldset.from_modulefile(filename), that returns a FieldSet instance based on a python module file atfilename. That file should include acreate_fieldset()function, which returns aFieldSetobject.An example of how this can be used is in the unit tests:
The data manager places a function to create the fieldset somewhere (e.g. in the same directory as where the data is)
https://github.com/OceanParcels/parcels/blob/7d3cf6ed10e7b89fa0f840a8079cfaed972f0dfe/tests/test_data/fieldset_nemo.py#L5-L16
Then, a user only has to issue
https://github.com/OceanParcels/parcels/blob/548d62df1eabe31793cde92227f10a770bdc2913/tests/test_fieldset.py#L203-L205
The advantage is that users don't need to think anymore which fieldset creation method to use (
from_nemo,from_netcdf, etc) and that all settings are immediately correct