Example #1
0
    def get_lonlats(self):
        """Obtain GCPs and construct latitude and longitude arrays.

        Args:
           band (gdal band): Measurement band which comes with GCP's
           array_shape (tuple) : The size of the data array
        Returns:
           coordinates (tuple): A tuple with longitude and latitude arrays
        """
        band = self.filehandle

        band_x_size = band.RasterXSize
        band_y_size = band.RasterYSize

        (xpoints, ypoints), (gcp_lons, gcp_lats) = self.get_gcps()
        fine_cols = np.arange(band_x_size)
        fine_rows = np.arange(band_y_size)

        satint = GeoInterpolator((gcp_lons, gcp_lats), (ypoints, xpoints),
                                 (fine_rows, fine_cols), 2, 2)

        longitudes, latitudes = satint.interpolate()

        # FIXME: check if the array is C-contigious, and make it such if it
        # isn't
        if longitudes.flags['CONTIGUOUS'] is False:
            longitudes = np.ascontiguousarray(longitudes)
        if latitudes.flags['CONTIGUOUS'] is False:
            latitudes = np.ascontiguousarray(latitudes)

        return longitudes, latitudes
Example #2
0
def modis1kmto250m(lons1km, lats1km, cores=1):
    """Getting 250m geolocation for modis from 1km tiepoints.

    http://www.icare.univ-lille1.fr/tutorials/MODIS_geolocation
    """
    if cores > 1:
        return _multi(modis1kmto250m, lons1km, lats1km, 10, cores)

    cols1km = np.arange(1354)
    cols250m = np.arange(1354 * 4) / 4.0

    along_track_order = 1
    cross_track_order = 3

    lines = lons1km.shape[0]
    rows1km = np.arange(lines)
    rows250m = (np.arange(lines * 4) - 1.5) / 4.0

    satint = SatelliteInterpolator((lons1km, lats1km),
                                   (rows1km, cols1km),
                                   (rows250m, cols250m),
                                   along_track_order,
                                   cross_track_order,
                                   chunk_size=40)
    satint.fill_borders("y", "x")
    lons250m, lats250m = satint.interpolate()

    return lons250m, lats250m
Example #3
0
def modis1kmto250m(lons1km, lats1km, cores=1):
    """Getting 250m geolocation for modis from 1km tiepoints.
    """
    if cores > 1:
        return _multi(modis1kmto250m, lons1km, lats1km, 10, cores)
    
    cols1km = np.arange(0, 5416, 4)
    cols250m = np.arange(5416)

    along_track_order = 1
    cross_track_order = 3
    
    lines = lons1km.shape[0] * 4
    rows1km = np.arange(1.5, lines, 4)
    rows250m = np.arange(lines)

    satint = SatelliteInterpolator((lons1km, lats1km),
                                   (rows1km, cols1km),
                                   (rows250m, cols250m),
                                   along_track_order,
                                   cross_track_order,
                                   chunk_size=40)
    satint.fill_borders("y", "x")
    lons250m, lats250m = satint.interpolate()

    return lons250m, lats250m
Example #4
0
def modis5kmto1km(lons5km, lats5km):
    """Getting 1km geolocation for modis from 5km tiepoints.

    http://www.icare.univ-lille1.fr/tutorials/MODIS_geolocation
    """
    from geotiepoints.geointerpolator import \
        GeoInterpolator as SatelliteInterpolator

    # FIXME: I changed the values here to work with MOD06 - but why?!
    cols5km = np.arange(2, 1350, 5) / 5.0
    cols1km = np.arange(1350) / 5.0
    lines = lons5km.shape[0] * 5
    rows5km = np.arange(2, lines, 5) / 5.0
    rows1km = np.arange(lines) / 5.0

    along_track_order = 1
    cross_track_order = 3

    satint = SatelliteInterpolator((lons5km, lats5km), (rows5km, cols5km),
                                   (rows1km, cols1km),
                                   along_track_order,
                                   cross_track_order,
                                   chunk_size=10)
    satint.fill_borders("y", "x")
    lons1km, lats1km = satint.interpolate()
    return lons1km, lats1km
Example #5
0
def modis5kmto1km(lons5km, lats5km):
    """Getting 1km geolocation for modis from 5km tiepoints.

    http://www.icare.univ-lille1.fr/tutorials/MODIS_geolocation
    """
    from geotiepoints.geointerpolator import \
        GeoInterpolator as SatelliteInterpolator

    # FIXME: I changed the values here to work with MOD06 - but why?!
    cols5km = np.arange(2, 1350, 5) / 5.0
    cols1km = np.arange(1350) / 5.0
    lines = lons5km.shape[0] * 5
    rows5km = np.arange(2, lines, 5) / 5.0
    rows1km = np.arange(lines) / 5.0

    along_track_order = 1
    cross_track_order = 3

    satint = SatelliteInterpolator((lons5km, lats5km),
                                   (rows5km, cols5km),
                                   (rows1km, cols1km),
                                   along_track_order,
                                   cross_track_order,
                                   chunk_size=10)
    satint.fill_borders("y", "x")
    lons1km, lats1km = satint.interpolate()
    return lons1km, lats1km
Example #6
0
def modis1kmto250m(lons1km, lats1km, cores=1):
    """Getting 250m geolocation for modis from 1km tiepoints.

    http://www.icare.univ-lille1.fr/tutorials/MODIS_geolocation
    """
    if cores > 1:
        return _multi(modis1kmto250m, lons1km, lats1km, 10, cores)

    cols1km = np.arange(1354)
    cols250m = np.arange(1354 * 4) / 4.0

    along_track_order = 1
    cross_track_order = 3

    lines = lons1km.shape[0]
    rows1km = np.arange(lines)
    rows250m = (np.arange(lines * 4) - 1.5) / 4.0

    satint = SatelliteInterpolator((lons1km, lats1km), (rows1km, cols1km),
                                   (rows250m, cols250m),
                                   along_track_order,
                                   cross_track_order,
                                   chunk_size=40)
    satint.fill_borders("y", "x")
    lons250m, lats250m = satint.interpolate()

    return lons250m, lats250m
 def test_extrapolate_rows(self):
     lons = np.arange(10).reshape((2, 5), order="F")
     lats = np.arange(10).reshape((2, 5), order="C")
     lines = np.array([2, 7])
     cols = np.array([2, 7, 12, 17, 22])
     hlines = np.arange(10)
     hcols = np.arange(24)
     satint = GeoInterpolator((lons, lats), (lines, cols), (hlines, hcols))
     np.testing.assert_allclose(
         satint._extrapolate_rows(satint.tie_data[0], hlines, -0.4, 9.4),
         TIES_EXP4)
 def test_extrapolate_rows(self):
     lons = np.arange(10).reshape((2, 5), order="F")
     lats = np.arange(10).reshape((2, 5), order="C")
     lines = np.array([2, 7])
     cols = np.array([2, 7, 12, 17, 22])
     hlines = np.arange(10)
     hcols = np.arange(24)
     satint = GeoInterpolator((lons, lats), (lines, cols), (hlines, hcols))
     np.testing.assert_allclose(satint._extrapolate_rows(satint.tie_data[0],
                                                         hlines, -0.4, 9.4),
                                TIES_EXP4)
    def test_extrapolate_cols(self):
        lons = np.arange(10).reshape((2, 5), order="F")
        lats = np.arange(10).reshape((2, 5), order="C")
        lines = np.array([2, 7])
        cols = np.array([2, 7, 12, 17, 22])
        hlines = np.arange(10)
        hcols = np.arange(24)
        satint = GeoInterpolator((lons, lats), (lines, cols), (hlines, hcols))

        self.assertTrue(np.allclose(satint._extrapolate_cols(satint.tie_data[0]),
                                    TIES_EXP2))
    def test_extrapolate_cols(self):
        lons = np.arange(10).reshape((2, 5), order="F")
        lats = np.arange(10).reshape((2, 5), order="C")
        lines = np.array([2, 7])
        cols = np.array([2, 7, 12, 17, 22])
        hlines = np.arange(10)
        hcols = np.arange(24)
        satint = GeoInterpolator((lons, lats), (lines, cols), (hlines, hcols))

        self.assertTrue(
            np.allclose(satint._extrapolate_cols(satint.tie_data[0]),
                        TIES_EXP2))
 def test_fill_col_borders(self):
     lons = np.arange(10).reshape((2, 5), order="F")
     lats = np.arange(10).reshape((2, 5), order="C")
     lines = np.array([2, 7])
     cols = np.array([2, 7, 12, 17, 22])
     hlines = np.arange(10)
     hcols = np.arange(24)
     satint = GeoInterpolator((lons, lats), (lines, cols), (hlines, hcols))
     satint._fill_col_borders()
     np.testing.assert_allclose(satint.tie_data[0], TIES_EXP7)
     np.testing.assert_allclose(satint.col_indices,
                                np.array([0, 2, 7, 12, 17, 22, 23]))
 def test_fill_col_borders(self):
     lons = np.arange(10).reshape((2, 5), order="F")
     lats = np.arange(10).reshape((2, 5), order="C")
     lines = np.array([2, 7])
     cols = np.array([2, 7, 12, 17, 22])
     hlines = np.arange(10)
     hcols = np.arange(24)
     satint = GeoInterpolator((lons, lats), (lines, cols), (hlines, hcols))
     satint._fill_col_borders()
     np.testing.assert_allclose(satint.tie_data[0], TIES_EXP7)
     np.testing.assert_allclose(satint.col_indices,
                                np.array([0,  2,  7, 12, 17, 22, 23]))
Example #13
0
def metop20kmto1km(lons20km, lats20km):
    """Getting 1km geolocation for metop avhrr from 20km tiepoints.
    """
    cols20km = np.array([0] + range(4, 2048, 20) + [2047])
    cols1km = np.arange(2048)
    lines = lons20km.shape[0]
    rows20km = np.arange(lines)
    rows1km = np.arange(lines)

    along_track_order = 1
    cross_track_order = 3

    satint = SatelliteInterpolator((lons20km, lats20km), (rows20km, cols20km),
                                   (rows1km, cols1km), along_track_order,
                                   cross_track_order)
    return satint.interpolate()
    def test_fillborders(self):
        lons = np.arange(20).reshape((4, 5), order="F")
        lats = np.arange(20).reshape((4, 5), order="C")
        lines = np.array([2, 7, 12, 17]) / 5.0
        cols = np.array([2, 7, 12, 17, 22])
        hlines = np.arange(20) / 5.0
        hcols = np.arange(24)
        satint = GeoInterpolator(
            (lons, lats), (lines, cols), (hlines, hcols), chunk_size=10)
        satint.fill_borders('x', 'y')

        np.testing.assert_allclose(satint.tie_data[0], TIES_EXP1)
        np.testing.assert_allclose(satint.row_indices, np.array(
            [0,  2,  7,  9, 10, 12, 17, 19]) / 5.0)
        self.assertTrue(
            np.allclose(satint.col_indices, np.array([0,  2,  7, 12, 17, 22, 23])))
 def test_extrapolate_cols(self):
     lons = np.arange(10).reshape((2, 5), order="F")
     lats = np.arange(10).reshape((2, 5), order="C")
     lines = np.array([2, 7])
     cols = np.array([2, 7, 12, 17, 22])
     hlines = np.arange(10)
     hcols = np.arange(24)
     satint = GeoInterpolator((lons, lats), (lines, cols), (hlines, hcols))
     
     self.assertTrue(np.allclose(satint._extrapolate_cols(satint.tie_data[0]),
       np.array([[ 6372937.31273379,  6370997.        ,  6366146.21816553,
                   6351605.98629588,  6327412.61244969,  6293626.50067273,
                   6286869.27831734],
                 [ 6353136.46335726,  6345786.79166939,  6327412.61244969,
                   6299445.69529922,  6261968.60390423,  6215087.60607344,
                   6205711.40650728]])))
 def test_extrapolate_rows(self):
     lons = np.arange(10).reshape((2, 5), order="F")
     lats = np.arange(10).reshape((2, 5), order="C")
     lines = np.array([2, 7])
     cols = np.array([2, 7, 12, 17, 22])
     hlines = np.arange(10)
     hcols = np.arange(24)
     satint = GeoInterpolator((lons, lats), (lines, cols), (hlines, hcols))
     self.assertTrue(np.allclose(satint._extrapolate_rows(satint.tie_data[0]),
       np.array([[ 6381081.08333225,  6381639.66045187,  6372470.10269454,
                   6353590.21586788,  6325042.05851245],
                 [ 6370997.        ,  6366146.21816553,  6351605.98629588,
                   6327412.61244969,  6293626.50067273],
                 [ 6345786.79166939,  6327412.61244969,  6299445.69529922,
                   6261968.60390423,  6215087.60607344],
                 [ 6335702.70833714,  6311919.17016336,  6278581.57890056,
                   6235791.00048604,  6183672.04823372]])))
    def test_fillborders(self):
        lons = np.arange(20).reshape((4, 5), order="F")
        lats = np.arange(20).reshape((4, 5), order="C")
        lines = np.array([2, 7, 12, 17]) / 5.0
        cols = np.array([2, 7, 12, 17, 22])
        hlines = np.arange(20) / 5.0
        hcols = np.arange(24)
        satint = GeoInterpolator((lons, lats), (lines, cols), (hlines, hcols),
                                 chunk_size=10)
        satint.fill_borders('x', 'y')

        np.testing.assert_allclose(satint.tie_data[0], TIES_EXP1)
        np.testing.assert_allclose(
            satint.row_indices,
            np.array([0, 2, 7, 9, 10, 12, 17, 19]) / 5.0)
        self.assertTrue(
            np.allclose(satint.col_indices, np.array([0, 2, 7, 12, 17, 22,
                                                      23])))
