-
Notifications
You must be signed in to change notification settings - Fork 303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failed to save tropomi nc file with specific variables loaded #1493
Comments
Just curious, why are you specifically loading for Could you print out the |
@djhoese Because Here's some information about
|
If you remove the
|
Same error if I add |
What if you remove the My guess, after looking at the code, is that the CF writer is looking at That said, you don't need to explicitly add the longitude and latitude variables to what you load because the CF writer will add them automatically from the SwathDefinition (I think). |
Thanks for the explanation David. This method works well: skipping the manual saving of lon/lat and getting the lon and lat by It looks reasonable to me. Shall we close this issue? |
I'd still like to know why the longitude and latitude datasets don't work. It seems like a bug in the CF writer. |
@ninahakansson @sfinkens might have ideas |
I guess this has something to do with the additional In [20]: a = xr.DataArray([[1,2], [3,4]], dims=('y', 'x'), coords={'x': [1,2], 'y': [3,4]})
In [21]: lon = a.copy()
In [22]: a['lon'] = lon
In [23]: a
Out[23]:
<xarray.DataArray (y: 2, x: 2)>
array([[1, 2],
[3, 4]])
Coordinates:
* x (x) int64 1 2
* y (y) int64 3 4
lon (y, x) int64 1 2 3 4 But with an additional time dimension it doesn't: In [24]: lon = lon.expand_dims('time')
In [25]: a['lon'] = lon
...
ValueError: cannot add coordinates with new dimensions to a DataArray |
But why are the lon/lat coordinates getting a |
Oh, sorry. I thought the lats returned by the reader had an extra time dimension. But I misread the snippet above. It's just a scalar time coordinate, no extra dimension. |
Aha, the CF writer is adding a time dimension if the dataset has a
should work around the problem for now. The |
Maybe not just scalar but any coordinates that aren't also dimensions? Right? |
@djhoese Yes, any coordinates that aren't also dimensions could lead to the error. BTW, I'm curious whether the |
The |
If I delete the However, as discussed in #1246, we don't need Is it correct to create a PR to delete the time coordinates for TROPOMI data? |
I had a quick test and found that we need to drop two things to make the
If this is OK, I will create a PR. |
Is it possible to rename things so they work better? Otherwise update CF writer to handle these? I'd prefer not to remove information from the reader unless it's redundant. Someone could be using it. |
Here're some testing steps: Try to fix by editing yaml and readerStep1: Drop time coordinatesI add these:
above satpy/satpy/readers/tropomi_l2.py Line 240 in f248972
And I got this error:
Step2: Edit coordinates in yaml fileI comment out the coordinates in yaml:
Then,
Try to Fix by
|
dataset[coord] = datas[coord] |
print(dataset[coord])
save_datasets()
works again with some warnings:
/public/home/zhangxin/new/miniconda3/envs/s5p_tobac/lib/python3.8/site-packages/satpy/writers/cf_writer.py:260: UserWarning: Coordinate "longitude" referenced by dataset cloud_fraction_crb_nitrogendioxide_window does not exist, dropping reference.
warnings.warn('Coordinate "{}" referenced by dataset {} does not exist, dropping reference.'.format(
/public/home/zhangxin/new/miniconda3/envs/s5p_tobac/lib/python3.8/site-packages/satpy/writers/cf_writer.py:260: UserWarning: Coordinate "latitude" referenced by dataset cloud_fraction_crb_nitrogendioxide_window does not exist, dropping reference.
warnings.warn('Coordinate "{}" referenced by dataset {} does not exist, dropping reference.'.format(
The NetCDF file looks like this:
netcdf test {
dimensions:
time = 1 ;
y = 389 ;
x = 450 ;
bnds_1d = 2 ;
variables:
int64 time(time) ;
time:bounds = "time_bnds" ;
time:standard_name = "time" ;
time:units = "days since 2019-07-25" ;
time:calendar = "proleptic_gregorian" ;
float cloud_fraction_crb_nitrogendioxide_window(y, x) ;
.............
float longitude(y, x, time) ;
............
float latitude(time, y, x) ;
...........
double time_bnds(time, bnds_1d) ;
Thoughts
I suppose the time dimension should be dropped, but don't know the correct way to add it to CF writer ...
In that last test with the The summary of my opinion on how to fix this is: If there is something semi-standard in the tropomi data (like a time dimension) that fails when using the CF writer, then the CF writer should be changed to handle it. |
Describe the bug
I got this error which is similar with #1031 when I tried to save the loaded scene of TROPOMI NO2 L2 data to NetCDF file.
To Reproduce
This issue happens when some specific variables like
nitrogendioxide_stratospheric_column
,surface_albedo
andsurface_pressure
etc. are included in thevnames
with thelongitude
orlatitude
together.Note that this issue doesn't exist before #1357 is merged.
Environment Info:
The text was updated successfully, but these errors were encountered: