YAXArrays.jl icon indicating copy to clipboard operation
YAXArrays.jl copied to clipboard

[Draft] Add CF conventions in YAXArray to use in plots

Open danlooo opened this issue 7 months ago • 9 comments

This PR aims to utilize CF conventions to generate name and label of a YAXArray. Enables to use CF meta data in heatmap plots, see https://github.com/rafaqz/DimensionalData.jl/pull/989. Implements same behavior as of python xarray. Like named DimArrays, this will also add the name to Base.show, if the CF metadata if present: Closing #393 would improve the axis labels.

╭───────────────────────────────────────────────────╮
│ 4×5 YAXArray{Int64,2} global mean air temperature │
├───────────────────────────────────────────────────┴────────────── dims ┐
  ↓ X     Sampled{Float64} 1.0:1.0:4.0 ForwardOrdered Regular Points,
  → YVals Sampled{Int64} [1, 2, 3, 4, 5] ForwardOrdered Irregular Points
├────────────────────────────────────────────────────────────── metadata ┤
  Dict{String, String} with 3 entries:
  "units"         => "K"
  "long_name"     => "global mean air temperature"
  "standard_name" => "air_temperature"
├────────────────────────────────────────────────────── loaded in memory ┤
  data size: 160.0 bytes
└────────────────────────────────────────────────────────────────────────┘
plot(a_cfa)

image

See testset "YAXArrays with CF conventions" for further details.

danlooo avatar Apr 30 '25 09:04 danlooo

Codecov Report

Attention: Patch coverage is 54.83871% with 28 lines in your changes missing coverage. Please review.

Project coverage is 73.81%. Comparing base (1069fa1) to head (dab169e).

Files with missing lines Patch % Lines
src/Cubes/Cubes.jl 54.83% 28 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #501      +/-   ##
==========================================
+ Coverage   73.67%   73.81%   +0.14%     
==========================================
  Files          12       12              
  Lines        1865     1875      +10     
==========================================
+ Hits         1374     1384      +10     
  Misses        491      491              
Files with missing lines Coverage Δ
src/Cubes/Cubes.jl 52.76% <54.83%> (+2.09%) :arrow_up:
:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Apr 30 '25 09:04 codecov[bot]

BUG in scatter plot but not inb lines plot: No method matching project_position(,..., DiskArrays.BlockedIndices) required for Makie.plot in unidata example.nc.

danlooo avatar Apr 30 '25 12:04 danlooo

From the docs failures it seems as if this broke somehow the AlgebraOfGraphics functionality. Apart from that it looks good to me.

felixcremer avatar Apr 30 '25 13:04 felixcremer

AlgebraOfGraphics creates a DimStack using the name for its type. I changed the name function to always return a Symbol.

danlooo avatar Apr 30 '25 15:04 danlooo

  • error in 1D lines plot: Makie.number_to_date(::Type{DateTime360Day}, i) not implemented
  • error in 1D scatter plot: no method matching _indices_sub(::DiskArrays.BlockedIndices{DiskArrays.GridChunks{1, Tuple{DiskArrays.RegularChunks}}}

danlooo avatar Apr 30 '25 16:04 danlooo

AoG errors might be unrelated to this PR, probably more an internal AoG change, I will take a look later.

lazarusA avatar May 01 '25 17:05 lazarusA

DimensionalData v0.29.16 + is required to show colorbar label. However, YAXArrays allows below as DD 0.27.

danlooo avatar May 05 '25 12:05 danlooo

mmm .. 0.29 flavours are allow.

DimensionalData = "0.27, 0.28, 0.29"

lazarusA avatar May 05 '25 12:05 lazarusA

Whats is the status for this PR. Is is ready for a final review or still in draft stage?

meggart avatar Oct 22 '25 07:10 meggart