-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Patch download and area calculation (#275)
* Patch download and area calculation * shapefile_util codacy tweaks * extractproduct condacy fixes * update NLCD to new LULC mask * more conservative area calculation for dem chunk * catch error when old files exists for different specified products * Capture duplicates with all executables * GACOS update new format * print error when caught very simple update so that the error of why multiprocessing fails is printed to the screen * fix logging bug Co-authored-by: bbuzz31 <[email protected]>
- Loading branch information
Showing
9 changed files
with
780 additions
and
431 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env python3 | ||
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
# | ||
# Author: Simran Sangha | ||
# Copyright 2019, by the California Institute of Technology. ALL RIGHTS | ||
# RESERVED. United States Government Sponsorship acknowledged. | ||
# | ||
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
import os, os.path as op | ||
|
||
###Capture and segregate duplicate products (if applicable) | ||
def url_versions(urls, user_version, wd): | ||
"""For duplicate products (other than version number) | ||
Uses the the latest if user_version is None else use specified ver.""" | ||
if isinstance(user_version, str) and user_version.lower() == 'all': | ||
return urls | ||
|
||
url_bases = [] | ||
for url in urls: | ||
url_base = '-'.join(url.split('-')[:-1]) | ||
if not url_base in url_bases: | ||
url_bases.append(url_base) | ||
|
||
urls_final = [] | ||
for url_base in url_bases: | ||
# get the possible matches | ||
duplicates = [url for url in urls if url_base in url] | ||
if len(duplicates) == 1: | ||
urls_final.append(duplicates[0]) | ||
else: | ||
versions = [] | ||
for dupe in duplicates: | ||
ver_str = dupe.split('-')[-1] | ||
versions.append(float(ver_str.lstrip('v').rstrip('.nc'))) | ||
|
||
## default, use latest version | ||
if user_version is None: | ||
version = str(max(versions)) | ||
version = f'v{version[0]}_{version[1]}_{version[2]}.nc' | ||
else: | ||
version=f'v{user_version}.nc' | ||
|
||
urls_final.append(f'{url_base}-{version}') | ||
|
||
## move duplicates to a different folder | ||
dupe_folder = op.join(wd, 'duplicated_products') | ||
os.makedirs(dupe_folder, exist_ok=True) | ||
for dupe in duplicates: | ||
dupe_path = os.path.join(dupe_folder, os.path.basename(dupe)) | ||
wd_path = os.path.join(wd, os.path.basename(dupe)) | ||
if os.path.basename(dupe) != \ | ||
os.path.basename(urls_final[-1]) and \ | ||
os.path.exists(wd_path): | ||
os.rename(wd_path, dupe_path) | ||
return urls_final |
Oops, something went wrong.