MCPcopy
hub / github.com/tum-pbs/PhiFlow / to_field

Function to_field

phi/vis/_vis_base.py:498–526  ·  view source on GitHub ↗
(obj)

Source from the content-addressed store, hash-verified

496
497
498def to_field(obj) -> Field:
499 if isinstance(obj, Tensor) and obj.dtype.kind == object:
500 return math.map(to_field, obj, dims=object)
501 if isinstance(obj, Field):
502 return obj
503 if isinstance(obj, Geometry):
504 return Field(obj, math.NAN, math.NAN)
505 if isinstance(obj, Tensor):
506 arbitrary_lines_1d = spatial(obj).rank == 1 and 'vector' in obj.shape
507 point_cloud = instance(obj) and 'vector' in obj.shape
508 if point_cloud or arbitrary_lines_1d:
509 if math.get_format(obj) != 'dense':
510 obj = math.stored_values(obj)
511 return PointCloud(obj, math.NAN)
512 elif spatial(obj) and 'vector' not in channel(obj):
513 return CenteredGrid(obj, 0, bounds=Box(math.const_vec(-0.5, spatial(obj)), wrap(spatial(obj), channel('vector')) - 0.5))
514 elif spatial(obj):
515 return PointCloud(obj, math.NAN)
516 elif 'vector' in obj.shape:
517 return PointCloud(math.expand(obj, instance(points=1)), math.NAN)
518 elif instance(obj) and not spatial(obj):
519 assert instance(obj).rank == 1, "Bar charts must have only one instance dimension"
520 vector = channel(vector=instance(obj).names)
521 equal_spacing = math.range_tensor(instance(obj), vector)
522 return PointCloud(equal_spacing, values=obj)
523 else:
524 point = expand(vec(value=0.), instance(value=1))
525 return PointCloud(point, obj)
526 raise ValueError(f"Cannot plot {obj}. Tensors, geometries and fields can be plotted.")
527
528
529@math.broadcast(dims=object)

Callers 4

_plot_pointsMethod · 0.90
plotMethod · 0.90
test_tensor_as_fieldMethod · 0.90
layout_sub_figuresFunction · 0.85

Calls 4

FieldClass · 0.90
PointCloudFunction · 0.90
CenteredGridFunction · 0.90
BoxClass · 0.90

Tested by 1

test_tensor_as_fieldMethod · 0.72