NCPP / ocgis

OpenClimateGIS is a set of geoprocessing and calculation tools for CF-compliant climate datasets.
Other
70 stars 19 forks source link

netCDF4-python renamed/moved time packages #485

Closed bekozi closed 5 years ago

bekozi commented 6 years ago

netcdftime is lost in the ether somewhere around the v1.4.0 release. It is apparently a separate package now that itself may be renamed to cftime.

Until a patch release, a version requirement will be needed for the conda installations.

jhamman commented 6 years ago

If you were previously importing netcdftime, you should just be able to work around this with:

try:
    import cftime as netcdftime
except ImportError:
    import netcdftime
    warnings.warn('netcdftime has been ported to cftime, now would be a good time to update...')
bekozi commented 6 years ago

Thanks @jhamman. We had to pin the nc4 version limitation to our conda packages to keep things working...

bekozi commented 6 years ago

Update to cftime went smoothly. Biggest issue was a test that hit an edge case in leap day calendars that is now handled correctly by the new time library.

The auto masking behavior in netcdf4-python was also updated (probably a good thing). This affects many situations where mask used to be None and is now allocated with False. Mask creation might have to work more closely with the driver...

Also noticed CF unit libraries do not work with v1.4.0 of netcdf4-python yet.

aaschwanden commented 5 years ago

Hi,

after a fresh install of ocgis, I am unable to import ocgis anymore:

    import ocgis
  File "/Users/andy/Library/Python/3.6/lib/python/site-packages/ocgis-2.1.0-py3.6.egg/ocgis/__init__.py", line 7, in <module>
    from .vmachine.core import vm, OcgVM
  File "/Users/andy/Library/Python/3.6/lib/python/site-packages/ocgis-2.1.0-py3.6.egg/ocgis/vmachine/core.py", line 5, in <module>
    from ocgis.base import AbstractOcgisObject
  File "/Users/andy/Library/Python/3.6/lib/python/site-packages/ocgis-2.1.0-py3.6.egg/ocgis/base.py", line 10, in <module>
    from ocgis.util.helpers import get_iter
  File "/Users/andy/Library/Python/3.6/lib/python/site-packages/ocgis-2.1.0-py3.6.egg/ocgis/util/helpers.py", line 15, in <module>
    from netCDF4 import netcdftime

I have netCDF4, netcdftime, and cftime installed. So far the only solution I found was to patch the ocgis source code by hand before installing the module, replacing all calls

from netCDF4 import netcdftime

with

import netcdftime

Would it be possible to insert "try...except..." statements in the code wherever ocgis imports netcdftime?

bekozi commented 5 years ago

Hi @aaschwanden. I have a branch that fixes this, and I'll try to push soon. The netCDF4 1.4.0 version made some changes that were backwards incompatible then backed out. Version 1.4.2 seems to be fixed and stable.

I know it's not convenient, but netCDF4 version 1.3.1 works in the meantime (should work with a fresh install using conda-forge). Sorry for the trouble!

bekozi commented 5 years ago

@aaschwanden I pushed a branch (https://github.com/NCPP/ocgis/tree/i485-cftime) that supports netcdf4-python 1.4.2 with cftime. Can you test with your installation? Thanks!

aaschwanden commented 5 years ago

@bekozi : I updated netcdf4python to version 1.4.2 and installed ocgis using the i485-cftime branch. I can confirm that it now works. Thank you very much for your efforts and keep up the good work!

bekozi commented 5 years ago

Thanks @aaschwanden! There's a bit of clean-up with this branch before merging to master. I'll close this issue once it's merged. Have a good weekend.

bekozi commented 5 years ago

Merged to master.