Skip to content

Chardata docs#7194

Open
pp-mo wants to merge 18 commits into
SciTools:FEATURE_chardatafrom
pp-mo:chardata_docs
Open

Chardata docs#7194
pp-mo wants to merge 18 commits into
SciTools:FEATURE_chardatafrom
pp-mo:chardata_docs

Conversation

@pp-mo

@pp-mo pp-mo commented Jul 7, 2026

Copy link
Copy Markdown
Member

Closes #6924

In writing this, I have encountered a bit of a doubt about the implementation : #7195
But for the sake of getting this under review, I'm going to treat that as a separate issue :
I believe it can only simplify the account here.

scitools-ci[bot]

This comment was marked as outdated.

@pp-mo pp-mo changed the base branch from main to FEATURE_chardata July 7, 2026 11:15
@pp-mo pp-mo changed the base branch from FEATURE_chardata to main July 7, 2026 11:20
@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.29%. Comparing base (ebc6531) to head (93720c1).

Additional details and impacted files
@@                Coverage Diff                @@
##           FEATURE_chardata    #7194   +/-   ##
=================================================
  Coverage             90.29%   90.29%           
=================================================
  Files                    92       92           
  Lines                 25171    25171           
  Branches               4700     4700           
=================================================
  Hits                  22728    22728           
  Misses                 1673     1673           
  Partials                770      770           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pp-mo pp-mo changed the base branch from main to FEATURE_chardata July 8, 2026 10:19
@pp-mo pp-mo requested a review from pt331 July 8, 2026 14:27
@pp-mo pp-mo linked an issue Jul 8, 2026 that may be closed by this pull request
2 tasks
@pp-mo pp-mo marked this pull request as ready for review July 8, 2026 15:34
@pp-mo pp-mo dismissed scitools-ci[bot]’s stale review July 8, 2026 17:09

Changes to pre-commit actually occurred in the target branch 'FEATURE_chardata'.
Only appeared here because I temporarily changed the target to 'main' to get docs building

@pt331 pt331 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My review is all over the place since I was adding them as I was reading and rereading, but I think I understand the overall idea. Most of the comments are nitpicks or thoughts on structuring.

Comment thread docs/src/user_manual/explanation/netcdf_io.rst Outdated
Comment thread docs/src/user_manual/explanation/netcdf_io.rst Outdated
Comment thread docs/src/user_manual/explanation/netcdf_io.rst Outdated
Comment thread docs/src/user_manual/explanation/netcdf_io.rst Outdated
encoding support (described below).


In Iris

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the Iris part of this section should be the first under summary, since I imagine users are most interested in that. The other sections are more to provide context for decisions made in Iris

cubes and coordinates.

* the numpy dtype is of the type "U<xx>", where <xx> is a character width.
* the character width relates to a string *dimension* of the netCDF variable,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not following what this bullet point means.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread docs/src/user_manual/explanation/netcdf_io.rst Outdated
Comment thread docs/src/user_manual/explanation/netcdf_io.rst Outdated
Comment thread docs/src/user_manual/explanation/netcdf_io.rst Outdated


Character and String datatypes
------------------------------

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an introduction might be warranted. Something like:

In NetCDF, text can be represented in 2 ways:

  • char: the number of characters in the text is fixed
  • string: the number of characters in the text can vary

Then text can have different encodings, which affects the number of bytes used to store a character. For example:

  • ASCII and UTF-32: the number of bytes are fixed
  • UTF-8 and UTF-16: the number of bytes can vary

This section discusses how Iris handles the different cases and how the standards and interpretations have changed.

@pp-mo

pp-mo commented Jul 13, 2026

Copy link
Copy Markdown
Member Author

Hi again @pt331 !
I think I've responded to all your comments now.
The last 2 commits have mixed things up a bit, and moved parts around (partly as you suggested). And I made some significant changes there too. So, those commits don't make easy diffs, and may be worth considering separately
So, it's changed quite a lot, and probably wants re-considering as a whole now -- please feel free to add fresh suggestions.

determined by **inverting the above relations**.

The actual maximum number of characters in the data will always be less than or equal to
this, since the maximum possible character width is for all-ascii data.

@pt331 pt331 Jul 14, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you meant to say

Suggested change
this, since the maximum possible character width is for all-ascii data.
this, since the maximum possible string width is 1 byte for all-ascii data.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, not exactly..
I meant that the longest string you can get is when the bytes are full with all ascii characters.
I'll try + rephrase this more clearly...

The width created by reading will always round-trip correctly, i.e. the dimension
length is unchanged if data is read and then written back.

Summary of Iris string handling

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this summary can be removed now and once you have more concrete examples (mentioned in private), something like "Iris string handling in practice" would be a good replacement.

See in netCDF4 python documentation :
`Dealing with strings <https://unidata.github.io/netcdf4-python/#dealing-with-strings>`_.
**However,** Iris turns this feature *off*, in order to implement its own
wider-ranging encoding support (described below).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no longer described below

adopted when translating to and from bytes, and rules for determining what the encoding
is or was.

Background

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the Background can now be moved above "String data in NetCDF", "String data in the NetCDF CF Conventions" and "String data in the netCDF4 Python module" and make them subheadings

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK that's nice + a simpler way of doing it than creating a separate new page.

Comment thread docs/src/user_manual/explanation/netcdf_io.rst Outdated
Comment thread docs/src/user_manual/explanation/netcdf_io.rst Outdated
Comment thread docs/src/user_manual/explanation/netcdf_io.rst Outdated
pp-mo and others added 4 commits July 14, 2026 15:07
Co-authored-by: pt331 <144435193+pt331@users.noreply.github.com>
Co-authored-by: pt331 <144435193+pt331@users.noreply.github.com>
Co-authored-by: pt331 <144435193+pt331@users.noreply.github.com>

@pt331 pt331 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I like the idea to link to other sections for further details so that the user can shortcut to them if they feel it's more appropriate for them to know. The only changes left are broken links

Character and String datatypes
------------------------------
Text can be present in NetCDF in a variety of ways
(see : `String data in NetCDF <cf_strings>`_ for details).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link is broken. I think it should be

Suggested change
(see : `String data in NetCDF <cf_strings>`_ for details).
(see : `String data in NetCDF <cf-strings>`_ for details).

coordinate ``.points``.

These are always stored as arrays of numpy dtype "U<xx>", where <xx> is a maximum
string width (which could be either `real or lazy <real_and_lazy_data>`_).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link is broken. I think it should be

Suggested change
string width (which could be either `real or lazy <real_and_lazy_data>`_).
string width (which could be either `real or lazy <real-and-lazy_data>`_).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Complete documentation of chardata handling

2 participants