original_docstring: Calculate VI and add as new bands
docstring: Calculate VI and add as new bands
docstring_tokens: Calculate VI and add as new bands
code: def vegetation_idxs(img):
      "Calculate VI and add as new bands"
      e = 0.00015 # Add a small value to avoid division by zero
      im = img
      
      # Calculate the VIs - change to np functions
      ndvi = np.divide(np.subtract(im[:,:,4], im[:,:,2]), (np.add(im[:,:,4], im[:,:,2])+e))
      ndvi_re = (im[:,:,4] - im[:,:,3]) / ((im[:,:,4] + im[:,:,3]) + e)
      ndre = (im[:,:,3] - im[:,:,2]) / ((im[:,:,3] + im[:,:,3]) + e) 
      envi = ((im[:,:,4] + im[:,:,1]) - (2 * im[:,:,0])) / (((im[:,:,4] - im[:,:,1]) + (2 * im[:,:,0])) + e)
      ccci = ndvi_re / (ndvi + e)
      gndvi = (im[:,:,4] - im[:,:,1])/ ((im[:,:,4] + im[:,:,1]) + e)
      gli = ((2* im[:,:,1]) - im[:,:,0] - im[:,:,2]) / (((2* im[:,:,1]) + im[:,:,0] + im[:,:,2]) + e)
      osavi = ((im[:,:,4] - im[:,:,3])/ ((im[:,:,4] + im[:,:,3] + 0.16)) *(1 + 0.16) + e)
      
      vi_list = [ndvi, ndvi_re, ndre, envi, ccci, gndvi , gli, osavi]
      vis = np.zeros((40,40,13)) 
      
      vis_stacked = np.stack(vi_list, axis=2)
      vis[:,:,:5] = im
      vis[:,:,5:] = vis_stacked
      
      return vis
code_tokens: def vegetation_idxs ( img ) : e = 0.00015 im = img ndvi = np . divide ( np . subtract ( im [ : , : , 4 ] , im [ : , : , 2 ] ) , ( np . add ( im [ : , : , 4 ] , im [ : , : , 2 ] ) + e ) ) ndvi_re = ( im [ : , : , 4 ] - im [ : , : , 3 ] ) / ( ( im [ : , : , 4 ] + im [ : , : , 3 ] ) + e ) ndre = ( im [ : , : , 3 ] - im [ : , : , 2 ] ) / ( ( im [ : , : , 3 ] + im [ : , : , 3 ] ) + e ) envi = ( ( im [ : , : , 4 ] + im [ : , : , 1 ] ) - ( 2 * im [ : , : , 0 ] ) ) / ( ( ( im [ : , : , 4 ] - im [ : , : , 1 ] ) + ( 2 * im [ : , : , 0 ] ) ) + e ) ccci = ndvi_re / ( ndvi + e ) gndvi = ( im [ : , : , 4 ] - im [ : , : , 1 ] ) / ( ( im [ : , : , 4 ] + im [ : , : , 1 ] ) + e ) gli = ( ( 2 * im [ : , : , 1 ] ) - im [ : , : , 0 ] - im [ : , : , 2 ] ) / ( ( ( 2 * im [ : , : , 1 ] ) + im [ : , : , 0 ] + im [ : , : , 2 ] ) + e ) osavi = ( ( im [ : , : , 4 ] - im [ : , : , 3 ] ) / ( ( im [ : , : , 4 ] + im [ : , : , 3 ] + 0.16 ) ) * ( 1 + 0.16 ) + e ) vi_list = [ ndvi , ndvi_re , ndre , envi , ccci , gndvi , gli , osavi ] vis = np . zeros ( ( 40 , 40 , 13 ) ) vis_stacked = np . stack ( vi_list , axis = 2 ) vis [ : , : , : 5 ] = im vis [ : , : , 5 : ] = vis_stacked return vis
short_docstring: Calculate VI and add as new bands
short_docstring_tokens: Calculate VI and add as new bands
comment: "Calculate VI and add as new bands"$SEP$# Add a small value to avoid division by zero$SEP$# Calculate the VIs - change to np functions