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
536bfc3f
Commit
536bfc3f
authored
1 year ago
by
Martin Bergemann
Browse files
Options
Downloads
Patches
Plain Diff
Check make cf conventions configurable
parent
3d787859
No related branches found
Branches containing commit
No related tags found
1 merge request
!14
Check make cf conventions configurable
Pipeline
#46070
failed
1 year ago
Stage: test
Stage: report
Stage: deploy
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+8
-6
8 additions, 6 deletions
README.md
src/rechunk_data/__init__.py
+14
-2
14 additions, 2 deletions
src/rechunk_data/__init__.py
src/rechunk_data/_rechunk.py
+25
-5
25 additions, 5 deletions
src/rechunk_data/_rechunk.py
with
47 additions
and
13 deletions
README.md
+
8
−
6
View file @
536bfc3f
...
...
@@ -29,20 +29,22 @@ new_data = rechunk_dataset(dset)
```
bash
rechunk-data
--help
usage: rechunk-data
[
-h
]
[
--output
OUTPUT]
[
--netcdf-engine
{
h5netcdf,netcdf4
}]
[
-v
]
[
-V
]
input
usage: rechunk-data
[
-h
]
[
--output
OUTPUT]
[
--netcdf-engine
{
h5netcdf,netcdf4
}]
[
--skip-cf-convention
]
[
-v
]
[
-V
]
input
Rechunk input netcdf data to optimal chunk-size. approx. 126 MB per chunk
positional arguments:
input Input file/directory. If a directory is given all
``
.nc
``
files
in
all sub directories will be processed
option
al argument
s:
options:
-h
,
--help
show this
help
message and
exit
--output
OUTPUT 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.
(
default: None
)
--output
OUTPUT 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.
(
default: None
)
--netcdf-engine
{
h5netcdf,netcdf4
}
The netcdf engine used to create the new netcdf file.
(
default: h5netcdf
)
-v
The netcdf engine used to create the new netcdf file.
(
default: netcdf4
)
--skip-cf-convention
Do not assume assume data variables follow CF conventions.
(
default: False
)
-v
Increase verbosity
(
default: 0
)
-V
,
--version
show program
's version number and exit
```
...
...
This diff is collapsed.
Click to expand it.
src/rechunk_data/__init__.py
+
14
−
2
View file @
536bfc3f
...
...
@@ -51,10 +51,17 @@ def parse_args(argv: Optional[List[str]]) -> argparse.Namespace:
default
=
"
netcdf4
"
,
type
=
str
,
)
parser
.
add_argument
(
"
--skip-cf-convention
"
,
help
=
"
Do not assume assume data variables follow CF conventions.
"
,
action
=
"
store_true
"
,
default
=
False
,
)
parser
.
add_argument
(
"
-v
"
,
action
=
"
count
"
,
default
=
0
,
help
=
"
Increase verbosity
"
,
)
parser
.
add_argument
(
"
-V
"
,
...
...
@@ -63,11 +70,16 @@ def parse_args(argv: Optional[List[str]]) -> argparse.Namespace:
version
=
f
"
%(prog)s
{
__version__
}
"
,
)
args
=
parser
.
parse_args
(
argv
)
logger
.
setLevel
(
max
(
logging
.
ERROR
-
(
10
+
args
.
v
*
10
),
0
))
logger
.
setLevel
(
max
(
logging
.
ERROR
-
(
10
+
args
.
v
*
10
),
1
0
))
return
args
def
cli
(
argv
:
Optional
[
List
[
str
]]
=
None
)
->
None
:
"""
Command line interface calling the rechunking method.
"""
args
=
parse_args
(
argv
)
rechunk_netcdf_file
(
args
.
input
,
args
.
output
,
engine
=
args
.
netcdf_engine
)
rechunk_netcdf_file
(
args
.
input
,
args
.
output
,
engine
=
args
.
netcdf_engine
,
decode_cf
=
args
.
skip_cf_convention
is
False
,
)
This diff is collapsed.
Click to expand it.
src/rechunk_data/_rechunk.py
+
25
−
5
View file @
536bfc3f
...
...
@@ -92,13 +92,21 @@ def _rechunk_dataset(
)
from
error
for
data_var
in
dset
.
data_vars
:
var
=
str
(
data_var
)
if
not
isinstance
(
dset
[
var
].
data
,
Array
):
if
(
not
isinstance
(
dset
[
var
].
data
,
Array
)
or
"
bnds
"
in
var
or
"
rotated_pole
"
in
var
):
logger
.
debug
(
"
Skipping rechunking variable %s
"
,
var
)
continue
logger
.
debug
(
"
Rechunking variable %s
"
,
var
)
chunks
:
Dict
[
int
,
Optional
[
str
]]
=
{}
for
i
,
dim
in
enumerate
(
map
(
str
,
dset
[
var
].
dims
)):
if
"
lon
"
in
dim
.
lower
()
or
"
lat
"
in
dim
.
lower
()
or
"
bnds
"
in
dim
.
lower
():
if
(
"
lon
"
in
dim
.
lower
()
or
"
lat
"
in
dim
.
lower
()
or
"
bnds
"
in
dim
.
lower
()
):
chunks
[
i
]
=
None
else
:
chunks
[
i
]
=
"
auto
"
...
...
@@ -116,9 +124,14 @@ def _rechunk_dataset(
)
logger
.
debug
(
"
Settings encoding of variable %s
"
,
var
)
encoding
[
data_var
]
=
{
str
(
k
):
v
for
k
,
v
in
dset
[
var
].
encoding
.
items
()
if
str
(
k
)
in
_keywords
str
(
k
):
v
for
k
,
v
in
dset
[
var
].
encoding
.
items
()
if
str
(
k
)
in
_keywords
}
if
engine
!=
"
netcdf4
"
or
encoding
[
data_var
].
get
(
"
contiguous
"
,
False
)
is
False
:
if
(
engine
!=
"
netcdf4
"
or
encoding
[
data_var
].
get
(
"
contiguous
"
,
False
)
is
False
):
encoding
[
data_var
][
"
chunksizes
"
]
=
new_chunks
return
dset
,
encoding
...
...
@@ -146,6 +159,7 @@ def rechunk_dataset(
def
rechunk_netcdf_file
(
input_path
:
os
.
PathLike
,
output_path
:
Optional
[
os
.
PathLike
]
=
None
,
decode_cf
:
bool
=
True
,
engine
:
Literal
[
"
h5netcdf
"
,
"
netcdf4
"
]
=
"
netcdf4
"
,
)
->
None
:
"""
Rechunk netcdf files.
...
...
@@ -159,6 +173,9 @@ 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.
decode_cf: bool, default: True
Whether to decode these variables, assuming they were saved according
to CF conventions.
engine: str, default: netcdf4
The netcdf engine used to create the new netcdf file.
"""
...
...
@@ -175,7 +192,10 @@ def rechunk_netcdf_file(
output_file
.
parent
.
mkdir
(
exist_ok
=
True
,
parents
=
True
)
try
:
with
xr
.
open_mfdataset
(
str
(
input_file
),
decode_cf
=
True
,
parallel
=
True
str
(
input_file
),
parallel
=
True
,
decode_cf
=
decode_cf
,
inline_array
=
True
,
)
as
nc_data
:
new_data
,
encoding
=
_rechunk_dataset
(
nc_data
,
engine
)
if
encoding
:
...
...
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