Esempio n. 1
0
def orthorectify(dem_path=None,
                 geoid_path=None,
                 spacing=None,
                 create_options=[],
                 *,
                 src_path,
                 dst_path):
    spacing_opt = ""
    if spacing:
        spacing_opt = "-opt.gridspacing {spacing}".format(spacing=spacing)
    create_opt = ''
    if create_options:
        create_opt = '&'.join('gdal:co:{}'.format(opt)
                              for opt in create_options)
    base_cmd = """otbcli_OrthoRectification \
      -io.in \"{src}?{create_opt}&skipcarto=true\" \
      -io.out {dst} uint16 \
      -outputs.mode auto \
      -elev.geoid {geoid_path} \
      -elev.dem {dem_path} \
      {spacing_opt}
    """

    if not geoid_path:
        geoid_path = GEOID_PATH
    if not dem_path:
        dem_path = DEM_PATH

    cmd = base_cmd.format(src=src_path,
                          dst=dst_path,
                          geoid_path=geoid_path,
                          dem_path=dem_path,
                          spacing_opt=spacing_opt,
                          create_opt=create_opt)
    run_otb_command(cmd)
Esempio n. 2
0
def calibrate(*, src_path, dst_path, metadata_path, create_options=[]):
    create_opt = ''
    if create_options:
        create_opt = '&'.join('gdal:co:{}'.format(opt)
                              for opt in create_options)
    base_cmd = """otbcli_OpticalCalibration \
      -in {src} \
      -out "{dst}?{create_opt}" uint16 \
      -milli true \
      -level toa \
      -acqui.minute {minute} \
      -acqui.hour {hour} \
      -acqui.day {day} \
      -acqui.month {month} \
      -acqui.year {year} \
      -acqui.sun.elev {sun_elev} \
      -acqui.sun.azim {sun_azim} \
      -acqui.view.elev {view_elev} \
      -acqui.view.azim {view_azim} \
      -acqui.gainbias {gainbias_path} float \
      -acqui.solarilluminations {solarillum_path} float
    """
    metadata = extract_calibration_metadata(metadata_path)

    gf = tempfile.NamedTemporaryFile(suffix='.txt', delete=False)
    for k in ('gains', 'biases'):
        line = "{}\n".format(" : ".join(str(v) for v in metadata[k]))
        gf.write(line.encode())
    gf.close()

    sf = tempfile.NamedTemporaryFile(suffix='.txt', delete=False)
    line = "{}\n".format(" : ".join(
        str(v) for v in metadata['solar_irradiances']))
    sf.write(line.encode())
    sf.close()

    cmd = base_cmd.format(src=src_path,
                          dst=dst_path,
                          gainbias_path=gf.name,
                          solarillum_path=sf.name,
                          create_opt=create_opt,
                          **metadata)
    run_otb_command(cmd)

    os.unlink(gf.name)
    os.unlink(sf.name)
Esempio n. 3
0
def orthorectify(dem_path=None, geoid_path=None, *, src_path, dst_path):
    base_cmd = """otbcli_OrthoRectification \
      -io.in \"{src}?&skipcarto=true\" \
      -io.out {dst} uint16 \
      -outputs.mode auto \
      -elev.geoid {geoid_path} \
      -elev.dem {dem_path}
    """

    if not geoid_path:
        geoid_path = GEOID_PATH
    if not dem_path:
        dem_path = DEM_PATH

    cmd = base_cmd.format(src=src_path,
                          dst=dst_path,
                          geoid_path=geoid_path,
                          dem_path=dem_path)
    run_otb_command(cmd)
Esempio n. 4
0
def pansharpen(inp, inxs, out):
    base_cmd = 'otbcli_BundleToPerfectSensor -inp {inp} ' \
        '-inxs {inxs} ' \
        '-out "{out}" uint16'
    run_otb_command(base_cmd.format(inp=inp, inxs=inxs, out=out))