Exemple #1
0
subprocess.check_call('ncatted -a units,smb,o,c,"kg m-2 year-1" ' +
                      output_file,
                      shell=True)
#subprocess.check_call('ncatted -a units,precip,o,c,"kg m-2 year-1" '+output_file,shell=True)

# rename variables
subprocess.check_call("ncrename -v tskin,ice_surface_temp -O " + output_file +
                      " " + output_file,
                      shell=True)
subprocess.check_call("ncrename -v smb,climatic_mass_balance -O " +
                      output_file + " " + output_file,
                      shell=True)
#subprocess.check_call("ncrename -v t2m,air_temp -O "+output_file+" "+output_file,shell=True)
#subprocess.check_call("ncrename -v precip,precipitation -O "+output_file+" "+output_file,shell=True)

subprocess.check_call('ncks -O -C -x -v lon_2,lat_2,lon_3,lat_3 ' +
                      output_file + " " + output_file,
                      shell=True)
#RACMO grid actually comes on a lon lat coordinate, so multipliaction here provides values close to meters, but this is not important here
subprocess.check_call("ncap2 -O -s 'x=x*1.0e5;y=y*1.0e5' " + output_file +
                      " " + output_file,
                      shell=True)
#subprocess.check_call("ncks -C -O -x -v lon,lat "+output_file+" "+output_file,shell=True)

# prepare the input file for cdo remapping
# this step takes a while for high resolution data (i.e. 1km)
pi.prepare_ncfile_for_cdo(output_file)

print " RACMO file", output_file, "successfully preprocessed."
Exemple #2
0
import os, sys
import numpy as np
import sys
import netCDF4 as nc
import datetime
import subprocess

## this hack is needed to import config.py from the project root
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if project_root not in sys.path: sys.path.append(project_root)
import config as cf
reload(cf)
import pism_input.pism_input as pi
reload(pi)

bedmachine_data_path = os.path.join(cf.output_data_path, "bedmachine")
ncout_name = os.path.join(bedmachine_data_path,
                          filename + "_ReadyForRemapping.nc")

print "Prepare for cdo " + ncout_name
pi.prepare_ncfile_for_cdo(ncout_name)
Exemple #3
0
reload(cf)
import pism_input.pism_input as pi

reload(pi)

dataset = "accum"

# conservative regridding for bedmap2 and albmap data. does
# not yet work for the other datasets.
use_conservative_regridding = True

data_path = os.path.join(cf.output_data_path, dataset)

# prepare the input file for cdo remapping
# this step takes a while for high resolution data (i.e. 1km)
inputfile = os.path.join(data_path, 'accum_1km_input.nc')
pi.prepare_ncfile_for_cdo(inputfile)

cdo_targetgrid_file, regridded_file = pi.get_filenames_for_cdo(
    cf.cdo_remapgridpath, data_path, dataset, cf.grid_id)

# Create a bash script that handles the regridding.
# Regridding can be a CPU-heavy task. Choose cluster_regridding=True in config.py
# If you want to submit to the cluster using SLURM.
# use 'sbatch cdo_remap.sh' to submit your job.
# Conservative regridding does not work for all datasets yet, use it for bedmap2 or albmap.
# We use cdo, see https://code.zmaw.de/projects/cdo/embedded/index.html
pi.write_regrid_command_file(cf, data_path, dataset, inputfile, cf.grid_id,
                             cdo_targetgrid_file, regridded_file,
                             use_conservative_regridding)
Exemple #4
0
# import datetime, math
import os, sys
import subprocess
import netCDF4 as nc

## this hack is needed to import config.py from the project root
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if project_root not in sys.path: sys.path.append(project_root)
import config as cf; reload(cf)
import pism_input.pism_input as pi; reload(pi)

dataset = "tillphi_pism"

data_path = os.path.join(cf.output_data_path, dataset)
if not os.path.exists(data_path): os.makedirs(data_path)

savefile = os.path.join(data_path, dataset)+".nc"

subprocess.check_call("ncks -O -4 -v tillphi "+cf.tillphi_data_path+" "+
                      os.path.join(data_path,dataset+"temp.nc"),shell=True)
# ncks -O -4 -v tillphi cf.tillphi_data_path tillphi_15km.nc
subprocess.check_call('ncap2 -O -s "lon_bnds=double(lon_bnds);lat_bnds=double(lat_bnds)" '+
                      os.path.join(data_path,dataset+"temp.nc")+" "+
                      savefile,shell=True)

subprocess.check_call('ncatted -O -a reference,tillphi,c,c,"optimized till friction angle as described in Albrecht et al., 2020a, https://doi.org/10.5194/tc-14-599-2020" '+ 
                        savefile, shell=True)


pi.prepare_ncfile_for_cdo(os.path.join(data_path,dataset+".nc"))
ncbhflxu = wrtfile.createVariable('bheatflx_uncertainty',
                                  'f4', ('y', 'x'),
                                  fill_value=fillvalue)

ncbhflx[:] = bheatflx
ncbhflx.long_name = "geothermal heat flux - Martos et al., 2017"
ncbhflx.units = "W m-2"
ncbhflx.source = data_file + " downloaded from https://doi.pangaea.de/10.1594/PANGAEA.882503"
ncbhflx.reference = "Martos, Yasmina M; Catalan, Manuel; Jordan, Tom A; Golynsky, Alexander V; Golynsky, Dmitry A; Eagles, Graeme; Vaughan, David G (accepted): Heat flux distribution of Antarctica unveiled. Geophysical Research Letters, https://doi.org/10.1002/2017GL075609"
ncbhflx.missing_value = fillvalue