Example #18
0
def metop20kmto1km(lons20km, lats20km):
    """Getting 1km geolocation for metop avhrr from 20km tiepoints.
    """
    cols20km = np.array([0] + list(range(4, 2048, 20)) + [2047])
    cols1km = np.arange(2048)
    lines = lons20km.shape[0]
    rows20km = np.arange(lines)
    rows1km = np.arange(lines)

    along_track_order = 1
    cross_track_order = 3

    satint = SatelliteInterpolator((lons20km, lats20km),
                                   (rows20km, cols20km),
                                   (rows1km, cols1km),
                                   along_track_order,
                                   cross_track_order)
    return satint.interpolate()
Example #19
0
def modis5kmto1km(lons5km, lats5km):
    """Getting 1km geolocation for modis from 5km tiepoints.
    """
    cols5km = np.arange(2, 1354, 5)
    cols1km = np.arange(1354)
    lines = lons5km.shape[0] * 5
    rows5km = np.arange(2, lines, 5)
    rows1km = np.arange(lines)

    along_track_order = 1
    cross_track_order = 3

    satint = SatelliteInterpolator((lons5km, lats5km),
                                   (rows5km, cols5km),
                                   (rows1km, cols1km),
                                   along_track_order,
                                   cross_track_order,
                                   chunk_size=10)
    satint.fill_borders("y", "x")
    lons1km, lats1km = satint.interpolate()
    return lons1km, lats1km
Example #20
0
def modis5kmto1km(lons5km, lats5km):
    """Getting 1km geolocation for modis from 5km tiepoints.

    http://www.icare.univ-lille1.fr/tutorials/MODIS_geolocation
    """
    cols5km = np.arange(2, 1354, 5) / 5.0
    cols1km = np.arange(1354) / 5.0
    lines = lons5km.shape[0] * 5
    rows5km = np.arange(2, lines, 5) / 5.0
    rows1km = np.arange(lines) / 5.0

    along_track_order = 1
    cross_track_order = 3

    satint = SatelliteInterpolator((lons5km, lats5km), (rows5km, cols5km),
                                   (rows1km, cols1km),
                                   along_track_order,
                                   cross_track_order,
                                   chunk_size=10)
    satint.fill_borders("y", "x")
    lons1km, lats1km = satint.interpolate()
    return lons1km, lats1km
Example #21
0
def modis5kmto1km(lons5km, lats5km):
    """Getting 1km geolocation for modis from 5km tiepoints.

    http://www.icare.univ-lille1.fr/tutorials/MODIS_geolocation
    """
    cols5km = np.arange(2, 1354, 5) / 5.0
    cols1km = np.arange(1354) / 5.0
    lines = lons5km.shape[0] * 5
    rows5km = np.arange(2, lines, 5) / 5.0
    rows1km = np.arange(lines) / 5.0

    along_track_order = 1
    cross_track_order = 3

    satint = SatelliteInterpolator((lons5km, lats5km),
                                   (rows5km, cols5km),
                                   (rows1km, cols1km),
                                   along_track_order,
                                   cross_track_order,
                                   chunk_size=10)
    satint.fill_borders("y", "x")
    lons1km, lats1km = satint.interpolate()
    return lons1km, lats1km
