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

Added a working script for snow class upload, working on #5 #12

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions scripts/download/nsidc_sources.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ https://n5eil01u.ecs.nsidc.org/SNOWEX/SNEX20_BSU_GPR.001/
https://n5eil01u.ecs.nsidc.org/SNOWEX/SNEX20_GM_SP.001/
https://n5eil01u.ecs.nsidc.org/SNOWEX/SNEX20_SMP.001/
https://n5eil01u.ecs.nsidc.org/SNOWEX/SNEX20_SD.001/
https://daacdata.apps.nsidc.org/pub/DATASETS/nsidc0768_global_seasonal_snow_classification_v01/SnowClass_NA_300m_10.0arcsec_2021_v01.0.tif
54 changes: 54 additions & 0 deletions scripts/upload/add_snow_classification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""
Upload the snow classification data from
Liston, G. E. and M. Sturm. 2021

# To run with all the scripts
python run.py

# To run individually
python add_snow_classification.py

"""
from datetime import date
from os.path import join
from subprocess import check_output
from snowex_db.batch import UploadRasterBatch


def main():
"""
Uploader script for ASO Snow off data
"""

# Typical kwargs
kwargs = {'instrument': 'None',
'observers': 'Liston, Sturm',
'description': 'Seasonal-Snow Classification 300m cropped to Western US',
'tiled': True,
'epsg': 4326,
'no_data': 9,
'in_timezone': 'UTC',
'doi': 'https://doi.org/10.5067/99FTCYYYLAQ0',
'date': None,
'type': "snow_classification",
'units': None
}

# Directory of Cropped Snow classification
directory = '../download/data/pub/DATASETS/nsidc0768_global_seasonal_snow_classification_v01/'
original = join(directory, 'SnowClass_NA_300m_10.0arcsec_2021_v01.0.tif')
final = join(directory, 'cropped_snow_classification.tif')
# Crop the file to just the western US
cmd = f'gdalwarp -overwrite -te -125 32 -100 50 {original} {final}'
print(f'Executing {cmd}')
check_output(cmd, shell=True)
# Upload
uploader = UploadRasterBatch([final], **kwargs)
uploader.push()
errors = len(uploader.errors)
return errors


# Add this so you can run your script directly without running run.py
if __name__ == '__main__':
main()