Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix and simplification for netcdf output #111

Merged
merged 1 commit into from
Jan 1, 2025
Merged

Conversation

sjdaines
Copy link
Member

@sjdaines sjdaines commented Jan 1, 2025

Fix for wrong Array dimensions for variable with Space=PB.CellSpace in a scalar Domain (with no grid).

This is represented by FieldArray and in netcdf output as 2 dimensional: (cell x tmodel) size (1, nrecs) (previous code got this wrong, netcdf output dropped the cell dimension, and FieldArray reported a cell dimension but returned wrong type for the stored values)

NB: there are three ways of representing a single scalar value per record or timestep:

  1. A scalar variable Space=PB.ScalarSpace:

    • always represented by FieldArray and stored in netcdf as 1 dimensional: (tmodel), size (nrecs,)
    • always stored internally by FieldRecord (and accessed by PB.get_data) as a Vector{Float64} (ie one value per record or timestep)
  2. A CellSpace variable Space=PB.CellSpace in a scalar Domain (with no grid)

    • represented by FieldArray and stored in netcdf as 2 dimensional: (cells, tmodel), size (1, nrecs,) (the bugfix here)
    • stored internally by FieldRecord (and accessed by PB.get_data) as a Vector{Float64} (ie one value per record index or timestep)
  3. A CellSpace variable Space=PB.CellSpace in a Domain with a grid with one cell:

    • represented by FieldArray and stored in netcdf as 2 dimensional: (cells, tmodel), size (1, nrecs,)
    • stored internally by FieldRecord (and accessed by PB.get_data) as a Vector{Vector{Float64}}
      eg [[42.0], [43.0]] (ie one value per record index or timestep, each value as a Vector{Float64} of length 1)

NB: the dimensions and representation used by FieldArray.values and the netcdf file are considered well defined for analyzing output, the internal storage in FieldArray.records is an implementation detail (chosen to optimise storage of long timeseries of scalar variables):

Fix for variable with Space=PB.CellSpace in a scalar Domain (with no grid):

This is stored internally by FieldRecord as a Vector (ie one value per record index or timestep)
But is represented by FieldArray and in netcdf output as dimensions (cell x tmodel) size (1, nrecs)
(previous code got this wrong and FieldArray and netcdf output dropped the cell dimension)

There are three cases, each representing a single scalar value per record or timestep:

1) A scalar variable Space=PB.ScalarSpace:
  always stored internally by FieldRecord (and accessed by PB.get_data) as a Vector{Float64} (ie one value per record or timestep)
  always represented by FieldArray and stored in netcdf as dimensions (tmodel), size (nrecs,)

2) A CellSpace variable Space=PB.CellSpace in a scalar Domain (with no grid) (the bugfix here):
  stored internally by FieldRecord (and accessed by PB.get_data) as a Vector{Float64} (ie one value per record index or timestep)
  represented by FieldArray and stored in netcdf as dimensions (cells, tmodel), size (1, nrecs,)

3) A CellSpace variable Space=PB.CellSpace in a Domain with a grid with one cell:
  stored internally by FieldRecord (and accessed by PB.get_data) as a Vector{Vector{Float64}}
  eg [[42.0], [43.0]]  (ie one value per record index or timestep, as a Vector{Float64} of length 1)
  represented by FieldArray and stored in netcdf as dimensions (cells, tmodel), size (1, nrecs,)
@sjdaines sjdaines merged commit f5824fc into main Jan 1, 2025
@sjdaines sjdaines deleted the dims_coords_fixes branch January 1, 2025 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant