예제 #1
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
예제 #2
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
예제 #3
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
예제 #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
예제 #5
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
예제 #6
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
예제 #7
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()
예제 #8
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()
예제 #9
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
예제 #10
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
예제 #11
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
예제 #12
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
예제 #13
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)
예제 #14
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')