Advertisement
Abhisek92

Lunar_Mean.py

Jun 19th, 2023 (edited)
841
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.40 KB | None | 0 0
  1. import numpy as np
  2. import rasterio as rio
  3. from rasterio.crs import CRS
  4. from rasterio.warp import transform
  5. from rasterio.windows import Window
  6. from rasterio.transform import rowcol
  7.  
  8. radius = 200
  9.  
  10. gcs_moon_2000 = CRS.from_wkt(
  11.     """GEOGCS["GCS_Moon_2000",DATUM["D_Moon_2000",SPHEROID["Moon_2000_IAU_IAG",1737400,0,AUTHORITY["ESRI","107903"]],AUTHORITY["ESRI","106903"]],PRIMEM["Reference_Meridian",0,AUTHORITY["ESRI","108900"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["ESRI","104903"]]"""
  12. )
  13. with rio.open("Apollo_14.tiff", "r") as src:
  14.     res_x, res_y = src.res
  15.     meta = src.meta.copy()
  16.     origin_x, origin_y = transform(src_crs=gcs_moon_2000, dst_crs=meta["crs"], xs=[-17.47139], ys=[-3.64544], zs=None)
  17.     origin_r, origin_c = rowcol(transform=meta["transform"], xs=origin_x[0], ys=origin_y[0], op=lambda x: x, precision=None)
  18.     rx, ry = radius / res_x, radius / res_y
  19.     row_off, col_off = round(origin_r - rx), round(origin_c - ry)
  20.     wh, ww = round(2 * rx), round(2 * ry)
  21.     window = Window(row_off=row_off, col_off=col_off, height=wh, width=ww)
  22.     r, c = np.meshgrid(np.arange(0, wh), np.arange(0, ww))
  23.     mask = (((r - (wh / 2) + 0.5) / rx) **2) + (((c - (ww / 2) + 0.5) / ry) ** 2) >= 1
  24.     arr = src.read(window=window, masked=True, boundless=True, fill_value=meta["nodata"])
  25.     arr.mask = np.logical_or(arr.mask, mask)
  26.     print(arr.mean(axis=(1, 2)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement