Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an option to upload the open data #247

Merged
merged 27 commits into from
Mar 20, 2024
Merged
Changes from 2 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4fc2594
add an option to upload the opendata
cirrusasf Mar 18, 2024
8af8a54
modify code style
cirrusasf Mar 18, 2024
9ad03cc
refactor the upload open data code
cirrusasf Mar 19, 2024
5a11809
modify code style
cirrusasf Mar 19, 2024
1ff4769
Apply suggestions from code review
forrestfwilliams Mar 19, 2024
af16ede
finish up code review additions
forrestfwilliams Mar 19, 2024
c584df1
mild refactor
forrestfwilliams Mar 19, 2024
587e2ce
correct one statement in process.py
cirrusasf Mar 19, 2024
b97aecd
add test functions in test_process.py
cirrusasf Mar 19, 2024
0787b01
add an example product file in tests/data
cirrusasf Mar 19, 2024
58c7c2d
re-orangenize the workflow
cirrusasf Mar 19, 2024
533eb15
Update CHANGELOG.md
cirrusasf Mar 19, 2024
cbe5d8e
clean up the code
cirrusasf Mar 19, 2024
b2527ac
Merge branch 'auto_upload_its_live_data_bucket' of github.com:ASFHyP3…
cirrusasf Mar 19, 2024
56eb37f
clean up the debug code
cirrusasf Mar 19, 2024
ce20b83
modify code style
cirrusasf Mar 19, 2024
0be1a65
modify code style
cirrusasf Mar 20, 2024
dbf5088
modify code style
cirrusasf Mar 20, 2024
deb80cf
set up access key for open data upload
forrestfwilliams Mar 20, 2024
9415247
add 4 more test cases in the test_point_to_prefix function in test_pr…
cirrusasf Mar 20, 2024
657dce3
Merge pull request #248 from ASFHyP3/access_key
forrestfwilliams Mar 20, 2024
30d6f17
change to a publish-bucket parameter to enable testing
forrestfwilliams Mar 20, 2024
cae7455
update changelog
forrestfwilliams Mar 20, 2024
61879bc
fix flake8
forrestfwilliams Mar 20, 2024
279e62f
fix flake8
forrestfwilliams Mar 20, 2024
a9260ba
Merge pull request #249 from ASFHyP3/bucket_arg
forrestfwilliams Mar 20, 2024
9ad126d
Apply suggestions from code review
cirrusasf Mar 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/hyp3_autorift/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@
'autorift_parameters/v001/autorift_landice_0120m.shp'


PLATFORM_SHORTNAME_LONGNAME_MAPPING = {
'S1': 'sentinel1',
'S2': 'sentinel2',
'L4': 'landsatOLI',
'L5': 'landsatOLI',
'L7': 'landsatOLI',
'L8': 'landsatOLI',
'L9': 'landsatOLI',
}


def get_lc2_stac_json_key(scene_name: str) -> str:
platform = get_platform(scene_name)
year = scene_name[17:21]
Expand Down Expand Up @@ -319,6 +330,42 @@ def apply_landsat_filtering(reference_path: str, secondary_path: str) \
return reference_path, reference_zero_path, secondary_path, secondary_zero_path


def get_lon_lat_from_ncfile(ncfile):
forrestfwilliams marked this conversation as resolved.
Show resolved Hide resolved
with Dataset(ncfile) as ds:
var = ds.variables['img_pair_info']
return var.latitude, var.longitude


def point_to_prefix(dir_path: str, lat: float, lon: float) -> str:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're hard-coding the prefix anyways, I think it'd be better to take platform as input and instead return the entire prefix from this function so that we'd end up calling it like:

>>> platform = get_platform(scene)
>>> lat, lon = get_lon_lat_from_ncfile(file)
>>> point_to_prefix(platform, lat, lon)
'velocity_image_pair/landsatOLI/v02/S80W100'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

"""
Returns a string (for example, N78W124) for directory name based on
granule centerpoint lat,lon
"""
NShemi_str = 'N' if lat >= 0.0 else 'S'
EWhemi_str = 'E' if lon >= 0.0 else 'W'

outlat = int(10*np.trunc(np.abs(lat/10.0)))
if outlat == 90: # if you are exactly at a pole, put in lat = 80 bin
outlat = 80

outlon = int(10*np.trunc(np.abs(lon/10.0)))

if outlon >= 180: # if you are at the dateline, back off to the 170 bin
outlon = 170

dirstring = os.path.join(dir_path, f'{NShemi_str}{outlat:02d}{EWhemi_str}{outlon:03d}')
return dirstring


def upload_opendata(product_file: str, bucket: str, scene: str):
# bucket = 's3://its-live-data'
platform_shortname = get_platform(scene)
dir_path = f'velocity_image_pair/{PLATFORM_SHORTNAME_LONGNAME_MAPPING[platform_shortname]}'
forrestfwilliams marked this conversation as resolved.
Show resolved Hide resolved
lat, lon = get_lon_lat_from_ncfile(product_file)
bucket_prefix = point_to_prefix(dir_path, lat, lon)
upload_file_to_s3(product_file, bucket, bucket_prefix)


def process(
reference: str,
secondary: str,
Expand Down Expand Up @@ -520,6 +567,7 @@ def main():
)
parser.add_argument('--bucket', help='AWS bucket to upload product files to')
parser.add_argument('--bucket-prefix', default='', help='AWS prefix (location in bucket) to add to product files')
parser.add_argument('--opendata-upload', type=bool, default=True, help="If or not upload to its-live-data bucket")
forrestfwilliams marked this conversation as resolved.
Show resolved Hide resolved
parser.add_argument('--esa-username', default=None, help="Username for ESA's Copernicus Data Space Ecosystem")
parser.add_argument('--esa-password', default=None, help="Password for ESA's Copernicus Data Space Ecosystem")
parser.add_argument('--parameter-file', default=DEFAULT_PARAMETER_FILE,
Expand All @@ -539,6 +587,10 @@ def main():

product_file, browse_file = process(g1, g2, parameter_file=args.parameter_file, naming_scheme=args.naming_scheme)

if args.opendata_upload:
bucket = 'its-live-data'
upload_opendata(product_file, bucket, args.granules[0])
jhkennedy marked this conversation as resolved.
Show resolved Hide resolved

if args.bucket:
upload_file_to_s3(product_file, args.bucket, args.bucket_prefix)
upload_file_to_s3(browse_file, args.bucket, args.bucket_prefix)
Expand Down
Loading