def run():
   parser = argparse.ArgumentParser(description='Compute monthly NDVI')
   parser.add_argument('--index_file', default='2015index.txt.gz', help='default=2015index.txt.gz  Use gs://gcp-public-data-landsat/index.csv.gz to process full dataset')
   parser.add_argument('--output_file', default='output.txt', help='default=output.txt Supply a location on GCS when running on cloud')
   parser.add_argument('--output_dir', required=True, help='Where should the ndvi images be stored? Supply a GCS location when running on cloud')
   known_args, pipeline_args = parser.parse_known_args()
 
   p = beam.Pipeline(argv=pipeline_args)
   index_file = known_args.index_file
   output_file = known_args.output_file
   output_dir = known_args.output_dir

   #lat =   4.37; lon =  -7.71  # Cape Palmas
   lat =-21.1; lon = 55.50     # Reunion Island

   # Read the index file and find the best look
   scenes = (p
      | 'read_index' >> beam.Read(beam.io.TextFileSource(index_file))
      | 'filter_scenes' >> beam.FlatMap(lambda line: filterScenes(line, lat, lon) )
      | 'least_cloudy' >> beam.CombinePerKey(clearest)
   )

   # write out info about scene
   scenes | beam.Map(lambda (yrmon, scene): scene.__dict__) | 'scene_info' >> beam.io.textio.WriteToText(output_file)

   # compute ndvi on scene
   scenes | 'compute_ndvi' >> beam.Map(lambda (yrmon, scene): ndvi.computeNdvi(scene.BASE_URL, output_dir))

   p.run()
Exemple #2
0
def run():
    import os
    parser = argparse.ArgumentParser(description='Compute monthly NDVI')
    parser.add_argument(
        '--index_file',
        default='2015index.txt.gz',
        help=
        'default=2015.txt.gz ... gs://cloud-training-demos/landsat/2015index.txt.gz  Use gs://gcp-public-data-landsat/index.csv.gz to process full dataset'
    )
    parser.add_argument(
        '--output_file',
        default='output.txt',
        help='default=output.txt Supply a location on GCS when running on cloud'
    )
    parser.add_argument(
        '--output_dir',
        required=True,
        help=
        'Where should the ndvi images be stored? Supply a GCS location when running on cloud'
    )
    known_args, pipeline_args = parser.parse_known_args()

    p = beam.Pipeline(argv=pipeline_args)
    index_file = known_args.index_file
    output_file = known_args.output_file
    output_dir = known_args.output_dir

    lat = -21.1
    lon = 55.50  # center of Reunion Island
    dlat = 0.4
    dlon = 0.4

    # Read the index file and find all scenes that cover this area
    allscenes = (p
                 |
                 'read_index' >> beam.Read(beam.io.TextFileSource(index_file))
                 | 'to_scene' >> beam.Map(lambda line: SceneInfo(line))
                 | 'by_area' >> beam.FlatMap(lambda scene: filterByArea(
                     scene, lat + dlat, lon - dlon, lat - dlat, lon + dlon)))

    # for each month and spacecraft-coverage-pattern (given by the path and row), find clearest scene
    scenes = (
        allscenes
        |
        'cov_month' >> beam.Map(lambda scene: (scene.month_path_row(), scene))
        | 'least_cloudy' >> beam.CombinePerKey(clearest)
        |
        'yrmon-scene' >> beam.Map(lambda (key, scene): (scene.yrmon(), scene)))

    # write out info about scene
    scenes | beam.Map(
        lambda (yrmon, scene): '{}: {}'.format(yrmon, scene.SCENE_ID)
    ) | 'scene_info' >> beam.io.textio.WriteToText(output_file)

    # compute ndvi on scene
    scenes | 'compute_ndvi' >> beam.Map(lambda (yrmon, scene): ndvi.computeNdvi(
        scene.BASE_URL, os.path.join(output_dir, yrmon), scene.SPACECRAFT_ID))

    p.run()
def run():
   import os
   parser = argparse.ArgumentParser(description='Compute monthly NDVI')
   parser.add_argument('--index_file', default='2015index.txt.gz', help='default=2015.txt.gz ... gs://cloud-training-demos/landsat/2015index.txt.gz  Use gs://gcp-public-data-landsat/index.csv.gz to process full dataset')
   parser.add_argument('--output_file', default='output.txt', help='default=output.txt Supply a location on GCS when running on cloud')
   parser.add_argument('--output_dir', required=True, help='Where should the ndvi images be stored? Supply a GCS location when running on cloud')
   known_args, pipeline_args = parser.parse_known_args()
 
   p = beam.Pipeline(argv=pipeline_args)
   index_file = known_args.index_file
   output_file = known_args.output_file
   output_dir = known_args.output_dir

   lat =-21.1; lon = 55.50     # center of Reunion Island
   dlat = 0.4; dlon = 0.4

   # Read the index file and find all scenes that cover this area
   allscenes = (p
      | 'read_index' >> beam.io.ReadFromText(index_file)
      | 'to_scene' >> beam.Map(lambda line:  SceneInfo(line))
      | 'by_area' >> beam.FlatMap(lambda scene: filterByArea(scene,lat+dlat,lon-dlon,lat-dlat,lon+dlon) )
   )

   # for each month and spacecraft-coverage-pattern (given by the path and row), find clearest scene
   scenes = (allscenes
      | 'cov_month' >> beam.Map(lambda scene: (scene.month_path_row(), scene))
      | 'least_cloudy' >> beam.CombinePerKey(clearest)
      | 'yrmon-scene' >> beam.Map(lambda (key,scene): (scene.yrmon(), scene))
   )

   # write out info about scene
   scenes | beam.Map(lambda (yrmon, scene): '{}: {}'.format(yrmon,scene.SCENE_ID)) | 'scene_info' >> beam.io.WriteToText(output_file)

   # compute ndvi on scene
   scenes | 'compute_ndvi' >> beam.Map(lambda (yrmon, scene): ndvi.computeNdvi(scene.BASE_URL, os.path.join(output_dir,yrmon), scene.SPACECRAFT_ID))

   p.run()