From 091e8d4d2fd2ed21cfa56dfee3cb4f784f7e06a4 Mon Sep 17 00:00:00 2001 From: Nicky Hochmuth Date: Wed, 1 Nov 2023 15:25:14 +0100 Subject: [PATCH] fix number formats in strings and magicMoc error --- stixcore/io/fits/processors.py | 11 +++++++++-- stixcore/processing/tests/test_publish.py | 5 ++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/stixcore/io/fits/processors.py b/stixcore/io/fits/processors.py index c4530daa..977910b4 100644 --- a/stixcore/io/fits/processors.py +++ b/stixcore/io/fits/processors.py @@ -28,6 +28,12 @@ NAN = 2 ** 32 - 1 +def version_format(version): + # some very strange work around for direct use of format '{0:02d}'.format(version) + # as this is not supported by magicMoc + return f'{version:02d}' + + def set_bscale_unsigned(table_hdu): """ Set bscale value to 1 if unsigned int. @@ -96,10 +102,11 @@ def generate_filename(cls, product, *, version, date_range, status='', header=Tr status = 'U' return f'solo_{product.level}_stix-{product.type}-{product.name.replace("_", "-")}' \ - f'_{date_range}_V{version:02d}{status}{user_req}{tc_control}.fits' + f'_{date_range}_V{version_format(version)}{status}{user_req}{tc_control}.fits' @classmethod def generate_common_header(cls, filename, product, *, version=0): + headers = ( # Name, Value, Comment ('FILENAME', filename, 'FITS filename'), @@ -115,7 +122,7 @@ def generate_common_header(cls, filename, product, *, version=0): ('CREATOR', 'stixcore', 'FITS creation software'), ('VERS_SW', str(stixcore.__version__), 'Version of SW that provided FITS file'), # ('VERS_CAL', '', 'Version of the calibration pack'), - ('VERSION', f'{version:02d}', 'Version of data product'), + ('VERSION', version_format(version), 'Version of data product'), ('OBSRVTRY', 'Solar Orbiter', 'Satellite name'), ('TELESCOP', 'SOLO/STIX', 'Telescope/Sensor name'), ('INSTRUME', 'STIX', 'Instrument name'), diff --git a/stixcore/processing/tests/test_publish.py b/stixcore/processing/tests/test_publish.py index 1a358bbc..57c0a825 100644 --- a/stixcore/processing/tests/test_publish.py +++ b/stixcore/processing/tests/test_publish.py @@ -140,6 +140,7 @@ def test_publish_fits_to_esa_incomplete(product, out_dir): product.date_end = end product.split_to_files.return_value = [product] product.get_energies = False + product.get_processing_version.return_value = 1 files.extend(processor.write_fits(product)) @@ -147,7 +148,7 @@ def test_publish_fits_to_esa_incomplete(product, out_dir): # this was processed with predicted and flown assert fits.getval(files[0], 'SPICE_MK') ==\ "solo_ANC_soc-pred-mk_V106_20201116_001.tm, solo_ANC_soc-flown-mk_V105_20200515_001.tm" - # the filename should be mared as incomplete + # the filename should be marked as incomplete assert get_complete_file_name(files[0].name) != files[0].name assert get_incomplete_file_name(files[0].name) == files[0].name @@ -219,6 +220,7 @@ def test_fits_incomplete_switch_over(out_dir): product.date_end = end product.split_to_files.return_value = [product] product.get_energies = False + product.get_processing_version.return_value = 1 files_first.extend(processor.write_fits(product)) @@ -338,6 +340,7 @@ def test_publish_fits_to_esa(product, out_dir): product.date_beg = beg product.date_end = end product.split_to_files.return_value = [product] + product.get_processing_version.return_value = 1 product.get_energies = False data = product.data[:] # make a clone