示例#1
0
def get_world_size(minlat, minlon, maxlat, maxlon):
    """Return the world size in X-Z coordinates."""
    x1, z1 = Projection.project(minlon, minlat)
    x2, z2 = Projection.project(maxlon, maxlat)
    xSize = math.fabs(x2 - x1)
    zSize = math.fabs(z2 - z1)
    return (xSize, zSize)
示例#2
0
 def center_coordinates(minlat, minlon, maxlat, maxlon):
     """Center the coordinate around (0,0) and returns the offsets between earth and local world coordinate."""
     x1, z1 = Projection.project(minlon, minlat)
     x2, z2 = Projection.project(maxlon, maxlat)
     xOffset = (x1 + x2) / 2
     zOffset = (z1 + z2) / 2
     for osmid in OSMCoord.coordDictionnary:
         # inverse X, because OSM and Webots X are inversed
         OSMCoord.coordDictionnary[osmid].x = -OSMCoord.coordDictionnary[osmid].x + xOffset
         OSMCoord.coordDictionnary[osmid].z = OSMCoord.coordDictionnary[osmid].z - zOffset
     return xOffset, zOffset
示例#3
0
 def add(osmid, long, lat):
     """Add a new coordinate to the list from longitude latitude."""
     coord = OSMCoord()
     coord.OSMID = osmid
     coord.long = long
     coord.lat = lat
     coord.x, coord.z = Projection.project(coord.long, coord.lat)
     OSMCoord.coordDictionnary[osmid] = coord
示例#4
0
 def add(osmid, long, lat, tags):
     """Add a new node to the list from longitude latitude."""
     node = OSMNode()
     node.OSMID = osmid
     node.long = long
     node.lat = lat
     node.x, node.z = Projection.project(node.long, node.lat)
     node.tags = tags
     OSMNode.nodeDictionnary[osmid] = node
示例#5
0
def print_header(file, minlat, minlon, maxlat, maxlon, elevation=None):
    """Print the 'WorldInfo', 'Viewpoint', 'TexturedBackground', 'TexturedBackgroundLight' and 'Floor' nodes."""
    xSize, zSize = get_world_size(minlat=minlat,
                                  minlon=minlon,
                                  maxlat=maxlat,
                                  maxlon=maxlon)
    file.write("#VRML_SIM R2021a utf8\n")
    file.write("WorldInfo {\n")
    file.write("  info [\n")
    file.write(
        "    \"World generated using the Open Street Map to Webots importer\"\n"
    )
    file.write("    \"Author: David Mansolino <*****@*****.**>\"\n")
    file.write("  ]\n")
    file.write("  coordinateSystem \"NUE\"\n")
    longitude = (float(maxlon) + float(minlon)) / 2
    latitude = (float(maxlat) + float(minlat)) / 2
    x, z = Projection.project(longitude, latitude)
    height = 0
    if elevation is not None:
        height = elevation.interpolate_height(x, z)
    file.write("  gpsCoordinateSystem \"WGS84\"\n")
    file.write("  gpsReference " + str(latitude) + " " + str(longitude) + " " +
               str(height) + "\n")
    file.write("  lineScale " + str(round(max(xSize, zSize) / 200.0)) + "\n")
    file.write("}\n")
    file.write("Viewpoint {\n")
    file.write("  orientation 0.305 0.902 0.305 4.609\n")
    position = round(xSize * math.cos(0.785) * 1.5 +
                     zSize * math.cos(0.785) * 1.5)
    file.write("  position " + str(-position * 1.25) + " " + str(position) +
               " 0\n")
    file.write("  near 3\n")
    file.write("}\n")
    file.write("TexturedBackground {\n")
    file.write("}\n")
    file.write("TexturedBackgroundLight {\n")
    file.write("}\n")
    if elevation is None:
        file.write("Floor {\n")
        file.write("  translation 0 -0.02 0\n")
        file.write("  size " + str(round(1.5 * xSize)) + " " +
                   str(round(1.5 * zSize)) + "\n")
        file.write("  appearance PBRAppearance {\n")
        file.write("    baseColorMap ImageTexture {\n")
        file.write("      url [\n")
        file.write("        \"textures/grass.jpg\"\n")
        file.write("      ]\n")
        file.write("    }\n")
        file.write("    roughness 1\n")
        file.write("    metalness 0\n")
        file.write("  }\n")
        file.write("}\n")
    else:
        file.write(elevation.floorString)
示例#6
0
def print_header(file, minlat, minlon, maxlat, maxlon, elevation=None):
    """Print the 'WorldInfo', 'Viewpoint', 'TexturedBackground', 'TexturedBackgroundLight' and 'Floor' nodes."""
    xSize, zSize = get_world_size(minlat=minlat,
                                  minlon=minlon,
                                  maxlat=maxlat,
                                  maxlon=maxlon)
    file.write("#VRML_SIM R2018a utf8\n")
    file.write("WorldInfo {\n")
    file.write("  info [\n")
    file.write(
        "    \"World generated using the Open Street Map to Webots importer\"\n"
    )
    file.write("    \"Author: David Mansolino <*****@*****.**>\"\n")
    file.write("  ]\n")
    file.write("  northDirection 0 0 1\n")
    longitude = (float(maxlon) + float(minlon)) / 2
    latitude = (float(maxlat) + float(minlat)) / 2
    x, z = Projection.project(longitude, latitude)
    height = 0
    if elevation is not None:
        height = elevation.interpolate_height(x, z)
    file.write("  gpsCoordinateSystem \"WGS84\"\n")
    file.write("  gpsReference " + str(latitude) + " " + str(longitude) + " " +
               str(height) + "\n")
    file.write("  lineScale " + str(round(max(xSize, zSize) / 200.0)) + "\n")
    file.write("}\n")
    file.write("Viewpoint {\n")
    file.write("  orientation 0 0.92 0.38 3.1416\n")
    position = round(xSize * math.cos(0.785) * 1.5 +
                     zSize * math.cos(0.785) * 1.5)
    file.write("  position 0 " + str(position) + " " + str(-position) + "\n")
    file.write("  near 3\n")
    file.write("}\n")
    file.write("TexturedBackground {\n")
    file.write("}\n")
    file.write("TexturedBackgroundLight {\n")
    file.write("}\n")
    file.write("Fog {\n")
    file.write("  color 0.93 0.96 1.0\n")
    file.write("  visibilityRange %s\n" % (max(3000, xSize, zSize)))
    file.write("}\n")
    if elevation is None:
        file.write("Floor {\n")
        file.write("  translation 0 -0.02 0\n")
        file.write("  size " + str(round(1.5 * xSize)) + " " +
                   str(round(1.5 * zSize)) + "\n")
        file.write("  texture [\n")
        file.write("    \"textures/grass.jpg\"\n")
        file.write("  ]\n")
        file.write("}\n")
    else:
        file.write(elevation.floorString)
示例#7
0
 def calc_brightness(self):
     """
     Project the electron number density or gas mass density profile
     to calculate the 2D surface brightness profile.
     """
     if self.cf_radius is None or self.cf_value is None:
         raise ValueError("cooling function profile missing")
     if self.cf_spline is None:
         self.fit_spline(spline="cooling_function", log10=[])
     #
     ne = self.calc_density_electron()
     # flux per unit volume
     cf_new = self.eval_spline(spline="cooling_function", x=self.r)
     flux = cf_new * ne**2 / AstroParams.ratio_ne_np
     # project the 3D flux into 2D brightness
     rout = (self.r + self.r_err) * au.kpc.to(au.cm)
     projector = Projection(rout)
     brightness = projector.project(flux)
     return brightness