if use_method_one: ## Method one extracts data one ts at a time and builds the complete timeseries for each variable piecemeal # This method is slower but robust if data variables are added/removed during the timeseries # NOTE: does not yet deal with gaps in the timeseries for i in range(ntimes): try: tsvert = mesh.getEntAdj(tlines[i], iBase.Type.vertex)[0] except IndexError: tsvert = mesh.getEntAdj(tlines[i - 1], iBase.Type.vertex)[0] topo_set = iMesh.EntitySet(t_topo_tag[tsvert], mesh) verts = topo_set.getEntities(type=iBase.Type.vertex) dtags = mesh.getAllTags(tsvert) for dt in (dt for dt in dtags if dt.name.startswith("DATA")): dtc, _ = utils.unpack_data_tag_name(dt.name) data = utils.get_packed_data(dt, tsvert, dtc) if not dt.name in data_map: data_map[dt.name] = data else: data_map[dt.name] = numpy.vstack([data_map[dt.name], data]) else: ## Method two extracts the entire timeseries for each variable # This method is faster but only works if data exists for all vertices # Extract the temporal vertex array from the time_topology (tlines) tsverts = [x[0] for x in mesh.getEntAdj(tlines, iBase.Type.vertex)] tsverts.append(mesh.getEntAdj(tlines[len(tlines) - 1], iBase.Type.vertex)[1]) dtags = mesh.getAllTags(tsverts[0]) # This assumes that all data_tags are present on the first vertex for dt in (dt for dt in dtags if dt.name.startswith("DATA")):
from matplotlib.collections import PolyCollection # We know this is a rectilinear grid, which means we know there are quadrilateral entities, # so get them, get the data tags associated with them, and then loop through them to plot the data #quads=mesh.getEntities(topo=iMesh.Topology.quadrilateral) quads=set.getEntities(topo=iMesh.Topology.quadrilateral) # Find all the data tags dtags=mesh.getAllTags(set) ntags=len(dtags) nrow=2 ncol=int(ntags/nrow)+1 for i in range(ntags): data_t=dtags[i] dtc, varname=utils.unpack_data_tag_name(data_t.name) print " > Plotting data for %s" % varname # Get the units, _FillValue, scale_factor, and add_offset fill_val=numpy.nan scale_factor=None add_offset=None units='Unknown' if varname in var_atts: if '_FillValue' in var_atts[varname]: fill_val=var_atts[varname]['_FillValue'] if 'scale_factor' in var_atts[varname]: scale_factor=var_atts[varname]['scale_factor'] if 'add_offset' in var_atts[varname]: add_offset=var_atts[varname]['add_offset'] if 'units' in var_atts[varname]: units=var_atts[varname]['units']