manipulating non-missing elements in a field
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 35/100
- Tipo de issue
- Funcionalidade
- Clareza
- Razoavelmente clara
- Status de atividade
- Estagnada
- Stack de tecnologia
- numpy, python, scikit-learn
- Domínio
- data
Direção de pesquisa
Comece inspecionando o campo CF e os pontos de entrada de Data mencionados no relatório: compressed(), reshape(), get_data() e set_data(), incluindo como arrays mascarados e arrays respaldados por dask são tratados. Defina as operações de conveniência desejadas para extrair valores não ausentes e atribuir resultados; em seguida, adicione cobertura para o fluxo de trabalho 3D-to-2D e para o caso de tamanho de chunk desconhecido do dask.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
In order to use a scikit regression module, I need to
-
Extract the non-missing elements from a 3D field
fin(z,y,x) into a numpy array (z,p), where p is a 1D index over all the non-missing (y,x) locations, which are the same for every z. -
Put a 1D array of results
r(p) into the non-missing data elements of a 2D fieldfout(y,x).
I've done it as follows:
findata=fin.data.compressed().to_dask_array()
findata.compute_chunk_sizes()
findata=findata.reshape(fin.shape[0],fin[0,:].data.compressed().size)
# compute r from findata
foutdata=fout.get_data().flatten()
foutdata[~foutdata.mask]=r
fout.set_data(foutdata.reshape(fout.shape))
Are there better ways, or could you provide better ways? The following occur to me:
- It would be handy if
compressed()was a method of a CF field, to flatten it into a 1D array containing only the non-missing values. - I needed three lines to produce
findatabecause of having tocompute_chunk_sizeson the dask array. Without that step, I got errors as below. - Is there a way to avoid having to get the
Dataout of the field in order to assign to some elements of it using the mask? This was a bit clumsy.
In the Met O IDL lib, both input and output are easier:
findata=fin.data(where(fin(0).data ne fin(0).bmdi))
; compute r from findata
fout.data(where(fout.data ne fout.bmdi))=r
It would be good to have something equally convenient in cf-python. Perhaps there is?
Here's the dask problem:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/users/sws02jmg/.local/lib/python3.11/site-packages/cfdm/decorators.py", line 44, in inplace_wrapper
processed_copy = operation_method(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/users/sws02jmg/.local/lib/python3.11/site-packages/cf/data/data.py", line 10489, in reshape
dx = dx.reshape(*shape, merge_chunks=merge_chunks, limit=limit)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/software/applications/anaconda/2023.09-0/lib/python3.11/site-packages/dask/array/core.py", line 2220, in reshape
return reshape(self, shape, merge_chunks=merge_chunks, limit=limit)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/software/applications/anaconda/2023.09-0/lib/python3.11/site-packages/dask/array/reshape.py", line 222, in reshape
raise ValueError(
ValueError: Array chunk size or shape is unknown. shape: (nan,)
Possible solution with x.compute_chunk_sizes()
Thanks. Jonathan
- Linguagem predominante
- Python
- Estrelas
- 150
- Forks
- 23
- Merge médio
- 21h 29min
- PRs com merge (30d)
- 1
Preparar o ambiente
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de NCAS-CMS/cf-python
-
code tidy
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
-
Attempt at unsupported conservative 3D mesh regriddingTalvez já em andamento @sadielbartholomew assumiu há 19 dias. Abertabug?
-
Release: migrate from deprecated build commandTalvez já em andamento @sadielbartholomew assumiu há 21 dias. Abertarelease
-
Remove support for Python 3.10 (EOL)Talvez já em andamento @sadielbartholomew assumiu há 21 dias. Abertaenhancement
-
bug
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 45/100
Todas as issues de NCAS-CMS/cf-python
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
PedestrianDynamics/pyFDS-Evac#343 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
theskumar/python-dotenv#708 ·
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 88/100
Mantenedores costumam responder em até 2 dias
-
Docs Timedelta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
pandas-dev/pandas#69919 ·
Mantenedores costumam responder em até 1 dia
-
API documentation
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
zephyrproject-rtos/west#1009 · 2 comentários ·
Mantenedores costumam responder em até 3 dias