Skip to content

Commit

Permalink
Merge pull request #269 from davidhassell/read-https
Browse files Browse the repository at this point in the history
Fix bug that prevents "https://" netCDF files from being read
  • Loading branch information
davidhassell authored Aug 30, 2023
2 parents 142accf + 8860191 commit e13ec51
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
10 changes: 10 additions & 0 deletions Changelog.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
Version 1.10.1.2
----------------

**2023-08-31**

* Fix bug that prevented "https://" netCDF files from being read
(https://github.com/NCAS-CMS/cfdm/issues/268)

----

Version 1.10.1.1
----------------

Expand Down
8 changes: 5 additions & 3 deletions cfdm/read_write/netcdf/netcdfread.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,10 @@ def cdl_to_netcdf(cls, filename):
def is_netcdf_file(cls, filename):
"""Return `True` if the file is a netCDF file.
Note that the file type is determined by inspecting the file's
contents and any file suffix is not not considered.
The file type is determined by inspecting the file's contents
and any file suffix is not not considered. However, file names
starting ``https://`` or ``http://`` are assumed, without
checking, to be netCDF files.
:Parameters:
Expand All @@ -501,7 +503,7 @@ def is_netcdf_file(cls, filename):
"""
# Assume that URLs are in netCDF format
if filename.startswith("http://"):
if filename.startswith("https://") or filename.startswith("http://"):
return True

# Read the magic number
Expand Down
11 changes: 5 additions & 6 deletions cfdm/test/test_read_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,12 +985,11 @@ def test_read_write_domain_ancillary(self):

def test_read_url(self):
"""Test reading urls."""
remote = "http://psl.noaa.gov/thredds/dodsC/Datasets/cru/crutem5/Monthlies/air.mon.anom.nobs.nc"
# Check that the file remote is indeed accesible
_ = netCDF4.Dataset(remote, "r")
# Check that cfdm can access it
f = cfdm.read(remote)
self.assertEqual(len(f), 1)
for scheme in ("http", "https"):
remote = f"{scheme}://psl.noaa.gov/thredds/dodsC/Datasets/cru/crutem5/Monthlies/air.mon.anom.nobs.nc"
# Check that cfdm can access it
f = cfdm.read(remote)
self.assertEqual(len(f), 1)


if __name__ == "__main__":
Expand Down

0 comments on commit e13ec51

Please sign in to comment.