Пример #1
0
def convert_nc(yyyymmdd, file_in, out_file):

    r = raster.ReadRaster(file_in)
    lons = np.linspace(r.xmin + 0.5 * r.xres, r.xmax - 0.5 * r.xres, r.ncol)
    lats = np.linspace(r.ymin + np.abs(0.5 * r.yres),
                       r.ymax - 0.5 * np.abs(r.xres), r.nrow)

    rootgrp = Dataset(out_file, "w", format="NETCDF4_CLASSIC")
    time = rootgrp.createDimension("time", None)
    lat = rootgrp.createDimension("lat", len(lats))
    lon = rootgrp.createDimension("lon", len(lons))

    times = rootgrp.createVariable("time", "f8", ("time", ))
    latitudes = rootgrp.createVariable("lat", "f8", ("lat", ))
    longitudes = rootgrp.createVariable("lon", "f8", ("lon", ))
    var = rootgrp.createVariable("temp",
                                 "f4", (
                                     "time",
                                     "lat",
                                     "lon",
                                 ),
                                 zlib=True,
                                 least_significant_digit=1)

    data = np.flipud(r.data)

    #data[data>200] = np.nan

    latitudes[:] = lats
    longitudes[:] = lons
    var[0, :, ] = data

    rootgrp.description = "Computed by Satyukt Analytics"
    rootgrp.history = "Created %s " % dt.date.today()
    rootgrp.source = "Estimated using vikleda"
    latitudes.units = "degrees north"
    longitudes.units = "degrees east"
    times.units = "days since 0001-01-01"
    times.calendar = "gregorian"

    dates = dt.datetime.strptime(yyyymmdd, '%Y%m%d')
    times[0] = date2num(dates, units=times.units, calendar=times.calendar)
    rootgrp.close()
    print('%s file created' % out_file)
Пример #2
0
def convert_nc(yyyymmdd, dir_tif, dir_nc):
    files_in = glob.glob(os.path.join(dir_tif, "S1?_??_????_????_%s*.tif"%yyyymmdd))
    
    for file_in in files_in:
        out_file = os.path.join(dir_nc, os.path.basename(file_in).replace(".tif",".nc"))
        if not os.path.exists(out_file):
            r = raster.ReadRaster(file_in)
            lons = np.linspace(r.xmin+0.5*r.xres, r.xmax-0.5*r.xres, r.ncol)
            lats = np.linspace(r.ymin+np.abs(0.5*r.yres), r.ymax-0.5*np.abs(r.xres), r.nrow)
            
            rootgrp = Dataset(out_file, "w", format="NETCDF4_CLASSIC")
            time = rootgrp.createDimension("time", None)
            lat = rootgrp.createDimension("lat", len(lats))
            lon = rootgrp.createDimension("lon", len(lons))
            
            times = rootgrp.createVariable("time","f8",("time",))
            latitudes = rootgrp.createVariable("lat","f8",("lat",))
            longitudes = rootgrp.createVariable("lon","f8",("lon",))
            var = rootgrp.createVariable("temp","f4",("time","lat","lon",), zlib=True, 
                                             least_significant_digit=1)
                                             
            data = np.flipud(r.data)
            if "VV" in file_in or "VH" in file_in:
                data = 10*np.log10(data)
            #data[data>200] = np.nan
                
            latitudes[:] = lats
            longitudes[:] = lons
            var[0,:,] = data
                
            rootgrp.description = "Computed by Satyukt Analytics"
            rootgrp.history = "Created %s "%dt.date.today()
            rootgrp.source = "Estimated using vikleda"
            latitudes.units = "degrees north"
            longitudes.units = "degrees east"
            times.units = "days since 0001-01-01"
            times.calendar = "gregorian"
                
            dates = dt.datetime.strptime(yyyymmdd,'%Y%m%d')
            times[0] = date2num(dates, units=times.units, calendar=times.calendar)
            rootgrp.close()

def store_evolution_in(lst):
    """Returns a callback function to store the evolution of the level sets in
    the given list.
    """
    def _store(x):
        lst.append(np.copy(x))

    return _store


in_dir = "/home/pavithra/Desktop/Satyukt/20th Dec 2018_B2.tif"
sd_dir = "/home/pavithra/Desktop/New_test_folder"

r_band = raster.ReadRaster(in_dir)
#data = r_band.data

image = r_band.data

init_ls = checkerboard_level_set(image.shape, 5)

evolution = []
callback = store_evolution_in(evolution)
ls = morphological_chan_vese(image,
                             100,
                             init_level_set=init_ls,
                             smoothing=5,
                             iter_callback=callback)

