Created
April 17, 2015 14:26
-
-
Save lukecampbell/51278b589b64ea6e222b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
diff --git a/migrations/2015-04-17-metadata.py b/migrations/2015-04-17-metadata.py | |
new file mode 100644 | |
index 0000000..622dfac | |
--- /dev/null | |
+++ b/migrations/2015-04-17-metadata.py | |
@@ -0,0 +1,32 @@ | |
+#!/usr/bin/env python | |
+''' | |
+migrations/2015-04-17-metadata.py | |
+ | |
+Migration to update the metadata for existing netCDF files to include the new comments, acknowledgements etc. | |
+''' | |
+ | |
+from netCDF4 import Dataset | |
+from glob import glob | |
+import os | |
+ | |
+ | |
+def apply_metadata(nc): | |
+ nc.setncattr("creator_email", "[email protected]") | |
+ nc.setncattr("creator_url", "http://www.lre.usace.army.mil/Missions/GreatLakesInformation/GreatLakesWaterLevels.aspx") | |
+ nc.setncattr("acknowledgement", 'Daily mean Great Lakes water levels are harvested from the Great Lakes Water Level reports (link) on the Great Lakes Information pages (link) maintained by the Detroit District of the US Army Corps of Engineers (link). The mean water levels for each of the Great Lakes is calculated from individual water level sensors according to guidance provided by the Coordinating Committee on Great Lakes Basic Hydraulic and Hydrologic Data.') | |
+ nc.setncattr('institution', 'US Army Corps of Engineers') | |
+ nc.setncattr('comment', 'These data are harvested with permission from the U.S. Army Corps of Engineers\' Great Lakes Water Levels Reports. (link to http://www.lre.usace.army.mil/Missions/GreatLakesInformation/GreatLakesWaterLevels/CurrentConditions.aspx)') | |
+ | |
+ | |
+def main(args): | |
+ | |
+ for path in glob(os.path.join(args.path, '**/*.nc')): | |
+ with Dataset(path, 'r+') as nc: | |
+ apply_metadata(nc) | |
+ | |
+if __name__ == '__main__': | |
+ from argparse import ArgumentParser | |
+ parser = ArgumentParser(description="Migration script to apply new metadata to the GLOS Water Levels datasets") | |
+ parser.add_argument('path', help='Path to the root dataset directory containing all the netCDF files') | |
+ args = parser.parse_args() | |
+ main(args) | |
diff --git a/waterlevels/glos.py b/waterlevels/glos.py | |
index a3126eb..ab9ceb1 100644 | |
--- a/waterlevels/glos.py | |
+++ b/waterlevels/glos.py | |
@@ -293,6 +293,12 @@ def ncCreate(pageno, report_path): | |
nc.setncattr("time_coverage_start", (time_list[0])) | |
nc.setncattr("time_coverage_end", (time_list[-1])) | |
#nc.setncattr("time_coverage_duration", time_list[0]-time_list[-1]) | |
+ nc.setncattr("creator_email", "[email protected]") | |
+ nc.setncattr("creator_url", "http://www.lre.usace.army.mil/Missions/GreatLakesInformation/GreatLakesWaterLevels.aspx") | |
+ nc.setncattr("acknowledgement", 'Daily mean Great Lakes water levels are harvested from the Great Lakes Water Level reports (link) on the Great Lakes Information pages (link) maintained by the Detroit District of the US Army Corps of Engineers (link). The mean water levels for each of the Great Lakes is calculated from individual water level sensors according to guidance provided by the Coordinating Committee on Great Lakes Basic Hydraulic and Hydrologic Data.') | |
+ nc.setncattr('institution', 'US Army Corps of Engineers') | |
+ nc.setncattr('comment', 'These data are harvested with permission from the U.S. Army Corps of Engineers\' Great Lakes Water Levels Reports. (link to http://www.lre.usace.army.mil/Missions/GreatLakesInformation/GreatLakesWaterLevels/CurrentConditions.aspx)') | |
+ | |
nc.setncattr("time_coverage_resolution", "0") | |
nc.setncattr("Conventions", "CF-1.6") | |
#nc.setncattr("date_created", datetime.utcnow().strftime("%Y-%m-%dT%H:%M:00Z")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment