From 4e069b731c178872c3c8dc2ee000f16722531b14 Mon Sep 17 00:00:00 2001 From: acpaquette Date: Fri, 15 Jun 2018 13:50:27 -0700 Subject: [PATCH] Generic reproject (#56) * Small updates to get the scripts working. * Fixed pradius calculations, and made some small changes. * Removed coord transforms and made body_fix func more generic. * Updated version. * Updated reproj doc string. --- plio/spatial/transformations.py | 144 ++++++-------------------------- recipe/meta.yaml | 2 +- setup.py | 2 +- 3 files changed, 27 insertions(+), 121 deletions(-) diff --git a/plio/spatial/transformations.py b/plio/spatial/transformations.py index b04e92c..b185a9d 100644 --- a/plio/spatial/transformations.py +++ b/plio/spatial/transformations.py @@ -171,34 +171,17 @@ def get_axis(file): return eRadius, pRadius -def lat_ISIS_coord(record, semi_major, semi_minor): - """ - Function to convert lat_Y_North to ISIS_lat - - Parameters - ---------- - record : object - Pandas series object - - semi_major : float - Radius from the center of the body to the equater - - semi_minor : float - Radius from the pole to the center of mass - - Returns - ------- - coord_360 : float - Converted latitude into ocentric space, and mapped - into 0 to 360 - """ - ocentric_coord = og2oc(record['lat_Y_North'], semi_major, semi_minor) - coord_360 = to_360(ocentric_coord) - return coord_360 - -def lon_ISIS_coord(record, semi_major, semi_minor): - """ - Function to convert long_X_East to ISIS_lon +def reproject(record, semi_major, semi_minor, source_proj, dest_proj, **kwargs): + """ + Thin wrapper around PyProj's Transform() function to transform 1 or more three-dimensional + point from one coordinate system to another. If converting between Cartesian + body-centered body-fixed (BCBF) coordinates and Longitude/Latitude/Altitude coordinates, + the values input for semi-major and semi-minor axes determine whether latitudes are + planetographic or planetocentric and determine the shape of the datum for altitudes. + If semi_major == semi_minor, then latitudes are interpreted/created as planetocentric + and altitudes are interpreted/created as referenced to a spherical datum. + If semi_major != semi_minor, then latitudes are interpreted/created as planetographic + and altitudes are interpreted/created as referenced to an ellipsoidal datum. Parameters ---------- @@ -211,97 +194,23 @@ def lon_ISIS_coord(record, semi_major, semi_minor): semi_minor : float Radius from the pole to the center of mass - Returns - ------- - coord_360 : float - Converted longitude into ocentric space, and mapped - into 0 to 360 - """ - ocentric_coord = og2oc(record['long_X_East'], semi_major, semi_minor) - coord_360 = to_360(ocentric_coord) - return coord_360 - -def lat_socet_coord(record, semi_major, semi_minor): - """ - Function to convert lat_Y_North to ISIS_lat - - Parameters - ---------- - record : object - Pandas series object + source_proj : str + Pyproj string that defines a projection space ie. 'geocent' - semi_major : float - Radius from the center of the body to the equater - - semi_minor : float - Radius from the pole to the center of mass - - Returns - ------- - coord_360 : float - Converted latitude into ocentric space, and mapped - into 0 to 360 - """ - ographic_coord = oc2og(record['lat_Y_North'], semi_major, semi_minor) - coord_180 = ((ographic_coord + 180) % 360) - 180 - return coord_180 - -def lon_socet_coord(record, semi_major, semi_minor): - """ - Function to convert long_X_East to ISIS_lon - - Parameters - ---------- - record : object - Pandas series object - - semi_major : float - Radius from the center of the body to the equater - - semi_minor : float - Radius from the pole to the center of mass - - Returns - ------- - coord_360 : float - Converted longitude into ocentric space, and mapped - into 0 to 360 - """ - ographic_coord = oc2og(record['long_X_East'], semi_major, semi_minor) - coord_180 = ((ographic_coord + 180) % 360) - 180 - return coord_180 - -def body_fix(record, semi_major, semi_minor, inverse = False, **kwargs): - """ - Transforms latitude, longitude, and height of a socet point into - a body fixed point - - Parameters - ---------- - record : object - Pandas series object - - semi_major : float - Radius from the center of the body to the equater - - semi_minor : float - Radius from the pole to the center of mass + dest_proj : str + Pyproj string that defines a project space ie. 'latlon' Returns ------- : list - Body fixed lat, lon and height coordinates as lat, lon, ht + Transformed coordinates as y, x, z """ - ecef = pyproj.Proj(proj='geocent', a=semi_major, b=semi_minor) - lla = pyproj.Proj(proj='latlon', a=semi_major, b=semi_minor) + source_pyproj = pyproj.Proj(proj = source_proj, a = semi_major, b = semi_minor) + dest_pyproj = pyproj.Proj(proj = dest_proj, a = semi_major, b = semi_minor) - if inverse: - lon, lat, height = pyproj.transform(ecef, lla, record[0], record[1], record[2], **kwargs) - return lon, lat, height - else: - y, x, z = pyproj.transform(lla, ecef, record[0], record[1], record[2], **kwargs) - return y, x, z + y, x, z = pyproj.transform(source_pyproj, dest_pyproj, record[0], record[1], record[2], **kwargs) + return y, x, z def stat_toggle(record): if record['stat'] == 0: @@ -338,11 +247,10 @@ def apply_isis_transformations(df, eRadius, pRadius, serial_dict, extension, cub """ # Convert from geocentered coords (x, y, z), to lat lon coords (latitude, longitude, alltitude) ecef = np.array([[df['long_X_East']], [df['lat_Y_North']], [df['ht']]]) - lla = body_fix(ecef, semi_major = eRadius, semi_minor = pRadius, inverse=True) - df['long_X_East'], df['lat_Y_North'], df['ht'] = lla[0][0], lla[1][0], lla[2][0] + lla = reproject(ecef, semi_major = eRadius, semi_minor = pRadius, + source_proj = 'latlon', dest_proj = 'geocent') - # df['lat_Y_North'] = df.apply(lat_socet_coord, semi_major = eRadius, semi_minor = pRadius, axis=1) - # df['long_X_East'] = df.apply(lon_socet_coord, semi_major = eRadius, semi_minor = pRadius, axis=1) + df['long_X_East'], df['lat_Y_North'], df['ht'] = lla[0][0], lla[1][0], lla[2][0] # Update the stat fields and add the val field as it is just a clone of stat df['stat'] = df.apply(ignore_toggle, axis = 1) @@ -392,12 +300,10 @@ def apply_socet_transformations(atf_dict, df): eRadius, pRadius = get_axis(prj_file) - # df['lat_Y_North'] = df.apply(lat_ISIS_coord, semi_major = eRadius, semi_minor = pRadius, axis=1) - # df['long_X_East'] = df.apply(lon_ISIS_coord, semi_major = eRadius, semi_minor = pRadius, axis=1) - lla = np.array([[df['long_X_East']], [df['lat_Y_North']], [df['ht']]]) - ecef = body_fix(lla, semi_major = eRadius, semi_minor = pRadius, inverse=False) + ecef = reproject(lla, semi_major = eRadius, semi_minor = pRadius, + source_proj = 'geocent', dest_proj = 'latlon') df['s.'], df['l.'], df['image_index'] = (zip(*df.apply(line_sample_size, path = atf_dict['PATH'], axis=1))) df['known'] = df.apply(known, axis=1) diff --git a/recipe/meta.yaml b/recipe/meta.yaml index b331207..c2dae1d 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -1,6 +1,6 @@ package: name: plio - version: 0.1.3 + version: 0.1.4 source: git_url: https://github.com/USGS-Astrogeology/plio diff --git a/setup.py b/setup.py index 8c8e392..040954e 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ def setup_package(): setup( name = "plio", - version = '0.1.3', + version = '0.1.4', author = "Jay Laura", author_email = "jlaura@usgs.gov", description = ("I/O API to support planetary data formats."), -- GitLab