-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate_dc_dataset_yaml.py
61 lines (35 loc) · 1.4 KB
/
create_dc_dataset_yaml.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# IF for some reason we have a dataset indexed into a datacube, but can't find the dataset yaml, this will create a simple one with information from datacube database.
import click
import datacube
dc = datacube.Datacube()
import yaml
# Get datasets which cover the provided region
def get_datasets(prod, x, y):
query=({'x': x,
'y': y,
'crs':"EPSG:3577",})
print("x:",x,", y:",y)
return dc.find_datasets(product=prod, **query)
def prep_metadata(ds):
meta = ds.metadata_doc
for key in meta['image']['bands'].keys():
meta['image']['bands'][key]['path'] = str(ds.local_path)
return meta
@click.command(help="Prepare metadata for indexing into a datacube.")
@click.option('--x', required=True, type=(int, int))
@click.option('--y', required=True, type=(int, int))
@click.option('--product', required=True, type=str)
@click.option('--output', required=True, help="Write dataset docs into this path",
type=click.Path(file_okay=False, exists=False, writable=True))
def main(x, y, product, output):
print("Creating dataset yamls for "+product)
datasets = get_datasets(product, x, y)
for dataset in datasets:
print(dataset)
path = dataset.local_path
out = path.name[0:-3] + ".yaml"
meta = dataset.metadata
with open(output + out, 'w') as stream:
yaml.dump(prep_metadata(dataset), stream)
if __name__ == "__main__":
main()