Example #22
0
def modis1kmto500m(lons1km, lats1km, cores=1):
    """Getting 500m geolocation for modis from 1km tiepoints.
    """
    if cores > 1:
        return _multi(modis1kmto500m, lons1km, lats1km, 10, cores)
    
    cols1km = np.arange(0, 2708, 2)
    cols500m = np.arange(2708)
    lines = lons1km.shape[0] * 2
    rows1km = np.arange(0.5, lines, 2)
    rows500m = np.arange(lines)

    along_track_order = 1
    cross_track_order = 3
    
    satint = SatelliteInterpolator((lons1km, lats1km),
                                   (rows1km, cols1km),
                                   (rows500m, cols500m),
                                   along_track_order,
                                   cross_track_order,
                                   chunk_size=20)
    satint.fill_borders("y", "x")
    lons500m, lats500m = satint.interpolate()
    return lons500m, lats500m
 def test_fill_row_borders(self):
     lons = np.arange(20).reshape((4, 5), order="F")
     lats = np.arange(20).reshape((4, 5), order="C")
     lines = np.array([2, 7, 12, 17])
     cols = np.array([2, 7, 12, 17, 22])
     hlines = np.arange(20)
     hcols = np.arange(24)
     satint = GeoInterpolator((lons, lats), (lines, cols), (hlines, hcols))
     satint._fill_row_borders()
     self.assertTrue(np.allclose(satint.tie_data[0],
       np.array([[ 6381081.08333225,  6371519.34066148,  6328950.00792935,
                   6253610.69157758,  6145946.19489936],
                 [ 6370997.        ,  6354509.6014956 ,  6305151.62592155,
                   6223234.99818839,  6109277.14889072],
                 [ 6345786.79166939,  6311985.2535809 ,  6245655.67090206,
                   6147295.76471541,  6017604.5338691 ],
                 [ 6270385.16249031,  6219684.08214232,  6137100.75832981,
                   6023313.2794414 ,  5879194.72399075],
                 [ 6145476.82098957,  6078546.55734877,  5980676.23854351,
                   5852716.72120069,  5695705.57359808],
                 [ 6095513.48438928,  6022091.54743135,  5918106.430629  ,
                   5784478.09790441,  5622309.91344102]])))
     self.assertTrue(np.allclose(satint.row_indices,
                                 np.array([ 0,  2,  7, 12, 17, 19])))
     satint = GeoInterpolator((lons, lats), (lines, cols),
                              (hlines, hcols), chunk_size=10)
     satint._fill_row_borders()
     self.assertTrue(np.allclose(satint.tie_data[0],
       np.array([[ 6381081.08333225,  6371519.34066148,  6328950.00792935,
                   6253610.69157758,  6145946.19489936],
                 [ 6370997.        ,  6354509.6014956 ,  6305151.62592155,
                   6223234.99818839,  6109277.14889072],
                 [ 6345786.79166939,  6311985.2535809 ,  6245655.67090206,
                   6147295.76471541,  6017604.5338691 ],
                 [ 6335702.70833714,  6294975.51441502,  6221857.28889426,
                   6116920.07132621,  5980935.48786045],
                 [ 6320348.4990906 ,  6276139.09205974,  6199670.56624433,
                   6091551.90273768,  5952590.38414781],
                 [ 6270385.16249031,  6219684.08214232,  6137100.75832981,
                   6023313.2794414 ,  5879194.72399075],
                 [ 6145476.82098957,  6078546.55734877,  5980676.23854351,
                   5852716.72120069,  5695705.57359808],
                 [ 6095513.48438928,  6022091.54743135,  5918106.430629  ,
                   5784478.09790441,  5622309.91344102]])))
     self.assertTrue(np.allclose(satint.row_indices,
                                 np.array([ 0,  2,  7,  9, 10, 12, 17, 19])))
 def test_fillborders(self):
     lons = np.arange(20).reshape((4, 5), order="F")
     lats = np.arange(20).reshape((4, 5), order="C")
     lines = np.array([2, 7, 12, 17])
     cols = np.array([2, 7, 12, 17, 22])
     hlines = np.arange(20)
     hcols = np.arange(24)
     satint = GeoInterpolator((lons, lats), (lines, cols), (hlines, hcols), chunk_size=10)
     satint.fill_borders('x', 'y')
     self.assertTrue(np.allclose(satint.tie_data[0],
       np.array([[ 6384905.78040055,  6381081.08333225,  6371519.34066148,
                   6328950.00792935,  6253610.69157758,  6145946.19489936,
                   6124413.29556372],
                 [ 6377591.95940176,  6370997.        ,  6354509.6014956 ,
                   6305151.62592155,  6223234.99818839,  6109277.14889072,
                   6086485.57903118],
                 [ 6359307.40690478,  6345786.79166939,  6311985.2535809 ,
                   6245655.67090206,  6147295.76471541,  6017604.5338691 ,
                   5991666.28769983],
                 [ 6351993.58590599,  6335702.70833714,  6294975.51441502,
                   6221857.28889426,  6116920.07132621,  5980935.48786045,
                   5953738.5711673 ],
                 [ 6338032.26190294,  6320348.4990906 ,  6276139.09205974,
                   6199670.56624433,  6091551.90273768,  5952590.38414781,
                   5924798.08042984],
                 [ 6290665.5946295 ,  6270385.16249031,  6219684.08214232,
                   6137100.75832981,  6023313.2794414 ,  5879194.72399075,
                   5850371.01290062],
                 [ 6172248.92644589,  6145476.82098957,  6078546.55734877,
                   5980676.23854351,  5852716.72120069,  5695705.57359808,
                   5664303.34407756],
                 [ 6124882.25917245,  6095513.48438928,  6022091.54743135,
                   5918106.430629  ,  5784478.09790441,  5622309.91344102,
                   5589876.27654834]])))
     self.assertTrue(np.allclose(satint.row_indices, np.array([ 0,  2,  7,  9, 10, 12, 17, 19])))
     self.assertTrue(np.allclose(satint.col_indices, np.array([ 0,  2,  7, 12, 17, 22, 23])))
