Skip to content
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

Add assembled_lat_bounds, assembled_lon_bounds and time variables #1091

Merged
merged 16 commits into from Mar 25, 2020
Merged
20 changes: 20 additions & 0 deletions satpy/etc/readers/tropomi_l2.yaml
Expand Up @@ -24,3 +24,23 @@ datasets:
file_key: 'PRODUCT/longitude'
coordinates: [longitude, latitude]
standard_name: longitude
latitude_bounds:
name: 'latitude_bounds'
file_type: tropomi_l2
file_key: 'PRODUCT/SUPPORT_DATA/GEOLOCATIONS/latitude_bounds'
standard_name: latitude bounds
zxdawn marked this conversation as resolved.
Show resolved Hide resolved
longitude_bounds:
name: 'longitude_bounds'
file_type: tropomi_l2
file_key: 'PRODUCT/SUPPORT_DATA/GEOLOCATIONS/longitude_bounds'
standard_name: longitude bounds
assembled_lat_bounds:
name: 'assembled_lat_bounds'
file_type: tropomi_l2
file_key: 'PRODUCT/SUPPORT_DATA/GEOLOCATIONS/latitude_bounds'
standard_name: assembled latitude bounds
assembled_lon_bounds:
name: 'assembled_lon_bounds'
file_type: tropomi_l2
file_key: 'PRODUCT/SUPPORT_DATA/GEOLOCATIONS/longitude_bounds'
standard_name: assembled longitude bounds
35 changes: 33 additions & 2 deletions satpy/readers/tropomi_l2.py
Expand Up @@ -32,6 +32,7 @@
from satpy.readers.netcdf_utils import NetCDF4FileHandler, netCDF4
import logging
import numpy as np
import xarray as xr

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -89,9 +90,13 @@ def available_datasets(self, configured_datasets=None):
matches = self.file_type_matches(ds_info['file_type'])
# we can confidently say that we can provide this dataset and can
# provide more info
if matches and var_name in self:
assembled = var_name in ['assembled_lat_bounds', 'assembled_lon_bounds']
zxdawn marked this conversation as resolved.
Show resolved Hide resolved
if (matches and var_name in self) or (assembled):
logger.debug("Handling previously configured variable: %s", var_name)
handled_variables.add(var_name)
if not assembled:
# Because assembled variables and bounds use the same file_key,
# we need to omit file_key once.
handled_variables.add(var_name)
new_info = ds_info.copy() # don't mess up the above yielded
yield True, new_info
elif is_avail is None:
Expand Down Expand Up @@ -158,6 +163,30 @@ def _rename_dims(self, data_arr):
dims_dict['scanline'] = 'y'
return data_arr.rename(dims_dict)

def prepare_geo(self, bounds_data):
# lat/lon bounds are ordered in the following way:
zxdawn marked this conversation as resolved.
Show resolved Hide resolved
# 3----2
# | |
# 0----1
# Extend longitudes and latitudes with one element to support "pcolormesh"
dest_shape = (bounds_data.shape[0]+1, bounds_data.shape[1]+1)
dest = np.zeros(dest_shape, dtype=np.float64)
zxdawn marked this conversation as resolved.
Show resolved Hide resolved
# Fill most elements with the left-bottom lat/lon coordinates
dest[0:-1, 0:-1] = bounds_data[:, :, 0]
# Fill the rightmost column with the right-bottom lat/lon coordinates
dest[0:-1, -1] = bounds_data[:, -1, 1]
# Fill the rightmost top element with right-top lat/lon coordinates
dest[-1, -1] = bounds_data[-1, -1, 2]
# Fill the top row with left-top lat/lon coordinates
dest[-1, 0:-1] = bounds_data[-1, :, 3]
# Convert to DataArray
dest = xr.DataArray(dest,
zxdawn marked this conversation as resolved.
Show resolved Hide resolved
dims=('y', 'x')
)
# Copy attrs
dest.attrs = bounds_data.attrs
return dest

def get_dataset(self, ds_id, ds_info):
"""Get dataset."""
logger.debug("Getting data for: %s", ds_id.name)
Expand All @@ -168,4 +197,6 @@ def get_dataset(self, ds_id, ds_info):
data = data.squeeze()
data = data.where(data != fill)
data = self._rename_dims(data)
if ds_id.name in ['assembled_lat_bounds', 'assembled_lon_bounds']:
data = self.prepare_geo(data)
return data