Beispiel #1
0
 def get_altitude(self, point):
     point = round_coords(point)
     alt = self.altitudes.get(point)
     if not alt:
         alt = get_altitude(point)
         self.altitudes[point] = alt
     return alt
Beispiel #2
0
    def test_azalt2spherical_1(self):
        """Test azimuth, altitude 2 spherical 1"""
        a_point = utils.azalt2spherical(an_azimuth=utils.parse_angle_arg('248:02:0.77676'),
                                        an_altitude=utils.parse_angle_arg('15:07:30.0779'))

        self.assertAlmostEqual(248.03354910000002, utils.get_azimuth(a_point).value)
        self.assertAlmostEqual(15.125021649800004, utils.get_altitude(a_point).value)

        return
def generate_weather_data(cities):
    full_weather_data = []
    for city in cities:
        latitude, longitude = utils.get_lat_and_lon()
        altitude = utils.get_altitude()
        local_time = utils.get_local_time()
        temperature = utils.get_temperature()
        pressure = utils.get_pressure()
        weather_condition = utils.get_condition(temperature)
        humidity = utils.get_humidity()

        entry = utils.create_weather_entry(city, latitude, longitude, altitude,
                                           local_time, weather_condition,
                                           temperature, pressure, humidity)
        full_weather_data.append(entry)
    return full_weather_data
Beispiel #4
0
def profile():
  try:
    body = group(json.loads(request.data))

    interpolated_path = []
    for line in body:
      interpolated_path.append(interpolate(line[0], line[1]))

    result = []
    for line in interpolated_path:
      for point in line:
        alt = int(get_altitude(point[1], point[0]))
        result.append([*point, alt])

    print(result)
    return make_response(json.dumps(result), 200)
  except:
    return Response(status=404)
def rescale_image(image_directory, image_name, target_pixel_size,
                  data_filename):
    altitude = get_altitude(image_name.split(".")[0], data_filename)
    print(image_directory + image_name)
    image, image_width, image_height = get_image_and_info(image_directory +
                                                          image_name)
    pixel_height = get_pixel_size(altitude, image_height,
                                  vertical_opening_angle)
    pixel_width = get_pixel_size(altitude, image_width,
                                 horizontal_opening_angle)
    vertical_rescale = pixel_height / target_pixel_size
    horizontal_rescale = pixel_width / target_pixel_size
    print("pixel height = " + str(pixel_height) + ", pixel width = " +
          str(pixel_width))
    print("rescaling image - " + str(vertical_rescale) + " " +
          str(horizontal_rescale))
    size = (int(image_width * horizontal_rescale),
            int(image_height * vertical_rescale))
    image = Image.fromarray(image.astype("uint8"), "RGB")
    image = image.resize(size, Image.BICUBIC)
    return np.array(image)
def coco_labels_scale_correction(
    coco_labels_filepath,
    output_coco_labels_filepath,
    altitude_data_filepath,
    image_width,
    image_height,
):
    data = initialise_data_dictionary(coco_labels_filepath +
                                      "annotations.json")

    # load coco info
    coco = COCO(coco_labels_filepath + "annotations.json")
    img_ids = coco.getImgIds()
    cat_ids = coco.getCatIds()

    for img_id in img_ids:
        # get annotations for image
        anns_ids = coco.getAnnIds(imgIds=[img_id],
                                  catIds=cat_ids,
                                  iscrowd=None)
        anns = coco.loadAnns(anns_ids)
        coco_image = coco.loadImgs([img_id])[0]
        image_width = coco_image["width"]
        image_height = coco_image["height"]
        image_name = coco_image["file_name"].split("/")[1].split(".")[0]
        altitude = get_altitude(image_name, altitude_data_filepath)
        print("altitude: " + str(altitude) + ", image height: " +
              str(image_height) + ", vertical opening angle: " +
              str(vertical_opening_angle))
        pixel_height = get_pixel_size(altitude, image_height,
                                      vertical_opening_angle)
        pixel_width = get_pixel_size(altitude, image_width,
                                     horizontal_opening_angle)
        vertical_rescale = pixel_height / target_pixel_size
        horizontal_rescale = pixel_width / target_pixel_size
        print("pixel_height - " + str(pixel_height) + ", pixel_width: " +
              str(pixel_width))
        print("rescaling coco - " + str(vertical_rescale) + " " +
              str(horizontal_rescale))

        for image in data["images"]:
            if image["id"] == img_id:
                image["height"] = int(image["height"] * vertical_rescale)
                image["width"] = int(image["width"] * horizontal_rescale)
        # loop through, correcting scale on each annotation and appending to new list of annotations
        for ann in anns:
            new_area = ann["area"] * horizontal_rescale * vertical_rescale
            new_bounding_box = [
                p * vertical_rescale if i % 2 else p * horizontal_rescale
                for i, p in enumerate(ann["bbox"])
            ]
            new_segmentation = [
                p * vertical_rescale if i % 2 else p * horizontal_rescale
                for i, p in enumerate(ann["segmentation"][0])
            ]
            new_annotation = {
                "segmentation": [new_segmentation],
                "area": new_area,
                "iscrowd": 0,
                "image_id": ann["image_id"],
                "bbox": new_bounding_box,
                "category_id": ann["category_id"],
                "id": ann["id"],
            }
            data["annotations"].append(new_annotation)
    save_new_annotations_file(output_coco_labels_filepath, data)
Beispiel #7
0
 def test_get_altitude(self):
     altitude = utils.get_altitude(
         "fakeimage2", "./test/mock_data/mock_altitude.csv"
     )
     self.assertEqual(altitude, "6.5")
Beispiel #8
0
 def __init__(self, lat, lon):
   self.lat = float(lat)
   self.lon = float(lon)
   self.alt = int(get_altitude(self.lon, self.lat))
    an_observer = utils.latlon2spherical(a_latitude=utils.parse_angle_arg(args[2]),
                                         a_longitude=utils.parse_angle_arg(args[3]))

    a_datetime = coords.datetime(args[4])

    # TODO validate toEquatorial/toHorizon option logic

    # ---------------------
    # ----- transform -----
    # ---------------------

    if options.toEquatorial is True:

        an_object = utils.azalt2spherical(an_azimuth=utils.parse_angle_arg(args[0]),
                                          an_altitude=utils.parse_angle_arg(args[1]))

        result = toEquatorial(an_object, an_observer, a_datetime, is_verbose=options.verbose)

        print 'Equatorial Latitude:', utils.get_latitude(result),
        print ', Longitude:', utils.get_longitude(result),

    else:

        an_object = utils.radec2spherical(a_right_ascension=utils.parse_angle_arg(args[0]),
                                          a_declination=utils.parse_angle_arg(args[1]))

        result = toHorizon(an_object, an_observer, a_datetime, is_verbose=options.verbose)

        print 'Azimuth:', utils.get_azimuth(result),
        print ', Altitude:', utils.get_altitude(result)
Beispiel #10
0
 def test_altitude(self):
     alt = utils.get_altitude()
     self.assertGreater(float(alt), 0)
     self.assertLess(float(alt), 5000)