Skip to content
Snippets Groups Projects
Commit 68798d80 authored by Shavers, Nicholas H's avatar Shavers, Nicholas H
Browse files

with compression at the file level

parent 41e88066
No related branches found
No related tags found
1 merge request!368Imagcdf factory mvp
...@@ -129,12 +129,20 @@ class ImagCDFFactory(TimeseriesFactory): ...@@ -129,12 +129,20 @@ class ImagCDFFactory(TimeseriesFactory):
def write_file(self, fh, timeseries: Stream, channels: List[str]): def write_file(self, fh, timeseries: Stream, channels: List[str]):
# Create a temporary file to write the CDF data # Create a temporary file to write the CDF data
with tempfile.NamedTemporaryFile(delete=False) as tmp_file: with tempfile.NamedTemporaryFile(delete=False, suffix='.cdf') as tmp_file:
tmp_file_path = tmp_file.name + ".cdf" tmp_file_path = tmp_file.name
try: try:
# Initialize the CDF writer # Initialize the CDF writer
cdf_writer = cdflib.cdfwrite.CDF(tmp_file_path) cdf_spec = {
'Compressed': 9, # Enable compression (0-9)
# 'Majority': 'row_major', # Data layout - gets set automatically
# 'Encoding': 'ibmpc', # Corrupts CDF - gets set automatically
'Checksum': True, # Disable checksum for faster writes (optional)
'rDim_sizes': [], # Applicable only if using rVariables - CDF protocol recommends only using zVariables.
}
cdf_writer = cdflib.cdfwrite.CDF(path=tmp_file_path, cdf_spec=cdf_spec, delete=True)
# Write global attributes # Write global attributes
global_attrs = self._create_global_attributes(timeseries, channels) global_attrs = self._create_global_attributes(timeseries, channels)
...@@ -206,7 +214,6 @@ class ImagCDFFactory(TimeseriesFactory): ...@@ -206,7 +214,6 @@ class ImagCDFFactory(TimeseriesFactory):
# Cleanup the temporary file # Cleanup the temporary file
os.remove(tmp_file_path) os.remove(tmp_file_path)
def put_timeseries( def put_timeseries(
self, self,
timeseries: Stream, timeseries: Stream,
...@@ -288,7 +295,7 @@ class ImagCDFFactory(TimeseriesFactory): ...@@ -288,7 +295,7 @@ class ImagCDFFactory(TimeseriesFactory):
# Read existing data to merge with new data # Read existing data to merge with new data
existing_cdf = cdflib.cdfread.CDF(url_file) existing_cdf = cdflib.cdfread.CDF(url_file)
existing_stream = self._read_cdf(existing_cdf) existing_stream = self._read_cdf(existing_cdf)
existing_cdf.close() # existing_cdf.close() #no close method?
existing_data = existing_stream existing_data = existing_stream
# Merge existing data with new data # Merge existing data with new data
...@@ -480,7 +487,7 @@ class ImagCDFFactory(TimeseriesFactory): ...@@ -480,7 +487,7 @@ class ImagCDFFactory(TimeseriesFactory):
elif channel in TEMPERATURE_ELEMENTS_ID: elif channel in TEMPERATURE_ELEMENTS_ID:
units = 'Celsius' units = 'Celsius'
fieldnam = f"Temperature {temperature_index} {trace.stats.location}" fieldnam = f"Temperature {temperature_index} {trace.stats.location}"
validmin = -273.15 validmin = -273.15 #absolute zero
validmax = 79_999 validmax = 79_999
elif channel in ['F','S']: elif channel in ['F','S']:
units = 'nT' units = 'nT'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment