Exemple #1
0
def getPCFs(index, strike):
    # Get inputs
    indexlist = npzIn("data/indices/" + index + "_arrays.npz",
                      "data/indices/" + index + "_dates.npz")
    grid = readRaster("data/rma/prfgrid.tif", 1, -9999)[0]
    premiums = npzIn('data/actuarial/premium_arrays_2018.npz',
                     'data/actuarial/premium_dates_2018.npz')
    bases = npzIn('data/actuarial/base_arrays_2018.npz',
                  'data/actuarial/base_dates_2018.npz')

    # Get sample returns
    df = indexInsurance(indexlist, grid, premiums, bases,
                        2018,  # Actuarial Year
                        [1948, 2017],  # Study years
                        [1948, 2016],  # Baseline
                        1,  # Productivity
                        strike,  # Strike
                        1,  # Acres
                        1,  # Allocation
                        scale=True, plot=False)
    pcfs = df[3]
    return([indexlist, pcfs])
Exemple #2
0
os.chdir(r'C:\Users\user\Github')
sys.path.insert(0, 'PRF-ALTIND')

from functions import adjustIntervals, normalize, readRaster

# In[] Download data - Monthly values of average daily rainfall in mm
url = "ftp://ftp.cdc.noaa.gov/Datasets/cpc_us_precip/precip.V1.0.mon.mean.nc"
ncpath = "C:/Users/user/Github/data/rasters/precip.V1.0.mon.mean.nc"
tifpath = "C:/Users/user/Github/data/rasters/precip.V1.0.mon.mean.tif"
filename = os.path.basename(url)

# Download .NC from the NOAA CPC site
urllib.request.urlretrieve(url, ncpath)

# In[] Get the RMA grid for cell reference and masking out great lakes
grid, geom, proj = readRaster("data/rasters/prfgrid.tif", 1, -9999)
mask = grid * 0 + 1

raster = gdal.Open(ncpath)
arrays = [
    readRaster(tifpath, i, -9999)[0][::-1] * mask
    for i in tqdm(range(1, raster.RasterCount + 1), position=0)
]

# Assign year and month to each - starts in Jan 1948
years = [str(y) for y in range(1948, 2019)]
months = [str(m).zfill(2) for m in range(1, 13)]
dates = [[y + m for m in months] for y in years]
dates = [lst for sublst in dates for lst in sublst]
indexlist = [["NOAA_" + dates[i], arrays[i]] for i in range(len(arrays))]
Exemple #3
0
            in_path = out_path
            out_file = 'proj_' + out_file
            out_path = os.path.join(temp_folder, out_file)
            ds = gdal.Warp(out_path, in_path, dstSRS=proj)
            del ds

        # Now that we have all of the tif files, we can split them into months
        tfiles = glob(os.path.join(temp_folder, 'temp*'))
        pfiles = glob(os.path.join(temp_folder, 'proj*'))
        for f in tfiles:
            year = f[-8:-4]
            for i in range(1, 13):
                month = '{:02d}'.format(i)
                new_name = 'temp_' + year + month + '.tif'
                new_file = os.path.join(temp_folder, new_name)
                band, geom, proj = readRaster(f, i)
                band[band == 9999.] = -9999
                toRaster(band, new_file, geom, proj)

            # As we're finished we can remove the larger tifs
            os.remove(f)

        for f in pfiles:
            year = f[-8:-4]
            for i in range(1, 13):
                month = '{:02d}'.format(i)
                new_name = 'proj_temp_' + year + month + '.tif'
                new_file = os.path.join(temp_folder, new_name)
                band, geom, proj = readRaster(f, i)
                band[band > 9000.] = -9999
                toRaster(band, new_file, geom, proj)
    r'F:\data\droughtindices\pdsiz\nad83',
    r'F:\data\droughtindices\spei\nad83\1month',
    r'F:\data\droughtindices\spei\nad83\2month',
    r'F:\data\droughtindices\spei\nad83\3month',
    r'F:\data\droughtindices\spei\nad83\6month',
    r'F:\data\droughtindices\spi\nad83\1month',
    r'F:\data\droughtindices\spi\nad83\2month',
    r'F:\data\droughtindices\spi\nad83\3month',
    r'F:\data\droughtindices\spi\nad83\6month'
]

# In[]
# Okay, now we can read them in
grasslands = RasterArrays(
    r"F:\data\RPMS_RangeProd_For_Posting\tifs\nad83_lowres", -32768.)
mask, geom, proj = readRaster("F:/data/masks/nad83/mask25.tif", 1, -9999)

correlations = {}
meancorrs = {}
indexnames = []
for path in paths:
    print(path)
    # Okay now, get a drought index!
    indices = RasterArrays(path, -9999.)

    # Get name for dataframe
    indexname = indices.namedlist[0][0][:-7]
    indexnames.append(indexname)

    # Aggregate by into bi-monthly bins, then by year
    if 'noaa' in path:
Exemple #5
0
Created on Wed Aug 29 18:33:14 2018

@author: User
"""
import numpy as np
import os
import pandas as pd
import sys
import warnings
warnings.filterwarnings("ignore")
sys.path.insert(0, 'c:/Users/User/Github/PRF-ALTIND')
os.chdir('c:/Users/User/Github')
from functions import npzIn, indexInsurance, insuranceCalc, readRaster

# In[] Argument Definitions
grid, geom, proj = readRaster("data/rma/prfgrid.tif", 1, -9999)
actuarialyear = 2018
baselineyears = [1948, 2016]
studyears = [2000, 2017]
productivity = 1
strike = .8
acres = 500
allocation = .5

# In[] Testing...
# Get premium and base rates
premiums = npzIn('data/actuarial/premium_arrays_2018.npz',
                 'data/actuarial/premium_dates_2018.npz')
bases = npzIn('data/actuarial/base_arrays_2018.npz',
              'data/actuarial/base_dates_2018.npz')