diff --git a/.github/workflows/build_latest.yml b/.github/workflows/build_latest.yml index 3ddd0517d..079774710 100644 --- a/.github/workflows/build_latest.yml +++ b/.github/workflows/build_latest.yml @@ -17,6 +17,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + submodules: true - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 diff --git a/.github/workflows/build_master.yml b/.github/workflows/build_master.yml index c0fd2a020..97dea032d 100644 --- a/.github/workflows/build_master.yml +++ b/.github/workflows/build_master.yml @@ -14,6 +14,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + submodules: true - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 diff --git a/.github/workflows/build_old.yml b/.github/workflows/build_old.yml index fb3272f55..eeaa61c3b 100644 --- a/.github/workflows/build_old.yml +++ b/.github/workflows/build_old.yml @@ -17,6 +17,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + submodules: true - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 diff --git a/.github/workflows/miniconda.yml b/.github/workflows/miniconda.yml index ca4309c33..33f079898 100644 --- a/.github/workflows/miniconda.yml +++ b/.github/workflows/miniconda.yml @@ -22,6 +22,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + submodules: true - name: Setup Micromamba uses: mamba-org/setup-micromamba@v1 @@ -53,6 +55,8 @@ jobs: platform: [x64] steps: - uses: actions/checkout@v4 + with: + submodules: true - name: Setup Micromamba uses: mamba-org/setup-micromamba@v1 diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..7b0ff7c97 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "external/nc_complex"] + path = external/nc_complex + url = git@github.com:PlasmaFAIR/nc-complex.git diff --git a/Changelog b/Changelog index e5c5362c8..3a0168ecf 100644 --- a/Changelog +++ b/Changelog @@ -1,7 +1,8 @@ version 1.7.0 (not yet released) =============================== + * add support for complex numbers via `auto_complex` keyword to `Dataset` (PR #1295) * fix for deprecated Cython `DEF` and `IF` statements using compatibility header - with shims for unavailable functionality + with shims for unavailable functionality (PR #1277) version 1.6.5 (tag v1.6.5rel) =============================== diff --git a/docs/index.html b/docs/index.html index 7ed8055d2..6971ceb5b 100644 --- a/docs/index.html +++ b/docs/index.html @@ -3,7 +3,7 @@
- +git submodule update --init
to
+ensure all the submodules are also checked out.All of the code in this tutorial is available in examples/tutorial.py
, except
+the parallel IO example, which is in examples/mpi_example.py
.
+Unit tests are in the test
directory.
To create a netCDF file from python, you simply call the Dataset
constructor. This is also the method used to open an existing netCDF
@@ -671,9 +675,9 @@
Dataset.createCompoundType()
method of a Dataset
or Group
instance.
-Since there is no native complex data type in netcdf, compound types are handy
-for storing numpy complex arrays.
-Here's an example:
+Since there is no native complex data type in netcdf (but see
+Support for complex numbers), compound
+types are handy for storing numpy complex arrays. Here's an example:
>>> f = Dataset("complex.nc","w")
>>> size = 3 # length of 1-d complex array
>>> # create sample complex data.
@@ -1096,9 +1100,43 @@ In-memory (diskless) Datasets
[0 1 2 3 4]
>>> nc.close()
-All of the code in this tutorial is available in examples/tutorial.py
, except
-the parallel IO example, which is in examples/mpi_example.py
.
-Unit tests are in the test
directory.
Although there is no native support for complex numbers in netCDF, there are
+some common conventions for storing them. Two of the most common are to either
+use a compound datatype for the real and imaginary components, or a separate
+dimension. netCDF4
supports reading several of these conventions, as well as
+writing using one of two conventions (depending on file format). This support
+for complex numbers is enabled by setting auto_complex=True
when opening a
+Dataset
:
>>> complex_array = np.array([0 + 0j, 1 + 0j, 0 + 1j, 1 + 1j, 0.25 + 0.75j])
+>>> with netCDF4.Dataset("complex.nc", "w", auto_complex=True) as nc:
+... nc.createDimension("x", size=len(complex_array))
+... var = nc.createVariable("data", "c16", ("x",))
+... var[:] = complex_array
+... print(var)
+<class 'netCDF4._netCDF4.Variable'>
+compound data(x)
+compound data type: complex128
+unlimited dimensions:
+current shape = (5,)
+
+When reading files using auto_complex=True
, netCDF4
will interpret variables
+stored using the following conventions as complex numbers:
float
or double
members who names begin with
+r
and i
(case insensitive)complex
or ri
When writing files using auto_complex=True
, netCDF4
will use:
_PFNC_DOUBLE_COMPLEX_TYPE
(or *FLOAT*
as
+appropriate) with members r
and i
for netCDF4 formats;_pfnc_complex
for netCDF3 or classic
+formats.Support for complex numbers is handled via the
+nc-complex
library. See there for
+further details.
contact: Jeffrey Whitaker jeffrey.s.whitaker@noaa.gov
copyright: 2008 by Jeffrey Whitaker.
license: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
@@ -1553,7 +1591,8 @@parallel=False
.
info
: MPI_Info object for parallel access. Default None
, which
means MPI_INFO_NULL will be used.
-Ignored if parallel=False
.
parallel=False
.
+auto_complex
: if True
, then automatically convert complex number types
var auto_complex
Return an attribute of instance, which is of type owner.
var cmptypes
Return an attribute of instance, which is of type owner.
Return an attribute of instance, which is of type owner.
var auto_complex
Return an attribute of instance, which is of type owner.
var chartostring
Return an attribute of instance, which is of type owner.
CompoundT
Dataset
+auto_complex
close
cmptypes
createCompoundType
@@ -3156,6 +3205,7 @@ Variable
always_mask
assignValue
+auto_complex
chartostring
chunking
datatype
@@ -3198,7 +3248,7 @@ Variable