Exemplo n.º 1
0
def chlor_a(im_fname, out_dir, alg_name):  
  # Load image
  im_dset = gdal.Open(im_fname, gdalconst.GA_ReadOnly)
  im_wl = pml_utils_io.get_ATCOR_image_wavelength(im_dset)
  
  # Process data
  if alg_name=='git':
    # Gitelson Chl-a

    # Select bands
    git_bands = [675.,695.,730.]              
    sel_band_ind,sel_band_val = pml_utils_io.select_bands(im_wl,git_bands)

    # Load bands
    im_data = pml_utils_io.get_image_raster(im_dset,sel_band_ind)

    # Interpolate Gitelson bands
    ip_fun = scipy.interpolate.interp1d(sel_band_val,im_data,axis=2,kind='linear',bounds_error=False,fill_value=-9999.)
    interp_im_data = ip_fun(git_bands)

    # Gitelson calculation for Rrs
    chla = pml_utils_wq.gitelson(interp_im_data[:,:,0], interp_im_data[:,:,1], interp_im_data[:,:,2])

  elif alg_name=='oc4':
    # OC4 Chl-a

    # Select bands
    oc4_bands = [443.,489.,510.,555.]    
    sel_band_ind,sel_band_val = pml_utils_io.select_bands(im_wl,oc4_bands)

    # Load bands
    im_data = pml_utils_io.get_image_raster(im_dset,sel_band_ind)

    # Interpolate OC4 bands
    ip_fun = scipy.interpolate.interp1d(sel_band_val,im_data,axis=2,kind='linear',bounds_error=False,fill_value=-9999.)
    interp_im_data = ip_fun(oc4_bands)

    # OC4 calculation
    chla = pml_utils_wq.oc4v6(interp_im_data[:,:,0], interp_im_data[:,:,1], interp_im_data[:,:,2], interp_im_data[:,:,3])

  else:
    print "ERROR: unknown name for chl-a algorithm ($s)"%alg_name
    raise

  
  # Apply water mask
  water_mask = pml_utils_wq.water_mask(im_dset,im_wl)
  chla[water_mask] = 0.

  # ------------------------------------------------------------------------------------------
  # Write down results
  out_fname = os.path.join(out_dir,'chl_'+alg_name+'_'+os.path.basename(im_fname))
  pml_utils_io.write_envi_image(out_fname,chla,im_dset)
Exemplo n.º 2
0
def water_mask(im_dset,im_wl):
  
  water_threshold = 800.
  #water_threshold = 0.08

  # Select bands
  bands = [875.]
  #bands = [772.]
  sel_band_ind,sel_band_val = pml_utils_io.select_bands(im_wl,bands)

  #pdb.set_trace() 

  # Load bands
  im_data = pml_utils_io.get_image_raster(im_dset,[sel_band_ind[0]])

  water_mask = np.logical_or( im_data[:,:,0]>water_threshold , im_data[:,:,0]<=0 )

  return water_mask
Exemplo n.º 3
0
def nechad_tsm(im_dset,im_wl):

  # Select bands
  tsm_bands = [710.]
  sel_band_ind,sel_band_val = pml_utils_io.select_bands(im_wl,tsm_bands)

  # Load bands
  im_data = pml_utils_io.get_image_raster(im_dset,sel_band_ind)

  # Interpolate bands
  ip_fun = scipy.interpolate.interp1d(sel_band_val,im_data,axis=2,kind='linear',bounds_error=False,fill_value=-9999.)
  interp_im_data = ip_fun(tsm_bands)

  # Calculation
  Rw710 = interp_im_data[:,:,0]*0.0001
  #Rw710 = interp_im_data[:,:,0]*1.

  Ap = 561.94
  Bp = 1.23
  Cp = 0.1892

  S = Ap*Rw710*(1-Rw710/Cp)+Bp

  return S
Exemplo n.º 4
0
def iop(im_dset,im_wl,date_time,lat,lon,water_mask):

  model_dir = os.path.dirname( os.path.realpath(__file__) ) + '/iop_model/'
  
  # ------------------------------------------
  # set model dir as your current dir
  current_dir = os.getcwd()
  os.chdir(model_dir)


  # Select bands
  bands = [412.,443.,490.,510.,555.,670.]
  sel_band_ind,sel_band_val = pml_utils_io.select_bands(im_wl,bands)

  # Load bands
  im_data = pml_utils_io.get_image_raster(im_dset,sel_band_ind)

  # Interpolate IOP bands
  ip_fun = scipy.interpolate.interp1d(sel_band_val,im_data,axis=2,kind='linear',bounds_error=False,fill_value=-9999.)
  interp_im_data = ip_fun(bands)

  # Rw calculation
  Rw = interp_im_data*0.0001

  # Calculate sun angle
  # sun_theta = `sun_angle $lat $lon $year $jday[1] $gmt`
  jday = julian(date_time.day,date_time.month,date_time.year)
  cmd_str = model_dir+'sun_angle ' + \
            str(lat) + ' ' + str(lon) + ' ' + str(date_time.year) + ' ' + str(jday) + ' ' + str(date_time.hour + date_time.minute/60.) 
  sun_theta_str = commands.getoutput(cmd_str)

  res = []
  no_data_res = ['0.0']*24


  for i in xrange(Rw.shape[0]):
    for j in xrange(Rw.shape[1]):
      if water_mask[i,j]:
        # In case of land or no data
        res.append(no_data_res)
      else:
        # Calculate iop output without noise 
        cmd_str = model_dir+'pml_iop_model_test' + \
                  ' -config '+model_dir+'config/pml_acc.cfg' + \
                  ' -sun_theta ' + sun_theta_str + \
                  ' -sen_theta ' + '0.83053' + \
                  ' -dphi '+ '1.57' + \
                  ' -rhow'
        for r in xrange(Rw.shape[2]): cmd_str = cmd_str+' '+str(Rw[i,j,r]) 

        # process and store IOP model output
        r = commands.getoutput(cmd_str)    
        rp = string.strip(r,' \t\n')   
           
        res.append(re.split('\s+',rp)) 

    print "%i/%i"%(i,Rw.shape[0])

  ares = np.array(res,dtype=float)

  a = ares[:,:6]
  ady = ares[:,6:12]
  ap = ares[:,12:18]
  bbp = ares[:,18:24]

  a_ = a.reshape((Rw.shape[0],Rw.shape[1],6))
  ady_ = ady.reshape((Rw.shape[0],Rw.shape[1],6))
  ap_ = ap.reshape((Rw.shape[0],Rw.shape[1],6))
  bbp_ = bbp.reshape((Rw.shape[0],Rw.shape[1],6))

  # return to the original working directory
  os.chdir(current_dir)

  return (a_,ady_,ap_,bbp_)