Skip to content

Commit

Permalink
Merge pull request #12 from NASA-IMPACT/fix/L30_debug_crs
Browse files Browse the repository at this point in the history
Add CRS management for L30 debug files.
  • Loading branch information
sharkinsspatial authored Sep 21, 2022
2 parents 9a74432 + bd5c152 commit 69e524b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
8 changes: 7 additions & 1 deletion hls_hdf_to_cog/hls_hdf_to_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,13 @@ def main(input, output_dir, product, cogeo_profile, blocksize, debug_mode, creat
# TODO: add a test
if debug_mode:
metadata = src_dst.tags()
new_crs = rasterio.crs.CRS.from_string(metadata["HORIZONTAL_CS_CODE"])
if metadata.get("HORIZONTAL_CS_CODE") is None:
crs_string = metadata.get("HORIZONTAL_CS_NAME")
zone = crs_string.split(" ")[-1]
new_crs = rasterio.crs.CRS.from_dict({"proj": "utm", "zone": zone})
else:
new_crs = rasterio.crs.CRS.from_string(metadata["HORIZONTAL_CS_CODE"])

transform = rasterio.transform.from_origin(
float(metadata["ULX"]), float(metadata["ULY"]), 30, 30
)
Expand Down
13 changes: 13 additions & 0 deletions tests/test_hls_hdf_to_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,16 @@ def test_hls_hdf_to_cog_S30_debug():
outputfile = os.path.join(test_dir, "resample30m.2.tif")
with rasterio.open(outputfile, "r") as src:
assert datum_string in src.crs.to_wkt()


def test_hls_hdf_to_cog_L30_debug():
granule_basename = "gridded{}"
inputfile = os.path.join(data_dir, granule_basename.format(".hdf"))
runner = CliRunner(echo_stdin=True)
result = runner.invoke(main, [inputfile, "--output-dir", test_dir,
"--product", "L30", "--debug-mode"])
print(result.exception)
assert result.exit_code == 0
outputfile = os.path.join(test_dir, "gridded.2.tif")
with rasterio.open(outputfile, "r") as src:
assert datum_string in src.crs.to_wkt()
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
envlist = py36

[flake8]
ignore = D203
ignore = D203,C901
exclude = .git,__pycache__,docs/source/conf.py,old,build,dist,site-packages,venv,bin
max-complexity = 12
max-line-length = 120
Expand Down

0 comments on commit 69e524b

Please sign in to comment.