本文整理汇总了Python中netCDF4.Dataset.proj4方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.proj4方法的具体用法?Python Dataset.proj4怎么用?Python Dataset.proj4使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类netCDF4.Dataset
的用法示例。
在下文中一共展示了Dataset.proj4方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: asctime
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import proj4 [as 别名]
var_out.units = "degrees_north"
var_out.valid_range = -90.0, 90.0
var_out.standard_name = "latitude"
var_out[:] = lat
var = "dummy"
var_out = nc.createVariable(var, "f", dimensions=("y", "x"), fill_value=-9999)
var_out.units = "meters"
var_out.long_name = "Just A Dummy"
var_out.comment = "This is just a dummy variable for CDO."
var_out.grid_mapping = "mapping"
var_out.coordinates = "lon lat"
var_out[:] = 0.0
mapping = nc.createVariable("mapping", "c")
mapping.ellipsoid = "WGS84"
mapping.false_easting = 0.0
mapping.false_northing = 0.0
mapping.grid_mapping_name = "polar_stereographic"
mapping.latitude_of_projection_origin = 90.0
mapping.standard_parallel = 70.0
mapping.straight_vertical_longitude_from_pole = -45.0
from time import asctime
historystr = "Created " + asctime() + "\n"
nc.history = historystr
nc.proj4 = projection
nc.Conventions = "CF-1.5"
nc.close()
示例2: create_searise_grid
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import proj4 [as 别名]
#.........这里部分代码省略.........
for corner in range(0, grid_corners):
## grid_corners in x-direction
gc_easting[:, corner] = easting + de_vec[corner]
# grid corners in y-direction
gc_northing[:, corner] = northing + dn_vec[corner]
# meshgrid of grid corners in x-y space
gc_ee, gc_nn = np.meshgrid(
gc_easting[:, corner], gc_northing[:, corner])
# project grid corners from x-y to lat-lon space
gc_lon[:, :, corner], gc_lat[:, :, corner] = proj(
gc_ee, gc_nn, inverse=True)
nc = CDF(filename, 'w', format=fileformat)
nc.createDimension(xdim, size=easting.shape[0])
nc.createDimension(ydim, size=northing.shape[0])
var = xdim
var_out = nc.createVariable(var, 'f', dimensions=(xdim))
var_out.axis = xdim
var_out.long_name = "X-coordinate in Cartesian system"
var_out.standard_name = "projection_x_coordinate"
var_out.units = "meters"
var_out[:] = easting
var = ydim
var_out = nc.createVariable(var, 'f', dimensions=(ydim))
var_out.axis = ydim
var_out.long_name = "Y-coordinate in Cartesian system"
var_out.standard_name = "projection_y_coordinate"
var_out.units = "meters"
var_out[:] = northing
var = 'lon'
var_out = nc.createVariable(var, 'f', dimensions=(ydim, xdim))
var_out.units = "degrees_east"
var_out.valid_range = -180., 180.
var_out.standard_name = "longitude"
var_out.bounds = "lon_bnds"
var_out[:] = lon
var = 'lat'
var_out = nc.createVariable(var, 'f', dimensions=(ydim, xdim))
var_out.units = "degrees_north"
var_out.valid_range = -90., 90.
var_out.standard_name = "latitude"
var_out.bounds = "lat_bnds"
var_out[:] = lat
nc.createDimension(grid_corner_dim_name, size=grid_corners)
var = 'lon_bnds'
# Create variable 'lon_bnds'
var_out = nc.createVariable(
var, 'f', dimensions=(ydim, xdim, grid_corner_dim_name))
# Assign units to variable 'lon_bnds'
var_out.units = "degreesE"
# Assign values to variable 'lon_nds'
var_out[:] = gc_lon
var = 'lat_bnds'
# Create variable 'lat_bnds'
var_out = nc.createVariable(
var, 'f', dimensions=(ydim, xdim, grid_corner_dim_name))
# Assign units to variable 'lat_bnds'
var_out.units = "degreesN"
# Assign values to variable 'lat_bnds'
var_out[:] = gc_lat
var = 'dummy'
var_out = nc.createVariable(
var,
'f',
dimensions=(
"y",
"x"),
fill_value=-2e9)
var_out.units = "meters"
var_out.long_name = "Just A Dummy"
var_out.comment = "This is just a dummy variable for CDO."
var_out.grid_mapping = "mapping"
var_out.coordinates = "lon lat"
var_out[:] = 0.
mapping = nc.createVariable("mapping", 'c')
mapping.ellipsoid = "WGS84"
mapping.false_easting = 0.
mapping.false_northing = 0.
mapping.grid_mapping_name = "polar_stereographic"
mapping.latitude_of_projection_origin = 90.
mapping.standard_parallel = 71.
mapping.straight_vertical_longitude_from_pole = -39.
from time import asctime
historystr = 'Created ' + asctime() + '\n'
nc.history = historystr
nc.proj4 = projection
nc.Conventions = 'CF-1.5'
nc.close()
示例3: list
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import proj4 [as 别名]
for var in list(nc.variables.keys()):
if (nc.variables[var].ndim >= 2):
nc.variables[var].coordinates = "lon lat"
# lat/lon coordinates must not have mapping and coordinate attributes
# if they exist, delete them
for var in ['lat', 'lon', 'lat_bnds', 'lon_bnds']:
if hasattr(nc.variables[var], 'grid_mapping'):
delattr(nc.variables[var], 'grid_mapping')
if hasattr(nc.variables[var], 'coordinates'):
delattr(nc.variables[var], 'coordinates')
# If present prepend history history attribute, otherwise create it
from time import asctime
histstr = asctime() + \
' : grid info for CDO added by nc2cdo.py, a PISM utility\n'
if 'History' in nc.ncattrs():
nc.History = histstr + nc.History
elif 'history' in nc.ncattrs():
nc.history = histstr + nc.history
else:
nc.history = histstr
for attr in ("projection", "proj4"):
if hasattr(nc, attr):
delattr(nc, attr)
# Write projection attribute
nc.proj4 = proj.srs
# Close file
nc.close()
示例4: run
# 需要导入模块: from netCDF4 import Dataset [as 别名]
# 或者: from netCDF4.Dataset import proj4 [as 别名]
files = ["pisms-output.nc",
"pismr-output.nc",
"both-consistent.nc",
"both-string-missing.nc",
"both-string-mismatch.nc",
"both-double-missing.nc",
"both-double-mismatch.nc"]
# create an input file
run(PISMS + " -verbose 1 -Mx 3 -My 3 -Mz 5 -y 10 -o pisms-output.nc")
# add the PROJ.4 string
nc = Dataset("pisms-output.nc", "a")
nc.proj4 = "+init=epsg:3413"
nc.close()
print("Test running PISM initialized from a file w/o mapping but with proj4...")
assert run(PISMR + " -verbose 1 -i pisms-output.nc -y 10 -o both-consistent.nc") == 0
print("Test that the mapping variable was initialized using the proj4 attribute...")
nc = Dataset("both-consistent.nc", "r")
mapping = nc.variables["mapping"]
assert mapping.grid_mapping_name == "polar_stereographic"
nc.close()
print("Test re-starting PISM with consistent proj4 and mapping...")
assert run(PISMR + " -verbose 1 -i both-consistent.nc -o pismr-output.nc") == 0
# remove a required string attribute