|
8 | 8 | from tarfile import ExFileObject |
9 | 9 | from tokenize import TokenError |
10 | 10 |
|
| 11 | +import packaging |
11 | 12 | import zarr |
12 | 13 | from matplotlib.cm import get_cmap |
13 | 14 | from matplotlib.collections import PolyCollection |
|
74 | 75 |
|
75 | 76 | logger = logging.getLogger("pet") |
76 | 77 |
|
| 78 | +# keep only major and minor version number |
| 79 | +_software_version_reduced = packaging.version.Version("{v.major}.{v.minor}".format(v=packaging.version.parse(__version__))) |
| 80 | + |
| 81 | + |
| 82 | +def _check_versions(version): |
| 83 | + """Check if version of py_eddy_tracker used to create the file is compatible with software version |
| 84 | +
|
| 85 | + if not, warn user with both versions |
| 86 | +
|
| 87 | + :param version: string version of software used to create the file. If None, version was not provided |
| 88 | + :type version: str, None |
| 89 | + """ |
| 90 | + |
| 91 | + file_version = packaging.version.parse(version) if version is not None else None |
| 92 | + if file_version is None or file_version < _software_version_reduced: |
| 93 | + logger.warning("File was created with py-eddy-tracker version '%s' but software version is '%s'", |
| 94 | + file_version, _software_version_reduced |
| 95 | + ) |
| 96 | + |
77 | 97 |
|
78 | 98 | @njit(cache=True, fastmath=True) |
79 | 99 | def shifted_ellipsoid_degrees_mask2(lon0, lat0, lon1, lat1, minor=1.5, major=1.5): |
@@ -765,6 +785,8 @@ def load_from_zarr( |
765 | 785 | if not isinstance(filename, str): |
766 | 786 | filename = filename.astype(str) |
767 | 787 | h_zarr = zarr.open(filename) |
| 788 | + |
| 789 | + _check_versions(h_zarr.attrs.get("framework_version", None)) |
768 | 790 | var_list = cls.build_var_list(list(h_zarr.keys()), remove_vars, include_vars) |
769 | 791 |
|
770 | 792 | nb_obs = getattr(h_zarr, var_list[0]).shape[0] |
@@ -908,6 +930,8 @@ def load_from_netcdf( |
908 | 930 | else: |
909 | 931 | args, kwargs = (filename,), dict() |
910 | 932 | with Dataset(*args, **kwargs) as h_nc: |
| 933 | + _check_versions(getattr(h_nc, "framework_version", None)) |
| 934 | + |
911 | 935 | var_list = cls.build_var_list( |
912 | 936 | list(h_nc.variables.keys()), remove_vars, include_vars |
913 | 937 | ) |
|
0 commit comments