{"id":21606,"library":"ndcube","title":"ndcube","description":"A Python package for multi-dimensional contiguous and non-contiguous coordinate aware arrays, built on sunpy and astropy. Current version 2.4.0, release cadence irregular. Works with NumPy arrays and supports powerful slicing and dicing with World Coordinate System (WCS) awareness.","status":"active","version":"2.4.0","language":"python","source_language":"en","source_url":"https://github.com/sunpy/ndcube","tags":["solar-physics","astronomy","wcs","numpy","multidimensional-arrays","coordinate-aware","sunpy"],"install":[{"cmd":"pip install ndcube","lang":"bash","label":"Latest from PyPI"},{"cmd":"pip install ndcube[all]","lang":"bash","label":"With extra dependencies for visualization"}],"dependencies":[{"reason":"NDCube is built on sunpy's WCS and coordinate framework","package":"sunpy","optional":false},{"reason":"For unit handling and WCS support","package":"astropy","optional":false},{"reason":"For plotting functionality (ndcube provides visualization wrappers)","package":"matplotlib","optional":true}],"imports":[{"note":"ndcube.ndcube is the internal module, but the public API is directly under ndcube","wrong":"from ndcube.ndcube import NDCube","symbol":"NDCube","correct":"from ndcube import NDCube"},{"note":"NDCollection is also available directly under ndcube since v2.0","wrong":"from ndcube.collection import NDCollection","symbol":"NDCollection","correct":"from ndcube import NDCollection"}],"quickstart":{"code":"import numpy as np\nfrom ndcube import NDCube, NDCollection\n\n# Create a simple 2D array\ndata = np.random.rand(10, 10)\nwcs = None  # For simplicity; in practice, provide astropy WCS\ncube = NDCube(data, wcs)\nprint(cube)\nprint(cube.shape)\n\n# Slice along first axis\nslice1 = cube[0]\nprint(slice1.shape)\n\n# Create collection of cubes\ncubes = [NDCube(np.random.rand(5,5), None) for _ in range(3)]\ncollection = NDCollection(cubes, meta={'source': 'test'})\nprint(collection)","lang":"python","description":"Minimal demo of NDCube creation and slicing."},"warnings":[{"fix":"If upgrading from v1.x, update code that assigns crop result to multiple variables.","message":"API change in v2.0: NDCube.crop returns a new NDCube, not a tuple of slices.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Replace ndcube.NDCubeSequence with ndcube.NDCollection.","message":"NDCubeSequence is deprecated since v2.1; use NDCollection instead.","severity":"deprecated","affected_versions":">=2.1.0"},{"fix":"Use boolean or integer array indexing with caution; prefer basic slicing.","message":"When slicing an NDCube, the result may drop WCS information if the slice is not a view (e.g., fancy indexing). Always check cube.wcs after slicing.","severity":"gotcha","affected_versions":"all"},{"fix":"Install via conda (conda install -c conda-forge ndcube) to avoid compilation.","message":"Installing from source may require Cython and numpy headers if not using wheels. Wheels are provided for common platforms, but on rare architectures you may need to build.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Access units via cube.wcs.world_axis_units or similar astropy properties.","cause":"ndcube v2.0 removed the 'unit' attribute in favor of astropy unit in the WCS.","error":"AttributeError: 'NDCube' object has no attribute 'unit'"},{"fix":"Use ndcube.NDCollection instead of ndcube.NDCubeSequence.","cause":"NDCubeSequence was removed in ndcube v2.1.","error":"ImportError: cannot import name 'NDCubeSequence' from 'ndcube'"},{"fix":"Ensure the data shape matches the number of WCS axes, or use cube.drop_axis() after slicing.","cause":"Data array has fewer dimensions than WCS expects (common when slicing).","error":"ValueError: The dimension of the WCS does not match the data."}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}