From 651489c21aea300536640f2b55c2c89b4382f955 Mon Sep 17 00:00:00 2001 From: micah johnson Date: Thu, 7 Jul 2022 07:14:31 -0600 Subject: [PATCH 1/2] Added a working script for snow class upload, working on #5 --- scripts/upload/add_snow_classification.py | 54 +++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 scripts/upload/add_snow_classification.py diff --git a/scripts/upload/add_snow_classification.py b/scripts/upload/add_snow_classification.py new file mode 100644 index 0000000..b95d1a1 --- /dev/null +++ b/scripts/upload/add_snow_classification.py @@ -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() From 71bbff482a99bdd3dfaf60aff454be164ad9bafe Mon Sep 17 00:00:00 2001 From: micah johnson Date: Thu, 7 Jul 2022 07:21:13 -0600 Subject: [PATCH 2/2] Added nsidc url --- scripts/download/nsidc_sources.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/download/nsidc_sources.txt b/scripts/download/nsidc_sources.txt index a26501a..d1e8f51 100644 --- a/scripts/download/nsidc_sources.txt +++ b/scripts/download/nsidc_sources.txt @@ -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