Skip to content

Commit

Permalink
Initial reformat with black
Browse files Browse the repository at this point in the history
  • Loading branch information
caitlinadams committed Jan 16, 2025
1 parent 5b53ed5 commit 3fb0323
Show file tree
Hide file tree
Showing 19 changed files with 945 additions and 591 deletions.
34 changes: 25 additions & 9 deletions check_gamma_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
REQUIRED_LIBS_PATH = "/g/data/yp75/projects/pyrosar_processing/sar-pyrosar-nci"

if os.environ.get("GAMMA_HOME", None) is None:

print(f"Setting GAMMA to {GAMMA_HOME_PATH}")
os.environ["GAMMA_HOME"] = GAMMA_HOME_PATH

Expand All @@ -21,23 +21,39 @@
else:
print(os.environ.get("LD_LIBRARY_PATH"))

commands_to_skip = ["coord_trans", "phase_sum", "dishgt", "SLC_cat", "ras_ratio_dB", "ptarg"]
commands_to_skip = [
"coord_trans",
"phase_sum",
"dishgt",
"SLC_cat",
"ras_ratio_dB",
"ptarg",
]

for module in finder(GAMMA_HOME_PATH, ['[A-Z]*'], foldermode=2):
for module in finder(GAMMA_HOME_PATH, ["[A-Z]*"], foldermode=2):
print(module)
for submodule in ['bin', 'scripts']:
for submodule in ["bin", "scripts"]:
print(f"{module}/{submodule}")
for cmd in sorted(finder(module+"/"+submodule, [r'^\w+$'], regex=True), key=lambda s: s.lower()):
for cmd in sorted(
finder(module + "/" + submodule, [r"^\w+$"], regex=True),
key=lambda s: s.lower(),
):
command_base = os.path.basename(cmd)
if command_base in commands_to_skip:
print(" skipping " + command_base)
else:

print(" " + command_base)
proc = sp.Popen(cmd, stdin=sp.PIPE, stdout=sp.PIPE, stderr=sp.PIPE, universal_newlines=True)
proc = sp.Popen(
cmd,
stdin=sp.PIPE,
stdout=sp.PIPE,
stderr=sp.PIPE,
universal_newlines=True,
)
out, err = proc.communicate()
out += err
usage = re.search('usage:.*(?=\n)', out)
usage = re.search("usage:.*(?=\n)", out)
if usage is None:
print(" " + err)
print("\n\n")
print("\n\n")
62 changes: 38 additions & 24 deletions sar_antarctica/nci/preparation/create_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,16 @@
from sar_antarctica.nci.preparation.orbits import find_latest_orbit_for_scene
from sar_antarctica.nci.preparation.dem import get_cop30_dem_for_bounds

def write_file_paths(config_file: Path, scene_file: Path, orbit_file: Path, dem_file: Path, data_dir: Path, ancillary_dir="ancillary", processed_dir="processed_scene"):

