def test_document_has_expected_packets(): packet0 = Packet(id="id_00") packet1 = Packet(id="id_01") document = Document([packet0, packet1]) assert document.packets == [packet0, packet1]
def test_packet_dump(): expected_result = """{"id": "id_00"}""" packet = Packet(id="id_00") with StringIO() as fp: packet.dump(fp) fp.seek(0) result = fp.read() assert result == expected_result
def test_packet_description(): expected_result = """{ "id": "id_00", "name": "Name", "description": "<strong>Description</strong>" }""" string = "<strong>Description</strong>" packet_str = Packet(id="id_00", name="Name", description=string) packet_val = Packet(id="id_00", name="Name", description=StringValue(string=string)) assert repr(packet_str) == repr(packet_val) == expected_result
def write_rx_czml(): height = 50 receiver_point_packets = [] lob_packets = [] top = Preamble(name="Receivers") rx_properties = { "verticalOrigin": "BOTTOM", "scale": 0.75, "heightReference":"CLAMP_TO_GROUND", "height": 48, "width": 48, } for index, x in enumerate(receivers): if x.isActive and ms.receiving: lob_start_lat = x.latitude lob_start_lon = x.longitude lob_stop_lat, lob_stop_lon = v.direct(lob_start_lat, lob_start_lon, x.doa, d) lob_packets.append(Packet(id=f"LOB-{x.station_id}-{index}", polyline=Polyline( material= Material( polylineOutline = PolylineOutlineMaterial( color= Color(rgba=[255, 140, 0, 255]), outlineColor= Color(rgba=[0, 0, 0, 255]), outlineWidth= 2 )), clampToGround=True, width=5, positions=Position(cartographicDegrees=[lob_start_lon, lob_start_lat, height, lob_stop_lon, lob_stop_lat, height]) ))) else: lob_packets = [] if x.isMobile == True: rx_icon = {"image":{"uri":"/static/flipped_car.svg"}} # if x.heading > 0 or x.heading < 180: # rx_icon = {"image":{"uri":"/static/flipped_car.svg"}, "rotation":math.radians(360 - x.heading + 90)} # elif x.heading < 0 or x.heading > 180: # rx_icon = {"image":{"uri":"/static/car.svg"}, "rotation":math.radians(360 - x.heading - 90)} else: rx_icon = {"image":{"uri":"/static/tower.svg"}} receiver_point_packets.append(Packet(id=f"{x.station_id}-{index}", billboard={**rx_properties, **rx_icon}, position={"cartographicDegrees": [ x.longitude, x.latitude, 15 ]})) output = Document([top] + receiver_point_packets + lob_packets) return output
def test_packet_custom_properties(): expected_result = """{ "id": "id_00", "properties": { "a": false, "b": 1, "c": "C", "ellipsoid": { "radii": { "cartesian": [ 6378137, 6378137, 6356752.31414 ] } } } }""" prop_dict = { "a": False, "b": 1, "c": "C", "ellipsoid": Ellipsoid( radii=EllipsoidRadii( cartesian=Cartesian3Value(values=[6378137, 6378137, 6356752.314140]) ) ), } packet = Packet(id="id_00", properties=prop_dict) assert repr(packet) == expected_result
def test_packet_repr_id_only(): expected_result = """{ "id": "id_00" }""" packet = Packet(id="id_00") assert repr(packet) == expected_result
def test_packet_dynamic_cartesian_position_perfect(): # Trying to group the cartesian value by sample # is much more difficult than expected. # Pull requests welcome expected_result = """{ "id": "InternationalSpaceStation", "position": { "interpolationAlgorithm": "LAGRANGE", "referenceFrame": "INERTIAL", "cartesian": [ 0.0, -6668447.2211117, 1201886.45913705, 146789.427467256, 60.0, -6711432.84684144, 919677.673492462, -214047.552431458 ] } }""" packet = Packet( id="InternationalSpaceStation", position=Position( interpolationAlgorithm=InterpolationAlgorithms.LAGRANGE, referenceFrame=ReferenceFrames.INERTIAL, cartesian=[ 0.0, -6668447.2211117, 1201886.45913705, 146789.427467256, 60.0, -6711432.84684144, 919677.673492462, -214047.552431458, ], ), ) assert repr(packet) == expected_result
def test_doc_dumps(): packet = Packet(id="id_00") expected_result = """[{"id": "id_00"}]""" document = Document([packet]) assert document.dumps() == expected_result
def test_packet_with_delete_has_nothing_else(): expected_result = """{ "id": "id_00", "delete": true }""" packet = Packet(id="id_00", delete=True, name="No Name In Packet") assert repr(packet) == expected_result
def test_packet_repr_id_name(): expected_result = """{ "id": "id_00", "name": "Test Packet" }""" packet = Packet(id="id_00", name="Test Packet") assert repr(packet) == expected_result
def test_packet_billboard(): expected_result = """{ "id": "id_00", "billboard": { "image": "file://image.png" } }""" packet = Packet(id="id_00", billboard=Billboard(image="file://image.png")) assert repr(packet) == expected_result
def test_doc_repr(): packet = Packet(id="id_00") expected_result = """[ { "id": "id_00" } ]""" document = Document([packet]) assert str(document) == expected_result
def test_document_dump(): expected_result = """[{"id": "id_00"}]""" packet = Packet(id="id_00") document = Document([packet]) with StringIO() as fp: document.dump(fp) fp.seek(0) result = fp.read() assert result == expected_result
def test_packet_constant_cartesian_position(): expected_result = """{ "id": "MyObject", "position": { "cartesian": [ 0.0, 0.0, 0.0 ] } }""" packet = Packet(id="MyObject", position=Position(cartesian=[0.0, 0.0, 0.0])) assert repr(packet) == expected_result
def packet_from_point(feat, id_=None): name = feat.get("name", "point_{}".format(id_) if id_ is not None else "point_0") description = feat.get("description", name) color = get_color(feat.get("color", 0xff0000)) point = feat.get_shape(WGS84_CRS) return Packet( id=id_, name=name, description=description, point=Point(color=color, pixelSize=5), position=Position( # this assumes 0 elevation for all points cartographicDegrees=[point.x, point.y, 0]), )
def packet_from_polygon(feat, id_=None): name = feat.get( "name", "polygon_{}".format(id_) if id_ is not None else "polygon_0") description = feat.get("description", name) color = get_color(feat.get("color", 0xff0000)) polygon = feat.get_shape(WGS84_CRS) return Packet( id=id_, name=name, description=description, polygon=Polygon( positions=PositionList(cartographicDegrees=list( flatten_line(fill_height(polygon.exterior.coords)))), material=Material(solidColor=SolidColorMaterial(color=color)), ), )
def test_packet_constant_cartesian_position_perfect(): # Trying to group the cartesian value by sample # is much more difficult than expected. # Pull requests welcome expected_result = """{ "id": "MyObject", "position": { "interpolationAlgorithm": "LINEAR", "referenceFrame": "FIXED", "cartesian": [ 0.0, 0.0, 0.0 ] } }""" packet = Packet(id="MyObject", position=Position(cartesian=[0.0, 0.0, 0.0])) assert repr(packet) == expected_result
def test_packet_point(): expected_result = """{ "id": "id_00", "point": { "color": { "rgba": [ 255, 0, 0, 255 ] } } }""" packet = Packet(id="id_00", point=Point(color=Color.from_list([255, 0, 0, 255]))) assert repr(packet) == expected_result
def test_packet_polyline(): expected_result = """{ "id": "id_00", "polyline": { "positions": { "cartographicDegrees": [ -75, 43, 500000, -125, 43, 500000 ] }, "material": { "solidColor": { "color": { "rgba": [ 255, 0, 0, 255 ] } } } } }""" packet = Packet( id="id_00", polyline=Polyline( positions=PositionList( cartographicDegrees=[-75, 43, 500000, -125, 43, 500000] ), material=PolylineMaterial( solidColor=SolidColorMaterial.from_list([255, 0, 0, 255]) ), ), ) assert repr(packet) == expected_result
def test_make_czml_png_rectangle_file(image): wsen = [20, 40, 21, 41] rectangle_packet = Packet( id="id_00", rectangle=Rectangle( coordinates=RectangleCoordinates(wsenDegrees=wsen), fill=True, material=Material(image=ImageMaterial( transparent=True, repeat=None, image="data:image/png;base64," + image, ), ), ), ) with tempfile.NamedTemporaryFile(mode="w", suffix=".czml") as out_file: out_file.write(str(Document([Preamble(), rectangle_packet]))) exists = os.path.isfile(out_file.name) # TODO: Should we be testing something else? assert exists
def test_packet_rectangles(image): wsen = [20, 40, 21, 41] expected_result = """{{ "id": "id_00", "rectangle": {{ "coordinates": {{ "wsenDegrees": [ {}, {}, {}, {} ] }}, "fill": true, "material": {{ "image": {{ "image": "data:image/png;base64,{}", "transparent": true }} }} }} }}""".format(*wsen, image) rectangle_packet = Packet( id="id_00", rectangle=Rectangle( coordinates=RectangleCoordinates(wsenDegrees=wsen), fill=True, material=Material(image=ImageMaterial( transparent=True, repeat=None, image="data:image/png;base64," + image, ), ), ), ) assert repr(rectangle_packet) == expected_result
def test_packet_dynamic_cartesian_position(): expected_result = """{ "id": "InternationalSpaceStation", "position": { "interpolationAlgorithm": "LAGRANGE", "referenceFrame": "INERTIAL", "cartesian": [ 0.0, -6668447.2211117, 1201886.45913705, 146789.427467256, 60.0, -6711432.84684144, 919677.673492462, -214047.552431458 ] } }""" packet = Packet( id="InternationalSpaceStation", position=Position( interpolationAlgorithm=InterpolationAlgorithms.LAGRANGE, referenceFrame=ReferenceFrames.INERTIAL, cartesian=[ 0.0, -6668447.2211117, 1201886.45913705, 146789.427467256, 60.0, -6711432.84684144, 919677.673492462, -214047.552431458, ], ), ) assert repr(packet) == expected_result
def test_packet_label(): expected_result = """{ "id": "0", "label": { "show": true, "font": "20px sans-serif", "style": "FILL", "fillColor": { "rgbaf": [ 0.2, 0.3, 0.4, 1.0 ] }, "outlineColor": { "rgba": [ 0, 233, 255, 2 ] }, "outlineWidth": 2.0 } }""" packet = Packet( id="0", label=Label( font="20px sans-serif", fillColor=Color.from_list([0.2, 0.3, 0.4]), outlineColor=Color.from_list([0, 233, 255, 2]), outlineWidth=2.0, ), ) assert repr(packet) == expected_result
def write_czml(best_point, all_the_points, ellipsedata): point_properties = { "pixelSize":5.0, "heightReference":"CLAMP_TO_GROUND", # "heightReference":"RELATIVE_TO_GROUND", # "color": { # "rgba": [255, 0, 0, 255], # } } best_point_properties = { "pixelSize":12.0, # "heightReference":"RELATIVE_TO_GROUND", "heightReference":"CLAMP_TO_GROUND", "color": { "rgba": [0, 255, 0, 255], } } ellipse_properties = { "granularity": 0.008722222, "material": { "solidColor": { "color": { "rgba": [255, 0, 0, 90] } } } } top = Preamble(name="Geolocation Data") all_point_packets = [] best_point_packets = [] ellipse_packets = [] if len(all_the_points) > 0 and (ms.plotintersects or ms.eps == 0): all_the_points = np.array(all_the_points) scaled_time = minmax_scale(all_the_points[:,-1]) all_the_points = np.column_stack((all_the_points, scaled_time)) for x in all_the_points: rgb = hsvtorgb(x[-1]/3, 0.9, 0.9) color_property = {"color":{"rgba": [*rgb, 255]}} all_point_packets.append(Packet(id=str(x[1]) + ", " + str(x[0]), point={**point_properties, **color_property}, position={"cartographicDegrees": [ x[0], x[1], 20 ]}, )) if len(best_point) > 0: for x in best_point: best_point_packets.append(Packet(id=str(x[0]) + ", " + str(x[1]), point=best_point_properties, position={"cartographicDegrees": [ x[1], x[0], 15 ]})) if len(ellipsedata) > 0: for x in ellipsedata: # rotation = 2 * np.pi - x[2] if x[0] >= x[1]: semiMajorAxis = x[0] semiMinorAxis = x[1] rotation = 2 * np.pi - x[2] rotation += np.pi/2 # print(f"{x[4], x[3]} is inveted") else: rotation = x[2] semiMajorAxis = x[1] semiMinorAxis = x[0] # print(f"{x[4], x[3]} is NOT inveted") ellipse_info = {"semiMajorAxis": semiMajorAxis, "semiMinorAxis": semiMinorAxis, "rotation": rotation} ellipse_packets.append(Packet(id=str(x[4]) + ", " + str(x[3]), ellipse={**ellipse_properties, **ellipse_info}, position={"cartographicDegrees": [ x[3], x[4], 15 ]})) output = Document([top] + best_point_packets + all_point_packets + ellipse_packets) return output
def test_packet_dumps(): expected_result = """{"id": "id_00"}""" packet = Packet(id="id_00") assert packet.dumps() == expected_result
def write_czml(best_point, all_the_points, ellipsedata): point_properties = { "pixelSize": 5.0, "heightReference": "RELATIVE_TO_GROUND", # "color": { # "rgba": [255, 0, 0, 255], # } } best_point_properties = { "pixelSize": 12.0, "heightReference": "RELATIVE_TO_GROUND", "color": { "rgba": [0, 255, 0, 255], } } rx_properties = { "image": { "uri": "/static/tower.svg" }, # "rotation": "Cesium.Math.PI_OVER_FOUR", "verticalOrigin": "BOTTOM", "scale": 0.75, "heightReference": "RELATIVE_TO_GROUND", "height": 48, "width": 48 } ellipse_properties = { "granularity": 0.008722222, "material": { "solidColor": { "color": { "rgba": [255, 0, 0, 90] } } } } top = Preamble(name="Geolocation Data") all_point_packets = [] best_point_packets = [] receiver_point_packets = [] ellipse_packets = [] if all_the_points != None and (ms.plotintersects or ms.eps == 0): all_the_points = np.array(all_the_points) scaled_time = minmax_scale(all_the_points[:, -1]) all_the_points = np.column_stack((all_the_points, scaled_time)) for x in all_the_points: rgb = hsvtorgb(x[-1] / 3, 0.8, 0.8) color_property = {"color": {"rgba": [*rgb, 255]}} all_point_packets.append( Packet( id=str(x[1]) + ", " + str(x[0]), point={ **point_properties, **color_property }, position={"cartographicDegrees": [x[0], x[1], 10]}, )) if best_point != None: for x in best_point: best_point_packets.append( Packet(id=str(x[0]) + ", " + str(x[1]), point=best_point_properties, position={"cartographicDegrees": [x[1], x[0], 15]})) if ellipsedata != None: for x in ellipsedata: # rotation = 2 * np.pi - x[2] if x[0] >= x[1]: semiMajorAxis = x[0] semiMinorAxis = x[1] rotation = 2 * np.pi - x[2] rotation += np.pi / 2 # print(f"{x[4], x[3]} is inveted") else: rotation = x[2] semiMajorAxis = x[1] semiMinorAxis = x[0] # print(f"{x[4], x[3]} is NOT inveted") ellipse_info = { "semiMajorAxis": semiMajorAxis, "semiMinorAxis": semiMinorAxis, "rotation": rotation } ellipse_packets.append( Packet(id=str(x[4]) + ", " + str(x[3]), ellipse={ **ellipse_properties, **ellipse_info }, position={"cartographicDegrees": [x[3], x[4], 15]})) for x in receivers: receiver_point_packets.append( Packet(id=x.station_id, billboard=rx_properties, position={ "cartographicDegrees": [x.longitude, x.latitude, 15] })) with open("static/output.czml", "w") as file1: file1.write( str( Document([top] + best_point_packets + all_point_packets + receiver_point_packets + ellipse_packets)))
) from czml3.types import IntervalValue, Sequence, TimeInterval accesses_id = "9927edc4-e87a-4e1f-9b8b-0bfb3b05b227" start = dt.datetime(2012, 3, 15, 10, tzinfo=dt.timezone.utc) end = dt.datetime(2012, 3, 16, 10, tzinfo=dt.timezone.utc) simple = Document( [ Preamble( name="simple", clock=IntervalValue( start=start, end=end, value=Clock(currentTime=start, multiplier=60) ), ), Packet(id=accesses_id, name="Accesses", description="List of Accesses"), Packet( id="Satellite/Geoeye1-to-Satellite/ISS", name="Geoeye1 to ISS", parent=accesses_id, availability=Sequence( [ TimeInterval( start="2012-03-15T10:16:06.97400000000198Z", end="2012-03-15T10:33:59.3549999999959Z", ), TimeInterval( start="2012-03-15T11:04:09.73799999999756Z", end="2012-03-15T11:21:04.51900000000023Z", ), TimeInterval(
def test_packet_custom_id(): expected_id = "id_00" packet = Packet(id=expected_id) assert packet.id == expected_id
def test_auto_generated_id(): packet = Packet() assert UUID(packet.id, version=4)
def test_packet_polygon(): expected_result = """{ "id": "id_00", "polygon": { "positions": { "cartographicDegrees": [ -115.0, 37.0, 0, -115.0, 32.0, 0, -107.0, 33.0, 0, -102.0, 31.0, 0, -102.0, 35.0, 0 ] }, "granularity": 1.0, "material": { "solidColor": { "color": { "rgba": [ 255, 0, 0, 255 ] } } } } }""" packet = Packet( id="id_00", polygon=Polygon( positions=PositionList( cartographicDegrees=[ -115.0, 37.0, 0, -115.0, 32.0, 0, -107.0, 33.0, 0, -102.0, 31.0, 0, -102.0, 35.0, 0, ] ), granularity=1.0, material=Material(solidColor=SolidColorMaterial.from_list([255, 0, 0])), ), ) assert repr(packet) == expected_result