fig, axes = plt.subplots(1, 2, figsize=(8, 8))
Пример #4
0
import scipy
from apya import raster
from scipy import misc
from scipy.cluster.vq import kmeans, vq, whiten
from skimage import filters

in_dir = "/home/pavithra/Desktop/Rasterimages/AndhraPradesh_SCL/*SCL_20m.tif"

in_files = glob.glob(in_dir)
in_files.sort()

sd_dir = "/home/pavithra/Desktop/Rasterimages/AndhraPradesh_Data/Cloudy/"
sd_dir2 = "/home/pavithra/Desktop/Rasterimages/AndhraPradesh_Data/clear_data/"

for in_file in in_files:
    reading = raster.ReadRaster(in_file)
    im = Image.open(in_file, 'r')
    pix_val = list(im.getdata())

    #getting the count of values
    five = pix_val.count(5.0)
    seven = pix_val.count(7.0)
    four = pix_val.count(4.0)
    three = pix_val.count(3.0)

    #print('5',five)
    #print('7',seven)
    #print('4',four)
    #print('3',three)

    #total pixel count
#This program coverts the featured images into a different pixel composition. Replacing the black and grey ones with white and the white with black, to make the boundaries more clear, to implement the algorithm.

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from scipy import ndimage as ndi
import cv2
from skimage.feature import shape_index
from apya import raster
from PIL import Image
import os
import cv2

im = raster.ReadRaster(
    '/home/pavithra/Desktop/Rasterimages/NEW_Feature_data/B02/T14QQF_20181220T165719_B02_10m.tif'
)

sd_dir = "/home/pavithra/Desktop/Satyukt"

data = im.data

print(data[1][2])

print(data.shape)

#955 is the number of pixels in row and 1190 in the column

for i in range(0, 955):
    for j in range(0, 1190):
        if (data[i][j] <= 65):
            data[i][j] = 255
from apya import raster
from scipy import misc
from scipy.cluster.vq import kmeans, vq, whiten
from skimage import filters
from skimage import measure

#finding the Standard deviation of the bands
#For cloudy data, the 'less cloudy' data is applied feature extraction

in_dir = "/home/pavithra/Desktop/Rasterimages/NEW_MEX_DATA/mex_data/B12/*.tif"
in_files = glob.glob(in_dir)
in_files.sort()
sd_dir = "/home/pavithra/Desktop/Rasterimages/NEW_SD/SD_B12"

for in_file in in_files:
    r_band = raster.ReadRaster(in_file)
    data = r_band.data

    out_sd = ndimage.generic_filter(data, np.var, size=3)**0.5

    sd_file = os.path.join(sd_dir, os.path.basename(in_file))

    r_band_sd = raster.Raster(out_sd,
                              extent=r_band.extent,
                              projection=r_band.projection)

    raster.WriteRaster(r_band_sd, sd_file)

    print(sd_file)

#Applying Guassian filter
sd_dir = "/home/pavithra/Desktop/Rasterimages/AndhraPradesh_Data/*.tif"
sd_files = glob.glob(sd_dir)
sd_files.sort()


sd_datacc = "/home/pavithra/Desktop/Rasterimages/AndhraPradesh_Data/Data_cc/"


for in_file in in_files:
    for ik_file in sd_files:
        one = os.path.basename(in_file)
        on = one.rsplit('_',2)
        two = os.path.basename(ik_file)
        tw = two.rsplit('_',2)
        if(on[0] == tw[0]):
           r_band = raster.ReadRaster(ik_file)
           data = r_band.data
           #data1 = r_band.astype(np.uint8)
           for i in range(len(data)):
               for j in range(len(data[0])):
                   if(data[i,j]>3000):
                      data[i,j] = np.nan
                   else:
                      data[i,j] = data[i,j]
          
           sd_file = os.path.join(sd_datacc, os.path.basename(ik_file))
           r_band_cc = raster.Raster(data, extent=r_band.extent, projection=r_band.projection)
           raster.WriteRaster(r_band_cc, sd_file)
           print(sd_file)                          
        else:
           print('file not matched')
import cv2
import argparse
import os
from apya import raster
import matplotlib.pyplot as plt



#destination folder
sd_dir = '/home/pavithra/Desktop/New_test_folder/Canny_level2_outputs/'

#input image
image = '/home/pavithra/Desktop/Rasterimages/Test_pixel/T44QND_20190317T045659_B03_10m.tif'

#Reading the raster data
read_rast = raster.ReadRaster(image)
data_canni = read_rast.data

img = cv2.imread(image,cv2.IMREAD_UNCHANGED)
img = (img).astype(np.uint8)
print(type(img))

canny = cv2.Canny(img,100,200)

print(canny)



titles = ['Band-8', 'Output']

images = [img, (canny)]