Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruff formatting for some modules #686

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

[Unreleased]
### Changed
* [686](https://github.com/dbekaert/RAiDER/pull/686) - Linted the project with `ruff`.
* [672](https://github.com/dbekaert/RAiDER/pull/672) - Linted the project with `ruff`.
* [683](https://github.com/dbekaert/RAiDER/pull/683) - Fixed a naive datetime and added default template to template generation argument

Expand Down
41 changes: 19 additions & 22 deletions test/test_gnss.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
from pathlib import Path
from RAiDER.models.customExceptions import NoStationDataFoundError
from RAiDER.gnss.downloadGNSSDelays import (
get_stats_by_llh, get_station_list, download_tropo_delays,
filterToBBox
)
from RAiDER.gnss.processDelayFiles import (
addDateTimeToFiles,
getDateTime,
concatDelayFiles
)
import datetime
import os
import pytest
from pathlib import Path

import pandas as pd
import pytest

from RAiDER.gnss.downloadGNSSDelays import download_tropo_delays, filterToBBox, get_station_list, get_stats_by_llh
from RAiDER.gnss.processDelayFiles import addDateTimeToFiles, concatDelayFiles, getDateTime
from RAiDER.models.customExceptions import NoStationDataFoundError
from test import TEST_DIR, pushd


from test import pushd, TEST_DIR
SCENARIO2_DIR = os.path.join(TEST_DIR, "scenario_2")


Expand Down Expand Up @@ -125,17 +120,19 @@ def test_download_tropo_delays2():


def test_download_tropo_delays2(tmp_path):
stations, output_file = get_station_list(
stationFile=os.path.join(SCENARIO2_DIR, 'stations.csv'))
with pushd(tmp_path):
stations, output_file = get_station_list(
stationFile=os.path.join(SCENARIO2_DIR, 'stations.csv')
)

# spot check a couple of stations
assert 'CAPE' in stations
assert 'FGNW' in stations
assert isinstance(output_file, str)
# spot check a couple of stations
assert 'CAPE' in stations
assert 'FGNW' in stations
assert isinstance(output_file, str)

# try downloading the delays
download_tropo_delays(stats=stations, years=[2022], writeDir=tmp_path)
assert True
# try downloading the delays
download_tropo_delays(stats=stations, years=[2022], writeDir=tmp_path)
assert True


def test_filterByBBox1():
Expand Down
10 changes: 5 additions & 5 deletions test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
writeArrayToRaster, rio_profile,
rio_extents, getTimeFromFile, enu2ecef, ecef2enu,
transform_bbox, clip_bbox, get_nearest_wmtimes,
robmax,robmin,padLower,convertLons,
padLower,convertLons,
projectDelays,floorish,round_date,
)

Expand Down Expand Up @@ -551,10 +551,10 @@ def test_rio_4():


def test_robs():
assert robmin([1, 2, 3, np.nan])==1
assert robmin([1,2,3])==1
assert robmax([1, 2, 3, np.nan])==3
assert robmax([1,2,3])==3
assert np.nanmin([1, 2, 3, np.nan])==1
assert np.nanmin([1,2,3])==1
assert np.nanmax([1, 2, 3, np.nan])==3
assert np.nanmax([1,2,3])==3


def test_floorish1():
Expand Down
9 changes: 6 additions & 3 deletions tools/RAiDER/llreader.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# noqa: D100
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Author: Jeremy Maurer, Raymond Hogenson & David Bekaert
Expand All @@ -23,7 +24,6 @@

from RAiDER.logger import logger
from RAiDER.types import BB, RIO
from RAiDER.utilFcns import rio_open, rio_stats


class AOI:
Expand Down Expand Up @@ -265,6 +265,7 @@ def __init__(self, lat_file, lon_file=None, hgt_file=None, dem_file=None, conven

def readLL(self) -> tuple[np.ndarray, Optional[np.ndarray]]:
# allow for 2-band lat/lon raster
from RAiDER.utilFcns import rio_open
lats, _ = rio_open(Path(self._latfile))

if self._lonfile is None:
Expand All @@ -275,6 +276,7 @@ def readLL(self) -> tuple[np.ndarray, Optional[np.ndarray]]:

def readZ(self) -> np.ndarray:
"""Read the heights from the raster file, or download a DEM if not present."""
from RAiDER.utilFcns import rio_open
if self._hgtfile is not None and os.path.exists(self._hgtfile):
logger.info('Using existing heights at: %s', self._hgtfile)
hgts, _ = rio_open(self._hgtfile)
Expand Down Expand Up @@ -320,7 +322,7 @@ class GeocodedFile(AOI):
def __init__(self, path: Path, is_dem=False, cube_spacing_in_m: Optional[float]=None) -> None:
super().__init__(cube_spacing_in_m)

from RAiDER.utilFcns import rio_extents, rio_profile
from RAiDER.utilFcns import rio_extents, rio_profile, rio_stats

self._filename = path
self.p = rio_profile(path)
Expand Down Expand Up @@ -361,6 +363,7 @@ class Geocube(AOI):
"""Pull lat/lon/height from a georeferenced data cube."""

def __init__(self, path_cube, cube_spacing_in_m: Optional[float]=None) -> None:
from RAiDER.utilFcns import rio_stats
super().__init__(cube_spacing_in_m)
self.path = path_cube
self._type = 'Geocube'
Expand Down Expand Up @@ -392,7 +395,7 @@ def bounds_from_latlon_rasters(lat_filestr: str, lon_filestr: str) -> tuple[BB.S
Parse lat/lon/height inputs and return
the appropriate outputs.
"""
from RAiDER.utilFcns import get_file_and_band
from RAiDER.utilFcns import get_file_and_band, rio_stats

latinfo = get_file_and_band(lat_filestr)
loninfo = get_file_and_band(lon_filestr)
Expand Down
Loading