Skip to content

Commit

Permalink
Small pipeline fixes (#72)
Browse files Browse the repository at this point in the history
* Remove default for subset

This is easy to forget and then run with subset without the intention to actually subset

* Improve file name

Closes #69

- Zero padding for counter
- v before version number
- Underscores instead of hyphon separators
- Drop hyphons from date stamp

* Bump version to 02

* Make mgrs sample file external

Closes #71

* Add date to raster metadata

Closes #70

* Improve print statement
  • Loading branch information
yellowcap authored Dec 7, 2023
1 parent 8763bb3 commit 018fcbc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
14 changes: 10 additions & 4 deletions scripts/datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,12 @@ def convert_attrs_and_coords_objects_to_str(data):


@click.command()
@click.option(
"--sample",
required=False,
default="https://clay-mgrs-samples.s3.amazonaws.com/mgrs_sample.fgb",
help="Location of MGRS tile sample",
)
@click.option(
"--index",
required=False,
Expand All @@ -414,13 +420,13 @@ def convert_attrs_and_coords_objects_to_str(data):
@click.option(
"--subset",
required=False,
default="1000,1000,2000,2000",
default=None,
help="For debugging, subset x and y to this pixel window.",
)
def main(index, subset, bucket):
print("Starting algorithm", index)
def main(sample, index, subset, bucket):
print("Starting algorithm for MGRS tile with index", index)
index = int(index)
tiles = gpd.read_file("mgrs_sample.gpkg")
tiles = gpd.read_file(sample)
tile = tiles.iloc[index]
start_year = 2017
end_year = 2023
Expand Down
Binary file removed scripts/mgrs_sample.gpkg
Binary file not shown.
11 changes: 9 additions & 2 deletions scripts/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
PIXELS_PER_TILE = TILE_SIZE * TILE_SIZE
BAD_PIXEL_MAX_PERCENTAGE = 0.3
SCL_FILTER = [0, 1, 3, 8, 9, 10]
VERSION = "01"
VERSION = "02"


def filter_clouds_nodata(tile):
Expand Down Expand Up @@ -99,11 +99,18 @@ def tiler(stack, date, mgrs, bucket):
] * (len(tile.band) - 3)

# Write tile to tempdir
name = f"{dir}/claytile-{mgrs}-{date}-{VERSION}-{counter}.tif"
name = "{dir}/claytile_{mgrs}_{date}_v{version}_{counter}.tif".format(
dir=dir,
mgrs=mgrs,
date=date.replace("-", ""),
version=VERSION,
counter=str(counter).zfill(4),
)
tile.rio.to_raster(name, compress="deflate")

with rasterio.open(name, "r+") as rst:
rst.colorinterp = color
rst.update_tags(date=date)

print(f"Syncing {dir} with s3://{bucket}/{VERSION}/{mgrs}/{date}")
subprocess.run(
Expand Down

0 comments on commit 018fcbc

Please sign in to comment.