Skip to content

Commit

Permalink
adding comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Enovotny committed Oct 2, 2023
1 parent 3fcddbe commit 63bb1ae
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/cumulus_geoproc/utils/cgdal.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def openfileGDAL(src, dst):
return ds, src_path, dst_path


def findsubset(ds, subset_params):
def findsubset(ds: gdal.Dataset, subset_params):
"""Find and open correct Subdataset in gdal file and open it
Parameters
Expand Down Expand Up @@ -397,7 +397,9 @@ def findsubset(ds, subset_params):
return ds


def getVersionDate(ds, src_path, metaVar, fileDateFormat, filedateSearch):
def getVersionDate(
ds: gdal.Dataset, src_path, metaVar: str, fileDateFormat: str, filedateSearch
):
"""Get the Version date of the grid
Parameters
ds: osgeo.gdal.Dataset Object
Expand Down Expand Up @@ -434,7 +436,19 @@ def getVersionDate(ds, src_path, metaVar, fileDateFormat, filedateSearch):
return version_datetime


def geoTransform_ds(ds, SUBSET_NAME):
def geoTransform_ds(ds: gdal.Dataset, SUBSET_NAME: str, dstSRS: str = "EPSG:4326"):
"""
Args:
ds (gdal.Dataset): open GDAL object
SUBSET_NAME (str): used to grab meta data from the gdal object
dstSRS (str, optional): projection to convert the gdal object to. Defaults to "EPSG:4326".
Returns:
warp(gdal.Dataset): gdal object with correct projection and geotranformation
lonLL, latLL, lonUR, latUR: Lat and long of Lower Left corner and Upper Right corner of dataset
"""
sub_meta = ds.GetMetadata_Dict()

# Initial metadata value for qpe_grid#latLonLL looks like: "{-123.6735229012065,29.94159256439344}"
Expand Down Expand Up @@ -488,13 +502,13 @@ def geoTransform_ds(ds, SUBSET_NAME):

ds.SetGeoTransform(geotransform)
ds.SetProjection(hrap.PROJ4)
warp = gdal.Warp("", ds, format="vrt", dstSRS="EPSG:4326")
warp = gdal.Warp("", ds, format="vrt", dstSRS=dstSRS)
return warp, lonLL, latLL, lonUR, latUR


def subsetOutFile(
ds,
SUBSET_NAME,
ds: gdal.Dataset,
SUBSET_NAME: str,
dst_path,
acquirable,
version_datetime,
Expand Down Expand Up @@ -544,8 +558,7 @@ def subsetOutFile(
nodata = raster_band.GetNoDataValue()
cgdal.gdal_translate_w_options(
tif := str(
dst_path
/ f'{acquirable}testing.{valid_datetime.strftime("%Y%m%d_%H%M")}.tif'
dst_path / f'{acquirable}.{valid_datetime.strftime("%Y%m%d_%H%M")}.tif'
),
ds,
bandList=[i],
Expand Down

0 comments on commit 63bb1ae

Please sign in to comment.