Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rechunk-data
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ch1187
rechunk-data
Commits
3d787859
Commit
3d787859
authored
2 years ago
by
Martin Bergemann
Browse files
Options
Downloads
Plain Diff
Merge branch 'use-netcdf4' into 'main'
Use netcdf4 as default engine See merge request
!13
parents
a0d439c6
2398e787
No related branches found
No related tags found
1 merge request
!13
Use netcdf4 as default engine
Pipeline
#27985
passed
2 years ago
Stage: test
Stage: report
Stage: deploy
Changes
3
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitlab-ci.yml
+9
-1
9 additions, 1 deletion
.gitlab-ci.yml
src/rechunk_data/__init__.py
+2
-2
2 additions, 2 deletions
src/rechunk_data/__init__.py
src/rechunk_data/_rechunk.py
+14
-8
14 additions, 8 deletions
src/rechunk_data/_rechunk.py
with
25 additions
and
11 deletions
.gitlab-ci.yml
+
9
−
1
View file @
3d787859
...
...
@@ -48,13 +48,21 @@ test_39:
script
:
-
/tmp/test/bin/python -m pytest -vv
test_310
:
<<
:
*py_test
before_script
:
-
conda create -q -p /tmp/test python=3.10 pip dask -y
-
/tmp/test/bin/python -m pip install -e .[test]
script
:
-
/tmp/test/bin/python -m pytest -vv
pages
:
stage
:
report
needs
:
[]
tags
:
-
conda
before_script
:
-
conda create -c conda-forge -q -p /tmp/test python=3.1
0
pip dask -y
-
conda create -c conda-forge -q -p /tmp/test python=3.1
1
pip dask
hdf5
-y
-
/tmp/test/bin/python -m pip install -e .[test]
script
:
-
/tmp/test/bin/coverage run -m pytest
...
...
This diff is collapsed.
Click to expand it.
src/rechunk_data/__init__.py
+
2
−
2
View file @
3d787859
...
...
@@ -10,7 +10,7 @@ from ._rechunk import (
logger
,
)
__version__
=
"
2
208
.0.
1
"
__version__
=
"
2
301
.0.
0
"
PROGRAM_NAME
=
"
rechunk-data
"
...
...
@@ -48,7 +48,7 @@ def parse_args(argv: Optional[List[str]]) -> argparse.Namespace:
"
--netcdf-engine
"
,
help
=
(
"
The netcdf engine used to create the new netcdf file.
"
),
choices
=
(
"
h5netcdf
"
,
"
netcdf4
"
),
default
=
"
h5
netcdf
"
,
default
=
"
netcdf
4
"
,
type
=
str
,
)
parser
.
add_argument
(
...
...
This diff is collapsed.
Click to expand it.
src/rechunk_data/_rechunk.py
+
14
−
8
View file @
3d787859
...
...
@@ -118,12 +118,13 @@ def _rechunk_dataset(
encoding
[
data_var
]
=
{
str
(
k
):
v
for
k
,
v
in
dset
[
var
].
encoding
.
items
()
if
str
(
k
)
in
_keywords
}
encoding
[
data_var
][
"
chunksizes
"
]
=
new_chunks
if
engine
!=
"
netcdf4
"
or
encoding
[
data_var
].
get
(
"
contiguous
"
,
False
)
is
False
:
encoding
[
data_var
][
"
chunksizes
"
]
=
new_chunks
return
dset
,
encoding
def
rechunk_dataset
(
dset
:
xr
.
Dataset
,
engine
:
Literal
[
"
h5netcdf
"
,
"
netcdf4
"
]
=
"
h5
netcdf
"
dset
:
xr
.
Dataset
,
engine
:
Literal
[
"
h5netcdf
"
,
"
netcdf4
"
]
=
"
netcdf
4
"
)
->
xr
.
Dataset
:
"""
Rechunk a xarray dataset.
...
...
@@ -131,7 +132,7 @@ def rechunk_dataset(
----------
dset: xarray.Dataset
Input dataset that is going to be rechunked
engine: str, default:
h5
netcdf
engine: str, default: netcdf
4
The netcdf engine used to create the new netcdf file.
Returns
...
...
@@ -145,7 +146,7 @@ def rechunk_dataset(
def
rechunk_netcdf_file
(
input_path
:
os
.
PathLike
,
output_path
:
Optional
[
os
.
PathLike
]
=
None
,
engine
:
Literal
[
"
h5netcdf
"
,
"
netcdf4
"
]
=
"
h5
netcdf
"
,
engine
:
Literal
[
"
h5netcdf
"
,
"
netcdf4
"
]
=
"
netcdf
4
"
,
)
->
None
:
"""
Rechunk netcdf files.
...
...
@@ -158,7 +159,7 @@ def rechunk_netcdf_file(
Output file/directory of the chunked netcdf file(s). Note: If ``input``
is a directory output should be a directory. If None given (default)
the ``input`` is overidden.
engine: str, default:
h5
netcdf
engine: str, default: netcdf
4
The netcdf engine used to create the new netcdf file.
"""
input_path
=
Path
(
input_path
).
expanduser
().
absolute
()
...
...
@@ -173,16 +174,21 @@ def rechunk_netcdf_file(
output_file
=
Path
(
output_path
)
output_file
.
parent
.
mkdir
(
exist_ok
=
True
,
parents
=
True
)
try
:
with
xr
.
open_mfdataset
(
str
(
input_file
),
parallel
=
True
)
as
nc_data
:
with
xr
.
open_mfdataset
(
str
(
input_file
),
decode_cf
=
True
,
parallel
=
True
)
as
nc_data
:
new_data
,
encoding
=
_rechunk_dataset
(
nc_data
,
engine
)
if
encoding
:
logger
.
debug
(
"
Loading data into memory (%s).
"
,
format_bytes
(
new_data
.
nbytes
)
"
Loading data into memory (%s).
"
,
format_bytes
(
new_data
.
nbytes
),
)
new_data
=
new_data
.
load
()
except
Exception
as
error
:
logger
.
error
(
"
Error while processing file %s: %s
"
,
str
(
input_file
),
str
(
error
)
"
Error while processing file %s: %s
"
,
str
(
input_file
),
str
(
error
),
)
continue
_save_dataset
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment