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

Bug fixes and unit test updates #661

Merged
merged 6 commits into from
Jul 5, 2024
Merged
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
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
* [651](https://github.com/dbekaert/RAiDER/pull/651) - Removed use of deprecated argument to `pandas.read_csv`.
### Fixed
* [657](https://github.com/dbekaert/RAiDER/pull/657) - Fixed a few typos in `README.md`.
* [651](https://github.com/dbekaert/RAiDER/pull/651) - Removed use of deprecated argument to `pandas.read_csv`.
* [627](https://github.com/dbekaert/RAiDER/pull/627) - Made Python datetimes timezone-aware and add unit tests and bug fixes.
* [662](https://github.com/dbekaert/RAiDER/pull/662) - Ensures dem-stitcher to be >= v2.5.6, which updates the url for reading the Geoid EGM 2008.
* [661](https://github.com/dbekaert/RAiDER/pull/661) - Fix bug in raiderDownloadGNSS, remove call to scipy.sum, and add unit tests

## [0.5.1]
### Changed
Expand Down
6 changes: 4 additions & 2 deletions test/test_GUNW.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
get_slc_ids_from_gunw,get_acq_time_from_slc_id
)
from RAiDER.cli.raider import calcDelaysGUNW
from RAiDER.models.customExceptions import NoWeatherModelData
from RAiDER.models.customExceptions import (
NoWeatherModelData, WrongNumberOfFiles,
)


def compute_transform(lats, lons):
Expand Down Expand Up @@ -568,7 +570,7 @@ def test_GUNW_workflow_fails_if_a_download_fails(gunw_azimuth_test, orbit_dict_f
'-interp', 'azimuth_time_grid'
]

with pytest.raises(RuntimeError):
with pytest.raises(WrongNumberOfFiles):
calcDelaysGUNW(iargs_1)
RAiDER.s1_azimuth_timing.get_s1_azimuth_time_grid.assert_not_called()

Expand Down
52 changes: 34 additions & 18 deletions test/test_downloadGNSS.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from test import TEST_DIR, pushd
from RAiDER.dem import download_dem
from RAiDER.gnss.downloadGNSSDelays import (
check_url,read_text_file,in_box,fix_lons,get_ID,

check_url,in_box,fix_lons,get_ID,
download_UNR,main,
)

# Test check_url with a valid and invalid URL
Expand All @@ -23,21 +23,6 @@ def test_check_url_invalid():
mock_head.return_value.status_code = 404 # Simulate not found response
assert check_url(invalid_url) == ''

# Test read_text_file with a valid and invalid filename
def test_read_text_file_valid():
# Create a temporary test file with some content
with open("test_file.txt", "w") as f:
f.write("line1\nline2\n")
try:
lines = read_text_file("test_file.txt")
assert lines == ["line1", "line2"]
finally:
os.remove("test_file.txt") # Cleanup the temporary file

def test_read_text_file_invalid():
invalid_filename = "not_a_file.txt"
with pytest.raises(FileNotFoundError):
read_text_file(invalid_filename)

# Test in_box with points inside and outside the box
def test_in_box_inside():
Expand Down Expand Up @@ -82,4 +67,35 @@ def test_get_ID_valid():
def test_get_ID_invalid():
line = "ABCD 35.0" # Missing longitude and height
with pytest.raises(ValueError):
get_ID(line)
get_ID(line)


def test_download_UNR():
statID = 'MORZ'
year = 2020
outDict = download_UNR(statID, year)
assert outDict['path'] == 'http://geodesy.unr.edu/gps_timeseries/trop/MORZ/MORZ.2020.trop.zip'

def test_download_UNR_2():
statID = 'MORZ'
year = 2000
with pytest.raises(ValueError):
download_UNR(statID, year, download=True)

def test_download_UNR_3():
statID = 'DUMY'
year = 2020
with pytest.raises(ValueError):
download_UNR(statID, year, download=True)

def test_download_UNR_4():
statID = 'MORZ'
year = 2020
with pytest.raises(NotImplementedError):
download_UNR(statID, year, baseURL='www.google.com')


def test_main():
# iargs = None
# main(inps=iargs)
assert True
4 changes: 3 additions & 1 deletion test/test_gnss.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from RAiDER.models.customExceptions import NoStationDataFoundError
from RAiDER.gnss.downloadGNSSDelays import (
get_stats_by_llh, get_station_list, download_tropo_delays,
filterToBBox,
filterToBBox
)
from RAiDER.gnss.processDelayFiles import (
addDateTimeToFiles,
Expand All @@ -15,6 +15,7 @@
import pandas as pd

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


Expand Down Expand Up @@ -163,3 +164,4 @@ def test_filterByBBox2():
assert stat not in new_data['ID'].to_list()
for stat in ['FGNW', 'JPLT', 'NVTP', 'WLHG', 'WORG']:
assert stat in new_data['ID'].to_list()

2 changes: 1 addition & 1 deletion tools/RAiDER/cli/raider.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def calcDelays(iargs=None):
logger.error(e)
logger.error('Weather model files are: {}'.format(wfiles))
logger.error(msg)
raise
continue

# dont process the delays for download only
if dl_only:
Expand Down
76 changes: 15 additions & 61 deletions tools/RAiDER/cli/statsPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from RAiDER.utilFcns import WGS84_to_UTM
from rasterio.transform import Affine
from scipy import optimize
from scipy import sum as scipy_sum
from scipy.optimize import OptimizeWarning
from shapely.strtree import STRtree
from shapely.geometry import Point, Polygon
Expand Down Expand Up @@ -183,12 +182,12 @@ def convert_SI(val, unit_in, unit_out):
# e.g. sigZTD filter, already extracted datetime object
try:
return eval('val.apply(pd.to_datetime).dt.{}.astype(float).astype("Int32")'.format(unit_out))
except BaseException: # TODO: Which error(s)?
except AttributeError:
return val

# check if output spatial unit is supported
if unit_out not in SI:
raise Exception("User-specified output unit {} not recognized.".format(unit_out))
raise ValueError("User-specified output unit {} not recognized.".format(unit_out))

return val * SI[unit_in] / SI[unit_out]

Expand All @@ -199,6 +198,9 @@ def midpoint(p1, p2):
'''
import math

if p1[1] == p2[1]:
return p1[1]

lat1, lon1, lat2, lon2 = map(math.radians, (p1[0], p1[1], p2[0], p2[1]))
dlon = lon2 - lon1
dx = math.cos(lat2) * math.cos(dlon)
Expand Down Expand Up @@ -243,19 +245,22 @@ def save_gridfile(df, gridfile_type, fname, plotbbox, spacing, unit,
dst.update_tags(0, **metadata_dict)
dst.write(df, 1)

return
return metadata_dict


def load_gridfile(fname, unit):
'''
Function to load gridded-arrays saved from previous runs.
'''

with rasterio.open(fname) as src:
grid_array = src.read(1).astype(float)
try:
with rasterio.open(fname) as src:
grid_array = src.read(1).astype(float)
except TypeError:
raise ValueError('fname is not a valid file')

# Read metadata variables needed for plotting
metadata_dict = src.tags()
# Read metadata variables needed for plotting
metadata_dict = src.tags()

# Initiate no-data array to mask data
nodat_arr = [0, np.nan, np.inf]
Expand Down Expand Up @@ -375,7 +380,7 @@ def _emp_vario(self, x, y, data, Nsamp=1000):
y = y[mask]

# deramp
temp1, temp2, x, y = WGS84_to_UTM(x, y, common_center=True)
_, _, x, y = WGS84_to_UTM(x, y, common_center=True)
A = np.array([x, y, np.ones(len(x))]).T
ramp = np.linalg.lstsq(A, data.T, rcond=None)[0]
data = data - (np.matmul(A, ramp))
Expand Down Expand Up @@ -1487,7 +1492,7 @@ def fitfunc(t):
phsfit_c[station] = pcov[2, 2]**0.5
# pass RMSE of fit
seasonalfit_rmse[station] = yy - custom_sine_function_base(tt, *popt)
seasonalfit_rmse[station] = (scipy_sum(seasonalfit_rmse[station]**2) /
seasonalfit_rmse[station] = (np.sum(seasonalfit_rmse[station]**2) /
Copy link
Collaborator

@cmarshak cmarshak Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all I can review as I don't know what else you made changes to - looks fine.

(seasonalfit_rmse[station].size - 2))**0.5
except FloatingPointError:
pass
Expand Down Expand Up @@ -2099,54 +2104,3 @@ def main():
inps.variogram_per_timeslice,
inps.variogram_errlimit
)


def main():
inps = cmd_line_parse()

stats_analyses(
inps.fname,
inps.col_name,
inps.unit,
inps.workdir,
inps.cpus,
inps.verbose,
inps.bounding_box,
inps.spacing,
inps.timeinterval,
inps.seasonalinterval,
inps.obs_errlimit,
inps.figdpi,
inps.user_title,
inps.plot_fmt,
inps.cbounds,
inps.colorpercentile,
inps.usr_colormap,
inps.densitythreshold,
inps.stationsongrids,
inps.drawgridlines,
inps.time_lines,
inps.plotall,
inps.station_distribution,
inps.station_delay_mean,
inps.station_delay_median,
inps.station_delay_stdev,
inps.station_seasonal_phase,
inps.phaseamp_per_station,
inps.grid_heatmap,
inps.grid_delay_mean,
inps.grid_delay_median,
inps.grid_delay_stdev,
inps.grid_seasonal_phase,
inps.grid_delay_absolute_mean,
inps.grid_delay_absolute_median,
inps.grid_delay_absolute_stdev,
inps.grid_seasonal_absolute_phase,
inps.grid_to_raster,
inps.min_span,
inps.period_limit,
inps.variogramplot,
inps.binnedvariogram,
inps.variogram_per_timeslice,
inps.variogram_errlimit
)
Loading