zooniverse / tprn-data-processing

The Planetary Response Network data processing pipeline
1 stars 1 forks source link

Converting from image coordinates to lat and lon #7

Open CKrawczyk opened 5 years ago

CKrawczyk commented 5 years ago

Looking at the metadata from the latest Dorian PRN project the metadata names have changed from lat_min to //lat_min, lon_min to //lon_min, etc... Additionally it looks like the get_lat_coords_from_pixels has the interp1d function the wrong way around.

On Panoptes the classifications use SVG coordinates that has (0,0) in the upper left of the image as opposed to lat-lon coordinates that would have the origin in the lower left. For the drawn points the min value will always be 0 and the max value will be determined by the size of the images uploaded, minus any parts are the bottom added for the "before" and "after" labels. This pixel size can be pulled from the //tifsize_x_pix and //tifsize_y_pix metadata.

Taking this into account the updated lat and lon conversion code should look like:

def get_lat_coords_from_pixels(marks, geo_metadata):
    try:
        the_y = np.array([0, geo_metadata['//tifsize_y_pix']], dtype=float)
        the_lat = np.array([geo_metadata['//lat_max'], geo_metadata['//lat_min']], dtype=float)
    except KeyError as e:
        # missing data for the converstion to lat / lon
        raise MissingCoordinateMetadata(str(e))

    # setup interpolation functions to get the lat / lon from pixel marks
    # don't throw an error if the coords are out of bounds, but also don't extrapolate
    f_y_lat = interp1d(the_y, the_lat, bounds_error=False, fill_value=(None, None))

    return f_y_lat(marks)

def get_lon_coords_from_pixels(marks, geo_metadata):
    try:
        the_x = np.array([0, geo_metadata['//tifsize_x_pix']], dtype=float)
        the_lon = np.array([geo_metadata['//lon_min'], geo_metadata['//lon_max']], dtype=float)
    except KeyError as e:
        # missing data for the converstion to lat / lon
        raise MissingCoordinateMetadata(str(e))

    # setup interpolation functions to get the lat / lon from pixel marks
    # don't throw an error if the coords are out of bounds, but also don't extrapolate
    f_x_lon = interp1d(the_x, the_lon, bounds_error=False, fill_value=(None, None))

    return f_x_lon(marks)
CKrawczyk commented 5 years ago

Let me know if you would like this as a PR (not sure how much refactoring you are going to do, so figured I would hold off just in case).