Skip to content

Commit 8cdb7d3

Browse files
committed
dev
1 parent fc5407d commit 8cdb7d3

File tree

2 files changed

+65
-9
lines changed

2 files changed

+65
-9
lines changed

cf/cfimplementation.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,33 @@ class CFImplementation(cfdm.CFDMImplementation):
4848
4949
"""
5050

51+
def nc_set_hdf5_chunksizes(self, data, sizes, override=False):
52+
"""Set the data HDF5 chunksizes.
53+
54+
.. versionadded:: NEXTVERSION
55+
56+
:Parameters:
57+
58+
data: `Data`
59+
The data.
60+
61+
sizes: sequence of `int`
62+
The new HDF5 chunk sizes.
63+
64+
override: `bool`, optional
65+
If True then set the HDF5 chunks sizes even if some
66+
have already been specified. If False, the default,
67+
then only set the HDF5 chunks sizes if some none have
68+
already been specified.
69+
70+
:Returns:
71+
72+
`None`
73+
74+
"""
75+
if override or not data.nc_hdf5_chunksizes():
76+
data.nc_set_hdf5_chunksizes(sizes)
77+
5178
def set_construct(self, parent, construct, axes=None, copy=True, **kwargs):
5279
"""Insert a construct into a field or domain.
5380

