Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
rhugonnet committed Nov 17, 2024
1 parent 662221f commit 268eb15
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion doc/source/core_inheritance.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ If you are DEM-enthusiastic, **[check-out our sister package xDEM](https://xdem.
Many types of geospatial data can be viewed as a subclass of {class}`Rasters<geoutils.Raster>`, which have more attributes and require their own methods:
**spectral images**, **velocity fields**, **phase difference maps**, etc...

If you are interested to build your own subclass of {class}`~geoutils.Raster`, you can take example of the structure of {class}`xdem.DEM`.
If you are interested to build your own subclass of {class}`~geoutils.Raster`, you can take example of the structure of {class}`xdem.DEM`.
Then, just add any of your own attributes and methods, and overload parent methods if necessary! Don't hesitate to reach out on our
GitHub if you have a subclassing project.
2 changes: 1 addition & 1 deletion geoutils/raster/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def __init__(
raise TypeError("The filename argument is not recognised, should be a path or a Rasterio dataset.")

# Parse metadata and add to tags
if parse_sensor_metadata:
if parse_sensor_metadata and self.filename is not None:
sensor_meta = parse_and_convert_metadata_from_filename(self.filename, silent=silent)
self.tags.update(sensor_meta)

Expand Down
22 changes: 12 additions & 10 deletions geoutils/raster/satimg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@

from __future__ import annotations

from typing import TypedDict

import datetime as dt
import os
import re
from collections import abc
from typing import Any
from typing import Any, TypedDict

import numpy as np

# Metadata tags used for all
satimg_tags = ["platform", "sensor", "product", "version", "tile_name", "datetime"]


class SatImgDict(TypedDict, total=False):
"""Keys and types of inputs associated with image metadata."""

Expand All @@ -34,6 +33,7 @@ class SatImgDict(TypedDict, total=False):
xtile_size: float
ytile_size: float


def parse_landsat(gname: str) -> list[Any]:
"""Parse Landsat metadata."""

Expand Down Expand Up @@ -71,7 +71,7 @@ def parse_metadata_from_fn(filename: str) -> SatImgDict:
# Extract basename from full filename
bname = os.path.splitext(os.path.basename(filename))[0]

# The attributes correspond in order to: satellite, sensor, product, version, tile_name, datetime
# The attributes correspond in order to: platform, sensor, product, version, tile_name, datetime
tags = satimg_tags

# First, we assume that the filename has a form XX_YY.ext
Expand Down Expand Up @@ -163,7 +163,7 @@ def parse_metadata_from_fn(filename: str) -> SatImgDict:
else:
attrs = (None,) * 6

dict_meta = {tags[i]: attrs[i] for i in range(len(tags))}
dict_meta: SatImgDict = {tags[i]: attrs[i] for i in range(len(tags))} # type: ignore

return dict_meta

Expand Down Expand Up @@ -293,10 +293,12 @@ def latlon_to_sw_naming(

return tile_name


###################################################
# MAIN FUNCTION THAT WILL BE CALLED BY RASTER CLASS
###################################################


def parse_and_convert_metadata_from_filename(filename: str, silent: bool = False) -> SatImgDict:
"""
Attempts to pull metadata (e.g., sensor, date information) from fname, and convert to human-usable format.
Expand All @@ -314,16 +316,16 @@ def parse_and_convert_metadata_from_filename(filename: str, silent: bool = False
return {}

# Else, if not silent, print what was read
for a in attrs.keys():
if attrs[a] is not None:
for k, v in attrs.items():
if v is not None:
if not silent:
print("Setting " + a + " as " + str(attrs[a])+ " read from filename.")
print("Setting " + k + " as " + str(v) + " read from filename.")

# And convert tile name to human-readable tile extent/size
supported_tile = ["ASTGTM2", "SRTMGL1", "NASADEM", "TDM1"]
supported_tile = ["ASTGTM2", "SRTMGL1", "NASADEM", "TDM1"]
if attrs["tile_name"] is not None and attrs["product"] is not None and attrs["product"] in supported_tile:
ymin, xmin, yx_sizes, _ = parse_tile_attr_from_name(attrs["tile_name"], product=attrs["product"])
tile_attrs = {"xtile_min": xmin, "ytile_min": ymin, "xtile_size": yx_sizes[1], "ytile_size": yx_sizes[0]}
tile_attrs = SatImgDict(xtile_min=xmin, ytile_min=ymin, xtile_size=yx_sizes[1], ytile_size=yx_sizes[0])
attrs.update(tile_attrs)

return attrs

0 comments on commit 268eb15

Please sign in to comment.