forecasting/phenology/pheno_utils.py
def process_vi_files ( data_dir, fname_out, cell_size=1.5, vi="NDVI" ):
    """This function scans all the MODIS HDF files, and process them in annual
    chunks"""
    import glob
    # This globs all the files ending in HDF. I'm assuming that that's the ones
    # I want. Ok, will also do the M?D13C2 bit too...
    files = glob.glob ( "%s/M*D13C2.*.hdf" % data_dir )
    files.sort()
    files = np.array ( files )
    years = np.array( [int(s.split(".")[1][1:5]) for s in files] )
    nny = 180./cell_size
    nnx = 360./cell_size
    x_factor = cell_size/0.05 # CMG cell size is 0.05 degrees
    y_factor = cell_size/0.05 # CMG cell size is 0.05 degrees
    
    for y in np.unique ( years ):
        if y > 2000 and y < 2012:
            if not os.path.exists ( "%s_%04d.tif" % ( fname_out, y ) ):
                # 2000 only has 11 months' worth of data. Skip it
                # 2012 isn't yet finished...
                print "Doing year ", y
                
                year_sel = ( years == y )
                annual = np.zeros ( ( 12, nny, nnx ) )
                for ( i, f_in ) in enumerate ( files[ year_sel ] ):
                    annual [i, :, : ] = resample_dataset ( f_in, x_factor,\
                        y_factor )
                    print i, f_in, "Done..."
                save_raster ( "%s_%04d.tif" % ( fname_out, y ), annual, \
                        cell_size )
                print "Saved to %s_%04d.tif" % ( fname_out, y )
            
            
    print "Finished"
This function scans all the MODIS HDF files, and process them in annual
    chunks
This function scans all the MODIS HDF files, and process them in annual
chunks
This function scans all the MODIS HDF files and process them in annual chunks
def process_vi_files ( data_dir, fname_out, cell_size=1.5, vi="NDVI" ):
    import glob
    files = glob.glob ( "%s/M*D13C2.*.hdf" % data_dir )
    files.sort()
    files = np.array ( files )
    years = np.array( [int(s.split(".")[1][1:5]) for s in files] )
    nny = 180./cell_size
    nnx = 360./cell_size
    x_factor = cell_size/0.05 
    y_factor = cell_size/0.05 
    for y in np.unique ( years ):
        if y > 2000 and y < 2012:
            if not os.path.exists ( "%s_%04d.tif" % ( fname_out, y ) ):
                print "Doing year ", y
                year_sel = ( years == y )
                annual = np.zeros ( ( 12, nny, nnx ) )
                for ( i, f_in ) in enumerate ( files[ year_sel ] ):
                    annual [i, :, : ] = resample_dataset ( f_in, x_factor,\
                        y_factor )
                    print i, f_in, "Done..."
                save_raster ( "%s_%04d.tif" % ( fname_out, y ), annual, \
                        cell_size )
                print "Saved to %s_%04d.tif" % ( fname_out, y )
    print "Finished"
def process_vi_files ( data_dir , fname_out , cell_size = 1.5 , vi = "NDVI" ) : import glob files = glob . glob ( "%s/M*D13C2.*.hdf" % data_dir ) files . sort ( ) files = np . array ( files ) years = np . array ( [ int ( s . split ( "." ) [ 1 ] [ 1 : 5 ] ) for s in files ] ) nny = 180. / cell_size nnx = 360. / cell_size x_factor = cell_size / 0.05 y_factor = cell_size / 0.05 for y in np . unique ( years ) : if y > 2000 and y < 2012 : if not os . path . exists ( "%s_%04d.tif" % ( fname_out , y ) ) : print "Doing year " , y year_sel = ( years == y ) annual = np . zeros ( ( 12 , nny , nnx ) ) for ( i , f_in ) in enumerate ( files [ year_sel ] ) : annual [ i , : , : ] = resample_dataset ( f_in , x_factor , y_factor ) print i , f_in , "Done..." save_raster ( "%s_%04d.tif" % ( fname_out , y ) , annual , cell_size ) print "Saved to %s_%04d.tif" % ( fname_out , y ) print "Finished"
This function scans all the MODIS HDF files, and process them in annual
chunks
This function scans all the MODIS HDF files and process them in annual chunks
"""This function scans all the MODIS HDF files, and process them in annual
    chunks""" # This globs all the files ending in HDF. I'm assuming that that's the ones # I want. Ok, will also do the M?D13C2 bit too... # CMG cell size is 0.05 degrees # CMG cell size is 0.05 degrees # 2000 only has 11 months' worth of data. Skip it # 2012 isn't yet finished...
data_dir
fname_out
cell_size
vi