cf/read_write/netcdf/netcdfwrite.py

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -431,10 +431,12 @@ def _create_cfa_data(self, ncvar, ncdimensions, data, cfvar):
431431
`None`
432432
433433
"""
434+
import time # TODO
435+
print (f"\n{ncvar}") # TODO
436+
434437
g = self.write_vars
435438

436439
ndim = data.ndim
437-
438440
cfa = self._cfa_aggregation_instructions(data, cfvar)
439441

440442
# ------------------------------------------------------------
@@ -482,16 +484,21 @@ def _create_cfa_data(self, ncvar, ncdimensions, data, cfvar):
482484
aggregated_data_attr = []
483485

484486
# Location
487+
start = time.time() # TODO
485488
term = "location"
489+
data = cfa[term]
490+
self.implementation.nc_set_hdf5_chunksizes(data, data.shape)
486491
term_ncvar = self._cfa_write_term_variable(
487-
cfa[term],
492+
data ,#cfa[term],
488493
aggregated_data.get(term, f"cfa_{term}"),
489494
location_ncdimensions,
490495
)
491496
aggregated_data_attr.append(f"{term}: {term_ncvar}")
492-
497+
print (f"{term:<10}: {time.time() - start:.3}")
498+
493499
# File
494500
term = "file"
501+
start = time.time() # TODO
495502
if substitutions:
496503
# Create the "substitutions" netCDF attribute
497504
subs = []
@@ -502,16 +509,20 @@ def _create_cfa_data(self, ncvar, ncdimensions, data, cfvar):
502509
else:
503510
attributes = None
504511

512+
data = cfa[term]
513+
self.implementation.nc_set_hdf5_chunksizes(data, data.shape)
505514
term_ncvar = self._cfa_write_term_variable(
506-
cfa[term],
515+
data, #cfa[term],
507516
aggregated_data.get(term, f"cfa_{term}"),
508517
fragment_ncdimensions,
509518
attributes=attributes,
510519
)
511520
aggregated_data_attr.append(f"{term}: {term_ncvar}")
521+
print (f"{term:<10}: {time.time() - start:.3}")
512522

513523
# Address
514524
term = "address"
525+
start = time.time() # TODO
515526

516527
# Attempt to reduce addresses to a common scalar value
517528
u = cfa[term].unique().compressed().persist()
@@ -521,15 +532,19 @@ def _create_cfa_data(self, ncvar, ncdimensions, data, cfvar):
521532
else:
522533
dimensions = fragment_ncdimensions
523534

535+
data = cfa[term]
536+
self.implementation.nc_set_hdf5_chunksizes(data, data.shape)
524537
term_ncvar = self._cfa_write_term_variable(
525-
cfa[term],
538+
data, # cfa[term],
526539
aggregated_data.get(term, f"cfa_{term}"),
527540
dimensions,
528541
)
529542
aggregated_data_attr.append(f"{term}: {term_ncvar}")
543+
print (f"{term:<10}: {time.time() - start:.3}")
530544

531545
# Format
532546
term = "format"
547+
start = time.time() # TODO
533548

534549
# Attempt to reduce addresses to a common scalar value
535550
u = cfa[term].unique().compressed().persist()
@@ -539,13 +554,16 @@ def _create_cfa_data(self, ncvar, ncdimensions, data, cfvar):
539554
else:
540555
dimensions = fragment_ncdimensions
541556

557+
data = cfa[term]
558+
self.implementation.nc_set_hdf5_chunksizes(data, data.shape)
542559
term_ncvar = self._cfa_write_term_variable(
543-
cfa[term],
560+
data, #cfa[term],
544561
aggregated_data.get(term, f"cfa_{term}"),
545562
dimensions,
546563
)
547564
aggregated_data_attr.append(f"{term}: {term_ncvar}")
548565

566+
print (f"{term:<10}: {time.time() - start:.3}")
549567
# ------------------------------------------------------------
550568
# Look for non-standard CFA terms stored as field ancillaries
551569
# on a field and write them to the CFA-netCDF file
@@ -809,8 +827,10 @@ def _cfa_write_non_standard_terms(
809827
terms.append(term)
810828

811829
# Create the new CFA term variable
830+
data = type(data)(dx)
831+
self.implementation.nc_set_hdf5_chunksizes(data, data.shape)
812832
term_ncvar = self._cfa_write_term_variable(
813-
data=type(data)(dx),
833+
data=data, #type(data)(dx),
814834
ncvar=aggregated_data.get(term, f"cfa_{term}"),
815835
ncdimensions=fragment_ncdimensions,
816836
)
@@ -884,7 +904,9 @@ def _cfa_aggregation_instructions(self, data, cfvar):
884904
from os.path import abspath, join, relpath
885905
from pathlib import PurePath
886906
from urllib.parse import urlparse
887-
907+
import time # TODO
908+
start = time.time() # TODO
909+
888910
g = self.write_vars
889911

890912
# Define the CFA file susbstitutions, giving precedence over
@@ -899,11 +921,15 @@ def _cfa_aggregation_instructions(self, data, cfvar):
899921
# Size of the trailing dimension
900922
n_trailing = 0
901923

924+
start1 = time.time() # TODO
902925
aggregation_file = []
903926
aggregation_address = []
904927
aggregation_format = []
928+
nnn = 0
905929
for indices in data.chunk_indices():
930+
nnn += 1
906931
file_details = self._cfa_get_file_details(data[indices])
932+
907933
if len(file_details) != 1:
908934
if file_details:
909935
raise ValueError(
@@ -948,7 +974,9 @@ def _cfa_aggregation_instructions(self, data, cfvar):
948974
aggregation_file.append(tuple(filenames2))
949975
aggregation_address.append(addresses)
950976
aggregation_format.append(formats)
951-
977+
print ('len(data.chunk_indices()) =',nnn)
978+
print (f"loop 1: {time.time() - start1:.3}")
979+
952980
# Pad each value of the aggregation instruction arrays so that
953981
# it has 'n_trailing' elements
954982
a_shape = data.numblocks
@@ -1005,6 +1033,7 @@ def _cfa_aggregation_instructions(self, data, cfvar):
10051033
# Return Data objects
10061034
# ------------------------------------------------------------
10071035
data = type(data)
1036+
print (f"_cfa_aggregation_instructions: {time.time() - start:.3}")
10081037
return {
10091038
"location": data(aggregation_location),
10101039
"file": data(aggregation_file),

0 commit comments

Comments
 (0)