forked from serapred/netcdf-to-zarr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import numpy as np | ||
|
||
|
||
# Convert non-json-encodable types to built-in types | ||
|
||
|
||
def json_encode(val): | ||
|
||
if isinstance(val, np.integer): | ||
return int(val) | ||
elif isinstance(val, np.floating): | ||
return float(val) | ||
elif isinstance(val, np.ndarray): | ||
return val.tolist() | ||
else: | ||
return val |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# parser for netcdf_to_zarr | ||
|
||
import argparse | ||
|
||
|
||
def configure(args): | ||
|
||
class toList(argparse.Action): | ||
def __init__(self, option_strings, dest, nargs=None, **kwargs): | ||
if nargs is not None: | ||
raise ValueError("nargs not allowed") | ||
super(toList, self).__init__(option_strings, dest, **kwargs) | ||
|
||
def __call__(self, parser, namespace, values, option_string=None): | ||
setattr(namespace, self.dest, values.split(' ')) | ||
|
||
desc = ('This script converts netCDF4 into zarr files\n' | ||
'It is possible to specify a list of netCDF4 files\n' | ||
'to merge them into a single zarr file.\n' | ||
'to do so, the variables in the netCD4 file\n' | ||
'must have a common shape and run along the same dimension.\n' | ||
'\nExamples:\n' | ||
' -convert.py src.nc dst.nc [-options]\n' | ||
' -convert.py "src1.nc src2.nc src3.nc" dst.zarr [-options]\n') | ||
|
||
parser = argparse.ArgumentParser(description=desc, | ||
formatter_class=argparse.RawTextHelpFormatter) | ||
|
||
parser.add_argument('src', | ||
help='source netCDF4 file/files', | ||
action=toList, | ||
default=[]) | ||
|
||
parser.add_argument('dst', | ||
help='target zarr file', | ||
default='') | ||
|
||
parser.add_argument('-a', | ||
'--axis', | ||
metavar='axis', | ||
help='axis name to append along', | ||
default=None) | ||
|
||
parser.add_argument('-n', | ||
'--nested', | ||
help='chunks are located into a nested path', | ||
action='store_true', | ||
default=False) | ||
|
||
parser.add_argument('-m', | ||
'--mode', | ||
metavar='mode', | ||
help='use processes or threads', | ||
choices=('threads', 'processes'), | ||
default='serial') | ||
|
||
return parser.parse_args(args) |