Skip to content

Commit

Permalink
update dir_list and unittest
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardolaiolo committed Jun 13, 2024
1 parent ade1b3f commit f35fd6a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
21 changes: 10 additions & 11 deletions aodndata/moorings/classifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,18 +326,17 @@ def dest_path(cls, input_file):
dir_list += ['ASFS', 'SOFS', cat, 'Real-time', rt_folder_name]
elif subfac in ('SOTS', 'ASFS'):
dir_list.append('SOTS')
# Open the NetCDF file
dataset = cls._open_nc_file(input_file)
try:
# Check for data_product_type attribute
if hasattr(dataset, 'data_product_type'):
dir_list.append('derived_products')
data_product_type = cls._get_nc_att(input_file, 'data_product_type', default=False)
if data_product_type:
dir_list.append('derived_products')
if data_product_type == 'gridded_data':
dir_list.append('gridded')
else:
dir_list.append(cls._get_deployment_year(input_file))
if cls._is_realtime(input_file):
dir_list.append('real-time')
finally:
dataset.close()
dir_list.append(data_product_type)
else:
dir_list.append(cls._get_deployment_year(input_file))
if cls._is_realtime(input_file):
dir_list.append('real-time')
else:
raise InvalidFileNameError(
"Unknown DWM sub-facility '{subfac}' for file '{input_file}'".format(subfac=subfac,
Expand Down
6 changes: 3 additions & 3 deletions test_aodndata/moorings/test_dwmFileClassifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,16 +328,16 @@ def test_hourly_depth_gridded_product(self):
self.assertEqual(dest_dir, 'IMOS/DWM/DA/CSIRO_gridded_all_variables')
self.assertEqual(dest_filename, filename)

def test_sots_derived_product(self):
def test_sots_derived_product_gridded(self):
filename = 'IMOS_DWM-SOTS_BCOPSTUW_20210420_SOFS_FV02_SOFS-10-2021-hourly-gridded-product_END-20220512_C-20221117.nc'
testfile = os.path.join(self.tempdir, filename)
make_test_file(testfile, {
'site_code': 'SOTS',
'platform_code': 'SOFS',
'data_product_type': 'derived'
'data_product_type': 'gridded_data'
})
dest_dir, dest_filename = os.path.split(DwmFileClassifier.dest_path(testfile))
expected_dir = 'IMOS/DWM/SOTS/derived_products'
expected_dir = 'IMOS/DWM/SOTS/derived_products/gridded'
self.assertEqual(dest_dir, expected_dir)
self.assertEqual(dest_filename, filename)

Expand Down

0 comments on commit f35fd6a

Please sign in to comment.