# open file in append mode nc_to = NC(to_file_name, 'a') # get dimensions from file xdim, ydim, zdim, tdim = ppt.get_dims(nc_to) # set variable order for permutation var_order = (tdim, xdim, ydim, zdim) # read in z-coordinate z = nc_to.variables[zdim][:] # read ice thickness print((" - reading variable %s from file %s" % (thk_var_name, to_file_name))) try: thk_to = np.squeeze( ppt.permute(nc_to.variables[thk_var_name], var_order)) except: print(("ERROR: unknown or not-found variable '%s' in file %s ... ending ..." % (thk_var_name, to_file_name))) import sys sys.exit() # read interpolation variable print((" - reading variable %s from file %s" % (interp_var_name, to_file_name))) try: # Don't know why squeezing changes dimension ordering ## var_old = np.squeeze(ppt.permute(nc_to.variables[interp_var_name], var_order)) var_old = ppt.permute(nc_to.variables[interp_var_name], var_order) except: print(("ERROR: unknown or not-found variable '%s' in file %s ... ending ..."
# open file in append mode nc_to = NC(to_file_name, "a") # get dimensions from file xdim, ydim, zdim, tdim = ppt.get_dims(nc_to) # set variable order for permutation var_order = (tdim, xdim, ydim, zdim) # read in z-coordinate z = nc_to.variables[zdim][:] # read ice thickness print((" - reading variable %s from file %s" % (thk_var_name, to_file_name))) try: thk_to = np.squeeze( ppt.permute(nc_to.variables[thk_var_name], var_order)) except: print(( "ERROR: unknown or not-found variable '%s' in file %s ... ending ..." % (thk_var_name, to_file_name))) import sys sys.exit() # read interpolation variable print((" - reading variable %s from file %s" % (interp_var_name, to_file_name))) try: # Don't know why squeezing changes dimension ordering ## var_old = np.squeeze(ppt.permute(nc_to.variables[interp_var_name], var_order)) var_old = ppt.permute(nc_to.variables[interp_var_name], var_order)
# get the dimensions xdim, ydim, zdim, tdim = ppt.get_dims(nc) # set up dimension ordering dim_order = (tdim, zdim, ydim, xdim) myvar = varname for name in nc.variables.keys(): v = nc.variables[name] if getattr(v, "standard_name", "") == varname: print("variabe {0} found by its standard_name {1}".format(name, varname)) myvar = name print((" - reading variable %s from file %s" % (myvar, obs_file))) try: data = np.squeeze(ppt.permute(nc.variables[myvar], dim_order)) except: print(("ERROR: unknown or not-found variable '%s' in file %s ... ending ..." % (variable.var_name, obs_file))) exit(2) try: inunit = str(nc.variables[var].units) except: print(("ERROR: units not found in variable '%s' in file %s ... ending ..." % (variable.var_name, obs_file))) exit(2) if outunit is not None: data = ppt.unit_converter(data, inunit, outunit)
# get the dimensions xdim, ydim, zdim, tdim = ppt.get_dims(nc) # set up dimension ordering dim_order = (tdim, zdim, ydim, xdim) myvar = varname for name in list(nc.variables.keys()): v = nc.variables[name] if getattr(v, "standard_name", "") == varname: print(("variabe {0} found by its standard_name {1}".format( name, varname))) myvar = name print((" - reading variable %s from file %s" % (myvar, obs_file))) try: data = np.squeeze(ppt.permute(nc.variables[myvar], dim_order)) except: print(( "ERROR: unknown or not-found variable '%s' in file %s ... ending ..." % (variable.var_name, obs_file))) exit(2) try: inunit = str(nc.variables[myvar].units) except: print(( "ERROR: units not found in variable '%s' in file %s ... ending ..." % (variable.var_name, obs_file))) exit(2) if outunit is not None:
# get the dimensions xdim, ydim, zdim, tdim = ppt.get_dims(nc) # set up dimension ordering dim_order = (tdim, zdim, ydim, xdim) myvar = varname for name in nc.variables.keys(): v = nc.variables[name] if getattr(v, "standard_name", "") == varname: print("variabe {0} found by its standard_name {1}".format(name, varname)) myvar = name print((" - reading variable %s from file %s" % (myvar, obs_file))) try: data = np.squeeze(ppt.permute(nc.variables[myvar], dim_order)) except: print(("ERROR: unknown or not-found variable '%s' in file %s ... ending ..." % (variable.var_name, obs_file))) exit(2) try: inunit = str(nc.variables[myvar].units) except: print(("ERROR: units not found in variable '%s' in file %s ... ending ..." % (variable.var_name, obs_file))) exit(2) if outunit is not None: data = ppt.unit_converter(data, inunit, outunit)
if time[0] < 0: is_paleo = True else: is_paleo = False cdftime = utime(time_units, time_calendar) for k, t in enumerate(time): if is_paleo: timestamp = '1-1-1' my_year = k else: timestamp = cdftime.num2date(t) my_year = 0 print('Processing {}'.format(timestamp)) for level in contour_levels: contour_var = np.array( ppt.permute(nc.variables[varname], var_order), order='C')[k, Ellipsis] contour_points = get_contours( contour_var, x, y, nc_projection, level) # For each contour polygon = ogr.Geometry(ogr.wkbPolygon) for point in range(0, len(contour_points)): geoLocations = contour_points[point] ring = ogr.Geometry(ogr.wkbLinearRing) # For each point, for pointIndex, geoLocation in enumerate(geoLocations): ring.AddPoint(geoLocation[0], geoLocation[1]) ring.CloseRings() polygon.AddGeometry(ring) # Create feature featureDefn = layer.GetLayerDefn() feature = ogr.Feature(featureDefn)
time_calendar = time.calendar if time[0] < 0: is_paleo = True else: is_paleo = False cdftime = utime(time_units, time_calendar) for k, t in enumerate(time): if is_paleo: timestamp = "1-1-1" my_year = k else: timestamp = cdftime.num2date(t) my_year = 0 print(("Processing {}".format(timestamp))) for level in contour_levels: contour_var = np.array(ppt.permute(nc.variables[varname], var_order), order="C")[k, Ellipsis] contour_points = get_contours(contour_var, x, y, nc_projection, level) # For each contour polygon = ogr.Geometry(ogr.wkbPolygon) for point in range(0, len(contour_points)): geoLocations = contour_points[point] ring = ogr.Geometry(ogr.wkbLinearRing) # For each point, for pointIndex, geoLocation in enumerate(geoLocations): ring.AddPoint(geoLocation[0], geoLocation[1]) ring.CloseRings() polygon.AddGeometry(ring) # Create feature featureDefn = layer.GetLayerDefn() feature = ogr.Feature(featureDefn) feature.SetGeometry(polygon)
sys.exit() # get the dimensions xdim, ydim, zdim, tdim = ppt.get_dims(nc) # set up dimension ordering dim_order = (tdim, zdim, ydim, xdim) myvar = varname for name in list(nc.variables.keys()): v = nc.variables[name] if getattr(v, "standard_name", "") == varname: print(("variabe {0} found by its standard_name {1}".format(name, varname))) myvar = name print((" - reading variable %s from file %s" % (myvar, obs_file))) try: data = np.squeeze(ppt.permute(nc.variables[myvar], dim_order)) except: print(("ERROR: unknown or not-found variable '%s' in file %s ... ending ..." % (variable.var_name, obs_file))) exit(2) try: inunit = str(nc.variables[myvar].units) except: print(("ERROR: units not found in variable '%s' in file %s ... ending ..." % (variable.var_name, obs_file))) exit(2) if outunit is not None: data = ppt.unit_converter(data, inunit, outunit) if variable.var_name in vars_dem: mask = data <= variable.vmin
print(("copy ice thickness from %s to %s." % (thk_file_name, to_file_name))) subprocess.call(["ncks", "-A -v thk", thk_file_name, to_file_name]) # open file in append mode nc_to = NC(to_file_name, "a") # get dimensions from file xdim, ydim, zdim, tdim = ppt.get_dims(nc_to) # set variable order for permutation var_order = (tdim, xdim, ydim, zdim) # read in z-coordinate z = nc_to.variables[zdim][:] # read ice thickness print((" - reading variable %s from file %s" % (thk_var_name, to_file_name))) try: thk_to = np.squeeze(ppt.permute(nc_to.variables[thk_var_name], var_order)) except: print( ("ERROR: unknown or not-found variable '%s' in file %s ... ending ..." % (thk_var_name, to_file_name)) ) import sys sys.exit() # read interpolation variable print((" - reading variable %s from file %s" % (interp_var_name, to_file_name))) try: # Don't know why squeezing changes dimension ordering ## var_old = np.squeeze(ppt.permute(nc_to.variables[interp_var_name], var_order)) var_old = ppt.permute(nc_to.variables[interp_var_name], var_order) except:
print("variabe {0} found by its standard_name {1}".format(name, in_varname)) varname = name profile_axis = nc.variables['profile'][profile_id] profile_axis_units = nc.variables['profile'].units profile_axis_name = nc.variables['profile'].long_name profile_axis_out_units = 'km' profile_axis = np.squeeze( ppt.unit_converter(profile_axis[:], profile_axis_units, profile_axis_out_units)) x = profile_axis my_var = nc.variables[varname] my_var_units = my_var.units my_var_p = ppt.permute(my_var, output_order=output_order) xdim, ydim, zdim, tdim = ppt.get_dims(nc) if tdim: data = np.squeeze(my_var_p[profile_id, 0, Ellipsis]) else: data = np.squeeze(my_var_p[profile_id, Ellipsis]) data = ppt.unit_converter(data, my_var_units, o_units) if label_params[0] == 'none': exp_str = None else: pism_config = nc.variables["pism_config"] run_stats = nc.variables['run_stats'] config = dict() for attr in pism_config.ncattrs():