#   Adam.Dybbroe <*****@*****.**>

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""
"""

import numpy as np
from geotiepoints.geointerpolator import GeoInterpolator

lons = np.arange(20).reshape((4, 5), order="F")
lats = np.arange(20).reshape((4, 5), order="C")
lines = np.array([2, 7, 12, 17]) / 5.0
cols = np.array([2, 7, 12, 17, 22])
hlines = np.arange(20) / 5.0
hcols = np.arange(24)
satint = GeoInterpolator(
    (lons, lats), (lines, cols), (hlines, hcols), chunk_size=10)
satint.fill_borders('x', 'y')
Example #26
0
def main(path, output_folder):

	df = pd.DataFrame()
	files = glob.glob(path)


	for f in files:
		print(f'Processing file {f}')

		file = SD(f, SDC.READ)

		# Seconds since 1993-01-01 at 0:00:00.0 (TAI)
		sec93 = file.select('Scan_Start_Time').get()[0,0]
		utc = datetime(1993,1,1,0,0) + timedelta(seconds=sec93)
		print(f'Acquisition date: {utc.strftime("%Y-%m-%d %H:%M")}')

		lat5km = file.select('Latitude').get()
		lon5km = file.select('Longitude').get()
		mask1km = file.select('Cloud_Mask_1km').get()
		height1km = file.select('cloud_top_height_1km').get()
		fraction5km = file.select('Cloud_Fraction_Night').get()

		tie_rows = np.arange(2,3000,5)[:np.shape(lat5km)[0]]
		tie_cols = np.arange(2,1500,5)[:np.shape(lat5km)[1]]
		fine_rows = np.arange(0,3000,1)[:np.shape(mask1km)[0]]
		fine_cols = np.arange(0,1500,1)[:np.shape(mask1km)[1]]

		interpolator = GeoInterpolator(
				(lon5km, lat5km), 
				(tie_rows, tie_cols), 
				(fine_rows, fine_cols), 2, 2)
		lon1km, lat1km = interpolator.interpolate()

		lon1km = lon1km.flatten()
		lat1km = lat1km.flatten()

		lon5km = lon5km.flatten()
		lat5km = lat5km.flatten()


		cmask_1 = bits_stripping(1, 2, mask1km[:,:,0]).flatten()
		cheight = height1km.flatten()
		cfraction = fraction5km.flatten()


		for location in ['Arkaroola', 'WesternAustralia', 'Mereenie', 'Arkaroola', 'FowlersGap', 'Woomera', 'SidingSpring', 'Koonamoore', 'Riverland']:

			if location == 'MtBruce':
				lat = -22.608
				lon = 118.144
			elif location == 'MtMeharry':
				lat = -22.980
				lon = 118.588
			elif location == 'WesternAustralia':
				lat = -22.72372
				lon = 118.39802
			elif location == 'Mereenie':
				lat = -23.886
				lon = 132.20
			elif location == 'Arkaroola':
				lat = -30.308
				lon = 139.338
			elif location == 'FowlersGap':
				lat = -31.087
				lon = 141.705
			elif location == 'Woomera':
				lat = -31.099
				lon = 136.786
			elif location == 'SidingSpring':
				lat = -31.2755
				lon = 149.067
			elif location == 'Koonamoore':
				lat = -32.064
				lon = 139.383
			elif location == 'Moorook':
				lat = -34.267
				lon = 140.334
			elif location == 'Riverland':
				lat = -34.4235
				lon = 139.897.334
			elif location == 'Adelaide':
				lat = -34.928889
				lon = 138.601111

			dlat = 1
			dlon = 1

			dist1km = np.sqrt( (lon - lon1km) ** 2 + (lat - lat1km) ** 2 )

			if np.min(dist1km) < 0.005:

				print(f'{location} on map')

				grid_x1km, grid_y1km = np.mgrid[lon-dlon:lon+dlon:200j, lat-dlat:lat+dlat:200j]
				grid_x5km, grid_y5km = np.mgrid[lon-dlon:lon+dlon:40j, lat-dlat:lat+dlat:40j]
	        
				intp_cmask = griddata((lon1km,lat1km), 
	                               cmask_1, 
	                               (grid_x1km,grid_y1km), 
	                               method='nearest')
				np.save(f'{output_folder}{location}_cloudmask_{utc.date()}_{utc.time()}_{lon-dlon}_{lon-dlat}_{lat-dlat}_{lat+dlat}.npy', intp_cmask)
	        
				intp_cheight = griddata((lon1km,lat1km), 
	                               cheight, 
	                               (grid_x1km,grid_y1km), 
	                               method='nearest')
				np.save(f'{output_folder}{location}_cloudheight_{utc.date()}_{utc.time()}_{lon-dlon}_{lon-dlat}_{lat-dlat}_{lat+dlat}.npy', intp_cheight)
	        

				intp_cfraction = griddata((lon5km,lat5km), 
	                               cfraction, 
	                               (grid_x5km,grid_y5km), 
	                               method='nearest')
				np.save(f'{output_folder}{location}_cloudfraction_{utc.date()}_{utc.time()}_{lon-dlon}_{lon-dlat}_{lat-dlat}_{lat+dlat}.npy', intp_cfraction)


			else:
				print(f'{location} not on map')
Example #27
0
def main(path, output_folder, output_file, location, coords, maps):

    df = pd.DataFrame()
    files = glob.glob(path)

    if location == 'MtBruce':
        lat = -22.608
        lon = 118.144
    elif location == 'MtMeharry':
        lat = -22.980
        lon = 118.588
    elif location == 'Mereenie':
        lat = -23.886
        lon = 132.20
    elif location == 'Arkaroola':
        lat = -30.308
        lon = 139.338
    elif location == 'FowlersGap':
        lat = -31.087
        lon = 141.705
    elif location == 'Woomera':
        lat = -31.099
        lon = 136.786
    elif location == 'SidingSpring':
        lat = -31.2755
        lon = 149.067
    elif location == 'Koonamoore':
        lat = -32.064
        lon = 139.383
    elif location == 'Moorook':
        lat = -34.267
        lon = 140.334
    elif location == 'Adelaide':
        lat = -34.928889
        lon = 138.601111
    else:
        #if len(location) > 0:
        #	raise Exception('This location is not pre-defined. Please specify the coordinates.')
        print(len(coords))
        if len(coords) != 2:
            raise Exception('Please specify a location or coordinates.')
        else:
            lon = coords[0]
            lat = coords[1]
            location = f'Lon{lon}_Lat{lat}'

    for f in files:
        print(f'Processing file {f}')

        file = SD(f, SDC.READ)

        # Seconds since 1993-01-01 at 0:00:00.0 (TAI)
        sec93 = file.select('Scan_Start_Time').get()[0, 0]
        utc = datetime(1993, 1, 1, 0, 0) + timedelta(seconds=sec93)
        print(f'Acquisition date: {utc.strftime("%Y-%m-%d %H:%M")}')

        lat5km = file.select('Latitude').get()
        lon5km = file.select('Longitude').get()
        mask1km = file.select('Cloud_Mask_1km').get()
        height1km = file.select('cloud_top_height_1km').get()
        fraction5km = file.select('Cloud_Fraction_Night').get()

        tie_rows = np.arange(2, 3000, 5)[:np.shape(lat5km)[0]]
        tie_cols = np.arange(2, 1500, 5)[:np.shape(lat5km)[1]]
        fine_rows = np.arange(0, 3000, 1)[:np.shape(mask1km)[0]]
        fine_cols = np.arange(0, 1500, 1)[:np.shape(mask1km)[1]]

        interpolator = GeoInterpolator((lon5km, lat5km), (tie_rows, tie_cols),
                                       (fine_rows, fine_cols), 2, 2)
        lon1km, lat1km = interpolator.interpolate()

        lon1km = lon1km.flatten()
        lat1km = lat1km.flatten()

        lon5km = lon5km.flatten()
        lat5km = lat5km.flatten()

        cmask_0 = bits_stripping(0, 1, mask1km[:, :, 0]).flatten()
        cmask_1 = bits_stripping(1, 2, mask1km[:, :, 0]).flatten()
        cmask_3 = bits_stripping(3, 1, mask1km[:, :, 0]).flatten()
        cmask_4 = bits_stripping(4, 1, mask1km[:, :, 0]).flatten()
        cmask_5 = bits_stripping(5, 1, mask1km[:, :, 0]).flatten()
        cmask_6 = bits_stripping(6, 2, mask1km[:, :, 0]).flatten()
        cmask_8 = bits_stripping(8, 1, mask1km[:, :, 0]).flatten()
        cmask_14 = bits_stripping(14, 1, mask1km[:, :, 0]).flatten()
        cmask_15 = bits_stripping(15, 1, mask1km[:, :, 0]).flatten()
        cmask_17 = bits_stripping(17, 1, mask1km[:, :, 0]).flatten()
        cmask_18 = bits_stripping(18, 1, mask1km[:, :, 0]).flatten()
        cmask_19 = bits_stripping(19, 1, mask1km[:, :, 0]).flatten()

        cheight = height1km.flatten()
        cfraction = fraction5km.flatten()

        dist1km = np.sqrt((lon - lon1km)**2 + (lat - lat1km)**2)
        dist5km = np.sqrt((lon - lon5km)**2 + (lat - lat5km)**2)

        if np.min(dist1km) < 0.005:
            idx1km = np.argmin(dist1km)
            idx5km = np.argmin(dist5km)

            df = df.append(
                {
                    'date': utc,
                    'filename': f,
                    'cmask_0': cmask_0[idx1km],
                    'cmask_1': cmask_1[idx1km],
                    'cmask_3': cmask_3[idx1km],
                    'cmask_4': cmask_4[idx1km],
                    'cmask_5': cmask_5[idx1km],
                    'cmask_6': cmask_6[idx1km],
                    'cmask_8': cmask_8[idx1km],
                    'cmask_14': cmask_14[idx1km],
                    'cmask_15': cmask_15[idx1km],
                    'cmask_17': cmask_17[idx1km],
                    'cmask_18': cmask_18[idx1km],
                    'cmask_19': cmask_19[idx1km],
                    'cloudfraction': cfraction[idx5km],
                    'height': cheight[idx1km],
                },
                ignore_index=True)

            if maps:

                size_map = 0.25
                idx_map = (lon1km > (lon - size_map)) & (lon1km <
                                                         (lon + size_map))
                idx_map = idx_map & (lat1km >
                                     (lat - size_map)) & (lat1km <
                                                          (lat + size_map))

                grid_x, grid_y = np.mgrid[
                    np.min(lon1km[idx_map]):np.max(lon1km[idx_map]):100j,
                    np.min(lat1km[idx_map]):np.max(lat1km[idx_map]):200j]
                intp_cmask = griddata((lon1km[idx_map], lat1km[idx_map]),
                                      cmask_1[idx_map], (grid_x, grid_y),
                                      method='nearest')
                intp_cheight = griddata((lon1km[idx_map], lat1km[idx_map]),
                                        cheight[idx_map], (grid_x, grid_y),
                                        method='nearest')

                np.save(
                    f'{output_folder}{location}_cloudmask_{utc.date()}_{utc.time()}_{np.min(lon1km[idx_map])}_{np.max(lon1km[idx_map])}_{np.min(lat1km[idx_map])}_{np.max(lat1km[idx_map])}.npy',
                    intp_cmask)
                np.save(
                    f'{output_folder}{location}_cloudheight_{utc.date()}_{utc.time()}_{np.min(lon1km[idx_map])}_{np.max(lon1km[idx_map])}_{np.min(lat1km[idx_map])}_{np.max(lat1km[idx_map])}.npy',
                    intp_cheight)

        else:
            print('Site not on map')

    df = df.sort_values(
        by='date', ascending=True
    )  #reorders dataframe so histogram will be in correct order
    if output_file == None:
        df.to_csv(
            f'{output_folder}{location}_{df.date.min()}_{df.date.max()}.csv',
            index=False)
    else:
        df.to_csv(output_folder + output_file, index=False)
Example #28
0
#   Adam.Dybbroe <*****@*****.**>

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""
"""

import numpy as np
from geotiepoints.geointerpolator import GeoInterpolator

lons = np.arange(20).reshape((4, 5), order="F")
lats = np.arange(20).reshape((4, 5), order="C")
lines = np.array([2, 7, 12, 17]) / 5.0
cols = np.array([2, 7, 12, 17, 22])
hlines = np.arange(20) / 5.0
hcols = np.arange(24)
satint = GeoInterpolator((lons, lats), (lines, cols), (hlines, hcols),
                         chunk_size=10)
satint.fill_borders('x', 'y')