Esempio n. 1
0
from spi import SPI
import numpy as np
import os, random
from PIL import Image
import time
import gdal
import osr
from math import isnan

spi = SPI()
    
spi.set_rolling_window_params(
    span=1, window_type=None, center=True)

    # Set distribution parameters
spi.set_distribution_params(dist_type='gam')


def use_spi(arr: np.array) -> np.array:

    
    data = spi.calculate(arr, starting_month=1)
    data = data.flatten()    
    #Calculate and return 1d array
    return data



directory_name = "C:\\Users\\anind\\SpiCalc\\data"
def tiffolder_to_3darr(directory_name) -> np.array:
    '''Returns a 3d array from a directory containing tiff images of
Esempio n. 2
0

if __name__ == '__main__':
    # Read precip data from csv
    crnt_path = os.path.dirname(os.path.abspath(__file__))
    precip_file = os.path.join(crnt_path, '..', 'data', 'rainfall_test.csv')
    rainfall_data = np.genfromtxt(precip_file, delimiter=',')

    # Initialize SPI class
    spi = SPI()

    # Set rolling window parameters
    spi.set_rolling_window_params(span=1, window_type=None, center=True)

    # Set distribution parameters
    spi.set_distribution_params(dist_type='gengamma')

    # Calculate SPI
    data = spi.calculate(rainfall_data, starting_month=1)

    # Create date list for plotting
    n_dates = np.shape(data)[0]
    date_list = create_datelist(dt.date(2000, 1, 1), n_dates)

    # Plot SPI
    plot_index(date_list, data)
    print np.squeeze(data)

    # Test find best distribution fit
    dist_list = ['gamma', 'gengamma', 'fisk', 'dweibull', 'logistic']