11if __name__ ==
"__main__":
13 target_structure =
"parametric_rectangular"
17 element_shape = (nx, ny)
21 element_x = np.tile(x1d, (ny, 1))
22 element_y = np.transpose(np.tile(y1d, (nx, 1)))
24 time_data = 10 * element_x + element_y
25 field_name =
"index2d"
27 out_file =
"ParaGridIO_input_test.nc"
28 out_root = netCDF4.Dataset(out_file,
"w", format=
"NETCDF4")
29 structgrp = out_root.createGroup(
"structure")
30 structgrp.type = target_structure
32 metagrp = out_root.createGroup(
"metadata")
33 metagrp.type = target_structure
34 confgrp = metagrp.createGroup(
"configuration")
35 timegrp = metagrp.createGroup(
"time")
37 formatted = timegrp.createVariable(
"formatted", str)
38 formatted.format =
"%Y-%m-%dT%H:%M:%SZ"
39 formatted[0] =
"1970-01-01T00:00:00Z"
40 time_attr = timegrp.createVariable(
"time",
"i8")
42 time_attr[:] = the_time
43 time_attr.units =
"seconds since 1970-01-01T00:00:00Z"
45 datagrp = out_root.createGroup(
"data")
46 xDim = datagrp.createDimension(
"x", nx)
47 yDim = datagrp.createDimension(
"y", ny)
48 tDim = datagrp.createDimension(
"time",
None)
51 nc_lons = datagrp.createVariable(
"longitude",
"f8", (
"y",
"x"))
52 nc_lons[:, :] = element_x
53 nc_lats = datagrp.createVariable(
"latitude",
"f8", (
"y",
"x"))
54 nc_lats[:, :] = element_y
56 nc_times = datagrp.createVariable(
"time",
"f8", (
"time"))
61 data = datagrp.createVariable(field_name,
"f8", (
"time",
"y",
"x"))
62 data[0, :, :] = time_data
64 nc_times[0] = the_time