{"id":23400,"library":"cdflib","title":"cdflib","description":"A Python library for reading and writing NASA Common Data Format (CDF) files. Current version 1.3.10, released 2025-05. Maintained by LASP, supports Python >=3.9. Includes integration with xarray and handles ISTP compliance checks.","status":"active","version":"1.3.10","language":"python","source_language":"en","source_url":"https://github.com/lasp/cdflib","tags":["CDF","NASA","space physics","data format","ISTP","xarray"],"install":[{"cmd":"pip install cdflib","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"core dependency for array operations and CDF data type conversion","package":"numpy","optional":false},{"reason":"optional, used for time conversions and FITS compatibility","package":"astropy","optional":true},{"reason":"optional, used for xarray integration (cdf_to_xarray, xarray_to_cdf)","package":"xarray","optional":true}],"imports":[{"note":"CDF is a top-level class in cdflib, not a submodule.","wrong":"from cdflib.cdf import CDF","symbol":"CDF","correct":"from cdflib import CDF"},{"note":"cdf_to_xarray is a top-level function, not nested in an xarray submodule.","wrong":"from cdflib.xarray import cdf_to_xarray","symbol":"cdf_to_xarray","correct":"from cdflib import cdf_to_xarray"},{"note":"Same as cdf_to_xarray; both are top-level functions.","wrong":"from cdflib.xarray import xarray_to_cdf","symbol":"xarray_to_cdf","correct":"from cdflib import xarray_to_cdf"}],"quickstart":{"code":"from cdflib import CDF\n\ncdf_file = CDF('example.cdf')\ninfo = cdf_file.globalattsget()\nprint(info)\nvars = cdf_file.cdf_info()\nprint(vars)\ndata = cdf_file.varget('variable_name')\nprint(data.shape)\ncdf_file.close()","lang":"python","description":"Open a CDF file, read global attributes, list variables, and read data for a variable."},"warnings":[{"fix":"Replace `from cdflib.util import from_unixtime` with `CDFtime(utc).tt2000` or use astropy.","message":"In version 1.3.3, the deprecated functions `from_unixtime`, `from_datetime`, `unixtime_to_cdftt2000`, `datetime_to_cdftt2000`, and `datetime64_to_cdftt2000` were fully removed. Use `CDFtime` class or `astropy.time.Time` conversion instead.","severity":"breaking","affected_versions":">=1.3.3"},{"fix":"After calling `cdf_to_xarray`, do `ds = ds.assign_coords(delta_var=ds['delta_var'])` if needed.","message":"When using `cdf_to_xarray`, `DELTA_VAR` variables are no longer promoted to coordinates (since 1.3.5). If you rely on them as coordinates, you must manually add them via xarray.","severity":"gotcha","affected_versions":">=1.3.5"},{"fix":"Use a new CDF instance per thread (or use read locks).","message":"The CDF class is not thread-safe. Do not share a CDF object across threads; open separate instances per thread.","severity":"gotcha","affected_versions":"all"},{"fix":"Always use 0-based indices: `cdf.varget('var', start=[0], count=[10])`.","message":"As of version 1.3.10, `CDF.varget()` with `start` and `count` parameters uses 0-based indexing. Some users mistakenly use 1-based indexing from IDL/old CDF standards.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use `from cdflib import CDF` instead.","cause":"Incorrect import path; CDF is a class in the top-level cdflib package, not a submodule.","error":"ModuleNotFoundError: No module named 'cdflib.cdf'"},{"fix":"Install xarray (`pip install xarray`) and import using `from cdflib import cdf_to_xarray`.","cause":"Attempting to import cdf_to_xarray from a wrong location or missing install (e.g., without xarray dependency).","error":"AttributeError: module 'cdflib' has no attribute 'cdf_to_xarray'"},{"fix":"Cast to int: `start=int(start_val)` or use `varget('var', start=[int(s) for s in start])`.","cause":"Passing a numpy float as start/count index to varget(). varget() expects Python ints.","error":"TypeError: 'numpy.float64' object cannot be interpreted as an integer"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}