ACHMartin / seastar_project

4 stars 0 forks source link

No output from RSC calculation #168

Closed DavidMcCann-NOC closed 1 year ago

DavidMcCann-NOC commented 1 year ago

I've gotten to the point of calculating the RSC from all of our recent doppler code changes etc and although now running free of exceptions and errors the output of the process is null.

I have had to make a number of changes to the code to get everything to work so there may be a rabbit loose further upstream, but placing a plot command on the output of doppler.py provides a null image - so either there's something amiss in the doppler.py code or the inputs to it are wrong.

ACHMartin commented 1 year ago

Could you put here the error message you got, and a minimal example on how to trigger these errors. Thank

DavidMcCann-NOC commented 1 year ago

Could you put here the error message you got, and a minimal example on how to trigger these errors. Thank

No error message at all - It just currently produces RSC images full of NaNs - I've just pushed a cleaned-up and up-to-date notebook with the output onto my branch, however to reproduce (using local OSCAR data - you'll have to link to the files on your machine, sorry):

import xarray as xr import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt import seastar as ss import seastar.oscar import seastar.retrieval for_file="D:\data\SEASTAR\SEASTARex\Data\Metasensing\OSCAR\Brest_Sample_June_28_2022\SAR_CPLX_20220517T093239_13.5G_VV_33_pres_1_fdc_auto.sar_INF_SAR_CPLX_20220517T093239_13.5G_VV_34_pres_1_fdc_auto.sar.nc" aft_file="D:\data\SEASTAR\SEASTARex\Data\Metasensing\OSCAR\Brest_Sample_June_28_2022\SAR_CPLX_20220517T093239_13.5G_VV_77_pres_1_fdc_auto.sar_INF_SAR_CPLX_20220517T093239_13.5G_VV_78_pres_1_fdc_auto.sar.nc" dsf = xr.open_dataset(for_file, mask_and_scale=True,drop_variables='GBPGridInfo') dsa = xr.open_dataset(aft_file, mask_and_scale=True,drop_variables='GBPGridInfo') mid_file="D:\data\SEASTAR\SEASTARex\Data\Metasensing\OSCAR\Brest_Sample_June_28_2022\SAR_CPLX_20220517T093239_13.5G_VV_00_pres_1_fdc_auto.sar.nc" dsm = xr.open_dataset(mid_file, mask_and_scale=True,drop_variables='GBPGridInfo')

L1 OSCAR processing

Compute Fore antenna L1 variables

dsf = ss.oscar.level1.compute_multilooking_Master_Slave(dsf, window=7) dsf = ss.oscar.level1.add_antenna_baseline(dsf, baseline=0.2) dsf = ss.oscar.level1.compute_antenna_azimuth_direction(dsf, antenna='fore') dsf = ss.oscar.level1.compute_time_lag_Master_Slave(dsf, options='from_SAR_time') dsf = ss.oscar.level1.compute_radial_surface_velocity(dsf)

Compute Aft antenna L1 variables

dsa = ss.oscar.level1.compute_multilooking_Master_Slave(dsa, window=7) dsa = ss.oscar.level1.add_antenna_baseline(dsa, baseline=0.2) dsa = ss.oscar.level1.compute_antenna_azimuth_direction(dsa, antenna='aft') dsa = ss.oscar.level1.compute_time_lag_Master_Slave(dsa, options='from_SAR_time') dsa = ss.oscar.level1.compute_radial_surface_velocity(dsa)

Build Level1 dataset

dsl1 = ss.oscar.level1.init_level1_dataset(dsf, dsa, dsm)

Initialise level2 dataset

dsl2=ss.oscar.level1.init_level2(dsf, dsa)

Generating geophysical data fields for GMF doppler computation

u10 = 10 # wind speed wind_direction = 20 # wind direction aux = ss.oscar.level1.init_auxiliary(dsl1,dsa,dsf,10,20)

L2 OSCAR processing

dsl2 = seastar.retrieval.level2.compute_radial_surface_current(dsl1, dsl2, aux, gmf='mouche12') ax3 = dsl2.RadialSurfaceCurrent.sel(Antenna='Fore').plot(figsize=(30, 6), y='GroundRange', x='CrossRange', robust=True, cmap='jet', )

DavidMcCann-NOC commented 1 year ago

(Oh wow - no idea where the giant fonts came from....!)

ACHMartin commented 1 year ago

Did you try compute_wasv to see what you get?

DavidMcCann-NOC commented 1 year ago

Yes - the line dsl2 = seastar.retrieval.level2.compute_radial_surface_current(dsl1, dsl2, aux, gmf='mouche12') Calls compute_wasv internally. The output of compute_wasv is full of NaNs so its either in there or upstream

ACHMartin commented 1 year ago

Your error might come from compute_wasv line 55: L1, aux_geo = xr.align(L1, aux_geo, join="outer")

If L1 and aux_geo don't share the same coordinates, it might be the origin of the NaNs. We need certainly to raise an error if it is the case. => new issue

DavidMcCann-NOC commented 1 year ago

Great thanks - I'll do some testing and raise a new one if so.

DavidMcCann-NOC commented 1 year ago

Your error might come from compute_wasv line 55: L1, aux_geo = xr.align(L1, aux_geo, join="outer")

At present the aux dataset has been initialised with the L1 dataset as input for coordinates etc - commenting out line 55 still results in a null output for the wasv

DavidMcCann-NOC commented 1 year ago

Found the likely bug - the conditional statement surrounding the polarization at line 69 isn't passing, so dop_c is remaining as an empty array

DavidMcCann-NOC commented 1 year ago

It might be the format Polarization is in - its currently:

dsl1.sel(Antenna='Fore').Polarization xarray.DataArray 'Polarization' array('VV', dtype='<U2') Coordinates: Antenna () <U4 'Fore' Attributes: (0)

DavidMcCann-NOC commented 1 year ago

Fixed by changing line 64: ind[pol_str] = (L1.Polarization == pol_val).values

to: ind[pol_str] = (L1.Polarization == pol_str).values