ncbhflxu[:] = bheatflxu
ncbhflxu.units = ncbhflx.units
ncbhflx.long_name = "uncertainty of " + ncbhflx.long_name

ncx[:] = x_new
ncy[:] = y_new
ncx.units = "meters"
ncy.units = "meters"

wrtfile.proj4 = cf.proj4str

wrtfile.close()

# prepare the input file for cdo remapping
# this step takes a while for high resolution data (i.e. 1km)
pi.prepare_ncfile_for_cdo(final_filename)
#subprocess.check_call('python ../tools/nc2cdo.py '+final_filename,shell=True)

print 'Data successfully saved to', final_filename
Exemple #6
0
"""
Create grids based on the ALBMAP dimensions, that are compatible with PISM.
That means, if they are fed into PISM, PISM will not need to regrid internally.
The here created grids are used as input for the cdo remapping, which is done
for each dataset separately. See for example bedmap2/remap.py

"""

import os, sys
import numpy as np
from pyproj import Proj
import netCDF4

## this hack is needed to import config.py from the project root
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
if project_root not in sys.path: sys.path.append(project_root)
import config as cf
reload(cf)
import pism_input.pism_input as pi
reload(pi)

if __name__ == "__main__":

    for name, grid in cf.grids.iteritems():
        #if "initmip" not in name: continue
        # cdo_targetgrid_file = os.path.join(cf.cdo_remapgridpath,
        #                         'pism_'+str(int(resolution))+'km.nc')
        gridfile = pi.create_grid_for_cdo_remap(cf.cdo_remapgridpath, name,
                                                grid)
        pi.prepare_ncfile_for_cdo(gridfile)
ncv[:] = thetao
ncv = ncout.createVariable(varname="salinity_ocean",
                           datatype='float32',
                           dimensions=('y', 'x'))
ncv[:] = salinity
ncout.variables['theta_ocean'].units = "Celsius"
ncout.variables['salinity_ocean'].units = "g/kg"

basinsvar = ncout.variables['basins']
basinsvar.long_name = "drainage basins"
basinsvar.standard_name = "drainage_basins"

now = datetime.datetime.now().strftime("%B %d, %Y")
ncout.Descricption = "Antarctic drainage basins mapped by NASA and modified. Temperature (converted to potential) and salinity averaged over the basins at the depth of the continential shelf."
ncout.Reference = "Basins from Zwally, H. Jay, Mario B. Giovinetto, Matthew A. Beckley, and Jack L. Saba, 2012, Antarctic and Greenland Drainage  Systems, GSFC Cryospheric Sciences Laboratory, at http://icesat4.gsfc.nasa.gov/cryo_data/ant_grn_drainage_systems.php. Temperature, Salinity from Schmidtko, S., Heywood, K. J., Thompson, A. F., & Aoki, S. (2014). Multidecadal warming of Antarctic waters. Science, 346(6214), 1227-1231. ,at http://www.geomar.de/fileadmin/personal/fb1/po/sschmidtko/Antarctic_shelf_data.txt"
ncout.proj4 = "+lon_0=0.0 +ellps=WGS84 +datum=WGS84 +lat_ts=-71.0 +proj=stere +x_0=0.0 +units=m +y_0=0.0 +lat_0=-90.0"
ncout.comment = cf.authors + " created netcdf file at " + now

ncout.close()

## TODO: the following does not fully solve the problem for cdo merge this file with the
##       others. Should we just not put time and depth dimension in the creation of
##       the Schmidtko data at first place?
## Remove the time dimesion
#subprocess.check_call("ncwa -O -a time "+outfile+" "+outfile, shell=True)
## delete the time and the height variable
#subprocess.check_call("ncks -O -C -x -v time "+outfile+" "+outfile, shell=True)
#subprocess.check_call("ncks -O -C -x -v height "+outfile+" "+outfile, shell=True)

pi.prepare_ncfile_for_cdo(regridded_file)
Exemple #8
0
                           datatype='float32',
                           dimensions=('y', 'x'))
ncv[:] = basins

now = datetime.datetime.now().strftime("%B %d, %Y")
#ncout.created  = "created based on reese@pik at " + now
ncout.data_origin = "downloaded from http://homepages.see.leeds.ac.uk/~earkhb/Basins_page.html"
ncout.regions = "regions follow the definition of Zwally et al. 2012"
ncout.proj4 = "+lon_0=0.0 +ellps=WGS84 +datum=WGS84 +lat_ts=-71.0 +proj=stere +x_0=0.0 +units=m +y_0=0.0 +lat_0=-90.0"
ncout.comment = cf.authors + " created netcdf basins file at " + now

ncout.close()

# prepare the input file for cdo remapping
# this step takes a while for high resolution data (i.e. 1km)
pi.prepare_ncfile_for_cdo(ncout_ocean)

# print '\nPlotting... '
# fig=plt.figure()
# ax = plt.subplot(1,1,1)
# plt.contourf(basins)

# plt.contour(mask,mask_grounded,colors='gray',linewidths=2) # GROUNDING LINE
# plt.contour(mask,mask_floating,colors='gray',linewidths=2) # CALVING FRONT
# #cbar = plt.colorbar(ticks=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19])

# ax.set_xticks([])
# ax.set_yticks([])
# p.axis('equal')

# #plt.show()