def write_file_paths(
config_file: Path,
scene_file: Path,
orbit_file: Path,
dem_file: Path,
data_dir: Path,
ancillary_dir="ancillary",
processed_dir="processed_scene",
):
inputs_header = "[inputs]\n"
scene_setting = f"scene = '{str(scene_file)}'\n"
orbit_setting = f"orbit = '{str(orbit_file)}'\n"
Expand All @@ -19,21 +28,24 @@ def write_file_paths(config_file: Path, scene_file: Path, orbit_file: Path, dem_
processed_setting = f"processed = '{processed_dir}'\n"

with open(config_file, "w") as cf:
cf.writelines([
inputs_header,
scene_setting,
orbit_setting,
dem_setting,
"\n",
outputs_header,
data_path_setting,
ancillary_setting,
processed_setting
])

cf.writelines(
[
inputs_header,
scene_setting,
orbit_setting,
dem_setting,
"\n",
outputs_header,
data_path_setting,
ancillary_setting,
processed_setting,
]
)


@click.command()
@click.argument("scene_id", nargs=1)
@click.argument('scene_config', nargs=1)
@click.argument("scene_config", nargs=1)
def main(scene_id: str, scene_config: str):
print(f"Processing scene: {scene_id} \n")

Expand All @@ -52,22 +64,24 @@ def main(scene_id: str, scene_config: str):
# Identify bounds of scene and use bounding box to build DEM
scene = identify(str(scene_file))
scene_bbox = scene.bbox().extent
scene_bounds = (scene_bbox["xmin"], scene_bbox["ymin"], scene_bbox["xmax"], scene_bbox["ymax"])
scene_bounds = (
scene_bbox["xmin"],
scene_bbox["ymin"],
scene_bbox["xmax"],
scene_bbox["ymax"],
)

# Set path for dem and create
dem_dir = data_dir / "dem"
dem_file = dem_dir / f"{scene_id}_dem.tif"
_, _ = get_cop30_dem_for_bounds(bounds=scene_bounds, save_path=dem_file, ellipsoid_heights=True)
_, _ = get_cop30_dem_for_bounds(
bounds=scene_bounds, save_path=dem_file, ellipsoid_heights=True
)

# Write to config file
write_file_paths(
config_file,
scene_file,
latest_poe_file,
dem_file,
data_dir
)
write_file_paths(config_file, scene_file, latest_poe_file, dem_file, data_dir)


if __name__ == "__main__":

main()
main()
27 changes: 19 additions & 8 deletions sar_antarctica/nci/preparation/create_dem_vrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path
from typing import Generator


def find_tiles(source_dir: Path, pattern: str) -> Generator[Path, None, None]:
"""_summary_
Expand All @@ -24,7 +25,12 @@ def find_tiles(source_dir: Path, pattern: str) -> Generator[Path, None, None]:

return tiles

def build_vrt(tiles: Generator[Path, None, None] | list[Path], vrt_path: str | os.PathLike, run: bool = True):

def build_vrt(
tiles: Generator[Path, None, None] | list[Path],
vrt_path: str | os.PathLike,
run: bool = True,
):
"""Generic function for building a VRT from a generator of tile paths
Parameters
Expand All @@ -42,11 +48,16 @@ def build_vrt(tiles: Generator[Path, None, None] | list[Path], vrt_path: str | o
f.writelines(f"{tile}\n" for tile in tiles)

if run:
os.system(f'gdalbuildvrt -input_file_list temp.txt {vrt_path}')
os.system(f"gdalbuildvrt -input_file_list temp.txt {vrt_path}")

os.remove("temp.txt")

def build_tileindex(tiles: Generator[Path, None, None] | list[Path], tindex_path: str | os.PathLike, run: bool = True):

def build_tileindex(
tiles: Generator[Path, None, None] | list[Path],
tindex_path: str | os.PathLike,
run: bool = True,
):
"""Generic function for building a tile index from a generator of tile paths
Parameters
Expand All @@ -64,18 +75,18 @@ def build_tileindex(tiles: Generator[Path, None, None] | list[Path], tindex_path
f.writelines(f"{tile}\n" for tile in tiles)

if run:
os.system(f'gdaltindex {tindex_path} --optfile temp.txt')
os.system(f"gdaltindex {tindex_path} --optfile temp.txt")

os.remove("temp.txt")


def create_glo30_dem_south_vrt():
"""Create a VRT for the Copernicus Global 30m DEM on NCI
"""

"""Create a VRT for the Copernicus Global 30m DEM on NCI"""

SOURCE_DIR = Path("/g/data/v10/eoancillarydata-2/elevation/copernicus_30m_world")
PATTERN = "Copernicus_DSM_COG_10_S??_00_????_00_DEM/*.tif"
VRT_PATH = Path("/g/data/yp75/projects/ancillary/dem/copdem_south.vrt")

tiles = find_tiles(SOURCE_DIR, PATTERN)

build_vrt(tiles, VRT_PATH)
build_vrt(tiles, VRT_PATH)
Loading

0 comments on commit 3fb0323

Please sign in to comment.