fsspec / fsspec/filesystem_spec
decompress $name.$format.bz2
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.4k
- Forks
- 490
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 38
Description
I would like to use https://opendata.dwd.de grib2 data, which is bz2 compressed. To load the data with xarray, I need it to be decompressed, therefore I cache with simplecache and hope to decompress before passing to xarray.
import fsspec
import xarray as xr
# decompress and cache
with fsspec.open('simplecache::bz2://*.grib2::https://opendata.dwd.de/weather/nwp/icon-eu/grib/09/t_2m/icon-eu_europe_regular-lat-lon_single-level_2021060809_017_T_2M.grib2.bz2') as f:
ds = xr.open_dataset(f)
I found some tests in fsspec for tar.bz2. Is grib2.bz2 implemented? If not, would it be worth an addition?
once the file is cached to disk (omitting bz2://*grib2:: above), decompression would work like this:
# https://stackoverflow.com/questions/16963352/decompress-bz2-files
# once cached
localfilepath = 'my_caching_folder/icon-eu_europe_regular-lat-lon_single-level_2021060809_017_T_2M.grib2.bz2'
zipfile = bz2.BZ2File(localfilepath) # open the file
data = zipfile.read() # get the decompressed data
newfilepath = localfilepath[:-4] # assuming the filepath ends with .bz2
open(newfilepath, 'wb').write(data) # write a uncompressed file
xr.open_dataset(newfilepath, engine='cfgrib')
The solution would look like:
# import intake_xarray
intake.open_netcdf('simplecache::bz2://*.grib2::https://opendata.dwd.de/weather/nwp/icon-eu/grib/09/t_2m/icon-eu_europe_regular-lat-lon_single-level_2021060809_017_T_2M.grib2.bz2',
xarray_kwargs=dict(engine='cfgrib')).to_dask()
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing fsspec tests for tar.bz2 and the related filesystem_spec pull request 561. Determine whether the proposed bz2 path can support the cached grib2 example, then verify the expected decompression behavior with xarray and cfgrib and add coverage for the supported case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100