forecasting/phenology/pheno_utils.py
def save_raster ( fname_out, raster_in, cell_size, \
        driver="GTiff",dtype=gdal.GDT_Float32 ):
    """This function saves a raster to a filename. The raster must either be
    two-dimensional, or three dimensional, with the first dimension being the
    number of bands. By default, we use GeoTIFF output."""
    
    drv = gdal.GetDriverByName ( driver )
    # Get shapes
    try:
        ( n_bands, nx, ny ) = raster_in.shape
    except ValueError:
        ( nx, ny ) = raster_in.shape
        n_bands = 1
    # Create output file
    dst_ds = drv.Create ( fname_out, ny, nx, n_bands, dtype, \
            ["TFW=YES","TILED=YES","COMPRESS=LZW"] )
    dst_ds.SetGeoTransform( [-180, cell_size, 0.0, 90, 0.0, -cell_size])
    dst_ds.SetProjection ( 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84"' + \
    ',6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],' + \
    'PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",' + \
    '0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]' )

    for b in xrange ( n_bands ):
        try:
            dst_ds.GetRasterBand ( b+1 ).WriteArray ( \
                raster_in [ b, :, :].astype(np.float32) )
        except IndexError:
            dst_ds.GetRasterBand ( b+1 ).WriteArray ( \
                raster_in [ :, :].astype(np.float32) )
    dst_ds = None
This function saves a raster to a filename. The raster must either be
    two-dimensional, or three dimensional, with the first dimension being the
    number of bands. By default, we use GeoTIFF output.
This function saves a raster to a filename. The raster must either be
two-dimensional, or three dimensional, with the first dimension being the
number of bands. By default, we use GeoTIFF output.
This function saves a raster to a filename . The raster must either be two - dimensional or three dimensional with the first dimension being the number of bands . By default we use GeoTIFF output .
def save_raster ( fname_out, raster_in, cell_size, \
        driver="GTiff",dtype=gdal.GDT_Float32 ):
    drv = gdal.GetDriverByName ( driver )
    try:
        ( n_bands, nx, ny ) = raster_in.shape
    except ValueError:
        ( nx, ny ) = raster_in.shape
        n_bands = 1
    dst_ds = drv.Create ( fname_out, ny, nx, n_bands, dtype, \
            ["TFW=YES","TILED=YES","COMPRESS=LZW"] )
    dst_ds.SetGeoTransform( [-180, cell_size, 0.0, 90, 0.0, -cell_size])
    dst_ds.SetProjection ( 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84"' + \
    ',6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],' + \
    'PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",' + \
    '0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]' )
    for b in xrange ( n_bands ):
        try:
            dst_ds.GetRasterBand ( b+1 ).WriteArray ( \
                raster_in [ b, :, :].astype(np.float32) )
        except IndexError:
            dst_ds.GetRasterBand ( b+1 ).WriteArray ( \
                raster_in [ :, :].astype(np.float32) )
    dst_ds = None
def save_raster ( fname_out , raster_in , cell_size , driver = "GTiff" , dtype = gdal . GDT_Float32 ) : drv = gdal . GetDriverByName ( driver ) try : ( n_bands , nx , ny ) = raster_in . shape except ValueError : ( nx , ny ) = raster_in . shape n_bands = 1 dst_ds = drv . Create ( fname_out , ny , nx , n_bands , dtype , [ "TFW=YES" , "TILED=YES" , "COMPRESS=LZW" ] ) dst_ds . SetGeoTransform ( [ - 180 , cell_size , 0.0 , 90 , 0.0 , - cell_size ] ) dst_ds . SetProjection ( 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84"' + ',6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],' + 'PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",' + '0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]' ) for b in xrange ( n_bands ) : try : dst_ds . GetRasterBand ( b + 1 ) . WriteArray ( raster_in [ b , : , : ] . astype ( np . float32 ) ) except IndexError : dst_ds . GetRasterBand ( b + 1 ) . WriteArray ( raster_in [ : , : ] . astype ( np . float32 ) ) dst_ds = None
This function saves a raster to a filename.
This function saves a raster to a filename .
"""This function saves a raster to a filename. The raster must either be
    two-dimensional, or three dimensional, with the first dimension being the
    number of bands. By default, we use GeoTIFF output.""" # Get shapes # Create output file
fname_out
raster_in
cell_size
driver
dtype