Ejemplo n.º 1
0
def info(input, to_json):
    """Dataset info."""
    metadata = cog_info(input)

    if to_json:
        click.echo(json.dumps(metadata))
    else:
        sep = 25
        click.echo(f"""{click.style('Driver:', bold=True)} {metadata['Driver']}
{click.style('File:', bold=True)} {metadata['Path']}
{click.style('COG:', bold=True)} {metadata['COG']}
{click.style('Compression:', bold=True)} {metadata['Compression']}
{click.style('ColorSpace:', bold=True)} {metadata['ColorSpace']}

{click.style('Profile', bold=True)}
    {click.style("Width:", bold=True):<{sep}} {metadata['Profile']['Width']}
    {click.style("Height:", bold=True):<{sep}} {metadata['Profile']['Height']}
    {click.style("Bands:", bold=True):<{sep}} {metadata['Profile']['Bands']}
    {click.style("Tiled:", bold=True):<{sep}} {metadata['Profile']['Tiled']}
    {click.style("Dtype:", bold=True):<{sep}} {metadata['Profile']['Dtype']}
    {click.style("NoData:", bold=True):<{sep}} {metadata['Profile']['Nodata']}
    {click.style("Alpha Band:", bold=True):<{sep}} {metadata['Profile']['Alpha Band']}
    {click.style("Internal Mask:", bold=True):<{sep}} {metadata['Profile']['Internal Mask']}
    {click.style("Interleave:", bold=True):<{sep}} {metadata['Profile']['Interleave']}
    {click.style("ColorMap:", bold=True):<{sep}} {metadata['Profile']['ColorMap']}
    {click.style("ColorInterp:", bold=True):<{sep}} {metadata['Profile']['ColorInterp']}
    {click.style("Scales:", bold=True):<{sep}} {metadata['Profile']['Scales']}
    {click.style("Offsets:", bold=True):<{sep}} {metadata['Profile']['Offsets']}

{click.style('Image Metadata', bold=True)}
    {create_tag_table(metadata['Tags'], sep+5)}

{click.style('Geo', bold=True)}
    {click.style("Crs:", bold=True):<{sep}} {metadata['GEO']['CRS']}
    {click.style("Origin:", bold=True):<{sep}} {metadata['GEO']['Origin']}
    {click.style("Resolution:", bold=True):<{sep}} {metadata['GEO']['Resolution']}
    {click.style("BoundingBox:", bold=True):<{sep}} {metadata['GEO']['BoundingBox']}
    {click.style("MinZoom:", bold=True):<{sep}} {metadata['GEO']['MinZoom']}
    {click.style("MaxZoom:", bold=True):<{sep}} {metadata['GEO']['MaxZoom']}"""
                   )

        click.echo(f"""
{click.style('IFD', bold=True)}
    {click.style('Id', underline=True, bold=True):<20}{click.style('Size', underline=True, bold=True):<27}{click.style('BlockSize', underline=True, bold=True):<26}{click.style('Decimation', underline=True, bold=True):<33}"""
                   )

        for ifd in metadata["IFD"]:
            wh = f"{ifd['Width']}x{ifd['Height']}"
            bl = f"{ifd['Blocksize'][1]}x{ifd['Blocksize'][0]}"
            click.echo(
                f"""    {ifd['Level']:<8}{wh:<15}{bl:<14}{ifd['Decimation']}"""
            )

        if metadata.get("COG_errors") or metadata.get("COG_warnings"):
            click.echo(f"""
{click.style('COG Validation info', bold=True)}""")
            for error in metadata.get("COG_errors", []):
                click.secho(f"""    - {error} (error)""", fg="red")
            for warning in metadata.get("COG_warnings", []):
                click.secho(f"""    - {warning} (warning)""", fg="yellow")
Ejemplo n.º 2
0
def test_info_with_metadata():
    """Make sure info returns band metadata."""
    info = cog_info(raster_band_tags)
    assert info.Band_Metadata
    assert info.dict(by_alias=True)["Band Metadata"]
    assert info.Band_Metadata["Band 1"].Description == "Green"
    assert info.Band_Metadata["Band 1"].Metadata
Ejemplo n.º 3
0
def test_cog_info():
    """Test COGEO info."""
    info = cog_info(raster_web_z5_z11)
    assert info["COG"]
    assert info["GEO"]["CRS"] == "EPSG:3857"
    assert info["GEO"]["MinZoom"] == 5
    assert info["GEO"]["MaxZoom"] == 11
    assert len(info["IFD"]) == 6
Ejemplo n.º 4
0
def test_local_filesystem():
    fs = LocalFilesystem()
    cog = _create_cog()
    fs.save(cog, path="/tmp/test-cog.tif")

    info = cog_info("/tmp/test-cog.tif")
    assert info["COG"]

    os.remove("/tmp/test-cog.tif")
Ejemplo n.º 5
0
def test_cog_info_dict_access():
    """Test dictionary access to COGEO info."""
    info = cog_info(raster_web_z5_z11)
    assert info["COG"]
    assert info["GEO"]["CRS"] == "EPSG:3857"
    assert info["GEO"]["MinZoom"] == 5
    assert info["GEO"]["MaxZoom"] == 11
    assert len(info["IFD"]) == 6
    assert info["Tags"]["Image Metadata"]
    assert info["Tags"]["Image Structure"]
Ejemplo n.º 6
0
def test_cog_info():
    """Test COGEO info."""
    info = cog_info(raster_web_z5_z11)
    assert info.COG
    assert info.GEO.CRS == "EPSG:3857"
    assert info.GEO.MinZoom == 5
    assert info.GEO.MaxZoom == 11
    assert len(info.IFD) == 6
    assert info.Tags["Image Metadata"]
    assert info.Tags["Image Structure"]
Ejemplo n.º 7
0
def test_fake_cog():
    img = FakeImage(
        driver="GTiff",
        width=512,
        height=512,
        count=3,
        dtype="uint8",
        crs=CRS.from_epsg(3857),
        transform=from_origin(1470996, 6914001, 2.0, 2.0),
    )
    cog = FakeCog(
        src_img=img,
        dst_kwargs=JPEGProfile(),
    )

    info = cog_info(cog.handle.name)
    assert info["COG"]
    assert info["Compression"] == "JPEG"

    img.close()
    cog.close()
Ejemplo n.º 8
0
def info(input, to_json):
    """Dataset info."""
    metadata = cog_info(input)

    if to_json:
        click.echo(metadata.json(exclude_none=True, by_alias=True))
    else:

        sep = 25
        click.echo(f"""{click.style('Driver:', bold=True)} {metadata.Driver}
{click.style('File:', bold=True)} {metadata.Path}
{click.style('COG:', bold=True)} {metadata.COG}
{click.style('Compression:', bold=True)} {metadata.Compression}
{click.style('ColorSpace:', bold=True)} {metadata.ColorSpace}

{click.style('Profile', bold=True)}
    {click.style("Width:", bold=True):<{sep}} {metadata.Profile.Width}
    {click.style("Height:", bold=True):<{sep}} {metadata.Profile.Height}
    {click.style("Bands:", bold=True):<{sep}} {metadata.Profile.Bands}
    {click.style("Tiled:", bold=True):<{sep}} {metadata.Profile.Tiled}
    {click.style("Dtype:", bold=True):<{sep}} {metadata.Profile.Dtype}
    {click.style("NoData:", bold=True):<{sep}} {metadata.Profile.Nodata}
    {click.style("Alpha Band:", bold=True):<{sep}} {metadata.Profile.AlphaBand}
    {click.style("Internal Mask:", bold=True):<{sep}} {metadata.Profile.InternalMask}
    {click.style("Interleave:", bold=True):<{sep}} {metadata.Profile.Interleave}
    {click.style("ColorMap:", bold=True):<{sep}} {metadata.Profile.ColorMap}
    {click.style("ColorInterp:", bold=True):<{sep}} {metadata.Profile.ColorInterp}
    {click.style("Scales:", bold=True):<{sep}} {metadata.Profile.Scales}
    {click.style("Offsets:", bold=True):<{sep}} {metadata.Profile.Offsets}""")

        click.echo(f"""
{click.style('Geo', bold=True)}
    {click.style("Crs:", bold=True):<{sep}} {metadata.GEO.CRS}
    {click.style("Origin:", bold=True):<{sep}} {metadata.GEO.Origin}
    {click.style("Resolution:", bold=True):<{sep}} {metadata.GEO.Resolution}
    {click.style("BoundingBox:", bold=True):<{sep}} {metadata.GEO.BoundingBox}
    {click.style("MinZoom:", bold=True):<{sep}} {metadata.GEO.MinZoom}
    {click.style("MaxZoom:", bold=True):<{sep}} {metadata.GEO.MaxZoom}""")

        for ns, values in metadata.Tags.items():
            click.echo(f"""
{click.style(ns, bold=True)}""")
            for key, val in values.items():
                click.echo(
                    f"""    {click.style(key, underline=True, bold=True)}: {val}"""
                )

        for ns, meta in metadata.Band_Metadata.items():
            click.echo(f"""
{click.style(ns, bold=True)}""")

            if meta.Description:
                click.echo(
                    f"""    {click.style("Description", underline=True, bold=True)}: {meta.Description}"""
                )
            click.echo(
                f"""    {click.style("ColorInterp", underline=True, bold=True)}: {meta.ColorInterp}"""
            )
            if meta.Offset != 0.0 and meta.Scale != 1.0:
                click.echo(
                    f"""    {click.style("Offset", underline=True, bold=True)}: {meta.Offset}"""
                )
                click.echo(
                    f"""    {click.style("Scale", underline=True, bold=True)}: {meta.Scale}"""
                )

            if meta.Metadata:
                click.echo(
                    f"""    {click.style("Metadata", underline=True, bold=True)}:"""
                )
                for key, val in meta.Metadata.items():
                    click.echo(
                        f"""        {click.style(key, underline=True, bold=True)}: {val}"""
                    )

        click.echo(f"""
{click.style('IFD', bold=True)}
    {click.style('Id', underline=True, bold=True):<20}{click.style('Size', underline=True, bold=True):<27}{click.style('BlockSize', underline=True, bold=True):<26}{click.style('Decimation', underline=True, bold=True):<33}"""
                   )

        for ifd in metadata.IFD:
            wh = f"{ifd.Width}x{ifd.Height}"
            bl = f"{ifd.Blocksize[1]}x{ifd.Blocksize[0]}"
            click.echo(
                f"""    {ifd.Level:<8}{wh:<15}{bl:<14}{ifd.Decimation}""")

        if metadata.COG_errors or metadata.COG_warnings:
            click.echo(f"""
{click.style('COG Validation info', bold=True)}""")
            for error in metadata.COG_errors or []:
                click.secho(f"""    - {error} (error)""", fg="red")
            for warning in metadata.COG_warnings or []:
                click.secho(f"""    - {warning} (warning)""", fg="yellow")