From 96043bd6cc9b72983f3dc9315f077a9313597781 Mon Sep 17 00:00:00 2001 From: Scott Stewart Date: Wed, 6 Nov 2024 15:02:54 -0700 Subject: [PATCH 1/4] remove 'reference' ncattr from variables --- seaice_ecdr/intermediate_monthly.py | 1 - seaice_ecdr/nrt.py | 16 ---------------- seaice_ecdr/set_daily_ncattrs.py | 1 - 3 files changed, 18 deletions(-) diff --git a/seaice_ecdr/intermediate_monthly.py b/seaice_ecdr/intermediate_monthly.py index 1eb52008..34234644 100644 --- a/seaice_ecdr/intermediate_monthly.py +++ b/seaice_ecdr/intermediate_monthly.py @@ -417,7 +417,6 @@ def calc_cdr_seaice_conc_monthly( units="1", valid_range=(np.uint8(0), np.uint8(100)), grid_mapping="crs", - reference="https://nsidc.org/data/g02202/versions/5", number_of_missing_pixels=num_missing_conc_pixels, ) diff --git a/seaice_ecdr/nrt.py b/seaice_ecdr/nrt.py index d61f3bc9..b63f6f0e 100644 --- a/seaice_ecdr/nrt.py +++ b/seaice_ecdr/nrt.py @@ -341,22 +341,6 @@ def override_attrs_for_nrt( ) override_for_nrt.attrs["product_version"] = ECDR_NRT_PRODUCT_VERSION.version_str - # Override the reference attr for the cdr variable - if "cdr_seaice_conc" in override_for_nrt: - override_for_nrt["cdr_seaice_conc"].attrs["reference"] = link_to_dataproduct - if "cdr_seaice_conc_monthly" in override_for_nrt: - override_for_nrt["cdr_seaice_conc_monthly"].attrs[ - "reference" - ] = link_to_dataproduct - - # AM2 data available and we need to override the "reference" for the monthly cdr variable. - # TODO: this assumes the prototype group will always contain AM2 data, which - # may not be the case in the future. - if "prototype_am2" in override_for_nrt: - override_for_nrt["prototype_am2"]["am2_seaice_conc_monthly"].attrs[ - "reference" - ] = link_to_dataproduct - return override_for_nrt diff --git a/seaice_ecdr/set_daily_ncattrs.py b/seaice_ecdr/set_daily_ncattrs.py index 0cbbf8e8..1315fcfa 100644 --- a/seaice_ecdr/set_daily_ncattrs.py +++ b/seaice_ecdr/set_daily_ncattrs.py @@ -70,7 +70,6 @@ def finalize_cdecdr_ds( "NOAA/NSIDC CDR of Passive Microwave" " Sea Ice Concentration" ), "grid_mapping": "crs", - "reference": "https://nsidc.org/data/g02202/versions/5", "ancillary_variables": "cdr_seaice_conc_stdev cdr_seaice_conc_qa_flag", "valid_range": np.array((0, 100), dtype=np.uint8), "number_of_missing_pixels": num_missing_conc_pixels, From c98f7bca86b52e0e3c0d340ab22062c859a4fcf8 Mon Sep 17 00:00:00 2001 From: Scott Stewart Date: Wed, 6 Nov 2024 15:44:00 -0700 Subject: [PATCH 2/4] remove number_of_missing_pixels attr --- seaice_ecdr/intermediate_monthly.py | 9 --------- seaice_ecdr/set_daily_ncattrs.py | 8 -------- 2 files changed, 17 deletions(-) diff --git a/seaice_ecdr/intermediate_monthly.py b/seaice_ecdr/intermediate_monthly.py index 34234644..67bf7dfb 100644 --- a/seaice_ecdr/intermediate_monthly.py +++ b/seaice_ecdr/intermediate_monthly.py @@ -49,7 +49,6 @@ from seaice_ecdr.tb_data import get_hemisphere_from_crs_da from seaice_ecdr.util import ( get_intermediate_output_dir, - get_num_missing_pixels, platform_id_from_filename, standard_monthly_filename, ) @@ -402,13 +401,6 @@ def calc_cdr_seaice_conc_monthly( other=0, ) - num_missing_conc_pixels = get_num_missing_pixels( - seaice_conc_var=conc_monthly, - hemisphere=hemisphere, - resolution=resolution, - ancillary_source=ancillary_source, - ) - conc_monthly.name = "cdr_seaice_conc_monthly" conc_monthly = conc_monthly.assign_attrs( long_name="NOAA/NSIDC CDR of Passive Microwave Monthly Northern Hemisphere Sea Ice Concentration", @@ -417,7 +409,6 @@ def calc_cdr_seaice_conc_monthly( units="1", valid_range=(np.uint8(0), np.uint8(100)), grid_mapping="crs", - number_of_missing_pixels=num_missing_conc_pixels, ) conc_monthly.encoding.update( diff --git a/seaice_ecdr/set_daily_ncattrs.py b/seaice_ecdr/set_daily_ncattrs.py index 1315fcfa..aa021610 100644 --- a/seaice_ecdr/set_daily_ncattrs.py +++ b/seaice_ecdr/set_daily_ncattrs.py @@ -11,7 +11,6 @@ ) from seaice_ecdr.nc_attrs import get_global_attrs from seaice_ecdr.tb_data import get_data_url_from_data_source -from seaice_ecdr.util import get_num_missing_pixels CDECDR_FIELDS_TO_DROP = [ "h19_day_si", @@ -53,12 +52,6 @@ def finalize_cdecdr_ds( # Variables that need special handling... - num_missing_conc_pixels = get_num_missing_pixels( - seaice_conc_var=ds["cdr_seaice_conc"], - hemisphere=hemisphere, - resolution=resolution, - ancillary_source=ancillary_source, - ) ds["cdr_seaice_conc"] = ( ("time", "y", "x"), ds["cdr_seaice_conc"].data, @@ -72,7 +65,6 @@ def finalize_cdecdr_ds( "grid_mapping": "crs", "ancillary_variables": "cdr_seaice_conc_stdev cdr_seaice_conc_qa_flag", "valid_range": np.array((0, 100), dtype=np.uint8), - "number_of_missing_pixels": num_missing_conc_pixels, }, # Note: encoding is set when saved to netcdf file ) From 5aa8293b16753852e345a84750f74acebab0e7e4 Mon Sep 17 00:00:00 2001 From: Scott Stewart Date: Wed, 6 Nov 2024 15:44:22 -0700 Subject: [PATCH 3/4] fix nrt 'summary' attr --- seaice_ecdr/nrt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seaice_ecdr/nrt.py b/seaice_ecdr/nrt.py index b63f6f0e..57efbd5b 100644 --- a/seaice_ecdr/nrt.py +++ b/seaice_ecdr/nrt.py @@ -326,7 +326,7 @@ def override_attrs_for_nrt( elif platform_id == "am2": # TODO: confirm this summary is OK with Ann. override_for_nrt.attrs["summary"] = ( - f"This data set provides a near-real-time (NRT) passive microwave sea ice concentration climate data record (CDR) based on gridded brightness temperatures (TBs) from the Global Change Observation Mission 1st-Water (GCOM-W1) passive microwave radiometer: Advanced Microwave Scanning Radiometer 2 (AMSR2) am2. The sea ice concentration CDR is an estimate of sea ice concentration that is produced by combining concentration estimates from two algorithms developed at the NASA Goddard Space Flight Center (GSFC): the NASA Team algorithm and the Bootstrap algorithm. The individual algorithms are used to process and combine brightness temperature data at NSIDC. This product is designed to provide an NRT time series of sea ice concentrations (the fraction, or percentage, of ocean area covered by sea ice). The data are gridded on the NSIDC polar stereographic grid with {resolution} x {resolution} km grid cells and are available in NetCDF file format. Each file contains a variable with the CDR concentration values as well as variables that hold the NASA Team and Bootstrap processed concentrations for reference. Variables containing standard deviation, quality flags, and projection information are also included." + f"This data set provides a near-real-time (NRT) passive microwave sea ice concentration climate data record (CDR) based on gridded brightness temperatures (TBs) from the Global Change Observation Mission 1st-Water (GCOM-W1) passive microwave radiometer: Advanced Microwave Scanning Radiometer 2 (AMSR2). The sea ice concentration CDR is an estimate of sea ice concentration that is produced by combining concentration estimates from two algorithms developed at the NASA Goddard Space Flight Center (GSFC): the NASA Team algorithm and the Bootstrap algorithm. The individual algorithms are used to process and combine brightness temperature data at NSIDC. This product is designed to provide an NRT time series of sea ice concentrations (the fraction, or percentage, of ocean area covered by sea ice). The data are gridded on the NSIDC polar stereographic grid with {resolution} x {resolution} km grid cells and are available in NetCDF file format. Each file contains a variable with the CDR concentration values as well as variables that hold the NASA Team and Bootstrap processed concentrations for reference. Variables containing standard deviation, quality flags, and projection information are also included." ) # NOTE: this NRT summary is specific to either F17 or AMSR2 From 3c4fb2570592c00f1cc0193d52ee83a85addac01 Mon Sep 17 00:00:00 2001 From: Scott Stewart Date: Wed, 6 Nov 2024 19:31:20 -0700 Subject: [PATCH 4/4] add script to add global attrs ot dailyclim ancillary files --- scripts/ancillary/fix_dailyclim_attrs.py | 102 +++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 scripts/ancillary/fix_dailyclim_attrs.py diff --git a/scripts/ancillary/fix_dailyclim_attrs.py b/scripts/ancillary/fix_dailyclim_attrs.py new file mode 100644 index 00000000..fe20de1d --- /dev/null +++ b/scripts/ancillary/fix_dailyclim_attrs.py @@ -0,0 +1,102 @@ +""" +./fix_dailyclim_attrs.py + +Add global attributes to daily climatology files + + +""" + +import os + +from netCDF4 import Dataset + +source_dir = "/share/apps/G02202_V5/v05_ancillary/" + +base_filename = { + "psn25": "G02202-ancillary-psn25-daily-invalid-ice-v05r00.nc", + "pss25": "G02202-ancillary-pss25-daily-invalid-ice-v05r00.nc", +} + +new_global_attrs_for_gridid = { + "psn25": { + "title": "Day of year climatology invalid ice mask used in CDRv5", + "date_created": "2024-11-06", + "date_modified": "2024-11-06", + "date_metadata_modified": "2024-11-06", + "keywords": "EARTH SCIENCE SERVICES > DATA ANALYSIS AND VISUALIZATION > GEOGRAPHIC INFORMATION SYSTEMS", + "Conventions": "CF-1.10, ACDD-1.3", + "cdm_data_type": "grid", + "geospatial_bounds": "POLYGON ((-3850000 5850000, 3750000 5850000, 3750000 -5350000, -3850000 -5350000, -3850000 5850000))", + "geospatial_bounds_crs": "EPSG:3411", + "geospatial_x_units": "meters", + "geospatial_y_units": "meters", + "geospatial_x_resolution": "25000 meters", + "geospatial_y_resolution": "25000 meters", + "geospatial_lat_min": 30.980564, + "geospatial_lat_max": 90.0, + "geospatial_lon_min": -180.0, + "geospatial_lon_max": 180.0, + "geospatial_lat_units": "degrees_north", + "geospatial_lon_units": "degrees_east", + }, + "pss25": { + "title": "Day of year climatology invalid ice mask used in CDRv5", + "date_created": "2024-11-06", + "date_modified": "2024-11-06", + "date_metadata_modified": "2024-11-06", + "keywords": "EARTH SCIENCE SERVICES > DATA ANALYSIS AND VISUALIZATION > GEOGRAPHIC INFORMATION SYSTEMS", + "Conventions": "CF-1.10, ACDD-1.3", + "cdm_data_type": "grid", + "geospatial_bounds": "POLYGON ((-3950000 4350000, 3950000 4350000, 3950000 -3950000, -3950000 -3950000, -3950000 4350000))", + "geospatial_bounds_crs": "EPSG:3412", + "geospatial_x_units": "meters", + "geospatial_y_units": "meters", + "geospatial_x_resolution": "25000 meters", + "geospatial_y_resolution": "25000 meters", + "geospatial_lat_min": -90.0, + "geospatial_lat_max": -39.23089, + "geospatial_lon_min": -180.0, + "geospatial_lon_max": 180.0, + "geospatial_lat_units": "degrees_north", + "geospatial_lon_units": "degrees_east", + }, +} + + +if __name__ == "__main__": + import sys + + all_gridids = ("psn25", "pss25") + try: + gridid_list = (sys.argv[1],) + assert gridid_list[0] in all_gridids + except IndexError: + gridid_list = all_gridids + print("No gridid given, using: {gridid_list}", flush=True) + except AssertionError: + err_message = f""" + Invalid gridid + {sys.argv[1]} not in {all_gridids} + """ + raise ValueError(err_message) + + for gridid in gridid_list: + ifn = source_dir + base_filename[gridid] + assert os.path.isfile(ifn) + + ofn = "./" + base_filename[gridid] + + print(f" input file: {ifn}") + print(f"output file: {ofn}") + assert ifn != ofn + + os.system(f"cp -v {ifn} {ofn}") + + assert gridid in new_global_attrs_for_gridid.keys() + + with Dataset(ofn, "r+") as ds: + + new_attrs_dict = new_global_attrs_for_gridid[gridid] + ds.setncatts(new_attrs_dict) + + print(f"Wrote: {ofn}")