@@ -126,7 +126,7 @@ def mask_land_or_ocean(arr, msk, use_nan=False):
126126 missing_value = - 999.
127127 #End if
128128
129- arr = xr .where (msk >= 0.9 ,arr ,missing_value )
129+ arr = xr .where (msk >= 0.9 ,arr ,missing_value , keep_attrs = True )
130130 arr .attrs ["missing_value" ] = missing_value
131131 return (arr )
132132
@@ -535,7 +535,7 @@ def lev_to_plev(data, ps, hyam, hybm, P0=100000., new_levels=None,
535535 #Temporary print statement to notify users to ignore warning messages.
536536 #This should be replaced by a debug-log stdout filter at some point:
537537 print ("Please ignore the interpolation warnings that follow!" )
538-
538+
539539 #Apply GeoCAT hybrid->pressure interpolation:
540540 if new_levels is not None :
541541 data_interp = gcomp .interpolation .interp_hybrid_to_pressure (data , ps ,
@@ -559,10 +559,22 @@ def lev_to_plev(data, ps, hyam, hybm, P0=100000., new_levels=None,
559559 #Rename vertical dimension back to "lev" in order to work with
560560 #the ADF plotting functions:
561561 data_interp_rename = data_interp .rename ({"plev" : "lev" })
562+ attrs = data_interp_rename .attrs .copy ()
563+ lev_orig = data_interp_rename ["lev" ]
564+ lev_orig_attrs = lev_orig .attrs .copy ()
562565
563566 #Convert vertical dimension to mb/hPa, if requested:
564567 if convert_to_mb :
565- data_interp_rename ["lev" ] = data_interp_rename ["lev" ] / 100.0
568+ lev_new = lev_orig / 100.0
569+ lev_new .attrs = lev_orig_attrs
570+ lev_new .name = "lev"
571+ lev_new .attrs ["units" ] = "hPa"
572+ lev_new .attrs ["history" ] = f"converted to hPa by dividing by 100 in adf_utils.lev_to_plev"
573+ data_interp_rename ["lev" ] = lev_new
574+ data_interp_rename .attrs = attrs
575+ else :
576+ data_interp_rename .attrs ['units' ] = "Pa"
577+ data_interp_rename .attrs ['history' ] = f"Interpolated using GeoCAT, assume units of Pa in adf_utils.lev_to_plev"
566578
567579 return data_interp_rename
568580
@@ -678,6 +690,7 @@ def plev_to_plev(data, new_levels=None, convert_to_mb=False):
678690
679691 # convert vertical dimension to mb/hPa, if requested:
680692 if convert_to_mb :
693+ ## DEAL WITH METADATA BETTER HERE
681694 output ["lev" ] = output ["lev" ] / 100.0
682695 #End if
683696
0 commit comments