def test_add_imaginary_field(): fc = FieldsContainer() fc.labels = ["time", "complex"] f1 = Field(3) f1.append([10.2, 3.0, -11.8], 1) f1.append([10.2, 2.0, 11.8], 2) f1.append([10.2, 1.0, -11.8], 3) mscop1 = {"time": 1, "complex": 1} fc.add_field(mscop1, f1) assert len(fc) == 1 f2 = Field(1) f2.append([4.0, 4.4, 3.6], 1) mscop2 = {"time": 1, "complex": 0} fc.add_field(mscop2, f2) assert len(fc) == 2 f3 = Field(1) f3.append([0.0, 0.4, 0.6], 1) fc.add_imaginary_field(f3, 2) field_to_compare = Field(1) field_to_compare.append([0.0, 0.4, 0.6], 1) field = fc.get_field({"time": 2, "complex": 1}) assert len(fc) == 3 assert np.allclose(field.data, field_to_compare.data) fc.add_imaginary_field(f3, 1) field_result_1 = fc.get_field({"time": 1, "complex": 1}) field_result_2 = fc.get_field({"time": 2, "complex": 1}) assert np.allclose(field_result_1.data, field_result_2.data) fc.add_label("body") with pytest.raises(dpf_errors.DpfValueError): fc.add_imaginary_field(f3, 10)
def test_set_get_field_fields_container(): fc = FieldsContainer() fc.labels = ["time", "complex"] for i in range(0, 20): mscop = {"time": i + 1, "complex": 0} fc.add_field(mscop, Field(nentities=i + 10)) assert fc.get_available_ids_for_label() == list(range(1, 21)) for i in range(0, 20): fieldid = fc.get_field({"time": i + 1, "complex": 0})._message.id assert fieldid != 0 assert fc.get_field(i)._message.id != 0 assert (fc.get_field_by_time_complex_ids(timeid=i + 1, complexid=0)._message.id != 0) assert fc[i]._message.id != 0
def test_set_get_field_fields_container_new_label_default_value(): fc = FieldsContainer() fc.labels = ["time", "complex"] for i in range(0, 20): mscop = {"time": i + 1, "complex": 0} fc.add_field(mscop, Field(nentities=i + 10)) fc.add_label("shape", 3) for i in range(0, 20): mscop = {"time": i + 1, "complex": 0, "shape": 1} fc.add_field(mscop, Field(nentities=i + 10)) for i in range(0, 20): fieldid = fc.get_field({ "time": i + 1, "complex": 0, "shape": 1 })._message.id assert fieldid != 0 assert fc.get_field(i + 20)._message.id != 0 assert fc[i]._message.id != 0 assert fc.get_label_space(i + 20) == { "time": i + 1, "complex": 0, "shape": 1 } for i in range(0, 20): fieldid = fc.get_field({ "time": i + 1, "complex": 0, "shape": 3 })._message.id assert fieldid != 0 assert fc.get_field(i)._message.id != 0 assert fc[i]._message.id != 0 assert fc.get_label_space(i) == { "time": i + 1, "complex": 0, "shape": 3 }