Handle (mask & ignore) off-domain values natively in log plots
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 38/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- python
- Área
- data-visualization
Línea de trabajo
Comienza en cfplot/cfplot.py, en calculate_levels, cerca de la llamada fallida np.max(field[pts]) mostrada en el traceback, y reproduce el MRE con cfp.setvars(level_spacing="log") y cfp.con(f). Se considera terminado cuando los gráficos log y loglike gestionen automáticamente los valores cero o negativos, utilicen el comportamiento de blockfill y emitan una advertencia que explique el enmascaramiento.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
At the moment, cf-plot supports logarithmic level plotting, i.e. when the colour scale is on a log scale to visualise the underlying data in a logarithmic fashion (not to be confused with log axes for the projected flat representation via xlog or ylog, etc.). However, when there are array values which are invalid for the domain of a log operation, namely zero or negative, they cause the plot to show an opaque error of ValueError: zero-size array to reduction operation maximum which has no identity. A log plot can still be produced by masking the invalid values out and then plotting with blockfill=True to handle the masked values (see example below), but this all needs to be done manually as prep. We should allow the log call to work as-is where the invalid domain values are masked automatically and the plot is converted to a blockfill, with a warning-level log message to indicate why this has occured.
MRE of failing naive log attempt and workaround
(From a real user support case today.)
>>> a = cf.read("liap_MMR_2006bco.nc")[0]
>>> >>> f = a[0, 0]
>>> f
<CF Field: long_name=actual contrail coverage (not area weighted)(long_name=hours since 1900-01-01 00:00 UTC at the first of the month(1), long_name=pressure_level(1), long_name=latitude(73), long_name=longitude(144)) %>
>>> f.shape
(1, 1, 73, 144)
>>> cfp.con(f) # non-log plot, works
>>>
>>> # Attempt to get a log plot via the supported approach
>>> cfp.setvars(level_spacing="log")
>>> cfp.con(f)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/slb93/git-repos/cf-plot/cfplot/cfplot.py", line 3438, in con
clevs, mult, fmult = calculate_levels(
^^^^^^^^^^^^^^^^^
File "/home/slb93/git-repos/cf-plot/cfplot/cfplot.py", line 10183, in calculate_levels
close_below = np.max(field[pts])
^^^^^^^^^^^^^^^^^^
File "/home/slb93/miniconda3/envs/old-sphinx-cf-doc-build-only/lib/python3.11/site-packages/numpy/_core/fromnumeric.py", line 3164, in max
return _wrapreduction(a, np.maximum, 'max', axis, None, out,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/slb93/miniconda3/envs/old-sphinx-cf-doc-build-only/lib/python3.11/site-packages/numpy/_core/fromnumeric.py", line 86, in _wrapreduction
return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: zero-size array to reduction operation maximum which has no identity
>>> cfp.setvars(level_spacing="loglike")
>>> cfp.con(f)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/slb93/git-repos/cf-plot/cfplot/cfplot.py", line 3438, in con
clevs, mult, fmult = calculate_levels(
^^^^^^^^^^^^^^^^^
File "/home/slb93/git-repos/cf-plot/cfplot/cfplot.py", line 10183, in calculate_levels
close_below = np.max(field[pts])
^^^^^^^^^^^^^^^^^^
File "/home/slb93/miniconda3/envs/old-sphinx-cf-doc-build-only/lib/python3.11/site-packages/numpy/_core/fromnumeric.py", line 3164, in max
return _wrapreduction(a, np.maximum, 'max', axis, None, out,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/slb93/miniconda3/envs/old-sphinx-cf-doc-build-only/lib/python3.11/site-packages/numpy/_core/fromnumeric.py", line 86, in _wrapreduction
return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: zero-size array to reduction operation maximum which has no identity
>>>
>>> # Workaround by masking values out of the valid domain then plotting with blockfill=True
>>> a_with_zeros_masked = a.where(cf.isclose(0.0), cf.masked) # mask out all zero values - note you need cf.isclose() to deal with float precision differences
>>> cfp.setvars() # reset level spacing from before
>>> cfp.con(a_with_zeros_masked[0, 0], blockfill=True) # standard, non-log plot
>>> cfp.setvars(level_spacing="log")
>>> cfp.con(a_with_zeros_masked[0, 0], blockfill=True) # logarithmic scale plot, works
- Lenguaje dominante
- Python
- Estrellas
- 21
- Forks
- 11
- Merge medio
- 7 h 11 min
- PR fusionados (30 d)
- 1
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de NCAS-CMS/cf-plot
-
testing
Dificultad 3/5 1-2 días Aptitud para principiantes 58/100
-
Add `AGENTS.md` fileAbiertodocs enhancement
Dificultad 3/5 1-2 días Aptitud para principiantes 64/100
-
Add animation hooks into cf-plotQuizá libre de nuevo @bnlawrence la tomó hace 100 días y no hay ningún pull request abierto. Abiertoenhancement
-
Ugly nemo plotting issueAbiertobug v35plus
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
-
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
Todos los issues de NCAS-CMS/cf-plot
Issues similares
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
MystenLabs/MemWal#1163 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
infertopics leaves new nodes without a topic when untopiced neighbours outnumber topiced onesPosiblemente ocupada @moneebullah25 la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
FinanceFlash/unvibecode#218 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
NVIDIA/earth2studio#1241 ·
Los mantenedores suelen responder en 3 días