text: #!/srv/conda/envs/notebook/bin/python3
  
  import numpy as np
  import re,h5py,pyproj
  
  
  def atl06_to_dict(filename, beam, field_dict=None, index=None, epsg=None):
      """
          Read selected datasets from an ATL06 file
  
          Input arguments:
              filename: ATl06 file to read
              beam: a string specifying which beam is to be read (ex: gt1l, gt1r, gt2l, etc)
              field_dict: A dictinary describing the fields to be read
                      keys give the group names to be read, 
                      entries are lists of datasets within the groups
              index: which entries in each field to read
              epsg: an EPSG code specifying a projection (see www.epsg.org).  Good choices are:
                  for Greenland, 3413 (polar stereographic projection, with Greenland along the Y axis)
                  for Antarctica, 3031 (polar stereographic projection, centered on the Pouth Pole)
          Output argument:
              D6: dictionary containing ATL06 data.  Each dataset in 
                  dataset_dict has its own entry in D6.  Each dataset 
                  in D6 contains a numpy array containing the 
                  data
      """
      if field_dict is None:
          field_dict={None:['latitude','longitude','h_li', 'atl06_quality_summary'],\
                      'ground_track':['x_atc','y_atc'],\
                      'fit_statistics':['dh_fit_dx', 'dh_fit_dy']}
      D={}
      file_re=re.compile('ATL06_(?P<date>\d+)_(?P<rgt>\d\d\d\d)(?P<cycle>\d\d)(?P<region>\d\d)_(?P<release>\d\d\d)_(?P<version>\d\d).h5')
      with h5py.File(filename,'r') as h5f:
          for key in field_dict:
              for ds in field_dict[key]:
                  if key is not None:
                      ds_name=beam+'/land_ice_segments/'+key+'/'+ds
                  else:
                      ds_name=beam+'/land_ice_segments/'+ds
                  if index is not None:
                      D[ds]=np.array(h5f[ds_name][index])
                  else:
                      D[ds]=np.array(h5f[ds_name])
                  if '_FillValue' in h5f[ds_name].attrs:
                      bad_vals=D[ds]==h5f[ds_name].attrs['_FillValue']
                      D[ds]=D[ds].astype(float)
                      D[ds][bad_vals]=np.NaN
      if epsg is not None:
          xy=np.array(pyproj.proj.Proj(epsg)(D['longitude'], D['latitude']))
          D['x']=xy[0,:].reshape(D['latitude'].shape)
          D['y']=xy[1,:].reshape(D['latitude'].shape)
      temp=file_re.search(filename)
      D['rgt']=int(temp['rgt'])
      D['cycle']=int(temp['cycle'])
      D['beam']=beam
      return D
  