shom-fr / xoa

xarray-based ocean analysis library
https://xoa.readthedocs.io
Apache License 2.0
6 stars 4 forks source link

Can't decode sigma from my dataset #57

Closed Matt29 closed 2 years ago

Matt29 commented 2 years ago

Hi,

The bug raises when i use decode_sigma from my dataset (Mars3d model)

There may be a bug in this part of code because when searching for all my possible sigma variables in the list sigs it raises an error (XoaSigmaError) and stop at the first one because it has not the right attribute (standard name is no in the list). The behaviour should be to pass and look into the second item of my "sigs" list. (which is ok) but the error make the code stop.

As far as i understand XoaSigmaError is a class herited from XoaError which contain only a pass instruction so i dont know why it stops ?:

class XoaError(Exception):
    pass

My issue starts at : https://github.com/VACUMM/xoa/blob/058b1879b4fd2d4fe157b146755726988d9f89c4/xoa/sigma.py#L533

    for sig in sigs:

        # Check standard_name and get loc
        if "standard_name" not in sig.attrs:
            raise XoaSigmaError(
                "No standard_name attribute found in sigma/s " "variable name: " + sig.name
            )
        standard_name, loc = cfspecs.sglocator.parse_attr("standard_name", sig.standard_name)
        if standard_name not in SIGMA_COORDINATE_TYPES:
            raise XoaSigmaError(
                "Sigma/s coordinate not supported: "
                + standard_name
                + ". Supported coordinates: "
                + " ".join(SIGMA_COORDINATE_TYPES)
            )

I also paste the content of sigs to better understand :

sigma [<xarray.DataArray 'SIG' (level: 10)>
array([-0.95, -0.85, -0.75, -0.65, -0.55, -0.45, -0.35, -0.25, -0.15, -0.05],
      dtype=float32)
Coordinates:
  * level    (level) float32 -0.95 -0.85 -0.75 -0.65 ... -0.35 -0.25 -0.15 -0.05
Attributes:
    long_name:      sigma variable
    standard_name:  ocean_sigma_variable
    units:          
    valid_min:      -1.0
    valid_max:      0.0, <xarray.DataArray 'level' (level: 10)>
array([-0.95, -0.85, -0.75, -0.65, -0.55, -0.45, -0.35, -0.25, -0.15, -0.05],
      dtype=float32)
Coordinates:
  * level    (level) float32 -0.95 -0.85 -0.75 -0.65 ... -0.35 -0.25 -0.15 -0.05
Attributes:
    long_name:           sigma level
    axis:                Z
    c_grid_axis_shift:   0.0
    positive:            up
    valid_min:           -1.0
    valid_max:           0.0
    standard_name:       ocean_sigma_coordinate
    formula_terms:       sigma: level eta: XE depth: H0
    formula_definition:  z(n,k,j,i) = eta(n,j,i) + sigma(k)*(depth(j,i)+eta(n...]
stefraynaud commented 2 years ago

We should is probably to silently ignore candidates that don't have this standard_name. Can you make a PR and update CHANGES.rst accordinly by creating a new section named "Current" or "In development"?

Matt29 commented 2 years ago

by silently you mean by replacing the raise instruction by a continue ?

stefraynaud commented 2 years ago

Yes!

stefraynaud commented 2 years ago

Fixed by #60