Fix exposure coordinate extraction for CalcDeltaImpact - #1304
8 fail, 4 skipped, 1 036 pass in 5m 41s
Annotations
Check warning on line 0 in climada.hazard.centroids.test.test_centr.TestCentroidsMethods
github-actions / Core / Unit Test Results (3.10)
test_dist_coast_pass (climada.hazard.centroids.test.test_centr.TestCentroidsMethods) failed
tests_xml/tests.xml [took 0s]
Raw output
ValueError: Error loading page https://oceancolor.gsfc.nasa.gov/docs/distfromcoast/GMT_intermediate_coast_distance_01d.zip
Status: 444
Content: b'403 Forbidden\n'
self = <climada.hazard.centroids.test.test_centr.TestCentroidsMethods testMethod=test_dist_coast_pass>
def test_dist_coast_pass(self):
"""Test get_dist_coast"""
> dist_coast = self.centr.get_dist_coast()
climada/hazard/centroids/test/test_centr.py:1030:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/hazard/centroids/centr.py:684: in get_dist_coast
return u_coord.dist_to_coast_nasa(
climada/util/coordinates.py:717: in dist_to_coast_nasa
path = _get_dist_to_coast_nasa_tif()
climada/util/coordinates.py:688: in _get_dist_to_coast_nasa_tif
path_dwn = download_file(url, download_dir=SYSTEM_DIR)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
url = 'https://oceancolor.gsfc.nasa.gov/docs/distfromcoast/GMT_intermediate_coast_distance_01d.zip'
download_dir = PosixPath('/home/runner/climada/data'), overwrite = True
def download_file(url, download_dir=None, overwrite=True):
"""Download file from url to given target folder and provide full path of the downloaded file.
Parameters
----------
url : str
url containing data to download
download_dir : Path or str, optional
the parent directory of the eventually downloaded file
default: local_data.save_dir as defined in climada.conf
overwrite : bool, optional
whether or not an already existing file at the target location should be overwritten,
by default True
Returns
-------
str
the full path to the eventually downloaded file
"""
file_name = url.split("/")[-1]
if file_name.strip() == "":
raise ValueError(f"cannot download {url} as a file")
download_path = (
CONFIG.local_data.save_dir.dir() if download_dir is None else Path(download_dir)
)
file_path = download_path.absolute().joinpath(file_name)
if file_path.exists():
if not file_path.is_file() or not overwrite:
raise FileExistsError(f"cannot download to {file_path}")
try:
req_file = requests.get(url, stream=True)
except IOError as ioe:
raise type(ioe)("Check URL and internet connection: " + str(ioe)) from ioe
if req_file.status_code < 200 or req_file.status_code > 299:
> raise ValueError(
f"Error loading page {url}\n"
f" Status: {req_file.status_code}\n"
f" Content: {req_file.content}"
)
E ValueError: Error loading page https://oceancolor.gsfc.nasa.gov/docs/distfromcoast/GMT_intermediate_coast_distance_01d.zip
E Status: 444
E Content: b'403 Forbidden\n'
climada/util/files_handler.py:97: ValueError
Check warning on line 0 in climada.hazard.centroids.test.test_centr.TestCentroidsMethods
github-actions / Core / Unit Test Results (3.10)
test_dist_coast_pass_raster (climada.hazard.centroids.test.test_centr.TestCentroidsMethods) failed
tests_xml/tests.xml [took 0s]
Raw output
ValueError: Error loading page https://oceancolor.gsfc.nasa.gov/docs/distfromcoast/GMT_intermediate_coast_distance_01d.zip
Status: 444
Content: b'403 Forbidden\n'
self = <climada.hazard.centroids.test.test_centr.TestCentroidsMethods testMethod=test_dist_coast_pass_raster>
def test_dist_coast_pass_raster(self):
"""Test get_dist_coast for centroids derived from a raster file"""
centr_ras = Centroids.from_raster_file(HAZ_DEMO_FL, window=Window(0, 0, 50, 60))
> dist_coast = centr_ras.get_dist_coast()
climada/hazard/centroids/test/test_centr.py:1050:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/hazard/centroids/centr.py:684: in get_dist_coast
return u_coord.dist_to_coast_nasa(
climada/util/coordinates.py:717: in dist_to_coast_nasa
path = _get_dist_to_coast_nasa_tif()
climada/util/coordinates.py:688: in _get_dist_to_coast_nasa_tif
path_dwn = download_file(url, download_dir=SYSTEM_DIR)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
url = 'https://oceancolor.gsfc.nasa.gov/docs/distfromcoast/GMT_intermediate_coast_distance_01d.zip'
download_dir = PosixPath('/home/runner/climada/data'), overwrite = True
def download_file(url, download_dir=None, overwrite=True):
"""Download file from url to given target folder and provide full path of the downloaded file.
Parameters
----------
url : str
url containing data to download
download_dir : Path or str, optional
the parent directory of the eventually downloaded file
default: local_data.save_dir as defined in climada.conf
overwrite : bool, optional
whether or not an already existing file at the target location should be overwritten,
by default True
Returns
-------
str
the full path to the eventually downloaded file
"""
file_name = url.split("/")[-1]
if file_name.strip() == "":
raise ValueError(f"cannot download {url} as a file")
download_path = (
CONFIG.local_data.save_dir.dir() if download_dir is None else Path(download_dir)
)
file_path = download_path.absolute().joinpath(file_name)
if file_path.exists():
if not file_path.is_file() or not overwrite:
raise FileExistsError(f"cannot download to {file_path}")
try:
req_file = requests.get(url, stream=True)
except IOError as ioe:
raise type(ioe)("Check URL and internet connection: " + str(ioe)) from ioe
if req_file.status_code < 200 or req_file.status_code > 299:
> raise ValueError(
f"Error loading page {url}\n"
f" Status: {req_file.status_code}\n"
f" Content: {req_file.content}"
)
E ValueError: Error loading page https://oceancolor.gsfc.nasa.gov/docs/distfromcoast/GMT_intermediate_coast_distance_01d.zip
E Status: 444
E Content: b'403 Forbidden\n'
climada/util/files_handler.py:97: ValueError
Check warning on line 0 in climada.hazard.test.test_tc_tracks.TestFuncs
github-actions / Core / Unit Test Results (3.10)
test_dist_since_lf_pass (climada.hazard.test.test_tc_tracks.TestFuncs) failed
tests_xml/tests.xml [took 0s]
Raw output
ValueError: Error loading page https://oceancolor.gsfc.nasa.gov/docs/distfromcoast/GMT_intermediate_coast_distance_01d.zip
Status: 444
Content: b'403 Forbidden\n'
self = <climada.hazard.test.test_tc_tracks.TestFuncs testMethod=test_dist_since_lf_pass>
def test_dist_since_lf_pass(self):
"""Test _dist_since_lf for andrew tropical cyclone."""
tc_track = tc.TCTracks.from_processed_ibtracs_csv(TC_ANDREW_FL)
track = tc_track.get_track()
track["on_land"] = (
"time",
u_coord.coord_on_land(track["lat"].values, track["lon"].values),
)
track["dist_since_lf"] = ("time", tc._dist_since_lf(track))
msk = ~track.on_land
self.assertTrue(np.all(np.isnan(track["dist_since_lf"].values[msk])))
self.assertEqual(track["dist_since_lf"].values[msk].size, 38)
self.assertGreater(
track["dist_since_lf"].values[-1],
> u_coord.dist_to_coast_nasa(track["lat"].values[-1], track["lon"].values[-1])
/ 1000,
)
climada/hazard/test/test_tc_tracks.py:1248:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/util/coordinates.py:717: in dist_to_coast_nasa
path = _get_dist_to_coast_nasa_tif()
climada/util/coordinates.py:688: in _get_dist_to_coast_nasa_tif
path_dwn = download_file(url, download_dir=SYSTEM_DIR)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
url = 'https://oceancolor.gsfc.nasa.gov/docs/distfromcoast/GMT_intermediate_coast_distance_01d.zip'
download_dir = PosixPath('/home/runner/climada/data'), overwrite = True
def download_file(url, download_dir=None, overwrite=True):
"""Download file from url to given target folder and provide full path of the downloaded file.
Parameters
----------
url : str
url containing data to download
download_dir : Path or str, optional
the parent directory of the eventually downloaded file
default: local_data.save_dir as defined in climada.conf
overwrite : bool, optional
whether or not an already existing file at the target location should be overwritten,
by default True
Returns
-------
str
the full path to the eventually downloaded file
"""
file_name = url.split("/")[-1]
if file_name.strip() == "":
raise ValueError(f"cannot download {url} as a file")
download_path = (
CONFIG.local_data.save_dir.dir() if download_dir is None else Path(download_dir)
)
file_path = download_path.absolute().joinpath(file_name)
if file_path.exists():
if not file_path.is_file() or not overwrite:
raise FileExistsError(f"cannot download to {file_path}")
try:
req_file = requests.get(url, stream=True)
except IOError as ioe:
raise type(ioe)("Check URL and internet connection: " + str(ioe)) from ioe
if req_file.status_code < 200 or req_file.status_code > 299:
> raise ValueError(
f"Error loading page {url}\n"
f" Status: {req_file.status_code}\n"
f" Content: {req_file.content}"
)
E ValueError: Error loading page https://oceancolor.gsfc.nasa.gov/docs/distfromcoast/GMT_intermediate_coast_distance_01d.zip
E Status: 444
E Content: b'403 Forbidden\n'
climada/util/files_handler.py:97: ValueError
Check warning on line 0 in climada.hazard.test.test_trop_cyclone.TestReader
github-actions / Core / Unit Test Results (3.10)
test_cross_antimeridian (climada.hazard.test.test_trop_cyclone.TestReader) failed
tests_xml/tests.xml [took 3s]
Raw output
ValueError: Error loading page https://oceancolor.gsfc.nasa.gov/docs/distfromcoast/GMT_intermediate_coast_distance_01d.zip
Status: 444
Content: b'403 Forbidden\n'
self = <climada.hazard.test.test_trop_cyclone.TestReader testMethod=test_cross_antimeridian>
def test_cross_antimeridian(self):
# Two locations on the island Taveuni (Fiji), one west and one east of 180° longitude.
# We list the second point twice, with different lon-normalization:
cen = Centroids.from_lat_lon([-16.95, -16.8, -16.8], [179.9, 180.1, -179.9])
cen.set_dist_coast(precomputed=True)
# Cyclone YASA (2020) passed directly over Fiji
tr = TCTracks.from_ibtracs_netcdf(storm_id=["2020346S13168"])
> inten = TropCyclone.from_tracks(tr, centroids=cen).intensity.toarray()[0, :]
climada/hazard/test/test_trop_cyclone.py:182:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/hazard/trop_cyclone/trop_cyclone.py:294: in from_tracks
dist_coast = centroids.get_dist_coast()
climada/hazard/centroids/centr.py:684: in get_dist_coast
return u_coord.dist_to_coast_nasa(
climada/util/coordinates.py:717: in dist_to_coast_nasa
path = _get_dist_to_coast_nasa_tif()
climada/util/coordinates.py:688: in _get_dist_to_coast_nasa_tif
path_dwn = download_file(url, download_dir=SYSTEM_DIR)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
url = 'https://oceancolor.gsfc.nasa.gov/docs/distfromcoast/GMT_intermediate_coast_distance_01d.zip'
download_dir = PosixPath('/home/runner/climada/data'), overwrite = True
def download_file(url, download_dir=None, overwrite=True):
"""Download file from url to given target folder and provide full path of the downloaded file.
Parameters
----------
url : str
url containing data to download
download_dir : Path or str, optional
the parent directory of the eventually downloaded file
default: local_data.save_dir as defined in climada.conf
overwrite : bool, optional
whether or not an already existing file at the target location should be overwritten,
by default True
Returns
-------
str
the full path to the eventually downloaded file
"""
file_name = url.split("/")[-1]
if file_name.strip() == "":
raise ValueError(f"cannot download {url} as a file")
download_path = (
CONFIG.local_data.save_dir.dir() if download_dir is None else Path(download_dir)
)
file_path = download_path.absolute().joinpath(file_name)
if file_path.exists():
if not file_path.is_file() or not overwrite:
raise FileExistsError(f"cannot download to {file_path}")
try:
req_file = requests.get(url, stream=True)
except IOError as ioe:
raise type(ioe)("Check URL and internet connection: " + str(ioe)) from ioe
if req_file.status_code < 200 or req_file.status_code > 299:
> raise ValueError(
f"Error loading page {url}\n"
f" Status: {req_file.status_code}\n"
f" Content: {req_file.content}"
)
E ValueError: Error loading page https://oceancolor.gsfc.nasa.gov/docs/distfromcoast/GMT_intermediate_coast_distance_01d.zip
E Status: 444
E Content: b'403 Forbidden\n'
climada/util/files_handler.py:97: ValueError
Check warning on line 0 in climada.util.test.test_coordinates.TestGetGeodata
github-actions / Core / Unit Test Results (3.10)
test_dist_to_coast_nasa (climada.util.test.test_coordinates.TestGetGeodata) failed
tests_xml/tests.xml [took 0s]
Raw output
ValueError: Error loading page https://oceancolor.gsfc.nasa.gov/docs/distfromcoast/GMT_intermediate_coast_distance_01d.zip
Status: 444
Content: b'403 Forbidden\n'
self = <climada.util.test.test_coordinates.TestGetGeodata testMethod=test_dist_to_coast_nasa>
def test_dist_to_coast_nasa(self):
"""Test point in coast and point not in coast"""
points = np.array(
[
# Caribbean Sea:
[13.208333333333329, -59.625000000000014],
# South America:
[-12.497529, -58.849505],
# Very close to coast of Somalia:
[1.96475615, 45.23249055],
]
)
dists = [-3000, -1393549.5, 48.77]
dists_lowres = [729.1666667, 1393670.6973145, 945.73129294]
# Warning: This will download more than 300 MB of data if not already present!
> result = u_coord.dist_to_coast_nasa(
points[:, 0], points[:, 1], highres=True, signed=True
)
climada/util/test/test_coordinates.py:1643:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/util/coordinates.py:717: in dist_to_coast_nasa
path = _get_dist_to_coast_nasa_tif()
climada/util/coordinates.py:688: in _get_dist_to_coast_nasa_tif
path_dwn = download_file(url, download_dir=SYSTEM_DIR)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
url = 'https://oceancolor.gsfc.nasa.gov/docs/distfromcoast/GMT_intermediate_coast_distance_01d.zip'
download_dir = PosixPath('/home/runner/climada/data'), overwrite = True
def download_file(url, download_dir=None, overwrite=True):
"""Download file from url to given target folder and provide full path of the downloaded file.
Parameters
----------
url : str
url containing data to download
download_dir : Path or str, optional
the parent directory of the eventually downloaded file
default: local_data.save_dir as defined in climada.conf
overwrite : bool, optional
whether or not an already existing file at the target location should be overwritten,
by default True
Returns
-------
str
the full path to the eventually downloaded file
"""
file_name = url.split("/")[-1]
if file_name.strip() == "":
raise ValueError(f"cannot download {url} as a file")
download_path = (
CONFIG.local_data.save_dir.dir() if download_dir is None else Path(download_dir)
)
file_path = download_path.absolute().joinpath(file_name)
if file_path.exists():
if not file_path.is_file() or not overwrite:
raise FileExistsError(f"cannot download to {file_path}")
try:
req_file = requests.get(url, stream=True)
except IOError as ioe:
raise type(ioe)("Check URL and internet connection: " + str(ioe)) from ioe
if req_file.status_code < 200 or req_file.status_code > 299:
> raise ValueError(
f"Error loading page {url}\n"
f" Status: {req_file.status_code}\n"
f" Content: {req_file.content}"
)
E ValueError: Error loading page https://oceancolor.gsfc.nasa.gov/docs/distfromcoast/GMT_intermediate_coast_distance_01d.zip
E Status: 444
E Content: b'403 Forbidden\n'
climada/util/files_handler.py:97: ValueError
Check warning on line 0 in climada.util.test.test_coordinates.TestRasterIO
github-actions / Core / Unit Test Results (3.10)
test_bounded_refined_raster (climada.util.test.test_coordinates.TestRasterIO) failed
tests_xml/tests.xml [took 0s]
Raw output
ValueError: Error loading page https://oceancolor.gsfc.nasa.gov/docs/distfromcoast/GMT_intermediate_coast_distance_01d.zip
Status: 444
Content: b'403 Forbidden\n'
self = <climada.util.test.test_coordinates.TestRasterIO testMethod=test_bounded_refined_raster>
def test_bounded_refined_raster(self):
"""Test reading a raster within specified bounds and at specified resolution"""
# the bounds have an additional digit (1) at the end to avoid floating-point errors
bounds = (-69.141, 9.991, -69.111, 10.021)
res = 0.004
global_origin = (-180, 90)
z, transform = u_coord.read_raster_bounds(
HAZ_DEMO_FL, bounds, res=res, global_origin=global_origin
)
# the first dimension corresponds to the raster bands:
self.assertEqual(z.shape[0], 1)
z = z[0]
# the signs of stepsizes are retained from the original raster:
self.assertLess(transform[4], 0)
self.assertGreater(transform[0], 0)
# the absolute step sizes are as requested
self.assertEqual(np.abs(transform[0]), res)
self.assertEqual(np.abs(transform[4]), res)
# the raster is aligned to the specified global origin
align_x = (transform[2] - global_origin[0]) / res
align_y = (transform[5] - global_origin[1]) / res
self.assertAlmostEqual(align_x, np.round(align_x))
self.assertAlmostEqual(align_y, np.round(align_y))
# the bounds of returned pixel centers cover the specified region:
# check along x-axis
self.assertLessEqual(transform[2] + 0.5 * transform[0], bounds[0])
self.assertGreater(transform[2] + 1.5 * transform[0], bounds[0])
self.assertGreaterEqual(
transform[2] + (z.shape[1] - 0.5) * transform[0], bounds[2]
)
self.assertLess(transform[2] + (z.shape[1] - 1.5) * transform[0], bounds[2])
# check along y-axis (note that the orientation is reversed)
self.assertGreaterEqual(transform[5] + 0.5 * transform[4], bounds[3])
self.assertLess(transform[5] + 1.5 * transform[4], bounds[3])
self.assertLessEqual(
transform[5] + (z.shape[0] - 0.5) * transform[4], bounds[1]
)
self.assertGreater(transform[5] + (z.shape[0] - 1.5) * transform[4], bounds[1])
# trigger downloading of dist-to-coast dataset (if not already present)
> path = u_coord._get_dist_to_coast_nasa_tif()
climada/util/test/test_coordinates.py:2299:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/util/coordinates.py:688: in _get_dist_to_coast_nasa_tif
path_dwn = download_file(url, download_dir=SYSTEM_DIR)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
url = 'https://oceancolor.gsfc.nasa.gov/docs/distfromcoast/GMT_intermediate_coast_distance_01d.zip'
download_dir = PosixPath('/home/runner/climada/data'), overwrite = True
def download_file(url, download_dir=None, overwrite=True):
"""Download file from url to given target folder and provide full path of the downloaded file.
Parameters
----------
url : str
url containing data to download
download_dir : Path or str, optional
the parent directory of the eventually downloaded file
default: local_data.save_dir as defined in climada.conf
overwrite : bool, optional
whether or not an already existing file at the target location should be overwritten,
by default True
Returns
-------
str
the full path to the eventually downloaded file
"""
file_name = url.split("/")[-1]
if file_name.strip() == "":
raise ValueError(f"cannot download {url} as a file")
download_path = (
CONFIG.local_data.save_dir.dir() if download_dir is None else Path(download_dir)
)
file_path = download_path.absolute().joinpath(file_name)
if file_path.exists():
if not file_path.is_file() or not overwrite:
raise FileExistsError(f"cannot download to {file_path}")
try:
req_file = requests.get(url, stream=True)
except IOError as ioe:
raise type(ioe)("Check URL and internet connection: " + str(ioe)) from ioe
if req_file.status_code < 200 or req_file.status_code > 299:
> raise ValueError(
f"Error loading page {url}\n"
f" Status: {req_file.status_code}\n"
f" Content: {req_file.content}"
)
E ValueError: Error loading page https://oceancolor.gsfc.nasa.gov/docs/distfromcoast/GMT_intermediate_coast_distance_01d.zip
E Status: 444
E Content: b'403 Forbidden\n'
climada/util/files_handler.py:97: ValueError
Check warning on line 0 in climada.util.test.test_coordinates.TestRasterIO
github-actions / Core / Unit Test Results (3.10)
test_sample_raster (climada.util.test.test_coordinates.TestRasterIO) failed
tests_xml/tests.xml [took 0s]
Raw output
ValueError: Error loading page https://oceancolor.gsfc.nasa.gov/docs/distfromcoast/GMT_intermediate_coast_distance_01d.zip
Status: 444
Content: b'403 Forbidden\n'
self = <climada.util.test.test_coordinates.TestRasterIO testMethod=test_sample_raster>
def test_sample_raster(self):
"""Test sampling points from raster file"""
val_1, val_2, fill_value = 0.056825936, 0.10389626, -999
i_j_vals = np.array(
[
[44, 21, 0],
[44, 22, 0],
[44, 23, 0],
[45, 21, 0],
[45, 22, val_1],
[45, 23, val_2],
[46, 21, 0],
[46, 22, 0],
[46, 23, 0],
[45, 22.2, 0.8 * val_1 + 0.2 * val_2],
[45.3, 21.4, 0.7 * 0.4 * val_1],
[-20, 0, fill_value],
]
)
res = 0.009000000000000341
lat = 10.42822096697894 - res / 2 - i_j_vals[:, 0] * res
lon = -69.33714959699981 + res / 2 + i_j_vals[:, 1] * res
values = u_coord.read_raster_sample(
HAZ_DEMO_FL, lat, lon, fill_value=fill_value
)
self.assertEqual(values.size, lat.size)
for i, val in enumerate(i_j_vals[:, 2]):
self.assertAlmostEqual(values[i], val)
# with explicit intermediate resolution
values = u_coord.read_raster_sample(
HAZ_DEMO_FL, lat, lon, fill_value=fill_value, intermediate_res=res
)
self.assertEqual(values.size, lat.size)
for i, val in enumerate(i_j_vals[:, 2]):
self.assertAlmostEqual(values[i], val)
# for the antimeridian tests, use the dist-to-coast dataset
> path = u_coord._get_dist_to_coast_nasa_tif()
climada/util/test/test_coordinates.py:2185:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/util/coordinates.py:688: in _get_dist_to_coast_nasa_tif
path_dwn = download_file(url, download_dir=SYSTEM_DIR)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
url = 'https://oceancolor.gsfc.nasa.gov/docs/distfromcoast/GMT_intermediate_coast_distance_01d.zip'
download_dir = PosixPath('/home/runner/climada/data'), overwrite = True
def download_file(url, download_dir=None, overwrite=True):
"""Download file from url to given target folder and provide full path of the downloaded file.
Parameters
----------
url : str
url containing data to download
download_dir : Path or str, optional
the parent directory of the eventually downloaded file
default: local_data.save_dir as defined in climada.conf
overwrite : bool, optional
whether or not an already existing file at the target location should be overwritten,
by default True
Returns
-------
str
the full path to the eventually downloaded file
"""
file_name = url.split("/")[-1]
if file_name.strip() == "":
raise ValueError(f"cannot download {url} as a file")
download_path = (
CONFIG.local_data.save_dir.dir() if download_dir is None else Path(download_dir)
)
file_path = download_path.absolute().joinpath(file_name)
if file_path.exists():
if not file_path.is_file() or not overwrite:
raise FileExistsError(f"cannot download to {file_path}")
try:
req_file = requests.get(url, stream=True)
except IOError as ioe:
raise type(ioe)("Check URL and internet connection: " + str(ioe)) from ioe
if req_file.status_code < 200 or req_file.status_code > 299:
> raise ValueError(
f"Error loading page {url}\n"
f" Status: {req_file.status_code}\n"
f" Content: {req_file.content}"
)
E ValueError: Error loading page https://oceancolor.gsfc.nasa.gov/docs/distfromcoast/GMT_intermediate_coast_distance_01d.zip
E Status: 444
E Content: b'403 Forbidden\n'
climada/util/files_handler.py:97: ValueError
Check warning on line 0 in climada.util.test.test_coordinates.TestRasterIO
github-actions / Core / Unit Test Results (3.10)
test_sample_raster_gradient (climada.util.test.test_coordinates.TestRasterIO) failed
tests_xml/tests.xml [took 0s]
Raw output
ValueError: Error loading page https://oceancolor.gsfc.nasa.gov/docs/distfromcoast/GMT_intermediate_coast_distance_01d.zip
Status: 444
Content: b'403 Forbidden\n'
self = <climada.util.test.test_coordinates.TestRasterIO testMethod=test_sample_raster_gradient>
def test_sample_raster_gradient(self):
"""Test sampling gradients from a raster file"""
> path = u_coord._get_dist_to_coast_nasa_tif()
climada/util/test/test_coordinates.py:2210:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
climada/util/coordinates.py:688: in _get_dist_to_coast_nasa_tif
path_dwn = download_file(url, download_dir=SYSTEM_DIR)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
url = 'https://oceancolor.gsfc.nasa.gov/docs/distfromcoast/GMT_intermediate_coast_distance_01d.zip'
download_dir = PosixPath('/home/runner/climada/data'), overwrite = True
def download_file(url, download_dir=None, overwrite=True):
"""Download file from url to given target folder and provide full path of the downloaded file.
Parameters
----------
url : str
url containing data to download
download_dir : Path or str, optional
the parent directory of the eventually downloaded file
default: local_data.save_dir as defined in climada.conf
overwrite : bool, optional
whether or not an already existing file at the target location should be overwritten,
by default True
Returns
-------
str
the full path to the eventually downloaded file
"""
file_name = url.split("/")[-1]
if file_name.strip() == "":
raise ValueError(f"cannot download {url} as a file")
download_path = (
CONFIG.local_data.save_dir.dir() if download_dir is None else Path(download_dir)
)
file_path = download_path.absolute().joinpath(file_name)
if file_path.exists():
if not file_path.is_file() or not overwrite:
raise FileExistsError(f"cannot download to {file_path}")
try:
req_file = requests.get(url, stream=True)
except IOError as ioe:
raise type(ioe)("Check URL and internet connection: " + str(ioe)) from ioe
if req_file.status_code < 200 or req_file.status_code > 299:
> raise ValueError(
f"Error loading page {url}\n"
f" Status: {req_file.status_code}\n"
f" Content: {req_file.content}"
)
E ValueError: Error loading page https://oceancolor.gsfc.nasa.gov/docs/distfromcoast/GMT_intermediate_coast_distance_01d.zip
E Status: 444
E Content: b'403 Forbidden\n'
climada/util/files_handler.py:97: ValueError