Skip to content

Commit

Permalink
fixing "ValueError: cannot unstack dimensions that do not have exactl…
Browse files Browse the repository at this point in the history
…y one multi-index: ('z',)" occuring in level2/wind_current_retrieval with version xarray 2022.11.0 (was working in xarray v0.16.0) on unstack on 'z'.

Explanation of the pb here:
pydata/xarray#7076 (comment)
Push in cost_function/find_minima the level1 coords to the output
  • Loading branch information
ACHMartin committed Feb 16, 2023
1 parent 379172b commit 9d3a285
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions seastar/retrieval/cost_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
from seastar.utils.tools import dotdict, da2py

# import seastar.gmfs.doppler
import pdb
# pdb.set_trace() # where we want to start to debug
# import pdb # pdb.set_trace() # where we want to start to debug


def fun_residual(variables, level1, noise, gmf):
Expand Down Expand Up @@ -136,6 +135,7 @@ def find_minima(level1_pixel, noise_pixel, gmf):

dslmout = xr.concat(lmout, dim='Ambiguities')
dslmout = optionLeastSquares2dataset(opt, dslmout)
dslmout = dslmout.assign_coords(level1_pixel.coords)

return dslmout

Expand Down
15 changes: 10 additions & 5 deletions seastar/retrieval/level2.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

import numpy as np
import xarray as xr
from seastar.retrieval import cost_function, ambiguity_removal
import seastar
import pdb # pdb.set_trace() # where we want to start to debug
from seastar.retrieval import cost_function, ambiguity_removal
# from seastar.utils.tools import da2py

# import pdb # pdb.set_trace() # where we want to start to debug

def wind_current_retrieval(level1, noise, gmf, ambiguity):
"""
Expand Down Expand Up @@ -54,21 +56,24 @@ def wind_current_retrieval(level1, noise, gmf, ambiguity):
for ii, zindex in enumerate(level1_stack.z.data):
sl1 = level1_stack.sel(z=zindex)
sn = noise_stack.sel(z=zindex)
# pdb.set_trace()
lmout = cost_function.find_minima(sl1, sn, gmf)
lmout = ambiguity_removal.solve_ambiguity(lmout, ambiguity)
lmoutmap[ii] = lmout

# pdb.set_trace()
lmmap = xr.concat(lmoutmap, dim='z')
lmmap['z'] = level1_stack.z
lmmap = lmmap.reset_index('z')
# lmmap['z'] = level1_stack.z
# lmmap = lmmap.reset_index('z')
lmmap = lmmap.set_index(z=list_L1s0)
sol = lmmap.unstack(dim='z')
else: # single pixel
lmout = cost_function.find_minima(level1, noise, gmf)
sol = ambiguity_removal.solve_ambiguity(lmout, ambiguity)

# pdb.set_trace()
level2 = xr.Dataset()
level2['x_variables'] = sol.x.isel(Ambiguities=0)
level2['x'] = sol.x.isel(Ambiguities=0)
level2['CurrentU'] = sol.x.isel(Ambiguities=0).sel(x_variables='c_u')
level2['CurrentV'] = sol.x.isel(Ambiguities=0).sel(x_variables='c_v')
level2['WindU'] = sol.x.isel(Ambiguities=0).sel(x_variables='u')
Expand Down

0 comments on commit 9d3a285

Please sign in to comment.