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
af98cf81
Commit
af98cf81
authored
2 years ago
by
Martin Bergemann
Browse files
Options
Downloads
Patches
Plain Diff
Use netcdf4 as default engine
parent
a0d439c6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!13
Use netcdf4 as default engine
Pipeline
#27980
passed
2 years ago
Stage: test
Stage: report
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
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
16 additions
and
10 deletions
src/rechunk_data/__init__.py
+
2
−
2
View file @
af98cf81
...
...
@@ -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 @
af98cf81
...
...
@@ -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