Geotools

Utilities to work with geo-referenced (image) data. (GDAL required)

Abbreviations

  • ul = Upper Left
  • lr = LowerRight

source

pixel_to_meter

 pixel_to_meter (sample, line, geotransform, shift=False)

provide point in map projection coordinates.

Type Default Details
sample
line
geotransform
shift bool False
Returns tuple (x,y) coordinates in the projection of the dataset

source

shift_to_center

 shift_to_center (x, y, geotransform)

source

debug_srs

 debug_srs (projection)

*Correct wrong scale_factor in PolarStereographic data.

Some PolarStereographic data have a 0 as a scale_factor in the projection (mostly MOLA), which is being corrected here. TODO: Check for being PolarStereographic before doing this!*


source

get_sun_angles

 get_sun_angles (spicer, img)

*Calculate solar azimuth and incidence.

By requiring a spicer object for this function, it becomes independent from the solar system object where the calculations are made.*

Type Details
spicer spicer.Spicer needs to be setup for time, but spoint is set from img.center in here.
img geotools.ImgData The image data of which the center point serves as the start point.
Returns tuple(float, float) Solar azimuth, incidence [degrees]

source

calculate_image_north_azimuth

 calculate_image_north_azimuth (img, zero='right')

source

get_north_shifted_point

 get_north_shifted_point (img, offset=0.001)

Increasing the latitude is a sure way of getting north.


source

calculate_image_azimuth

 calculate_image_azimuth (origPoint, newPoint, zero='right')

*Calculate azimuth angle between 2 image points.

Beware that this function calculates trigonometric angles. If the points are from an image that has (0, 0) in the upper left, this means that the angles increase clockwise. That is why, for example, for an HiRISE image, the return of this function matches the angle rotation definition for HiRISE data.*

Type Default Details
origPoint
newPoint
zero str right
Returns azimuth: Azimuth angle
/home/runner/micromamba/envs/my-env/lib/python3.12/site-packages/fastcore/docscrape.py:225: UserWarning: Unknown section Requires
  else: warn(msg)

source

Point

 Point (sample=None, line=None, x=None, y=None, lon=None, lat=None,
        geotrans=None, proj=None)

Point class to manage pixel and map points and their transformations.


source

Window

 Window (ulPoint=None, lrPoint=None, centerPoint=None, width=None)

*class to manage a window made of corner Points (objects of Point())

when using width, only quadratic windows supported currently >>> p1 = Point(0, 1) >>> p2 = Point(10,20)*


source

ImgData

 ImgData (fname=None)

docstring for ImgData

# todo: Fix missing MOLA class
#| export
# class CTX(ImgData):
#     """docstring for CTX"""

#     def __init__(self, fname):
#         ImgData.__init__(self, fname)

#     def add_mola_contours(self):
#         self.window_coords_to_lonlat()
#         mola = MOLA()
#         mola.window = self.window.copy()
#         mola.window_coords_to_pixel()
#         mola.read_window(mola.window)
#         mola.data = mola.data - mola.data.mean()
#         fig = plt.figure(figsize=(10, 10))
#         ax = fig.add_subplot(111)
#         plt.gray()
#         ax.imshow(self.data, extent=self.window.get_extent(self.dataset))
#         CS = ax.contour(
#             mola.data,
#             8,
#             cmap=cm.jet,
#             extent=self.window.get_extent(self.dataset),
#             origin="image",
#         )
#         plt.clabel(CS, fontsize=13, inline=1)
#         ax.set_xlabel("Polar stereographic X [km]")
#         ax.set_ylabel("Polar stereographic Y [km]")
#         ax.set_title("CTX: " + os.path.basename(self.fname))
#         self.ax = ax
#         plt.show()
# def combine_ctx_and_mola(ctxFilename, ctxSample, ctxLine, ctxWidth):
#     """combine CTX and MOLA data.
#
#     MOLA and CTX data will be combined with these tools.
#     User shall provide line,sample center coordinate of CTX file ROI to
#     define distance in meters from southpole.
#     """
#
#     ctx = CTX(ctxFilename)
#     mola = MOLA()
#     ctxULsample, ctxULline, ctxLRsample, ctxLRline = \
#         get_corners_from_center(ctxSample, ctxLine, ctxWidth)
#     ulX,ulY = get_coords_from_pixels(ctxDS, ctxULsample, ctxULline)
#     lrX,lrY = get_coords_from_pixels(ctxDS, ctxLRsample, ctxLRline)
#
#     molaULsample,molaULline = get_pixels_from_coords(molaDS,ulX,ulY)
#     molaLRsample,molaLRline = get_pixels_from_coords(molaDS,lrX,lrY)
#     print(ctxULsample, ctxULline, ctxLRsample, ctxLRline)
#     print(molaULsample, molaULline,molaLRsample, molaLRline)
#     print(ulX,ulY,lrX,lrY)
#     ctxData = ctxDS.ReadAsArray(ctxULsample,ctxULline,ctxWidth,ctxWidth)
#     molaData = molaDS.ReadAsArray(int(molaULsample)+1,int(molaULline),
#                                   int(molaLRsample - molaULsample),
#                                   int(molaLRline - molaULline))
#
#     molaData = molaData - molaData.mean()
#
#     # x = np.arange(ulX,lrX)
#     # y = np.arange(lrY,ulY)
#     # X, Y = np.meshgrid(x,y)
#     # plotting
#     fig = plt.figure(figsize=(10,10))
#     ax = fig.add_subplot(111)
#     plt.gray()
#     ax.imshow(ctxData, extent=(min(ulX,lrX),max(ulX,lrX),min(ulY,lrY),
#                                      max(ulY,lrY)))
#     CS = ax.contour(molaData, 20, cmap = cm.jet,
#                      extent=(min(ulX,lrX),
#                              max(ulX,lrX),
#                              min(ulY,lrY),
#                              max(ulY,lrY)),
#                      origin='image' )
#     plt.clabel(CS,fontsize=9, inline=1)
#     plt.show()

# def main(argv=None):
#     """docstring for main"""
#     from mayavi import mlab

#     if argv is None:
#         argv = sys.argv

#     x1 = x2 = y1 = y2 = 0
#     fname = ""
#     try:
#         fname = argv[1]
#         x1, x2, y1, y2 = [int(i) for i in argv[2:]]
#     except:
#         print("Usage: {0} fname x1 x2 y1 y2".format(argv[0]))

#     print(x1, x2, y1, y2)
#     ds = gdal.Open(fname)
#     band = ds.GetRasterBand(1)
#     STORED_VALUE = band.ReadAsArray(x1, y1, x2 - x1, y2 - y1)
#     ds = 0

#     # PDS label infos:
#     SCALING_FACTOR = 0.25
#     OFFSET = -8000
#     topo = (STORED_VALUE * SCALING_FACTOR) + OFFSET
#     mlab.surf(topo, warp_scale=1 / 115.0, vmin=1700)
#     mlab.colorbar(orientation="vertical", title="Height [m]", label_fmt="%4.0f")
#     mlab.show()