Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary ncattrs #174

Merged
merged 4 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions scripts/ancillary/fix_dailyclim_attrs.py
Original file line number Diff line number Diff line change
@@ -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}")
10 changes: 0 additions & 10 deletions seaice_ecdr/intermediate_monthly.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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",
Expand All @@ -417,8 +409,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,
)

conc_monthly.encoding.update(
Expand Down
18 changes: 1 addition & 17 deletions seaice_ecdr/nrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down
9 changes: 0 additions & 9 deletions seaice_ecdr/set_daily_ncattrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand All @@ -70,10 +63,8 @@ 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,
},
# Note: encoding is set when saved to netcdf file
)
Expand Down