7 from netCDF4
import Dataset
9 __version__ =
'1.1.0_2019-10-28'
12 merged = [
None]*(len(lons)+len(lats))
19 for element
in merged:
25 gPolygon = gPolygon + delimiter +
str(element)
27 gPolygon = gPolygon +
',' +
str(merged[0]) +
' ' +
str(merged[1])
33 '''This method writes the xml metadata for the GIBS imagery'''
35 productionTime = datetime.datetime.utcnow().strftime(
'%Y-%m-%dT%H:%M:%SZ')
36 xmlbody =
'''<ImageryMetadata
37 xmlns="http://www.w3.org/2005/Atom"
38 xmlns:georss="http://www.georss.org/georss/10">
39 <ProviderProductId>%s</ProviderProductId>
40 <ProductionDateTime>%s</ProductionDateTime>
41 <DataStartDateTime>%s</DataStartDateTime>
42 <DataEndDateTime>%s</DataEndDateTime>
45 ''' % (path.basename(browseFileName),
48 stoptime,datadays[0].strftime(
"%Y%j"))
72 Write XML metadata file for GIBS browse imagery
74 parser = argparse.ArgumentParser(description=\
75 'Generate XML metadata file for GIBS browse imagery')
76 parser.add_argument(
'--version', action=
'version', version=
'%(prog)s ' + __version__)
77 parser.add_argument(
'-i',
'--input_file', type=str, required=
True)
78 parser.add_argument(
'-t',
'--tiff_file', type=str, required=
True)
79 parser.add_argument(
'-o',
'--output_file', type=str)
80 parser.add_argument(
'-d',
'--datadays', nargs=
'+', type=str, help=
"dataday(s) in YYYDDD or YYYY-MM-DD format")
81 parser.add_argument(
'-v',
'--verbose', action=
'store_true')
83 args = parser.parse_args()
85 rootgrp = Dataset(args.input_file,
"r", format=
"NETCDF4")
86 starttime = rootgrp.getncattr(
"time_coverage_start")
87 stoptime = rootgrp.getncattr(
"time_coverage_end")
95 for dataday
in args.datadays:
97 datadays.append(datetime.datetime.strptime(dataday,
"%Y%j"))
98 elif len(dataday) == 10:
99 datadays.append(datetime.datetime.strptime(dataday,
"%Y-%m-%d"))
101 print(
"Could not parse data day: %s" % dataday)
104 datadays.append(datetime.datetime.strptime(starttime[:10],
"%Y-%m-%d"))
106 outputFile = args.tiff_file +
'.xml'
108 outputFile = args.output_file
111 print(
"StartTime: %s" % starttime)
112 print(
"StopTime: %s" % stoptime)
113 print(
"Input file: %s" % args.input_file)
114 print(
"TIFF file: %s" % args.tiff_file)
115 print(
"Output file: %s" % outputFile)
116 for cnt,dataday
in enumerate(datadays):
117 print(
"DataDay[%d]: %s" % (cnt,dataday.strftime(
"%Y%j")))
124 xmlfile = open(outputFile,
'w')
125 xmlfile.write(xmlbody)
129 print(
"XML for %s:" % outputFile)
133 if __name__ ==
'__main__':