TNO Intern

Commit 2b2605d0 authored by Arjo Segers's avatar Arjo Segers
Browse files

Fix longitude/latitude arrays with no-data values, interpolate between surrounding locations.

parent 957a65a0
Loading
Loading
Loading
Loading
+29 −7
Original line number Diff line number Diff line
@@ -4,6 +4,9 @@
# 2025-02, Arjo Segers
#   Initial version based on "cso_viirs.py".
#
# 2025-09, Arjo Segers
#   Fix longitude/latitude arrays with no-data values, interpolate between surrounding locations.
#


########################################################################
@@ -166,12 +169,6 @@ class VIIRS_File(object):
        # store:
        self.filenames = filenames

        ## check ...
        # if not os.path.isfile(filename):
        #    logging.error("file not found : %s" % filename)
        #    raise Exception
        ## endif

        # open:
        with xarray.open_mfdataset(
            self.filenames, concat_dim="Idx_Atrack", combine="nested"
@@ -1035,6 +1032,9 @@ class CSO_VIIRS_File(cso_file.CSO_File):
        Correct locations of the odd scan lines,
        which seem to become dis-located towards the edge of the swath.

        Sometimes no-data values are found (-999), this is problematic to define the footprint bounds.
        Therfore, these are filled by interpolation.

        Arguments:

        * ``values`` : array of shape ``(ny,nx)`` with longitudes or latitudes
@@ -1050,6 +1050,28 @@ class CSO_VIIRS_File(cso_file.CSO_File):
        # shape:
        ny, nx = values.shape

        # check ...
        if numpy.any( values < -180.0 ):
            # info ..
            logging.warning(f"        replace no-data values in pixel locations ...")
            # modules;
            import scipy
            # loop over pixels:
            for i in range(nx):
                # pixels without data:
                jj, = numpy.where( values[:,i] < -180.0 )
                # any?
                if len(jj) > 0:
                    # valid values:
                    jj1, = numpy.where( values[:,i] >= -180.0 )
                    # interpolator, linear:
                    spl = scipy.interpolate.make_interp_spline( jj1, values[jj1,i], k=1 )
                    # replace:
                    values[jj,i] = spl( jj )
                #endif
            #endfor
        #endif

        # target arrays:
        xx = numpy.zeros((ny, nx))