-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLANDFRAC2sftlf.py
executable file
·36 lines (30 loc) · 1.34 KB
/
LANDFRAC2sftlf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
# Input: a file containing the CESM/E3SM variable LANDFRAC. This is land area fraction.
# If you don't supply the filename, this will look for a file named LANDFRAC.nc.
# Output: creates a new file, named sftlf.nc, containing the CMIP-5 variable sftlf.
# This is land area percentage.
import os, sys, argparse
import cdms2
def make_sftlf_file( infilen, outfilen ):
print 'Writing from %s to %s' % (infilen, outfilen)
# Write output in NetCDF-3 format for compatibility with Ben Santer's software:
cdms2.setNetcdf4Flag(0)
cdms2.useNetcdf3()
fi = cdms2.open( infilen )
fo = cdms2.open( outfilen, 'w' )
LANDFRAC = fi('LANDFRAC')
sftlf = LANDFRAC*100
sftlf.units = '%'
sftlf.long_name = "Percentage of surface area covered by land"
sftlf.standard_name = "land_area_fraction"
sftlf.id = 'sftlf'
fo.write( sftlf, id='sftlf' )
fo.close()
if __name__ == '__main__':
p = argparse.ArgumentParser( description="Convert LANDFRAC to sftlf in a new file" )
p.add_argument( "--infiles", dest="infiles", help="Names of input LANDFRAC files (mandatory)",
nargs='+', required=True )
args = p.parse_args(sys.argv[1:])
for infilen in args.infiles:
outfilen = os.path.basename(infilen).replace('LANDFRAC','sftlf')
make_sftlf_file( infilen, outfilen )